<?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/itstaff/show_allvj.php");
		echo "<a href='http://ul.uc.edu/uclit/protected/itstaff/show_allvj.php'>View All Phone Jacks</a>";
		exit;    	
	}
	else 
	{
		//format date 2003-05-06 13:20:59
		$datetimenow = date('Y-m-d')." ".strftime("%H:%M:%S");
		
		$jack_id = $_POST['jack_id'];
		$department = $_POST['department'];
		$voice_jack = $_POST['voice_jack'];
		$room_jack = $_POST['room_jack'];
		$uaction = $_POST['uaction'];
		$building = $_POST['building'];
		$notes = $_POST['notes_jack'];
		$account = $_POST['account'];
		$active = $_POST['active_sel'];
		$phone = $_POST['phone_num'];
		
		
		//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 jack_id='$jack_id', department='$department', voice_jack='$voice_jack', room_jack='$room_jack', building='$building', account='$account', notes='$notes', active='$active', phone_num='$phone'"; 		    	
			
			//update sql statement
			$sql = "UPDATE voice_jacks SET department='$department', voice_jack='$voice_jack', room_jack='$room_jack', building='$building', account='$account', notes='$notes', active='$active', phone_num='$phone' WHERE jack_id='$jack_id'" ;		    	
			//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 = "Jack_ID[ '$jack_id' ] has been successfully updated.";
			}
			
		}
		elseif($_POST['uaction'] == 'delete')
		{
			$sql = "UPDATE voice_jacks SET department='$department', voice_jack='$voice_jack', room_jack='$room_jack', building='$building', account='$account', notes='$notes', active='0', phone_num='$phone' WHERE jack_id='$jack_id'" ;	
			$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);
				
				$sql2 = "UPDATE equipment_detail SET voice_id='991' WHERE voice_id='$jack_id'" ;	
				$sql_result2 = 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 = "Jack_ID[ '$jack_id' ] has been successfully deleted.";
				}
			}
		}
	}
	echo "
    <h2><i>$h2</i></h2>
	<a href='http://ul.uc.edu/uclit/protected/itstaff/show_allvj.php'>View All Voice Jacks</a>";
	include('/var/www/html/uclit/protected/common/css_login/css_foot2.php'); 
?>