<?php 
session_start();
if(isset($_SESSION['loggedin_id']))
{
   header("location:dashboard.php");
} 

include 'config.php'; 

 $imgLink = "";

    function get_company_datas($id=0){
      ini_set('display_errors', '1');
      ini_set('display_startup_errors', '1');
      error_reporting(E_ALL);
      include("config.php");
      $query = "SELECT * from company where id <> 0 LIMIT 1";
      $run = mysqli_query($conn, $query);
      $res=mysqli_fetch_assoc($run);
      return $res;
    }
    $company_data = get_company_datas();
      $location = "../".$company_data['location'];
      $img = explode(',', $company_data['logo']);
      $imgLink = 'feedback/'.$location.'/'.$img[0];
?>
<!doctype html>
<html lang="en">

<head>
    <title>Login Panel</title>
    <!--== META TAGS ==-->
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <!--== FAV ICON ==-->
    <link rel="shortcut icon" href="images/fav.ico">

    <!-- GOOGLE FONTS -->
    <link href="https://fonts.googleapis.com/css?family=Nunito+Sans:400,600,700" rel="stylesheet">

    <!-- FONT-AWESOME ICON CSS -->
    <link rel="stylesheet" href="css/font-awesome.min.css">

    <!--== ALL CSS FILES ==-->
    <link rel="stylesheet" href="css/style.css">
    <link rel="stylesheet" href="css/mob.css">
    <link rel="stylesheet" href="css/bootstrap.css">
    <link rel="stylesheet" href="css/materialize.css" />

    <!-- HTML5 Shim and Respond.js IE8 support of HTML5 elements and media queries -->
    <!-- WARNING: Respond.js doesn't work if you view the page via file:// -->
    <!--[if lt IE 9]>
  <script src="js/html5shiv.js"></script>
  <script src="js/respond.min.js"></script>
  <![endif]-->
  
  <style type="text/css">
  label{
      color: white !important;
  }
  .blog-login-in{
    text-align: center !important;
  }

      /* MODAL STYLING */
      #errorMsgModal, #successrMsgModal {
         display: none; /* Hidden by default */
         position: absolute; /* Stay in place */
         z-index: 1; /* Sit on top */
        padding-bottom: 100px;
        padding-top: 100px;
         left: 0;
         top: 0;
         width: 100%; /* Full width */
         height: 100%; /* Full height */
         overflow: auto; /* Enable scroll if needed */
         background-color: rgb(0,0,0); /* Fallback color */
         background-color: #00000000; /* Black w/ opacity */
         text-align: center;
         z-index: 9999;
       }
       
      #errorMsgModal .modal-content {
         background-color: #f443367a;
         padding: 30px;
         border: 1px solid #888;
         color: white;
         width: auto;
         font-size: 20px;
         font-weight: 600;
         height: auto;
         top: 10px;
         position: absolute;
         right: 10px;
       }
       #successrMsgModal .modal-content {
         background-color: #aab555d4;
         padding: 30px;
         border: 1px solid #888;
         color: white;
         width: auto;
         font-size: 20px;
         font-weight: 600;
         height: auto;
         top: 10px;
         position: absolute;
         right: 10px;
      }


       /* The Close Button */
       .close {
         color: #aaaaaa;
         float: right;
         font-size: 28px;
         font-weight: bold;
       }

       .close:hover,
       .close:focus {
         color: #000;
         text-decoration: none;
         cursor: pointer;
       }
      /* MODAL STYLING */

   </style>
   <script type="text/javascript">
      function promptMsg(type = 0, msg=""){
            if(type == 1)
            {
               $("#successrMsgModal").show();
               $("#successrMsgModal").find('span').html(msg);
            }
            else if(type == 0)
            {
               $("#errorMsgModal").show();
               $("#errorMsgModal").find('span').html(msg);
            }
         setTimeout(function() { 
               $("#errorMsgModal").hide();
               $("#successrMsgModal").hide();
         }, 1500);

      }
   </script>
   
</head>

<body>
    <!-- ERROR MSG MODAL -->
      <div id="errorMsgModal">
          <div class="modal-content">
              <span></span>
          </div>
      </div>
      <!-- SUCCESS MSG MODAL -->
      <div id="successrMsgModal">
          <div class="modal-content">
              <span></span>
          </div>
      </div>
    <div class="blog-login2">
        <div class="blog-login-in">
            <img src="<?=$imgLink?>" width='250'><br>
            <h3>IT Resources</h3>
            <form method="POST" action="ajax-request.php" id="signInForm">
                <img src="images/logo.png" alt="" />
                <div class="row">
                    <div class="input-field col s12">
                        <input name="email" id="email" type="text" class="validate">
                        <label for="email">Email Id</label>
                    </div>
                </div>
                <div class="row">
                    <div class="input-field col s12">
                        <input id="password" name="password" type="password" class="validate">
                        <label for="password">Password</label>
                    </div>
                </div>
                <div class="row">
                    <div class="input-field col s12">
                        <button class="waves-effect waves-light btn-large btn-log-in" type="submit">Login</button>
                    </div>
                </div>
                <input type="hidden" name="signin-request" value="1">
            </form>
        </div>
    </div>

    <!--======== SCRIPT FILES =========-->
    <script src="js/jquery.min.js"></script>
    <script src="js/bootstrap.min.js"></script>
    <script src="js/materialize.min.js"></script>
    <script src="js/custom.js"></script>
     <script type="text/javascript">
          function promptMsg(type = 0, msg=""){
                if(type == 1)
                {
                   $("#successrMsgModal").show();
                   $("#successrMsgModal").find('span').html(msg);
                }
                else if(type == 0)
                {
                   $("#errorMsgModal").show();
                   $("#errorMsgModal").find('span').html(msg);
                }
             setTimeout(function() { 
                   $("#errorMsgModal").fadeOut();
                }, 1500);
    
          }
    
          $(document).ready(function() {
    
             $("#signInForm").on('submit', (function(e) {
                e.preventDefault();
    
                //console.log("form Submitted");
    
                $.ajax({
                   url: $(this).attr('action'),
                   type: "POST",
                   data: new FormData(this),
                   dataType: "json",
                   contentType: false,
                   cache: false,
                   processData: false,
                   success: function(data) {
                   if(data.success == 1){
                      $("#signInForm").trigger("reset"); // to reset form input fields  
                      promptMsg(1,data.msg);
                      setTimeout(function() { 
                         window.location.href = "dashboard.php";
                      }, 1000);
                      
                   }
                   else{
                      promptMsg(0,data.msg);
                   }
                         
                   },
                   error: function(e) {
                      console.log(e);
                   }
                });
    
          }));
       });

   </script>
</body>

</html>