ok
Direktori : /home/institutonamaste/www/admin/class/ |
Current File : /home/institutonamaste/www/admin/class/functions.php |
<?php function MAc($id) { echo (($_SESSION['Menu-Adm'] == $id)? 'active' : ''); } function Bread($lk, $title, $list) { $bread = '<div class="breadcrumb">'; foreach($lk as $value){ if(!empty($value[0])) $bread .= '<a href="'.$value[0].'">'.$value[1].'</a>'; } $bread .= '</div> <h1>'.$title.'</h1> <div class="botao"> <a href="'.$list.'"> <i class="fa fa-list" aria-hidden="true"></i> Listar </a> <a href="?url=cadastrar"> <i class="fa fa-plus" aria-hidden="true"></i> Novo </a>'; if(!$_GET['url']) { $bread .= ' <div class="search"> <form method="GET"> <input name="busca" type="text" placeholder="Buscar informações" value="'.$_GET['busca'].'" required/> <button type="submit"><i class="fa fa-search" aria-hidden="true"></i></button> <button type="button" onClick="window.location.href=\''.$list.'\'"><i class="fa fa-trash-o" aria-hidden="true"></i></button> </form> </div><!-- search -->'; } $bread .=' </div>'; echo $bread; } function FiltroInt($numb) { return (is_numeric($numb)) ? $numb : 0; } function FiltroSemAcentos($lk) { $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", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "-", "", "", "", "", "-", "", "-", "", "", "","-",""); $link = str_replace('--', '-', (str_replace('--', '-', strtolower(str_replace($array1, $array2, $lk))))); return $link; } function GerarLink($tb, $nome, $id = FALSE) { $link = str_replace('.', '',FiltroSemAcentos($nome)); $num = BuscaLK($tb, $link, $id); if($num > 0) { $a = 1; while(BuscaLK($tb, $link."-$a", $id) > 0) $a++; $link = $link."-".$a; } return $link; } function BuscaLK($tb, $link, $id = FALSE) { $idC = ($id) ? " AND id <> '$id'" : ""; $sql = DBRead($tb, "WHERE url = '$link'".$idC, "id"); return (!$sql) ? 0 : mysqli_num_rows($sql); } function ValidData($data) { list($dia, $mes, $ano) = explode("/", $data); if(strlen(trim($ano)) == 4) return $ano.'-'.$mes.'-'.$dia; elseif(strlen(trim($ano)) == 2 && strlen(trim($dia)) == 4) return $data; else LinkAlert('', "Data inválida."); } function VideoYoutubeLink($youtube) { list($x, $link1) = explode("?", $youtube); list($x, $link2) = explode("v=", $link1); list($video, $x) = explode("&", $link2); return $video; } function IcoVideo($img) { return(!empty($img)) ? '<a class="tooltipB"><span><img src="http://i1.ytimg.com/vi/'.$img.'/mqdefault.jpg" width="200"/></span><i class="fa fa-youtube-play" aria-hidden="true"></i></a>' : ''; } function BtDupli($la) { return '<a href="'.$la.'"><i class="fa fa-files-o" aria-hidden="true"></i></a>'; } function BtEdit($la) { return '<a href="'.$la.'"><i class="fa fa-pencil" aria-hidden="true"></i></a>'; } function BtRem($le) { return '<a href="javascript:ConfEx(\''.$le.'\')"> <i class="fa fa-times" aria-hidden="true"></i></a>'; } function MapUrl($loc, $freq, $pri) { return ' <url> <loc>'.$loc.'</loc> <changefreq>'.$freq.'</changefreq> <priority>'.$pri.'</priority> </url>'; } /* PDF */ function FiltroPdf($file, $link, $url) { $pdf = FiltroSemAcentos($file['name']); if($file['type'] != 'application/pdf') { LinkAlert($link, "Formato inválido"); }else{ if(file_exists($url.$pdf)) { $a = 1; while(file_exists($url."[$a]$pdf")){ $a++; } $pdf = "[".$a."]".$pdf; } if(!move_uploaded_file($file['tmp_name'], $url.$pdf)) { LinkAlert($link, "Erro ao enviar o arquivo."); } } return $pdf; } function PdfUpdate($file, $pdf, $la, $li) { if(is_file($file['tmp_name'])) { $doc = FiltroPdf($file, $la, $li); (!empty($pdf) && file_exists($li.$pdf)) ? unlink($li.$pdf) : ''; } else { $doc = $pdf; } return $doc; } function LkPdfDel($pdf, $lk, $li = '') { if(!empty($pdf)) $pdf = ' <div class="img-atual"><b>Arquivo em PDF cadastrado</b><br> <i class="fa fa-file-pdf-o" aria-hidden="true"></i> <a href="javascript:ConfEx(\''.$li.'\')" class="img-delete"><i class="fa fa-times" aria-hidden="true"></i> apagar arquivo</a> </div>'; return $pdf; } function CriarSiteMap() { /*$link = "sitemap.xml"; $site = '<?xml version="1.0" encoding="UTF-8"?> <urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.sitemaps.org/schemas/sitemap/0.9 http://www.sitemaps.org/schemas/sitemap/0.9/sitemap.xsd">'; $site .= MapUrl("http://institutoricardomelo.com.br/", 'weekly', '1.00'); $site .= MapUrl("http://institutoricardomelo.com.br/".'index', 'weekly', '1.00'); $site .= MapUrl("http://institutoricardomelo.com.br/sobre", 'weekly', '0.60'); $site .= MapUrl('http://institutoricardomelo.com.br/ricardo-melo', 'weekly', '0.60'); $site .= MapUrl('http://institutoricardomelo.com.br/irm-midia', 'weekly', '0.60'); $site .= MapUrl('http://institutoricardomelo.com.br/coaching', 'weekly', '0.60'); $site .= MapUrl('http://institutoricardomelo.com.br/cursos', 'weekly', '0.60'); $site .= MapUrl('http://institutoricardomelo.com.br/in-company', 'weekly', '1.00'); $site .= MapUrl('http://institutoricardomelo.com.br/blog', 'weekly', '1.00'); $site .= MapUrl('http://institutoricardomelo.com.br/agenda', 'weekly', '1.00'); $sql = DBRead($this->tb, "ORDER BY id DESC LIMIT 200", "url"); while($row = mysqli_fetch_object($sql)){ $lk = $this->urlArt.$row->url; $site .= $this->MapUrl($lk , 'weekly', '0.80'); } $site .= ' </urlset>'; $link = fopen ("../".$link,"w+"); fwrite($link, $site); */ } function Paginacao($qnt, $p, $link, $where, $table) { $sql = DBRead($table, $where); $total = (!$sql) ? $qnt : mysqli_num_rows($sql); $pags = ceil($total/$qnt); $max_links = 2; $ini = ($p-1 > 0) ? $p-1 : $p; $ind = ($p-1 > 0) ? '' : 'disabled'; $fim = ($p+1 <= $pags) ? $p+1 : $p; $fid = ($p+1 <= $pags) ? '' : 'disabled'; if($total > $qnt) { $page = ' <nav aria-label="..." class="paginacao col-12"> <ul class="pagination"> <li class="page-item '.$ind.'"> <a class="page-link" href="'.$link.'p='.$ini.'" tabindex="-1" aria-label="Previous"><span aria-hidden="true">«</span><span class="sr-only">Voltar</span></a> </li>'; for($i = $p-$max_links; $i <= $p-1; $i++){ if($i > 0) $page .= '<li class="page-item"><a class="page-link" href="'.$link.'p='.$i.'">'.$i.'</a></li>'; } $page .= '<li class="page-item active"><a class="page-link" href="#">'.$p.'<span class="sr-only">(current)</span></a></li>'; for($i = $p+1; $i <= $p+$max_links; $i++){ if($i <= $pags) $page .= '<li class="page-item"><a class="page-link" href="'.$link.'p='.$i.'">'.$i.'</a></li>'; } $page .= ' <li class="page-item '.$fid.'"> <a class="page-link" href="'.$link.'p='.$fim.'" aria-label="Next"><span aria-hidden="true">»</span><span class="sr-only">Próximo</span></a> </li> </ul> </nav>'; } return $page; } function LinkAlert($link = NULL, $text = NULL) { echo (!empty($text)) ? "<script type=\"text/javascript\">alert(\"".$text."\");</script>" : ""; echo (!empty($link)) ? "<META HTTP-EQUIV=REFRESH CONTENT='0; URL=".$link."'>" : "<script language=\"javascript\">parent.history.back(1);</script>";; exit(); } /* DIRETÓRIO */ function GerarPasta($link) { if(!file_exists($link)) { mkdir($dir.$link, 0755, true); return TRUE; } else { return FALSE; } } function RenamePasta($linkold, $link) { if(file_exists($linkold) and !file_exists($link)) { rename($linkold, $link); return TRUE; } else { return FALSE; } } function RemovePasta($link) { if(!empty($link)) rmdir($link); } /* IMAGEMS */ function FiltroImg($file, $link, $li) { $img = FiltroSemAcentos($file['name']); if(!preg_match("/^image\/(jpeg|png|gif|pjpeg|jpg)$/", $file['type'])) { LinkAlert($link, "Formato inválido"); }else{ if(file_exists($li.$img)) { $a = 1; while(file_exists($li."$a-$img")){ $a++; } $img = $a."-".$img; } if(!move_uploaded_file($file['tmp_name'], $li.$img)) { LinkAlert($link, "Erro ao enviar o arquivo."); } } return $img; } function FiltroImgKey($file, $key, $link, $li) { $img = FiltroSemAcentos($file['name'][$key]); if(!preg_match("/^image\/(jpeg|png|gif|pjpeg|jpg)$/", $file['type'][$key])) { LinkAlert($link, "Formato inválido"); }else{ if(file_exists($li.$img)) { $a = 1; while(file_exists($li."$a-$img")){ $a++; } $img = $a."-".$img; } if(!move_uploaded_file($file['tmp_name'][$key], $li.$img)) { LinkAlert($link, "Erro ao enviar o arquivo."); } } return $img; } function IcoImg($img, $lk, $li = '') { if(!empty($li) && file_exists($lk.$img)) $del = ' <a href="javascript:ConfImg(\''.$li.'\')" class="img-delete"><i class="fa fa-times" aria-hidden="true"></i> apagar imagem</a>'; if(!empty($img) && file_exists($lk.$img)) $atual = '<a class="tooltipB"><span><img src="'.$lk.$img.'" width="250"/></span><img src="'.$lk.$img.'" width="50" /></a>'.$del; return(!empty($img)) ? $atual : ''; } function ImgUpdate($file, $img, $la, $li) { if(is_file($file['tmp_name'])) { $image = FiltroImg($file, $la, $li); (!empty($img) && file_exists($li.$img)) ? unlink($li.$img) : ''; } else { $image = $img; } return $image; } function ImageRemove($id, $img, $tb, $li, $rem = TRUE) { $id = FiltroInt($id); if(!empty($id)) { $sql = DBRead($tb, "WHERE id = '$id'", $img); $row = mysqli_fetch_object($sql); if(!empty($row->$img) && file_exists($li.$row->$img)) unlink($li.$row->$img); $pt[$img] = ''; $update = DBUpDate($tb, $pt, "WHERE id = $id"); if($rem) ($update) ? LinkAlert('', "Imagem excluida com sucesso!") : LinkAlert('', "Ocorreu um erro ao excluir a imagem."); } } function LkImgDel($img, $li, $lk) { if(!empty($img)) $img = '<div class="img-atual"><b>Imagem cadastrada</b><br>'.IcoImg($img, $li, $lk).'</div>'; return $img; } /* FILTROS */ function OptionCidade($pais) { $pais = DBEscape($pais); $cidades = array(); $sql = DBExecute(" SELECT c.cidade cidade, c.url url, c.id id FROM ST_localizacao_cidade c INNER JOIN ST_localizacao_estado e ON e.id = c.id_estado INNER JOIN ST_localizacao_pais p ON p.id = e.id_pais WHERE p.id = '$pais'"); while ( $row = mysqli_fetch_assoc( $sql ) ) { $cidades[] = array( 'id_cidade' => $row['id'], 'nome' => $row['cidade'], ); } echo( json_encode($cidades)); } function LinkFranquias($id) { $id = DBEscape($id); $franquia = array(); $sql = DBExecute(" SELECT e.escola escola, e.id eid, i.titulo titulo, f.id fid FROM ST_escola e INNER JOIN ST_escola_franquia f ON e.id = f.id_escola INNER JOIN ST_escola_informacoes i ON i.id = f.id_informacoes WHERE e.id = '$id'"); while ( $row = mysqli_fetch_assoc( $sql ) ) { $franquia[] = array( 'id_franquia' => $row['fid'], 'nome' => $row['titulo'], ); } echo( json_encode($franquia)); } function FlagIdioma($id, $img = 'FALSE') { $sql = DBRead(TB_IDIOMAS, "WHERE id = '".$id."'", "idioma, sigla, img"); $row = mysqli_fetch_object($sql); $image = '<img src="'.ICONE.$row->img.'" title="'.$row->idioma.'"/>'; if($img) return $image; else return $row; } ?>