Code

Updated plugin creation && locking for all main.incs
[gosa.git] / gosa-plugins / goto / admin / devices / class_deviceGeneric.inc
index d66c4906c4483cb26bd2a5818db6337285ae8fd1..0448b3bde477c104852c65bfc142a2dcb5f575ea 100644 (file)
@@ -9,16 +9,16 @@ class deviceGeneric extends plugin
   public $orig_dn       = "";
   public $description   = "";
   public $vendor        = "";
-  public $dev_id        = "";
+  public $devID        = "";
   public $serial        = "";
   public $base          = "";  
   public $types;
   public $type;
 
-  public $attributes      = array("cn","description","dev_id","serial","vendor", "type");
+  public $attributes      = array("cn","description","devID","serial","vendor", "type");
   public $objectclasses   = array("top","gotoDevice");
 
-  public $CopyPasteVars   = array("orig_cn","description","vendor","dev_id","serial","base");
+  public $CopyPasteVars   = array("orig_cn","description","vendor","devID","serial","base");
 
   public function deviceGeneric(&$config,$dn = NULL)
   {
@@ -36,7 +36,7 @@ class deviceGeneric extends plugin
       $tmp = preg_split("/\|/",$this->attrs['gotoHotplugDevice'][0]);
       $this->cn         = $this->attrs['cn'][0];
       $this->description= $tmp[0];
-      $this->dev_id     = $tmp[1];
+      $this->devID     = $tmp[1];
       $this->serial     = $tmp[2];
       $this->vendor     = $tmp[3];
       if (isset($tmp[4])){
@@ -55,7 +55,7 @@ class deviceGeneric extends plugin
         $this->base= dn2base($ui->dn);
       }
     } else {
-      $this->base =preg_replace ("/^[^,]+,".get_ou('deviceou')."/","",$this->dn);
+      $this->base =preg_replace ("/^[^,]+,".get_ou('deviceRDN')."/","",$this->dn);
     }
     $this->orig_base = $this->base;
     $this->orig_dn   = $this->dn;
@@ -86,7 +86,7 @@ class deviceGeneric extends plugin
   {
     $message = plugin::check();
 
-    if(empty($this->cn)||(preg_match("/[^a-z0-9]/i",$this->cn))){
+    if($this->cn == "" ||(preg_match("/[^a-z0-9]/i",$this->cn))){
       $message[]= msgPool::invalid(_("Name"),$this->cn,"/^[a-z0-9]*$/i");
     }
     if(preg_match("/[^a-z0-9!\"?.,;:-_\(\) ]/i",$this->description)){
@@ -94,8 +94,10 @@ class deviceGeneric extends plugin
     }
 
     /* Skip serial check if vendor and product id are given */
-    if(preg_match("/^\s+$/i",$this->dev_id)){
+    if(preg_match("/^\s+$/i",$this->devID)){
       $message[]= msgPool::invalid(_("iSerial"),"","01234");
+    }elseif(empty($this->devID) && $this->devID!="0"){
+      $message[]= msgPool::required(_("iSerial"));
     }
     if(empty($this->serial) || !$this->is_2byteHex($this->serial)){
       $message[]= msgPool::invalid(_("Serial"),"","","0x1234");
@@ -165,10 +167,16 @@ class deviceGeneric extends plugin
   {
     plugin::save();
 
-    $this->attrs = array();
-    $this->attrs['cn'] = $this->cn;
+    /* Unset non ldap attributes 
+     */
+    foreach(array("devID","serial","vendor", "type", "description") as $name){
+      if(isset($this->attrs[$name])){
+        unset($this->attrs[$name]);
+      }
+    }
+
     $this->attrs['gotoHotplugDevice'] = "";
-    foreach(array("description","dev_id","serial","vendor", "type") as $post){
+    foreach(array("description","devID","serial","vendor", "type") as $post){
       $this->attrs['gotoHotplugDevice'] .= $this->$post."|"; 
     }
     $this->attrs['gotoHotplugDevice'] = preg_replace("/\|$/","",$this->attrs['gotoHotplugDevice']);
@@ -252,10 +260,10 @@ class deviceGeneric extends plugin
             "cn"            => _("Name"),
             "base"          => _("Base"),
             "description"   => _("Description"),
-            "type"          => _("Tpye"),
+            "type"          => _("Type"),
             "serial"        => _("Serial"),
             "vendor"        => _("Vendor"), 
-            "dev_id"        => _("Devive ID"))
+            "devID"        => _("Device ID"))
           ));
 
   }