| @@ -4,6 +4,6 @@ | ||
| 4 | 4 |  define('DATABASE_USER', "nelson");  | 
| 5 | 5 |  define('DATABASE_PASSWORD', "secret");  | 
| 6 | 6 |  define('DATABASE_PARAMETERS', [ | 
| 7 | - PDO::ATTR_PERSISTENT => true, | |
| 7 | + PDO::ATTR_PERSISTENT => true, | |
| 8 | 8 | PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION, | 
| 9 | 9 | ]); | 
| 10 | 10 | \ No newline at end of file | 
| @@ -8,49 +8,49 @@ | ||
| 8 | 8 | */ | 
| 9 | 9 | class Session | 
| 10 | 10 |  { | 
| 11 | - /** | |
| 12 | - * Permite obtener una entrada desde la variable $_SESSION | |
| 13 | - * de acuerdo a su clave $key | |
| 14 | - * @param $key | |
| 15 | - * @return mixed | |
| 16 | - */ | |
| 17 | - public static function get($key) | |
| 18 | -	{ | |
| 19 | -		if (empty($_SESSION[$key])) { | |
| 20 | - return null; | |
| 21 | - } | |
| 11 | + /** | |
| 12 | + * Permite obtener una entrada desde la variable $_SESSION | |
| 13 | + * de acuerdo a su clave $key | |
| 14 | + * @param $key | |
| 15 | + * @return mixed | |
| 16 | + */ | |
| 17 | + public static function get($key) | |
| 18 | +    { | |
| 19 | +        if (empty($_SESSION[$key])) { | |
| 20 | + return null; | |
| 21 | + } | |
| 22 | 22 | |
| 23 | - return $_SESSION[$key]; | |
| 24 | - } | |
| 23 | + return $_SESSION[$key]; | |
| 24 | + } | |
| 25 | 25 | |
| 26 | - /** | |
| 27 | - * Permite crear una entrada en la variable $_SESSION | |
| 28 | - * de acuerdo a su clave $key | |
| 29 | - * @param $key | |
| 30 | - * @param mixed $value | |
| 31 | - * @return void | |
| 32 | - */ | |
| 33 | - public static function set($key, $value) | |
| 34 | -	{ | |
| 35 | - $_SESSION[$key] = $value; | |
| 36 | - } | |
| 26 | + /** | |
| 27 | + * Permite crear una entrada en la variable $_SESSION | |
| 28 | + * de acuerdo a su clave $key | |
| 29 | + * @param $key | |
| 30 | + * @param mixed $value | |
| 31 | + * @return void | |
| 32 | + */ | |
| 33 | + public static function set($key, $value) | |
| 34 | +    { | |
| 35 | + $_SESSION[$key] = $value; | |
| 36 | + } | |
| 37 | 37 | |
| 38 | - /** | |
| 39 | - * Permite eliminar una entrada en la variable $_SESSION | |
| 40 | - * de acuerdo a su clave $key | |
| 41 | - * @param $key | |
| 42 | - * @return void | |
| 43 | - */ | |
| 44 | - public static function delete($key) | |
| 45 | -	{ | |
| 46 | - unset($_SESSION[$key]); | |
| 47 | - } | |
| 38 | + /** | |
| 39 | + * Permite eliminar una entrada en la variable $_SESSION | |
| 40 | + * de acuerdo a su clave $key | |
| 41 | + * @param $key | |
| 42 | + * @return void | |
| 43 | + */ | |
| 44 | + public static function delete($key) | |
| 45 | +    { | |
| 46 | + unset($_SESSION[$key]); | |
| 47 | + } | |
| 48 | 48 | |
| 49 | - /** | |
| 50 | - * Permite cerrar la sesión | |
| 51 | - */ | |
| 52 | - public static function destroy() | |
| 53 | -	{ | |
| 54 | - session_destroy(); | |
| 55 | - } | |
| 49 | + /** | |
| 50 | + * Permite cerrar la sesión | |
| 51 | + */ | |
| 52 | + public static function destroy() | |
| 53 | +    { | |
| 54 | + session_destroy(); | |
| 55 | + } | |
| 56 | 56 | } | 
| @@ -6,7 +6,7 @@ discard block | ||
| 6 | 6 | * @return string | 
| 7 | 7 | */ | 
| 8 | 8 |  function javascript_include_tag($src){ | 
| 9 | - return "<script type='text/javascript' src='".PUBLIC_PATH."js/$src.js'></script>\r\n"; | |
| 9 | + return "<script type='text/javascript' src='".PUBLIC_PATH."js/$src.js'></script>\r\n"; | |
| 10 | 10 | } | 
| 11 | 11 | |
| 12 | 12 | /** | 
| @@ -15,7 +15,7 @@ discard block | ||
| 15 | 15 | * @return string | 
| 16 | 16 | */ | 
| 17 | 17 |  function stylesheet_link($src=''){ | 
| 18 | - return "<link rel='stylesheet' type='text/css' href='".PUBLIC_PATH."css/$src.css'/>\r\n"; | |
| 18 | + return "<link rel='stylesheet' type='text/css' href='".PUBLIC_PATH."css/$src.css'/>\r\n"; | |
| 19 | 19 | } | 
| 20 | 20 | |
| 21 | 21 | /** | 
| @@ -26,7 +26,7 @@ discard block | ||
| 26 | 26 | * @return string | 
| 27 | 27 | */ | 
| 28 | 28 |  function link_to($action, $text, $attributes=''){ | 
| 29 | - return "<a href='".PUBLIC_PATH."$action' $attributes>$text</a>"; | |
| 29 | + return "<a href='".PUBLIC_PATH."$action' $attributes>$text</a>"; | |
| 30 | 30 | } | 
| 31 | 31 | |
| 32 | 32 | /** | 
| @@ -36,7 +36,7 @@ discard block | ||
| 36 | 36 | * @return string | 
| 37 | 37 | */ | 
| 38 | 38 |  function img_tag($img, $attributes=''){ | 
| 39 | - return "<img src='".PUBLIC_PATH."img/$img' $attributes />\r\n"; | |
| 39 | + return "<img src='".PUBLIC_PATH."img/$img' $attributes />\r\n"; | |
| 40 | 40 | } | 
| 41 | 41 | |
| 42 | 42 | /** | 
| @@ -46,7 +46,7 @@ discard block | ||
| 46 | 46 | * @return string | 
| 47 | 47 | */ | 
| 48 | 48 |  function form_tag($action, $attributes=''){ | 
| 49 | - return "<form action='".PUBLIC_PATH."$action' $attributes>\r\n"; | |
| 49 | + return "<form action='".PUBLIC_PATH."$action' $attributes>\r\n"; | |
| 50 | 50 | } | 
| 51 | 51 | |
| 52 | 52 | /** | 
| @@ -54,7 +54,7 @@ discard block | ||
| 54 | 54 | * @return string | 
| 55 | 55 | */ | 
| 56 | 56 |  function end_form_tag(){ | 
| 57 | - return "</form>\r\n"; | |
| 57 | + return "</form>\r\n"; | |
| 58 | 58 | } | 
| 59 | 59 | |
| 60 | 60 | /** | 
| @@ -64,7 +64,7 @@ discard block | ||
| 64 | 64 | * @return string | 
| 65 | 65 | */ | 
| 66 | 66 |  function submit_tag($caption, $attributes=''){ | 
| 67 | - return "<input type='submit' value='$caption' $attributes />\r\n"; | |
| 67 | + return "<input type='submit' value='$caption' $attributes />\r\n"; | |
| 68 | 68 | } | 
| 69 | 69 | |
| 70 | 70 | /** | 
| @@ -75,7 +75,7 @@ discard block | ||
| 75 | 75 | * @return string | 
| 76 | 76 | */ | 
| 77 | 77 |  function button_tag($caption, $type='button', $attributes=''){ | 
| 78 | - return "<button type='$type' $attributes>$caption</button>\r\n"; | |
| 78 | + return "<button type='$type' $attributes>$caption</button>\r\n"; | |
| 79 | 79 | } | 
| 80 | 80 | |
| 81 | 81 | /** | 
| @@ -85,13 +85,13 @@ discard block | ||
| 85 | 85 | */ | 
| 86 | 86 | function get_field_name_and_id($name) | 
| 87 | 87 |  { | 
| 88 | - $id=""; | |
| 89 | -	if (strpos($name, ".") != false) { | |
| 90 | -		$items = explode(".", $name); | |
| 91 | -		$id=" id='{$items[0]}_{$items[1]}' "; | |
| 92 | - $name = $items[0]."[".$items[1]."]"; | |
| 93 | - } | |
| 94 | - return [$id, $name]; | |
| 88 | + $id=""; | |
| 89 | +    if (strpos($name, ".") != false) { | |
| 90 | +        $items = explode(".", $name); | |
| 91 | +        $id=" id='{$items[0]}_{$items[1]}' "; | |
| 92 | + $name = $items[0]."[".$items[1]."]"; | |
| 93 | + } | |
| 94 | + return [$id, $name]; | |
| 95 | 95 | } | 
| 96 | 96 | |
| 97 | 97 | /** | 
| @@ -102,9 +102,9 @@ discard block | ||
| 102 | 102 | * @return string | 
| 103 | 103 | */ | 
| 104 | 104 |  function text_field_tag($name, $value='', $attributes=''){ | 
| 105 | - list($id, $name) = get_field_name_and_id($name); | |
| 105 | + list($id, $name) = get_field_name_and_id($name); | |
| 106 | 106 | |
| 107 | - return "<input type='text' name='$name' $id value='$value' $attributes />\r\n"; | |
| 107 | + return "<input type='text' name='$name' $id value='$value' $attributes />\r\n"; | |
| 108 | 108 | } | 
| 109 | 109 | |
| 110 | 110 | /** | 
| @@ -115,9 +115,9 @@ discard block | ||
| 115 | 115 | * @return string | 
| 116 | 116 | */ | 
| 117 | 117 |  function password_field_tag($name, $value='', $attributes=''){ | 
| 118 | - list($id, $name) = get_field_name_and_id($name); | |
| 118 | + list($id, $name) = get_field_name_and_id($name); | |
| 119 | 119 | |
| 120 | - return "<input type='password' name='$name' $id value='$value' $attributes />\r\n"; | |
| 120 | + return "<input type='password' name='$name' $id value='$value' $attributes />\r\n"; | |
| 121 | 121 | } | 
| 122 | 122 | |
| 123 | 123 | /** | 
| @@ -128,9 +128,9 @@ discard block | ||
| 128 | 128 | * @return string | 
| 129 | 129 | */ | 
| 130 | 130 |  function text_area_tag($name, $value='', $attributes=''){ | 
| 131 | - list($id, $name) = get_field_name_and_id($name); | |
| 131 | + list($id, $name) = get_field_name_and_id($name); | |
| 132 | 132 | |
| 133 | - return "<textarea name='$name' $id $attributes>$value</textarea>\r\n"; | |
| 133 | + return "<textarea name='$name' $id $attributes>$value</textarea>\r\n"; | |
| 134 | 134 | } | 
| 135 | 135 | |
| 136 | 136 | /** | 
| @@ -141,9 +141,9 @@ discard block | ||
| 141 | 141 | * @return string | 
| 142 | 142 | */ | 
| 143 | 143 |  function hidden_field_tag($name, $value='', $attributes=''){ | 
| 144 | - list($id, $name) = get_field_name_and_id($name); | |
| 144 | + list($id, $name) = get_field_name_and_id($name); | |
| 145 | 145 | |
| 146 | - return "<input type='hidden' name='$name' $id value='$value' $attributes />\r\n"; | |
| 146 | + return "<input type='hidden' name='$name' $id value='$value' $attributes />\r\n"; | |
| 147 | 147 | } | 
| 148 | 148 | |
| 149 | 149 | /** | 
| @@ -156,9 +156,9 @@ discard block | ||
| 156 | 156 | * @return string | 
| 157 | 157 | */ | 
| 158 | 158 |  function check_box_tag($name, $value, $text, $checked=false, $attributes=''){ | 
| 159 | - list($id, $name) = get_field_name_and_id($name); | |
| 160 | - $checked = $checked == true ? ' checked ' : ''; | |
| 161 | - return "<input type='checkbox' $id name='$name' $checked $attributes value='$value'/>\r\n"; | |
| 159 | + list($id, $name) = get_field_name_and_id($name); | |
| 160 | + $checked = $checked == true ? ' checked ' : ''; | |
| 161 | + return "<input type='checkbox' $id name='$name' $checked $attributes value='$value'/>\r\n"; | |
| 162 | 162 | } | 
| 163 | 163 | |
| 164 | 164 | /** | 
| @@ -170,9 +170,9 @@ discard block | ||
| 170 | 170 | * @return string | 
| 171 | 171 | */ | 
| 172 | 172 |  function radio_button_tag($name, $value, $checked=false, $attributes=''){ | 
| 173 | - list($id, $name) = get_field_name_and_id($name); | |
| 174 | - $checked = $checked == true ? ' checked ' : ''; | |
| 175 | - return "<input type='radio' $id name='$name' $checked $attributes value='$value'/>\r\n"; | |
| 173 | + list($id, $name) = get_field_name_and_id($name); | |
| 174 | + $checked = $checked == true ? ' checked ' : ''; | |
| 175 | + return "<input type='radio' $id name='$name' $checked $attributes value='$value'/>\r\n"; | |
| 176 | 176 | } | 
| 177 | 177 | |
| 178 | 178 | /** | 
| @@ -195,14 +195,14 @@ discard block | ||
| 195 | 195 | * @return string | 
| 196 | 196 | */ | 
| 197 | 197 |  function select_tag($name, $options='', $include_blank=false, $attributes=''){ | 
| 198 | - list($id, $name) = get_field_name_and_id($name); | |
| 198 | + list($id, $name) = get_field_name_and_id($name); | |
| 199 | 199 | |
| 200 | - $code = ""; | |
| 201 | -	if ($include_blank != false) { | |
| 202 | - $code="<option value=''>$include_blank</option>\r\n"; | |
| 203 | - } | |
| 200 | + $code = ""; | |
| 201 | +    if ($include_blank != false) { | |
| 202 | + $code="<option value=''>$include_blank</option>\r\n"; | |
| 203 | + } | |
| 204 | 204 | |
| 205 | - return "<select $id name='$name' $attributes>\r\n$code$options</select>\r\n"; | |
| 205 | + return "<select $id name='$name' $attributes>\r\n$code$options</select>\r\n"; | |
| 206 | 206 | |
| 207 | 207 | } | 
| 208 | 208 | |
| @@ -216,15 +216,15 @@ discard block | ||
| 216 | 216 | */ | 
| 217 | 217 | function options_for_dbselect($data, $show, $value, $selected='') | 
| 218 | 218 |  { | 
| 219 | - $code=""; | |
| 220 | -	foreach($data as $item) { | |
| 221 | - $selected_tag=""; | |
| 222 | -		if ($selected == $item[$value]){ | |
| 223 | - $selected_tag = " selected='selected' "; | |
| 224 | - } | |
| 225 | -		$code.="<option value='{$item[$value]}' $selected_tag>{$item[$show]}</option>\r\n"; | |
| 226 | - } | |
| 227 | - return $code; | |
| 219 | + $code=""; | |
| 220 | +    foreach($data as $item) { | |
| 221 | + $selected_tag=""; | |
| 222 | +        if ($selected == $item[$value]){ | |
| 223 | + $selected_tag = " selected='selected' "; | |
| 224 | + } | |
| 225 | +        $code.="<option value='{$item[$value]}' $selected_tag>{$item[$show]}</option>\r\n"; | |
| 226 | + } | |
| 227 | + return $code; | |
| 228 | 228 | } | 
| 229 | 229 | |
| 230 | 230 | /** | 
| @@ -235,15 +235,15 @@ discard block | ||
| 235 | 235 | */ | 
| 236 | 236 | function options_for_select($data, $selected='') | 
| 237 | 237 |  { | 
| 238 | - $code=""; | |
| 239 | -	foreach($data as $key => $value) { | |
| 240 | - $selected_tag=""; | |
| 241 | -		if ($selected == $value){ | |
| 242 | - $selected_tag = " selected='selected' "; | |
| 243 | - } | |
| 244 | - $code.="<option value='$key' $selected_tag>$value</option>\r\n"; | |
| 245 | - } | |
| 246 | - return $code; | |
| 238 | + $code=""; | |
| 239 | +    foreach($data as $key => $value) { | |
| 240 | + $selected_tag=""; | |
| 241 | +        if ($selected == $value){ | |
| 242 | + $selected_tag = " selected='selected' "; | |
| 243 | + } | |
| 244 | + $code.="<option value='$key' $selected_tag>$value</option>\r\n"; | |
| 245 | + } | |
| 246 | + return $code; | |
| 247 | 247 | } | 
| 248 | 248 | |
| 249 | 249 | /** | 
| @@ -253,8 +253,8 @@ discard block | ||
| 253 | 253 | * @return string | 
| 254 | 254 | */ | 
| 255 | 255 |  function js_redirect_to($action, $seconds = 0.01){ | 
| 256 | - $seconds*=1000; | |
| 257 | -	return "<script type=\"text/javascript\">setTimeout('window.location=\"?/$action\"', $seconds)</script>"; | |
| 256 | + $seconds*=1000; | |
| 257 | +    return "<script type=\"text/javascript\">setTimeout('window.location=\"?/$action\"', $seconds)</script>"; | |
| 258 | 258 | } | 
| 259 | 259 | |
| 260 | 260 | /** | 
| @@ -265,5 +265,5 @@ discard block | ||
| 265 | 265 | * @return string | 
| 266 | 266 | */ | 
| 267 | 267 |  function button_to_action($caption, $action, $attributes=''){ | 
| 268 | - return "<button type='button' $attributes onclick='window.location=\"".PUBLIC_PATH."$action\"'>$caption</button>"; | |
| 268 | + return "<button type='button' $attributes onclick='window.location=\"".PUBLIC_PATH."$action\"'>$caption</button>"; | |
| 269 | 269 | } | 
| @@ -5,8 +5,8 @@ discard block | ||
| 5 | 5 | * @param string $src | 
| 6 | 6 | * @return string | 
| 7 | 7 | */ | 
| 8 | -function javascript_include_tag($src){ | |
| 9 | - return "<script type='text/javascript' src='".PUBLIC_PATH."js/$src.js'></script>\r\n"; | |
| 8 | +function javascript_include_tag($src) { | |
| 9 | + return "<script type='text/javascript' src='" . PUBLIC_PATH . "js/$src.js'></script>\r\n"; | |
| 10 | 10 | } | 
| 11 | 11 | |
| 12 | 12 | /** | 
| @@ -14,8 +14,8 @@ discard block | ||
| 14 | 14 | * @param string $src | 
| 15 | 15 | * @return string | 
| 16 | 16 | */ | 
| 17 | -function stylesheet_link($src=''){ | |
| 18 | - return "<link rel='stylesheet' type='text/css' href='".PUBLIC_PATH."css/$src.css'/>\r\n"; | |
| 17 | +function stylesheet_link($src = '') { | |
| 18 | + return "<link rel='stylesheet' type='text/css' href='" . PUBLIC_PATH . "css/$src.css'/>\r\n"; | |
| 19 | 19 | } | 
| 20 | 20 | |
| 21 | 21 | /** | 
| @@ -25,8 +25,8 @@ discard block | ||
| 25 | 25 | * @param string $attributes | 
| 26 | 26 | * @return string | 
| 27 | 27 | */ | 
| 28 | -function link_to($action, $text, $attributes=''){ | |
| 29 | - return "<a href='".PUBLIC_PATH."$action' $attributes>$text</a>"; | |
| 28 | +function link_to($action, $text, $attributes = '') { | |
| 29 | + return "<a href='" . PUBLIC_PATH . "$action' $attributes>$text</a>"; | |
| 30 | 30 | } | 
| 31 | 31 | |
| 32 | 32 | /** | 
| @@ -35,8 +35,8 @@ discard block | ||
| 35 | 35 | * @param string $attributes | 
| 36 | 36 | * @return string | 
| 37 | 37 | */ | 
| 38 | -function img_tag($img, $attributes=''){ | |
| 39 | - return "<img src='".PUBLIC_PATH."img/$img' $attributes />\r\n"; | |
| 38 | +function img_tag($img, $attributes = '') { | |
| 39 | + return "<img src='" . PUBLIC_PATH . "img/$img' $attributes />\r\n"; | |
| 40 | 40 | } | 
| 41 | 41 | |
| 42 | 42 | /** | 
| @@ -45,15 +45,15 @@ discard block | ||
| 45 | 45 | * @param string $attributes | 
| 46 | 46 | * @return string | 
| 47 | 47 | */ | 
| 48 | -function form_tag($action, $attributes=''){ | |
| 49 | - return "<form action='".PUBLIC_PATH."$action' $attributes>\r\n"; | |
| 48 | +function form_tag($action, $attributes = '') { | |
| 49 | + return "<form action='" . PUBLIC_PATH . "$action' $attributes>\r\n"; | |
| 50 | 50 | } | 
| 51 | 51 | |
| 52 | 52 | /** | 
| 53 | 53 | * end_form_tag | 
| 54 | 54 | * @return string | 
| 55 | 55 | */ | 
| 56 | -function end_form_tag(){ | |
| 56 | +function end_form_tag() { | |
| 57 | 57 | return "</form>\r\n"; | 
| 58 | 58 | } | 
| 59 | 59 | |
| @@ -63,7 +63,7 @@ discard block | ||
| 63 | 63 | * @param string $attributes | 
| 64 | 64 | * @return string | 
| 65 | 65 | */ | 
| 66 | -function submit_tag($caption, $attributes=''){ | |
| 66 | +function submit_tag($caption, $attributes = '') { | |
| 67 | 67 | return "<input type='submit' value='$caption' $attributes />\r\n"; | 
| 68 | 68 | } | 
| 69 | 69 | |
| @@ -74,7 +74,7 @@ discard block | ||
| 74 | 74 | * @param string $attributes | 
| 75 | 75 | * @return string | 
| 76 | 76 | */ | 
| 77 | -function button_tag($caption, $type='button', $attributes=''){ | |
| 77 | +function button_tag($caption, $type = 'button', $attributes = '') { | |
| 78 | 78 | return "<button type='$type' $attributes>$caption</button>\r\n"; | 
| 79 | 79 | } | 
| 80 | 80 | |
| @@ -85,11 +85,11 @@ discard block | ||
| 85 | 85 | */ | 
| 86 | 86 | function get_field_name_and_id($name) | 
| 87 | 87 |  { | 
| 88 | - $id=""; | |
| 88 | + $id = ""; | |
| 89 | 89 |  	if (strpos($name, ".") != false) { | 
| 90 | 90 |  		$items = explode(".", $name); | 
| 91 | -		$id=" id='{$items[0]}_{$items[1]}' "; | |
| 92 | - $name = $items[0]."[".$items[1]."]"; | |
| 91 | +		$id = " id='{$items[0]}_{$items[1]}' "; | |
| 92 | + $name = $items[0] . "[" . $items[1] . "]"; | |
| 93 | 93 | } | 
| 94 | 94 | return [$id, $name]; | 
| 95 | 95 | } | 
| @@ -101,7 +101,7 @@ discard block | ||
| 101 | 101 | * @param string $attributes | 
| 102 | 102 | * @return string | 
| 103 | 103 | */ | 
| 104 | -function text_field_tag($name, $value='', $attributes=''){ | |
| 104 | +function text_field_tag($name, $value = '', $attributes = '') { | |
| 105 | 105 | list($id, $name) = get_field_name_and_id($name); | 
| 106 | 106 | |
| 107 | 107 | return "<input type='text' name='$name' $id value='$value' $attributes />\r\n"; | 
| @@ -114,7 +114,7 @@ discard block | ||
| 114 | 114 | * @param string $attributes | 
| 115 | 115 | * @return string | 
| 116 | 116 | */ | 
| 117 | -function password_field_tag($name, $value='', $attributes=''){ | |
| 117 | +function password_field_tag($name, $value = '', $attributes = '') { | |
| 118 | 118 | list($id, $name) = get_field_name_and_id($name); | 
| 119 | 119 | |
| 120 | 120 | return "<input type='password' name='$name' $id value='$value' $attributes />\r\n"; | 
| @@ -127,7 +127,7 @@ discard block | ||
| 127 | 127 | * @param string $attributes | 
| 128 | 128 | * @return string | 
| 129 | 129 | */ | 
| 130 | -function text_area_tag($name, $value='', $attributes=''){ | |
| 130 | +function text_area_tag($name, $value = '', $attributes = '') { | |
| 131 | 131 | list($id, $name) = get_field_name_and_id($name); | 
| 132 | 132 | |
| 133 | 133 | return "<textarea name='$name' $id $attributes>$value</textarea>\r\n"; | 
| @@ -140,7 +140,7 @@ discard block | ||
| 140 | 140 | * @param string $attributes | 
| 141 | 141 | * @return string | 
| 142 | 142 | */ | 
| 143 | -function hidden_field_tag($name, $value='', $attributes=''){ | |
| 143 | +function hidden_field_tag($name, $value = '', $attributes = '') { | |
| 144 | 144 | list($id, $name) = get_field_name_and_id($name); | 
| 145 | 145 | |
| 146 | 146 | return "<input type='hidden' name='$name' $id value='$value' $attributes />\r\n"; | 
| @@ -155,7 +155,7 @@ discard block | ||
| 155 | 155 | * @param string $attributes | 
| 156 | 156 | * @return string | 
| 157 | 157 | */ | 
| 158 | -function check_box_tag($name, $value, $text, $checked=false, $attributes=''){ | |
| 158 | +function check_box_tag($name, $value, $text, $checked = false, $attributes = '') { | |
| 159 | 159 | list($id, $name) = get_field_name_and_id($name); | 
| 160 | 160 | $checked = $checked == true ? ' checked ' : ''; | 
| 161 | 161 | return "<input type='checkbox' $id name='$name' $checked $attributes value='$value'/>\r\n"; | 
| @@ -169,7 +169,7 @@ discard block | ||
| 169 | 169 | * @param string $attributes | 
| 170 | 170 | * @return string | 
| 171 | 171 | */ | 
| 172 | -function radio_button_tag($name, $value, $checked=false, $attributes=''){ | |
| 172 | +function radio_button_tag($name, $value, $checked = false, $attributes = '') { | |
| 173 | 173 | list($id, $name) = get_field_name_and_id($name); | 
| 174 | 174 | $checked = $checked == true ? ' checked ' : ''; | 
| 175 | 175 | return "<input type='radio' $id name='$name' $checked $attributes value='$value'/>\r\n"; | 
| @@ -182,7 +182,7 @@ discard block | ||
| 182 | 182 | * @param string $attributes | 
| 183 | 183 | * @return string | 
| 184 | 184 | */ | 
| 185 | -function label_tag($field, $caption, $attributes='') { | |
| 185 | +function label_tag($field, $caption, $attributes = '') { | |
| 186 | 186 | return "<label for='$field' $attributes>$caption</label>\r\n"; | 
| 187 | 187 | } | 
| 188 | 188 | |
| @@ -194,12 +194,12 @@ discard block | ||
| 194 | 194 | * @param string $attributes | 
| 195 | 195 | * @return string | 
| 196 | 196 | */ | 
| 197 | -function select_tag($name, $options='', $include_blank=false, $attributes=''){ | |
| 197 | +function select_tag($name, $options = '', $include_blank = false, $attributes = '') { | |
| 198 | 198 | list($id, $name) = get_field_name_and_id($name); | 
| 199 | 199 | |
| 200 | 200 | $code = ""; | 
| 201 | 201 |  	if ($include_blank != false) { | 
| 202 | - $code="<option value=''>$include_blank</option>\r\n"; | |
| 202 | + $code = "<option value=''>$include_blank</option>\r\n"; | |
| 203 | 203 | } | 
| 204 | 204 | |
| 205 | 205 | return "<select $id name='$name' $attributes>\r\n$code$options</select>\r\n"; | 
| @@ -214,15 +214,15 @@ discard block | ||
| 214 | 214 | * @param string $selected | 
| 215 | 215 | * @return string | 
| 216 | 216 | */ | 
| 217 | -function options_for_dbselect($data, $show, $value, $selected='') | |
| 217 | +function options_for_dbselect($data, $show, $value, $selected = '') | |
| 218 | 218 |  { | 
| 219 | - $code=""; | |
| 220 | -	foreach($data as $item) { | |
| 221 | - $selected_tag=""; | |
| 222 | -		if ($selected == $item[$value]){ | |
| 219 | + $code = ""; | |
| 220 | +	foreach ($data as $item) { | |
| 221 | + $selected_tag = ""; | |
| 222 | +		if ($selected == $item[$value]) { | |
| 223 | 223 | $selected_tag = " selected='selected' "; | 
| 224 | 224 | } | 
| 225 | -		$code.="<option value='{$item[$value]}' $selected_tag>{$item[$show]}</option>\r\n"; | |
| 225 | +		$code .= "<option value='{$item[$value]}' $selected_tag>{$item[$show]}</option>\r\n"; | |
| 226 | 226 | } | 
| 227 | 227 | return $code; | 
| 228 | 228 | } | 
| @@ -233,15 +233,15 @@ discard block | ||
| 233 | 233 | * @param string $selected | 
| 234 | 234 | * @return string | 
| 235 | 235 | */ | 
| 236 | -function options_for_select($data, $selected='') | |
| 236 | +function options_for_select($data, $selected = '') | |
| 237 | 237 |  { | 
| 238 | - $code=""; | |
| 239 | -	foreach($data as $key => $value) { | |
| 240 | - $selected_tag=""; | |
| 241 | -		if ($selected == $value){ | |
| 238 | + $code = ""; | |
| 239 | +	foreach ($data as $key => $value) { | |
| 240 | + $selected_tag = ""; | |
| 241 | +		if ($selected == $value) { | |
| 242 | 242 | $selected_tag = " selected='selected' "; | 
| 243 | 243 | } | 
| 244 | - $code.="<option value='$key' $selected_tag>$value</option>\r\n"; | |
| 244 | + $code .= "<option value='$key' $selected_tag>$value</option>\r\n"; | |
| 245 | 245 | } | 
| 246 | 246 | return $code; | 
| 247 | 247 | } | 
| @@ -252,8 +252,8 @@ discard block | ||
| 252 | 252 | * @param float $seconds | 
| 253 | 253 | * @return string | 
| 254 | 254 | */ | 
| 255 | -function js_redirect_to($action, $seconds = 0.01){ | |
| 256 | - $seconds*=1000; | |
| 255 | +function js_redirect_to($action, $seconds = 0.01) { | |
| 256 | + $seconds *= 1000; | |
| 257 | 257 |  	return "<script type=\"text/javascript\">setTimeout('window.location=\"?/$action\"', $seconds)</script>"; | 
| 258 | 258 | } | 
| 259 | 259 | |
| @@ -264,6 +264,6 @@ discard block | ||
| 264 | 264 | * @param string $attributes | 
| 265 | 265 | * @return string | 
| 266 | 266 | */ | 
| 267 | -function button_to_action($caption, $action, $attributes=''){ | |
| 268 | - return "<button type='button' $attributes onclick='window.location=\"".PUBLIC_PATH."$action\"'>$caption</button>"; | |
| 267 | +function button_to_action($caption, $action, $attributes = '') { | |
| 268 | + return "<button type='button' $attributes onclick='window.location=\"" . PUBLIC_PATH . "$action\"'>$caption</button>"; | |
| 269 | 269 | } | 
| @@ -7,19 +7,19 @@ | ||
| 7 | 7 | */ | 
| 8 | 8 | class Config | 
| 9 | 9 |  { | 
| 10 | - private static $_db_config = [ | |
| 11 | - 'dsn' => "mysql:host=DB_HOST;dbname=DB_NAME;charset=utf8", | |
| 12 | - 'user' => "USER_NAME", | |
| 13 | - 'password' => "USER_PASSWORD", | |
| 14 | - 'parameters' => [ | |
| 15 | - PDO::ATTR_PERSISTENT => true, | |
| 16 | - PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION, | |
| 17 | - ] | |
| 18 | - ]; | |
| 10 | + private static $_db_config = [ | |
| 11 | + 'dsn' => "mysql:host=DB_HOST;dbname=DB_NAME;charset=utf8", | |
| 12 | + 'user' => "USER_NAME", | |
| 13 | + 'password' => "USER_PASSWORD", | |
| 14 | + 'parameters' => [ | |
| 15 | + PDO::ATTR_PERSISTENT => true, | |
| 16 | + PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION, | |
| 17 | + ] | |
| 18 | + ]; | |
| 19 | 19 | |
| 20 | - public static function getDbConfig() | |
| 21 | -	{ | |
| 22 | - return self::$_db_config; | |
| 23 | - } | |
| 20 | + public static function getDbConfig() | |
| 21 | +    { | |
| 22 | + return self::$_db_config; | |
| 23 | + } | |
| 24 | 24 | |
| 25 | 25 | } | 
| 26 | 26 | \ No newline at end of file | 
| @@ -118,7 +118,7 @@ | ||
| 118 | 118 | */ | 
| 119 | 119 |      public function __toString() { | 
| 120 | 120 | $sql = 'SELECT ' . (empty($this->_columns) ? '*' : $this->_columns) . | 
| 121 | - ' ' . 'FROM ' . $this->_table; | |
| 121 | + ' ' . 'FROM ' . $this->_table; | |
| 122 | 122 | |
| 123 | 123 | $check_for = [ | 
| 124 | 124 | '_joins', | 
| @@ -2,17 +2,17 @@ | ||
| 2 | 2 | |
| 3 | 3 | function signin() | 
| 4 | 4 |  { | 
| 5 | -	Session::set("is_logged_in", true); | |
| 6 | -	Session::set("flash", "Bienvenido!"); | |
| 7 | -	redirect_to(""); | |
| 8 | - return; | |
| 5 | +    Session::set("is_logged_in", true); | |
| 6 | +    Session::set("flash", "Bienvenido!"); | |
| 7 | +    redirect_to(""); | |
| 8 | + return; | |
| 9 | 9 | } | 
| 10 | 10 | |
| 11 | 11 | function signout() | 
| 12 | 12 |  { | 
| 13 | - Session::destroy(); | |
| 14 | -	Session::set("flash", "Adios!"); | |
| 15 | -	redirect_to(""); | |
| 16 | - return; | |
| 13 | + Session::destroy(); | |
| 14 | +    Session::set("flash", "Adios!"); | |
| 15 | +    redirect_to(""); | |
| 16 | + return; | |
| 17 | 17 | } | 
| 18 | 18 | |
| @@ -2,12 +2,12 @@ | ||
| 2 | 2 | |
| 3 | 3 | function index() | 
| 4 | 4 |  { | 
| 5 | - $template = new Template(); | |
| 6 | -	$template->set("saludo", "Saludo interno"); | |
| 7 | -	$template->render("default/index"); | |
| 5 | + $template = new Template(); | |
| 6 | +    $template->set("saludo", "Saludo interno"); | |
| 7 | +    $template->render("default/index"); | |
| 8 | 8 | } | 
| 9 | 9 | |
| 10 | 10 | function redirigir() | 
| 11 | 11 |  { | 
| 12 | -	return redirect_to("page/show"); | |
| 12 | +    return redirect_to("page/show"); | |
| 13 | 13 | } | 
| @@ -3,32 +3,32 @@ | ||
| 3 | 3 | |
| 4 | 4 | function page_initializer() | 
| 5 | 5 |  { | 
| 6 | -	if (Session::get("is_logged_in") !== true) { | |
| 7 | - //ir a la pagina inicial | |
| 8 | -		Session::set("flash", "Debe iniciar sesión para acceder al recurso *<i>page</i>*"); | |
| 9 | -		redirect_to(""); | |
| 10 | - return; | |
| 11 | - } | |
| 6 | +    if (Session::get("is_logged_in") !== true) { | |
| 7 | + //ir a la pagina inicial | |
| 8 | +        Session::set("flash", "Debe iniciar sesión para acceder al recurso *<i>page</i>*"); | |
| 9 | +        redirect_to(""); | |
| 10 | + return; | |
| 11 | + } | |
| 12 | 12 | } | 
| 13 | 13 | |
| 14 | 14 | function show($slug = '') | 
| 15 | 15 |  { | 
| 16 | - $template = new Template(); | |
| 17 | -	$template->set("slug", $slug); | |
| 18 | -	$template->render("page/show"); | |
| 16 | + $template = new Template(); | |
| 17 | +    $template->set("slug", $slug); | |
| 18 | +    $template->render("page/show"); | |
| 19 | 19 | } | 
| 20 | 20 | |
| 21 | 21 | function edit() | 
| 22 | 22 |  { | 
| 23 | - $template = new Template(); | |
| 24 | -	$template->render("page/edit");	 | |
| 23 | + $template = new Template(); | |
| 24 | +    $template->render("page/edit");	 | |
| 25 | 25 | } | 
| 26 | 26 | |
| 27 | 27 | function update() | 
| 28 | 28 |  { | 
| 29 | - $template = new Template(); | |
| 30 | -	Session::set("flash", "Página actualizada correctamente"); | |
| 31 | -	$template->render("page/edit");	 | |
| 29 | + $template = new Template(); | |
| 30 | +    Session::set("flash", "Página actualizada correctamente"); | |
| 31 | +    $template->render("page/edit");	 | |
| 32 | 32 | } | 
| 33 | 33 | |
| 34 | 34 | |
| @@ -35,7 +35,7 @@ discard block | ||
| 35 | 35 | |
| 36 | 36 | function load_partial($partial, array $parameters = null) | 
| 37 | 37 |  { | 
| 38 | - load_file($partial, ".phtml", PIN_PATH . 'partials'. DS , "Parcial", $parameters); | |
| 38 | + load_file($partial, ".phtml", PIN_PATH . 'partials' . DS, "Parcial", $parameters); | |
| 39 | 39 | } | 
| 40 | 40 | |
| 41 | 41 | function redirect_to($url) | 
| @@ -47,7 +47,7 @@ discard block | ||
| 47 | 47 | //implementar autoloader para clases | 
| 48 | 48 | //espera que las clases se definan en PascalCase y los archivos | 
| 49 | 49 | //usen snake_case. Ejemplo class QueryBuilder, archivo query_builder.php | 
| 50 | -spl_autoload_register(function($className){ | |
| 50 | +spl_autoload_register(function($className) { | |
| 51 | 51 |  	$file_name = strtolower(preg_replace('/(?<!^)[A-Z]/', '_$0', $className)); | 
| 52 | 52 | $file = PIN_PATH . 'libs' . DS . $file_name . '.php'; | 
| 53 | 53 |  	if (file_exists($file)) { | 
| @@ -2,60 +2,60 @@ discard block | ||
| 2 | 2 | |
| 3 | 3 | function load_file($file, $extension, $base_dir, $classification, $parameters = null) | 
| 4 | 4 |  { | 
| 5 | -	if (isset($parameters) && is_array($parameters)) { | |
| 6 | - extract($parameters); | |
| 7 | - } | |
| 8 | -	if (file_exists($base_dir . $file . $extension)) {	 | |
| 9 | - require $base_dir . $file . $extension; | |
| 10 | -	} else { | |
| 11 | -		throw (new Exception("$classification <b>$file</b> no existe!"));	 | |
| 12 | - } | |
| 5 | +    if (isset($parameters) && is_array($parameters)) { | |
| 6 | + extract($parameters); | |
| 7 | + } | |
| 8 | +    if (file_exists($base_dir . $file . $extension)) {	 | |
| 9 | + require $base_dir . $file . $extension; | |
| 10 | +    } else { | |
| 11 | +        throw (new Exception("$classification <b>$file</b> no existe!"));	 | |
| 12 | + } | |
| 13 | 13 | } | 
| 14 | 14 | |
| 15 | 15 | function load_lib($lib) | 
| 16 | 16 |  { | 
| 17 | - load_file($lib, ".php", PIN_PATH . 'libs' . DS, "Librería"); | |
| 17 | + load_file($lib, ".php", PIN_PATH . 'libs' . DS, "Librería"); | |
| 18 | 18 | } | 
| 19 | 19 | |
| 20 | 20 | function load_config($config) | 
| 21 | 21 |  { | 
| 22 | - load_file($config, ".php", PIN_PATH . 'config' . DS, "Configuración"); | |
| 22 | + load_file($config, ".php", PIN_PATH . 'config' . DS, "Configuración"); | |
| 23 | 23 | } | 
| 24 | 24 | |
| 25 | 25 | |
| 26 | 26 | function load_helper($helper) | 
| 27 | 27 |  { | 
| 28 | - load_file($helper, ".php", PIN_PATH . 'helpers' . DS, "Helper"); | |
| 28 | + load_file($helper, ".php", PIN_PATH . 'helpers' . DS, "Helper"); | |
| 29 | 29 | } | 
| 30 | 30 | |
| 31 | 31 | function load_view($view, array $parameters = null) | 
| 32 | 32 |  { | 
| 33 | - load_file($view, ".phtml", PIN_PATH . 'views' . DS, "Vista", $parameters); | |
| 33 | + load_file($view, ".phtml", PIN_PATH . 'views' . DS, "Vista", $parameters); | |
| 34 | 34 | } | 
| 35 | 35 | |
| 36 | 36 | function load_partial($partial, array $parameters = null) | 
| 37 | 37 |  { | 
| 38 | - load_file($partial, ".phtml", PIN_PATH . 'partials'. DS , "Parcial", $parameters); | |
| 38 | + load_file($partial, ".phtml", PIN_PATH . 'partials'. DS , "Parcial", $parameters); | |
| 39 | 39 | } | 
| 40 | 40 | |
| 41 | 41 | function redirect_to($url) | 
| 42 | 42 |  { | 
| 43 | - $url = PUBLIC_PATH . $url; | |
| 44 | -	header("Location: $url", true, 301); | |
| 43 | + $url = PUBLIC_PATH . $url; | |
| 44 | +    header("Location: $url", true, 301); | |
| 45 | 45 | } | 
| 46 | 46 | |
| 47 | 47 | //implementar autoloader para clases | 
| 48 | 48 | //espera que las clases se definan en PascalCase y los archivos | 
| 49 | 49 | //usen snake_case. Ejemplo class QueryBuilder, archivo query_builder.php | 
| 50 | 50 |  spl_autoload_register(function($className){ | 
| 51 | -	$file_name = strtolower(preg_replace('/(?<!^)[A-Z]/', '_$0', $className)); | |
| 52 | - $file = PIN_PATH . 'libs' . DS . $file_name . '.php'; | |
| 53 | -	if (file_exists($file)) { | |
| 54 | - require_once $file; | |
| 55 | - return; | |
| 56 | -	} else { | |
| 57 | -		throw new Exception("$className no existe en $file", 1);		 | |
| 58 | - } | |
| 51 | +    $file_name = strtolower(preg_replace('/(?<!^)[A-Z]/', '_$0', $className)); | |
| 52 | + $file = PIN_PATH . 'libs' . DS . $file_name . '.php'; | |
| 53 | +    if (file_exists($file)) { | |
| 54 | + require_once $file; | |
| 55 | + return; | |
| 56 | +    } else { | |
| 57 | +        throw new Exception("$className no existe en $file", 1);		 | |
| 58 | + } | |
| 59 | 59 | }); | 
| 60 | 60 | |
| 61 | 61 | |
| @@ -79,54 +79,54 @@ discard block | ||
| 79 | 79 | |
| 80 | 80 |      if (error_reporting() !== 0) { | 
| 81 | 81 | echo "<div style='padding: 40px;'>"; | 
| 82 | - echo "<h1>Fatal error</h1>"; | |
| 82 | + echo "<h1>Fatal error</h1>"; | |
| 83 | 83 | echo "<p>Uncaught exception: '" . get_class($exception) . "'</p>"; | 
| 84 | 84 | echo "<p>Message: '" . $exception->getMessage() . "'</p>"; | 
| 85 | 85 | echo "<p>Stack trace:<pre>" . $exception->getTraceAsString() . "</pre></p>"; | 
| 86 | 86 | echo "<p>Thrown in '" . $exception->getFile() . "' on line " . $exception->getLine() . "</p>"; | 
| 87 | - echo "</div>"; | |
| 87 | + echo "</div>"; | |
| 88 | 88 | } | 
| 89 | 89 | } | 
| 90 | 90 | |
| 91 | 91 | |
| 92 | 92 | function load_page_from_url($url) | 
| 93 | 93 |  { | 
| 94 | -	$content = explode('/', $url); | |
| 94 | +    $content = explode('/', $url); | |
| 95 | 95 | //quitar el elemento inicial vacio | 
| 96 | 96 | array_shift($content); | 
| 97 | 97 | |
| 98 | - $page = !empty($content[0]) ? trim($content[0]) : 'default'; | |
| 99 | - array_shift($content); | |
| 98 | + $page = !empty($content[0]) ? trim($content[0]) : 'default'; | |
| 99 | + array_shift($content); | |
| 100 | 100 | |
| 101 | -	if (file_exists(PIN_PATH . 'pages' . DS . $page . '.php')) { | |
| 102 | - require PIN_PATH . 'pages' . DS . $page . '.php'; | |
| 103 | -	} else { | |
| 104 | -		throw (new Exception("La página <b>$page</b> no existe!")); | |
| 105 | - } | |
| 101 | +    if (file_exists(PIN_PATH . 'pages' . DS . $page . '.php')) { | |
| 102 | + require PIN_PATH . 'pages' . DS . $page . '.php'; | |
| 103 | +    } else { | |
| 104 | +        throw (new Exception("La página <b>$page</b> no existe!")); | |
| 105 | + } | |
| 106 | 106 | |
| 107 | - $function_to_be_load = !empty($content[0]) ? trim($content[0]) : 'index'; | |
| 108 | - array_shift($content); | |
| 107 | + $function_to_be_load = !empty($content[0]) ? trim($content[0]) : 'index'; | |
| 108 | + array_shift($content); | |
| 109 | 109 | |
| 110 | -	if (function_exists("page_initializer")) { | |
| 111 | -		call_user_func("page_initializer"); | |
| 112 | - } | |
| 110 | +    if (function_exists("page_initializer")) { | |
| 111 | +        call_user_func("page_initializer"); | |
| 112 | + } | |
| 113 | 113 | |
| 114 | - $request_method = strtolower($_SERVER['REQUEST_METHOD']); | |
| 115 | - $api_function_to_be_load = $function_to_be_load; | |
| 114 | + $request_method = strtolower($_SERVER['REQUEST_METHOD']); | |
| 115 | + $api_function_to_be_load = $function_to_be_load; | |
| 116 | 116 | |
| 117 | -	if (!empty($request_method)) { | |
| 118 | - $api_function_to_be_load = $request_method; | |
| 119 | - } | |
| 117 | +    if (!empty($request_method)) { | |
| 118 | + $api_function_to_be_load = $request_method; | |
| 119 | + } | |
| 120 | 120 | |
| 121 | -	if (function_exists($function_to_be_load)) { | |
| 122 | - call_user_func_array($function_to_be_load, $content); | |
| 123 | -	} else { | |
| 124 | -		if (function_exists($api_function_to_be_load)) { | |
| 125 | - $content[] = $function_to_be_load; | |
| 126 | - call_user_func_array($api_function_to_be_load, $content); | |
| 127 | -		} else { | |
| 128 | -			throw (new Exception("La función <b>$function_to_be_load</b> no existe en la página <b>$page</b>!"));	 | |
| 129 | - } | |
| 130 | - } | |
| 121 | +    if (function_exists($function_to_be_load)) { | |
| 122 | + call_user_func_array($function_to_be_load, $content); | |
| 123 | +    } else { | |
| 124 | +        if (function_exists($api_function_to_be_load)) { | |
| 125 | + $content[] = $function_to_be_load; | |
| 126 | + call_user_func_array($api_function_to_be_load, $content); | |
| 127 | +        } else { | |
| 128 | +            throw (new Exception("La función <b>$function_to_be_load</b> no existe en la página <b>$page</b>!"));	 | |
| 129 | + } | |
| 130 | + } | |
| 131 | 131 | |
| 132 | 132 | } |