<?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');
	
	$query2 = "SELECT dept_name FROM departments ORDER BY dept_name" ;
	$db = mysql_select_db('uclit_db', $uclit_dbConn) or die ("Unable to select uclit_db database.");
	$sql_result2 = mysql_query($query2, $uclit_dbConn) or die("Couldn't execute query. <p>$query2</p>");
	
	if(!$_GET['monitor_serial'])
	{
		$monitor_make = '';
		$monitor_model = '';
		$monitor_serial = '';
		$monitor_uc = '';
		$monitor_lock_key = '';
		$monitor_size = '';
		$monitor_type = '';
	}
	else //Page is being called from edit or delete
	{
		$db = mysql_select_db('equipment', $equipConn) or die ("Unable to select equipment database.");
		$monitor_serial = $_GET['monitor_serial'];
		$uaction = $_GET['uaction'];
		$dbtablemon = 'monitors';
		$sql = "SELECT * FROM monitors WHERE monitor_serial='$monitor_serial'";
			
		$vdj_result = mysql_query($sql, $equipConn) or die ("Unable to exercute query: <p>$sql</p>");
		
		while($row = mysql_fetch_array($vdj_result))
		{
			$monitor_make = strtoupper($row['monitor_make']);
			$monitor_model = $row['monitor_model'];
			$monitor_serial = strtoupper($row['monitor_serial']);
			$monitor_uc = strtoupper($row['monitor_uc_property_num']);
			$monitor_lock_key = strtoupper($row['monitor_lock_key']);
			$monitor_size = $row['monitor_size'];
			$monitor_type = $row['monitor_type'];
		}
	}	

	if($uaction == '')
	{
		$h3 = 'Add a Monitor';
		$goto = 'process_monitor_add.php';
		$buttonvalue = 'Add this monitor';
	}
	elseif ($uaction == 'edit')
	{
		$h3 = "Update Record[ '$monitor_serial' ] from Monitors";
		$goto = 'process_monitorud.php';
		$buttonvalue = 'Update Monitor';
	}
	elseif ($uaction == 'delete')
	{
		$h3 = "Delete Current Record[ '$monitor_serial' ] from Monitors?";
		$goto = 'process_monitorud.php';
		$buttonvalue = 'Delete Monitor';
	}	

	echo"<h2>$h3</h2>
<font color='red'>*</font><font size='-1'>- Indicates required fields</font>
<form action='$goto' method='post' name='monitor_form' onSubmit='return validator();'>
<table border='0' cellspacing='3' cellpadding='1'>
  <tr>
      <td align='right'>Monitor Make:&nbsp;&nbsp;</td>
    <td>
		<select name='monitor_make'>";
	if (empty($uaction))
		echo "<option value=''>Select ....</option>";

	$db = mysql_select_db('equipment', $equipConn) or die ("Unable to select equipment database.");
	$sql_mbrand = "SELECT mbrand FROM monitor_brand ORDER BY mbrand";
	$mbrand_result = mysql_query($sql_mbrand, $equipConn) or die ("Unable to exercute query. <p>$sql_mbrand</p>");
	
	while($row = mysql_fetch_array($mbrand_result))
	{
	
	$BrandName = strtoupper($row['mbrand']);
	
	if ($monitor_make == $BrandName)
		echo "\\n<option value='$BrandName' selected>$BrandName</option>";
	else 
		echo "\\n<option value='$BrandName'>$BrandName</option>";
	}
echo "
        </select><font color='red'>*</font>
      </td>
  </tr>
  <tr>
    <td align='right'>Monitor Model:&nbsp;&nbsp;</td>
    <td><input name='monitor_model' type='text' id='monitor_model' size='30' maxlength='30' value='$monitor_model'><font color='red'>*</font></td>
  </tr>
    <tr>
    <td align='right'>Monitor Size:&nbsp;&nbsp;</td>
    <td><select name='monitor_size'>
		<option value='$monitor_size' selected>$monitor_size</option>
						<option value='14inch'>14inch</option>
						<option value='15inch'>15inch</option>
						<option value='17inch'>17inch</option>
						<option value='18inch'>18inch</option>
						<option value='19inch'>19inch</option>
						<option value='20inch'>20inch</option>
						<option value='21inch'>21inch</option>
						<option value='22inch'>22inch</option>
						<option value='24inch'>24inch</option>
						<option value='29inch'>29inch</option>
						<option value='34inch'>34inch</option>
				    </select><font color='red'>*</font></td>
  </tr>
  
   <tr>
    <td align='right'>Monitor Type:&nbsp;&nbsp;</td>
    <td><select name='monitor_type'>
		<option value='$monitor_size' selected>$monitor_type</option>
						<option value='ALL-IN-ONE'>ALL-IN-ONE</option>
						<option value='LCD'>LCD</option>
						<option value='CRT'>CRT</option>
						<option value='LAPTOP'>LAPTOP</option>
						<option value='WIDESCREEN'>WIDESCREEN</option>
						
				    </select><font color='red'>*</font></td>
  </tr>";

	if(!isset($uaction) || $uaction == "" || $uaction == null)
	{
	echo "
  <tr>
    <td align='right'>Monitor Serial:&nbsp;&nbsp;</td>
    <td><input name='monitor_serial' type='text' id='monitor_serial' size='30' maxlength='30' value='$monitor_serial'><font color='red'>*</font></td>
  </tr>";
	}
	else 
	{
	echo "
  <tr>
    <td align='right'>Monitor Serial:&nbsp;&nbsp;</td>
    <td><input name='monitor_serial' type='text' id='monitor_serial' size='30' maxlength='30' value='$monitor_serial'  disabled='true'><font color='red'>*</font></td>
  </tr>";		
	}
    
    echo"
  <tr>
    <td align='right'>UC Property Number:&nbsp;&nbsp;</td>
    <td><input name='monitor_uc_property_num' type='text' id='monitor_uc_property_num' size='30' maxlength='30' value='$monitor_uc'></td>
  </tr>
  <tr>
    <td align='right'>Monitor Lock Key:&nbsp;&nbsp;</td>
    <td><input name='monitor_lock_key' type='text' id='monitor_lock_key' size='30' maxlength='30' value='$monitor_lock_key'></td>
  </tr>
  <tr>
      <td align='right'><input name='mon_serial' type='hidden' value='$monitor_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/itcoordinator/show_allmonitor.php'>List All Monitors</a>
      </td>
  </tr>
</table>
</form>";
	include('/var/www/html/uclit/protected/common/css_login/css_foot2.php'); 
?>
<script language='javascript'>

function validator()
{
	var noErrors;
	var msgError = 'Please enter data in the following fields\\n';
	var obj = document.monitor_form;
	
	if (obj.monitor_make.value != '' && obj.monitor_model.value != ''
		&& obj.monitor_size.value != '' && obj.monitor_serial.value != '')
	{
		return (true);
	}
	else //
	{
		//required fields is empty
		noErrors = false;

		if(obj.monitor_make.value == '')
		{
			obj.monitor_make.focus();
			msgError += ''Monitor make' field\\n';
		}
		if(obj.monitor_model.value == '')
		{
    		if(obj.monitor_make.value != '')
				obj.monitor_model.focus();
			msgError += ''Monitor model' field\\n';
		}
		if(obj.monitor_size.value == '')
		{
    		if(obj.monitor_model.value != '')
				obj.monitor_size.focus();
			msgError += ''Monitor size' list\\n';
		}
		if(obj.monitor_serial.value == '')
		{
    		if(obj.monitor_size.value != '')
				obj.monitor_serial.focus();
			msgError += ''Monitor serial number' field\\n';
		}
		if(obj.monitor_type.value == '')
		{
    		if(obj.monitor_type.value != '')
				obj.monitor_type.focus();
			msgError += ''Monitor Type' field\\n';
		}

		//errors found
		if(!noErrors)
		{
			alert(msgError);
			return (noErrors);
		}
	}
}//end function
</script>