Initial Commit

This commit is contained in:
Cloud User
2024-03-06 17:45:49 -06:00
commit 8986493161
250 changed files with 43078 additions and 0 deletions

127
include/util.php Normal file
View File

@@ -0,0 +1,127 @@
<?php
/*
* Funciones de utilidad
*/
function fechaGuion($fechaTxt, $showDay = true){//convierte fecha a guiones
$fechaTxt = trim($fechaTxt);
if(substr($fechaTxt,2,1) == "/" && substr($fechaTxt,5,1) == "/"){// dd/mm/aaaa
$fechaArr = explode("/", $fechaTxt);
if($showDay)
return $fechaArr[2]."-".$fechaArr[1]."-".$fechaArr[0];
else
return $fechaArr[2]."-".$fechaArr[1]."-01";
}
if(substr($fechaTxt,4,1) == "-" && substr($fechaTxt,7,1) == "-"){// aaaa-mm-dd
if($showDay)
return $fechaTxt;
$fechaArr = explode("-", $fechaTxt);
return $fechaArr[0]."-".$fechaArr[1]."-01";
}
return "";
}
function fechaSlash($fechaTxt, $showDay = true){//convierte fecha a /
$fechaTxt = trim($fechaTxt);
if(substr($fechaTxt,2,1) == "/" && substr($fechaTxt,5,1) == "/"){// dd/mm/aaaa
if($showDay)
return $fechaTxt;
$fechaArr = explode("/", $fechaTxt);
return "01/".$fechaTxt[1]."/".$fechaTxt[2];
}
if(substr($fechaTxt,4,1) == "-" && substr($fechaTxt,7,1) == "-"){// aaaa-mm-dd
$fechaArr = explode("-", $fechaTxt);
if($showDay)
return $fechaArr[2]."/".$fechaArr[1]."/".$fechaArr[0];
else
return "01/".$fechaArr[1]."/".$fechaArr[0];
}
return "";
}
function fechaTexto($fechaTxt, $showYear = true){//convierte fecha a cadena de texto
$fechaTxt = trim($fechaTxt);
if(substr($fechaTxt,2,1) == "/" && substr($fechaTxt,5,1) == "/"){// dd/mm/aaaa
$fechaArr = explode("/", $fechaTxt);
if($showYear)
return intval($fechaArr[0])." de ".mesNombre($fechaArr[1])." de ".$fechaArr[2];
else
return intval($fechaArr[0])." de ".mesNombre($fechaArr[1]);
}
if(substr($fechaTxt,4,1) == "-" && substr($fechaTxt,7,1) == "-"){// aaaa-mm-dd
$fechaArr = explode("-", $fechaTxt);
if($showYear)
return intval($fechaArr[2])." de ".mesNombre($fechaArr[1])." de ".$fechaArr[0];
else
return intval($fechaArr[2])." de ".mesNombre($fechaArr[1]);
}
return "";
}
function fechaMonthPicker($fechaTxt){
$meses=array(1=>"ene", "feb", "mar", "abr", "may", "jun", "jul", "ago", "sep", "oct", "nov", "dic");
$fechaTxt = trim($fechaTxt);
if(substr($fechaTxt,2,1) == "/" && substr($fechaTxt,5,1) == "/"){// dd/mm/aaaa
$fechaArr = explode("/", $fechaTxt);
return $meses[intval($fechaArr[1])].", ".$fechaArr[2];
}
if(substr($fechaTxt,4,1) == "-" && substr($fechaTxt,7,1) == "-"){// aaaa-mm-dd
$fechaArr = explode("-", $fechaTxt);
return $meses[intval($fechaArr[1])].", ".$fechaArr[0];
}
return "";
}
function fechaMes($fechaTxt){
$fechaTxt = trim($fechaTxt);
if(substr($fechaTxt,2,1) == "/" && substr($fechaTxt,5,1) == "/"){// dd/mm/aaaa
$fechaArr = explode("/", $fechaTxt);
return intval(mesNombre($fechaArr[1])." ".$fechaArr[2]);
}
if(substr($fechaTxt,4,1) == "-" && substr($fechaTxt,7,1) == "-"){// aaaa-mm-dd
$fechaArr = explode("-", $fechaTxt);
return intval(mesNombre($fechaArr[2])." ".$fechaArr[1]);
}
return "";
}
function mesNombre($num){
$meses=array(1=>"enero", "febrero", "marzo", "abril", "mayo", "junio", "julio", "agosto", "septiembre", "octubre", "noviembre", "diciembre");
return $meses[intval($num)];
}
function diaNombre($num){
$dias=array("domingo", "lunes", "martes", "miércoles", "jueves", "viernes", "sábado");
return $dias[intval($num)];
}
function horaMin($arr, $campo = "Horario_hora"){
$min = "";
foreach($arr as $horario){
if($min == "" || date('H:i', strtotime($horario[$campo])) < date('H:i', strtotime($min))){
$min = $horario[$campo];
}
}
return date('H:i', strtotime($min));
}
function horaMax($arr, $campo = "Horario_hora_final"){
$max = "";
foreach($arr as $horario){
if($max == "" || date('H:i', strtotime($horario[$campo])) > date('H:i', strtotime($max))){
$max = $horario[$campo];
}
}
return date('H:i', strtotime($max));
}
function duracionMinutos($fechahora_i, $fechahora_f){
return round((strtotime($fechahora_f) - strtotime($fechahora_i)) / 60,2);
}
function validaPassword($pass){
$expr = '/^\S*(?=\S{5,})(?=\S*[a-zA-Z])(?=\S*[\d])(?=\S*[\W])\S*$/';
return preg_match($expr, $pass);
}