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

$logger = new logger(basename(__FILE__));
$logger->info(" ===af904x_search_start=== ");

$response["status"] = "OK";

$listutil = null;

// 再ページ読込用
$header = Array();
foreach($_POST as $key => $val) {
  $header[$key] = $val;
}
$logger->info("header", $header);

//コンボボックス作成
$listutil = null;
$listutil = new getListUtil();
$assign_var["listModfr"] = $cbo_modfr;
$assign_var["listHtcls"] = $cbo_htcls;
$assign_var["listPlhcls"] = $cbo_plhcls;
$assign_var["listPaycls"] = $cbo_paycls;
$assign_var["listMpcls"] = $cbo_mpcls;
$assign_var["listCdcls"] = $cbo_cdcls;
$assign_var["listMres"] = $cbo_mres;
$assign_var["listMpay"] = $cbo_mpay;
$assign_var["listMsu"] = $cbo_msu;

//POPUP
$assign_var["hasPopChgcd"]="1";
$assign_var["hasPopMcd"]="1";

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

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

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

  // SQL実行
  $sql = file_get_contents("./sql/search.sql");
  $result = $dbutil->select($sql, $whereParams);

  if ($result == null) {
    // 1:新規, 2:修正, 3:削除
    $header["smode"] = '1';
    $assign_var["isNoData"] = true;
    $dataList = Array(
      "modfr" => "0",
      "cfrt"=> ""
    );
    $assign_var["data"] = $dataList;
  } else {
    $dataList = $result[0];
    // 1:新規, 2:修正
    $header["smode"] = '2';
    $assign_var["isNoData"] = false;
    $assign_var["data"] = $dataList;
  }

  $logger->info('head', $header);
  $assign_var["header"] = $header;

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

}

//$logger->info("smarty", $assign_var);

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

$smarty->display("index");

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