<?php 
include_once('../libs/main.php');
$moduleObj = new module_pages();

if(!isset($_SESSION['admin_email_address']) || $_SESSION['admin_email_address']=='' || !isset($_SESSION['admin_id']) || $_SESSION['admin_id']==''){
	header('location:admin-login.php');
	exit;
}
$admin_filename=basename($_SERVER['SCRIPT_FILENAME']);

if($_SESSION['admin_email_address']!= ''){	

	if($_SESSION['admin_access']!='Full'){
		$admin_access = explode(',',$_SESSION['admin_access']);
                
                $select =array('m.*','md.*');
                $joinTables=array('tbl_modules md');
                $joinFields=array('md.id = m.module_id');
                $joinTypes=array('INNER');
                $where = array('page=' => $admin_filename);
                $data=array('where'=>$where,'joinTables'=>$joinTables,'joinFields'=>$joinFields,'joinTypes'=>$joinTypes,'fields'=>$select);
                
                $modules = $moduleObj->fromFields($data);
                if(isset($modules) && !empty($modules)){
			if(!in_array($modules->module_id,$admin_access)){				
				header("Location: access_denied.php");
				exit;
			}
		}
	}	
}else {	
	header("Location: index.php");
	exit;
}
?>