<?php 

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

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

// Logical section of criteria
$criteriaObj =  new  criteria();


$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['crit_id'])){
	
	if(isset($_REQUEST['status'])){
		$criteriaObj->changeStatus($_REQUEST['crit_id'],$_REQUEST['status']);
		echo 'criteria Status changed successfully';
	}

	return true;
}

if ($_REQUEST['act']=="order"){
	$criteriaObj->changeOrder($_REQUEST['crit_id'],$_REQUEST['criteria_order'],$_REQUEST['position']);
	header('Location:criterialist.php');
	exit;
}

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

	$criteriaObj->deleteRecord($_REQUEST['crit_id'],$_REQUEST['status']);
	$successMsg = "Campaign Deleted successfully";
}

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

/*if(isset($_REQUEST['parent_id']) && $_REQUEST['parent_id']!=''){
	$criteriaDetails = $criteriaObj->getAllRecords('*',' criteria_parent ='.$_REQUEST['parent_id']);
}else{
	$criteriaDetails = $criteriaObj->getAllRecords('*',' criteria_parent=0');
}*/

$criteriaDetails = $criteriaObj->getAllRecords('*',''," ORDER BY crit_id DESC ");

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

?>