<?php

	function Get($input)
	{
		if (isset ($_REQUEST[$input])) 
			return $_REQUEST[$input] ; 
		else if (isset ($_POST[$input]))
			return $_POST[$input] ; 
		else if (isset ($_GET[$input]))
			return $_GET[$input] ; 
		return null;
	}

	function GetCheckbox($input)
	{
		$tmp = 0;
		if (isset ($_REQUEST[$input])) 
			$tmp = $_REQUEST[$input] ; 
		else if (isset ($_POST[$input]))
			$tmp = $_POST[$input] ; 
		else if (isset ($_GET[$input]))
			$tmp = $_GET[$input] ; 
		
		if ($tmp == 0)
			return "";
		else
			return "CHECKED";
	}

	function SetRequest($data)
	{
		foreach ($data as $key => $value){
			$_REQUEST[$key] = $data[$key];
		}
	}

	function get_include_contents($filename) {
		if (is_file($filename)) {
			ob_start();
			include $filename;
			$contents = ob_get_contents();
			ob_end_clean();
			return $contents;
		}
		return false;
	}

	function DateRemoveZero($data)
	{
		$ano = substr($data,0,4);
		$mes = (int) substr($data,5,2);
		$dia = (int) substr($data,8,2);
		return  $ano ."-". $mes ."-". $dia ;
	}

	function Mes($data)
	{	
		$data = substr($data,5,2);
		switch ($data)
		{
			case "01":
				return "Jan";
				break;
			case "02":
				return "Fev";
				break;
			case "03":
				return "Mar";
				break;
			case "04":
				return "Abr";
				break;
			case "05":
				return "Mai";
				break;
			case "06":
				return "Jun";
				break;
			case "07":
				return "Jul";
				break;
			case "08":
				return "Ago";
				break;
			case "09":
				return "Set";
				break;
			case "10":
				return "Out";
				break;
			case "11":
				echo "de Nov";
				break;
			case "12":
				return "Dez";
				break;
		}
	}

	function utf_iso(&$a){
		if (is_array($a)){
			foreach ($a as $k => $v) {
				if (!is_array($v)){
					$a[$k] = utf8_decode($a[$k]);
				} else {
					utf_iso($a[$k]);
				}
			}
		} else {
			$a = utf8_decode($a);
		}
		return $a;
	}	

	function to_utf8($in)
	{
		if (is_array($in)) 
		{
			if (count($in) == 0)
				return $in;
		}

		if (is_array($in)) 
		{
			foreach ($in as $key => $value) 
			{
				$out[to_utf8($key)] = to_utf8($value);
			}
		} 
		else if(is_string($in)) 
		{
			//if(mb_detect_encoding($in) != "UTF-8")
				return utf8_encode($in);
			//else
				//return $in;
		} else {
			return $in;
		}
		return $out;
	}

	function Logger($msg)
	{ 
		global $GLOBALS, $LOGGER;

		if ($LOGGER)
		{
			$data = date("d-m-y");
			$hora = date("H:i:s");
			$ip = $_SERVER['REMOTE_ADDR'];
 
			$arquivo = "Logger_$data.txt";

			$texto = "[$hora][$ip]> $msg \n";
 
			$manipular = fopen("$arquivo", "a+b");
			fwrite($manipular, $texto);
			fclose($manipular);
		}
	}

?>