<?php 
session_start();
 if(isset($_SESSION['_session']['user']) ){
   header("location: index/panel/dashboard.php");
   exit;
 }
?>
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" type="text/css" href="../css/style.css">
 <link rel="icon" type="image/png" href="../images/Atommed.png">

  <title>Atommed</title>

<style type="text/css">
  /* Set a style for all buttons */
button {
  background-color: #04AA6D;
  color: white;
  padding: 14px 20px;
  margin: 8px 0;
  border: none;
  cursor: pointer;
  width: 100%;
  border-radius: 6px;
}

button:hover {
  opacity: 0.8;
}

</style>
</head>
<body style="background-image: url(../images/forest.jpg);background-repeat: no-repeat;">



<!-- START Modali i parë -->
<div id="id01" class="modal" >  
  <div class="modal-content animate">
    <div class="imgcontainer">
      <img src="../images/Atommed.png" alt="Avatar" class="avatar">
    </div>

    <div class="container">
      
      <label for="uname"><b>Përdoruesi</b></label>
      <input type="text" placeholder="Shkruaj perdoruesin" id="txtuser" name="perdoruesi">

      <label for="psw"><b>Fjalëkalimi</b></label>
      <input type="password" placeholder="Shkruani Fjalëkalimin" id="txtpass" name="fjalekalimi">
        
      <button type="button" id="btnlogin" value="login" name="login_user">Kyçu</button>

    </div>

    <div class="alert hidden informasi" role="alert" style="margin-top: 12px; padding: 0.75rem 1.25rem;"></div>
  </div>
    <!-- jQuery -->
    <script  type="text/javascript" src="index/panel/plugins/jquery/jquery.min.js"></script>
    <script  type="text/javascript" src="index/panel/js/sha256.js"></script>

    <script>
            document.getElementById('id01').style.display='block';
    var input = document.getElementById("txtpass");
    input.addEventListener("keyup", function(event) {
        if (event.keyCode === 13) {
            event.preventDefault();
            document.getElementById("btnlogin").click();
        }
    });
    var input = document.getElementById("txtuser");
    input.addEventListener("keyup", function(event) {
        if (event.keyCode === 13) {
            event.preventDefault();
            document.getElementById("btnlogin").click();
        }
    });
    </script>

      

</div>
<!-- END Modali i parë -->


<script type="text/javascript">
    
 $(document).ready(function(){
 $("#btnlogin").click(function(){
 var ajax = {
 user : $("#txtuser").val(),
 password : sha256($("#txtpass").val())
 }
 $.ajax({
 url: "https://atommed.net/service2/api/login",
 type: "POST",
 data: ajax,
 success: function(data, textStatus, jqXHR)
 {
 var ajax = {
 data : data
 }
 $.ajax({
 url: "index/set_authenticate.php",
 type: "POST",
 data: ajax,
 success: function(data, textStatus, jqXHR)
 {
 var data = jQuery.parseJSON(data);
 var red= data.url;
 window.location.replace(red);
 return false; 

 },
 error: function (request, textStatus, errorThrown) {
 console.log(request);
 }
 });
 },
 error: function (request, textStatus, errorThrown) {
  $(".informasi").removeClass("hidden").addClass('alert-danger').html(request.responseJSON.message);
    // $(".informasi").effect( "shake", {  times: 2, distance: 7}, 800);
    }
   });
  });
 });
</script>

</body>
</html>
