From: hickert Date: Thu, 14 Apr 2011 13:50:32 +0000 (+0000) Subject: Added check to avoid overwriting entries X-Git-Url: https://git.tokkee.org/?a=commitdiff_plain;h=dbff8bfadb7e12f89791d814757aa3f6cc5026fd;p=gosa.git Added check to avoid overwriting entries git-svn-id: https://oss.gonicus.de/repositories/gosa/trunk@20736 594d385d-05f5-0310-b6e9-bd551577e9d8 --- 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);