<?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_help.php');
    	
	$db = mysql_select_db('helpcalls', $helpConn)	or die("Couldn't select database helpcalls.");
    	
	if (isset($_POST['tech_name']))
	{

		//format date 2003-05-06 13:20:59
		$datetimenow = date('Y-m-d')." ".strftime("%H:%M:%S");
		
		$tid = ucwords($_POST['tech_id']);
		$tname = ucwords($_POST['tech_name']);
		$status = $_POST['status'];
		$action = $_POST['uaction'];
	   
		if ($status != 1)
			$status = '0';
		
		if ($action == '')
		{
			$sql_chk_exist = "Select tech_name FROM techs WHERE ( tech_name='$tname')"; 
			$sql_chk_exist_result = mysql_query($sql_chk_exist, $helpConn) or die ("Unable to exercute equery.<p>$sql_techList</p>");
			
			if(mysql_fetch_row($sql_chk_exist_result) > 0)
			{
				//name exist in techs table
				echo "
				
				<h2>Error Occured!</h2>
				<p><b><font color='red'>$tname already exist in help calls admin. list. $action</font><b><p>
				";
				exit();
			}
			else 
			{
				//add new admin name to list
				$sql_add = "INSERT INTO techs (tech_id, tech_name, status) VALUES ('', '$tname', '$status')";
				$sql_add_result = mysql_query($sql_add, $helpConn) or die ("Unable to exercute add query.<br>$sql_add");
				if(mysql_affected_rows() > 0)
				{
					//log added record
					$sql_useraccessD = "INSERT INTO HelpcallsUserAccessLog VALUES ('', '$suser', '$sql_add', '$datetimenow')";
					mysql_query($sql_useraccessD, $helpConn);
					
					$h2 = "$tname has been successfully added to the admin. list.";
				}
			}
					
		}//end add 

    		
		elseif ($action == 'edit')
		{
			$sql_update = "UPDATE techs SET tech_name='$tname', status='$status' WHERE tech_id='$tid'";
			$sql_update_result = mysql_query($sql_update, $helpConn) or die ("Unable to exercute update query.<br>$sql_update");
			if(mysql_affected_rows() > 0)
			{
				$sql_viewed = "VIEWED  tech_id='$tid',  tech_name='$tname',  status='$status' ";
				//log user access
				$sql_useraccess = "INSERT INTO HelpcallsUserAccessLog VALUES ('', '$suser', '$sql_viewed', '$datetimenow')";
				mysql_query($sql_useraccess, $helpConn);
				
				$sql_useraccess = "INSERT INTO HelpcallsUserAccessLog VALUES ('', '$suser', '$sql_update', '$datetimenow')";
				@mysql_query($sql_useraccess, $sqlConn);
			}	
			$h2 = "$tname has been successfully updated.";
		}
			
			
		elseif ($action == 'delete')
		{
			$sql_delete = "DELETE FROM techs WHERE (tech_id='$tid')";
			$sql_delete_result = mysql_query($sql_delete, $helpConn) or die ("Unable to exercute delete query.<br>$sql_delete");
			if(mysql_affected_rows() > 0)
			{
				$sql_viewed = "VIEWED  tech_id='$tid',  tech_name='$tname',  status='$status' ";
				//log user access
				$sql_useraccess = "INSERT INTO HelpcallsUserAccessLog VALUES ('', '$suser', $sql_viewed, '$datetimenow')";
				mysql_query($sql_useraccess, $helpConn) or die ("Unable to exercute insert query.<br>$sql_useraccess");
				
				$sql_useraccess = "INSERT INTO HelpcallsUserAccessLog VALUES ('', '$suser', '$sql_delete', '$datetimenow')";
				mysql_query($sql_useraccess, $helpConn) or die ("Unable to exercute insert query.<br>$sql_useraccess");
			}
			$h2 = "$tname has been successfully removed from admin. list. ";
		}
		
	}
	else
	{
		header("location: http://ul.uc.edu/uclit/default.php");
		exit();	
	}
    
	echo "
	<h2>$h2</h2>
	<a href='http://ul.uc.edu/uclit/protected/itstaff/show_addadmin.php'>List/Add Admin. to list</a>";
	include('/var/www/html/uclit/protected/common/css_login/css_foot2.php'); 
?>