Location: PHPKode > scripts > Error Management > error-management/search_error.php
<?
include("dbconnect.inc.php");

class SearchErrors
	{
/******************************************************************************************************************
-Class variables
/******************************************************************************************************************/
		var $display_fields;
  		var $search_result;
	  	var $ed_list;
  		var $field_list;
/******************************************************************************************************************
-Used to process the form data
/******************************************************************************************************************/  		
		function ProcessForm()
			{
				$select="SELECT * FROM error_description";
				$result1=mysql_query($select);

				$this->ed_list='';
				$this->ed_list="<option value='-1'>Please Select</option>";
				while($row=mysql_fetch_assoc($result1))
					{
						if(isset($_POST['error_description'])&&$_POST['error_description']==$row['description']) $this->ed_list.="<option value='$row[description]' selected>$row[description]</option>\n";
						else $this->ed_list.="<option value='$row[description]'>$row[description]</option>\n";
					}

				$select="SHOW FIELDS FROM error_reports";
				$result1=mysql_query($select);

				if(!isset($_POST['display_fields']))$default_fields=array('id','page_url','reported_on','is_fixed','description');
				else $default_fields=array();

				$this->field_list='';
				while($row=mysql_fetch_assoc($result1))
					{
						if(isset($_POST['display_fields'])&& in_array($row['Field'],$_POST['display_fields']))$this->field_list.="<option value='$row[Field]' selected>$row[Field]</option>\n";
						else if(in_array($row['Field'],$default_fields))$this->field_list.="<option value='$row[Field]' selected>$row[Field]</option>\n";
						else $this->field_list.="<option value='$row[Field]'>$row[Field]</option>\n";
					}

				$this->display_fields="<tr>";
				$this->search_result="";
				if(isset($_POST['Submit']))
					{			
						$category=$_POST['category'];
						if($_POST['category']=="other")$category=$_POST['other_text'];
						$time_taken=$_POST['time_taken']*3600;
						
						$select="SELECT id,";	
						$this->display_fields.="<td align='left'><b>Sr No.</b></td>\n";					
						for($count=0;$count<count($_POST['display_fields']);$count++)
							{
								$field_name=str_replace("_"," ",$_POST['display_fields'][$count]);
								$field_name=ucwords($field_name);
								
								$this->display_fields.="<td align='left'><b>".$field_name."</b></td>\n";
								$select.=$_POST['display_fields'][$count].",";
							}
						if(count($_POST['display_fields'])>0)$this->display_fields.="<td align='left'><b>Action</b></td>\n";
						$this->display_fields.="</tr>";
						$select=trim($select,',')." FROM error_reports ";
						
						if(isset($_POST['use_sql']))$select.="WHERE ".$_POST['sql'];
						else if(isset($_POST['search_by']))
							{
								$where=array();
								if(in_array("Error Fixed",$_POST['search_by']))$where[]="is_fixed='".htmlentities(mysql_escape_string($_POST['is_fixed']))."'";
								if(in_array("Fixed By",$_POST['search_by']))$where[]="fixed_by='".htmlentities(mysql_escape_string($_POST['fixed_by']))."'";
								if(in_array("Fixed Between",$_POST['search_by']))$where[]="fixed_on>=".htmlentities(mysql_escape_string(strtotime($_POST['fb_start'])))." AND fixed_on<=".htmlentities(mysql_escape_string(strtotime($_POST['fb_end'])));
								if(in_array("Time Taken To Fix",$_POST['search_by']))$where[]="time_taken<=$time_taken";
								if(in_array("Error Location",$_POST['search_by']))$where[]="location='".htmlentities(mysql_escape_string($_POST['location']))."'";
								if(in_array("Error Category",$_POST['search_by']) && isset($_POST['category']))$where[]="category='".htmlentities(mysql_escape_string($category))."'";
								if(in_array("Error Description",$_POST['search_by']))$where[]="description='".htmlentities(mysql_escape_string($_POST['error_description']))."'";
								if(in_array("Browser Issue",$_POST['search_by']))$where[]="is_browser='".htmlentities(mysql_escape_string($_POST['browser']))."'";
								if(in_array("Incorrect Solution",$_POST['search_by']))$where[]="incorrect_solution='".htmlentities(mysql_escape_string($_POST['incorrect_solution']))."'";
								if(in_array("Site Owned By US",$_POST['search_by']))$where[]="owned_by_us='".htmlentities(mysql_escape_string($_POST['owned_by_us']))."'";
								if(in_array("Reported By",$_POST['search_by']))$where[]="reported_by='".htmlentities(mysql_escape_string($_POST['reported_by']))."'";
								if(in_array("Reported Between",$_POST['search_by']))$where[]="reported_on>=".htmlentities(mysql_escape_string(strtotime($_POST['rb_start'])))." AND reported_on<=".htmlentities(mysql_escape_string(strtotime($_POST['rb_end'])));
								if(in_array("Error Severity",$_POST['search_by']))$where[]="severity='".htmlentities(mysql_escape_string($_POST['error_severity']))."'";
								if(in_array("Page URL",$_POST['search_by']))$where[]="page_url like '%".htmlentities(mysql_escape_string($_POST['page_url']))."%'";
								if(in_array("Domain",$_POST['search_by']))$where[]="domain like '%".htmlentities(mysql_escape_string($_POST['domain']))."%'";
								
								if(count($where)>0)$select.=" WHERE ".implode(" AND ",$where);				
							}
						
						$counter=1;
						if($result2=mysql_query($select))
							{
								while($row=mysql_fetch_assoc($result2))
									{
										$this->search_result.="<tr>";
										$this->search_result.="<td align='left'>".$counter."</td>\n";
										for($count=0;$count<count($_POST['display_fields']);$count++)
												{
													if($_POST['display_fields'][$count]=="reported_on"||$_POST['display_fields'][$count]=="fixed_on")$str=date('M  d Y',$row[$_POST['display_fields'][$count]]);
													else if($_POST['display_fields'][$count]=="time_taken")$str=round($row[$_POST['display_fields'][$count]]/3600,2)." hrs";
													else $str=$row[$_POST['display_fields'][$count]];
													$this->search_result.="<td align='left'>".$str."</td>\n";			
												}
										$this->search_result.="<td align='left'><input name='edit' type='button' value='Edit' onclick=\"window.location.href='edit_error.php?id=$row[id]'\"/></td>\n";
										$this->search_result.="</tr>";
										$counter++;
									}
							}
						else
							{
								echo "Database Error.<br/>Details : ".mysql_error();
								echo "<br/>Query String : ".$select;
								exit;
							}
					}
			}
/******************************************************************************************************************
-Used to display the form
/******************************************************************************************************************/
		function DisplayForm()
			{
				?>
				<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
				<html xmlns="http://www.w3.org/1999/xhtml">
				<head>
				<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
				<title>Report Error</title>
				<script language='javascript' src= "js/choosedate.js"></script>
				<link type="text/css" rel="stylesheet" href="css/calendar.css">
				<script language='javascript'>
				function CheckOther()
					{
						if(document.search.category[3].checked)document.search.other_text.disabled=false;
						else document.search.other_text.disabled=true;
					}
				</script>
				</head>

				<body>
				<br/>
				<h2 align="center">Search Error Report</h2>
				<br/>
				<form name="search" action="<?=$_SERVER['PHP_SELF']?>" method="post">
				<table width="100%" border="0" cellspacing="5" align="center">
				  <tr>
					<td>Fixed By : </td>
					<td><select name="fixed_by">
					  <?
						$select = "select name from staff";
						$result=mysql_query($select);
						while($row=mysql_fetch_array($result))
							{
								if(isset($_POST['fixed_by'])&&strtolower($_POST['fixed_by'])==strtolower($row['name']))echo "<option value='".$row['name']."' selected>".$row['name']."</option>\n";
								else echo "<option value='".$row['name']."'>".$row['name']."</option>\n";
							}
					?>
					</select></td>
					<td>&nbsp;</td>
				  </tr>
				  <tr>
					<td>Error Location : </td>
					<td><input name="location" type="radio" value="local" <?if(isset($_POST['location'])&&$_POST['location']=='local')echo 'checked';?>/>
					local
					  <input name="location" type="radio" value="www" <?if(isset($_POST['location'])&&$_POST['location']=='www')echo 'checked';?>/>
					www
					<input name="location" type="radio" value="hosting" <?if(isset($_POST['location'])&&$_POST['location']=='hosting')echo 'checked';?>/>
					hosting</td>
					<td>&nbsp;</td>
				  </tr>
				  <tr>
					<td>Error Category : </td>
					<td><input type="radio" name="category" value="php" <?if(isset($_POST['category'])&&$_POST['category']=='php')echo 'checked';?> onchange="CheckOther();"/>
					Php
					  <input type="radio" name="category" value="javascript" <?if(isset($_POST['category'])&&$_POST['category']=='javascript')echo 'checked';?> onchange="CheckOther();"/>
					Javascript
					<input type="radio" name="category" value="html" <?if(isset($_POST['category'])&&$_POST['category']=='html')echo 'checked';?> onchange="CheckOther();"/>
					HTML
					<input type="radio" name="category" value="other" <?if(isset($_POST['category'])&&$_POST['category']=='other')echo 'checked';?> onchange="CheckOther();"/>
					Other  
					<input type="text" name="other_text" value="<?=@$_POST['other_text'];?>" <?if(isset($_POST['category'])&&($_POST['category']=='php'||$_POST['category']=='javascript'||$_POST['category']=='html'))echo"disabled='disabled'";?>/></td>
					<td>&nbsp;</td>
				  </tr>
				  <tr>
					<td>Error Description : </td>
					<td>
						<select name="error_description" id="error_description">
						<?=$this->ed_list;?>
						</select>	
					</td>
					<td>&nbsp;</td>
				  </tr>
				  <tr>
					<td>Browser Issue : </td>
					<td><input name="browser" type="radio" value="yes" <?if(isset($_POST['browser'])&&$_POST['browser']=='yes')echo 'checked';?>/>
					yes
					  <input name="browser" type="radio" value="no" <?if(isset($_POST['browser'])&&$_POST['browser']=='no')echo 'checked';?>/>
					no</td>
					<td>&nbsp;</td>
				  </tr>
				  <tr>
					<td>Incorrect Solution : </td>
					<td><input name="incorrect_solution" type="radio" value="yes" <?if(isset($_POST['incorrect_solution'])&&$_POST['incorrect_solution']=='yes')echo 'checked';?>/>
					yes
					  <input name="incorrect_solution" type="radio" value="no" <?if(isset($_POST['incorrect_solution'])&&$_POST['incorrect_solution']=='no')echo 'checked';?>/>
					no</td>
					<td>&nbsp;</td>
				  </tr>
				  <tr>
					<td>Site Owned by us : </td>
					<td><input name="owned_by_us" type="radio" value="radiobutton" <?if(isset($_POST['owned_by_us'])&&$_POST['owned_by_us']=='yes')echo 'checked';?>/>
					yes
					  <input name="owned_by_us" type="radio" value="radiobutton" <?if(isset($_POST['owned_by_us'])&&$_POST['owned_by_us']=='no')echo 'checked';?> />
					no</td>
					<td>&nbsp;</td>
				  </tr>
				   <tr>
					<td>Error Fixed : </td>
					<td><input name="is_fixed" type="radio" value="yes" <?if(isset($_POST['is_fixed'])&&$_POST['is_fixed']=='yes')echo 'checked';?>/>
					yes
					  <input name="is_fixed" type="radio" value="no" <?if(isset($_POST['is_fixed'])&&$_POST['is_fixed']=='no')echo 'checked';?>/>
					no</td>
					<td>&nbsp;</td>
				  </tr>
				  <tr>
					<td width="13%" scope="col">Reported By : </td>
					<td width="46%" scope="col">
					<select name="reported_by">
					<?
						$select = "select name from staff";
						$result=mysql_query($select);
						while($row=mysql_fetch_array($result))
							{
								if(strtolower($_SESSION['username'])==strtolower($row['name']))echo "<option value='".$row['name']."' selected>".$row['name']."</option>\n";
								else echo "<option value='".$row['name']."'>".$row['name']."</option>\n";
							}
					?>
					</select></td>
					<td width="14%" scope="col">&nbsp;</td>
				  </tr>
				  <tr>
					<td>Error Severity : </td>
					<td>
					<select name="error_severity">
					<option value="low" <?if(isset($_POST['error_severity'])&&$_POST['error_severity']=='low')echo 'selected';?>>Low</option>
					<option value="medium" <?if(isset($_POST['error_severity'])&&$_POST['error_severity']=='medium')echo 'selected';?>>Medium</option>
					<option value="high" <?if(isset($_POST['error_severity'])&&$_POST['error_severity']=='high')echo 'selected';?>>High</option>
					</select>    </td>
					<td>&nbsp;</td>
				  </tr>
					<tr>
					<td>Domain : </td>
					<td><input type="text" name="domain" size="35" value="<?=@$_POST['domain']?>"/></td>
					<td>&nbsp;</td>
					</tr>
				  <tr>
					<td>Page URL : </td>
					<td><input type="text" name="page_url" size="75" value="<?=@$_POST['page_url']?>"/></td>
				    
				  </tr>
				  <tr>
					<td>Reported Between : </td>
					<td>
					<input type="text" name="rb_start" size="10" value="<?=@$_POST['rb_start']?>"/>
					<script language= javascript> 
						var myCal = new calendar("FIELD:document.search.rb_start;");
						myCal.writeCalendar();
					</script>
					 and 
					<input type="text" name="rb_end" size="15" value="<?=@$_POST['rb_end']?>"/>
					<script language= javascript> 
						var myCal = new calendar("FIELD:document.search.rb_end;");
						myCal.writeCalendar();
					</script>
					</td>
				  </tr>
				  <tr>
					<td>Fixed Between : </td>
					<td><input type="text" name="fb_start" size="10" value="<?=@$_POST['fb_start']?>"/>
					<script language= javascript> 
						var myCal = new calendar("FIELD:document.search.fb_start;");
						myCal.writeCalendar();
					</script>
					and <input type="text" name="fb_end" size="15" value="<?=@$_POST['fb_end']?>"/>
					<script language= javascript> 
						var myCal = new calendar("FIELD:document.search.fb_end;");
						myCal.writeCalendar();
					</script>
					</td>
				  </tr>
				  <tr>
					<td>Time taken to fix (<=) : </td>
					<td><input type="text" name="time_taken" size="75" value="<?=@$_POST['time_taken']?>"/> hours</td>
					<td width="14%"></td>
				  </tr>
				   <tr>
					<td>&nbsp;</td>
					<td>&nbsp;</td>
					<td rowspan="4"><strong>Display Fields
					</strong>      
					<select name="display_fields[]" multiple="multiple" size="5">
   					  <?=$this->field_list?>
					</select></td>
					<td width="14%" rowspan="4"><strong>Search By
					</strong>      
					<select name="search_by[]" multiple="multiple" size="5">
   					  <option value="Error Fixed" <?if(@in_array("Error Fixed",$_POST['search_by']))echo 'selected';?>>Error Fixed</option>
					  <option value="Fixed By" <?if(@in_array("Fixed By",$_POST['search_by']))echo 'selected';?>>Fixed By</option>
					  <option value="Fixed Between" <?if(@in_array("Fixed Between",$_POST['search_by']))echo 'selected';?>>Fixed Between</option>
					  <option value="Time Taken to Fix" <?if(@in_array("Time Taken to Fix",$_POST['search_by']))echo 'selected';?>>Time Taken to Fix</option>
					  <option value="Error Location" <?if(@in_array("Error Location",$_POST['search_by']))echo 'selected';?>>Error Location</option>
					  <option value="Error Category" <?if(@in_array("Error Category",$_POST['search_by']))echo 'selected';?>>Error Category</option>
					  <option value="Error Description" <?if(@in_array("Error Description",$_POST['search_by']))echo 'selected';?>>Error Description</option>
					  <option value="Browser Issue" <?if(@in_array("Browser Issue",$_POST['search_by']))echo 'selected';?>>Browser Issue</option>
					  <option value="Incorrect Solution" <?if(@in_array("Incorrect Solution",$_POST['search_by']))echo 'selected';?>>Incorrect Solution</option>
					  <option value="Site Owned by US" <?if(@in_array("Site Owned by US",$_POST['search_by']))echo 'selected';?>>Site Owned by US</option>
					  <option value="Reported By" <?if(@in_array("Reported By",$_POST['search_by']))echo 'selected';?>>Reported By</option>
					  <option value="Reported Between" <?if(@in_array("Reported Between",$_POST['search_by']))echo 'selected';?>>Reported Between</option>
					  <option value="Error Severity" <?if(@in_array("Error Severity",$_POST['search_by']))echo 'selected';?>>Error Severity</option>
					  <option value="Page URL" <?if(@in_array("Page URL",$_POST['search_by']))echo 'selected';?>>Page URL</option>
					  <option value="Domain" <?if(@in_array("Domain",$_POST['search_by']))echo 'selected';?>>Domain</option>
					</select></td>
				   </tr>
				   <tr>
					<td valign="bottom"><strong>SQL (Where Only) : </strong></td>
					<td valign="bottom"><input type="text" name="sql" size="75" value="<?=@$_POST['sql'];?>"/></td>
					<td width="13%" valign="bottom"><input type="submit" name="Submit" value="Search" />&nbsp;&nbsp;
					  <input type="checkbox" name="use_sql" value="checkbox" <?if(isset($_POST['use_sql']))echo "checked";?>/>
					  <strong>use sql</strong></td>
				   </tr>
				</table>
				<br/>
				<br/>
				<hr />
				<br/>
				<br/>
				<h2 align="center">Search Results</h2>
				<table border="0" cellspacing="15" align="left">
				  <tr>
				  <?
  					echo $this->display_fields;
  					echo $this->search_result;
				  ?>
				  </tr>
				</table>

				</form>
				</body>
				</html>
				<?
			}
/******************************************************************************************************************
-Main function of the class.
/******************************************************************************************************************/
		function MainFunction()
			{
				$this->ProcessForm();
				$this->DisplayForm();	
			}
	}
	
$search_errors=new SearchErrors();
$search_errors->MainFunction();
Return current item: Error Management