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


// if (!isset($_SERVER['PHP_AUTH_USER'])) 
//	{
//	    header('WWW-Authenticate: Basic realm="libitdb.lang.uc.edu"');
//	    header('HTTP/1.0 401 Unauthorized');
//	    echo "<a href='http://ul.uc.edu/uclit/protected/common/login.php'>Main - Home</a>";
//	    exit();
//	}
//	else
//	{
		//format date 2003-05-06 13:20:59
		$datetimenow = date('Y-m-d')." ".strftime("%H:%M:%S");
		    	    
		if(!isset($_GET['type']) && !isset($_POST['type']))
	    {
	    	//page was not called from another page
	    	@header("Location: http://ul.uc.edu/uclit/protected/itcoordinator/show_allemployee.php");
	    	echo "<a href='http://ul.uc.edu/uclit/protected/itcoordinator/show_allemployee.php'>View All Employees</a>";
	    	exit;    	
	    }
	    else 
	    {
	    	$statid = $_POST['statid'];
                $statid2 = $_GET['statid'];
                $uid = $_GET['persid'];
	    	$type = $_POST['type'];
	    	$caltype = $_POST['caltype'];
		$usertype = $_POST['usertype'];
		$cattype = $_POST['cattype'];
		$loctype = $_POST['loctype'];
		$mattype = $_POST['mattype'];
		$stype = $_POST['stype'];
            	$value = $_POST['value'];
			
               
	    	  	
	    	//select database to be used equipment database
		$db = mysql_select_db('arlstats', $arlConn) or die ("Unable to select uclit_db database");
			
		if($_POST['type'] == 'edit')
			{
		//update sql statement
		    	$sql = "UPDATE Current_Stats SET QID='$caltype', UID='$usertype',  CID='$cattype',  LID='$loctype', MID='$mattype', SID='$stype', Value='$value'WHERE Stat_ID='$statid' ";
		    	$sql_viewed = "UPDATE Current_Stats SET QID='$caltype', UID='$usertype',  CID='$cattype',  LID='$loctype', MID='$mattype', SID='$stype', Value='$value'WHERE Stat_ID='$statid' ";
		    	
		    	//exercute sql statement
			$sql_result = mysql_query($sql, $arlConn) or die ("Couldn't execute query<p>$sql</p>");
		    	
				if(!mysql_errno())
				{
					//log user access
					
					$sql_useraccess = "INSERT INTO EquipmentUserAccessLog VALUES ('', '$suser', '$sql_viewed', '$datetimenow')";
					mysql_query($sql_useraccess, $arlConn);
					
					$h2 = "Statistical Record [ '$statid' ] has been successfully updated.";
                                        echo"$h2
                                            </br>
                                            </br>
                                            </br>
                                        
                                        <td>
                                        <FORM ACTION='http://ul.uc.edu/uclit/protected/catalogsuper/menu_select_ad.php' METHOD=GET>
                                        <INPUT TYPE=submit VALUE='Search Again...'>
                                        </FORM>
                                        </td>";



                                }
		    }
		    if($_GET['type'] == 'delete')
		    {
                    //update sql statement
		    	$sql = "DELETE from Current_Stats WHERE Stat_ID='$statid2'";
		    	$sql_viewed = "DELETE from Current_Stats WHERE Stat_ID='$statid2'";
		    	
		    	//exercute sql statement
			$sql_result = mysql_query($sql, $arlConn) or die ("Couldn't execute query<p>$sql</p>");
		    	echo" Delete Check ";
				if(!mysql_errno())
				{
					//log user access
					
					$sql_useraccess = "INSERT INTO EquipmentUserAccessLog VALUES ('', '$suser', '$sql_viewed', '$datetimenow')";
					mysql_query($sql_useraccess, $arlConn);
					
					$h2 = "Statistical Record [ '$statid2' ] has been successfully deleted.";
                                        echo"$h2
                                            </br>
                                            </br>
                                            </br>
                                        
                                        <td>
                                        <FORM ACTION='http://ul.uc.edu/uclit/protected/catalogsuper/menu_select_ad.php' METHOD=GET>
                                        <INPUT TYPE=submit VALUE='Search Again...'>
                                        </FORM>
                                        </td>";
                                }
		    }
	    }
  	echo "
    
    <div align='bottom' class='footer'>";
     $last_modified = filemtime("process_update.php");
     print("Last Modified ");
     print(date("m/j/y", $last_modified));

    if($_POST['type'] == 'edit') 
        {
        $query3 = "Select personnel.personnel_id, personnel.last_name, personnel.first_name, personnel.middle_name, personnel.e_mail
        From personnel Where personnel.personnel_id = '$usertype'" ;
        $db5 = mysql_select_db('uclit_db', $arlConn) or die("Couldn't select database. uclit_db");
        $sql_result3 = mysql_query($query3, $arlConn) or die("Couldn't execute query. <p>Test 1</p>");
        
        while($class_row = @mysql_fetch_array($sql_result3))
		{	
			$lastname = $class_row['last_name'];
			$firstname = $class_row['first_name'];
			$email = $class_row['e_mail'];
		}
        };

    if($_GET['type'] == 'delete') 
        {
        $query3 = "Select personnel.personnel_id, personnel.last_name, personnel.first_name, personnel.middle_name, personnel.e_mail
        From personnel Where personnel.personnel_id = '$uid'" ;
        $db5 = mysql_select_db('uclit_db', $arlConn) or die("Couldn't select database. uclit_db");
        $sql_result3 = mysql_query($query3, $arlConn) or die("Couldn't execute query. <p>Test 2</p>");
        
        while($class_row = @mysql_fetch_array($sql_result3))
		{	
			$lastname = $class_row['last_name'];
			$firstname = $class_row['first_name'];
			$email = $class_row['e_mail'];
		}
        };


     echo "</div>";
     $type1 = $_POST['type'];
     $type2 = $_GET['type'];
        $mail_to = "george.f.johnston@uc.edu, $email";
        $mail_subj = "Records have been changed in the collection statistics.";
	$mail_text = "$firstname, Your statistical Record [ '$statid2' ] has been successfully deleted at $datetimenow by Johnston, George.";
	$mail_text2 = "$firstname, Your statistical Record [ '$statid' ] has been successfully updated at $datetimenow by Johnston, George.";
	$mail_header = "From: libhelp@uc.edu\r\n";
	$mail_header .= "X-Mailer: server\r\n";
	$mail_header .= "Reply To: libhelp@uc.edu\r\n";
	$sendmail_param = "libhelp@uc.edu";
	if($_POST['type'] == 'edit') // email if staff is edited
		mail("$mail_to","$mail_subj","$mail_text2","$mail_header","-f$sendmail_param");
	if($type2 == 'delete') //email if staff is deleted
                mail("$mail_to","$mail_subj","$mail_text","$mail_header","-f$sendmail_param");
	 
include('/var/www/html/uclit/protected/common/css_login/css_foot2.php');   
?>