From: Kevin Day Date: Wed, 26 Apr 2017 03:25:00 +0000 (-0500) Subject: Progress: more path management changes, imrpove languages support, and other fixes X-Git-Url: https://git.kevux.org/?a=commitdiff_plain;h=34dd355407a6f07e6ac136b52a31d71c1ec22094;p=koopa Progress: more path management changes, imrpove languages support, and other fixes Continue developing path handling functionality. I've decided to implement language handling as sub-classes, using japanese as the first language to test with. Other bugfixes and tweaks. --- diff --git a/common/base/classes/base_http.php b/common/base/classes/base_http.php index 4beffbd..a510ef5 100644 --- a/common/base/classes/base_http.php +++ b/common/base/classes/base_http.php @@ -827,6 +827,54 @@ class c_base_http extends c_base_rfc_string { } /** + * Chooses a language based on available languages and the requested languages. + * + * Because multiple languages may be returned, this does not explicitly define the langugae headers. + * + * @param array $supported_languages + * An array of supported languages as defined in i_base_language. + * + * @return c_base_return_int + * An integer representing the language code as defined in i_base_language. + * 0 with the error bit set is returned on error. + * An integer representing the language code as defined in i_base_language with the error bit set is returned on error. + */ + public function select_language($supported_languages) { + if (!is_array($supported_languages) || empty($supported_languages)) { + $error = c_base_error::s_log(NULL, array('arguments' => array(':argument_name' => 'supported_languages', ':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::INVALID_ARGUMENT); + return c_base_return_error::s_value(0, 'c_base_return_int', $error); + } + + // specify a failsafe in case decision making has trouble. + $language_chosen = reset($supported_languages); + + if (isset($this->request[self::REQUEST_ACCEPT_LANGUAGE]['data']) && is_array($this->request[self::REQUEST_ACCEPT_LANGUAGE]['data'])) { + if (isset($this->request[self::REQUEST_ACCEPT_LANGUAGE]['invalid']) && $this->request[self::REQUEST_ACCEPT_LANGUAGE]['invalid']) {; + $error = c_base_error::s_log(NULL, array('arguments' => array(':argument_name' => 'supported_languages', ':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::INVALID_ARGUMENT); + return c_base_return_error::s_value($language_chosen, 'c_base_return_int', $error); + } + + if (isset($this->request[self::REQUEST_ACCEPT_LANGUAGE]['data']['weight']) && is_array($this->request[self::REQUEST_ACCEPT_LANGUAGE]['data']['weight'])) { + foreach ($this->request[self::REQUEST_ACCEPT_LANGUAGE]['data']['weight'] as $weight => $aliases) { + $alias = end($aliases); + $language_code = c_base_defaults_global::s_get_languages()::s_get_id_by_alias($alias)->get_value_exact(); + unset($alias); + + if (array_key_exists($language_code, $supported_languages)) { + $language_chosen = $language_code; + break; + } + } + unset($weight); + unset($aliases); + unset($language_code); + } + } + + return c_base_return_int::s_new($language_chosen); + } + + /** * Assign HTTP response header: access-control-allow-origin. * * Note on multiple urls: The standard appears to only support one url. @@ -2468,8 +2516,9 @@ class c_base_http extends c_base_rfc_string { * * Use self::SCHEME_LOCAL for a local filesystem link. * - * @param string $uri - * The URI to assign to the specified header. + * @param stringarray $uri + * When a string, the URI to assign to the specified header. + * When an array, an array of the destination url parts to assign to the specified header. * * @return c_base_return_status * TRUE on success, FALSE otherwise. @@ -2478,13 +2527,27 @@ class c_base_http extends c_base_rfc_string { * @see: https://tools.ietf.org/html/rfc3986 */ public function set_response_location($uri) { - if (!is_string($uri)) { + if (!is_string($uri) && !is_array($uri)) { $error = c_base_error::s_log(NULL, array('arguments' => array(':argument_name' => 'uri', ':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::INVALID_ARGUMENT); return c_base_return_error::s_false($error); } + if (is_array($uri)) { + $uri_string = $this->pr_rfc_string_combine_uri_array($uri); + if ($combined === FALSE) { + unset($parts); + unset($combined); - $text = $this->pr_rfc_string_prepare($uri); + $error = c_base_error::s_log(NULL, array('arguments' => array(':format_name' => 'URI or URL', ':expected_format' => 'URI or URL', ':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::INVALID_FORMAT); + return c_base_return_error::s_false($error); + } + unset($combined); + } + else { + $uri_string = $uri; + } + + $text = $this->pr_rfc_string_prepare($$uri_string); if ($text['invalid']) { unset($text); @@ -2502,7 +2565,6 @@ class c_base_http extends c_base_rfc_string { } unset($parsed['invalid']); - $this->response[self::RESPONSE_LOCATION] = $parsed; unset($parsed); @@ -8735,10 +8797,11 @@ class c_base_http extends c_base_rfc_string { $language_array = $this->languages->s_get_aliases_by_id($language); if ($language_array instanceof c_base_return_array) { $language_array = $language_array->get_value_exact(); - - if (!empty($language_array[0])) { - $output .= ', ' . $language_array[0]; + $alias = end($language_array); + if (!empty($alias)) { + $output .= ', ' . $alias; } + unset($alias); } unset($language_array); } @@ -8920,7 +8983,13 @@ class c_base_http extends c_base_rfc_string { return; } - // @todo + $header_output[self::RESPONSE_LOCATION] = $header_name . self::SEPARATOR_HEADER_NAME; + + $combined = self::pr_rfc_string_combine_uri_array($this->response[self::RESPONSE_LOCATION]); + if (is_string($combined)) { + $header_output[self::RESPONSE_LOCATION] .= $combined; + } + unset($combined); } /** diff --git a/common/base/classes/base_languages.php b/common/base/classes/base_languages.php index b893f98..e394a67 100644 --- a/common/base/classes/base_languages.php +++ b/common/base/classes/base_languages.php @@ -12,6 +12,7 @@ * @see: http://www.loc.gov/standards/iso639-2/php/code_list.php */ interface i_base_language { + const NONE = 0; const AFAR = 1; // aar, aa const ABKHAZIAN = 2; // abk, ab const ACHINESE = 3; // ace @@ -508,23 +509,23 @@ interface i_base_language { * @param int $id * The id of the names to return. * - * @return c_base_return_status|c_base_return_array - * An array of names or FALSE on error. - * FALSE without the error flag means that there are no names associated with the given id. + * @return c_base_return_array + * An array of names. + * An empty array with the error bit set is returned on error. */ - static function s_get_names_by_id($id); + public static function s_get_names_by_id($id); /** * Get the language names associated with the alias. * * @param string $alias - * The id of the names to return. + * The alias of the names to return. * - * @return c_base_return_status|c_base_return_array - * An array of names or FALSE on error. - * FALSE without the error flag means that there are no names associated with the given alias. + * @return c_base_return_array + * An array of names. + * An empty array with the error bit set is returned on error. */ - static function s_get_names_by_alias($alias); + public static function s_get_names_by_alias($alias); /** * Get the id associated with the language name. @@ -532,11 +533,11 @@ interface i_base_language { * @param string $name * The string associated with the id * - * @return c_base_return_status|c_base_return_int - * The numeric id or FALSE on error. - * FALSE without the error flag means that there are no ids associated with the given name. + * @return c_base_return_int + * The numeric id. + * 0 with the error bit set is returned on error. */ - static function s_get_id_by_name($name); + public static function s_get_id_by_name($name); /** * Get the id associated with the language name. @@ -544,11 +545,11 @@ interface i_base_language { * @param string $name * The string associated with the id * - * @return c_base_return_status|c_base_return_int - * The numeric id or FALSE on error. - * FALSE without the error flag means that there are no ids associated with the given name. + * @return c_base_return_int + * The numeric id. + * 0 with the error bit set is returned on error. */ - static function s_get_id_by_alias($alias); + public static function s_get_id_by_alias($alias); /** * Get the language aliases associated with the id. @@ -556,11 +557,11 @@ interface i_base_language { * @param int $id * The id of the aliases to return. * - * @return c_base_return_status|c_base_return_array - * An array of aliases or FALSE on error. - * FALSE without the error flag means that there are no aliases associated with the given id. + * @return c_base_return_array + * An array of aliases. + * An empty array with the error bit set is returned on error. */ - static function s_get_aliases_by_id($id); + public static function s_get_aliases_by_id($id); /** * Get the language aliases associated with the name. @@ -568,29 +569,57 @@ interface i_base_language { * @param string $name * The language name of the aliases to return. * - * @return c_base_return_status|c_base_return_array - * An array of aliases or FALSE on error. - * FALSE without the error flag means that there are no aliases associated with the given name. + * @return c_base_return_array + * An array of aliases. + * An empty array with the error bit set is returned on error. */ - static function s_get_aliases_by_name($name); + public static function s_get_aliases_by_name($name); /** * Get the id of the language considered to be default by the implementing class. * - * @return c_base_return_status|c_base_return_int + * @return c_base_return_int * An integer representing the default language. - * FALSE without the error flag means that there are no languages assigned as default. + * 0 without the error bit set is returned if there is no default language. + * 0 with the error bit set is returned on error. */ - static function s_get_default_id(); + public static function s_get_default_id(); /** * Get the name of the language considered to be default by the implementing class. * - * @return c_base_return_status|c_base_return_string + * @return c_base_return_string * A string representing the default language. - * FALSE without the error flag means that there are no languages assigned as default. + * An empty string with the error bit set is returned on error. + */ + public static function s_get_default_name(); + + /** + * Get an array of all ids associated with this class. + * + * @return c_base_return_array + * An array of ids, keyed by the unique ids. + * An empty array with the error bit set is returned on error. + */ + public static function s_get_ids(); + + /** + * Get an array of all aliases associated with this class. + * + * @return c_base_return_array + * An array of aliases, keyed by the unique ids. + * An empty array with error bit set is returned on error. */ - static function s_get_default_name(); + public static function s_get_aliases(); + + /** + * Get an array of all names associated with this class. + * + * @return c_base_return_array + * An array of names, keyed by the unique ids. + * An empty array with error bit set is returned on error. + */ + public static function s_get_names(); } /** @@ -624,164 +653,142 @@ final class c_base_language_us_only implements i_base_language { /** - * Get the language names associated with the id. - * - * @param int $id - * The id of the names to return. - * - * @return c_base_return_status|c_base_return_array - * An array of names or FALSE on error. - * FALSE without the error flag means that there are no names associated with the given id. + * Implementation of s_get_names_by_id(). */ - static function s_get_names_by_id($id) { + public static function s_get_names_by_id($id) { if (!is_int($id) && !is_numeric($id)) { $error = c_base_error::s_log(NULL, array('arguments' => array(':argument_name' => 'id', ':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::INVALID_ARGUMENT); - return c_base_return_error::s_false($error); + return c_base_return_error::s_value(array(), 'c_base_return_array', $error); } if (array_key_exists($id, self::$s_names)) { return c_base_return_array::s_new(self::$s_names[$id]); } - return new c_base_return_false(); + return new c_base_return_array(); } /** - * Get the language names associated with the alias. - * - * @param string $alias - * The id of the names to return. - * - * @return c_base_return_status|c_base_return_array - * An array of names or FALSE on error. - * FALSE without the error flag means that there are no names associated with the given alias. + * Implementation of s_get_names_by_alias(). */ - static function s_get_names_by_alias($alias) { - if (!is_int($id) && !is_numeric($id)) { - $error = c_base_error::s_log(NULL, array('arguments' => array(':argument_name' => 'id', ':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::INVALID_ARGUMENT); - return c_base_return_error::s_false($error); + public static function s_get_names_by_alias($alias) { + if (!is_string($alias)) { + $error = c_base_error::s_log(NULL, array('arguments' => array(':argument_name' => 'alias', ':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::INVALID_ARGUMENT); + return c_base_return_error::s_value(array(), 'c_base_return_array', $error); } - if (array_key_exists($id, self::$s_aliases)) { - return c_base_return_array::s_new(self::$s_aliases[$id]); + if (array_key_exists($alias, self::$s_ids) && array_key_exists(self::$s_ids[$alias], self::$s_names)) { + return c_base_return_array::s_new(self::$s_names[$self::$s_ids[$alias]]); } - return new c_base_return_false(); + return new c_base_return_array(); } /** - * Get the id associated with the language name. - * - * @param string $name - * The string associated with the id - * - * @return c_base_return_status|c_base_return_int - * The numeric id or FALSE on error. - * FALSE without the error flag means that there are no ids associated with the given name. + * Implementation of s_get_id_by_name(). */ - static function s_get_id_by_name($name) { + public static function s_get_id_by_name($name) { if (!is_string($name)) { $error = c_base_error::s_log(NULL, array('arguments' => array(':argument_name' => 'name', ':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::INVALID_ARGUMENT); - return c_base_return_error::s_false($error); + return c_base_return_error::s_value(0, 'c_base_return_int', $error); } if (array_key_exists($name, self::$s_ids)) { return c_base_return_int::s_new(self::$s_ids[$name]); } - return new c_base_return_false(); + return new c_base_return_int(); } /** - * Get the id associated with the language name. - * - * @param string $name - * The string associated with the id - * - * @return c_base_return_status|c_base_return_int - * The numeric id or FALSE on error. - * FALSE without the error flag means that there are no ids associated with the given name. + * Implementation of s_get_id_by_alias(). */ - static function s_get_id_by_alias($alias) { + public static function s_get_id_by_alias($alias) { if (!is_string($alias)) { $error = c_base_error::s_log(NULL, array('arguments' => array(':argument_name' => 'alias', ':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::INVALID_ARGUMENT); - return c_base_return_error::s_false($error); + return c_base_return_error::s_value(0, 'c_base_return_int', $error); } if (array_key_exists($alias, self::$s_ids)) { return c_base_return_int::s_new(self::$s_ids[$alias]); } - return new c_base_return_false(); + return new c_base_return_int(); } /** - * Get the language aliases associated with the id. - * - * @param int $id - * The id of the aliases to return. - * - * @return c_base_return_status|c_base_return_array - * An array of aliases or FALSE on error. - * FALSE without the error flag means that there are no aliases associated with the given id. + * Implementation of s_get_aliases_by_id(). */ - static function s_get_aliases_by_id($id) { + public static function s_get_aliases_by_id($id) { if (!is_int($id) && !is_numeric($id)) { $error = c_base_error::s_log(NULL, array('arguments' => array(':argument_name' => 'id', ':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::INVALID_ARGUMENT); - return c_base_return_error::s_false($error); + return c_base_return_error::s_value(array(), 'c_base_return_array', $error); } if (array_key_exists($id, self::$s_aliases)) { return c_base_return_array::s_new(self::$s_aliases[$id]); } - return new c_base_return_false(); + return new c_base_return_array(); } /** - * Get the language aliases associated with the name. - * - * @param string $name - * The language name of the aliases to return. - * - * @return c_base_return_status|c_base_return_array - * An array of aliases or FALSE on error. - * FALSE without the error flag means that there are no aliases associated with the given name. + * Implementation of s_get_aliases_by_name(). */ - static function s_get_aliases_by_name($name) { + public static function s_get_aliases_by_name($name) { if (!is_string($name)) { $error = c_base_error::s_log(NULL, array('arguments' => array(':argument_name' => 'name', ':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::INVALID_ARGUMENT); - return c_base_return_error::s_false($error); + return c_base_return_error::s_value(array(), 'c_base_return_array', $error); } if (array_key_exists($name, self::$s_aliases)) { return c_base_return_array::s_new(self::$s_aliases[$name]); } - return new c_base_return_false(); + return new c_base_return_array(); } /** - * Get the id of the language considered to be default by the implementing class. - * - * @return c_base_return_status|c_base_return_int - * An integer representing the default language. - * FALSE without the error flag means that there are no languages assigned as default. + * Implementation of s_get_default_id(). */ - static function s_get_default_id() { + public static function s_get_default_id() { return c_base_return_int::s_new(self::ENGLISH_US); } /** - * Get the name of the language considered to be default by the implementing class. - * - * @return c_base_return_status|c_base_return_string - * A string representing the default language. - * FALSE without the error flag means that there are no languages assigned as default. + * Implementation of s_get_default_name(). */ - static function s_get_default_name() { + public static function s_get_default_name() { return c_base_return_string::s_new($this->s_aliases[self::ENGLISH_US]); } + + /** + * Implementation of s_get_ids(). + */ + public static function s_get_ids() { + $ids = array(); + foreach (self::$s_aliases as $key => $value) { + $ids[$key] = $key; + } + unset($key); + unset($value); + + return c_base_return_array::s_new($ids); + } + + /** + * Implementation of s_get_aliases(). + */ + public static function s_get_aliases() { + return c_base_return_array::s_new(self::$s_aliases); + } + + /** + * Implementation of s_get_names(). + */ + public static function s_get_names() { + return c_base_return_array::s_new(self::$s_names); + } } /** @@ -849,164 +856,142 @@ final class c_base_language_limited implements i_base_language { /** - * Get the language names associated with the id. - * - * @param int $id - * The id of the names to return. - * - * @return c_base_return_status|c_base_return_array - * An array of names or FALSE on error. - * FALSE without the error flag means that there are no names associated with the given id. + * Implementation of s_get_names_by_id(). */ - static function s_get_names_by_id($id) { + public static function s_get_names_by_id($id) { if (!is_int($id) && !is_numeric($id)) { $error = c_base_error::s_log(NULL, array('arguments' => array(':argument_name' => 'id', ':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::INVALID_ARGUMENT); - return c_base_return_error::s_false($error); + return c_base_return_error::s_value(array(), 'c_base_return_array', $error); } if (array_key_exists($id, self::$s_names)) { return c_base_return_array::s_new(self::$s_names[$id]); } - return new c_base_return_false(); + return new c_base_return_array(); } /** - * Get the language names associated with the alias. - * - * @param string $alias - * The id of the names to return. - * - * @return c_base_return_status|c_base_return_array - * An array of names or FALSE on error. - * FALSE without the error flag means that there are no names associated with the given alias. + * Implementation of s_get_names_by_alias(). */ - static function s_get_names_by_alias($alias) { - if (!is_int($id) && !is_numeric($id)) { + public static function s_get_names_by_alias($alias) { + if (!is_string($alias)) { $error = c_base_error::s_log(NULL, array('arguments' => array(':argument_name' => 'alias', ':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::INVALID_ARGUMENT); - return c_base_return_error::s_false($error); + return c_base_return_error::s_value(array(), 'c_base_return_array', $error); } - if (array_key_exists($id, self::$s_aliases)) { - return c_base_return_array::s_new(self::$s_aliases[$id]); + if (array_key_exists($alias, self::$s_ids) && array_key_exists(self::$s_ids[$alias], self::$s_names)) { + return c_base_return_array::s_new(self::$s_names[$self::$s_ids[$alias]]); } - return new c_base_return_false(); + return new c_base_return_array(); } /** - * Get the id associated with the language name. - * - * @param string $name - * The string associated with the id - * - * @return c_base_return_status|c_base_return_int - * The numeric id or FALSE on error. - * FALSE without the error flag means that there are no ids associated with the given name. + * Implementation of s_get_id_by_name(). */ - static function s_get_id_by_name($name) { + public static function s_get_id_by_name($name) { if (!is_string($name)) { $error = c_base_error::s_log(NULL, array('arguments' => array(':argument_name' => 'name', ':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::INVALID_ARGUMENT); - return c_base_return_error::s_false($error); + return c_base_return_error::s_value(0, 'c_base_return_int', $error); } if (array_key_exists($name, self::$s_ids)) { return c_base_return_int::s_new(self::$s_ids[$name]); } - return new c_base_return_false(); + return new c_base_return_int(); } /** - * Get the id associated with the language name. - * - * @param string $name - * The string associated with the id - * - * @return c_base_return_status|c_base_return_int - * The numeric id or FALSE on error. - * FALSE without the error flag means that there are no ids associated with the given name. + * Implementation of s_get_id_by_alias(). */ - static function s_get_id_by_alias($alias) { + public static function s_get_id_by_alias($alias) { if (!is_string($alias)) { $error = c_base_error::s_log(NULL, array('arguments' => array(':argument_name' => 'alias', ':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::INVALID_ARGUMENT); - return c_base_return_error::s_false($error); + return c_base_return_error::s_value(0, 'c_base_return_int', $error); } if (array_key_exists($alias, self::$s_ids)) { return c_base_return_int::s_new(self::$s_ids[$alias]); } - return new c_base_return_false(); + return new c_base_return_int(); } /** - * Get the language aliases associated with the id. - * - * @param int $id - * The id of the aliases to return. - * - * @return c_base_return_status|c_base_return_array - * An array of aliases or FALSE on error. - * FALSE without the error flag means that there are no aliases associated with the given id. + * Implementation of s_get_aliases_by_id(). */ - static function s_get_aliases_by_id($id) { + public static function s_get_aliases_by_id($id) { if (!is_int($id) && !is_numeric($id)) { $error = c_base_error::s_log(NULL, array('arguments' => array(':argument_name' => 'id', ':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::INVALID_ARGUMENT); - return c_base_return_error::s_false($error); + return c_base_return_error::s_value(array(), 'c_base_return_array', $error); } if (array_key_exists($id, self::$s_aliases)) { return c_base_return_array::s_new(self::$s_aliases[$id]); } - return new c_base_return_false(); + return new c_base_return_array(); } /** - * Get the language aliases associated with the name. - * - * @param string $name - * The language name of the aliases to return. - * - * @return c_base_return_status|c_base_return_array - * An array of aliases or FALSE on error. - * FALSE without the error flag means that there are no aliases associated with the given name. + * Implementation of s_get_aliases_by_name(). */ - static function s_get_aliases_by_name($name) { + public static function s_get_aliases_by_name($name) { if (!is_string($name)) { $error = c_base_error::s_log(NULL, array('arguments' => array(':argument_name' => 'name', ':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::INVALID_ARGUMENT); - return c_base_return_error::s_false($error); + return c_base_return_error::s_value(array(), 'c_base_return_array', $error); } if (array_key_exists($name, self::$s_aliases)) { return c_base_return_array::s_new(self::$s_aliases[$name]); } - return new c_base_return_false(); + return new c_base_return_array(); } /** - * Get the id of the language considered to be default by the implementing class. - * - * @return c_base_return_status|c_base_return_int - * An integer representing the default language. - * FALSE without the error flag means that there are no languages assigned as default. + * Implementation of s_get_default_id(). */ - static function s_get_default_id() { + public static function s_get_default_id() { return c_base_return_int::s_new(self::ENGLISH_US); } /** - * Get the name of the language considered to be default by the implementing class. - * - * @return c_base_return_status|c_base_return_string - * A string representing the default language. - * FALSE without the error flag means that there are no languages assigned as default. + * Implementation of s_get_default_name(). */ - static function s_get_default_name() { + public static function s_get_default_name() { return c_base_return_string::s_new($this->s_aliases[self::ENGLISH_US]); } + + /** + * Implementation of s_get_ids(). + */ + public static function s_get_ids() { + $ids = array(); + foreach (self::$s_aliases as $key => $value) { + $ids[$key] = $key; + } + unset($key); + unset($value); + + return c_base_return_array::s_new($ids); + } + + /** + * Implementation of s_get_aliases(). + */ + public static function s_get_aliases() { + return c_base_return_array::s_new(self::$s_aliases); + } + + /** + * Implementation of s_get_names(). + */ + public static function s_get_names() { + return c_base_return_array::s_new(self::$s_names); + } } /** @@ -2690,162 +2675,140 @@ final class c_base_language_all implements i_base_language { /** - * Get the language names associated with the id. - * - * @param int $id - * The id of the names to return. - * - * @return c_base_return_status|c_base_return_array - * An array of names or FALSE on error. - * FALSE without the error flag means that there are no names associated with the given id. + * Implementation of s_get_names_by_id(). */ - static function s_get_names_by_id($id) { + public static function s_get_names_by_id($id) { if (!is_int($id) && !is_numeric($id)) { $error = c_base_error::s_log(NULL, array('arguments' => array(':argument_name' => 'id', ':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::INVALID_ARGUMENT); - return c_base_return_error::s_false($error); + return c_base_return_error::s_value(array(), 'c_base_return_array', $error); } if (array_key_exists($id, self::$s_names)) { return c_base_return_array::s_new(self::$s_names[$id]); } - return new c_base_return_false(); + return new c_base_return_array(); } /** - * Get the language names associated with the alias. - * - * @param string $alias - * The id of the names to return. - * - * @return c_base_return_status|c_base_return_array - * An array of names or FALSE on error. - * FALSE without the error flag means that there are no names associated with the given alias. + * Implementation of s_get_names_by_alias(). */ - static function s_get_names_by_alias($alias) { - if (!is_int($id) && !is_numeric($id)) { + public static function s_get_names_by_alias($alias) { + if (!is_string($alias)) { $error = c_base_error::s_log(NULL, array('arguments' => array(':argument_name' => 'alias', ':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::INVALID_ARGUMENT); - return c_base_return_error::s_false($error); + return c_base_return_error::s_value(array(), 'c_base_return_array', $error); } - if (array_key_exists($id, self::$s_aliases)) { - return c_base_return_array::s_new(self::$s_aliases[$id]); + if (array_key_exists($alias, self::$s_ids) && array_key_exists(self::$s_ids[$alias], self::$s_names)) { + return c_base_return_array::s_new(self::$s_names[$self::$s_ids[$alias]]); } - return new c_base_return_false(); + return new c_base_return_array(); } /** - * Get the id associated with the language name. - * - * @param string $name - * The string associated with the id - * - * @return c_base_return_status|c_base_return_int - * The numeric id or FALSE on error. - * FALSE without the error flag means that there are no ids associated with the given name. + * Implementation of s_get_id_by_name(). */ - static function s_get_id_by_name($name) { + public static function s_get_id_by_name($name) { if (!is_string($name)) { $error = c_base_error::s_log(NULL, array('arguments' => array(':argument_name' => 'name', ':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::INVALID_ARGUMENT); - return c_base_return_error::s_false($error); + return c_base_return_error::s_value(0, 'c_base_return_int', $error); } if (array_key_exists($name, self::$s_ids)) { return c_base_return_int::s_new(self::$s_ids[$name]); } - return new c_base_return_false(); + return new c_base_return_int(); } /** - * Get the id associated with the language name. - * - * @param string $name - * The string associated with the id - * - * @return c_base_return_status|c_base_return_int - * The numeric id or FALSE on error. - * FALSE without the error flag means that there are no ids associated with the given name. + * Implementation of s_get_id_by_alias(). */ - static function s_get_id_by_alias($alias) { + public static function s_get_id_by_alias($alias) { if (!is_string($alias)) { $error = c_base_error::s_log(NULL, array('arguments' => array(':argument_name' => 'alias', ':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::INVALID_ARGUMENT); - return c_base_return_error::s_false($error); + return c_base_return_error::s_value(0, 'c_base_return_int', $error); } if (array_key_exists($alias, self::$s_ids)) { return c_base_return_int::s_new(self::$s_ids[$alias]); } - return new c_base_return_false(); + return new c_base_return_int(); } /** - * Get the language aliases associated with the id. - * - * @param int $id - * The id of the aliases to return. - * - * @return c_base_return_status|c_base_return_array - * An array of aliases or FALSE on error. - * FALSE without the error flag means that there are no aliases associated with the given id. + * Implementation of s_get_aliases_by_id(). */ - static function s_get_aliases_by_id($id) { + public static function s_get_aliases_by_id($id) { if (!is_int($id) && !is_numeric($id)) { $error = c_base_error::s_log(NULL, array('arguments' => array(':argument_name' => 'id', ':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::INVALID_ARGUMENT); - return c_base_return_error::s_false($error); + return c_base_return_error::s_value(array(), 'c_base_return_array', $error); } if (array_key_exists($id, self::$s_aliases)) { return c_base_return_array::s_new(self::$s_aliases[$id]); } - return new c_base_return_false(); + return new c_base_return_array(); } /** - * Get the language aliases associated with the name. - * - * @param string $name - * The language name of the aliases to return. - * - * @return c_base_return_status|c_base_return_array - * An array of aliases or FALSE on error. - * FALSE without the error flag means that there are no aliases associated with the given name. + * Implementation of s_get_aliases_by_name(). */ - static function s_get_aliases_by_name($name) { + public static function s_get_aliases_by_name($name) { if (!is_string($name)) { $error = c_base_error::s_log(NULL, array('arguments' => array(':argument_name' => 'name', ':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::INVALID_ARGUMENT); - return c_base_return_error::s_false($error); + return c_base_return_error::s_value(array(), 'c_base_return_array', $error); } if (array_key_exists($name, self::$s_aliases)) { return c_base_return_array::s_new(self::$s_aliases[$name]); } - return new c_base_return_false(); + return new c_base_return_array(); } /** - * Get the id of the language considered to be default by the implementing class. - * - * @return c_base_return_status|c_base_return_int - * An integer representing the default language. - * FALSE without the error flag means that there are no languages assigned as default. + * Implementation of s_get_default_id(). */ - static function s_get_default_id() { + public static function s_get_default_id() { return c_base_return_int::s_new(self::ENGLISH_US); } /** - * Get the name of the language considered to be default by the implementing class. - * - * @return c_base_return_status|c_base_return_string - * A string representing the default language. - * FALSE without the error flag means that there are no languages assigned as default. + * Implementation of s_get_default_name(). */ - static function s_get_default_name() { + public static function s_get_default_name() { return c_base_return_string::s_new($this->s_aliases[self::ENGLISH_US]); } + + /** + * Implementation of s_get_ids(). + */ + public static function s_get_ids() { + $ids = array(); + foreach (self::$s_aliases as $key => $value) { + $ids[$key] = $key; + } + unset($key); + unset($value); + + return c_base_return_array::s_new($ids); + } + + /** + * Implementation of s_get_aliases(). + */ + public static function s_get_aliases() { + return c_base_return_array::s_new(self::$s_aliases); + } + + /** + * Implementation of s_get_names(). + */ + public static function s_get_names() { + return c_base_return_array::s_new(self::$s_names); + } } diff --git a/common/base/classes/base_path.php b/common/base/classes/base_path.php index 8821533..c3cde25 100644 --- a/common/base/classes/base_path.php +++ b/common/base/classes/base_path.php @@ -251,7 +251,6 @@ class c_base_path extends c_base_rfc_string { * 0 may be assigned to represent no group. * @param string $field_path * The URL path assigned to this field. - * This is not assigned on parameter error. * @param bool $is_private * (optional) When TRUE, path is considered private and requires specific access privileges. * When FALSE, the path is accessible without any access privileges. @@ -269,13 +268,8 @@ class c_base_path extends c_base_rfc_string { // @todo: store all errors on return. $errors = array(); - if (is_int($id_group)) { - $path->set_id_group($id_group); - } - - if (is_string($field_path)) { - $path->set_value($field_path); - } + $path->set_id_group($id_group); + $path->set_value($field_path); if (is_bool($is_private)) { $path->set_is_private($is_private); @@ -304,9 +298,9 @@ class c_base_path extends c_base_rfc_string { * 0 may be assigned to represent no group. * @param string $field_path * The URL path assigned to this field. - * This is not assigned on parameter error. - * @param string $field_destination - * A destination URL to in which this is an alias of. + * @param string|array $field_destination + * When a string, a destination URL to redirect to. + * When an array, an array of the destination url parts. * @param bool $is_private * (optional) When TRUE, path is considered private and requires specific access privileges. * When FALSE, the path is accessible without any access privileges. @@ -324,17 +318,9 @@ class c_base_path extends c_base_rfc_string { // @todo: store all errors on return. $errors = array(); - if (is_int($id_group)) { - $path->set_id_group($id_group); - } - - if (is_string($field_path)) { - $path->set_value($field_path); - } - - if (is_string($field_destination)) { - $path->set_field_destination($field_destination); - } + $path->set_id_group($id_group); + $path->set_value($field_path); + $path->set_field_destination($field_destination); if (is_bool($is_private)) { $path->set_is_private($is_private); @@ -358,8 +344,9 @@ class c_base_path extends c_base_rfc_string { * * Defaults are silently forced on invalid parameters. * - * @param string $field_destination - * A destination URL to redirect to. + * @param string|array $field_destination + * When a string, a destination URL to redirect to. + * When an array, an array of the destination url parts. * @param int $response_code * The HTTP code to use when performing the redirect. * Should be one of 3xx error code integers. @@ -370,7 +357,6 @@ class c_base_path extends c_base_rfc_string { * - 300 (Multiple Choices): * - 301 (Moved Permanently): * - 303 (See Other): - * This is not assigned on parameter error. * @param bool $is_private * (optional) When TRUE, path is considered private and requires specific access privileges. * When FALSE, the path is accessible without any access privileges. @@ -388,13 +374,8 @@ class c_base_path extends c_base_rfc_string { // @todo: store all errors on return. $errors = array(); - if (is_string($field_destination)) { - $path->set_field_destination($field_destination); - } - - if (is_int($field_response_code)) { - $path->set_field_response_code($field_response_code); - } + $path->set_field_destination($field_destination); + $path->set_field_response_code($field_response_code); if (is_bool($is_private)) { $path->set_is_private($is_private); @@ -607,14 +588,15 @@ class c_base_path extends c_base_rfc_string { /** * Assigns the destination field setting. * - * @param string $field_destination - * The destination field associated with the path. + * @param string|array $field_destination + * When a string, a destination URL to redirect to. + * When an array, an array of the destination url parts. * * @return c_base_return_status * TRUE on success, FALSE otherwise. */ public function set_field_destination($field_destination) { - if (!is_string($field_destination)) { + if (!is_string($field_destination) && !is_array($field_destination)) { $error = c_base_error::s_log(NULL, array('arguments' => array(':argument_name' => 'field_destination', ':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::INVALID_ARGUMENT); return c_base_return_error::s_false($error); } @@ -828,17 +810,21 @@ class c_base_path extends c_base_rfc_string { /** * Gets the destination field setting. * - * @return c_base_return_string + * @return c_base_return_string|c_base_return_array * Destination field on success. * An empty string is returned if not defined. * Error bit is set on error. */ public function get_field_destination() { - if (!is_string($this->field_destination)) { + if (!is_string($this->field_destination) && !is_array($this->field_destination)) { return c_base_return_string::s_new(''); } - return c_base_return_string::s_new($this->field_destination); + if (is_string($this->field_destination)) { + return c_base_return_string::s_new($this->field_destination); + } + + return c_base_return_array::s_new($this->field_destination); } /** @@ -930,9 +916,6 @@ class c_base_path extends c_base_rfc_string { * The database object, which is usually used by form and ajax paths. * @param c_base_session &$session * The current session. - * @pram c_base_html &$html - * The HTML object. - * If the content is not renderring HTML, the output parameter should instead be used for providing content. * @param array $settings * (optional) An array of additional settings that are usually site-specific. * @@ -940,7 +923,7 @@ class c_base_path extends c_base_rfc_string { * An executed array object is returned on success. * An executed array object with error bit set is returned on error. */ - public function do_execute(&$http, &$database, &$session, &$html, $settings = array()) { + public function do_execute(&$http, &$database, &$session, $settings = array()) { if (!($database instanceof c_base_database)) { $error = c_base_error::s_log(NULL, array('arguments' => array(':argument_name' => 'database', ':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::INVALID_ARGUMENT); return c_base_return_error::s_value(array(), 'c_base_path_executed', $error); @@ -956,11 +939,6 @@ class c_base_path extends c_base_rfc_string { return c_base_return_error::s_value(array(), 'c_base_path_executed', $error); } - if (!($html instanceof c_base_html)) { - $error = c_base_error::s_log(NULL, array('arguments' => array(':argument_name' => 'html', ':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::INVALID_ARGUMENT); - return c_base_return_error::s_value(array(), 'c_base_path_executed', $error); - } - if (!is_array($settings)) { $error = c_base_error::s_log(NULL, array('arguments' => array(':argument_name' => 'settings', ':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::INVALID_ARGUMENT); return c_base_return_error::s_value(array(), 'c_base_path_executed', $error); @@ -1138,7 +1116,7 @@ class c_base_path_executed extends c_base_return_array { /** * Assign output. * - * @param c_base_value + * @param c_base_return * The output to assign. * * @return c_base_return_status @@ -1146,7 +1124,7 @@ class c_base_path_executed extends c_base_return_array { * FALSE with error bit set is returned on error. */ public function set_output($output) { - if (!($output instanceof c_base_value)) { + if (!($output instanceof c_base_return)) { $error = c_base_error::s_log(NULL, array('arguments' => array(':argument_name' => 'output', ':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::INVALID_ARGUMENT); return c_base_return_error::s_false($error); } @@ -1158,7 +1136,7 @@ class c_base_path_executed extends c_base_return_array { /** * Gets the assigned output * - * @return c_base_return_value|c_base_return_null + * @return c_base_return|c_base_return_null * The assigned output is returned. * If there is no assigned output (generally when execution is not performed) NULL is returned. */ @@ -1260,7 +1238,7 @@ class c_base_paths extends c_base_return { } if (mb_strlen($path) == 0) { - $this->root = array('handler' => $handler, 'include' => $include); + $this->root = array('handler' => $handler, 'include' => $include, 'is_root' => TRUE); return new c_base_return_true(); } @@ -1293,7 +1271,7 @@ class c_base_paths extends c_base_return { $id_group = $ordinal; } unset($ordinal); - unset($path_pats[0]); + unset($path_parts[0]); } if (!is_array($this->paths)) { @@ -1363,7 +1341,7 @@ class c_base_paths extends c_base_return { if (is_null($path_string) || mb_strlen($path_string) == 0) { if (is_array($this->root)) { - return $this->root; + return c_base_return_array::s_new($this->root); } return new c_base_return_null(); @@ -1383,7 +1361,7 @@ class c_base_paths extends c_base_return { unset($path); // if the sanitized path is different from the original, then send a url redirect. - if (strcmp($path_string, $sanitized) != 0) { + if (strcmp($path_string, $sanitized) != 0 && $path_string != '/' . $sanitized) { return c_base_return_array::s_new(array('redirect' => $sanitized, 'code' => c_base_http_status::MOVED_PERMANENTLY)); } @@ -1399,14 +1377,14 @@ class c_base_paths extends c_base_return { $id_group = $ordinal; } unset($ordinal); - unset($path_pats[0]); + unset($path_parts[0]); } $depth_current = 1; $depth_total = count($path_parts); $found = NULL; - $path_tree = &$this->paths[$sort]; + $path_tree = &$this->paths[$id_group]; foreach ($path_parts as $path_part) { if ($depth_current == $depth_total) { if (isset($path_tree['handler'])) { diff --git a/common/base/classes/base_rfc_string.php b/common/base/classes/base_rfc_string.php index be02c3a..0c44f75 100644 --- a/common/base/classes/base_rfc_string.php +++ b/common/base/classes/base_rfc_string.php @@ -3671,7 +3671,7 @@ abstract class c_base_rfc_string extends c_base_rfc_char { $combined = NULL; if (isset($uri_array['scheme'])) { - $combined .= $uri_array['scheme'] . ':'; + $combined .= $uri_array['scheme'] . '://'; } if (isset($uri_array['authority'])) { @@ -3687,30 +3687,7 @@ abstract class c_base_rfc_string extends c_base_rfc_char { $combined .= '?' . $uri_array['query']; } elseif (is_array($uri_array['query'])) { - $combined .= '?'; - - reset($uri_array['query']); - $query_name = key($uri_array['query']); - $query_value = $uri_array['query'][$query_name]; - unset($uri_array['query'][$query_name]); - - if (is_null($query_value)) { - $combined .= $query_name; - } - else { - $combined .= $query_name . '=' . $query_value; - } - - foreach ($uri_array['query'] as $query_name => $query_value) { - if (is_null($query_value)) { - $combined .= $query_name; - continue; - } - - $combined .= '&' . $query_name . '=' . $query_value; - } - unset($query_name); - unset($query_value); + $combined .= '?' . http_build_query($uri_array['query'], '', '&', PHP_QUERY_RFC3986); } } diff --git a/database/sql/reservation/reservation-users.sql b/database/sql/reservation/reservation-users.sql index 95c11c6..6dcfa3b 100644 --- a/database/sql/reservation/reservation-users.sql +++ b/database/sql/reservation/reservation-users.sql @@ -654,7 +654,7 @@ create function s_administers.f_users_update_materialized_views() returns trigge end; $$ language plpgsql; -alter function s_administers.f_users_update_as_administer() owner to r_reservation_administer; +alter function s_administers.f_users_update_materialized_views() owner to r_reservation_administer; create trigger tr_users_insert_actions before insert on s_tables.t_users diff --git a/program/reservation/index.php b/program/reservation/index.php index 89e21bf..e24708d 100644 --- a/program/reservation/index.php +++ b/program/reservation/index.php @@ -1,420 +1,338 @@ do_load_request(); + // default supported languages. + c_base_defaults_global::s_set_languages(new c_base_language_limited()); - // Assign a default response protocol. - $http->set_response_protocol('HTTP/1.1'); + return $settings; +} - // Assign a default response status (expected to be overridden by path handlers). - $http->set_response_status(c_base_http_status::OK); - - return $http; - } - - /** - * Send HTTP response. - * - * @param c_base_http $http - * Http object. - */ - function reservation_send_response($http) { - // add headers - $http->set_response_date(); - $http->set_response_content_type('text/html'); - $http->set_response_content_language(); - #$http->set_response_etag(); - #$http->set_response_last_modified(strtotime('now')); - #$http->set_response_expires(strtotime('+30 minutes')); - $http->set_response_pragma('no-cache'); - $http->set_response_vary('Host'); - $http->set_response_vary('User-Agent'); - $http->set_response_vary('Accept'); - $http->set_response_vary('Accept-Language'); - #$http->set_response_warning('1234 This site is under active development.'); - - // finalize the content prior to sending headers to ensure header accuracy. - $http->encode_response_content(); - - - // manually disable output buffering (if enabled) when transfer headers and content. - $old_output_buffering = ini_get('output_buffering'); - ini_set('output_buffering', 'off'); - - - // when the headers are sent, checksums are created, so at this point all error output should be stored and not sent. - $http->send_response_headers(TRUE); +/** + * Process HTTP request. + * + * @return c_base_http + * Processed and loaded request. + */ +function reservation_receive_request() { + $http = new c_base_http(); + $http->do_load_request(); + // Assign a default response protocol. + $http->set_response_protocol('HTTP/1.1'); - // once the header are sent, send the content. - $http->send_response_content(); + // Assign a default response status (expected to be overridden by path handlers). + $http->set_response_status(c_base_http_status::OK); - - ini_set('output_buffering', $old_output_buffering); - unset($old_output_buffering); + // get the current language and assign the default. + $languages = c_base_defaults_global::s_get_languages()::s_get_ids()->get_value_exact(); + if (!is_array($languages) || empty($languages)) { + $languages = array(i_base_language::ENGLISH_US => i_base_language::ENGLISH_US, i_base_language::ENGLISH => i_base_language::ENGLISH); } - /** - * Process page request. - * - * @param c_base_http &$http - * Http object. - * @param c_base_database &$databbase - * The database object. - * @param array &$settings - * System settings - * @param c_base_session &$session - * Session information. - * - * @return c_base_html|c_base_return_array - * The generated html is returned on success. - * In certain cases, an array is returned for special handling, such as redirects. - */ - function reservation_process_request(&$http, &$database, &$settings, &$session) { - $html = new c_base_html(); - - - // assign class attribute - $class = array( - 'reservation', - 'no-script', - 'is-html5', - ); - - $html->set_attribute(c_base_markup_attributes::ATTRIBUTE_CLASS, $class); - unset($class); - - - // assign id attribute - $html->set_attribute(c_base_markup_attributes::ATTRIBUTE_ID, 'reservation-system'); - - - // assign language attribute - $html->set_attribute(c_base_markup_attributes::ATTRIBUTE_LANGUAGE, i_base_language::ENGLISH_US); - - - // assign direction attribute - $html->set_attribute(c_base_markup_attributes::ATTRIBUTE_DIRECTION, 'ltr'); - - - // assign title header tag (setting title tag at delta 0 so that it can easily be overriden as needed). - $tag = new c_base_markup_tag(); - $tag->set_type(c_base_markup_tag::TYPE_TITLE); - $tag->set_text('Reservation System'); - $html->set_header($tag, 0); - unset($tag); - - - // assign base header tag - #$tag = c_theme_html::s_create_tag(c_base_markup_tag::TYPE_BASE); - #$tag->set_attribute(c_base_markup_attributes::ATTRIBUTE_HREF, 'http://localhost/'); - #$html->set_header($tag); - #unset($tag); - - - // assign http-equiv header tag - $tag = c_theme_html::s_create_tag(c_base_markup_tag::TYPE_META); - $tag->set_attribute(c_base_markup_attributes::ATTRIBUTE_HTTP_EQUIV, 'Content-Type'); - $tag->set_attribute(c_base_markup_attributes::ATTRIBUTE_CONTENT, 'text/html; charset=utf-8'); - $html->set_header($tag); - unset($tag); - - - // assign charset header tag - $tag = c_theme_html::s_create_tag(c_base_markup_tag::TYPE_META); - $tag->set_attribute(c_base_markup_attributes::ATTRIBUTE_CHARACTER_SET, c_base_charset::UTF_8); - $html->set_header($tag); - unset($tag); - - - // assign canonical header tag - #$tag = c_theme_html::s_create_tag(c_base_markup_tag::TYPE_META); - #$tag->set_attribute(c_base_markup_attributes::ATTRIBUTE_REL, 'canonical'); - #$tag->set_attribute(c_base_markup_attributes::ATTRIBUTE_HREF, 'http://localhost/'); - #$html->set_header($tag); - #unset($tag); - + $selected = $http->select_language($languages)->get_value_exact(); - // assign shortlink header tag - #$tag = c_theme_html::s_create_tag(c_base_markup_tag::TYPE_META); - #$tag->set_attribute(c_base_markup_attributes::ATTRIBUTE_REL, 'shortlink'); - #$tag->set_attribute(c_base_markup_attributes::ATTRIBUTE_HREF, '/'); - #$html->set_header($tag); - #unset($tag); - - - // assign description header tag - $tag = c_theme_html::s_create_tag(c_base_markup_tag::TYPE_META); - $tag->set_attribute(c_base_markup_attributes::ATTRIBUTE_NAME, 'description'); - $tag->set_attribute(c_base_markup_attributes::ATTRIBUTE_CONTENT, 'A reservation/scheduling system.'); - $html->set_header($tag); - unset($tag); - - - // assign distribution header tag - $tag = c_theme_html::s_create_tag(c_base_markup_tag::TYPE_META); - $tag->set_attribute(c_base_markup_attributes::ATTRIBUTE_NAME, 'distribution'); - $tag->set_attribute(c_base_markup_attributes::ATTRIBUTE_CONTENT, 'web'); - $html->set_header($tag); - unset($tag); - - - // assign robots header tag - $tag = c_theme_html::s_create_tag(c_base_markup_tag::TYPE_META); - $tag->set_attribute(c_base_markup_attributes::ATTRIBUTE_NAME, 'robots'); - $tag->set_attribute(c_base_markup_attributes::ATTRIBUTE_CONTENT, 'INDEX,FOLLOW'); - $html->set_header($tag); - unset($tag); - - - // assign expires header tag - #$tag = c_theme_html::s_create_tag(c_base_markup_tag::TYPE_META); - #$tag->set_attribute(c_base_markup_attributes::ATTRIBUTE_HTTP_EQUIV, 'expires'); - #$tag->set_attribute(c_base_markup_attributes::ATTRIBUTE_CONTENT, c_base_defaults_global::s_get_date('r', strtotime('+30 minutes'))->get_value_exact()); - #$html->set_header($tag); - #unset($tag); + // select the primary language. + $http->set_response_content_language($selected, FALSE); + // this website is primary us-english (and therefore english), also set this as an additional language because multi-lingual support is not 100% guaranteed. + if ($selected != i_base_language::ENGLISH_US) { + $http->set_response_content_language(i_base_language::ENGLISH_US); + } - // assign viewport header tag - $tag = c_theme_html::s_create_tag(c_base_markup_tag::TYPE_META); - $tag->set_attribute(c_base_markup_attributes::ATTRIBUTE_NAME, 'viewport'); - $tag->set_attribute(c_base_markup_attributes::ATTRIBUTE_CONTENT, 'width=device-width, initial-scale=1'); - $html->set_header($tag); - unset($tag); + if ($selected != i_base_language::ENGLISH) { + $http->set_response_content_language(i_base_language::ENGLISH); + } + unset($selected); + + return $http; +} + +/** + * Send HTTP response. + * + * @param c_base_http $http + * Http object. + */ +function reservation_send_response($http) { + // add headers + $http->set_response_date(); + $http->set_response_content_type('text/html'); + #$http->set_response_etag(); + #$http->set_response_last_modified(strtotime('now')); + #$http->set_response_expires(strtotime('+30 minutes')); + $http->set_response_pragma('no-cache'); + $http->set_response_vary('Host'); + $http->set_response_vary('User-Agent'); + $http->set_response_vary('Accept'); + $http->set_response_vary('Accept-Language'); + #$http->set_response_warning('1234 This site is under active development.'); + + // finalize the content prior to sending headers to ensure header accuracy. + $http->encode_response_content(); + + + // manually disable output buffering (if enabled) when transfer headers and content. + $old_output_buffering = ini_get('output_buffering'); + ini_set('output_buffering', 'off'); + + + // when the headers are sent, checksums are created, so at this point all error output should be stored and not sent. + $http->send_response_headers(TRUE); + + + // once the header are sent, send the content. + $http->send_response_content(); + + + ini_set('output_buffering', $old_output_buffering); + unset($old_output_buffering); +} + +/** + * Process page request. + * + * @param c_base_http &$http + * Http object. + * @param c_base_database &$databbase + * The database object. + * @param array &$settings + * System settings + * @param c_base_session &$session + * Session information. + * + * @return c_base_return + * The generated html is returned on success. + * The generated text is returned on success. + * This does not set the error bit on error. + */ +function reservation_process_request(&$http, &$database, &$session, &$settings) { + $session_user = $session->get_name()->get_value_exact(); + if (is_null($session_user)) { + $logged_in = FALSE; + + // @todo: delete old cookies, if they expire. + $cookie_login = $session->get_cookie(); + + // @fixme: shouldn't this check be in the session management code? + // the session should already be logged into at this point. + // if the session id exists, but no user id is defined, then the session is no longer valid, so delete the invalid cookie. + if (!empty($session->get_session_id()->get_value_exact())) { + $cookie_login->set_expires(-1); + $cookie_login->set_max_age(-1); + $session->set_cookie($cookie_login); + unset($cookie_login); - if (!isset($_SERVER["HTTPS"])) { - //reservation_login_page_require_https($settings, $session, $html); - // @todo: provide custom https required page. - return $html; + $session->set_session_id(NULL); } + } + else { + $user_name = $session->get_name()->get_value(); + $password = $session->get_password()->get_value(); - $session_user = $session->get_name()->get_value_exact(); - if (is_null($session_user)) { - $logged_in = FALSE; - - // @todo: delete old cookies, if they expire. - $cookie_login = $session->get_cookie(); - - // @fixme: shouldn't this check be in the session management code? - // the session should already be logged into at this point. - // if the session id exists, but no user id is defined, then the session is no longer valid, so delete the invalid cookie. - if (!empty($session->get_session_id()->get_value_exact())) { - $cookie_login->set_expires(-1); - $cookie_login->set_max_age(-1); - $session->set_cookie($cookie_login); - unset($cookie_login); + if (is_null($user_name) || is_null($password)) { + unset($user_name); + unset($password); - $session->set_session_id(NULL); - } + $logged_in = FALSE; } else { $logged_in = TRUE; - } - - $paths = new c_reservation_paths(); - $paths->reservation_process_path($http, $database, $session, $html, $settings, $logged_in); - unset($logged_in); - unset($paths); - - return $html; - } - - /** - * Render the theme. - * - * @param c_base_http $http - * Http object. - * @param c_base_html $html - * The HTML object. - */ - function reservation_render_theme($http, $html) { - $theme = new c_theme_html(); - $theme->set_html($html); - $theme->set_http($http); - $theme->render_markup(); - - return $theme->get_markup(); - } + reservation_database_string($database, $settings, $user_name, $password); - /** - * Build the HTTP response. - * - * @param c_base_http &$http - * Http object. - * @param c_base_session &$session - * Session information. - * @param string $markup - * The HTML markup. - */ - function reservation_build_response(&$http, &$session, $markup) { - $http->set_response_checksum_header(c_base_http::CHECKSUM_ACTION_AUTO); - $http->set_response_content($markup); - - - // send the session cookie if a session id is specified. - $session_id = $session->get_session_id()->get_value_exact(); - if (!empty($session_id)) { - $cookie_login = $session->get_cookie(); - - if ($cookie_login instanceof c_base_cookie) { - $http->set_response_set_cookie($cookie_login); - } - unset($cookie_login); + unset($user_name); + unset($password); } - unset($session_id); - - return new c_base_return_true(); } - /** - * Main Program Function - * - * note: Future designs will likely include content caching. - * There are different designs based on the type of content that can be used for caching. - * The following are some common generic areas to cache: - * - design 1 (public content): 3, 4. 5 (cache handling happens between 2 and 3). - * - design 2 (database bypass): 4 (4 is to be replaced with cache handling). - * - design 3 (theme bypass): 4. 5 (4 is to be replaced with cache handling). - * - design 4 (full private cache): 4. 5, 6* (should still handling login access, only (vary) headers are to be changed in 6). - * - design 5 (full public cache): 3, 4. 5, 6* (should still handling login access, only (vary) headers are to be changed in 6). - * - * It is also recommended that some placeholders are added to the css body to provide dynamic css class names, even on cached content. - */ - function reservation_main() { - // 1: local settings: - $settings = reservation_load_settings(); - gc_collect_cycles(); - - - // 2: receive request information. - $http = reservation_receive_request(); - gc_collect_cycles(); - - - // 3: process session information - $session = reservation_process_sessions($http, $settings); - gc_collect_cycles(); - - - // 4: perform actions, process work. - $database = new c_base_database(); - $html = reservation_process_request($http, $database, $settings, $session); - if (!($html instanceof c_base_html)) { - $html = new c_base_html(); - } - - if ($database->is_connected() instanceof c_base_return_true) { - $database->do_disconnect(); + $paths = new c_reservation_paths(); + $executed = $paths->reservation_process_path($http, $database, $session, $settings, $logged_in); + unset($logged_in); + unset($paths); + + return $executed->get_output(); +} + +/** + * Render the theme. + * + * @param c_base_http $http + * Http object. + * @param c_base_return $output + * The HTML object. + */ +function reservation_render_theme($http, $output) { + $theme = new c_theme_html(); + $theme->set_html($output); // @fixme: this needs to be changed from set_html() to set_output() to handle more types of content. + $theme->set_http($http); + $theme->render_markup(); + + return $theme->get_markup(); +} + +/** + * Build the HTTP response. + * + * @param c_base_http &$http + * Http object. + * @param c_base_session &$session + * Session information. + * @param string $markup + * The HTML markup. + */ +function reservation_build_response(&$http, &$session, $markup) { + $http->set_response_checksum_header(c_base_http::CHECKSUM_ACTION_AUTO); + $http->set_response_content($markup); + + + // send the session cookie if a session id is specified. + $session_id = $session->get_session_id()->get_value_exact(); + if (!empty($session_id)) { + $cookie_login = $session->get_cookie(); + + if ($cookie_login instanceof c_base_cookie) { + $http->set_response_set_cookie($cookie_login); } - unset($database); - gc_collect_cycles(); + unset($cookie_login); + } + unset($session_id); + + return new c_base_return_true(); +} + +/** + * Main Program Function + * + * note: Future designs will likely include content caching. + * There are different designs based on the type of content that can be used for caching. + * The following are some common generic areas to cache: + * - design 1 (public content): 3, 4. 5 (cache handling happens between 2 and 3). + * - design 2 (database bypass): 4 (4 is to be replaced with cache handling). + * - design 3 (theme bypass): 4. 5 (4 is to be replaced with cache handling). + * - design 4 (full private cache): 4. 5, 6* (should still handling login access, only (vary) headers are to be changed in 6). + * - design 5 (full public cache): 3, 4. 5, 6* (should still handling login access, only (vary) headers are to be changed in 6). + * + * It is also recommended that some placeholders are added to the css body to provide dynamic css class names, even on cached content. + */ +function reservation_main() { + // 1: local settings: + $settings = reservation_load_settings(); + gc_collect_cycles(); + + + // 2: receive request information. + $http = reservation_receive_request(); + gc_collect_cycles(); + + + // 3: process session information + $session = reservation_process_sessions($http, $settings); + gc_collect_cycles(); + + + // 4: perform actions, process work. + $database = new c_base_database(); + $output = reservation_process_request($http, $database, $session, $settings); + + if ($database->is_connected() instanceof c_base_return_true) { + $database->do_disconnect(); + } + unset($database); + gc_collect_cycles(); - // 5: build or finalize theme. - $markup = reservation_render_theme($http, $html)->get_value_exact(); - unset($html); - gc_collect_cycles(); + // 5: build or finalize theme. + $markup = reservation_render_theme($http, $output)->get_value_exact(); + unset($output); + gc_collect_cycles(); - // 6: build response information. - reservation_build_response($http, $session, $markup); - unset($markup); - gc_collect_cycles(); + // 6: build response information. + reservation_build_response($http, $session, $markup); + unset($markup); + gc_collect_cycles(); - // 7: send HTTP response. - reservation_send_response($http); - gc_collect_cycles(); + // 7: send HTTP response. + reservation_send_response($http); + gc_collect_cycles(); - unset($settings); - unset($http); - unset($session); - gc_collect_cycles(); - } + unset($settings); + unset($http); + unset($session); + gc_collect_cycles(); +} - reservation_main(); +reservation_main(); diff --git a/program/reservation/internal/access_denied.php b/program/reservation/internal/access_denied.php index 703d22c..af302fe 100644 --- a/program/reservation/internal/access_denied.php +++ b/program/reservation/internal/access_denied.php @@ -13,14 +13,13 @@ require_once('common/base/classes/base_session.php'); require_once('common/theme/classes/theme_html.php'); -final class c_reservation_path_access_denied extends c_base_path { - +class c_reservation_path_access_denied extends c_base_path { /** * Implements do_execute(). */ - public function do_execute(&$http, &$database, &$session, &$html, $settings = array()) { + public function do_execute(&$http, &$database, &$session, $settings = array()) { // the parent function performs validation on the parameters. - $executed = parent::do_execute($http, $database, $session, $html, $settings); + $executed = parent::do_execute($http, $database, $session, $settings); if (c_base_return::s_has_error($executed)) { return $executed; } @@ -32,21 +31,27 @@ final class c_reservation_path_access_denied extends c_base_path { // H1 $tag = c_theme_html::s_create_tag(c_base_markup_tag::TYPE_H1); - $tag->set_text('Access Denied'); + $tag->set_text($this->pr_get_text(0)); $wrapper->set_tag($tag); unset($tag); // Content $tag = c_theme_html::s_create_tag(c_base_markup_tag::TYPE_DIVIDER); - $tag->set_text('You are not authorized to access this resource.'); + $tag->set_text($this->pr_get_text(1)); $wrapper->set_tag($tag); unset($tag); + // initialize the content as HTML. + $html = c_reservation_build::s_create_html($http, $database, $session, $settings, $this->pr_get_title()); $html->set_tag($wrapper); unset($wrapper); + $executed = new c_base_path_executed(); + $executed->set_output($html); + unset($html); + // assign HTTP response status. $http->set_response_status(c_base_http_status::FORBIDDEN); @@ -54,4 +59,34 @@ final class c_reservation_path_access_denied extends c_base_path { return $executed; } + + /** + * Load the title text associated with this page. + * + * This is provided here as a means for a language class to override with a custom language for the title. + * + * @return string|null + * A string is returned as the custom title. + * NULL is returned to enforce default title. + */ + protected function pr_get_title() { + return NULL; + } + + /** + * Load text for a supported language. + * + * @param int $index + * A number representing which block of text to return. + */ + protected function pr_get_text($code) { + switch ($code) { + case 0: + return 'Access Denied'; + case 1: + return 'You are not authorized to access this resource.'; + } + + return ''; + } } diff --git a/program/reservation/internal/bad_method.php b/program/reservation/internal/bad_method.php index 7a22ca0..b40b287 100644 --- a/program/reservation/internal/bad_method.php +++ b/program/reservation/internal/bad_method.php @@ -13,15 +13,15 @@ require_once('common/base/classes/base_session.php'); require_once('common/theme/classes/theme_html.php'); -final class c_reservation_path_not_found extends c_base_path { +class c_reservation_path_bad_method extends c_base_path { /** * Implements do_execute(). */ - public function do_execute(&$http, &$database, &$session, &$html, $settings = array()) { + public function do_execute(&$http, &$database, &$session, $settings = array()) { // @todo: This needs to return the HTTP invalid method response status. // the parent function performs validation on the parameters. - $executed = parent::do_execute($http, $database, $session, $html, $settings); + $executed = parent::do_execute($http, $database, $session, $settings); if (c_base_return::s_has_error($executed)) { return $executed; } @@ -33,21 +33,27 @@ final class c_reservation_path_not_found extends c_base_path { // H1 $tag = c_theme_html::s_create_tag(c_base_markup_tag::TYPE_H1); - $tag->set_text('Bad Method'); + $tag->set_text($this->pr_get_text(0)); $wrapper->set_tag($tag); unset($tag); // Content $tag = c_theme_html::s_create_tag(c_base_markup_tag::TYPE_DIVIDER); - $tag->set_text('The provided HTTP request method is either unsupported or invalid for the request path.'); + $tag->set_text($this->pr_get_text(1)); $wrapper->set_tag($tag); unset($tag); + // initialize the content as HTML. + $html = c_reservation_build::s_create_html($http, $database, $session, $settings, $this->pr_get_title()); $html->set_tag($wrapper); unset($wrapper); + $executed = new c_base_path_executed(); + $executed->set_output($html); + unset($html); + // assign HTTP response status. $http->set_response_status(c_base_http_status::METHOD_NOT_ALLOWED); @@ -55,4 +61,34 @@ final class c_reservation_path_not_found extends c_base_path { return $executed; } + + /** + * Load the title text associated with this page. + * + * This is provided here as a means for a language class to override with a custom language for the title. + * + * @return string|null + * A string is returned as the custom title. + * NULL is returned to enforce default title. + */ + protected function pr_get_title() { + return NULL; + } + + /** + * Load text for a supported language. + * + * @param int $index + * A number representing which block of text to return. + */ + protected function pr_get_text($code) { + switch ($code) { + case 0: + return 'Bad Method'; + case 1: + return 'The provided HTTP request method is either unsupported or invalid for the request path.'; + } + + return ''; + } } diff --git a/program/reservation/internal/ja/access_denied.php b/program/reservation/internal/ja/access_denied.php new file mode 100644 index 0000000..b197b8c --- /dev/null +++ b/program/reservation/internal/ja/access_denied.php @@ -0,0 +1,28 @@ +set_text('Page Not Found'); + $tag->set_text($this->pr_get_text(0)); $wrapper->set_tag($tag); unset($tag); // Content $tag = c_theme_html::s_create_tag(c_base_markup_tag::TYPE_DIVIDER); - $tag->set_text('The page you requested is not available.'); + $tag->set_text($this->pr_get_text(1)); $wrapper->set_tag($tag); unset($tag); + // initialize the content as HTML. + $html = c_reservation_build::s_create_html($http, $database, $session, $settings, $this->pr_get_title()); $html->set_tag($wrapper); unset($wrapper); + $executed = new c_base_path_executed(); + $executed->set_output($html); + unset($html); + // assign HTTP response status. $http->set_response_status(c_base_http_status::NOT_FOUND); + return $executed; } + + /** + * Load the title text associated with this page. + * + * This is provided here as a means for a language class to override with a custom language for the title. + * + * @return string|null + * A string is returned as the custom title. + * NULL is returned to enforce default title. + */ + protected function pr_get_title() { + return NULL; + } + + /** + * Load text for a supported language. + * + * @param int $index + * A number representing which block of text to return. + */ + protected function pr_get_text($code) { + switch ($code) { + case 0: + return 'Page Not Found'; + case 1: + return 'The page you requested is not available.'; + } + + return ''; + } } diff --git a/program/reservation/internal/server_error.php b/program/reservation/internal/server_error.php new file mode 100644 index 0000000..9efd4d5 --- /dev/null +++ b/program/reservation/internal/server_error.php @@ -0,0 +1,92 @@ +set_text($this->pr_get_text(0)); + $wrapper->set_tag($tag); + unset($tag); + + + // Content + $tag = c_theme_html::s_create_tag(c_base_markup_tag::TYPE_DIVIDER); + $tag->set_text($this->pr_get_text(1)); + $wrapper->set_tag($tag); + unset($tag); + + + // initialize the content as HTML. + $html = c_reservation_build::s_create_html($http, $database, $session, $settings, $this->pr_get_title()); + $html->set_tag($wrapper); + unset($wrapper); + + $executed = new c_base_path_executed(); + $executed->set_output($html); + unset($html); + + + // assign HTTP response status. + $http->set_response_status(c_base_http_status::INTERNAL_SERVER_ERROR); + + + return $executed; + } + + /** + * Load the title text associated with this page. + * + * This is provided here as a means for a language class to override with a custom language for the title. + * + * @return string|null + * A string is returned as the custom title. + * NULL is returned to enforce default title. + */ + protected function pr_get_title() { + return NULL; + } + + /** + * Load text for a supported language. + * + * @param int $index + * A number representing which block of text to return. + */ + protected function pr_get_text($code) { + switch ($code) { + case 0: + return 'Server Error'; + case 1: + return 'Something went wrong while processing your request, please try again later.'; + } + + return ''; + } +} diff --git a/program/reservation/paths/u/dashboard.php b/program/reservation/paths/u/dashboard.php index 75139ab..1e48187 100644 --- a/program/reservation/paths/u/dashboard.php +++ b/program/reservation/paths/u/dashboard.php @@ -13,23 +13,13 @@ require_once('common/base/classes/base_session.php'); require_once('common/theme/classes/theme_html.php'); -final class c_reservation_path_user_dashboard extends c_base_path { - - /** - * Class constructor. - */ - public function __construct() { - parent::__construct(); - - $this->is_root = TRUE; - } - +class c_reservation_path_user_dashboard extends c_base_path { /** * Implements do_execute(). */ - public function do_execute(&$http, &$database, &$session, &$html, $settings = array()) { + public function do_execute(&$http, &$database, &$session, $settings = array()) { // the parent function performs validation on the parameters. - $executed = parent::do_execute($http, $database, $session, $html, $settings); + $executed = parent::do_execute($http, $database, $session, $settings); if (c_base_return::s_has_error($executed)) { return $executed; } @@ -41,12 +31,12 @@ final class c_reservation_path_user_dashboard extends c_base_path { // Dashboard Content $tag = c_theme_html::s_create_tag(c_base_markup_tag::TYPE_H1); - $tag->set_text('Dashboard'); + $tag->set_text($this->pr_get_text(0)); $wrapper->set_tag($tag); unset($tag); $tag = c_theme_html::s_create_tag(c_base_markup_tag::TYPE_DIVIDER); - $tag->set_text('All links will go here.'); + $tag->set_text($this->pr_get_text(1)); $wrapper->set_tag($tag); unset($tag); @@ -58,12 +48,12 @@ final class c_reservation_path_user_dashboard extends c_base_path { unset($roles_object); $tag = c_theme_html::s_create_tag(c_base_markup_tag::TYPE_DIVIDER); - $tag->set_text('You are currently logged in as: ' . $settings['database_user']); + $tag->set_text($this->pr_get_text(2) . $settings['database_user']); $wrapper->set_tag($tag); unset($tag); $tag = c_theme_html::s_create_tag(c_base_markup_tag::TYPE_DIVIDER); - $tag->set_text('You are currently assigned the following roles:'); + $tag->set_text($this->pr_get_text(3)); $wrapper->set_tag($tag); unset($tag); @@ -74,40 +64,40 @@ final class c_reservation_path_user_dashboard extends c_base_path { switch ($role) { case c_base_roles::PUBLIC: - $tag_li->set_text('Public'); + $tag_li->set_text($this->pr_get_text(4)); break; case c_base_roles::USER: - $tag_li->set_text('User'); + $tag_li->set_text($this->pr_get_text(5)); break; case c_base_roles::REQUESTER: - $tag_li->set_text('Requester'); + $tag_li->set_text($this->pr_get_text(6)); break; case c_base_roles::DRAFTER: - $tag_li->set_text('Drafter'); + $tag_li->set_text($this->pr_get_text(7)); break; case c_base_roles::EDITOR: - $tag_li->set_text('Editor'); + $tag_li->set_text($this->pr_get_text(8)); break; case c_base_roles::REVIEWER: - $tag_li->set_text('Reviewer'); + $tag_li->set_text($this->pr_get_text(9)); break; case c_base_roles::FINANCER: - $tag_li->set_text('Financer'); + $tag_li->set_text($this->pr_get_text(10)); break; case c_base_roles::INSURER: - $tag_li->set_text('Insurer'); + $tag_li->set_text($this->pr_get_text(11)); break; case c_base_roles::PUBLISHER: - $tag_li->set_text('Publisher'); + $tag_li->set_text($this->pr_get_text(12)); break; case c_base_roles::AUDITOR: - $tag_li->set_text('Auditor'); + $tag_li->set_text($this->pr_get_text(13)); break; case c_base_roles::MANAGER: - $tag_li->set_text('Manager'); + $tag_li->set_text($this->pr_get_text(14)); break; case c_base_roles::ADMINISTER: - $tag_li->set_text('Administer'); + $tag_li->set_text($this->pr_get_text(15)); break; } @@ -118,10 +108,59 @@ final class c_reservation_path_user_dashboard extends c_base_path { $wrapper->set_tag($tag_ul); - + // initialize the content as HTML. + $html = c_reservation_build::s_create_html($http, $database, $session, $settings); $html->set_tag($wrapper); - unset($wrapper); + + $executed = new c_base_path_executed(); + $executed->set_output($html); + unset($html); return $executed; } + + /** + * Load text for a supported language. + * + * @param int $index + * A number representing which block of text to return. + */ + protected function pr_get_text($code) { + switch ($code) { + case 0: + return 'Dashboard'; + case 1: + return 'All links will go here.'; + case 2: + return 'You are currently logged in as: '; + case 3: + return 'You are currently assigned the following roles:'; + case 4: + return 'Public'; + case 5: + return 'User'; + case 6: + return 'Requester'; + case 7: + return 'Drafter'; + case 8: + return 'Editor'; + case 9: + return 'Reviewer'; + case 10: + return 'Financer'; + case 11: + return 'Insurer'; + case 12: + return 'Publisher'; + case 13: + return 'Auditor'; + case 14: + return 'Manager'; + case 15: + return 'Administer'; + } + + return ''; + } } diff --git a/program/reservation/paths/u/login.php b/program/reservation/paths/u/login.php index bc4ee30..383ccca 100644 --- a/program/reservation/paths/u/login.php +++ b/program/reservation/paths/u/login.php @@ -17,18 +17,22 @@ require_once('common/theme/classes/theme_html.php'); * * This listens on: /u/login */ -final class c_reservation_path_user_login extends c_base_path { +class c_reservation_path_user_login extends c_base_path { + private const PATH_REDIRECTS = 'program/reservation/reservation_redirects.php'; /** * Implements do_execute(). */ - public function do_execute(&$http, &$database, &$session, &$html, $settings = array()) { + public function do_execute(&$http, &$database, &$session, $settings = array()) { // the parent function performs validation on the parameters. - $executed = parent::do_execute($http, $database, $session, $html, $settings); + $executed = parent::do_execute($http, $database, $session, $settings); if (c_base_return::s_has_error($executed)) { return $executed; } + // initialize the content as HTML. + $html = c_reservation_build::s_create_html($http, $database, $session, $settings); + // handle any resulting errors. $problem_fields = array(); @@ -58,8 +62,15 @@ final class c_reservation_path_user_login extends c_base_path { } elseif ($login_result instanceof c_base_return_true) { // successfully logged in. + require_once(self::PATH_REDIRECTS); + + $destination = $settings['uri']; + $destination['path'] = $settings['base_path'] . '/u/dashboard'; + // note: by using a SEE OTHER redirect, the client knows to make a GET request and that the redirect is temporary. - $redirect = c_reservation_path_redirect::s_create_redirect('/u/dashboard', c_base_http_status::SEE_OTHER, FALSE); + $redirect = c_reservation_path_redirect::s_create_redirect($destination, c_base_http_status::SEE_OTHER, FALSE); + unset($destination); + return $redirect->do_execute($http, $database, $session, $html, $settings); } @@ -101,7 +112,7 @@ final class c_reservation_path_user_login extends c_base_path { // H1 $tag = c_theme_html::s_create_tag(c_base_markup_tag::TYPE_H1); - $tag->set_text('Login to System'); + $tag->set_text($this->pr_get_text(0)); $form->set_tag($tag); unset($tag); @@ -130,7 +141,7 @@ final class c_reservation_path_user_login extends c_base_path { // label: username $tag = c_theme_html::s_create_tag(c_base_markup_tag::TYPE_LABEL, NULL, array('login_form-label-username')); $tag->set_attribute(c_base_markup_attributes::ATTRIBUTE_FOR, 'login_form-username'); - $tag->set_text('Username'); + $tag->set_text($this->pr_get_text(1)); $form->set_tag($tag); unset($tag); @@ -155,7 +166,7 @@ final class c_reservation_path_user_login extends c_base_path { // label: password $tag = c_theme_html::s_create_tag(c_base_markup_tag::TYPE_LABEL, NULL, array('login_form-label-password')); $tag->set_attribute(c_base_markup_attributes::ATTRIBUTE_FOR, 'login_form-password'); - $tag->set_text('Password'); + $tag->set_text($this->pr_get_text(2)); $form->set_tag($tag); unset($tag); @@ -198,9 +209,15 @@ final class c_reservation_path_user_login extends c_base_path { $wrapper->set_tag($form); unset($form); + + // assing the content. $html->set_tag($wrapper); unset($wrapper); + $executed = new c_base_path_executed(); + $executed->set_output($html); + unset($html); + return $executed; } @@ -415,6 +432,8 @@ final class c_reservation_path_user_login extends c_base_path { $pushed = $session->do_push($settings['session_expire'], $settings['session_max']); $session->do_disconnect(); + reservation_get_current_roles($database, $session, $settings); + $cookie_login = NULL; if (c_base_return::s_has_error($pushed)) { $socket_error = $session->get_error_socket(); @@ -459,4 +478,23 @@ final class c_reservation_path_user_login extends c_base_path { return c_base_return_array::s_new($problems); } + + /** + * Load text for a supported language. + * + * @param int $index + * A number representing which block of text to return. + */ + protected function pr_get_text($code) { + switch ($code) { + case 0: + return 'Login to System'; + case 1: + return 'Username'; + case 2: + return 'Password'; + } + + return ''; + } } diff --git a/program/reservation/paths/u/logout.php b/program/reservation/paths/u/logout.php index 7301bb6..4e165ad 100644 --- a/program/reservation/paths/u/logout.php +++ b/program/reservation/paths/u/logout.php @@ -16,14 +16,14 @@ require_once('common/theme/classes/theme_html.php'); * * This listens on: /s/u/logout */ -final class c_reservation_path_form_user_logout extends c_base_path { +class c_reservation_path_form_user_logout extends c_base_path { /** * Implements do_execute(). */ - public function do_execute(&$http, &$database, &$session, &$html, $settings = array()) { + public function do_execute(&$http, &$database, &$session, $settings = array()) { // the parent function performs validation on the parameters. - $executed = parent::do_execute($http, $database, $session, $html, $settings); + $executed = parent::do_execute($http, $database, $session, $settings); if (c_base_return::s_has_error($executed)) { return $executed; } @@ -35,31 +35,34 @@ final class c_reservation_path_form_user_logout extends c_base_path { // H1 $tag = c_theme_html::s_create_tag(c_base_markup_tag::TYPE_H1); - $tag->set_text('You Have Logged Out'); + $tag->set_text($this->pr_get_text(0)); $wrapper->set_tag($tag); unset($tag); // H1 $tag = c_theme_html::s_create_tag(c_base_markup_tag::TYPE_DIVIDER); - $tag->set_text('You have been logged out of the system.'); + $tag->set_text($this->pr_get_text(1)); $wrapper->set_tag($tag); unset($tag); + + // initialize the content as HTML. + $html = c_reservation_build::s_create_html($http, $database, $session, $settings); $html->set_tag($wrapper); unset($wrapper); + $executed = new c_base_path_executed(); + $executed->set_output($html); + unset($html); reservation_session_logout($database, $session, $settings); return $executed; } - /** * Logout of the session. * - * @fixme: much of this is just a carbon copy of the login form and needs to be rewritten accordingly. - * * @param c_base_database &$database * The database object. * @param c_base_session &$session @@ -72,245 +75,22 @@ final class c_reservation_path_form_user_logout extends c_base_path { * An array of problems on failure. */ private function p_do_logout(&$database, &$session, $settings) { - // @fixme: below is a copy and paste of the login form, it needs to be replaced with the logout code! - $problems = array(); - if (empty($_POST['login_form-username'])) { - $problems[] = c_base_form_problem::s_create_error('login_form-username', 'No valid username has been supplied.'); - } - - if (empty($_POST['login_form-password'])) { - $problems[] = c_base_form_problem::s_create_error('login_form-password', 'No valid password has been supplied.'); - } - - // explicitly deny access to internal user accounts - if ($_POST['login_form-username'] == 'u_reservation_public') { - $problems[] = c_base_form_problem::s_create_error('login_form-username', 'Unable to login, an incorrect user name or password has been specified.'); - } - - // return current list of problems before continuing to login attempt with credentials. - if (!empty($problems)) { - return c_base_return_array::s_new($problems); - } - - $session->set_name($_POST['login_form-username']); - $session->set_password($_POST['login_form-password']); - - // the database string must be rebuilt using the new username and password. - reservation_database_string($database, $settings, $_POST['login_form-username'], $_POST['login_form-password']); - - $access_denied = FALSE; - $error_messages = array(); - $connected = reservation_database_connect($database); - if (c_base_return::s_has_error($connected)) { - // try to determine what the warning is. - // this is not very accurate/efficient, but scanning the string appears to be the only way to identify the error. - $errors = $connected->get_error(); - - // @todo: walk through all errors instead of just checking the first. - $error = reset($errors); - unset($errors); - - $details = $error->get_details(); - unset($error); - - if (isset($details['arguments'][':failure_reasons'][0]['message'])) { - // in the case where the database cannot be connected to, do not attempt to ensure user account. - if (preg_match('/could not connect to server: connection refused/i', $details['arguments'][':failure_reasons'][0]['message']) > 0) { - // @todo: separate messages for admin users and public users. - #foreach ($details['arguments'][':failure_reasons'] as $error_message) { - # $error_messages[] = $error_message; - #} - #unset($error_message); - unset($details); - - $problems[] = c_base_form_problem::s_create_error(NULL, 'Unable to login, cannot connect to the database.'); - return c_base_return_array::s_new($problems); - } - elseif (preg_match('/no pg_hba\.conf entry for host/i', $details['arguments'][':failure_reasons'][0]['message']) > 0) { - // the account either does note exist or is not authorized. - // it is a pity that postgresql doesn't differentiate the two. - $access_denied = TRUE; - } - else { - $problems[] = c_base_form_problem::s_create_error(NULL, 'Unable to login, reason: ' . $details['arguments'][':failure_reasons'][0]['message'] . '.'); - unset($details); - - return c_base_return_array::s_new($problems); - } - } - unset($details); - - if ($access_denied) { - // it is possible the user name might not exist, so try to auto-create the username if the username does not exist. - $ensure_result = reservation_ensure_user_account($settings, $_POST['login_form-username']); - if ($ensure_result instanceof c_base_return_int) { - $ensure_result = $ensure_result->get_value_exact(); - - $connected = new c_base_return_false(); - if ($ensure_result === 0) { - // try again now that the system has attempted to ensure the user account exists. - $connected = reservation_database_connect($database); - if ($connected instanceof c_base_return_true) { - // @todo: add log entry. - #set_log_user($database, 'create_user'); - } - } - elseif ($ensure_result === 1) { - // invalid user name, bad characters, or name too long. - } - elseif ($ensure_result === 2) { - // failed to connect to the ldap server and could not query the ldap name. - } - elseif ($ensure_result === 3) { - // user name not found in ldap database. - } - elseif ($ensure_result === 4) { - // 4 = failed to connect to the database. - } - elseif ($ensure_result === 5) { - // 5 = error returned while executing the SQL command. - } - elseif ($ensure_result === 6) { - // 6 = error occured while reading input from the user (such as via recv()). - } - elseif ($ensure_result === 7) { - // 7 = error occured while writing input from the user (such as via send()). - } - elseif ($ensure_result === 8) { - // 8 = the received packet is invalid, such as wrong length. - } - elseif ($ensure_result === 9) { - // 10 = connection timed out when reading or writing. - } - elseif ($ensure_result === 10) { - // 10 = the connection is being forced closed. - } - elseif ($ensure_result === 11) { - // 11 = the connection is closing because the service is quitting. - } - } - unset($ensure_result); - } - } - - if (c_base_return::s_has_error($connected) || $connected instanceof c_base_return_false) { - // @todo: rewrite this function to handle multiple errors. - if ($access_denied) { - $problems[] = c_base_form_problem::s_create_error('login_form-username', 'Unable to login, an incorrect user or password has been specified.'); - } - else { - $errors = $connected->get_error(); - - $error = reset($errors); - unset($errors); - - $details = $error->get_details(); - unset($error); - - // @todo: not just database errors, but also session create errors need to be checked. - if (isset($details['arguments'][':failure_reasons'][0]['message']) && is_string($details['arguments'][':failure_reasons'][0]['message'])) { - $problems[] = c_base_form_problem::s_create_error(NULL, 'Unable to login, ' . $details['arguments'][':failure_reasons'][0]['message']); - } - else { - // here the reason for failure is unknown. - $problems[] = c_base_form_problem::s_create_error(NULL, 'Unable to login,'); - } - unset($details); - } - - unset($access_denied); - unset($connected); - - if (empty($problems)) { - unset($problems); - return new c_base_return_false(); - } - - return c_base_return_array::s_new($problems); - } - unset($access_denied); - - // @todo: add log entry. - #set_log_user($database, 'login'); - - // @todo: load and store custom settings (loaded from the database and/or ldap). - #$session->set_settings($user_data); - - // the session needs to be opened and the data needs to be saved on successful login. - $result = $session->do_connect(); - if (c_base_return::s_has_error($result)) { - $socket_error = $session->get_error_socket(); - if ($socket_error instanceof c_base_return_int) { - $problems[] = c_base_form_problem::s_create_error(NULL, 'Failed to load session, due to socket error (' . $socket_error->get_value_exact() . '): ' . @socket_strerror($socket_error->get_value_exact()) . '.'); - } - else { - $problems[] = c_base_form_problem::s_create_error(NULL, 'Failed to load session.'); - } - unset($socket_error); - } - else { - $ldap = reservation_database_load_ldap_data($settings, $_POST['login_form-username'])->get_value(); - if ($ldap instanceof c_base_return_false || !is_array($ldap)) { - $ldap = array( - 'data' => NULL, - ); - } - - if (isset($ldap['status']) && $ldap['status'] instanceof c_base_return_false) { - $problems[] = c_base_form_problem::s_create_error('login_form-username', 'Failed to retrieve ldap information for specified user.'); - - // @todo: handle error situation. - } - - $user_data = reservation_database_get_user_data($database, $_POST['login_form-username'], $ldap['data'])->get_value(); - - // @todo: get and use user id from $user_data. - - $pushed = $session->do_push($settings['session_expire'], $settings['session_max']); - $session->do_disconnect(); - - $cookie_login = NULL; - if (c_base_return::s_has_error($pushed)) { - $socket_error = $session->get_error_socket(); - if ($socket_error instanceof c_base_return_int) { - $problems = c_base_form_problem::s_create_error(NULL, 'Failed to push session, due to socket error (' . $socket_error->get_value_exact() . '): ' . @socket_strerror($socket_error->get_value_exact()) . '.'); - } - else { - $problems[] = c_base_form_problem::s_create_error(NULL, 'Failed to push session.'); - } - unset($socket_error); - } - else { - $session_expire = $session->get_timeout_expire()->get_value_exact(); - $cookie_login = $session->get_cookie(); - } - - if ($cookie_login instanceof c_base_cookie) { - $cookie_login->set_expires($session_expire); - $cookie_login->set_max_age(NULL); - - if ($pushed instanceof c_base_return_true) { - $data = array( - 'session_id' => $session->get_session_id()->get_value_exact(), - 'expire' => gmdate("D, d-M-Y H:i:s T", $session_expire), // unnecessary, but provided for debug purposes. - ); - - $cookie_login->set_value($data); - $session->set_cookie($cookie_login); - } - } - unset($cookie_login); - unset($session_expire); - unset($pushed); - } - unset($result); - unset($connected); + } - if (empty($problems)) { - unset($problems); - return new c_base_return_true(); + /** + * Load text for a supported language. + * + * @param int $index + * A number representing which block of text to return. + */ + protected function pr_get_text($code) { + switch ($code) { + case 0: + return 'You Have Logged Out'; + case 1: + return 'You have been logged out of the system.'; } - return c_base_return_array::s_new($problems); + return ''; } } diff --git a/program/reservation/reservation_build.php b/program/reservation/reservation_build.php new file mode 100644 index 0000000..7a8e855 --- /dev/null +++ b/program/reservation/reservation_build.php @@ -0,0 +1,200 @@ +set_attribute(c_base_markup_attributes::ATTRIBUTE_CLASS, $class); + unset($class); + + + // assign id attribute + $html->set_attribute(c_base_markup_attributes::ATTRIBUTE_ID, 'reservation-system'); + + + // assign default language attribute. + $html->set_attribute(c_base_markup_attributes::ATTRIBUTE_LANGUAGE, i_base_language::ENGLISH_US); + + + // assign default direction attribute + $html->set_attribute(c_base_markup_attributes::ATTRIBUTE_DIRECTION, 'ltr'); + + + // assign title header tag (setting title tag at delta 0 so that it can easily be overriden as needed). + $tag = new c_base_markup_tag(); + $tag->set_type(c_base_markup_tag::TYPE_TITLE); + + if (is_string($title)) { + $tag->set_text($title); + } + else { + $tag->set_text('Reservation System'); + } + + $html->set_header($tag, 0); + unset($tag); + + + // assign base header tag + if (isset($settings['base_path']) && is_string($settings['base_path']) && mb_strlen($settings['base_scheme']) > 0) { + $href = ''; + if (isset($settings['base_scheme']) && is_string($settings['base_scheme']) && mb_strlen($settings['base_scheme']) > 0) { + if (isset($settings['base_host']) && is_string($settings['base_host']) && mb_strlen($settings['base_host']) > 0) { + $href .= $settings['base_scheme'] . '://' . $settings['base_host']; + } + } + + $href .= $settings['base_path']; + + $tag = c_theme_html::s_create_tag(c_base_markup_tag::TYPE_BASE); + $tag->set_attribute(c_base_markup_attributes::ATTRIBUTE_HREF, $href); + $html->set_header($tag); + unset($tag); + unset($href); + } + + + // assign http-equiv header tag + $tag = c_theme_html::s_create_tag(c_base_markup_tag::TYPE_META); + $tag->set_attribute(c_base_markup_attributes::ATTRIBUTE_HTTP_EQUIV, 'Content-Type'); + $tag->set_attribute(c_base_markup_attributes::ATTRIBUTE_CONTENT, 'text/html; charset=utf-8'); + $html->set_header($tag); + unset($tag); + + + // assign charset header tag + $tag = c_theme_html::s_create_tag(c_base_markup_tag::TYPE_META); + $tag->set_attribute(c_base_markup_attributes::ATTRIBUTE_CHARACTER_SET, c_base_charset::UTF_8); + $html->set_header($tag); + unset($tag); + + + // assign canonical header tag + #$tag = c_theme_html::s_create_tag(c_base_markup_tag::TYPE_META); + #$tag->set_attribute(c_base_markup_attributes::ATTRIBUTE_REL, 'canonical'); + #$tag->set_attribute(c_base_markup_attributes::ATTRIBUTE_HREF, 'http://localhost/'); + #$html->set_header($tag); + #unset($tag); + + + // assign shortlink header tag + #$tag = c_theme_html::s_create_tag(c_base_markup_tag::TYPE_META); + #$tag->set_attribute(c_base_markup_attributes::ATTRIBUTE_REL, 'shortlink'); + #$tag->set_attribute(c_base_markup_attributes::ATTRIBUTE_HREF, '/'); + #$html->set_header($tag); + #unset($tag); + + + // assign description header tag + $tag = c_theme_html::s_create_tag(c_base_markup_tag::TYPE_META); + $tag->set_attribute(c_base_markup_attributes::ATTRIBUTE_NAME, 'description'); + $tag->set_attribute(c_base_markup_attributes::ATTRIBUTE_CONTENT, 'A reservation/scheduling system.'); + $html->set_header($tag); + unset($tag); + + + // assign distribution header tag + $tag = c_theme_html::s_create_tag(c_base_markup_tag::TYPE_META); + $tag->set_attribute(c_base_markup_attributes::ATTRIBUTE_NAME, 'distribution'); + $tag->set_attribute(c_base_markup_attributes::ATTRIBUTE_CONTENT, 'web'); + $html->set_header($tag); + unset($tag); + + + // assign robots header tag + $tag = c_theme_html::s_create_tag(c_base_markup_tag::TYPE_META); + $tag->set_attribute(c_base_markup_attributes::ATTRIBUTE_NAME, 'robots'); + $tag->set_attribute(c_base_markup_attributes::ATTRIBUTE_CONTENT, 'INDEX,FOLLOW'); + $html->set_header($tag); + unset($tag); + + + // assign expires header tag + #$tag = c_theme_html::s_create_tag(c_base_markup_tag::TYPE_META); + #$tag->set_attribute(c_base_markup_attributes::ATTRIBUTE_HTTP_EQUIV, 'expires'); + #$tag->set_attribute(c_base_markup_attributes::ATTRIBUTE_CONTENT, c_base_defaults_global::s_get_date('r', strtotime('+30 minutes'))->get_value_exact()); + #$html->set_header($tag); + #unset($tag); + + + // assign viewport header tag + $tag = c_theme_html::s_create_tag(c_base_markup_tag::TYPE_META); + $tag->set_attribute(c_base_markup_attributes::ATTRIBUTE_NAME, 'viewport'); + $tag->set_attribute(c_base_markup_attributes::ATTRIBUTE_CONTENT, 'width=device-width, initial-scale=1'); + $html->set_header($tag); + unset($tag); + + + // assign content http-equiv header tag + $aliases = array(); + $languages = $http->get_response_content_language()->get_value_exact(); + if (is_array($languages) && !empty($languages)) { + // assign the primary language. + $language_aliases = c_base_defaults_global::s_get_languages()::s_get_aliases_by_id(reset($languages))->get_value_exact(); + if (is_array($language_aliases) && !empty($language_aliases)) { + $html->set_attribute(c_base_markup_attributes::ATTRIBUTE_LANGUAGE, reset($language_aliases)); + } + unset($language_aliases); + + foreach ($languages as $language) { + $language_aliases = c_base_defaults_global::s_get_languages()::s_get_aliases_by_id($language)->get_value_exact(); + if (is_array($language_aliases) && !empty($language_aliases)) { + $aliases[] = array_pop($language_aliases); + } + unset($language_aliases); + } + unset($language); + } + unset($languages); + + if (!empty($aliases)) { + $tag = c_theme_html::s_create_tag(c_base_markup_tag::TYPE_META); + $tag->set_attribute(c_base_markup_attributes::ATTRIBUTE_HTTP_EQUIV, 'content-language'); + $tag->set_attribute(c_base_markup_attributes::ATTRIBUTE_CONTENT, implode(', ', $aliases)); + $html->set_header($tag); + unset($tag); + } + unset($aliases); + + return $html; + } +} diff --git a/program/reservation/reservation_database.php b/program/reservation/reservation_database.php index 9846443..3d325cd 100644 --- a/program/reservation/reservation_database.php +++ b/program/reservation/reservation_database.php @@ -3,542 +3,553 @@ * @file * Provides reservation database functions. */ - require_once('common/base/classes/base_error.php'); - require_once('common/base/classes/base_return.php'); - require_once('common/base/classes/base_session.php'); - require_once('common/base/classes/base_database.php'); - require_once('common/base/classes/base_access.php'); +require_once('common/base/classes/base_error.php'); +require_once('common/base/classes/base_return.php'); +require_once('common/base/classes/base_session.php'); +require_once('common/base/classes/base_database.php'); +require_once('common/base/classes/base_access.php'); /** - * Build the database connection string. - * - * @param c_base_database &$database - * The database to connect to. - * @param array $settings - * Custom settings. - * @param string|null $username - * The username string. - * If NULL, then the global username is used. - * @param string|null $password - * The password string. - * If NULL, then the global password is used. - * - * @return c_base_return_status - * TRUE on success, FALSE otherwise. - * FALSE with error bit set on error. - */ - function reservation_database_string(&$database, $settings, $user_name = NULL, $password = NULL) { - if (!($database instanceof c_base_database)) { - $error = c_base_error::s_log(NULL, array('arguments' => array(':argument_name' => 'database', ':function_name' => __FUNCTION__)), i_base_error_messages::INVALID_ARGUMENT); - return c_base_return_error::s_false($error); - } + * Build the database connection string. + * + * @param c_base_database &$database + * The database to connect to. + * @param array $settings + * Custom settings. + * @param string|null $username + * The username string. + * If NULL, then the global username is used. + * @param string|null $password + * The password string. + * If NULL, then the global password is used. + * + * @return c_base_return_status + * TRUE on success, FALSE otherwise. + * FALSE with error bit set on error. + */ +function reservation_database_string(&$database, $settings, $user_name = NULL, $password = NULL) { + if (!($database instanceof c_base_database)) { + $error = c_base_error::s_log(NULL, array('arguments' => array(':argument_name' => 'database', ':function_name' => __FUNCTION__)), i_base_error_messages::INVALID_ARGUMENT); + return c_base_return_error::s_false($error); + } - if (!is_array($settings)) { - $error = c_base_error::s_log(NULL, array('arguments' => array(':argument_name' => 'settings', ':function_name' => __FUNCTION__)), i_base_error_messages::INVALID_ARGUMENT); - return c_base_return_error::s_false($error); - } + if (!is_array($settings)) { + $error = c_base_error::s_log(NULL, array('arguments' => array(':argument_name' => 'settings', ':function_name' => __FUNCTION__)), i_base_error_messages::INVALID_ARGUMENT); + return c_base_return_error::s_false($error); + } - if (!is_null($user_name) && !is_string($user_name)) { - $error = c_base_error::s_log(NULL, array('arguments' => array(':argument_name' => 'user_name', ':function_name' => __FUNCTION__)), i_base_error_messages::INVALID_ARGUMENT); - return c_base_return_error::s_false($error); - } + if (!is_null($user_name) && !is_string($user_name)) { + $error = c_base_error::s_log(NULL, array('arguments' => array(':argument_name' => 'user_name', ':function_name' => __FUNCTION__)), i_base_error_messages::INVALID_ARGUMENT); + return c_base_return_error::s_false($error); + } - if (!is_null($password) && !is_string($password)) { - $error = c_base_error::s_log(NULL, array('arguments' => array(':argument_name' => 'password', ':function_name' => __FUNCTION__)), i_base_error_messages::INVALID_ARGUMENT); - return c_base_return_error::s_false($error); - } + if (!is_null($password) && !is_string($password)) { + $error = c_base_error::s_log(NULL, array('arguments' => array(':argument_name' => 'password', ':function_name' => __FUNCTION__)), i_base_error_messages::INVALID_ARGUMENT); + return c_base_return_error::s_false($error); + } - $connection_string = new c_base_connection_string(); - $connection_string->set_host($settings['database_host']); - $connection_string->set_port($settings['database_port']); - $connection_string->set_database($settings['database_name']); + $connection_string = new c_base_connection_string(); + $connection_string->set_host($settings['database_host']); + $connection_string->set_port($settings['database_port']); + $connection_string->set_database($settings['database_name']); - if (is_null($user_name)) { - $connection_string->set_user($settings['database_user']); + if (is_null($user_name)) { + $connection_string->set_user($settings['database_user']); - if (!is_null($settings['database_password'])) { - $connection_string->set_password($settings['database_password']); - } + if (!is_null($settings['database_password'])) { + $connection_string->set_password($settings['database_password']); } - else { - $connection_string->set_user($user_name); + } + else { + $connection_string->set_user($user_name); - if (!is_null($password)) { - $connection_string->set_password($password); - } + if (!is_null($password)) { + $connection_string->set_password($password); } + } - $connection_string->set_ssl_mode($settings['database_ssl_mode']); - $connection_string->set_connect_timeout($settings['database_timeout']); + $connection_string->set_ssl_mode($settings['database_ssl_mode']); + $connection_string->set_connect_timeout($settings['database_timeout']); - $database->set_connection_string($connection_string); - unset($connection_string); + $database->set_connection_string($connection_string); + unset($connection_string); - return new c_base_return_true(); + return new c_base_return_true(); +} + +/** + * Connect the database and configure default settings. + * + * @param c_base_database &$database + * The database to connect to. + * + * @return c_base_return_status + * TRUE on success, FALSE otherwise. + * FALSE with error bit set on error. + */ +function reservation_database_connect(&$database) { + if (!($database instanceof c_base_database)) { + $error = c_base_error::s_log(NULL, array('arguments' => array(':argument_name' => 'database', ':function_name' => __FUNCTION__)), i_base_error_messages::INVALID_ARGUMENT); + return c_base_return_error::s_false($error); } - /** - * Connect the database and configure default settings. - * - * @param c_base_database &$database - * The database to connect to. - * - * @return c_base_return_status - * TRUE on success, FALSE otherwise. - * FALSE with error bit set on error. - */ - function reservation_database_connect(&$database) { - if (!($database instanceof c_base_database)) { - $error = c_base_error::s_log(NULL, array('arguments' => array(':argument_name' => 'database', ':function_name' => __FUNCTION__)), i_base_error_messages::INVALID_ARGUMENT); - return c_base_return_error::s_false($error); - } + $status = $database->do_connect(); + if (!($status instanceof c_base_return_true)) { + return $status; + } + unset($status); - $status = $database->do_connect(); - if (!($status instanceof c_base_return_true)) { - return $status; - } - unset($status); + // configure default settings. + $database->do_query('set bytea_output to hex;'); + $database->do_query('set search_path to s_administers,s_managers,s_auditors,s_publishers,s_insurers,s_financers,s_reviewers,s_editors,s_drafters,s_requesters,s_users,public;'); + $database->do_query('set datestyle to us;'); - // configure default settings. - $database->do_query('set bytea_output to hex;'); - $database->do_query('set search_path to s_administers,s_managers,s_auditors,s_publishers,s_insurers,s_financers,s_reviewers,s_editors,s_drafters,s_requesters,s_users,public;'); - $database->do_query('set datestyle to us;'); + return new c_base_return_true(); +} - return new c_base_return_true(); +/** + * Load the user data. + * + * This is necessary to load and process session data. + * + * @param c_base_database &$database + * The database to connect to. + * @param string $user_name + * The name of the user to load. + * @param array|null $ldap_data + * (optional) An array of ldap data (if available). + * This is used to auto-populate user information in the database when an account is auto-created. + * + * @return c_base_return_array|c_base_return_status + * An array of user data is returned on success. + * FALSE with error bit set on error. + */ +function reservation_database_get_user_data(&$database, $user_name, $ldap_data = NULL) { + if (!($database instanceof c_base_database)) { + $error = c_base_error::s_log(NULL, array('arguments' => array(':argument_name' => 'database', ':function_name' => __FUNCTION__)), i_base_error_messages::INVALID_ARGUMENT); + return c_base_return_error::s_false($error); } - /** - * Load the user data. - * - * This is necessary to load and process session data. - * - * @param c_base_database &$database - * The database to connect to. - * @param string $user_name - * The name of the user to load. - * @param array|null $ldap_data - * (optional) An array of ldap data (if available). - * This is used to auto-populate user information in the database when an account is auto-created. - * - * @return c_base_return_array|c_base_return_status - * An array of user data is returned on success. - * FALSE with error bit set on error. - */ - function reservation_database_get_user_data(&$database, $user_name, $ldap_data = NULL) { - if (!($database instanceof c_base_database)) { - $error = c_base_error::s_log(NULL, array('arguments' => array(':argument_name' => 'database', ':function_name' => __FUNCTION__)), i_base_error_messages::INVALID_ARGUMENT); - return c_base_return_error::s_false($error); - } + if (!is_string($user_name)) { + $error = c_base_error::s_log(NULL, array('arguments' => array(':argument_name' => 'user_name', ':function_name' => __FUNCTION__)), i_base_error_messages::INVALID_ARGUMENT); + return c_base_return_error::s_false($error); + } - if (!is_string($user_name)) { - $error = c_base_error::s_log(NULL, array('arguments' => array(':argument_name' => 'user_name', ':function_name' => __FUNCTION__)), i_base_error_messages::INVALID_ARGUMENT); - return c_base_return_error::s_false($error); - } + if (!is_null($ldap_data) && !is_array($ldap_data)) { + $error = c_base_error::s_log(NULL, array('arguments' => array(':argument_name' => 'ldap_data', ':function_name' => __FUNCTION__)), i_base_error_messages::INVALID_ARGUMENT); + return c_base_return_error::s_false($error); + } - if (!is_null($ldap_data) && !is_array($ldap_data)) { - $error = c_base_error::s_log(NULL, array('arguments' => array(':argument_name' => 'ldap_data', ':function_name' => __FUNCTION__)), i_base_error_messages::INVALID_ARGUMENT); - return c_base_return_error::s_false($error); - } + $parameters = array( + $user_name, + ); - $parameters = array( - $user_name, - ); + $query_result = $database->do_query('select id, id_sort, id_external, name_machine, name_human, address_email, is_administer, is_manager, is_auditor, is_publisher, is_financer, is_reviewer, is_editor, is_drafter, is_requester, is_system, is_public, is_locked, is_private, date_created, date_changed, date_synced, date_locked, settings from v_users_self where id_sort = ascii($1) and name_machine = $1', $parameters); + unset($parameters); - $query_result = $database->do_query('select id, id_sort, id_external, name_machine, name_human, address_email, is_administer, is_manager, is_auditor, is_publisher, is_financer, is_reviewer, is_editor, is_drafter, is_requester, is_system, is_public, is_locked, is_private, date_created, date_changed, date_synced, date_locked, settings from v_users_self where id_sort = ascii($1) and name_machine = $1', $parameters); - unset($parameters); + if (c_base_return::s_has_error($query_result)) { + return reservation_error_get_query('database->do_query(select from v_users_self)', __FUNCTION__, $query_result); + } - if (c_base_return::s_has_error($query_result)) { - return reservation_error_get_query('database->do_query(select from v_users_self)', __FUNCTION__, $query_result); + if ($query_result instanceof c_base_database_result && $query_result->number_of_rows()->get_value_exact() > 0) { + $result = $query_result->fetch_row(); + unset($query_result); + + if (c_base_return::s_has_error($result)) { + return reservation_error_get_query('database->do_query(select from v_users_self)', __FUNCTION__, $result); } - if ($query_result instanceof c_base_database_result && $query_result->number_of_rows()->get_value_exact() > 0) { - $result = $query_result->fetch_row(); - unset($query_result); + $result_array = $result->get_value(); + unset($result); - if (c_base_return::s_has_error($result)) { - return reservation_error_get_query('database->do_query(select from v_users_self)', __FUNCTION__, $result); - } + if (is_array($result_array) && !empty($result_array)) { + $user_data = array(); + $user_data['id'] = $result_array[0]; + $user_data['id_sort'] = $result_array[1]; + $user_data['id_external'] = $result_array[2]; + $user_data['name_machine'] = $result_array[3]; + $user_data['name_human'] = $result_array[4]; + $user_data['address_email'] = $result_array[5]; + $user_data['is_administer'] = $result_array[6]; + $user_data['is_manager'] = $result_array[7]; + $user_data['is_auditor'] = $result_array[8]; + $user_data['is_publisher'] = $result_array[9]; + $user_data['is_financer'] = $result_array[10]; + $user_data['is_reviewer'] = $result_array[11]; + $user_data['is_editor'] = $result_array[12]; + $user_data['is_drafter'] = $result_array[13]; + $user_data['is_requester'] = $result_array[14]; + $user_data['is_system'] = $result_array[15]; + $user_data['is_public'] = $result_array[16]; + $user_data['is_locked'] = $result_array[17]; + $user_data['is_private'] = $result_array[18]; + $user_data['date_created'] = $result_array[19]; + $user_data['date_changed'] = $result_array[20]; + $user_data['date_synced'] = $result_array[21]; + $user_data['date_locked'] = $result_array[22]; + $user_data['settings'] = json_decode($result_array[23], TRUE); - $result_array = $result->get_value(); - unset($result); - - if (is_array($result_array) && !empty($result_array)) { - $user_data = array(); - $user_data['id'] = $result_array[0]; - $user_data['id_sort'] = $result_array[1]; - $user_data['id_external'] = $result_array[2]; - $user_data['name_machine'] = $result_array[3]; - $user_data['name_human'] = $result_array[4]; - $user_data['address_email'] = $result_array[5]; - $user_data['is_administer'] = $result_array[6]; - $user_data['is_manager'] = $result_array[7]; - $user_data['is_auditor'] = $result_array[8]; - $user_data['is_publisher'] = $result_array[9]; - $user_data['is_financer'] = $result_array[10]; - $user_data['is_reviewer'] = $result_array[11]; - $user_data['is_editor'] = $result_array[12]; - $user_data['is_drafter'] = $result_array[13]; - $user_data['is_requester'] = $result_array[14]; - $user_data['is_system'] = $result_array[15]; - $user_data['is_public'] = $result_array[16]; - $user_data['is_locked'] = $result_array[17]; - $user_data['is_private'] = $result_array[18]; - $user_data['date_created'] = $result_array[19]; - $user_data['date_changed'] = $result_array[20]; - $user_data['date_synced'] = $result_array[21]; - $user_data['date_locked'] = $result_array[22]; - $user_data['settings'] = json_decode($result_array[23], TRUE); - - unset($result_array); - return c_base_return_array::s_new($user_data); - } unset($result_array); + return c_base_return_array::s_new($user_data); } - unset($query_result); + unset($result_array); + } + unset($query_result); - // at this ppint the user account likely does not exist in the database, so create it using any ldap information if available. - if (is_null($ldap_data)) { - $query_result = $database->do_query('insert into v_users_self_insert (name_human.first) values (null)'); + // at this ppint the user account likely does not exist in the database, so create it using any ldap information if available. + if (is_null($ldap_data)) { + $query_result = $database->do_query('insert into v_users_self_insert (name_human.first) values (null)'); - if (c_base_return::s_has_error($query_result)) { - return reservation_error_get_query('database->do_query(insert into v_users_self_insert)', __FUNCTION__, $query_result); - } - } - else { - $email = explode('@', $ldap_data['mail']); - $parameters = array( - $ldap_data['givenname'], - $ldap_data['sn'], - $ldap_data['cn'], - $email[0], - $email[1], - $ldap_data['employeenumber'], - ); - - $query_result = $database->do_query('insert into v_users_self_insert (name_human.first, name_human.last, name_human.complete, address_email, id_external) values ($1, $2, $3, ($4, $5, TRUE), $6)', $parameters); - - if (c_base_return::s_has_error($query_result)) { - return reservation_error_get_query('database->do_query(insert into v_users_self_insert)', __FUNCTION__, $query_result); - } + if (c_base_return::s_has_error($query_result)) { + return reservation_error_get_query('database->do_query(insert into v_users_self_insert)', __FUNCTION__, $query_result); } - unset($query_result); - - - // try loading the user information again now that the user information exists in the database. + } + else { + $email = explode('@', $ldap_data['mail']); $parameters = array( - $user_name, + $ldap_data['givenname'], + $ldap_data['sn'], + $ldap_data['cn'], + $email[0], + $email[1], + $ldap_data['employeenumber'], ); - $query_result = $database->do_query('select id, id_sort, id_external, name_machine, name_human, address_email, is_administer, is_manager, is_auditor, is_publisher, is_financer, is_reviewer, is_editor, is_drafter, is_requester, is_system, is_public, is_locked, is_private, date_created, date_changed, date_synced, date_locked, settings from v_users_self where id_sort = ascii($1) and name_machine = $1', $parameters); - unset($parameters); + $query_result = $database->do_query('insert into v_users_self_insert (name_human.first, name_human.last, name_human.complete, address_email, id_external) values ($1, $2, $3, ($4, $5, TRUE), $6)', $parameters); if (c_base_return::s_has_error($query_result)) { - return reservation_error_get_query('database->do_query(select from v_users_self)', __FUNCTION__, $query_result); + return reservation_error_get_query('database->do_query(insert into v_users_self_insert)', __FUNCTION__, $query_result); } + } + unset($query_result); - if ($query_result instanceof c_base_database_result && $query_result->number_of_rows()->get_value_exact() > 0) { - $result = $query_result->fetch_row(); - unset($query_result); - if (c_base_return::s_has_error($result)) { - return reservation_error_get_query('database->do_query(select from v_users_self)', __FUNCTION__, $result); - } + // try loading the user information again now that the user information exists in the database. + $parameters = array( + $user_name, + ); - $result_array = $result->get_value(); - unset($result); - - if (is_array($result_array) && !empty($result_array)) { - $user_data = array(); - $user_data['id'] = $result_array[0]; - $user_data['id_sort'] = $result_array[1]; - $user_data['id_external'] = $result_array[2]; - $user_data['name_machine'] = $result_array[3]; - $user_data['name_human'] = $result_array[4]; - $user_data['address_email'] = $result_array[5]; - $user_data['is_administer'] = $result_array[6]; - $user_data['is_manager'] = $result_array[7]; - $user_data['is_auditor'] = $result_array[8]; - $user_data['is_publisher'] = $result_array[9]; - $user_data['is_financer'] = $result_array[10]; - $user_data['is_reviewer'] = $result_array[11]; - $user_data['is_editor'] = $result_array[12]; - $user_data['is_drafter'] = $result_array[13]; - $user_data['is_requester'] = $result_array[14]; - $user_data['is_system'] = $result_array[15]; - $user_data['is_public'] = $result_array[16]; - $user_data['is_locked'] = $result_array[17]; - $user_data['is_private'] = $result_array[18]; - $user_data['date_created'] = $result_array[19]; - $user_data['date_changed'] = $result_array[20]; - $user_data['date_synced'] = $result_array[21]; - $user_data['date_locked'] = $result_array[22]; - $user_data['settings'] = json_decode($result_array[23], TRUE); - - unset($result_array); - return c_base_return_array::s_new($user_data); - } - unset($result_array); - } - unset($query_result); + $query_result = $database->do_query('select id, id_sort, id_external, name_machine, name_human, address_email, is_administer, is_manager, is_auditor, is_publisher, is_financer, is_reviewer, is_editor, is_drafter, is_requester, is_system, is_public, is_locked, is_private, date_created, date_changed, date_synced, date_locked, settings from v_users_self where id_sort = ascii($1) and name_machine = $1', $parameters); + unset($parameters); - - return c_base_return_array::s_new(array()); + if (c_base_return::s_has_error($query_result)) { + return reservation_error_get_query('database->do_query(select from v_users_self)', __FUNCTION__, $query_result); } - /** - * Loads LDAP information for the given user (if available). - * - * @param array $settings - * System settings array. - * @param string $user_name - * The user name to load - * - * @return c_base_return_array|c_base_return_status - * An array of ldap data associated with the given user. - * This array may contain error information if there were connection problems to the ldap database. - * The array structure is: - * 'title': a Title for any error that occured. - * 'message': The detailed ldap error message. - * 'status': c_base_return_true if there were no problems and c_base_return_false if there were problems. - * 'data': Any ldap data found for the given user name. - * FALSE with the error bit set is returned on error. - */ - function reservation_database_load_ldap_data($settings, $user_name) { - if (!is_array($settings)) { - $error = c_base_error::s_log(NULL, array('arguments' => array(':argument_name' => 'settings', ':function_name' => __FUNCTION__)), i_base_error_messages::INVALID_ARGUMENT); - return c_base_return_error::s_false($error); - } + if ($query_result instanceof c_base_database_result && $query_result->number_of_rows()->get_value_exact() > 0) { + $result = $query_result->fetch_row(); + unset($query_result); - if (!is_string($user_name)) { - $error = c_base_error::s_log(NULL, array('arguments' => array(':argument_name' => 'user_name', ':function_name' => __FUNCTION__)), i_base_error_messages::INVALID_ARGUMENT); - return c_base_return_error::s_false($error); + if (c_base_return::s_has_error($result)) { + return reservation_error_get_query('database->do_query(select from v_users_self)', __FUNCTION__, $result); } - $return_data = array( - 'title' => NULL, - 'message' => NULL, - 'status' => new c_base_return_true(), - 'data' => NULL, - ); - - $ldap = new c_base_ldap(); - $ldap->set_name($settings['ldap_server']); - #$ldap->set_bind_name(''); - #$ldap->set_bind_password(''); - $connected = $ldap->do_connect(); - if (c_base_return::s_has_error($connected)) { - $message = $ldap->get_error_message(); + $result_array = $result->get_value(); + unset($result); - $return_data['title'] = 'Connection Failed'; - $return_data['message'] = $message->get_value_exact(); - $return_data['status'] = new c_base_return_false(); - unset($message); + if (is_array($result_array) && !empty($result_array)) { + $user_data = array(); + $user_data['id'] = $result_array[0]; + $user_data['id_sort'] = $result_array[1]; + $user_data['id_external'] = $result_array[2]; + $user_data['name_machine'] = $result_array[3]; + $user_data['name_human'] = $result_array[4]; + $user_data['address_email'] = $result_array[5]; + $user_data['is_administer'] = $result_array[6]; + $user_data['is_manager'] = $result_array[7]; + $user_data['is_auditor'] = $result_array[8]; + $user_data['is_publisher'] = $result_array[9]; + $user_data['is_financer'] = $result_array[10]; + $user_data['is_reviewer'] = $result_array[11]; + $user_data['is_editor'] = $result_array[12]; + $user_data['is_drafter'] = $result_array[13]; + $user_data['is_requester'] = $result_array[14]; + $user_data['is_system'] = $result_array[15]; + $user_data['is_public'] = $result_array[16]; + $user_data['is_locked'] = $result_array[17]; + $user_data['is_private'] = $result_array[18]; + $user_data['date_created'] = $result_array[19]; + $user_data['date_changed'] = $result_array[20]; + $user_data['date_synced'] = $result_array[21]; + $user_data['date_locked'] = $result_array[22]; + $user_data['settings'] = json_decode($result_array[23], TRUE); - return c_base_return_array::s_new($return_data); + unset($result_array); + return c_base_return_array::s_new($user_data); } + unset($result_array); + } + unset($query_result); - $read = $ldap->do_search($settings['ldap_base_dn'], '(uid=' . $user_name . ')', $settings['ldap_fields']); - if (c_base_return::s_has_error($read)) { - $message = $ldap->get_error_message(); - $return_data['title'] = 'Search Failed'; - $return_data['message'] = $message->get_value_exact(); - $return_data['status'] = new c_base_return_false(); - unset($message); + return c_base_return_array::s_new(array()); +} - $ldap->do_disconnect(); +/** + * Loads LDAP information for the given user (if available). + * + * @param array $settings + * System settings array. + * @param string $user_name + * The user name to load + * + * @return c_base_return_array|c_base_return_status + * An array of ldap data associated with the given user. + * This array may contain error information if there were connection problems to the ldap database. + * The array structure is: + * 'title': a Title for any error that occured. + * 'message': The detailed ldap error message. + * 'status': c_base_return_true if there were no problems and c_base_return_false if there were problems. + * 'data': Any ldap data found for the given user name. + * FALSE with the error bit set is returned on error. + */ +function reservation_database_load_ldap_data($settings, $user_name) { + if (!is_array($settings)) { + $error = c_base_error::s_log(NULL, array('arguments' => array(':argument_name' => 'settings', ':function_name' => __FUNCTION__)), i_base_error_messages::INVALID_ARGUMENT); + return c_base_return_error::s_false($error); + } - return c_base_return_array::s_new($return_data); - } + if (!is_string($user_name)) { + $error = c_base_error::s_log(NULL, array('arguments' => array(':argument_name' => 'user_name', ':function_name' => __FUNCTION__)), i_base_error_messages::INVALID_ARGUMENT); + return c_base_return_error::s_false($error); + } - $entries = $read->get_entry_all(); - if ($entries instanceof c_base_return_array) { - $entries = $entries->get_value(); - } - else { - $entries = array(); - } + $return_data = array( + 'title' => NULL, + 'message' => NULL, + 'status' => new c_base_return_true(), + 'data' => NULL, + ); + + $ldap = new c_base_ldap(); + $ldap->set_name($settings['ldap_server']); + #$ldap->set_bind_name(''); + #$ldap->set_bind_password(''); + $connected = $ldap->do_connect(); + if (c_base_return::s_has_error($connected)) { + $message = $ldap->get_error_message(); + + $return_data['title'] = 'Connection Failed'; + $return_data['message'] = $message->get_value_exact(); + $return_data['status'] = new c_base_return_false(); + unset($message); - if ($entries['count'] > 0) { - $return_data['data'] = array( - 'uid' => $user_name, - ); + return c_base_return_array::s_new($return_data); + } - foreach ($settings['ldap_fields'] as $ldap_field) { - $return_data['data'][$ldap_field] = $entries[0][$ldap_field][0]; - } - unset($ldap_field); - } - else { - $return_data['title'] = 'Username Not Found'; - $return_data['message'] = 'The user \'' . $user_name . '\' was not found.'; - $return_data['status'] = new c_base_return_false(); - } - unset($entries); + $read = $ldap->do_search($settings['ldap_base_dn'], '(uid=' . $user_name . ')', $settings['ldap_fields']); + if (c_base_return::s_has_error($read)) { + $message = $ldap->get_error_message(); + + $return_data['title'] = 'Search Failed'; + $return_data['message'] = $message->get_value_exact(); + $return_data['status'] = new c_base_return_false(); + unset($message); + + $ldap->do_disconnect(); return c_base_return_array::s_new($return_data); } - /** - * Get all roles assigned to the current user. - * - * @todo: this might be unecessary as it may be automated via the user view table and sql triggers. - * @todo: review and update or delete this function as necessary. - * - * @param c_base_database &$database - * The database object. - * @param array &$settings - * The system settings array. - * @param c_base_session &$session - * The current session. - * - * @return c_base_return_status - * TRUE on success, FALSE otherwise. - * FALSE with error bit set is returned on error. - */ - function reservation_get_current_roles($database, $settings, &$session) { - $connected = $database->is_connected(); - if ($connected instanceof c_base_return_false) { - $connected = reservation_database_connect($database); + $entries = $read->get_entry_all(); + if ($entries instanceof c_base_return_array) { + $entries = $entries->get_value(); + } + else { + $entries = array(); + } + + if ($entries['count'] > 0) { + $return_data['data'] = array( + 'uid' => $user_name, + ); + + foreach ($settings['ldap_fields'] as $ldap_field) { + $return_data['data'][$ldap_field] = $entries[0][$ldap_field][0]; } + unset($ldap_field); + } + else { + $return_data['title'] = 'Username Not Found'; + $return_data['message'] = 'The user \'' . $user_name . '\' was not found.'; + $return_data['status'] = new c_base_return_false(); + } + unset($entries); - $roles = new c_base_roles(); + return c_base_return_array::s_new($return_data); +} +/** + * Get all roles assigned to the current user. + * + * @todo: this might be unecessary as it may be automated via the user view table and sql triggers. + * @todo: review and update or delete this function as necessary. + * + * @param c_base_database &$database + * The database object. + * @param c_base_session &$session + * The current session. + * @param array $settings + * The system settings array. + * + * @return c_base_return_status + * TRUE on success, FALSE otherwise. + * FALSE with error bit set is returned on error. + */ +function reservation_get_current_roles(&$database, &$session, $settings) { + $pre_connected = TRUE; + $connected = $database->is_connected(); + if ($connected instanceof c_base_return_false) { + $pre_connected = FALSE; + $connected = reservation_database_connect($database); + } - // if there is no session, then assume that this is a public account. - if (empty($session->get_session_id()->get_value_exact())) { - $roles->set_role(c_base_roles::PUBLIC, TRUE); - $session->set_setting('roles', $roles); - unset($roles); + $roles = new c_base_roles(); - return new c_base_return_true(); - } + // if there is no session, then assume that this is a public account. + if (empty($session->get_session_id()->get_value_exact())) { + unset($pre_connected); - // if unable to connect to database to retrieve other roles, just return the ppublic role. - if ($connected instanceof c_base_return_false) { - $roles->set_role(c_base_roles::PUBLIC, TRUE); - $session->set_setting('roles', $roles); - unset($roles); + $roles->set_role(c_base_roles::PUBLIC, TRUE); + $session->set_setting('roles', $roles); + unset($roles); - $connection_string = $database->get_connection_string(); - $database_name = ($connection_string instanceof c_base_connection_string) ? $connection_string->get_database()->get_value_exact() : ''; - unset($connection_string); + return new c_base_return_true(); + } - $error = c_base_error::s_log(NULL, array('arguments' => array(':database_name' => $database_name, ':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::POSTGRESQL_NO_CONNECTION); - unset($database_name); - return c_base_return_error::s_false($error); - } - unset($connected); - - - // assign default roles. - $roles->set_role(c_base_roles::PUBLIC, FALSE); - $roles->set_role(c_base_roles::USER, TRUE); - - - // load all postgresql roles. - $result = $database->do_query('SELECT role_name FROM information_schema.enabled_roles'); - if ($result instanceof c_base_database_result) { - $rows = $result->fetch_all()->get_value_exact(); - - foreach ($rows as $row) { - if (!array_key_exists('role_name', $row)) { - continue; - } - - switch ($row['role_name']) { - case $settings['database_name'] . '_requester': - $roles->set_role(c_base_roles::REQUESTER, TRUE); - break; - case $settings['database_name'] . '_drafter': - $roles->set_role(c_base_roles::DRAFTER, TRUE); - break; - case $settings['database_name'] . '_editor': - $roles->set_role(c_base_roles::EDITOR, TRUE); - break; - case $settings['database_name'] . '_reviewer': - $roles->set_role(c_base_roles::REVIEWER, TRUE); - break; - case $settings['database_name'] . '_financer': - $roles->set_role(c_base_roles::FINANCER, TRUE); - break; - case $settings['database_name'] . '_insurer': - $roles->set_role(c_base_roles::INSURER, TRUE); - break; - case $settings['database_name'] . '_publisher': - $roles->set_role(c_base_roles::PUBLISHER, TRUE); - break; - case $settings['database_name'] . '_auditor': - $roles->set_role(c_base_roles::AUDITOR, TRUE); - break; - case $settings['database_name'] . '_manager': - $roles->set_role(c_base_roles::MANAGER, TRUE); - break; - case $settings['database_name'] . '_administer': - $roles->set_role(c_base_roles::ADMINISTER, TRUE); - break; - } - } - unset($row); - unset($rows); - } - unset($result); + // if unable to connect to database to retrieve other roles, just return the ppublic role. + if ($connected instanceof c_base_return_false) { + unset($pre_connected); + $roles->set_role(c_base_roles::PUBLIC, TRUE); $session->set_setting('roles', $roles); unset($roles); - return new c_base_return_true(); + $connection_string = $database->get_connection_string(); + $database_name = ($connection_string instanceof c_base_connection_string) ? $connection_string->get_database()->get_value_exact() : ''; + unset($connection_string); + + $error = c_base_error::s_log(NULL, array('arguments' => array(':database_name' => $database_name, ':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::POSTGRESQL_NO_CONNECTION); + unset($database_name); + + return c_base_return_error::s_false($error); } + unset($connected); - /** - * Builds a return object for a query. - * - * This functions is provided to simplify the return of specific code. - * Error handling is not performed, instead simple failsafes are used. - * - * @param string $operation_name - * The name of the operation, which is generally something like: database->do_query. - * @param string $function_name - * The name of the function. - * The caller should usually use __FUNCTION__ here. - * @param c_base_return $result - * The query return result. - * - * @return c_base_error - * A generated oepration failure error. - */ - function reservation_error_get_query($operation_name, $function_name, $result) { - if (!is_string($operation_name)) { - $operation_name = ''; - } - if (!is_string($function_name)) { - $function_name = ''; - } + // assign default roles. + $roles->set_role(c_base_roles::PUBLIC, FALSE); + $roles->set_role(c_base_roles::USER, TRUE); + + + // load all postgresql roles. + $result = $database->do_query('SELECT role_name FROM information_schema.enabled_roles'); + if ($result instanceof c_base_database_result) { + $rows = $result->fetch_all()->get_value_exact(); + + foreach ($rows as $row) { + if (!array_key_exists('role_name', $row)) { + continue; + } - $failure = new c_base_return_false(); - $found_errors = FALSE; - if ($result instanceof c_base_return) { - $errors = $result->get_error(); - if (is_array($errors)) { - $found_errors = TRUE; - - foreach ($errors as $error) { - $failure->set_error($error); - } - unset($error); + switch ($row['role_name']) { + case 'r_' . $settings['database_name'] . '_requester': + $roles->set_role(c_base_roles::REQUESTER, TRUE); + break; + case 'r_' . $settings['database_name'] . '_drafter': + $roles->set_role(c_base_roles::DRAFTER, TRUE); + break; + case 'r_' . $settings['database_name'] . '_editor': + $roles->set_role(c_base_roles::EDITOR, TRUE); + break; + case 'r_' . $settings['database_name'] . '_reviewer': + $roles->set_role(c_base_roles::REVIEWER, TRUE); + break; + case 'r_' . $settings['database_name'] . '_financer': + $roles->set_role(c_base_roles::FINANCER, TRUE); + break; + case 'r_' . $settings['database_name'] . '_insurer': + $roles->set_role(c_base_roles::INSURER, TRUE); + break; + case 'r_' . $settings['database_name'] . '_publisher': + $roles->set_role(c_base_roles::PUBLISHER, TRUE); + break; + case 'r_' . $settings['database_name'] . '_auditor': + $roles->set_role(c_base_roles::AUDITOR, TRUE); + break; + case 'r_' . $settings['database_name'] . '_manager': + $roles->set_role(c_base_roles::MANAGER, TRUE); + break; + case 'r_' . $settings['database_name'] . '_administer': + $roles->set_role(c_base_roles::ADMINISTER, TRUE); + break; } - unset($errors); } + unset($row); + unset($rows); + } + unset($result); + + if (!$pre_connected) { + $database->do_disconnect(); + } + unset($pre_connected); + + $session->set_setting('roles', $roles); + unset($roles); - if (!$found_errors) { - $error = c_base_error::s_log(NULL, array('arguments' => array(':operation_name' => $operation_name, ':function_name' => $function_name)), i_base_error_messages::OPERATION_FAILURE); - $failure->set_error($error); + return new c_base_return_true(); +} + +/** + * Builds a return object for a query. + * + * This functions is provided to simplify the return of specific code. + * Error handling is not performed, instead simple failsafes are used. + * + * @param string $operation_name + * The name of the operation, which is generally something like: database->do_query. + * @param string $function_name + * The name of the function. + * The caller should usually use __FUNCTION__ here. + * @param c_base_return $result + * The query return result. + * + * @return c_base_error + * A generated oepration failure error. + */ +function reservation_error_get_query($operation_name, $function_name, $result) { + if (!is_string($operation_name)) { + $operation_name = ''; + } + + if (!is_string($function_name)) { + $function_name = ''; + } + + $failure = new c_base_return_false(); + $found_errors = FALSE; + if ($result instanceof c_base_return) { + $errors = $result->get_error(); + if (is_array($errors)) { + $found_errors = TRUE; + + foreach ($errors as $error) { + $failure->set_error($error); + } unset($error); } - unset($found_errors); + unset($errors); + } - return $failure; + if (!$found_errors) { + $error = c_base_error::s_log(NULL, array('arguments' => array(':operation_name' => $operation_name, ':function_name' => $function_name)), i_base_error_messages::OPERATION_FAILURE); + $failure->set_error($error); + unset($error); } + unset($found_errors); + + return $failure; +} diff --git a/program/reservation/reservation_paths.php b/program/reservation/reservation_paths.php index c9d8021..5ce5ee8 100644 --- a/program/reservation/reservation_paths.php +++ b/program/reservation/reservation_paths.php @@ -3,30 +3,41 @@ * @file * Provides reservation session functions. */ - require_once('common/base/classes/base_error.php'); - require_once('common/base/classes/base_return.php'); - require_once('common/base/classes/base_markup.php'); - require_once('common/base/classes/base_html.php'); - require_once('common/base/classes/base_charset.php'); - require_once('common/base/classes/base_ascii.php'); - require_once('common/base/classes/base_form.php'); - require_once('common/base/classes/base_path.php'); - - require_once('program/reservation/reservation_database.php'); - require_once('program/reservation/reservation_session.php'); +require_once('common/base/classes/base_error.php'); +require_once('common/base/classes/base_return.php'); +require_once('common/base/classes/base_markup.php'); +require_once('common/base/classes/base_html.php'); +require_once('common/base/classes/base_charset.php'); +require_once('common/base/classes/base_ascii.php'); +require_once('common/base/classes/base_form.php'); +require_once('common/base/classes/base_path.php'); + +require_once('program/reservation/reservation_database.php'); +require_once('program/reservation/reservation_session.php'); class c_reservation_paths { // paths to common files (not url paths). - private const PATH_LOGIN = 'program/reservation/paths/u/login.php'; - private const PATH_LOGOUT = 'program/reservation/paths/u/logout.php'; - private const PATH_ACCESS_DENIED = 'program/reservation/internal/access_denied.php'; - private const PATH_NOT_FOUND = 'program/reservation/internal/not_found.php'; + private const PATH_LOGIN = 'program/reservation/paths/u/'; + private const PATH_LOGOUT = 'program/reservation/paths/u/'; + private const PATH_ACCESS_DENIED = 'program/reservation/internal/'; + private const PATH_NOT_FOUND = 'program/reservation/internal/'; + private const PATH_BAD_METHOD = 'program/reservation/internal/'; + private const PATH_SERVER_ERROR = 'program/reservation/internal/'; + private const PATH_REDIRECTS = 'program/reservation/'; + + private const NAME_LOGIN = 'login'; + private const NAME_LOGOUT = 'logout'; + private const NAME_ACCESS_DENIED = 'access_denied'; + private const NAME_NOT_FOUND = 'not_found'; + private const NAME_BAD_METHOD = 'bad_method'; + private const NAME_SERVER_ERROR = 'server_error'; + private const NAME_REDIRECTS = 'reservation_redirects'; private $http = NULL; private $database = NULL; private $settings = NULL; private $session = NULL; - private $markup = NULL; + private $content = NULL; private $logged_in = NULL; private $paths = NULL; @@ -34,12 +45,11 @@ class c_reservation_paths { * Class constructor. */ public function __construct() { - $this->uri = NULL; $this->http = NULL; $this->database = NULL; $this->settings = NULL; $this->session = NULL; - $this->markup = NULL; + $this->content = NULL; $this->logged_in = NULL; $this->paths = NULL; $this->path = NULL; @@ -49,11 +59,10 @@ class c_reservation_paths { * Class destructor. */ public function __destruct() { - unset($this->uri); unset($this->http); unset($this->settings); unset($this->session); - unset($this->markup); + unset($this->content); unset($this->logged_in); unset($this->paths); unset($this->path); @@ -79,7 +88,7 @@ class c_reservation_paths { * The execution results. * The execution results with the error bit set on error. */ - public function reservation_process_path(&$http, &$database, &$session, &$html, $settings, $logged_in = TRUE) { + public function reservation_process_path(&$http, &$database, &$session, $settings, $logged_in = TRUE) { // @todo: these parameter errors might need a custom service unavailable and system log support. if (!($http instanceof c_base_http)) { $error = c_base_error::s_log(NULL, array('arguments' => array(':argument_name' => 'http', ':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::INVALID_ARGUMENT); @@ -96,11 +105,6 @@ class c_reservation_paths { return c_base_return_error::s_value(array(), 'c_base_path_executed', $error); } - if (!($html instanceof c_base_html)) { - $error = c_base_error::s_log(NULL, array('arguments' => array(':argument_name' => 'html', ':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::INVALID_ARGUMENT); - return c_base_return_error::s_value(array(), 'c_base_path_executed', $error); - } - if (!is_array($settings)) { $error = c_base_error::s_log(NULL, array('arguments' => array(':argument_name' => 'settings', ':function_name' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::INVALID_ARGUMENT); return c_base_return_error::s_value(array(), 'c_base_path_executed', $error); @@ -115,21 +119,22 @@ class c_reservation_paths { $this->database = &$database; $this->settings = $settings; $this->session = &$session; - $this->markup = &$html; + $this->content = NULL; $this->logged_in = $logged_in; + // require HTTPS for access to any part of this website. if (!isset($_SERVER["HTTPS"])) { // @todo: redirect to https version of requested uri. $failure_path = $this->p_get_path_not_found(); - return $failure_path->do_execute($this->http, $this->database, $this->session, $this->markup, $this->settings); + return $failure_path->do_execute($this->http, $this->database, $this->session, $this->settings); } $request_uri = $http->get_request(c_base_http::REQUEST_URI)->get_value_exact(); - $this->uri = array( + $this->settings['uri'] = array( 'scheme' => '', 'authority' => '', 'path' => '', @@ -139,14 +144,14 @@ class c_reservation_paths { ); if (isset($request_uri['data'])) { - $this->uri = $request_uri['data']; + $this->settings['uri'] = $request_uri['data']; } unset($request_uri); // strip the base path from the requested uri. if (!empty($settings['base_path'])) { - $this->uri['path'] = preg_replace('@^' . preg_quote($settings['base_path'], '@') . '@i', '', $this->uri['path']); - $this->uri['path'] = preg_replace('@/$@', '', $this->uri['path']); + $this->settings['uri']['path'] = preg_replace('@^' . preg_quote($settings['base_path'], '@') . '@i', '', $this->settings['uri']['path']); + $this->settings['uri']['path'] = preg_replace('@/$@', '', $this->settings['uri']['path']); } @@ -155,17 +160,27 @@ class c_reservation_paths { // find the path - $handler_settings = $this->paths->find_path($this->uri['path']); + $handler_settings = $this->paths->find_path($this->settings['uri']['path'])->get_value(); if (!is_array($handler_settings)) { - unset($handler_settings); - - // @todo: handle error case and failsafe (404)?. - return new c_base_return_false(); + $not_found = $this->p_get_path_not_found(); + return $not_found->do_execute($this->http, $this->database, $this->session, $this->settings); } if (array_key_exists('redirect', $handler_settings)) { - // @todo: handle redirect. + // successfully logged in. + require_once(self::PATH_REDIRECTS . self::NAME_REDIRECTS . '.php'); + + if (!is_string($handler_settings['redirect'])) { + $handler_settings['redirect'] = ''; + } + + if (!isset($handler_settings['code']) || !is_int($handler_settings['code'])) { + $handler_settings['code'] = c_base_http_status::MOVED_PERMANENTLY; + } + + $redirect = c_reservation_path_redirect::s_create_redirect($handler_settings['redirect'], $handler_settings['code'], FALSE); + return $redirect->do_execute($this->http, $this->database, $this->session, $this->settings); } else { if (!empty($handler_settings['include']) && is_string($handler_settings['include'])) { @@ -173,10 +188,14 @@ class c_reservation_paths { } if (empty($handler_settings['handler']) || !class_exists($handler_settings['handler'])) { - // @todo: handle error case. + $not_found = $this->p_get_path_server_error(); + return $not_found->do_execute($this->http, $this->database, $this->session, $this->settings); } else { $this->path = new $handler_settings['handler'](); + if (isset($handler_settings['is_root']) && $handler_settings['is_root']) { + $this->path->set_is_root(TRUE); + } } } unset($handler_settings); @@ -192,17 +211,16 @@ class c_reservation_paths { if ($id_group === c_base_ascii::LOWER_S || $id_group === c_base_ascii::LOWER_X) { $failure_path = $this->p_get_path_bad_method(); - return $failure_path->do_execute($this->http, $this->database, $this->session, $this->markup, $this->settings); + return $failure_path->do_execute($this->http, $this->database, $this->session, $this->settings); } unset($id_group); } else { $failure_path = $this->p_get_path_bad_method(); - return $failure_path->do_execute($this->http, $this->database, $this->session, $this->markup, $this->settings); + return $failure_path->do_execute($this->http, $this->database, $this->session, $this->settings); } - return $this->p_paths_normal(); } @@ -217,25 +235,15 @@ class c_reservation_paths { private function p_paths_create() { $this->paths = new c_base_paths(); - // set root path to be the user dashboard. $this->paths->set_path('', 'c_reservation_path_user_dashboard', 'program/reservation/paths/u/dashboard.php'); - // create login/logout paths - $path = c_base_path::s_create_content(c_base_ascii::LOWER_U, 'login', FALSE); - $this->paths->set_path($path, 'c_reservation_path_user_login', 'program/reservation/login.php'); - unset($path); - - $path = c_base_path::s_create_content(c_base_ascii::LOWER_U, 'logout', FALSE); - $this->paths->set_path($path, 'c_reservation_path_user_logout', 'program/reservation/logout.php'); - unset($path); - + $this->paths->set_path('/u/login', 'c_reservation_path_user_login', 'program/reservation/login.php'); + $this->paths->set_path('/u/logout', 'c_reservation_path_user_logout', 'program/reservation/logout.php'); // user dashboard - $path = c_base_path::s_create_content(c_base_ascii::LOWER_U, 'dashboard', FALSE); - $this->paths->set_path($path, 'c_reservation_path_user_dashboard', 'program/reservation/paths/u/dashboard.php'); - unset($path); + $this->paths->set_path('/u/dashboard', 'c_reservation_path_user_dashboard', 'program/reservation/paths/u/dashboard.php'); } /** @@ -255,7 +263,7 @@ class c_reservation_paths { if ($this->path instanceof c_reservation_path_user_login) { unset($id_group); - return $this->path->do_execute($this->http, $this->database, $this->session, $this->markup, $this->settings); + return $this->path->do_execute($this->http, $this->database, $this->session, $this->settings); } @@ -263,7 +271,7 @@ class c_reservation_paths { if ($id_group === c_base_ascii::LOWER_A || $id_group === c_base_ascii::LOWER_U || $this->path->get_is_private()->get_value_exact()) { if ($this->logged_in) { unset($id_group); - return $this->path->do_execute($this->http, $this->database, $this->session, $this->markup, $this->settings); + return $this->path->do_execute($this->http, $this->database, $this->session, $this->settings); } elseif ($this->path->get_is_root()->get_value_exact()) { unset($id_group); @@ -271,7 +279,7 @@ class c_reservation_paths { $this->http->set_response_status(c_base_http_status::FORBIDDEN); $login_path = $this->p_get_path_login(); - return $login_path->do_execute($this->http, $this->database, $this->session, $this->markup, $this->settings); + return $login_path->do_execute($this->http, $this->database, $this->session, $this->settings); } else { // some special case paths always provide login prompt along with access denied. @@ -281,13 +289,13 @@ class c_reservation_paths { $this->http->set_response_status(c_base_http_status::FORBIDDEN); $login_path = $this->p_get_path_login(); - return $login_path->do_execute($this->http, $this->database, $this->session, $this->markup, $this->settings); + return $login_path->do_execute($this->http, $this->database, $this->session, $this->settings); } } } else { unset($id_group); - return $this->path->do_execute($this->http, $this->database, $this->session, $this->markup, $this->settings); + return $this->path->do_execute($this->http, $this->database, $this->session, $this->settings); } // return access denied or page not found depending on path and privacy settings. @@ -305,7 +313,7 @@ class c_reservation_paths { } unset($id_group); - return $failsafe_path->do_execute($this->http, $this->database, $this->session, $this->markup, $this->settings); + return $failsafe_path->do_execute($this->http, $this->database, $this->session, $this->settings); } /** @@ -321,7 +329,7 @@ class c_reservation_paths { // always return not found, do not inform user if the access is denied. $failsafe_path = $this->p_get_path_not_found(); - return $failsafe_path->do_execute($this->http, $this->database, $this->session, $this->markup, $this->settings); + return $failsafe_path->do_execute($this->http, $this->database, $this->session, $this->settings); } /** @@ -337,46 +345,120 @@ class c_reservation_paths { // always return not found, do not inform user if the access is denied. $failsafe_path = $this->p_get_path_not_found(); - return $failsafe_path->do_execute($this->http, $this->database, $this->session, $this->markup, $this->settings); + return $failsafe_path->do_execute($this->http, $this->database, $this->session, $this->settings); } /** * Load and return the login path. */ private function p_get_path_login() { - require_once(self::PATH_LOGIN); - return new c_reservation_path_user_login(); + return $this->p_include_path(self::PATH_LOGIN, self::NAME_LOGIN, 'c_reservation_path_user_login'); } /** * Load and return the logout path. */ private function p_get_path_logout() { - require_once(self::PATH_LOGOUT); - return new c_reservation_path_user_logout(); + return $this->p_include_path(self::PATH_LOGOUT, self::NAME_LOGOUT, 'c_reservation_path_user_logout'); } /** * Load and return the access denied path. */ private function p_get_path_access_denied() { - require_once(self::PATH_ACCESS_DENIED); - return new c_reservation_path_access_denied(); + return $this->p_include_path(self::PATH_ACCESS_DENIED, self::NAME_ACCESS_DENIED, 'c_reservation_path_access_denied'); } /** * Load and return the not found path. */ private function p_get_path_not_found() { - require_once(self::PATH_NOT_FOUND); - return new c_reservation_path_not_found(); + return $this->p_include_path(self::PATH_NOT_FOUND, self::NAME_NOT_FOUND, 'c_reservation_path_not_found'); } /** * Load and return the not found path. */ private function p_get_path_bad_method() { - require_once(self::PATH_BAD_METHOD); - return new c_reservation_path_bad_method(); + return $this->p_include_path(self::PATH_BAD_METHOD, self::NAME_BAD_METHOD, 'c_reservation_path_bad_method'); + } + + /** + * Load and return the internal server error path. + */ + private function p_get_path_server_error() { + return $this->p_include_path(self::PATH_SERVER_ERROR, self::NAME_SERVER_ERROR, 'c_reservation_path_server_error'); + } + + /** + * Will include a custom language path if one exists. + * + * The default language files ends in "${path}${name}.php". + * All other language files end in "${path}${language_alias}/${name}.php". + * + * The default class is the provided class name. + * All other languages use the provided class name with '_${language_alias}' appended. + * + * For example (using path='my_file'), us english is the default, so that would load the file 'my_file.php'. + * japanese language load the file 'my_file-ja.php'. + * + * @param string $path + * The path to the include file, without the file name. + * @param string $name + * The file name of the PHP file, without the '.php' extension. + * @param string $class + * The name of the class, that is an instance of c_base_path, to execute. + * + * @return c_base_path + * The created c_base_path object. + */ + private function p_include_path($path, $name, $class) { + require_once($path . $name . '.php'); + + $aliases = array(); + $languages = $this->http->get_response_content_language()->get_value_exact(); + if (is_array($languages) && !empty($languages)) { + $language = reset($languages); + + // us-english is the default, so do not attempt to include any external files. + if ($language == i_base_language::ENGLISH_US || $language == i_base_language::ENGLISH) { + unset($language); + unset($aliases); + unset($languages); + return new $class(); + } + + $aliases = c_base_defaults_global::s_get_languages()::s_get_aliases_by_id($language)->get_value_exact(); + } + + // use default if no aliases are found. + if (empty($aliases)) { + unset($aliases); + unset($languages); + return new $class(); + } + + foreach ($aliases as $alias) { + // use include_once instead of require_require to allow for failsafe behavior. + @include_once($path . $alias . '/' . $name . '.php'); + + $language_class = $class . '_' . $alias; + if (class_exists($language_class)) { + unset($aliases); + unset($alias); + + $this->html->set_attribute(c_base_markup_attributes::ATTRIBUTE_LANGUAGE, $language); + unset($language); + + return new $language_class(); + } + } + unset($aliases); + unset($alias); + unset($language_class); + unset($language); + + // if unable to find, fallback to original class + return new $class(); } } diff --git a/program/reservation/reservation_redirects.php b/program/reservation/reservation_redirects.php index 14283e4..00a366a 100644 --- a/program/reservation/reservation_redirects.php +++ b/program/reservation/reservation_redirects.php @@ -19,11 +19,71 @@ final class c_reservation_path_redirect extends c_base_path { const PREFIX_CLASS = 'reservation-'; /** + * Create a redirect path. + * + * Defaults are silently forced on invalid parameters. + * + * @param string $field_destination + * A destination URL to redirect to. + * @param int $response_code + * The HTTP code to use when performing the redirect. + * Should be one of 3xx error code integers. + * @param int $field_response_code + * The redirect response code. + * Should be a 3xx url code. + * Usually one of: + * - 300 (Multiple Choices): + * - 301 (Moved Permanently): + * - 303 (See Other): + * This is not assigned on parameter error. + * @param bool $is_private + * (optional) When TRUE, path is considered private and requires specific access privileges. + * When FALSE, the path is accessible without any access privileges. + * Default setting is assigned on parameter error. + * + * @return c_base_markup_tag|c_base_return_status + * A newly created tag is returned on success. + * FALSE with the error bit set is returned on error. + */ + public static function s_create_redirect($field_destination, $field_response_code, $is_private = TRUE) { + $class = __CLASS__; + $path = new $class(); + unset($class); + + // @todo: store all errors on return. + $errors = array(); + + if (is_string($field_destination)) { + $path->set_field_destination($field_destination); + } + + if (is_int($field_response_code)) { + $path->set_field_response_code($field_response_code); + } + + if (is_bool($is_private)) { + $path->set_is_private($is_private); + } + else { + $path->set_is_private(TRUE); + } + + $path->set_is_redirect(TRUE); + + $timestamp_session = c_base_defaults_global::s_get_timestamp_session(); + $path->set_date_created($timestamp_session); + $path->set_date_changed($timestamp_session); + unset($timestamp_session); + + return $path; + } + + /** * Implements do_execute(). */ - public function do_execute(&$http, &$database, &$session, &$html, $settings = array()) { + public function do_execute(&$http, &$database, &$session, $settings = array()) { // the parent function performs validation on the parameters. - $executed = parent::do_execute($http, $database, $session, $html, $settings); + $executed = parent::do_execute($http, $database, $session, $settings); if (c_base_return::s_has_error($executed)) { return $executed; } diff --git a/program/reservation/reservation_session.php b/program/reservation/reservation_session.php index 14af8f0..a61b918 100644 --- a/program/reservation/reservation_session.php +++ b/program/reservation/reservation_session.php @@ -3,13 +3,13 @@ * @file * Provides reservation session functions. */ - require_once('common/base/classes/base_error.php'); - require_once('common/base/classes/base_return.php'); - require_once('common/base/classes/base_http.php'); - require_once('common/base/classes/base_session.php'); - require_once('common/base/classes/base_cookie.php'); +require_once('common/base/classes/base_error.php'); +require_once('common/base/classes/base_return.php'); +require_once('common/base/classes/base_http.php'); +require_once('common/base/classes/base_session.php'); +require_once('common/base/classes/base_cookie.php'); - require_once('program/reservation/reservation_database.php'); +require_once('program/reservation/reservation_database.php'); /**