<?php

require_once(dirname(__FILE__).'/common/header.php');
require_once(dirname(__FILE__).'/cek_login.php');

if(isset($_GET['do_login'])){
                        $login =getUser($_POST['username'],$_POST['password']);
                        if($login == false){  
                            $_SESSION['login_error'] = TRUE;
                        }else{
                            $_SESSION['user'] = TRUE;
                            header("location:index.php"); 
                        }
                        $log =getAdmin($_POST['username'],$_POST['password']);
                        if($log == false){  
                            $_SESSION['login_error'] = TRUE;
                        }else{
                            $_SESSION['admin'] = TRUE;
                            header("location:list_menu.php"); 
                        }
                        if(isset($_SESSION["login_error"])){
                            echo "<div style='margin-bottom:-55px' class='alert alert-danger' role='alert'><span class='glyphicon glyphicon-warning-sign'></span>  Login Gagal !! Username dan Password Salah !!</div>";
                            }
                      }
                      ?>

<form class='well form-horizontal' action='form_login.php?do_login=1' method='post'  id='contact_form'>
<fieldset>
<legend><span class='glyphicon glyphicon-log-in'></span>&nbsp;Login</legend>
<div class='form-group'>
  <label class='col-md-4 control-label'>Username</label>  
  <div class='col-md-4 inputGroupContainer'>
  <div class='input-group'>
  <span class='input-group-addon'><i class='glyphicon glyphicon-user'></i></span>
  <input type='text'  name='username' required placeholder='Username' class='form-control'  type='text'>
    </div>
  </div>
</div>
<div class='form-group'>
  <label class='col-md-4 control-label'>Password</label> 
    <div class='col-md-4 inputGroupContainer'>
    <div class='input-group'>
    <span class='input-group-addon'><i class='glyphicon glyphicon-lock'></i></span>
    <input name='password' required placeholder='Password' class='form-control'  type='password'>
    </div>
  </div>
</div>
<div class='form-group'>
  <label class='col-md-4 control-label'></label>
  <div class='col-md-4'>
    <input type='submit' value='login' class='btn btn-default'>
  </div>
</div>
<center>Belum punya akun?
<a href='form_daftar.php'>    silahkan daftar disini </center>
</fieldset>

</form>
<?php
 require_once(dirname(__FILE__).'/common/footer.php');
?>