<?php
ob_start();
session_start();
if(isset($_SESSION['user_id'])){
	header('Location: index.php');
	exit;
}

require_once("conn.php");
require_once("config.php");
require_once 'dbconfig.php';
require_once 'db_connection.php';

	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)) {
				$userid = $row['user_id'];
				$bramchinfo = mysqli_fetch_array(mysqli_query($conn, "SELECT * FROM tbl_user_branch WHERE user_id='$userid'"));
				$branch_id = $bramchinfo['branch_id'];
				$binfo = mysqli_fetch_array(mysqli_query($conn, "SELECT * FROM branch WHERE branch_id ='$branch_id'"));
				//$enddate = $binfo['enddate'];
				//if($today > $enddate){
					
					//$error = 'Your package has expired.';
				//}else{
				$content = array('user_id', 'user_name', 'admintype');

				foreach ($content as $x) {
					$_SESSION[$x] = $row[$x];
				}
				
				$_SESSION['branch_id'] = $bramchinfo['branch_id'];
				header('location:home.php');
				exit();
				//}
			}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 | Payroll | 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']; ?> | Dashboard"/>
				<?php 
				} 
				}
				?>
				</h3>
			<h5 style="font-weight:bold;text-align:center;color:#000000;">Payroll | Login</h4>
			</div>
			<div class="card-body">
				<form method="POST" action="index.php">
					<?php if(!empty($error)){ ?>
					
						<div class="alert alert-danger" role="alert" style="width: 100%;">
  								<?php echo $error; ?>
						</div>
					
					<?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">
					</div>
				</form>
			</div>
			<div class="card-footer" >
				<div class="d-flex justify-content-center links" style="font-size:12px;text-align:center;">
				Copyright @ 2025 | Payroll | All Rights Reserverd | Developed By Seopro Developer
				</div>             
			</div>
		</div>
	</div>
</div>

</body>
</html>