<?php

function loadPage($rota1)

{
	global $uquerys;
	$querys = array();
    $querys = explode("/", $uquerys);
	if($querys[0]==NULL){

		$retorno = 'index';

	}else if(array_key_exists($querys[0], $rota1)){

		$retorno = $rota1[$querys[0]];

	}else{

		$retorno = '404';
	}

	return $retorno;
}

function loadSub()

{
	global $uquerys;
	$querys = array();
    $querys = explode("/", $uquerys);
	return $querys;
}


function qEx($uquerys){

	return explode('/', $uquerys);

}

function loadAction($action)

{
	global $uquerys;
	$querys = array();
    $querys = explode("/", $uquerys);
    if(array_key_exists($querys[0], $action)){

		include sti('cont').'/'.sti('pages').'/actions/'.$querys[0].'.php';
		exit;
	}

}

function curPageURL() 
{
 $pageURL = 'http';
 if ($_SERVER["HTTPS"] == "on") {$pageURL .= "s";}
 $pageURL .= "://";
 if ($_SERVER["SERVER_PORT"] != "80") {
  $pageURL .= $_SERVER["SERVER_NAME"].":".$_SERVER["SERVER_PORT"].$_SERVER["REQUEST_URI"];
 } else {
  $pageURL .= $_SERVER["SERVER_NAME"].$_SERVER["REQUEST_URI"];
 }
 return $pageURL;
}

function gertoken($salt){

	$token = md5(time().$salt);
	return $token;
}

function trim_value(&$value)
{
    $value = trim($value);   
}

function dataBuild($datetime)
{

	#Formatos de entrada [2015-02-27 19:00:00] ou [2015-02-27]

	$diasemana = date("l", strtotime($datetime));
	$dia = date("d", strtotime($datetime));
	$ano = date("Y", strtotime($datetime));
	$menm = date("m", strtotime($datetime));
	$hora12 = date("h", strtotime($datetime));
	$hora24 = date("H", strtotime($datetime));
	$min = date("i", strtotime($datetime));
	$seg = date("s", strtotime($datetime));

	
	switch($diasemana)
	{
		case "Monday": $diasemana = "Segunda-Feira"; break;
		case "Tuesday": $diasemana = "Terça-Feira"; break;
		case "Wednesday": $diasemana = "Quarta-Feira"; break;
		case "Thursday": $diasemana = "Quinta-Feira"; break;
		case "Friday": $diasemana = "Sexta-Feira"; break;
		case "Saturday": $diasemana = "Sábado"; break;
		case "Sunday": $diasemana = "Domingo"; break;
		default: $diasemana = "Unknown"; break;
	}

	switch($menm)
	{
		case "01": $mesF = "Janeiro";  $mesM='Jan'; break;
		case "02": $mesF = "Fevereiro"; $mesM='Fev'; break;
		case "03": $mesF = "Março"; $mesM='Mar'; break;
		case "04": $mesF = "Abril"; $mesM='Abr'; break;
		case "05": $mesF = "Maio"; $mesM='Mai'; break;
		case "06": $mesF = "Junho"; $mesM='Jun'; break;
		case "07": $mesF = "Julho"; $mesM='Jul'; break;
		case "08": $mesF = "Agosto"; $mesM='Ago'; break;
		case "09": $mesF = "Setembro"; $mesM='Set'; break;
		case "10": $mesF = "Outubro"; $mesM='Out'; break;
		case "11": $mesF = "Novembro"; $mesM='Nov'; break;
		case "12": $mesF = "Dezembro"; $mesM='Dez'; break;
		default: $mesF = "Unknown"; $mesM='Unknown'; break;
	}


	$dtparts = array();

	$dtparts['diasemana'] =  $diasemana;
	$dtparts['dia'] =  $dia;
	$dtparts['mes0'] =  $menm;
	$dtparts['mes1'] =  $mesF;
	$dtparts['mes2'] =  $mesM;
	$dtparts['ano']  =  $ano;
	$dtparts['hora12']  =  $hora12;
	$dtparts['hora24']  =  $hora24;
	$dtparts['min']  =  $min;
	$dtparts['seg']  =  $seg;


	return $dtparts;

}



function retDados($id, $tab){

	global $con;
	$sel = mysql_query("SELECT * FROM $tab WHERE id='$id'");
	if(mysql_num_rows($sel)==1)
	{

		return mysql_fetch_assoc($sel);

	}
}
//modulo cart

function retornaQ($q){

	global $con;
	$sel_prod = mysql_query($q);
	if(mysql_num_rows($sel_prod)==1)
	{

		return mysql_fetch_assoc($sel_prod);

	}else{
		return false;
	}
}

function getSeo($curPage){

	$selSeo = mysql_query("SELECT * FROM seo WHERE page='$curPage'");


	if(mysql_num_rows($selSeo)==0){

		echo "<h1 style='color:red;font-size:20px'>Aten&ccedil;&atilde;o! P&aacute;gina sem SEO</h1>";

	}

	return mysql_fetch_assoc($selSeo);

}

function retorna($id, $table){
	global $con;
	$sel = mysql_query("SELECT * FROM ".$table." WHERE id='$id'");

	return mysql_fetch_assoc($sel);

}

function retornaCol($id, $col, $table){
	global $con;
	$sel = mysql_query("SELECT ".$col." FROM ".$table." WHERE id='$id'");

	return mysql_fetch_assoc($sel);

}

function remove_http($url) {
   $disallowed = array('http://', 'https://');
   foreach($disallowed as $d) {
      if(strpos($url, $d) === 0) {
         return str_replace($d, '', $url);
      }
   }
   return $url;
}

function troca_data($data){

	$datas = explode('/', $data);


	return $datas['2'].'-'.$datas['1'].'-'.$datas['0'];



}

function troca_data2($data){

	$datas = explode('-', $data);


	return $datas['2'].'/'.$datas['1'].'/'.$datas['0'];



}
function corta($texto, $b=300,$sep='') {
$size_original = strlen($texto);
if($size_original>$b){
$c01=substr($texto, 0, $b);
$c01=substr($c01, 0, strrpos($c01, " "));
return  $c01.' '.$sep;
} else {
return $texto;
}
}
