<?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);
    if($run && mysqli_num_rows($run) > 0){
        return mysqli_fetch_assoc($run);
    }
    return [];
}

$company_data = get_company_datas();
if (is_array($company_data) && !empty($company_data['location']) && !empty($company_data['logo'])) {
    $location = "../".$company_data['location'];
    $img      = explode(',', (string)$company_data['logo']);
    if (!empty($img[0])) {
        $imgLink = 'feedback/'.$location.'/'.$img[0];
    }
}
?>

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

    <!--== 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/mob.css">
    <link rel="stylesheet" href="css/bootstrap.css">
    <link rel="stylesheet" href="css/materialize.css" />






<!----------------------------------------------------------------------------------------->
  <!-- Design by Asnaff -->
    <title>login</title>
 
    <link rel="preconnect" href="https://fonts.gstatic.com">
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.15.4/css/all.min.css">
    <link href="https://fonts.googleapis.com/css2?family=Poppins:wght@300;500;600&display=swap" rel="stylesheet">
    <!--Stylesheet-->
    <style media="screen">
      *,
*:before,
*:after{
    padding: 0;
    margin: 0;
    box-sizing: border-box;
}
      /* 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 */
/** Layout & background **/
.imgcent{
    display:block;
    margin:0 auto 16px auto;
}
body{
    min-height:100vh;
    background: radial-gradient(circle at top left, #1e3a8a 0, #020617 45%, #000 100%);
    font-family: 'Poppins',sans-serif;
}
.background{
    width: 430px;
    height: 520px;
    position: absolute;
    transform: translate(-50%,-50%);
    left: 50%;
    top: 50%;
}
.background .shape{
    height: 200px;
    width: 200px;
    position: absolute;
    border-radius: 50%;
}
.shape:first-child{
    background: linear-gradient(135deg,#38bdf8,#2563eb);
    left: -80px;
    top: -80px;
}
.shape:last-child{
    background: linear-gradient(135deg,#22c55e,#4ade80);
    right: -30px;
    bottom: -80px;
}
form{
    max-height: 640px;
    width: 400px;
    background-color: rgba(15,23,42,0.85);
    position: absolute;
    transform: translate(-50%,-50%);
    top: 50%;
    left: 50%;
    border-radius: 18px;
    backdrop-filter: blur(18px);
    border: 1px solid rgba(148,163,184,0.4);
    box-shadow: 0 22px 60px rgba(15,23,42,0.9);
    padding: 50px 35px;
}
form *{
    font-family: 'Poppins',sans-serif;
    color: #ffffff;
    letter-spacing: 0.5px;
    outline: none;
    border: none;
}
form h3{
    font-size: 26px;
    font-weight: 600;
    line-height: 36px;
    text-align: center;
    margin-bottom: 8px;
}

label{
    display: block;
    margin-top: 30px;
    font-size: 16px;
    font-weight: 500;
}
input{
    display: block;
    height: 50px;
    width: 100%;
    background-color: rgba(255,255,255,0.07);
    border-radius: 3px;
    padding: 0 10px;
    margin-top: 8px;
    font-size: 14px;
    font-weight: 300;
}
::placeholder{
    color: #e5e5e5;
}
button{
    margin-top: 40px;
    width: 100%;
    background: linear-gradient(135deg,#2563eb,#22c55e);
    color: #f9fafb;
    padding: 15px 0;
    font-size: 18px;
    font-weight: 600;
    border-radius: 999px;
    cursor: pointer;
}
.social{
  margin-top: 30px;
  display: flex;
  justify-content: space-between;
}
.social div{
  background: red;
  width: 150px;
  border-radius: 3px;
  padding: 5px 10px 10px 5px;
  background-color: rgba(255,255,255,0.27);
  color: #eaf0fb;
  text-align: center;
}
.social div:hover{
  background-color: rgba(255,255,255,0.47);
}
.social .fb{
  margin-left: 12px;
}
.social i{
  margin-right: 4px;
}

    </style>
</head>
<body>
    <div class="background">
        <div class="shape"></div>
        <div class="shape"></div>
    </div>
    <form method="POST" action="ajax-request.php" id="signInForm">
    <?php if(!empty($imgLink)): ?>
        <img src="<?=$imgLink?>" width='100' class="imgcent">
    <?php endif; ?>
        <h3>ITR FeedBack</h3>
        
        <label for="username">Username</label>
        <input name="email" id="email" type="text" class="validate"  placeholder="Email or Phone" >

        <label for="password">Password</label>
        <input id="password" name="password" type="password" class="validate" placeholder="Password">

        <button type="submit">Log In</button>
        <input type="hidden" name="signin-request" value="1">
        <br>
        <br>
       <p style="color:#ffff"> Having Any Problem ?</p>
        <div class="social">
          <div class="go"><i class="fab fa-readme"></i> <a href="tel:03113917777"> phone </a></div>
          <div class="fb"><i class="fab fa-facebook"></i>  <a href="https://www.facebook.com/Itresources.com.pk"> Facebook </a> </div>

        </div>
    </form>



    <!----------------------------------------------------------------------------->


    <!-- 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>

























    <!--======== 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>
