<?php
ob_start();
session_start();
require_once("conn.php");
require_once 'db_connection.php'; 
include 'dbconfig.php';

if(isset($_SESSION['admin']))
{		
	header('location:home.php');
	die();
}

	if(isset($_POST['login'])){

		
		$username = $_POST['username'];
		$password =  $_POST['pass'];

		$sql = "SELECT * FROM mobileusers where user_name = :user";
		$query = $DB_con->prepare($sql);
		$query->bindParam('user', $username);
		$query->execute();

		if($query->rowCount() == 1){

			$row = $query->fetch();
			 
			$password_hasaman = $row['user_pass'];
			if (password_verify($password, $password_hasaman)) {
			   
				$content = array('user_id', 'user_name', 'admintype');

				foreach ($content as $x) {
					$_SESSION[$x] = $row[$x];
				}
				$userid = $row['user_id'];
				$bramchinfo = mysqli_fetch_array(mysqli_query($conn, "SELECT * FROM tbl_user_branch WHERE user_id='$userid'"));
				$_SESSION['branch_id'] = $bramchinfo['branch_id'];
				header('location:home.php');
				die();
			}else{
				
				$error = 'Username or password is wrong!';
			}

		}else{
			
			$error = 'Username or password is wrong!';
		}
	}

?>


<!DOCTYPE html>
<html lang="en">

<head>

<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=0">
<meta name="description" content="POS - Pos & Invetory Systems">
<meta name="keywords" content="Pos & Invetory Systems">
<meta name="author" content="Pos & Invetory Systems">
<meta name="robots" content="noindex, nofollow">

<title>Login | Eat More Resturant   | Pos & Invetory System | Dashboard
</title>

<script src="assets/bootstrap.min.js"></script>
<script src="assets/jquery.min.js"></script>

<link rel="shortcut icon" type="image/x-icon" href="assets/img/favicon.png">

<!--Fontawesome CDN-->
<link rel="stylesheet" href="assets/css/all.css" integrity="sha384-mzrmE5qonljUremFsqc01SB46JvROS7bZs3IO2EmfFsd15uHvIt+Y8vEf7N7fWAU" crossorigin="anonymous">
<link rel="stylesheet" href="assets/plugins/fontawesome/css/fontawesome.min.css">
<link rel="stylesheet" href="assets/plugins/fontawesome/css/all.min.css">
<!--Bootsrap 4 CDN-->
<link rel="stylesheet" href="assets/bootstrap.min.css">
<!--Fontawesome CDN-->
<link rel="stylesheet" href="assets/all.css">

<link rel="stylesheet" href="assets/login.css">

<style>

</style>

</head>

<body>
<style>
body{
background-size: cover;		
}
</style>
<div class="container">
	<div class="d-flex justify-content-center h-100">
		<div class="card">
			<div class="card-header">
				<h3 style="text-align:center;">
				<?php

								$stmt = $DB_con->prepare('SELECT * FROM mobilesettings where status="1" ORDER BY stid');

								$stmt->execute();

								if($stmt->rowCount() > 0)

								{

								while($row=$stmt->fetch(PDO::FETCH_ASSOC))

								{

								extract($row);

								?>
								
								<img src="assets/img/logo.png" alt="<?php echo $row['systemname']; ?>"/>
				<?php 
				} 
				}
				?>
				</h3>
			</div>
			<h4 style="background-color:#000000;font-weight:bold;font-size:17px;text-align:center;color:#ffffff;padding:5px 5px 5px 5px;">Login | Eat More Resturant  </h4>
			<div class="card-body">
				<form method="POST" action="index.php">
					<div class="input-group form-group">
						<div class="input-group-prepend">
							<span class="input-group-text"><i class="fa fa-user"></i></span>
						</div>
						<input type="text" class="form-control" name="username" placeholder="Username">
					</div>
					<div class="input-group form-group">
						<div class="input-group-prepend">
							<span class="input-group-text"><i class="fa fa-key"></i></span>
						</div>
						<input type="password" class="form-control" name="pass" placeholder="Password">
					</div>
					<div class="form-group">
						<input type="submit" name="login" value="Login" class="btn float-right login_btn btn-block" style="font-weight:700;color:#ffffff;">
					</div>
				</form>
			</div>
			<div class="card-footer" >
				<div class="d-flex justify-content-center links" style="font-size:12px;font-weight:700;text-align:center;color:#ffffff;">
				Copyright @ 2025 | Eat More Resturant | All Rights Reserverd | Developed By Seopro Developer
				</div>             
			</div>
		</div>
	</div>
</div>

</body>
</html>