<?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();
?>



<?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";
		$loginpers_result = mysql_query($sql_logindept, $uclit_dbConn) or die ("Unable to query: $sql_logindept");
		
			while($emp_row = mysql_fetch_array($loginpers_result))
			{	
				$pid = $emp_row['personnel_id'];
				$lname = $emp_row['last_name'];
				$fname = $emp_row['first_name'];
				$mname = $emp_row['middle_name'];
			}
	}
	echo"<h2>Good day $fname.  <br/>Here are your Departmental Totals for 2008 </h2><table border='0'>";

	$db = mysql_select_db('arlstats', $arlConn) or die ("Unable to select arlstats database.");
		$sql_calendar = "SELECT QID, Month FROM Calendar WHERE (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";
		
 	$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))
		{			
			$location = $lid;
			$locationname = $loc;
			
			$sql_mono_held = "SELECT SUM(Value) AS Total FROM Current_Stats WHERE ((MID = 1) AND (CID = 4 or CID=3 or CID=2 or CID=1) AND (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) AND (SID = 1 OR SID=4) AND (LID = $lid))";
	$mono_held_result = @mysql_query($sql_mono_held, $arlConn) or die ("Unable to query: $sql_mono_held");
	$mono_held_total = @mysql_result($mono_held_result,0);

	$sql_mono_widthdrawn = "SELECT SUM(Value) AS Total FROM Current_Stats WHERE ((MID = 1) AND (CID = 7) AND (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) AND (SID = 1 OR SID=4) AND (LID = $lid))";
	$mono_widthdrawn_result = @mysql_query($sql_mono_widthdrawn, $arlConn) or die ("Unable to query: $sql_mono_widthdrawn");
	$mono_widthdrawn_total = @mysql_result($mono_widthdrawn_result,0);
	
	$mono_net = number_format($mono_held_total - $mono_widthdrawn_total);
	
			$sql_score_held = "SELECT SUM(Value) AS Total FROM Current_Stats WHERE ((MID = 2) AND (CID = 4 or CID=3 or CID=2 or CID=1) AND (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) AND (SID = 1 OR SID=4) AND (LID = $lid))";
	$score_held_result = @mysql_query($sql_score_held, $arlConn) or die ("Unable to query: $sql_score_held");
	$score_held_total = @mysql_result($score_held_result,0);

	$sql_score_widthdrawn = "SELECT SUM(Value) AS Total FROM Current_Stats WHERE ((MID = 2) AND (CID = 7) AND (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) AND (SID = 1 OR SID=4) AND (LID = $lid))";
	$score_widthdrawn_result = @mysql_query($sql_score_widthdrawn, $arlConn) or die ("Unable to query: $sql_score_widthdrawn");
	$score_widthdrawn_total = @mysql_result($score_widthdrawn_result,0);
	
	$score_net = number_format($score_held_total - $score_widthdrawn_total);
	
			$sql_serial_held = "SELECT SUM(Value) AS Total FROM Current_Stats WHERE ((MID = 3) AND (CID = 4 or CID=3 or CID=2 or CID=1) AND (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) AND (SID = 1 OR SID=4) AND (LID = $lid))";
	$serial_held_result = @mysql_query($sql_serial_held, $arlConn) or die ("Unable to query: $sql_serial_held");
	$serial_held_total = @mysql_result($serial_held_result,0);

	$sql_serial_widthdrawn = "SELECT SUM(Value) AS Total FROM Current_Stats WHERE ((MID = 3) AND (CID = 7) AND (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) AND (SID = 1 OR SID=4) AND (LID = $lid))";
	$serial_widthdrawn_result = @mysql_query($sql_serial_widthdrawn, $arlConn) or die ("Unable to query: $sql_score_widthdrawn");
	$serial_widthdrawn_total = @mysql_result($serial_widthdrawn_result,0);
	
	$serial_net = number_format($serial_held_total - $serial_widthdrawn_total);
	
		$sql_micro_held = "SELECT SUM(Value) AS Total FROM Current_Stats WHERE ((MID = 4) AND (CID = 4 or CID=3 or CID=2 or CID=1) AND (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) AND (SID = 1 OR SID=4) AND (LID = $lid))";
	$micro_held_result = @mysql_query($sql_micro_held, $arlConn) or die ("Unable to query: $sql_micro_held");
	$micro_held_total = @mysql_result($micro_held_result,0);

	$sql_micro_widthdrawn = "SELECT SUM(Value) AS Total FROM Current_Stats WHERE ((MID = 4) AND (CID = 7) AND (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) AND (SID = 1 OR SID=4) AND (LID = $lid))";
	$micro_widthdrawn_result = @mysql_query($sql_micro_widthdrawn, $arlConn) or die ("Unable to query: $sql_micro_widthdrawn");
	$micro_widthdrawn_total = @mysql_result($micro_widthdrawn_result,0);
	
	$micro_net = number_format($micro_held_total - $micro_widthdrawn_total);
	
		$sql_comp_held = "SELECT SUM(Value) AS Total FROM Current_Stats WHERE ((MID = 5) AND (CID = 4 or CID=3 or CID=2 or CID=1) AND (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) AND (SID = 1 OR SID=4) AND (LID = $lid))";
	$comp_held_result = @mysql_query($sql_comp_held, $arlConn) or die ("Unable to query: $sql_comp_held");
	$comp_held_total = @mysql_result($comp_held_result,0);

	$sql_comp_widthdrawn = "SELECT SUM(Value) AS Total FROM Current_Stats WHERE ((MID = 5) AND (CID = 7) AND (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) AND (SID = 1 OR SID=4) AND (LID = $lid))";
	$comp_widthdrawn_result = @mysql_query($sql_comp_widthdrawn, $arlConn) or die ("Unable to query: $sql_comp_widthdrawn");
	$comp_widthdrawn_total = @mysql_result($comp_widthdrawn_result,0);
	
	$comp_net = number_format($comp_held_total - $comp_widthdrawn_total);
	
		$sql_map_held = "SELECT SUM(Value) AS Total FROM Current_Stats WHERE ((MID = 6) AND (CID = 4 or CID=3 or CID=2 or CID=1) AND (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) AND (SID = 1 OR SID=4) AND (LID = $lid))";
	$map_held_result = @mysql_query($sql_map_held, $arlConn) or die ("Unable to query: $sql_map_held");
	$map_held_total = @mysql_result($map_held_result,0);

	$sql_map_widthdrawn = "SELECT SUM(Value) AS Total FROM Current_Stats WHERE ((MID = 6) AND (CID = 7) AND (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) AND (SID = 1 OR SID=4) AND (LID = $lid))";
	$map_widthdrawn_result = @mysql_query($sql_map_widthdrawn, $arlConn) or die ("Unable to query: $sql_map_widthdrawn");
	$map_widthdrawn_total = @mysql_result($map_widthdrawn_result,0);
	
	$map_net = number_format($map_held_total - $map_widthdrawn_total);
	
		$sql_dd_held = "SELECT SUM(Value) AS Total FROM Current_Stats WHERE ((MID = 7) AND (CID = 4 or CID=3 or CID=2 or CID=1) AND (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) AND (SID = 1 OR SID=4) AND (LID = $lid))";
	$dd_held_result = @mysql_query($sql_dd_held, $arlConn) or die ("Unable to query: $sql_dd_held");
	$dd_held_total = @mysql_result($dd_held_result,0);

	$sql_dd_widthdrawn = "SELECT SUM(Value) AS Total FROM Current_Stats WHERE ((MID = 7) AND (CID = 7) AND (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) AND (SID = 1 OR SID=4) AND (LID = $lid))";
	$dd_widthdrawn_result = @mysql_query($sql_dd_widthdrawn, $arlConn) or die ("Unable to query: $sql_dd_widthdrawn");
	$dd_widthdrawn_total = @mysql_result($dd_widthdrawn_result,0);
	
	$dd_net = number_format($dd_held_total - $dd_widthdrawn_total);
	
			$sql_sound_held = "SELECT SUM(Value) AS Total FROM Current_Stats WHERE ((MID = 8) AND (CID = 4 or CID=3 or CID=2 or CID=1) AND (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) AND (SID = 1 OR SID=4) AND (LID = $lid))";
	$sound_held_result = @mysql_query($sql_sound_held, $arlConn) or die ("Unable to query: $sql_sound_held");
	$sound_held_total = @mysql_result($sound_held_result,0);

	$sql_sound_widthdrawn = "SELECT SUM(Value) AS Total FROM Current_Stats WHERE ((MID = 8) AND (CID = 7) AND (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) AND (SID = 1 OR SID=4) AND (LID = $lid))";
	$sound_widthdrawn_result = @mysql_query($sql_sound_widthdrawn, $arlConn) or die ("Unable to query: $sql_dd_widthdrawn");
	$sound_widthdrawn_total = @mysql_result($sound_widthdrawn_result,0);
	
	$sound_net = number_format($sound_held_total - $sound_widthdrawn_total);
	
		$sql_proj_held = "SELECT SUM(Value) AS Total FROM Current_Stats WHERE ((MID = 9) AND (CID = 4 or CID=3 or CID=2 or CID=1) AND (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) AND (SID = 1 OR SID=4) AND (LID = $lid))";
	$proj_held_result = @mysql_query($sql_proj_held, $arlConn) or die ("Unable to query: $sql_proj_held");
	$proj_held_total = @mysql_result($proj_held_result,0);

	$sql_proj_widthdrawn = "SELECT SUM(Value) AS Total FROM Current_Stats WHERE ((MID = 9) AND (CID = 7) AND (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) AND (SID = 1 OR SID=4) AND (LID = $lid))";
	$proj_widthdrawn_result = @mysql_query($sql_proj_widthdrawn, $arlConn) or die ("Unable to query: $sql_dd_widthdrawn");
	$proj_widthdrawn_total = @mysql_result($proj_widthdrawn_result,0);
	
	$proj_net = number_format($proj_held_total - $proj_widthdrawn_total);
	
		$sql_models_held = "SELECT SUM(Value) AS Total FROM Current_Stats WHERE ((MID = 10) AND (CID = 4 or CID=3 or CID=2 or CID=1) AND (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) AND (SID = 1 OR SID=4) AND (LID = $lid))";
	$models_held_result = @mysql_query($sql_models_held, $arlConn) or die ("Unable to query: $sql_models_held");
	$models_held_total = @mysql_result($models_held_result,0);

	$sql_models_widthdrawn = "SELECT SUM(Value) AS Total FROM Current_Stats WHERE ((MID = 10) AND (CID = 7) AND (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) AND (SID = 1 OR SID=4) AND (LID = $lid))";
	$models_widthdrawn_result = @mysql_query($sql_models_widthdrawn, $arlConn) or die ("Unable to query: $sql_models_widthdrawn");
	$models_widthdrawn_total = @mysql_result($models_widthdrawn_result,0);
	
	$models_net = number_format($models_held_total - $models_widthdrawn_total);
	
			$sql_kit_held = "SELECT SUM(Value) AS Total FROM Current_Stats WHERE ((MID = 11) AND (CID = 4 or CID=3 or CID=2 or CID=1) AND (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) AND (SID = 1 OR SID=4) AND (LID = $lid))";
	$kit_held_result = @mysql_query($sql_kit_held, $arlConn) or die ("Unable to query: $sql_kit_held");
	$kit_held_total = @mysql_result($kit_held_result,0);

	$sql_kit_widthdrawn = "SELECT SUM(Value) AS Total FROM Current_Stats WHERE ((MID = 11) AND (CID = 7) AND (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) AND (SID = 1 OR SID=4) AND (LID = $lid))";
	$kit_widthdrawn_result = @mysql_query($sql_kit_widthdrawn, $arlConn) or die ("Unable to query: $sql_kit_widthdrawn");
	$kit_widthdrawn_total = @mysql_result($kit_widthdrawn_result,0);
	
	$kit_net = number_format($kit_held_total - $kit_widthdrawn_total);
			
			echo"<tr><td>Location:  $locationname ( $lde )</td><td></td><td></td><td width='100'></td><td><u>Net Items</u></td></tr>
					<tr><td></td><td>Monograph:</td><td></td><td></td><td>$mono_net</td></tr>
					<tr><td></td><td>Serial:</td><td></td><td></td><td>$serial_net</td></tr>
					<tr><td></td><td>Sound Recording:</td><td></td><td></td><td>$sound_net</td></tr>
					<tr><td></td><td>Score:</td></td><td></td><td></td><td>$score_net</td></tr>
					<tr><td></td><td>Microform:</td><td></td><td></td><td>$micro_net</td></tr>
					<tr><td></td><td>Projected Medium:</td><td></td><td></td><td>$proj_net</td></tr>
					<tr><td></td><td>Map:</td><td></td><td></td><td>$map_net</td></tr>
					<tr><td></td><td>Computer File:</td><td></td><td></td><td>$comp_net</td></tr>
					<tr><td></td><td>2-D Object:</td><td></td><td></td><td>$dd_net</td></tr>
					<tr><td></td><td>Models:</td><td></td><td></td><td>$models_net</td></tr>
					<tr><td></td><td>Kit:</td><td></td><td></td><td>$kit_net</td></tr>
					<tr height='20'></tr>";
		}
	}	
	
echo"</table>";	
?>




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