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

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

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

$header = Array(
  'ktktcd' => $_SESSION[$GLOBALS['SYSTEM_NAME_EN']]["LGKTKTCD"]
);
$assign_var["header"] = $header;

$logger->info("header", $header);

//コンボボックス作成
$listutil = null;
$listutil = new getListUtil();

//POPUP
$assign_var["listSearchKbn"] = $cbo_searchkbn;
$assign_var["hasPopChgcd"] = "1";

$assign_var["hasPopAf08m"] = "1";

// 初期表示
$dataList = Array(
);
array_push($dataList, $obj);

try {

  //保有権利の名称取得
  $dmyArray = getChgatnm( $dbutil, $logger);

  foreach($dmyArray as $key => $val) {
    $assign_var["header"][$key] = $val;
  }
  $logger->info('$assign_var', $assign_var);

  // sqlの条件を設定する
  $whereParams["ktktcd"] = $header["ktktcd"];

  // SQL実行
  $sql = file_get_contents("./sql/callTBL_Axm99.sql");
  $result = $dbutil->select($sql, $whereParams);
  $logger->info('result', $result);
  if ($result == null) {
    $assign_var["isNoData"] = true;

  } else {
    $dataList = $result[0];

    $assign_var["isNoData"] = false;
    foreach($dataList as $key => $val) {
      $assign_var["header"][$key] = $val;
    }
  }

} 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();

}

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

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


//oriexから
function getChgatnm($dbutil, $logger) {
    global $stringUtil;
  
    // SQL実行
    $sql = file_get_contents("./sql/getChgatnm.sql");
    $result = $dbutil->select($sql, $whereParams);
    $logger->info('result', $result);
    $cnt = 0;
    if ($result == null) {
      $assign_var["isNoData"] = true;
  
    } else {
      $assign_var["isNoData"] = false;
      //名称取得前チェック
      foreach($result as $k => $detail) {
        $cnt++;
        $dataList = $detail;
        if($cnt > 10){
          throw new UserException("E0002", "権限の登録が不正です。(権限は最大で10個までです。)" ,null);
        }
  
        $search = array("00","01","02","03","04","05","06","07","08","09");
        $ret = in_array($dataList['scls1'],$search);
        if (!$ret) {
          throw new UserException("E0002", "権限の登録が不正です。(権限は00～09で登録して下さい。)" ,null);
        }
        $assign_var["data"] = $dataList;
        $logger->info('$assign_var', $assign_var);
      }
  
      //名称取得
      $cnt = 0;
      foreach($result as $k => $detail) {
        
        //森川で変更
        if(substr($detail["scls1"],0,1) == '0') {
          $wchgat = 'chgat' . substr($detail["scls1"],1,1);
          $logger->info("meke_chgatnm1",$wchgat);
        } else {
          $wchgat = 'chgat' . $detail["scls1"];
          $logger->info("meke_chgatnm2",$wchgat);
        }
        $chgat = $wchgat;
  
        $logger->info('$chgat', $chgat);
        $logger->info('$detail[$cnt]', $detail[$cnt]);

        $chgatDatalist[$chgat] = $detail['nm'];
        $cnt++;
        $logger->info('$chgatDatalist', $chgatDatalist);
      }
    }
  
    return $chgatDatalist;
  }
  

?>
