<?php session_start(); include('includes/conn.php'); ?>
<!DOCTYPE html>
<html lang="en">
  <head>
	<title>ECIMS ADMIN | LOGIN</title>
    <?php include('includes/head.php'); ?>
  </head>
  <body>
    <div class="container-scroller">
      <div class="horizontal-menu">
        <?php $activePage = basename($_SERVER['PHP_SELF'], ".php"); ?>
<nav class="navbar top-navbar col-lg-12 col-12 p-0">
  <div class="container-fluid">
	<div class="text-center navbar-brand-wrapper d-flex align-items-center justify-content-start">
	  <a class="navbar-brand brand-logo" href="index.php"><img style="width: 115px;height:140px;" src="assets/images/logo.png" alt="logo" /></a>
	  <a class="navbar-brand brand-logo-mini" href="index.php"><img style="width: 115px;height:140px;" src="assets/images/logo.png" alt="logo" /></a>
	</div>
	<div class="text-center navbar-menu-wrapper d-none d-lg-block d-flex align-items-center justify-content-center">
	  <span style="text-transform:uppercase;font-size: 30px;font-weight: bold;color: #000;">military engineer services <br> HISAR/ALWAR</span>
	</div>
	<div class="navbar-brand-wrapper d-flex align-items-center justify-content-end">
	  <a class="navbar-brand brand-logo d-none d-lg-block" href="index.php"><img style="width: 115px;height:auto;" src="assets/images/logo-right.png" alt="logo" /></a>
	  <button class="navbar-toggler navbar-toggler-right d-lg-none align-self-center" type="button" data-toggle="horizontal-menu-toggle">
		<span class="icon-menu"></span>
	  </button>
	</div>
  </div>
</nav>
<p class="text-center p-0 m-1 fw-bolder">Today Date : <?php echo date('d/m/Y'); ?></p>
<nav class="bottom-navbar">
  <div class="container-fluid">
	<ul class="nav page-navigation">
	  <li class="nav-item <?= (($activePage == 'index')) ? 'active':''; ?>">
		<a class="nav-link" href="index.php">
		  <span class="menu-title">HOME</span>
		</a>
	  </li>
	  <li class="nav-item <?= (($activePage == 'about')) ? 'active':''; ?>">
		<a class="nav-link" href="about.php">
		  <span class="menu-title">ABOUT US</span>
		</a>
	  </li>
	  <li class="nav-item <?= (($activePage == 'help')) ? 'active':''; ?>">
		<a class="nav-link" href="help.php">
		  <span class="menu-title">HELP</span>
		</a>
	  </li>
	  <li class="nav-item <?= (($activePage == 'contact')) ? 'active':''; ?>">
		<a class="nav-link" href="contact.php">
		  <span class="menu-title">CONTACT</span>
		</a>
	  </li>
	  <li class="nav-item <?= (($activePage == 'login')) ? 'active':''; ?>">
		<a class="nav-link" href="login.php">
		  <span class="menu-title">LOGIN</span>
		</a>
	  </li>
	</ul>
  </div>
</nav>
      </div>
      <div class="container-fluid page-body-wrapper full-page-wrapper">
        <div class="content-wrapper d-flex align-items-center auth">
          <div class="row flex-grow">
            <div class="col-lg-4 mx-auto">
              <div class="auth-form-light text-left p-5">
                <div class="brand-logo text-center mb-0">
                  <!--<img style="width:100%" src="assets/images/logo-login.png">-->
                </div>
                <h2 class="text-center" style="color:#2B6F96">Welcome to <br>ECIMS</h2>
                <?php $err='';
				if(isset($_POST['login'])) {
				$username = $_POST['username'];
				$password = $_POST['password'];
				$select = $conn->query("SELECT * FROM admin WHERE mobile='".$username."'");
				if($select->num_rows > 0){
					$fetch = $select->fetch_assoc();
					$adminstatus = $fetch['status'];
					if($adminstatus == '1'){
						$adminpassword = $fetch['password'];
						if($password == $adminpassword){
						    if($fetch['role'] == 'bso') {
						        echo '<script>window.location="stockReport.php"</script>';
						    } elseif($fetch['type'] == 'super') {
						        echo '<script>window.location="report.php"</script>';
						    } else {
							    echo '<script>window.location="dashboard.php"</script>';
						    }
							$_SESSION['admin'] = $fetch['id'];
							$_SESSION['adminname'] = $fetch['name'];
							$_SESSION['admintype'] = $fetch['type'];
							$_SESSION['role'] = $fetch['role'];
							$_SESSION['division_id'] = $fetch['division_id'];
							$_SESSION['department_id'] = $fetch['department_id'];
							
						} else {
							$err = '<p style="color: #ff6666;text-align: center;">Wrong Password !!</p>';
						}
					} else {
						$err = '<p style="color: #ff6666;text-align: center;">Your account is not active !!</p>';
					}
				} else {
					$err = '<p style="color: #ff6666;text-align: center;">Wrong Username !!</p>';
				}
			}?>
			<?php echo $err; ?>
                <form class="pt-3" method="POST">
                  <div class="form-group">
                    <input type="text" autocomplete="off" class="form-control form-control-lg" name="username" id="exampleInputEmail1" placeholder="Username">
                  </div>
                  <div class="form-group">
                    <input type="password" autocomplete="off" class="form-control form-control-lg" name="password" id="exampleInputPassword1" placeholder="Password">
                  </div>
                  <div class="mt-3">
                    <input type="submit" name="login" class="btn btn-block btn-dark btn-lg font-weight-medium auth-form-btn" value="SIGN IN"/>
                    <!--<a href="#" class="auth-link text-black" style="float:right;vertical-align:middle;">Forgot password?</a>-->
                  </div>
                </form>
              </div>
            </div>
          </div>
        </div>
        <!-- content-wrapper ends -->
      </div>
      <!-- page-body-wrapper ends -->
    </div>
    <?php include('includes/foot.php'); ?>
  </body>
</html>
