<?php
session_start();
//Admin
// if($_SESSION['admin'] !='True')
// {		
// 	header('location:home.php');
// 	die();
// }

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

		include 'dbconfig4.php';

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

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

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

			$row = $query->fetch();
			
			$password_haorms = $row['user_pass'];
			if (password_verify($password, $password_haorms)) {
				$content = array('image','fullname','user_name','admintype','paydesk','category','providers','services','reload','datacard','customers','reports','status');

				foreach ($content as $x) {
					$_SESSION[$x] = $row[$x];
				}
				
				$_SESSION['admin_user_id'] = $row['user_id'];


				//var_dump($_SESSION);
				header('location:home.php');
				die();
			}else{
				//password wrong
				$error = 'Username or password is wrong!';
			}

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

?>

<!DOCTYPE html>
<html lang="en" class="h-100">

<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width,initial-scale=1">
    <title>Login | Mobile Recharge and Billing System | ORMS | Dashbaord</title>
	
    <?php
	//require_once './favicon.php';
	?>
	
	<?php
	require_once 'headercss.php';
	?>

</head>

<body class="h-100">
    <div class="authincation h-100">
        <div class="container h-100">
            <div class="row justify-content-center h-100 align-items-center">
                <div class="col-md-6">
                    <div class="authincation-content">
                        <div class="row no-gutters">
                            <div class="col-xl-12">
                                <div class="auth-form">
									<p><center><img src="images/logo.gif" alt="" style="width:300px;"></center></p>
                                    <h4 class="text-center mb-4" style="font-weight:bold;color:#ffffff;">Login in Admin Panel</h4>
									<hr>
									<h1 style="background-color: #ff0000; color: #ffffff; width: 100%; font-size: 18px; text-align: center;"><?php if(isset($error)){echo $error; }?></h1>
                                    <form action="index.php" method="POST" >
                                        <div class="form-group">
                                            <label style="font-weight:bold;color:#ffffff;"><strong>Username</strong></label>
                                            <input type="text" name="username" id="exampleInputUsername" class="form-control" placeholder="Enter Username">
                                        </div>
                                        <div class="form-group">
                                            <label style="font-weight:bold;color:#ffffff;"><strong>Password</strong></label>
                                            <input type="password" name="pass" id="exampleInputPassword" class="form-control" placeholder="Enter Password">
                                        </div>
                                        <div class="text-center">
											<input type="submit" class="btn btn-default btn-block" name="log" value="Login" style="color: #000000;background-color: #ffffff;border-color: #ffffff;">
                                        </div>
                                    </form>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>

    <?php
	require_once 'footerjs.php';
	?>

</body>

</html>