<?php include("session_controller.php"); ?>
<?php
// *** Validate request to login to this site.


$loginFormAction = $_SERVER['PHP_SELF'];
if (isset($_GET['accesscheck'])) {
  $_SESSION['PrevUrl'] = $_GET['accesscheck'];
}

if (isset($_POST['username'])) {
  $loginUsername=$_POST['username'];
  $password=$_POST['password'];
  $_SESSION['pass'] = $password;
  $MM_fldUserAuthorization = "";
  $MM_redirectLoginSuccess = "accounts.php";
  $MM_redirectLoginFailed = "index.php?status=invalid+username+or+password!";
  $MM_redirecttoReferrer = false;
  mysqli_select_db($conn, $database_conn);
  
  $LoginRS__query=sprintf("SELECT username, password, role, location  FROM admin WHERE username=%s AND password=%s",
    GetSQLValueString($loginUsername, "text"), GetSQLValueString($password, "text")); 
   
  $LoginRS = mysqli_query($conn, $LoginRS__query) or die(mysqli_error($conn));
  $LoginRS_users = mysqli_fetch_assoc($LoginRS);
  $loginFoundUser = mysqli_num_rows($LoginRS);
  if ($loginFoundUser) {
     $loginStrGroup = $LoginRS_users['role'];
    
	if (PHP_VERSION >= 5.1) {session_regenerate_id(true);} else {session_regenerate_id();}
    //declare two session variables and assign them
    $_SESSION['MM_Username'] = $loginUsername;
    $_SESSION['MM_UserGroup'] = $loginStrGroup;	 
    $_SESSION['location'] = $LoginRS_users['location'];
    $_SESSION['log_in'] = time();        

    if (isset($_SESSION['PrevUrl']) && false) {
      $MM_redirectLoginSuccess = $_SESSION['PrevUrl'];	
    }
    header("Location: " . $MM_redirectLoginSuccess );
  }
  else {
    header("Location: ". $MM_redirectLoginFailed );
  }
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Login to Accounts </title>
<link href="style.css" rel="stylesheet" type="text/css"/>


      <script type="text/javascript" src="bootstrap-3.3.5-dist/js/jquery-3.2.1.min.js" ></script>
  <link href="bootstrap-3.3.5-dist/css/bootstrap.min.css" rel="stylesheet" type="text/css" media="screen" />
     <script type="text/javascript" src="bootstrap-3.3.5-dist/js/bootstrap.min.js"></script>
          <script type="text/javascript" src="bootstrap-3.3.5-dist/js/moment.min.js"></script>
      <script type="text/javascript" src="bootstrap-3.3.5-dist/js/bootstrap-datetimepicker.min.js"></script>
  <link rel="stylesheet" href="bootstrap-3.3.5-dist/css/bootstrap-datetimepicker.css" type="text/css" media="screen"/>
  
  <style>
  @import "bourbon";

body {
	/* background: #eee !important;	*/
}
.col{
	font-size:17px; padding-left:15px; padding-right:15px; color:#FFF; background-color:#333333;
}
.wrapper {	
	margin-top: 40px;
margin-bottom: 100px;
}

.form-signin {
  max-width: 380px;
  padding: 15px 35px 45px;
  margin: 0 auto;
  background-color: #fff;
  border: 1px solid rgba(0,0,0,0.1);  

  .form-signin-heading,
	.checkbox {
	  margin-bottom: 30px;
	}

	.checkbox {
	  font-weight: normal;
	}

	.form-control {
	  position: relative;
	  font-size: 16px;
	  height: auto;
	  padding: 10px;
		@include box-sizing(border-box);

		&:focus {
		  z-index: 2;
		}
	}

	input[type="text"] {
	  margin-bottom: -1px;
	  border-bottom-left-radius: 0;
	  border-bottom-right-radius: 0;
	}

	input[type="password"] {
	  margin-bottom: 20px;
	  border-top-left-radius: 0;
	  border-top-right-radius: 0;
	}
}

body {
  /*  background-image: url("img/nysc3.jpg");
    background-repeat: repeat-x;*/
}

</style>
  
</head>

<body>

  <p><font face="Georgia, Times New Roman, Times, serif"></font></p>

<div align="center">
  <p><font face="Georgia, Times New Roman, Times, serif"></font></p>
  <p>&nbsp;</p>
  <p>&nbsp;</p>
  <div align="center"> <!-- <img src="images/logo.jpg" width="120" height="120" /> --> <br/>  </div>
</div>
<br/>
<div style="font-family:Century Gothic; font-size:22px;" align="center">Login to Accounts  </div>

  <div class="wrapper">
    <form ACTION="<?php echo $loginFormAction; ?>" name="form1" method="POST" class="form-signin">      
      <h4 class="form-signin-heading">Please login</h4>
      
      
  
   <div align="center"> <?php if(isset($_GET['status']) && ($_GET['status'] != "")){ echo '<font style="color:red;" size="+1">'.$_GET['status'].'</font>' ; } ?></div>
     
      
      <input type="text" class="form-control" name="username" placeholder="Email Address" required="" autofocus="" />
      <br/>
      <input type="password" class="form-control" name="password" placeholder="Password" required=""/>      
     <br />
      <button class="btn btn-md btn-danger col" type="submit"> Login</button>   
    </form> 
  </div>
 
</body>
</html>
