<?php
$loginerrors=array();
include('../includes/validations.php');
include('../includes/functions.php');
session_start();
//  make_connection();
//  $password='qwerty';
// $password=password_hash($password,PASSWORD_DEFAULT);
// $query="UPDATE user SET password='$password' WHERE regno='15BCE0329';";
// $result=mysqli_query($connection,$query);
if(isset($_POST['loginsubmit']))
{
  $regno=$_POST['regno'];
  $password=$_POST['password'];
  make_connection();
  $success=attempt_login($regno,$password);
  if(!$success)
    $loginerrors['login']="Wrong Email/Password";
  else
  {
        //authentication successfull
        $_SESSION['login']=$regno;//**********ID for recognizing user*********
        redirect_to("home.php");
      }
    }
    ?>
    <!DOCTYPE html>
    <html lang="en">
    <head>
     <?php include('../includes/head.php');?>
     <title>Utopia - Smarter City</title>
     <link rel="stylesheet" type="text/css" href="font-awesome/css/font-awesome.min.css">

     <link rel="stylesheet" type="text/css" href="materialize/css/materialize.css">
     <link rel="stylesheet" type="text/css" href="css/signup.css">
     <link rel="stylesheet" type="text/css" href="css/common.css">
     <style>
     .main{
      display:table;
      width:100%;
      background-size: cover !important;
      background-repeat: no-repeat !important;
      background: linear-gradient( rgba(0, 0, 0, 0.5), rgba(0, 0, 0, 0.5) ), url('images/smartcity.png');
      background-position:center top;
      min-height:100vh;
    }
    .white-color{
      color: #fff;
    }
  </style>
</head>
<body>
  <div class="main">
   <div class="fbdiv">
    <span class="pull-left"><a href="index.php"><i class="fa fa-home fa-2x" aria-hidden="true"></i></a></span>
    <a class="facebook" href="https://www.facebook.com/vitbookshare/"><span></span><i class="fa fa-facebook fa-2x" aria-hidden="true"></i></a>
  </div>
  <h1 class="green-color center">Utopia - Smarter City</h1>
  <hr class="underlinehr">
  <main>
    <h3 class="center signuph2 white-color">Login</h3>
    <?php
    if(isset($loginerrors['login']) && !empty($loginerrors['login']))
      echo "<h5 class='center redcolor'>{$loginerrors['login']}</h5>";
    ?>
    <h4 class="center red-text"></h4>
    <div class="container">
      <div class="card z-depth-3">
        <div class="container">
          <div class="row">
           <form action="login.php" method="post">
            <div class="col s12 l12 m12 input-field"> 
              <input required type="email" name="regno" id="email"/>
              <label class="" for="email">Email</label>
            </div>
            <div class="col s12 l12 m12 input-field">
             <input required type="password" name="password" id="password" />
             <label class="active" for="password">Password</label>
           </div>
           <a class="waves-effect waves-light btn right">
            <input type="submit" name="loginsubmit" value="Login"/> <i class="material-icons right">send</i>
          </a>
        </form>  
        <div class="waves-effect waves-light btn left white"><a href="signup.php">Sign Up <i class="material-icons right">perm_identity</i></a></div>
      </div>
    </div>
  </div>
</div>
</main>
<br><br>
</div>
<script src="js/jquery.js"></script>
<script src="materialize/js/materialize.min.js"></script>
<script type="text/javascript">
  $(document).ready(function() {
    Materialize.updateTextFields();
  });
</script>
</body>
</html>