<?php







session_start();







include "connect.php";







if (isset($_POST['submit'])){







/*$agent= $_SERVER['HTTP_USER_AGENT'];







if (strlen(strstr($agent, 'Firefox')) > 0) {



*/











$email=$_POST['adminemail'];







$email=strip_tags($email);







$email=trim($email);







 







      $password=$_POST['password'];







      $password=strip_tags($password);







      $password=trim($password);







      $password=md5($password);









$chk=mysqli_query($conn,"select * from admin where username='$email'");

$chk1=mysqli_num_rows($chk);



$chek=mysqli_query($conn,"select * from employee where username='$email'");

$chek1=mysqli_num_rows($chek);





if($chk1>0)

{

$getusername = "select * from admin where username='$email' and password='$password'"; 

}



else

{

$getusername = "select * from employee where username='$email' and password='$password'"; 

}





      $result = mysqli_query($conn,$getusername) or die(mysqli_error($conn));







      $result2=mysqli_fetch_assoc($result);





//echo"$email & $password";





      if($result2)







{







@session_start();







$_SESSION['adminemail']=htmlspecialchars($email);







if(function_exists('date_default_timezone_set'))







date_default_timezone_set("Asia/Calcutta");







$lastonline=$result2['nowonline'];







      $nowonline=date("Y-m-d g:i:s a");







      $up="update admin set nowonline='$nowonline',lastonline='$lastonline' where username='$result2[username]'";



      mysqli_query($conn,$up);





	  $date=date('Y-m-d');





	  $mon=date("m");



	  if($mon>=04)

	  {



	  $cy=date("Y",strtotime($date));

	  $ny=$cy+1;

	  

	  $financial=$cy.'-'.$ny;



	  }

	  

	  else

	  {



	  $ny=date("Y",strtotime($date));	  

	  $cy=$ny-1;

	  

	  $financial=$cy.'-'.$ny;



	  }

	  

	  

		$fromd=$cy.'-04-01';

		$tod=$ny.'-03-31';





	  $upd=mysqli_query($conn,"insert into financial(user,financial,fromdate,todate) values('$result2[username]','$financial','$fromd','$tod')");

	  

	  

if($chek1>0)

{

header("location:index.php?s=1" . urlencode($Message));

}

elseif($chk1>0)

{

header("location:index.php?s=1" . urlencode($Message));

}



}



else

{





//echo"$email & $password";



header("location:login.php?s=2" . urlencode($Message));







}   





}



else

{





  // Not logged in



 echo '<META HTTP-EQUIV = "Refresh" Content = "1; URL =login.php">';





}





?>