Code

When moving or renaming devices, check whether they are in use by a
[gosa.git] / trunk / gosa-plugins / goto / admin / devices / class_deviceGeneric.inc
index 00d63d0be6b084e48148f3002aed6cd8ff95dc57..cd83d097eef8294095971a63e1fbc34e89feb6ae 100644 (file)
@@ -100,12 +100,15 @@ class deviceGeneric extends plugin
       $message[]= msgPool::required(_("iSerial"));
     }
     if(empty($this->serial) || !$this->is_2byteHex($this->serial)){
-      $message[]= msgPool::invalid(_("Product ID"),"","","0x1234");
+      $message[]= msgPool::invalid(_("Product-ID"),"","","0x1234");
     }
     if(empty($this->vendor) || !$this->is_2byteHex($this->vendor)){
-      $message[]= msgPool::invalid(_("Vendor ID"),"","","0x1234");
+      $message[]= msgPool::invalid(_("Vendor-ID"),"","","0x1234");
     }
-  
+    /* Convert vendorId and productId to lower case */
+    $this->serial = strtolower($this->serial);
+    $this->vendor = strtolower($this->vendor);
+
     /* Check if entry already exists */ 
     if($this->cn != $this->orig_cn || $this->dn == "new"){
       $ldap = $this->config->get_ldap_link();
@@ -123,6 +126,21 @@ class deviceGeneric extends plugin
       $message[] = msgPool::permMove();
     }
 
+    if ($this->cn != $this->orig_cn || $this->base != $this->orig_base) { 
+
+      $ldap = $this->config->get_ldap_link();
+      $ldap->cd($this->config->current['BASE']);
+      $ldap->search("(&(objectClass=gotoEnvironment)(gotoHotplugDeviceDN=".LDAP::prepare4filter($this->orig_dn)."))",
+                    array("cn","uid"));
+      $obj = array();
+      while($attrs = $ldap->fetch()){
+        $obj[$ldap->getDN()]= $attrs['cn'][0];
+      }
+      if ($obj != array()) {
+        $message[] = msgPool::stillInUse(_("Device"), $obj);
+      }
+    }
+     
     return($message);
   }