<?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'];
	ob_start();
?>
<form id='stat' name='stat' ACTION='menu_display.php' METHOD='POST'>
<h1>View Collection Reports</h1><br />
<table border='0'>
<tr>
	<td align='right'>Statistics Type:</td>
	<td><input type='radio' name='stype' value='1' checked />Current 
    	<input type='radio' name='stype' value='2' />Retro 
    	<input type='radio' name='stype' value='3' />Retro GovDocs
	<!--	<input type='radio' name='stype' value='4'>ARL -->
	</td>
</tr>
<tr>
	<td align='right'>By Name/Dept:</td>
	<td>   <select name='Personnel'>
<?php
	$sql_login = "SELECT username, personnel_id FROM users WHERE username = '$loggedinuser' ";
	$db = mysql_select_db('login', $loginConn) or die ("Unable to select login database.");
	$login_result = mysql_query($sql_login, $arlConn) or die ("Unable to query: $sql_login");
	
	while($log_row = mysql_fetch_array($login_result))
	{	
		$pid = $log_row['personnel_id'];
			
		$db = mysql_select_db('uclit_db', $uclit_dbConn) or die ("Unable to select uclit_db database.");
		$sql_logindept = "SELECT personnel_id, last_name, first_name, middle_name, dept_id 
						  FROM personnel 
						  WHERE personnel_id = '$pid' 
						  ORDER BY last_name";
		$logindept_result = mysql_query($sql_logindept, $uclit_dbConn) or die ("Unable to query: $sql_logindept");
		while($logdept_row = mysql_fetch_array($logindept_result))
		{
			$did = $logdept_row['dept_id'];
			
			$sql_deptpers = "SELECT personnel_id, last_name, first_name, middle_name, dept_id FROM personnel WHERE dept_id = 
				'$did' ORDER BY last_name";
			$deptpers_result = mysql_query($sql_deptpers, $uclit_dbConn) or die ("Unable to query: $sql_deptpers");
		
			$dept_string = "";
			$counter = 0;
			while($emp_row = mysql_fetch_array($deptpers_result))
			{	
				$pid = $emp_row['personnel_id'];
				$lname = $emp_row['last_name'];
				$fname = $emp_row['first_name'];
				$mname = $emp_row['middle_name'];
				echo "\\n<option value='$pid'>$lname, $fname $mname</option>";
				$dept_string .= "$pid OR UID=";
			}
			$dept_string = substr($dept_string, 0, -8); 
	
			echo "\\n<option value='$dept_string'>Departmental Total</option></select>";
		}	
	}
?>	
	</td>
</tr>
<tr>
	<td align='right'>Location:</td>
	<td>    <select name='Location'>
<?php
	$db = mysql_select_db('arlstats', $arlConn) or die ("Unable to select arlstats database.");
	$sql_location = "SELECT LID, Name, Description, UID FROM Location ORDER BY Name";
	$location_result = mysql_query($sql_location, $arlConn) or die ("Unable to query: $sql_location");
	
	echo "\\n<option value='0'>Select All</option>";
	
	while($loc_row= mysql_fetch_array($location_result))
	{
		$lid = $loc_row['LID'];
		$loc = $loc_row['Name'];
		$lde = $loc_row['Description'];
		$luserstring = $loc_row['UID'];
		$luserarray = split("\+", $luserstring);
	
		if (in_array($loggedinuser, $luserarray))
		{			
			echo "\\n<option value='$lid'>$loc ($lde)</option>";
		}
	}		
?>
			</select>
	</td>
</tr>
<tr>
	<td align='right'>Format: </td>
	<td>    <select name='Material'>
<?php
		$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");
	
		echo "\\n<option value='0'>Select All</option>";
		while($mat_row = mysql_fetch_array($material_result))
			{	
			$mid = $mat_row['MID'];
			$mname = $mat_row['Name'];
			echo "\\n<option value='$mid'>$mname</option>";
			}
?>
		</select>
	</td>
</tr>
<tr>
	<td align='right'>Cataloging Action:</td>
	<td>     <select name='Catalog'>
<?php
		$sql_catalog = "SELECT CID, Name FROM Catalog_Types ORDER BY Name";
		$catalog_result = mysql_query($sql_catalog, $arlConn) or die("Unable to query: $sql_catalog");
	
		echo "\\n<option value='0'>Select All</option>";
		while($cat_row = mysql_fetch_array($catalog_result))
		{
			$cid = $cat_row['CID'];
			$cat = $cat_row['Name'];
			echo "\\n<option value='$cid'>$cat</option>";
		}
?>
		</select>
	  </td>
</tr>
<tr>
	<td align='right'>Month: </td>
	<td>   
		<select name='Month'>
<?php
		$sql_calendar = "SELECT QID, Month FROM Calendar ORDER BY QID";
		$calendar_result = mysql_query($sql_calendar, $arlConn) or die ("Unable to query: $sql_material");
		
		echo "\\n<option value='0'>Year-to-Date</option>";
		while($cal_row = mysql_fetch_array($calendar_result))
			{	
			$qid = $cal_row['QID'];
			$qname = $cal_row['Month'];
			echo "\\n<option value='$qid'>$qname</option>";
			}
?>
		</select>
	 </td>
</tr>
<tr>
	<td align='right'><input type='checkbox' name='summary'  value='1'></td>
	<td>Click here to view a summary of the report.</td>
</tr>
<tr>
	<td align='right'><input type='submit' name='Submit' value='Submit'></td>
	<td><input name='Clear' type='reset' id='Clear' value='Clear'></td>
</tr>
</table>
</form>
<?php
	include('/var/www/html/uclit/protected/common/css_login/css_foot2.php'); 
?>