Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- // error_reporting(E_ALL ^ E_NOTICE);
- if ( (!defined('BASE_INCLUSA')) or (count(get_included_files()) == 1) )
- {
- header( $_SERVER["SERVER_PROTOCOL"]." 404 Not Found", true, 404 );
- exit();
- }
- ####
- ####
- ####
- define( 'USR_INCLUSO', true );
- require_once( dirname( $_SERVER["DOCUMENT_ROOT"] ) . "/usr.php" );
- // $app["raiz"] = dirname(__FILE__);
- define( "APP_RAIZ", dirname(__FILE__) . "/dashboard/" );
- // define( "APP", "RAIZ" => dirname(__FILE__) );
- ####
- ####
- ####
- // $db["sys_pct"]["pk"] = "paciente_id";
- define( "THE_ROOT", $_SERVER["DOCUMENT_ROOT"] . "/" );
- define( "THE_ROOT_DEBUG", THE_ROOT . "debug" );
- define( "THE_ROOT_SESSOES", THE_ROOT . "sessoes" );
- // define( "THE_ROOT_API", THE_ROOT . "api" );
- define( "THE_ROOT_CLASS", THE_ROOT . "classes" );
- // define( "THE_ROOT_SMTP", THE_ROOT_API . "/smtp" );
- // define( "THE_ROOT_INCLUDE", THE_ROOT . "inc" );
- define( "THE_ROOT_CABECALHO", THE_ROOT . "header.php" );
- define( "THE_ROOT_RODAPE", THE_ROOT . "footer.php" );
- define( "THE_ROOT_ESTATICOS", THE_ROOT . "estaticos" );
- /*
- define( "THE_ROOT_CARIMBOS", THE_ROOT_ESTATICOS . "/carimbos" );
- define( "THE_ROOT_CARIMBOS_FISIO", THE_ROOT_CARIMBOS . "/fisio" );
- define( "THE_ROOT_CARIMBOS_FONO", THE_ROOT_CARIMBOS . "/fono" );
- define( "THE_ROOT_CARIMBOS_TO", THE_ROOT_CARIMBOS . "/to" );
- define( "THE_ROOT_CARIMBOS_NUTR", THE_ROOT_CARIMBOS . "/nutri" );
- define( "THE_ROOT_CURRICULOS", THE_ROOT_ESTATICOS . "/curriculos" );
- */
- define( "THE_ROOT_IMAGENS", THE_ROOT_ESTATICOS . "/imagens" );
- ####
- ####
- ####
- /*
- define( "THE_VOLUME", "/mnt/volume-nyc1-01/fisiolar" );
- #
- define( "VOLUME_CURRICULOS", THE_VOLUME."/curriculos" );
- define( "VOLUME_CARIMBOS", THE_VOLUME."/carimbos" );
- define( "VOLUME_CARIMBOS_FTA", VOLUME_CARIMBOS."/fta" );
- define( "VOLUME_CARIMBOS_FGA", VOLUME_CARIMBOS."/fga" );
- define( "VOLUME_CARIMBOS_TO", VOLUME_CARIMBOS."/to" );
- define( "VOLUME_CARIMBOS_NUTR", VOLUME_CARIMBOS."/nutr" );
- define( "VOLUME_FICHAS", THE_VOLUME."/fichas" );
- define( "VOLUME_FICHAS_FTA", VOLUME_FICHAS."/fta" );
- define( "VOLUME_FICHAS_FGA", VOLUME_FICHAS."/fga" );
- define( "VOLUME_FICHAS_TO", VOLUME_FICHAS."/to" );
- define( "VOLUME_FICHAS_NUTR", VOLUME_FICHAS."/nutr" );
- #
- define( "THE_ROOT_CURRICULOS", THE_VOLUME."/curriculos" );
- define( "THE_ROOT_CARIMBOS", THE_VOLUME."/carimbos" );
- define( "THE_ROOT_CARIMBOS_FISIO", THE_ROOT_CARIMBOS."/fta" );
- define( "THE_ROOT_CARIMBOS_FONO", THE_ROOT_CARIMBOS."/fga" );
- define( "THE_ROOT_CARIMBOS_TO", THE_ROOT_CARIMBOS."/to" );
- define( "THE_ROOT_CARIMBOS_NUTR", THE_ROOT_CARIMBOS."/nutr" );
- // define( "THE_ROOT_FICHAS", THE_VOLUME . "/fichas" );
- define( "THE_ROOT_FICHAS", THE_ROOT_ESTATICOS . "/fichas" );
- define( "THE_ROOT_FICHAS_FISIO", THE_ROOT_FICHAS . "/fisio" );
- define( "THE_ROOT_FICHAS_FONO", THE_ROOT_FICHAS . "/fono" );
- define( "THE_ROOT_FICHAS_TO", THE_ROOT_FICHAS . "/to_a" );
- define( "THE_ROOT_FICHAS_V", THE_VOLUME . "/fichas" );
- define( "THE_ROOT_FICHAS_FISIO_V", THE_ROOT_FICHAS_V . "/fta" );
- define( "THE_ROOT_FICHAS_FONO_V", THE_ROOT_FICHAS_V . "/fga" );
- define( "THE_ROOT_FICHAS_TO_V", THE_ROOT_FICHAS_V . "/to" );
- // define( "THE_ROOT_FICHAS_NUTR", THE_ROOT_FICHAS . "/nutr" );
- // define( "THE_ROOT_FICHAS_FISIO", THE_ROOT_FICHAS . "/fisio" );
- // define( "THE_ROOT_FICHAS_FONO", THE_ROOT_FICHAS . "/fono" );
- // define( "THE_ROOT_FICHAS_NUTR", THE_ROOT_FICHAS . "/nutri" );
- // define( "THE_ROOT_FICHAS_TO", THE_ROOT_FICHAS . "/to" );
- // define( "THE_ROOT_FICHAS", THE_VOLUME . "/fichas" );
- // define( "THE_ROOT_FICHAS_FISIO", THE_ROOT_FICHAS . "/fta" );
- // define( "THE_ROOT_FICHAS_FONO", THE_ROOT_FICHAS . "/fga" );
- // define( "THE_ROOT_FICHAS_TO", THE_ROOT_FICHAS . "/to" );
- // define( "THE_ROOT_FICHAS_NUTR", THE_ROOT_FICHAS . "/nutr" );
- */
- ####
- ####
- ####
- if (isset($_SERVER['HTTPS']) && ($_SERVER['HTTPS'] == 'on' || $_SERVER['HTTPS'] == 1) || isset($_SERVER['HTTP_X_FORWARDED_PROTO']) && $_SERVER['HTTP_X_FORWARDED_PROTO'] == 'https')
- {
- $protocol = 'https';
- }
- else
- {
- $protocol = 'http';
- }
- define( "WEB_PROTOCOL", "{$protocol}://" );
- define( "WEB_ROOT", WEB_PROTOCOL . $_SERVER["SERVER_NAME"] . "/" );
- define( "WEB_ROOT_DASHBOARD", WEB_ROOT . "dashboard/" );
- define( "ROOT_DASHBOARD", WEB_ROOT . "dashboard/" );
- // define( "WEB_ROOT_API", WEB_ROOT . "api" );
- // define( "WEB_ROOT_ESTATICOS", WEB_ROOT . "estaticos" );
- // define( "WEB_ROOT_CARIMBOS", WEB_ROOT_ESTATICOS . "/carimbos" );
- // define( "WEB_ROOT_CARIMBOS_FISIO", WEB_ROOT_CARIMBOS . "/fisio" );
- ####
- ####
- ####
- # indiano estrutura de config
- DEFINE("DOMINGO", 0);
- DEFINE("SEGUNDA", 1);
- DEFINE("TERCA", 2);
- DEFINE("QUARTA", 3);
- DEFINE("QUINTA", 4);
- DEFINE("SEXTA", 5);
- DEFINE("SABADO", 6);
- $gl_nome_dia[DOMINGO] = "Domingo";
- $gl_nome_dia[SEGUNDA] = "Segunda-feira";
- $gl_nome_dia[TERCA] = "Terça-feira";
- $gl_nome_dia[QUARTA] = "Quarta-feira";
- $gl_nome_dia[QUINTA] = "Quinta-feira";
- $gl_nome_dia[SEXTA] = "Sexta-feira";
- $gl_nome_dia[SABADO] = "Sábado";
- $gl_mes[1] = "Janeiro";
- $gl_mes[2] = "Fevereiro";
- $gl_mes[3] = "Março";
- $gl_mes[4] = "Abril";
- $gl_mes[5] = "Maio";
- $gl_mes[6] = "Junho";
- $gl_mes[7] = "Julho";
- $gl_mes[8] = "Agosto";
- $gl_mes[9] = "Setembro";
- $gl_mes[10] = "Outubro";
- $gl_mes[11] = "Novembro";
- $gl_mes[12] = "Dezembro";
- $ab_mes[1] = "jan";
- $ab_mes[2] = "fev";
- $ab_mes[3] = "mar";
- $ab_mes[4] = "abr";
- $ab_mes[5] = "mai";
- $ab_mes[6] = "jun";
- $ab_mes[7] = "jul";
- $ab_mes[8] = "ago";
- $ab_mes[9] = "set";
- $ab_mes[10] = "out";
- $ab_mes[11] = "nov";
- $ab_mes[12] = "dez";
- $gl_estados["AC"] = "Acre";
- $gl_estados["AL"] = "Alagoas";
- $gl_estados["AM"] = "Amazonas";
- $gl_estados["AP"] = "Amapá";
- $gl_estados["BA"] = "Bahia";
- $gl_estados["CE"] = "Ceará";
- $gl_estados["DF"] = "Distrito Federal";
- $gl_estados["ES"] = "Espirito Santo";
- $gl_estados["GO"] = "Goiás";
- $gl_estados["MA"] = "Maranhão";
- $gl_estados["MT"] = "Mato Grosso";
- $gl_estados["MS"] = "Mato Grosso do Sul";
- $gl_estados["MG"] = "Minas Gerais";
- $gl_estados["PA"] = "Pará";
- $gl_estados["PB"] = "Paraíba";
- $gl_estados["PR"] = "Paraná";
- $gl_estados["PE"] = "Pernambuco";
- $gl_estados["PI"] = "Piauí";
- $gl_estados["RJ"] = "Rio de Janeiro";
- $gl_estados["RN"] = "Rio Grande do Norte";
- $gl_estados["RO"] = "Rondônia";
- $gl_estados["RS"] = "Rio Grande do Sul";
- $gl_estados["RR"] = "Roraima";
- $gl_estados["SC"] = "Santa Catarina";
- $gl_estados["SE"] = "Sergipe";
- $gl_estados["SP"] = "São Paulo";
- $gl_estados["TO"] = "Tocantins";
- $gl_condicao["0"] = "Ativo";
- $gl_condicao["1"] = "Óbito";
- $gl_condicao["2"] = "Alta";
- $str_yn["0"] = "Não";
- $str_yn["1"] = "Sim";
- $str_upload_errors[UPLOAD_ERR_OK] = 'Não houve erro, o envio foi bem sucedido';
- $str_upload_errors[UPLOAD_ERR_INI_SIZE] = 'O tamanho do arquivo excede o limite definido no servidor';
- $str_upload_errors[UPLOAD_ERR_FORM_SIZE] = 'O tamanho do arquivo excede o limite definido no formulário de envio';
- $str_upload_errors[UPLOAD_ERR_PARTIAL] = 'O envio do arquivo foi feito parcialmente';
- $str_upload_errors[UPLOAD_ERR_NO_FILE] = 'Nenhum arquivo foi enviado';
- $str_upload_errors[UPLOAD_ERR_NO_TMP_DIR] = 'Pasta temporária ausênte';
- $str_upload_errors[UPLOAD_ERR_CANT_WRITE] = 'Falha em escrever o arquivo no servidor';
- $str_upload_errors[UPLOAD_ERR_EXTENSION] = 'Uma extensão do PHP interrompeu o upload do arquivo';
- ####
- ####
- ####
- define( "NIVEL_USUARIO", 0 );
- define( "NIVEL_ADMINISTRATIVO", 1 );
- ####
- ####
- ####
- /*
- define( "NOME_BUCKET", "fisiolar-sistema" );
- define("THE_AMAZON_CARIMBOS_FISIO", "https://s3-sa-east-1.amazonaws.com/".NOME_BUCKET."/carimbos/fisio/");
- define("THE_AMAZON_CARIMBOS_FONO", "https://s3-sa-east-1.amazonaws.com/".NOME_BUCKET."/carimbos/fono/");
- define("THE_AMAZON_CARIMBOS_TO", "https://s3-sa-east-1.amazonaws.com/".NOME_BUCKET."/carimbos/to/");
- define("THE_AMAZON_CARIMBOS_NUTR", "https://s3-sa-east-1.amazonaws.com/".NOME_BUCKET."/carimbos/nutri/");
- define("THE_AMAZON_FICHAS_FISIO", "https://s3-sa-east-1.amazonaws.com/".NOME_BUCKET."/fichas/fisio/");
- define("THE_AMAZON_FICHAS_FONO", "https://s3-sa-east-1.amazonaws.com/".NOME_BUCKET."/fichas/fono/");
- define("THE_AMAZON_FICHAS_TO", "https://s3-sa-east-1.amazonaws.com/".NOME_BUCKET."/fichas/to/");
- define("THE_AMAZON_FICHAS_NUTR", "https://s3-sa-east-1.amazonaws.com/".NOME_BUCKET."/fichas/nutri/");
- // define("THE_AMAZON_FICHAS_OLD", "https://s3-sa-east-1.amazonaws.com/".NOME_BUCKET."/fichas/antigo/");
- define("THE_AMAZON_CURRICULOS", "https://s3-sa-east-1.amazonaws.com/".NOME_BUCKET."/curriculos/");
- ####
- ####
- ####
- define( "MAX_FOLHAS_GEAP", 4 );
- define( "TAMANHO_MAXIMO_CURRICULO", 5242880 );
- define( "TAMANHO_MAXIMO_CURRICULO_STR", "5 MB" );
- define( "TAMANHO_MAXIMO_FICHA", 5242880 );
- define( "TAMANHO_MAXIMO_FICHA_STR", "5 MB" );
- define( "TAMANHO_MAXIMO_CARIMBO", 2097152 );
- define( "TAMANHO_MAXIMO_CARIMBO_STR", "2 MB" );
- */
- ####
- ####
- ####
- define( "SESSAO_TITULO", "log" );
- define( "sSessaoLogado", "logado" );
- define( "sSessaoPessoa", "pessoa_id" );
- // define( "sSessaoFisio", "fisio_id" );
- // define( "sSessaoFono", "fono_id" );
- // define( "sSessaoNutr", "nutr_id" );
- // define( "sSessaoTo", "to_id" );
- define( "sSessaoPrivilegio", "pessoa_privilegio" );
- define( "sUsuario", "pessoa_acesso_usuario" );
- define( "sNome", "pessoa_nome" );
- define( "sSessaoTempoInicial", "tempo_inicio" );
- define( "sSessaoTempo", "tempo_real" );
- define( "sSessaoIP", "ip" );
- define( "sSessaoURL", "url" );
- define( "sSessaoAGENTE", "agente" );
- ini_set( "session.save_path", THE_ROOT_SESSOES );
- ini_set( "session.use_cookies", 1 );
- ini_set( "session.use_only_cookies", 1 );
- ini_set( "session.cookie_secure", 1 );
- ini_set( "session.cookie_httponly", 1 );
- ini_set( "session.cookie_lifetime", 0 );
- ini_set( "session.use_strict_mode", 1 );
- ini_set( "session.use_trans_sid", 0 );
- session_start();
- // ---- RETORNA ID DA LINHA CORRESPONDENTE NA TABELA MYSQL
- function getPessoaID() {
- return (int)$_SESSION[SESSAO_TITULO][sSessaoPessoa];
- }
- /*
- function getFisioID() {
- return (int)$_SESSION[SESSAO_TITULO][sSessaoFisio];
- }
- function getFonoID() {
- return (int)$_SESSION[SESSAO_TITULO][sSessaoFono];
- }
- function getTerapeutaOcupacionalID() {
- return (int)$_SESSION[SESSAO_TITULO][sSessaoTo];
- }
- function getNutrID() {
- return (int)$_SESSION[SESSAO_TITULO][sSessaoNutr];
- }
- // ---- VALIDAÇÃO DE PREVILÉGIOS
- function IsFISIO()
- {
- return ( getFisioID() !== -1 );
- }
- function IsFONO()
- {
- return ( getFonoID() !== -1 );
- }
- function IsTerapeutaOcupacional()
- {
- return ( getTerapeutaOcupacionalID() !== -1 );
- }
- function IsNutricionista()
- {
- return ( getNutrID() !== -1 );
- }
- */
- function fmtNivel($nivel)
- {
- $nome = "Desconhecido";
- if ( (int)$nivel === NIVEL_USUARIO ) {
- $nome = "Usuário";
- } else if ( (int)$nivel === NIVEL_ADMINISTRATIVO ) {
- $nome = "Administração";
- }
- return $nome;
- }
- function lerNivel()
- {
- return (int)$_SESSION[SESSAO_TITULO][sSessaoPrivilegio];
- }
- /*
- function IsOnlyADMIN()
- {
- return ( (lerNivel() >= NIVEL_OPERACIONAL) and (!IsFISIO()) and (!IsFONO()) and (!IsTerapeutaOcupacional()) and (!IsNutricionista()) );
- }
- function IsNADA()
- {
- return ( (lerNivel() === NIVEL_USUARIO) and (!IsFISIO()) and (!IsFONO()) and (!IsTerapeutaOcupacional()) and (!IsNutricionista()) );
- }
- */
- function EstaLogado()
- {
- return ( (string)$_SESSION[SESSAO_TITULO][sSessaoLogado] === "1" );
- }
- // function SaidaSessao()
- // {
- // return var_export($_SESSION, true);
- // }
- function sessaoID()
- {
- return session_id();
- }
- ####
- ####
- ####
- #
- ####
- ####
- ####
- $isMobile = (
- preg_match('/(android|bb\d+|meego).+mobile|avantgo|bada\/|blackberry|blazer|compal|elaine|fennec|hiptop|iemobile|ip(hone|od)|iris|kindle|lge |maemo|midp|mmp|mobile.+firefox|netfront|opera m(ob|in)i|palm( os)?|phone|p(ixi|re)\/|plucker|pocket|psp|series(4|6)0|symbian|treo|up\.(browser|link)|vodafone|wap|windows ce|xda|xiino/i', $_SERVER['HTTP_USER_AGENT'])
- ||
- preg_match('/1207|6310|6590|3gso|4thp|50[1-6]i|770s|802s|a wa|abac|ac(er|oo|s\-)|ai(ko|rn)|al(av|ca|co)|amoi|an(ex|ny|yw)|aptu|ar(ch|go)|as(te|us)|attw|au(di|\-m|r |s )|avan|be(ck|ll|nq)|bi(lb|rd)|bl(ac|az)|br(e|v)w|bumb|bw\-(n|u)|c55\/|capi|ccwa|cdm\-|cell|chtm|cldc|cmd\-|co(mp|nd)|craw|da(it|ll|ng)|dbte|dc\-s|devi|dica|dmob|do(c|p)o|ds(12|\-d)|el(49|ai)|em(l2|ul)|er(ic|k0)|esl8|ez([4-7]0|os|wa|ze)|fetc|fly(\-|_)|g1 u|g560|gene|gf\-5|g\-mo|go(\.w|od)|gr(ad|un)|haie|hcit|hd\-(m|p|t)|hei\-|hi(pt|ta)|hp( i|ip)|hs\-c|ht(c(\-| |_|a|g|p|s|t)|tp)|hu(aw|tc)|i\-(20|go|ma)|i230|iac( |\-|\/)|ibro|idea|ig01|ikom|im1k|inno|ipaq|iris|ja(t|v)a|jbro|jemu|jigs|kddi|keji|kgt( |\/)|klon|kpt |kwc\-|kyo(c|k)|le(no|xi)|lg( g|\/(k|l|u)|50|54|\-[a-w])|libw|lynx|m1\-w|m3ga|m50\/|ma(te|ui|xo)|mc(01|21|ca)|m\-cr|me(rc|ri)|mi(o8|oa|ts)|mmef|mo(01|02|bi|de|do|t(\-| |o|v)|zz)|mt(50|p1|v )|mwbp|mywa|n10[0-2]|n20[2-3]|n30(0|2)|n50(0|2|5)|n7(0(0|1)|10)|ne((c|m)\-|on|tf|wf|wg|wt)|nok(6|i)|nzph|o2im|op(ti|wv)|oran|owg1|p800|pan(a|d|t)|pdxg|pg(13|\-([1-8]|c))|phil|pire|pl(ay|uc)|pn\-2|po(ck|rt|se)|prox|psio|pt\-g|qa\-a|qc(07|12|21|32|60|\-[2-7]|i\-)|qtek|r380|r600|raks|rim9|ro(ve|zo)|s55\/|sa(ge|ma|mm|ms|ny|va)|sc(01|h\-|oo|p\-)|sdk\/|se(c(\-|0|1)|47|mc|nd|ri)|sgh\-|shar|sie(\-|m)|sk\-0|sl(45|id)|sm(al|ar|b3|it|t5)|so(ft|ny)|sp(01|h\-|v\-|v )|sy(01|mb)|t2(18|50)|t6(00|10|18)|ta(gt|lk)|tcl\-|tdg\-|tel(i|m)|tim\-|t\-mo|to(pl|sh)|ts(70|m\-|m3|m5)|tx\-9|up(\.b|g1|si)|utst|v400|v750|veri|vi(rg|te)|vk(40|5[0-3]|\-v)|vm40|voda|vulc|vx(52|53|60|61|70|80|81|83|85|98)|w3c(\-| )|webc|whit|wi(g |nc|nw)|wmlb|wonu|x700|yas\-|your|zeto|zte\-/i', substr($_SERVER['HTTP_USER_AGENT'], 0, 4))
- );
- ####
- ####
- ####
- function weeks_in_month( $year, $month, $start_day_of_week )
- {
- // Total number of days in the given month.
- $num_of_days = date( "t", mktime( 0, 0, 0, $month, 1, $year ) );
- // Count the number of times it hits $start_day_of_week.
- $num_of_weeks = 0;
- for ( $i = 1; $i <= $num_of_days; $i++ )
- {
- $day_of_week = date( 'w', mktime( 0, 0, 0, $month, $i, $year ) );
- if ( $day_of_week == $start_day_of_week ) {
- $num_of_weeks++;
- }
- }
- return $num_of_weeks;
- }
- function QualIP()
- {
- if ( !empty($_SERVER['HTTP_CLIENT_IP']) ) {
- $ip = $_SERVER['HTTP_CLIENT_IP'];
- } elseif ( !empty($_SERVER['HTTP_X_FORWARDED_FOR']) ) {
- $ip = $_SERVER['HTTP_X_FORWARDED_FOR'];
- } else{
- $ip = $_SERVER['REMOTE_ADDR'];
- }
- return $ip;
- }
- /*
- $ipAddress = $_SERVER['REMOTE_ADDR'];
- if ( array_key_exists('HTTP_X_FORWARDED_FOR', $_SERVER) )
- {
- $ipAddress = array_pop( explode(',', $_SERVER['HTTP_X_FORWARDED_FOR']) );
- }
- */
- function GerarLOG($prefixo, $origem, $msg)
- {
- $hAtual = new DateTime();
- $err_data = $hAtual->format("d/m/Y");
- $err_hora = $hAtual->format("H:i:s");
- $err_ip = QualIP();
- $saida = array( "DATA" => $err_data,
- "HORA" => $err_hora,
- "IP" => $err_ip,
- "ORIGEM" => $origem,
- "MENSAGEM" => $msg );
- $str_saida = ( var_export($saida, true) . PHP_EOL );
- @file_put_contents( THE_ROOT_DEBUG."/debug_{$prefixo}.log", $str_saida, FILE_APPEND );
- }
- function ErroPDO($origem, $msg)
- {
- $hAtual = new DateTime();
- $err_data = $hAtual->format("d/m/Y");
- $err_hora = $hAtual->format("H:i:s");
- $err_ip = QualIP();
- $saida = array( "DATA" => $err_data,
- "HORA" => $err_hora,
- "IP" => $err_ip,
- "ORIGEM" => $origem,
- "MENSAGEM" => $msg );
- $str_saida = ( var_export($saida, true) . PHP_EOL );
- @file_put_contents( THE_ROOT_DEBUG."/debug_pdo.log", $str_saida, FILE_APPEND );
- }
- function RegistrarEvento( $h_pdo, $codigo, $saida, $v_post, $v_get, $v_file )
- {
- try
- {
- $qry_evento = $h_pdo->prepare("INSERT INTO sys_eventos (data,pessoa_id,codigo,evento_post,evento_get,evento_file,saida,zip) VALUES (NOW(),:pessoa,:codigo,COMPRESS(:post),COMPRESS(:get),COMPRESS(:file),:saida,1)");
- $qry_evento->bindValue( ":pessoa", getPessoaID() );
- $qry_evento->bindValue( ":codigo", $codigo );
- if (trim($v_post) != "") {
- $qry_evento->bindValue( ":post", "{$v_post}" );
- } else {
- $qry_evento->bindValue( ":post", null );
- }
- if (trim($v_get) != "") {
- $qry_evento->bindValue( ":get", "{$v_get}" );
- } else {
- $qry_evento->bindValue( ":get", null );
- }
- if (trim($v_file) != "") {
- $qry_evento->bindValue( ":file", "{$v_file}" );
- } else {
- $qry_evento->bindValue( ":file", null );
- }
- $qry_evento->bindValue( ":saida", $saida );
- $qry_evento->execute();
- $qry_evento = null;
- }
- catch(PDOException $pdo_err)
- {
- $pdo_error = true;
- ErroPDO( $_SERVER["PHP_SELF"], $pdo_err->getMessage() );
- }
- }
- function RegistrarNavegacao( $h_pdo, $script, $url )
- {
- try
- {
- $qry_evento = $h_pdo->prepare("INSERT INTO sys_navegacao (pessoa_id,data,ip,user_agent,script,url) VALUES (:pessoa,NOW(),:ip,:agente,:script,:url)");
- $qry_evento->bindValue( ":pessoa", getPessoaID() );
- $qry_evento->bindValue( ":ip", QualIP() );
- $qry_evento->bindValue( ":agente", $_SERVER["HTTP_USER_AGENT"] );
- $qry_evento->bindValue( ":script", $script );
- $qry_evento->bindValue( ":url", $url );
- $qry_evento->execute();
- $qry_evento = null;
- }
- catch(PDOException $pdo_err)
- {
- $pdo_error = true;
- ErroPDO( $_SERVER["PHP_SELF"], $pdo_err->getMessage() );
- }
- }
- ####
- ####
- ####
- // Convert an UTF-8 encoded string to a single-byte string suitable for
- // functions such as levenshtein.
- //
- // The function simply uses (and updates) a tailored dynamic encoding
- // (in/out map parameter) where non-ascii characters are remapped to
- // the range [128-255] in order of appearance.
- //
- // Thus it supports up to 128 different multibyte code points max over
- // the whole set of strings sharing this encoding.
- //
- function utf8_to_extended_ascii($str, &$map)
- {
- // find all multibyte characters (cf. utf-8 encoding specs)
- $matches = array();
- if (!preg_match_all('/[\xC0-\xF7][\x80-\xBF]+/', $str, $matches))
- return $str; // plain ascii string
- // update the encoding map with the characters not already met
- foreach ($matches[0] as $mbc)
- if (!isset($map[$mbc]))
- $map[$mbc] = chr(128 + count($map));
- // finally remap non-ascii characters
- return strtr($str, $map);
- }
- // Didactic example showing the usage of the previous conversion function but,
- // for better performance, in a real application with a single input string
- // matched against many strings from a database, you will probably want to
- // pre-encode the input only once.
- //
- function levenshtein_utf8($s1, $s2)
- {
- $charMap = array();
- $s1 = utf8_to_extended_ascii($s1, $charMap);
- $s2 = utf8_to_extended_ascii($s2, $charMap);
- return levenshtein($s1, $s2);
- }
- function LimparNome($str, $direcao = MB_CASE_UPPER)
- {
- setlocale( LC_CTYPE, 'pt_BR.utf8' );
- $str = iconv( 'utf-8', 'us-ascii//TRANSLIT', $str );
- $str = preg_replace( "/[^[:alpha:][:space:]]/u", '', $str );
- $str = preg_replace( "!\s+!", " ", $str );
- $str = trim( $str );
- return mb_convert_case( $str, $direcao, "utf-8" );
- }
- function ordernarColuna(&$arr, $col, $dir = SORT_ASC)
- {
- $sort_col = array();
- foreach ( $arr as $key => $row )
- {
- $sort_col[$key] = $row[$col];
- }
- array_multisort($sort_col, $dir, $arr);
- }
- /*
- function remoteFileExists( $url )
- {
- $ch = @curl_init( $url );
- @curl_setopt($ch, CURLOPT_NOBODY, true);
- @curl_exec($ch);
- $retcode = @curl_getinfo($ch, CURLINFO_HTTP_CODE);
- @curl_close($ch);
- return ( $retcode === 200 ); // $retcode >= 400 -> not found, $retcode = 200, found.
- }
- */
- function encodeURIComponent($str)
- {
- $revert = array('%21'=>'!', '%2A'=>'*', '%28'=>'(', '%29'=>')');
- return strtr( urlencode($str), $revert );
- }
- function mask($val, $mask)
- {
- $maskared = '';
- $k = 0;
- for ( $i = 0; $i <= strlen($mask)-1; $i++ )
- {
- if ( $mask[$i] == '#' )
- {
- if ( isset($val[$k]) ) {
- $maskared .= $val[$k++];
- }
- }
- else
- {
- if ( isset($mask[$i]) ) {
- $maskared .= $mask[$i];
- }
- }
- }
- return $maskared;
- }
- function get_string_between($string, $start, $end)
- {
- $string = " ".$string;
- $ini = strpos($string,$start);
- if ($ini == 0) return "";
- $ini += strlen($start);
- $len = strpos($string,$end,$ini) - $ini;
- return substr($string,$ini,$len);
- }
- function calcular_idade($data_nascimento)
- {
- $stt_nascimento = strtotime($data_nascimento);
- if($stt_nascimento == false) {
- return false;
- }
- $stt_agora = strtotime("now");
- list($y1, $m1, $d1) = explode( "-", date("Y-m-d", $stt_nascimento) );
- list($y2, $m2, $d2) = explode( "-", date("Y-m-d", $stt_agora) );
- $stt_nascimento = ($y2 - $y1);
- if ((int)($m2.$d2) < (int)($m1.$d1)) {
- $stt_nascimento -= 1;
- }
- return $stt_nascimento;
- }
- function fmt_idade($data_nascimento)
- {
- # $stt_nascimento = ( preg_match("/^(0[1-9]|[12][0-9]|3[01])\/(0[1-9]|1[012])\/(18|19|20)\d\d$/", $data_nascimento) );
- $stt_nascimento = ( preg_match("/^((18|19|20)\d\d)-(0[1-9]|1[012])-(0[1-9]|[12][0-9]|3[01])$/", $data_nascimento) );
- if (!$stt_nascimento)
- {
- return ""; # Formato inválido
- }
- else
- {
- # $fmt_data = preg_replace("/(\d+)\D+(\d+)\D+(\d+)/", "$3-$2-$1", $data_nascimento);
- $fmt_data = $data_nascimento;
- $date = new DateTime("{$fmt_data}");
- $diff = $date->diff( new DateTime("today") );
- $str_ano = ( ($diff->y == 1) ? "ano" : "anos" );
- $str_mes = ( ($diff->m == 1) ? "mês" : "meses" );
- $str_dia = ( ($diff->d == 1) ? "dia" : "dias" );
- $str_anoz = ( ($diff->y >= 1) ? "{$diff->y} {$str_ano}" : "" );
- $str_mesz = ( ($diff->m >= 1) ? "{$diff->m} {$str_mes}" : "" );
- $str_diaz = ( ($diff->d >= 1) ? "{$diff->d} {$str_dia}" : "" );
- if (($diff->y == 0) and ($diff->m == 0) and ($diff->d == 0)) {
- $retorno = "Hoje";
- } else if (($diff->y == 0) and ($diff->m == 0) and ($diff->d > 0)) {
- $retorno = "{$diff->d} {$str_dia}";
- } else if (($diff->y == 0) and ($diff->m > 0) and ($diff->d == 0)) {
- $retorno = "{$diff->m} {$str_mes}";
- } else if (($diff->y == 0) and ($diff->m > 0) and ($diff->d > 0)) {
- $retorno = "{$diff->m}m {$diff->d}d";
- } else if (($diff->y > 0) and ($diff->m == 0)) {
- $retorno = "{$diff->y} {$str_ano}";
- } else if (($diff->y > 0) and ($diff->m > 0)) {
- #$retorno = "{$diff->y}a {$diff->m}m";
- $retorno = "{$diff->y} {$str_ano}";
- }
- # return $fmt_data.": ".$retorno;
- return $retorno;
- }
- }
- function dateIsBetween($date_time_a, $date_time_b, $date_time_teste)
- {
- $stt_start = strtotime($date_time_a);
- $stt_end = strtotime($date_time_b);
- $stt_test = strtotime($date_time_teste);
- return (($stt_test >= $stt_start) and ($stt_test <= $stt_end));
- }
- function inTimeRange($data, $INICIO, $FINAL, $BUSCA)
- {
- $res = false;
- $t_inicio = strtotime("{$data} {$INICIO}:00");
- $t_final = strtotime("{$data} {$FINAL}:00");
- $t_busca = strtotime("{$data} {$BUSCA}:00");
- if ($t_inicio >= $t_final) $t_final = strtotime('+1 day', $t_final);
- return ($t_busca >= $t_inicio) and ($t_busca <= $t_final); // or return ($t_busca > $t_inicio) && ($t_busca < $t_final);
- }
- function datescompare($a, $b)
- {
- $a = strtotime("01/".$a); //dirty, but works
- $b = strtotime("01/".$b);
- return ($b-$a);
- }
- function formatar_tamanho($bytes, $precision = 2)
- {
- $units = array('B', 'KB', 'MB', 'GB', 'TB');
- $bytes = max($bytes, 0);
- $pow = floor(($bytes ? log($bytes) : 0) / log(1024));
- $pow = min($pow, count($units) - 1);
- // Uncomment one of the following alternatives
- $bytes /= pow(1024, $pow);
- // $bytes /= (1 << (10 * $pow));
- return round($bytes, $precision) . ' ' . $units[$pow];
- }
- function valida_cpf($cpf = false)
- {
- if (!function_exists('calc_digitos_posicoes'))
- {
- function calc_digitos_posicoes( $digitos, $posicoes = 10, $soma_digitos = 0 )
- {
- for ( $i = 0; $i < strlen( $digitos ); $i++ ) {
- $soma_digitos = $soma_digitos + ( $digitos[$i] * $posicoes );
- $posicoes--;
- }
- $soma_digitos = $soma_digitos % 11;
- if ( $soma_digitos < 2 ) {
- $soma_digitos = 0;
- } else {
- $soma_digitos = 11 - $soma_digitos;
- }
- $cpf = $digitos . $soma_digitos;
- return $cpf;
- }
- }
- if ( ! $cpf ) {
- return false;
- }
- $cpf = preg_replace( '/[^0-9]/is', '', $cpf );
- if ( strlen( $cpf ) != 11 ) {
- return false;
- }
- $digitos = substr($cpf, 0, 9);
- $novo_cpf = calc_digitos_posicoes( $digitos );
- $novo_cpf = calc_digitos_posicoes( $novo_cpf, 11 );
- if ( $novo_cpf == $cpf ) {
- return true;
- } else {
- return false;
- }
- }
- function aURL()
- {
- $teste = $_SERVER["SCRIPT_NAME"];
- return substr($teste, 1, strrpos($teste, ".php")+4);
- }
- function TresNomes($nome)
- {
- # ABREVIAR OS DEMAIS...
- $saida = trim( preg_replace( "!\s+!", " ", $nome ) ); # agrupa os espaços em um
- if ( strpos($saida, " ") )
- {
- $ex_nome = explode(" ", $saida);
- $qnt = count($ex_nome);
- if ($qnt > 2)
- {
- $opcao = "";
- $tok = strtok($saida, " ");
- while ( $tok = strtok(" ") )
- {
- if (strlen($tok) > 3)
- {
- $opcao = $tok;
- break;
- }
- }
- if ( $opcao != "" )
- {
- $saida = $ex_nome[0] . " " . $opcao;
- if ( $opcao !== end($ex_nome) ) {
- $saida = $ex_nome[0] . " " . $opcao . " " . end($ex_nome);
- }
- }
- }
- }
- return htmlspecialchars( $saida, ENT_QUOTES );
- }
- function searchArrayKeyVal($sKey, $id, $array)
- {
- foreach ($array as $key => $val)
- {
- if ($val[$sKey] == $id)
- {
- return $key;
- }
- }
- return false;
- }
- function PrimeiroNome($nome)
- {
- $nome_profissional = htmlspecialchars( $nome, ENT_QUOTES );
- if (strpos($nome_profissional, " ")) {
- $nome_profissional = explode(" ", $nome_profissional);
- $nome_profissional = $nome_profissional[0]." ".end($nome_profissional);
- }
- return $nome_profissional;
- }
- function FormatarNome($nome)
- {
- $saida = htmlspecialchars( trim($nome), ENT_QUOTES );
- if (strpos($saida, " ")) {
- $tmp = explode(" ", $saida);
- $saida = (string)$tmp[0];
- }
- return $saida;
- }
- function br2nl($contexto)
- {
- return str_replace("<br />", "\r\n", $contexto);
- }
- ####
- ####
- ####
- function checkSessao($close = true)
- {
- global $_SESSION;
- $UTC = new DateTimeZone("UTC");
- $newTZ = new DateTimeZone("America/Sao_Paulo");
- $date = new DateTime( "now", $UTC );
- $date->setTimezone( $newTZ );
- $tempo_vigente = $date->format("Y-m-d H:i:s");
- $ip = QualIP();
- $url = "{$_SERVER["SERVER_NAME"]}{$_SERVER["REQUEST_URI"]}";
- // if ( !isset($_SESSION[SESSAO_TITULO][sSessaoTempoInicial]) or ($_SESSION[SESSAO_TITULO][sSessaoTempoInicial] != $tempo_vigente))
- if ( !isset($_SESSION[SESSAO_TITULO][sSessaoTempoInicial]) )
- {
- $_SESSION[SESSAO_TITULO][sSessaoTempoInicial] = $tempo_vigente;
- }
- if ( (!isset($_SESSION[SESSAO_TITULO][sSessaoTempo])) or ($_SESSION[SESSAO_TITULO][sSessaoTempo] != $tempo_vigente) )
- {
- $_SESSION[SESSAO_TITULO][sSessaoTempo] = $tempo_vigente;
- }
- if ( (!isset($_SESSION[SESSAO_TITULO][sSessaoIP])) or ($_SESSION[SESSAO_TITULO][sSessaoIP] != $ip) )
- {
- $_SESSION[SESSAO_TITULO][sSessaoIP] = $ip;
- }
- if ( (!isset($_SESSION[SESSAO_TITULO][sSessaoURL])) or ($_SESSION[SESSAO_TITULO][sSessaoURL] != $url) )
- {
- $_SESSION[SESSAO_TITULO][sSessaoURL] = $url;
- }
- if ( (!isset($_SESSION[SESSAO_TITULO][sSessaoAGENTE])) or ($_SESSION[SESSAO_TITULO][sSessaoAGENTE] != $_SERVER["HTTP_USER_AGENT"]) )
- {
- $_SESSION[SESSAO_TITULO][sSessaoAGENTE] = $_SERVER["HTTP_USER_AGENT"];
- }
- if ( $close )
- {
- session_write_close();
- }
- }
- function sessaoInicio($usuario, $senha, $pessoa_id, $pessoa_privilegio, $pessoa_nome)
- {
- global $_SESSION;
- $UTC = new DateTimeZone("UTC");
- $newTZ = new DateTimeZone("America/Sao_Paulo");
- $date = new DateTime( "now", $UTC );
- $date->setTimezone( $newTZ );
- $tempo_vigente = $date->format("Y-m-d H:i:s");
- $_SESSION["persistencia"]["a"] = $usuario;
- $_SESSION["persistencia"]["b"] = $senha;
- $_SESSION[SESSAO_TITULO][sSessaoPessoa] = $pessoa_id;
- $_SESSION[SESSAO_TITULO][sSessaoPrivilegio] = $pessoa_privilegio;
- $_SESSION[SESSAO_TITULO][sUsuario] = (string)$usuario;
- $_SESSION[SESSAO_TITULO][sNome] = $pessoa_nome;
- $_SESSION[SESSAO_TITULO]["aviso_index"] = "1";
- $_SESSION[SESSAO_TITULO][sSessaoLogado] = "1";
- $i = count($_SESSION[SESSAO_TITULO]["usuarios"])+1;
- $_SESSION[SESSAO_TITULO]["usuarios"][$i]["dt"] = $tempo_vigente;
- $_SESSION[SESSAO_TITULO]["usuarios"][$i]["id"] = $pessoa_id;
- // $_SESSION[SESSAO_TITULO]["abas"] = array();
- session_write_close();
- }
- function sessaoSair()
- {
- global $_SESSION;
- // $backup["tempo"] = $_SESSION[SESSAO_TITULO][sSessaoTempoInicial];
- // unset( $_SESSION[SESSAO_TITULO] );
- // $_SESSION[SESSAO_TITULO][sSessaoTempoInicial] = $backup["tempo"];
- // unset( $_SESSION[SESSAO_TITULO][sSessaoLogado] );
- // unset( $_SESSION[SESSAO_TITULO][sSessaoPessoa] );
- $_SESSION[SESSAO_TITULO][sSessaoLogado] = "0";
- session_write_close();
- }
- function sessaoNome($fmt = true)
- {
- global $_SESSION;
- $saida = $_SESSION[SESSAO_TITULO][sNome];
- if ( $fmt )
- {
- $saida = FormatarNome( $saida );
- }
- return $saida; # htmlentities
- }
- function sessaoAviso($tmp = null)
- {
- global $_SESSION;
- if ( !is_null($tmp) )
- {
- $_SESSION[SESSAO_TITULO]["aviso_index"] = $tmp;
- session_write_close();
- }
- return $_SESSION[SESSAO_TITULO]["aviso_index"];
- }
- function sessaoPrivilegio($tmp = null)
- {
- global $_SESSION;
- if ( !is_null($tmp) )
- {
- $_SESSION[SESSAO_TITULO][sSessaoPrivilegio] = $tmp;
- session_write_close();
- }
- return $_SESSION[SESSAO_TITULO][sSessaoPrivilegio];
- }
- ####
- ####
- ####
- /*
- $_SESSION = array();
- $useCookies = ini_get("session.use_cookies");
- if ( $useCookies )
- {
- $params = session_get_cookie_params();
- $name = session_name();
- setcookie( $name, "", time() - 42000, $params["path"], $params["domain"], $params["secure"], $params["httponly"] );
- }
- session_destroy();
- */
- // if ( aURL() != "sessoes.php" )
- // if ( (aURL() != "sessoes/sessao.php") and (aURL() != "sessoes.php") )
- if ( (aURL() != "sessao.php") and (aURL() != "sessoes.php") )
- {
- if ( EstaLogado() )
- {
- $_SESSION[SESSAO_TITULO][sSessaoTempo] = (new DateTime("now"))->format("Y-m-d H:i:s");
- }
- }
- ####
- #### CORS
- ####
- header("X-Frame-Options: DENY"); // SAMEORIGIN
- header("X-XSS-Protection: 1; mode=block");
- header("Strict-Transport-Security: max-age=31536000");
- header("X-Content-Type-Options: nosniff");
- // add_header Strict-Transport-Security "max-age=31536000; includeSubdomains; preload";
- // add_header Content-Security-Policy "script-src 'unsafe-inline' 'unsafe-eval' 'self' *.catalogop2p.com.br *.jsdelivr.net *.facebook.com *.facebook.net *.fbcdn.net *.google-analytics.com";
- // add_header Referrer-Policy "no-referrer-when-downgrade";
- // $maxAge = 2592000;
- // header ("Content-Type: application/x-javascript; charset=utf-8");
- // header ("Last-Modified: Thu, 19 Jul 2012 12:56:03 GMT");
- // header ("Expires: " . gmdate ('D, d M Y H:i:s \G\M\T', time () + $maxAge));
- // header ("Cache-Control: max-age=" . $maxAge);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement