<table width="200" border="0" align="center">
  <tr>
    <td><a href="http://ul.uc.edu/uclit/teaming/equipment/add_home.php"><img src="addequip.jpg" alt="Add" width="120" height="50" border="0" /></a></td>
    <td><a href="http://ul.uc.edu/uclit/teaming/equipment/sel_allequiptdetail.php"><img src="equipbydept.jpg" alt="dept" width="120" height="50" border="0" /></a></td>
    <td><a href="http://ul.uc.edu/uclit/teaming/equipment/show_move.php"><img src="searchequip.jpg" alt="search" width="120" height="50" border="0" /></a></td>
    <td><a href="http://ul.uc.edu/uclit/teaming/equipment/show_assignequipt.php"><img src="Assign.jpg" alt="assign" width="120" height="50" border="0" /></a></td>
    <td><a href="http://ul.uc.edu/uclit/teaming/equipment/printmon.php"><img src="printmon.jpg" alt="print" width="120" height="50" border="0" /></a></td>
  </tr>
</table>
<?php
	include('/var/www/html/uclit/protected/connections/db_equip.php');

	//format date 2003-05-06 13:20:59
	$datetimenow = date('Y-m-d')." ".strftime("%H:%M:%S");
		
	$dbname = 'equipment';
	$dbtable = 'personnel';
	$dbtable2 = 'departments';
	
	if(!isset($_POST['uaction']))
	{
		//page was not called from another page
		header("Location: http://ul.uc.edu/uclit/protected/itstaff/show_allemployee.php");
		echo "<a href='http://ul.uc.edu/uclit/protected/itstaff/show_allemployee.php'>View All Employees</a>";
		exit;    	
	}
	else 
	{
		$pid = $_POST['hpid'];			
		$lname = $_POST['lname'];
		$fname = $_POST['fname'];
		$title = $_POST['title'];
		$idnum = $_POST['id_num'];
		
		if($_POST['mname'] == null || $_POST['mname'] == "" || !isset($_POST['mname']))
			$mname = '*';
		else 
			$mname = strtoupper($_POST['mname']);	
		
		$dept_id = $_POST['department'];
		
		//select database to be used equipment database
		$db = mysql_select_db('uclit_db', $uclit_dbConn) or die ("Unable to select uclit_db database.");
		
		//SQL statement to select mail_location of matched dept_id
		$sql_dept = "SELECT mail_location FROM departments WHERE dept_id='$dept_id'";
		
		//Query sql statement
		$dept_result = mysql_query($sql_dept, $uclit_dbConn) or die ("Unable to exercute query:<p>$sql_dept</p>");

		if(isset($mail_location))
		{
			$mail_location = $_POST['mail_location'];
		}
		else 
		{
			while($row = mysql_fetch_array($dept_result))
			{
				$did = $row['mail_location'];
			}
			
			if (!isset($did) || $did == '' || $did == null)
			{
				$mail_location = '*';
			}
			else
			{
				$mail_location = $did;
			}
		}
		
		
		$email = $_POST['email'];
		if ($email != '' && $email != 'No E-Mail')
		{
			if (!eregi('^[a-zA-Z0-9._-]+@[a-zA-Z0-9._-]+\.([a-zA-Z]{2,4})$', $email)) 
			{
				echo "Invalid E-Mail";	
				exit;
			}
		}
		else 
			$email = 'No E-Mail';
			
		$phone = $_POST['phone'];
		if($phone == '')
			$phone = '*';
		
		$fax = $_POST['fax'];
		if($fax == '')
			$fax = '*';
			
		$web_role = $_POST['web_role'];
		if($web_role == '')
			$web_role = '*';


		if($_POST['uaction'] == 'edit')
	{
		//sql statement to track user activity		    
			$sql_viewed = "VIEWED    personnel_id='$pid',  lname='$lname',  fname='$fname',  mname='$mname',  dept_id='$dept_id',  email='$email', phone='$phone', web_role='$web_role', title='$title', ID_Num='$idnum'  ";
			
			//update sql statement
			$sql = "UPDATE personnel SET last_name='$lname', first_name='$fname', middle_name='$mname',  dept_id='$dept_id',  e_mail='$email', phone='$phone', web_role='$web_role', title='$title', ID_Num='$idnum' WHERE personnel_id='$pid' ";
			
			//exercute sql statement
			$sql_result = mysql_query($sql, $uclit_dbConn) or die ("Couldn't exercute query<p>$sql</p>");
			
			if(!mysql_errno())
			{
				$db = mysql_select_db('equipment', $equipConn) or die ("Unable to select equipment database.");
				//log user access
				$sql_useraccess = "INSERT INTO EquipmentUserAccessLog VALUES ('', '$suser', '$sql_viewed', '$datetimenow')";
				mysql_query($sql_useraccess, $equipConn);
				$sql_useraccess = "INSERT INTO EquipmentUserAccessLog VALUES ('', '$suser', '$sql', '$datetimenow')";
				mysql_query($sql_useraccess, $equipConn);
				
				$h2 = "Personnel ID[ '$pid' ] has been successfully updated.";
			}
			
		}
		elseif($_POST['uaction'] == 'delete')
		{
			$sql = "DELETE FROM personnel WHERE personnel_id='$pid'";
			$sql_viewed = "VIEWED    personnel_id='$pid',  lname='$lname',  fname='$fname',  mname='$mname',  dept_id='$dept_id',  mail_location='$mail_location', email='$email', phone='$phone', fax='$fax', web_role='$web_role'  ";
			$db = mysql_select_db('uclit_db', $uclit_dbConn) or die ("Unable to select uclit_db database.");
			$sql_result = mysql_query($sql, $uclit_dbConn) or die ("Couldn't execute query:<p>$sql</P>");
			if(!mysql_errno())
			{
				//log user access
				$db = mysql_select_db('equipment', $equipConn) or die ("Unable to select equipment database.");
				$sql_useraccess = "INSERT INTO EquipmentUserAccessLog VALUES ('', '$suser', '$sql_viewed', '$datetimenow')";
				@mysql_query($sql_useraccess, $equipConn);
				$sql_useraccess = "INSERT INTO EquipmentUserAccessLog VALUES ('', '$suser', '$sql', '$datetimenow')";
				@mysql_query($sql_useraccess, $equipConn);
				
				$h2 = "Personnel ID[ '$pid' ] has been successfully deleted.";
			}//end if for mysql_errno()
			
		}
	}
	echo "
    <h2><i>$h2</i></h2>
	
	<br><br><br><br><br><br><br><br>
    <div align='bottom' class='footer'>";
     $last_modified = filemtime("process_employeeud.php");
     print("Last Modified ");
     print(date("m/j/y", $last_modified));
     echo "</div>";
?>