<?php 

// Include main file
include_once('../libs/main.php');

// Check user Login
include_once('checkLogin.php');

// Logical section of page
$userObj =  new  user();


$successMsg = '';

if(isset($_REQUEST['successMsg'])){
	$successMsg = $_REQUEST['successMsg'];
}

if(isset($_REQUEST['failedMsg'])){
	$failedMsg = $_REQUEST['failedMsg'];
}

if(isset($_REQUEST['act']) && $_REQUEST['act']=='change_status' && isset($_REQUEST['id'])){
	
	if(isset($_REQUEST['status'])){
		$userObj->changeStatus($_REQUEST['id'],$_REQUEST['status']);
		echo 'Agency Status changed successfully';
	}

	return true;
}
if(isset($_REQUEST['act']) && $_REQUEST['act']=='change_hstatus' && isset($_REQUEST['id'])){
	
	if(isset($_REQUEST['status'])){
		$userObj->changeHomepageStatus($_REQUEST['id'],$_REQUEST['status']);
		echo 'Agency Homepage Display changed successfully';
	}

	return true;
}

if(isset($_REQUEST['act']) && $_REQUEST['act']=='change_pstatus' && isset($_REQUEST['id'])){
	
	if(isset($_REQUEST['status'])){
		$userObj->changePaymentStatus($_REQUEST['id'],$_REQUEST['status']);
		echo 'Payment Status changed successfully';
	}

	return true;
}

if(isset($_REQUEST['act']) && $_REQUEST['act']=='delete' && isset($_REQUEST['id'])){

	$userObj->deleteRecord($_REQUEST['id'],$_REQUEST['status']);
	$successMsg = "Agency Deleted successfully";
}

if(isset($_REQUEST['submit'])){
	$act_val = $_REQUEST['action_val'];
	$userObj->allAction($act_val,$_POST['check']);
	
	if($act_val=='delete_all'){
		$successMsg = "selected Agency deleted successfully";
	}else  if($act_val=='activate_all'){
		$successMsg = "selected Agency activated successfully";
	}else if($act_val=='inactivate_all'){
		$successMsg = "selected Agency inactivated successfully";
	}
}

$searchStr = "";
if(isset($_POST['search_submit']) && $_POST['search_input']!=''){
	$searchStr = " name LIKE '%".$_POST['search_input']."%'  OR email LIKE '%".$_POST['search_input']."%' OR mobile_no LIKE '%".$_POST['search_input']."%'";
}

if(isset($_REQUEST['act']) && $_REQUEST['act']=='export'){
	exportTableToCSV('tbl_user','user.csv',array('0','4','14'));
	exit;
}

$userDetails = $userObj->getAllRecords("*",$searchStr,"ORDER BY id ASC");

// Include Template 
include_once('../libs/routs.php')

?>