<?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  name='ticket_form' ACTION='menu_display.php' method='post' onsubmit="return CheckBeforeSumbit();" >
<h1>View Collection Reports</h1><br />
<table border='0'>
<tr>
	<td align='right'>Statistics Type:</td>
	<td colspan='2'><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'>Adjustment
	</td>
 </tr>
 <tr>
    <td align='right'>By Name/Dept:</td>
	<td>   <select name='Personnel[]' size="5" multiple>
<?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 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>
    <td align='right'>Month: </td>
    <td>   
		<select name='Month[]' multiple size="5">
<?php
		$db = mysql_select_db('arlstats', $arlConn) or die ("Unable to select arlstats database.");
		$sql_calendar = "SELECT QID, Month FROM Calendar WHERE (QID=35 OR QID=36 OR QID=37 OR QID=38 OR QID=39 OR QID=40 or QID=41 OR QID=42 OR QID=43 OR QID=44 OR QID=45 OR QID=46 OR QID=47 OR QID=48 OR QID=49 OR QID=50 OR QID=51 OR QID=52 OR QID=53 OR QID=54 OR QID=55 OR QID=56 OR QID=57 OR QID=58) ORDER BY QID";
		$calendar_result = mysql_query($sql_calendar, $arlConn) or die ("Unable to query: $sql_material");
		
		// echo "\\n<option value='0' selected='selected'>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'>Format: </td>
	<td>    <select name='Material[]' multiple size="5">
<?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' selected='selected'>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>
    <td align='right'>Cataloging Action:</td>
	<td>     <select name='Catalog[]' multiple size="5">
<?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' selected='selected'>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'>Location:</td>
	<td>    <select name='Location[]' multiple size="5" >
<?php
	
	$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' selected='selected'>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>
    <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></td><td></td>
	<td align='right'><input type='submit' value='Submit'></td>
	<td align='right'><input name='Clear' type='reset' id='Clear' value='Clear'></td>
</tr>
</table>
</form>


<script type="text/javascript">
function PersonnelOK()
{
var opt = document.forms[0].elements["Personnel[]"].options;
var x, len = opt.length;
for (x=0; x<len; ++x) 
	{
    if(opt[x].selected) break;
	}
if(x<len) 
	{
	return true;
	} 
else 
	{
	return false;
	}
}
function MonthOK()
{
var optionCount = document.forms[0].elements["Month[]"].options.length;
for (var k = 0; k < optionCount; k++)
	{
	if (document.forms[0].elements["Month[]"].options[k].selected == true)
		{
		return true;
		}
	}

return false;
}

function MaterialOK()
{
var optionCount = document.forms[0].elements["Material[]"].options.length;
for (var k = 0; k < optionCount; k++)
	{
	if (document.forms[0].elements["Material[]"].options[k].selected == true)
		{
		return true;
		}
	}

return false;
}


function CatalogOK()
{
var optionCount = document.forms[0].elements["Catalog[]"].options.length;
for (var k = 0; k < optionCount; k++)
	{
	if (document.forms[0].elements["Catalog[]"].options[k].selected == true)
		{
		return true;
		}
	}

return false;
}


function LocationOK()
{
var optionCount = document.forms[0].elements["Location[]"].options.length;
for (var k = 0; k < optionCount; k++)
	{
	if (document.forms[0].elements["Location[]"].options[k].selected == true)
		{
		return true;
		}
	}

return false;
}

function CheckBeforeSumbit()
{

returnval = true;
if (PersonnelOK() == false)
	{
	window.alert("Sorry.  Please select at least one Cataloger");
	returnval = false;
	}
if (MonthOK() == false)
	{
	window.alert("Sorry.  Please select at least one Month");
	returnval = false;
	}
if (MaterialOK() == false)
	{
	window.alert("Sorry.  Please select at least one Material Type");
	returnval = false;
	}	
if (CatalogOK() == false)
	{
	window.alert("Sorry.  Please select at least one Catalog Type");
	returnval = false;
	}
if (LocationOK() == false)
	{
	window.alert("Sorry.  Please select at least one Location");
	returnval = false;
	}
	
return returnval;
	
}
</script>


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