From dbff8bfadb7e12f89791d814757aa3f6cc5026fd Mon Sep 17 00:00:00 2001 From: hickert Date: Thu, 14 Apr 2011 13:50:32 +0000 Subject: [PATCH] Added check to avoid overwriting entries git-svn-id: https://oss.gonicus.de/repositories/gosa/trunk@20736 594d385d-05f5-0310-b6e9-bd551577e9d8 --- .../TemplateEngine/class_TemplateEngine.inc | 2 +- .../class_newConfigManagement.inc | 60 ++++++++++--------- 2 files changed, 33 insertions(+), 29 deletions(-) diff --git a/gosa-plugins/goto-ng/admin/newConfigManagement/TemplateEngine/class_TemplateEngine.inc b/gosa-plugins/goto-ng/admin/newConfigManagement/TemplateEngine/class_TemplateEngine.inc index ab768a8f7..f5eb611b4 100644 --- a/gosa-plugins/goto-ng/admin/newConfigManagement/TemplateEngine/class_TemplateEngine.inc +++ b/gosa-plugins/goto-ng/admin/newConfigManagement/TemplateEngine/class_TemplateEngine.inc @@ -42,7 +42,7 @@ class TemplateEngine $this->template = $tmpl; } - + /*! \brief Returns the list of widgets which are currently used * by the template engine to render the plugin. * @return Array A list of widgets. diff --git a/gosa-plugins/goto-ng/admin/newConfigManagement/class_newConfigManagement.inc b/gosa-plugins/goto-ng/admin/newConfigManagement/class_newConfigManagement.inc index 608c1344f..e10e16a99 100644 --- a/gosa-plugins/goto-ng/admin/newConfigManagement/class_newConfigManagement.inc +++ b/gosa-plugins/goto-ng/admin/newConfigManagement/class_newConfigManagement.inc @@ -559,6 +559,36 @@ class newConfigManagement extends plugin function saveItemChanges() { + // Save template engine modifications and validate values. + $this->TemplateEngine->save_object(); + $msgs = $this->TemplateEngine->check(); + + // Get values to be saved + $values = array(); + foreach($this->TemplateEngine->getWidgets() as $w){ + $values[$w->getName()] = $w->getValue(); + } + + // No input error were found, now check that we do not use the same name twice. + if(!count($msgs)){ + $usedNames = $this->getUsedNamesForPath($this->selectedContainer); + + // Allow the item to keep its name. + if($this->currentObject != NULL && isset($this->currentObject['values']['name'])){ + $usedNames = array_remove_entries(array($this->currentObject['values']['name']), $usedNames); + } + if(in_array($values['name'],$usedNames)){ + $msgs[] = msgPool::duplicated(_("Name")); + } + } + + // Display errors + if(count($msgs)){ + msg_dialog::displayChecks($msgs); + return; + } + + // Get the item type to be saved $item = $this->currentObject; $type = $this->TemplateEngine->getItemType(); if($this->cfgItemMap[$type] == 'root'){ @@ -567,21 +597,11 @@ class newConfigManagement extends plugin return; } - - + // Save a CONFIG-ITEM object. if($this->cfgItemMap[$type] != 'root'){ - // Save template engine modifications - $this->TemplateEngine->save_object(); - $release = preg_replace("/^.*\//","", $this->getReleasePath($this->selectedContainer)); - - // Get values to be saved - $values = array(); - foreach($this->TemplateEngine->getWidgets() as $w){ - $values[$w->getName()] = $w->getValue(); - } - // Get paths + $release = preg_replace("/^.*\//","", $this->getReleasePath($this->selectedContainer)); $newPath = $this->selectedContainer."/".$values['name']; $newItemPath = $this->getItemPath($this->selectedContainer)."/".$values['name']; if($item){ @@ -592,13 +612,6 @@ class newConfigManagement extends plugin // If this is a new item, then create it now. if($item == NULL){ - // Validate item name - $usedNames = $this->getUsedNamesForPath($this->selectedContainer); - if(in_array($values['name'],$usedNames)){ - echo 'The name is used'; - return; - } - // Add the new item $rpc = $this->config->getRpcHandle(); $res = $rpc->setConfigItem($release, $newItemPath, $type, $values); @@ -615,15 +628,6 @@ class newConfigManagement extends plugin } }else{ - // Validate item name - if($item['name'] != $values['name']){ - $usedNames = $this->getUsedNamesForPath($this->selectedContainer); - if(in_array($values['name'],$usedNames)){ - echo 'The name is used'; - return; - } - } - // Write the modifications back to the server. $rpc = $this->config->getRpcHandle(); $res = $rpc->setConfigItem($release, $oldItemPath, $type, $values); -- 2.30.2