<?php
	include('/var/www/html/uclit/protected/common/login/check.php');
	include('/var/www/html/uclit/protected/common/css_login/css_head2.php');
	include('/var/www/html/uclit/protected/connections/db_comments.php');

// Establish Database Connection

/*	$dbserver = 'libitdb.lang.uc.edu';
	$dbuser = 'phpadmin';
	$dbpass = '25or624';
	$sqlConn = mysql_connect($dbserver, $dbuser, $dbpass) or die("Couldn't connect to database");
*/	

// FORM DATA
$lib = $_POST['lib'];
$year = $_POST['year'];
$month = $_POST['month'];
$day = $_POST['day'];
$name = $_POST['name'];
$email = $_POST['email'];
$emailcheck = $_POST['emailcheck'];
$who = $_POST['who'];
$ctype = $_POST['ctype'];
$general = $_POST['general'];

// FORMATED FORM DATA
$visit_date = "$year-$month-$day";


/* echo "lib: $lib <br>";
echo "year: $year <br>";
echo "month: $month <br>";
echo "day: $day <br>";
echo "visit date: $visit_date <br>";
echo "name: $name <br>";
echo "email: $email <br>";
echo "emailcheck: $emailcheck <br>";
echo "who: $who <br>";
echo "features: $features <br>";
echo "improve: $improve <br>";
echo "general: $general <br>";
*/

$now = date("Y-m-d");

//echo"$now";

$dbemail = mysql_select_db("uclit_db", $commentsConn) or die("Couldn't select database");


//echo $sql;
$deptquery_name = "Select departments.dept_id, departments.dept_name, departments.dept_head_id, personnel.personnel_id, personnel.e_mail
From departments Inner Join personnel ON personnel.personnel_id = departments.dept_head_id
Where departments.dept_id = '$lib'";

			$deptsql_result = mysql_query($deptquery_name, $commentsConn) or die("Couldn't execute query. $query_name");
			while ($row = mysql_fetch_array($deptsql_result))
			{
				$dept_head_email = $row['e_mail'];
				$dept_head_id = $row['dept_head_id'];
			}
	//echo"$deptquery_name";
		
?>
    <td width=490 valign="top"> <h2>Help call successfully added to log</h2>
      <hr> 
<?php

				$mail_to = $dept_head_email;
				
					
					
			$mail_subj = "Library Technology Services (Comment Card Submitted)";
			$mail_text = "The following comment has been submitted on now():\n$general\n\nPlease log into the application system and assign the comment card.  \n\nhttp://ul.uc.edu/uclit/protected/common/login/login.php\nThanks a lot!\n\nLibrary Technology Services.";
			$mail_header = "From: libhelp@uc.edu\r\n";
			$mail_header .= "X-Mailer: server\r\n";
			$mail_header .= "Reply To: libhelp@uc.edu\r\n";
			$sendmail_param = "libhelp@uc.edu";
			//mail("$mail_to","$mail_subj","$mail_text","$mail_header","-f$sendmail_param");

$dbConn = mysql_select_db("comments", $commentsConn) or die("Couldn't select database");

$sql = "
		INSERT into comments (lib, visit_date, comment_date, name, email, assigned_personnel, email_check, rating, patron_type, comment_type, status, comment)
		VALUES ('$lib', '$visit_date', '$now', '$name', '$email', '$dept_head_id','$emailcheck', '3', '$who', '$ctype','3', '$general')";

//echo"$sql";

$result = @mysql_query($sql);


// MAIN OUTPUT
//header
		echo "<br />Thank you for your comment!";
		
echo "<br /><br />visit date: $visit_date <br>";
echo "name: $name <br>";
echo "email: $email <br>";
echo "who: $who <br>";
echo "Comment: $general <br> <br /> <a href='http://ul.uc.edu/uclit/protected/general/comments/enter.php'>Add another Comment</a>";

//footer
	include('/var/www/html/uclit/protected/common/css_login/css_foot2.php');
?>  