Guest User

Untitled

a guest
Feb 17th, 2018
303
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.69 KB | None | 0 0
  1. <?php
  2. //Genera contraseña aleatoria
  3. function password_generator()
  4. {
  5. $password = "";
  6.  
  7. //Cadenas de caracteres permitidos para el password
  8. $minus = rc("abcdefghijklmnopqrstuvwxyz");
  9. $mayus = rc("ABCDEFGHIJKLMNOPQRSTUVWXYZ");
  10. $numbers = rc("1234567890");
  11. $specials = rc("#=)_@$-%{&*+}(");
  12.  
  13. $tmpPassword = $minus . $mayus . $numbers . $specials;
  14. $password = str_shuffle($tmpPassword);
  15.  
  16. return $password;
  17. }
  18.  
  19. function rc($str = '', $num = 2)
  20. {
  21. if(strlen($str))
  22. {
  23. $s = extract_str($str, $num);
  24. return $s;
  25. }
  26.  
  27. return '';
  28. }
  29.  
  30. function extract_str($str, $num)
  31. {
  32. $finalStr = ""; //variable para almacenar la cadena generada
  33. for($i = 0; $i < $num; $i++)
  34. {
  35. /*Extraemos 1 caracter de los caracteres
  36. entre el rango 0 a Numero de letras que tiene la cadena */
  37. $finalStr .= substr($str, rand(0, strlen($str)), 1);
  38. }
  39.  
  40. if(strlen($finalStr) < $num)//si no genera el numero total de elementos que se vuelta a ejecutar
  41. {
  42. $finalStr = extract_str($str, $num);
  43. }
  44.  
  45. return $finalStr;
  46. }
  47.  
  48. //Quita todos los espacios en blanco
  49. function remove_spaces($string)
  50. {
  51. return preg_replace("/\s+/"," ", $string);
  52. }
  53.  
  54. //Valida email
  55. function valid_email($email)
  56. {
  57. return (filter_var($email, FILTER_VALIDATE_EMAIL));
  58. }
  59.  
  60. //Devuelve el valor en entero de la cadena(activo, inactivo)
  61. function get_status_value($status)
  62. {
  63. $s = -1;
  64. switch ($status)
  65. {
  66. case 'Activo':
  67. $s = 1;
  68. break;
  69. case 'Inactivo':
  70. $s = 0;
  71. break;
  72. }
  73.  
  74. return $s;
  75. }
  76.  
  77. //verifica si un valor es un bool
  78. function filter_bool($value)
  79. {
  80. return filter_var($value, FILTER_VALIDATE_BOOLEAN);
  81. }
  82.  
  83. //Elimina saltos de linea y tabs
  84. function remove_breaks($string)
  85. {
  86. return remove_spaces(preg_replace("/\r\n+|\r+|\n+|\t+/i", " ", trim($string)));
  87. }
  88.  
  89. function generate_username($type, $campus_id, $studentid = '')
  90. {
  91. $username = '';
  92. $t = 'I';
  93. switch ($type)
  94. {
  95. case 'Alumno':
  96. $t = 'A';
  97. break;
  98. case 'Profesor':
  99. $t = 'P';
  100. }
  101.  
  102. $username = $campus_id . $t . $studentid;
  103.  
  104. return strtoupper($username);
  105. }
  106.  
  107. function validate_date($date)
  108. {
  109. 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))
  110. return true;
  111.  
  112. return false;
  113. }
  114.  
  115. function validate_cycle($cycle)
  116. {
  117. $quarter = substr($cycle, 2, 1);
  118. $num_quarter = substr($cycle, 3, 1);
  119.  
  120. if(strlen($cycle) > 4 || !is_numeric($cycle) || $quarter != 4 || $num_quarter > 3 || $num_quarter == 0) return false;
  121.  
  122. return true;
  123. }
  124.  
  125. function validate_grade($grade)
  126. {
  127. if((int)$grade < 1 || (int)$grade > 10)
  128. return false;
  129.  
  130. return true;
  131. }
  132.  
  133. function validate_group($group)
  134. {
  135. $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'];
  136. if (!in_array(mb_strtolower($group), $letters))
  137. return false;
  138.  
  139. return true;
  140. }
  141.  
  142. function limit_invalid($string, $limit)
  143. {
  144. return (strlen(removeAccents($string)) > $limit);
  145. }
  146.  
  147. function min_invalid($string, $min)
  148. {
  149. return (strlen(removeAccents($string)) < $min);
  150. }
  151.  
  152. function greater_date($end, $start, $after_or_equal = false)
  153. {
  154. $d1 = new DateTime($start);
  155. $d2 = new DateTime($end);
  156.  
  157. if($after_or_equal)
  158. return ($d2 >= $d1);
  159.  
  160. return ($d2 > $d1);
  161. }
  162.  
  163. function removeAccents($str) {
  164. $a = array('À', 'Á', 'Â', 'Ã', 'Ä', 'Å', 'Æ', 'Ç', 'È', 'É', 'Ê', 'Ë', 'Ì', 'Í', 'Î', 'Ï', 'Ð', 'Ñ', 'Ò', 'Ó', 'Ô', 'Õ', 'Ö', 'Ø', 'Ù', 'Ú', 'Û', 'Ü', 'Ý', 'ß', 'à', 'á', 'â', 'ã', 'ä', 'å', 'æ', 'ç', 'è', 'é', 'ê', 'ë', 'ì', 'í', 'î', 'ï', 'ñ', 'ò', 'ó', 'ô', 'õ', 'ö', 'ø', 'ù', 'ú', 'û', 'ü', 'ý', 'ÿ', 'Ā', 'ā', 'Ă', 'ă', 'Ą', 'ą', 'Ć', 'ć', 'Ĉ', 'ĉ', 'Ċ', 'ċ', 'Č', 'č', 'Ď', 'ď', 'Đ', 'đ', 'Ē', 'ē', 'Ĕ', 'ĕ', 'Ė', 'ė', 'Ę', 'ę', 'Ě', 'ě', 'Ĝ', 'ĝ', 'Ğ', 'ğ', 'Ġ', 'ġ', 'Ģ', 'ģ', 'Ĥ', 'ĥ', 'Ħ', 'ħ', 'Ĩ', 'ĩ', 'Ī', 'ī', 'Ĭ', 'ĭ', 'Į', 'į', 'İ', 'ı', 'IJ', 'ij', 'Ĵ', 'ĵ', 'Ķ', 'ķ', 'Ĺ', 'ĺ', 'Ļ', 'ļ', 'Ľ', 'ľ', 'Ŀ', 'ŀ', 'Ł', 'ł', 'Ń', 'ń', 'Ņ', 'ņ', 'Ň', 'ň', 'ʼn', 'Ō', 'ō', 'Ŏ', 'ŏ', 'Ő', 'ő', 'Œ', 'œ', 'Ŕ', 'ŕ', 'Ŗ', 'ŗ', 'Ř', 'ř', 'Ś', 'ś', 'Ŝ', 'ŝ', 'Ş', 'ş', 'Š', 'š', 'Ţ', 'ţ', 'Ť', 'ť', 'Ŧ', 'ŧ', 'Ũ', 'ũ', 'Ū', 'ū', 'Ŭ', 'ŭ', 'Ů', 'ů', 'Ű', 'ű', 'Ų', 'ų', 'Ŵ', 'ŵ', 'Ŷ', 'ŷ', 'Ÿ', 'Ź', 'ź', 'Ż', 'ż', 'Ž', 'ž', 'ſ', 'ƒ', 'Ơ', 'ơ', 'Ư', 'ư', 'Ǎ', 'ǎ', 'Ǐ', 'ǐ', 'Ǒ', 'ǒ', 'Ǔ', 'ǔ', 'Ǖ', 'ǖ', 'Ǘ', 'ǘ', 'Ǚ', 'ǚ', 'Ǜ', 'ǜ', 'Ǻ', 'ǻ', 'Ǽ', 'ǽ', 'Ǿ', 'ǿ', 'Ά', 'ά', 'Έ', 'έ', 'Ό', 'ό', 'Ώ', 'ώ', 'Ί', 'ί', 'ϊ', 'ΐ', 'Ύ', 'ύ', 'ϋ', 'ΰ', 'Ή', 'ή');
  165. $b = array('A', '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', 'Α', 'α', 'Ε', 'ε', 'Ο', 'ο', 'Ω', 'ω', 'Ι', 'ι', 'ι', 'ι', 'Υ', 'υ', 'υ', 'υ', 'Η', 'η');
  166. return str_replace($a, $b, $str);
  167. }
  168.  
  169. function valid_between($value, $start, $end)
  170. {
  171. return ($value >= $start && $value <= $end);
  172. }
  173.  
  174. function now()
  175. {
  176. return date('Y-m-d H:i:s');
  177. }
  178.  
  179. function date_now()
  180. {
  181. return date('Y-m-d');
  182. }
  183.  
  184. // function for debugin var
  185. function p($s)
  186. {
  187. if(!is_string($s))
  188. {
  189. echo "<pre>";
  190. print_r($s);
  191. echo "</pre>";
  192. }
  193. else
  194. {
  195. echo nl2br($s);
  196. }
  197. }
  198.  
  199. function months($m)
  200. {
  201. $months = array(
  202. 0 => 'smarch',
  203. 1 => 'enero',
  204. 2 => 'febrero',
  205. 3 => 'marzo',
  206. 4 => 'abril',
  207. 5 => 'mayo',
  208. 6 => 'junio',
  209. 7 => 'julio',
  210. 8 => 'agosto',
  211. 9 => 'septiembre',
  212. 10 => 'octubre',
  213. 11 => 'noviembre',
  214. 12 => 'diciembre'
  215. );
  216.  
  217. return $months[(int)$m];
  218. }
  219.  
  220. function weekdays() {
  221. $days = array(
  222. 1 => 'Lunes',
  223. 2 => 'Martes',
  224. 3 => 'Miércoles',
  225. 4 => 'Jueves',
  226. 5 => 'Viernes',
  227. 6 => 'Sábado',
  228. 7 => 'Domingo'
  229. );
  230.  
  231. return $days;
  232. }
  233.  
  234. function date_short_text($f)
  235. {
  236. if (strlen($f)) {
  237. $f = explode(' ', $f);
  238. $f = explode('-', $f[0]);
  239. return $f[2] . " " . substr(months($f[1]), 0, 3) . ". " . $f[0];
  240. }
  241.  
  242. return 'Fecha no definida.';
  243. }
  244.  
  245. function date_text($f, $dName = true)
  246. {
  247. if (strlen($f)) {
  248. $dayName = '';
  249.  
  250. $days = weekdays();
  251.  
  252. $d = date('N', strtotime($f));
  253. $f = explode(' ', $f);
  254. $f = explode('-', $f[0]);
  255.  
  256. if($dName) $dayName = $days[ $d ] . ", ";
  257.  
  258. return $dayName . $f[2] . " de " . months($f[1]) . " de " . $f[0];
  259. }
  260.  
  261. return 'Fecha no definida.';
  262. }
  263.  
  264. function date_month_year($f)
  265. {
  266. if (strlen($f)) {
  267. $f = explode(' ', $f);
  268. $f = explode('-', $f[0]);
  269.  
  270. return months($f[1]) . " " . $f[0];
  271. }
  272.  
  273. return 'Fecha no definida.';
  274. }
  275.  
  276. function date_in_words($f){
  277. if (strlen($f)) {
  278. $f = explode(' ', $f);
  279. $f = explode('-', $f[0]);
  280.  
  281. $tDays = number_to_letters($f[2]);
  282. $text1 = " a los ";
  283. $text2 = " días ";
  284.  
  285. if ($f[2] == 1) {
  286. $text1 = " a un";
  287. $text2 = " día ";
  288. }
  289.  
  290. $finalText = strtolower($text1 . $tDays . $text2 . " del mes de " . months($f[1]) . " del año " . number_to_letters($f[0]));
  291.  
  292. return $finalText;
  293. }
  294. }
  295.  
  296. function number_to_letters($number){
  297. return \NumeroALetras::convertir((int)$number);
  298. }
  299. ?>
Add Comment
Please, Sign In to add comment