 <?php 
  session_start(); 
  include_once('config.php'); 
  //include_once('class.php');
  //$con=new DB();
  if(isset($_POST['login'])){
  			   
           $user_name = trim($_POST['email']);
           $user_password = trim($_POST['password']);
           $password = sha1($user_password);

           //check if the username exists in the database
  			   $statement="select * from system_users where email_address=?";
           try{
            $query=$db->prepare($statement);            
            $array=array($user_name);
            $results=$query->execute($array);            
            if($results){
              
              if($query->rowCount() > 0){
                  $row=$query->fetch($results);
                  $user_id=$row['user_id'];
                  $login_trials=$row['login_trials'];
                  //$status=$row['status'];

                  //check if the username and password matches
                  $sql=$db->prepare("select * from system_users where user_id=? and password=?");
                  $arr=array($user_id,$password);
                  $execute=$sql->execute($arr);

                  if($execute){
                    if($sql->rowCount() > 0){

                        $_SESSION['user_id']=$row['user_id'];
                        $_SESSION['user_role']=$row['user_type'];
                        $user_role=$row['user_type'];
                        //$question=$row['question_id'];
                        $_SESSION['UPSWD']=$password;
                        $_SESSION['name'] =ucwords($row['first_name']).' '.ucwords($row['last_name']);
                        //print_r($_SESSION);
                        
                        if($user_role =='Admin'){
                            echo "2";
                            //header("Location:users/admin/dashboard.php");
                        }
                        elseif($user_role == 'user'){
                            echo "3";
                           // header("Location:users/eusers/dashboard.php");
                        }   
                        
                      
                    }else{
                      echo "4";
                     

                    }
                  }
                                
              }
              else{
                //
                echo"4";               
              }
            }

           }
           catch(PDOExceptions $e){
            echo $e->getMessage();
           }  			   		   
  			   
  		   }
		?> 