<? session_start();
 include("si_confi.php");

if(isset($_REQUEST['login_admin']))
{
	
	$randum_number=$_SESSION['randum_number'];

if($_REQUEST['captcha_code']!=$randum_number){  
		?><script>window.location="op_log.php?ca=err";</script><?
	    }else{
			
	$username=$_REQUEST['username'];
	$password=$_REQUEST['password'];
	
	$select_count_admin=mysql_query("select count(*) as num from `employee_mng` where `work_emailid`='$username' and `email_password`='$password'");
	$fetch_count_admin=mysql_fetch_array($select_count_admin);
	$result_count=$fetch_count_admin['num'];
	if($result_count==0)
	{ ?>
    <script>window.location="op_log.php?user=error";</script>
    <?
	} else {
		$_SESSION['login_username']=$username;
		?><script>window.location="ad_site.php";</script><?
	}}} ?>
<? include("ad_head.php"); ?>
  
  <? if($_REQUEST['user']=='error'){ ?>
  <div class="error" style="width:50%;margin:0 auto;margin-top:9px;">Invalid Username (or) Password</div><? } ?>
  
  <? if($_REQUEST['ca']=='err'){ ?>
  <div class="error" style="width:50%;margin:0 auto;margin-top:9px;">Invalid Captcha code.</div><? } ?>
  
   <? if($_REQUEST['ses']=='out'){ ?>
  <div class="warning" style="width:50%;margin:0 auto;margin-top:9px;">Session Time out...</div><? } ?>
  
<div class="container">
	<section id="content">
		<form method="post" enctype="multipart/form-data" id="admin_login_form" autocomplete="off" action="<?php echo $_SERVER['PHP_SELF']; ?>">
        <script type="text/javascript" src="prototype.js"></script>
        <script type="text/javascript" src="validation.js"></script>
			<h1>Employee Login Form</h1>
			<div>
				<input type="text" name="username" placeholder="Email ID (Office)" class="required" id="username" autofocus/>
			</div>
			<div>
				<input type="password" name="password" placeholder="Password" class="required" id="password" />
			</div>
            <div>
<? function GeraHash($qtd){ 
$Caracteres = 'ABCDEFGHIJKLMOPQRSTUVXWYZ'; 
$QuantidadeCaracteres = strlen($Caracteres); 
$QuantidadeCaracteres--; 
$Hash=NULL; 
    for($x=1;$x<=$qtd;$x++){ 
        $Posicao = rand(0,$QuantidadeCaracteres); 
        $Hash .= substr($Caracteres,$Posicao,1); 
    } 
return $Hash; 
} 
$randum_number=GeraHash(6);
$_SESSION['randum_number']=$randum_number; ?>
        <input style="background:none;" name="captcha_code" type="text" class="required" placeholder="Enter the Captcha code">
                                <div style="width:100%;height:30px;background:#036;border-radius:5px;color:#FFF;letter-spacing:6px;padding:10px 0px 0px 10px;font-size:20px;"><? echo $randum_number; ?></div>
                                
                                </div>
			<div>
				<input type="submit" value="Log in" name="login_admin" />
			</div>
		</form><!-- form -->
        <script type="text/javascript">
						function formCallback(result, form) 
						{window.status = "valiation callback for form '" + form.id + "': result = " + result;}
						var valid = new Validation('admin_login_form', {immediate : true, onFormValidate : formCallback});
					</script>
	</section><!-- content -->
</div><!-- container -->
  </body>
</html>
