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

/**
 * af216x共通カスタム関数
 */

function doReg($dbutil, $data){
  $logger = new logger(basename(__FILE__));
    global $stringUtil;
$logger->info("doReg>>",$data);
    $ret_array = array(
      "ret" => "0", //0:OK, -9:プリンタ登録エラー
      "msg" => "",
    );
    $ret = '0';
    $msg = "";

    try {
      $cnt = 0;

      $header = $data["header"][0];

      foreach($data["data"] as $detail) {

        //変更あれば 更新
        if($stringUtil->nvl($detail["mfax"],'NULL') != $stringUtil->nvl($detail["org_mfax"],'NULL')
        || $stringUtil->toNumber($stringUtil->nvl($detail["htpnt1"],'-999999999')) != $stringUtil->toNumber($stringUtil->nvl($detail["org_htpnt1"],'-999999999'))
        || $stringUtil->toNumber($stringUtil->nvl($detail["htpnt2"],'-999999999')) != $stringUtil->toNumber($stringUtil->nvl($detail["org_htpnt2"],'-999999999'))
        || $stringUtil->toNumber($stringUtil->nvl($detail["htlmt1"],'-999999999')) != $stringUtil->toNumber($stringUtil->nvl($detail["org_htlmt1"],'-999999999'))
        || $stringUtil->toNumber($stringUtil->nvl($detail["htlmt2"],'-999999999')) != $stringUtil->toNumber($stringUtil->nvl($detail["org_htlmt2"],'-999999999'))
        ) {
          $cnt = $cnt + 1;

          //afw53 Insert
          $sql  = file_get_contents("./sql/udpate.sql");
          $whereParams = array();
          $whereParams["mcd"]    = $detail["mcd"];
          $whereParams["mfax"]   = $detail["mfax"];
          $whereParams["htpnt1"] = $stringUtil->toNumber($detail["htpnt1"]);
          $whereParams["htpnt2"] = $stringUtil->toNumber($detail["htpnt2"]);
          $whereParams["htlmt1"] = $stringUtil->toNumber($detail["htlmt1"]);
          $whereParams["htlmt2"] = $stringUtil->toNumber($detail["htlmt2"]);
          $whereParams["chgcd"]  = $_SESSION[$GLOBALS['SYSTEM_NAME_EN']]["CHGCD"];
          $logger->info("upate",$whereParams);
          $dbutil->update($sql,$whereParams);
        }
      }

      endReg:

      if($cnt > 0) {
        $dbutil->commit();
      }

    } catch(userException $ue) {
      $ret = '-999';
      $msg = $ue->getErrorMessage();
      $dbutil->rollback();
    } catch(Exception $e) {
      $ret = '-999';
      $msg = $e->getMessage();
      $dbutil->rollback();
    }

    $ret_array["ret"] = $ret;
    $ret_array["msg"] = $msg;

    return $ret_array;
  }

?>
