<?php session_start();?>
<!--link href='blue/style.css' rel='stylesheet' type='text/css' /-->
<link href='css/imagetable.css' rel='stylesheet' type='text/css' />
<?php 
		//$message = '<font color=red>Please insert username and password</font>';
		if (isset($_POST['login'])) {
			$username = trim(addslashes($_POST['username']));
			$password = trim(addslashes($_POST['password']));
			
			if ($username != '' && $password != '') {
				include 'open_connection.php';
				$sql = "SELECT * FROM tbl_dir_user WHERE user_name = '$username' AND user_password = '$password'";
																		
				$result = mysql_query($sql) or die('Query failed. ' . mysql_error());
				$row = mysql_fetch_array($result, MYSQL_ASSOC);
				
				 if (mysql_num_rows($result) == 1) {
					$_SESSION['isLogged_in'] = true;
					   $_SESSION['username'] = $row['user_name'];
					    $_SESSION['section'] = $row['user_section'];
					     $_SESSION['access'] = $row['user_access'];
				   $_SESSION['section_name'] = $row['section_name'];
				$_SESSION['designation_name']=$row['designation_name'];
				
				
				if($_SESSION['access'] == 'admin' && $_SESSION['designation_name']=='Assistant Manager (Finance)'||$_SESSION['designation_name']=='Executive (ICT & Multimedia)')
				{
			       			echo "<script language='javascript'>window.location='vendor_FinanceAdmin_MainMenu.php'</script>";
				}

				elseif($_SESSION['access'] == 'admin' && $_SESSION['designation_name']=='Senior Manager (Facility Management)'||
				$_SESSION['designation_name']=='Senior Sales Manager (Government)'||$_SESSION['designation_name']=='Executive (ICT & Multimedia)'||
				$_SESSION['designation_name']=='Senior Coordinator (Administration)')
				{
			       			 echo "<script language='javascript'>window.location='vendor_list.php'</script>";
				}

				elseif($_SESSION['access'] == 'admin' && $_SESSION['designation_name']=='Coordinator (Culinary Administration)'||
				$_SESSION['designation_name']== 'Coordinator (F&B Admin)'||$_SESSION['designation_name']=='Coordinator (Steward)')
				{
			       			 echo "<script language='javascript'>window.location='vendor_fnb_menu.php'</script>";
				}

				elseif($_SESSION['access'] == 'admin' && $_SESSION['designation_name']=='Manager (F&B)')
				{
			       			   echo "<script language='javascript'>window.location='cost_fnb.php'</script>";
				}
				elseif($_SESSION['access'] == 'admin' && $_SESSION['designation_name']=='General Manager (F&B)')
				{
			       			   echo "<script language='javascript'>window.location='fnb_page.php'</script>";
				}
				elseif($_SESSION['access'] == 'user' && $_SESSION['designation_name']=='Executive (Pastry Chef)'||$_SESSION['designation_name']=='Chef (De Cuisine)'||
				$_SESSION['designation_name']=='Manager (Steward & Hygiene)')
				{
			       			   echo "<script language='javascript'>window.location='cost_fnb.php'</script>";
				}
				
			}

				else
					   $message = '<script type="text/javascript">
					window.alert("Invalid username and password")
					</script>';
						
			} // username pwd blank			
		
			else 
				    $message = '<script type="text/javascript">
						window.alert("Please enter username and password")
						</script>';
	
					
			}
										   
		?>
<!DOCTYPE html>
<html>

<head>
    <title>PICCSB e-Directory System</title>

  </head>
<body bgcolor="#333333"> 
<table width="100%" border="0" align="center">
<tr>
<td width="15%" bgcolor="#333333">&nbsp;</td>
<td width="70%" align="center" bgcolor="#FFFFFF" > 

<table width="100%" border="0" align="center">

<!-- row for header picc 1 -->
<tr>  
     <th width="100%" colspan="4"><img src="images/header-cox.jpg" width="100%" height="auto"></th>
</tr>

<!-- row for header picc 2 -->
					<tr>
     					<th width="100%" colspan="4"><img src="images/eoffice-cox.jpg" width="100%" height="auto"></th>
					</tr>

<!-- calling frame -->	
					<tr>
   						 <td colspan="1" width="10%" align="center"><?php include("header.php");?></td>
					</tr>
					<tr>
						<td>
						<table align="center">
						<tr><td>&nbsp;</td></tr>
					<tr><td>&nbsp;</td></tr>
					
					
						<tr>
						<td colspan="3" align="center"><img src="images/login.jpg" width="150" height="90">
						</td>
						</tr>
						<form method="post" action="<?php echo $_SERVER['PHP_SELF'];?>">
							<tr><td align="center">Username</td><td> : </td><td><input type="text" size="20" maxlength="12" name="username"></td></tr>
    						<tr><td align="center">Password</td><td> : </td><td><input type="password" size="20" maxlength="8" name="password"></td></tr>
    						<tr><td colspan="3" align="center"><br /><br /><input type="submit" value="LOGIN" name="login" id="login" class="myButton">
    						<input type="reset" value="RESET" name="reset" id="reset" class="myButton">
    						<input type="button" class="myButton" value="CHANGE PASSWORD" onClick="window.location.href='user_changepassword.php'"></td></tr>
 						</form>
    					 <?php  echo $message ?> 
						 </table>
      					</td>
    				</tr>
					<tr><td>&nbsp;</td></tr>
					<tr><td>&nbsp;</td></tr>
					<tr><td>&nbsp;</td></tr>
					<tr><td>&nbsp;</td></tr>
					<tr><td>&nbsp;</td></tr>
					
					<tr>
						<th align="center" colspan="4">
						<?php include ('footer.php'); ?>
						</th>
					</tr>
 				 </table>
  
		<td width="20%" bgcolor="#333333">&nbsp;</td>

</tr>

<!--- end for ruang kerja 100% -->
</table>
</table>
</body>
</html>