<?php
$cate_id = "mnu_cust"; //현재 메뉴 ID 필수!!!
include_once "{$_SERVER['DOCUMENT_ROOT']}/common.inc.php";
include_once _ADM_INC_PATH_ ."/auth_check.php";

include _ADM_INC_PATH_ ."/header.html";

$custObj = new Cust();
$cinfo = array();
$smnu_txt = "추가";
if( isset($_REQUEST['cust_id']) ){
  $cinfo = $custObj->getCust($_REQUEST['cust_id']);
  $smnu_txt = "수정";
}
?>

        <div id="cmd_bar" class="mb-2">
          <div class="h4"><i class="bi bi-files-alt"></i> 소속 <?=$smnu_txt?></div>
          <div class="text-right">
          </div>
        </div>

        <form method="post" enctype="multipart/form-data" id="aform" class="fadmin" action="###" onsubmit="return false;">
          <div class="fld-block">
            <label for="cust_id">소속 코드 </label>
            <div>
              <input type="text" name="cust_id" id="cust_id" value="<?=$cinfo['cust_id']?>" class="form-control inline" <?=($cinfo)?"readonly":""?>>
              <small class="text-info"><?=cUtil\Mlang::getText("※ 소속 코드는 {$GLOBALS['_varsBaseCode']['cust_id_len']}자리 이상, 영문자/숫자만으로 구성되어야 합니다.")?></small>
            </div>
          </div>
          <div class="fld-block">
            <label>소속명 </label>
            <div>
              <input type="text" name="cust_name" value="<?=$cinfo['cust_name']?>" class="form-control inline">
            </div>
          </div>
          <div class="fld-block">
            <label>소속명 (정식)</label>
            <div>
              <input type="text" name="cust_fullname" value="<?=$cinfo['cust_fullname']?>" class="form-control inline">
            </div>
          </div>
          <div class="fld-block">
            <label>담당자 </label>
            <div>
              <input type="text" name="cust_charger" value="<?=$cinfo['cust_charger']?>" class="form-control inline">
            </div>
          </div>
          <div class="fld-block">
            <label>연락처 </label>
            <div>
              <input type="text" name="cust_phone" value="<?=$cinfo['cust_phone']?>" class="form-control inline">
            </div>
          </div>
          <div class="fld-block">
            <label>메일 </label>
            <div>
              <input type="text" name="cust_mail" value="<?=$cinfo['cust_mail']?>" class="form-control inline">
            </div>
          </div>
          <div class="fld-block">
            <label>승인여부 </label>
            <div class="form-inline">
              <select name="cust_status" data-defval="<?=$cinfo['cust_status']?>" class="form-control">
                <?=getSelectOptions(array_reverse($GLOBALS['_varsCommonStatus'],true))?>
              </select>
            </div>
          </div>
          <?php if( $cinfo ){?>
          <div class="fld-block">
            <label>등록일 </label>
            <div class="form-inline"><?=getDT_datetime($cinfo['reg_date'])?></div>
          </div>
          <div class="fld-block">
            <label>수정일 </label>
            <div class="form-inline"><?=getDT_datetime($cinfo['mod_date'])?></div>
          </div>
          <?php }?>
          <div class="text-center mt-4">
            <a href="./cust_list.php" class="btn btn-success px-5">리스트</a>
            <button type="submit" class="btn btn-primary px-5"><?=$cate_title?> <?=$smnu_txt?></button>
          </div>
          <?=hidden_input('cust_oid', $cinfo['cust_id'])?>
          <?=csrf_input('putCust')?>
        </form>

<?php
include _ADM_INC_PATH_ ."/footer.html";
?>

<script>
  jQuery("#aform").on("submit",function(){
    var formdata = new FormData(document.forms['aform']);
    formdata.append("mode","putCust");

    ajax_form({
      url: "./cust.ajax.php",
      type: "POST",
      data: formdata,
      success: function (data) {
        if (!data.code) {
          kuls_alert(data.mesg);
          return;
        }
        kuls_alert('<?=cUtil\Mlang::getText("등록 되었습니다.")?>',function(){
          location.href = "<?=_ADM_URL_."/cust/"?>";
        });
      },
      error: function (request, status, error) {
        kuls_alert(error.message);
      }
    });
  });
</script>