<?php
require_once 'db.php';
include_once "ewcfg12.php";
include_once ((EW_USE_ADODB) ? "adodb5/adodb.inc.php" : "ewmysql12.php");
include_once "phpfn12.php";
include_once "class.user.php";

//
// Page class
//

$login = NULL; // Initialize page object first

class clogin {

  private $db;

  function __construct($DB_con)
  {
    $this->db = $DB_con;
  }
    
	function Page_Init() {
		global $Security, $User;

		// Security
		$Security = new cAdvancedSecurity();
    $User     = new USER($this->db);
	}
  
}

// Create page object
if (!isset($login)) $login = new clogin($DB_con);

// Page init
$login->Page_Init();


// grab recaptcha library
require_once "phpinc/recaptchalib.php";

$secretKey   = '6LfM3yUTAAAAAIN9C0U154G3M04Gxb76YdWtsI_4';
$response    = false;
$err_message = '';

if($User->is_loggedin()!="") {
    //if ($_SESSION['user_session']=='sysadmin'){
    //    $User->redirect('sa-index.php');
    //} else {
        $User->redirect('index.php');
    //}
}


if($_SERVER['REQUEST_METHOD'] == 'POST'){
  if(!empty($_POST['g-recaptcha-response'])){
    $objRecaptcha = new ReCaptcha($secretKey);
    $response = $objRecaptcha->verifyResponse($_SERVER['REMOTE_ADDR'], $_POST['g-recaptcha-response']);
  }
  if(isset($response->success) && 1 == $response->success){
    //Human is detected you can write script to perform actual action
    
      if(isset($_POST['btn-login'])) {
         $uname = ew_RemoveXSS(ew_StripSlashes($_POST['armyno']));
         $upass = ew_RemoveXSS(ew_StripSlashes($_POST['userpassword']));
         
         if($User->login($uname,$upass)) {
           //if ($uname=='sysadmin'){
           //    $User->redirect('sa-index.php');
           //} else {
               $User->redirect('index.php');
           //}
         } else {
            $error[] = "Invalid login credential";
         }
      }    
  } else {
    $error[] = "You are not human!";
  }
}

?>

<?php
/*
if($_SERVER['REQUEST_METHOD'] == 'POST'){
  if(!empty($_POST['g-recaptcha-response'])){
    $objRecaptcha = new ReCaptcha($secretKey);
    $response = $objRecaptcha->verifyResponse($_SERVER['REMOTE_ADDR'], $_POST['g-recaptcha-response']);
  }
  if(isset($response->success) && 1 == $response->success){
    //Human is detected you can write script to perform actual action
    // Open connection
    if (!isset($conn)) $conn = ew_Connect();
    $validlogin = ew_ExecuteScalar("select count() from WEBUSER where USERID='$userid'");
    
    if ($validlogin!==0){
      $username = $_REQUEST['armyno'];
      $password = $_REQUEST['password'];
    
      header("Location: index.php");
    } else {
      $err_message = 'Invalid login credential';
    }
  } else {
    $err_message = 'You are not human';
  }
}
*/
?>

<!DOCTYPE html>
<html lang="en">
<head>
  <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1.0, user-scalable=no">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <title>LTAT Online Caruman Login</title>
  <!-- CORE CSS-->  
  <link rel="stylesheet" href="mycss/materialize.css">
  <link rel="stylesheet" href="mycss/footer-distributed.css">
  <link rel='stylesheet prefetch' href='font-awesome-4.4.0/css/font-awesome.min.css'>
 

<style type="text/css">
.margin {
  margin: 0 !important;
}
</style>

<style>
    /* NOTE: The styles were added inline because Prefixfree needs access to your styles and they must be inlined if they are on local disk! */
    * {
      box-sizing: border-box;
    }

    html {
      height: 100%;
    }

    body {
      margin: 0;
      height: 100%;
    }

    [role='main'] {
      position: relative;
      z-index: 1;
      /* text-align: center; */
      margin: 0;
      padding: 15px;
      background: #0277bd;
      /* color: #55BADA; */
      height: 100%;
      margin-bottom: 270px;
    }
    [role='main']:after {
      content: '';
      position: absolute;
      left: 0;
      bottom: -3rem;
      font-size: 0.3rem;
      background: url('data:image/svg+xml;base64,PD94bWwgdmVyc2lvbj0iMS4wIiBlbmNvZGluZz0idXRmLTgiPz4gPHN2ZyB2ZXJzaW9uPSIxLjEiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyI+PGRlZnM+PGxpbmVhckdyYWRpZW50IGlkPSJncmFkIiBncmFkaWVudFVuaXRzPSJvYmplY3RCb3VuZGluZ0JveCIgeDE9IjAuMCIgeTE9IjAuMCIgeDI9IjEuMCIgeTI9IjEuMCI+PHN0b3Agb2Zmc2V0PSIyNSUiIHN0b3AtY29sb3I9IiMzMzMzMzMiLz48c3RvcCBvZmZzZXQ9IjI1JSIgc3RvcC1jb2xvcj0iIzAwMDAwMCIgc3RvcC1vcGFjaXR5PSIwLjAiLz48L2xpbmVhckdyYWRpZW50PjwvZGVmcz48cmVjdCB4PSIwIiB5PSIwIiB3aWR0aD0iMTAwJSIgaGVpZ2h0PSIxMDAlIiBmaWxsPSJ1cmwoI2dyYWQpIiAvPjwvc3ZnPiA=') -3em 0, url('data:image/svg+xml;base64,PD94bWwgdmVyc2lvbj0iMS4wIiBlbmNvZGluZz0idXRmLTgiPz4gPHN2ZyB2ZXJzaW9uPSIxLjEiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyI+PGRlZnM+PGxpbmVhckdyYWRpZW50IGlkPSJncmFkIiBncmFkaWVudFVuaXRzPSJvYmplY3RCb3VuZGluZ0JveCIgeDE9IjEuMCIgeTE9IjAuMCIgeDI9IjAuMCIgeTI9IjEuMCI+PHN0b3Agb2Zmc2V0PSIyNSUiIHN0b3AtY29sb3I9IiMzMzMzMzMiLz48c3RvcCBvZmZzZXQ9IjI1JSIgc3RvcC1jb2xvcj0iIzAwMDAwMCIgc3RvcC1vcGFjaXR5PSIwLjAiLz48L2xpbmVhckdyYWRpZW50PjwvZGVmcz48cmVjdCB4PSIwIiB5PSIwIiB3aWR0aD0iMTAwJSIgaGVpZ2h0PSIxMDAlIiBmaWxsPSJ1cmwoI2dyYWQpIiAvPjwvc3ZnPiA=') -3em 0;
      background: -moz-linear-gradient(315deg, #0277bd 25%, rgba(0, 0, 0, 0) 25%) -3em 0, -moz-linear-gradient(225deg, #0277bd 25%, rgba(0, 0, 0, 0) 25%) -3em 0;
      background: -webkit-linear-gradient(315deg, #0277bd 25%, rgba(0, 0, 0, 0) 25%) -3em 0, -webkit-linear-gradient(225deg, #0277bd 25%, rgba(0, 0, 0, 0) 25%) -3em 0;
      background: linear-gradient(135deg, #0277bd 25%, rgba(0, 0, 0, 0) 25%) -3em 0, linear-gradient(225deg, #0277bd 25%, rgba(0, 0, 0, 0) 25%) -3em 0;
      background-size: 3rem 100%;
      background-color: transparent;
      height: 3rem;
      width: 100%;
      border: none;
      margin: 0;
    }

    [role='contentinfo'] {
      height: 270px;
      width: 100%;
      /* text-align: center; */
      background: #333;
      padding-top: 3em;
      color: #bada55;
      position: fixed;
      bottom: 0;
      left: 0;
    }
    [role='contentinfo'] > h2 {
      font-size: 3em;
    }
    [role='contentinfo'] a {
      /* color: #DA7555; */
      color: #9CBBD4;      
    }

    h1 {
      font-size: 3em;
    }

    @-moz-keyframes bounce {
      0%, 20%, 50%, 80%, 100% {
        -moz-transform: translateY(0);
        transform: translateY(0);
      }
      40% {
        -moz-transform: translateY(-30px);
        transform: translateY(-30px);
      }
      60% {
        -moz-transform: translateY(-15px);
        transform: translateY(-15px);
      }
    }
    @-webkit-keyframes bounce {
      0%, 20%, 50%, 80%, 100% {
        -webkit-transform: translateY(0);
        transform: translateY(0);
      }
      40% {
        -webkit-transform: translateY(-30px);
        transform: translateY(-30px);
      }
      60% {
        -webkit-transform: translateY(-15px);
        transform: translateY(-15px);
      }
    }
    @keyframes bounce {
      0%, 20%, 50%, 80%, 100% {
        -moz-transform: translateY(0);
        -ms-transform: translateY(0);
        -webkit-transform: translateY(0);
        transform: translateY(0);
      }
      40% {
        -moz-transform: translateY(-30px);
        -ms-transform: translateY(-30px);
        -webkit-transform: translateY(-30px);
        transform: translateY(-30px);
      }
      60% {
        -moz-transform: translateY(-15px);
        -ms-transform: translateY(-15px);
        -webkit-transform: translateY(-15px);
        transform: translateY(-15px);
      }
    }

    .arrow {
      position: absolute;
      bottom: 50px;
      left: 50%;
      margin-left: -20px;
      width: 20px;
      height: 20px;
      background-image: url(data:image/svg+xml;base64,PD94bWwgdmVyc2lvbj0iMS4wIiBlbmNvZGluZz0iVVRGLTgiPz4NCjwhLS0gR2VuZXJhdG9yOiBBZG9iZSBJbGx1c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xNzgtMjAuMTc4LTUzLjE2NC0xOS45MTMtNzMuNjcxLDAuNTk1bDAsMGMtMjAuNTA4LDIwLjUwOS0yMC43NzIsNTMuNDkyLTAuNTk1LDczLjY3MUwyMjAuMjQ5LDQ1NS44Njh6Ii8+DQo8L3N2Zz4=);
      background-size: contain;
    }

    .bounce {
      -moz-animation: bounce 2s infinite;
      -webkit-animation: bounce 2s infinite;
      animation: bounce 2s infinite;
    }
</style>

<!-- Google reCAPTCHA API -->
<script src='https://www.google.com/recaptcha/api.js'></script>
  <!-- jQuery Library -->
<script type="text/javascript" src="myjs/jquery-2.1.3.min.js"></script>

  
</head>

<body class="light-blue darken-3">

<?php 
  //foreach ($_POST as $key => $value) {
  //  echo '<p><strong>' . $key.':</strong> '.$value.'</p>';
  //}
?>

<section role="main">
<div class="container">
  <div id="login-page" class="row">
    <div class="col s10 m6 l4 push-s1 push-m3 push-l4 z-depth-4 card-panel">
      <form class="login-form" id="login-form" action="<?php echo ew_CurrentPage() ?>" method="post">
        <?php if ($User->CheckToken) { ?>
        <input type="hidden" name="<?php echo EW_TOKEN_NAME ?>" value="<?php echo $User->Token ?>">
        <?php } ?>      
        <div class="row">
          <div class="input-field col s3">
            <!--<img src="http://w3lessons.info/logo.png" alt="" class="responsive-img valign profile-image-login">-->
            <img src="img/LTATlogo3.png" alt="LTAT Logo" class="responsive-img valign profile-image-login"></img>            
          </div>
          <div class="col s4">
            <h4 class="red-text">LOGIN</h4>          
          </div>
        </div>
        
        <?php
            if(isset($error))
            {
               foreach($error as $error)
               {
                  ?>
                  <div class="row margin">
                      <div class="col s2">
                          <div class="red-text">
                              <li class="collection-item valign-wrapper align-left">
                                <i class="material-icons small valign">&#xE002;</i>
                              </li>
                          </div>
                      </div>
                      <div class="col s10">
                          <div class="red-text">
                              <li class="collection-item valign-wrapper">
                                <?php echo $error; ?>
                              </li>
                          </div>
                      </div>
                  </div>
                  <?php
               }
            }
        ?>
        
        <div class="row margin">
          <div class="input-field col s12">
            <!--<i class="mdi-social-person-outline prefix"></i>-->
            <i class="material-icons prefix">&#xE8AA</i>
            <input id="armyno" name="armyno" type="text" class="validate" required>
            <!--<label for="nric" data-error="wrong" data-success="right">No. Pengenalan</label>-->
            <label for="armyno">No. Tentera</label>
          </div>
        </div>
        <div class="row margin">
          <div class="input-field col s12">
            <!--i class="mdi-action-lock-outline prefix"></i-->
            <i class="material-icons prefix">&#xE899</i>
            <input id="userpassword" name="userpassword" type="password" required>
            <label for="password">Password</label>
          </div>
        </div>
        <!-- Google Recaptcha here -->
          <div class="row col s12 g-recaptcha" data-size="normal" data-sitekey="6LfM3yUTAAAAAJBkHNnZNKtx0xARtQ3N-FwwX_HQ"></div>
        
        <div id="error">
        <!-- error will be shown here ! -->  
        </div>
        
        <div class="row">          
          <div class="input-field col s12 m12 l12  login-text">
              <input type="checkbox" id="remember-me" />
              <label for="remember-me">Remember me</label>
          </div>
        </div>
        <div class="row">
          <div class="input-field col s12">
            <!--<a href="login.html" class="btn waves-effect waves-light col s12">Login</a>-->
            <input class="btn waves-effect waves-light col s12" name="btn-login" id="btn-login" type="submit" value="Login" />
          </div>
        </div>
        <div class="row">
          <div class="input-field col s6 m6 l6">
            <p class="margin"><a href="register.php">Register Now!</a></p>
          </div>
          <div class="input-field col s6 m6 l6">
              <p class="margin right-align"><a href="forgotpwd.php">Forgot password?</a></p>
          </div>          
        </div>

      </form>
    </div>
  </div>
  <div class="arrow animated bounce"></div>
</div>

<div class="container">
<p class="white-text center-align">Laman web rasmi Semakan Caruman LTAT Atas Talian <br> Paparan terbaik menggunakan Internet Explorer 9 dan ke atas, Mozilla Firefox dan Google Chrome</p>
</div>

</section>

  <!-- ================================================
    Scripts
    ================================================ -->
<!--materialize js-->
<script src="myjs/materialize.js"></script>
<script src="myjs/prefixfree.min.js"></script>

  
  

        <footer class="page-footer grey darken-3" role="contentinfo">
          <div class="container">
            <div class="row">
              <div class="col l12 s12">
                <p class="white-text">LEMBAGA TABUNG ANGKATAN TENTERA</p>
                <p class="grey-text text-lighten-4">
                    <br><i class="fa fa-building fa-fw"></i>   Lembaga Tabung Angkatan Tentera, Bangunan LTAT, Jalan Bukit Bintang, 55100 Kuala Lumpur.
                    <br><i class="fa fa-phone fa-fw"></i>   1-300-88-5828 (Talian Bebas Tol)
                    <br><i class="fa fa-envelope fa-fw"></i>   <a href="mailto:support@company.com">   webmaster@ltat.org.my</a>                    
                    <br><i class="fa fa-map-marker fa-fw"></i>   N 3 08.898 E 101 43.034
                <p>
                
                </p>
              </div>
            </div>
          </div>
          <div class="footer-copyright grey darken-4 hide-on-small-only">
            <div class="container">
            &copy 2016 Lembaga Tabung Angkatan Tentera - Hak Cipta Terpelihara
            </div>
          </div>
          <div class="footer-copyright grey darken-4 hide-on-med-and-up"> <!-- show this on mobile only -->
            <div class="container">
            &copy 2016 LTAT - Hak Cipta Terpelihara
            </div>
          </div>
        </footer>

        
  
  
</body>

</html>