Code

Added check to avoid overwriting entries
authorhickert <hickert@594d385d-05f5-0310-b6e9-bd551577e9d8>
Thu, 14 Apr 2011 13:50:32 +0000 (13:50 +0000)
committerhickert <hickert@594d385d-05f5-0310-b6e9-bd551577e9d8>
Thu, 14 Apr 2011 13:50:32 +0000 (13:50 +0000)
git-svn-id: https://oss.gonicus.de/repositories/gosa/trunk@20736 594d385d-05f5-0310-b6e9-bd551577e9d8

gosa-plugins/goto-ng/admin/newConfigManagement/TemplateEngine/class_TemplateEngine.inc
gosa-plugins/goto-ng/admin/newConfigManagement/class_newConfigManagement.inc

index ab768a8f7ab406b34a845a82a27e5307fa11e3b9..f5eb611b4c08c308deee07a8d30aea16b8889fe6 100644 (file)
@@ -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.
index 608c1344ff5aef2034eef04a919bf1fe76736d57..e10e16a99bbc2c27da4cfd7259eb4f6b00147d8b 100644 (file)
@@ -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);