<?php

session_start();

include("db_con.php");

$message=array();

if(isset($_POST['username']) && !empty($_POST['username'])){

    $uname=mysqli_real_escape_string($con,$_POST['username']);

}
else{

    $message[]='<center><b>Please enter username</b></center>';
}


if(isset($_POST['password']) && !empty($_POST['password'])){

    $upass=sha1(mysqli_real_escape_string($con,$_POST['password']));

}
else{

    $message[]='<center><b>Please enter password</b></center>';
}


$countError=count($message);


if($countError > 0){

     for($i=0;$i<$countError;$i++){

              $msg=ucwords($message[$i]);
     }

}
else{

    $query="select * from adminusers where u_name='$uname' AND u_password='$upass' AND u_status=1";
//echo $query;

    $res=mysqli_query($con,$query);
    $rw=mysqli_fetch_array($res);
    $checkUser=mysqli_num_rows($res);



    if($checkUser > 0){

        //check the IP address of the user
        $ip = $_SERVER['REMOTE_ADDR']?:($_SERVER['HTTP_X_FORWARDED_FOR']?:$_SERVER['HTTP_CLIENT_IP']);
        $ipquery="select * from ip_table where ip_address='$ip' AND ip_status=1";
        //echo $query;
        $ipres=mysqli_query($con,$ipquery);        
        $checkip=mysqli_num_rows($ipres);
		$checkip=2;
        if($checkip < 1){

             header('Location: index.php?msg=21');
             exit();
        }

         $_SESSION['LOGIN_STATUS']=true;
         $_SESSION['UNAME']=$uname;
         $_SESSION['level']=$rw['u_type'];
        // $_SESSION['delcenter']=$rw['delcenter'];

         //$_SESSION['ALEVEL'] =$rw['restrictions'];

         include ('files/methodlist.php'); 
        
        error_reporting(0);

        $_SESSION['rules'] =$rw['restrictions'];
        /*
        $string = $rw['restrictions'];

        $array = explode(',', $string);

        for ($i = 0; $i < count($array)-1; $i++) {

            $key = array_search($array[$i], $rules);
            $newarr[$key]=$array[$i];
        }

        for ($i = 0; $i < count($rules); $i++) {

            if($newarr[$i]==NULL) $newarr[$i]="NO";
        }

        $_SESSION['ALEVEL'] =$newarr;
        */
        header('Location: files/dashboard.php');
 
    }else{

         $msg='<center><b>please enter correct user details</b></center>';
         header('Location: index.php?msg=1');
    }

}



?>







