diff options
author | Alexander Shubin <aleksandrs.subins@zabbix.com> | 2020-07-14 17:55:24 +0300 |
---|---|---|
committer | Alexander Shubin <aleksandrs.subins@zabbix.com> | 2020-07-14 17:55:33 +0300 |
commit | 2676c3fd547c6edf47b5edc15fffaff7c35d0c21 (patch) | |
tree | b8d4dea3d4e7e2dd561089a4a4a965082b79291d | |
parent | 65270afbe022cbdd38733bfbcce40f62dff7c77d (diff) |
..F....... [ZBXNEXT-5965] fixed messages helper
66 files changed, 336 insertions, 369 deletions
diff --git a/ui/app/controllers/CControllerAuthenticationUpdate.php b/ui/app/controllers/CControllerAuthenticationUpdate.php index 58da4065bec..38b24555381 100644 --- a/ui/app/controllers/CControllerAuthenticationUpdate.php +++ b/ui/app/controllers/CControllerAuthenticationUpdate.php @@ -100,7 +100,7 @@ class CControllerAuthenticationUpdate extends CController { || $data['ldap_configured'] == ZBX_AUTH_LDAP_ENABLED); if (!$is_valid) { - CMessages::addError(_s('Incorrect value for field "%1$s": %2$s.', 'authentication_type', + CMessageHelper::setErrorTitle(_s('Incorrect value for field "%1$s": %2$s.', 'authentication_type', _('LDAP is not configured') )); } @@ -131,14 +131,14 @@ class CControllerAuthenticationUpdate extends CController { foreach ($ldap_fields as $field) { if (trim($config[$field]) === '') { - CMessages::addError(_s('Incorrect value for field "%1$s": %2$s.', $field, _('cannot be empty'))); + CMessageHelper::setErrorTitle(_s('Incorrect value for field "%1$s": %2$s.', $field, _('cannot be empty'))); $is_valid = false; break; } } if ($is_valid && ($config['ldap_port'] < ZBX_MIN_PORT_NUMBER || $config['ldap_port'] > ZBX_MAX_PORT_NUMBER)) { - CMessages::addError(_s( + CMessageHelper::setErrorTitle(_s( 'Incorrect value "%1$s" for "%2$s" field: must be between %3$s and %4$s.', $this->getInput('ldap_port'), 'ldap_port', ZBX_MIN_PORT_NUMBER, ZBX_MAX_PORT_NUMBER )); @@ -146,7 +146,7 @@ class CControllerAuthenticationUpdate extends CController { } if ($ldap_status['result'] != CFrontendSetup::CHECK_OK) { - CMessages::addError($ldap_status['error']); + CMessageHelper::setErrorTitle($ldap_status['error']); $is_valid = false; } elseif ($is_valid) { @@ -167,7 +167,7 @@ class CControllerAuthenticationUpdate extends CController { ]); if (!$login) { - CMessages::addError($ldap_validator->getError()); + CMessageHelper::setErrorTitle($ldap_validator->getError()); $is_valid = false; } } @@ -187,7 +187,7 @@ class CControllerAuthenticationUpdate extends CController { foreach ($saml_fields as $field) { if (trim($config[$field]) === '') { - CMessages::addError(_s('Incorrect value for field "%1$s": %2$s.', $field, _('cannot be empty'))); + CMessageHelper::setErrorTitle(_s('Incorrect value for field "%1$s": %2$s.', $field, _('cannot be empty'))); return false; } @@ -222,7 +222,7 @@ class CControllerAuthenticationUpdate extends CController { // Only ZBX_AUTH_LDAP have 'Test' option. if ($this->hasInput('ldap_test')) { - CMessages::addSuccess(_('LDAP login successful')); + CMessageHelper::setSuccessTitle(_('LDAP login successful')); $this->response->setFormData($this->getInputAll()); $this->setResponse($this->response); return; @@ -297,12 +297,12 @@ class CControllerAuthenticationUpdate extends CController { $this->invalidateSessions(); } - CMessages::addSuccess(_('Authentication settings updated')); + CMessageHelper::setSuccessTitle(_('Authentication settings updated')); add_audit(AUDIT_ACTION_UPDATE, AUDIT_RESOURCE_ZABBIX_CONFIG, _('Authentication method changed')); } else { $this->response->setFormData($this->getInputAll()); - CMessages::addError(_('Cannot update authentication')); + CMessageHelper::setErrorTitle(_('Cannot update authentication')); } } diff --git a/ui/app/controllers/CControllerAutoregUpdate.php b/ui/app/controllers/CControllerAutoregUpdate.php index 5017cc0d945..26dcfd5360b 100644 --- a/ui/app/controllers/CControllerAutoregUpdate.php +++ b/ui/app/controllers/CControllerAutoregUpdate.php @@ -38,7 +38,7 @@ class CControllerAutoregUpdate extends CController { ->getUrl() ); $response->setFormData($this->getInputAll()); - CMessages::addError(_('Cannot update configuration')); + CMessageHelper::setErrorTitle(_('Cannot update configuration')); $this->setResponse($response); break; case self::VALIDATION_FATAL_ERROR: @@ -66,11 +66,11 @@ class CControllerAutoregUpdate extends CController { ); if ($result) { - CMessages::addSuccess(_('Configuration updated')); + CMessageHelper::setSuccessTitle(_('Configuration updated')); } else { $response->setFormData($this->getInputAll()); - CMessages::addError(_('Cannot update configuration')); + CMessageHelper::setErrorTitle(_('Cannot update configuration')); } $this->setResponse($response); diff --git a/ui/app/controllers/CControllerDashboardDelete.php b/ui/app/controllers/CControllerDashboardDelete.php index ed735f6f0a5..814ca314cd9 100644 --- a/ui/app/controllers/CControllerDashboardDelete.php +++ b/ui/app/controllers/CControllerDashboardDelete.php @@ -56,10 +56,10 @@ class CControllerDashboardDelete extends CController { if ($result) { $response->setFormData(['uncheck' => '1']); - CMessages::addSuccess(_n('Dashboard deleted', 'Dashboards deleted', $deleted)); + CMessageHelper::setSuccessTitle(_n('Dashboard deleted', 'Dashboards deleted', $deleted)); } else { - CMessages::addError(_n('Cannot delete dashboard', 'Cannot delete dashboards', $deleted)); + CMessageHelper::setErrorTitle(_n('Cannot delete dashboard', 'Cannot delete dashboards', $deleted)); } $this->setResponse($response); diff --git a/ui/app/controllers/CControllerExportXml.php b/ui/app/controllers/CControllerExportXml.php index 090b19efe73..4c216c455f8 100644 --- a/ui/app/controllers/CControllerExportXml.php +++ b/ui/app/controllers/CControllerExportXml.php @@ -106,7 +106,7 @@ class CControllerExportXml extends CController { $response = new CControllerResponseRedirect( $this->getInput('backurl', 'zabbix.php?action=dashboard.view')); - CMessages::addError(_('No permissions to referred object or it does not exist!')); + CMessageHelper::setErrorTitle(_('No permissions to referred object or it does not exist!')); } else { $response = new CControllerResponseData([ diff --git a/ui/app/controllers/CControllerGuiUpdate.php b/ui/app/controllers/CControllerGuiUpdate.php index 5f7f32b55c9..6660c6791a3 100644 --- a/ui/app/controllers/CControllerGuiUpdate.php +++ b/ui/app/controllers/CControllerGuiUpdate.php @@ -40,7 +40,7 @@ class CControllerGuiUpdate extends CController { ->getUrl() ); $response->setFormData($this->getInputAll()); - CMessages::addError(_('Cannot update configuration')); + CMessageHelper::setErrorTitle(_('Cannot update configuration')); $this->setResponse($response); break; @@ -73,11 +73,11 @@ class CControllerGuiUpdate extends CController { ); if ($result) { - CMessages::addSuccess(_('Configuration updated')); + CMessageHelper::setSuccessTitle(_('Configuration updated')); } else { $response->setFormData($this->getInputAll()); - CMessages::addError(_('Cannot update configuration')); + CMessageHelper::setErrorTitle(_('Cannot update configuration')); } $this->setResponse($response); diff --git a/ui/app/controllers/CControllerHousekeepingUpdate.php b/ui/app/controllers/CControllerHousekeepingUpdate.php index ff88188c7ec..c0feb3d18bb 100644 --- a/ui/app/controllers/CControllerHousekeepingUpdate.php +++ b/ui/app/controllers/CControllerHousekeepingUpdate.php @@ -54,7 +54,7 @@ class CControllerHousekeepingUpdate extends CController { ->getUrl() ); $response->setFormData($this->getInputAll()); - CMessages::addError(_('Cannot update configuration')); + CMessageHelper::setErrorTitle(_('Cannot update configuration')); $this->setResponse($response); break; case self::VALIDATION_FATAL_ERROR: @@ -119,11 +119,11 @@ class CControllerHousekeepingUpdate extends CController { ); if ($result) { - CMessages::addSuccess(_('Configuration updated')); + CMessageHelper::setSuccessTitle(_('Configuration updated')); } else { $response->setFormData($this->getInputAll()); - CMessages::addError(_('Cannot update configuration')); + CMessageHelper::setErrorTitle(_('Cannot update configuration')); } $this->setResponse($response); diff --git a/ui/app/controllers/CControllerIconMapCreate.php b/ui/app/controllers/CControllerIconMapCreate.php index 516d01fabec..c1edba2e0b5 100644 --- a/ui/app/controllers/CControllerIconMapCreate.php +++ b/ui/app/controllers/CControllerIconMapCreate.php @@ -46,14 +46,14 @@ class CControllerIconMapCreate extends CController { $response = new CControllerResponseRedirect((new CUrl('zabbix.php')) ->setArgument('action', 'iconmap.list') ); - CMessages::addSuccess(_('Icon map created')); + CMessageHelper::setSuccessTitle(_('Icon map created')); } else { $response = new CControllerResponseRedirect((new CUrl('zabbix.php')) ->setArgument('action', 'iconmap.edit') ); $response->setFormData($this->getInputAll()); - CMessages::addError(_('Cannot create icon map')); + CMessageHelper::setErrorTitle(_('Cannot create icon map')); } $this->setResponse($response); diff --git a/ui/app/controllers/CControllerIconMapDelete.php b/ui/app/controllers/CControllerIconMapDelete.php index e9202cd81c2..e8f3c587b78 100644 --- a/ui/app/controllers/CControllerIconMapDelete.php +++ b/ui/app/controllers/CControllerIconMapDelete.php @@ -58,14 +58,14 @@ class CControllerIconMapDelete extends CController { $response = new CControllerResponseRedirect((new CUrl('zabbix.php')) ->setArgument('action', 'iconmap.list') ); - CMessages::addSuccess(_('Icon map deleted')); + CMessageHelper::setSuccessTitle(_('Icon map deleted')); } else { $response = new CControllerResponseRedirect((new CUrl('zabbix.php')) ->setArgument('action', 'iconmap.edit') ->setArgument('iconmapid', $this->getInput('iconmapid')) ); - CMessages::addError(_('Cannot delete icon map')); + CMessageHelper::setErrorTitle(_('Cannot delete icon map')); } $this->setResponse($response); diff --git a/ui/app/controllers/CControllerIconMapUpdate.php b/ui/app/controllers/CControllerIconMapUpdate.php index d780092fa02..4226f5af238 100644 --- a/ui/app/controllers/CControllerIconMapUpdate.php +++ b/ui/app/controllers/CControllerIconMapUpdate.php @@ -62,7 +62,7 @@ class CControllerIconMapUpdate extends CController { $response = new CControllerResponseRedirect((new CUrl('zabbix.php')) ->setArgument('action', 'iconmap.list') ); - CMessages::addSuccess(_('Icon map updated')); + CMessageHelper::setSuccessTitle(_('Icon map updated')); } else { $response = new CControllerResponseRedirect((new CUrl('zabbix.php')) @@ -74,7 +74,7 @@ class CControllerIconMapUpdate extends CController { $form_data['iconmap']['mappings'] = []; } $response->setFormData($form_data); - CMessages::addError(_('Cannot update icon map')); + CMessageHelper::setErrorTitle(_('Cannot update icon map')); } $this->setResponse($response); diff --git a/ui/app/controllers/CControllerImageCreate.php b/ui/app/controllers/CControllerImageCreate.php index 9b15a9f4e62..a4126af5592 100644 --- a/ui/app/controllers/CControllerImageCreate.php +++ b/ui/app/controllers/CControllerImageCreate.php @@ -38,7 +38,7 @@ class CControllerImageCreate extends CController { $response = new CControllerResponseRedirect($url); $response->setFormData($this->getInputAll()); - CMessages::addError(_('Cannot add image')); + CMessageHelper::setErrorTitle(_('Cannot add image')); $this->setResponse($response); break; @@ -104,7 +104,7 @@ class CControllerImageCreate extends CController { $response = new CControllerResponseRedirect($url); error($error); $response->setFormData($this->getInputAll()); - CMessages::addError(_('Cannot add image')); + CMessageHelper::setErrorTitle(_('Cannot add image')); return $this->setResponse($response); } @@ -122,7 +122,7 @@ class CControllerImageCreate extends CController { ->setArgument('action', 'image.list') ->setArgument('imagetype', $this->getInput('imagetype')) ); - CMessages::addSuccess(_('Image added')); + CMessageHelper::setSuccessTitle(_('Image added')); } else { $response = new CControllerResponseRedirect((new CUrl('zabbix.php')) @@ -130,7 +130,7 @@ class CControllerImageCreate extends CController { ->setArgument('imagetype', $this->getInput('imagetype')) ); $response->setFormData($this->getInputAll()); - CMessages::addError(_('Cannot add image')); + CMessageHelper::setErrorTitle(_('Cannot add image')); } $this->setResponse($response); diff --git a/ui/app/controllers/CControllerImageDelete.php b/ui/app/controllers/CControllerImageDelete.php index 93dfc023356..0d7cc4a2428 100644 --- a/ui/app/controllers/CControllerImageDelete.php +++ b/ui/app/controllers/CControllerImageDelete.php @@ -64,14 +64,14 @@ class CControllerImageDelete extends CController { ->setArgument('action', 'image.list') ->setArgument('imagetype', $this->getInput('imagetype')) ); - CMessages::addSuccess(_('Image deleted')); + CMessageHelper::setSuccessTitle(_('Image deleted')); } else { $response = new CControllerResponseRedirect((new CUrl('zabbix.php')) ->setArgument('action', 'image.edit') ->setArgument('imageid', $this->getInput('imageid')) ); - CMessages::addError(_('Cannot delete image')); + CMessageHelper::setErrorTitle(_('Cannot delete image')); } $this->setResponse($response); diff --git a/ui/app/controllers/CControllerImageUpdate.php b/ui/app/controllers/CControllerImageUpdate.php index 59b60719cb4..5dd59dc3a64 100644 --- a/ui/app/controllers/CControllerImageUpdate.php +++ b/ui/app/controllers/CControllerImageUpdate.php @@ -40,7 +40,7 @@ class CControllerImageUpdate extends CController { $response = new CControllerResponseRedirect($url); $response->setFormData($this->getInputAll()); - CMessages::addError(_('Cannot update image')); + CMessageHelper::setErrorTitle(_('Cannot update image')); $this->setResponse($response); break; @@ -107,7 +107,7 @@ class CControllerImageUpdate extends CController { ); error($error); $response->setFormData($this->getInputAll()); - CMessages::addError(_('Cannot update image')); + CMessageHelper::setErrorTitle(_('Cannot update image')); return $this->setResponse($response); } @@ -134,7 +134,7 @@ class CControllerImageUpdate extends CController { ->setArgument('action', 'image.list') ->setArgument('imagetype', $this->getInput('imagetype')) ); - CMessages::addSuccess(_('Image updated')); + CMessageHelper::setSuccessTitle(_('Image updated')); } else { $response = new CControllerResponseRedirect((new CUrl('zabbix.php')) @@ -143,7 +143,7 @@ class CControllerImageUpdate extends CController { ->setArgument('imageid', $this->getInput('imageid')) ); $response->setFormData($this->getInputAll()); - CMessages::addError(_('Cannot update image')); + CMessageHelper::setErrorTitle(_('Cannot update image')); } $this->setResponse($response); diff --git a/ui/app/controllers/CControllerMacrosUpdate.php b/ui/app/controllers/CControllerMacrosUpdate.php index c3f6a28bf13..32b473a7107 100644 --- a/ui/app/controllers/CControllerMacrosUpdate.php +++ b/ui/app/controllers/CControllerMacrosUpdate.php @@ -107,10 +107,10 @@ class CControllerMacrosUpdate extends CController { $response = new CControllerResponseRedirect((new CUrl('zabbix.php'))->setArgument('action', 'macros.edit')); if ($result) { - CMessages::addSuccess(_('Macros updated')); + CMessageHelper::setSuccessTitle(_('Macros updated')); } else { - CMessages::addError(_('Cannot update macros')); + CMessageHelper::setErrorTitle(_('Cannot update macros')); $form_data = $this->getInputAll(); $form_data['macros'] = array_values($form_data['macros']); $response->setFormData($form_data); diff --git a/ui/app/controllers/CControllerMediatypeCreate.php b/ui/app/controllers/CControllerMediatypeCreate.php index 9d4c8cd9e9f..f97527be55a 100644 --- a/ui/app/controllers/CControllerMediatypeCreate.php +++ b/ui/app/controllers/CControllerMediatypeCreate.php @@ -73,7 +73,7 @@ class CControllerMediatypeCreate extends CController { case self::VALIDATION_ERROR: $response = new CControllerResponseRedirect('zabbix.php?action=mediatype.edit'); $response->setFormData($this->getInputAll()); - CMessages::addError(_('Cannot add media type')); + CMessageHelper::setErrorTitle(_('Cannot add media type')); $this->setResponse($response); break; @@ -155,14 +155,14 @@ class CControllerMediatypeCreate extends CController { ->setArgument('page', CPagerHelper::loadPage('mediatype.list', null)) ); $response->setFormData(['uncheck' => '1']); - CMessages::addSuccess(_('Media type added')); + CMessageHelper::setSuccessTitle(_('Media type added')); } else { $response = new CControllerResponseRedirect( (new CUrl('zabbix.php'))->setArgument('action', 'mediatype.edit') ); $response->setFormData($this->getInputAll()); - CMessages::addError(_('Cannot add media type')); + CMessageHelper::setErrorTitle(_('Cannot add media type')); } $this->setResponse($response); } diff --git a/ui/app/controllers/CControllerMediatypeDelete.php b/ui/app/controllers/CControllerMediatypeDelete.php index f6dc8e6fc1a..d6bf54e3a85 100644 --- a/ui/app/controllers/CControllerMediatypeDelete.php +++ b/ui/app/controllers/CControllerMediatypeDelete.php @@ -63,10 +63,10 @@ class CControllerMediatypeDelete extends CController { if ($result) { $response->setFormData(['uncheck' => '1']); - CMessages::addSuccess(_n('Media type deleted', 'Media types deleted', $deleted)); + CMessageHelper::setSuccessTitle(_n('Media type deleted', 'Media types deleted', $deleted)); } else { - CMessages::addError(_n('Cannot delete media type', 'Cannot delete media types', $deleted)); + CMessageHelper::setErrorTitle(_n('Cannot delete media type', 'Cannot delete media types', $deleted)); } $this->setResponse($response); } diff --git a/ui/app/controllers/CControllerMediatypeDisable.php b/ui/app/controllers/CControllerMediatypeDisable.php index 41ee77277de..fe9410970e3 100644 --- a/ui/app/controllers/CControllerMediatypeDisable.php +++ b/ui/app/controllers/CControllerMediatypeDisable.php @@ -69,10 +69,10 @@ class CControllerMediatypeDisable extends CController { if ($result) { $response->setFormData(['uncheck' => '1']); - CMessages::addSuccess(_n('Media type disabled', 'Media types disabled', $updated)); + CMessageHelper::setSuccessTitle(_n('Media type disabled', 'Media types disabled', $updated)); } else { - CMessages::addError(_n('Cannot disable media type', 'Cannot disable media types', $updated)); + CMessageHelper::setErrorTitle(_n('Cannot disable media type', 'Cannot disable media types', $updated)); } $this->setResponse($response); } diff --git a/ui/app/controllers/CControllerMediatypeEnable.php b/ui/app/controllers/CControllerMediatypeEnable.php index 23f482d662e..2ee3849de89 100644 --- a/ui/app/controllers/CControllerMediatypeEnable.php +++ b/ui/app/controllers/CControllerMediatypeEnable.php @@ -69,10 +69,10 @@ class CControllerMediatypeEnable extends CController { if ($result) { $response->setFormData(['uncheck' => '1']); - CMessages::addSuccess(_n('Media type enabled', 'Media types enabled', $updated)); + CMessageHelper::setSuccessTitle(_n('Media type enabled', 'Media types enabled', $updated)); } else { - CMessages::addError(_n('Cannot enable media type', 'Cannot enable media types', $updated)); + CMessageHelper::setErrorTitle(_n('Cannot enable media type', 'Cannot enable media types', $updated)); } $this->setResponse($response); } diff --git a/ui/app/controllers/CControllerMediatypeUpdate.php b/ui/app/controllers/CControllerMediatypeUpdate.php index 21854d16885..373a1525ea7 100644 --- a/ui/app/controllers/CControllerMediatypeUpdate.php +++ b/ui/app/controllers/CControllerMediatypeUpdate.php @@ -74,7 +74,7 @@ class CControllerMediatypeUpdate extends CController { case self::VALIDATION_ERROR: $response = new CControllerResponseRedirect('zabbix.php?action=mediatype.edit'); $response->setFormData($this->getInputAll()); - CMessages::addError(_('Cannot update media type')); + CMessageHelper::setErrorTitle(_('Cannot update media type')); $this->setResponse($response); break; @@ -170,14 +170,14 @@ class CControllerMediatypeUpdate extends CController { ->setArgument('page', CPagerHelper::loadPage('mediatype.list', null)) ); $response->setFormData(['uncheck' => '1']); - CMessages::addSuccess(_('Media type updated')); + CMessageHelper::setSuccessTitle(_('Media type updated')); } else { $response = new CControllerResponseRedirect((new CUrl('zabbix.php')) ->setArgument('action', 'mediatype.edit') ); $response->setFormData($this->getInputAll()); - CMessages::addError(_('Cannot update media type')); + CMessageHelper::setErrorTitle(_('Cannot update media type')); } $this->setResponse($response); } diff --git a/ui/app/controllers/CControllerMiscConfigUpdate.php b/ui/app/controllers/CControllerMiscConfigUpdate.php index 491e9f91931..8cff9ceef4a 100644 --- a/ui/app/controllers/CControllerMiscConfigUpdate.php +++ b/ui/app/controllers/CControllerMiscConfigUpdate.php @@ -40,7 +40,7 @@ class CControllerMiscConfigUpdate extends CController { ); $response->setFormData($this->getInputAll()); - CMessages::addError(_('Cannot update configuration')); + CMessageHelper::setErrorTitle(_('Cannot update configuration')); $this->setResponse($response); break; @@ -74,10 +74,10 @@ class CControllerMiscConfigUpdate extends CController { $result = DBend($result); if ($result) { - CMessages::addSuccess(_('Configuration updated')); + CMessageHelper::setSuccessTitle(_('Configuration updated')); } else { - CMessages::addError(_('Cannot update configuration')); + CMessageHelper::setErrorTitle(_('Cannot update configuration')); $response->setFormData($this->getInputAll()); } diff --git a/ui/app/controllers/CControllerModuleEdit.php b/ui/app/controllers/CControllerModuleEdit.php index 10ba8cfe9ba..bd71844419a 100644 --- a/ui/app/controllers/CControllerModuleEdit.php +++ b/ui/app/controllers/CControllerModuleEdit.php @@ -103,7 +103,7 @@ class CControllerModuleEdit extends CController { ->setArgument('action', 'module.list') ->setArgument('page', CPagerHelper::loadPage('module.list', null)) ); - CMessages::addError(_s('Cannot load module at: %1$s.', $this->module['relative_path'])); + CMessageHelper::setErrorTitle(_s('Cannot load module at: %1$s.', $this->module['relative_path'])); $this->setResponse($response); } } diff --git a/ui/app/controllers/CControllerModuleScan.php b/ui/app/controllers/CControllerModuleScan.php index 49555be5103..2dc8c3374df 100644 --- a/ui/app/controllers/CControllerModuleScan.php +++ b/ui/app/controllers/CControllerModuleScan.php @@ -37,7 +37,7 @@ class CControllerModuleScan extends CController { } protected function doAction() { - clear_messages(); + get_and_clear_messages(); $db_modules_create = []; $db_modules_create_names = []; @@ -132,10 +132,10 @@ class CControllerModuleScan extends CController { : _('No new modules discovered'); if (hasErrorMesssages()) { - CMessages::addError($message); + CMessageHelper::setErrorTitle($message); } else { - CMessages::addSuccess($message); + CMessageHelper::setSuccessTitle($message); } $this->setResponse($response); diff --git a/ui/app/controllers/CControllerModuleUpdate.php b/ui/app/controllers/CControllerModuleUpdate.php index 21e848f48d1..fbbfc9019d1 100644 --- a/ui/app/controllers/CControllerModuleUpdate.php +++ b/ui/app/controllers/CControllerModuleUpdate.php @@ -139,30 +139,30 @@ class CControllerModuleUpdate extends CController { if ($result) { if ($this->getAction() === 'module.update') { - CMessages::addSuccess(_s('Module updated: %1$s.', $db_modules_update_names[0])); + CMessageHelper::setSuccessTitle(_s('Module updated: %1$s.', $db_modules_update_names[0])); } elseif ($set_status == MODULE_STATUS_ENABLED) { - CMessages::addSuccess(_n('Module enabled: %1$s.', 'Modules enabled: %1$s.', + CMessageHelper::setSuccessTitle(_n('Module enabled: %1$s.', 'Modules enabled: %1$s.', implode(', ', $db_modules_update_names), count($this->modules) )); } else { - CMessages::addSuccess(_n('Module disabled: %1$s.', 'Modules disabled: %1$s.', + CMessageHelper::setSuccessTitle(_n('Module disabled: %1$s.', 'Modules disabled: %1$s.', implode(', ', $db_modules_update_names), count($this->modules) )); } } else { if ($this->getAction() === 'module.update') { - CMessages::addError(_s('Cannot update module: %1$s.', $db_modules_update_names[0])); + CMessageHelper::setErrorTitle(_s('Cannot update module: %1$s.', $db_modules_update_names[0])); } elseif ($set_status == MODULE_STATUS_ENABLED) { - CMessages::addError(_n('Cannot enable module: %1$s.', 'Cannot enable modules: %1$s.', + CMessageHelper::setErrorTitle(_n('Cannot enable module: %1$s.', 'Cannot enable modules: %1$s.', implode(', ', $db_modules_update_names), count($this->modules) )); } else { - CMessages::addError(_n('Cannot disable module: %1$s.', 'Cannot disable modules: %1$s.', + CMessageHelper::setErrorTitle(_n('Cannot disable module: %1$s.', 'Cannot disable modules: %1$s.', implode(', ', $db_modules_update_names), count($this->modules) )); } diff --git a/ui/app/controllers/CControllerProxyCreate.php b/ui/app/controllers/CControllerProxyCreate.php index 8aa11f6513d..d1d6277a2fd 100644 --- a/ui/app/controllers/CControllerProxyCreate.php +++ b/ui/app/controllers/CControllerProxyCreate.php @@ -53,7 +53,7 @@ class CControllerProxyCreate extends CController { case self::VALIDATION_ERROR: $response = new CControllerResponseRedirect('zabbix.php?action=proxy.edit'); $response->setFormData($this->getInputAll()); - CMessages::addError(_('Cannot add proxy')); + CMessageHelper::setErrorTitle(_('Cannot add proxy')); $this->setResponse($response); break; case self::VALIDATION_FATAL_ERROR: @@ -102,14 +102,14 @@ class CControllerProxyCreate extends CController { ->setArgument('page', CPagerHelper::loadPage('proxy.list', null)) ); $response->setFormData(['uncheck' => '1']); - CMessages::addSuccess(_('Proxy added')); + CMessageHelper::setSuccessTitle(_('Proxy added')); } else { $response = new CControllerResponseRedirect((new CUrl('zabbix.php')) ->setArgument('action', 'proxy.edit') ); $response->setFormData($this->getInputAll()); - CMessages::addError(_('Cannot add proxy')); + CMessageHelper::setErrorTitle(_('Cannot add proxy')); } $this->setResponse($response); } diff --git a/ui/app/controllers/CControllerProxyDelete.php b/ui/app/controllers/CControllerProxyDelete.php index 9829caf49c2..778d44e8bf1 100644 --- a/ui/app/controllers/CControllerProxyDelete.php +++ b/ui/app/controllers/CControllerProxyDelete.php @@ -63,10 +63,10 @@ class CControllerProxyDelete extends CController { if ($result) { $response->setFormData(['uncheck' => '1']); - CMessages::addSuccess(_n('Proxy deleted', 'Proxies deleted', $deleted)); + CMessageHelper::setSuccessTitle(_n('Proxy deleted', 'Proxies deleted', $deleted)); } else { - CMessages::addError(_n('Cannot delete proxy', 'Cannot delete proxies', $deleted)); + CMessageHelper::setErrorTitle(_n('Cannot delete proxy', 'Cannot delete proxies', $deleted)); } $this->setResponse($response); } diff --git a/ui/app/controllers/CControllerProxyHostDisable.php b/ui/app/controllers/CControllerProxyHostDisable.php index bc69cecbc6f..902ffb78727 100644 --- a/ui/app/controllers/CControllerProxyHostDisable.php +++ b/ui/app/controllers/CControllerProxyHostDisable.php @@ -74,10 +74,10 @@ class CControllerProxyHostDisable extends CController { if ($result) { $response->setFormData(['uncheck' => '1']); - CMessages::addSuccess(_n('Host disabled', 'Hosts disabled', $updated)); + CMessageHelper::setSuccessTitle(_n('Host disabled', 'Hosts disabled', $updated)); } else { - CMessages::addError(_n('Cannot disable host', 'Cannot disable hosts', $updated)); + CMessageHelper::setErrorTitle(_n('Cannot disable host', 'Cannot disable hosts', $updated)); } $this->setResponse($response); } diff --git a/ui/app/controllers/CControllerProxyHostEnable.php b/ui/app/controllers/CControllerProxyHostEnable.php index fb1f72ca8f4..fd5abf781e2 100644 --- a/ui/app/controllers/CControllerProxyHostEnable.php +++ b/ui/app/controllers/CControllerProxyHostEnable.php @@ -74,10 +74,10 @@ class CControllerProxyHostEnable extends CController { if ($result) { $response->setFormData(['uncheck' => '1']); - CMessages::addSuccess(_n('Host enabled', 'Hosts enabled', $updated)); + CMessageHelper::setSuccessTitle(_n('Host enabled', 'Hosts enabled', $updated)); } else { - CMessages::addError(_n('Cannot enable host', 'Cannot enable hosts', $updated)); + CMessageHelper::setErrorTitle(_n('Cannot enable host', 'Cannot enable hosts', $updated)); } $this->setResponse($response); } diff --git a/ui/app/controllers/CControllerProxyUpdate.php b/ui/app/controllers/CControllerProxyUpdate.php index 3a2ca56e675..6bf16d0622b 100644 --- a/ui/app/controllers/CControllerProxyUpdate.php +++ b/ui/app/controllers/CControllerProxyUpdate.php @@ -55,7 +55,7 @@ class CControllerProxyUpdate extends CController { case self::VALIDATION_ERROR: $response = new CControllerResponseRedirect('zabbix.php?action=proxy.edit'); $response->setFormData($this->getInputAll()); - CMessages::addError(_('Cannot update proxy')); + CMessageHelper::setErrorTitle(_('Cannot update proxy')); $this->setResponse($response); break; case self::VALIDATION_FATAL_ERROR: @@ -112,7 +112,7 @@ class CControllerProxyUpdate extends CController { ->setArgument('page', CPagerHelper::loadPage('proxy.list', null)) ); $response->setFormData(['uncheck' => '1']); - CMessages::addSuccess(_('Proxy updated')); + CMessageHelper::setSuccessTitle(_('Proxy updated')); } else { $response = new CControllerResponseRedirect((new CUrl('zabbix.php')) @@ -120,7 +120,7 @@ class CControllerProxyUpdate extends CController { ->setArgument('proxyid', $this->getInput('proxyid')) ); $response->setFormData($this->getInputAll()); - CMessages::addError(_('Cannot update proxy')); + CMessageHelper::setErrorTitle(_('Cannot update proxy')); } $this->setResponse($response); } diff --git a/ui/app/controllers/CControllerRegExCreate.php b/ui/app/controllers/CControllerRegExCreate.php index 58abfeb52fe..5873932181a 100644 --- a/ui/app/controllers/CControllerRegExCreate.php +++ b/ui/app/controllers/CControllerRegExCreate.php @@ -40,7 +40,7 @@ class CControllerRegExCreate extends CController { $response = new CControllerResponseRedirect($url); $response->setFormData($this->getInputAll()); - CMessages::addError(_('Cannot add regular expression')); + CMessageHelper::setErrorTitle(_('Cannot add regular expression')); $this->setResponse($response); break; @@ -82,12 +82,12 @@ class CControllerRegExCreate extends CController { if ($result) { $response = new CControllerResponseRedirect((new CUrl('zabbix.php'))->setArgument('action', 'regex.list')); - CMessages::addSuccess(_('Regular expression added')); + CMessageHelper::setSuccessTitle(_('Regular expression added')); } else { $response = new CControllerResponseRedirect((new CUrl('zabbix.php'))->setArgument('action', 'regex.edit')); $response->setFormData($this->getInputAll()); - CMessages::addError(_('Cannot add regular expression')); + CMessageHelper::setErrorTitle(_('Cannot add regular expression')); } $this->setResponse($response); diff --git a/ui/app/controllers/CControllerRegExDelete.php b/ui/app/controllers/CControllerRegExDelete.php index b1feb70bed5..3afb6f762f0 100644 --- a/ui/app/controllers/CControllerRegExDelete.php +++ b/ui/app/controllers/CControllerRegExDelete.php @@ -75,12 +75,12 @@ class CControllerRegExDelete extends CController { $response = new CControllerResponseRedirect((new CUrl('zabbix.php'))->setArgument('action', 'regex.list')); if ($result) { $response->setFormData(['uncheck' => '1']); - CMessages::addSuccess(_n('Regular expression deleted', 'Regular expressions deleted', + CMessageHelper::setSuccessTitle(_n('Regular expression deleted', 'Regular expressions deleted', count($this->db_regexes) )); } else { - CMessages::addError(_n('Cannot delete regular expression', 'Cannot delete regular expressions', + CMessageHelper::setErrorTitle(_n('Cannot delete regular expression', 'Cannot delete regular expressions', count($this->db_regexes) )); } diff --git a/ui/app/controllers/CControllerRegExUpdate.php b/ui/app/controllers/CControllerRegExUpdate.php index 6378626bc04..d70ec60784e 100644 --- a/ui/app/controllers/CControllerRegExUpdate.php +++ b/ui/app/controllers/CControllerRegExUpdate.php @@ -42,7 +42,7 @@ class CControllerRegExUpdate extends CController { ->setArgument('regexid', $this->getInput('regexid')) ); $response->setFormData($this->getInputAll()); - CMessages::addError(_('Cannot update regular expression')); + CMessageHelper::setErrorTitle(_('Cannot update regular expression')); $this->setResponse($response); break; @@ -91,14 +91,14 @@ class CControllerRegExUpdate extends CController { if ($result) { $response = new CControllerResponseRedirect((new CUrl('zabbix.php'))->setArgument('action', 'regex.list')); - CMessages::addSuccess(_('Regular expression updated')); + CMessageHelper::setSuccessTitle(_('Regular expression updated')); } else { $response = new CControllerResponseRedirect((new CUrl('zabbix.php')) ->setArgument('action', 'regex.edit') ->setArgument('regexid', $this->getInput('regexid'))); $response->setFormData($this->getInputAll()); - CMessages::addError(_('Cannot update regular expression')); + CMessageHelper::setErrorTitle(_('Cannot update regular expression')); } $this->setResponse($response); diff --git a/ui/app/controllers/CControllerScriptCreate.php b/ui/app/controllers/CControllerScriptCreate.php index f4cf06e2515..569d8930a0d 100644 --- a/ui/app/controllers/CControllerScriptCreate.php +++ b/ui/app/controllers/CControllerScriptCreate.php @@ -44,7 +44,7 @@ class CControllerScriptCreate extends CController { case self::VALIDATION_ERROR: $response = new CControllerResponseRedirect('zabbix.php?action=script.edit'); $response->setFormData($this->getInputAll()); - CMessages::addError(_('Cannot add script')); + CMessageHelper::setErrorTitle(_('Cannot add script')); $this->setResponse($response); break; case self::VALIDATION_FATAL_ERROR: @@ -87,14 +87,14 @@ class CControllerScriptCreate extends CController { ->setArgument('page', CPagerHelper::loadPage('script.list', null)) ); $response->setFormData(['uncheck' => '1']); - CMessages::addSuccess(_('Script added')); + CMessageHelper::setSuccessTitle(_('Script added')); } else { $response = new CControllerResponseRedirect((new CUrl('zabbix.php')) ->setArgument('action', 'script.edit') ); $response->setFormData($this->getInputAll()); - CMessages::addError(_('Cannot add script')); + CMessageHelper::setErrorTitle(_('Cannot add script')); } $this->setResponse($response); } diff --git a/ui/app/controllers/CControllerScriptDelete.php b/ui/app/controllers/CControllerScriptDelete.php index 26e6e4435da..1aba4911497 100644 --- a/ui/app/controllers/CControllerScriptDelete.php +++ b/ui/app/controllers/CControllerScriptDelete.php @@ -63,10 +63,10 @@ class CControllerScriptDelete extends CController { if ($result) { $response->setFormData(['uncheck' => '1']); - CMessages::addSuccess(_n('Script deleted', 'Scripts deleted', $deleted)); + CMessageHelper::setSuccessTitle(_n('Script deleted', 'Scripts deleted', $deleted)); } else { - CMessages::addError(_n('Cannot delete script', 'Cannot delete scripts', $deleted)); + CMessageHelper::setErrorTitle(_n('Cannot delete script', 'Cannot delete scripts', $deleted)); } $this->setResponse($response); diff --git a/ui/app/controllers/CControllerScriptUpdate.php b/ui/app/controllers/CControllerScriptUpdate.php index 6209634f594..7a77b470620 100644 --- a/ui/app/controllers/CControllerScriptUpdate.php +++ b/ui/app/controllers/CControllerScriptUpdate.php @@ -45,7 +45,7 @@ class CControllerScriptUpdate extends CController { case self::VALIDATION_ERROR: $response = new CControllerResponseRedirect('zabbix.php?action=script.edit'); $response->setFormData($this->getInputAll()); - CMessages::addError(_('Cannot update script')); + CMessageHelper::setErrorTitle(_('Cannot update script')); $this->setResponse($response); break; case self::VALIDATION_FATAL_ERROR: @@ -97,7 +97,7 @@ class CControllerScriptUpdate extends CController { ->setArgument('page', CPagerHelper::loadPage('script.list', null)) ); $response->setFormData(['uncheck' => '1']); - CMessages::addSuccess(_('Script updated')); + CMessageHelper::setSuccessTitle(_('Script updated')); } else { $response = new CControllerResponseRedirect((new CUrl('zabbix.php')) @@ -105,7 +105,7 @@ class CControllerScriptUpdate extends CController { ->setArgument('scriptid', $this->getInput('scriptid')) ); $response->setFormData($this->getInputAll()); - CMessages::addError(_('Cannot update script')); + CMessageHelper::setErrorTitle(_('Cannot update script')); } $this->setResponse($response); } diff --git a/ui/app/controllers/CControllerSystemWarning.php b/ui/app/controllers/CControllerSystemWarning.php index f19d88d827e..e62531715b8 100644 --- a/ui/app/controllers/CControllerSystemWarning.php +++ b/ui/app/controllers/CControllerSystemWarning.php @@ -39,7 +39,7 @@ class CControllerSystemWarning extends CController { 'messages' => [] ]; - $data['messages'] = CMessages::get(); + $data['messages'] = CMessageHelper::getMessages(); $this->setResponse(new CControllerResponseData($data)); } diff --git a/ui/app/controllers/CControllerTimeSelectorUpdate.php b/ui/app/controllers/CControllerTimeSelectorUpdate.php index 6872a38e0cc..80c5e579395 100644 --- a/ui/app/controllers/CControllerTimeSelectorUpdate.php +++ b/ui/app/controllers/CControllerTimeSelectorUpdate.php @@ -61,7 +61,7 @@ class CControllerTimeSelectorUpdate extends CController { * throw a JS alert() with current message in timeSelectorEventHandler() in gtlc.js. */ - $messages = CMessages::get(); + $messages = CMessageHelper::getMessages(); $this->setResponse(new CControllerResponseData([ 'main_block' => json_encode(['error' => $messages[0]['message']]) diff --git a/ui/app/controllers/CControllerTrigDisplayUpdate.php b/ui/app/controllers/CControllerTrigDisplayUpdate.php index b391f6ff665..40821ecad76 100644 --- a/ui/app/controllers/CControllerTrigDisplayUpdate.php +++ b/ui/app/controllers/CControllerTrigDisplayUpdate.php @@ -44,7 +44,7 @@ class CControllerTrigDisplayUpdate extends CController { ); $response->setFormData($this->getInputAll()); - CMessages::addError(_('Cannot update configuration')); + CMessageHelper::setErrorTitle(_('Cannot update configuration')); $this->setResponse($response); } @@ -83,10 +83,10 @@ class CControllerTrigDisplayUpdate extends CController { $result = DBend($result); if ($result) { - CMessages::addSuccess(_('Configuration updated')); + CMessageHelper::setSuccessTitle(_('Configuration updated')); } else { - CMessages::addError(_('Cannot update configuration')); + CMessageHelper::setErrorTitle(_('Cannot update configuration')); $response->setFormData($this->getInputAll()); } diff --git a/ui/app/controllers/CControllerTrigSeverityUpdate.php b/ui/app/controllers/CControllerTrigSeverityUpdate.php index a554a31b108..8f2b8bd9bd5 100644 --- a/ui/app/controllers/CControllerTrigSeverityUpdate.php +++ b/ui/app/controllers/CControllerTrigSeverityUpdate.php @@ -43,7 +43,7 @@ class CControllerTrigSeverityUpdate extends CController { $response = new CControllerResponseRedirect((new CUrl('zabbix.php')) ->setArgument('action', 'trigseverity.edit') ); - CMessages::addError(_('Cannot update configuration')); + CMessageHelper::setErrorTitle(_('Cannot update configuration')); $response->setFormData($this->getInputAll()); $this->setResponse($response); } @@ -76,11 +76,11 @@ class CControllerTrigSeverityUpdate extends CController { ]); if ($result) { - CMessages::addSuccess(_('Configuration updated')); + CMessageHelper::setSuccessTitle(_('Configuration updated')); } else { $response->setFormData($this->getInputAll()); - CMessages::addError(_('Cannot update configuration')); + CMessageHelper::setErrorTitle(_('Cannot update configuration')); } $this->setResponse($response); diff --git a/ui/app/controllers/CControllerUserCreate.php b/ui/app/controllers/CControllerUserCreate.php index a622ab81eb7..c6b7dc7788f 100644 --- a/ui/app/controllers/CControllerUserCreate.php +++ b/ui/app/controllers/CControllerUserCreate.php @@ -58,7 +58,7 @@ class CControllerUserCreate extends CControllerUserUpdateGeneral { case self::VALIDATION_ERROR: $response = new CControllerResponseRedirect('zabbix.php?action=user.edit'); $response->setFormData($this->getInputAll()); - CMessages::addError(_('Cannot add user')); + CMessageHelper::setErrorTitle(_('Cannot add user')); $this->setResponse($response); break; @@ -107,14 +107,14 @@ class CControllerUserCreate extends CControllerUserUpdateGeneral { ->setArgument('page', CPagerHelper::loadPage('user.list', null)) ); $response->setFormData(['uncheck' => '1']); - CMessages::addSuccess(_('User added')); + CMessageHelper::setSuccessTitle(_('User added')); } else { $response = new CControllerResponseRedirect((new CUrl('zabbix.php')) ->setArgument('action', 'user.edit') ); $response->setFormData($this->getInputAll()); - CMessages::addError(_('Cannot add user')); + CMessageHelper::setErrorTitle(_('Cannot add user')); } $this->setResponse($response); } diff --git a/ui/app/controllers/CControllerUserDelete.php b/ui/app/controllers/CControllerUserDelete.php index f231f4db14f..d49629ed30b 100644 --- a/ui/app/controllers/CControllerUserDelete.php +++ b/ui/app/controllers/CControllerUserDelete.php @@ -53,10 +53,10 @@ class CControllerUserDelete extends CController { if ($result) { $response->setFormData(['uncheck' => '1']); - CMessages::addSuccess(_n('User deleted', 'Users deleted', $deleted)); + CMessageHelper::setSuccessTitle(_n('User deleted', 'Users deleted', $deleted)); } else { - CMessages::addError(_n('Cannot delete user', 'Cannot delete users', $deleted)); + CMessageHelper::setErrorTitle(_n('Cannot delete user', 'Cannot delete users', $deleted)); } $this->setResponse($response); diff --git a/ui/app/controllers/CControllerUserProfileUpdate.php b/ui/app/controllers/CControllerUserProfileUpdate.php index 54089cb3243..d08aed44981 100644 --- a/ui/app/controllers/CControllerUserProfileUpdate.php +++ b/ui/app/controllers/CControllerUserProfileUpdate.php @@ -58,7 +58,7 @@ class CControllerUserProfileUpdate extends CControllerUserUpdateGeneral { case self::VALIDATION_ERROR: $response = new CControllerResponseRedirect('zabbix.php?action=userprofile.edit'); $response->setFormData($this->getInputAll()); - CMessages::addError(_('Cannot update user')); + CMessageHelper::setErrorTitle(_('Cannot update user')); $this->setResponse($response); break; @@ -111,12 +111,12 @@ class CControllerUserProfileUpdate extends CControllerUserUpdateGeneral { if ($result) { $response = new CControllerResponseRedirect(ZBX_DEFAULT_URL); - CMessages::addSuccess(_('User updated')); + CMessageHelper::setSuccessTitle(_('User updated')); } else { $response = new CControllerResponseRedirect('zabbix.php?action=userprofile.edit'); $response->setFormData($this->getInputAll()); - CMessages::addError(_('Cannot update user')); + CMessageHelper::setErrorTitle(_('Cannot update user')); } $this->setResponse($response); diff --git a/ui/app/controllers/CControllerUserUnblock.php b/ui/app/controllers/CControllerUserUnblock.php index df966a335b2..fca35fada51 100644 --- a/ui/app/controllers/CControllerUserUnblock.php +++ b/ui/app/controllers/CControllerUserUnblock.php @@ -72,10 +72,10 @@ class CControllerUserUnblock extends CController { if ($result) { $response->setFormData(['uncheck' => '1']); - CMessages::addSuccess(_n('User unblocked', 'Users unblocked', $unblocked)); + CMessageHelper::setSuccessTitle(_n('User unblocked', 'Users unblocked', $unblocked)); } else { - CMessages::addError(_n('Cannot unblock user', 'Cannot unblock users', $unblocked)); + CMessageHelper::setErrorTitle(_n('Cannot unblock user', 'Cannot unblock users', $unblocked)); } $this->setResponse($response); diff --git a/ui/app/controllers/CControllerUserUpdate.php b/ui/app/controllers/CControllerUserUpdate.php index d81edd982bf..e722ee679ce 100644 --- a/ui/app/controllers/CControllerUserUpdate.php +++ b/ui/app/controllers/CControllerUserUpdate.php @@ -62,7 +62,7 @@ class CControllerUserUpdate extends CControllerUserUpdateGeneral { case self::VALIDATION_ERROR: $response = new CControllerResponseRedirect('zabbix.php?action=user.edit'); $response->setFormData($this->getInputAll()); - CMessages::addError(_('Cannot update user')); + CMessageHelper::setErrorTitle(_('Cannot update user')); $this->setResponse($response); break; @@ -119,14 +119,14 @@ class CControllerUserUpdate extends CControllerUserUpdateGeneral { ->setArgument('page', CPagerHelper::loadPage('user.list', null)) ); $response->setFormData(['uncheck' => '1']); - CMessages::addSuccess(_('User updated')); + CMessageHelper::setSuccessTitle(_('User updated')); } else { $response = new CControllerResponseRedirect((new CUrl('zabbix.php')) ->setArgument('action', 'user.edit') ); $response->setFormData($this->getInputAll()); - CMessages::addError(_('Cannot update user')); + CMessageHelper::setErrorTitle(_('Cannot update user')); } $this->setResponse($response); diff --git a/ui/app/controllers/CControllerUsergroupCreate.php b/ui/app/controllers/CControllerUsergroupCreate.php index 548676c8592..e6a6aa90368 100644 --- a/ui/app/controllers/CControllerUsergroupCreate.php +++ b/ui/app/controllers/CControllerUsergroupCreate.php @@ -48,7 +48,7 @@ class CControllerUsergroupCreate extends CController { ->getUrl() ); $response->setFormData($this->getInputAll()); - CMessages::addError(_('Cannot add user group')); + CMessageHelper::setErrorTitle(_('Cannot add user group')); $this->setResponse($response); break; @@ -91,13 +91,13 @@ class CControllerUsergroupCreate extends CController { ->setArgument('page', CPagerHelper::loadPage('usergroup.list', null)) ); $response->setFormData(['uncheck' => '1']); - CMessages::addSuccess(_('User group added')); + CMessageHelper::setSuccessTitle(_('User group added')); } else { $response = new CControllerResponseRedirect((new CUrl('zabbix.php')) ->setArgument('action', 'usergroup.edit') ); - CMessages::addError(_('Cannot add user group')); + CMessageHelper::setErrorTitle(_('Cannot add user group')); $response->setFormData($this->getInputAll()); } diff --git a/ui/app/controllers/CControllerUsergroupDelete.php b/ui/app/controllers/CControllerUsergroupDelete.php index 1ca27764f8e..8a735728a79 100644 --- a/ui/app/controllers/CControllerUsergroupDelete.php +++ b/ui/app/controllers/CControllerUsergroupDelete.php @@ -53,10 +53,10 @@ class CControllerUsergroupDelete extends CController { if ($result) { $response->setFormData(['uncheck' => '1']); - CMessages::addSuccess(_n('User group deleted', 'User groups deleted', $deleted)); + CMessageHelper::setSuccessTitle(_n('User group deleted', 'User groups deleted', $deleted)); } else { - CMessages::addError(_n('Cannot delete user group', 'Cannot delete user groups', $deleted)); + CMessageHelper::setErrorTitle(_n('Cannot delete user group', 'Cannot delete user groups', $deleted)); } $this->setResponse($response); diff --git a/ui/app/controllers/CControllerUsergroupMassUpdate.php b/ui/app/controllers/CControllerUsergroupMassUpdate.php index 4ef45148424..baba30cb3d9 100644 --- a/ui/app/controllers/CControllerUsergroupMassUpdate.php +++ b/ui/app/controllers/CControllerUsergroupMassUpdate.php @@ -63,10 +63,10 @@ class CControllerUsergroupMassUpdate extends CController { if ($result) { $response->setFormData(['uncheck' => '1']); - CMessages::addSuccess(_n('User group updated', 'User groups updated', $updated)); + CMessageHelper::setSuccessTitle(_n('User group updated', 'User groups updated', $updated)); } else { - CMessages::addError(_n('Cannot update user group', 'Cannot update user groups', $updated)); + CMessageHelper::setErrorTitle(_n('Cannot update user group', 'Cannot update user groups', $updated)); } $this->setResponse($response); diff --git a/ui/app/controllers/CControllerUsergroupUpdate.php b/ui/app/controllers/CControllerUsergroupUpdate.php index 50cd8fc861c..882f2f9e855 100644 --- a/ui/app/controllers/CControllerUsergroupUpdate.php +++ b/ui/app/controllers/CControllerUsergroupUpdate.php @@ -50,7 +50,7 @@ class CControllerUsergroupUpdate extends CController { ->getUrl() ); $response->setFormData($this->getInputAll()); - CMessages::addError(_('Cannot update user group')); + CMessageHelper::setErrorTitle(_('Cannot update user group')); $this->setResponse($response); break; @@ -95,14 +95,14 @@ class CControllerUsergroupUpdate extends CController { ->setArgument('page', CPagerHelper::loadPage('usergroup.list', null)) ); $response->setFormData(['uncheck' => '1']); - CMessages::addSuccess(_('User group updated')); + CMessageHelper::setSuccessTitle(_('User group updated')); } else { $response = new CControllerResponseRedirect((new CUrl('zabbix.php')) ->setArgument('action', 'usergroup.edit') ->setArgument('usrgrpid', $this->getInput('usrgrpid')) ); - CMessages::addError(_('Cannot update user group')); + CMessageHelper::setErrorTitle(_('Cannot update user group')); $response->setFormData($this->getInputAll()); } diff --git a/ui/app/controllers/CControllerValuemapCreate.php b/ui/app/controllers/CControllerValuemapCreate.php index 828d3a78783..5da16653341 100644 --- a/ui/app/controllers/CControllerValuemapCreate.php +++ b/ui/app/controllers/CControllerValuemapCreate.php @@ -38,7 +38,7 @@ class CControllerValuemapCreate extends CController { $response = new CControllerResponseRedirect($url); $response->setFormData($this->getInputAll()); - CMessages::addError(_('Cannot add value map')); + CMessageHelper::setErrorTitle(_('Cannot add value map')); $this->setResponse($response); break; @@ -68,13 +68,13 @@ class CControllerValuemapCreate extends CController { ->setArgument('page', CPagerHelper::loadPage('valuemap.list', null)) ); $response->setFormData(['uncheck' => '1']); - CMessages::addSuccess(_('Value map added')); + CMessageHelper::setSuccessTitle(_('Value map added')); } else { $response = new CControllerResponseRedirect((new CUrl('zabbix.php')) ->setArgument('action', 'valuemap.edit') ); - CMessages::addError(_('Cannot add value map')); + CMessageHelper::setErrorTitle(_('Cannot add value map')); $response->setFormData($this->getInputAll()); } diff --git a/ui/app/controllers/CControllerValuemapDelete.php b/ui/app/controllers/CControllerValuemapDelete.php index 99884b2b8f3..8c4925c1ebc 100644 --- a/ui/app/controllers/CControllerValuemapDelete.php +++ b/ui/app/controllers/CControllerValuemapDelete.php @@ -64,10 +64,10 @@ class CControllerValuemapDelete extends CController { if ($result) { $response->setFormData(['uncheck' => '1']); - CMessages::addSuccess(_n('Value map deleted', 'Value maps deleted', count($valuemapids))); + CMessageHelper::setSuccessTitle(_n('Value map deleted', 'Value maps deleted', count($valuemapids))); } else { - CMessages::addError(_n('Cannot delete value map', 'Cannot delete value maps', count($valuemapids))); + CMessageHelper::setErrorTitle(_n('Cannot delete value map', 'Cannot delete value maps', count($valuemapids))); } $this->setResponse($response); diff --git a/ui/app/controllers/CControllerValuemapUpdate.php b/ui/app/controllers/CControllerValuemapUpdate.php index 9c82819cb8c..00edd0e722e 100644 --- a/ui/app/controllers/CControllerValuemapUpdate.php +++ b/ui/app/controllers/CControllerValuemapUpdate.php @@ -41,7 +41,7 @@ class CControllerValuemapUpdate extends CController { $response = new CControllerResponseRedirect($url); $response->setFormData($this->getInputAll()); - CMessages::addError(_('Cannot update value map')); + CMessageHelper::setErrorTitle(_('Cannot update value map')); $this->setResponse($response); break; @@ -92,14 +92,14 @@ class CControllerValuemapUpdate extends CController { ->setArgument('page', CPagerHelper::loadPage('valuemap.list', null)) ); $response->setFormData(['uncheck' => '1']); - CMessages::addSuccess(_('Value map updated')); + CMessageHelper::setSuccessTitle(_('Value map updated')); } else { $response = new CControllerResponseRedirect((new CUrl('zabbix.php')) ->setArgument('action', 'valuemap.edit') ->setArgument('valuemapid', $this->getInput('valuemapid')) ); - CMessages::addError(_('Cannot update value map')); + CMessageHelper::setErrorTitle(_('Cannot update value map')); $response->setFormData($this->getInputAll()); } diff --git a/ui/app/controllers/CControllerWorkingTimeUpdate.php b/ui/app/controllers/CControllerWorkingTimeUpdate.php index c0e9a3dfc6e..4e0b67cbc91 100644 --- a/ui/app/controllers/CControllerWorkingTimeUpdate.php +++ b/ui/app/controllers/CControllerWorkingTimeUpdate.php @@ -34,7 +34,7 @@ class CControllerWorkingTimeUpdate extends CController { ->getUrl() ); $response->setFormData($this->getInputAll()); - CMessages::addError(_('Cannot update configuration')); + CMessageHelper::setErrorTitle(_('Cannot update configuration')); $this->setResponse($response); } @@ -55,11 +55,11 @@ class CControllerWorkingTimeUpdate extends CController { $result = DBend($result); if ($result) { - CMessages::addSuccess(_('Configuration updated')); + CMessageHelper::setSuccessTitle(_('Configuration updated')); } else { $response->setFormData($this->getInputAll()); - CMessages::addError(_('Cannot update configuration')); + CMessageHelper::setErrorTitle(_('Cannot update configuration')); } $this->setResponse($response); diff --git a/ui/host_prototypes.php b/ui/host_prototypes.php index cf82fee2e92..e7572e02506 100644 --- a/ui/host_prototypes.php +++ b/ui/host_prototypes.php @@ -153,7 +153,7 @@ elseif (isset($_REQUEST['clone']) && isset($_REQUEST['hostid'])) { $msg = [ 'type' => 'error', 'message' => _('The cloned host prototype contains user defined macros with type "Secret text". The value and type of these macros were reset.'), - 'src' => '' + 'source' => '' ]; echo makeMessageBox(false, [$msg], null, true, false)->addClass(ZBX_STYLE_MSG_WARNING); diff --git a/ui/hosts.php b/ui/hosts.php index 24355c31af7..c90bd27d1bd 100644 --- a/ui/hosts.php +++ b/ui/hosts.php @@ -349,7 +349,7 @@ elseif (hasRequest('hostid') && (hasRequest('clone') || hasRequest('full_clone') $msg = [ 'type' => 'error', 'message' => _('The cloned host contains user defined macros with type "Secret text". The value and type of these macros were reset.'), - 'src' => '' + 'source' => '' ]; echo makeMessageBox(false, [$msg], null, true, false)->addClass(ZBX_STYLE_MSG_WARNING); diff --git a/ui/include/classes/core/CMessages.php b/ui/include/classes/core/CMessages.php deleted file mode 100644 index 8fafca6603e..00000000000 --- a/ui/include/classes/core/CMessages.php +++ /dev/null @@ -1,142 +0,0 @@ -<?php declare(strict_types = 1); -/* -** Zabbix -** Copyright (C) 2001-2020 Zabbix SIA -** -** This program is free software; you can redistribute it and/or modify -** it under the terms of the GNU General Public License as published by -** the Free Software Foundation; either version 2 of the License, or -** (at your option) any later version. -** -** This program is distributed in the hope that it will be useful, -** but WITHOUT ANY WARRANTY; without even the implied warranty of -** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -** GNU General Public License for more details. -** -** You should have received a copy of the GNU General Public License -** along with this program; if not, write to the Free Software -** Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -**/ - - -/** - * Helper to store succes / error messages. - */ -class CMessages { - - /** - * Messages array. - * - * @static - * - * @var array - */ - private static $msgs = []; - /** - * Success message. - * - * @static - * - * @var string - */ - private static $success; - /** - * Error message. - * - * @static - * - * @var string - */ - private static $error; - - /** - * Add messages. - * - * @static - * - * @param array $msg - * - * @return boolean - */ - public static function add(array $msg): bool { - self::$msgs[] = $msg; - - return true; - } - - /** - * Add success message. - * - * @static - * - * @param string $msg - * - * @return boolean - */ - public static function addSuccess(string $msg): bool { - self::$success = $msg; - - return true; - } - - /** - * Add error message. - * - * @static - * - * @param string $msg - * - * @return boolean - */ - public static function addError(string $msg): bool { - self::$error = $msg; - - return true; - } - - /** - * Get messages. - * - * @static - * - * @return array - */ - public static function get(): array { - return self::$msgs; - } - - /** - * Get success message. - * - * @static - * - * @return string|null - */ - public static function getSuccess(): ?string { - return self::$success; - } - - /** - * Get error message. - * - * @static - * - * @return string|null - */ - public static function getError(): ?string { - return self::$error; - } - - /** - * Clear messages. - * - * @static - * - * @return boolean - */ - public static function clear(): bool { - self::$msgs = []; - - return true; - } -} diff --git a/ui/include/classes/core/ZBase.php b/ui/include/classes/core/ZBase.php index 918da4cfafc..6b66616c6cb 100644 --- a/ui/include/classes/core/ZBase.php +++ b/ui/include/classes/core/ZBase.php @@ -425,11 +425,11 @@ class ZBase { */ private function initMessages(): void { if (CCookieHelper::has('system-message-ok')) { - CMessages::addSuccess(CCookieHelper::get('system-message-ok')); + CMessageHelper::setSuccessTitle(CCookieHelper::get('system-message-ok')); CCookieHelper::unset('system-message-ok'); } if (CCookieHelper::has('system-message-error')) { - CMessages::addError(CCookieHelper::get('system-message-error')); + CMessageHelper::setErrorTitle(CCookieHelper::get('system-message-error')); CCookieHelper::unset('system-message-error'); } } @@ -516,10 +516,7 @@ class ZBase { if ($response instanceof CControllerResponseRedirect) { header('Content-Type: text/html; charset=UTF-8'); - $messages = filter_messages(CMessages::get()); - foreach ($messages as $message) { - CMessages::add($message); - } + filter_messages(); $response->redirect(); } @@ -527,16 +524,13 @@ class ZBase { elseif ($response instanceof CControllerResponseFatal) { header('Content-Type: text/html; charset=UTF-8'); - $messages = filter_messages(CMessages::get()); - foreach ($messages as $message) { - CMessages::add($message); - } + filter_messages(); - CMessages::add(['message' => 'Controller: '.$router->getAction()]); + CMessageHelper::addError(['message' => 'Controller: '.$router->getAction()]); ksort($_REQUEST); foreach ($_REQUEST as $key => $value) { if ($key !== 'sid') { - CMessages::add(['message' => is_scalar($value) ? $key.': '.$value : $key.': '.gettype($value)]); + CMessageHelper::addError(['message' => is_scalar($value) ? $key.': '.$value : $key.': '.gettype($value)]); } } diff --git a/ui/include/classes/helpers/CMessageHelper.php b/ui/include/classes/helpers/CMessageHelper.php new file mode 100644 index 00000000000..5cfae0e53ea --- /dev/null +++ b/ui/include/classes/helpers/CMessageHelper.php @@ -0,0 +1,128 @@ +<?php declare(strict_types = 1); +/* +** Zabbix +** Copyright (C) 2001-2020 Zabbix SIA +** +** This program is free software; you can redistribute it and/or modify +** it under the terms of the GNU General Public License as published by +** the Free Software Foundation; either version 2 of the License, or +** (at your option) any later version. +** +** This program is distributed in the hope that it will be useful, +** but WITHOUT ANY WARRANTY; without even the implied warranty of +** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +** GNU General Public License for more details. +** +** You should have received a copy of the GNU General Public License +** along with this program; if not, write to the Free Software +** Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +**/ + + +/** + * Helper to store succes / error messages. + */ +class CMessageHelper { + + public const MessageTypeError = 'error'; + public const MessageTypeSuccess = 'success'; + + /** + * @var string + */ + private static $type = self::MessageTypeSuccess; + + /** + * @var string + */ + private static $title; + + /** + * Messages array. + * + * @var array + */ + private static $messages = []; + + /** + * Get messages. + * + * @return array + */ + public static function getMessages(): array { + return self::$messages; + } + + /** + * Add message with type error. + * + * @param string $message + * @param string $source + */ + public static function addError(string $message, string $source = ''): void { + self::$type = self::MessageTypeError; + self::$messages[] = [ + 'type' => self::MessageTypeError, + 'message' => $message, + 'source' => $source + ]; + } + + /** + * Add message with type info. + * + * @param string $message + */ + public static function addSuccess(string $message): void { + self::$messages[] = [ + 'type' => self::MessageTypeSuccess, + 'message' => $message + ]; + } + + /** + * Get messages title. + * + * @return string|null + */ + public static function getTitle(): ?string { + return self::$title; + } + + /** + * Set title for error messages. + * + * @param string $title + */ + public static function setErrorTitle(string $title): void { + self::$type = self::MessageTypeError; + self::$title = $title; + } + + /** + * Set title for info messages. + * + * @param $title + */ + public static function setSuccessTitle($title): void { + self::$title = $title; + } + + /** + * Get messages type. + * + * @return string + */ + public static function getType(): string { + return self::$type; + } + + /** + * Clear messages. + */ + public static function clear(): void { + self::$type = self::MessageTypeSuccess; + self::$title = null; + self::$messages = []; + } +} diff --git a/ui/include/classes/mvc/CController.php b/ui/include/classes/mvc/CController.php index 0857cff0601..38c78d534ae 100644 --- a/ui/include/classes/mvc/CController.php +++ b/ui/include/classes/mvc/CController.php @@ -160,15 +160,20 @@ abstract class CController { if ($data['messages']) { if (array_key_exists('success', $data['messages'])) { - CMessages::addSuccess($data['messages']['success']); + CMessageHelper::setSuccessTitle($data['messages']['success']); } if (array_key_exists('error', $data['messages'])) { - CMessages::addError($data['messages']['error']); + CMessageHelper::setErrorTitle($data['messages']['error']); } if (array_key_exists('messages', $data['messages'])) { foreach ($data['messages']['messages'] as $message) { - CMessages::add($message); + if ($message['type'] === CMessageHelper::MessageTypeSuccess) { + CMessageHelper::addSuccess($message['message']); + } + else { + CMessageHelper::addError($message['message'], $message['source']); + } } } } diff --git a/ui/include/classes/mvc/CControllerResponse.php b/ui/include/classes/mvc/CControllerResponse.php index 8e0ca0cf5cd..0d0bca12403 100644 --- a/ui/include/classes/mvc/CControllerResponse.php +++ b/ui/include/classes/mvc/CControllerResponse.php @@ -32,7 +32,7 @@ abstract class CControllerResponse { public function redirect(): void { // Redirect as simple request. if ($this instanceof CControllerResponseRedirect) { - if ($this->getFormData() === null && CMessages::getSuccess() === null && CMessages::getError() === null) { + if ($this->getFormData() === null && CMessageHelper::getTitle() === null) { redirect($this->getLocation()); } } @@ -84,23 +84,11 @@ abstract class CControllerResponse { private function getData(): array { $data = []; - $messages = []; - - foreach (CMessages::get() as $value) { - if (!is_array($value)) { - $value = ['message' => $value]; - } - - $messages['messages'][] = $value; - } + $messages['messages'] = CMessageHelper::getMessages(); if ($this instanceof CControllerResponseRedirect) { - if (CMessages::getSuccess() !== null) { - $messages['success'] = CMessages::getSuccess(); - } - - if (CMessages::getError() !== null) { - $messages['error'] = CMessages::getError(); + if (CMessageHelper::getTitle() !== null) { + $messages[CMessageHelper::getType()] = CMessageHelper::getTitle(); } $data = $this->getFormData(); diff --git a/ui/include/classes/setup/CSetupWizard.php b/ui/include/classes/setup/CSetupWizard.php index 8fdfccfb6d6..39e46191f08 100644 --- a/ui/include/classes/setup/CSetupWizard.php +++ b/ui/include/classes/setup/CSetupWizard.php @@ -303,7 +303,8 @@ class CSetupWizard extends CForm { } if ($this->STEP_FAILED) { - $message_box = makeMessageBox(false, CMessages::get(), _('Cannot connect to the database.'), false, true); + $message_box = makeMessageBox(false, CMessageHelper::getMessages(), _('Cannot connect to the database.'), + false, true); } else { $message_box = null; diff --git a/ui/include/classes/user/CWebUser.php b/ui/include/classes/user/CWebUser.php index c9300090544..b9492a19668 100644 --- a/ui/include/classes/user/CWebUser.php +++ b/ui/include/classes/user/CWebUser.php @@ -100,7 +100,7 @@ class CWebUser { ]); if (empty(self::$data)) { - clear_messages(); + CMessageHelper::clear(); throw new Exception(); } diff --git a/ui/include/func.inc.php b/ui/include/func.inc.php index fd5d548dc69..235cfcbf78c 100644 --- a/ui/include/func.inc.php +++ b/ui/include/func.inc.php @@ -1573,8 +1573,7 @@ function detect_page_type($default = PAGE_TYPE_HTML) { return $default; } -function makeMessageBox($good, array $messages, $title = null, $show_close_box = true, $show_details = false) -{ +function makeMessageBox($good, array $messages, $title = null, $show_close_box = true, $show_details = false) { $class = $good ? ZBX_STYLE_MSG_GOOD : ZBX_STYLE_MSG_BAD; $msg_details = null; $link_details = null; @@ -1640,31 +1639,29 @@ function makeMessageBox($good, array $messages, $title = null, $show_close_box = /** * Filters messages that can be displayed to user based on defines (see ZBX_SHOW_TECHNICAL_ERRORS) and user settings. * - * @param array $messages List of messages to filter. - * * @return array */ -function filter_messages(array $messages = []) { +function filter_messages() { if (!ZBX_SHOW_TECHNICAL_ERRORS && CWebUser::getType() != USER_TYPE_SUPER_ADMIN && !CWebUser::getDebugMode()) { - $filtered_messages = []; - $generic_exists = false; + $messages = CMessageHelper::getMessages(); + CMessageHelper::clear(); + $generic_exists = false; foreach ($messages as $message) { - if (array_key_exists('src', $message) && ($message['src'] === 'sql' || $message['src'] === 'php')) { + if ($message['type'] === CMessageHelper::MessageTypeError + && ($message['source'] === 'sql' || $message['source'] === 'php')) { if (!$generic_exists) { - $message['message'] = _('System error occurred. Please contact Zabbix administrator.'); - $filtered_messages[] = $message; + CMessageHelper::addError(_('System error occurred. Please contact Zabbix administrator.')); $generic_exists = true; } } else { - $filtered_messages[] = $message; + CMessageHelper::addSuccess($message['message']); } } - $messages = $filtered_messages; } - return $messages; + return CMessageHelper::getMessages(); } /** @@ -1677,14 +1674,12 @@ function filter_messages(array $messages = []) { * @return CDiv|null */ function getMessages($good = false, $title = null, $show_close_box = true) { - $messages = filter_messages(CMessages::get()); + $messages = get_and_clear_messages(); $message_box = ($title || $messages) ? makeMessageBox($good, $messages, $title, $show_close_box) : null; - CMessages::clear(); - return $message_box; } @@ -1696,9 +1691,7 @@ function show_messages($good = false, $okmsg = null, $errmsg = null) { } $title = $good ? $okmsg : $errmsg; - $messages = filter_messages(CMessages::get()); - - CMessages::clear(); + $messages = get_and_clear_messages(); if ($title === null && !$messages) { return; @@ -1816,11 +1809,11 @@ function get_prepared_messages(array $options = []): ?string { } else { $messages_current = []; - $restore_messages = CMessages::get(); + $restore_messages = CMessageHelper::getMessages(); $restore_messages_prepared = $ZBX_MESSAGES_PREPARED; } - CMessages::clear(); + CMessageHelper::clear(); $ZBX_MESSAGES_PREPARED = []; // Process authentication warning if user had unsuccessful authentication attempts. @@ -1843,18 +1836,18 @@ function get_prepared_messages(array $options = []): ?string { } $messages_authentication = $ZBX_MESSAGES_PREPARED; - CMessages::clear(); + CMessageHelper::clear(); $ZBX_MESSAGES_PREPARED = []; // Process messages passed by the previous request. if ($options['with_session_messages']) { - if (CMessages::getSuccess()) { - show_messages(true, CMessages::getSuccess(), null); - } - - if (CMessages::getError()) { - show_messages(false, null, CMessages::getError()); + if (CMessageHelper::getTitle() !== null) { + show_messages( + CMessageHelper::getType() === CMessageHelper::MessageTypeSuccess, + CMessageHelper::getTitle(), + CMessageHelper::getTitle() + ); } } @@ -1869,9 +1862,14 @@ function get_prepared_messages(array $options = []): ?string { )->toString(); } - array_map(function ($value) { - return CMessages::add($value); - }, $restore_messages); + foreach ($restore_messages as $message) { + if ($message['type'] === CMessageHelper::MessageTypeSuccess) { + CMessageHelper::addSuccess($message['message']); + } + else { + CMessageHelper::addError($message['message'], $message['source']); + } + } $ZBX_MESSAGES_PREPARED = $restore_messages_prepared; @@ -1890,7 +1888,7 @@ function info($msgs) { zbx_value2array($msgs); foreach ($msgs as $msg) { - CMessages::add(['type' => 'info', 'message' => $msg]); + CMessageHelper::addSuccess($msg); } } @@ -1904,7 +1902,7 @@ function error($msgs, $src = '') { $msgs = zbx_toArray($msgs); foreach ($msgs as $msg) { - CMessages::add(['type' => 'error', 'message' => $msg, 'src' => $src]); + CMessageHelper::addError($msg, $src); } } @@ -1921,11 +1919,11 @@ function error_group($data) { } } -function clear_messages() { - $messages = CMessages::get(); - CMessages::clear(); +function get_and_clear_messages() { + $messages = filter_messages(); + CMessageHelper::clear(); - return filter_messages($messages); + return $messages; } function fatal_error($msg) { @@ -2172,13 +2170,7 @@ function imageOut(&$image, $format = null) { * @return bool */ function hasErrorMesssages() { - foreach (CMessages::get() as $message) { - if (array_key_exists('type', $message) && $message['type'] === 'error') { - return true; - } - } - - return false; + return CMessageHelper::getType() === CMessageHelper::MessageTypeError; } /** diff --git a/ui/include/validate.inc.php b/ui/include/validate.inc.php index bbab9a799b8..97a3fc4cb55 100644 --- a/ui/include/validate.inc.php +++ b/ui/include/validate.inc.php @@ -365,15 +365,20 @@ function invalid_url($msg = null) { global $DB; // backup messages before including page_header.php - $temp = CMessages::get(); - CMessages::clear(); + $messages_backup = CMessageHelper::getMessages(); + CMessageHelper::clear(); require_once dirname(__FILE__).'/page_header.php'; // Rollback reset messages. - array_map(function ($value) { - return CMessages::add($value); - }, $temp); + foreach ($messages_backup as $message) { + if ($message['type'] === CMessageHelper::MessageTypeSuccess) { + CMessageHelper::addSuccess($message['message']); + } + else { + CMessageHelper::addError($message['message'], $message['source']); + } + } unset_all(); show_error_message($msg); diff --git a/ui/index.php b/ui/index.php index d7a2d6589b1..c689196d9bd 100644 --- a/ui/index.php +++ b/ui/index.php @@ -88,7 +88,7 @@ if (CWebUser::isLoggedIn() && !CWebUser::isGuest()) { redirect(CWebUser::$data['url'] ? CWebUser::$data['url'] : ZBX_DEFAULT_URL); } -$messages = clear_messages(); +$messages = get_and_clear_messages(); echo (new CView('general.login', [ 'http_login_url' => ($config['http_auth_enabled'] == ZBX_AUTH_HTTP_ENABLED) diff --git a/ui/index_http.php b/ui/index_http.php index e02ec75903a..da01f8e1f2c 100644 --- a/ui/index_http.php +++ b/ui/index_http.php @@ -80,11 +80,9 @@ else { error(_('Login name or password is incorrect.')); } -$messages = clear_messages(); - echo (new CView('general.warning', [ 'header' => _('You are not logged in'), - 'messages' => array_column($messages, 'message'), + 'messages' => array_column(get_and_clear_messages(), 'message'), 'buttons' => [ (new CButton('login', _('Login')))->onClick('document.location = '. json_encode($redirect_to->getUrl()).';') diff --git a/ui/index_sso.php b/ui/index_sso.php index 7e472f27969..e4a39b5c9dd 100644 --- a/ui/index_sso.php +++ b/ui/index_sso.php @@ -241,11 +241,9 @@ catch (Exception $e) { error($e->getMessage()); } -$messages = clear_messages(); - echo (new CView('general.warning', [ 'header' => _('You are not logged in'), - 'messages' => array_column($messages, 'message'), + 'messages' => array_column(get_and_clear_messages(), 'message'), 'buttons' => [ (new CButton('login', _('Login')))->onClick( 'document.location = '.json_encode( diff --git a/ui/sysmap.php b/ui/sysmap.php index 891ff1480fa..ea65762ea07 100644 --- a/ui/sysmap.php +++ b/ui/sysmap.php @@ -116,7 +116,7 @@ if (isset($_REQUEST['favobj'])) { DBend(false); $msg = [$e->getMessage()]; - foreach (clear_messages() as $errMsg) { + foreach (get_and_clear_messages() as $errMsg) { $msg[] = $errMsg['type'].': '.$errMsg['message']; } diff --git a/ui/templates.php b/ui/templates.php index 650953ab1a6..25f58cf8fa1 100644 --- a/ui/templates.php +++ b/ui/templates.php @@ -201,7 +201,7 @@ elseif (hasRequest('templateid') && (hasRequest('clone') || hasRequest('full_clo $msg = [ 'type' => 'error', 'message' => _('The cloned template contains user defined macros with type "Secret text". The value and type of these macros were reset.'), - 'src' => '' + 'source' => '' ]; echo makeMessageBox(false, [$msg], null, true, false)->addClass(ZBX_STYLE_MSG_WARNING); |