Index: branches/5.0.x/core/units/configuration/configuration_event_handler.php =================================================================== diff -u -r12233 -r12264 --- branches/5.0.x/core/units/configuration/configuration_event_handler.php (.../configuration_event_handler.php) (revision 12233) +++ branches/5.0.x/core/units/configuration/configuration_event_handler.php (.../configuration_event_handler.php) (revision 12264) @@ -1,6 +1,6 @@ addFilter('module_filter', '%1$s.ModuleOwner = '.$this->Conn->qstr($module)); $object->addFilter('section_filter', '%1$s.Section = '.$this->Conn->qstr($section)); + if (!$this->Application->ConfigValue('AllowAdminConsoleInterfaceChange')) { + $object->addFilter('interface_change_filter', '%1$s.VariableName <> "AdminConsoleInterface"'); + } + if (defined('IS_INSTALL') && IS_INSTALL) { $object->addFilter('install_filter', 'ca.Install = 1'); } @@ -55,8 +59,23 @@ */ function OnBeforeItemUpdate(&$event) { + static $default_field_options = null; + $object =& $event->getObject(); + /* @var $object kDBItem */ + // ability to validate each configuration variable separately + if (!isset($default_field_options)) { + $default_field_options = $object->GetFieldOptions('VariableValue'); + } + + $new_field_options = $default_field_options; + $validation = $object->GetDBField('Validation'); + if ($validation) { + $new_field_options = array_merge($new_field_options, unserialize($validation)); + } + $object->SetFieldOptions('VariableValue', $new_field_options); + // if password field is empty, then don't update if ($object->GetDBField('element_type') == 'password') { if (trim($object->GetDBField('VariableValue')) == '') { @@ -69,7 +88,7 @@ } } - $field_values = $this->Application->GetVar($event->getPrefixSpecial(true)); + $field_values = $this->Application->GetVar( $event->getPrefixSpecial(true) ); $state_country_hash = Array ( 'Comm_State' => 'Comm_Country', @@ -79,10 +98,15 @@ $field_name = $object->GetDBField('VariableName'); if (array_key_exists($field_name, $state_country_hash)) { // if this is state field + $sql = 'SELECT VariableId + FROM ' . $this->Application->getUnitOption('conf', 'TableName') . ' + WHERE VariableName = "' . $state_country_hash[$field_name] . '"'; + $country_variable_id = $this->Conn->GetOne($sql); + $check_state = $object->GetDBField('VariableValue'); - $check_country = $field_values[ $state_country_hash[$field_name] ]['VariableValue']; + $check_country = $field_values[$country_variable_id]['VariableValue']; - if (!($check_country && $check_state)) { + if (!$check_country || !$check_state) { return true; } @@ -92,15 +116,18 @@ $object->SetDBField('VariableValue', $state_iso); } else { - $errormsgs = $this->Application->GetVar('errormsgs'); - $errors = !$errormsgs || !isset($errormsgs[$event->Prefix_Special]) ? Array() : $errormsgs[$event->Prefix_Special]; + // selected state doesn't belong to selected country + $object->SetError('VariableValue', 'invalid_state', 'la_InvalidState'); + } + } - $errors[$field_name] = 'la_InvalidState'; - $errormsgs[$event->Prefix_Special] = $errors; + if ($object->GetDBField('VariableName') == 'AdminConsoleInterface') { + $can_change = $this->Application->ConfigValue('AllowAdminConsoleInterfaceChange'); - $this->Application->SetVar('errormsgs', $errormsgs); - $event->status = erFAIL; + if (($object->GetDBField('VariableValue') != $object->GetOriginalField('VariableValue')) && !$can_change) { + $object->SetError('VariableValue', 'not_allowed', 'la_error_NotAllowed'); } + } } @@ -125,13 +152,16 @@ // allows to check if variable's value was changed now $variable_name = $object->GetDBField('VariableName'); $variable_value = $object->GetDBField('VariableValue'); - $watch_variables = Array ('Require_AdminSSL', 'AdminSSL_URL', 'AdvancedUserManagement', 'Site_Name'); + $watch_variables = Array ( + 'Require_AdminSSL', 'AdminSSL_URL', 'AdvancedUserManagement', + 'Site_Name', 'AdminConsoleInterface' + ); if (in_array($variable_name, $watch_variables)) { $changed = $this->Application->GetVar($event->getPrefixSpecial() . '_changed', Array ()); if ($variable_value != $object->GetOriginalField('VariableValue')) { - $changed[$variable_name] = $variable_value; + $changed[] = $variable_name; $this->Application->SetVar($event->getPrefixSpecial() . '_changed', $changed); } @@ -140,7 +170,7 @@ case 'AdminSSL_URL': static $skin_deleted = false; - if (array_key_exists($variable_name, $changed) && !$skin_deleted) { + if (in_array($variable_name, $changed) && !$skin_deleted) { // when administrative console is moved to SSL mode, then delete skin $skin_helper =& $this->Application->recallObject('SkinHelper'); /* @var $skin_helper SkinHelper */ @@ -166,32 +196,52 @@ function OnUpdate(&$event) { if (!$this->Application->CheckPermission('SYSTEM_ACCESS.READONLY', 1)) { + $items_info = $this->Application->GetVar( $event->getPrefixSpecial(true) ); // 1. save user selected module root category - $items_info = $this->Application->GetVar($event->getPrefixSpecial(true)); $new_category_id = getArrayValue($items_info, 'ModuleRootCategory', 'VariableValue'); if ($new_category_id !== false) { unset($items_info['ModuleRootCategory']); - $this->Application->SetVar($event->getPrefixSpecial(true), $items_info); } - parent::OnUpdate($event); + $object =& $event->getObject( Array('skip_autoload' => true) ); + /* @var $object kDBItem */ - if ($event->status == erSUCCESS && $new_category_id !== false) { - // root category was submitted - $module = $this->Application->GetVar('module'); - $root_category_id = $this->Application->findModule('Name', $module, 'RootCat'); + if ($items_info) { + $has_error = false; + foreach ($items_info as $id => $field_values) { + $object->Clear(); // clear validation errors from previous variable + $object->Load($id); + $object->SetFieldsFromHash($field_values); - if ($root_category_id != $new_category_id) { - // root category differs from one in db - $fields_hash = Array('RootCat' => $new_category_id); - $this->Conn->doUpdate($fields_hash, TABLE_PREFIX.'Modules', 'Name = '.$this->Conn->qstr($module)); + if (!$object->Update($id)) { + // don't stop when error found ! + $has_error = true; + } } + + $event->status = $has_error ? erFAIL : erSUCCESS; } - if ($event->status == erSUCCESS) { // reset cache + if ($event->status == erSUCCESS) { + if ($new_category_id !== false) { + // root category was submitted + $module = $this->Application->GetVar('module'); + $root_category_id = $this->Application->findModule('Name', $module, 'RootCat'); + + if ($root_category_id != $new_category_id) { + // root category differs from one in db + $fields_hash = Array('RootCat' => $new_category_id); + $this->Conn->doUpdate($fields_hash, TABLE_PREFIX.'Modules', 'Name = '.$this->Conn->qstr($module)); + } + } + + // reset cache $changed = $this->Application->GetVar($event->getPrefixSpecial() . '_changed', Array ()); - $refresh_sections = array_key_exists('AdvancedUserManagement', $changed) || array_key_exists('Site_Name', $changed); + $require_refresh = Array ( + 'AdvancedUserManagement', 'Site_Name', 'AdminConsoleInterface' + ); + $refresh_sections = array_intersect($require_refresh, $changed); if ($refresh_sections) { // reset sections too, because of AdvancedUserManagement @@ -200,14 +250,12 @@ $this->Application->UnitConfigReader->ResetParsedData($refresh_sections ? true : false); } + elseif ($this->Application->GetVar('errors_' . $event->getPrefixSpecial())) { + // because we have list out there, and this is item + $this->Application->removeObject( $event->getPrefixSpecial() ); + } } - if ($this->Application->GetVar('errormsgs')) { - // because we have list out there, and this is item - $this->Application->removeObject($event->getPrefixSpecial()); - $event->redirect = false; - } - // keeps module and section in REQUEST to ensure, that last admin template will work $event->SetRedirectParam('module', $this->Application->GetVar('module')); $event->SetRedirectParam('section', $this->Application->GetVar('section'));