From 64c33c49d6cf6970177f9a2491d167ea52736905 Mon Sep 17 00:00:00 2001 From: Kevin Day Date: Wed, 14 Jun 2017 22:44:50 -0500 Subject: [PATCH] Progress: work on view pages, numerous bugfixes and cleanups --- common/base/classes/base_array.php | 18 + common/base/classes/base_path.php | 86 +++- common/base/classes/base_return.php | 2 +- common/base/classes/base_session.php | 1 + common/base/classes/base_view.php | 121 ++++++ common/standard/classes/standard_index.php | 6 + common/standard/classes/standard_path.php | 112 ++---- common/standard/classes/standard_users.php | 3 +- common/standard/internal/access_denied.php | 2 - common/standard/internal/bad_method.php | 2 - common/standard/internal/index.php | 2 - common/standard/internal/not_found.php | 2 - common/standard/internal/server_error.php | 2 - common/standard/paths/a/dashboard.php | 2 - common/standard/paths/m/dashboard.php | 2 - common/standard/paths/u/dashboard.php | 2 - common/standard/paths/u/login.php | 2 - common/standard/paths/u/logout.php | 2 - common/standard/paths/u/user_create.php | 2 - common/standard/paths/u/user_delete.php | 2 - common/standard/paths/u/user_lock.php | 2 - common/standard/paths/u/user_settings.php | 2 - common/standard/paths/u/user_unlock.php | 2 - common/standard/paths/u/user_view.php | 82 +++- common/view/classes/view_log_users_self.php | 602 ++++++++++++++++++++++++++++ 25 files changed, 916 insertions(+), 147 deletions(-) create mode 100644 common/base/classes/base_view.php create mode 100644 common/view/classes/view_log_users_self.php diff --git a/common/base/classes/base_array.php b/common/base/classes/base_array.php index e59caf5..dfbd8a8 100644 --- a/common/base/classes/base_array.php +++ b/common/base/classes/base_array.php @@ -26,6 +26,24 @@ class c_base_array extends c_base_rfc_string { protected $items; /** + * Class constructor. + */ + public function __construct() { + parent::__construct(); + + $this->items = array(); + } + + /** + * Class constructor. + */ + public function __destruct() { + unset($this->items); + + parent::__destruct(); + } + + /** * @see: t_base_return_value::p_s_new() */ public static function s_new($value) { diff --git a/common/base/classes/base_path.php b/common/base/classes/base_path.php index 4e0bcdd..30feb6f 100644 --- a/common/base/classes/base_path.php +++ b/common/base/classes/base_path.php @@ -1198,33 +1198,89 @@ class c_base_path extends c_base_rfc_string { public function do_execute(&$http, &$database, &$session, $settings = array()) { $executed = new c_base_path_executed(); + if ($this->is_redirect) { + $http->set_response_location($this->field_destination); + $http->set_response_status($this->field_response_code); + } + + $result = $this->set_parameters($http, $database, $session, $settings); + if (c_base_return::s_has_error($result)) { + $executed->set_error($result->get_errors()); + } + unset($result); + + return $executed; + } + + /** + * Assign default variables used by this class. + * + * This is normally done automatically, but in certain cases, this may need to be explicitly called. + * + * Calling this will trigger default settings to be regernated, including the breadcrumbs. + * + * @param c_base_http &$http + * The entire HTTP information to allow for the execution to access anything that is necessary. + * @param c_base_database &$database + * The database object, which is usually used by form and ajax paths. + * @param c_base_session &$session + * The current session. + * @param array $settings + * (optional) An array of additional settings that are usually site-specific. + * + * @return c_base_return_status + * TRUE on success. + * FALSE with error bit set is returned on error. + * + * @see: self::do_execute() + */ + protected function set_parameters(&$http, &$database, &$session, $settings) { 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); - $executed->set_error($error); - unset($error); + return c_base_return_error::s_false($error); } - elseif (!($database instanceof c_base_database)) { + + 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); - $executed->set_error($error); - unset($error); + return c_base_return_error::s_false($error); } - elseif (!($session instanceof c_base_session)) { + + if (!($session instanceof c_base_session)) { $error = c_base_error::s_log(NULL, array('arguments' => array(':{argument_name}' => 'session', ':{function_name}' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::INVALID_ARGUMENT); - $executed->set_error($error); - unset($error); + return c_base_return_error::s_false($error); } - elseif (!is_array($settings)) { + + 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); - $executed->set_error($error); - unset($error); + return c_base_return_error::s_false($error); } - if ($this->is_redirect) { - $http->set_response_location($this->field_destination); - $http->set_response_status($this->field_response_code); + $this->http = $http; + $this->database = $database; + $this->session = $session; + $this->settings = $settings; + + $request_uri = $this->http->get_request(c_base_http::REQUEST_URI)->get_value_exact(); + if (isset($request_uri['data']) && is_string($request_uri['data'])) { + $request_uri = $request_uri['data']; + unset($request_uri['current']); + unset($request_uri['invalid']); + + $this->request_uri = $request_uri; + } + else { + $this->request_uri = array( + 'scheme' => $this->settings['base_scheme'], + 'authority' => $this->settings['base_host'], + 'path' => $this->settings['base_path'], + 'query' => NULL, + 'fragment' => NULL, + 'url' => TRUE, + ); } + unset($request_uri); - return $executed; + return new c_base_return_true(); } /** diff --git a/common/base/classes/base_return.php b/common/base/classes/base_return.php index d911b92..70554b5 100644 --- a/common/base/classes/base_return.php +++ b/common/base/classes/base_return.php @@ -1916,7 +1916,7 @@ class c_base_return_error { * @see: self::s_value() */ public static function s_return($class, $error = NULL) { - if (!class_exists($class) || !($class instanceof c_base_return)) { + if (!class_exists($class) && !($class instanceof c_base_return)) { return self::s_false($error); } diff --git a/common/base/classes/base_session.php b/common/base/classes/base_session.php index 1f34055..5dfe249 100644 --- a/common/base/classes/base_session.php +++ b/common/base/classes/base_session.php @@ -6,6 +6,7 @@ require_once('common/base/classes/base_error.php'); require_once('common/base/classes/base_return.php'); require_once('common/base/classes/base_form.php'); +require_once('common/base/classes/base_users.php'); /** * A class for managing sessions. diff --git a/common/base/classes/base_view.php b/common/base/classes/base_view.php new file mode 100644 index 0000000..a6395d7 --- /dev/null +++ b/common/base/classes/base_view.php @@ -0,0 +1,121 @@ + array(':{argument_name}' => 'database', ':{function_name}' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::INVALID_ARGUMENT); + return c_base_return_error::s_false($error); + } + + if (!is_null($query) && !is_string($query)) { + $error = c_base_error::s_log(NULL, array('arguments' => array(':{argument_name}' => 'query', ':{function_name}' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::INVALID_ARGUMENT); + return c_base_return_error::s_false($error); + } + + if (!is_array($arguments)) { + $error = c_base_error::s_log(NULL, array('arguments' => array(':{argument_name}' => 'arguments', ':{function_name}' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::INVALID_ARGUMENT); + return c_base_return_error::s_false($error); + } + + if (!is_null($conditions) && !is_string($conditions)) { + $error = c_base_error::s_log(NULL, array('arguments' => array(':{argument_name}' => 'conditions', ':{function_name}' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::INVALID_ARGUMENT); + return c_base_return_error::s_false($error); + } + + if (!is_null($limit) && !is_string($limit)) { + $error = c_base_error::s_log(NULL, array('arguments' => array(':{argument_name}' => 'limit', ':{function_name}' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::INVALID_ARGUMENT); + return c_base_return_error::s_false($error); + } + + if (!is_null($offset) && !is_string($offset)) { + $error = c_base_error::s_log(NULL, array('arguments' => array(':{argument_name}' => 'offset', ':{function_name}' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::INVALID_ARGUMENT); + return c_base_return_error::s_false($error); + } + + if (!is_null($group_by) && !is_string($group_by)) { + $error = c_base_error::s_log(NULL, array('arguments' => array(':{argument_name}' => 'group_by', ':{function_name}' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::INVALID_ARGUMENT); + return c_base_return_error::s_false($error); + } + + if (!is_null($order_by) && !is_string($order_by)) { + $error = c_base_error::s_log(NULL, array('arguments' => array(':{argument_name}' => 'order_by', ':{function_name}' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::INVALID_ARGUMENT); + return c_base_return_error::s_false($error); + } + + // return FALSE because this is a stub function and it does nothing. + return new c_base_return_false(); + } +} diff --git a/common/standard/classes/standard_index.php b/common/standard/classes/standard_index.php index 92ba4e5..0db4822 100644 --- a/common/standard/classes/standard_index.php +++ b/common/standard/classes/standard_index.php @@ -527,12 +527,18 @@ class c_standard_index extends c_base_return { if ($user_current->do_load($this->database) instanceof c_base_return_true) { $this->session->set_user_current($user_current); } + else { + // @todo: hanle errors. + } unset($user_current); $user_session = new c_standard_users_user(); if ($user_session->do_load($this->database, TRUE) instanceof c_base_return_true) { $this->session->set_user_current($user_session); } + else { + // @todo: hanle errors. + } unset($user_session); return new c_base_return_true(); diff --git a/common/standard/classes/standard_path.php b/common/standard/classes/standard_path.php index 62b4e21..96168b2 100644 --- a/common/standard/classes/standard_path.php +++ b/common/standard/classes/standard_path.php @@ -136,49 +136,41 @@ class c_standard_path extends c_base_path { } /** - * Assign default variables used by this class. - * - * This is normally done automatically, but in certain cases, this may need to be explicitly called. - * - * Calling this will trigger default settings to be regernated, including the breadcrumbs. - * - * @param c_base_http &$http - * The entire HTTP information to allow for the execution to access anything that is necessary. - * @param c_base_database &$database - * The database object, which is usually used by form and ajax paths. - * @param c_base_session &$session - * The current session. - * @param array $settings - * (optional) An array of additional settings that are usually site-specific. - * - * @return c_base_return_status - * TRUE on success. - * FALSE with error bit set is returned on error. - * - * @see: self::do_execute() + * Implements do_execute(). */ - protected function set_parameters(&$http, &$database, &$session, $settings) { - 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); - return c_base_return_error::s_false($error); + public function do_execute(&$http, &$database, &$session, $settings = array()) { + $executed = parent::do_execute($http, $database, $session, $settings); + if (c_base_return::s_has_error($executed)) { + return $executed; } - 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_false($error); + // to avoid recursion, breadcrumbs are initialized here instead of in set_parameters(). + $this->pr_build_breadcrumbs(); + + return $executed; + } + + /** + * Implements set_parameters(). + */ + protected function set_parameters(&$http, &$database, &$session, $settings) { + $result = parent::set_parameters($http, $database, $session, $settings); + if (c_base_return::s_has_error($result)) { + return $result; } + unset($result); - if (!($session instanceof c_base_session)) { - $error = c_base_error::s_log(NULL, array('arguments' => array(':{argument_name}' => 'session', ':{function_name}' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::INVALID_ARGUMENT); - return c_base_return_error::s_false($error); + $this->text_type = c_base_markup_tag::TYPE_SPAN; + if (isset($this->settings['standards_issue-use_p_tags']) && $this->settings['standards_issue-use_p_tags']) { + $this->text_type = c_base_markup_tag::TYPE_PARAGRAPH; } - 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_false($error); + $this->languages = $this->http->get_response_content_language()->get_value_exact(); + if (!is_array($this->languages)) { + $this->languages = array(); } - $this->pr_assign_defaults($http, $database, $session, $settings); + $this->pr_get_language_alias(); return new c_base_return_true(); } @@ -234,58 +226,6 @@ class c_standard_path extends c_base_path { return $path_parts; } - /** - * Load any default settings. - * - * @param c_base_http &$http - * The entire HTTP information to allow for the execution to access anything that is necessary. - * @param c_base_database &$database - * The database object, which is usually used by form and ajax paths. - * @param c_base_session &$session - * The current session. - * @param array $settings - * (optional) An array of additional settings that are usually site-specific. - */ - protected function pr_assign_defaults(&$http, &$database, &$session, &$settings) { - $this->http = $http; - $this->database = $database; - $this->session = $session; - $this->settings = $settings; - - $this->text_type = c_base_markup_tag::TYPE_SPAN; - if (isset($this->settings['standards_issue-use_p_tags']) && $this->settings['standards_issue-use_p_tags']) { - $this->text_type = c_base_markup_tag::TYPE_PARAGRAPH; - } - - $request_uri = $this->http->get_request(c_base_http::REQUEST_URI)->get_value_exact(); - if (isset($request_uri['data']) && is_string($request_uri['data'])) { - $request_uri = $request_uri['data']; - unset($request_uri['current']); - unset($request_uri['invalid']); - - $this->request_uri = $request_uri; - } - else { - $this->request_uri = array( - 'scheme' => $this->settings['base_scheme'], - 'authority' => $this->settings['base_host'], - 'path' => $this->settings['base_path'], - 'query' => NULL, - 'fragment' => NULL, - 'url' => TRUE, - ); - } - unset($request_uri); - - $this->languages = $this->http->get_response_content_language()->get_value_exact(); - if (!is_array($this->languages)) { - $this->languages = array(); - } - - $this->pr_get_language_alias(); - - $this->pr_build_breadcrumbs(); - } /** * Build the breadcrumb. diff --git a/common/standard/classes/standard_users.php b/common/standard/classes/standard_users.php index 67219c0..70b3a2f 100644 --- a/common/standard/classes/standard_users.php +++ b/common/standard/classes/standard_users.php @@ -106,10 +106,11 @@ class c_standard_users_user extends c_base_users_user { $false = c_base_return_error::s_false($query_result->get_error()); $last_error = $database->get_last_error()->get_value_exact(); - var_dump($last_error); + if (!empty($last_error)) { $error = c_base_error::s_log(NULL, array('arguments' => array(':{database_error_message}' => $last_error, ':{function_name}' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::POSTGRESQL_ERROR); $false->set_error($error); + unset($error); } unset($last_error); diff --git a/common/standard/internal/access_denied.php b/common/standard/internal/access_denied.php index 582a8ee..b358e12 100644 --- a/common/standard/internal/access_denied.php +++ b/common/standard/internal/access_denied.php @@ -23,8 +23,6 @@ class c_standard_path_access_denied extends c_standard_path_exception { return $executed; } - $this->pr_assign_defaults($http, $database, $session, $settings); - $wrapper = $this->pr_create_tag_section(array(1 => 0)); $wrapper->set_tag($this->pr_create_tag_text_block(1)); diff --git a/common/standard/internal/bad_method.php b/common/standard/internal/bad_method.php index 085333f..8b2c946 100644 --- a/common/standard/internal/bad_method.php +++ b/common/standard/internal/bad_method.php @@ -25,8 +25,6 @@ class c_standard_path_bad_method extends c_standard_path_exception { return $executed; } - $this->pr_assign_defaults($http, $database, $session, $settings); - $wrapper = $this->pr_create_tag_section(array(1 => 0)); $wrapper->set_tag($this->pr_create_tag_text_block(1)); diff --git a/common/standard/internal/index.php b/common/standard/internal/index.php index a15169e..0d0e512 100644 --- a/common/standard/internal/index.php +++ b/common/standard/internal/index.php @@ -37,8 +37,6 @@ class c_standard_path_index extends c_standard_path { return $executed; } - $this->pr_assign_defaults($http, $database, $session, $settings); - $wrapper = $this->pr_create_tag_section(array(1 => 0)); $wrapper->set_tag($this->pr_create_tag_text_block(1)); diff --git a/common/standard/internal/not_found.php b/common/standard/internal/not_found.php index 5f691f9..91dc434 100644 --- a/common/standard/internal/not_found.php +++ b/common/standard/internal/not_found.php @@ -23,8 +23,6 @@ class c_standard_path_not_found extends c_standard_path_exception { return $executed; } - $this->pr_assign_defaults($http, $database, $session, $settings); - $wrapper = $this->pr_create_tag_section(array(1 => 0)); $wrapper->set_tag($this->pr_create_tag_text_block(1)); diff --git a/common/standard/internal/server_error.php b/common/standard/internal/server_error.php index 79aafa6..3d9b488 100644 --- a/common/standard/internal/server_error.php +++ b/common/standard/internal/server_error.php @@ -23,8 +23,6 @@ class c_standard_path_server_error extends c_standard_path_exception { return $executed; } - $this->pr_assign_defaults($http, $database, $session, $settings); - $wrapper = $this->pr_create_tag_section(array(1 => 0)); $wrapper->set_tag($this->pr_create_tag_text_block(1)); diff --git a/common/standard/paths/a/dashboard.php b/common/standard/paths/a/dashboard.php index f6b10e7..a03fbca 100644 --- a/common/standard/paths/a/dashboard.php +++ b/common/standard/paths/a/dashboard.php @@ -25,8 +25,6 @@ class c_standard_path_administer_dashboard extends c_standard_path { return $executed; }; - $this->pr_assign_defaults($http, $database, $session, $settings); - $wrapper = $this->pr_create_tag_section(array(1 => 0)); diff --git a/common/standard/paths/m/dashboard.php b/common/standard/paths/m/dashboard.php index 158f73e..ac3c46e 100644 --- a/common/standard/paths/m/dashboard.php +++ b/common/standard/paths/m/dashboard.php @@ -25,8 +25,6 @@ class c_standard_path_management_dashboard extends c_standard_path { return $executed; }; - $this->pr_assign_defaults($http, $database, $session, $settings); - $wrapper = $this->pr_create_tag_section(array(1 => 0)); diff --git a/common/standard/paths/u/dashboard.php b/common/standard/paths/u/dashboard.php index 0b9231b..193decd 100644 --- a/common/standard/paths/u/dashboard.php +++ b/common/standard/paths/u/dashboard.php @@ -47,8 +47,6 @@ class c_standard_path_user_dashboard extends c_standard_path { return $executed; }; - $this->pr_assign_defaults($http, $database, $session, $settings); - $wrapper = $this->pr_create_tag_section(array(1 => 0)); $wrapper->set_tag($this->pr_create_tag_text_block(1)); diff --git a/common/standard/paths/u/login.php b/common/standard/paths/u/login.php index 79fad31..b12a088 100644 --- a/common/standard/paths/u/login.php +++ b/common/standard/paths/u/login.php @@ -37,8 +37,6 @@ class c_standard_path_user_login extends c_standard_path { return $executed; } - $this->pr_assign_defaults($http, $database, $session, $settings); - // initialize the content as HTML. $this->pr_create_html(); diff --git a/common/standard/paths/u/logout.php b/common/standard/paths/u/logout.php index 9239b13..759cf01 100644 --- a/common/standard/paths/u/logout.php +++ b/common/standard/paths/u/logout.php @@ -33,8 +33,6 @@ class c_standard_path_user_logout extends c_standard_path { return $executed; } - $this->pr_assign_defaults($http, $database, $session, $settings); - $this->pr_do_logout($http, $database, $session, $settings); $wrapper = $this->pr_create_tag_section(array(1 => 0)); diff --git a/common/standard/paths/u/user_create.php b/common/standard/paths/u/user_create.php index 2417caa..28e53d1 100644 --- a/common/standard/paths/u/user_create.php +++ b/common/standard/paths/u/user_create.php @@ -25,8 +25,6 @@ class c_standard_path_user_create extends c_standard_path { return $executed; }; - $this->pr_assign_defaults($http, $database, $session, $settings); - $wrapper = $this->pr_create_tag_section(array(1 => 0)); // initialize the content as HTML. diff --git a/common/standard/paths/u/user_delete.php b/common/standard/paths/u/user_delete.php index 107766c..ffea35a 100644 --- a/common/standard/paths/u/user_delete.php +++ b/common/standard/paths/u/user_delete.php @@ -25,8 +25,6 @@ class c_standard_path_user_delete extends c_standard_path { return $executed; }; - $this->pr_assign_defaults($http, $database, $session, $settings); - $wrapper = $this->pr_create_tag_section(array(1 => 0)); // initialize the content as HTML. diff --git a/common/standard/paths/u/user_lock.php b/common/standard/paths/u/user_lock.php index daa9780..50b9207 100644 --- a/common/standard/paths/u/user_lock.php +++ b/common/standard/paths/u/user_lock.php @@ -25,8 +25,6 @@ class c_standard_path_user_lock extends c_standard_path { return $executed; }; - $this->pr_assign_defaults($http, $database, $session, $settings); - $wrapper = $this->pr_create_tag_section(array(1 => 0)); // initialize the content as HTML. diff --git a/common/standard/paths/u/user_settings.php b/common/standard/paths/u/user_settings.php index 74d3e1c..0797653 100644 --- a/common/standard/paths/u/user_settings.php +++ b/common/standard/paths/u/user_settings.php @@ -30,8 +30,6 @@ class c_standard_path_user_settings extends c_standard_path { return $executed; }; - $this->pr_assign_defaults($http, $database, $session, $settings); - $arguments = $this->pr_get_path_arguments(self::PATH_SELF); if (!empty($arguments)) { // @todo: return $this->p_do_execute_X($executed); diff --git a/common/standard/paths/u/user_unlock.php b/common/standard/paths/u/user_unlock.php index d87bdfa..be3cc00 100644 --- a/common/standard/paths/u/user_unlock.php +++ b/common/standard/paths/u/user_unlock.php @@ -25,8 +25,6 @@ class c_standard_path_user_unlock extends c_standard_path { return $executed; }; - $this->pr_assign_defaults($http, $database, $session, $settings); - $wrapper = $this->pr_create_tag_section(array(1 => 0)); // initialize the content as HTML. diff --git a/common/standard/paths/u/user_view.php b/common/standard/paths/u/user_view.php index 03b4f3b..44cc0b1 100644 --- a/common/standard/paths/u/user_view.php +++ b/common/standard/paths/u/user_view.php @@ -35,10 +35,9 @@ class c_standard_path_user_view extends c_standard_path { return $executed; }; - $this->pr_assign_defaults($http, $database, $session, $settings); - // @todo: this function needs to check to see if the user has administer (or manager?) roles (c_base_roles::MANAGER, c_base_roles::ADMINISTER) and if they do, set administrative to TRUE when calling do_load(). - $roles_current = $this->session->get_user_current()->get_roles()->get_value_exact(); + $user = $this->session->get_user_current(); + $roles_current = $user->get_roles()->get_value_exact(); $id_user = NULL; $arguments = $this->pr_get_path_arguments(self::PATH_SELF); @@ -51,13 +50,14 @@ class c_standard_path_user_view extends c_standard_path { // do not allow view access to reserved/special accounts. if ($id_user < self::ID_USER_MINIMUM) { - $id_user = NULL; + $id_user = FALSE; } } else { unset($arguments_total); unset($argument); unset($id_user); + unset($user); $error = c_base_error::s_log(NULL, array('arguments' => array(':{path_name}' => self::PATH_SELF . '/' . implode('/', $arguments), ':{function_name}' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::NOT_FOUND_PATH); $executed->set_error($error); @@ -84,13 +84,16 @@ class c_standard_path_user_view extends c_standard_path { # $id_user = NULL; #} else { - $id_user = NULL; + $id_user = FALSE; } } unset($arguments_total); unset($argument); - if (is_null($id_user)) { + if ($id_user === FALSE) { + unset($user); + unset($id_user); + $error = c_base_error::s_log(NULL, array('arguments' => array(':{path_name}' => self::PATH_SELF . '/' . implode('/', $arguments), ':{function_name}' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::NOT_FOUND_PATH); $executed->set_error($error); @@ -101,10 +104,14 @@ class c_standard_path_user_view extends c_standard_path { } } + $user = NULL; if (is_null($id_user)) { - // load current user. - if ($this->session->get_user_current()->get_id()->get_value_exact() > 0) { - $user = $this->session->get_user_current(); + $user = $this->session->get_user_current(); + $id_user = $user->get_id()->get_value_exact(); + + // do not allow view access to reserved/special accounts. + if ($id_user < self::ID_USER_MINIMUM) { + $id_user = FALSE; } } else { @@ -113,14 +120,14 @@ class c_standard_path_user_view extends c_standard_path { // @todo: handle database errors. $loaded = $user->do_load($this->database, $id_user); if ($loaded instanceof c_base_return_false) { - $user = NULL; + $id_user = FALSE; } unset($loaded); } - unset($id_user); - // user is set to NULL on error. - if (is_null($user)) { + if ($id_user === FALSE) { + unset($id_user); + $error = c_base_error::s_log(NULL, array('arguments' => array(':{path_name}' => self::PATH_SELF . '/' . implode('/', $arguments), ':{function_name}' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::NOT_FOUND_PATH); $executed->set_error($error); @@ -129,6 +136,7 @@ class c_standard_path_user_view extends c_standard_path { return $executed; } unset($arguments); + unset($id_user); $this->p_do_execute_view($executed, $user); unset($user); @@ -314,8 +322,14 @@ class c_standard_path_user_view extends c_standard_path { * The execution results to be returned. * @param c_base_users_user $user_id * An object representing the user to view. + * + * @return null|c_base_return_error + * NULL is returned if no errors are found. + * Errors are returned if found. */ - private function p_do_execute_view(&$executed, $user) { + protected function p_do_execute_view(&$executed, $user) { + $errors = NULL; + $arguments = array(); $arguments[':{user_name}'] = $user->get_name_human()->get_first()->get_value_exact() . ' ' . $user->get_name_human()->get_last()->get_value_exact(); if (mb_strlen($arguments[':{user_name}']) == 0) { @@ -548,6 +562,46 @@ class c_standard_path_user_view extends c_standard_path { // @todo: implement code for processing and generating a table/list of history, with the ability to navigate additional entries. + $query_result = $this->database->do_query('select id, id_user, log_title, log_type, log_type_sub, log_severity, log_facility, log_details, log_date, request_client, response_code from v_log_users_self limit 10'); + + if (c_base_return::s_has_error($query_result)) { + if (is_null($errors)) { + $errors = $query_result->get_error(); + } + else { + c_base_return::s_copy_errors($query_result->get_error(), $errors); + } + + $last_error = $this->database->get_last_error()->get_value_exact(); + + if (!empty($last_error)) { + $error = c_base_error::s_log(NULL, array('arguments' => array(':{database_error_message}' => $last_error, ':{function_name}' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::POSTGRESQL_ERROR); + $errors->set_error($error); + unset($error); + } + unset($last_error); + } + else { + $columns = $query_result->fetch_row()->get_value(); + while (is_array($columns) && !empty($columns)) { + $this->id = (int) $columns[0]; + $this->id_user = (int) $columns[1]; + + $this->log_title = (string) $columns[2]; + $this->log_type = (int) $columns[3]; + $this->log_type_sub = (int) $columns[4]; + $this->log_severity = (int) $columns[5]; + $this->log_facility = (int) $columns[6]; + $this->log_details = json_decode($columns[7], TRUE); + $this->log_date = c_base_defaults_global::s_get_timestamp($columns[8])->get_value_exact(); + $this->request_client = (string) $columns[9]; + $this->response_code = (int) $columns[10]; + + $columns = $query_result->fetch_row()->get_value(); + } + unset($columns); + } + $fieldset->set_tag($content); unset($content); diff --git a/common/view/classes/view_log_users_self.php b/common/view/classes/view_log_users_self.php new file mode 100644 index 0000000..9917c42 --- /dev/null +++ b/common/view/classes/view_log_users_self.php @@ -0,0 +1,602 @@ +id = NULL; + } + + /** + * Class constructor. + */ + public function __destruct() { + unset($this->id); + + parent::__destruct(); + } + + /** + * @see: t_base_return_value::p_s_new() + */ + public static function s_new($value) { + return self::p_s_new($value, __CLASS__); + } + + /** + * @see: t_base_return_value::p_s_value() + */ + public static function s_value($return) { + return self::p_s_value($return, __CLASS__); + } + + /** + * @see: t_base_return_value_exact::p_s_value_exact() + */ + public static function s_value_exact($return) { + return self::p_s_value_exact($return, __CLASS__, ''); + } + + /** + * Provides basic database load access for whose data is to be stored in this class. + * + * @param c_base_database &$database + * The database object to load from. + * @param string|null $query + * (optional) The query string to execute. + * If NULL, then the class default will be used. + * @param array $arguments + * (optional) An array containing arguments to be passed along with the query string. + * @param string|null $conditions + * (optional) This can be a string of additional conditions to append to the default query string. + * This is appended to the query string along with ' where '. + * If a where condition is already specified in the query string then this will result in a query error. + * @param int|null $limit + * (optional) This can be an integer to append to the default query string as a query limit. + * This is appended to the query string along with ' limit '. + * If a limit condition is already specified in the query string then this will result in a query error. + * @param int|null $offset + * (optional) This can be an integer to append to the default query string as a query offset. + * This is appended to the query string along with ' offset '. + * If a offset condition is already specified in the query string then this will result in a query error. + * @param int|null $group_by + * (optional) This can be an integer to append to the default query string as a query group by. + * This is appended to the query string along with ' group by '. + * If a group by condition is already specified in the query string then this will result in a query error. + * @param int|null $order_by + * (optional) This can be an integer to append to the default query string as a query order by. + * This is appended to the query string along with ' order by '. + * If a order by condition is already specified in the query string then this will result in a query error. + * + * @return c_base_return_status + * TRUE on success. + * FALSE without error bit set is returned if nothing was done. + * FALSE with error bit set is returned on error. + */ + public function pull(&$database, $query = NULL, $arguments = array(), $conditions = NULL, $limit = NULL, $offset = NULL, $group_by = NULL, $order_by = NULL) { + $result = parent::pull($database, $query, $arguments, $conditions, $limit, $offset, $group_by, $order_by); + if (c_base_return::s_has_error($result)) { + return $result; + } + unset($result); + + $query_string = ''; + if (is_null($query)) { + } + else { + $query_string = $query; + } + + } +} + +/** + * A specific class for storing view results: v_log_users_self. + */ +class c_view_log_users_self extends c_base_return { + protected $id; + protected $id_user; + + protected $log_title; + protected $log_type; + protected $log_type_sub; + protected $log_severity; + protected $log_facility; + protected $log_details; + protected $log_date; + + protected $request_client; + protected $response_code; + + /** + * Class constructor. + */ + public function __construct() { + parent::__construct(); + + $this->id = NULL; + $this->id_user = NULL; + + $this->log_title = NULL; + $this->log_type = NULL; + $this->log_type_sub = NULL; + $this->log_severity = NULL; + $this->log_facility = NULL; + $this->log_details = NULL; + $this->log_date = NULL; + + $this->request_client = NULL; + $this->response_code = NULL; + } + + /** + * Class constructor. + */ + public function __destruct() { + unset($this->id); + unset($this->id_user); + + unset($this->log_title); + unset($this->log_type); + unset($this->log_type_sub); + unset($this->log_severity); + unset($this->log_facility); + unset($this->log_details); + unset($this->log_date); + + unset($this->request_client); + unset($this->response_code); + + parent::__destruct(); + } + + /** + * @see: t_base_return_value::p_s_new() + */ + public static function s_new($value) { + return self::p_s_new($value, __CLASS__); + } + + /** + * @see: t_base_return_value::p_s_value() + */ + public static function s_value($return) { + return self::p_s_value($return, __CLASS__); + } + + /** + * @see: t_base_return_value_exact::p_s_value_exact() + */ + public static function s_value_exact($return) { + return self::p_s_value_exact($return, __CLASS__, ''); + } + + /** + * Set the log id. + * + * @param int $id + * The log id. + * + * @return c_base_return_status + * TRUE on success. + * FALSE with error bit set is returned on error. + */ + public function set_id($id) { + if (!is_int($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); + } + + $this->id = $id; + return new c_base_return_true(); + } + + /** + * Set the user id. + * + * @param int $id_user + * The user id. + * + * @return c_base_return_status + * TRUE on success. + * FALSE with error bit set is returned on error. + */ + public function set_id_user($id_user) { + if (!is_int($id_user)) { + $error = c_base_error::s_log(NULL, array('arguments' => array(':{argument_name}' => 'id_user', ':{function_name}' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::INVALID_ARGUMENT); + return c_base_return_error::s_false($error); + } + + $this->id_user = $id_user; + return new c_base_return_true(); + } + + /** + * Set the log title. + * + * @param string $title + * The log title. + * + * @return c_base_return_status + * TRUE on success. + * FALSE with error bit set is returned on error. + */ + public function set_title($title) { + if (!is_string($title)) { + $error = c_base_error::s_log(NULL, array('arguments' => array(':{argument_name}' => 'title', ':{function_name}' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::INVALID_ARGUMENT); + return c_base_return_error::s_false($error); + } + + $this->title = $title; + return new c_base_return_true(); + } + + /** + * Set the log type. + * + * @param string $type + * The log type. + * + * @return c_base_return_status + * TRUE on success. + * FALSE with error bit set is returned on error. + */ + public function set_type($type) { + if (!is_string($type)) { + $error = c_base_error::s_log(NULL, array('arguments' => array(':{argument_name}' => 'type', ':{function_name}' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::INVALID_ARGUMENT); + return c_base_return_error::s_false($error); + } + + $this->type = $type; + return new c_base_return_true(); + } + + /** + * Set the log type sub. + * + * @param string $type_sub + * The log sub-type. + * + * @return c_base_return_status + * TRUE on success. + * FALSE with error bit set is returned on error. + */ + public function set_type_sub($type_sub) { + if (!is_string($type_sub)) { + $error = c_base_error::s_log(NULL, array('arguments' => array(':{argument_name}' => 'type_sub', ':{function_name}' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::INVALID_ARGUMENT); + return c_base_return_error::s_false($error); + } + + $this->type_sub = $type_sub; + return new c_base_return_true(); + } + + /** + * Set the log severity. + * + * @param string $log_severity + * The log severity. + * + * @return c_base_return_status + * TRUE on success. + * FALSE with error bit set is returned on error. + */ + public function set_log_severity($log_severity) { + if (!is_int($log_severity)) { + $error = c_base_error::s_log(NULL, array('arguments' => array(':{argument_name}' => 'log_severity', ':{function_name}' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::INVALID_ARGUMENT); + return c_base_return_error::s_false($error); + } + + $this->log_severity = $log_severity; + return new c_base_return_true(); + } + + /** + * Set the log facility. + * + * @param string $log_facility + * The log facility. + * + * @return c_base_return_status + * TRUE on success. + * FALSE with error bit set is returned on error. + */ + public function set_log_facility($log_facility) { + if (!is_string($log_facility)) { + $error = c_base_error::s_log(NULL, array('arguments' => array(':{argument_name}' => 'log_facility', ':{function_name}' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::INVALID_ARGUMENT); + return c_base_return_error::s_false($error); + } + + $this->log_facility = $log_facility; + return new c_base_return_true(); + } + + /** + * Set the log details. + * + * @param array|string $log_details + * The log details. + * If a string, then this is a json encoded string to be converted into an array. + * + * @return c_base_return_status + * TRUE on success. + * FALSE with error bit set is returned on error. + */ + public function set_log_details($log_details) { + if (is_string($log_details)) { + $log_details_decoded = json_decode($log_details, TRUE); + + if (!is_array($log_details_decoded)) { + unset($log_details_decoded); + $error = c_base_error::s_log(NULL, array('arguments' => array(':{argument_name}' => 'log_details', ':{function_name}' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::INVALID_ARGUMENT); + return c_base_return_error::s_false($error); + } + + $this->log_details = $log_details_decoded; + unset($log_details_decoded); + + return new c_base_return_true(); + } + + if (!is_array($log_details)) { + $error = c_base_error::s_log(NULL, array('arguments' => array(':{argument_name}' => 'log_details', ':{function_name}' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::INVALID_ARGUMENT); + return c_base_return_error::s_false($error); + } + + $this->log_details = $log_details; + return new c_base_return_true(); + } + + /** + * Set the log date. + * + * @param int|float|string $date + * The log date. + * If this is a string, then it is a date string to be converted into a timestamp. + * + * @return c_base_return_status + * TRUE on success. + * FALSE with error bit set is returned on error. + */ + public function set_date($date) { + if (is_string($date)) { + $this->date = c_base_defaults_global::s_get_timestamp($date)->get_value_exact();; + return new c_base_return_true(); + } + + if (!is_int($date) && !is_float($date)) { + $error = c_base_error::s_log(NULL, array('arguments' => array(':{argument_name}' => 'date', ':{function_name}' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::INVALID_ARGUMENT); + return c_base_return_error::s_false($error); + } + + $this->date = $date; + return new c_base_return_true(); + } + + /** + * Set the log request_client. + * + * @param string $request_client + * The log request_client. + * + * @return c_base_return_status + * TRUE on success. + * FALSE with error bit set is returned on error. + */ + public function set_request_client($request_client) { + if (!is_string($request_client)) { + $error = c_base_error::s_log(NULL, array('arguments' => array(':{argument_name}' => 'request_client', ':{function_name}' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::INVALID_ARGUMENT); + return c_base_return_error::s_false($error); + } + + $this->request_client = $request_client; + return new c_base_return_true(); + } + + /** + * Set the log response_code. + * + * @param string $response_code + * The log response_code. + * + * @return c_base_return_status + * TRUE on success. + * FALSE with error bit set is returned on error. + */ + public function set_response_code($response_code) { + if (!is_string($response_code)) { + $error = c_base_error::s_log(NULL, array('arguments' => array(':{argument_name}' => 'response_code', ':{function_name}' => __CLASS__ . '->' . __FUNCTION__)), i_base_error_messages::INVALID_ARGUMENT); + return c_base_return_error::s_false($error); + } + + $this->response_code = $response_code; + return new c_base_return_true(); + } + + /** + * Get the log id. + * + * @return c_base_return_int + * The unique numeric id assigned to this object. + * 0 with error bit set is returned on error. + */ + public function get_id() { + if (!is_int($this->id)) { + $this->id = 0; + } + + return c_base_return_int::s_new($this->id); + } + + /** + * Get the user id. + * + * @return c_base_return_int + * The numeric id assigned to this object. + * 0 with error bit set is returned on error. + */ + public function get_id_user() { + if (!is_int($this->id_user)) { + $this->id_user = 0; + } + + return c_base_return_int::s_new($this->id_user); + } + + /** + * Get the log title. + * + * @return c_base_return_string + * The unique log title assigned to this object. + * An empty string with error bit set is returned on error. + */ + public function get_log_title() { + if (!is_string($this->log_title)) { + $this->log_title = ''; + } + + return c_base_return_string::s_new($this->log_title); + } + + /** + * Get the log type. + * + * @return c_base_return_int + * The log type assigned to this object. + * An empty string with error bit set is returned on error. + */ + public function get_log_type() { + if (!is_int($this->log_type)) { + $this->log_type = 0; + } + + return c_base_return_int::s_new($this->log_type); + } + + /** + * Get the log type_sub. + * + * @return c_base_return_int + * The log sub-type assigned to this object. + * An empty string with error bit set is returned on error. + */ + public function get_log_type_sub() { + if (!is_int($this->log_type_sub)) { + $this->log_type_sub = 0; + } + + return c_base_return_int::s_new($this->log_type_sub); + } + + /** + * Get the log severity. + * + * @return c_base_return_int + * The log severity assigned to this object. + * An empty string with error bit set is returned on error. + */ + public function get_log_severity() { + if (!is_int($this->log_severity)) { + $this->log_severity = 0; + } + + return c_base_return_int::s_new($this->log_severity); + } + + /** + * Get the log facility. + * + * @return c_base_return_int + * The log facility assigned to this object. + * An empty string with error bit set is returned on error. + */ + public function get_log_facility() { + if (!is_int($this->log_facility)) { + $this->log_facility = 0; + } + + return c_base_return_int::s_new($this->log_facility); + } + + /** + * Get the log details. + * + * @return c_base_return_array + * The log details assigned to this object. + * An empty array with error bit set is returned on error. + */ + public function get_log_details() { + if (!is_array($this->log_details)) { + $this->log_details = array(); + } + + return c_base_return_array::s_new($this->log_details); + } + + /** + * Get the log date. + * + * @return c_base_return_int|c_base_return_float + * The log date assigned to this object. + * An empty string with error bit set is returned on error. + */ + public function get_log_date() { + if (!is_int($this->log_date) && !is_float($this->log_date)) { + $this->log_date = 0; + } + + if (is_float($this->log_date)) { + return c_base_return_float::s_new($this->log_date); + } + + return c_base_return_int::s_new($this->log_date); + } + + /** + * Get the log request_client. + * + * @return c_base_return_string + * The request client assigned to this object. + * An empty string with error bit set is returned on error. + */ + public function get_request_client() { + if (!is_string($this->request_client)) { + $this->request_client = ''; + } + + return c_base_return_string::s_new($this->request_client); + } + + /** + * Get the log response_code. + * + * @return c_base_return_int + * The response code assigned to this object. + * An empty string with error bit set is returned on error. + */ + public function get_response_code() { + if (!is_int($this->response_code)) { + $this->response_code = 0; + } + + return c_base_return_int::s_new($this->response_code); + } +} -- 1.8.3.1