Code

Updated get_ou it receives values from the config registry now.
[gosa.git] / gosa-plugins / goto / admin / devices / class_deviceGeneric.inc
index a92a9cbb7d7295c5e3857d5177064f7049e1ebf6..81993e1a2e27dc849553b26268feb8de091becd4 100644 (file)
@@ -5,19 +5,21 @@ class deviceGeneric extends plugin
   public $dn            = "";
   public $cn            = "";
   public $orig_cn       = "";
+  public $orig_base     = "";
+  public $orig_dn       = "";
   public $description   = "";
   public $vendor        = "";
-  public $dev_id        = "";
+  public $devID        = "";
   public $serial        = "";
   public $base          = "";  
   public $types;
   public $type;
+  public $baseSelector;
 
-  public $posts           = array("description","dev_id","serial","vendor", "type");
-  public $attributes      = array("cn");
+  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)
   {
@@ -35,7 +37,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])){
@@ -54,26 +56,36 @@ class deviceGeneric extends plugin
         $this->base= dn2base($ui->dn);
       }
     } else {
-      $this->base =preg_replace ("/^[^,]+,".get_ou('deviceou')."/","",$this->dn);
+      $this->base =preg_replace ("/^[^,]+,".preg_quote(get_ou("deviceGeneric", "deviceRDN") , '/')."/i","",$this->dn);
     }
+    $this->orig_base = $this->base;
+    $this->orig_dn   = $this->dn;
+
+    /* Instanciate base selector */
+    $this->baseSelector= new baseSelector($this->get_allowed_bases(), $this->base);
+    $this->baseSelector->setSubmitButton(false);
+    $this->baseSelector->setHeight(300);
+    $this->baseSelector->update(true);
   }
 
 
   public function execute()
   {
+    plugin::execute();
     $smarty = get_smarty();
-    $smarty->assign("base",$this->base);
-    $smarty->assign("bases",$this->get_allowed_bases());
+
+    $smarty->assign("base", $this->baseSelector->render());
     foreach($this->attributes as $attr){
       $smarty->assign($attr,$this->$attr);
     }
-    foreach($this->posts as $attr){
-      $smarty->assign($attr,$this->$attr);
+  
+    $tmp = $this->plInfo();
+    foreach($tmp['plProvidedAcls'] as $attr => $desc){
+      $smarty->assign($attr."ACL", $this->getacl($attr));
     }
 
     $smarty->assign("type",$this->type);
     $smarty->assign ("types", $this->types);
-
     return($smarty->fetch(get_template_path("deviceGeneric.tpl",TRUE,dirname(__FILE__))));
   }
 
@@ -82,7 +94,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)){
@@ -90,18 +102,25 @@ 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");
+      $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");
     }
-   
+
+    // Check if a wrong base was supplied
+    if(!$this->baseSelector->checkLastBaseUpdate()){
+      $message[]= msgPool::check_base();
+    }
+  
     /* Check if entry already exists */ 
-    if($this->cn != $this->orig_cn){
+    if($this->cn != $this->orig_cn || $this->dn == "new"){
       $ldap = $this->config->get_ldap_link();
       $ldap->search("(&(objectClass=gotoDevice)(cn=".$this->cn."*))",array("cn"));
       if($ldap->count()){
@@ -109,6 +128,14 @@ class deviceGeneric extends plugin
       }
     }
 
+    /* Check if we are allowed to create or move this object
+     */
+    if($this->orig_dn == "new" && !$this->acl_is_createable($this->base)){
+      $message[] = msgPool::permCreate();
+    }elseif($this->orig_dn != "new" && $this->base != $this->orig_base && !$this->acl_is_moveable($this->base)){
+      $message[] = msgPool::permMove();
+    }
+
     return($message);
   }
 
@@ -117,19 +144,18 @@ class deviceGeneric extends plugin
   {
     if(isset($_POST['deviceGeneric_posted'])){
       plugin::save_object();
-  
-      if(isset($_POST['base'])){
-        $tmp = $this->get_allowed_bases();
-        if(isset($tmp[get_post("base")])){
-          $this->base = get_post("base");
+
+      /* Refresh base */
+      if ($this->acl_is_moveable($this->base)){
+        if (!$this->baseSelector->update()) {
+          msg_dialog::display(_("Error"), msgPool::permMove(), ERROR_DIALOG);
         }
-      }
-    
-      foreach($this->posts as $post){
-        if(isset($_POST[$post])){
-          $this->$post = get_post($post);
+        if ($this->base != $this->baseSelector->getBase()) {
+          $this->base= $this->baseSelector->getBase();
+          $this->is_modified= TRUE;
         }
       }
+
     }
   }
 
@@ -159,8 +185,16 @@ class deviceGeneric extends plugin
   {
     plugin::save();
 
+    /* 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($this->posts as $post){
+    foreach(array("description","devID","serial","vendor", "type") as $post){
       $this->attrs['gotoHotplugDevice'] .= $this->$post."|"; 
     }
     $this->attrs['gotoHotplugDevice'] = preg_replace("/\|$/","",$this->attrs['gotoHotplugDevice']);
@@ -185,7 +219,7 @@ class deviceGeneric extends plugin
   /* check if given str in like this 0xffff*/
   function is_2byteHex($str)
   {
-    return !strlen($str) || preg_match("/^(0x|x|)[a-f0-9][a-f0-9][a-f0-9][a-f0-9]/i",$str);
+    return !strlen($str) || preg_match("/^(0x|x|)[a-f0-9]{4}$/i",$str);
   }
 
 
@@ -233,15 +267,33 @@ class deviceGeneric extends plugin
   {
     return (array(
           "plShortName"   => _("Generic"),
-          "plDescription" => _("Device generic"),
+          "plDescription" => _("Device generic")." ("._("Hotplug").")",
           "plSelfModify"  => FALSE,
           "plDepends"     => array(),
           "plPriority"    => 0,
           "plSection"     => array("administration"),
           "plCategory"    => array("devices" => array("description"  => _("Devices"),
                                                         "objectClass"  => "gotoHotplugDevice")),
+          "plProperties" =>
+          array(
+              array(
+                  "name"          => "deviceRDN",
+                  "type"          => "rdn",
+                  "default"       => "ou=devices,",
+                  "description"   => "The 'deviceRDN' statement defines the location where new devices will be created. The default is 'ou=devices,'.",
+                  "check"         => "gosaProperty::isRdn",
+                  "migrate"       => "",
+                  "group"         => "plugin",
+                  "mandatory"     => FALSE)),
+
           "plProvidedAcls"=> array(
-            "cn"                          => _("Name"))
+            "cn"            => _("Name"),
+            "base"          => _("Base"),
+            "description"   => _("Description"),
+            "type"          => _("Type"),
+            "serial"        => _("Serial"),
+            "vendor"        => _("Vendor"), 
+            "devID"        => _("Device ID"))
           ));
 
   }