PageRenderTime 61ms CodeModel.GetById 21ms RepoModel.GetById 1ms app.codeStats 0ms

/scripts_diversos/sendip/crislib.php

https://github.com/prefeituramunicipalosorio/secsaude
PHP | 883 lines | 565 code | 59 blank | 259 comment | 38 complexity | f1992b8d08927a93b2f1c75430966ac9 MD5 | raw file
  1. <?
  2. /*
  3. * crislib - biblioteca de funções em PHP
  4. * Copyright (C) 2012 Tiago Cardoso Floriano <mail@poweredbycaffeine.com.br>
  5. *
  6. * Este programa e software livre; voce pode redistribui-lo e/ou
  7. * modifica-lo sob os termos da Licenca Publica Geral GNU, conforme
  8. * publicada pela Free Software Foundation; tanto a versao 2 da
  9. * Licenca como (a seu criterio) qualquer versao mais nova.
  10. *
  11. * Este programa e distribuido na expectativa de ser util, mas SEM
  12. * QUALQUER GARANTIA; sem mesmo a garantia implicita de
  13. * COMERCIALIZACAO ou de ADEQUACAO A QUALQUER PROPOSITO EM
  14. * PARTICULAR. Consulte a Licenca Publica Geral GNU para obter mais
  15. * detalhes.
  16. *
  17. * Voce deve ter recebido uma copia da Licenca Publica Geral GNU
  18. * junto com este programa; se nao, escreva para a Free Software
  19. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
  20. * 02111-1307, USA.
  21. *
  22. * Copia da licenca no diretorio licenca/licenca_en.txt
  23. * licenca/licenca_pt.txt
  24. */
  25. /**
  26. * @name crisLib <http://paico.wordpress.com/crislib/>
  27. * @author Original by Tiago Floriano <mail@tiagofloriano.com.br> <http://tiagofloriano.com/>
  28. * @author Modified by LeoCaseiro <http://www.leocaseiro.com/> 2008-11-28 11:47
  29. * @author Modified by nome <email ou URI> aaaa-mm-dd hh:mm //para os pr�ximos que modificarem
  30. * @version 1.0.2
  31. * @license GPLv2
  32. * @since Documenta��o no formato PHPDocumentor e arquivo em UTF-8 Release 1.0.1 //aqui devemos colocar as releases
  33. *
  34. *
  35. *
  36. * �NDICE
  37. *
  38. * Resumo de fun��es: fun��es que s�o abrevia��es(resumos) de outras fun��es
  39. * Login de usu�rios: funl�oes para fazer um login de usu�rio de forma simples e pr�tica
  40. * Banco de Dados: fun��es para inserir, selecionar, excluir e atualizar dados
  41. * Arquivos: manipula��o de Arquivos
  42. * Protocolos: email e ftp
  43. * Utilidades: fun��es �teis
  44. * Plugins: adicione aqui os plugins da crisLib
  45. *
  46. */
  47. ####################
  48. ### Resumo de Funes ###
  49. ####################
  50. /**
  51. * Atalho para a fun��o mysql_escape_string
  52. *
  53. * @name escape
  54. * @author php-br, canal brasileiro de PHP no IRC <irc.freenode.net>
  55. * @param string $string //troquei de $n para $string, assim fica mais semantico by LeoCaseiro
  56. * @return string
  57. */
  58. function escape($string){
  59. return mysql_escape_string($string);
  60. }
  61. /**
  62. * Atalho do mysql_num_rows
  63. *
  64. * @name total
  65. * @param string $query
  66. * @return int $num
  67. */
  68. function total($query){
  69. $num = mysql_num_rows($query);
  70. return $num;
  71. }
  72. /**
  73. * Atalho para fun��o mysql_fetch_array
  74. *
  75. * @name fetch
  76. * @param string $query
  77. * @return array
  78. */
  79. function fetch($query){
  80. $fetch = mysql_fetch_array($query);
  81. return $fetch;
  82. }
  83. /**
  84. * Resumo da fun��o mysql_real_escape_string
  85. *
  86. * @name str
  87. * @param string $nome
  88. * @return string
  89. */
  90. function str($nome){
  91. $filtro = strip_tags($nome);
  92. $filtro = addslashes($filtro);
  93. $filtro = mysql_real_escape_string($filtro);
  94. return $filtro;
  95. }
  96. /**
  97. * Atalho da fun��o echo
  98. *
  99. * @name e
  100. * @param string $texto
  101. * @return string
  102. */
  103. function e($texto){
  104. echo $texto;
  105. }
  106. /**
  107. * Imprime um par�grafo centralizado
  108. *
  109. * @name p
  110. * @param string $texto
  111. * @param bool $red caso for true, exibe texto em vermelho
  112. */
  113. function p($texto, $red = false){ //(deixei por default o normal, assim...basta digitar p("escrevi aqui"); //Sem precisar do $red
  114. if(!$red){ //mensagem normal
  115. e("<p align=\"center\">$texto</p>");
  116. }elseif($red){ //mensagem de erro
  117. e("<p align=\"center\" style=\"color: red\">$texto</p>");
  118. }else{
  119. echo "<p>$texto</p>";
  120. }
  121. }
  122. ####################
  123. ### LOGIN DE USURIO ###
  124. ####################
  125. /**
  126. * Fun��o que autentica o usu�rio
  127. *
  128. * @name login
  129. * @param string $usuario
  130. * @param string $senha
  131. * @param string $tabela_de_usuarios
  132. * @param string $tabela_de_sessoes
  133. * @param string $destino
  134. */
  135. function login($usuario, $senha, $tabela_de_usuarios, $tabela_de_sessoes, $destino){
  136. //verifica se o usu�rio e a senha constam na tabela
  137. echo "Verificando usu&aacute;rio ... ";
  138. $sel = sel($tabela_de_usuarios,"usuario = '$usuario' and senha = '$senha'","","");
  139. echo "<b>ok</b><br>";
  140. if(mysql_num_rows($sel) == 0){//se n�o existir, mostra a mensagem abaixo
  141. echo "<i>Este usu&aacute;rio n&atilde;o existe!</i><br><br>";
  142. echo "<a href=\"javascript:history.go(-1);\">Voltar</a>";
  143. exit; //encerra a execu��o do arquivo, n�o permitindo que o usu�rio prossiga
  144. }else{
  145. echo "Gravando sess&atilde;o ... ";
  146. //guarda usuario e senha
  147. $_SESSION["login"] = $usuario;
  148. $_SESSION["senha"] = $senha;
  149. echo "<b>ok</b><br>";
  150. //guarda um valor de sess�o �nico para gravar que o usu�rio est� logado
  151. if($tabela_de_controle_de_sessoes != ""){
  152. $_SESSION["idsession"] = date("H") + date("i") + date("s") + date("d") + date("m") + date("Y");
  153. $idsession = $_SESSION["idsession"];
  154. ins($tabela_de_controle_de_sessoes,"usuario, senha, sessao, status","'$usuario', '$senha', '$idsession','online'");
  155. }
  156. echo "Redirecionando ... ";
  157. echo "<meta http-equiv=\"refresh\" content=\"0;URL=$destino\">";
  158. echo "<b>ok</b>";
  159. exit;
  160. }
  161. }
  162. /**
  163. * Fun��o para desautenticar o usu�rio
  164. *
  165. * @name logoff
  166. * @param sting $usuario
  167. * @param string $senha //na minha opini�o, este valor � desnecess�rio para esta fun��o By LeoCaseiro
  168. * @param string $tabela_de_usuarios
  169. * @param string $tabela_de_sessoes
  170. * @param string $destino
  171. */
  172. function logoff($usuario, $senha, $tabela_de_usuarios, $tabela_de_sessoes, $destino){
  173. if($tabela_de_sessoes != ""){
  174. $ids = $_SESSION["idsession"];
  175. $sel = sel($tabela_de_sessoes,"ids = '$ids' and usuario = '$usuario and senha = '$senha'","","");
  176. if(total($sel) != 0){
  177. $r = fetch($sel);
  178. $del = del($tabela_de_sessoes,$r["id"]);
  179. $_SESSION["idsession"] = "";
  180. $_SESSION["login"] = "";
  181. $_SESSION["senha"] = "";
  182. echo "Usu&aacute;rio desautenticado...";
  183. }
  184. }else{
  185. $login = $_SESSION["login"];
  186. $senha = $_SESSION["senha"];
  187. $sel = sel($tabela_de_usuarios,"login = '$login' and senha = '$senha'","","");
  188. if(total($sel) > 0){
  189. $_SESSION["login"] = "";
  190. $_SESSION["senha"] = "";
  191. echo "Usu&aacute;rio desautenticado...";
  192. }
  193. }
  194. }
  195. /**
  196. * Verifica se o usu�rio est� autenticado e o redireciona para a p�gina de login
  197. *
  198. * @name is_autenticado
  199. * @param string $tabela_de_usuarios
  200. * @param string $destino
  201. * @param string $tabela_de_sessoes
  202. */
  203. function is_autenticado($tabela_de_usuarios, $destino, $tabela_de_sessoes) {
  204. if(is_on($tabela_de_usuarios,$tabela_de_sessoes) == false){
  205. e("Voc&ecirc; n&atilde;o est&aacute; logado! Redirecionando...");
  206. e("<meta http-equiv=\"refresh\" content=\"0;URL=$destino\">");
  207. }
  208. }
  209. /**
  210. * Verifica se o usu�rio est� autenticado
  211. *
  212. * @name is_on
  213. * @param string $tabela_de_usuarios
  214. * @param bool $tabela_de_sessoes caso for true, verifica autentica��o atrav�s de tabela de controle de sess�es no banco de dados
  215. * @return bool
  216. */
  217. function is_on($tabela_de_usuarios, $tabela_de_sessoes = false){
  218. $login = str($_SESSION["login"]);
  219. $senha = str($_SESSION["senha"]);
  220. $sel = sel($tabela_de_usuarios,"usuario = '$login' and senha = '$senha'","","");
  221. if(total($sel) == 0){
  222. return false;
  223. }else{
  224. if($tabela_de_sessoes != ""){
  225. $ids = $_SESSION["idsession"];
  226. $sel = sel($tabela_de_sessoes,"ids = '$ids' and usuario = '$usuario and senha = '$senha'","","");
  227. if(total($sel) == 0){
  228. return false;
  229. }else{
  230. return true;
  231. }
  232. }else{
  233. return true;
  234. }
  235. }
  236. }
  237. ######################
  238. ### BANCO DE DADOS ###
  239. ######################
  240. /**
  241. * Fun��o para conectar no Bando de Dados
  242. *
  243. * @name con
  244. * @param string $usuario
  245. * @param string $senha
  246. * @return bool
  247. */
  248. function con($usuario, $senha, $localhost=false){
  249. if($localhost == false){ $localhost = "localhost"; }
  250. if(!mysql_connect($localhost,$usuario,$senha)){
  251. echo "Erro ao conectar no db.";
  252. return false;
  253. } else {
  254. return true;
  255. }
  256. }
  257. /**
  258. * Selecionando um db
  259. *
  260. * @name db
  261. * @param string $db
  262. * @return bool
  263. */
  264. function db($db){
  265. if(!mysql_select_db($db)){
  266. echo "Erro ao selecionar db.";
  267. return false;
  268. } else {
  269. return true;
  270. }
  271. }
  272. /**
  273. * Fun��o para exucutar consulta(select) no banco
  274. *
  275. * @name sel
  276. * @param string $tabela
  277. * @param string $condicoes
  278. * @param string $ordem
  279. * @param int $limite
  280. * @return true|die if die, print mysql_error
  281. */
  282. function sel($tabela, $condicoes, $ordem = false, $limite = false){
  283. $query = "SELECT * FROM $tabela";
  284. if($condicoes != "") {
  285. $query .= " WHERE $condicoes";
  286. }
  287. if($ordem != ""){
  288. $query .= " ORDER BY $ordem";
  289. }
  290. if($limite != ""){
  291. $query .= " LIMIT $limite";
  292. }
  293. $sql = mysql_query($query) or die(mysql_error());
  294. return $sql;
  295. }
  296. /**
  297. * Retorna o valor de um determinado registro(id) na tabela
  298. *
  299. * @name campo
  300. * @param string $tabela
  301. * @param string $campo
  302. * @param int $id
  303. * @return string
  304. */
  305. function campo($tabela, $campo, $id){
  306. $sel = mysql_query("SELECT * FROM $tabela WHERE id = '$id'") or die(mysql_error());
  307. $r = mysql_fetch_array($sel);
  308. return $r[$campo];
  309. }
  310. /**
  311. * Insere os campos com os respectivos valores
  312. *
  313. * @name ins
  314. * @param string $tabela
  315. * @param string $campos seguidos de v�rgula
  316. * @param string $valores seguidos de v�rgula
  317. * @return true|die if die, print mysql_error
  318. */
  319. function ins($tabela, $campos, $valores){
  320. $query = "INSERT INTO $tabela ($campos) VALUES ($valores)";
  321. $sql = mysql_query($query) or die(mysql_error());
  322. return $sql;
  323. }
  324. /**
  325. * Efetua uma altera��o (update) em uma tabela com seus respectivos valores
  326. *
  327. * @name upd
  328. * @param string $tabela
  329. * @param string $dados
  330. * @param int $id
  331. * @return true|die if die, print mysql_error
  332. */
  333. function upd($tabela, $dados, $id){
  334. $query = "UPDATE $tabela SET $dados WHERE id = '$id'";
  335. $sql = mysql_query($query) or die(mysql_error());
  336. return $sql;
  337. }
  338. /**
  339. * Deletar
  340. *
  341. * @name del
  342. * @param string $tabela
  343. * @param int $id
  344. * @return true|die if die, print mysql_error
  345. */
  346. function del($tabela, $id){
  347. $query = "DELETE FROM $tabela WHERE id = '$id'";
  348. $sql = mysql_query($query) or die(mysql_error());
  349. return $sql;
  350. }
  351. /**
  352. * Criar tabela
  353. *
  354. * @name createT
  355. * @param string $nometabela
  356. * @param string $campos
  357. * @return true|die if die, print mysql_error
  358. */
  359. function createT($nometabela,$campos){
  360. $sql = mysql_query("CREATE TABLE IF NOT EXISTS $nometabela ( id int(11), $campos, primary key(id) )") or die(mysql_error());
  361. return $sql;
  362. }
  363. ##############
  364. ### ARQUIVOS ###
  365. ##############
  366. # - Nome: Upload de arquivos
  367. function up($arquivo,$destino,$extensoes){//para permitir todas extens��es de arquivos, deixe a $extens�es em branco, se n�o, informe todas as extens�es permitidas
  368. }
  369. # - Nome: Gera miniatura de imagem gif, png ou jpg
  370. /**
  371. * Gera miniatura de imagem gif, png ou jpg
  372. *
  373. * @param string $imagem
  374. * @param int $h altura
  375. * @param int $w largura
  376. * @return string endere�o da miniatura gerada da imagem ($imagem)
  377. * @example im("imagens/minhaimagem.png",150,200);
  378. */
  379. function im($imagem, $h, $w){
  380. //verifica na $imagem o que � pasta, o que � arquivo e o que � extens�o
  381. $explode = explode("/",$imagem);
  382. $pasta = $explode[0]."/"; // $pasta = pasta_de_imagens/
  383. $arquivo = $explode[1]; // $arquivo = arquivo.jpg ou .gif ou .png
  384. $explode = explode(".",$arquivo);
  385. $extensao = $explode[1];
  386. $nomearquivo = $explode[0];
  387. //script original: http://sniptools.com/tutorials/generating-jpggifpng-thumbnails-in-php-using-imagegif-imagejpeg-imagepng
  388. //adaptado por Tiago Floriano Webdesigner em 27 de outubro de 2007
  389. $thumbWidth = $w; // Intended dimension of thumb
  390. $thumbHeight = $h;
  391. if(!file_exists($pasta.$nomearquivo."_".$w.$h.".".$extensao)){
  392. if($extensao == "jpg" or $extensao == "JPG" or $extensao == "jpeg" or $extensao == "JPEG"){
  393. // Beyond this point is simply code.
  394. $sourceImage = imagecreatefromjpeg($imagem);
  395. $sourceWidth = imagesx($sourceImage);
  396. $sourceHeight = imagesy($sourceImage);
  397. $targetImage = imagecreatetruecolor($thumbWidth,$thumbHeight);
  398. imagecopyresampled($targetImage,$sourceImage,0,0,0,0,$thumbWidth,$thumbHeight,imagesx($sourceImage),imagesy($sourceImage));
  399. imagejpeg($targetImage,$pasta.$nomearquivo."_".$w.$h.".".$extensao);
  400. $thumbName = $pasta.$nomearquivo."_".$w.$h.".".$extensao;
  401. }
  402. if($extensao == "gif" or $extensao == "GIF"){
  403. // Beyond this point is simply code.
  404. $sourceImage = imagecreatefromgif($imagem);
  405. $sourceWidth = imagesx($sourceImage);
  406. $sourceHeight = imagesy($sourceImage);
  407. $targetImage = imagecreatetruecolor($thumbWidth,$thumbHeight);
  408. imagecopyresampled($targetImage,$sourceImage,0,0,0,0,$thumbWidth,$thumbHeight,imagesx($sourceImage),imagesy($sourceImage));
  409. imagegif($targetImage, $pasta.$nomearquivo."_".$w.$h.".".$extensao);
  410. $thumbName = $pasta.$nomearquivo."_".$w.$h.".".$extensao;
  411. }
  412. if($extensao == "png" or $extensao == "PNG"){
  413. // Beyond this point is simply code.
  414. $sourceImage = imagecreatefrompng($imagem);
  415. $sourceWidth = imagesx($sourceImage);
  416. $sourceHeight = imagesy($sourceImage);
  417. $targetImage = imagecreatetruecolor($thumbWidth,$thumbHeight);
  418. imagecopyresampled($targetImage,$sourceImage,0,0,0,0,$thumbWidth,$thumbHeight,imagesx($sourceImage),imagesy($sourceImage));
  419. imagepng($targetImage, $pasta.$nomearquivo."_".$w.$h.".".$extensao);
  420. $thumbName = $pasta.$nomearquivo."_".$w.$h.".".$extensao;
  421. }
  422. }else{
  423. $thumbName = $pasta.$nomearquivo."_".$w.$h.".".$extensao;
  424. }
  425. return $thumbName;
  426. }
  427. /**
  428. * Exibe arquivos de uma pasta
  429. *
  430. * @param string $diretorio
  431. */
  432. function pasta($diretorio){
  433. }
  434. /**
  435. * Edita arquivo
  436. *
  437. * @param string $arquivo
  438. */
  439. function arq($arquivo){
  440. }
  441. ################
  442. ### PROTOCOLOS ###
  443. ################
  444. /**
  445. * Fun��o para Enviar E-mail
  446. *
  447. * @param string $destino
  448. * @param string $assunto
  449. * @param string $mensagem
  450. * @param string $remetente
  451. * @param string $tipo (html|texto)
  452. * @param string $protocolo (mail|smtp)
  453. */
  454. function sendmail($destino, $assunto, $mensagem, $remetente, $tipo, $protocolo){//o $tipo � se o e-mail � html ou somente texto, o $protocolo � se � usando a fun��o mail ou smtp
  455. if($protocolo == "mail"){ //criado por LeoCaseiro e adaptado por Tiago Floriano
  456. if($tipo == "html"){
  457. /* Para enviar email HTML, voc� precisa definir o header Content-type. */
  458. $headers = 'MIME-Version: 1.0\n';
  459. $headers .= 'Content-type: text/html; charset=iso-8859-1\n';
  460. }
  461. /* headers adicionais */
  462. $headers .= "From: $deNome <$deEmail>\r\n";
  463. $headers .= "To: $paraNome <$paraEmail>\r\n";
  464. /* Enviar o email */
  465. if(mail($para, $assunto, $mensagem, $headers)) {
  466. return true;
  467. }else{
  468. return false;
  469. }
  470. }else{
  471. //smtp
  472. }
  473. }
  474. /**
  475. * Criar conta de e-mail no cPanel
  476. *
  477. * @param string $email
  478. * @param string $senha
  479. */
  480. function criamail($email, $senha){
  481. }
  482. /**
  483. * Deleta e-mail do cPanel
  484. *
  485. * @param string $email
  486. * @param string $senha
  487. */
  488. function delmail($email,$senha){
  489. }
  490. ##########################
  491. ### UTILIDADES E INUTILIDADES ###
  492. ##########################
  493. /**
  494. * Retira caracteres especiais de uma string
  495. *
  496. * @param string $string
  497. * @return string
  498. */
  499. function remCE($string){
  500. //retira acentos
  501. $string = str_replace("ã","a",$string);
  502. $string = str_replace("á","a",$string);
  503. $string = str_replace("à","a",$string);
  504. $string = str_replace("ä","a",$string);
  505. $string = str_replace("â","a",$string);
  506. #$string = str_replace("ẽ","e",$string);
  507. $string = str_replace("é","e",$string);
  508. $string = str_replace("è","e",$string);
  509. $string = str_replace("ë","e",$string);
  510. $string = str_replace("ê","e",$string);
  511. $string = str_replace("ĩ","i",$string);
  512. $string = str_replace("í","i",$string);
  513. $string = str_replace("ì","i",$string);
  514. $string = str_replace("ï","i",$string);
  515. $string = str_replace("î","i",$string);
  516. $string = str_replace("õ","o",$string);
  517. $string = str_replace("ó","o",$string);
  518. $string = str_replace("ò","o",$string);
  519. $string = str_replace("ö","o",$string);
  520. $string = str_replace("ô","o",$string);
  521. $string = str_replace("ũ","u",$string);
  522. $string = str_replace("ú","u",$string);
  523. $string = str_replace("ù","u",$string);
  524. $string = str_replace("ü","u",$string);
  525. $string = str_replace("û","u",$string);
  526. $string = str_replace("ç","c",$string);
  527. //retira outras porcarias
  528. $string = str_replace("\"","",$string);
  529. $string = str_replace("'","",$string);
  530. $string = str_replace("�","",$string);
  531. $string = str_replace("`","",$string);
  532. $string = str_replace("!","",$string);
  533. $string = str_replace("#","",$string);
  534. $string = str_replace("$","",$string);
  535. $string = str_replace("%","",$string);
  536. $string = str_replace("�","",$string);
  537. $string = str_replace("&","",$string);
  538. $string = str_replace("*","",$string);
  539. $string = str_replace("(","",$string);
  540. $string = str_replace(")","",$string);
  541. $string = str_replace("_","",$string);
  542. $string = str_replace("-","",$string);
  543. $string = str_replace("+","",$string);
  544. $string = str_replace("=","",$string);
  545. $string = str_replace("�","",$string);
  546. $string = str_replace("}","",$string);
  547. $string = str_replace("]","",$string);
  548. $string = str_replace("�","",$string);
  549. $string = str_replace("�","",$string);
  550. $string = str_replace("�","",$string);
  551. $string = str_replace("�","",$string);
  552. $string = str_replace("�","",$string);
  553. $string = str_replace("�","",$string);
  554. $string = str_replace("{","",$string);
  555. $string = str_replace("[","",$string);
  556. $string = str_replace("�","",$string);
  557. $string = str_replace("^","",$string);
  558. $string = str_replace("~","",$string);
  559. $string = str_replace("?","",$string);
  560. $string = str_replace("/","",$string);
  561. $string = str_replace("�","",$string);
  562. $string = str_replace("<","",$string);
  563. $string = str_replace(",","",$string);
  564. $string = str_replace(">","",$string);
  565. # $string = str_replace(".","",$string);
  566. $string = str_replace(":","",$string);
  567. $string = str_replace(";","",$string);
  568. $string = str_replace("|","",$string);
  569. $string = str_replace("\\","",$string);
  570. $string = str_replace(" ","",$string);
  571. //retira espa�os
  572. $string = trim($string);
  573. return $string;
  574. }
  575. /**
  576. * Exibe m�s em Portugu�s do Brasil
  577. *
  578. * @param int $mes
  579. * @return string (use ucfirst para deixar com a 1a. letra mai�scula)
  580. */
  581. function mes($mes){
  582. if($mes == 1){
  583. $mes = "janeiro";
  584. }
  585. if($mes == 2){
  586. $mes = "fevereiro";
  587. }
  588. if($mes == 3){
  589. $mes = "mar&ccedil;o";
  590. }
  591. if($mes == 4){
  592. $mes = "abril";
  593. }
  594. if($mes == 5){
  595. $mes = "maio";
  596. }
  597. if($mes == 6){
  598. $mes = "junho";
  599. }
  600. if($mes == 7){
  601. $mes = "julho";
  602. }
  603. if($mes == 8){
  604. $mes = "agosto";
  605. }
  606. if($mes == 9){
  607. $mes = "setembro";
  608. }
  609. if($mes == 10){
  610. $mes = "outubro";
  611. }
  612. if($mes == 11){
  613. $mes = "novembro";
  614. }
  615. if($mes == 12){
  616. $mes = "dezembro";
  617. }
  618. return $mes;
  619. }
  620. /**
  621. * Transforma data formato aaaa-mm-dd para dd/mm/aaaa ou dd de mm de aaaa
  622. *
  623. * @param string $data (aaaa-mm-dd)
  624. * @param bool $tipo (if true, exibe dd/mm/aaaa, else print dd de mm de aaaa) //valor default
  625. * @return string (dd/mm/aaaa)
  626. */
  627. function data($data, $tipo = 0){
  628. if($tipo == 0){
  629. $data = explode("-",$data);
  630. $data = $data[2]."/".$data[1]."/".$data[0];
  631. }elseif($tipo == 1){
  632. $data = explode("-",$data);
  633. $data = $data[2]." de ".mes($data[1])." de ".$data[0];
  634. }else{
  635. $data = explode("/",$data);
  636. $data = $data[2]."-".$data[1]."-".$data[0];
  637. }
  638. return $data;
  639. }
  640. /**
  641. * Atalho para URL (Ex: ?pagina ao inv�s de page=pagina)
  642. *
  643. * @param string $uri
  644. * @param string $pasta
  645. * @return string
  646. * @example $path = url($_SERVER['REQUEST_URI'],"meusite/"); include($path);
  647. */
  648. function url($uri, $pasta) { //Podemos amadurecer mais ainda esta fun��o
  649. if($uri == "/$pasta"){ $uri = "/?home"; }
  650. $uri = explode("?",$uri);
  651. $uri = explode("&",$uri[1]);
  652. $uri = $uri[0];
  653. $arquivo = "pages/".$uri.".php";//pages ? o nome da pasta onde ficar?o os arquivos internos que guardam o conte?do, que ser?o inseridos no arquivo principal, no lugar do conte?do. Mude para o nome da pasta onde voc? guarda os arquivos.
  654. if(is_file($arquivo)){
  655. $path = $arquivo;
  656. }else{
  657. $path = "pages/erro.php";
  658. }
  659. return $path;
  660. }
  661. /**
  662. * Verifica se uma string est� vazia
  663. *
  664. * @param string $var
  665. * @param int $num
  666. * @return bool
  667. */
  668. function is_clear($var, $num){ //pega variavel e o n�mero de campos que h� nela
  669. $str = explode(" ",$var); //registra array
  670. $cont = 0;
  671. while($cont <= $num){ //enquanto a $cont for diferente de $num, ele faz a verifica��o
  672. if($str[$cont] != ""){ //se $str n�o for vazia, soma 1 na $result
  673. $result = $result + 1;
  674. }
  675. $cont = $cont + 1;
  676. }
  677. if($result == $num){ //se todas as $str tiverem valor, o resultado deste if deve ser true
  678. return true;
  679. }else{ //se houver algum campo vazio, dar� false
  680. return false;
  681. }
  682. }
  683. /**
  684. * Fun��o que gera lista de um select de estado(UF) do Brasil
  685. *
  686. * @param string $tipo (full)
  687. * @param string $selecione (campo marcado)
  688. */
  689. function gerauf($tipo, $selecione){ //Acho que poderia melhorar essa fun��o usando o selected="selected" e tamb�m trocando a ordem dos campos
  690. if($tipo == "full"){
  691. echo "<select name=\"uf\">";
  692. echo "<option>$selecione</option>";
  693. }
  694. echo "<option value=\"AC\">AC</option>
  695. <option value=\"AL\">AL</option>
  696. <option value=\"AP\">AP</option>
  697. <option value=\"AM\">AM</option>
  698. <option value=\"BA\">BA</option>
  699. <option value=\"CE\">CE</option>
  700. <option value=\"DF\">DF</option>
  701. <option value=\"ES\">ES</option>
  702. <option value=\"GO\">GO</option>
  703. <option value=\"MA\">MA</option>
  704. <option value=\"MT\">MT</option>
  705. <option value=\"MS\">MS</option>
  706. <option value=\"MG\">MG</option>
  707. <option value=\"PA\">PA</option>
  708. <option value=\"PB\">PB</option>
  709. <option value=\"PR\">PR</option>
  710. <option value=\"PE\">PE</option>
  711. <option value=\"PI\">PI</option>
  712. <option value=\"RJ\">RJ</option>
  713. <option value=\"RN\">RN</option>
  714. <option value=\"RS\">RS</option>
  715. <option value=\"RO\">RO</option>
  716. <option value=\"RR\">RR</option>
  717. <option value=\"SC\">SC</option>
  718. <option value=\"SP\">SP</option>
  719. <option value=\"SE\">SE</option>
  720. <option value=\"TO\">TO</option>";
  721. if($tipo == "full"){
  722. echo "</select>";
  723. }
  724. }
  725. function redir($url,$tempo=0){
  726. e("<meta http-equiv=\"refresh\" content=\"$tempo;URL=$url\">");
  727. }
  728. ##################
  729. ### PLUGINS
  730. /* para adicionar novas extens��es, adicione as seguintes linhas abaixo:
  731. if(file_exists("nomedoarquivo.php")){
  732. include("nomedoarquivo.php");
  733. }
  734. */
  735. # para pegar plugins da crisLib acesse http://blogosfera.us
  736. # para adicionar plugins no site da crisLib, envie para crislib@blogosfera.us. Seus crditos sero mantidos!
  737. /**
  738. * Mostra mensagem de informação usando jqueryui.com. Baixe a biblioteca em http://jqueryui.com para usar esta função.
  739. * @name info
  740. * @since v. r2
  741. * @param string $txt
  742. * @example info("Cadastro efetuado com sucesso!");
  743. * @return string
  744. */
  745. function info($txt,$width=false){
  746. if($width == true){ $width = "width: ".$width."px"; }
  747. e("<div class=\"ui-widget\" style=\"margin-top: 3px;$width\">");
  748. e("<div class=\"ui-state-highlight ui-corner-all\" style=\"padding: 5px;\">");
  749. e("<span class=\"ui-icon ui-icon-info\" style=\"float: left; margin-right: 0.3em;\"></span><span style=\"font-size: 11px;\">");
  750. e($txt);
  751. e("</span></div>");
  752. e("</div>");
  753. }
  754. /**
  755. * Mostra mensagem de erro usando jqueryui.com. Baixe a biblioteca em http://jqueryui.com para usar esta função.
  756. * @name error
  757. * @since v. r2
  758. * @param string $txt
  759. * @example error("Você não preencheu o campo e-mail!");
  760. * @return string
  761. */
  762. function error($txt,$width=false){
  763. if($width == true){ $width = "width: ".$width."px"; }
  764. e("<div class=\"ui-widget\" style=\"margin-top: 3px;$width\">");
  765. e("<div class=\"ui-state-error ui-corner-all\" style=\"padding: 5px;\">");
  766. e("<span class=\"ui-icon ui-icon-info\" style=\"float: left; margin-right: 0.3em;\"></span><span style=\"font-size: 11px;\">");
  767. e($txt);
  768. e("</span></div>");
  769. e("</div>");
  770. }
  771. /**
  772. * Cria janela popup
  773. * @param string $nomejanela
  774. * @param string $nomedivajax
  775. * @param int $width
  776. * @param int $height
  777. * @param string|boolean $conteudo
  778. */
  779. function janelaUI($nomejanela,$nomedivajax,$width,$height,$conteudo=false){
  780. ?>
  781. <div id="<?= $nomejanela ?>" style="display: none;">
  782. <div class="ui-overlay">
  783. <div class="ui-widget-overlay" style="position: absolute; z-index: 99999999999999;"></div>
  784. <div id="<?= $nomejanela ?>_background" class="ui-widget-shadow ui-corner-all" style="width: <?= $width+22 ?>px; height: <?= $height+22 ?>px; position: absolute; z-index: 99999999999999; left: 50%; top: 50%; padding: 11px; margin-left: -<?= ($width+22)/2 ?>px; margin-top: -<?= ($height+22)/2 ?>px;"></div>
  785. </div>
  786. <div id="<?= $nomedivajax ?>" style="position: absolute; z-index: 99999999999999; width: <?= $width ?>px; height: <?= $height ?>px; left: 50%; top: 50%; padding: 10px; margin-left: -<?= $width/2 ?>px; margin-top: -<?= $height/2 ?>px; overflow:auto;" class="ui-widget ui-widget-content ui-corner-all"><?= $conteudo ?></div>
  787. </div>
  788. <?
  789. }
  790. /**
  791. * Cria tag <a> com jqueryui
  792. * @param string $nome
  793. * @param string $onclick
  794. * @param string $icon
  795. */
  796. function aUI($nome,$onclick,$icon,$href=false){
  797. if($href == false){ $href = "#"; }
  798. e("<a href=\"$href\" onclick=\"$onclick\" id=\"dialog_link\" class=\"ui-state-default ui-corner-all\" style=\"margin-right: 5px;\"><span class=\"ui-icon ui-icon-$icon\"></span>$nome</a>");
  799. }
  800. ?>