diff --git a/conf/messages.php b/conf/messages.php index f03b523e5..eafcf2749 100644 --- a/conf/messages.php +++ b/conf/messages.php @@ -1,101 +1,100 @@ - - * @copyright Copyright © 2006 Peter Adams - * @license http://www.gnu.org/copyleft/gpl.html GPL v2.0 - * @category owa - * @package owa - * @version $Revision$ - * @since owa 1.0.0 - */ - -$_owa_messages = array( - -2000 => array("An e-mail containing instructions on how to complete the password reset process has been sent to %s",1), -2001 => array("The e-mail %s was not found in our database. Please check the address and try again.",1), -2002 => array("Login Failed. Your user name or password did not match.",0), -2003 => array("Your Account lacks the necessary privileges to access the requested resource.",0), -2004 => array("You must login to access the requested resource.",0), -2010 => array("Success. Logout Complete.",0), -2011 => array("Error. Can't find your temporary passkey in the db.",0), - -// Options/Configuration related -2500 => array("Options Saved.",0), -2501 => array("The module was activated successfully.",0), -2502 => array("The module was deactivated successfully.",0), -2503 => array("Options reset to Default Values.",0), -2504 => array("Entity %s Schema Created.",1), -2504 => array("Goal Saved.",0), - - -//User managment -3000 => array("Success. User Added.", 0), -3001 => array("Error. That user name is already taken.",0), -3002 => array("The form data that you entered contained one or more errors. Please check the data and submit the from again."), -3003 => array("Success. User profile saved.",0), -3004 => array("Success. User acount deleted."), -3005 => array("Enter Your New Password", 0), -3006 => array("Success. Please login with your new password.",0), -3007 => array("Error. Your passwords must match.",0), -3008 => array("Error. Your password must be %s characters long.", 1), -3009 => array("Error. A user with that email address already exists.", 0), -3010 => array("A user with that email address does not exist.", 0), -3011 => array("Could not update user profile."), -3012 => array("Could not connect the database. Check your settings and try again.",0), - -//sites management -3200 => array("Error. Please fill in all required fields.",0), -3201 => array("Success. Site Profile Updated.",0), -3202 => array("Success. Site Added.",0), -3203 => array("Error. Site Could not be added",0), -3204 => array("Success. Site Deleted.",0), -3206 => array("Error. A site with that domain already exists.",0), -3207 => array("Error. You must enter a domain when adding a web site.",0), -3208 => array("Error. That site does not exist.",0), -3208 => array("Please remove the http:// from your beginning of your domain.",0), - - -//install -3300 => array("Could not connect to the database. Please check the database connection settings in your configuration file and try again.",0), -3301 => array("This version of OWA requires PHP 5.2.x or higher.",0), -3302 => array("Database Schema Installation failed. Please check the error log file for more details.",0), -3303 => array("Success. Default Site Added.",0), -3304 => array("Success. Admin User Added.",0), -3305 => array("Success. Base Database Schema Installed.",0), -3306 => array("Error. User id already exists for some reason.",0), -3307 => array("Updates failed. Check OWA's error log file for more details and try again.",0), -3308 => array("Success. Updates were applied.",0), -3309 => array("Site Domain is required.",0), -3310 => array("E-mail Address is required.",0), -3310 => array("Password is required.",0), -3311 => array("These updates must be applied using the command line interface (CLI). Run '/path/to/php cli.php cmd=update' from your server's command shell to apply these updates. For more information on updating see the install/update page on the wiki.",0), -// Graph related -3500 => array("There is no data for\nthis time period.",0), - -// Report Related -3600 => array("Unknown",0) - -); - - + + * @copyright Copyright © 2006 Peter Adams + * @license http://www.gnu.org/copyleft/gpl.html GPL v2.0 + * @category owa + * @package owa + * @version $Revision$ + * @since owa 1.0.0 + */ + +$_owa_messages = [ + 2000 => ['headline' => 'Success', 'message' => 'An e-mail containing instructions on how to complete the password reset process has been sent to %s'], + 2001 => ['headline' => 'Error', 'message' => 'The e-mail %s was not found in our database. Please check the address and try again.'], + 2002 => ['headline' => 'Login Failed', 'message' => 'Your user name or password did not match.'], + 2003 => ['headline' => 'Error', 'message' => 'Your Account lacks the necessary privileges to access the requested resource.'], + 2004 => ['headline' => 'Error', 'message' => 'You must login to access the requested resource.'], + 2010 => ['headline' => 'Success', 'message' => 'Logout Complete.'], + 2011 => ['headline' => 'Error', 'message' => 'Can\'t find your temporary passkey in the db.'], + + // Options/Configuration related + 2500 => ['headline' => 'Success', 'message' => 'Options Saved.'], + 2501 => ['headline' => 'Success', 'message' => 'The module was activated successfully.'], + 2502 => ['headline' => 'Success', 'message' => 'The module was deactivated successfully.'], + 2503 => ['headline' => 'Success', 'message' => 'Options reset to Default Values.'], + 2504 => ['headline' => 'Success', 'message' => 'Entity %s Schema Created.'], + 2504 => ['headline' => 'Success', 'message' => 'Goal Saved.'], + + + //User managment + 3000 => ['headline' => 'Success', 'message' => 'User Added.',], + 3001 => ['headline' => 'Error', 'message' => 'That user name is already taken.'], + 3002 => ['headline' => 'Error', 'message' => 'The form data that you entered contained one or more errors. Please check the data and submit the from again.'], + 3003 => ['headline' => 'Success', 'message' => 'User profile saved.'], + 3004 => ['headline' => 'Success', 'message' => 'User acount deleted.'], + 3005 => ['message' => 'Enter Your New Password',], + 3006 => ['headline' => 'Success', 'message' => 'Please login with your new password.'], + 3007 => ['headline' => 'Error', 'message' => 'Your passwords must match.'], + 3008 => ['headline' => 'Error', 'message' => 'Your password must be %s characters long.',], + 3009 => ['headline' => 'Error', 'message' => 'A user with that email address already exists.',], + 3010 => ['headline' => 'Error', 'message' => 'A user with that email address does not exist.',], + 3011 => ['headline' => 'Error', 'message' => 'Could not update user profile.'], + 3012 => ['headline' => 'Error', 'message' => 'Could not connect the database. Check your settings and try again.'], + + //sites management + 3200 => ['headline' => 'Error', 'message' => 'Please fill in all required fields.'], + 3201 => ['headline' => 'Success', 'message' => 'Site Profile Updated.'], + 3202 => ['headline' => 'Success', 'message' => 'Site Added.'], + 3203 => ['headline' => 'Error', 'message' => 'Site Could not be added'], + 3204 => ['headline' => 'Success', 'message' => 'Site Deleted.'], + 3206 => ['headline' => 'Error', 'message' => 'A site with that domain already exists.'], + 3207 => ['headline' => 'Error', 'message' => 'You must enter a domain when adding a web site.'], + 3208 => ['headline' => 'Error', 'message' => 'That site does not exist.'], + 3208 => ['headline' => 'Error', 'message' => 'Please remove the http:// from your beginning of your domain.'], + + + //install + 3300 => ['headline' => 'Error', 'message' => 'Could not connect to the database. Please check the database connection settings in your configuration file and try again.'], + 3301 => ['headline' => 'Error', 'message' => 'This version of OWA requires PHP 5.2.x or higher.'], + 3302 => ['headline' => 'Error', 'message' => 'Database Schema Installation failed. Please check the error log file for more details.'], + 3303 => ['headline' => 'Success', 'message' => 'Default Site Added.'], + 3304 => ['headline' => 'Success', 'message' => 'Admin User Added.'], + 3305 => ['headline' => 'Success', 'message' => 'Base Database Schema Installed.'], + 3306 => ['headline' => 'Error', 'message' => 'User id already exists for some reason.'], + 3307 => ['headline' => 'Error', 'message' => 'Updates failed. Check OWA\'s error log file for more details and try again.'], + 3308 => ['headline' => 'Success', 'message' => 'Updates were applied.'], + 3309 => ['headline' => 'Error', 'message' => 'Site Domain is required.'], + 3310 => ['headline' => 'Error', 'message' => 'E-mail Address is required.'], + 3310 => ['headline' => 'Error', 'message' => 'Password is required.'], + 3311 => ['headline' => 'Error', 'message' => 'These updates must be applied using the command line interface (CLI). Run \'/path/to/php cli.php cmd=update\' from your server\'s command shell to apply these updates. For more information on updating see the install/update page on the wiki.'], + + // Graph related + 3500 => ['headline' => 'Error', 'message' => 'There is no data for\nthis time period.'], + + // Report Related + 3600 => ['headline' => 'Error', 'message' => 'Unknown'], +]; + + ?> \ No newline at end of file diff --git a/modules/base/classes/installController.php b/modules/base/classes/installController.php index c7182a1e1..4056380fc 100644 --- a/modules/base/classes/installController.php +++ b/modules/base/classes/installController.php @@ -94,7 +94,7 @@ function createAdminUser($user_id, $email_address, $password = '') { return $password; } else { - owa_coreAPI::debug($this->getMsg(3306)); + owa_coreAPI::debug($this->getMsgAsString(3306)); } } else { owa_coreAPI::debug("Admin user already exists."); diff --git a/modules/base/classes/installManager.php b/modules/base/classes/installManager.php index 287fe077c..3fa1ac6bb 100644 --- a/modules/base/classes/installManager.php +++ b/modules/base/classes/installManager.php @@ -73,7 +73,7 @@ function createAdminUser($user_id, $email_address, $password = '') { return $password; } else { - owa_coreAPI::debug($this->getMsg(3306)); + owa_coreAPI::debug($this->getMsgAsString(3306)); } } else { owa_coreAPI::debug("Admin user already exists."); diff --git a/modules/base/classes/sanitize.php b/modules/base/classes/sanitize.php index 1b396a547..df6a0e746 100644 --- a/modules/base/classes/sanitize.php +++ b/modules/base/classes/sanitize.php @@ -82,7 +82,10 @@ public static function escapeForDisplay($string, $encoding = 'UTF-8', $quotes = //use mode to ocnvert both single and double quotes. $quotes = ENT_QUOTES; } - + + // revert special chars, some values are saved encoded in the database eg. page title + $string = html_entity_decode($string, $quotes); + return htmlentities($string, $quotes, $encoding); } diff --git a/modules/base/installCheckEnv.php b/modules/base/installCheckEnv.php index 2c2c7bbcc..5b52747e1 100644 --- a/modules/base/installCheckEnv.php +++ b/modules/base/installCheckEnv.php @@ -1,152 +1,152 @@ - - * @copyright Copyright © 2006 Peter Adams - * @license http://www.gnu.org/copyleft/gpl.html GPL v2.0 - * @category owa - * @package owa - * @version $Revision$ - * @since owa 1.0.0 - */ - -class owa_installCheckEnvController extends owa_installController { - - function __construct($params) { - - return parent::__construct($params); - } - - function action() { - - $errors = array(); - $bad_environment = false; - $config_file_present = false; - - // check PHP version - $version = explode( '.', phpversion() ); - - if ( $version[0] < 5 && $version[1] < 2 ) { - $errors['php_version']['name'] = 'PHP Version'; - $errors['php_version']['value'] = phpversion(); - $errors['php_version']['msg'] = $this->getMsg(3301); - $bad_environment = true; - } - - // Check permissions on log directory - if ( ! is_writable( OWA_DATA_DIR . 'logs/' ) ) { - - $errors['owa_logdir_permissions']['name'] = 'Log Directory Permissions'; - $errors['owa_logdir_permissions']['value'] = 'Not writable'; - $errors['owa_logdir_permissions']['msg'] = 'Check filesystem permissions for '. OWA_DATA_DIR . 'logs/ ' . ' to ensure it is writable.'; - $bad_environment = true; - } - - // Check permissions on caches directory - if ( ! is_writable( OWA_DATA_DIR . 'caches/' ) ) { - - $errors['owa_caches_permissions']['name'] = 'Caches Directory Permissions'; - $errors['owa_caches_permissions']['value'] = 'Not writable'; - $errors['owa_caches_permissions']['msg'] = 'Check filesystem permissions for '. OWA_DATA_DIR . 'caches/ ' . ' to ensure it is writable.'; - $bad_environment = true; - } - - // check for magic_quotes - if ( function_exists( 'get_magic_quotes_gpc' ) ) { - - $magic_quotes = get_magic_quotes_gpc(); - - if ( $magic_quotes ) { - - $errors['magic_quotes_gpc']['name'] = 'magic_quotes_gpc'; - $errors['magic_quotes_gpc']['value'] = $magic_quotes; - $errors['magic_quotes_gpc']['msg'] = "The magic_quotes_gpc PHP INI directive must be set to 'OFF' in order for OWA domstreams to operate correctly."; - $bad_environment = true; - - } - } - - // Check for config file and then test the db connection - if ($this->c->isConfigFilePresent()) { - $config_file_present = true; - $conn = $this->checkDbConnection(); - if ($conn != true) { - $errors['db']['name'] = 'Database Connection'; - $errors['db']['value'] = 'Connection failed'; - $errors['db']['msg'] = 'Check the connection settings in your configuration file.' ; - $bad_environment = true; - } - } - - // if the environment is good - if ($bad_environment != true) { - // and the config file is present - if ($config_file_present === true) { - //skip to defaults entry step - $this->setRedirectAction('base.installDefaultsEntry'); - return; - } else { - // otherwise show config file entry form - $this->setView('base.install'); - // Todo: prepopulate public URL. - //$config = array('public_url', $url); - //$this->set('config', $config); - $this->setSubview('base.installConfigEntry'); - return; - } - // if the environment is bad, then show environment error details. - } else { - $this->set('errors', $errors); - $this->setView('base.install'); - $this->setSubview('base.installCheckEnv'); - } - } -} - -/** - * Installer Server Environment Setup Check View - * - * @author Peter Adams - * @copyright Copyright © 2006 Peter Adams - * @license http://www.gnu.org/copyleft/gpl.html GPL v2.0 - * @category owa - * @package owa - * @version $Revision$ - * @since owa 1.0.0 - */ - -class owa_installCheckEnvView extends owa_view { - - function render($data) { - - //page title - $this->t->set('page_title', 'Server Environment Check'); - $this->body->set('errors', $this->get('errors')); - // load body template - $this->body->set_template('install_check_env.tpl'); - $this->setJs("owa", "base/js/owa.js"); - } -} - + + * @copyright Copyright © 2006 Peter Adams + * @license http://www.gnu.org/copyleft/gpl.html GPL v2.0 + * @category owa + * @package owa + * @version $Revision$ + * @since owa 1.0.0 + */ + +class owa_installCheckEnvController extends owa_installController { + + function __construct($params) { + + return parent::__construct($params); + } + + function action() { + + $errors = array(); + $bad_environment = false; + $config_file_present = false; + + // check PHP version + $version = explode( '.', phpversion() ); + + if ( $version[0] < 5 && $version[1] < 2 ) { + $errors['php_version']['name'] = 'PHP Version'; + $errors['php_version']['value'] = phpversion(); + $errors['php_version']['msg'] = $this->getMsgAsString(3301); + $bad_environment = true; + } + + // Check permissions on log directory + if ( ! is_writable( OWA_DATA_DIR . 'logs/' ) ) { + + $errors['owa_logdir_permissions']['name'] = 'Log Directory Permissions'; + $errors['owa_logdir_permissions']['value'] = 'Not writable'; + $errors['owa_logdir_permissions']['msg'] = 'Check filesystem permissions for '. OWA_DATA_DIR . 'logs/ ' . ' to ensure it is writable.'; + $bad_environment = true; + } + + // Check permissions on caches directory + if ( ! is_writable( OWA_DATA_DIR . 'caches/' ) ) { + + $errors['owa_caches_permissions']['name'] = 'Caches Directory Permissions'; + $errors['owa_caches_permissions']['value'] = 'Not writable'; + $errors['owa_caches_permissions']['msg'] = 'Check filesystem permissions for '. OWA_DATA_DIR . 'caches/ ' . ' to ensure it is writable.'; + $bad_environment = true; + } + + // check for magic_quotes + if ( function_exists( 'get_magic_quotes_gpc' ) ) { + + $magic_quotes = get_magic_quotes_gpc(); + + if ( $magic_quotes ) { + + $errors['magic_quotes_gpc']['name'] = 'magic_quotes_gpc'; + $errors['magic_quotes_gpc']['value'] = $magic_quotes; + $errors['magic_quotes_gpc']['msg'] = "The magic_quotes_gpc PHP INI directive must be set to 'OFF' in order for OWA domstreams to operate correctly."; + $bad_environment = true; + + } + } + + // Check for config file and then test the db connection + if ($this->c->isConfigFilePresent()) { + $config_file_present = true; + $conn = $this->checkDbConnection(); + if ($conn != true) { + $errors['db']['name'] = 'Database Connection'; + $errors['db']['value'] = 'Connection failed'; + $errors['db']['msg'] = 'Check the connection settings in your configuration file.' ; + $bad_environment = true; + } + } + + // if the environment is good + if ($bad_environment != true) { + // and the config file is present + if ($config_file_present === true) { + //skip to defaults entry step + $this->setRedirectAction('base.installDefaultsEntry'); + return; + } else { + // otherwise show config file entry form + $this->setView('base.install'); + // Todo: prepopulate public URL. + //$config = array('public_url', $url); + //$this->set('config', $config); + $this->setSubview('base.installConfigEntry'); + return; + } + // if the environment is bad, then show environment error details. + } else { + $this->set('errors', $errors); + $this->setView('base.install'); + $this->setSubview('base.installCheckEnv'); + } + } +} + +/** + * Installer Server Environment Setup Check View + * + * @author Peter Adams + * @copyright Copyright © 2006 Peter Adams + * @license http://www.gnu.org/copyleft/gpl.html GPL v2.0 + * @category owa + * @package owa + * @version $Revision$ + * @since owa 1.0.0 + */ + +class owa_installCheckEnvView extends owa_view { + + function render($data) { + + //page title + $this->t->set('page_title', 'Server Environment Check'); + $this->body->set('errors', $this->get('errors')); + // load body template + $this->body->set_template('install_check_env.tpl'); + $this->setJs("owa", "base/js/owa.js"); + } +} + ?> \ No newline at end of file diff --git a/modules/base/passwordResetRequest.php b/modules/base/passwordResetRequest.php index 6c2a264c0..02e0dbe60 100644 --- a/modules/base/passwordResetRequest.php +++ b/modules/base/passwordResetRequest.php @@ -61,14 +61,15 @@ function action() { // return view $this->setView('base.passwordResetForm'); $email_address = trim($this->getParam('email_address')); - $msg = $this->getMsg(2000, $email_address); + $msg = $this->getMsg(2000, ['message' => $email_address]); $this->set('status_msg', $msg); } - + function errorAction() { - + $this->setView('base.passwordResetForm'); - $this->set('error_msg', $this->getMsg(2001, $this->getParam('email_address'))); + $email_address = trim($this->getParam('email_address')); + $this->set('error_msg', $this->getMsg(2001, ['message' => $email_address])); } } diff --git a/modules/base/templates/apiError.php b/modules/base/templates/apiError.php index d33910e47..a6af7837e 100644 --- a/modules/base/templates/apiError.php +++ b/modules/base/templates/apiError.php @@ -1 +1,2 @@ -out($error_msg);?> \ No newline at end of file +out( $error_msg['headline'] ); endif; ?> +out( $error_msg['message'] ); endif; ?> \ No newline at end of file diff --git a/modules/base/templates/error_validation_summary.tpl b/modules/base/templates/error_validation_summary.tpl deleted file mode 100644 index 70447b516..000000000 --- a/modules/base/templates/error_validation_summary.tpl +++ /dev/null @@ -1,6 +0,0 @@ -The form that you completed had some errors: -
    - $v): ?> -
  • - -
\ No newline at end of file diff --git a/modules/base/templates/msgs.tpl b/modules/base/templates/msgs.tpl index 0115f1160..d1e265217 100644 --- a/modules/base/templates/msgs.tpl +++ b/modules/base/templates/msgs.tpl @@ -1,7 +1,27 @@ -
out( $status_msg );?>
+
+ out( $status_msg['headline'] ); ?>! + out( $status_msg['message'] ); endif; ?> +
- -
out( $error_msg );?>
+ +
+ out( $error_msg['headline'] ); ?>! + out( $error_msg['message'] ); endif; ?> +
+ + + +
+ The form that you completed had some errors: +
    + +
  • + out( $validation_error['headline'] ); ?>! + out( $validation_error['message'] ); endif; ?> +
  • + +
+
\ No newline at end of file diff --git a/modules/base/updates/004.php b/modules/base/updates/004.php index 0c3c35a7e..ef8c80c88 100644 --- a/modules/base/updates/004.php +++ b/modules/base/updates/004.php @@ -87,8 +87,8 @@ function createAdminUser($email_address) { return $password; - } else { - owa_coreAPI::debug($this->getMsg(3306)); + } else { + owa_coreAPI::debug($this->getMsgAsString(3306)); } } else { owa_coreAPI::debug("Admin user already exists."); diff --git a/owa_base.php b/owa_base.php index ab288a115..a51957e90 100644 --- a/owa_base.php +++ b/owa_base.php @@ -1,162 +1,160 @@ - - * @copyright Copyright © 2006 Peter Adams - * @license http://www.gnu.org/copyleft/gpl.html GPL v2.0 - * @category owa - * @package owa - * @version $Revision$ - * @since owa 1.0.0 - */ - -class owa_base { - - /** - * Configuration - * - * @var array - */ - var $config; - - /** - * Error Logger - * - * @var object - */ - var $e; - - /** - * Configuration Entity - * - * @var owa_settings Object global configuration object - */ - var $c; - - /** - * Module that this class belongs to - * - * @var unknown_type - */ - var $module; - - /** - * Request Params - * - * @var array - */ - var $params; - - /** - * Base Constructor - * - * @return owa_base - */ - function __construct() { - owa_coreAPI::profile($this, __FUNCTION__, __LINE__); - $this->e = owa_coreAPI::errorSingleton(); - $this->c = owa_coreAPI::configSingleton(); - $this->config = $this->c->fetch('base'); - } - - /** - * Retrieves string message from mesage file - * - * @param integer $code - * @param string $s1 - * @param string $s2 - * @param string $s3 - * @param string $s4 - * @return string - */ - function getMsg($code, $s1 = null, $s2 = null, $s3 = null, $s4 = null) { - - static $_owa_messages; - - if (empty($_owa_messages)) { - - require_once(OWA_DIR.'conf/messages.php'); - } - - switch ($_owa_messages[$code][1]) { - - case 0: - $msg = $_owa_messages[$code][0]; - break; - case 1: - $msg = sprintf($_owa_messages[$code][0], $s1); - break; - case 2: - $msg = sprintf($_owa_messages[$code][0], $s1, $s2); - break; - case 3: - $msg = sprintf($_owa_messages[$code][0], $s1, $s2, $s3); - break; - case 4: - $msg = sprintf($_owa_messages[$code][0], $s1, $s2, $s3, $s4); - break; - } - - return $msg; - - } - - /** - * Sets object attributes - * - * @param unknown_type $array - */ - function _setObjectValues($array) { - - foreach ($array as $n => $v) { - - $this->$n = $v; - - } - - return; - } - - /** - * Sets array attributes - * - * @param unknown_type $array - */ - function _setArrayValues($array) { - - foreach ($array as $n => $v) { - - $this->params['$n'] = $v; - - } - - return; - } - - function __destruct() { - owa_coreAPI::profile($this, __FUNCTION__, __LINE__); - } - -} - + + * @copyright Copyright © 2006 Peter Adams + * @license http://www.gnu.org/copyleft/gpl.html GPL v2.0 + * @category owa + * @package owa + * @version $Revision$ + * @since owa 1.0.0 + */ + +class owa_base { + + /** + * Configuration + * + * @var array + */ + var $config; + + /** + * Error Logger + * + * @var object + */ + var $e; + + /** + * Configuration Entity + * + * @var owa_settings Object global configuration object + */ + var $c; + + /** + * Module that this class belongs to + * + * @var unknown_type + */ + var $module; + + /** + * Request Params + * + * @var array + */ + var $params; + + /** + * Base Constructor + * + * @return owa_base + */ + function __construct() { + owa_coreAPI::profile($this, __FUNCTION__, __LINE__); + $this->e = owa_coreAPI::errorSingleton(); + $this->c = owa_coreAPI::configSingleton(); + $this->config = $this->c->fetch('base'); + } + + /** + * Retrieves string message from mesage file + * + * @param integer $code + * @param array $substitutions + * @return array + */ + function getMsg($code, $substitutions = []) { + + static $_owa_messages; + + if (empty($_owa_messages)) { + require_once(OWA_DIR.'conf/messages.php'); + } + + $msg = $_owa_messages[$code]; + + if (isset($msg['headline'])) { + $msg['headline'] = vsprintf($msg['headline'], $substitutions['headline']); + } + + if (isset($msg['message'])) { + $msg['message'] = vsprintf($msg['message'], $substitutions['message']); + } + + return $msg; + } + + /** + * @param $code + * @param array $substitutions + * @return string + */ + public function getMsgAsString($code, $substitutions = []) + { + $msg = $this->getMsg($code, $substitutions); + + return implode(' ', array_values($msg)); + } + + /** + * Sets object attributes + * + * @param unknown_type $array + */ + function _setObjectValues($array) { + + foreach ($array as $n => $v) { + + $this->$n = $v; + + } + + return; + } + + /** + * Sets array attributes + * + * @param unknown_type $array + */ + function _setArrayValues($array) { + + foreach ($array as $n => $v) { + + $this->params['$n'] = $v; + + } + + return; + } + + function __destruct() { + owa_coreAPI::profile($this, __FUNCTION__, __LINE__); + } + +} + ?> \ No newline at end of file diff --git a/owa_view.php b/owa_view.php index 320b0e43c..3d4363b91 100644 --- a/owa_view.php +++ b/owa_view.php @@ -1,791 +1,787 @@ - - * @copyright Copyright © 2006 Peter Adams - * @license http://www.gnu.org/copyleft/gpl.html GPL v2.0 - * @category owa - * @package owa - * @version $Revision$ - * @since owa 1.0.0 - */ - -class owa_view extends owa_base { - - /** - * Main view template object - * - * @var object - */ - var $t; - - /** - * Body content template object - * - * @var object - */ - var $body; - - /** - * Sub View object - * - * @var object - */ - var $subview; - - /** - * Rednered subview - * - * @var string - */ - var $subview_rendered; - - /** - * CSS file for main template - * - * @var unknown_type - */ - var $css_file; - - /** - * The priviledge level required to access this view - * @depricated - * @var string - */ - var $priviledge_level; - - /** - * Type of page - * - * @var unknown_type - */ - var $page_type; - - /** - * Request Params - * - * @var unknown_type - */ - var $params; - - /** - * Authorization object - * - * @var object - */ - var $auth; - - var $module; // set by factory. - - var $data; - - var $default_subview; - - var $is_subview; - - var $js = array(); - - var $css = array(); - - var $postProcessView = false; - - var $renderJsInline; - - /** - * Constructor - * - */ - function __construct($params = null) { - - parent::__construct($params); - - $this->t = new owa_template(); - $this->body = new owa_template($this->module); - $this->setTheme(); - $this->setCss("base/css/owa.css"); - } - - /** - * Assembles the view using passed model objects - * - * @param unknown_type $data - * @return unknown - */ - function assembleView($data) { - - $this->e->debug('Assembling view: '.get_class($this)); - - - // set view name in template class. used for navigation. - if (array_key_exists('view', $this->data)) { - $this->body->caller_params['view'] = $this->data['view']; - } - - if (array_key_exists('params', $this->data)): - $this->body->set('params', $this->data['params']); - endif; - - if (array_key_exists('subview', $this->data)): - $this->body->caller_params['subview'] = $this->data['subview']; - endif; - - // Assign status msg - if (array_key_exists('status_msg', $this->data)): - $this->t->set('status_msg', $this->data['status_msg']); - endif; - - // get status msg from code passed on the query string from a redirect. - if (array_key_exists('status_code', $this->data)): - $this->t->set('status_msg', $this->getMsg($this->data['status_code'])); - endif; - - // set error msg directly if passed from constructor - if (array_key_exists('error_msg', $this->data)): - $this->t->set('error_msg', $this->data['error_msg']); - endif; - - // authentication status - if (array_key_exists('auth_status', $this->data)): - $this->t->set('authStatus', $this->data['auth_status']); - endif; - - // get error msg from error code passed on the query string from a redirect. - if (array_key_exists('error_code', $this->data)): - $this->t->set('error_msg', $this->getMsg($this->data['error_code'])); - endif; - - // load subview - if (!empty($this->data['subview']) || !empty($this->default_subview)): - // Load subview - $this->loadSubView($this->data['subview']); - endif; - - // construct main view. This might set some properties of the subview. - if (method_exists($this, 'render')) { - $this->render($this->data); - } else { - // old style - $this->construct($this->data); - } - //array of errors usually used for field validations - if (array_key_exists('validation_errors', $this->data)): - $this->body->set('validation_errors', $this->data['validation_errors']); - endif; - - // pagination - if (array_key_exists('pagination', $this->data)): - $this->body->set('pagination', $this->data['pagination']); - endif; - - //$this->_setLinkState(); - - // assemble subview - if (!empty($this->data['subview'])): - - // set view name in template. used for navigation. - $this->subview->body->caller_params['view'] = $this->data['subview']; - - // Set validation errors - $this->subview->body->set('validation_errors', $this->get('validation_errors')); - - // pagination - if (array_key_exists('pagination', $this->data)): - $this->subview->body->set('pagination', $this->data['pagination']); - endif; - - if (array_key_exists('params', $this->data)): - $this->subview->body->set('params', $this->data['params']); - $this->subview->body->set('do', $this->data['params']['do']); - endif; - - // Load subview - $this->renderSubView($this->data); - - // assign subview to body template - $this->body->set('subview', $this->subview_rendered); - - - endif; - - // assign validation errors - if (!empty($this->data['validation_errors'])) { - $ves = new owa_template('base'); - $ves->set_template('error_validation_summary.tpl'); - $ves->set('validation_errors', $this->data['validation_errors']); - $validation_errors_summary = $ves->fetch(); - $this->t->set('error_msg', $validation_errors_summary); - } - - - // fire post method - $this->post(); - - // assign css and js ellements if the view is not a subview. - // subview css/js have been merged/pulls from subview and assigned here. - if ($this->is_subview != true) { - if (!empty($this->css)) { - $this->t->set('css', $this->css); - } - - if (!empty($this->js)) { - $this->t->set('js', $this->js); - } - } - - //Assign body to main template - $this->t->set('config', $this->config); - - //Assign body to main template - $this->t->set('body', $this->body); - - if ($this->postProcessView === true){ - return $this->postProcess(); - } else { - // Return fully asembled View - return $this->t->fetch(); - } - } - - /** - * Abstract Alternative rendering method reuires the setting of $this->postProcessView to fire - * - */ - function postProcess() { - - return false; - } - - /** - * Post method fired right before view is rendered and returned - * as output - */ - function post() { - - return false; - } - - - /** - * Sets the theme to be used by a view - * - */ - function setTheme() { - - $this->t->set_template($this->config['report_wrapper']); - - return; - } - - /** - * Abstract method for assembling a view - * @depricated - * @param array $data - */ - function construct($data) { - - return; - - } - - /** - * Assembles subview - * - * @param array $data - */ - function loadSubView($subview) { - - if (empty($subview)): - if (!empty($this->default_subview)): - $subview = $this->default_subview; - $this->data['subview'] = $this->default_subview; - else: - return $this->e->debug("No Subview was specified by caller."); - endif; - endif; - - $this->subview = owa_coreAPI::subViewFactory($subview); - //print_r($subview.'///'); - $this->subview->setData($this->data); - } - - /** - * Assembles subview - * - * @param array $data - */ - function renderSubView($data) { - - // Stores subview as string into $this->subview - $this->subview_rendered = $this->subview->assembleSubView($data); - - // pull css and js elements needed by subview - $this->css = array_merge($this->css, $this->subview->css); - $this->js = array_merge($this->js, $this->subview->js); - } - - /** - * Assembles the view using passed model objects - * - * @param unknown_type $data - * @return unknown - */ - function assembleSubView($data) { - - // construct main view. This might set some properties of the subview. - if (method_exists($this, 'render')) { - $this->render($data); - } else { - // old style - $this->construct($data); - } - - $this->t->set_template('wrapper_subview.tpl'); - - //Assign body to main template - $this->t->set('body', $this->body); - - // Return fully asembled View - $page = $this->t->fetch(); - - return $page; - - } - - function setCss($path, $version = null, $deps = array(), $ie_only = false) { - - if ( ! $version ) { - $version = OWA_VERSION; - } - - $uid = $path; - $url = sprintf('%s?version=%s', owa_coreAPI::getSetting('base', 'modules_url').$path, $version); - $this->css[$uid]['url'] = $url; - // build file system path just in case we need to concatenate the JS into a single file. - $fs_path = OWA_MODULES_DIR.$path; - $this->css[$uid]['path'] = $fs_path; - $this->css[$uid]['deps'] = $deps; - $this->css[$uid]['version'] = $version; - $this->css[$uid]['ie_only'] = $ie_only; - } - - function setJs($name, $path, $version ='', $deps = array(), $ie_only = false) { - - if (empty($version)) { - $version = OWA_VERSION; - } - - $uid = $name.$version; - - $url = sprintf('%s?version=%s', owa_coreAPI::getSetting('base', 'modules_url').$path, $version); - $this->js[$uid]['url'] = $url; - - // build file system path just in case we need to concatenate the JS into a single file. - $fs_path = OWA_MODULES_DIR.$path; - $this->js[$uid]['path'] = $fs_path; - $this->js[$uid]['deps'] = $deps; - $this->js[$uid]['version'] = $version; - $this->js[$uid]['ie_only'] = $ie_only; - } - - function concatinateJs() { - - $js_libs = ''; - - foreach ($this->js as $lib) { - - $js_libs .= file_get_contents($lib['path']); - $js_libs .= "\n\n"; - } - - $this->body->set('js_includes', $js_libs); - - return; - - } - - /** - * Sets flag to tell view to render the JS inline as