<!--includes for all the database connections
edit: Michael Lucas
date: September 2, 2005
purpose:  sent an instant email to the user-->

<!--loads the php code to connect to databases and queries -->

<!--begin html-->
<!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"><!-- InstanceBegin template="/Templates/final_php.dwt.php" codeOutsideHTMLIsLocked="false" -->
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<!--template parameters-->
<!--use this editable area to add an additional style sheet-->

<!-- InstanceBeginEditable name="doctitle" -->
<title>Intranet</title>
<!-- InstanceEndEditable -->
<!-- use the editable area below to add any additional head items-->
<!--code to load css for page and menus-->
<?php require_once('../../../int05c/incs/loadcss.inc'); ?>
<?php require_once('../../../int05c/incs/loadscripts.inc'); ?>
<!--menu hack-->
<!--[if gte IE 5]>
<style>#p7TMnav div a {width: 100%;}</style>
<![endif]-->
<!-- InstanceBeginEditable name="head" --><!-- InstanceEndEditable -->
</head>
<body onload="P7_swapClass(0,'none','open','closed','li')"> 
   <div class="skipLinks">
     skip to: <a href="#content">page content</a> | <a href="/pageNav">links on this page</a> | <a     href="#globalNav">site navigation</a> | <a href="#siteInfo">footer (site information)</a>
   </div>
   <div id="header">
    <?php require_once('../../../int05c/incs/header.htm'); ?> 
   </div>
   <div id="utility">
    <?php require_once('../../../int05c/incs/ut.htm'); ?>
   </div>
   <div id="content"> 
	   <!--left menus-->
	   <div id="pageNav">
	   <?php require_once('../../../int05c/incs/nav3.htm'); ?>
	   </div>  
       <!--main content div--> 
       <div class="story"> 	  <!-- InstanceBeginEditable name="content" -->
<?php	   
	include ('/var/www/html/uclit/protected/connections/db_help.php');
	
	$db = mysql_select_db("uclit_db", $uclit_dbConn) or die("Couldn't select database. uclit_db");
?>
			<table border="0" width="520" cellspacing="0" cellpadding="0" align="left">
  			<!-- begin first row for logo and headline -->
  			<!-- begin blank row to provide exact spacing between first and second rows -->
  			<!-- begin third row for links and content -->
  			<tr> 

    		<!--<h2>Add a computer</h2>-->
<?php
	$help_user_id = $_POST['per'];
	$help_user = $_POST['username'];
	$help_dept = $_POST['help_dept'];
	$help_desc = $_POST['help_desc'];
	$help_phone = $_POST['help_phone'];
	$help_url = $_POST['help_url'];
	$help_email = $_POST['email'];
	$proj_name = $_POST['proj_name'];

	if ($help_dept != "" and $help_user != "" and  $help_desc != "")
	{	
		$help_tech = "";	
		$today=date("Y-m-d");
		
		//get user's name
		if($help_user_id != "")
		{
			$query_name = "Select departments.dept_id, departments.dept_name, departments.dept_head_id, personnel.personnel_id, personnel.last_name, personnel.first_name, personnel.dept_id, personnel.e_mail
From departments Inner Join personnel ON personnel.dept_id = departments.dept_id
WHERE personnel_id = '$help_user_id'";
			$sql_result = mysql_query($query_name, $uclit_dbConn) or die("Couldn't execute query. $query_name");
			$help_user = "";
			while ($row = mysql_fetch_array($sql_result))
			{
				$help_user = $row['first_name'];
				$help_user .= " ";
				$help_user .= $row['last_name'];
				$help_email = $row['e_mail'];
				$dept_head_id = $row['dept_head_id'];
			}
		}
		else
		{
			$help_user = "Student/Other";			
		}
		
		$db = mysql_select_db("helpcalls", $helpConn) or die("Couldn't select helpcalls.");
		if($help_user_id != "")
		{
			$sql = "INSERT INTO log 
				(Help_User, Help_User_ID, Help_Dept, Help_Desc, Date_Arrived, Help_Phone, Help_Url, Stage_1, Email)
				VALUES 
				('$help_user','$help_user_id','$help_dept','$help_desc','$today',
					'$help_phone','$help_url','$stage1','$help_email')";
		}
		else
		{
			$sql = "INSERT INTO log 
				(Help_User, Help_User_ID, Help_Dept, Help_Desc, Date_Arrived, Help_Phone, Help_Url, Stage_1, Email)
				VALUES 
				('$help_user','0','$help_dept','$help_desc','$today',
					'$help_phone','$help_url','$stage1','$help_email')";

		}
		$datetimenow = date('Y-m-d')." ".strftime("%H:%M:%S");
		$help_result = mysql_query($sql, $helpConn) or die("Couldn't execute query. $query_name");
		
	}

?>
    <td width=490 valign="top"> <h2>Help call successfully added to log</h2>
      <hr> 
<?php
				$db2 = mysql_select_db("uclit_db", $uclit_dbConn) or die("Couldn't select database. uclit_db");
				
				$query_dh = "Select personnel.personnel_id, personnel.last_name, personnel.first_name, personnel.e_mail, personnel.dept_id
From personnel WHERE personnel_id = '$dept_head_id'";
			$sql_result2 = mysql_query($query_dh, $uclit_dbConn) or die("Couldn't execute query. $query_dh");
			
			while ($row = mysql_fetch_array($sql_result2))
			{
				$dept_head_email = $row['e_mail'];
				$dept_id = $row['dept_id'];
			}

				$mail_to = $help_email;
				$mail_to .= ",mahoneme@ucmail.uc.edu";
				
				if ($help_email != $dept_head_email)
				{
					$mail_to .= ",";
					$mail_to .= $dept_head_email;
				}		
				
				if ($dept_id == '35')
				{
					$mail_to .= ",bachpl@ucmail.uc.edu, wattsdc@ucmail.uc.edu";
				}
				if ($dept_id == '12')
				{
					$mail_to .= ",alphonzo.early@uc.edu";
				}
				if ($dept_id == '9')
				{
					$mail_to .= ",david.ball@uc.edu, braunlml@ucmail.uc.edu";
				}

				if ($dept_id == '13')
				{
					$mail_to .= ", sara.harper@uc.edu, elizabeth.meyer@uc.edu";
				}

				
				$sentmsgRespondUser = "true";
				$sentmsgRespondHead = "true";
			
			$mail_subj = "Library Technology Services (Help Call Submitted)";
			$mail_text = "The following help call has been submitted on $today:\n$help_desc\n\nSend us an 
				email if you have any questions <libhelp@uc.edu>\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");




	echo "Help User: $help_user<br />
		  Help Department:$help_dept<br />
		  Help Description:$help_desc<br />
		  Help Email:$mail_to<br /><br />";
?>
      <a href="http://ul.uc.edu/departments/libit/help/show_addhelp.php">Add Another Help Call</a> 
    </td>
</table><!-- InstanceEndEditable -->       </div> 
   </div>
   
 <div id="siteInfo"> 
 <?php require_once('../../../int05c/incs/footer.htm'); ?>    
 </div>

</body>
<!-- InstanceEnd --></html>
<!-- clear all queries and free the databases-->

