<?php

error_reporting(0);
if (isset($_POST['adminID']) && isset($_POST['adminPassword'])) {
	require 'connect.php';
	$AdminEmail = trim($_POST['adminID']);
	$AdminPassword = trim($_POST['adminPassword']);

	if ($AdminPassword == '') {
		echo "emptyPassword";
	}
	else {
		    //=================== DATA =======================
    $QUERY = "SELECT * FROM customers WHERE Username = '$AdminEmail' AND Admin = 1";
    //==============================QUERY DATA ================================
    $result = mysqli_query($connect, $QUERY);
    //======================== GET NUM ROWS ==============================
    $num_rows = mysqli_num_rows($result);
    //============================LOGIN USER OR DIE USER ===============================
            if ($num_rows == 1) {
                           //===================== FETCH DATA ==================================
                $fetch_data = mysqli_fetch_assoc($result);
                $ID = $fetch_data['ID'];
                $email = $fetch_data['Email'];
                $DB_password = $fetch_data['Password'];               

                if ($DB_password == $AdminPassword) {
                    session_start();
                    echo "<div class='wow successful_login fadeIn animated' style='text-align: center; color: green;'><span> Login successful..</span></div>";
                    echo "<script>window.location.href='/personal/admin/'</script>";
                    $_SESSION['AdminID'] = $fetch_data['ID'];
                    $_SESSION['Adminpage'] = $fetch_data['PageKey'];
                    $_SESSION['username'] = $fetch_data['AccFullname'];
                    $_SESSION['AccBal'] = $fetch_data['AccBal'];
		            $_SESSION['Acclmage'] = $fetch_data['AccImage'];
		            
		            
                } else {
                    echo '<div class="wow error_display fadeIn animated" style="text-align: center; color: red;"> Invalid login details, Please try again.</div>';
                }
            }
            else {
                echo '<div class="wow error_display fadeIn animated" style="text-align: center; color: red;"> Invalid login details, Please try again.</div>';
            }
	}







}else {
	header("Location: /en/");
	die();
}