<?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_equip.php');
		    
	if(!isset($_POST['uaction']))
	{
		//page was not called from another page
		header("Location: http://ul.uc.edu/uclit/protected/equipment/show_allmonitor.php");
		echo "<a href='http://ul.uc.edu/uclit/protected/equipment/show_allmonitor.php'>View All Monitors</a>";
		exit;    	
	}
	else 
	{
		//format date 2003-05-06 13:20:59
		$datetimenow = date('Y-m-d')." ".strftime("%H:%M:%S");
		
		$monitor_make = $_POST['monitor_make'];
		$monitor_model = $_POST['monitor_model'];
		$monitor_serial = $_POST['mon_serial'];
		$monitor_uc = $_POST['monitor_uc_property_num'];
		$monitor_lock_key = $_POST['monitor_lock_key'];
		$monitor_size = $_POST['monitor_size'];
		$monitor_type = $_POST['monitor_type'];
		
		//select database to be used equipment database
		$db = mysql_select_db('equipment', $equipConn) or die ("Unable to select equipment database.");
	
		if($_POST['uaction'] == 'edit')
		{
			//sql statement to track user activity		    
			$sql_viewed = "VIEWED  monitor_make='$monitor_make',  monitor_model='$monitor_model',  monitor_serial='$monitor_serial',  monitor_uc_property_num='$monitor_uc',  monitor_lock_key='$monitor_lock_key',  monitor_size='$monitor_size' ";
			
			//update sql statement
			$sql = "UPDATE monitors SET monitor_make='$monitor_make',  monitor_model='$monitor_model', monitor_type='$monitor_type', monitor_uc_property_num='$monitor_uc',  monitor_lock_key='$monitor_lock_key',  monitor_size='$monitor_size' WHERE monitor_serial='$monitor_serial'  ";
			
			//exercute sql statement
			$sql_result = mysql_query($sql, $equipConn) or die ("Couldn't exercute query<p>$sql</p>");
			
			if(!mysql_errno())
			{
				//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 = "Monitor_Serial[ '$monitor_serial' ] has been successfully updated.";
			}
		}
		elseif($_POST['uaction'] == 'delete')
		{
			$sql = "DELETE FROM monitors WHERE monitor_serial='$monitor_serial'";
			
			$sql_result = mysql_query($sql, $equiConn) or die ("Couldn't execute query:<p>$sql</P>");
			if(!mysql_errno())
			{
				//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 = "Monitor_Serial[ '$monitor_serial' ] has been successfully deleted.";
			}
		}
	}
	echo "<h2><i>$h2</i></h2>
			<a href='http://ul.uc.edu/uclit/protected/itstaff/show_allmonitor.php'>View All Monitors</a>";

 	echo "<div align='bottom' id='footer'>";
 	$last_modified = filemtime("process_monitorud.php");
 	print("Last Modified ");
 	print(date("m/j/y", $last_modified));
 	echo "</div>";
	include('/var/www/html/uclit/protected/common/css_login/css_foot2.php'); 
?>