<?php 

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

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

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

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

	return true;
}

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

	return true;
}

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

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

if(isset($_REQUEST['submit'])){
	$act_val = $_REQUEST['action_val'];
	$nominationObj->allAction($act_val,$_POST['check']);
	
	if($act_val=='delete_all'){
		$successMsg = "selected nomination deleted successfully";
	}else  if($act_val=='activate_all'){
		$successMsg = "selected nomination activated successfully";
	}else if($act_val=='inactivate_all'){
		$successMsg = "selected nomination 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_nomination','nomination.csv',array('0','4','14'));
	exit;
}

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

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

?>