| @@ -2,47 +2,47 @@ 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 | - return; | |
| 13 | - } | |
| 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 | + return; | |
| 13 | + } | |
| 14 | 14 | } | 
| 15 | 15 | |
| 16 | 16 | function load_lib(string $lib) | 
| 17 | 17 |  { | 
| 18 | - load_file($lib, ".php", PIN_PATH . 'libs' . DS, "Librería"); | |
| 18 | + load_file($lib, ".php", PIN_PATH . 'libs' . DS, "Librería"); | |
| 19 | 19 | } | 
| 20 | 20 | |
| 21 | 21 | function load_config(string $config) | 
| 22 | 22 |  { | 
| 23 | - load_file($config, ".php", PIN_PATH . 'config' . DS, "Configuración"); | |
| 23 | + load_file($config, ".php", PIN_PATH . 'config' . DS, "Configuración"); | |
| 24 | 24 | } | 
| 25 | 25 | |
| 26 | 26 | |
| 27 | 27 | function load_helper(string $helper) | 
| 28 | 28 |  { | 
| 29 | - load_file($helper, ".php", PIN_PATH . 'helpers' . DS, "Helper"); | |
| 29 | + load_file($helper, ".php", PIN_PATH . 'helpers' . DS, "Helper"); | |
| 30 | 30 | } | 
| 31 | 31 | |
| 32 | 32 | function load_view(string $view, array $parameters = null) | 
| 33 | 33 |  { | 
| 34 | - load_file($view, ".phtml", PIN_PATH . 'views' . DS, "Vista", $parameters); | |
| 34 | + load_file($view, ".phtml", PIN_PATH . 'views' . DS, "Vista", $parameters); | |
| 35 | 35 | } | 
| 36 | 36 | |
| 37 | 37 | function load_partial(string $partial, array $parameters = null) | 
| 38 | 38 |  { | 
| 39 | - load_file($partial, ".phtml", PIN_PATH . 'partials'. DS , "Parcial", $parameters); | |
| 39 | + load_file($partial, ".phtml", PIN_PATH . 'partials'. DS , "Parcial", $parameters); | |
| 40 | 40 | } | 
| 41 | 41 | |
| 42 | 42 | function redirect_to(string $url) | 
| 43 | 43 |  { | 
| 44 | - $url = PUBLIC_PATH . $url; | |
| 45 | -	header("Location: $url", 301); | |
| 44 | + $url = PUBLIC_PATH . $url; | |
| 45 | +    header("Location: $url", 301); | |
| 46 | 46 | } | 
| 47 | 47 | |
| 48 | 48 | |
| @@ -66,45 +66,45 @@ discard block | ||
| 66 | 66 | |
| 67 | 67 |      if (error_reporting() !== 0) { | 
| 68 | 68 | |
| 69 | -		load_partial("templates/header"); | |
| 69 | +        load_partial("templates/header"); | |
| 70 | 70 | echo "<h1>Fatal error</h1>"; | 
| 71 | 71 | echo "<p>Uncaught exception: '" . get_class($exception) . "'</p>"; | 
| 72 | 72 | echo "<p>Message: '" . $exception->getMessage() . "'</p>"; | 
| 73 | 73 | echo "<p>Stack trace:<pre>" . $exception->getTraceAsString() . "</pre></p>"; | 
| 74 | 74 | echo "<p>Thrown in '" . $exception->getFile() . "' on line " . $exception->getLine() . "</p>"; | 
| 75 | -		load_partial("templates/footer"); | |
| 75 | +        load_partial("templates/footer"); | |
| 76 | 76 | } | 
| 77 | 77 | } | 
| 78 | 78 | |
| 79 | 79 | |
| 80 | 80 | function load_page_from_url($url) | 
| 81 | 81 |  { | 
| 82 | -	$content = explode('/', $url); | |
| 82 | +    $content = explode('/', $url); | |
| 83 | 83 | //quitar el elemento inicial vacio | 
| 84 | 84 | array_shift($content); | 
| 85 | 85 | |
| 86 | - $page = !empty($content[0]) ? trim($content[0]) : 'default'; | |
| 87 | - array_shift($content); | |
| 86 | + $page = !empty($content[0]) ? trim($content[0]) : 'default'; | |
| 87 | + array_shift($content); | |
| 88 | 88 | |
| 89 | -	if (file_exists(PIN_PATH . 'pages' . DS . $page . '.php')) { | |
| 90 | - require PIN_PATH . 'pages' . DS . $page . '.php'; | |
| 91 | -	} else { | |
| 92 | -		throw (new Exception("La página <b>$page</b> no existe!")); | |
| 93 | - return; | |
| 94 | - } | |
| 89 | +    if (file_exists(PIN_PATH . 'pages' . DS . $page . '.php')) { | |
| 90 | + require PIN_PATH . 'pages' . DS . $page . '.php'; | |
| 91 | +    } else { | |
| 92 | +        throw (new Exception("La página <b>$page</b> no existe!")); | |
| 93 | + return; | |
| 94 | + } | |
| 95 | 95 | |
| 96 | - $function_to_be_load = !empty($content[0]) ? trim($content[0]) : 'index'; | |
| 97 | - array_shift($content); | |
| 96 | + $function_to_be_load = !empty($content[0]) ? trim($content[0]) : 'index'; | |
| 97 | + array_shift($content); | |
| 98 | 98 | |
| 99 | -	if (function_exists("page_initializer")) { | |
| 100 | -		call_user_func("page_initializer"); | |
| 101 | - } | |
| 99 | +    if (function_exists("page_initializer")) { | |
| 100 | +        call_user_func("page_initializer"); | |
| 101 | + } | |
| 102 | 102 | |
| 103 | -	if (function_exists($function_to_be_load)) { | |
| 104 | - call_user_func($function_to_be_load, $content); | |
| 105 | -	} else { | |
| 106 | -		throw (new Exception("La función <b>$function_to_be_load</b> no existe en la página <b>$page</b>!")); | |
| 107 | - return; | |
| 108 | - } | |
| 103 | +    if (function_exists($function_to_be_load)) { | |
| 104 | + call_user_func($function_to_be_load, $content); | |
| 105 | +    } else { | |
| 106 | +        throw (new Exception("La función <b>$function_to_be_load</b> no existe en la página <b>$page</b>!")); | |
| 107 | + return; | |
| 108 | + } | |
| 109 | 109 | |
| 110 | 110 | } | 
| 111 | 111 | \ No newline at end of file | 
| @@ -36,7 +36,7 @@ | ||
| 36 | 36 | |
| 37 | 37 | function load_partial(string $partial, array $parameters = null) | 
| 38 | 38 |  { | 
| 39 | - load_file($partial, ".phtml", PIN_PATH . 'partials'. DS , "Parcial", $parameters); | |
| 39 | + load_file($partial, ".phtml", PIN_PATH . 'partials' . DS, "Parcial", $parameters); | |
| 40 | 40 | } | 
| 41 | 41 | |
| 42 | 42 | function redirect_to(string $url) | 
| @@ -6,22 +6,22 @@ | ||
| 6 | 6 | |
| 7 | 7 | function page_initializer() | 
| 8 | 8 |  { | 
| 9 | -	if (Session::get("is_logged_in") !== true) { | |
| 10 | - //ir a la pagina inicial | |
| 11 | -		Session::set("flash", "Debe iniciar sesión para acceder al recurso *<i>page</i>*"); | |
| 12 | -		return redirect_to(""); | |
| 13 | - } | |
| 9 | +    if (Session::get("is_logged_in") !== true) { | |
| 10 | + //ir a la pagina inicial | |
| 11 | +        Session::set("flash", "Debe iniciar sesión para acceder al recurso *<i>page</i>*"); | |
| 12 | +        return redirect_to(""); | |
| 13 | + } | |
| 14 | 14 | } | 
| 15 | 15 | |
| 16 | 16 | function show($slug) | 
| 17 | 17 |  { | 
| 18 | -	$users = Db::findAll("SELECT * FROM Usuario"); | |
| 19 | -	load_view("page/show", ['users' => $users, 'slug' => $slug]); | |
| 18 | +    $users = Db::findAll("SELECT * FROM Usuario"); | |
| 19 | +    load_view("page/show", ['users' => $users, 'slug' => $slug]); | |
| 20 | 20 | } | 
| 21 | 21 | |
| 22 | 22 | function edit() | 
| 23 | 23 |  { | 
| 24 | -	$users = Db::findAll("SELECT * FROM Usuario"); | |
| 25 | -	load_view("page/edit", ['users' => $users]); | |
| 24 | +    $users = Db::findAll("SELECT * FROM Usuario"); | |
| 25 | +    load_view("page/edit", ['users' => $users]); | |
| 26 | 26 | } | 
| 27 | 27 | |
| @@ -4,14 +4,14 @@ | ||
| 4 | 4 | |
| 5 | 5 | function signin() | 
| 6 | 6 |  { | 
| 7 | -	Session::set("is_logged_in", true); | |
| 8 | -	Session::set("flash", "Bienvenido!"); | |
| 9 | -	return redirect_to(""); | |
| 7 | +    Session::set("is_logged_in", true); | |
| 8 | +    Session::set("flash", "Bienvenido!"); | |
| 9 | +    return redirect_to(""); | |
| 10 | 10 | } | 
| 11 | 11 | |
| 12 | 12 | function signout() | 
| 13 | 13 |  { | 
| 14 | - Session::destroy(); | |
| 15 | -	return redirect_to(""); | |
| 14 | + Session::destroy(); | |
| 15 | +    return redirect_to(""); | |
| 16 | 16 | } | 
| 17 | 17 | |
| @@ -2,10 +2,10 @@ | ||
| 2 | 2 | |
| 3 | 3 | function index() | 
| 4 | 4 |  { | 
| 5 | -	load_view("default/index"); | |
| 5 | +    load_view("default/index"); | |
| 6 | 6 | } | 
| 7 | 7 | |
| 8 | 8 | function redirigir() | 
| 9 | 9 |  { | 
| 10 | -	return redirect_to("page/show"); | |
| 10 | +    return redirect_to("page/show"); | |
| 11 | 11 | } | 
| 12 | 12 | \ No newline at end of file | 
| @@ -1,82 +1,82 @@ discard block | ||
| 1 | 1 | <?php | 
| 2 | 2 | |
| 3 | 3 |  function javascript_include_tag($src){ | 
| 4 | - return "<script type='text/javascript' src='".PUBLIC_PATH."js/$src.js'></script>\r\n"; | |
| 4 | + return "<script type='text/javascript' src='".PUBLIC_PATH."js/$src.js'></script>\r\n"; | |
| 5 | 5 | } | 
| 6 | 6 | |
| 7 | 7 |  function stylesheet_link($src=''){ | 
| 8 | - return "<link rel='stylesheet' type='text/css' href='".PUBLIC_PATH."css/$src.css'/>\r\n"; | |
| 8 | + return "<link rel='stylesheet' type='text/css' href='".PUBLIC_PATH."css/$src.css'/>\r\n"; | |
| 9 | 9 | } | 
| 10 | 10 | |
| 11 | 11 |  function link_to($action, $text, $attributes=''){ | 
| 12 | - return "<a href='".PUBLIC_PATH."$action' $attributes>$text</a>"; | |
| 12 | + return "<a href='".PUBLIC_PATH."$action' $attributes>$text</a>"; | |
| 13 | 13 | } | 
| 14 | 14 | |
| 15 | 15 |  function img_tag($img, $attributes=''){ | 
| 16 | - return "<img src='".PUBLIC_PATH."img/$img' $attributes />\r\n"; | |
| 16 | + return "<img src='".PUBLIC_PATH."img/$img' $attributes />\r\n"; | |
| 17 | 17 | } | 
| 18 | 18 | |
| 19 | 19 |  function form_tag($action, $attributes=''){ | 
| 20 | - return "<form action='".PUBLIC_PATH."$action' $attributes>\r\n"; | |
| 20 | + return "<form action='".PUBLIC_PATH."$action' $attributes>\r\n"; | |
| 21 | 21 | } | 
| 22 | 22 | |
| 23 | 23 |  function end_form_tag(){ | 
| 24 | - return "</form>\r\n"; | |
| 24 | + return "</form>\r\n"; | |
| 25 | 25 | } | 
| 26 | 26 | |
| 27 | 27 |  function submit_tag($caption, $attributes=''){ | 
| 28 | - return "<input type='submit' value='$caption' $attributes />\r\n"; | |
| 28 | + return "<input type='submit' value='$caption' $attributes />\r\n"; | |
| 29 | 29 | } | 
| 30 | 30 | |
| 31 | 31 |  function button_tag($caption, $type='button', $attributes=''){ | 
| 32 | - return "<button type='$type' $attributes>$caption</button>\r\n"; | |
| 32 | + return "<button type='$type' $attributes>$caption</button>\r\n"; | |
| 33 | 33 | } | 
| 34 | 34 | |
| 35 | 35 | function get_field_name_and_id($name) | 
| 36 | 36 |  { | 
| 37 | - $id=""; | |
| 38 | -	if (strpos($name, ".") != false) { | |
| 39 | -		$items = explode(".", $name); | |
| 40 | -		$id=" id='{$items[0]}_{$items[1]}' "; | |
| 41 | - $name = $items[0]."[".$items[1]."]"; | |
| 42 | - } | |
| 43 | - return [$id, $name]; | |
| 37 | + $id=""; | |
| 38 | +    if (strpos($name, ".") != false) { | |
| 39 | +        $items = explode(".", $name); | |
| 40 | +        $id=" id='{$items[0]}_{$items[1]}' "; | |
| 41 | + $name = $items[0]."[".$items[1]."]"; | |
| 42 | + } | |
| 43 | + return [$id, $name]; | |
| 44 | 44 | } | 
| 45 | 45 | |
| 46 | 46 |  function text_field_tag($name, $value='', $attributes=''){ | 
| 47 | - list($id, $name) = get_field_name_and_id($name); | |
| 47 | + list($id, $name) = get_field_name_and_id($name); | |
| 48 | 48 | |
| 49 | - return "<input type='text' name='$name' $id value='$value' $attributes />\r\n"; | |
| 49 | + return "<input type='text' name='$name' $id value='$value' $attributes />\r\n"; | |
| 50 | 50 | } | 
| 51 | 51 | |
| 52 | 52 |  function password_field_tag($name, $value='', $attributes=''){ | 
| 53 | - list($id, $name) = get_field_name_and_id($name); | |
| 53 | + list($id, $name) = get_field_name_and_id($name); | |
| 54 | 54 | |
| 55 | - return "<input type='password' name='$name' $id value='$value' $attributes />\r\n"; | |
| 55 | + return "<input type='password' name='$name' $id value='$value' $attributes />\r\n"; | |
| 56 | 56 | } | 
| 57 | 57 | |
| 58 | 58 |  function text_area_tag($name, $value='', $attributes=''){ | 
| 59 | - list($id, $name) = get_field_name_and_id($name); | |
| 59 | + list($id, $name) = get_field_name_and_id($name); | |
| 60 | 60 | |
| 61 | - return "<textarea name='$name' $id $attributes>$value</textarea>\r\n"; | |
| 61 | + return "<textarea name='$name' $id $attributes>$value</textarea>\r\n"; | |
| 62 | 62 | } | 
| 63 | 63 | |
| 64 | 64 |  function hidden_field_tag($name, $value='', $attributes=''){ | 
| 65 | - list($id, $name) = get_field_name_and_id($name); | |
| 65 | + list($id, $name) = get_field_name_and_id($name); | |
| 66 | 66 | |
| 67 | - return "<input type='hidden' name='$name' $id value='$value' $attributes />\r\n"; | |
| 67 | + return "<input type='hidden' name='$name' $id value='$value' $attributes />\r\n"; | |
| 68 | 68 | } | 
| 69 | 69 | |
| 70 | 70 |  function check_box_tag($name, $value, $text, $checked=false, $attributes=''){ | 
| 71 | - list($id, $name) = get_field_name_and_id($name); | |
| 72 | - $checked = $checked == true ? ' checked ' : ''; | |
| 73 | - return "<input type='checkbox' $id name='$name' $checked $attributes value='$value'/>\r\n"; | |
| 71 | + list($id, $name) = get_field_name_and_id($name); | |
| 72 | + $checked = $checked == true ? ' checked ' : ''; | |
| 73 | + return "<input type='checkbox' $id name='$name' $checked $attributes value='$value'/>\r\n"; | |
| 74 | 74 | } | 
| 75 | 75 | |
| 76 | 76 |  function radio_button_tag($name, $value, $checked=false, $attributes=''){ | 
| 77 | - list($id, $name) = get_field_name_and_id($name); | |
| 78 | - $checked = $checked == true ? ' checked ' : ''; | |
| 79 | - return "<input type='radio' $id name='$name' $checked $attributes value='$value'/>\r\n"; | |
| 77 | + list($id, $name) = get_field_name_and_id($name); | |
| 78 | + $checked = $checked == true ? ' checked ' : ''; | |
| 79 | + return "<input type='radio' $id name='$name' $checked $attributes value='$value'/>\r\n"; | |
| 80 | 80 | } | 
| 81 | 81 | |
| 82 | 82 |  function label_tag($field, $caption, $attributes='') { | 
| @@ -84,48 +84,48 @@ discard block | ||
| 84 | 84 | } | 
| 85 | 85 | |
| 86 | 86 |  function select_tag($name='', $options, $include_blank=false, $attributes=''){ | 
| 87 | - list($id, $name) = get_field_name_and_id($name); | |
| 87 | + list($id, $name) = get_field_name_and_id($name); | |
| 88 | 88 | |
| 89 | - $code = ""; | |
| 90 | -	if ($include_blank != false) { | |
| 91 | - $code="<option value=''>$include_blank</option>\r\n"; | |
| 92 | - } | |
| 89 | + $code = ""; | |
| 90 | +    if ($include_blank != false) { | |
| 91 | + $code="<option value=''>$include_blank</option>\r\n"; | |
| 92 | + } | |
| 93 | 93 | |
| 94 | - return "<select $id name='$name' $attributes>\r\n$code$options</select>\r\n"; | |
| 94 | + return "<select $id name='$name' $attributes>\r\n$code$options</select>\r\n"; | |
| 95 | 95 | |
| 96 | 96 | } | 
| 97 | 97 | |
| 98 | 98 | function options_for_dbselect($data, $show, $value, $selected='') | 
| 99 | 99 |  { | 
| 100 | - $code=""; | |
| 101 | -	foreach($data as $item) { | |
| 102 | - $selected_tag=""; | |
| 103 | -		if ($selected == $item[$value]){ | |
| 104 | - $selected_tag = " selected='selected' "; | |
| 105 | - } | |
| 106 | -		$code.="<option value='{$item[$value]}' $selected_tag>{$item[$show]}</option>\r\n"; | |
| 107 | - } | |
| 108 | - return $code; | |
| 100 | + $code=""; | |
| 101 | +    foreach($data as $item) { | |
| 102 | + $selected_tag=""; | |
| 103 | +        if ($selected == $item[$value]){ | |
| 104 | + $selected_tag = " selected='selected' "; | |
| 105 | + } | |
| 106 | +        $code.="<option value='{$item[$value]}' $selected_tag>{$item[$show]}</option>\r\n"; | |
| 107 | + } | |
| 108 | + return $code; | |
| 109 | 109 | } | 
| 110 | 110 | |
| 111 | 111 | function options_for_select($data, $selected='') | 
| 112 | 112 |  { | 
| 113 | - $code=""; | |
| 114 | -	foreach($data as $key => $value) { | |
| 115 | - $selected_tag=""; | |
| 116 | -		if ($selected == $value){ | |
| 117 | - $selected_tag = " selected='selected' "; | |
| 118 | - } | |
| 119 | - $code.="<option value='$key' $selected_tag>$value</option>\r\n"; | |
| 120 | - } | |
| 121 | - return $code; | |
| 113 | + $code=""; | |
| 114 | +    foreach($data as $key => $value) { | |
| 115 | + $selected_tag=""; | |
| 116 | +        if ($selected == $value){ | |
| 117 | + $selected_tag = " selected='selected' "; | |
| 118 | + } | |
| 119 | + $code.="<option value='$key' $selected_tag>$value</option>\r\n"; | |
| 120 | + } | |
| 121 | + return $code; | |
| 122 | 122 | } | 
| 123 | 123 | |
| 124 | 124 |  function js_redirect_to($action, $seconds = 0.01){ | 
| 125 | - $seconds*=1000; | |
| 126 | -	return "<script type=\"text/javascript\">setTimeout('window.location=\"?/$action\"', $seconds)</script>"; | |
| 125 | + $seconds*=1000; | |
| 126 | +    return "<script type=\"text/javascript\">setTimeout('window.location=\"?/$action\"', $seconds)</script>"; | |
| 127 | 127 | } | 
| 128 | 128 | |
| 129 | 129 |  function button_to_action($caption, $action, $attributes=''){ | 
| 130 | - return "<button type='button' $attributes onclick='window.location=\"".PUBLIC_PATH."$action\"'>$caption</button>"; | |
| 130 | + return "<button type='button' $attributes onclick='window.location=\"".PUBLIC_PATH."$action\"'>$caption</button>"; | |
| 131 | 131 | } | 
| @@ -1,131 +1,131 @@ | ||
| 1 | 1 | <?php | 
| 2 | 2 | |
| 3 | -function javascript_include_tag($src){ | |
| 4 | - return "<script type='text/javascript' src='".PUBLIC_PATH."js/$src.js'></script>\r\n"; | |
| 3 | +function javascript_include_tag($src) { | |
| 4 | + return "<script type='text/javascript' src='" . PUBLIC_PATH . "js/$src.js'></script>\r\n"; | |
| 5 | 5 | } | 
| 6 | 6 | |
| 7 | -function stylesheet_link($src=''){ | |
| 8 | - return "<link rel='stylesheet' type='text/css' href='".PUBLIC_PATH."css/$src.css'/>\r\n"; | |
| 7 | +function stylesheet_link($src = '') { | |
| 8 | + return "<link rel='stylesheet' type='text/css' href='" . PUBLIC_PATH . "css/$src.css'/>\r\n"; | |
| 9 | 9 | } | 
| 10 | 10 | |
| 11 | -function link_to($action, $text, $attributes=''){ | |
| 12 | - return "<a href='".PUBLIC_PATH."$action' $attributes>$text</a>"; | |
| 11 | +function link_to($action, $text, $attributes = '') { | |
| 12 | + return "<a href='" . PUBLIC_PATH . "$action' $attributes>$text</a>"; | |
| 13 | 13 | } | 
| 14 | 14 | |
| 15 | -function img_tag($img, $attributes=''){ | |
| 16 | - return "<img src='".PUBLIC_PATH."img/$img' $attributes />\r\n"; | |
| 15 | +function img_tag($img, $attributes = '') { | |
| 16 | + return "<img src='" . PUBLIC_PATH . "img/$img' $attributes />\r\n"; | |
| 17 | 17 | } | 
| 18 | 18 | |
| 19 | -function form_tag($action, $attributes=''){ | |
| 20 | - return "<form action='".PUBLIC_PATH."$action' $attributes>\r\n"; | |
| 19 | +function form_tag($action, $attributes = '') { | |
| 20 | + return "<form action='" . PUBLIC_PATH . "$action' $attributes>\r\n"; | |
| 21 | 21 | } | 
| 22 | 22 | |
| 23 | -function end_form_tag(){ | |
| 23 | +function end_form_tag() { | |
| 24 | 24 | return "</form>\r\n"; | 
| 25 | 25 | } | 
| 26 | 26 | |
| 27 | -function submit_tag($caption, $attributes=''){ | |
| 27 | +function submit_tag($caption, $attributes = '') { | |
| 28 | 28 | return "<input type='submit' value='$caption' $attributes />\r\n"; | 
| 29 | 29 | } | 
| 30 | 30 | |
| 31 | -function button_tag($caption, $type='button', $attributes=''){ | |
| 31 | +function button_tag($caption, $type = 'button', $attributes = '') { | |
| 32 | 32 | return "<button type='$type' $attributes>$caption</button>\r\n"; | 
| 33 | 33 | } | 
| 34 | 34 | |
| 35 | 35 | function get_field_name_and_id($name) | 
| 36 | 36 |  { | 
| 37 | - $id=""; | |
| 37 | + $id = ""; | |
| 38 | 38 |  	if (strpos($name, ".") != false) { | 
| 39 | 39 |  		$items = explode(".", $name); | 
| 40 | -		$id=" id='{$items[0]}_{$items[1]}' "; | |
| 41 | - $name = $items[0]."[".$items[1]."]"; | |
| 40 | +		$id = " id='{$items[0]}_{$items[1]}' "; | |
| 41 | + $name = $items[0] . "[" . $items[1] . "]"; | |
| 42 | 42 | } | 
| 43 | 43 | return [$id, $name]; | 
| 44 | 44 | } | 
| 45 | 45 | |
| 46 | -function text_field_tag($name, $value='', $attributes=''){ | |
| 46 | +function text_field_tag($name, $value = '', $attributes = '') { | |
| 47 | 47 | list($id, $name) = get_field_name_and_id($name); | 
| 48 | 48 | |
| 49 | 49 | return "<input type='text' name='$name' $id value='$value' $attributes />\r\n"; | 
| 50 | 50 | } | 
| 51 | 51 | |
| 52 | -function password_field_tag($name, $value='', $attributes=''){ | |
| 52 | +function password_field_tag($name, $value = '', $attributes = '') { | |
| 53 | 53 | list($id, $name) = get_field_name_and_id($name); | 
| 54 | 54 | |
| 55 | 55 | return "<input type='password' name='$name' $id value='$value' $attributes />\r\n"; | 
| 56 | 56 | } | 
| 57 | 57 | |
| 58 | -function text_area_tag($name, $value='', $attributes=''){ | |
| 58 | +function text_area_tag($name, $value = '', $attributes = '') { | |
| 59 | 59 | list($id, $name) = get_field_name_and_id($name); | 
| 60 | 60 | |
| 61 | 61 | return "<textarea name='$name' $id $attributes>$value</textarea>\r\n"; | 
| 62 | 62 | } | 
| 63 | 63 | |
| 64 | -function hidden_field_tag($name, $value='', $attributes=''){ | |
| 64 | +function hidden_field_tag($name, $value = '', $attributes = '') { | |
| 65 | 65 | list($id, $name) = get_field_name_and_id($name); | 
| 66 | 66 | |
| 67 | 67 | return "<input type='hidden' name='$name' $id value='$value' $attributes />\r\n"; | 
| 68 | 68 | } | 
| 69 | 69 | |
| 70 | -function check_box_tag($name, $value, $text, $checked=false, $attributes=''){ | |
| 70 | +function check_box_tag($name, $value, $text, $checked = false, $attributes = '') { | |
| 71 | 71 | list($id, $name) = get_field_name_and_id($name); | 
| 72 | 72 | $checked = $checked == true ? ' checked ' : ''; | 
| 73 | 73 | return "<input type='checkbox' $id name='$name' $checked $attributes value='$value'/>\r\n"; | 
| 74 | 74 | } | 
| 75 | 75 | |
| 76 | -function radio_button_tag($name, $value, $checked=false, $attributes=''){ | |
| 76 | +function radio_button_tag($name, $value, $checked = false, $attributes = '') { | |
| 77 | 77 | list($id, $name) = get_field_name_and_id($name); | 
| 78 | 78 | $checked = $checked == true ? ' checked ' : ''; | 
| 79 | 79 | return "<input type='radio' $id name='$name' $checked $attributes value='$value'/>\r\n"; | 
| 80 | 80 | } | 
| 81 | 81 | |
| 82 | -function label_tag($field, $caption, $attributes='') { | |
| 82 | +function label_tag($field, $caption, $attributes = '') { | |
| 83 | 83 | return "<label for='$field' $attributes>$caption</label>\r\n"; | 
| 84 | 84 | } | 
| 85 | 85 | |
| 86 | -function select_tag($name='', $options, $include_blank=false, $attributes=''){ | |
| 86 | +function select_tag($name = '', $options, $include_blank = false, $attributes = '') { | |
| 87 | 87 | list($id, $name) = get_field_name_and_id($name); | 
| 88 | 88 | |
| 89 | 89 | $code = ""; | 
| 90 | 90 |  	if ($include_blank != false) { | 
| 91 | - $code="<option value=''>$include_blank</option>\r\n"; | |
| 91 | + $code = "<option value=''>$include_blank</option>\r\n"; | |
| 92 | 92 | } | 
| 93 | 93 | |
| 94 | 94 | return "<select $id name='$name' $attributes>\r\n$code$options</select>\r\n"; | 
| 95 | 95 | |
| 96 | 96 | } | 
| 97 | 97 | |
| 98 | -function options_for_dbselect($data, $show, $value, $selected='') | |
| 98 | +function options_for_dbselect($data, $show, $value, $selected = '') | |
| 99 | 99 |  { | 
| 100 | - $code=""; | |
| 101 | -	foreach($data as $item) { | |
| 102 | - $selected_tag=""; | |
| 103 | -		if ($selected == $item[$value]){ | |
| 100 | + $code = ""; | |
| 101 | +	foreach ($data as $item) { | |
| 102 | + $selected_tag = ""; | |
| 103 | +		if ($selected == $item[$value]) { | |
| 104 | 104 | $selected_tag = " selected='selected' "; | 
| 105 | 105 | } | 
| 106 | -		$code.="<option value='{$item[$value]}' $selected_tag>{$item[$show]}</option>\r\n"; | |
| 106 | +		$code .= "<option value='{$item[$value]}' $selected_tag>{$item[$show]}</option>\r\n"; | |
| 107 | 107 | } | 
| 108 | 108 | return $code; | 
| 109 | 109 | } | 
| 110 | 110 | |
| 111 | -function options_for_select($data, $selected='') | |
| 111 | +function options_for_select($data, $selected = '') | |
| 112 | 112 |  { | 
| 113 | - $code=""; | |
| 114 | -	foreach($data as $key => $value) { | |
| 115 | - $selected_tag=""; | |
| 116 | -		if ($selected == $value){ | |
| 113 | + $code = ""; | |
| 114 | +	foreach ($data as $key => $value) { | |
| 115 | + $selected_tag = ""; | |
| 116 | +		if ($selected == $value) { | |
| 117 | 117 | $selected_tag = " selected='selected' "; | 
| 118 | 118 | } | 
| 119 | - $code.="<option value='$key' $selected_tag>$value</option>\r\n"; | |
| 119 | + $code .= "<option value='$key' $selected_tag>$value</option>\r\n"; | |
| 120 | 120 | } | 
| 121 | 121 | return $code; | 
| 122 | 122 | } | 
| 123 | 123 | |
| 124 | -function js_redirect_to($action, $seconds = 0.01){ | |
| 125 | - $seconds*=1000; | |
| 124 | +function js_redirect_to($action, $seconds = 0.01) { | |
| 125 | + $seconds *= 1000; | |
| 126 | 126 |  	return "<script type=\"text/javascript\">setTimeout('window.location=\"?/$action\"', $seconds)</script>"; | 
| 127 | 127 | } | 
| 128 | 128 | |
| 129 | -function button_to_action($caption, $action, $attributes=''){ | |
| 130 | - return "<button type='button' $attributes onclick='window.location=\"".PUBLIC_PATH."$action\"'>$caption</button>"; | |
| 129 | +function button_to_action($caption, $action, $attributes = '') { | |
| 130 | + return "<button type='button' $attributes onclick='window.location=\"" . PUBLIC_PATH . "$action\"'>$caption</button>"; | |
| 131 | 131 | } | 
| @@ -6,49 +6,49 @@ | ||
| 6 | 6 | */ | 
| 7 | 7 | class Session | 
| 8 | 8 |  { | 
| 9 | - /** | |
| 10 | - * Permite obtener una entrada desde la variable $_SESSION | |
| 11 | - * de acuerdo a su clave $key | |
| 12 | - * @param string $key | |
| 13 | - * @return mixed | |
| 14 | - */ | |
| 15 | - public static function get(string $key) | |
| 16 | -	{ | |
| 17 | -		if (empty($_SESSION[$key])) { | |
| 18 | - return null; | |
| 19 | - } | |
| 9 | + /** | |
| 10 | + * Permite obtener una entrada desde la variable $_SESSION | |
| 11 | + * de acuerdo a su clave $key | |
| 12 | + * @param string $key | |
| 13 | + * @return mixed | |
| 14 | + */ | |
| 15 | + public static function get(string $key) | |
| 16 | +    { | |
| 17 | +        if (empty($_SESSION[$key])) { | |
| 18 | + return null; | |
| 19 | + } | |
| 20 | 20 | |
| 21 | - return $_SESSION[$key]; | |
| 22 | - } | |
| 21 | + return $_SESSION[$key]; | |
| 22 | + } | |
| 23 | 23 | |
| 24 | - /** | |
| 25 | - * Permite crear una entrada en la variable $_SESSION | |
| 26 | - * de acuerdo a su clave $key | |
| 27 | - * @param string $key | |
| 28 | - * @param mixed $value | |
| 29 | - * @return void | |
| 30 | - */ | |
| 31 | - public static function set(string $key, $value) | |
| 32 | -	{ | |
| 33 | - $_SESSION[$key] = $value; | |
| 34 | - } | |
| 24 | + /** | |
| 25 | + * Permite crear una entrada en la variable $_SESSION | |
| 26 | + * de acuerdo a su clave $key | |
| 27 | + * @param string $key | |
| 28 | + * @param mixed $value | |
| 29 | + * @return void | |
| 30 | + */ | |
| 31 | + public static function set(string $key, $value) | |
| 32 | +    { | |
| 33 | + $_SESSION[$key] = $value; | |
| 34 | + } | |
| 35 | 35 | |
| 36 | - /** | |
| 37 | - * Permite eliminar una entrada en la variable $_SESSION | |
| 38 | - * de acuerdo a su clave $key | |
| 39 | - * @param string $key | |
| 40 | - * @return void | |
| 41 | - */ | |
| 42 | - public static function delete(string $key) | |
| 43 | -	{ | |
| 44 | - unset($_SESSION[$key]); | |
| 45 | - } | |
| 36 | + /** | |
| 37 | + * Permite eliminar una entrada en la variable $_SESSION | |
| 38 | + * de acuerdo a su clave $key | |
| 39 | + * @param string $key | |
| 40 | + * @return void | |
| 41 | + */ | |
| 42 | + public static function delete(string $key) | |
| 43 | +    { | |
| 44 | + unset($_SESSION[$key]); | |
| 45 | + } | |
| 46 | 46 | |
| 47 | - /** | |
| 48 | - * Permite cerrar la sesión | |
| 49 | - */ | |
| 50 | - public static function destroy() | |
| 51 | -	{ | |
| 52 | - session_destroy(); | |
| 53 | - } | |
| 47 | + /** | |
| 48 | + * Permite cerrar la sesión | |
| 49 | + */ | |
| 50 | + public static function destroy() | |
| 51 | +    { | |
| 52 | + session_destroy(); | |
| 53 | + } | |
| 54 | 54 | } | 
| @@ -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 |