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

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

// Logical section of news
$newsObj =  new  news();

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

	return true;
}

if ($_REQUEST['act']=="order"){
	$newsObj->changeOrder($_REQUEST['news_id'],$_REQUEST['news_order'],$_REQUEST['position']);
	header('Location:newslist.php');
	exit;
}

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

	$newsObj->deleteRecord($_REQUEST['news_id'],$_REQUEST['status']);
	$successMsg = "news Deleted successfully";
}

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


$newsDetails = $newsObj->getAllRecords('*',''," ORDER BY news_date ASC ");

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