<?php 

	session_start();
	include("../all_query.php");
	include '../db.php';


	$username=$_SESSION['loan_crm_username'];
	$user_id=$_SESSION['loan_crm_userid'];
	$login_as=$_SESSION['login_as'];

	 
	  if($login_as == 'advisor')
		{
			 mysqli_query($conn,"update advisors set apisipid = '' where id = $user_id ");
			 
			 
			 
			 
			   $LOGIN_DATA = array();
			   
			 $advisor_id =   $LOGIN_DATA['advisor_id'] = $_SESSION['loan_crm_userid'];
			   $LOGIN_DATA['advisor_name'] = $_SESSION['login_name'];
			   $LOGIN_DATA['apisipid'] = $_SESSION['apisipid'];
			   $LOGIN_DATA['status_date'] = date('Y-m-d');
			   $LOGIN_DATA['status_time'] = date('h:i A');
			   $LOGIN_DATA['login_status'] = 'logged_out';
			   $LOGIN_DATA['login_status_type'] = 'manual';
			   
			   insertTable($conn,'advisor_login_status',$LOGIN_DATA,'add_submit');
			
			
			
			 mysqli_query($conn,"update `advisors` set is_busy_on_call = '' where id=$advisor_id ");
			 
		}
		




	session_destroy();
	header('location:login.php');

?>