<?php

	/*
		-------------------------------------------------------------------------
		PhpRequest Copyright © 2003 GRAVICAL - gravical@hotmail.com
		November 25, 2003
		-------------------------------------------------------------------------
	*/

	// Global
	$request = new PhpRequest;

	function request($sName)
	{
		global $request;
		return $request->Get($sName);
	}
	
	class PhpRequest {

		var $m_Processesd;
		var $m_Values;

		function PhpRequest()
		{
			$this->ProcessAll();
		}
		
		function ProcessAll()
		{
			global $HTTP_GET_VARS;
			global $HTTP_POST_VARS;
			
			if($this->m_Processesd != "1")
			{
				$this->m_Values = array();
				$this->InternalProcess($HTTP_GET_VARS);
				$this->InternalProcess($HTTP_POST_VARS);
				//$this->InternalProcess($_COOKIES);
				$this->m_Processesd = "1";
			}
		}
		
		function Get($sName)
		{
			$sName = strtolower($sName);
			if(!isset($this->m_Values[ $sName  ]))
				return "";
			else
				return $this->m_Values[ $sName ];
		}

		function IsPresent($sName)
		{
			$sName = strtolower($sName);
			return isset($this->m_Values[ $sName  ]);
		}

		function Set($sName, $sValue)
		{
			$sName = strtolower($sName);
			$this->m_Values[ $sName ] = $sValue;
		}
		
		function InternalProcess($a)
		{
			// If this is an array
			if(is_array($a))
			{
				// Loop all elements
				while(list($key, $val) = each($a))
				{ 
					// Convert
					if(get_magic_quotes_gpc())
						$val = stripslashes($val);

					// Add it
					$this->m_Values[strtolower($key)] = $val;
				} 
			}
			
			// If this is a string
			else if(is_string($a))
			{
				return stripslashes($a);
			}
			
			// Otherwise return as is
			else
			{
				return $a;
			}
		}
		
	};

?>