<?php
//共通
require_once '../../base/common.php';
require_once '../../util/combo.php';

$logger = new logger(basename(__FILE__));
$logger->info("=== ai908x_index_start ===");
//$logger->info('post', $_POST)

$assign_var["noeventClassHeader"] = "";
$assign_var["noeventClassBody"]   = "";

//メニュー画面から引数
$header = Array();
if ($_GET != null) {
  $header['p_mode'] = $_GET['p_mode'];
} else {
  foreach($_POST as $key => $val) {
    $header[$key] = $val;
  }
}
// ktktcd初期表示
if ($stringUtil->isEmpty($_SESSION[$GLOBALS['SYSTEM_NAME_EN']]["LGKTKTCD"])) {
  $header['ktktcd'] = '00';
} else {
  $header['ktktcd'] = $_SESSION[$GLOBALS['SYSTEM_NAME_EN']]["LGKTKTCD"];
}

try {
  //axm99情報
  $sql = "select * from axm99 where ktktcd = :ktktcd";
  $whereParams["ktktcd"] = $header['ktktcd'];
  $result = $dbutil->select($sql, $whereParams);
  if ($result == null) {
    $header['pkeflg'] = '';
    $header['pketa'] = '';
    $header['preflg'] = '';
    $header['precycl'] = '';
  } else {
    $header['pkeflg'] = $result[0]['pkeflg'];
    $header['pketa'] = $result[0]['pketa'];
    $header['preflg'] = $result[0]['preflg'];
    $header['precycl'] = $result[0]['precycl'];
  }
  // ログイン担当者情報
  $chgcd = $_SESSION[$GLOBALS['SYSTEM_NAME_EN']]["CHGCD"];
  $sql = "select * from afm08 where chgcd=:chgcd";
  $whereParams = array();
  $whereParams["chgcd"] = $chgcd;
  $result = $dbutil->select($sql, $whereParams);
  if ($result == null) {
    $dataList['chgcd'] = '';
    $dataList['chgnm'] = '';
    $dataList['chgpas'] = '';
  } else {
    $dataList = $result[0];
  }

  $assign_var["header"] = $header;
  $assign_var["data"] = $dataList;

} catch(userException $ue) {
  $dbutil->rollback();
  $assign_var["hasError"] = true;
  $assign_var["errorMsg"] = $ue->getMessage();
} catch(Exception $e) {
  $dbutil->rollback();

  $assign_var["hasError"] = true;
  $assign_var["errorMsg"] = $e->getMessage();

}

$assign_var["header"] = $header;
$assign_var["data"] = $dataList;

$logger->info('assign_var',$assign_var);

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

$logger->info("=== ai908x_index_end ===");
?>
