connect_errno) { echo "Failed to connect to MySQL: " . $conx->connect_error; exit(); } /* cambiar el conjunto de caracteres a utf8 */ if (!$conx->set_charset("utf8")) { printf("Error cargando el conjunto de caracteres utf8: %s\n", $conx->error); exit(); } 'Oculto', 1=>'Visible', 2=>'Destacado' ); $tipos_pro=array( 1=>'Protocolo de Adulto', 2=>'Protocolo de Niños' ); $cod_protocolos = array( 0 => "a15", 1 => "a19", 2 => "a20" ); //$ruta_pdf = '../data/pdf/'; $ruta_autos = '../data/fotos/'; $ruta_prensa = '../data/prensa/'; $ruta_protocolos = '../data/protocolos/'; $ruta_marcas = '../data/marcas/'; //$ruta_lanzamientos = '../data/lanzamientos/'; $ruta_sanos = '../data/sanos/'; $ruta_publicaciones = '../data/publicaciones/'; if ($_SERVER['SERVER_NAME']!="cygnus"){//Rutas Online $ruta_pdf = '../../dln/pdf/'; $ruta_lanzamientos = '../../dln/lanzamientos/'; }else{ $ruta_pdf = '../oculto/pdf/'; $ruta_lanzamientos = '../oculto/lanzamientos/'; } if(!function_exists("gd_auto_rotate")){ function gd_auto_rotate($original_file, $destination_file=NULL){ $original_extension = strtolower(pathinfo($original_file, PATHINFO_EXTENSION)); if(isset($destination_file) and $destination_file!=''){ $destination_extension = strtolower(pathinfo($destination_file, PATHINFO_EXTENSION)); } // try to auto-rotate image by gd if needed (before editing it) // by imagemagik it has an easy option if(function_exists("exif_read_data")){ $exif_data = exif_read_data($original_file); $exif_orientation = $exif_data['Orientation']; // value 1 = normal ?! skip it ?! if($exif_orientation=='3' or $exif_orientation=='6' or $exif_orientation=='8'){ $new_angle[3] = 180; $new_angle[6] = -90; $new_angle[8] = 90; // load the image if($original_extension == "jpg" or $original_extension == "jpeg"){ $original_image = imagecreatefromjpeg($original_file); } if($original_extension == "gif"){ $original_image = imagecreatefromgif($original_file); } if($original_extension == "png"){ $original_image = imagecreatefrompng($original_file); } $rotated_image = imagerotate($original_image, $new_angle[$exif_orientation], 0); // if no destination file is set, then show the image if(!$destination_file){ header('Content-type: image/jpeg'); imagejpeg($rotated_image, NULL, 100); } // save the smaller image FILE if destination file given if($destination_extension == "jpg" or $destination_extension=="jpeg"){ imagejpeg($rotated_image, $destination_file,100); } if($destination_extension == "gif"){ imagegif($rotated_image, $destination_file); } if($destination_extension == "png"){ imagepng($rotated_image, $destination_file,9); } imagedestroy($original_image); imagedestroy($rotated_image); } } } } function remplaza_acentos($var){ //replace for accents catalan spanish and more $a = array(' ','À', 'Á', 'Â', 'Ã', 'Ä', 'Å', 'Æ', 'Ç', 'È', 'É', 'Ê', 'Ë', 'Ì', 'Í', 'Î', 'Ï', 'Ð', 'Ñ', 'Ò', 'Ó', 'Ô', 'Õ', 'Ö', 'Ø', 'Ù', 'Ú', 'Û', 'Ü', 'Ý', 'ß', 'à', 'á', 'â', 'ã', 'ä', 'å', 'æ', 'ç', 'è', 'é', 'ê', 'ë', 'ì', 'í', 'î', 'ï', 'ñ', 'ò', 'ó', 'ô', 'õ', 'ö', 'ø', 'ù', 'ú', 'û', 'ü', 'ý', 'ÿ', 'Ā', 'ā', 'Ă', 'ă', 'Ą', 'ą', 'Ć', 'ć', 'Ĉ', 'ĉ', 'Ċ', 'ċ', 'Č', 'č', 'Ď', 'ď', 'Đ', 'đ', 'Ē', 'ē', 'Ĕ', 'ĕ', 'Ė', 'ė', 'Ę', 'ę', 'Ě', 'ě', 'Ĝ', 'ĝ', 'Ğ', 'ğ', 'Ġ', 'ġ', 'Ģ', 'ģ', 'Ĥ', 'ĥ', 'Ħ', 'ħ', 'Ĩ', 'ĩ', 'Ī', 'ī', 'Ĭ', 'ĭ', 'Į', 'į', 'İ', 'ı', 'IJ', 'ij', 'Ĵ', 'ĵ', 'Ķ', 'ķ', 'Ĺ', 'ĺ', 'Ļ', 'ļ', 'Ľ', 'ľ', 'Ŀ', 'ŀ', 'Ł', 'ł', 'Ń', 'ń', 'Ņ', 'ņ', 'Ň', 'ň', 'ʼn', 'Ō', 'ō', 'Ŏ', 'ŏ', 'Ő', 'ő', 'Œ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n', 'O', 'o', 'O', 'o', 'O', 'o', 'OE', 'oe', 'R', 'r', 'R', 'r', 'R', 'r', 'S', 's', 'S', 's', 'S', 's', 'S', 's', 'T', 't', 'T', 't', 'T', 't', 'U', 'u', 'U', 'u', 'U', 'u', 'U', 'u', 'U', 'u', 'U', 'u', 'W', 'w', 'Y', 'y', 'Y', 'Z', 'z', 'Z', 'z', 'Z', 'z', 's', 'f', 'O', 'o', 'U', 'u', 'A', 'a', 'I', 'i', 'O', 'o', 'U', 'u', 'U', 'u', 'U', 'u', 'U', 'u', 'U', 'u', 'A', 'a', 'AE', 'ae', 'O', 'o', '-', '-', '-', ''); $var= str_replace($a, $b, $var); return $var; } function Tit($var){ //replace for accents catalan spanish and more $a = array(' ','À', 'Á', 'Â', 'Ã', 'Ä', 'Å', 'Æ', 'Ç', 'È', 'É', 'Ê', 'Ë', 'Ì', 'Í', 'Î', 'Ï', 'Ð', 'Ñ', 'Ò', 'Ó', 'Ô', 'Õ', 'Ö', 'Ø', 'Ù', 'Ú', 'Û', 'Ü', 'Ý', 'ß', 'à', 'á', 'â', 'ã', 'ä', 'å', 'æ', 'ç', 'è', 'é', 'ê', 'ë', 'ì', 'í', 'î', 'ï', 'ñ', 'ò', 'ó', 'ô', 'õ', 'ö', 'ø', 'ù', 'ú', 'û', 'ü', 'ý', 'ÿ', 'Ā', 'ā', 'Ă', 'ă', 'Ą', 'ą', 'Ć', 'ć', 'Ĉ', 'ĉ', 'Ċ', 'ċ', 'Č', 'č', 'Ď', 'ď', 'Đ', 'đ', 'Ē', 'ē', 'Ĕ', 'ĕ', 'Ė', 'ė', 'Ę', 'ę', 'Ě', 'ě', 'Ĝ', 'ĝ', 'Ğ', 'ğ', 'Ġ', 'ġ', 'Ģ', 'ģ', 'Ĥ', 'ĥ', 'Ħ', 'ħ', 'Ĩ', 'ĩ', 'Ī', 'ī', 'Ĭ', 'ĭ', 'Į', 'į', 'İ', 'ı', 'IJ', 'ij', 'Ĵ', 'ĵ', 'Ķ',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 'e', 'E', 'e', 'G', 'g', 'G', 'g', 'G', 'g', 'G', 'g', 'H', 'h', 'H', 'h', 'I', 'i', 'I', 'i', 'I', 'i', 'I', 'i', 'I', 'i', 'IJ', 'ij', 'J', 'j', 'K', 'k', 'L', 'l', 'L', 'l', 'L', 'l', 'L', 'l', 'l', 'l', 'N', 'n', 'N', 'n', 'N', 'n', 'n', 'O', 'o', 'O', 'o', 'O', 'o', 'OE', 'oe', 'R', 'r', 'R', 'r', 'R', 'r', 'S', 's', 'S', 's', 'S', 's', 'S', 's', 'T', 't', 'T', 't', 'T', 't', 'U', 'u', 'U', 'u', 'U', 'u', 'U', 'u', 'U', 'u', 'U', 'u', 'W', 'w', 'Y', 'y', 'Y', 'Z', 'z', 'Z', 'z', 'Z', 'z', 's', 'f', 'O', 'o', 'U', 'u', 'A', 'a', 'I', 'i', 'O', 'o', 'U', 'u', 'U', 'u', 'U', 'u', 'U', 'u', 'U', 'u', 'A', 'a', 'AE', 'ae', 'O', 'o','','','','','','','','','','','','','-','','','','','',''); $var = rtrim($var); $var = str_replace($a, $b, $var); return strtolower($var); } /////////////////////// function generarPassword($numcar) { $password = ""; $caracteres = "0123456789bcdfghjkmnpqrstvwxyzBCDFGHJKMNPQRSTVWXYZ"; //#$%&/()=?,;.:-_}{*][*-+/"; $i = 0; while ($i < $numcar) { $char = substr($caracteres, mt_rand(0, strlen($caracteres)-1), 1); if(!strstr($password,$char)) { $password .= $char; $i+=1; } } return $password; } /////////////////////// /* function subeArchivo($campo_name,$campo_tmp,$ruta) { $ext = pathinfo($campo_name,PATHINFO_EXTENSION); if(in_array($ext,array('pdf','jpg','jpeg','png','mp4'))){ if ($campo_name != ""){ if (!move_uploaded_file($campo_tmp,$ruta.remplaza_acentos($campo_name))){ echo '

Ocurrió algún error al subir el archivo '.$campo_name.'. No pudo guardarse.

'; } else{ return $campo_name; } } }else{ echo '

Formato de archivo no soportado.

'; } } */ function subeArchivo($campo_name,$campo_tmp,$ruta) { $ext = '.'.pathinfo($campo_name, PATHINFO_EXTENSION);//Extrae la extención $nombre = pathinfo($campo_name, PATHINFO_FILENAME);//Extrae el nombre $file = remplaza_acentos($nombre).$ext; // Crea el nombre de archivo if(file_exists($ruta.$file)){//Revisa la existencia del archivo $i=1; $filename=remplaza_acentos($nombre)."-".$i.$ext;//Crea nuevo nombre con indicador numérico while(file_exists($ruta.$filename)){//Revisa si este archivo ya existe y si es asi, continua aumentado el identifiador numérico $filename=remplaza_acentos($nombre)."-".$i.$ext; $i++; } $file = $filename;//Redefine el nombre del archivo. } if ($campo_name != ""){ if (!move_uploaded_file($campo_tmp,$ruta.$file)){ die ('

Ocurrió algún error al subir el archivo '.$campo_name.'.
No pudo guardarse.

'); //Error de subida de archivo } else{ return $file;//Regresa el nombre del archivo ya formateado } } } function imgMuestra($ruta_data,$ruta_reldata,$img,$estilo) { if ($img!="" && file_exists($ruta_reldata.$img)){ return ''; } } function imgMuestraEdit($ruta,$img,$id) { if (file_exists($ruta.$img)){ return ' Eliminar imagen >>
'; } } function imgPrensaEdit($ruta,$img,$id) { if (file_exists($ruta.$img)){ return ' Eliminar imagen >>
'; } } function linkMuestra($link,$txt) { $readmore = 'style="font-size:12px; font-family:Arial, Helvetica, sans-serif; padding:0; margin:0; text-decoration:none; color:#9F161C;" '; if ($link!="" && $txt==""){ return 'Read more'; } else if ($link!="" && $txt!=""){ return ''.$txt.''; } } /* function subeFoto($campo_name,$campo_tmp,$nombre,$num,$ancho_gr,$ancho_md,$ancho_ch,$ruta) { $ext = pathinfo($campo_name,PATHINFO_EXTENSION); if(in_array($ext,array('jpg','jpeg'))){ if ($campo_name != ""){ $foto_nombre = $nombre.$num.'.jpg'; $md = 'md_'.$foto_nombre; $ch = 'ch_'.$foto_nombre; if (!move_uploaded_file($campo_tmp,$ruta.$foto_nombre)){ echo '

Ocurrió algún error al subir la foto '.$campo_name.'. No pudo guardarse.

'; return false; } else{ $thumb=new thumbnail($ruta.$foto_nombre); $size = GetImageSize($ruta.$foto_nombre); $thumb->jpeg_quality(95); if($size[0]>$ancho_gr){//Prevenir estirar fotos
//Ajustarla por ser mayor al ancho_gr $thumb->size_width($ancho_gr); }else{ //No ajustarla $thumb->size_width($size[0]); } $thumb->save($ruta.$foto_nombre); if ($ancho_md!=""){ $thumb->jpeg_quality(95); $thumb->size_width($ancho_md); $thumb->save($ruta.$md); } if ($ancho_ch!=""){ $thumb->jpeg_quality(95); $thumb->size_width($ancho_ch); $thumb->save($ruta.$ch); } return $foto_nombre; } } }else{ echo '

Formato de archivo no soportado.

'; return false; } } */ function subeFoto($campo_name,$campo_tmp,$nombre,$num,$ancho_gr,$ancho_md,$ancho_ch,$ruta) { $ext = pathinfo($campo_name,PATHINFO_EXTENSION); $ext = strtolower(pathinfo($campo_name,PATHINFO_EXTENSION));// Obtener extención y pasarla a minúsculas. $foto_temp = $nombre.$num.'.'.$ext; $foto_nombre = $nombre.$num.'.jpg'; $md = 'md_'.$foto_nombre; $ch = 'ch_'.$foto_nombre; if (!move_uploaded_file($campo_tmp,$ruta.$foto_temp)){ echo '

Ocurrió algún error al subir la foto '.$campo_name.'. no pudo guardarse.

'; return 'error'; } else{ if($ext!='jpg'){ if($ext=='png'){ $clon = imagecreatefrompng($ruta.$foto_temp); //echo 'png'; }elseif($ext=='jpeg'){ //echo 'jpeg'; $clon = imagecreatefromjpeg($ruta.$foto_temp); } imagejpeg($clon, $the_image, 100); imagedestroy($clon); }else{ //echo 'jpg'; $the_image = $ruta.$foto_temp; } gd_auto_rotate($ruta.$foto_temp, $ruta.$foto_temp); $thumb = new thumbnail($the_image); $size = GetImageSize($the_image); if ($size[0] > 1900){ $thumb->jpeg_quality(93); $thumb->size_width($ancho_gr); $thumb->save($ruta.$foto_nombre); } $thumb->jpeg_quality(93); $thumb->size_width($ancho_md); $thumb->save($ruta.$md); $thumb->jpeg_quality(93); $thumb->size_width($ancho_ch); $thumb->save($ruta.$ch); //por ultimo elimino la foto que subi if ($ext!='jpg' && file_exists($ruta.$foto_temp)){ @unlink($ruta.$foto_temp); } return $foto_nombre; } } function subeFotoAuto($campo_name,$campo_tmp,$nombre,$num,$alto_gr,$alto_ch,$ruta) { $ext = pathinfo($campo_name,PATHINFO_EXTENSION); if(in_array($ext,array('jpg','jpeg'))){ if ($campo_name != ""){ $foto_nombre = $nombre.$num.'.jpg'; $ch = 'ch_'.$foto_nombre; if (!move_uploaded_file($campo_tmp,$ruta.$foto_nombre)){ echo '

Ocurrió algún error al subir la foto '.$campo_name.'. No pudo guardarse.

'; return false; } else{ $thumb=new thumbnail($ruta.$foto_nombre); $thumb->jpeg_quality(92); $thumb->size_height($alto_gr); $thumb->save($ruta.$foto_nombre); if ($alto_ch!=""){ $thumb->jpeg_quality(92); $thumb->size_height($alto_ch); $thumb->save($ruta.$ch); } return $foto_nombre; } } }else{ echo '

Formato de archivo no soportado.

'; return false; } } function subeAutoPortada($campo_name,$campo_tmp,$nombre,$ruta) { $ext = pathinfo($campo_name,PATHINFO_EXTENSION); if(in_array($ext,array('jpg','jpeg'))){ if ($campo_name != ""){ $foto_nombre = $nombre.'.jpg'; $ch = 'ch_'.$foto_nombre; if (!move_uploaded_file($campo_tmp,$ruta.$foto_nombre)){ echo '

Ocurrió algún error al subir la foto '.$campo_name.'. No pudo guardarse.

'; return false; } else{ $thumb=new thumbnail($ruta.$foto_nombre); $thumb->jpeg_quality(92); $thumb->size_width(485); $thumb->save($ruta.'md_'.$foto_nombre); $thumb->jpeg_quality(92); $thumb->size_width(100); $thumb->save($ruta.$ch); return $foto_nombre; } } }else{ echo '

Formato de archivo no soportado.

'; return false; } } /* function subeFotoSola($campo_name,$campo_tmp,$nombre,$ruta) { $ext = pathinfo($campo_name,PATHINFO_EXTENSION); if(in_array($ext,array('jpg','jpeg'))){ if ($campo_name != ""){ $foto_nombre = $nombre.'.jpg'; $ch = 'ch_'.$foto_nombre; if (!move_uploaded_file($campo_tmp,$ruta.$foto_nombre)){ echo '

Ocurrió algún error al subir la foto '.$campo_name.'. No pudo guardarse.

'; } else{ $thumb=new thumbnail($ruta.$foto_nombre); $thumb->jpeg_quality(92); $thumb->size_width(120); $thumb->save($ruta.$ch); return $foto_nombre; } } }else{ die('

Formato de archivo no soportado.

'); } } */ function subeFotoSola($campo_name,$campo_tmp,$nombre,$ruta) { $ext = pathinfo($campo_name,PATHINFO_EXTENSION); if(in_array($ext,array('pdf','jpg','jpeg','png','mp4'))){ if ($campo_name != ""){ $foto_nombre = $nombre.'.jpg'; if (!move_uploaded_file($campo_tmp,$ruta.remplaza_acentos($foto_nombre))){ die ('

Ocurrió algún error al subir el archivo '.$campo_name.'. No pudo guardarse.

'); } else{ return $campo_name; } } }else{ echo '

Formato de archivo no soportado.

'; } } function subeAutoSano($campo_name,$campo_tmp,$nombre,$ruta) { $ext = pathinfo($campo_name,PATHINFO_EXTENSION); if(in_array($ext,array('jpg','jpeg','png'))){ if ($campo_name != ""){ $foto_nombre = $nombre.'_sano.png'; $ch = 'ch_'.$foto_nombre; if (!move_uploaded_file($campo_tmp,$ruta.$foto_nombre)){ echo '

Ocurrió algún error al subir la foto '.$campo_name.'. No pudo guardarse.

'; return false; } else{ $thumb = new thumbnail($ruta.$foto_nombre); $thumb->jpeg_quality(92); $thumb->size_width(400); $thumb->save($ruta.'md_'.$foto_nombre); $thumb->jpeg_quality(92); $thumb->size_width(200); $thumb->save($ruta.$ch); return $foto_nombre; } } }else{ echo '

Formato de archivo no soportado.

'; return false; } } //paso la fecha de mysql a fecha normal function MySQLDateToDate($MySQLFecha,$lg='es',$sep='.') { if (($MySQLFecha == "") or ($MySQLFecha == "0000-00-00") ){ return ""; }else{ if($lg=='en'){ $fecha='m'.$sep.'d'.$sep.'Y'; }else{ $fecha='d'.$sep.'m'.$sep.'Y'; } return date($fecha,strtotime($MySQLFecha)); } } /*function MySQLDateToDate($MySQLFecha) { if (($MySQLFecha == "") or ($MySQLFecha == "0000-00-00") ) {return "";} else {return date("d.m.Y",strtotime($MySQLFecha));} }*/ //paso la fecha de mysql a fecha normal function MySQLDateToDate_en($MySQLFecha) { if (($MySQLFecha == "") or ($MySQLFecha == "0000-00-00") ) {return "";} else {return date("m.d.Y",strtotime($MySQLFecha));} } // de normal a MYSQL function DateToQuotedMySQLDate($Fecha) { if ($Fecha<>""){ $trozos=explode(".",$Fecha,3); return "".$trozos[2]."-".$trozos[1]."-".$trozos[0].""; } else {return "NULL";} } function fechaAgenda($MySQLFecha){ if (($MySQLFecha == "") or ($MySQLFecha == "0000-00-00") ) {return "";} else {return date("d/m/Y",strtotime($MySQLFecha));} } function fechaCabezal($fecha){ if (($fecha == "") or ($fecha == "0000-00-00") ){ return ""; } $meses = array ('mes','Enero', 'Febrero', 'Marzo', 'Abril', 'Mayo', 'Junio', 'Julio', 'Agosto', 'Septiembre', 'Octubre', 'Noviembre', 'Diciembre'); $mes= date("m",strtotime($fecha)) + 0; $mes_muestra = $meses[$mes]; //$dia = date("d",strtotime($fecha)) + 0; return $mes_muestra.' '.date("Y",strtotime($fecha)); } function fechaAutos($fecha,$idioma,$sepa=' '){ if (($fecha == "") or ($fecha == "0000-00-00") ){ return ""; } $meses_es = array ('mes','Enero', 'Febrero', 'Marzo', 'Abril', 'Mayo', 'Junio', 'Julio', 'Agosto', 'Septiembre', 'Octubre', 'Noviembre', 'Diciembre'); $meses_en = array ('mes','January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'); $meses_po = array ('mes','Janeiro', 'Fevereiro', 'Março', 'Abril', 'Maio', 'Junho', 'Julho', 'Agosto', 'Setembro', 'Outubro', 'Novembro', 'Dezembro'); $mes= date("m",strtotime($fecha)) + 0; if ( $idioma == "en" ) : $mes_muestra = $meses_en[$mes]; elseif ( $idioma == "es" ) : $mes_muestra = $meses_es[$mes]; elseif ( $idioma == "po" ) : $mes_muestra = $meses_po[$mes]; endif; //$dia = date("d",strtotime($fecha)) + 0; return $mes_muestra.$sepa.date("Y",strtotime($fecha)); } function listado ($lista,$selec=FALSE,$desel=FALSE){ $selec = explode(",",$selec); foreach ($lista as $index => $fila) { if ($fila!=""){ if (strlen($index)==1){ $index = '00'.$index; } if (strlen($index)==2){ $index = '0'.$index; } echo ''; } } } function listadoSimple ($lista,$selec,$desel){ foreach ($lista as $index => $fila) { echo ''; } } function creaLista ($campo){ if ($campo!=""){ foreach($campo as $item){ $lista .= "$item,"; } $lista = substr ($lista, 0, -1); return $lista ; } } function muestraLista ($campo,$array){ if ($campo!=""){ $trozos=explode(",",$campo); foreach($trozos as $item){ $indice = $item + 0; $lista .= $array[$indice]."
"; } return $lista ; } } function limitarPalabras($cadena, $longitud=20, $elipsis = "...") { $palabras = explode(' ', $cadena); if (count($palabras) > $longitud){ return strip_tags(implode(' ', array_slice($palabras, 0, $longitud)) . $elipsis); }else{ return strip_tags($cadena); } } function check_email_address($email) { // First, we check that there's one @ symbol, and that the lengths are right if ( !filter_var($email, FILTER_VALIDATE_EMAIL) ) { // Email invalid because wrong number of characters in one section, or wrong number of @ symbols. return false; } // Split it into sections to make life easier $email_array = explode("@", $email); /*$local_array = explode(".", $email_array[0]); for ($i = 0; $i < sizeof($local_array); $i++) { if (!preg_match("^(([A-Za-z0-9!#$%&'*+/=?^_`{|}~-][A-Za-z0-9!#$%&'*+/=?^_`{|}~\.-]{0,63})|(\"[^(\\|\")]{0,62}\"))$^", $local_array[$i])) { return false; } }*/ if (!preg_match("^\[?[0-9\.]+\]?$^", $email_array[1])) { // Check if domain is IP. If not, it should be valid domain name $domain_array = explode(".", $email_array[1]); if (sizeof($domain_array) < 2) { return false; // Not enough parts to domain } for ($i = 0; $i < sizeof($domain_array); $i++) { if (!preg_match("^(([A-Za-z0-9][A-Za-z0-9-]{0,61}[A-Za-z0-9])|([A-Za-z0-9]+))$^", $domain_array[$i])) { return false; } } } return true; } function porcentaje ($resp1,$resp2,$resp3,$resp4,$num){ $total = $resp1 + $resp2 + $resp3 + $resp4; //resultados posibles switch ($num) { case 1: $respuesta = $resp1 * 100 / $total; break; case 2: $respuesta = $resp2 * 100 / $total; break; case 3: $respuesta = $resp3 * 100 / $total; break; case 4: $respuesta = $resp4 * 100 / $total; break; } /* $valor = round(($respuesta), 1); if (!strpos($valor, '.') && $valor!= 0){ $valor = $valor.'.0'; } //return $valor; */ return $respuesta; } function puntajeAdulto($fecha) { $fecha = str_replace('-', '', $fecha); if ($fecha >= '20130724'){ $cantidad = '17.00'; } else { $cantidad = '16.00'; } //echo $fecha.' - '.$cantidad; echo $cantidad; } function Txt($var){ //replace for accents catalan spanish and more $a = array("'"); $b = array("’"); $var= str_replace($a, $b, $var); return $var; } $protos = array( '01/2015' => array( 'nombre'=>'Latin NCAP Adult Occupant Protection Assessment Protocol v3.0– From January 2016', 'archivo'=>'Latin NCAP Adult Occupant Protection Assessment Protocol v3.0– From January 2016.pdf' ), '03/2014'=>array( 'nombre'=>'Latin NCAP Child Occupant Protection Assessment Protocol v3.0– From March 2014', 'archivo'=>'Latin_NCAP_COP_Protocol_2014_2016_FINAL_14429.pdf' ), ''=>array( 'nombre'=>'CSSTR - Latin NCAP Car Sponsorship Testing and Retesting Protocol v2.0', 'archivo'=>'CSSTR_Latin_NCAP_CAR_SPECIFICATION_SPONSORSHIP_TESTING_AND_RETESTING_Protocol_v2_0_March_2013.pdf' ), ''=>array( 'nombre'=>'Latin NCAP Adult Assessment Protocol v2.0', 'archivo'=>'AOP_Latin_NCAP_Adult_Assessment_Protocol_v2_0_March_2013.pdf' ), '03/2013'=>array( 'nombre'=>'Latin NCAP Child Occupant Assessment Protocol v2.0 - Until February 2014', 'archivo'=>'COP_Latin_NCAP_Child_Occupant_Assessment_Protocol_v2_0_March_2013.pdf' ), ''=>array( 'nombre'=>'Latin NCAP Frontal Protocol v1.0', 'archivo'=>'LatinNCAP_Frontal_Protocol_Version_1_0.pdf' ) ); function TxtMedia($txt,$array){ $busca=array( '/(?:\[link url=\"([^\"]*)\"\]([^\[]*)\[\/link\])/', '/(?:\[adjunto_([0-9]+) txt=\"([^\"]*)\"\])/', '/(\[foto_)+([0-9]+)+(\])/', '/(\[video_)+([0-9]+)+(\])/' ); $cambia=array( '$2', '$2', '', '
' ); $pre_txt = preg_replace($busca, $cambia, $txt); $a=array(); $b=array(); foreach($array as $busca=>$cambia){ array_push($a,$busca); array_push($b,$cambia); } preg_match_all('/(\\[(video_|foto_|adjunto_)+([0-9]+)\\])/',$pre_txt, $encontrados); foreach($encontrados[0] as $aca){ if(isset($array[$aca])){ $cambio = $array[$aca]; }else{ $cambio = ''; } $pre_txt = str_replace($aca,$cambio,$pre_txt); } return $pre_txt; } function fix_url($txt,$url){ $a=array('src="img/','href="../','src="../'); $b=array('src="'.$url.'img','href="'.$url,'src="'.$url); return str_replace($a,$b,$txt); } function copia_archivo($archivo,$ruta=false){ $ext = pathinfo($archivo, PATHINFO_EXTENSION); $nombre = pathinfo($archivo, PATHINFO_FILENAME); $origen = pathinfo($archivo, PATHINFO_DIRNAME).'/'; $ruta=(!$ruta) ? $origen : $ruta; $num=1; while(file_exists($ruta.$nombre.'_'.$num.'.'.$ext)){ $num++; } $nuevo_archivo = $nombre.'_'.$num.'.'.$ext; if(!copy($archivo,$ruta.$nuevo_archivo)){ return false; }else{ return $nuevo_archivo; } } function salar($txt){ $sal = 'ln_anti_hack'; $str = $txt.$sal; $md5 = md5($str); return md5($md5); } function get_client_ip() { $ipaddress = ''; if (isset($_SERVER['HTTP_CLIENT_IP'])) $ipaddress = $_SERVER['HTTP_CLIENT_IP']; else if(isset($_SERVER['HTTP_X_FORWARDED_FOR'])) $ipaddress = $_SERVER['HTTP_X_FORWARDED_FOR']; else if(isset($_SERVER['HTTP_X_FORWARDED'])) $ipaddress = $_SERVER['HTTP_X_FORWARDED']; else if(isset($_SERVER['HTTP_FORWARDED_FOR'])) $ipaddress = $_SERVER['HTTP_FORWARDED_FOR']; else if(isset($_SERVER['HTTP_FORWARDED'])) $ipaddress = $_SERVER['HTTP_FORWARDED']; else if(isset($_SERVER['REMOTE_ADDR'])) $ipaddress = $_SERVER['REMOTE_ADDR']; else $ipaddress = 'UNKNOWN'; return $ipaddress; } function idioma($lg,$txt_en,$txt_es,$txt_po){ switch ($lg) { case 'en': $txt = $txt_en; break; case 'es': $txt = $txt_es; break; case 'po': $txt = $txt_po; break; } return $txt; } function acentos($cadena) { $search = explode(",","á,é,í,ó,ú,ñ,Á,É,Í,Ó,Ú,Ñ,á,é,í,ó,ú,ñ,Ãá,Ãé,Ãí,Ãó,Ãú,Ãñ,Ó,à ,É,à ,Ú,“,†,¿,ü,°,ª,º,ó,çã,ç,ã,ö,’,ô"); $replace = explode(",","á,é,í,ó,ú,ñ,Á,É,Í,Ó,Ú,Ñ,á,é,í,ó,ú,ñ,Á,É,Í,Ó,Ú,Ñ,Ó,Á,É,Í,Ú,\",\",¿,ü,A,ª,º,ó,çã,ç,ã,ö,',ô"); $cadena= str_replace($search, $replace, $cadena); return $cadena; } function is_session_started() { if ( php_sapi_name() !== 'cli' ) { if ( version_compare(phpversion(), '5.4.0', '>=') ) { return session_status() === PHP_SESSION_ACTIVE ? TRUE : FALSE; } else { return session_id() === '' ? FALSE : TRUE; } } return FALSE; } function idMax($nombre_tabla, $conexion){ $sql = "SELECT MAX(id) as id FROM {$nombre_tabla};"; $result = $conexion->query($sql); $row = $result->fetch_assoc(); $result->free(); return $row['id']; } function posicionMax($nombre_tabla, $conexion){ $sql = "SELECT MAX(orden) as orden FROM {$nombre_tabla};"; $result = $conexion->query($sql); $row = $result->fetch_assoc(); $result->free(); return $row['orden']; } function noCacheURL($directorio){ $url = ""; if(is_file($directorio)){ $url = $directorio.'?'.filesize($directorio); } return $url; } function object_to_array($obj) { $_arr = is_object($obj) ? get_object_vars($obj) : $obj; foreach ($_arr as $key => $val) { $val = (is_array($val) || is_object($val)) ? object_to_array($val) : $val; $_arr[$key] = $val; } return $_arr; } function getDataExtraJson($nombre_id, $id, $conexion, $tabla_p = null, $campo_p = null){ $tabla = $tabla_p != null ? $tabla_p : 'autos_2020'; $campo = $campo_p != null ? $campo_p : 'extra_data_json'; $sql = "SELECT ${campo_p} FROM ${tabla} WHERE ${nombre_id} = ${id};"; // var_dump($sql); $result = $conexion->query($sql); $row = $result->fetch_assoc(); $result->free(); return json_decode($row[$campo_p], true); } function saveDataExtraJson($data_array, $nombre_id, $id, $conexion, $tabla_p = null, $campo_p = null){ $success = false; $data_json = json_encode($data_array, JSON_UNESCAPED_UNICODE | JSON_HEX_APOS ); $tabla = $tabla_p != null ? $tabla_p : 'autos_2020'; $campo = $campo_p != null ? $campo_p : 'extra_data_json'; $sql = "UPDATE `${tabla}` SET `${campo}` = '${data_json}' WHERE ${nombre_id} = ${id};"; if($conexion->query($sql)){ $success = true; } return $success; } function fSize($directorio){ $directorio = $directorio.'?'.filesize($directorio); echo $directorio; } ?>