<?php
session_start();
include "include.php";

if($updte == 1){ 
	$o->email = $_POST['email'];
	$o->password = cpassword($_POST['password']);

	$sql_check = "Select user_id from users where (email = '".$o->email."' or mobile = '".$o->email."') and password = '".$o->password."' and user_type = 'Admin' and is_active = 1";
	$res_check = getXbyY($sql_check);
	$row_check = count($res_check);

	if($row_check == 1){
		$o = $factory->get_object($res_check[0]['user_id'],"users","user_id");

        // Update last login info
        $o->last_login = todaysDate();
		$o->login_ip = $_SERVER['REMOTE_ADDR'];
		$o->user_id = $updater->update_object($o, "users");

        // Direct login for Admin - No OTP required
        $_SESSION['recharge_admin_id'] = $o->user_id;
		$_SESSION['recharge_app_admin_name'] = $o->name;
		$_SESSION['last_login'] = $o->last_login;

        $result['error'] = 0;
        $result['direct_login'] = 1;
		$result['error_msg'] = "Login Successful! Redirecting to dashboard...";
	}else{
		$result['error'] = 1;
		$result['error_msg'] = "Username / Password Mismatch. Please try again";
	}


}

echo json_encode($result);

?>