<?php 

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

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

// Logical section of page
$pagesObj =  new  pages();


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

	return true;
}

if ($_REQUEST['act']=="order"){
	$pagesObj->changeOrder($_REQUEST['page_id'],$_REQUEST['page_order'],$_REQUEST['position']);
	header('Location:pagelist.php');
	exit;
}

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

	$pagesObj->deleteRecord($_REQUEST['page_id'],$_REQUEST['status']);
	$successMsg = "page Deleted successfully";
}

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

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

$pagesDetails = $pagesObj->getAllRecords('*','page_parent =0'," ORDER BY page_order ");

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

?>