<?php 

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

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

// Logical section of package
$packagesObj =  new  packages();


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

	return true;
}

if ($_REQUEST['act']=="order"){
	$packagesObj->changeOrder($_REQUEST['package_id'],$_REQUEST['package_order'],$_REQUEST['position']);
	header('Location:packagelist.php');
	exit;
}

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

	$packagesObj->deleteRecord($_REQUEST['package_id'],$_REQUEST['status']);
	$successMsg = "package Deleted successfully";
}

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

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

$packagesDetails = $packagesObj->getAllRecords('*',''," ORDER BY package_id DESC ");

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

?>