

<!DOCTYPE html>
<html lang="en">

<head>
  <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
  <meta name="description" content="">
  <meta name="author" content="">
  <meta name="theme-color" content="" />

  <title>BML Online Report</title>

  <!-- Custom fonts for this template-->
  <link href="<?php echo base_url('assets/template/backend/') ?>vendor/fontawesome-free/css/all.min.css" rel="stylesheet" type="text/css">
  <link href="https://fonts.googleapis.com/css?family=Nunito:200,200i,300,300i,400,400i,600,600i,700,700i,800,800i,900,900i" rel="stylesheet">

  <!-- Custom styles for this template-->
  <link href="<?php echo base_url('assets/template/backend/') ?>css/sb-admin-2.min.css" rel="stylesheet">
  <link href="<?php echo base_url('assets/template/backend/') ?>sweetalert/sweetalert.css" rel="stylesheet">

</head>

<body class="bg-gradient-success d-flex align-items-center min-vh-100">

  <div class="container">

    <!-- Outer Row -->
    <div class="row justify-content-center">

      <div class="col-xl-5 col-lg-6 col-md-8">

        <div class="card o-hidden border-0 shadow-lg">
          <div class="card-body p-0">
            <!-- Nested Row within Card Body -->
            <div class="row">

              <div class="col-lg-12 p-5">
                <div class="text-center">
                  <img src="<?php echo base_url(); ?>assets/images/bml.png" style="max-width:50%; margin-top:-10px; margin-bottom:10px; z-index: 9; position: relative;">
                  <hr />
                </div>
                <form class="user" id="loginForm">
                  <div class="form-group">
                    <input type="text" class="form-control form-control-user" name="username" placeholder="Username">
                  </div>
                  <div class="form-group">
                    <input type="password" class="form-control form-control-user" id="exampleInputPassword" name="password" placeholder="Password">
                  </div>
                  <br />
                  <button id="btnLogin" type="submit" class="btn btn-success btn-user btn-block">
                    Login
                  </button>
                  <br />
                  <div class="text-center">
                    <small class="font-italic text-success"> prepared by BML IT Division @2026
                    </small>
                  </div>
                </form>

              </div>
            </div>
          </div>
        </div>
      </div>

    </div>

  </div>

  <!-- Bootstrap core JavaScript-->
  <script src="<?php echo base_url('assets/template/backend/') ?>vendor/jquery/jquery.min.js"></script>
  <script src="<?php echo base_url('assets/template/backend/') ?>vendor/bootstrap/js/bootstrap.bundle.min.js"></script>

  <!-- Core plugin JavaScript-->
  <script src="<?php echo base_url('assets/template/backend/') ?>vendor/jquery-easing/jquery.easing.min.js"></script>

  <!-- Custom scripts for all pages-->
  <script src="<?php echo base_url('assets/template/backend/') ?>js/sb-admin-2.min.js"></script>
  <script src="<?php echo base_url('assets/template/backend/') ?>sweetalert/sweetalert.min.js"></script>

  <script type="text/javascript">
    var base_url = '<?= base_url() ?>';

    $('#loginForm').submit(function(e) {
      e.preventDefault();
      var data = $(this).serialize();
      $('#btnLogin').html('<i class="fa fa-spinner spinner"></i> Loading...');
      $.ajax({
        type: 'post',
        url: base_url + 'login/log_in',
        data: "submit=true&" + data
      }).done(function(res) {
        console.log(res);
        $('#btnLogin').html('Login');
        if (res == '1') {
          location.reload();
        } else if (res == '2') {
          swal("Maaf!", 'Proses registrasi Anda sedang diverifikasi.', 'error');
          $('#loginForm')[0].reset();
        } else {
          swal("Maaf!", 'Username/Password salah!', 'error');
          $('#loginForm')[0].reset();
        }
      }).fail(function(res) {
        alert('Login Fail');
        console.log(res);
      })
      return false;
    })

    $('#registerForm').submit(function(e) {
      e.preventDefault();
      var panjang_nik = document.getElementById('nik').value.length;
      if (!(panjang_nik == 16)) {
        swal("Maaf!", 'NIK tidak valid', 'error');
        return false;
      }

      var data = $(this).serialize();
      $('#btnRegister').html('<i class="fa fa-spinner spinner"></i> Loading...');
      $.ajax({
        type: 'post',
        url: base_url + 'login/register',
        data: "submit=true&" + data
      }).done(function(res) {
        console.log(res);
        $('#btnRegister').html('Daftar');
        if (res == '1') {
          swal({
            title: 'Pendaftaran Berhasil',
            text: 'Kami akan mengkonfirmasi data anda maksimal 1x24 jam.',
            type: 'success',
            closeOnConfirm: false
          }, function(isConfirm) {
            if (isConfirm) {
              location.reload();
            }
          })
        } else if (res == '2') {
          swal("Maaf!", 'Ada kesalahan. Password tidak sama', 'error');
        } else {
          swal("Maaf!", 'Ada kesalahan. Data anda sudah terdaftar sebelumnya', 'error');
        }
      }).fail(function(res) {
        alert('Login Fail');
        console.log(res);
      })
      return false;
    })

    function show_reg() {
      $('#loginForm').hide("slow");
      $('#registerForm').show("slow");
    }

    function show_log() {
      $('#loginForm').show("slow");
      $('#registerForm').hide("slow");
    }
  </script>

</body>

</html>