<?php
namespace Empire\Legacy;
use Empire\Core\User;
use Empire\Core\Permission;
class Menu {
public static function getSecurePages() {
$getMenu = db::prepare("SELECT SP . * FROM SECUREPAGE SP LEFT JOIN PAGE_CATEGORY PC ON PC.PACA_ID = SP.PACA_ID WHERE SEPA_SECURE=1 ORDER BY SP.PACA_ID, SP.SEPA_ORDER");
return db::fetchArrayOfObjects($getMenu);
}
public static function getPageInfo($intPageID) {
$info = db::prepare("SELECT * FROM SECUREPAGE WHERE SEPA_ID=?", $intPageID);
return db::fetchObject($info);
}
/**
* get the info for the side menu bar
*
* @param int $intUserID
* @return array of pages
*/
public static function getSideMenu($intUserID) {
$user = User::load(array($intUserID));
$pages = Permission::getUserAccess($user, cint_PERMISSION_TYPE_PAGEVIEW);
if(Permission::hasAccess($user, array(cint_PERMISSION_TYPE_SPECIFIC => cint_PERMISSION_DEVELOPER))) {
$getMenu = db::prepare("SELECT * FROM SECUREPAGE AS SP, PAGE_CATEGORY AS PC WHERE SP.`PACA_ID`=PC.`PACA_ID` AND SP.`SEPA_SHOW`=1 AND SP.`SEPA_SECURE`=1 AND SP.`SEPA_CHILDOF` IS NULL ORDER BY PC.`PACA_ORDER`,SP.`PACA_ID`,SP.`SEPA_ORDER`");
} else {
$getMenu = db::prepare("SELECT * FROM SECUREPAGE AS SP, PAGE_CATEGORY AS PC WHERE SP.`PACA_ID`=PC.`PACA_ID` AND SP.`SEPA_SHOW`=1 AND SP.`SEPA_SECURE`=1 AND SP.`SEPA_CHILDOF` IS NULL AND SEPA_ID IN ? ORDER BY PC.`PACA_ORDER`,SP.`PACA_ID`,SP.`SEPA_ORDER`", $pages);
}
if(db::numRows($getMenu) > 0) {
return db::fetchArrayOfObjects($getMenu);
} else {
return array("No secure access.");
}
}
public static function getMenuChildren($strPageName, $intUserID) {
$user = User::load(array($intUserID));
$pages = Permission::getUserAccess($user, cint_PERMISSION_TYPE_PAGEVIEW);
$getMenu = db::prepare("SELECT * FROM SECUREPAGE AS SP, PAGE_CATEGORY AS PC WHERE SP.`PACA_ID`=PC.`PACA_ID` AND SP.`SEPA_CHILDOF` IS NOT NULL AND SEPA_ID IN ? AND SP.`SEPA_CHILDOF`=? ORDER BY SP.`PACA_ID`,SP.`SEPA_ORDER`", $pages, $strPageName);
if(db::numRows($getMenu) > 0) {
return db::fetchArrayOfObjects($getMenu);
}
return FALSE;
}
public static function getTopMenu() {
$getMenu = db::prepare("SELECT * FROM SECUREPAGE AS SP, PAGE_CATEGORY AS PC WHERE SP.`PACA_ID`=PC.`PACA_ID` AND SP.`SEPA_SECURE`=0 AND SP.`SEPA_CHILDOF` IS NULL ORDER BY PC.`PACA_ORDER`, SP.`SEPA_ORDER`");
return db::fetchArrayOfObjects($getMenu);
}
/**
* get the info for the unsecure side menu bar
*
* @param string $strPageName
* @return bool|array
*/
public static function getSideMenuCategories($strPageName) {
$get = db::prepare("SELECT PC.PACA_ID FROM PAGE_CATEGORY AS PC, SECUREPAGE AS SP WHERE SP.`SEPA_PAGE`=? AND SP.PACA_ID = PC.PACA_ID", $strPageName);
$getCategory = db::fetchObject($get);
if(is_object($getCategory)) {
$getMenu = db::prepare("SELECT * FROM PAGE_SUBCATEGORY WHERE PACA_ID=? ORDER BY SCAT_ORDER ASC", $getCategory->PACA_ID);
return db::fetchArrayOfObjects($getMenu);
}
return false;
}
/**
* get the info for the unsecure side menu bar
*
* @param int $intSCATid
* @return array of pages
*/
public static function getCategoryContentsUnsecure($intSCATid) {
$getMenu = db::prepare("SELECT * FROM SECUREPAGE WHERE SCAT_ID =? AND SEPA_SHOW=1 ORDER BY SEPA_ORDER ASC", $intSCATid);
$arr = db::fetchArrayOfObjects($getMenu);
return $arr;
}
public static function getMenuChildrenUnsecure($strPageName) {
$getMenu = db::prepare("SELECT * FROM SECUREPAGE AS SP, PAGE_CATEGORY AS PC WHERE SP.`PACA_ID`=PC.`PACA_ID` AND SP.`SEPA_SECURE`=0 AND SP.`SEPA_CHILDOF` IS NOT NULL AND SP.`SEPA_CHILDOF`=? ORDER BY PC.`PACA_ID`,SP.`SEPA_ORDER`", $strPageName);
if(db::numRows($getMenu) > 0) {
return db::fetchArrayOfObjects($getMenu);
}
return FALSE;
}
public static function getPacaId($strPageName){
$getPaca = db::prepare("SELECT * FROM SECUREPAGE WHERE SEPA_PAGE=?", $strPageName);
return db::fetchObject($getPaca);
}
}
?>