PHP Code:
<?php session_start();
include ("check_session_user.php");
//connect to database server
$link = mysql_connect("localhost","root","");
//connect to database
$dbconnect = mysql_select_db("supportdb",$link);
//send user input data to database
$result = $_POST['TicketNumber'];
$NameOfRequestor = $_POST['NameOfRequestor'];
$NameOfRequestor = str_replace("'","''",$NameOfRequestor);
$Department = $_POST['Department'];
$Department = str_replace("'","''",$Department);
$ProblemDescription = $_POST['ProblemDescription'];
$ProblemDescription = str_replace("'","''",$ProblemDescription);
$Email = $_POST['Email'];
$Email = str_replace("'","''",$Email);
$Photo = $_FILES['Photo'];
$file_size = $_FILES['Photo']['size'];
if ($file_size > 102400) {
echo "<script>alert('Image size exceeds maximum file size allowed'); history.go(-1);</script>";
exit;
}
if($file_size == "") {
echo "<script>alert('No image found.'); history.go(-1);</script>";
exit;
}
//uploading and resizing image width 300 max
if (isset ($_FILES['Photo'])){
$imagename = $_FILES['Photo']['name'];
$source = $_FILES['Photo']['tmp_name'];
$target = "C:\\wamp\\www\\ITSupportApp\\error_images\\".$imagename;
move_uploaded_file($source, $target);
$imagepath = $imagename;
$save = "C:\\wamp\\www\\ITSupportApp\\error_images\\" . $imagepath; //This is the new file you saving
$file = "C:\\wamp\\www\\ITSupportApp\\error_images\\" . $imagepath; //This is the original file
list($width, $height) = getimagesize($file) ;
//resize if width is more than 300
if($width > 140)
{
$modwidth = 140;
$diff = $width / $modwidth;
$modheight = $height / $diff;
}
else
{
$modwidth = $width;
$modheight = $height;
}
$tn = imagecreatetruecolor($modwidth, $modheight) ;
$image_info = getimagesize($file);
$image_type = $image_info[2];
if( $image_type == IMAGETYPE_JPEG ) {
$image = imagecreatefromjpeg($file) ;
} elseif( $image_type == IMAGETYPE_GIF ) {
$image = imagecreatefromgif($file);
} elseif( $image_type == IMAGETYPE_PNG ) {
$image = imagecreatefrompng($file);
}
imagecopyresampled($tn, $image, 0, 0, 0, 0, $modwidth, $modheight, $width, $height) ;
$save = "C:\\wamp\\www\\ITSupportApp\\error_images\\" . $imagepath; //This is the new file you saving
if( $image_type == IMAGETYPE_JPEG ) {
imagejpeg($tn,$save,100);
} elseif( $image_type == IMAGETYPE_GIF ) {
imagegif($tn,$save);
} elseif( $image_type == IMAGETYPE_PNG ) {
imagepng($tn,$save);
}
chmod($save,0777);
$save = "image/" . $imagepath;
}
else
{ echo('here3');
echo "<script>alert('No image found'); history.go(-1);</script>";
exit;
}
$Status = "Open"; //set 'open' value for Status column
//inserting user's input to the database
$sql = "INSERT INTO reported_problem (TicketNumber, NameOfRequestor, UserID, Department, ProblemDescription, Date, Status, EscalatedTo, Email, Resolution, UpdatedOn, UpdatedBy, ImagePath) VALUES (".$result.",'".$NameOfRequestor."', '".$_SESSION['userID']."', '".$Department."','".$ProblemDescription."',".date('ymd').",'".$Status."','','".$Email."','',000000,'', '".$save."');";
$count = mysql_query($sql,$link) or die(mysql_error()); // excuted sql
if ($count == 1) //check whether the data is inserted to the database or not
{
require_once('C:\php\PHPMailer_v5.1\class.phpmailer.php');
$mail = new PHPMailer();
$mail->IsSMTP();
$mail->Host = 'mail.bsgroup.com.sg';
$mail->Port = 25;
$mail->SMTPAuth = true;
$mail->Username = '***';
$mail->Password = '****';
$mail->From = '*****';
$mail->FromName = $NameOfRequestor;
$mail->Subject = 'Support Request';
$body = "The user has logged a IT support request.<br><br><br> Please click <a href=http://ibmx305/ITsupport/stafflogin.php>here</a> to login and check the request. <br><br><br> ";
$mail->MsgHTML($body);
$mail->AddAddress('potepote20@gmail.com', 'IT Department');
if ($mail->Send()) {
echo "<script>alert('Your request has been sent out successfully. Someone from the IT Department will be contacting you shortly to follow up your request. Thank you.'); history.go(-1); </script>";
}
}
?>
Bookmarks