<?php 
session_start();

error_reporting(E_ALL ^ (E_NOTICE | E_WARNING));
$session_id_user = (isset($_SESSION['id_siswa'])) ? $_SESSION['id_siswa'] : "";

if($session_id_user!=''){
  echo"<script>document.location.href='index.php'</script>";
}else{

include"inc/conn.php";
?>
<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="utf-8">
  <meta content="width=device-width, initial-scale=1.0" name="viewport">

  <title>Login Page - <?php echo $rsw['judul_modul'];?></title>
  <meta content="" name="description">
  <meta content="" name="keywords">

  <?php 
  include"inc/style.php";
  ?>
  
</head>

<body>

  <?php include"inc/menu.php";?>

  
  <!-- ======= Hero Section ======= -->
  <section id="hero" class="hero d-flex align-items-center">

    <div class="container">
      <div class="row">
        
        <div class="col-lg-5 hero-img d-none d-sm-block" data-aos="zoom-out" data-aos-delay="200" style="text-align:center;">
          <img src="assets/img/logosanggulpolos.png" class="img-fluid" alt="" style="margin-top:30px;" width="60%">
        </div>
        
        <div class="col-lg-7 d-flex flex-column justify-content-center">
          <h1 data-aos="fade-up">Ajar Sanggul Jawa</h1>
          
          
          <h2 data-aos="fade-up" data-aos-delay="400"><i>Login menggunakan akun anda</i></h2>
          
          <br>
          <div data-aos="fade-up" data-aos-delay="600" style="margin-top:20px;">

              <div class="row gy-4">

                <div class="col-md-12">
                  <input id="username" type="text" onkeyup="cekenter()" class="form-control" placeholder="Username" style="padding:12px;font-size:16px;font-weight:700;color:#c2326f;" required>
                </div>

                <div class="col-md-12">
                  <input id="password" type="password" onkeyup="cekenter()" name="name" class="form-control" placeholder="Password" style="padding:12px;font-size:16px;font-weight:700;color:#c2326f;" required>
                  

                  <div id="message" style="margin-top:10px;background:#faf5f9;"></div>
                  <div class="text-center loader" id="loader" style="display:none;">
                    <div class="spinner-border text-primary" role="status" style="margin-top:10px;">
                      <span class="sr-only"></span>
                    </div>
                  </div>
                  
                  <button id="tombollogin" onclick="masuk()" class="tombollogin btn-success scrollto d-inline-flex align-items-center justify-content-center align-self-center" style="width:100%;padding:13px;background:#c2326f;color:white;border:2px solid #c2326f;">
                    <span>Login Siswa</span>
                    <i class="bi bi-arrow-right"></i>
                  </button>
                
                </div>

                

              </div>


            <div class="text-center text-lg-start">
              
            </div>
          </div>
        </div>
        
      </div>
      
      <br><br>

      <div class="row" data-aos="fade-up" data-aos-delay="800">
        <div class="col-lg-12 d-flex flex-column justify-content-center">
            <div class="col-md-12" style="text-align:center;padding-top:30px;color:#c2326f;">
              <?php include"inc/footer.php";?>
            </div>
        </div>
      </div>


    </div>

  </section><!-- End Hero -->


  <?php include"inc/script.php";?>
  <script src="assets/js/jquery.min.js"></script>
  <script type='text/javascript'>
    
    function cekenter(e){
      if(event.keyCode===13){
        masuk()
      }
    }

    function masuk(){
      
      $(".loader").show();
      $(".tombollogin").hide();
      var username = document.getElementById('username').value;
      var password = document.getElementById('password').value;  

      $.ajax({
        url: 'ajax/login.php',
        type: 'POST',
        data: {
          username: username,
          password: password,
        },
        success: function(response){ 
          if(response == 1){
            msg = '<div class="alert alert-success" role="alert"><i class="fa fa-check"></i> &nbsp; Login berhasil, mengalihkan ...</div>'
            $("#message").html(msg);
            $("#tombollogin").hide();
            $(".loader").hide();
            window.location = "index.php";
          }else{
            msg = '<div class="alert alert-danger" role="alert"><i class="fa fa-exclamation-circle"></i> &nbsp; Username/Password salah !</div>'
            $("#message").html(msg);
            $(".loader").hide();
            $(".tombollogin").show();
          }
          
        }
      });
    
    }

  </script>

</body>

</html>
<?php }?>