<?
include("dbconnect.inc.php");
class EditErrors
{
/******************************************************************************************************************
-Class variables
/******************************************************************************************************************/
var $row;
var $ed_list;
/******************************************************************************************************************
-Used to process the form data
/******************************************************************************************************************/
function ProcessForm()
{
$select="SELECT * FROM error_reports WHERE id=$_GET[id]";
$result=mysql_query($select);
$row=mysql_fetch_assoc($result);
$select="SELECT * FROM error_description";
$result1=mysql_query($select);
$this->ed_list='';
$this->ed_list="<option value='-1'>Please Select</option>";
while($row1=mysql_fetch_assoc($result1))
{
if($row['description']==$row1['description']) $this->ed_list.="<option value='$row1[description]' selected>$row1[description]</option>\n";
else $this->ed_list.="<option value='$row1[description]'>$row1[description]</option>\n";
}
if(isset($_POST['update']))
{
$category=$_POST['category'];
if($_POST['category']=="other")$category=htmlentities(mysql_escape_string($_POST['other_text']));
foreach($_POST as $key=>$value)
{
if(!is_array($value))$_POST[$key]=htmlentities(mysql_escape_string($value));
}
$select="SELECT * FROM error_description WHERE description='$_POST[description]'";
$result1=mysql_query($select);
if(mysql_num_rows($result1)==0)
{
$insert_str="INSERT INTO error_description (description) VALUES('$_POST[description]')";
mysql_query($insert_str);
}
$update_str="UPDATE error_reports SET fixed_by='$_POST[fixed_by]',location='$_POST[location]',category='$category',description='$_POST[description]',
is_browser='$_POST[browser]',cause='$_POST[cause]',solution='$_POST[solution]',incorrect_solution='$_POST[incorrect_solution]',owned_by_us='$_POST[owned_by_us]',fixer_comments='$_POST[fixer_comments]',
time_taken=".(time()-$row['reported_on']).",is_fixed='yes',fixed_on=".time()." WHERE id=$_GET[id]";
if($result=mysql_query($update_str))echo"<script>alert('Error report was successfully updated and emailed to the selected users.');</script>";
else
{
echo "Database Error.<br/>Details : ".mysql_error();
echo "<br/>Query String : ".$update_str;
exit;
}
$select = "select * from staff where name='".$_POST['reported_by']."'";
$result=mysql_query($select);
$row=mysql_fetch_array($result);
$subject=$_POST['error_severity']." level error was reported by ".$row['reported_by'];
$from_address=$row['email'];
$body="<html>\n";
$body.="<body>\n";
$body.="Reported By : ".$row['reported_by'];
$body.="<br/><br/>Error Severity : ".$row['error_severity'];
$body.="<br/><br/>Page URL : ".$row['page_url'];
$body.="<br/><br/>Error Message : <br/>".$row['error_message'];
$body.="<br/><br/>Cause : <br/>".$_POST['cause'];
$body.="<br/><br/>Solution : <br/>".$_POST['solution'];
$body.="</body>";
$body.="</html>";
$headers= "From: ".$_POST['reported_by']."<".$from_address.">\n";
$headers.= "Reply-To: ".$_POST['reported_by']."<".$from_address.">\n";
$headers.= "Content-type: text/html; charset=\"iso-8859-1\"\n";
$headers.= "MIME-Version: 1.0\r\n";
for($count=0;$count<count($_POST['email_list']);$count++)
{
$to_address=$_POST['email_list'][$count];
mail($to_address,$subject,$body,$headers);
}
}
$select="SELECT * FROM error_reports WHERE id=$_GET[id]";
$result=mysql_query($select);
$this->row=mysql_fetch_assoc($result);
}
/******************************************************************************************************************
-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'>
function CheckOther()
{
if(document.update.category[3].checked)document.update.other_text.disabled=false;
else document.update.other_text.disabled=true;
}
</script>
</head>
<body>
<br/>
<h2 align="center">Modify Error Report</h2>
<br/>
<form name="update" method="POST" action="<?=$_SERVER['PHP_SELF']."?id=$_GET[id]";?>">
<table width="65%" 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($row1=mysql_fetch_array($result))
{
if(strtolower($this->row['fixed_by'])==strtolower($row1['name']))echo "<option value='".$row1['name']."' selected>".$row1['name']."</option>\n";
else echo "<option value='".$row1['name']."'>".$row1['name']."</option>\n";
}
?>
</select></td>
</tr>
<tr>
<td>Error Location : </td>
<td><input name="location" type="radio" value="local" <?if($this->row['location']=='local')echo 'checked';?>/>
local
<input name="location" type="radio" value="www" <?if($this->row['location']=='www')echo 'checked';?>/>
www
<input name="location" type="radio" value="hosting" <?if($this->row['location']=='hosting')echo 'checked';?>/>
hosting</td>
</tr>
<tr>
<td>Error Category : </td>
<td><input type="radio" name="category" value="php" <?if($this->row['category']=='php')echo 'checked';?> onchange="CheckOther();"/>
Php
<input type="radio" name="category" value="javascript" <?if($this->row['category']=='javascript')echo 'checked';?> onchange="CheckOther();"/>
Javascript
<input type="radio" name="category" value="html" <?if($this->row['category']=='html')echo 'checked';?> onchange="CheckOther();"/>
HTML
<input type="radio" name="category" value="other" <?if($this->row['category']!='php'&&$this->row['category']!='html'&&$this->row['category']!='javascript')echo 'checked';?> onchange="CheckOther();"/>
Other
<input type="text" name="other_text" value="<?if($this->row['category']!='php'&&$this->row['category']!='javascript'&&$this->row['category']!='html')echo $this->row['category'];?>"
<?if($this->row['category']=='php'||$this->row['category']=='javascript'||$this->row['category']=='html')echo "disabled='disabled'";?> onchange="CheckOther();" /></td>
<td> </td>
</tr>
<tr>
<td>Error Description : </td>
<td>
<select name="description" id="error_description">
<?=$this->ed_list;?>
</select>
<a href="javascript:"><img src="basic/btn_plus.gif" border="0" onclick="text=prompt('Enter Function Type : ','');
var option = document.createElement('OPTION');
option.text=text;
option.value=text;
option.selected=true;
if(text!=null&&text!='')document.getElementById('error_description').options.add(option);"/></a>
<a href="javascript:"><img src="basic/btn_delete.gif" border="0" onclick="index=document.getElementById('error_description').selectedIndex;
document.getElementById('error_description').remove(index);"/></a>
</td>
</tr>
<tr>
<td>Browser Issue : </td>
<td><input name="browser" type="radio" value="yes" <?if($this->row['is_browser']=='yes')echo 'checked';?>/>
yes
<input name="browser" type="radio" value="no" <?if($this->row['is_browser']=='no')echo 'checked';?>/>
no</td>
</tr>
<tr>
<td>Cause : </td>
<td><textarea name="cause" rows="5" cols="75"><?=$this->row['cause'];?></textarea></td>
</tr>
<tr>
<td>Solution : </td>
<td><textarea name="solution" rows="5" cols="75"><?=$this->row['solution'];?></textarea></td>
</tr>
<tr>
<td>Incorrect Solution : </td>
<td><input name="incorrect_solution" type="radio" value="yes" <?if($this->row['incorrect_solution']=='yes')echo 'checked';?>/>
yes
<input name="incorrect_solution" type="radio" value="no" <?if($this->row['incorrect_solution']=='no')echo 'checked';?>/>
no</td>
</tr>
<tr>
<td>Site Owned by us : </td>
<td><input name="owned_by_us" type="radio" value="yes" <?if($this->row['owned_by_us']=='yes')echo 'checked';?>/>
yes
<input name="owned_by_us" type="radio" value="no" <?if($this->row['owned_by_us']=='no')echo 'checked';?>/>
no</td>
</tr>
<tr>
<td>Fixer Comments : </td>
<td><textarea name="fixer_comments" rows="5" cols="75"><?=$this->row['fixer_comments'];?></textarea></td>
</tr>
<tr>
<td>Alert Users : </td>
<td>
<select name="email_list[]" multiple="multiple" size="4">
<?
$select = "select * from staff";
$result=mysql_query($select);
while($row1=mysql_fetch_array($result))
{
if(strtolower($_SESSION['username'])==strtolower($row1['name']))echo "<option value='".$row1['email']."' selected>".$row1['name']."</option>\n";
else echo "<option value='".$row1['email']."'>".$row1['name']."</option>\n";
}
?>
</select>
</td>
</tr>
<tr>
<td width="26%" scope="col">Reported By : </td>
<td width="74%" scope="col">
<select name="reported_by" disabled="disabled">
<?
$select = "select name from staff";
$result=mysql_query($select);
while($row1=mysql_fetch_array($result))
{
if(strtolower($this->row['reported_by'])==strtolower($row1['name']))echo "<option value='".$row1['name']."' selected>".$row1['name']."</option>\n";
else echo "<option value='".$row1['name']."'>".$row1['name']."</option>\n";
}
?>
</select></td>
</tr>
<tr>
<td>Error Severity : </td>
<td>
<select name="error_severity" disabled="disabled">
<option value="low" <?if($this->row['severity']=='low')echo 'selected';?>>Low</option>
<option value="medium" <?if($this->row['severity']=='medium')echo 'selected';?>>Medium</option>
<option value="high" <?if($this->row['severity']=='high')echo 'selected';?>>High</option>
</select> </td>
</tr>
<tr>
<td>Page URL : </td>
<td><input type="text" name="page_url" size="75" disabled="disabled" value="<?=$this->row['page_url']?>"/></td>
</tr>
<tr>
<td>Error Message : </td>
<td><textarea name="error_details" rows="10" cols="75" disabled="disabled"><?=$this->row['error_details'];?></textarea></td>
</tr>
<tr>
<td>Reporter Comments : </td>
<td><textarea name="reporter_comments" rows="5" cols="75" disabled="disabled"><?=$this->row['reporter_comments'];?></textarea></td>
</tr>
<tr>
<td colspan="2" align="center" height="60" valign="bottom"><input type="submit" name="update" value="Update" /></td>
</tr>
</table>
</form>
</body>
</html>
<?
}
/******************************************************************************************************************
-Main function of the class.
/******************************************************************************************************************/
function MainFunction()
{
$this->ProcessForm();
$this->DisplayForm();
}
}
$edit_errors=new EditErrors();
$edit_errors->MainFunction();