require_once("class.ibase.php");
class utils extends bd
{
function redireciona($site = false)
{
if (!$site) $site = "impressaoboleto.html";
$this->redireciona = "";
print $this->redireciona;
}
function mesExtenso($num)
{
$mes = Array(01 => "Janeiro", 02 => "Fevereiro", 03 => "Março", 04 => "Abril", 05 => "Maio", 06 => "Junho", 07 => "Julho", 08 => "Agosto", 09 => "Setembro", 10 => "Outubro", 11 => "Novembro", 12 => "Dezembro");
if ($num > 0 && $num < 13) return $mes[$num];
else return false;
}
// função que retorna "Bom dia", "Boa tarde" ou "Boa noite", verificando o horário atual
function bemvindo()
{
$BV_G = date("G");
if ($BV_G >= 6 && $BV_G < 12)
return "Bom dia";
elseif ($BV_G >= 12 && $BV_G < 18)
return "Boa tarde";
else
return "Boa noite";
}
// verifica se o usuario ainda está logado.
//
function checklogin($xsql = NULL)
{
GLOBAL $EMPRESA;
if (!isset($_SESSION['usersession']))
{
print"oi1";
#print $this->redireciona("login.php");
return false;
}
else
{
print"oi2";
if (!$xsql) $tabela = "SYS_CONFIGUSUARIO";
else $tabela = "SYS_CONFIGUSUARIO";
$q = $this->query("SELECT SESSION FROM $tabela WHERE SESSION='$_SESSION[usersession]'");
$l = $this->fetchobj($q);
if ($l->SESSION != $_SESSION['usersession'])
{
#print $l->SESSION . " # " . $_SESSION['usersession'];
#$this->redireciona("login.php");
return false;
}
else
return true;
}
}
// funcao que adiciona/deleta o email na newsletter dependendo de $fazer.
function newsletter($email, $fazer = true)
{
if ($fazer)
{
$q = $this->query("SELECT email FROM leob_newsletter WHERE email='$email'");
if (!$this->numrows($q))
{
$query = $this->query("INSERT INTO leob_newsletter (email) VALUES ('$email')");
if (!$query) return "Erro no cadastro do e-mail.";
else return "Muito obrigado! Agora você receberá as notícias mais relevantes em sua caixa postal.";
}
else
return "Erro. Você já está participando da newsletter!";
}
else
{
$query = $this->query("DELETE FROM leob_newsletter WHERE email='$email'");
if (!$query) return "Erro na exclusão do e-mail.";
else return "E-mail excluído da newsletter";
}
}
// se hora, minuto e segundo forem iguais a 1, mudar para a data atual!!!
// se for igual a 0, deixar 0 mesmo.
// mktime ( [int hour [, int minute [, int second [, int month [, int day [, int year [, int is_dst]]]]]]])
function maketime($data, $hora = 0, $minuto = 0, $segundo = 0)
{
$data = explode("/", $data);
$dia = $data[0];
$mes = $data[1];
$ano = $data[2];
$hora = ($hora == 1) ? date("H") : $hora;
$minuto = ($minuto == 1) ? date("i") : $minuto;
$segundo = ($segundo == 1) ? date("s") : $segundo;
$this->maketime = mktime($hora, $minuto, $segundo, $mes, $dia, $ano);
return $this->maketime;
}
function transforma_data($data, $check = false) // se check for true, executa o teste (dia/mes/ano).
{
$temp = explode("/", $data);
if ($check == false)
return $temp[0] . "/" . $temp[1] . "/" . $temp[2];
elseif ($check == true && checkdate($temp[1], $temp[0], $temp[2])) // mes, dia, ano
return $temp[1] . "/" . $temp[0] . "/" . $temp[2];
else
{
print "Data inválida: " . $data;
exit;
}
}
function paginacao($nome, $tabela, $ordemCampo, $ordemTipo, $limite, $pagina, $campos = "*", $where = 1)
{
GLOBAL $$nome;
$temp = $this->query("SELECT * FROM " . $tabela . " WHERE " . $where);
$totalPags = ceil($this->numrows($temp) / $limite);
$limitez = round(($pagina - 1) * $limite) . ", " . $limite;
if ($pagina > 1)
$$nome .= "";
$$nome .= "< ";
for ($i = 1; $i <= $totalPags; $i++)
$$nome .= "$i ";
if ($pagina < $totalPags)
$$nome .= "";
$$nome .= ">";
$$nome = preg_replace("/($pagina)<\/a>/", "$1", $$nome);
$this->paginacao = "SELECT " . $campos . " FROM " . $tabela . " WHERE " . $where . " ORDER BY " . $ordemCampo . " " . $ordemTipo . " LIMIT " . $limitez;
return $this->paginacao;
}
}
?>