<?php session_start();
include ('dbcon.php');
include ('functions.php');
$today = strftime("%Y-%m-%d", time()); 
if(isset($_POST['email']) && $_POST['password'] != ''){
    $uname= $_POST['email'];
    $passw= sha1($_POST['password']);
    $sql="SELECT * FROM tbl_user WHERE email='$uname' AND password='$passw' LIMIT 1";
    $res= mysqli_query($con, $sql);
    $row=mysqli_fetch_array($res);
    $count= mysqli_num_rows($res);
    
    if($count <= 0){
    if(get_fild_data('tbl_setting','1','sval')==0){     
    $_SESSION['errmsg'] = 'You enter wrong user name or password!';
    }else{
    $_SESSION['errmsg'] = 'আপনি  নাম অথবা পাসওয়ার্ড ভুল করেছেন!';    
    }
    $_SESSION['uid']=0;
    $_SESSION['axeslogin']=false;
    header("location:../index.php");    
    }else{
    if($today<=get_fild_data('tbl_limitset','1','expDate')){     
    $_SESSION['axeslogin']=true;    
	$_SESSION['utype']=$row['utype'];
    $_SESSION['avname']=$row['name'];    
    if(get_fild_data('tbl_setting','1','sval')==0){    
    $_SESSION['exname']=$row['name'];
    }else{
    $_SESSION['exname']=$row['bname'];    
    }
    $_SESSION['access']=$row['acess'];
    $_SESSION['uimage']=$row['image'];    
    $_SESSION['uid']=$row['id'];
    $_SESSION['abrid']=$row['abrid'];    
    if(isset($_SESSION['cuPages'])){
        
    }else{
    $_SESSION['cuPages']="home.php";    
    }
    write_activity($_SESSION['uid'],'LOG','Login Record','Successfully login.','লগইন রেকর্ড','প্রবেশ সফল হয়েছে।');
    header("location:../pages/".$_SESSION['cuPages']);    
    }else{
    if(get_fild_data('tbl_setting','1','sval')==0){    
    $_SESSION['errmsg'] = 'Your Validity Period was Expired!';
    }else{
    $_SESSION['errmsg'] = 'আপনার বৈধতার মেয়াদ শেষ হয়ে গেছে!';    
    }
    $_SESSION['uid']=0;
    $_SESSION['axeslogin']=false;
    header("location:../index.php");    
    }
    }    
}else{
header("location:../index.php");      
}

?>
