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

	/*	$dbequipt = 'equipment';
		$dbtable = 'departments';
		$dbtable2 = 'personnel';
		$dbtable3 = 'RequestLog';

		$dbhelpcalls = 'helpcalls';
		$dbtable4 = 'log';
*/		
		
	$db = mysql_select_db('uclit_db', $uclit_dbConn) or die ("Unable to select uclit_db database.");
	$QueryDept = "SELECT dept_id, dept_name, building, dept_head_id FROM departments ORDER BY dept_name" ;
	
	$dept_result = mysql_query($QueryDept, $uclit_dbConn) or die("Couldn't execute query. <p>$QueryDept</p>");
	
	$uaction = $_GET['uaction'];
	$pid = $_GET['pid'];
	

	$sql_personnel = "SELECT personnel.personnel_id,
       						 personnel.last_name,
       						 personnel.first_name,
       						 personnel.middle_name,
       						 personnel.dept_id,
       						 personnel.e_mail,
       						 personnel.phone,
       						 personnel.web_role,
       						 personnel.room,
       						 personnel.duties,
       						 personnel.duties_sec,
       						 personnel.removed,
       						 personnel.title,
       						 personnel.ID_Num,
	   						 personnel.PAF,
	   						 personnel.PAF_date,
	   						 personnel.PAF_num,
							 personnel.Start_date,
							 personnel.type_id,
       						 departments.dept_id,
       						 departments.dept_name,
       						 departments.building,
       						 departments.dept_head_id
					 FROM departments
   					 INNER JOIN personnel ON (departments.dept_id = personnel.dept_id) 
					 WHERE personnel_id='$pid'";
			
	$employee_result = mysql_query($sql_personnel, $uclit_dbConn) or die ("Unable to exercute query: <p>$sql_personnel</p>");

	while($row = mysql_fetch_array($employee_result))
	{
		$pid = $row['personnel_id'];
		$lname = $row['last_name'];
		$fname = $row['first_name'];
		$mname = $row['middle_name'];
		$dept_id = $row['dept_id'];
		$email = $row['e_mail'];
		$phone = $row['phone'];
		$web_role = $row['web_role'];
		$room = $row['room'];
		$duties = $row['duties'];
		$title = $row['title'];
		$id_num = $row['ID_Num'];
		$PAF = $row['PAF'];
		$PAF_date = $row['PAF_date'];
		$PAF_num = $row['PAF_num'];
		$telcodate = $row['Start_date'];
		$type = $row['type_id'];
		$bldg = $row['building'];
		$dept_head_id = $row['dept_head_id'];
	}

	// equipConn
	$db = mysql_select_db('equipment', $equipConn) or die ("Unable to select equipment database.");
	
	$sql_datajack = "SELECT jack_id, data_jack FROM data_jacks ORDER BY data_jack";
	$datajack_result = mysql_query($sql_datajack, $equipConn) or die ("Unable to execute query: <p>$sql_datajack</p>");
	
					
	$sql_voicejack = "SELECT jack_id, voice_jack FROM voice_jacks ORDER BY voice_jack";
	$voicejack_result = mysql_query($sql_voicejack, $equipConn) or die ("Unable to execute query: <p>$sql_datajack</p>");

	if($uaction == 'add')
	{
		if($type == '4'){
		$h3 = 'Assign Temp Resources';}
		else{
		$h3 = 'Assign Staff Resources';}
		$goto = 'process_employee_add.php';
		$buttonvalue = 'Assign';
	}
	elseif ($uaction == 'edit')
	{
		$h3 = "Update Record[ '$pid' ] from Personnel";
		$goto = 'process_employeeud.php';
		$buttonvalue = 'Update Employee';
	}
	elseif ($uaction == 'delete')
	{
		$h3 = "Delete Current Record[ '$pid' ] from Monitors?";
		$goto = 'process_employeeud.php';
		$buttonvalue = 'Delete Employee';
	}	
	
echo "
    <h2>$h3</h2>
	<font color='red'>*</font><font size='-1'>- Indicates required fields</font>
    <form action='$goto' method='post' name='employee_form' onSubmit='return validator();'>
	<table width='700' height='260'border='1' cellspacing='1' cellpadding='1'>
	   <tr>
		<td align='center' colspan='2'><font size='+2'>Personal Info</font></td>
	  <tr>
	  <tr>
	    <td width='33%' align='right'>Personnel ID:&nbsp;</td>
	    <td width='67%'><input name='pid' type='text' value='$pid' disabled></td>
	  </tr>
	  <tr>
	    <td align='right'>Last Name:&nbsp;</td>
	    <td><input name='lname' type='text' value='$lname'>
	  </tr>
	  <tr>
	    <td align='right'>First Name:&nbsp;</td>
	    <td><input name='fname' type='text' value='$fname'>
	  </tr>
	  <tr>
	    <td align='right'>Middle Name Initial:&nbsp;</td>
	    <td><input name='mname' type='text' value='$mname' size='2' maxlength='1' disabled></td>
	  </tr>
	  <tr>
	    <td align='right'>Department ID:&nbsp;</td>
	    <td><select name='department'>
			  <option value=''>Select ...</option>";
			  
	while($row = mysql_fetch_array($dept_result))
	{
		$fdept_id = $row['dept_id'];
		$dept_name = $row['dept_name'];
		$building = $row['building'];
	
		if ($dept_id == $fdept_id)
		{	echo "$dept_id == $fdept_id";
			echo "<option value='$fdept_id' selected>$dept_name</option>";
		}
		else 
			echo "<option value='$fdept_id'>$dept_name</option>";
	}
			  
	echo "</select><font color='red'>*</font></td>
	  </tr>";
	 
	if ($uaction == 'edit')
	{ 
		echo"
	   <tr>
	    <td align='right'>Building:&nbsp;</td>
	    <td><input name='building' type='text' value='$building' size='35' maxlength='30' disabled></td>
	  </tr>
	  <tr>
	    <td align='right'>E-mail:&nbsp;</td>
	    <td><input name='email' type='text' value='$email' size='35' maxlength='30'></td>
	  </tr>
	  <tr>
	    <td align='right'>Room Number:&nbsp;</td>
	    <td><input name='room_num' type='text' value='$room' size='35' maxlength='30'></td>
	  </tr>
	  <tr>
	    <td align='right'>Duties:&nbsp;</td>
		<td><textarea name='duties' cols='30' rows='6'>$duties</textarea> </td>
	  </tr>
	  <td align='right'>Web Role:&nbsp;</td>
	    <td><!--<input name='web_role' type='text' value='$web_role' size='20' maxlength='15'>-->
		<select name='web_role'> 
		 <option value='$web_role' selected>$web_role</option>
		 <option value='*'>None</option>
		 <option value='Contributor'>Contributor</option>
		 <option value='Developer'>Developer</option>
		 <option value='Editor'>Editor</option>
	     </select>
        </td>";
		
		$sql_supervisor = "SELECT personnel.personnel_id,
      					 		  personnel.last_name,
      					 		  personnel.first_name,
      					 		  departments.dept_id,
       					 		  departments.dept_name,
       					 		  departments.building,
       					 		  departments.dept_head_id
						   FROM departments
   						   INNER JOIN personnel ON (departments.dept_id = personnel.dept_id) 
						   WHERE personnel_id='$dept_head_id'";
		
		$db = mysql_select_db('uclit_db', $uclit_dbConn) or die ("Unable to select uclit_db database.");
	  	$supervisor_result = mysql_query($sql_supervisor, $uclit_dbConn) or die ("Unable to exercute query: <p>$sql_personnel</p>");
		
		while($row = mysql_fetch_array($supervisor_result))
		{
			$pid_sup = $row['personnel_id'];
			$lname_sup = $row['last_name'];
			$fname_sup = $row['first_name'];
			$mname_sup = $row['middle_name'];
			$dept_id_sup = $row['dept_id'];
			$bldg_sup = $row['building'];
			$dept_head_id = $row['dept_head_id'];
		}
		echo"
	    <td width='33%' align='right'>Supervisor:&nbsp;</td>
	    <td width='67%'><input name='supervisor' type='text' value='$lname_sup, $fname_sup' disabled></td>
	  </tr>
	  <tr>
	    <td width='33%' align='right'>Title:&nbsp;</td>
	    <td width='67%'><input name='title' type='text' value='$title'></td>
	  </tr>
	  <tr>
	    <td width='33%' align='right'>University ID Number:&nbsp;</td>
	    <td width='67%'><input name='id_num' type='text' value='$id_num'></td>
	  </tr>";
	}
	if ($uaction == 'add')
	{
		echo"
	  <tr>
	    <td align='right'>Room Number:&nbsp;</td>
	    <td><input name='room_num' type='text' size='35' maxlength='30' value='$room'><font color='red'>*</font></td>
	  </tr>
	  <tr>
	    <td align='right'>Duties:&nbsp;</td>
		<td><textarea name='duties' cols='30' rows='6'>$duties</textarea><font color='red'>*</font></td>
	  </tr>
	  <tr>
		<td align='center' colspan='2'><font size='+2'>Telco Requests</font></td>
	  <tr>
	    <td><input type='checkbox' name='activatedj' value='true'>Activate Data Jack:";
		if($type == '4'){
		echo"<br><font color='blue'>(Will require AD Approval)</font>";}
	
		echo"
		<br>
		</td>
	    <td><select name='data_jack'>
			  <option value=''>Select ...</option>";
			  
		while($row = mysql_fetch_array($datajack_result))
		{
			$dj_id = $row['jack_id'];
			$dj_name = $row['data_jack'];
			echo "<option value='$dj_id'>$dj_name</option>";
		}
		echo "
		</select>
		</td>
	</tr>
	<tr>
	    <td><input type='checkbox' name='activatevj' value='true'>Activate Voice Jack:";
		if($type == '4'){
		echo"<br><font color='blue'>(Will require AD Approval)</font>";}
	
		echo"<br>
		<td><select name='voice_jack'>
			  <option value=''>Select ...</option>";
			  
		while($row = mysql_fetch_array($voicejack_result))
		{
			$vj_id = $row['jack_id'];
			$vj_name = $row['voice_jack'];
		
			echo "<option value='$vj_id'>$vj_name</option><br>";
		}
		echo "
		</select>
	</tr>
	<tr> 
      <td width='33%' colspan='2'><input type='checkbox' name='newphone' value='true'>New Phone:";
		if($type == '4'){
		echo"<font color='blue'>(Will require AD Approval)</font>";}
	
		echo"&nbsp; &nbsp;
     <input type='checkbox' name='newvoice' value='true'>Voice Mail:";
		if($type == '4'){
		echo"<font color='blue'>(Will require AD Approval)</font>";}
	
		echo"&nbsp; &nbsp;
	  <input type='checkbox' name='newlong' value='true'>Long Distance Code:";
		if($type == '4'){
		echo"<font color='blue'>(Will require AD Approval)</font>";}
		if($type == '4'){
		echo"
		 <input type='checkbox' name='emailapp' value='true'>Email Account <font color='blue'>(Will require AD approval) </font> &nbsp; &nbsp;";}
		
		echo"</td>
    </tr>
	<tr>
	  <td align='center' colspan='2'><font size='+2'>Application Requests</font>
	  </td>
	<tr>
	  <td colspan='2'><b>Staff Applications:</b><br>
	    <input type='checkbox' name='uclidapp' value='true'>UCLID &nbsp; &nbsp;
	    <input type='checkbox' name='illiadapp' value='true'>Illiad &nbsp; &nbsp;";
		if($type != '4'){
		echo"
	    <input type='checkbox' name='ucflexhrapp' value='true'>UCFLEX HR &nbsp; &nbsp;
		<input type='checkbox' name='kronosapp' value='true'>Kronos &nbsp; &nbsp;
	    <input type='checkbox' name='ucflexfinapp' value='true'>UCFLEX Financial &nbsp; &nbsp;";}
		echo"
	  </td>
	</tr>
	<tr> 
	  <td colspan='2'><b>Pay Applications: ";
		if($type == '4'){
		echo"<font color='blue'> (Will require AD Approval)</font>";}
	
		echo"</b><br>
	    <input type='checkbox' name='cs3app' value='true'>Adobe CS3 Creative &nbsp; &nbsp;
		<input type='checkbox' name='cs3web' value='true'>Adobe CS3 Web &nbsp; &nbsp;
  	    <input type='checkbox' name='naviapp' value='true'>Navicat &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
	    <input type='checkbox' name='acroapp' value='true'>Adobe Acrobat &nbsp; &nbsp;
		 <input type='checkbox' name='contribapp' value='true'>Contribute &nbsp; &nbsp;
	  </td>
    </tr>
	<tr>
	  <td align='center' colspan='2'><font size='+2'>Authorization Requests</font>
	  </td>
	<tr>
	  <td colspan='2'><b>Server Authorizations:</b><br>
	    <input type='checkbox' name='uclidauth' value='true'>UCLID &nbsp; &nbsp;
	    <input type='checkbox' name='illiadauth' value='true'>Illiad &nbsp; &nbsp;
		<input type='checkbox' name='ableauth' value='true'>Able &nbsp; &nbsp;
	    <input type='checkbox' name='webauth' value='true'>Web Server &nbsp; &nbsp;
		<input type='checkbox' name='intraauth' value='true'>Intranet Server &nbsp; &nbsp;";
		if($type != '4'){
		echo"
	    <input type='checkbox' name='ucflexhrauth' value='true'>UCFLEX HR Account &nbsp; &nbsp;<br>
		<input type='checkbox' name='kronosauth' value='true'>Kronos Account &nbsp; &nbsp;
	    <input type='checkbox' name='ucflexfinauth' value='true'>UCFLEX Financial Account &nbsp; &nbsp;";}
		echo"
	  </td>
	</tr>
	 <tr>
		<td align='center' colspan='2'><font size='+2'>Equipment Request</font>";
		if($type == '4'){
		echo"<font color='blue'>(Will require AD Approval)</font>";}
	
		echo"
	  </td></tr>
	<tr>
	  <td colspan='2'>
	    <input type='checkbox' name='e_furniture' value='true'>Furniture &nbsp; &nbsp;
        <input type='checkbox' name='e_workstation' value='true'>Workstation &nbsp; &nbsp;
        <input type='checkbox' name='e_keys' value='true'>Keys
		<input type='checkbox' name='sec' value='true'>Security Access
	  </td>
	</tr>
	
	
	
	<tr>
	  <td align='center' colspan='2'><font size='+2'>Training Request</font>
	  </td></tr>
	  <tr>
	   <td align='left' colspan='2'><b>Request:</b> &nbsp; &nbsp;<input size='45' name='training' type='text' value=''>
	</tr>
   
	
	<tr>";
	}
	echo"
	 
	  <td align='center' colspan='2'><input name='telcodate' type='hidden' value='$telcodate'><input name='type' type='hidden' value='$type'><input name='hpid' type='hidden' value='$pid'><input name='uaction' type='hidden' value='$uaction'><input name='submit' type='submit' value='$buttonvalue'></td>
	</tr>
  </table>";
?>	
</form>
	<script language='javascript'>

	function validator()
	{
		var noErrors;
		var msgError = 'Please enter data in the following fields\\n';
		var obj = document.employee_form;
		
		if (obj.room_num.value != '' && obj.duties.value != '' && obj.web_role.value != '')
		{
			return (true);
		}
		else //
		{
			//required fields is empty
			noErrors = false;
	
			if(obj.room_num.value == '')
			{
				msgError += ''Room Number' field\\n';
				obj.room_num.focus();
			}
			if(obj.duties.value == '')
			{
				msgError += ''Duties' field\\n';
				if(obj.room_num.value != '')
					obj.duties.focus();
			}
			if(obj.web_role.value == '')
			{	
				msgError += ''Web Role' list\\n';
				if(obj.dutiesvalue != '')
					obj.web_role.focus();
			}
	
			//errors found
			if(!noErrors)
			{
				alert(msgError);
				return (noErrors);
			}
		}
	}//end function
	</script>
<?php
	include('/var/www/html/uclit/protected/common/css_login/css_foot2.php'); 
?>