Code

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

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

index a0d5cf78e3d3e59d98e29c525767f28070072650..608c1344ff5aef2034eef04a919bf1fe76736d57 100644 (file)
@@ -464,6 +464,16 @@ class newConfigManagement extends plugin
         }
     }
 
+    function getUsedNamesForPath($path)
+    {
+        $item = $this->dataModel->getItemByPath($path);
+        $names = array();
+        foreach($item['children'] as $path => $data){
+            $names[] = $data['name'];
+        }
+        return($names);
+    }
+
 
     /*! \brief      Edits a selected list item.
      */
@@ -557,6 +567,8 @@ class newConfigManagement extends plugin
             return;
         }
 
+
+
         if($this->cfgItemMap[$type] != 'root'){
 
             // Save template engine modifications
@@ -580,6 +592,13 @@ 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);
@@ -596,6 +615,15 @@ 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);