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

class AddError
	{
/******************************************************************************************************************
-Used to process the form data
/******************************************************************************************************************/
		function ProcessForm()
			{
				if(isset($_POST['add_error']))
					{
						foreach($_POST as $key=>$value)
							{
								if(!is_array($value))$_POST[$key]=htmlentities(mysql_escape_string($value));
							}
						
						$current_date=time();
						$arr=explode('/',$_POST['page_url']);
						$domain=$arr[2];
						$insert_str="INSERT INTO error_reports (domain,page_url,reported_on,reported_by,severity,error_details,reporter_comments) VALUES('$domain','$_POST[page_url]',$current_date,'$_POST[reported_by]',
						'$_POST[error_severity]','$_POST[error_message]','$_POST[reporter_comments]')";

						if(mysql_query($insert_str))echo"<script>alert('Error was successfully reported and emailed to the selected users.');</script>";
						else
							{
								echo "Database Error.<br/>Details : ".mysql_error();
								echo "<br/>Query String : ".$insert_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 ".$_POST['reported_by'];
						$from_address=$row['email'];

						$body="<html>\n";
						$body.="<body>\n";
						$body.="Reported By : ".$_POST['reported_by'];
						$body.="<br/><br/>Error Severity : ".$_POST['error_severity'];
						$body.="<br/><br/>Page URL : ".$_POST['page_url'];
						$body.="<br/><br/>Error Message : <br/>".$_POST['error_message'];
						$body.="<br/><br/>Reported Comments : <br/>".$_POST['reporter_comments'];		
						$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);
							}
					}			
			}
/******************************************************************************************************************
-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>
				</head>

				<body>
				<br/>
				<h2 align="center">Report Error</h2>
				<br/>
				<form name="add" action="<?=$_SERVER['PHP_SELF']?>" method="POST">
				<table width="75%" border="0" cellspacing="5" align="center">
				  <tr>
					<td width="15%" scope="col">Reported By : </td>
					<td width="77%" 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>
				  </tr>
				  <tr>
					<td>Error Severity : </td>
					<td>
					<select name="error_severity">
					<option value="low">Low</option>
					<option value="medium" selected="selected">Medium</option>
					<option value="high">High</option>
					</select>    </td>
				  </tr>
				  <tr>
					<td>Page URL : </td>
					<td><input type="text" name="page_url" size="75"/><b>  (e.g http://www.torontoharbour.com/test.php)</b></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($row=mysql_fetch_array($result))
							{
								if(strtolower($_SESSION['username'])==strtolower($row['name']))echo "<option value='".$row['email']."' selected>".$row['name']."</option>\n";
								else echo "<option value='".$row['email']."'>".$row['name']."</option>\n";
							}		
						?>
						</select>
					</td>
				  </tr>
				  <tr>
					<td>Error Message : </td>
					<td><textarea name="error_message" rows="10" cols="75"></textarea></td>
				  </tr>
				  <tr>
					<td>Comments : </td>
					<td><textarea name="reporter_comments" rows="5" cols="75"></textarea></td>
				  </tr>  
				  <tr>
					<td colspan="2" align="center" height="60" valign="bottom"><input type="submit" name="add_error" value="Submit" /></td>
				  </tr>
				</table>
				</form>
				</body>
				</html>
				<?
			}
/******************************************************************************************************************
-Main function of the class.
/******************************************************************************************************************/
		function MainFunction()
			{
				$this->ProcessForm();
				$this->DisplayForm();	
			}
		}
		
$add_errors=new AddError();
$add_errors->MainFunction();
Return current item: Error Management