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

	$loggedinuser = $_SESSION['username'];
	
	//QUERY Drop Down List Data
	
	// USE equipment database
	$db = mysql_select_db('uclit_db', $uclit_dbConn) or die ("Unable to select uclit_db 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, $uclit_dbConn) or die ("Unable to query: $sql_personnel");

	//USE arlstats database
	$db = mysql_select_db('arlstats', $arlConn) or die ("Unable to select arlstats database.");

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

	//Calendar
	$sql_calendar = "SELECT * FROM Calendar ORDER BY Month";
	$calendar_result = @mysql_query($sql_calendar, $arlConn) or die ("Unable to query: $sql_calendar");

	//Stype
	$sql_stype = "SELECT * FROM Stat_Types";
	$stype_result = @mysql_query($sql_stype, $arlConn) or die ("Unable to query: $sql_stype");
	
	//// Begin HTML HEADER output
?>
<form action="do_proc3_save.php" METHOD=POST>
  <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" />


  <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" />

<?php// Stype?>
<select name="stype" disabled>
<?php
	while($row = @mysql_fetch_array($stype_result))
	{	
		$selected_stype = "";
		$sid = $row['SID'];
		$sname = $row['Name']; 
		$sid_post = $_POST['stype'];
		if ("$sid_post" == "$sid") 
			$selected_stype = "selected"; 
		
		echo "<option value='$sid' $selected_stype>$sname</option>";
	}
?>
</select>
<input name="stype" type="hidden" value="<?php echo $_POST['stype'];?>" size="5" />

<p>
<br />
<?php 
	echo "Verify Values Below, then press 'Save Changes'";
?>
&nbsp;
</p>

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

<?php
	// Table loop through 
	function build_Location() 
	{ 
		global $arlConn; 
		$aryLocation;
		global $location_name;
		global $short_description;
		
		$sql_location = "SELECT * from Location"; 
		$location_result = @mysql_query($sql_location, $arlConn) or die ("unable to query: $sql_location");		//Query Database
		  
		$lnum_of_rows = @mysql_num_rows($location_result) or die("No data found");  //Get Number of Rows returned 
	
		$aryLocation = array();		//Create new Array 
		$i = 0;							//Position Index
		while($lrow = @mysql_fetch_array($location_result)) 
		{ 
			$location_name = $row['Name'];
			$location_description = $row['Description'];
			$short_description = $row['ShortDesc'];
			
			$aryLocation[$i][0] = $lrow['LID'];			//Location ID
			$aryLocation[$i][1] = $lrow['Name'];			//Name
			$aryLocation[$i][2] = $lrow['ShortDesc'];		//Short Description
			
			$i++;
		} 
	 
		return $aryLocation; 
	  
	}//end function build_Location()
	
	function build_Category() 
	{ 
		global $arlConn; 
		$aryCategory;
		
		$sql_catagory = "SELECT * from Catalog_Types";
		$catagory_result = @mysql_query($sql_catagory, $arlConn) or die ("unable to query: $sql_catagory"); 
		  
		$cnum_of_rows = @mysql_num_rows($catagory_result) or die("No data found");  //Get Number of Rows returned 
	
		$aryCategory = array();    //Create new Array  
		$i = 0; //Position Index 
		while($crow = @mysql_fetch_array($catagory_result)) 
		{ 
			$aryCategory[$i][0] = $crow['CID']; 
			$aryCategory[$i][1] = $crow['Name']; 
			$aryCategory[$i][2] = $crow['Description'];
			$i++;   
		} 
		 
		return $aryCategory; 
	  
	}//end function build_Catagory()
?>
<!--Begin table for final output-->
	<table width='90%' border='1' cellpadding='1'>
	  <tr>
		<td width='15%'>&nbsp;</td>
<?php //table header
	
	/*Load CategoryArray and LocationArray*/
	//Calling Function to generate Location and Category Array and storing them into global variables
	$LocationArray = build_Location();
	$CategoryArray = build_Category();
	
	//Loop through each Category in the Category Array
	//This is used to display the table header
	for($i=0;$i<count($CategoryArray);$i++)	
    {
		/*$name = $;
	   	$l_description = $l_row['Description'];*/
?>
      <td width='12%'><?php echo $CategoryArray[$i][1]; ?></td>
<?php 
	}//end for

//Check table for output

/*locPos - Location Position. Keeps track of the row we are on for the Location Array*/
/*catPos - Category Position. Keeps track of the row we are on for the Category Array*/
for($locPos=0;$locPos<count($LocationArray);$locPos++)	//Go through each location - 1x1 (table row)
{
	//Place Left most column on the table - Location Name
	for($catPos=0;$catPos<count($CategoryArray);$catPos++)	//Go through each category for that location - (table column)
	{
		//echo "<br /><br />Form Input Value:" . $LocationArray[$locPos][1].$CategoryArray[$catPos][0] . "<br />";
		if($_POST[$LocationArray[$locPos][1].$CategoryArray[$catPos][0]] > 0)
		{
			/*Write Row for display*/
			//Write Left Column
			// - [$locPos][1] - Location Name
			// - [$locPos][2] - Short Name
			$t = "hidden";
			echo "<tr><td nowrap>".$LocationArray[$locPos][1]."(<font color='#FF0000'>".$LocationArray[$locPos][2]."</font>)</td>";

			//Write Input Values
			for($index=0;$index<count($CategoryArray);$index++)
			{
				echo "<td>".$_POST[$LocationArray[$locPos][1].$CategoryArray[$index][0]]."</td>";
				echo "<input name=".$LocationArray[$locPos][1].$CategoryArray[$index][0]." value=".$_POST[$LocationArray[$locPos][1].$CategoryArray[$index][0]]." type=".$t.">";
			}//end for($index)
			
			/*Write Closing Row*/
			echo "</tr>";
			
			//Location contains values. The values have been echoed
			//calling Break to exit $CategoryArray Loop -- go to the next Location
			break;
			
		}//end if($_Post[] > 0
	}//end for($catPost)
}//end for($locPos)

?>
</table>
<br /><table width=100% ><tr><td>
  <input type="submit" name="Submit" value="Save Changes" />
</form>
</td><td></td><td><br />
<form action="menu_entry.php?status=preview" METHOD=POST>

<?php //table header
	
	/*Load CategoryArray and LocationArray*/
	//Calling Function to generate Location and Category Array and storing them into global variables
	$LocationArray = build_Location();
	$CategoryArray = build_Category();
	
	//Loop through each Category in the Category Array
	//This is used to display the table header
	for($i=0;$i<count($CategoryArray);$i++)	
    {
		/*$name = $;
	   	$l_description = $l_row['Description'];*/
	}//end for

//Check table for output

/*locPos - Location Position. Keeps track of the row we are on for the Location Array*/
/*catPos - Category Position. Keeps track of the row we are on for the Category Array*/
for($locPos=0;$locPos<count($LocationArray);$locPos++)	//Go through each location - 1x1 (table row)
{
	//Place Left most column on the table - Location Name
	for($catPos=0;$catPos<count($CategoryArray);$catPos++)	//Go through each category for that location - (table column)
	{
		//echo "<br /><br />Form Input Value:" . $LocationArray[$locPos][1].$CategoryArray[$catPos][0] . "<br />";
		if($_POST[$LocationArray[$locPos][1].$CategoryArray[$catPos][0]] > 0)
		{
			/*Write Row for display*/
			//Write Left Column
			// - [$locPos][1] - Location Name
			// - [$locPos][2] - Short Name
			$t = "hidden";
			//Write Input Values
			for($index=0;$index<count($CategoryArray);$index++)
			{
			echo "<input name=".$LocationArray[$locPos][1].$CategoryArray[$index][0]." value=".$_POST[$LocationArray[$locPos][1].$CategoryArray[$index][0]]." type=".$t.">";
			}//end for($index)
			
			/*Write Closing Row*/
					
			//Location contains values. The values have been echoed
			//calling Break to exit $CategoryArray Loop -- go to the next Location
			break;
			
		}//end if($_Post[] > 0
	}//end for($catPost)
}//end for($locPos)

?>
<input name="material" type="hidden" value="<?php echo $_POST['material'];?>" size="5" />
<input name="month" type="hidden" value="<?php echo $_POST['month'];?>" size="5" />
<input name="employee" type="hidden" value="<?php echo $_POST['employee'];?>" size="5" />
<input name="stype" type="hidden" value="<?php echo $_POST['stype'];?>" size="5" />
<input type="submit" name="Make Corrections" value="Make Corrections" />
</form>
</td></tr></table>
<?php
	include ('/var/www/html/uclit/protected/common/css_login/css_foot2.php'); 
?>