Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- //Genera contraseña aleatoria
- function password_generator()
- {
- $password = "";
- //Cadenas de caracteres permitidos para el password
- $minus = rc("abcdefghijklmnopqrstuvwxyz");
- $mayus = rc("ABCDEFGHIJKLMNOPQRSTUVWXYZ");
- $numbers = rc("1234567890");
- $specials = rc("#=)_@$-%{&*+}(");
- $tmpPassword = $minus . $mayus . $numbers . $specials;
- $password = str_shuffle($tmpPassword);
- return $password;
- }
- function rc($str = '', $num = 2)
- {
- if(strlen($str))
- {
- $s = extract_str($str, $num);
- return $s;
- }
- return '';
- }
- function extract_str($str, $num)
- {
- $finalStr = ""; //variable para almacenar la cadena generada
- for($i = 0; $i < $num; $i++)
- {
- /*Extraemos 1 caracter de los caracteres
- entre el rango 0 a Numero de letras que tiene la cadena */
- $finalStr .= substr($str, rand(0, strlen($str)), 1);
- }
- if(strlen($finalStr) < $num)//si no genera el numero total de elementos que se vuelta a ejecutar
- {
- $finalStr = extract_str($str, $num);
- }
- return $finalStr;
- }
- //Quita todos los espacios en blanco
- function remove_spaces($string)
- {
- return preg_replace("/\s+/"," ", $string);
- }
- //Valida email
- function valid_email($email)
- {
- return (filter_var($email, FILTER_VALIDATE_EMAIL));
- }
- //Devuelve el valor en entero de la cadena(activo, inactivo)
- function get_status_value($status)
- {
- $s = -1;
- switch ($status)
- {
- case 'Activo':
- $s = 1;
- break;
- case 'Inactivo':
- $s = 0;
- break;
- }
- return $s;
- }
- //verifica si un valor es un bool
- function filter_bool($value)
- {
- return filter_var($value, FILTER_VALIDATE_BOOLEAN);
- }
- //Elimina saltos de linea y tabs
- function remove_breaks($string)
- {
- return remove_spaces(preg_replace("/\r\n+|\r+|\n+|\t+/i", " ", trim($string)));
- }
- function generate_username($type, $campus_id, $studentid = '')
- {
- $username = '';
- $t = 'I';
- switch ($type)
- {
- case 'Alumno':
- $t = 'A';
- break;
- case 'Profesor':
- $t = 'P';
- }
- $username = $campus_id . $t . $studentid;
- return strtoupper($username);
- }
- function validate_date($date)
- {
- if (strlen(trim($date)) > 0 && preg_match("/^[0-9]{4}-(0[1-9]|1[0-2])-(0[1-9]|[1-2][0-9]|3[0-1])$/", $date))
- return true;
- return false;
- }
- function validate_cycle($cycle)
- {
- $quarter = substr($cycle, 2, 1);
- $num_quarter = substr($cycle, 3, 1);
- if(strlen($cycle) > 4 || !is_numeric($cycle) || $quarter != 4 || $num_quarter > 3 || $num_quarter == 0) return false;
- return true;
- }
- function validate_grade($grade)
- {
- if((int)$grade < 1 || (int)$grade > 10)
- return false;
- return true;
- }
- function validate_group($group)
- {
- $letters = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z'];
- if (!in_array(mb_strtolower($group), $letters))
- return false;
- return true;
- }
- function limit_invalid($string, $limit)
- {
- return (strlen(removeAccents($string)) > $limit);
- }
- function min_invalid($string, $min)
- {
- return (strlen(removeAccents($string)) < $min);
- }
- function greater_date($end, $start, $after_or_equal = false)
- {
- $d1 = new DateTime($start);
- $d2 = new DateTime($end);
- if($after_or_equal)
- return ($d2 >= $d1);
- return ($d2 > $d1);
- }
- function removeAccents($str) {
- $a = array('À', 'Á', 'Â', 'Ã', 'Ä', 'Å', 'Æ', 'Ç', 'È', 'É', 'Ê', 'Ë', 'Ì', 'Í', 'Î', 'Ï', 'Ð', 'Ñ', 'Ò', 'Ó', 'Ô', 'Õ', 'Ö', 'Ø', 'Ù', 'Ú', 'Û', 'Ü', 'Ý', 'ß', 'à', 'á', 'â', 'ã', 'ä', 'å', 'æ', 'ç', 'è', 'é', 'ê', 'ë', 'ì', 'í', 'î', 'ï', 'ñ', 'ò', 'ó', 'ô', 'õ', 'ö', 'ø', 'ù', 'ú', 'û', 'ü', 'ý', 'ÿ', 'Ā', 'ā', 'Ă', 'ă', 'Ą', 'ą', 'Ć', 'ć', 'Ĉ', 'ĉ', 'Ċ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 'A', 'A', 'A', 'A', 'A', 'AE', 'C', 'E', 'E', 'E', 'E', 'I', 'I', 'I', 'I', 'D', 'N', 'O', 'O', 'O', 'O', 'O', 'O', 'U', 'U', 'U', 'U', 'Y', 's', 'a', 'a', 'a', 'a', 'a', 'a', 'ae', 'c', 'e', 'e', 'e', 'e', 'i', 'i', 'i', 'i', 'n', 'o', 'o', 'o', 'o', 'o', 'o', 'u', 'u', 'u', 'u', 'y', 'y', 'A', 'a', 'A', 'a', 'A', 'a', 'C', 'c', 'C', 'c', 'C', 'c', 'C', 'c', 'D', 'd', 'D', 'd', 'E', 'e', 'E', 'e', 'E', 'e', 'E', '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', 'Α', 'α', 'Ε', 'ε', 'Ο', 'ο', 'Ω', 'ω', 'Ι', 'ι', 'ι', 'ι', 'Υ', 'υ', 'υ', 'υ', 'Η', 'η');
- return str_replace($a, $b, $str);
- }
- function valid_between($value, $start, $end)
- {
- return ($value >= $start && $value <= $end);
- }
- function now()
- {
- return date('Y-m-d H:i:s');
- }
- function date_now()
- {
- return date('Y-m-d');
- }
- // function for debugin var
- function p($s)
- {
- if(!is_string($s))
- {
- echo "<pre>";
- print_r($s);
- echo "</pre>";
- }
- else
- {
- echo nl2br($s);
- }
- }
- function months($m)
- {
- $months = array(
- 0 => 'smarch',
- 1 => 'enero',
- 2 => 'febrero',
- 3 => 'marzo',
- 4 => 'abril',
- 5 => 'mayo',
- 6 => 'junio',
- 7 => 'julio',
- 8 => 'agosto',
- 9 => 'septiembre',
- 10 => 'octubre',
- 11 => 'noviembre',
- 12 => 'diciembre'
- );
- return $months[(int)$m];
- }
- function weekdays() {
- $days = array(
- 1 => 'Lunes',
- 2 => 'Martes',
- 3 => 'Miércoles',
- 4 => 'Jueves',
- 5 => 'Viernes',
- 6 => 'Sábado',
- 7 => 'Domingo'
- );
- return $days;
- }
- function date_short_text($f)
- {
- if (strlen($f)) {
- $f = explode(' ', $f);
- $f = explode('-', $f[0]);
- return $f[2] . " " . substr(months($f[1]), 0, 3) . ". " . $f[0];
- }
- return 'Fecha no definida.';
- }
- function date_text($f, $dName = true)
- {
- if (strlen($f)) {
- $dayName = '';
- $days = weekdays();
- $d = date('N', strtotime($f));
- $f = explode(' ', $f);
- $f = explode('-', $f[0]);
- if($dName) $dayName = $days[ $d ] . ", ";
- return $dayName . $f[2] . " de " . months($f[1]) . " de " . $f[0];
- }
- return 'Fecha no definida.';
- }
- function date_month_year($f)
- {
- if (strlen($f)) {
- $f = explode(' ', $f);
- $f = explode('-', $f[0]);
- return months($f[1]) . " " . $f[0];
- }
- return 'Fecha no definida.';
- }
- function date_in_words($f){
- if (strlen($f)) {
- $f = explode(' ', $f);
- $f = explode('-', $f[0]);
- $tDays = number_to_letters($f[2]);
- $text1 = " a los ";
- $text2 = " días ";
- if ($f[2] == 1) {
- $text1 = " a un";
- $text2 = " día ";
- }
- $finalText = strtolower($text1 . $tDays . $text2 . " del mes de " . months($f[1]) . " del año " . number_to_letters($f[0]));
- return $finalText;
- }
- }
- function number_to_letters($number){
- return \NumeroALetras::convertir((int)$number);
- }
- ?>
Add Comment
Please, Sign In to add comment