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


<?php $this->load->view("admin/header"); ?>

<body>

  <?php $this->load->view("admin/side_topbar"); ?>

  <div id="wrapper">
    <div class="main-content">
      <div class="row small-spacing">
        <div class="col-xs-2"></div>
        <div class="col-xs-8">
          <form class="box-content" onsubmit="update_data(event)">
            <h4 class="box-title" id="header_peta">Ubah Username dan Password</h4>
            <div class="form-group">
              <label for="username">Username</label>
              <input type="text" class="form-control" id="username" placeholder="Masukkan Username" required value="<?= $cek_data->username ?>">
            </div>
            <div class="form-group">
              <label for="password">Password</label>
              <input type="password" class="form-control" id="password" placeholder="Masukkan Password" minlength="6" required>
            </div>
            <div class="form-group">
              <label for="konfirm_password">Konfirm Password</label>
              <input type="password" class="form-control" id="konfirm_password" minlength="6" placeholder="Masukkan Konfirm Password" required>
            </div>

            <!-- /.dropdown js__dropdown -->
            <div class="form-group text-center">
              <button type="submit" class="btn btn-primary btn-xs waves-effect waves-light">Ganti Username Dan Password</button>
            </div>

            <!-- /#flot-chart-1.flot-chart -->
          </form>
          <!-- /.box-content -->
        </div>
        <!-- /.col-xs-12 -->
        <div class="col-xs-2"></div>

        < <!-- /.col-xs-12 -->

      </div>
      <!-- /.row -->

      <?php $this->load->view('admin/footer') ?>

    </div>
    <!-- /.main-content -->
  </div>

  <?php $this->load->view('admin/scripts') ?>

  <script>
    function update_data(e) {
      e.preventDefault();
      var username = $('#username').val();
      var password = $('#password').val();
      var confirm_password = $('#konfirm_password').val();
      if (password != confirm_password) {
        toastr.error('Password Tidak Sama');
        // focus
        $('#password').focus();
      } else {

        $.ajax({
          url: server_url_api + "ganti_data_admin",
          type: 'POST',
          data: {
            username: username,
            password: password,
            nik: '<?= $cek_data->nik ?>',
            id_dinas : '<?= $cek_data->id_dinas ?>'
          },
          beforeSend: function(res) {
            // $('#modal_karyawan').modal('hide');
            block_ui("Update Data");
          },
          success: function(data) {
            $.unblockUI();
            // console.log(data);
            toastr.success('Berhasil Update Data');
            $("#password").val('');
            $("#konfirm_password").val('');
          },
          error: function(XMLHttpRequest, textStatus, errorThrown) {
            $.unblockUI();
            // console.log(errorThrown)
            // console.log(textStatus)
            const statusCode = XMLHttpRequest.status;
            const responseJSON = XMLHttpRequest.responseJSON;
            console.log(statusCode);
            console.log(responseJSON)
            if (statusCode != 500 || statusCode != 0) {
              toastr.error(responseJSON.message);
            } else {
              toastr.error("Jaringan atau server bermasalah, sila refresh kembali halaman");
            }


          }
        });
      }
    }
  </script>

</body>

<!-- Dibuat oleh Kicap Karan. https://www.kicap-karan.com -->

</html>