<?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['user_id'])){
	
	if(isset($_REQUEST['status'])){
		$userObj->changeStatus($_REQUEST['user_id'],$_REQUEST['status']);
		echo 'Agency Status changed successfully';
	}

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

	return true;
}

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

	return true;
}

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

	$userObj->deleteRecord($_REQUEST['user_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 = " user_name LIKE '%".$_POST['search_input']."%'  OR screen_name LIKE '%".$_POST['search_input']."%' OR user_uniq_id LIKE '%".$_POST['search_input']."%'  OR  user_username 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 user_id ASC");

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

?>