<?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');

	// Create our database connection
	$db = mysql_select_db('equipment', $equipConn) or die ("Unable to select equipment database.");
	
	global $voice_jack, $dbTable;

	if(isset($_POST['voice_jack']))
	{
		//format date 2003-05-06 13:20:59
		$datetimenow = date('Y-m-d')." ".strftime("%H:%M:%S");
		
		$voice_jack = strtoupper($_POST['voice_jack']);
		$department = $_POST['department'];
		$room_jack = strtoupper($_POST['room_jack']);
		$account = $_POST['account'];
		$notes = $_POST['notes_jack'];
		$bldg = $_POST['building'];
		$active =$_POST['active_sel'];
		$phone =$_POST['phone_num'];	
		
		if (!isset($_POST['room_jack']) || $_POST['room_jack'] == "")
			$room_jack = 'N/A';

		$dbTable = 'voice_jacks';
	
		$sql = "INSERT INTO voice_jacks (jack_id, department, voice_jack, room_jack, extension, building, notes, active, account, phone_num) VALUES ('',  '$department', '$voice_jack', '$room_jack','', '$bldg', '$notes', '$active', '$account', '$phone');";

		function error($voice_jack, $data_jacks)
		{
			if (mysql_errno() == 1062)
			{
				die("<p><b>".mysql_error()."</b></p><font color=red>'$data_jack' already exist in the data_jacks table.</font>");
				exit();
			}	
		}
		
		if(!($tResult = @mysql_query($sql, $equipConn)))
		{	
			error($data_jack, $dbTable);
		}
		//no errors log user access
		$sql_useraccess = "INSERT INTO EquipmentUserAccessLog VALUES ('', '$suser', '$sql', '$datetimenow')";
		//log user access
		mysql_query($sql_useraccess, $equipConn);		
		
		echo "
				<h3><i>Add a Voice - Voice Added</i></h3>
				<table cellspacing='3' cellpadding='3'>
			     <tr>		
				  <td valign=top><P><strong>Voice Jack#:</strong><br>$voice_jack</br></td>
				 </tr>
				 <tr>
				  <td valign=top><strong>Department:</strong><BR>$department</br></td>
				 </tr>
				 <tr>
				  <td valign=top><strong>Room Jack#:</strong><br>$room_jack</br></td>
				 </tr>
				 <tr>
				  <td valign=top><strong>Building:</strong><br>$bldg</br></td>
				 </tr>
				 <tr>
				  <td valign=top><strong>Notes:</strong><br>$notes</br></td>
				 </tr>
				 <tr>
				  <td valign=top><strong>Account#:</strong><br>$account</br></td>
				 </tr>
				<tr>
				  <td valign=top><strong>Phone Number:</strong><br>$phone</br></td>
				 </tr>

				
				</table>
  			    <p><a href='./show_addvjack.php'>Add Another Voice Jack</a></p></td>";
	}
	include('/var/www/html/uclit/protected/common/css_login/css_foot2.php');
?>