Code

Removed return()
[gosa.git] / include / class_plugin.inc
index 5f2a567b741e14943f12e995f8806ad7fdf11580..9a25100ff3f3e3b25b20975f4325c4c02c8999aa 100644 (file)
@@ -335,6 +335,8 @@ class plugin
       }
     }
 
+    /* Handle tagging */
+    $this->tag_attrs(&$this->attrs);
   }
 
 
@@ -541,6 +543,12 @@ class plugin
     }
 
     if ($command != ""){
+
+      /* Additional attributes */
+      foreach ($add_attrs as $name => $value){
+        $command= preg_replace("/%$name/", $value, $command);
+      }
+
       /* Walk through attribute list */
       foreach ($this->attributes as $attr){
         if (!is_array($this->$attr)){
@@ -549,11 +557,6 @@ class plugin
       }
       $command= preg_replace("/%dn/", $this->dn, $command);
 
-      /* Additional attributes */
-      foreach ($add_attrs as $name => $value){
-        $command= preg_replace("/%$name/", $value, $command);
-      }
-
       if (check_command($command)){
         @DEBUG (DEBUG_SHELL, __LINE__, __FUNCTION__, __FILE__,
             $command, "Execute");
@@ -575,6 +578,12 @@ class plugin
     }
 
     if ($command != ""){
+
+      /* Additional attributes */
+      foreach ($add_attrs as $name => $value){
+        $command= preg_replace("/%$name/", $value, $command);
+      }
+
       /* Walk through attribute list */
       foreach ($this->attributes as $attr){
         if (!is_array($this->$attr)){
@@ -583,11 +592,6 @@ class plugin
       }
       $command= preg_replace("/%dn/", $this->dn, $command);
 
-      /* Additional attributes */
-      foreach ($add_attrs as $name => $value){
-        $command= preg_replace("/%$name/", $value, $command);
-      }
-
       if (check_command($command)){
         @DEBUG (DEBUG_SHELL, __LINE__, __FUNCTION__, __FILE__,
             $command, "Execute");
@@ -609,6 +613,12 @@ class plugin
     }
 
     if ($command != ""){
+
+      /* Additional attributes */
+      foreach ($add_attrs as $name => $value){
+        $command= preg_replace("/%$name/", $value, $command);
+      }
+
       /* Walk through attribute list */
       foreach ($this->attributes as $attr){
         if (!is_array($this->$attr)){
@@ -683,7 +693,7 @@ class plugin
   {
     /* Rename dn in possible object groups */
     $ldap= $this->config->get_ldap_link();
-    $ldap->search('(&(objectClass=gosaGroupOfNames)(member='.@LDAP::fix($src_dn).'))',
+    $ldap->search('(&(objectClass=gosaGroupOfNames)(member='.@LDAP::prepare4filter($src_dn).'))',
         array('cn'));
     while ($attrs= $ldap->fetch()){
       $og= new ogroup($this->config, $ldap->getDN());
@@ -884,6 +894,59 @@ class plugin
   }
 
 
+  function tag_attrs($at, $dn= "", $tag= "", $show= false)
+  {
+    /* No dn? Self-operation... */
+    if ($dn == ""){
+      $dn= $this->dn;
+    
+      /* No tag? Find it yourself... */
+      if ($tag == ""){
+        $len= strlen($dn);
+
+        @DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__, "No tag for $dn - looking for one...", "Tagging");
+        $relevant= array();
+        foreach ($this->config->adepartments as $key => $ntag){
+
+          /* This one is bigger than our dn, its not relevant... */
+          if ($len <= strlen($key)){
+            continue;
+          }
+
+          /* This one matches with the latter part. Break and don't fix this entry */
+          if (preg_match('/(^|,)'.normalizePreg($key).'$/', $dn)){
+            @DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__, "DEBUG: Possibly relevant: $key", "Tagging");
+            $relevant[strlen($key)]= $ntag;
+            continue;
+          }
+
+        }
+
+        /* If we've some relevant tags to set, just get the longest one */
+        if (count($relevant)){
+          ksort($relevant);
+          $tmp= array_keys($relevant);
+          $idx= end($tmp);
+          $tag= $relevant[$idx];
+          $this->gosaUnitTag= $tag;
+        }
+      }
+    }
+
+    /* Remove tags that may already be here... */
+    remove_objectClass("gosaAdministrativeUnitTag", &$at);
+    if (isset($at['gosaUnitTag'])){
+       unset($at['gosaUnitTag']);
+    }
+
+    /* Set tag? */
+    if ($tag != ""){
+      add_objectClass("gosaAdministrativeUnitTag", &$at);
+      $at['gosaUnitTag']= $tag;
+    }
+  }
+
+
   function handle_object_tagging($dn= "", $tag= "", $show= false)
   {
     //FIXME: How to optimize this? We have at least two