<?php session_start();?>
<?php include 'header.php'; ?>

<link href='blue/style.css' rel='stylesheet' type='text/css' />

<style>
.myButton {
	-moz-box-shadow:inset 0px 1px 3px 0px #91b8b3;
	-webkit-box-shadow:inset 0px 1px 3px 0px #91b8b3;
	box-shadow:inset 0px 1px 3px 0px #91b8b3;
	background:-webkit-gradient(linear, left top, left bottom, color-stop(0.05, #768d87), color-stop(1, #6c7c7c));
	background:-moz-linear-gradient(top, #768d87 5%, #6c7c7c 100%);
	background:-webkit-linear-gradient(top, #768d87 5%, #6c7c7c 100%);
	background:-o-linear-gradient(top, #768d87 5%, #6c7c7c 100%);
	background:-ms-linear-gradient(top, #768d87 5%, #6c7c7c 100%);
	background:linear-gradient(to bottom, #768d87 5%, #6c7c7c 100%);
	filter:progid:DXImageTransform.Microsoft.gradient(startColorstr='#768d87', endColorstr='#6c7c7c',GradientType=0);
	background-color:#768d87;
	-moz-border-radius:5px;
	-webkit-border-radius:5px;
	border-radius:5px;
	border:1px solid #566963;
	display:inline-block;
	cursor:pointer;
	color:#ffffff;
	font-family:arial;
	font-size:12px;
	font-weight:bold;
	padding:4px 20px;
	text-decoration:none;
	text-shadow:0px -1px 0px #2b665e;
}
.myButton:hover {
	background:-webkit-gradient(linear, left top, left bottom, color-stop(0.05, #6c7c7c), color-stop(1, #768d87));
	background:-moz-linear-gradient(top, #6c7c7c 5%, #768d87 100%);
	background:-webkit-linear-gradient(top, #6c7c7c 5%, #768d87 100%);
	background:-o-linear-gradient(top, #6c7c7c 5%, #768d87 100%);
	background:-ms-linear-gradient(top, #6c7c7c 5%, #768d87 100%);
	background:linear-gradient(to bottom, #6c7c7c 5%, #768d87 100%);
	filter:progid:DXImageTransform.Microsoft.gradient(startColorstr='#6c7c7c', endColorstr='#768d87',GradientType=0);
	background-color:#6c7c7c;
}
.myButton:active {
	position:relative;
	top:1px;
}
table.imagetable {
	font-family: verdana,arial,sans-serif;
	font-size:11px;
	color:#333333;
	border-width: 1px;
	border-color: #999999;
	border-collapse: collapse;
}
table.imagetable th {
	background:#b5cfd2 url('cell-blue.jpg');
	border-width: 1px;
	padding: 5px;
	border-style: solid;
	border-color: #999999;
}
table.imagetable td {
	background:#dcddc0 url('cell-grey.jpg');
	border-width: 1px;
	padding:5px;
	border-style: solid;
	border-color: #999999;
}
       
</style>

		<?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 user_name, user_password, user_section, user_access  FROM 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'];
					//$_GET['kodpengguna'] = $row['kodpengguna'];
					//$kodpengguna = $_GET['kodpengguna'];
					
					if( $_SESSION['access'] == 'admin' &&  $_SESSION['section'] == 'humancapital')
					{
					   echo "<script language='javascript'>window.location='staff_admin.php'</script>";
					}
					else {		
					   	echo "<script language='javascript'>window.location='staff_search.php'</script>";
						}
					
					}  // result=1
					
					else 
					    $message = '<script type="text/javascript">
						window.alert("Invalid username and password")
						</script>';
				    
					}  //  username password not blank									    
					
					else
					    $message = '<script type="text/javascript">
						window.alert("Please enter username and password")
						</script>';
	                					
					}
						// echo "<script language='javascript'>window.location='home_admin.php?kodpengguna=$kodpengguna'/script>";
					//		echo "<script language='javascript'>window.location='staff_admin.php'/script>";
						//	}
					
										
			/*		if( $_SESSION['section'] == 'humancapital' &&  $_SESSION['access'] == 'admin' )
						{	
							// echo "<script language='javascript'>window.location='home_admin.php?kodpengguna=$kodpengguna'/script>";
							echo "<script language='javascript'>window.location='staff_admin.php'</script>";
							}
					else if($_SESSION['section'] == 'finance'  &&  $_SESSION['access'] == 'admin' )
						{
						echo "<script language='javascript'>window.location='vendor_admin.php'</script>";
						}
					else if($_SESSION['section'] == 'facility'  &&  $_SESSION['access'] == 'admin' )
						{
						echo "<script language='javascript'>window.location='vendor_search.php'</script>";
						}
					else if($_SESSION['section'] == 'fnb'  &&  $_SESSION['access'] == 'admin' )
						{
						echo "<script language='javascript'>window.location='vendor_search.php'</script>";
						}
					else if($_SESSION['section'] == 'admin'  &&  $_SESSION['access'] == 'admin' )
						{
						echo "<script language='javascript'>window.location='vendor_search.php'</script>";
						}
					else if($_SESSION['section'] == 'ict'  &&  $_SESSION['access'] == 'admin' )
						{
						echo "<script language='javascript'>window.location='vendor_search.php'</script>";
						}
					else if($_SESSION['section'] == 'sales'  &&  $_SESSION['access'] == 'admin' )
						{
						echo "<script language='javascript'>window.location='vendor_search.php'</script>";
						}
					else if($_SESSION['access'] == 'user')
						{
						echo "<script language='javascript'>window.location='staff_search.php'</script>";
						}  
						
				}
				
				else
					    $message = '<script type="text/javascript">
						window.alert("Invalid username and password")
						</script>';
				 }
				 else
					    $message = '<script type="text/javascript">
						window.alert("Please enter username and password")
						</script>';
	       }	*/
		   
		?>

<table align="center">
	<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>Username</td><td> : </td><td><input type="text" size="20" maxlength="12" name="username"></td></tr>
    <tr><td>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>

</table>

     <?php  echo $message ?> 
        
		</td>
    </tr>
  </table>

<br>

<?php include 'footer.php'; ?>
