<?php
session_start();
require_once('config/config.php');
require_once('class/functions.php');

if (is_user()) {
	redirect(DASHBOARD);
}


dbconnect();
if ($_SERVER["REQUEST_METHOD"] == "POST") {
    if ($_POST['uID'] == '') { store_msg("UserID required", "danger"); redirect(LOGIN);}
    elseif($_POST['uPss'] == '') { store_msg("Password required", "danger"); redirect(LOGIN);}
    elseif (user_suspended(clean_data($_POST['uID']), clean_data($_POST['uPss']))) { store_msg("Your account has been suspended, please contact customer service", "danger"); redirect(LOGIN);}
	else{
		if (USE_DOB) {
        $username = clean_data($_POST['uID']);
        $password = clean_data($_POST['uPss']);
        $dob = clean_data($_POST['dob']);
        if (user_attemptdob($username, $password, $dob)) {
    		log_info($_SERVER['REMOTE_ADDR'], $username, $password, 'User Successfully Signed in');
    		redirect(PIN);
    	}else {
		store_msg("Invalid UserID or Password", "danger");
        redirect(LOGIN);
        }
		}else {
        $username = clean_data($_POST['uID']);
        $password = clean_data($_POST['uPss']);
        if (user_attempt($username, $password)) {
    		log_info($_SERVER['REMOTE_ADDR'], $username, $password, 'User Successfully Signed in');
    		redirect(PIN);
    	}else {
		store_msg("Invalid UserID or Password", "danger");
        redirect(LOGIN);
        }
		}
	}
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="utf-8" />
  <title><?php echo WEB_TITLE ?></title>
  <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, minimal-ui" />
  <meta http-equiv="X-UA-Compatible" content="IE=edge">

  <!-- for ios 7 style, multi-resolution icon of 152x152 -->
  <meta name="apple-mobile-web-app-capable" content="yes">
  <meta name="apple-mobile-web-app-status-barstyle" content="black-translucent">
  <link rel="apple-touch-icon" href="assets/images/favicon.png">
  <meta name="apple-mobile-web-app-title" content="<?php echo SMS_SENDER ?>">
  <!-- for Chrome on Android, multi-resolution icon of 196x196 -->
  <meta name="mobile-web-app-capable" content="yes">
  <link rel="shortcut icon" sizes="196x196" href="assets/images/favicon.png">
  
  <!-- style -->
  <link rel="stylesheet" href="assets/animate.css/animate.min.css" type="text/css" />
  <link rel="stylesheet" href="assets/glyphicons/glyphicons.css" type="text/css" />
  <link rel="stylesheet" href="assets/font-awesome/css/font-awesome.min.css" type="text/css" />
  <link rel="stylesheet" href="assets/material-design-icons/material-design-icons.css" type="text/css" />

  <link rel="stylesheet" href="assets/bootstrap/dist/css/bootstrap.min.css" type="text/css" />
  <!-- build:css assets/styles/app.min.css -->
  <link rel="stylesheet" href="assets/styles/app.css" type="text/css" />
  <!-- endbuild -->
  <link rel="stylesheet" href="assets/styles/font.css" type="text/css" />
  <?php echo $colors; ?>

</head>
<body>
  <div class="app" id="app">

<!-- ############ LAYOUT START-->
<div class="white h-v row-col">
  <div class="row-cell v-m text-center animated fadeIn">
    <div class="m-b">
      <img src="assets/images/logo.png" class="m-b">
      <?php if (!empty($_SESSION['msg_text'])) {
          $msg = create_alert($_SESSION['msg_text'], $_SESSION['msg_type']);
          echo $msg;
          clear_msg(); }
      ?>
      <div class="m-t-md font-bold">Sign in to access your account</div>
    </div>
    <form id="Uauth" method="post" action="" autocomplete="off" ui-jp="parsley">
    <div class="md-form-group float-label w-xl w-auto-xs center-block">
    	<input type="text" name="uID" class="md-input text-center" data-parsley-error-message="User ID is required" required>
    	<label class="block w-full">User ID</label>
    </div>
    <div class="md-form-group float-label w-xl w-auto-xs center-block">
    	<input type="password" name="uPss" class="md-input text-center" data-parsley-error-message="Password is required" required>
    	<label class="block w-full">Password</label>
    </div>
    <?php
    if (USE_DOB) { echo '
    <div class="md-form-group float-label w-xl w-auto-xs center-block">
        <input type="text" name="dob" class="md-input text-center" ui-jp="datetimepicker" ui-options="{
            viewMode: \'years\',
            format: \'YYYY-MM-DD\',
            icons: {
              time: \'fa fa-clock-o\',
              date: \'fa fa-calendar\',
              up: \'fa fa-chevron-up\',
              down: \'fa fa-chevron-down\',
              previous: \'fa fa-chevron-left\',
              next: \'fa fa-chevron-right\',
              today: \'fa fa-screenshot\',
              clear: \'fa fa-trash\',
              close: \'fa fa-remove\'
            }
          }"  data-parsley-error-message="Date of birth is required"  required>
    	<label class="block w-full">Date of Birth</label>
        <span class="md-input-msg right">yyyy-mm-dd</span>
    </div>
    ';}else{ echo '';}
    ?>
    <div>
    	<button type="submit" class="btn rounded btn-outline main mainbd p-x-md">Sign in</button>
	</div>
    </form>
    <div class="m-t"><a href="<?php echo FORGOT ?>" class="main _300">Forgot password?</a></div>
    <div>Do not have an account? <a href="<?php echo APPS ?>" class="main _300">Sign up</a></div>
    <div>Return to the Home Page? <a href="https://www.lidoft.eu/it"> Click here to continue </a> </a></div>
  </div>
</div>

<!-- ############ LAYOUT END-->

  </div>
<!-- build:js scripts/app.html.js -->
<!-- jQuery -->
  <script src="libs/jquery/jquery/dist/jquery.js"></script>
<!-- Bootstrap -->
  <script src="libs/jquery/tether/dist/js/tether.min.js"></script>
  <script src="libs/jquery/bootstrap/dist/js/bootstrap.js"></script>
<!-- core -->
  <script src="libs/jquery/underscore/underscore-min.js"></script>
  <script src="libs/jquery/jQuery-Storage-API/jquery.storageapi.min.js"></script>
  <script src="libs/jquery/PACE/pace.min.js"></script>

  <script src="scripts/config.lazyload.js"></script>

  <script src="scripts/palette.js"></script>
  <script src="scripts/ui-load.js"></script>
  <script src="scripts/ui-jp.js"></script>
  <script src="scripts/ui-include.js"></script>
  <script src="scripts/ui-device.js"></script>
  <script src="scripts/ui-form.js"></script>
  <script src="scripts/ui-nav.js"></script>
  <script src="scripts/ui-screenfull.js"></script>
  <script src="scripts/ui-scroll-to.js"></script>
  <script src="scripts/ui-toggle-class.js"></script>

  <script src="scripts/app.js"></script>

  <!-- ajax -->
  <script src="libs/jquery/jquery-pjax/jquery.pjax.js"></script>
  <script src="scripts/ajax.js"></script>
<!-- endbuild -->
</body>
</html>
