<?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');
	
	//select a database
	$dbselected = mysql_select_db('equipment', $equipConn) or die ("<p>Unable to select equipment database.</p>");

	//format date 2003-05-06 13:20:59
	$datetimenow = date('Y-m-d')." ".strftime("%H:%M:%S");
	
	if(!isset($_POST['uaction']))
	{
		//page was not called from another page
		header("Location: http://ul.uc.edu/uclit/protected/itstaff/show_allprinter.php");
		echo "<a href='http://ul.uc.edu/uclit/protected/itstaff/show_allprinter.php'>View All Printers</a>";
		exit;    	
	}
	else 
	{
		$printer_serial = strtoupper($_POST['prntr_serial']);			
		$printer_name = strtoupper($_POST['tf_printer_name']);
		$printer_server = strtoupper($_POST['tf_printer_server']);
		$printer_make = $_POST['printer_make'];
		$printer_model = $_POST['tf_printer_model'];
		$printer_uc = strtoupper($_POST['tf_printer_uc_property_num']);
		
		if($_POST['uaction'] == 'edit')
		{
			//sql statement to track user activity		    
			$sql_viewed = "VIEWED  printer_serial='$printer_serial',  printer_name='$printer_name',  printer_server='$printer_server',  printer_make='$printer_make',  printer_model='$printer_model',  printer_uc_property_num='$printer_uc' ";
			
			//update sql statement
			$sql = "UPDATE printers SET printer_name='$printer_name', printer_server='$printer_server', printer_make='$printer_make',  printer_model='$printer_model',  printer_uc_property_num='$printer_uc' WHERE printer_serial='$printer_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 = "printer_serial[ '$printer_serial' ] has been successfully updated.";
			}
		}
		elseif($_POST['uaction'] == 'delete')
		{
			$sql = "DELETE FROM printers WHERE printer_serial='$printer_serial'";
			
			$sql_result = mysql_query($sql, $equipConn) 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 = "printer_serial[ '$printer_serial' ] has been successfully deleted.";
			}//end if for mysql_errno()
		    	
		}
	}
	echo "
    <h2><i>$h2</i></h2>
	<a href='http://ul.uc.edu/uclit/protected/itstaff/show_allprinter.php'>View All Printers</a>

	<br><br><br><br><br><br><br><br>
    <div align='bottom' id='footer'>";
     $last_modified = filemtime("process_printerud.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'); ?>