<?php
error_reporting(E_ERROR | E_PARSE);
date_default_timezone_set('asia/kolkata');
require_once 'ClassForm.php';

session_start();
if(isset($_POST['inputEmail']) && isset($_POST['inputPassword']))
{
    $Username = $_POST['inputEmail'];
    $Password = $_POST['inputPassword'];

    $Authenticate = "select * from login_info where email_id='".$Username."' and user_pwds = '".$Password."'";
    $Access = $ClassForm->Fetch_Result_Array($Authenticate);    
    if(count($Access > 0)){         
        if($Access['email_id'] == $Username && $Password == $Access['user_pwds']){
            $_SESSION['user'] = $Access['user_Name'];
            $_SESSION['email'] = $Access['email_id'];
            $_SESSION['mobile'] = $Access['mobile'];
            $_SESSION['user_id'] = $Access['id'];

            if($Access['user_role'] == 'admin' || $Access['user_role'] == 'system'){
                $return_array = array(
                    'status_code' => '11',
                    'status_info' => 'login successful...'
                );
                echo $jsonformat = json_encode($return_array);
                exit;
            }
            else{
                if($Access['user_Name'] == 'Rane'){
                    $return_array = array(
                        'status_code' => '2',
                        'status_info' => $Access['user_Name']
                    );
                    echo $jsonformat = json_encode($return_array);
                    exit;
                }else{
                    $return_array = array(
                        'status_code' => '1',
                        'status_info' => 'login successful...'
                    );
                    echo $jsonformat = json_encode($return_array);
                    exit;
                }
                
            }

            $return_array = array(
                'status_code' => '0',
                'status_info' => 'Something went wrong. Please Contact Administrator...'
            );
            echo $jsonformat = json_encode($return_array);
            exit;
        }
        else{
            $return_array = array(
                'status_code' => '0',
                'status_info' => 'Email / Password are not correct.'
            );
            echo $jsonformat = json_encode($return_array);
            exit;
        }        
    }
    else{
        $return_array = array(
            'status_code' => '0',
            'status_info' => 'Email / Password are not correct.'
        );
        echo $jsonformat = json_encode($return_array);
        exit;
    }
}
else{
    $return_array = array(
        'status_code' => '2',
        'status_info' => 'Posted value not get'
    );
    echo $jsonformat = json_encode($return_array);
    exit;
}













// $auth_array = $ClassAuth->Check_Login($Username, $Password);
// foreach ($_POST as $key => $value) {
//     echo "Field ".htmlspecialchars($key)." is ".htmlspecialchars($value)."<br>";
// }
// $Authenticate = "select * from login_info where email_id='system@stvat.com' and user_pwds = 'Sri@123#'";
// $Access = $ClassForm->Fetch_Result_Array($Authenticate);

// print_r($Access);


?>