<?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>");
	
	//select statement 
	$sql = "SELECT brand_printer FROM printer_manufacturer ORDER BY brand_printer";
	$result = mysql_query($sql, $equipConn) or die ("<p>Unable to perform the following query<br><br>$sql</br></br></p>");
	
	if(!$_GET['printer_serial'])
	{
		$printer_serial = '';
		$printer_name = '';
		$printer_server = '';
		$printer_make = '';
		$printer_model = '';
		$printer_uc = '';
	}
	else //Page is being called from edit or delete
	{
		$printer_serial = $_GET['printer_serial'];
		$uaction = $_GET['uaction'];
		$sql = "SELECT * FROM printers WHERE printer_serial='$printer_serial'";
			
		$printer_result = mysql_query($sql, $equipConn) or die ("Unable to exercute query: <p>$sql</p>");
		
		while($row = mysql_fetch_array($printer_result))
		{
			$printer_serial = $row['printer_serial'];
			$printer_name = $row['printer_name'];
			$printer_server = $row['printer_server'];
			$printer_make = $row['printer_make'];
			$printer_model = $row['printer_model'];
			$printer_uc = $row['printer_uc_property_num'];

		}//end while
		
	}	
	
	if($uaction == '')
	{
		$h3 = 'Add a Printer';
		$goto = 'process_printer_add.php';
		$buttonvalue = 'Add this Printer';
	}
	elseif ($uaction == 'edit')
	{
		$h3 = "Update Record[ '$printer_serial' ] from Printers";
		$goto = 'process_printerud.php';
		$buttonvalue = 'Update Printer';
	}
	elseif ($uaction == 'delete')
	{
		$h3 = "Delete Current Record[ '$printer_serial' ] from Printers?";
		$goto = 'process_printerud.php';
		$buttonvalue = 'Delete Printer';
	}
	echo"
<h2>$h3</h2>
<font color='red'>*</font><font size='-1'>- Indicates required fields</font>
<form action='$goto' method='post' name='printer_form' onSubmit='return validator();'>
<table border='0' cellspacing='3' cellpadding='1'>";

	if($uaction == "")
	{
		echo"
		<tr>
		  <td align='right'>Printer Serial:&nbsp;&nbsp;</td>
		<td><input name='tf_printer_serial' type='text' id='tf_printer_serial' size='30' maxlength='30' value='$printer_serial'><font color='red'>*</font>
		  </td>
		</tr>";
	}
	else
	{
		echo "
	  <tr>
		  <td align='right'>Printer Serial:&nbsp;&nbsp;</td>
		<td><input name='tf_printer_serial' type='text' id='tf_printer_serial' size='30' maxlength='30' value='$printer_serial' disabled='true'><font color='red'>*</font>
		  </td>
	  </tr>";  	
  	}
  	echo"
  <tr>
    <td align='right'>Printer Name:&nbsp;&nbsp;</td>
    <td><input name='tf_printer_name' type='text' id='tf_printer_name' size='30' maxlength='30' value='$printer_name'><font color='red'>*</font></td>
  </tr>
    <tr>
    <td align='right'>Printer Server:&nbsp;&nbsp;</td>
    <td><input name='tf_printer_server' type='text' id='tf_printer_server' size='30' maxlength='30' value='$printer_server'></td>
  </tr>
  <tr>
    <td align='right'>Printer Make:&nbsp;&nbsp;</td>
    <td><select name='printer_make'>
			<option value='$printer_make' selected>$printer_make</option>";
	
	while ($row = @mysql_fetch_array($result)) 
	{
		$brand_printer = $row['brand_printer'];
		echo "\n<option value='$brand_printer'>$brand_printer</option>";
	}
	
echo"
        </select><font color=red>*</font></td>
  </tr>
  <tr>
    <td align='right'>Printer Model:&nbsp;&nbsp;</td>
    <td><input name='tf_printer_model' type='text' id='tf_printer_model' size='30' maxlength='30' value='$printer_model'><font color='red'>*</font></td>
  </tr>
  <tr>
    <td align='right'>UC Property Number:&nbsp;&nbsp;</td>
    <td><input name='tf_printer_uc_property_num' type='text' id='tf_printer_uc_property_num' size='30' maxlength='30' value='$printer_uc'></td>
  </tr>
  <tr>
      <td align='right'><input name='prntr_serial' type='hidden' value='$printer_serial'></td>
      <td><input name='uaction' type='hidden' value='$uaction'></td>
  </tr>
  <tr>
      <td colspan='2' align='center'>
	  <input type='submit' name='Submit' value='$buttonvalue'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
	 
	  </td>
  </tr>
    <tr>
      <td colspan='2'align='center'><br><a href='http://ul.uc.edu/uclit/protected/itstaff/show_allprinter.php'>List All Printers</a></td>
  </tr>
</table>
</form>";
?>
<script language='javascript'>

function validator()
{
	var noErrors;
	var msgError = 'Please enter data in the following fields\\n\\n';
	var obj = document.printer_form;

	//required fields are filled in
	if (obj.tf_printer_serial.value != '' && obj.tf_printer_name.value != '' && obj.printer_make.value != '' && obj.tf_printer_model.value != '')
	{
		return (true);
	}
	else //required field is empty
	{
		noErrors = false;		

		if(obj.tf_printer_serial.value == '')
		{
			msgError += ''Printer serial' field\\n';
			obj.tf_printer_serial.focus();
		}
		if(obj.tf_printer_name.value == '')
		{
			msgError += ''Printer name' field\\n';
			if(obj.tf_printer_serial.value != '')
				obj.tf_printer_name.focus();
		}
		if(obj.printer_make.value == '')
		{
			msgError += ''Printer make' list\\n';
			if(obj.tf_printer_name.value != '')
				obj.printer_make.focus();
		}
		if(obj.tf_printer_model.value == '')
		{
			msgError += ''Printer model' field\\n';
			if(obj.printer_make.value != '' )
				obj.tf_printer_model.focus();
		}

		//errors found
		if(!noErrors)
		{
			alert(msgError);
			msgError = 'Please enter data in the following fields\\n\\n';
			return (noErrors);
		}
	}
}//end function
</script>

<?php
	include('/var/www/html/uclit/protected/common/css_login/css_foot2.php'); 
?>