function db_conectar($servidor=DB_SERVIDOR, $usuario=DB_USUARIO, $senha=DB_SENHA, $banco=DB_BANCO){
global $db_link;
$db_link = mysql_connect($servidor, $usuario, $senha);
if ($db_link)
mysql_select_db($banco);
return $db_link;
}
function db_desconectar(){
global $db_link;
return mysql_close($db_link);
}
function db_erro($consulta, $erronum, $erro){
die('
Erro! # '.$erronum.' - '.$erro.' '.$consulta.'
');
}
function db_consulta($consulta){
global $db_link;
$result = mysql_query($consulta, $db_link) or db_erro($consulta, mysql_errno(), mysql_error());
return $result;
}
function db_executa($tabela, $dados, $acao='insert', $parametros=''){
reset($dados);
if (strtolower($acao)=='insert'){
$consulta = 'insert into '.$tabela.' (';
while (list($coluna, )=each($dados))
$consulta.= $coluna.', ';
$consulta = substr($consulta, 0, -2) . ') values (';
reset($dados);
while (list(, $valor)=each($dados)){
switch ((string)$valor){
case 'now()':
$consulta .= 'now(), ';
break;
case 'null':
$consulta .= 'null, ';
break;
default:
$consulta .= '\''.db_entrada($valor).'\', ';
break;
}
}
$consulta = substr($consulta, 0, -2) . ')';
}
elseif (strtolower($acao)=='update'){
$consulta = 'update '.$tabela . ' set ';
reset($dados);
while (list($coluna, $valor)=each($dados)){
switch ((string)$valor){
case 'now()':
$consulta .= $coluna.' = now(), ';
break;
case 'null':
$consulta .= $coluna .= ' = null, ';
break;
default:
$consulta .= $coluna . ' = \'' . db_entrada($valor) . '\', ';
break;
}
}
$consulta = substr($consulta, 0, -2) . ' where ' . $parametros;
}
return db_consulta($consulta);
}
function db_lista($db_consulta){
return mysql_fetch_array($db_consulta);
}
function db_linhas($db_consulta){
return mysql_num_rows($db_consulta);
}
function db_insert_id(){
return mysql_insert_id();
}
function db_free_result($db_consulta){
return mysql_free_result($db_consulta);
}
function db_saida($string){
return htmlspecialchars($string);
}
function db_entrada($string){
return addslashes($string);
}
function db_dados($string){
return db_lista(db_consulta($string));
}
?>
function processaString($fonte) {
$fonte = str_replace('\\"', '"', $fonte);
$fonte = str_replace('\\\\', '\\', $fonte);
return $fonte;
}
function video_imagem($url) {
$url_imagem = parse_url($url);
if ($url_imagem['host'] == 'www.youtube.com' || $url_imagem['host'] == 'youtube.com') {
$array = explode("&", $url_imagem['query']);
return "http://img.youtube.com/vi/" . substr($array[0], 2) . "/0.jpg";
} else if ($url_imagem['host'] == 'www.vimeo.com' || $url_imagem['host'] == 'vimeo.com') {
$hash = unserialize(file_get_contents("http://vimeo.com/api/v2/video/" . substr($url_imagem['path'], 1) . ".php"));
return $hash[0]["thumbnail_small"];
}
}
function tiraCaracteres($aonde) {
$texto = preg_replace("/[^a-zA-ZÀ-ú0-9\s]/", " ", $aonde);
while (strpos($texto, " "))
$texto = str_replace(" ", " ", $texto);
return trim($texto);
}
function retiraAcentos($texto) {
$array1 = array("á", "à", "â", "ã", "ä", "é", "è", "ê", "ë", "í", "ì", "î", "ï", "ó", "ò", "ô", "õ", "ö", "ú", "ù", "û", "ü", "ç", "Á", "À", "Â", "Ã", "Ä", "É", "È", "Ê", "Ë", "Í", "Ì", "Î", "Ï", "Ó", "Ò", "Ô", "Õ", "Ö", "Ú", "Ù", "Û", "Ü", "Ç");
$array2 = array("a", "a", "a", "a", "a", "e", "e", "e", "e", "i", "i", "i", "i", "o", "o", "o", "o", "o", "u", "u", "u", "u", "c", "A", "A", "A", "A", "A", "E", "E", "E", "E", "I", "I", "I", "I", "O", "O", "O", "O", "O", "U", "U", "U", "U", "C");
return str_replace($array1, $array2, $texto);
}
function tiraRepetidos($fonte) {
asort($fonte);
return array_unique($fonte);
}
function soNumeros($fonte) {
return preg_replace("/[^0-9]/", "", $fonte);
}
function formataValor($valor) {
if (!empty($valor)) {
return number_format($valor, 2, ',', '.');
} else {
return "0,00";
}
}
function pesquisaQuery($colunas, $termos, $prefixo = "%", $sufixo = "%") {
$termos = tiraCaracteres($termos);
$buscastr = "";
if (strlen($termos) > 0) {
$chaves = array_unique(explode(" ", $termos));
if (sizeof($chaves)) {
foreach ($chaves as $chave) {
if (strlen($chave) > 0) {
$pesquisado .= $chave . " ";
if (is_array($colunas)) {
$buscastr .= " AND (1=2 ";
foreach ($colunas as $coluna) {
$buscastr .= " OR " . $coluna . " LIKE '" . $prefixo . $chave . $sufixo . "'";
}
$buscastr .= ")";
}
else
$buscastr .= " AND " . $coluna . " LIKE '" . $prefixo . $chave . $sufixo . "'";
}
}
}
}
return array($pesquisado, $buscastr);
}
class Consulta {
var $sql;
var $pp;
var $pgatual;
var $total_dados;
var $pgtotal;
var $consulta;
function Consulta($a, $b, $c) {
$this->sql = $a;
$this->pp = $b;
$this->pgatual = $c;
$this->total = db_linhas(db_consulta($a));
if (($this->total % $this->pp) == 0)
$this->pgtotal = ($this->total / $this->pp);
else
$this->pgtotal = (int) ($this->total / $this->pp) + 1;
$this->consulta = db_consulta($this->sql . ' LIMIT ' . $this->registroInicial() . ',' . $this->pp);
return true;
}
function registroInicial() {
return ($this->pp * ($this->pgatual - 1));
}
function totalPaginas() {
return $this->pgtotal;
}
function geraPaginacao() {
return paginar($this->pgatual, $this->pgtotal);
}
}
function paginar($atual, $qt) {
if (@!strpos($_SERVER ['REQUEST_URI'], ""))
$url = "" . utf8_decode($dadosconfig['url']) . "" . $_SERVER ['REQUEST_URI'] . ""; else
$url = $_SERVER ['REQUEST_URI'];
$url = str_replace(array("?pg=" . $atual, "?pg=" . $atual), "", $url);
$url = substr($url, strrpos($url, '') + 0, strlen($url));
$inicio = 1;
$fim = $qt;
if ($qt > 10) {
$inicio = $atual - 4;
$fim = $atual + 5;
if ($inicio < 1) {
$fim = $fim - $inicio + 1;
$inicio = 1;
}
if ($fim > $qt) {
$fim = $qt;
$inicio = $fim - 9;
}
}
$saida .= ' 1)
$saida .= ' href="' . $url . '?pg=' . ($atual - 1) . '" ';
$saida .= ' class="pg-naveg-ante">Anterior ';
for ($i = $inicio; $i <= $fim; $i++) {
$saida .= '';
}
$saida .= '
AC_FL_RunContent(\'codebase\',\'http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,19,0\',\'width\',\'' . $x . '\',\'height\',\'' . $y . '\',\'src\',\'' . $arq . '\',\'quality\',\'high\',\'pluginspage\',\'http://www.macromedia.com/go/getflashplayer\',\'movie\',\'' . $arq . '\',\'wmode\',\'transparent\' );
';
} else if ($extensao[$fimarray] == 'html') {
if (file_exists($arq)) {
return file_get_contents($arq);
}
} else {
$saida = ' ';
if (strlen($destino) > 0)
$saida = ' ' . $saida . ' ';
return $saida;
}
}
function senhaAleatoria($tamanho = 8) {
$chars = "abcdefghijkmnopqrstuvwxyz023456789";
srand((double) microtime() * 1000000);
$i = 1;
$pass = '';
while ($i <= $tamanho) {
$num = rand() % 33;
$tmp = substr($chars, $num, 1);
$pass = $pass . $tmp;
$i++;
}
return $pass;
}
function zeraSessao() {
foreach ($_SESSION as $campo => $valor) {
session_unregister($campo);
}
}
function urlOrigem() {
$get = $_GET;
$Proibidos = array('erro', 'msg', 'ok');
$get2 = '';
foreach ($get as $a => $b) {
if (!in_array($a, $Proibidos))
$get2.="&" . $a . "=" . $b;
}
return $_SERVER['PHP_SELF'] . "?" . $get2;
}
function extensaoArquivo($nomearquivo) {
$extensao = explode(".", $nomearquivo);
$fimarray = (count($extensao) - 1);
return strtolower($extensao[$fimarray]);
}
function fazerUpload($arquivo, $destino, $nome_arquivo = '', $tamanhomax = 0) {
if (($arquivo["size"] > $tamanhomax) && ($tamanhomax > 0 ))
return false;
if ($nome_arquivo == "") {
$nome_arquivo = md5(uniqid(time())) . "." . strtolower(extensaoArquivo($arquivo['name']));
}
move_uploaded_file($arquivo["tmp_name"], $destino . $nome_arquivo);
return $nome_arquivo;
}
function ListaDiretorio($diretorio, $tipoarquivo = null) {
$d = dir($diretorio);
while (false !== ($entry = $d->read())) {
if ($tipoarquivo == '') {
$array[] = $entry;
} else if ($tipoarquivo == 'dir') {
if (substr_count($entry, '.') == 0) {
$array[] = $entry;
}
} else {
if (substr_count($entry, $tipoarquivo) == 1) {
$array[] = $entry;
}
}
}
$d->close();
if ($array == '') {
$array = false;
} else {
sort($array);
reset($array);
}
return $array;
}
function apagarDir($dir) {
if (is_dir($dir)) {
if ($handle = opendir($dir)) {
while (false !== ($file = readdir($handle))) {
if (($file == ".") or ($file == "..")) {
continue;
}
if (is_dir($dir . "/" . $file)) {
apagarDir($dir . "/" . $file);
} else {
@unlink($dir . "/" . $file);
}
}
} else {
return false;
}
closedir($handle);
@rmdir($dir);
} else {
return false;
}
}
function nomeArquivo($orig, $pasta = '') {
preg_match_all('.[[:alnum:]\(\)_\.\[\]\- ].', $orig, $saida);
$saida = implode($saida[0]);
$saida = str_replace(' ', '_', $saida);
$saida = retiraAcentos($saida);
if ($pasta != "") {
$arqExtensao = substr($saida, strrpos($saida, '.'), strlen($saida));
$arqNome = substr(str_replace($arqExtensao, '', $saida), 0, 90);
$i = 0;
while (is_file($pasta . $saida)) {
$i++;
$saida = $arqNome . '(' . $i . ')' . strtolower($arqExtensao);
if ($i > 1000)
break;
}
}
return $saida;
}
class CriarImagem {
var $str = "123456789ABCDEFGHJKLMNPQRSTUVWXYZ";
var $width = 100;
var $height = 30;
var $fonts = array('../fonts/avgardd.ttf', '../fonts/bankgthd.ttf', '../fonts/bauhausb.ttf', '../fonts/goldminn.ttf');
var $linecolors = array("#bb0000", "#00bb00", "#0000bb");
var $hexcolors = array("#005500", "#000055", "#550000", "#555500", "#550055", "#005555");
var $image;
function make_seed() {
list($usec, $sec) = explode(' ', microtime());
return (float) $sec + ((float) $usec * 100000);
}
function hex2rgb($hex) {
$hex = str_replace('#', '', $hex);
$rgb = array(
'r' => hexdec(substr($hex, 0, 2)),
'g' => hexdec(substr($hex, 2, 2)),
'b' => hexdec(substr($hex, 4, 2)));
return $rgb;
}
function color($value) {
$rgb = $this->hex2rgb($value);
return ImageColorAllocate($this->image, $rgb['r'], $rgb['g'], $rgb['b']);
}
function randcolor() {
srand($this->make_seed());
shuffle($this->hexcolors);
return $this->color($this->hexcolors[0]);
}
function randcolor2() {
srand($this->make_seed());
shuffle($this->linecolors);
return $this->color($this->linecolors[0]);
}
function randline() {
srand($this->make_seed());
shuffle($this->hexcolors);
$i = rand(0, $this->width);
$k = rand(0, $this->width);
imagesetthickness($this->image, 2);
imageline($this->image, $i, 0, $k, $this->height, $this->randcolor2());
}
function randsquare() {
imagesetthickness($this->image, 1);
srand($this->make_seed());
$x = rand(0, ($this->width - 15));
$y = rand(0, ($this->height - 15));
ImageRectangle($this->image, $x, $y, $x + 12, $y + 12, $this->randcolor2());
}
function output() {
$defstr = "";
$this->image = imagecreatefromjpeg("../fonts/imgconfirm_bg.jpg");
srand($this->make_seed());
shuffle($this->hexcolors);
shuffle($this->fonts);
for ($i = 0; $i < 4; $i++) {
$this->str = str_shuffle($this->str);
$char = $this->str[0];
$defstr.=$char;
imagettftext($this->image, 24, rand(-15, 15), ($i * 31 + 6), rand(35, ($this->height - 7)), $this->color($this->hexcolors[$i]), $this->fonts[$i], $char);
}
for ($k = 0; $k < 3; $k++) {
$this->randline();
}
for ($k = 0; $k < 4; $k++) {
$this->randsquare();
}
ImagePng($this->image);
ImageDestroy($this->image);
return $defstr;
}
}
function nomeURL($orig) {
preg_match_all('.[[:alnum:]\(\)_\.\[\]\- ].', $orig, $saida);
$saida = implode($saida[0]);
$saida = str_replace(' ', '_', $saida);
$saida = retiraAcentos($saida);
return strtolower($saida);
}
function valFile($get) {
$file = $get;
$file = strtr($file, "ŠŒŽšœžŸ¥µÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖØÙÚÛÜÝßàáâãäåæçèéêëìíîïðñòóôõöøùúûüýÿ", "SOZsozYYuAAAAAAACEEEEIIIIDNOOOOOOUUUUYsaaaaaaaceeeeiiiionoooooouuuuyy");
$file = preg_replace('/(((f|ht){1}tp:\/\/)[-a-zA-Z0-9@:%_\+.~#?&\/\/=]+)/i', '', $file);
$file = str_replace('~', '', $file);
return $file;
}
function validateGetAmigavelParameters($arr) {
$param[0] = explode('.', $param['0']);
return $param;
}
function validateGetParameters($arr) {
if (MOD_REWRITE) {
foreach ($arr as $value) {
$param[] = valFile($value);
}
foreach ($arr as $value) {
if (!empty($value)) {
$val = valFile($value);
$param['self'] .= $val . '/';
$param['active'] = $val;
}
}
} else {
$paramNoRewrite = explode("/", $arr['p']);
foreach ($paramNoRewrite as $value) {
$param[] = reset(explode('.', valFile($value)));
}
$param = explode("/", $arr['p']);
$paramNew = array_fill(0, 5 - count($param), NULL);
$param = array_merge($param, $paramNew);
$param['active'] = end($param);
$param['self'] = $arr['p'];
foreach ($param as $key => $val) {
$param[$key] = valFile(reset(explode('.', $param[$key])));
}
}
@$param[0] = reset(explode('.', $param[0]));
return $param;
}
?>
@session_start();
//db_conectar('localhost', 'criacaod_mod10', '?gh6dv#LHv;z', 'criacaod_mod10');
db_conectar('localhost', 'markacom_bd', 'Site_2015@#', 'markacom_bd');
if (isset($_GET["pg"]) && is_numeric($_GET["pg"]))
$PGATUAL = $_GET["pg"]; else
$PGATUAL = 1;
ini_set('display_errors', true);
error_reporting((E_ALL & ~E_NOTICE));
function dump($var) {
echo'';
print_r($var);
echo' ';
echo' ';
}
?>