X-Git-Url: https://git.tokkee.org/?a=blobdiff_plain;f=include%2Fclass_plugin.inc;fp=include%2Fclass_plugin.inc;h=d6678993073e7b0def6c7f63f478a5669ae80b68;hb=f6e4d295bf041f03b2822c6583468dce99094df8;hp=e84ddec657b4b875b855927b819211f7f6177b14;hpb=1c78453aa9b60798750f32e06f00a881da121a95;p=gosa.git diff --git a/include/class_plugin.inc b/include/class_plugin.inc index e84ddec65..d66789930 100644 --- a/include/class_plugin.inc +++ b/include/class_plugin.inc @@ -335,6 +335,8 @@ class plugin } } + /* Handle tagging */ + $this->tag_attrs(&$this->attrs); } @@ -892,6 +894,61 @@ 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; + } + + return ($at); + } + + function handle_object_tagging($dn= "", $tag= "", $show= false) { //FIXME: How to optimize this? We have at least two