<?php  

  session_start();
  error_reporting(0);
   include("../db.php");
   include("../all_query.php");
		
		
		
		
	 $username=$_POST['username'];
     $password=$_POST['password'];
     $login_as=$_POST['login_as'];
      
	  
	  
	  	
	if($login_as == 'admin')
	{
	$query=mysqli_query($conn,"select * from admin where username='$username' and password='$password'");
	}
	if($login_as == 'advisor')
	{
	$query=mysqli_query($conn,"select * from advisors where username='$username' and password='$password' and ( status1 ='' or status1='Activated' ) ");
	}
	
	
	
		
	if($data=mysqli_fetch_assoc($query)){
			
		 
	 	$user_id=$data['id'];
		$_SESSION['loan_crm_username']=$username;
		$_SESSION['loan_crm_userid']=$user_id;
		$_SESSION['loan_crm_password']=$password;
		
		$_SESSION['login_as'] = $login_as;
		
		if($login_as == 'admin')
		{
		 $_SESSION['login_name'] = $data['username'];
		 
		  $role = $data['role'];
 		$rights = $data['rights'];
		$lead_owner_ids = $data['lead_owner_ids'];
		
		}
		else {
			
		$_SESSION['login_name'] = $data['name'];
		 $role = 'super';
		$rights = '';
		$lead_owner_ids = $data['id'];
		
		
		}
		
		
		
		 $_SESSION['role'] = $role;
 		$_SESSION['rights'] = $rights;
		$_SESSION['lead_owner_ids'] = $lead_owner_ids;
		
		$_SESSION['image'] = $data['image'];
		$_SESSION['mobile'] = $data['mobile'];
		
	 
		 
		
		 echo json_encode($data);
 
		
	 

	}
	else
	{
		echo "0";
	}
		
		
		
		
		
		?>