<?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'); 
  
        $query2 = "SELECT DISTINCT Name, MID FROM Material_Types ORDER BY Name" ;
	$db4 = mysql_select_db('arlstats', $arlConn) or die("Couldn't select database. uclit_db");
	$sql_result2 = mysql_query($query2, $arlConn) or die("Couldn't execute query. <p>$query2</p>");


      $query3 = "SELECT DISTINCT Month, QID, date_month, date_year FROM Calendar ORDER BY date_year, date_month" ;
	$db5 = mysql_select_db('arlstats', $arlConn) or die("Couldn't select database. uclit_db");
	$sql_result3 = mysql_query($query3, $arlConn) or die("Couldn't execute query. <p>$query2</p>");

	$query4 = "SELECT Personnel_id, last_name, first_name, middle_name, removed FROM personnel WHERE removed != '1' ORDER BY last_name, first_name" ;
	$db6 = mysql_select_db('uclit_db', $arlConn) or die("Couldn't select database. uclit_db");
	$sql_result4 = mysql_query($query4, $arlConn) or die("Couldn't execute query. <p>$query4</p>");

	$query5 = "SELECT CID, Name FROM Catalog_Types ORDER BY CID" ;
	$db7 = mysql_select_db('arlstats', $arlConn) or die("Couldn't select database. uclit_db");
	$sql_result5 = mysql_query($query5, $arlConn) or die("Couldn't execute query. <p>$query5</p>");

	$query6 = "SELECT LID, Name, Description, ShortDesc FROM Location ORDER BY LID" ;
	$db8 = mysql_select_db('arlstats', $arlConn) or die("Couldn't select database. uclit_db");
	$sql_result6 = mysql_query($query6, $arlConn) or die("Couldn't execute query. <p>$query6</p>");



      

	if(isset($_GET['type']) && $_GET['type'] == "edit") 
	{
		$statid = $_GET['statid'];
		$type = $_GET['type'];
		$db = mysql_select_db('arlstats', $arlConn) or die("Could not select database");
		$sqlQuerry = "select * from Current_Stats where Stat_ID='$statid'";
		$QuerryResult = mysql_query($sqlQuerry) or die("SELECT query failed");
		
		
		while($class_row = @mysql_fetch_array($QuerryResult))
		{	
			$lid = $class_row['LID'];
			$mid = $class_row['MID'];
			$cid = $class_row['CID'];
			$uid = $class_row['UID'];
			$qid = $class_row['QID'];
			$sid = $class_row['SID'];
                  $value = $class_row['Value'];
		}
		echo "<h1>Editing Collection Statistics</h1>";
		echo "
			<form name='administer' method='POST' action='process_update.php?&statid=$statid'>
			<table>
				<tr><td align='right'>
                        <strong>Value:</strong></td><td>
			<input type='text' name='value' value='$value'  size='25'/>
		</td>
                      </tr>

                        <tr>
                        <td align='right'>Statistics Type:</td>
                        <td><input type='radio' name='stype' value='1'";

                        if($sid == '1')
                        {
 			echo" CHECKED>"; 
                        }
                        else
                        {
			echo">";
                        }
                        echo"
                        Current 
                        <input type='radio' name='stype' value='2'";

                        if($sid == '2')
                        {
 			echo" CHECKED>"; 
                        }
                        else
                        {
			echo">";
                        }
                        echo"Retro 
                        <input type='radio' name='stype' value='3'";

                        if($sid == '3')
                        {
 			echo" CHECKED>"; 
                        }
                        else
                        {
			echo">";
                        }
                        echo"
                        Retro GovDocs
                        </td>
                        </tr>
                      
                      <tr>
                      <td align=right>Material Type:&nbsp;</td>
     <td><select name='mattype'>";

		while ($row = mysql_fetch_array($sql_result2)) 
		{
                        $material_name = $row["Name"];
                        $matid = $row["MID"];
                        echo"$mid, $matid";
                        if($mid == $matid)
                        {
 			echo" <option value='$matid' selected>$material_name</option>"; 
                        }
                        else
                        {
			echo "<option value='$matid'>$material_name</option>";
                        }
                        echo"$mid, $matid";
		}
                echo"</td></tr>
		
                       <tr>
                      <td align=right>Location:&nbsp;</td>
     <td><select name='loctype'>";

		while ($row = mysql_fetch_array($sql_result6)) 
		{
                        $loc_name = $row["Name"];
                        $locid = $row["LID"];
				$loc_desc = $row["Description"];
                        $loc_short = $row["ShortDesc"];

                        if($lid == $locid)
                        {
 			echo" <option value='$locid' selected>$loc_name ($loc_short)</option>"; 
                        }
                        else
                        {
			echo "<option value='$locid'>$loc_name ($loc_short)</option>";
                        }
		}
                echo"</td></tr>
		

                         <tr>
                      <td align=right>Cataloging Type:&nbsp;</td>
     <td><select name='cattype'>";

		while ($row = mysql_fetch_array($sql_result5)) 
		{
                        $cat_name = $row["Name"];
                        $catid = $row["CID"];
                        if($cid == $catid)
                        {
 			echo" <option value='$catid' selected>$cat_name</option>"; 
                        }
                        else
                        {
			echo "<option value='$catid'>$cat_name</option>";
                        }
            }
                echo"</td></tr>
		


              <tr>
		  <td align=right>Cataloger (User):&nbsp;</td>
     <td><select name='usertype'>";

		while ($row = mysql_fetch_array($sql_result4)) 
		{
                        $last_name = $row["last_name"];
 				$first_name = $row["first_name"];
				$middle_name = $row["middle_name"];
                        $userid = $row["Personnel_id"];
                        if($uid == $userid)
                        {
 			echo" <option value='$userid' selected>$last_name , $first_name</option>"; 
                        }
                        else
                        {
			echo "<option value='$userid'>$last_name , $first_name</option>";
                        }
		}
                echo"</td></tr>
			<br />


                      <tr>
		  <td align=right>Month:&nbsp;</td>
     <td><select name='caltype'>";

		while ($row = mysql_fetch_array($sql_result3)) 
		{
                        $month_name = $row["Month"];
                        $monthid = $row["QID"];
                        if($qid == $monthid)
                        {
 			echo" <option value='$monthid' selected>$month_name</option>"; 
                        }
                        else
                        {
			echo "<option value='$monthid'>$month_name</option>";
                        }
		}
                echo"</td></tr>
		
                        <table>
                        
		
                            
			<input type='hidden' name='statid' value='$statid' />
			<input type='hidden' name='type' value='$type' /><br /><td align='right'><input type='submit' name='Submit' value='Submit'></td>
	<td><input name='Clear' type='reset' id='Clear' value='Clear'></td>


			</form>
			";
	}
	else if( isset($_GET['type']) && $_GET['type'] == "add")
	{
		$type = $_GET['type'];
		echo "<h1>Adding Workshop</h1>";
		echo "
			<form name='administer' method='POST' action='update_administer.php'>
			<strong>Class Name:</strong><br />
			<input type='text' name='cname' value=''  size='50'/>
			<br />
			<strong>Class Description:</strong><br />
			<textarea name='cdes' cols='50' rows='10'></textarea>
			<br />
			<strong>Pre-Requisite:</strong><br />
			<select name='cprereq'>
				<option value=''>Select...</option>
			";
			mysql_select_db($database_workshop, $sqlConn) or die("Could not select database");
			$sqlC = "select w_name from workshop_detail";
			$CResult = mysql_query($sqlC) or die("SELECT query failed");
			while($c_row = @mysql_fetch_array($CResult))
			{	
				$c = $c_row['w_name'];
				echo "<option value='$c'>$c</option>";
			}
			echo "
			</select>
			<input type='hidden' name='cques' value='' />
			<input type='hidden' name='type' value='$type' /><br />
			<input name='submit' type='submit' value='Edit this Record' />
			<input type='button' name='back' value='Cancel' onClick='goBack()'/>
			</form>
			";

	}
	else
	{
		echo "Invalid entry into this form.  Please return to <a href='list_administer.php'>Administer List</a><br />";
	}
	include('/var/www/html/uclit/protected/common/css_foot.php'); 
	?>
	<script type="text/javascript">
	function EditCheckReq()
	{
		var n = document.administer.cname.value;
		var d = document.administer.cdes.value;
		var p = document.administer.cprereq.value;
		var q = document.administer.cques.value;

		var msg = "Invalid field(s):\n";
		var c = 0;
		if(n == "")
		{
			msg += "Class Name\n";
			c++;
		}
		if(d == "")
		{
			msg += "Class Description\n";
			c++;
		}
		if(p != "")
		{
			document.administer.cques.value = "1";
		}
		else
		{
			document.administer.cques.value = "0";
		}
		if(c != 0)
		{
			window.alert(msg);
		}	
		else
		{
			document.administer.submit();	
		}	
	}
	function AddCheckReq()
	{
		EditCheckReq();
	}
	function goBack()
	{
		window.location='http://ul.uc.edu/uclit/protected/workshop/list_administer.php';
	}
	</script>