<?php 

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

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

// Logical section of page
$restaurantObj =  new  restaurant();
$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'])){
		$restaurantObj->changeStatus($_REQUEST['id'],$_REQUEST['status']);
		echo 'Restaurant Status changed successfully';
	}

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

	return true;
}

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

	return true;
}

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

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

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

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

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

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

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

?>