<?php
session_start();
ob_start();
include('../config.php');
$id   = $_SESSION['userinfo']['id'];
$use  = mysql_query("SELECT * FROM `admin` WHERE id='$id'");
$user = mysql_fetch_assoc($use);
?>
<!DOCTYPE html>
<html>
  <head>
    <title>Admin Login</title>
    <!-- Bootstrap -->
    <link href="bootstrap/css/bootstrap.min.css" rel="stylesheet" media="screen">
    <link href="bootstrap/css/bootstrap-responsive.min.css" rel="stylesheet" media="screen">
    <link href="assets/styles.css" rel="stylesheet" media="screen">
     <!-- HTML5 shim, for IE6-8 support of HTML5 elements -->
    <!--[if lt IE 9]>
      <script src="http://html5shim.googlecode.com/svn/trunk/html5.js"></script>
    <![endif]-->
    <script src="js/vendor/modernizr-2.6.2-respond-1.1.0.min.js"></script>
  </head>
  <body id="login">
    <div class="container">
<?php
if ($_SESSION['logged'] == true) {
    header("Location: dashboard.php");
} else {
    echo '
      <form action="index.php" method="post" class="form-signin">
        <h2 class="form-signin-heading">Admin Panel</h2>
        <input type="text" name="name" class="input-block-level" placeholder="Username">
        <input type="password" name="password" class="input-block-level" placeholder="Password">
        <label class="checkbox">
          <input type="checkbox" value="remember-me"> Remember me
        </label>
        <input class="btn btn-large btn-primary" name="login" type="submit" value="Sign in">
      </form>
					';
    if ($_POST['login']) {
        $name = htmlspecialchars($_POST['name']);
        $pass = htmlspecialchars($_POST['password']);
        $info = mysql_query("SELECT * FROM admin WHERE name = '$name'") or die(mysql_error());
        $data = mysql_fetch_array($info);
        if ($data['password'] != $pass) {
            echo '			
				<br /><center>Wrong username or password</center><br />
							';
        } else {
            $runq      = mysql_query("SELECT * FROM `admin` WHERE name='$name' AND password='$pass'");
            $provLogin = mysql_num_rows($runq);
            if ($provLogin == 1) {
                $row                  = mysql_fetch_assoc($runq);
                $_SESSION['userinfo'] = $row;
                $_SESSION['logged']   = true;
                echo '
								<script type="text/javascript">
								window.location = "dashboard.php"
								</script>
								';
            }
        }
    }
}
ob_end_flush();
?>
    </div> <!-- /container -->
    <script src="vendors/jquery-1.9.1.min.js"></script>
    <script src="bootstrap/js/bootstrap.min.js"></script>
  </body>
</html>