<?php
	
	//@ob_start();

	$dbserver = 'libitdb.lang.uc.edu';
	$dbuser = 'phpadmin';
	$dbpass = '25or624';
	// Create our database connection
	$sqlConn = mysql_connect($dbserver, $dbuser, $dbpass) or die("Couldn't connect to database");

//QUERY Drop Down List Data

// USE equipment database
	$dbequipt = 'equipment';
	$db = @mysql_select_db($dbequipt, $sqlConn) or die ("Unable to select $dbequipt database.");

//Personnel Names
	$sql_personnel = "SELECT personnel_id, last_name, first_name, middle_name FROM personnel ORDER BY last_name";
	$employee_result = @mysql_query($sql_personnel, $sqlConn) or die ("Unable to query: $sql_personnel");


//USE arlstats database
	$dbmat = mysql_select_db("arlstats", $sqlConn) or die("Couldn't select database");

//Material Types
	$sql_material = "SELECT MID, Name FROM Material_Types ORDER BY Name";
	$material_result = @mysql_query($sql_material, $sqlConn) or die ("Unable to query: $sql_material");

//Calendar
	$sql_calendar = "SELECT * FROM Calendar ORDER BY Month";
	$calendar_result = @mysql_query($sql_calendar, $sqlConn) or die ("Unable to query: $sql_calendar");
	
//Locations
	function location_query()
	{
	global $sqlConn;
	global $location_result;
	
	 $sql_location = "SELECT * from Location";
	 $location_result = @mysql_query($sql_location, $sqlConn) or die ("unable to query: $sql_location");
	}
	location_query();
	
// Catalog Types
	function catalog_query() 
	{
	global $sqlConn;
	global $catalog_result;
	
	  $sql_location = "SELECT * from Catalog_Types";
	  $catalog_result = @mysql_query($sql_location, $sqlConn) or die ("unable to query: $sql_location");
    }
	catalog_query();
	
//// Begin HTML HEADER output
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
	<title>Data Entry</title>
</head>
<body>
<?php//Begin HTML BODY output?>

<form action="do_proc3_save.php" METHOD=POST>

<?php// Month?>

<select name="month" disabled>
<?php
	while($cal_row = @mysql_fetch_array($calendar_result))
		{	
		$selected_month = "";
		$qid = $cal_row['QID'];
		$qname = $cal_row['Month']; 
		echo "qid: $qid";
		$qid_post = $_POST['month'];
		if ("$qid_post" == "$qid") { $selected_month = "selected"; }
		echo "<option value=\"$qid\" $selected_month>$qname</option>";
		
		}
?>
</select>
<input name="month" type="hidden" value="<?php echo $_POST['month'];?>" size="5">



<?php// Name?>
<select name="employee" disabled>
<?php
//personnel_id, last_name, first_name,

	//$personnel_id_post = $_POST['employee'];
	while($row = @mysql_fetch_array($employee_result))
		{	
		$selected_personnel = "";
		$personnel_id = $row['personnel_id'];
		$last_name = $row['last_name'];
		$first_name = $row['first_name'];
		$middle_name = $row['middle_name'];
		$personnel_id_post = $_POST['employee'];
		if ("$personnel_id_post" == "$personnel_id") {$selected_personnel = "selected"; }
		echo "<option value=\"$personnel_id\" $selected_personnel>$last_name, $first_name</option>";
		
		}
?>
</select>
<input name="employee" type="hidden" value="<?php echo $_POST['employee'];?>" size="5">


<?php// Material?>
<select name="material" disabled>
<?php
	while($row = @mysql_fetch_array($material_result))
		{	
		$selected_material = "";
		$mid = $row['MID'];
		$mname = $row['Name']; 
		$mid_post = $_POST['material'];
		if ("$mid_post" == "$mid") { $selected_material = "selected"; }
		echo "<option value=\"$mid\" $selected_material>$mname</option>";
		
		}
?>
</select>
<input name="material" type="hidden" value="<?php echo $_POST['material'];?>" size="5">
<p>
<br>
<?php 
echo "Verify Values Below, then press 'Save Changes'";
?>
&nbsp;
</p>



<?php// Catalog Type - Location Table?>

  <table width='90%' border='1' cellpadding='1'>
    <tr> 
	<td width='15%'>&nbsp;</td>
	<?php //table header
	  while($row = @mysql_fetch_array($catalog_result))
      {
	   $name = $row['Name'];
	  ?>
      <td width='12%'><?php echo $name ?></td>
<?php } 
catalog_query();  //rebuild catalog query row
?>
    </tr>
	
	<?php //outer loop for each row of the table
	while($row = @mysql_fetch_array($location_result))
	{
	  $lid = $row['LID'];
	  $location_name = $row['Name'];
	  $location_description = $row['Description'];
	?>
    <tr> 
      <td><?php echo $location_name ?></td>
	  
	  <?php //inner loop for each column of the row
	  while($row2 = @mysql_fetch_array($catalog_result))
	   {
	   	//echo "boola";
	    $cid=$row2['CID'];
		$input=$location_name;
		//$input=$lid;
		$input.=$cid;
	  	?>
	  	<td><input name="<?php echo $input;?>" type="hidden" value="<?php echo $_POST[$location_name.$cid];?>" size="5">
		<?php echo $_POST[$location_name.$cid];?></td>
	  	<?php 
	  	
	  }?>
    </tr>
	<?php 
	catalog_query();
	}?>
	
</table>	
	<input type="submit" name="Submit" value="Save Changes">
	</form>
<p>
<?php

?>
&nbsp;</p>

<?php//END HTML BODY?>




</body>
</html>
