<?php 

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

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

// Logical section of gallery
$gallerysObj =  new  gallerys();


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

	return true;
}

if ($_REQUEST['act']=="order"){
	$gallerysObj->changeOrder($_REQUEST['gallery_id'],$_REQUEST['gallery_order'],$_REQUEST['position']);
	header('Location:gallerylist.php');
	exit;
}

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

	$gallerysObj->deleteRecord($_REQUEST['gallery_id'],$_REQUEST['status']);
	$successMsg = "gallery Deleted successfully";
}

if(isset($_REQUEST['submit'])){
	$act_val = $_REQUEST['action_val'];
	$gallerysObj->allAction($act_val,$_POST['check']);
	
	
	if($act_val=='delete_all'){
		$successMsg = "selected gallerys deleted successfully";
	}else  if($act_val=='activate_all'){
		$successMsg = "selected gallerys activated successfully";
	}else if($act_val=='inactivate_all'){
		$successMsg = "selected gallerys inactivated successfully";
	}
}
$searchStr = '';
if(isset($_POST['search_submit']) && $_POST['search_input']!=''){
	$searchStr = " gallery_title LIKE '%".$_POST['search_input']."%'";
}

$gallerysDetails = $gallerysObj->getAllRecords('*',$searchStr," ORDER BY gallery_order ");

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

?>