<?php
	class Access
	{
		function checkLogin()
		{
			if(isset($_SESSION['user_number']) && trim($_SESSION['user_number'])!='')
			{	
					
			}
			else 
			{
				header("Location:".ROOT."logout.php");
				die;
			}
		}
		function checkLoginOnly()
		{ 
			if(isset($_SESSION['user_number']) && trim($_SESSION['user_number'])!=''){			
				header("location:".ROOT);
			}
		}
		
		function checkAdmin(){
		    if(isset($_SESSION['userRole']) && $_SESSION['userRole']>0){
		        return true;
		    }else{
		        return false;
		    }
		}
		function getAccountAdmin(){
			$user = $_SESSION['user_id'];
			return $user;
		}
		function checkAdminAccess(){
		    if(!$this->checkAdmin()){
		        header("location:".ROOT);
		        die;
		    }
		}
	
		//random string generator
		function generateRandomString($length = 10) {
			$characters = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
			$charactersLength = strlen($characters);
			$randomString = '';
			for ($i = 0; $i < $length; $i++) {
				$randomString .= $characters[rand(0, $charactersLength - 1)];
			}
			return $randomString;
		}
		
	}
?>
