@@ -43,7 +43,7 @@ discard block |
||
| 43 | 43 | } |
| 44 | 44 | |
| 45 | 45 | |
| 46 | - // filtros Email |
|
| 46 | + // filtros Email |
|
| 47 | 47 | |
| 48 | 48 | function filtroEmail($email){ |
| 49 | 49 | if (!filter_input(INPUT_POST, $email, FILTER_VALIDATE_EMAIL)){ |
@@ -109,7 +109,7 @@ discard block |
||
| 109 | 109 | //texto |
| 110 | 110 | public function filtrarEntero($int){ |
| 111 | 111 | |
| 112 | - return filter_var($int, FILTER_VALIDATE_INT); |
|
| 112 | + return filter_var($int, FILTER_VALIDATE_INT); |
|
| 113 | 113 | |
| 114 | 114 | } |
| 115 | 115 | |
@@ -48,8 +48,7 @@ |
||
| 48 | 48 | function filtroEmail($email){ |
| 49 | 49 | if (!filter_input(INPUT_POST, $email, FILTER_VALIDATE_EMAIL)){ |
| 50 | 50 | echo "E-Mail no es valido"; |
| 51 | - } |
|
| 52 | - else |
|
| 51 | + } else |
|
| 53 | 52 | { |
| 54 | 53 | echo "E-Mail es valido"; |
| 55 | 54 | } |
@@ -26,100 +26,100 @@ |
||
| 26 | 26 | namespace Sistema\Ayudantes; |
| 27 | 27 | |
| 28 | 28 | class CFPHPCache { |
| 29 | - /** |
|
| 30 | - * Configuracion |
|
| 31 | - * |
|
| 32 | - * @access public |
|
| 33 | - */ |
|
| 34 | - public static $configuracion = array( |
|
| 35 | - 'cache_dir' => 'cache', |
|
| 36 | - // por defecto el tiempo expira en *minutos* |
|
| 37 | - 'expires' => 180, |
|
| 38 | - ); |
|
| 29 | + /** |
|
| 30 | + * Configuracion |
|
| 31 | + * |
|
| 32 | + * @access public |
|
| 33 | + */ |
|
| 34 | + public static $configuracion = array( |
|
| 35 | + 'cache_dir' => 'cache', |
|
| 36 | + // por defecto el tiempo expira en *minutos* |
|
| 37 | + 'expires' => 180, |
|
| 38 | + ); |
|
| 39 | 39 | |
| 40 | - public static function configurar($clave, $valor = null) { |
|
| 41 | - if( is_array($clave) ) { |
|
| 42 | - foreach ($clave as $config_name => $config_value) { |
|
| 43 | - self::$configuracion[$config_name] = $config_value; |
|
| 44 | - } |
|
| 45 | - } else { |
|
| 46 | - self::$configuracion[$clave] = $valor; |
|
| 47 | - } |
|
| 48 | - } |
|
| 49 | - /** |
|
| 50 | - * obtiene la ruta del archivo asociado a la clave. |
|
| 51 | - * |
|
| 52 | - * @access public |
|
| 53 | - * @param string $clave |
|
| 54 | - * @return string el nombre del archivo php |
|
| 55 | - */ |
|
| 56 | - public static function obtenerRuta($clave) { |
|
| 57 | - return static::$configuracion['cache_path'] . '/' . md5($clave) . '.php'; |
|
| 58 | - } |
|
| 59 | - /** |
|
| 60 | - * obtiene los datos asociados a la clave |
|
| 61 | - * |
|
| 62 | - * @access public |
|
| 63 | - * @param string $clave |
|
| 64 | - */ |
|
| 65 | - public static function obtener($clave, $raw = false, $tiempo_personalizado = null) { |
|
| 66 | - if( ! self::file_expired($archivo = self::obtenerRuta($clave), $tiempo_personalizado)) { |
|
| 67 | - $contenido = file_get_contents($archivo); |
|
| 68 | - return $raw ? $contenido : unserialize($contenido); |
|
| 69 | - } |
|
| 70 | - return null; |
|
| 71 | - } |
|
| 72 | - /** |
|
| 73 | - * Envia el contenido dentro de la cache |
|
| 74 | - * |
|
| 75 | - * @access public |
|
| 76 | - * @param string $clave |
|
| 77 | - * @param mixed $content the the content you want to store |
|
| 78 | - * @param bool $raw whether if you want to store raw data or not. If it is true, $content *must* be a string |
|
| 79 | - * It can be useful for static html caching. |
|
| 80 | - * @return bool whether if the operation was successful or not |
|
| 81 | - */ |
|
| 82 | - public static function enviar($clave, $contenido, $raw = false) { |
|
| 83 | - return @file_put_contents(self::obtenerRuta($clave), $raw ? $contenido : serialize($contenido)) !== false; |
|
| 84 | - } |
|
| 85 | - /** |
|
| 86 | - * Delete data from cache |
|
| 87 | - * |
|
| 88 | - * @access public |
|
| 89 | - * @param string $clave |
|
| 90 | - * @return bool true if the data was removed successfully |
|
| 91 | - */ |
|
| 92 | - public static function eliminar($clave) { |
|
| 93 | - if( ! file_exists($archivo = self::obtenerRuta($clave)) ) { |
|
| 94 | - return true; |
|
| 95 | - } |
|
| 96 | - return @unlink($archivo); |
|
| 97 | - } |
|
| 98 | - /** |
|
| 99 | - * limpia la cache |
|
| 100 | - * |
|
| 101 | - * @access public |
|
| 102 | - * @return bool always true |
|
| 103 | - */ |
|
| 104 | - public static function limpiar() { |
|
| 105 | - $cache_files = glob(self::$configuracion['cache_path'] . '/*.php', GLOB_NOSORT); |
|
| 106 | - foreach ($cache_files as $archivo) { |
|
| 107 | - @unlink($archivo); |
|
| 108 | - } |
|
| 109 | - return true; |
|
| 110 | - } |
|
| 111 | - /** |
|
| 112 | - * Check if a file has expired or not. |
|
| 113 | - * |
|
| 114 | - * @access public |
|
| 115 | - * @param $archivo the rout to the file |
|
| 116 | - * @param int $fecha the number of minutes it was set to expire |
|
| 117 | - * @return bool if the file has expired or not |
|
| 118 | - */ |
|
| 119 | - public static function file_expired($archivo, $fecha = null) { |
|
| 120 | - if( ! file_exists($archivo) ) { |
|
| 121 | - return true; |
|
| 122 | - } |
|
| 123 | - return (time() > (filemtime($archivo) + 60 * ($fecha ? $fecha : self::$configuracion['expires']))); |
|
| 124 | - } |
|
| 40 | + public static function configurar($clave, $valor = null) { |
|
| 41 | + if( is_array($clave) ) { |
|
| 42 | + foreach ($clave as $config_name => $config_value) { |
|
| 43 | + self::$configuracion[$config_name] = $config_value; |
|
| 44 | + } |
|
| 45 | + } else { |
|
| 46 | + self::$configuracion[$clave] = $valor; |
|
| 47 | + } |
|
| 48 | + } |
|
| 49 | + /** |
|
| 50 | + * obtiene la ruta del archivo asociado a la clave. |
|
| 51 | + * |
|
| 52 | + * @access public |
|
| 53 | + * @param string $clave |
|
| 54 | + * @return string el nombre del archivo php |
|
| 55 | + */ |
|
| 56 | + public static function obtenerRuta($clave) { |
|
| 57 | + return static::$configuracion['cache_path'] . '/' . md5($clave) . '.php'; |
|
| 58 | + } |
|
| 59 | + /** |
|
| 60 | + * obtiene los datos asociados a la clave |
|
| 61 | + * |
|
| 62 | + * @access public |
|
| 63 | + * @param string $clave |
|
| 64 | + */ |
|
| 65 | + public static function obtener($clave, $raw = false, $tiempo_personalizado = null) { |
|
| 66 | + if( ! self::file_expired($archivo = self::obtenerRuta($clave), $tiempo_personalizado)) { |
|
| 67 | + $contenido = file_get_contents($archivo); |
|
| 68 | + return $raw ? $contenido : unserialize($contenido); |
|
| 69 | + } |
|
| 70 | + return null; |
|
| 71 | + } |
|
| 72 | + /** |
|
| 73 | + * Envia el contenido dentro de la cache |
|
| 74 | + * |
|
| 75 | + * @access public |
|
| 76 | + * @param string $clave |
|
| 77 | + * @param mixed $content the the content you want to store |
|
| 78 | + * @param bool $raw whether if you want to store raw data or not. If it is true, $content *must* be a string |
|
| 79 | + * It can be useful for static html caching. |
|
| 80 | + * @return bool whether if the operation was successful or not |
|
| 81 | + */ |
|
| 82 | + public static function enviar($clave, $contenido, $raw = false) { |
|
| 83 | + return @file_put_contents(self::obtenerRuta($clave), $raw ? $contenido : serialize($contenido)) !== false; |
|
| 84 | + } |
|
| 85 | + /** |
|
| 86 | + * Delete data from cache |
|
| 87 | + * |
|
| 88 | + * @access public |
|
| 89 | + * @param string $clave |
|
| 90 | + * @return bool true if the data was removed successfully |
|
| 91 | + */ |
|
| 92 | + public static function eliminar($clave) { |
|
| 93 | + if( ! file_exists($archivo = self::obtenerRuta($clave)) ) { |
|
| 94 | + return true; |
|
| 95 | + } |
|
| 96 | + return @unlink($archivo); |
|
| 97 | + } |
|
| 98 | + /** |
|
| 99 | + * limpia la cache |
|
| 100 | + * |
|
| 101 | + * @access public |
|
| 102 | + * @return bool always true |
|
| 103 | + */ |
|
| 104 | + public static function limpiar() { |
|
| 105 | + $cache_files = glob(self::$configuracion['cache_path'] . '/*.php', GLOB_NOSORT); |
|
| 106 | + foreach ($cache_files as $archivo) { |
|
| 107 | + @unlink($archivo); |
|
| 108 | + } |
|
| 109 | + return true; |
|
| 110 | + } |
|
| 111 | + /** |
|
| 112 | + * Check if a file has expired or not. |
|
| 113 | + * |
|
| 114 | + * @access public |
|
| 115 | + * @param $archivo the rout to the file |
|
| 116 | + * @param int $fecha the number of minutes it was set to expire |
|
| 117 | + * @return bool if the file has expired or not |
|
| 118 | + */ |
|
| 119 | + public static function file_expired($archivo, $fecha = null) { |
|
| 120 | + if( ! file_exists($archivo) ) { |
|
| 121 | + return true; |
|
| 122 | + } |
|
| 123 | + return (time() > (filemtime($archivo) + 60 * ($fecha ? $fecha : self::$configuracion['expires']))); |
|
| 124 | + } |
|
| 125 | 125 | } |
@@ -25,26 +25,26 @@ discard block |
||
| 25 | 25 | |
| 26 | 26 | // se agradece a ArrayZone por el aporte de esta clase |
| 27 | 27 | |
| 28 | - /** |
|
| 29 | - * @name Form Generator for Kernel Web |
|
| 30 | - * @version A.1.0 |
|
| 31 | - * @copyright ArrayZone 2014 |
|
| 32 | - * @license AZPL or later; see License.txt or http://arrayzone.com/license |
|
| 33 | - * @category plugin |
|
| 34 | - * |
|
| 35 | - * Description: This script write a FORM HTML automatically from array (it will be generated trhoug functions). |
|
| 36 | - * It write any type of items basics of HTML4 and some of HTML5. |
|
| 37 | - * Once user clic "submit", all information will be validated via PHP |
|
| 38 | - * Some types like "required" and "email" validated trhough PHP to avoid problems with navigator compatibilities or hacker attacks |
|
| 39 | - * |
|
| 40 | - * NEXT VERSION: If you can use JavaScript and have JQuery implemented, the form can write JavaScript code to validate all |
|
| 41 | - * Read the documentation for all information in kernel.arrayzone.com |
|
| 42 | - * or all coments of all parameters and functions. |
|
| 43 | - * |
|
| 44 | - * IMPORTANT: If you use a specific system to get POST and GET, you have to edit "private function getData()" |
|
| 45 | - * IMPORTANT 2: If you use DISABLE, control it manually when you save it |
|
| 46 | - * IMPORTANT 3: Currently aren't supported array names (name="MyField[]"), you can use: name="MyField_1" |
|
| 47 | - */ |
|
| 28 | + /** |
|
| 29 | + * @name Form Generator for Kernel Web |
|
| 30 | + * @version A.1.0 |
|
| 31 | + * @copyright ArrayZone 2014 |
|
| 32 | + * @license AZPL or later; see License.txt or http://arrayzone.com/license |
|
| 33 | + * @category plugin |
|
| 34 | + * |
|
| 35 | + * Description: This script write a FORM HTML automatically from array (it will be generated trhoug functions). |
|
| 36 | + * It write any type of items basics of HTML4 and some of HTML5. |
|
| 37 | + * Once user clic "submit", all information will be validated via PHP |
|
| 38 | + * Some types like "required" and "email" validated trhough PHP to avoid problems with navigator compatibilities or hacker attacks |
|
| 39 | + * |
|
| 40 | + * NEXT VERSION: If you can use JavaScript and have JQuery implemented, the form can write JavaScript code to validate all |
|
| 41 | + * Read the documentation for all information in kernel.arrayzone.com |
|
| 42 | + * or all coments of all parameters and functions. |
|
| 43 | + * |
|
| 44 | + * IMPORTANT: If you use a specific system to get POST and GET, you have to edit "private function getData()" |
|
| 45 | + * IMPORTANT 2: If you use DISABLE, control it manually when you save it |
|
| 46 | + * IMPORTANT 3: Currently aren't supported array names (name="MyField[]"), you can use: name="MyField_1" |
|
| 47 | + */ |
|
| 48 | 48 | |
| 49 | 49 | |
| 50 | 50 | |
@@ -52,855 +52,855 @@ discard block |
||
| 52 | 52 | |
| 53 | 53 | class CFPHPFormularios |
| 54 | 54 | { |
| 55 | - /* |
|
| 55 | + /* |
|
| 56 | 56 | * Form configuration. It don't need description |
| 57 | 57 | */ |
| 58 | - public $method = 'post'; // post / get (CAUTION!!: Case sensitive) |
|
| 59 | - public $action = ''; |
|
| 60 | - public $name = ''; |
|
| 61 | - public $on_submit = ''; |
|
| 62 | - public $id = ''; |
|
| 63 | - public $class = ''; |
|
| 64 | - |
|
| 65 | - /** |
|
| 66 | - * Logging control |
|
| 67 | - * @logErrors boolean If is true, $errors will store errors |
|
| 68 | - * @errors string Contain al errors |
|
| 69 | - */ |
|
| 70 | - public $logErrors = true; |
|
| 71 | - public $errors = ''; |
|
| 72 | - |
|
| 73 | - /* |
|
| 58 | + public $method = 'post'; // post / get (CAUTION!!: Case sensitive) |
|
| 59 | + public $action = ''; |
|
| 60 | + public $name = ''; |
|
| 61 | + public $on_submit = ''; |
|
| 62 | + public $id = ''; |
|
| 63 | + public $class = ''; |
|
| 64 | + |
|
| 65 | + /** |
|
| 66 | + * Logging control |
|
| 67 | + * @logErrors boolean If is true, $errors will store errors |
|
| 68 | + * @errors string Contain al errors |
|
| 69 | + */ |
|
| 70 | + public $logErrors = true; |
|
| 71 | + public $errors = ''; |
|
| 72 | + |
|
| 73 | + /* |
|
| 74 | 74 | * Other configurations about form |
| 75 | 75 | */ |
| 76 | 76 | |
| 77 | - /** |
|
| 78 | - * @show_labels boolean |
|
| 79 | - * @tutorial If is true, it show label text of some inputs before input tag |
|
| 80 | - */ |
|
| 81 | - public $show_labels = true; |
|
| 77 | + /** |
|
| 78 | + * @show_labels boolean |
|
| 79 | + * @tutorial If is true, it show label text of some inputs before input tag |
|
| 80 | + */ |
|
| 81 | + public $show_labels = true; |
|
| 82 | 82 | |
| 83 | - /** IN DEVELOPMENT |
|
| 84 | - * @self_show boolean |
|
| 85 | - * @tutorial if is true, it show the input when function addX is called |
|
| 86 | - */ |
|
| 87 | - //public $self_show = false; |
|
| 83 | + /** IN DEVELOPMENT |
|
| 84 | + * @self_show boolean |
|
| 85 | + * @tutorial if is true, it show the input when function addX is called |
|
| 86 | + */ |
|
| 87 | + //public $self_show = false; |
|
| 88 | 88 | |
| 89 | 89 | |
| 90 | - /** IN DEVELOPMENT |
|
| 91 | - * @only_show boolean |
|
| 92 | - * @tutorial If is true, it don't save the configuration to input (so showForm() and validateData() don't work) |
|
| 93 | - */ |
|
| 94 | - //public $only_show = false; |
|
| 90 | + /** IN DEVELOPMENT |
|
| 91 | + * @only_show boolean |
|
| 92 | + * @tutorial If is true, it don't save the configuration to input (so showForm() and validateData() don't work) |
|
| 93 | + */ |
|
| 94 | + //public $only_show = false; |
|
| 95 | 95 | |
| 96 | 96 | |
| 97 | - /* |
|
| 97 | + /* |
|
| 98 | 98 | * Content |
| 99 | 99 | * It can be set manually or automatically trhough functions |
| 100 | 100 | */ |
| 101 | - public $content = array(); |
|
| 101 | + public $content = array(); |
|
| 102 | 102 | |
| 103 | 103 | /* |
| 104 | 104 | * Start functions |
| 105 | 105 | */ |
| 106 | 106 | |
| 107 | - /** |
|
| 108 | - * @name showArray |
|
| 109 | - * @tutorial This function show array result, it can be copied and you can replace all generator functions to this array |
|
| 110 | - * @example $fg->showArray(); |
|
| 111 | - */ |
|
| 112 | - public function showArray($array = false) { |
|
| 113 | - print_r($this->content); |
|
| 114 | - } |
|
| 115 | - |
|
| 116 | - |
|
| 117 | - /** |
|
| 118 | - * @name showForm |
|
| 119 | - * @tutorial This function generate the form |
|
| 120 | - * @example $fg->showForm(); |
|
| 121 | - */ |
|
| 122 | - public function showForm() { |
|
| 123 | - // Loading all arrays |
|
| 124 | - $toShow = $this->content; |
|
| 125 | - |
|
| 126 | - // Showing form |
|
| 127 | - echo $this->showStartForm(); |
|
| 128 | - |
|
| 129 | - |
|
| 130 | - // Itearate all inputs |
|
| 131 | - foreach ($toShow as $input) { |
|
| 132 | - // Reading data |
|
| 133 | - if (isset($input['data'])) $data = $input['data']; |
|
| 107 | + /** |
|
| 108 | + * @name showArray |
|
| 109 | + * @tutorial This function show array result, it can be copied and you can replace all generator functions to this array |
|
| 110 | + * @example $fg->showArray(); |
|
| 111 | + */ |
|
| 112 | + public function showArray($array = false) { |
|
| 113 | + print_r($this->content); |
|
| 114 | + } |
|
| 115 | + |
|
| 116 | + |
|
| 117 | + /** |
|
| 118 | + * @name showForm |
|
| 119 | + * @tutorial This function generate the form |
|
| 120 | + * @example $fg->showForm(); |
|
| 121 | + */ |
|
| 122 | + public function showForm() { |
|
| 123 | + // Loading all arrays |
|
| 124 | + $toShow = $this->content; |
|
| 125 | + |
|
| 126 | + // Showing form |
|
| 127 | + echo $this->showStartForm(); |
|
| 128 | + |
|
| 129 | + |
|
| 130 | + // Itearate all inputs |
|
| 131 | + foreach ($toShow as $input) { |
|
| 132 | + // Reading data |
|
| 133 | + if (isset($input['data'])) $data = $input['data']; |
|
| 134 | 134 | |
| 135 | - // New row |
|
| 136 | - echo '<div>'; |
|
| 137 | - // Showing labels |
|
| 138 | - if ($this->show_labels) { |
|
| 139 | - echo '<div>'; |
|
| 140 | - if (isset($input['label']) and $input['label'] != '') echo $input['label']; |
|
| 141 | - echo '</div>'; |
|
| 142 | - } |
|
| 135 | + // New row |
|
| 136 | + echo '<div>'; |
|
| 137 | + // Showing labels |
|
| 138 | + if ($this->show_labels) { |
|
| 139 | + echo '<div>'; |
|
| 140 | + if (isset($input['label']) and $input['label'] != '') echo $input['label']; |
|
| 141 | + echo '</div>'; |
|
| 142 | + } |
|
| 143 | 143 | |
| 144 | - // Showing content |
|
| 145 | - echo '<div>'; |
|
| 146 | - switch ($input['type']) { |
|
| 147 | - case 'input': |
|
| 148 | - echo $this->showInput($data); |
|
| 149 | - break; |
|
| 150 | - case 'radio': |
|
| 151 | - echo $this->showRadio($data, $input['values'], $input['selected']); |
|
| 152 | - break; |
|
| 153 | - case 'select'; |
|
| 154 | - echo $this->showSelect($data, $input['values'], $input['selected']); |
|
| 155 | - break; |
|
| 156 | - case 'textarea': |
|
| 157 | - echo $this->showTextArea($input['text'], $data); |
|
| 158 | - break; |
|
| 159 | - case 'separator'; |
|
| 160 | - echo '<br />'; |
|
| 161 | - break; |
|
| 162 | - } |
|
| 163 | - echo '</div>'; |
|
| 164 | - echo '</div>'.PHP_EOL; |
|
| 165 | - } |
|
| 166 | - |
|
| 167 | - // Closing form |
|
| 168 | - echo $this->showEndForm(); |
|
| 169 | - } |
|
| 170 | - |
|
| 171 | - |
|
| 172 | - /* |
|
| 144 | + // Showing content |
|
| 145 | + echo '<div>'; |
|
| 146 | + switch ($input['type']) { |
|
| 147 | + case 'input': |
|
| 148 | + echo $this->showInput($data); |
|
| 149 | + break; |
|
| 150 | + case 'radio': |
|
| 151 | + echo $this->showRadio($data, $input['values'], $input['selected']); |
|
| 152 | + break; |
|
| 153 | + case 'select'; |
|
| 154 | + echo $this->showSelect($data, $input['values'], $input['selected']); |
|
| 155 | + break; |
|
| 156 | + case 'textarea': |
|
| 157 | + echo $this->showTextArea($input['text'], $data); |
|
| 158 | + break; |
|
| 159 | + case 'separator'; |
|
| 160 | + echo '<br />'; |
|
| 161 | + break; |
|
| 162 | + } |
|
| 163 | + echo '</div>'; |
|
| 164 | + echo '</div>'.PHP_EOL; |
|
| 165 | + } |
|
| 166 | + |
|
| 167 | + // Closing form |
|
| 168 | + echo $this->showEndForm(); |
|
| 169 | + } |
|
| 170 | + |
|
| 171 | + |
|
| 172 | + /* |
|
| 173 | 173 | * The following "showX" functions are autoloaded and show the different parts of form |
| 174 | 174 | */ |
| 175 | 175 | |
| 176 | - /** |
|
| 177 | - * @name showInput |
|
| 178 | - * @tutorial This function show <input> tag with parameters specifics |
|
| 179 | - * @param array $data All data to show in the input |
|
| 180 | - * @return string |
|
| 181 | - */ |
|
| 182 | - private function showInput($data) { |
|
| 183 | - $r = ''; |
|
| 184 | - // Number start if is range |
|
| 185 | - if ($data['type'] == 'range' and isset($data['min'])) $r .= $data['min'] . ' '; |
|
| 176 | + /** |
|
| 177 | + * @name showInput |
|
| 178 | + * @tutorial This function show <input> tag with parameters specifics |
|
| 179 | + * @param array $data All data to show in the input |
|
| 180 | + * @return string |
|
| 181 | + */ |
|
| 182 | + private function showInput($data) { |
|
| 183 | + $r = ''; |
|
| 184 | + // Number start if is range |
|
| 185 | + if ($data['type'] == 'range' and isset($data['min'])) $r .= $data['min'] . ' '; |
|
| 186 | 186 | |
| 187 | - $r .= '<input '; |
|
| 187 | + $r .= '<input '; |
|
| 188 | 188 | |
| 189 | - // Reading value sended by user, if are any, we load it temporaly to show in form |
|
| 190 | - $data['value'] = $this->getData($data['name'], $data['value']); |
|
| 189 | + // Reading value sended by user, if are any, we load it temporaly to show in form |
|
| 190 | + $data['value'] = $this->getData($data['name'], $data['value']); |
|
| 191 | 191 | |
| 192 | - // Asignamos las claves conviritiendo el array |
|
| 193 | - foreach ($data as $attr=>$value) { |
|
| 194 | - $r .= $attr.'="'.$value.'" '; |
|
| 195 | - } |
|
| 192 | + // Asignamos las claves conviritiendo el array |
|
| 193 | + foreach ($data as $attr=>$value) { |
|
| 194 | + $r .= $attr.'="'.$value.'" '; |
|
| 195 | + } |
|
| 196 | 196 | |
| 197 | - $r .= '/>'; |
|
| 197 | + $r .= '/>'; |
|
| 198 | 198 | |
| 199 | - // Number end if is range |
|
| 200 | - if ($data['type'] == 'range' and isset($data['max'])) $r .= $data['max'] . ' '; |
|
| 199 | + // Number end if is range |
|
| 200 | + if ($data['type'] == 'range' and isset($data['max'])) $r .= $data['max'] . ' '; |
|
| 201 | 201 | |
| 202 | - // Return |
|
| 203 | - return $r; |
|
| 204 | - } |
|
| 202 | + // Return |
|
| 203 | + return $r; |
|
| 204 | + } |
|
| 205 | 205 | |
| 206 | - private function showRadio($data, $values, $selected) { |
|
| 207 | - // Primero generamos un esquema |
|
| 208 | - $base = '<label><input type="radio"'; |
|
| 206 | + private function showRadio($data, $values, $selected) { |
|
| 207 | + // Primero generamos un esquema |
|
| 208 | + $base = '<label><input type="radio"'; |
|
| 209 | 209 | |
| 210 | - // Asignamos las claves conviritiendo el array |
|
| 211 | - foreach ($data as $attr=>$value) { |
|
| 212 | - $base .= $attr.'="'.$value.'" '; |
|
| 213 | - } |
|
| 210 | + // Asignamos las claves conviritiendo el array |
|
| 211 | + foreach ($data as $attr=>$value) { |
|
| 212 | + $base .= $attr.'="'.$value.'" '; |
|
| 213 | + } |
|
| 214 | 214 | |
| 215 | 215 | |
| 216 | - // Leemos el valor enviado por el usuario (si lo hay) y si hay, reemplazamos $select por el valor |
|
| 217 | - $selected = $this->getData($data['name'], $selected); |
|
| 216 | + // Leemos el valor enviado por el usuario (si lo hay) y si hay, reemplazamos $select por el valor |
|
| 217 | + $selected = $this->getData($data['name'], $selected); |
|
| 218 | 218 | |
| 219 | - //echo $sendValue; |
|
| 220 | - // Si no tiene m�ltiples valores (es un string), lo retornamos de golpe |
|
| 221 | - if (!is_array($values)) { |
|
| 222 | - // Comprobamos el value, es posible que el usuario este intentando crear los Radio (option) de forma separada |
|
| 223 | - if (!is_array($values) and $selected == $values) $base .= ' checked="checked" '; |
|
| 224 | - return $base . ' value="'.$values.'" />'; |
|
| 225 | - } |
|
| 219 | + //echo $sendValue; |
|
| 220 | + // Si no tiene m�ltiples valores (es un string), lo retornamos de golpe |
|
| 221 | + if (!is_array($values)) { |
|
| 222 | + // Comprobamos el value, es posible que el usuario este intentando crear los Radio (option) de forma separada |
|
| 223 | + if (!is_array($values) and $selected == $values) $base .= ' checked="checked" '; |
|
| 224 | + return $base . ' value="'.$values.'" />'; |
|
| 225 | + } |
|
| 226 | 226 | |
| 227 | - // Por el contrario, tenemos 1 o m�s value con lo que es un posible texto |
|
| 228 | - // Ahora preparamos todos los input |
|
| 229 | - $r = ''; |
|
| 230 | - foreach ($values as $id=>$text) { |
|
| 231 | - $r .= $base; |
|
| 232 | - if ($selected !== null and $id == $selected) $r .= ' checked="checked" '; |
|
| 233 | - $r .= ' value="'. $id .'" />'.$text.'</label>'; |
|
| 234 | - } |
|
| 235 | - |
|
| 236 | - return $r; |
|
| 237 | - |
|
| 238 | - } |
|
| 239 | - |
|
| 240 | - /** |
|
| 241 | - * @name showSelect |
|
| 242 | - * @tutorial This function show <select> tag with all values |
|
| 243 | - * @param array $data All data to show in the input |
|
| 244 | - * @param array $values Values to show in select |
|
| 245 | - * @param string $selected Specify selected option |
|
| 246 | - * @return string |
|
| 247 | - */ |
|
| 248 | - private function showSelect($data, $values, $selected = null) { |
|
| 249 | - $r = '<select '; |
|
| 250 | - // Convert array to input string |
|
| 251 | - foreach ($data as $attr=>$value) { |
|
| 252 | - $r .= $attr.'="'.$value.'" '; |
|
| 253 | - } |
|
| 254 | - // Return end input |
|
| 255 | - $r .= '>'; |
|
| 256 | - |
|
| 257 | - // Leemos el valor enviado por el usuario (si lo hay) y si hay, reemplazamos $select por el valor |
|
| 258 | - $selected = $this->getData($data['name'], $selected); |
|
| 259 | - |
|
| 260 | - |
|
| 261 | - // Loading options |
|
| 262 | - // To speed up processes, we have two whiles depending if are any selected value |
|
| 263 | - if ($selected != '') { |
|
| 264 | - foreach ($values as $val=>$txt) { |
|
| 265 | - $r .= '<option value="' . $val . '"'; |
|
| 266 | - if ($val == $selected) $r .= ' selected '; |
|
| 267 | - $r .= '>' . $txt . '</option>'; |
|
| 268 | - } |
|
| 269 | - } else { |
|
| 270 | - foreach ($values as $val=>$txt) { |
|
| 271 | - $r .= '<option value="' . $val . '">' . $txt . '</option>'; |
|
| 272 | - } |
|
| 273 | - } |
|
| 274 | - |
|
| 275 | - return $r . '</select>'; |
|
| 276 | - } |
|
| 277 | - |
|
| 278 | - /** |
|
| 279 | - * @name showTextArea |
|
| 280 | - * @tutorial This function show <textarea> tag with all values |
|
| 281 | - * @param array $data All data to show in the input |
|
| 282 | - * @return string |
|
| 283 | - */ |
|
| 284 | - private function showTextArea($text, $data) { |
|
| 285 | - $r = ''; |
|
| 286 | - $r .= '<textarea '; |
|
| 287 | - |
|
| 288 | - // Asignamos las claves conviritiendo el array |
|
| 289 | - foreach ($data as $attr=>$value) { |
|
| 290 | - $r .= $attr.'="'.$value.'" '; |
|
| 291 | - } |
|
| 292 | - |
|
| 293 | - $r .= '>'; |
|
| 294 | - // Reading value sended by user, if are any, we load it temporaly to show in form |
|
| 295 | - $r .= $this->getData($data['name'], $text) . '</textarea>'; |
|
| 227 | + // Por el contrario, tenemos 1 o m�s value con lo que es un posible texto |
|
| 228 | + // Ahora preparamos todos los input |
|
| 229 | + $r = ''; |
|
| 230 | + foreach ($values as $id=>$text) { |
|
| 231 | + $r .= $base; |
|
| 232 | + if ($selected !== null and $id == $selected) $r .= ' checked="checked" '; |
|
| 233 | + $r .= ' value="'. $id .'" />'.$text.'</label>'; |
|
| 234 | + } |
|
| 235 | + |
|
| 236 | + return $r; |
|
| 237 | + |
|
| 238 | + } |
|
| 239 | + |
|
| 240 | + /** |
|
| 241 | + * @name showSelect |
|
| 242 | + * @tutorial This function show <select> tag with all values |
|
| 243 | + * @param array $data All data to show in the input |
|
| 244 | + * @param array $values Values to show in select |
|
| 245 | + * @param string $selected Specify selected option |
|
| 246 | + * @return string |
|
| 247 | + */ |
|
| 248 | + private function showSelect($data, $values, $selected = null) { |
|
| 249 | + $r = '<select '; |
|
| 250 | + // Convert array to input string |
|
| 251 | + foreach ($data as $attr=>$value) { |
|
| 252 | + $r .= $attr.'="'.$value.'" '; |
|
| 253 | + } |
|
| 254 | + // Return end input |
|
| 255 | + $r .= '>'; |
|
| 256 | + |
|
| 257 | + // Leemos el valor enviado por el usuario (si lo hay) y si hay, reemplazamos $select por el valor |
|
| 258 | + $selected = $this->getData($data['name'], $selected); |
|
| 259 | + |
|
| 260 | + |
|
| 261 | + // Loading options |
|
| 262 | + // To speed up processes, we have two whiles depending if are any selected value |
|
| 263 | + if ($selected != '') { |
|
| 264 | + foreach ($values as $val=>$txt) { |
|
| 265 | + $r .= '<option value="' . $val . '"'; |
|
| 266 | + if ($val == $selected) $r .= ' selected '; |
|
| 267 | + $r .= '>' . $txt . '</option>'; |
|
| 268 | + } |
|
| 269 | + } else { |
|
| 270 | + foreach ($values as $val=>$txt) { |
|
| 271 | + $r .= '<option value="' . $val . '">' . $txt . '</option>'; |
|
| 272 | + } |
|
| 273 | + } |
|
| 274 | + |
|
| 275 | + return $r . '</select>'; |
|
| 276 | + } |
|
| 277 | + |
|
| 278 | + /** |
|
| 279 | + * @name showTextArea |
|
| 280 | + * @tutorial This function show <textarea> tag with all values |
|
| 281 | + * @param array $data All data to show in the input |
|
| 282 | + * @return string |
|
| 283 | + */ |
|
| 284 | + private function showTextArea($text, $data) { |
|
| 285 | + $r = ''; |
|
| 286 | + $r .= '<textarea '; |
|
| 287 | + |
|
| 288 | + // Asignamos las claves conviritiendo el array |
|
| 289 | + foreach ($data as $attr=>$value) { |
|
| 290 | + $r .= $attr.'="'.$value.'" '; |
|
| 291 | + } |
|
| 292 | + |
|
| 293 | + $r .= '>'; |
|
| 294 | + // Reading value sended by user, if are any, we load it temporaly to show in form |
|
| 295 | + $r .= $this->getData($data['name'], $text) . '</textarea>'; |
|
| 296 | 296 | |
| 297 | - // Return |
|
| 298 | - return $r; |
|
| 299 | - } |
|
| 300 | - |
|
| 301 | - /** |
|
| 302 | - * @name showStartForm This function return the start part of the form |
|
| 303 | - * @return string |
|
| 304 | - */ |
|
| 305 | - private function showStartForm() { |
|
| 306 | - $r = '<form '; |
|
| 307 | - if ($this->action!= '') $r .= 'action="'.$this->action.'" '; |
|
| 308 | - if ($this->method != '') $r .= 'method="'.$this->method .'" '; |
|
| 309 | - if ($this->name != '') $r .= 'name="'.$this->name .'" '; |
|
| 310 | - if ($this->on_submit != '') $r .= 'onSubmit="'.$this->on_submit .'" '; |
|
| 311 | - if ($this->id != '') $r .= 'id="'.$this->id .'" '; |
|
| 312 | - if ($this->class != '') $r .= 'class="'.$this->class .'" '; |
|
| 313 | - |
|
| 314 | - return $r . '>'.PHP_EOL; |
|
| 315 | - } |
|
| 316 | - |
|
| 317 | - /** |
|
| 318 | - * @name showEndForm This show the end of the form |
|
| 319 | - * @return string |
|
| 320 | - */ |
|
| 321 | - private function showEndForm() { |
|
| 322 | - return '</form>'; |
|
| 323 | - } |
|
| 324 | - |
|
| 325 | - |
|
| 326 | - /* |
|
| 297 | + // Return |
|
| 298 | + return $r; |
|
| 299 | + } |
|
| 300 | + |
|
| 301 | + /** |
|
| 302 | + * @name showStartForm This function return the start part of the form |
|
| 303 | + * @return string |
|
| 304 | + */ |
|
| 305 | + private function showStartForm() { |
|
| 306 | + $r = '<form '; |
|
| 307 | + if ($this->action!= '') $r .= 'action="'.$this->action.'" '; |
|
| 308 | + if ($this->method != '') $r .= 'method="'.$this->method .'" '; |
|
| 309 | + if ($this->name != '') $r .= 'name="'.$this->name .'" '; |
|
| 310 | + if ($this->on_submit != '') $r .= 'onSubmit="'.$this->on_submit .'" '; |
|
| 311 | + if ($this->id != '') $r .= 'id="'.$this->id .'" '; |
|
| 312 | + if ($this->class != '') $r .= 'class="'.$this->class .'" '; |
|
| 313 | + |
|
| 314 | + return $r . '>'.PHP_EOL; |
|
| 315 | + } |
|
| 316 | + |
|
| 317 | + /** |
|
| 318 | + * @name showEndForm This show the end of the form |
|
| 319 | + * @return string |
|
| 320 | + */ |
|
| 321 | + private function showEndForm() { |
|
| 322 | + return '</form>'; |
|
| 323 | + } |
|
| 324 | + |
|
| 325 | + |
|
| 326 | + /* |
|
| 327 | 327 | * VALIDATORS |
| 328 | 328 | */ |
| 329 | - /** |
|
| 330 | - * @name validate |
|
| 331 | - * @tutorial this function validate items sends trhough form. It DON'T FILTER |
|
| 332 | - * Basically simulate HTML5 trhoguh PHP for full compatibility |
|
| 333 | - * @param boolean $error_list If is true, it generate in $this->error_list a list with data required |
|
| 334 | - */ |
|
| 335 | - public function validate() { |
|
| 336 | - $this->error_list = ''; // Clean error list |
|
| 337 | - $total = 0; // Total counted params |
|
| 338 | - $success = 0; // Total correct |
|
| 339 | - |
|
| 340 | - // load all inputs |
|
| 341 | - $params = $this->content; |
|
| 342 | - |
|
| 343 | - // reading all inputs |
|
| 344 | - foreach ($params as $param) { |
|
| 345 | - ++$total; |
|
| 329 | + /** |
|
| 330 | + * @name validate |
|
| 331 | + * @tutorial this function validate items sends trhough form. It DON'T FILTER |
|
| 332 | + * Basically simulate HTML5 trhoguh PHP for full compatibility |
|
| 333 | + * @param boolean $error_list If is true, it generate in $this->error_list a list with data required |
|
| 334 | + */ |
|
| 335 | + public function validate() { |
|
| 336 | + $this->error_list = ''; // Clean error list |
|
| 337 | + $total = 0; // Total counted params |
|
| 338 | + $success = 0; // Total correct |
|
| 339 | + |
|
| 340 | + // load all inputs |
|
| 341 | + $params = $this->content; |
|
| 342 | + |
|
| 343 | + // reading all inputs |
|
| 344 | + foreach ($params as $param) { |
|
| 345 | + ++$total; |
|
| 346 | 346 | |
| 347 | - // Skip separators and bad generated arrays |
|
| 348 | - if (!isset($param['data'])) { |
|
| 349 | - ++$success; |
|
| 350 | - continue; |
|
| 351 | - } |
|
| 347 | + // Skip separators and bad generated arrays |
|
| 348 | + if (!isset($param['data'])) { |
|
| 349 | + ++$success; |
|
| 350 | + continue; |
|
| 351 | + } |
|
| 352 | 352 | |
| 353 | - // Start validation |
|
| 354 | - $data = $param['data']; |
|
| 353 | + // Start validation |
|
| 354 | + $data = $param['data']; |
|
| 355 | 355 | |
| 356 | - // Checking type input |
|
| 357 | - switch ($param['type']) { |
|
| 356 | + // Checking type input |
|
| 357 | + switch ($param['type']) { |
|
| 358 | 358 | |
| 359 | - case 'input': |
|
| 360 | - $success += $this->validateInput($param['data']); |
|
| 361 | - break; |
|
| 362 | - case 'radio': |
|
| 363 | - $success += $this->validateRadio($param); |
|
| 364 | - break; |
|
| 365 | - case 'select': |
|
| 366 | - $success += $this->validateSelect($param); |
|
| 367 | - break; |
|
| 368 | - default: |
|
| 369 | - $success++; |
|
| 370 | - } |
|
| 371 | - } |
|
| 372 | - |
|
| 373 | - if ($success >= $total) return true; |
|
| 374 | - return false; |
|
| 375 | - } |
|
| 376 | - |
|
| 377 | - /** |
|
| 378 | - * @name validateInput |
|
| 379 | - * @tutorial This function test if an input (text, password, checkbox, ...) is valid depending assigned values |
|
| 380 | - * If you need other that is not invented, you can use "pattern" for example |
|
| 381 | - * It checks: |
|
| 382 | - * - required |
|
| 383 | - * - date |
|
| 384 | - * - min |
|
| 385 | - * - max |
|
| 386 | - * - number |
|
| 387 | - * @param array $data Contains all information about input |
|
| 388 | - * @return boolean If return true, its okay |
|
| 389 | - */ |
|
| 390 | - private function validateInput($data) { |
|
| 391 | - // Obtaining value send by user |
|
| 392 | - $readValue = $this->getData($data['name']); |
|
| 359 | + case 'input': |
|
| 360 | + $success += $this->validateInput($param['data']); |
|
| 361 | + break; |
|
| 362 | + case 'radio': |
|
| 363 | + $success += $this->validateRadio($param); |
|
| 364 | + break; |
|
| 365 | + case 'select': |
|
| 366 | + $success += $this->validateSelect($param); |
|
| 367 | + break; |
|
| 368 | + default: |
|
| 369 | + $success++; |
|
| 370 | + } |
|
| 371 | + } |
|
| 372 | + |
|
| 373 | + if ($success >= $total) return true; |
|
| 374 | + return false; |
|
| 375 | + } |
|
| 376 | + |
|
| 377 | + /** |
|
| 378 | + * @name validateInput |
|
| 379 | + * @tutorial This function test if an input (text, password, checkbox, ...) is valid depending assigned values |
|
| 380 | + * If you need other that is not invented, you can use "pattern" for example |
|
| 381 | + * It checks: |
|
| 382 | + * - required |
|
| 383 | + * - date |
|
| 384 | + * - min |
|
| 385 | + * - max |
|
| 386 | + * - number |
|
| 387 | + * @param array $data Contains all information about input |
|
| 388 | + * @return boolean If return true, its okay |
|
| 389 | + */ |
|
| 390 | + private function validateInput($data) { |
|
| 391 | + // Obtaining value send by user |
|
| 392 | + $readValue = $this->getData($data['name']); |
|
| 393 | 393 | |
| 394 | - // Empty/not send and required? |
|
| 395 | - // TODO: Add require --> file (uses $_FILE) |
|
| 396 | - |
|
| 397 | - if (isset($data['required']) and ($readValue === null or $readValue == '')) { |
|
| 398 | - $this->log('is required', $data); |
|
| 399 | - return false; |
|
| 400 | - } elseif ($readValue == '') { |
|
| 401 | - return true; |
|
| 402 | - } |
|
| 403 | - |
|
| 404 | - // Checking type input |
|
| 405 | - switch ($data['type']) { |
|
| 406 | - case 'text': |
|
| 407 | - // Maxlenght fail |
|
| 408 | - if (isset($data['maxlength']) and is_numeric($data['maxlength']) and $data['maxlength'] > -1 |
|
| 409 | - and strlen($readValue) > $data['maxlength']) { |
|
| 394 | + // Empty/not send and required? |
|
| 395 | + // TODO: Add require --> file (uses $_FILE) |
|
| 396 | + |
|
| 397 | + if (isset($data['required']) and ($readValue === null or $readValue == '')) { |
|
| 398 | + $this->log('is required', $data); |
|
| 399 | + return false; |
|
| 400 | + } elseif ($readValue == '') { |
|
| 401 | + return true; |
|
| 402 | + } |
|
| 403 | + |
|
| 404 | + // Checking type input |
|
| 405 | + switch ($data['type']) { |
|
| 406 | + case 'text': |
|
| 407 | + // Maxlenght fail |
|
| 408 | + if (isset($data['maxlength']) and is_numeric($data['maxlength']) and $data['maxlength'] > -1 |
|
| 409 | + and strlen($readValue) > $data['maxlength']) { |
|
| 410 | 410 | |
| 411 | - $this->log('is too long. Maximum' . ' ' . $data['maxlength'] . ' ' . 'characters', $data ); |
|
| 412 | - return false; |
|
| 413 | - } |
|
| 411 | + $this->log('is too long. Maximum' . ' ' . $data['maxlength'] . ' ' . 'characters', $data ); |
|
| 412 | + return false; |
|
| 413 | + } |
|
| 414 | 414 | |
| 415 | - if (isset($data['pattern']) and is_numeric($data['pattern']) and $data['maxlength'] != '' |
|
| 416 | - and preg_match($data['pattern'], $readValue) === FALSE) { |
|
| 415 | + if (isset($data['pattern']) and is_numeric($data['pattern']) and $data['maxlength'] != '' |
|
| 416 | + and preg_match($data['pattern'], $readValue) === FALSE) { |
|
| 417 | 417 | |
| 418 | - $this->log('pattern error' . ' (' . $data['pattern'] . ')' , $data); |
|
| 419 | - return false; |
|
| 420 | - } |
|
| 421 | - break; |
|
| 422 | - case 'number': |
|
| 423 | - case 'range': |
|
| 424 | - // IS NUMERIC |
|
| 425 | - if ($readValue != '' and !is_numeric($readValue)) { |
|
| 426 | - $this->log('Not numeric', $data); |
|
| 427 | - return false; |
|
| 428 | - } |
|
| 418 | + $this->log('pattern error' . ' (' . $data['pattern'] . ')' , $data); |
|
| 419 | + return false; |
|
| 420 | + } |
|
| 421 | + break; |
|
| 422 | + case 'number': |
|
| 423 | + case 'range': |
|
| 424 | + // IS NUMERIC |
|
| 425 | + if ($readValue != '' and !is_numeric($readValue)) { |
|
| 426 | + $this->log('Not numeric', $data); |
|
| 427 | + return false; |
|
| 428 | + } |
|
| 429 | 429 | |
| 430 | - // MIN |
|
| 431 | - if (isset($data['min']) and $readValue < $data['min']) { |
|
| 432 | - $this->log('The number have to be greather than' . ' ' . $data['min'].'.', $data); |
|
| 433 | - return false; |
|
| 434 | - } |
|
| 430 | + // MIN |
|
| 431 | + if (isset($data['min']) and $readValue < $data['min']) { |
|
| 432 | + $this->log('The number have to be greather than' . ' ' . $data['min'].'.', $data); |
|
| 433 | + return false; |
|
| 434 | + } |
|
| 435 | 435 | |
| 436 | - // MAX |
|
| 437 | - if (isset($data['max']) and $readValue > $data['max']) { |
|
| 438 | - $this->log('The number have to be less than' . ' ' . $data['max'].'.', $data); |
|
| 439 | - return false; |
|
| 440 | - } |
|
| 436 | + // MAX |
|
| 437 | + if (isset($data['max']) and $readValue > $data['max']) { |
|
| 438 | + $this->log('The number have to be less than' . ' ' . $data['max'].'.', $data); |
|
| 439 | + return false; |
|
| 440 | + } |
|
| 441 | 441 | |
| 442 | - // STEP http://www.w3schools.com/tags/att_input_step.asp |
|
| 443 | - // Value 0 ever is valid (and if you try Divide to Zero, it will take error because the result is inifinite |
|
| 444 | - if (isset($data['step']) and $readValue != 0 and $readValue % $data['step'] !== 0) { |
|
| 445 | - $this->log('The number have to be multiple of' . ' ' . $data['step'].'.', $data); |
|
| 446 | - return false; |
|
| 447 | - } |
|
| 442 | + // STEP http://www.w3schools.com/tags/att_input_step.asp |
|
| 443 | + // Value 0 ever is valid (and if you try Divide to Zero, it will take error because the result is inifinite |
|
| 444 | + if (isset($data['step']) and $readValue != 0 and $readValue % $data['step'] !== 0) { |
|
| 445 | + $this->log('The number have to be multiple of' . ' ' . $data['step'].'.', $data); |
|
| 446 | + return false; |
|
| 447 | + } |
|
| 448 | 448 | |
| 449 | - break; |
|
| 450 | - case 'date'; |
|
| 451 | - //min | max |
|
| 452 | - echo $readValue; |
|
| 453 | - if (!is_date($readValue)) { |
|
| 454 | - $this->log('The date' . ' ' .$readValue.' '. 'must have format' . ' mm/dd/yyyy '.'.', $data); |
|
| 455 | - return false; |
|
| 456 | - } |
|
| 457 | - break; |
|
| 449 | + break; |
|
| 450 | + case 'date'; |
|
| 451 | + //min | max |
|
| 452 | + echo $readValue; |
|
| 453 | + if (!is_date($readValue)) { |
|
| 454 | + $this->log('The date' . ' ' .$readValue.' '. 'must have format' . ' mm/dd/yyyy '.'.', $data); |
|
| 455 | + return false; |
|
| 456 | + } |
|
| 457 | + break; |
|
| 458 | 458 | |
| 459 | - case 'email': |
|
| 460 | - if (!filter_var($readValue, FILTER_VALIDATE_EMAIL)) { |
|
| 461 | - $this->log('Email invalid', $data); |
|
| 462 | - return false; |
|
| 463 | - } |
|
| 464 | - case 'file': |
|
| 465 | - //accept="image/*" (http://www.w3schools.com/tags/att_input_accept.asp) |
|
| 466 | - break; |
|
| 459 | + case 'email': |
|
| 460 | + if (!filter_var($readValue, FILTER_VALIDATE_EMAIL)) { |
|
| 461 | + $this->log('Email invalid', $data); |
|
| 462 | + return false; |
|
| 463 | + } |
|
| 464 | + case 'file': |
|
| 465 | + //accept="image/*" (http://www.w3schools.com/tags/att_input_accept.asp) |
|
| 466 | + break; |
|
| 467 | 467 | |
| 468 | - case 'url': |
|
| 469 | - if (!filter_var($readValue, FILTER_VALIDATE_URL)) { |
|
| 470 | - $this->log('Invalid url', $data); |
|
| 471 | - return false; |
|
| 472 | - } |
|
| 473 | - break; |
|
| 474 | - } |
|
| 475 | - // Validamos el resto como cierto (no podemos parametrizar el 100 % de cosas nuevas que salgan de HTML) |
|
| 476 | - return true; |
|
| 477 | - } |
|
| 478 | - |
|
| 479 | - /** |
|
| 480 | - * @name validateArray |
|
| 481 | - * This functions validate an Array, is a complement to validateRadio, select... |
|
| 482 | - * @param array/string $values List of values to validate |
|
| 483 | - * @param array/string $value/s selecteds by user |
|
| 484 | - */ |
|
| 485 | - private function validateArray($values, $value, $data = array()) { |
|
| 486 | - if (is_array($values)) { |
|
| 487 | - // Is array (serach all "$value" in "$values" |
|
| 488 | - if (!array_key_exists($value, $values)) { |
|
| 489 | - if (is_array($value)) { |
|
| 490 | - $this->log('Values don\'t match.', $data); |
|
| 491 | - } else { |
|
| 492 | - $this->log('ID ' .$value.' ' . 'don\'t match', $data); |
|
| 493 | - } |
|
| 494 | - return false; |
|
| 495 | - } |
|
| 496 | - } else { |
|
| 497 | - // Is string |
|
| 498 | - if ($readValue == $values) { |
|
| 499 | - $this->log('The value' . ' ' . $value.' ' . 'is not available', $data); |
|
| 500 | - return false; |
|
| 501 | - } |
|
| 502 | - } |
|
| 503 | - |
|
| 504 | - return true; |
|
| 505 | - } |
|
| 506 | - |
|
| 507 | - |
|
| 508 | - /** |
|
| 509 | - * @name validateRadio |
|
| 510 | - * @tutorial This function test if an radio is valid depending assigned values |
|
| 511 | - * @param array $data Contains all information about input |
|
| 512 | - * @return boolean If return true, its okay |
|
| 513 | - */ |
|
| 514 | - private function validateRadio($params) { |
|
| 515 | - $data = $params['data']; |
|
| 516 | - // Obtaining value send by user |
|
| 517 | - $readValue = $this->getData($data['name']); |
|
| 518 | - |
|
| 519 | - // Is required? |
|
| 520 | - if (isset($data['required']) and ($readValue === null or $readValue == '')) { |
|
| 521 | - $this->log('is required', $data); |
|
| 522 | - return false; |
|
| 523 | - } elseif ($readValue == '') { |
|
| 524 | - return true; |
|
| 525 | - } |
|
| 526 | - |
|
| 527 | - |
|
| 528 | - // Seleccionamos que tipo de analisis (dependiendo si se ha creado como input o como radio) |
|
| 529 | - // Esto no deberia estar aqui porque no es necesario, pero esta hecho por posibles despistes de usuarios finales |
|
| 530 | - if (isset($params['values'])) { |
|
| 531 | - return $this->validateArray($params['values'], $readValue, $data); |
|
| 532 | - } elseif ($data['value']) { |
|
| 533 | - // If user try to add radio like normal input... (into 'value' in index data) |
|
| 534 | - return $this->validateArray($params['value'], $readValue, $data); |
|
| 535 | - } |
|
| 536 | - |
|
| 537 | - return false; |
|
| 538 | - } |
|
| 539 | - |
|
| 540 | - /** |
|
| 541 | - * @name validateSelect |
|
| 542 | - * @tutorial This function test if an select is valid depending assigned values |
|
| 543 | - * @param array $data Contains all information about input |
|
| 544 | - * @return boolean If return true, its okay |
|
| 545 | - */ |
|
| 546 | - private function validateSelect($param) { |
|
| 547 | - $data = $param['data']; |
|
| 548 | - // Obtaining value send by user |
|
| 549 | - $readValue = $this->getData($data['name']); |
|
| 550 | - |
|
| 551 | - // Is required? |
|
| 552 | - if (isset($data['required']) and ($readValue === null or $readValue == '')) { |
|
| 553 | - $this->log('is required', $data); |
|
| 554 | - return false; |
|
| 555 | - } elseif ($readValue == '') { |
|
| 556 | - return true; |
|
| 557 | - } |
|
| 558 | - |
|
| 559 | - // Seleccionamos que tipo de analisis (dependiendo si se ha creado como input o como radio) |
|
| 560 | - // Esto no deberia estar aqui porque no es necesario, pero esta hecho por posibles despistes de usuarios finales |
|
| 561 | - return $this->validateArray($param['values'], $readValue, $data); |
|
| 562 | - } |
|
| 563 | - |
|
| 564 | - |
|
| 565 | - /** |
|
| 566 | - * @name getData This function get value from POST/GET trhough ID ($key) |
|
| 567 | - * If you use other system to load GET and POST, you have to edit this |
|
| 568 | - * @param string $key Object Index |
|
| 569 | - * @param string $default Default item if not data |
|
| 570 | - * @return string/null Return the value, if don't exist, return null |
|
| 571 | - */ |
|
| 572 | - private function getData($key, $default = null) { |
|
| 573 | - if ($this->method == "post") return isset($_POST[$key]) ? $_POST[$key] : $default; |
|
| 574 | - else return isset($_GET[$key]) ? $_GET[$key] : $default; |
|
| 575 | - } |
|
| 576 | - |
|
| 577 | - /* |
|
| 468 | + case 'url': |
|
| 469 | + if (!filter_var($readValue, FILTER_VALIDATE_URL)) { |
|
| 470 | + $this->log('Invalid url', $data); |
|
| 471 | + return false; |
|
| 472 | + } |
|
| 473 | + break; |
|
| 474 | + } |
|
| 475 | + // Validamos el resto como cierto (no podemos parametrizar el 100 % de cosas nuevas que salgan de HTML) |
|
| 476 | + return true; |
|
| 477 | + } |
|
| 478 | + |
|
| 479 | + /** |
|
| 480 | + * @name validateArray |
|
| 481 | + * This functions validate an Array, is a complement to validateRadio, select... |
|
| 482 | + * @param array/string $values List of values to validate |
|
| 483 | + * @param array/string $value/s selecteds by user |
|
| 484 | + */ |
|
| 485 | + private function validateArray($values, $value, $data = array()) { |
|
| 486 | + if (is_array($values)) { |
|
| 487 | + // Is array (serach all "$value" in "$values" |
|
| 488 | + if (!array_key_exists($value, $values)) { |
|
| 489 | + if (is_array($value)) { |
|
| 490 | + $this->log('Values don\'t match.', $data); |
|
| 491 | + } else { |
|
| 492 | + $this->log('ID ' .$value.' ' . 'don\'t match', $data); |
|
| 493 | + } |
|
| 494 | + return false; |
|
| 495 | + } |
|
| 496 | + } else { |
|
| 497 | + // Is string |
|
| 498 | + if ($readValue == $values) { |
|
| 499 | + $this->log('The value' . ' ' . $value.' ' . 'is not available', $data); |
|
| 500 | + return false; |
|
| 501 | + } |
|
| 502 | + } |
|
| 503 | + |
|
| 504 | + return true; |
|
| 505 | + } |
|
| 506 | + |
|
| 507 | + |
|
| 508 | + /** |
|
| 509 | + * @name validateRadio |
|
| 510 | + * @tutorial This function test if an radio is valid depending assigned values |
|
| 511 | + * @param array $data Contains all information about input |
|
| 512 | + * @return boolean If return true, its okay |
|
| 513 | + */ |
|
| 514 | + private function validateRadio($params) { |
|
| 515 | + $data = $params['data']; |
|
| 516 | + // Obtaining value send by user |
|
| 517 | + $readValue = $this->getData($data['name']); |
|
| 518 | + |
|
| 519 | + // Is required? |
|
| 520 | + if (isset($data['required']) and ($readValue === null or $readValue == '')) { |
|
| 521 | + $this->log('is required', $data); |
|
| 522 | + return false; |
|
| 523 | + } elseif ($readValue == '') { |
|
| 524 | + return true; |
|
| 525 | + } |
|
| 526 | + |
|
| 527 | + |
|
| 528 | + // Seleccionamos que tipo de analisis (dependiendo si se ha creado como input o como radio) |
|
| 529 | + // Esto no deberia estar aqui porque no es necesario, pero esta hecho por posibles despistes de usuarios finales |
|
| 530 | + if (isset($params['values'])) { |
|
| 531 | + return $this->validateArray($params['values'], $readValue, $data); |
|
| 532 | + } elseif ($data['value']) { |
|
| 533 | + // If user try to add radio like normal input... (into 'value' in index data) |
|
| 534 | + return $this->validateArray($params['value'], $readValue, $data); |
|
| 535 | + } |
|
| 536 | + |
|
| 537 | + return false; |
|
| 538 | + } |
|
| 539 | + |
|
| 540 | + /** |
|
| 541 | + * @name validateSelect |
|
| 542 | + * @tutorial This function test if an select is valid depending assigned values |
|
| 543 | + * @param array $data Contains all information about input |
|
| 544 | + * @return boolean If return true, its okay |
|
| 545 | + */ |
|
| 546 | + private function validateSelect($param) { |
|
| 547 | + $data = $param['data']; |
|
| 548 | + // Obtaining value send by user |
|
| 549 | + $readValue = $this->getData($data['name']); |
|
| 550 | + |
|
| 551 | + // Is required? |
|
| 552 | + if (isset($data['required']) and ($readValue === null or $readValue == '')) { |
|
| 553 | + $this->log('is required', $data); |
|
| 554 | + return false; |
|
| 555 | + } elseif ($readValue == '') { |
|
| 556 | + return true; |
|
| 557 | + } |
|
| 558 | + |
|
| 559 | + // Seleccionamos que tipo de analisis (dependiendo si se ha creado como input o como radio) |
|
| 560 | + // Esto no deberia estar aqui porque no es necesario, pero esta hecho por posibles despistes de usuarios finales |
|
| 561 | + return $this->validateArray($param['values'], $readValue, $data); |
|
| 562 | + } |
|
| 563 | + |
|
| 564 | + |
|
| 565 | + /** |
|
| 566 | + * @name getData This function get value from POST/GET trhough ID ($key) |
|
| 567 | + * If you use other system to load GET and POST, you have to edit this |
|
| 568 | + * @param string $key Object Index |
|
| 569 | + * @param string $default Default item if not data |
|
| 570 | + * @return string/null Return the value, if don't exist, return null |
|
| 571 | + */ |
|
| 572 | + private function getData($key, $default = null) { |
|
| 573 | + if ($this->method == "post") return isset($_POST[$key]) ? $_POST[$key] : $default; |
|
| 574 | + else return isset($_GET[$key]) ? $_GET[$key] : $default; |
|
| 575 | + } |
|
| 576 | + |
|
| 577 | + /* |
|
| 578 | 578 | * Array constructors |
| 579 | 579 | * This functions will be called to self construct array easy |
| 580 | 580 | */ |
| 581 | 581 | |
| 582 | - /** |
|
| 583 | - * @name separator |
|
| 584 | - * @tutorial This function add separation (<hr/>) between parts |
|
| 585 | - */ |
|
| 586 | - public function addSeparator() { |
|
| 587 | - $this->content[] = array('type' => 'separator'); |
|
| 588 | - } |
|
| 589 | - |
|
| 590 | - /** |
|
| 591 | - * @name addInput |
|
| 592 | - * @tutorial This class generate a generic INPUT |
|
| 593 | - * @param string $label If is not empty, it show a text "label" with the text |
|
| 594 | - * @param string $type Specify input type. It will be validated once use validate(); |
|
| 595 | - * Types that are current supported to validate: |
|
| 596 | - * text, password, hidden, file |
|
| 597 | - * Its supported use ALL type supported (http://www.w3schools.com/tags/att_input_type.asp), |
|
| 598 | - * Some type input you can declare directly via functions (afther this function are more) |
|
| 599 | - * @param string $name Element name |
|
| 600 | - * @param string $value Element value |
|
| 601 | - * @param string $required Element required? |
|
| 602 | - * @param array $attributes Optional atributes not listened (in array). |
|
| 603 | - * EX: You like use "date", then you can put array('min' => '1979-12-31', 'max' => '2000-01-02') |
|
| 604 | - * All parameters currently working: min, max (date and number), pattern, |
|
| 605 | - * |
|
| 606 | - * @example $fr->addInput('text', 'Username', '', true, 'Type here your username', array('class'=>'text red', id => 'text1'), array()) |
|
| 607 | - */ |
|
| 608 | - public function addInput($label = '', $type = 'text', $name = '', $value = '', $required = false, $placeholder = '', $attributes = array()) { |
|
| 609 | - // Creating main data |
|
| 610 | - $data = array( |
|
| 611 | - 'type' => $type, |
|
| 612 | - 'name' => $name, |
|
| 613 | - 'value' => $value, |
|
| 614 | - ); |
|
| 615 | - |
|
| 616 | - |
|
| 617 | - if ($required) $data['required'] = 'required'; |
|
| 618 | - if ($placeholder != '') $data['placeholder'] = $placeholder; |
|
| 619 | - if (!empty($attributes)) array_merge($data, $attributes); |
|
| 620 | - |
|
| 621 | - |
|
| 622 | - // Saving data to object |
|
| 623 | - $content = array( |
|
| 624 | - 'type' => 'input', |
|
| 625 | - 'data' => $data |
|
| 626 | - ); |
|
| 627 | - if ($label != '') $content['label'] = $label; |
|
| 582 | + /** |
|
| 583 | + * @name separator |
|
| 584 | + * @tutorial This function add separation (<hr/>) between parts |
|
| 585 | + */ |
|
| 586 | + public function addSeparator() { |
|
| 587 | + $this->content[] = array('type' => 'separator'); |
|
| 588 | + } |
|
| 589 | + |
|
| 590 | + /** |
|
| 591 | + * @name addInput |
|
| 592 | + * @tutorial This class generate a generic INPUT |
|
| 593 | + * @param string $label If is not empty, it show a text "label" with the text |
|
| 594 | + * @param string $type Specify input type. It will be validated once use validate(); |
|
| 595 | + * Types that are current supported to validate: |
|
| 596 | + * text, password, hidden, file |
|
| 597 | + * Its supported use ALL type supported (http://www.w3schools.com/tags/att_input_type.asp), |
|
| 598 | + * Some type input you can declare directly via functions (afther this function are more) |
|
| 599 | + * @param string $name Element name |
|
| 600 | + * @param string $value Element value |
|
| 601 | + * @param string $required Element required? |
|
| 602 | + * @param array $attributes Optional atributes not listened (in array). |
|
| 603 | + * EX: You like use "date", then you can put array('min' => '1979-12-31', 'max' => '2000-01-02') |
|
| 604 | + * All parameters currently working: min, max (date and number), pattern, |
|
| 605 | + * |
|
| 606 | + * @example $fr->addInput('text', 'Username', '', true, 'Type here your username', array('class'=>'text red', id => 'text1'), array()) |
|
| 607 | + */ |
|
| 608 | + public function addInput($label = '', $type = 'text', $name = '', $value = '', $required = false, $placeholder = '', $attributes = array()) { |
|
| 609 | + // Creating main data |
|
| 610 | + $data = array( |
|
| 611 | + 'type' => $type, |
|
| 612 | + 'name' => $name, |
|
| 613 | + 'value' => $value, |
|
| 614 | + ); |
|
| 615 | + |
|
| 616 | + |
|
| 617 | + if ($required) $data['required'] = 'required'; |
|
| 618 | + if ($placeholder != '') $data['placeholder'] = $placeholder; |
|
| 619 | + if (!empty($attributes)) array_merge($data, $attributes); |
|
| 620 | + |
|
| 621 | + |
|
| 622 | + // Saving data to object |
|
| 623 | + $content = array( |
|
| 624 | + 'type' => 'input', |
|
| 625 | + 'data' => $data |
|
| 626 | + ); |
|
| 627 | + if ($label != '') $content['label'] = $label; |
|
| 628 | 628 | |
| 629 | - $this->content[] = $content; |
|
| 630 | - } |
|
| 631 | - |
|
| 632 | - /** |
|
| 633 | - * @name addNumber This function add input "number" and "date" with min, max and step (if you like) |
|
| 634 | - * @param string $label If is not empty, it show a text "label" with the text |
|
| 635 | - * @param string $name Element name |
|
| 636 | - * @param string $value Default value |
|
| 637 | - * @param boolen $range If is true, then show "range" instead of text with number |
|
| 638 | - * @param boolen $required Is required? |
|
| 639 | - * @param number $min Minium value. Empty nothing |
|
| 640 | - * @param number $max Max value. Empty nothing |
|
| 641 | - * @param number $step Step (multiply). Empty nothing (ex: step 2: -2, 0, 2, 4 ...) |
|
| 642 | - * @param string $placeholder Default text to show if box is empty |
|
| 643 | - * @param unknown $attributes Additional attributes |
|
| 644 | - */ |
|
| 645 | - public function addNumber($label = '', $name = '', $value = '', $range = false, $required = false, $min = '', $max = '', $step = '', $placeholder = '', $attributes = array()) { |
|
| 646 | - // Creating main data |
|
| 647 | - $data = array( |
|
| 648 | - 'type' => (! $range) ? 'number' : 'range', |
|
| 649 | - 'name' => $name, |
|
| 650 | - 'value' => $value, |
|
| 651 | - ); |
|
| 652 | - |
|
| 653 | - |
|
| 654 | - if ($required) $data['required'] = 'required'; |
|
| 655 | - if ($min) $data['min'] = $min; |
|
| 656 | - if ($max) $data['max'] = $max; |
|
| 657 | - if ($step) $data['step'] = $step; |
|
| 658 | - if ($placeholder != '') $data['placeholder'] = $placeholder; |
|
| 659 | - if (!empty($attributes)) array_merge($data, $attributes); |
|
| 660 | - |
|
| 661 | - // Saving data to object |
|
| 662 | - $content = array( |
|
| 663 | - 'type' => 'input', |
|
| 664 | - 'data' => $data |
|
| 665 | - ); |
|
| 666 | - if ($label != '') $content['label'] = $label; |
|
| 667 | - |
|
| 668 | - $this->content[] = $content; |
|
| 669 | - } |
|
| 629 | + $this->content[] = $content; |
|
| 630 | + } |
|
| 631 | + |
|
| 632 | + /** |
|
| 633 | + * @name addNumber This function add input "number" and "date" with min, max and step (if you like) |
|
| 634 | + * @param string $label If is not empty, it show a text "label" with the text |
|
| 635 | + * @param string $name Element name |
|
| 636 | + * @param string $value Default value |
|
| 637 | + * @param boolen $range If is true, then show "range" instead of text with number |
|
| 638 | + * @param boolen $required Is required? |
|
| 639 | + * @param number $min Minium value. Empty nothing |
|
| 640 | + * @param number $max Max value. Empty nothing |
|
| 641 | + * @param number $step Step (multiply). Empty nothing (ex: step 2: -2, 0, 2, 4 ...) |
|
| 642 | + * @param string $placeholder Default text to show if box is empty |
|
| 643 | + * @param unknown $attributes Additional attributes |
|
| 644 | + */ |
|
| 645 | + public function addNumber($label = '', $name = '', $value = '', $range = false, $required = false, $min = '', $max = '', $step = '', $placeholder = '', $attributes = array()) { |
|
| 646 | + // Creating main data |
|
| 647 | + $data = array( |
|
| 648 | + 'type' => (! $range) ? 'number' : 'range', |
|
| 649 | + 'name' => $name, |
|
| 650 | + 'value' => $value, |
|
| 651 | + ); |
|
| 652 | + |
|
| 653 | + |
|
| 654 | + if ($required) $data['required'] = 'required'; |
|
| 655 | + if ($min) $data['min'] = $min; |
|
| 656 | + if ($max) $data['max'] = $max; |
|
| 657 | + if ($step) $data['step'] = $step; |
|
| 658 | + if ($placeholder != '') $data['placeholder'] = $placeholder; |
|
| 659 | + if (!empty($attributes)) array_merge($data, $attributes); |
|
| 660 | + |
|
| 661 | + // Saving data to object |
|
| 662 | + $content = array( |
|
| 663 | + 'type' => 'input', |
|
| 664 | + 'data' => $data |
|
| 665 | + ); |
|
| 666 | + if ($label != '') $content['label'] = $label; |
|
| 667 | + |
|
| 668 | + $this->content[] = $content; |
|
| 669 | + } |
|
| 670 | 670 | |
| 671 | - /** |
|
| 672 | - * @name addDate This function add input "number" with min, max and step (if you like) |
|
| 673 | - * @param string $label If is not empty, it show a text "label" with the text |
|
| 674 | - * @param string $name Element name |
|
| 675 | - * @param string $value Default value |
|
| 676 | - * @param string $required Is required? |
|
| 677 | - * @param string $min Minium value. Empty nothing |
|
| 678 | - * @param string $max Max value. Empty nothing |
|
| 679 | - * @param string $step Step (multiply). Empty nothing (ex: step 2: -2, 0, 2, 4 ...) |
|
| 680 | - * @param string $placeholder Default text to show if box is empty |
|
| 681 | - * @param unknown $attributes Additional attributes |
|
| 682 | - */ |
|
| 683 | - public function addDate($label = '', $name = '', $value = '', $required = false, $min = '', $max = '', $step = '', $placeholder = '', $attributes = array()) { |
|
| 684 | - // Creating main data |
|
| 685 | - $data = array( |
|
| 686 | - 'type' => 'date', |
|
| 687 | - 'name' => $name, |
|
| 688 | - 'value' => $value, |
|
| 689 | - ); |
|
| 690 | - |
|
| 691 | - if ($required) $data['required'] = 'required'; |
|
| 692 | - if ($min) $data['min'] = $min; |
|
| 693 | - if ($max) $data['max'] = $max; |
|
| 694 | - if ($step) $data['step'] = $step; |
|
| 695 | - if ($placeholder != '') $data['placeholder'] = $placeholder; |
|
| 696 | - if (!empty($attributes)) array_merge($data, $attributes); |
|
| 697 | - |
|
| 698 | - // Saving data to object |
|
| 699 | - $content = array( |
|
| 700 | - 'type' => 'input', |
|
| 701 | - 'data' => $data |
|
| 702 | - ); |
|
| 703 | - if ($label != '') $content['label'] = $label; |
|
| 704 | - |
|
| 705 | - $this->content[] = $content; |
|
| 706 | - } |
|
| 707 | - |
|
| 708 | - |
|
| 709 | - /** |
|
| 710 | - * @name addCheck |
|
| 711 | - * @tutorial Use this function to add a checkBox |
|
| 712 | - * @param string $label If is not empty, it show a text "label" with the text |
|
| 713 | - * @param string $name Check name |
|
| 714 | - * @param string $value Check value |
|
| 715 | - * @param boolean $required Specify if check is required |
|
| 716 | - * @param array $attributes Optional atributes not listened (in array). |
|
| 717 | - */ |
|
| 718 | - public function addCheck($label = '', $name = '', $value = '', $required = false, $attributes = array()) { |
|
| 719 | - $data = array( |
|
| 720 | - 'type' => 'checkbox', |
|
| 721 | - 'name' => $name, |
|
| 722 | - 'value' => $value |
|
| 723 | - ); |
|
| 724 | - if ($required) $data['required'] = 'required'; |
|
| 725 | - if (!empty($attributes)) array_merge($data, $attributes); |
|
| 726 | - |
|
| 727 | - $content = array( |
|
| 728 | - 'type' => 'input', |
|
| 729 | - 'data' => $data |
|
| 730 | - ); |
|
| 731 | - if ($label != '') $content['label'] = $label; |
|
| 732 | - |
|
| 733 | - $this->content[] = $content; |
|
| 734 | - } |
|
| 735 | - |
|
| 736 | - |
|
| 737 | - /** |
|
| 738 | - * @name addRadio |
|
| 739 | - * @tutorial Use this function to add a radio button |
|
| 740 | - * @param string $label If is not empty, it show a text "label" with the text |
|
| 741 | - * @param string $name Radio button name |
|
| 742 | - * @param array $values Contain all radio with values and text to show |
|
| 743 | - * EX: array('val1'=>'text1', 'val2'=>'text2'); |
|
| 744 | - * @param string $selected Specify wich option (ID) will be checked by default |
|
| 745 | - * @param boolean $required Specify if radio is required |
|
| 746 | - * @param array $attributes Optional atributes not listened (in array). This will be applicated to all radioButton |
|
| 747 | - */ |
|
| 748 | - public function addRadio($label = '', $name = '', $values = array(), $selected = null, $required = false, $attributes = array()) { |
|
| 749 | - if (!is_array($values)) die('FATAL ERROR: Trying to create "RadioButton" with string VALUE, is requried use ARRAY()'); |
|
| 750 | - $data = array( |
|
| 751 | - 'name' => $name, |
|
| 752 | - ); |
|
| 753 | - |
|
| 754 | - if ($required) $data['required'] = 'required'; |
|
| 755 | - if (!empty($attributes)) array_merge($data, $attributes); |
|
| 756 | - |
|
| 757 | - |
|
| 758 | - |
|
| 759 | - $content = array( |
|
| 760 | - 'type' => 'radio', |
|
| 761 | - 'data' => $data, |
|
| 762 | - 'values' => $values, |
|
| 763 | - 'selected' => $selected |
|
| 764 | - ); |
|
| 765 | - if ($label != '') $content['label'] = $label; |
|
| 766 | - |
|
| 767 | - $this->content[] = $content; |
|
| 768 | - } |
|
| 769 | - |
|
| 770 | - |
|
| 771 | - /** |
|
| 772 | - * @name addSelect |
|
| 773 | - * @tutorial Use this function to add a radio button |
|
| 774 | - * @param string $label Text to show before input |
|
| 775 | - * @param string $name Select name |
|
| 776 | - * @param array $values Array('value'=>'text to show') |
|
| 777 | - * @param boolean $required Specify if select is required |
|
| 778 | - * @param string $id ID Specify ID to manipulate via javascript or CSS |
|
| 779 | - * @param array $attributes Optional atributes not listened (in array). |
|
| 780 | - */ |
|
| 781 | - public function addSelect($label = '', $name = '', $values = '', $selected = null, $required = false, $multiple = false, $attributes = array()) { |
|
| 782 | - $data = array( |
|
| 783 | - 'name' => $name, |
|
| 784 | - 'required' => $required, |
|
| 785 | - ); |
|
| 786 | - if ($required) $data['required'] = 'required'; |
|
| 787 | - if ($multiple) $data['multiple'] = 'multiple'; |
|
| 788 | - if (!empty($attributes)) array_merge($data, $attributes); |
|
| 789 | - |
|
| 790 | - |
|
| 791 | - // In this case, the values are saved in the main of array to speed up select loader |
|
| 792 | - $content = array( |
|
| 793 | - 'type' => 'select', |
|
| 794 | - 'data' => $data, |
|
| 795 | - 'values' => $values, |
|
| 796 | - 'selected' => $selected |
|
| 797 | - ); |
|
| 798 | - if ($label != '') $content['label'] = $label; |
|
| 799 | - |
|
| 800 | - $this->content[] = $content; |
|
| 801 | - } |
|
| 802 | - |
|
| 803 | - /** |
|
| 804 | - * @name addSubmit |
|
| 805 | - * @tutorial Use this function to add a submit button |
|
| 806 | - * @param string $name Select name (optional, if leav blank it will not send in POST / GET) |
|
| 807 | - * @param string $value Text to show in button and ID |
|
| 808 | - * @param array $attributes Optional atributes not listened (in array). |
|
| 809 | - */ |
|
| 810 | - public function addSubmit($name = '', $value = '', $attributes = array()) { |
|
| 811 | - $data = array( |
|
| 812 | - 'type' => 'submit', |
|
| 813 | - 'name' => $name, |
|
| 814 | - 'value' => $value |
|
| 815 | - ); |
|
| 816 | - if (!empty($attributes)) array_merge($data, $attributes); |
|
| 817 | - |
|
| 818 | - $this->content[] = array( |
|
| 819 | - 'type' => 'input', |
|
| 820 | - 'data' => $data |
|
| 821 | - ); |
|
| 822 | - |
|
| 823 | - |
|
| 824 | - } |
|
| 825 | - |
|
| 826 | - /** |
|
| 827 | - * @name addButton |
|
| 828 | - * @tutorial Use this function to add a button with "onclick" action (or id/class to call via jquery) |
|
| 829 | - * @param string $value Name to show in button and ID |
|
| 830 | - * @param string $onClick Action to load when button is clicked |
|
| 831 | - * @param array $attributes Optional atributes not listened (in array). |
|
| 832 | - */ |
|
| 833 | - public function addButton($value = '', $onClick = '', $attributes = array()) { |
|
| 834 | - $data = array( |
|
| 835 | - 'type' => 'button', |
|
| 836 | - 'value' => $value, |
|
| 837 | - 'onClick' => $onClick |
|
| 838 | - ); |
|
| 839 | - if (!empty($attributes)) array_merge($data, $attributes); |
|
| 840 | - |
|
| 841 | - $this->content[] = array( |
|
| 842 | - 'type' => 'input', |
|
| 843 | - 'data' => $data |
|
| 844 | - ); |
|
| 845 | - } |
|
| 846 | - |
|
| 847 | - |
|
| 848 | - /** |
|
| 849 | - * @name addButton |
|
| 850 | - * @tutorial Use this function to add a button with "onclick" action (or id/class to call via jquery) |
|
| 851 | - * @param string $value Name to show in button and ID |
|
| 852 | - * @param string $onClick Action to load when button is clicked |
|
| 853 | - * @param array $attributes Optional atributes not listened (in array). |
|
| 854 | - */ |
|
| 855 | - public function addTextArea($label = '', $name = '', $value = '', $required = false, $attributes = array()) { |
|
| 856 | - // Creating main data |
|
| 857 | - $data = array( |
|
| 858 | - 'name' => $name, |
|
| 859 | - ); |
|
| 860 | - |
|
| 861 | - if ($required) $data['required'] = 'required'; |
|
| 862 | - if (!empty($attributes)) array_merge($data, $attributes); |
|
| 863 | - |
|
| 864 | - // Saving data to object |
|
| 865 | - $content = array( |
|
| 866 | - 'type' => 'textarea', |
|
| 867 | - 'text' => $value, |
|
| 868 | - 'data' => $data |
|
| 869 | - ); |
|
| 870 | - if ($label != '') $content['label'] = $label; |
|
| 671 | + /** |
|
| 672 | + * @name addDate This function add input "number" with min, max and step (if you like) |
|
| 673 | + * @param string $label If is not empty, it show a text "label" with the text |
|
| 674 | + * @param string $name Element name |
|
| 675 | + * @param string $value Default value |
|
| 676 | + * @param string $required Is required? |
|
| 677 | + * @param string $min Minium value. Empty nothing |
|
| 678 | + * @param string $max Max value. Empty nothing |
|
| 679 | + * @param string $step Step (multiply). Empty nothing (ex: step 2: -2, 0, 2, 4 ...) |
|
| 680 | + * @param string $placeholder Default text to show if box is empty |
|
| 681 | + * @param unknown $attributes Additional attributes |
|
| 682 | + */ |
|
| 683 | + public function addDate($label = '', $name = '', $value = '', $required = false, $min = '', $max = '', $step = '', $placeholder = '', $attributes = array()) { |
|
| 684 | + // Creating main data |
|
| 685 | + $data = array( |
|
| 686 | + 'type' => 'date', |
|
| 687 | + 'name' => $name, |
|
| 688 | + 'value' => $value, |
|
| 689 | + ); |
|
| 690 | + |
|
| 691 | + if ($required) $data['required'] = 'required'; |
|
| 692 | + if ($min) $data['min'] = $min; |
|
| 693 | + if ($max) $data['max'] = $max; |
|
| 694 | + if ($step) $data['step'] = $step; |
|
| 695 | + if ($placeholder != '') $data['placeholder'] = $placeholder; |
|
| 696 | + if (!empty($attributes)) array_merge($data, $attributes); |
|
| 697 | + |
|
| 698 | + // Saving data to object |
|
| 699 | + $content = array( |
|
| 700 | + 'type' => 'input', |
|
| 701 | + 'data' => $data |
|
| 702 | + ); |
|
| 703 | + if ($label != '') $content['label'] = $label; |
|
| 704 | + |
|
| 705 | + $this->content[] = $content; |
|
| 706 | + } |
|
| 707 | + |
|
| 708 | + |
|
| 709 | + /** |
|
| 710 | + * @name addCheck |
|
| 711 | + * @tutorial Use this function to add a checkBox |
|
| 712 | + * @param string $label If is not empty, it show a text "label" with the text |
|
| 713 | + * @param string $name Check name |
|
| 714 | + * @param string $value Check value |
|
| 715 | + * @param boolean $required Specify if check is required |
|
| 716 | + * @param array $attributes Optional atributes not listened (in array). |
|
| 717 | + */ |
|
| 718 | + public function addCheck($label = '', $name = '', $value = '', $required = false, $attributes = array()) { |
|
| 719 | + $data = array( |
|
| 720 | + 'type' => 'checkbox', |
|
| 721 | + 'name' => $name, |
|
| 722 | + 'value' => $value |
|
| 723 | + ); |
|
| 724 | + if ($required) $data['required'] = 'required'; |
|
| 725 | + if (!empty($attributes)) array_merge($data, $attributes); |
|
| 726 | + |
|
| 727 | + $content = array( |
|
| 728 | + 'type' => 'input', |
|
| 729 | + 'data' => $data |
|
| 730 | + ); |
|
| 731 | + if ($label != '') $content['label'] = $label; |
|
| 732 | + |
|
| 733 | + $this->content[] = $content; |
|
| 734 | + } |
|
| 735 | + |
|
| 736 | + |
|
| 737 | + /** |
|
| 738 | + * @name addRadio |
|
| 739 | + * @tutorial Use this function to add a radio button |
|
| 740 | + * @param string $label If is not empty, it show a text "label" with the text |
|
| 741 | + * @param string $name Radio button name |
|
| 742 | + * @param array $values Contain all radio with values and text to show |
|
| 743 | + * EX: array('val1'=>'text1', 'val2'=>'text2'); |
|
| 744 | + * @param string $selected Specify wich option (ID) will be checked by default |
|
| 745 | + * @param boolean $required Specify if radio is required |
|
| 746 | + * @param array $attributes Optional atributes not listened (in array). This will be applicated to all radioButton |
|
| 747 | + */ |
|
| 748 | + public function addRadio($label = '', $name = '', $values = array(), $selected = null, $required = false, $attributes = array()) { |
|
| 749 | + if (!is_array($values)) die('FATAL ERROR: Trying to create "RadioButton" with string VALUE, is requried use ARRAY()'); |
|
| 750 | + $data = array( |
|
| 751 | + 'name' => $name, |
|
| 752 | + ); |
|
| 753 | + |
|
| 754 | + if ($required) $data['required'] = 'required'; |
|
| 755 | + if (!empty($attributes)) array_merge($data, $attributes); |
|
| 756 | + |
|
| 757 | + |
|
| 758 | + |
|
| 759 | + $content = array( |
|
| 760 | + 'type' => 'radio', |
|
| 761 | + 'data' => $data, |
|
| 762 | + 'values' => $values, |
|
| 763 | + 'selected' => $selected |
|
| 764 | + ); |
|
| 765 | + if ($label != '') $content['label'] = $label; |
|
| 766 | + |
|
| 767 | + $this->content[] = $content; |
|
| 768 | + } |
|
| 769 | + |
|
| 770 | + |
|
| 771 | + /** |
|
| 772 | + * @name addSelect |
|
| 773 | + * @tutorial Use this function to add a radio button |
|
| 774 | + * @param string $label Text to show before input |
|
| 775 | + * @param string $name Select name |
|
| 776 | + * @param array $values Array('value'=>'text to show') |
|
| 777 | + * @param boolean $required Specify if select is required |
|
| 778 | + * @param string $id ID Specify ID to manipulate via javascript or CSS |
|
| 779 | + * @param array $attributes Optional atributes not listened (in array). |
|
| 780 | + */ |
|
| 781 | + public function addSelect($label = '', $name = '', $values = '', $selected = null, $required = false, $multiple = false, $attributes = array()) { |
|
| 782 | + $data = array( |
|
| 783 | + 'name' => $name, |
|
| 784 | + 'required' => $required, |
|
| 785 | + ); |
|
| 786 | + if ($required) $data['required'] = 'required'; |
|
| 787 | + if ($multiple) $data['multiple'] = 'multiple'; |
|
| 788 | + if (!empty($attributes)) array_merge($data, $attributes); |
|
| 789 | + |
|
| 790 | + |
|
| 791 | + // In this case, the values are saved in the main of array to speed up select loader |
|
| 792 | + $content = array( |
|
| 793 | + 'type' => 'select', |
|
| 794 | + 'data' => $data, |
|
| 795 | + 'values' => $values, |
|
| 796 | + 'selected' => $selected |
|
| 797 | + ); |
|
| 798 | + if ($label != '') $content['label'] = $label; |
|
| 799 | + |
|
| 800 | + $this->content[] = $content; |
|
| 801 | + } |
|
| 802 | + |
|
| 803 | + /** |
|
| 804 | + * @name addSubmit |
|
| 805 | + * @tutorial Use this function to add a submit button |
|
| 806 | + * @param string $name Select name (optional, if leav blank it will not send in POST / GET) |
|
| 807 | + * @param string $value Text to show in button and ID |
|
| 808 | + * @param array $attributes Optional atributes not listened (in array). |
|
| 809 | + */ |
|
| 810 | + public function addSubmit($name = '', $value = '', $attributes = array()) { |
|
| 811 | + $data = array( |
|
| 812 | + 'type' => 'submit', |
|
| 813 | + 'name' => $name, |
|
| 814 | + 'value' => $value |
|
| 815 | + ); |
|
| 816 | + if (!empty($attributes)) array_merge($data, $attributes); |
|
| 817 | + |
|
| 818 | + $this->content[] = array( |
|
| 819 | + 'type' => 'input', |
|
| 820 | + 'data' => $data |
|
| 821 | + ); |
|
| 822 | + |
|
| 823 | + |
|
| 824 | + } |
|
| 825 | + |
|
| 826 | + /** |
|
| 827 | + * @name addButton |
|
| 828 | + * @tutorial Use this function to add a button with "onclick" action (or id/class to call via jquery) |
|
| 829 | + * @param string $value Name to show in button and ID |
|
| 830 | + * @param string $onClick Action to load when button is clicked |
|
| 831 | + * @param array $attributes Optional atributes not listened (in array). |
|
| 832 | + */ |
|
| 833 | + public function addButton($value = '', $onClick = '', $attributes = array()) { |
|
| 834 | + $data = array( |
|
| 835 | + 'type' => 'button', |
|
| 836 | + 'value' => $value, |
|
| 837 | + 'onClick' => $onClick |
|
| 838 | + ); |
|
| 839 | + if (!empty($attributes)) array_merge($data, $attributes); |
|
| 840 | + |
|
| 841 | + $this->content[] = array( |
|
| 842 | + 'type' => 'input', |
|
| 843 | + 'data' => $data |
|
| 844 | + ); |
|
| 845 | + } |
|
| 846 | + |
|
| 847 | + |
|
| 848 | + /** |
|
| 849 | + * @name addButton |
|
| 850 | + * @tutorial Use this function to add a button with "onclick" action (or id/class to call via jquery) |
|
| 851 | + * @param string $value Name to show in button and ID |
|
| 852 | + * @param string $onClick Action to load when button is clicked |
|
| 853 | + * @param array $attributes Optional atributes not listened (in array). |
|
| 854 | + */ |
|
| 855 | + public function addTextArea($label = '', $name = '', $value = '', $required = false, $attributes = array()) { |
|
| 856 | + // Creating main data |
|
| 857 | + $data = array( |
|
| 858 | + 'name' => $name, |
|
| 859 | + ); |
|
| 860 | + |
|
| 861 | + if ($required) $data['required'] = 'required'; |
|
| 862 | + if (!empty($attributes)) array_merge($data, $attributes); |
|
| 863 | + |
|
| 864 | + // Saving data to object |
|
| 865 | + $content = array( |
|
| 866 | + 'type' => 'textarea', |
|
| 867 | + 'text' => $value, |
|
| 868 | + 'data' => $data |
|
| 869 | + ); |
|
| 870 | + if ($label != '') $content['label'] = $label; |
|
| 871 | 871 | |
| 872 | - $this->content[] = $content; |
|
| 873 | - } |
|
| 872 | + $this->content[] = $content; |
|
| 873 | + } |
|
| 874 | 874 | |
| 875 | - /* |
|
| 875 | + /* |
|
| 876 | 876 | * OTHER |
| 877 | 877 | */ |
| 878 | - /** |
|
| 879 | - * @name log |
|
| 880 | - * @tutorial Save a log if is enabled logging |
|
| 881 | - * @param boolean $save If is true, save the log |
|
| 882 | - * @param string $message Message to log |
|
| 883 | - */ |
|
| 884 | - private function log($message, $data = array()) { |
|
| 885 | - if ($this->logErrors) { |
|
| 886 | - // Try to get a name (label or name) |
|
| 887 | - if (class_exists('kw')) { |
|
| 888 | - if (isset($data['label'])) $this->errors .= 'Found an error in field' . ': "' . $data['label'] . '": '; |
|
| 889 | - elseif (isset($data['name'])) $this->errors .= 'Found an error in field' . ': "' . $data['name'] . '": '; |
|
| 890 | - } else { |
|
| 891 | - if (isset($data['label'])) $this->errors .= 'Found an error in field' . $data['label'] . '": '; |
|
| 892 | - elseif (isset($data['name'])) $this->errors .= 'Found an error in field' . ': "' . $data['name'] . '": '; |
|
| 893 | - } |
|
| 878 | + /** |
|
| 879 | + * @name log |
|
| 880 | + * @tutorial Save a log if is enabled logging |
|
| 881 | + * @param boolean $save If is true, save the log |
|
| 882 | + * @param string $message Message to log |
|
| 883 | + */ |
|
| 884 | + private function log($message, $data = array()) { |
|
| 885 | + if ($this->logErrors) { |
|
| 886 | + // Try to get a name (label or name) |
|
| 887 | + if (class_exists('kw')) { |
|
| 888 | + if (isset($data['label'])) $this->errors .= 'Found an error in field' . ': "' . $data['label'] . '": '; |
|
| 889 | + elseif (isset($data['name'])) $this->errors .= 'Found an error in field' . ': "' . $data['name'] . '": '; |
|
| 890 | + } else { |
|
| 891 | + if (isset($data['label'])) $this->errors .= 'Found an error in field' . $data['label'] . '": '; |
|
| 892 | + elseif (isset($data['name'])) $this->errors .= 'Found an error in field' . ': "' . $data['name'] . '": '; |
|
| 893 | + } |
|
| 894 | 894 | |
| 895 | - // preparing message |
|
| 896 | - $this->errors .= ' ' . $message . '.'; |
|
| 895 | + // preparing message |
|
| 896 | + $this->errors .= ' ' . $message . '.'; |
|
| 897 | 897 | |
| 898 | - // Extra message (title attribute) |
|
| 899 | - if (isset($data['title']) and $data['title'] != '') $this->errors .= ' | '. 'MESSAGE' .': ' . $data['title']; |
|
| 898 | + // Extra message (title attribute) |
|
| 899 | + if (isset($data['title']) and $data['title'] != '') $this->errors .= ' | '. 'MESSAGE' .': ' . $data['title']; |
|
| 900 | 900 | |
| 901 | - $this->errors .= '<br />'; |
|
| 902 | - } |
|
| 903 | - } |
|
| 901 | + $this->errors .= '<br />'; |
|
| 902 | + } |
|
| 903 | + } |
|
| 904 | 904 | } |
| 905 | 905 | |
| 906 | 906 | |
@@ -914,23 +914,23 @@ discard block |
||
| 914 | 914 | // More examples: |
| 915 | 915 | // http://us2.php.net/manual/es/function.checkdate.php |
| 916 | 916 | function is_date( $str ) { |
| 917 | - // Try to execute date creator |
|
| 918 | - try { |
|
| 919 | - $dt = new DateTime( trim($str) ); |
|
| 920 | - } catch( Exception $e ) { |
|
| 921 | - // If fails, it return false, date is incorrect |
|
| 922 | - return false; |
|
| 923 | - } |
|
| 924 | - |
|
| 925 | - // Checking date |
|
| 926 | - $month = $dt->format('m'); |
|
| 927 | - $day = $dt->format('d'); |
|
| 928 | - $year = $dt->format('Y'); |
|
| 929 | - |
|
| 930 | - // Date is ok |
|
| 931 | - if (checkdate($month, $day, $year)) { |
|
| 932 | - return true; |
|
| 933 | - } else { |
|
| 934 | - return false; |
|
| 935 | - } |
|
| 917 | + // Try to execute date creator |
|
| 918 | + try { |
|
| 919 | + $dt = new DateTime( trim($str) ); |
|
| 920 | + } catch( Exception $e ) { |
|
| 921 | + // If fails, it return false, date is incorrect |
|
| 922 | + return false; |
|
| 923 | + } |
|
| 924 | + |
|
| 925 | + // Checking date |
|
| 926 | + $month = $dt->format('m'); |
|
| 927 | + $day = $dt->format('d'); |
|
| 928 | + $year = $dt->format('Y'); |
|
| 929 | + |
|
| 930 | + // Date is ok |
|
| 931 | + if (checkdate($month, $day, $year)) { |
|
| 932 | + return true; |
|
| 933 | + } else { |
|
| 934 | + return false; |
|
| 935 | + } |
|
| 936 | 936 | } |
| 937 | 937 | \ No newline at end of file |
@@ -130,14 +130,18 @@ discard block |
||
| 130 | 130 | // Itearate all inputs |
| 131 | 131 | foreach ($toShow as $input) { |
| 132 | 132 | // Reading data |
| 133 | - if (isset($input['data'])) $data = $input['data']; |
|
| 133 | + if (isset($input['data'])) { |
|
| 134 | + $data = $input['data']; |
|
| 135 | + } |
|
| 134 | 136 | |
| 135 | 137 | // New row |
| 136 | 138 | echo '<div>'; |
| 137 | 139 | // Showing labels |
| 138 | 140 | if ($this->show_labels) { |
| 139 | 141 | echo '<div>'; |
| 140 | - if (isset($input['label']) and $input['label'] != '') echo $input['label']; |
|
| 142 | + if (isset($input['label']) and $input['label'] != '') { |
|
| 143 | + echo $input['label']; |
|
| 144 | + } |
|
| 141 | 145 | echo '</div>'; |
| 142 | 146 | } |
| 143 | 147 | |
@@ -182,7 +186,9 @@ discard block |
||
| 182 | 186 | private function showInput($data) { |
| 183 | 187 | $r = ''; |
| 184 | 188 | // Number start if is range |
| 185 | - if ($data['type'] == 'range' and isset($data['min'])) $r .= $data['min'] . ' '; |
|
| 189 | + if ($data['type'] == 'range' and isset($data['min'])) { |
|
| 190 | + $r .= $data['min'] . ' '; |
|
| 191 | + } |
|
| 186 | 192 | |
| 187 | 193 | $r .= '<input '; |
| 188 | 194 | |
@@ -197,7 +203,9 @@ discard block |
||
| 197 | 203 | $r .= '/>'; |
| 198 | 204 | |
| 199 | 205 | // Number end if is range |
| 200 | - if ($data['type'] == 'range' and isset($data['max'])) $r .= $data['max'] . ' '; |
|
| 206 | + if ($data['type'] == 'range' and isset($data['max'])) { |
|
| 207 | + $r .= $data['max'] . ' '; |
|
| 208 | + } |
|
| 201 | 209 | |
| 202 | 210 | // Return |
| 203 | 211 | return $r; |
@@ -220,7 +228,9 @@ discard block |
||
| 220 | 228 | // Si no tiene m�ltiples valores (es un string), lo retornamos de golpe |
| 221 | 229 | if (!is_array($values)) { |
| 222 | 230 | // Comprobamos el value, es posible que el usuario este intentando crear los Radio (option) de forma separada |
| 223 | - if (!is_array($values) and $selected == $values) $base .= ' checked="checked" '; |
|
| 231 | + if (!is_array($values) and $selected == $values) { |
|
| 232 | + $base .= ' checked="checked" '; |
|
| 233 | + } |
|
| 224 | 234 | return $base . ' value="'.$values.'" />'; |
| 225 | 235 | } |
| 226 | 236 | |
@@ -229,7 +239,9 @@ discard block |
||
| 229 | 239 | $r = ''; |
| 230 | 240 | foreach ($values as $id=>$text) { |
| 231 | 241 | $r .= $base; |
| 232 | - if ($selected !== null and $id == $selected) $r .= ' checked="checked" '; |
|
| 242 | + if ($selected !== null and $id == $selected) { |
|
| 243 | + $r .= ' checked="checked" '; |
|
| 244 | + } |
|
| 233 | 245 | $r .= ' value="'. $id .'" />'.$text.'</label>'; |
| 234 | 246 | } |
| 235 | 247 | |
@@ -263,7 +275,9 @@ discard block |
||
| 263 | 275 | if ($selected != '') { |
| 264 | 276 | foreach ($values as $val=>$txt) { |
| 265 | 277 | $r .= '<option value="' . $val . '"'; |
| 266 | - if ($val == $selected) $r .= ' selected '; |
|
| 278 | + if ($val == $selected) { |
|
| 279 | + $r .= ' selected '; |
|
| 280 | + } |
|
| 267 | 281 | $r .= '>' . $txt . '</option>'; |
| 268 | 282 | } |
| 269 | 283 | } else { |
@@ -304,12 +318,24 @@ discard block |
||
| 304 | 318 | */ |
| 305 | 319 | private function showStartForm() { |
| 306 | 320 | $r = '<form '; |
| 307 | - if ($this->action!= '') $r .= 'action="'.$this->action.'" '; |
|
| 308 | - if ($this->method != '') $r .= 'method="'.$this->method .'" '; |
|
| 309 | - if ($this->name != '') $r .= 'name="'.$this->name .'" '; |
|
| 310 | - if ($this->on_submit != '') $r .= 'onSubmit="'.$this->on_submit .'" '; |
|
| 311 | - if ($this->id != '') $r .= 'id="'.$this->id .'" '; |
|
| 312 | - if ($this->class != '') $r .= 'class="'.$this->class .'" '; |
|
| 321 | + if ($this->action!= '') { |
|
| 322 | + $r .= 'action="'.$this->action.'" '; |
|
| 323 | + } |
|
| 324 | + if ($this->method != '') { |
|
| 325 | + $r .= 'method="'.$this->method .'" '; |
|
| 326 | + } |
|
| 327 | + if ($this->name != '') { |
|
| 328 | + $r .= 'name="'.$this->name .'" '; |
|
| 329 | + } |
|
| 330 | + if ($this->on_submit != '') { |
|
| 331 | + $r .= 'onSubmit="'.$this->on_submit .'" '; |
|
| 332 | + } |
|
| 333 | + if ($this->id != '') { |
|
| 334 | + $r .= 'id="'.$this->id .'" '; |
|
| 335 | + } |
|
| 336 | + if ($this->class != '') { |
|
| 337 | + $r .= 'class="'.$this->class .'" '; |
|
| 338 | + } |
|
| 313 | 339 | |
| 314 | 340 | return $r . '>'.PHP_EOL; |
| 315 | 341 | } |
@@ -370,7 +396,9 @@ discard block |
||
| 370 | 396 | } |
| 371 | 397 | } |
| 372 | 398 | |
| 373 | - if ($success >= $total) return true; |
|
| 399 | + if ($success >= $total) { |
|
| 400 | + return true; |
|
| 401 | + } |
|
| 374 | 402 | return false; |
| 375 | 403 | } |
| 376 | 404 | |
@@ -570,8 +598,11 @@ discard block |
||
| 570 | 598 | * @return string/null Return the value, if don't exist, return null |
| 571 | 599 | */ |
| 572 | 600 | private function getData($key, $default = null) { |
| 573 | - if ($this->method == "post") return isset($_POST[$key]) ? $_POST[$key] : $default; |
|
| 574 | - else return isset($_GET[$key]) ? $_GET[$key] : $default; |
|
| 601 | + if ($this->method == "post") { |
|
| 602 | + return isset($_POST[$key]) ? $_POST[$key] : $default; |
|
| 603 | + } else { |
|
| 604 | + return isset($_GET[$key]) ? $_GET[$key] : $default; |
|
| 605 | + } |
|
| 575 | 606 | } |
| 576 | 607 | |
| 577 | 608 | /* |
@@ -614,9 +645,15 @@ discard block |
||
| 614 | 645 | ); |
| 615 | 646 | |
| 616 | 647 | |
| 617 | - if ($required) $data['required'] = 'required'; |
|
| 618 | - if ($placeholder != '') $data['placeholder'] = $placeholder; |
|
| 619 | - if (!empty($attributes)) array_merge($data, $attributes); |
|
| 648 | + if ($required) { |
|
| 649 | + $data['required'] = 'required'; |
|
| 650 | + } |
|
| 651 | + if ($placeholder != '') { |
|
| 652 | + $data['placeholder'] = $placeholder; |
|
| 653 | + } |
|
| 654 | + if (!empty($attributes)) { |
|
| 655 | + array_merge($data, $attributes); |
|
| 656 | + } |
|
| 620 | 657 | |
| 621 | 658 | |
| 622 | 659 | // Saving data to object |
@@ -624,7 +661,9 @@ discard block |
||
| 624 | 661 | 'type' => 'input', |
| 625 | 662 | 'data' => $data |
| 626 | 663 | ); |
| 627 | - if ($label != '') $content['label'] = $label; |
|
| 664 | + if ($label != '') { |
|
| 665 | + $content['label'] = $label; |
|
| 666 | + } |
|
| 628 | 667 | |
| 629 | 668 | $this->content[] = $content; |
| 630 | 669 | } |
@@ -651,19 +690,33 @@ discard block |
||
| 651 | 690 | ); |
| 652 | 691 | |
| 653 | 692 | |
| 654 | - if ($required) $data['required'] = 'required'; |
|
| 655 | - if ($min) $data['min'] = $min; |
|
| 656 | - if ($max) $data['max'] = $max; |
|
| 657 | - if ($step) $data['step'] = $step; |
|
| 658 | - if ($placeholder != '') $data['placeholder'] = $placeholder; |
|
| 659 | - if (!empty($attributes)) array_merge($data, $attributes); |
|
| 693 | + if ($required) { |
|
| 694 | + $data['required'] = 'required'; |
|
| 695 | + } |
|
| 696 | + if ($min) { |
|
| 697 | + $data['min'] = $min; |
|
| 698 | + } |
|
| 699 | + if ($max) { |
|
| 700 | + $data['max'] = $max; |
|
| 701 | + } |
|
| 702 | + if ($step) { |
|
| 703 | + $data['step'] = $step; |
|
| 704 | + } |
|
| 705 | + if ($placeholder != '') { |
|
| 706 | + $data['placeholder'] = $placeholder; |
|
| 707 | + } |
|
| 708 | + if (!empty($attributes)) { |
|
| 709 | + array_merge($data, $attributes); |
|
| 710 | + } |
|
| 660 | 711 | |
| 661 | 712 | // Saving data to object |
| 662 | 713 | $content = array( |
| 663 | 714 | 'type' => 'input', |
| 664 | 715 | 'data' => $data |
| 665 | 716 | ); |
| 666 | - if ($label != '') $content['label'] = $label; |
|
| 717 | + if ($label != '') { |
|
| 718 | + $content['label'] = $label; |
|
| 719 | + } |
|
| 667 | 720 | |
| 668 | 721 | $this->content[] = $content; |
| 669 | 722 | } |
@@ -688,19 +741,33 @@ discard block |
||
| 688 | 741 | 'value' => $value, |
| 689 | 742 | ); |
| 690 | 743 | |
| 691 | - if ($required) $data['required'] = 'required'; |
|
| 692 | - if ($min) $data['min'] = $min; |
|
| 693 | - if ($max) $data['max'] = $max; |
|
| 694 | - if ($step) $data['step'] = $step; |
|
| 695 | - if ($placeholder != '') $data['placeholder'] = $placeholder; |
|
| 696 | - if (!empty($attributes)) array_merge($data, $attributes); |
|
| 744 | + if ($required) { |
|
| 745 | + $data['required'] = 'required'; |
|
| 746 | + } |
|
| 747 | + if ($min) { |
|
| 748 | + $data['min'] = $min; |
|
| 749 | + } |
|
| 750 | + if ($max) { |
|
| 751 | + $data['max'] = $max; |
|
| 752 | + } |
|
| 753 | + if ($step) { |
|
| 754 | + $data['step'] = $step; |
|
| 755 | + } |
|
| 756 | + if ($placeholder != '') { |
|
| 757 | + $data['placeholder'] = $placeholder; |
|
| 758 | + } |
|
| 759 | + if (!empty($attributes)) { |
|
| 760 | + array_merge($data, $attributes); |
|
| 761 | + } |
|
| 697 | 762 | |
| 698 | 763 | // Saving data to object |
| 699 | 764 | $content = array( |
| 700 | 765 | 'type' => 'input', |
| 701 | 766 | 'data' => $data |
| 702 | 767 | ); |
| 703 | - if ($label != '') $content['label'] = $label; |
|
| 768 | + if ($label != '') { |
|
| 769 | + $content['label'] = $label; |
|
| 770 | + } |
|
| 704 | 771 | |
| 705 | 772 | $this->content[] = $content; |
| 706 | 773 | } |
@@ -721,14 +788,20 @@ discard block |
||
| 721 | 788 | 'name' => $name, |
| 722 | 789 | 'value' => $value |
| 723 | 790 | ); |
| 724 | - if ($required) $data['required'] = 'required'; |
|
| 725 | - if (!empty($attributes)) array_merge($data, $attributes); |
|
| 791 | + if ($required) { |
|
| 792 | + $data['required'] = 'required'; |
|
| 793 | + } |
|
| 794 | + if (!empty($attributes)) { |
|
| 795 | + array_merge($data, $attributes); |
|
| 796 | + } |
|
| 726 | 797 | |
| 727 | 798 | $content = array( |
| 728 | 799 | 'type' => 'input', |
| 729 | 800 | 'data' => $data |
| 730 | 801 | ); |
| 731 | - if ($label != '') $content['label'] = $label; |
|
| 802 | + if ($label != '') { |
|
| 803 | + $content['label'] = $label; |
|
| 804 | + } |
|
| 732 | 805 | |
| 733 | 806 | $this->content[] = $content; |
| 734 | 807 | } |
@@ -746,13 +819,19 @@ discard block |
||
| 746 | 819 | * @param array $attributes Optional atributes not listened (in array). This will be applicated to all radioButton |
| 747 | 820 | */ |
| 748 | 821 | public function addRadio($label = '', $name = '', $values = array(), $selected = null, $required = false, $attributes = array()) { |
| 749 | - if (!is_array($values)) die('FATAL ERROR: Trying to create "RadioButton" with string VALUE, is requried use ARRAY()'); |
|
| 822 | + if (!is_array($values)) { |
|
| 823 | + die('FATAL ERROR: Trying to create "RadioButton" with string VALUE, is requried use ARRAY()'); |
|
| 824 | + } |
|
| 750 | 825 | $data = array( |
| 751 | 826 | 'name' => $name, |
| 752 | 827 | ); |
| 753 | 828 | |
| 754 | - if ($required) $data['required'] = 'required'; |
|
| 755 | - if (!empty($attributes)) array_merge($data, $attributes); |
|
| 829 | + if ($required) { |
|
| 830 | + $data['required'] = 'required'; |
|
| 831 | + } |
|
| 832 | + if (!empty($attributes)) { |
|
| 833 | + array_merge($data, $attributes); |
|
| 834 | + } |
|
| 756 | 835 | |
| 757 | 836 | |
| 758 | 837 | |
@@ -762,7 +841,9 @@ discard block |
||
| 762 | 841 | 'values' => $values, |
| 763 | 842 | 'selected' => $selected |
| 764 | 843 | ); |
| 765 | - if ($label != '') $content['label'] = $label; |
|
| 844 | + if ($label != '') { |
|
| 845 | + $content['label'] = $label; |
|
| 846 | + } |
|
| 766 | 847 | |
| 767 | 848 | $this->content[] = $content; |
| 768 | 849 | } |
@@ -783,9 +864,15 @@ discard block |
||
| 783 | 864 | 'name' => $name, |
| 784 | 865 | 'required' => $required, |
| 785 | 866 | ); |
| 786 | - if ($required) $data['required'] = 'required'; |
|
| 787 | - if ($multiple) $data['multiple'] = 'multiple'; |
|
| 788 | - if (!empty($attributes)) array_merge($data, $attributes); |
|
| 867 | + if ($required) { |
|
| 868 | + $data['required'] = 'required'; |
|
| 869 | + } |
|
| 870 | + if ($multiple) { |
|
| 871 | + $data['multiple'] = 'multiple'; |
|
| 872 | + } |
|
| 873 | + if (!empty($attributes)) { |
|
| 874 | + array_merge($data, $attributes); |
|
| 875 | + } |
|
| 789 | 876 | |
| 790 | 877 | |
| 791 | 878 | // In this case, the values are saved in the main of array to speed up select loader |
@@ -795,7 +882,9 @@ discard block |
||
| 795 | 882 | 'values' => $values, |
| 796 | 883 | 'selected' => $selected |
| 797 | 884 | ); |
| 798 | - if ($label != '') $content['label'] = $label; |
|
| 885 | + if ($label != '') { |
|
| 886 | + $content['label'] = $label; |
|
| 887 | + } |
|
| 799 | 888 | |
| 800 | 889 | $this->content[] = $content; |
| 801 | 890 | } |
@@ -813,7 +902,9 @@ discard block |
||
| 813 | 902 | 'name' => $name, |
| 814 | 903 | 'value' => $value |
| 815 | 904 | ); |
| 816 | - if (!empty($attributes)) array_merge($data, $attributes); |
|
| 905 | + if (!empty($attributes)) { |
|
| 906 | + array_merge($data, $attributes); |
|
| 907 | + } |
|
| 817 | 908 | |
| 818 | 909 | $this->content[] = array( |
| 819 | 910 | 'type' => 'input', |
@@ -836,7 +927,9 @@ discard block |
||
| 836 | 927 | 'value' => $value, |
| 837 | 928 | 'onClick' => $onClick |
| 838 | 929 | ); |
| 839 | - if (!empty($attributes)) array_merge($data, $attributes); |
|
| 930 | + if (!empty($attributes)) { |
|
| 931 | + array_merge($data, $attributes); |
|
| 932 | + } |
|
| 840 | 933 | |
| 841 | 934 | $this->content[] = array( |
| 842 | 935 | 'type' => 'input', |
@@ -858,8 +951,12 @@ discard block |
||
| 858 | 951 | 'name' => $name, |
| 859 | 952 | ); |
| 860 | 953 | |
| 861 | - if ($required) $data['required'] = 'required'; |
|
| 862 | - if (!empty($attributes)) array_merge($data, $attributes); |
|
| 954 | + if ($required) { |
|
| 955 | + $data['required'] = 'required'; |
|
| 956 | + } |
|
| 957 | + if (!empty($attributes)) { |
|
| 958 | + array_merge($data, $attributes); |
|
| 959 | + } |
|
| 863 | 960 | |
| 864 | 961 | // Saving data to object |
| 865 | 962 | $content = array( |
@@ -867,7 +964,9 @@ discard block |
||
| 867 | 964 | 'text' => $value, |
| 868 | 965 | 'data' => $data |
| 869 | 966 | ); |
| 870 | - if ($label != '') $content['label'] = $label; |
|
| 967 | + if ($label != '') { |
|
| 968 | + $content['label'] = $label; |
|
| 969 | + } |
|
| 871 | 970 | |
| 872 | 971 | $this->content[] = $content; |
| 873 | 972 | } |
@@ -885,18 +984,26 @@ discard block |
||
| 885 | 984 | if ($this->logErrors) { |
| 886 | 985 | // Try to get a name (label or name) |
| 887 | 986 | if (class_exists('kw')) { |
| 888 | - if (isset($data['label'])) $this->errors .= 'Found an error in field' . ': "' . $data['label'] . '": '; |
|
| 889 | - elseif (isset($data['name'])) $this->errors .= 'Found an error in field' . ': "' . $data['name'] . '": '; |
|
| 987 | + if (isset($data['label'])) { |
|
| 988 | + $this->errors .= 'Found an error in field' . ': "' . $data['label'] . '": '; |
|
| 989 | + } elseif (isset($data['name'])) { |
|
| 990 | + $this->errors .= 'Found an error in field' . ': "' . $data['name'] . '": '; |
|
| 991 | + } |
|
| 890 | 992 | } else { |
| 891 | - if (isset($data['label'])) $this->errors .= 'Found an error in field' . $data['label'] . '": '; |
|
| 892 | - elseif (isset($data['name'])) $this->errors .= 'Found an error in field' . ': "' . $data['name'] . '": '; |
|
| 993 | + if (isset($data['label'])) { |
|
| 994 | + $this->errors .= 'Found an error in field' . $data['label'] . '": '; |
|
| 995 | + } elseif (isset($data['name'])) { |
|
| 996 | + $this->errors .= 'Found an error in field' . ': "' . $data['name'] . '": '; |
|
| 997 | + } |
|
| 893 | 998 | } |
| 894 | 999 | |
| 895 | 1000 | // preparing message |
| 896 | 1001 | $this->errors .= ' ' . $message . '.'; |
| 897 | 1002 | |
| 898 | 1003 | // Extra message (title attribute) |
| 899 | - if (isset($data['title']) and $data['title'] != '') $this->errors .= ' | '. 'MESSAGE' .': ' . $data['title']; |
|
| 1004 | + if (isset($data['title']) and $data['title'] != '') { |
|
| 1005 | + $this->errors .= ' | '. 'MESSAGE' .': ' . $data['title']; |
|
| 1006 | + } |
|
| 900 | 1007 | |
| 901 | 1008 | $this->errors .= '<br />'; |
| 902 | 1009 | } |
@@ -30,7 +30,7 @@ discard block |
||
| 30 | 30 | |
| 31 | 31 | |
| 32 | 32 | function menu_ul($sel = 'inicio') |
| 33 | - { |
|
| 33 | + { |
|
| 34 | 34 | $items = array( |
| 35 | 35 | 'inicio' => array( |
| 36 | 36 | 'id' => 'inicio', |
@@ -65,7 +65,7 @@ discard block |
||
| 65 | 65 | } |
| 66 | 66 | |
| 67 | 67 | function menu_p($sel = 'inicio', $separador = '') |
| 68 | - { |
|
| 68 | + { |
|
| 69 | 69 | //$CI =& get_instance(); |
| 70 | 70 | $items = array( |
| 71 | 71 | 'inicio' => array( |
@@ -39,311 +39,311 @@ |
||
| 39 | 39 | * (you can pass the most critical GETs manually if you like) |
| 40 | 40 | */ |
| 41 | 41 | |
| 42 | - //Esta clase fue editada por programadores de Cf con la aprobacion de Ruben Arroyo |
|
| 42 | + //Esta clase fue editada por programadores de Cf con la aprobacion de Ruben Arroyo |
|
| 43 | 43 | |
| 44 | 44 | namespace Sistema\Ayudantes; |
| 45 | 45 | |
| 46 | 46 | class Cf_PHPPaginator { |
| 47 | - /* |
|
| 47 | + /* |
|
| 48 | 48 | * MAIN Settings (required) |
| 49 | 49 | */ |
| 50 | 50 | |
| 51 | - /** |
|
| 52 | - * |
|
| 53 | - * @total_records string Total of records to paginate (specify manually) |
|
| 54 | - */ |
|
| 55 | - public $total_records = 0; |
|
| 51 | + /** |
|
| 52 | + * |
|
| 53 | + * @total_records string Total of records to paginate (specify manually) |
|
| 54 | + */ |
|
| 55 | + public $total_records = 0; |
|
| 56 | 56 | |
| 57 | 57 | |
| 58 | - /* |
|
| 58 | + /* |
|
| 59 | 59 | * MAIN Settings (optional) |
| 60 | 60 | */ |
| 61 | 61 | |
| 62 | - /** |
|
| 63 | - * @style string Specify Class to define |
|
| 64 | - * @tutorial If is specified, it would create <div class="style"> otherwise it not create div |
|
| 65 | - */ |
|
| 66 | - public $style = ''; |
|
| 62 | + /** |
|
| 63 | + * @style string Specify Class to define |
|
| 64 | + * @tutorial If is specified, it would create <div class="style"> otherwise it not create div |
|
| 65 | + */ |
|
| 66 | + public $style = ''; |
|
| 67 | 67 | |
| 68 | - /** |
|
| 69 | - * @records number Max records to show on every page |
|
| 70 | - */ |
|
| 71 | - public $records = 20; |
|
| 68 | + /** |
|
| 69 | + * @records number Max records to show on every page |
|
| 70 | + */ |
|
| 71 | + public $records = 20; |
|
| 72 | 72 | |
| 73 | - /** |
|
| 74 | - * @max_links number Maxium quantity of links to show before and after actual page |
|
| 75 | - * @example If current page is 4 and MAX is 2, it show "2 3 4 5 6" |
|
| 76 | - */ |
|
| 77 | - public $max_links = 3; |
|
| 73 | + /** |
|
| 74 | + * @max_links number Maxium quantity of links to show before and after actual page |
|
| 75 | + * @example If current page is 4 and MAX is 2, it show "2 3 4 5 6" |
|
| 76 | + */ |
|
| 77 | + public $max_links = 3; |
|
| 78 | 78 | |
| 79 | - /** |
|
| 80 | - * @get_name string Specify INDEX of GET that is used |
|
| 81 | - * |
|
| 82 | - * It will load automatically the current page. |
|
| 83 | - * If you like, you can specify manually in "$cur_page" |
|
| 84 | - * (if you like filter previously or the script will not load directly from URL) |
|
| 85 | - */ |
|
| 86 | - public $get_name = 'pag'; |
|
| 79 | + /** |
|
| 80 | + * @get_name string Specify INDEX of GET that is used |
|
| 81 | + * |
|
| 82 | + * It will load automatically the current page. |
|
| 83 | + * If you like, you can specify manually in "$cur_page" |
|
| 84 | + * (if you like filter previously or the script will not load directly from URL) |
|
| 85 | + */ |
|
| 86 | + public $get_name = 'pag'; |
|
| 87 | 87 | |
| 88 | - /** |
|
| 89 | - * @max_records number Specify maxium quantity of registers will be loaded. "0" disable this |
|
| 90 | - */ |
|
| 91 | - public $max_records = 0; |
|
| 88 | + /** |
|
| 89 | + * @max_records number Specify maxium quantity of registers will be loaded. "0" disable this |
|
| 90 | + */ |
|
| 91 | + public $max_records = 0; |
|
| 92 | 92 | |
| 93 | 93 | |
| 94 | - /** |
|
| 95 | - * @recicle_url boolean If is true, modify directly tue current URL to put the pagination (if not exist any, add &pag= to the end) |
|
| 96 | - * If is true, $url_start and $url_end will be ignored |
|
| 97 | - */ |
|
| 98 | - public $recicle_url = true; |
|
| 94 | + /** |
|
| 95 | + * @recicle_url boolean If is true, modify directly tue current URL to put the pagination (if not exist any, add &pag= to the end) |
|
| 96 | + * If is true, $url_start and $url_end will be ignored |
|
| 97 | + */ |
|
| 98 | + public $recicle_url = true; |
|
| 99 | 99 | |
| 100 | - /** |
|
| 101 | - * @specific_get array Specify what GETs (and order) you like recicle. |
|
| 102 | - * Set array() to ALL (not recomended to avoid atacks DoS) |
|
| 103 | - * Set '' for any |
|
| 104 | - * @example array('section', 'pag', 'subsection'); |
|
| 105 | - * If you don't need 'pag' in the midle, you can ignore it. |
|
| 106 | - * WARNING: If the order is very important, use the pag at THE END of url |
|
| 107 | - */ |
|
| 108 | - public $specific_get = ''; |
|
| 100 | + /** |
|
| 101 | + * @specific_get array Specify what GETs (and order) you like recicle. |
|
| 102 | + * Set array() to ALL (not recomended to avoid atacks DoS) |
|
| 103 | + * Set '' for any |
|
| 104 | + * @example array('section', 'pag', 'subsection'); |
|
| 105 | + * If you don't need 'pag' in the midle, you can ignore it. |
|
| 106 | + * WARNING: If the order is very important, use the pag at THE END of url |
|
| 107 | + */ |
|
| 108 | + public $specific_get = ''; |
|
| 109 | 109 | |
| 110 | - /** |
|
| 111 | - * @url_start string specify how the URL of every link start. IF $recicle_url is TRUE, this will be ignored |
|
| 112 | - * @example If you use MOD_REWRITE or JAVASCRIPT, you can put "http://mywebsite.com/subdir/pag-" or "javascript:paginate(" |
|
| 113 | - * |
|
| 114 | - * This value will auto completed if you leave empty |
|
| 115 | - */ |
|
| 116 | - public $url_start = ''; |
|
| 110 | + /** |
|
| 111 | + * @url_start string specify how the URL of every link start. IF $recicle_url is TRUE, this will be ignored |
|
| 112 | + * @example If you use MOD_REWRITE or JAVASCRIPT, you can put "http://mywebsite.com/subdir/pag-" or "javascript:paginate(" |
|
| 113 | + * |
|
| 114 | + * This value will auto completed if you leave empty |
|
| 115 | + */ |
|
| 116 | + public $url_start = ''; |
|
| 117 | 117 | |
| 118 | - /** |
|
| 119 | - * @url_end string specify how the URL of every link ends. IF $recicle_url is TRUE, this will be ignored |
|
| 120 | - * @example If you use MOD_REWRITE or JAVASCRIPT, you can put "/" or ");" |
|
| 121 | - * |
|
| 122 | - * This value will auto completed if you leave empty |
|
| 123 | - */ |
|
| 124 | - public $url_end = ''; |
|
| 118 | + /** |
|
| 119 | + * @url_end string specify how the URL of every link ends. IF $recicle_url is TRUE, this will be ignored |
|
| 120 | + * @example If you use MOD_REWRITE or JAVASCRIPT, you can put "/" or ");" |
|
| 121 | + * |
|
| 122 | + * This value will auto completed if you leave empty |
|
| 123 | + */ |
|
| 124 | + public $url_end = ''; |
|
| 125 | 125 | |
| 126 | 126 | |
| 127 | 127 | |
| 128 | - /* |
|
| 128 | + /* |
|
| 129 | 129 | * Design settings |
| 130 | 130 | */ |
| 131 | 131 | |
| 132 | - // Icons to show "First | Previous | Next | Last" |
|
| 133 | - //& laquo; = � | & lt; = < |
|
| 132 | + // Icons to show "First | Previous | Next | Last" |
|
| 133 | + //& laquo; = � | & lt; = < |
|
| 134 | 134 | //& raquo; = � | & gt; = > |
| 135 | 135 | // Leave empty '' to not show or ' ' to show empty |
| 136 | - public $first = '[<<]'; |
|
| 137 | - public $previous = '[<]'; |
|
| 138 | - public $next = '[>]'; |
|
| 139 | - public $last = '[>>]'; |
|
| 136 | + public $first = '[<<]'; |
|
| 137 | + public $previous = '[<]'; |
|
| 138 | + public $next = '[>]'; |
|
| 139 | + public $last = '[>>]'; |
|
| 140 | 140 | |
| 141 | 141 | |
| 142 | - /* |
|
| 142 | + /* |
|
| 143 | 143 | * RETURNS FROM PAGINATOR and internal use |
| 144 | 144 | */ |
| 145 | - // Return current page (auto loaded) |
|
| 146 | - public $cur_page; |
|
| 145 | + // Return current page (auto loaded) |
|
| 146 | + public $cur_page; |
|
| 147 | 147 | |
| 148 | - // original page loaded |
|
| 149 | - // it contains the real value in GET (ex: -1, 5...) to compare later |
|
| 150 | - public $original_page; |
|
| 148 | + // original page loaded |
|
| 149 | + // it contains the real value in GET (ex: -1, 5...) to compare later |
|
| 150 | + public $original_page; |
|
| 151 | 151 | |
| 152 | - // Return total pages |
|
| 153 | - public $total_pages; |
|
| 152 | + // Return total pages |
|
| 153 | + public $total_pages; |
|
| 154 | 154 | |
| 155 | - // LIMIT_START / Specify the first record of the page (ex, in page 3 and 20 records is record num 40) |
|
| 156 | - // Limit max is $records |
|
| 157 | - public $first_record; |
|
| 155 | + // LIMIT_START / Specify the first record of the page (ex, in page 3 and 20 records is record num 40) |
|
| 156 | + // Limit max is $records |
|
| 157 | + public $first_record; |
|
| 158 | 158 | |
| 159 | - // Specify limit to put directly in mysql query ( LIMIT 0,20 ) |
|
| 160 | - public $limit; |
|
| 159 | + // Specify limit to put directly in mysql query ( LIMIT 0,20 ) |
|
| 160 | + public $limit; |
|
| 161 | 161 | |
| 162 | 162 | |
| 163 | 163 | /* |
| 164 | 164 | * Functions |
| 165 | 165 | */ |
| 166 | - /** |
|
| 167 | - * @name paginate |
|
| 168 | - * @tutorial This function is called directly to load all params |
|
| 169 | - * @example $pag->paginate(); |
|
| 170 | - */ |
|
| 171 | - public function paginate() { |
|
| 172 | - $this->get(); // Filtering and obtaining variables |
|
| 173 | - $this->calculate(); // Calc current page |
|
| 174 | - $this->prepareUrl(); // Preparing URL to show |
|
| 175 | - } |
|
| 166 | + /** |
|
| 167 | + * @name paginate |
|
| 168 | + * @tutorial This function is called directly to load all params |
|
| 169 | + * @example $pag->paginate(); |
|
| 170 | + */ |
|
| 171 | + public function paginate() { |
|
| 172 | + $this->get(); // Filtering and obtaining variables |
|
| 173 | + $this->calculate(); // Calc current page |
|
| 174 | + $this->prepareUrl(); // Preparing URL to show |
|
| 175 | + } |
|
| 176 | 176 | |
| 177 | - /** |
|
| 178 | - * @name show |
|
| 179 | - * @tutorial Show links of pagination |
|
| 180 | - * @example $pag->show(); |
|
| 181 | - */ |
|
| 182 | - public function show() { |
|
| 183 | - // Prepare string with links |
|
| 184 | - // Reading here variables is faster than "$this->var" |
|
| 185 | - $cur_page = $this->cur_page; |
|
| 186 | - $url_start = $this->url_start; |
|
| 187 | - $url_end = $this->url_end; |
|
| 177 | + /** |
|
| 178 | + * @name show |
|
| 179 | + * @tutorial Show links of pagination |
|
| 180 | + * @example $pag->show(); |
|
| 181 | + */ |
|
| 182 | + public function show() { |
|
| 183 | + // Prepare string with links |
|
| 184 | + // Reading here variables is faster than "$this->var" |
|
| 185 | + $cur_page = $this->cur_page; |
|
| 186 | + $url_start = $this->url_start; |
|
| 187 | + $url_end = $this->url_end; |
|
| 188 | 188 | |
| 189 | - $start = $cur_page - $this->max_links; |
|
| 190 | - $end = $cur_page + $this->max_links; |
|
| 189 | + $start = $cur_page - $this->max_links; |
|
| 190 | + $end = $cur_page + $this->max_links; |
|
| 191 | 191 | |
| 192 | - if ($start < 1) $start = 1; |
|
| 193 | - if ($end > $this->total_pages) $end = $this->total_pages; |
|
| 192 | + if ($start < 1) $start = 1; |
|
| 193 | + if ($end > $this->total_pages) $end = $this->total_pages; |
|
| 194 | 194 | |
| 195 | - // Showing all clickable pages (create div if class is defined) |
|
| 196 | - if ($this->style != '') $r = '<div class="'.$this->style.'">'; |
|
| 197 | - else $r = ''; |
|
| 195 | + // Showing all clickable pages (create div if class is defined) |
|
| 196 | + if ($this->style != '') $r = '<div class="'.$this->style.'">'; |
|
| 197 | + else $r = ''; |
|
| 198 | 198 | |
| 199 | 199 | |
| 200 | - // First / previous |
|
| 201 | - if ($this->cur_page > 1) { |
|
| 202 | - if ($this->first != '') $r .= '<a class="first" href="' . $url_start . '1' . $url_end . '">'.$this->first.'</a> '; |
|
| 203 | - if ($this->previous != '') $r .= '<a class="previous" href="' . $url_start . ($cur_page - 1) . $url_end . '">'.$this->previous.'</a> '; |
|
| 204 | - } |
|
| 200 | + // First / previous |
|
| 201 | + if ($this->cur_page > 1) { |
|
| 202 | + if ($this->first != '') $r .= '<a class="first" href="' . $url_start . '1' . $url_end . '">'.$this->first.'</a> '; |
|
| 203 | + if ($this->previous != '') $r .= '<a class="previous" href="' . $url_start . ($cur_page - 1) . $url_end . '">'.$this->previous.'</a> '; |
|
| 204 | + } |
|
| 205 | 205 | |
| 206 | - // You can optimize this separating BEFORE and AFTER current page in two for (to avoid load "if" in each loop) |
|
| 207 | - // but it would be difficult on changes |
|
| 208 | - for ($n=$start; $n<=$end; $n++) { |
|
| 209 | - if ($n != $cur_page) $r .= '<a class="link" href="'. $url_start . $n . $url_end . '">'.$n.'</a> '; |
|
| 210 | - else $r .= '<a class="current">'.$n.'</a> '; |
|
| 211 | - } |
|
| 206 | + // You can optimize this separating BEFORE and AFTER current page in two for (to avoid load "if" in each loop) |
|
| 207 | + // but it would be difficult on changes |
|
| 208 | + for ($n=$start; $n<=$end; $n++) { |
|
| 209 | + if ($n != $cur_page) $r .= '<a class="link" href="'. $url_start . $n . $url_end . '">'.$n.'</a> '; |
|
| 210 | + else $r .= '<a class="current">'.$n.'</a> '; |
|
| 211 | + } |
|
| 212 | 212 | |
| 213 | - // next / last |
|
| 214 | - if ($this->cur_page < $this->total_pages) { |
|
| 215 | - if ($this->next != '') $r .= '<a class="next" href="' . $url_start . ($cur_page + 1) . $url_end . '">'.$this->next.'</a> '; |
|
| 216 | - if ($this->last != '') $r .= '<a class="last" href="' . $url_start . $this->total_pages . $url_end .'">'.$this->last.'</a> '; |
|
| 217 | - } |
|
| 213 | + // next / last |
|
| 214 | + if ($this->cur_page < $this->total_pages) { |
|
| 215 | + if ($this->next != '') $r .= '<a class="next" href="' . $url_start . ($cur_page + 1) . $url_end . '">'.$this->next.'</a> '; |
|
| 216 | + if ($this->last != '') $r .= '<a class="last" href="' . $url_start . $this->total_pages . $url_end .'">'.$this->last.'</a> '; |
|
| 217 | + } |
|
| 218 | 218 | |
| 219 | - // End div (if exist) |
|
| 220 | - if ($this->style != '') $r .= '</div>'; |
|
| 219 | + // End div (if exist) |
|
| 220 | + if ($this->style != '') $r .= '</div>'; |
|
| 221 | 221 | |
| 222 | - return $r; |
|
| 223 | - } |
|
| 222 | + return $r; |
|
| 223 | + } |
|
| 224 | 224 | |
| 225 | 225 | |
| 226 | - /** |
|
| 227 | - * @name get |
|
| 228 | - * @tutorial This function is autoloaded, it get the current page and filter number to avoid hackers |
|
| 229 | - */ |
|
| 230 | - private function get() { |
|
| 231 | - if (!is_numeric($this->cur_page)) { |
|
| 232 | - // First get the actual page, by default 1 |
|
| 233 | - $cur_page = isset($_GET[$this->get_name]) ? $_GET[$this->get_name] : 1; |
|
| 234 | - $this->original_page = $cur_page; |
|
| 226 | + /** |
|
| 227 | + * @name get |
|
| 228 | + * @tutorial This function is autoloaded, it get the current page and filter number to avoid hackers |
|
| 229 | + */ |
|
| 230 | + private function get() { |
|
| 231 | + if (!is_numeric($this->cur_page)) { |
|
| 232 | + // First get the actual page, by default 1 |
|
| 233 | + $cur_page = isset($_GET[$this->get_name]) ? $_GET[$this->get_name] : 1; |
|
| 234 | + $this->original_page = $cur_page; |
|
| 235 | 235 | |
| 236 | - // Filter values |
|
| 237 | - if (!is_numeric($cur_page) or $cur_page < 1) $cur_page = 1; |
|
| 236 | + // Filter values |
|
| 237 | + if (!is_numeric($cur_page) or $cur_page < 1) $cur_page = 1; |
|
| 238 | 238 | |
| 239 | - // Set new filtered values (is faster this method) |
|
| 240 | - $this->cur_page = $cur_page; |
|
| 241 | - } else { |
|
| 242 | - $this->original_page = $cur_page; |
|
| 243 | - } |
|
| 244 | - } |
|
| 239 | + // Set new filtered values (is faster this method) |
|
| 240 | + $this->cur_page = $cur_page; |
|
| 241 | + } else { |
|
| 242 | + $this->original_page = $cur_page; |
|
| 243 | + } |
|
| 244 | + } |
|
| 245 | 245 | |
| 246 | - /** |
|
| 247 | - * @name calculate |
|
| 248 | - * @tutorial Do all calcs about current and last page |
|
| 249 | - */ |
|
| 250 | - private function calculate() { |
|
| 251 | - // This vars are very used, so is faster do this |
|
| 252 | - $max_records = $this->max_records; |
|
| 253 | - $records = $this->records; |
|
| 246 | + /** |
|
| 247 | + * @name calculate |
|
| 248 | + * @tutorial Do all calcs about current and last page |
|
| 249 | + */ |
|
| 250 | + private function calculate() { |
|
| 251 | + // This vars are very used, so is faster do this |
|
| 252 | + $max_records = $this->max_records; |
|
| 253 | + $records = $this->records; |
|
| 254 | 254 | |
| 255 | - // Force maxium records loaded (only if is specified by user) |
|
| 256 | - if ($max_records > 0 and $max_records > $total_records) |
|
| 257 | - $this->total_records = $max_records; |
|
| 255 | + // Force maxium records loaded (only if is specified by user) |
|
| 256 | + if ($max_records > 0 and $max_records > $total_records) |
|
| 257 | + $this->total_records = $max_records; |
|
| 258 | 258 | |
| 259 | - // Calculate total pages that have |
|
| 260 | - $total_pages = ceil($this->total_records / $records); |
|
| 259 | + // Calculate total pages that have |
|
| 260 | + $total_pages = ceil($this->total_records / $records); |
|
| 261 | 261 | |
| 262 | - // Is correct current page? |
|
| 263 | - if ($this->cur_page > $total_pages) $this->cur_page = $total_pages; |
|
| 264 | - $this->total_pages = $total_pages; |
|
| 262 | + // Is correct current page? |
|
| 263 | + if ($this->cur_page > $total_pages) $this->cur_page = $total_pages; |
|
| 264 | + $this->total_pages = $total_pages; |
|
| 265 | 265 | |
| 266 | - // Specify LIMIT to do a query |
|
| 267 | - $start = ($this->cur_page - 1) * $records; |
|
| 266 | + // Specify LIMIT to do a query |
|
| 267 | + $start = ($this->cur_page - 1) * $records; |
|
| 268 | 268 | |
| 269 | - // Forcing maixum records to show (only if is specified by user) |
|
| 270 | - if ($max_records > 0 and $records > $max_records) { |
|
| 271 | - $records = $max_records; |
|
| 272 | - $this->records = $records; |
|
| 273 | - } |
|
| 269 | + // Forcing maixum records to show (only if is specified by user) |
|
| 270 | + if ($max_records > 0 and $records > $max_records) { |
|
| 271 | + $records = $max_records; |
|
| 272 | + $this->records = $records; |
|
| 273 | + } |
|
| 274 | 274 | |
| 275 | 275 | |
| 276 | - // Saving changes |
|
| 277 | - $this->first_record = $start; |
|
| 278 | - $this->limit = ' LIMIT '.$start.','.$records.' '; |
|
| 279 | - } |
|
| 276 | + // Saving changes |
|
| 277 | + $this->first_record = $start; |
|
| 278 | + $this->limit = ' LIMIT '.$start.','.$records.' '; |
|
| 279 | + } |
|
| 280 | 280 | |
| 281 | - /** |
|
| 282 | - * @name prepareUrl |
|
| 283 | - * @tutorial It prepare the url to show in each link, specified by user |
|
| 284 | - * If recicle URL is false, it will auto load $url_start and $url_end |
|
| 285 | - */ |
|
| 286 | - private function prepareUrl() { |
|
| 287 | - // This script use three methods to recicle GET depending user selection |
|
| 288 | - if ($this->recicle_url) { |
|
| 289 | - // gonna to recicle the URL |
|
| 290 | - $gets = $this->specific_get; |
|
| 291 | - $get_name = $this->get_name; |
|
| 281 | + /** |
|
| 282 | + * @name prepareUrl |
|
| 283 | + * @tutorial It prepare the url to show in each link, specified by user |
|
| 284 | + * If recicle URL is false, it will auto load $url_start and $url_end |
|
| 285 | + */ |
|
| 286 | + private function prepareUrl() { |
|
| 287 | + // This script use three methods to recicle GET depending user selection |
|
| 288 | + if ($this->recicle_url) { |
|
| 289 | + // gonna to recicle the URL |
|
| 290 | + $gets = $this->specific_get; |
|
| 291 | + $get_name = $this->get_name; |
|
| 292 | 292 | |
| 293 | - // If user specified an array |
|
| 294 | - if (is_array($gets)) { |
|
| 295 | - if (empty($gets)) { |
|
| 296 | - // And is empty, we have to Recicle ALL GET |
|
| 297 | - // To know that page needs to be replaced we will use the "original_page" (the real get) |
|
| 298 | - // Cortamos "pag=2" para obtener lo que va antes y despues, as� poder modificar directamente ese pag=2 por la pagina actual |
|
| 299 | - $query_string = explode($this->get_name.'='.$this->original_page, $_SERVER['QUERY_STRING']); |
|
| 293 | + // If user specified an array |
|
| 294 | + if (is_array($gets)) { |
|
| 295 | + if (empty($gets)) { |
|
| 296 | + // And is empty, we have to Recicle ALL GET |
|
| 297 | + // To know that page needs to be replaced we will use the "original_page" (the real get) |
|
| 298 | + // Cortamos "pag=2" para obtener lo que va antes y despues, as� poder modificar directamente ese pag=2 por la pagina actual |
|
| 299 | + $query_string = explode($this->get_name.'='.$this->original_page, $_SERVER['QUERY_STRING']); |
|
| 300 | 300 | |
| 301 | - // How start the new URL? To know it, we need to see the last character from current string |
|
| 302 | - if (!in_array(substr($query_string[0], -1), array('?', '&'))) { |
|
| 303 | - // Current string haven't any at end and it isn't "&" or "?" ? |
|
| 304 | - // If initial string have one character at least it means that not is the first index |
|
| 305 | - if (isset($query_string[0][0])) $this->url_start = '?'.$query_string[0].'&'; |
|
| 306 | - else $this->url_start = '?'.$query_string[0]; |
|
| 307 | - } else { |
|
| 308 | - // Current string already have ? or &, |
|
| 309 | - $this->url_start = '?'.$query_string[0]; |
|
| 310 | - } |
|
| 301 | + // How start the new URL? To know it, we need to see the last character from current string |
|
| 302 | + if (!in_array(substr($query_string[0], -1), array('?', '&'))) { |
|
| 303 | + // Current string haven't any at end and it isn't "&" or "?" ? |
|
| 304 | + // If initial string have one character at least it means that not is the first index |
|
| 305 | + if (isset($query_string[0][0])) $this->url_start = '?'.$query_string[0].'&'; |
|
| 306 | + else $this->url_start = '?'.$query_string[0]; |
|
| 307 | + } else { |
|
| 308 | + // Current string already have ? or &, |
|
| 309 | + $this->url_start = '?'.$query_string[0]; |
|
| 310 | + } |
|
| 311 | 311 | |
| 312 | - $this->url_end = isset($query_string[1]) ? $query_string[1] : ''; |
|
| 313 | - } else { |
|
| 314 | - // Only specifics GET, reading all and finally leave in the same order |
|
| 315 | - // With this we can clean all GET that we don't need (like hacker attempts) |
|
| 316 | - $tmp = ''; |
|
| 317 | - $tmp_start = ''; // If we found the current page, we move here all $tmp |
|
| 318 | - foreach ($gets as $get) { |
|
| 319 | - if ($get != $get_name) { |
|
| 320 | - // Trying to get the GET |
|
| 321 | - if (isset($_GET[$get])) $tmp .= $get.'='.$_GET[$get].'&'; |
|
| 322 | - } else { |
|
| 323 | - // Pour the $tmp content to $tmp_start |
|
| 324 | - if ($tmp_start == '') $tmp_start .= '?'; |
|
| 325 | - $tmp_start .= $tmp; |
|
| 326 | - $tmp = ''; |
|
| 327 | - } |
|
| 328 | - } |
|
| 312 | + $this->url_end = isset($query_string[1]) ? $query_string[1] : ''; |
|
| 313 | + } else { |
|
| 314 | + // Only specifics GET, reading all and finally leave in the same order |
|
| 315 | + // With this we can clean all GET that we don't need (like hacker attempts) |
|
| 316 | + $tmp = ''; |
|
| 317 | + $tmp_start = ''; // If we found the current page, we move here all $tmp |
|
| 318 | + foreach ($gets as $get) { |
|
| 319 | + if ($get != $get_name) { |
|
| 320 | + // Trying to get the GET |
|
| 321 | + if (isset($_GET[$get])) $tmp .= $get.'='.$_GET[$get].'&'; |
|
| 322 | + } else { |
|
| 323 | + // Pour the $tmp content to $tmp_start |
|
| 324 | + if ($tmp_start == '') $tmp_start .= '?'; |
|
| 325 | + $tmp_start .= $tmp; |
|
| 326 | + $tmp = ''; |
|
| 327 | + } |
|
| 328 | + } |
|
| 329 | 329 | |
| 330 | - // Finally, write the changes in the object |
|
| 331 | - if ($tmp_start != '') { |
|
| 332 | - // If have start and end |
|
| 333 | - $this->url_start = $tmp_start; |
|
| 334 | - $this->url_end = $tmp; |
|
| 335 | - } |
|
| 336 | - else $this->url_start = '?'.$tmp; |
|
| 337 | - } |
|
| 338 | - } else{ |
|
| 339 | - // Non recicle |
|
| 340 | - $this->url_start = '?'; |
|
| 341 | - $this->url_end = ''; |
|
| 342 | - } |
|
| 330 | + // Finally, write the changes in the object |
|
| 331 | + if ($tmp_start != '') { |
|
| 332 | + // If have start and end |
|
| 333 | + $this->url_start = $tmp_start; |
|
| 334 | + $this->url_end = $tmp; |
|
| 335 | + } |
|
| 336 | + else $this->url_start = '?'.$tmp; |
|
| 337 | + } |
|
| 338 | + } else{ |
|
| 339 | + // Non recicle |
|
| 340 | + $this->url_start = '?'; |
|
| 341 | + $this->url_end = ''; |
|
| 342 | + } |
|
| 343 | 343 | |
| 344 | - // Add the pagination |
|
| 345 | - $this->url_start .= $this->get_name.'='; |
|
| 346 | - } |
|
| 347 | - } |
|
| 344 | + // Add the pagination |
|
| 345 | + $this->url_start .= $this->get_name.'='; |
|
| 346 | + } |
|
| 347 | + } |
|
| 348 | 348 | } |
| 349 | 349 | ?> |
| 350 | 350 | \ No newline at end of file |
@@ -189,35 +189,55 @@ discard block |
||
| 189 | 189 | $start = $cur_page - $this->max_links; |
| 190 | 190 | $end = $cur_page + $this->max_links; |
| 191 | 191 | |
| 192 | - if ($start < 1) $start = 1; |
|
| 193 | - if ($end > $this->total_pages) $end = $this->total_pages; |
|
| 192 | + if ($start < 1) { |
|
| 193 | + $start = 1; |
|
| 194 | + } |
|
| 195 | + if ($end > $this->total_pages) { |
|
| 196 | + $end = $this->total_pages; |
|
| 197 | + } |
|
| 194 | 198 | |
| 195 | 199 | // Showing all clickable pages (create div if class is defined) |
| 196 | - if ($this->style != '') $r = '<div class="'.$this->style.'">'; |
|
| 197 | - else $r = ''; |
|
| 200 | + if ($this->style != '') { |
|
| 201 | + $r = '<div class="'.$this->style.'">'; |
|
| 202 | + } else { |
|
| 203 | + $r = ''; |
|
| 204 | + } |
|
| 198 | 205 | |
| 199 | 206 | |
| 200 | 207 | // First / previous |
| 201 | 208 | if ($this->cur_page > 1) { |
| 202 | - if ($this->first != '') $r .= '<a class="first" href="' . $url_start . '1' . $url_end . '">'.$this->first.'</a> '; |
|
| 203 | - if ($this->previous != '') $r .= '<a class="previous" href="' . $url_start . ($cur_page - 1) . $url_end . '">'.$this->previous.'</a> '; |
|
| 209 | + if ($this->first != '') { |
|
| 210 | + $r .= '<a class="first" href="' . $url_start . '1' . $url_end . '">'.$this->first.'</a> '; |
|
| 211 | + } |
|
| 212 | + if ($this->previous != '') { |
|
| 213 | + $r .= '<a class="previous" href="' . $url_start . ($cur_page - 1) . $url_end . '">'.$this->previous.'</a> '; |
|
| 214 | + } |
|
| 204 | 215 | } |
| 205 | 216 | |
| 206 | 217 | // You can optimize this separating BEFORE and AFTER current page in two for (to avoid load "if" in each loop) |
| 207 | 218 | // but it would be difficult on changes |
| 208 | 219 | for ($n=$start; $n<=$end; $n++) { |
| 209 | - if ($n != $cur_page) $r .= '<a class="link" href="'. $url_start . $n . $url_end . '">'.$n.'</a> '; |
|
| 210 | - else $r .= '<a class="current">'.$n.'</a> '; |
|
| 220 | + if ($n != $cur_page) { |
|
| 221 | + $r .= '<a class="link" href="'. $url_start . $n . $url_end . '">'.$n.'</a> '; |
|
| 222 | + } else { |
|
| 223 | + $r .= '<a class="current">'.$n.'</a> '; |
|
| 224 | + } |
|
| 211 | 225 | } |
| 212 | 226 | |
| 213 | 227 | // next / last |
| 214 | 228 | if ($this->cur_page < $this->total_pages) { |
| 215 | - if ($this->next != '') $r .= '<a class="next" href="' . $url_start . ($cur_page + 1) . $url_end . '">'.$this->next.'</a> '; |
|
| 216 | - if ($this->last != '') $r .= '<a class="last" href="' . $url_start . $this->total_pages . $url_end .'">'.$this->last.'</a> '; |
|
| 229 | + if ($this->next != '') { |
|
| 230 | + $r .= '<a class="next" href="' . $url_start . ($cur_page + 1) . $url_end . '">'.$this->next.'</a> '; |
|
| 231 | + } |
|
| 232 | + if ($this->last != '') { |
|
| 233 | + $r .= '<a class="last" href="' . $url_start . $this->total_pages . $url_end .'">'.$this->last.'</a> '; |
|
| 234 | + } |
|
| 217 | 235 | } |
| 218 | 236 | |
| 219 | 237 | // End div (if exist) |
| 220 | - if ($this->style != '') $r .= '</div>'; |
|
| 238 | + if ($this->style != '') { |
|
| 239 | + $r .= '</div>'; |
|
| 240 | + } |
|
| 221 | 241 | |
| 222 | 242 | return $r; |
| 223 | 243 | } |
@@ -234,7 +254,9 @@ discard block |
||
| 234 | 254 | $this->original_page = $cur_page; |
| 235 | 255 | |
| 236 | 256 | // Filter values |
| 237 | - if (!is_numeric($cur_page) or $cur_page < 1) $cur_page = 1; |
|
| 257 | + if (!is_numeric($cur_page) or $cur_page < 1) { |
|
| 258 | + $cur_page = 1; |
|
| 259 | + } |
|
| 238 | 260 | |
| 239 | 261 | // Set new filtered values (is faster this method) |
| 240 | 262 | $this->cur_page = $cur_page; |
@@ -253,14 +275,17 @@ discard block |
||
| 253 | 275 | $records = $this->records; |
| 254 | 276 | |
| 255 | 277 | // Force maxium records loaded (only if is specified by user) |
| 256 | - if ($max_records > 0 and $max_records > $total_records) |
|
| 257 | - $this->total_records = $max_records; |
|
| 278 | + if ($max_records > 0 and $max_records > $total_records) { |
|
| 279 | + $this->total_records = $max_records; |
|
| 280 | + } |
|
| 258 | 281 | |
| 259 | 282 | // Calculate total pages that have |
| 260 | 283 | $total_pages = ceil($this->total_records / $records); |
| 261 | 284 | |
| 262 | 285 | // Is correct current page? |
| 263 | - if ($this->cur_page > $total_pages) $this->cur_page = $total_pages; |
|
| 286 | + if ($this->cur_page > $total_pages) { |
|
| 287 | + $this->cur_page = $total_pages; |
|
| 288 | + } |
|
| 264 | 289 | $this->total_pages = $total_pages; |
| 265 | 290 | |
| 266 | 291 | // Specify LIMIT to do a query |
@@ -302,8 +327,11 @@ discard block |
||
| 302 | 327 | if (!in_array(substr($query_string[0], -1), array('?', '&'))) { |
| 303 | 328 | // Current string haven't any at end and it isn't "&" or "?" ? |
| 304 | 329 | // If initial string have one character at least it means that not is the first index |
| 305 | - if (isset($query_string[0][0])) $this->url_start = '?'.$query_string[0].'&'; |
|
| 306 | - else $this->url_start = '?'.$query_string[0]; |
|
| 330 | + if (isset($query_string[0][0])) { |
|
| 331 | + $this->url_start = '?'.$query_string[0].'&'; |
|
| 332 | + } else { |
|
| 333 | + $this->url_start = '?'.$query_string[0]; |
|
| 334 | + } |
|
| 307 | 335 | } else { |
| 308 | 336 | // Current string already have ? or &, |
| 309 | 337 | $this->url_start = '?'.$query_string[0]; |
@@ -318,10 +346,14 @@ discard block |
||
| 318 | 346 | foreach ($gets as $get) { |
| 319 | 347 | if ($get != $get_name) { |
| 320 | 348 | // Trying to get the GET |
| 321 | - if (isset($_GET[$get])) $tmp .= $get.'='.$_GET[$get].'&'; |
|
| 349 | + if (isset($_GET[$get])) { |
|
| 350 | + $tmp .= $get.'='.$_GET[$get].'&'; |
|
| 351 | + } |
|
| 322 | 352 | } else { |
| 323 | 353 | // Pour the $tmp content to $tmp_start |
| 324 | - if ($tmp_start == '') $tmp_start .= '?'; |
|
| 354 | + if ($tmp_start == '') { |
|
| 355 | + $tmp_start .= '?'; |
|
| 356 | + } |
|
| 325 | 357 | $tmp_start .= $tmp; |
| 326 | 358 | $tmp = ''; |
| 327 | 359 | } |
@@ -332,8 +364,9 @@ discard block |
||
| 332 | 364 | // If have start and end |
| 333 | 365 | $this->url_start = $tmp_start; |
| 334 | 366 | $this->url_end = $tmp; |
| 367 | + } else { |
|
| 368 | + $this->url_start = '?'.$tmp; |
|
| 335 | 369 | } |
| 336 | - else $this->url_start = '?'.$tmp; |
|
| 337 | 370 | } |
| 338 | 371 | } else{ |
| 339 | 372 | // Non recicle |
@@ -31,10 +31,10 @@ discard block |
||
| 31 | 31 | |
| 32 | 32 | //xss funciones de mitigacion |
| 33 | 33 | function xsseguro($texto,$encoding='UTF-8'){ |
| 34 | - return htmlspecialchars($texto,ENT_QUOTES | ENT_HTML401,$encoding); |
|
| 34 | + return htmlspecialchars($texto,ENT_QUOTES | ENT_HTML401,$encoding); |
|
| 35 | 35 | } |
| 36 | 36 | function xecho($texto){ |
| 37 | - echo xsseguro($texto); |
|
| 37 | + echo xsseguro($texto); |
|
| 38 | 38 | } |
| 39 | 39 | |
| 40 | 40 | public function filtrarTexto($texto){ |
@@ -54,7 +54,7 @@ discard block |
||
| 54 | 54 | $longitudCaracteres = strlen($caracteres); |
| 55 | 55 | $cadenaAleatoria = ''; |
| 56 | 56 | for ($i = 0; $i < $length; $i++) { |
| 57 | - $cadenaAleatoria .= $caracteres[rand(0, $longitudCaracteres - 1)]; |
|
| 57 | + $cadenaAleatoria .= $caracteres[rand(0, $longitudCaracteres - 1)]; |
|
| 58 | 58 | } |
| 59 | 59 | return $cadenaAleatoria; |
| 60 | 60 | } |
@@ -80,14 +80,14 @@ discard block |
||
| 80 | 80 | |
| 81 | 81 | function obtenerDireccionIP(){ |
| 82 | 82 | if (!empty($_SERVER ['HTTP_CLIENT_IP'] )) |
| 83 | - $ip=$_SERVER ['HTTP_CLIENT_IP']; |
|
| 83 | + $ip=$_SERVER ['HTTP_CLIENT_IP']; |
|
| 84 | 84 | elseif (!empty($_SERVER ['HTTP_X_FORWARDED_FOR'] )) |
| 85 | - $ip=$_SERVER ['HTTP_X_FORWARDED_FOR']; |
|
| 85 | + $ip=$_SERVER ['HTTP_X_FORWARDED_FOR']; |
|
| 86 | 86 | else |
| 87 | - $ip=$_SERVER ['REMOTE_ADDR']; |
|
| 87 | + $ip=$_SERVER ['REMOTE_ADDR']; |
|
| 88 | 88 | |
| 89 | 89 | return $ip; |
| 90 | - } |
|
| 90 | + } |
|
| 91 | 91 | |
| 92 | 92 | function restringirIp($ip){ |
| 93 | 93 | $ipCliente = $this->obtenerDireccionIP(); |
@@ -101,7 +101,7 @@ discard block |
||
| 101 | 101 | } |
| 102 | 102 | } |
| 103 | 103 | |
| 104 | - function restringirConjuntoIps($ips){ |
|
| 104 | + function restringirConjuntoIps($ips){ |
|
| 105 | 105 | $ipCliente = obtenerDireccionIP(); |
| 106 | 106 | |
| 107 | 107 | if (in_array($ipCliente,$ips)){ |
@@ -111,9 +111,9 @@ discard block |
||
| 111 | 111 | header('location: http://direccion_envio_salida'); |
| 112 | 112 | exit; |
| 113 | 113 | } |
| 114 | - } |
|
| 114 | + } |
|
| 115 | 115 | |
| 116 | - function restringirRango(){ |
|
| 116 | + function restringirRango(){ |
|
| 117 | 117 | $ipCliente = obtenerDireccionIP(); |
| 118 | 118 | |
| 119 | 119 | if(substr($ipCliente, 0, 8 ) == "150.214."){ |
@@ -123,20 +123,20 @@ discard block |
||
| 123 | 123 | header('location: http://direccion_envio_salida'); |
| 124 | 124 | exit; |
| 125 | 125 | } |
| 126 | - } |
|
| 126 | + } |
|
| 127 | 127 | |
| 128 | 128 | |
| 129 | 129 | /** |
| 130 | - * |
|
| 131 | - * @strip injection chars from email headers |
|
| 132 | - * |
|
| 133 | - * @param string $string |
|
| 134 | - * |
|
| 135 | - * return string |
|
| 136 | - * |
|
| 137 | - */ |
|
| 130 | + * |
|
| 131 | + * @strip injection chars from email headers |
|
| 132 | + * |
|
| 133 | + * @param string $string |
|
| 134 | + * |
|
| 135 | + * return string |
|
| 136 | + * |
|
| 137 | + */ |
|
| 138 | 138 | function emailSeguro($cadena) { |
| 139 | - return preg_replace( '((?:\n|\r|\t|%0A|%0D|%08|%09)+)i' , '', $cadena ); |
|
| 139 | + return preg_replace( '((?:\n|\r|\t|%0A|%0D|%08|%09)+)i' , '', $cadena ); |
|
| 140 | 140 | } |
| 141 | 141 | |
| 142 | 142 | /*** example usage |
@@ -79,12 +79,13 @@ discard block |
||
| 79 | 79 | } |
| 80 | 80 | |
| 81 | 81 | function obtenerDireccionIP(){ |
| 82 | - if (!empty($_SERVER ['HTTP_CLIENT_IP'] )) |
|
| 83 | - $ip=$_SERVER ['HTTP_CLIENT_IP']; |
|
| 84 | - elseif (!empty($_SERVER ['HTTP_X_FORWARDED_FOR'] )) |
|
| 85 | - $ip=$_SERVER ['HTTP_X_FORWARDED_FOR']; |
|
| 86 | - else |
|
| 87 | - $ip=$_SERVER ['REMOTE_ADDR']; |
|
| 82 | + if (!empty($_SERVER ['HTTP_CLIENT_IP'] )) { |
|
| 83 | + $ip=$_SERVER ['HTTP_CLIENT_IP']; |
|
| 84 | + } elseif (!empty($_SERVER ['HTTP_X_FORWARDED_FOR'] )) { |
|
| 85 | + $ip=$_SERVER ['HTTP_X_FORWARDED_FOR']; |
|
| 86 | + } else { |
|
| 87 | + $ip=$_SERVER ['REMOTE_ADDR']; |
|
| 88 | + } |
|
| 88 | 89 | |
| 89 | 90 | return $ip; |
| 90 | 91 | } |
@@ -94,8 +95,7 @@ discard block |
||
| 94 | 95 | |
| 95 | 96 | if($ipCliente == $ip){ |
| 96 | 97 | return true; |
| 97 | - } |
|
| 98 | - else{ |
|
| 98 | + } else{ |
|
| 99 | 99 | header('location: http://www.tusitioweb/redireccion'); |
| 100 | 100 | exit; |
| 101 | 101 | } |
@@ -106,8 +106,7 @@ discard block |
||
| 106 | 106 | |
| 107 | 107 | if (in_array($ipCliente,$ips)){ |
| 108 | 108 | return true; |
| 109 | - } |
|
| 110 | - else{ |
|
| 109 | + } else{ |
|
| 111 | 110 | header('location: http://direccion_envio_salida'); |
| 112 | 111 | exit; |
| 113 | 112 | } |
@@ -118,8 +117,7 @@ discard block |
||
| 118 | 117 | |
| 119 | 118 | if(substr($ipCliente, 0, 8 ) == "150.214."){ |
| 120 | 119 | return true; |
| 121 | - } |
|
| 122 | - else{ |
|
| 120 | + } else{ |
|
| 123 | 121 | header('location: http://direccion_envio_salida'); |
| 124 | 122 | exit; |
| 125 | 123 | } |
@@ -31,5 +31,5 @@ |
||
| 31 | 31 | |
| 32 | 32 | $dominio = "http://www.my-site-domain.com/"; |
| 33 | 33 | return $dominio; |
| 34 | - } |
|
| 34 | + } |
|
| 35 | 35 | } |
| 36 | 36 | \ No newline at end of file |
@@ -43,15 +43,13 @@ |
||
| 43 | 43 | |
| 44 | 44 | if(is_callable(array($controlador, $metodo))){ |
| 45 | 45 | $metodo = $peticion->getMetodo(); |
| 46 | - } |
|
| 47 | - else{ |
|
| 46 | + } else{ |
|
| 48 | 47 | $metodo = 'index'; |
| 49 | 48 | } |
| 50 | 49 | |
| 51 | 50 | if(isset($args)){ |
| 52 | 51 | call_user_func_array(array($controlador, $metodo), $args); |
| 53 | - } |
|
| 54 | - else{ |
|
| 52 | + } else{ |
|
| 55 | 53 | call_user_func(array($controlador, $metodo)); |
| 56 | 54 | } |
| 57 | 55 | |
@@ -38,7 +38,7 @@ discard block |
||
| 38 | 38 | $rutaLib = RUTA_LIBS . $libreria . '.php'; |
| 39 | 39 | if(is_readable($rutaLib)){ |
| 40 | 40 | require_once $rutaLib; |
| 41 | - //echo 'libreria cargada'; |
|
| 41 | + //echo 'libreria cargada'; |
|
| 42 | 42 | } |
| 43 | 43 | else { |
| 44 | 44 | throw new Exception("houston tenemos un problema! al cargar libreria"); |
@@ -47,12 +47,12 @@ discard block |
||
| 47 | 47 | |
| 48 | 48 | protected function cargaModelo($modelo){ |
| 49 | 49 | $modelo=$modelo.'Modelo'; |
| 50 | - $rutaMod = RUTA_MOD . $modelo . '.php'; |
|
| 50 | + $rutaMod = RUTA_MOD . $modelo . '.php'; |
|
| 51 | 51 | if(is_readable($rutaMod)){ |
| 52 | 52 | require_once $rutaMod; |
| 53 | 53 | $modelo = new $modelo; |
| 54 | 54 | return $modelo; |
| 55 | - //echo 'modelo cargado'; |
|
| 55 | + //echo 'modelo cargado'; |
|
| 56 | 56 | } |
| 57 | 57 | else { |
| 58 | 58 | //echo $rutaMod; |
@@ -64,10 +64,10 @@ discard block |
||
| 64 | 64 | } |
| 65 | 65 | |
| 66 | 66 | protected function cargaAyudante($ayudante){ |
| 67 | - $rutaAyudante = RUTA_AYUDANTES . $ayudante . '.php'; |
|
| 67 | + $rutaAyudante = RUTA_AYUDANTES . $ayudante . '.php'; |
|
| 68 | 68 | if(is_readable($rutaAyudante)){ |
| 69 | 69 | require_once $rutaAyudante; |
| 70 | - //echo 'libreria cargada'; |
|
| 70 | + //echo 'libreria cargada'; |
|
| 71 | 71 | } |
| 72 | 72 | else { |
| 73 | 73 | throw new Exception("houston tenemos un problema! al cargar ayudante"); |
@@ -39,8 +39,7 @@ discard block |
||
| 39 | 39 | if(is_readable($rutaLib)){ |
| 40 | 40 | require_once $rutaLib; |
| 41 | 41 | //echo 'libreria cargada'; |
| 42 | - } |
|
| 43 | - else { |
|
| 42 | + } else { |
|
| 44 | 43 | throw new Exception("houston tenemos un problema! al cargar libreria"); |
| 45 | 44 | } |
| 46 | 45 | } |
@@ -53,8 +52,7 @@ discard block |
||
| 53 | 52 | $modelo = new $modelo; |
| 54 | 53 | return $modelo; |
| 55 | 54 | //echo 'modelo cargado'; |
| 56 | - } |
|
| 57 | - else { |
|
| 55 | + } else { |
|
| 58 | 56 | //echo $rutaMod; |
| 59 | 57 | |
| 60 | 58 | |
@@ -68,8 +66,7 @@ discard block |
||
| 68 | 66 | if(is_readable($rutaAyudante)){ |
| 69 | 67 | require_once $rutaAyudante; |
| 70 | 68 | //echo 'libreria cargada'; |
| 71 | - } |
|
| 72 | - else { |
|
| 69 | + } else { |
|
| 73 | 70 | throw new Exception("houston tenemos un problema! al cargar ayudante"); |
| 74 | 71 | } |
| 75 | 72 | } |