<?php

    require_once "../../include/config.php";
    require_once GLOBAL_INCLUDE_PATH."include/startup.php";    
    
    session_start();
    $Validation = new Validation();
    
    if(isset($_POST['btnlogin'])){          
    
        $username = sanitize($_POST['username'], SQL);
        $password = sanitize($_POST['password'], SQL+HTML);
        
        $valid = "";
        $valid .= $Validation->check_username("username", $username, "Username");
        $valid .= $Validation->check_password("password", $password, "Password");
        
        if($valid){
            $redirect = ADMIN_DIR."auth/login.php";
            header("location:".$redirect);
            exit();    
        }else{
            $checklogin = adminchecklogin($username, $password);
            if($checklogin){
                $redirect = ADMIN_DIR."index.php";
                header("location:".$redirect);
                exit();
            }
        }
        
    }else if($G_userid > 0 && $G_userid != null && $G_userid != ''){
        $redirect = ADMIN_DIR."index.php";
        header("location:".$redirect);
        exit();   
    }else{
        require_once "login.html";
        unset($_SESSION['username']);
        unset($_SESSION['password']);
    }


?>