<?php
//共通
require_once '../../base/common.php';
$logger = new logger(basename(__FILE__));
$logger->info("===menu_start===");

try {
  global $dbutil;
  $valueUtil = new getValueUtil();
  global $stringUtil;

  $header = array();
  //axm993a権限取得
  $whereParams = array();
  $sql = file_get_contents("./sql/menu01.sql");
  $menus = $dbutil->select($sql, $whereParams);
  $logger->info("menu>>",$menus);

  if ($menus != null) {
    // apid キーの配列にする.
    foreach($menus as $value) {
      $key = $value["apid"];
      $menuarray[$key] = $value;
      unset($value);
    }
    $assign_var["menus"] = $menuarray;
  }


  //menuはurl部分で分ける。一応ファイルの存在確認はしておく。
  $menupath_tpl = "./templates/menu_".$GLOBALS['HOSP_SUB_DIR_ORG'].".tpl";
  $menupath_js =  "./templates/menu_".$GLOBALS['HOSP_SUB_DIR_ORG']."_js.tpl";
  $sys_menu = "menu_".$GLOBALS['HOSP_SUB_DIR_ORG'];

$logger->info("menupath_tpl",$menupath_tpl);
$logger->info("menupath_js ",$menupath_js);

  if(file_exists($menupath_tpl) && file_exists($menupath_js)) {
    $menu = $sys_menu;
  } else {
    $menu = "menu01";
  }
    
$logger->info("menu=",$menu);

  $assign_var["chgcd"]  = $_SESSION[$GLOBALS['SYSTEM_NAME_EN']]["CHGCD"];
  $assign_var["ipaddress"] = $_SESSION[$GLOBALS['SYSTEM_NAME_EN']]["IPADDRESS"];

} catch(userException $ue) {
  $retData["code"]  = $ue->getErrorCode();
  $retData["msg"]   = $ue->getErrorMessage();

  $response["status"] = "NG";
  $response["data"]   = $retData;

  $dbutil->rollback();

} catch(Exception $e) {
  $response["status"] = "NG";
  $response["data"]   = $e->getMessage();

  $dbutil->rollback();
}



//Smartyへアサイン
$smarty->assign($assign_var);

$smarty->display($menu);

$logger->info("=== end ===");

?>
