<?php
include_once "{$_SERVER['DOCUMENT_ROOT']}/common.inc.php";
?>
<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <?php include _ADM_INC_PATH_ ."/header_common.html"?>
</head>
<body class="">
  <div id="login">
    <div id="login-box" class="border border-secondary">
      <div id="login-info"></div>
      <div id="login-form">

        <!-- Login -->
        <form method="post" action="###" onsubmit="return false" name="alogin" id="alogin" class="w-75">
          <h3>Admin Login</h3>
          <div class="fld-block">
            <label>Admin ID :</label>
            <input type="text" name="admin_id" class="form-control" placeholder="관리자 아이디" required>
          </div>
          <div class="fld-block">
            <label>Admin PW :</label>
            <input type="password" name="admin_pw" class="form-control" placeholder="관리자 비밀번호" required>
          </div>
          <div class="fld-block">
            <button type="submit" class="btn btn-primary btn-block btn-lg btn-login">Log in</button>
          </div>
          <?php /**/ ?>
          <div class="fld-block">
            <button type="button" class="btn btn-success btn-block btn-join">Join >> </button>
          </div>
          <?php /**/ ?>
          
        <?=csrf_input('adminLogin')?>
        </form>
        <!-- Login //-->

        <!-- Join -->
        <form method="post" action="###" onsubmit="return false" name="ajoin" id="ajoin" class="w-75 d-none">
          <h3>Admin Join</h3>
          <h6>(You can log in after approval.)</h6>
          <div class="fld-block">
            <label>Admin ID :</label>
            <input type="text" name="admin_id" class="form-control" placeholder="아이디는 <?=$GLOBALS['_varsBaseCode']['id_len']?>자리이상 (영문/숫자)" required>
          </div>
          <div class="fld-block d-flex">
            <div>
              <label>Admin PW :</label>
              <input type="password" name="admin_pw" class="form-control" placeholder="비밀번호는 <?=$GLOBALS['_varsBaseCode']['pw_len']?>자리이상" required>
            </div>
            <div>
              <label>Admin PW Retype :</label>
              <input type="password" name="admin_pwf" class="form-control" placeholder="특수,대소,숫자 포함" required>
            </div>
          </div>
          <div class="fld-block">
            <label>Admin Name :</label>
            <input type="text" name="admin_name" class="form-control" placeholder="관리자명 필수" required>
          </div>
          <div class="fld-block">
            <button type="submit" class="btn btn-primary btn-block btn-lg btn-join">Join</button>
          </div>
          <div class="fld-block">
            <button type="button" class="btn btn-success btn-block btn-login">Log in >></button>
          </div>
        <?=csrf_input('adminJoin')?>
        </form>
        <!-- Join //-->

      </div>
    </div>
  </div>
</body>
</html>
<?php include _ADM_INC_PATH_ ."/footer_common.html"?>
<script>
  jQuery("#alogin .btn-join").on("click",function(){
    jQuery("#alogin").addClass("d-none");
    jQuery("#ajoin").removeClass("d-none");
  });
  jQuery("#ajoin .btn-login").on("click",function(){
    jQuery("#ajoin").addClass("d-none");
    jQuery("#alogin").removeClass("d-none");
  });

  jQuery("#alogin").on("submit",function(){
    var formdata = new FormData(document.forms['alogin']);
    formdata.append("mode","adminLogin");

    ajax_form({
      url: "<?=_ADM_INC_URL_?>/common.ajax.php",
      type: "POST",
      data: formdata,
      success: function (data) {
        if (!data.code) {
          kuls_alert(data.mesg);
          return;
        }
        location.reload();
      },
      error: function (request, status, error) {
        kuls_alert(error.message);
      }
    });
  });

  jQuery("#ajoin").on("submit",function(){
    var formdata = new FormData(document.forms['ajoin']);
    formdata.append("mode","adminJoin");

    ajax_form({
      url: "<?=_ADM_INC_URL_?>/common.ajax.php",
      type: "POST",
      data: formdata,
      success: function (data) {
        if (!data.code) {
          kuls_alert(data.mesg);
          return;
        }
        kuls_alert('<?=cUtil\Mlang::getText("신청되었습니다. 승인 후 사용가능합니다.")?>');
      },
      error: function (request, status, error) {
        kuls_alert(error.message);
      }
    });
  });
</script>