From: cajus Date: Tue, 2 May 2006 05:08:31 +0000 (+0000) Subject: Added ability to do department tagging X-Git-Url: https://git.tokkee.org/?a=commitdiff_plain;h=94b8aa0a58b057ecd52a37846bd0c5676df51702;p=gosa.git Added ability to do department tagging git-svn-id: https://oss.gonicus.de/repositories/gosa/trunk@3176 594d385d-05f5-0310-b6e9-bd551577e9d8 --- diff --git a/include/class_config.inc b/include/class_config.inc index fa1823503..d13bcf5d9 100644 --- a/include/class_config.inc +++ b/include/class_config.inc @@ -483,7 +483,7 @@ class config { /* Save administrative departments */ if (in_array_ics("gosaAdministrativeUnit", $attrs['objectClass']) && isset($attrs['gosaUnitTag'][0])){ - $administrative[$dn]= $attrs['gosaUnitTag']; + $administrative[$dn]= $attrs['gosaUnitTag'][0]; } if ($dn == $ignore_dn){ diff --git a/include/class_plugin.inc b/include/class_plugin.inc index 0926763c9..10f4636d6 100644 --- a/include/class_plugin.inc +++ b/include/class_plugin.inc @@ -319,7 +319,6 @@ class plugin } } - $this->handle_object_tagging(); } @@ -850,20 +849,59 @@ class plugin } - function handle_object_tagging() + function handle_object_tagging($dn= "", $tag= "") { - echo "Handle tagging
"; - /* Watch out for an administrative unit below own base */ - #echo "handle_object_tagging()
";
-    #echo "DN  : ".$this->dn."\n";
-    #echo "Base: ".$this->config->current['BASE']."\n";
-    #echo "
"; - - /* Make a base search on every department */ - //FIXME: evaluate if these informations should be cached, too - #$parts= split(',', preg_replace("/,".normalizePreg($this->config->current['BASE'])."$/", '', $this->dn)); - - /* Set objectclass and attribute */ + /* No dn? Self-operation... */ + if ($dn == ""){ + $dn= $this->dn; + } + + /* No tag? Find it yourself... */ + #.... + + /* Set tag? */ + if ($tag != ""){ + #echo "Add tagging ($tag) to $dn.
"; + + /* Set objectclass and attribute */ + $ldap= $this->config->get_ldap_link(); + $ldap->cat($dn); + $attrs= $ldap->fetch(); + $nattrs= array("gosaUnitTag" => $this->gosaUnitTag); + $nattrs['objectClass']= array(); + for ($i= 0; $i<$attrs['objectClass']['count']; $i++){ + $oc= $attrs['objectClass'][$i]; + if ($oc != "gosaAdministrativeUnitTag"){ + $nattrs['objectClass'][]= $oc; + } + } + $nattrs['objectClass'][]= "gosaAdministrativeUnitTag"; + $ldap->cd($dn); + $ldap->modify($nattrs); + if ($ldap->error != "Success"){ + print_red($ldap->get_error()); + } + } else { + #echo "Remove tagging from $dn.
"; + + /* Remove objectclass and attribute */ + $ldap= $this->config->get_ldap_link(); + $ldap->cat($dn); + $attrs= $ldap->fetch(); + $nattrs= array("gosaUnitTag" => array()); + $nattrs['objectClass']= array(); + for ($i= 0; $i<$attrs['objectClass']['count']; $i++){ + $oc= $attrs['objectClass'][$i]; + if ($oc != "gosaAdministrativeUnitTag"){ + $nattrs['objectClass'][]= $oc; + } + } + $ldap->cd($dn); + $ldap->modify($nattrs); + if ($ldap->error != "Success"){ + print_red($ldap->get_error()); + } + } } diff --git a/plugins/admin/departments/class_departmentGeneric.inc b/plugins/admin/departments/class_departmentGeneric.inc index d1689a4f2..b9e54e3ca 100644 --- a/plugins/admin/departments/class_departmentGeneric.inc +++ b/plugins/admin/departments/class_departmentGeneric.inc @@ -272,6 +272,8 @@ class department extends plugin } $this->gosaUnitTag= preg_replace("/\./", "", $sec.$usec); } + } else { + $this->gosaUnitTag= ""; } plugin::save(); @@ -287,7 +289,9 @@ class department extends plugin } } $this->attrs['objectClass']= $tmp; - $this->attrs['gosaUnitTag']= array(); + if(isset($this->attrs['gosaUnitTag'])){ + $this->attrs['gosaUnitTag']= array(); + } } /* Write back to ldap */ @@ -306,12 +310,7 @@ class department extends plugin $this->handle_post_events('add'); } show_ldap_error($ldap->get_error()); - - if ($this->is_administrational_unit){ - $this->tag_objects(); - } else { - $this->untag_objects(); - } + $this->tag_objects(); /* Optionally execute a command after we're done */ $this->postcreate(); @@ -321,24 +320,47 @@ class department extends plugin /* Tag objects to have the gosaAdministrativeUnitTag */ function tag_objects() { - echo "
Performing Tag:";
+		$add= $this->is_administrational_unit;
+		$len= strlen($this->dn);
 		$ldap= $this->config->get_ldap_link();
 		$ldap->cd($this->dn);
-		$ldap->search('(!(&(objectClass=gosaAdministrativeUnitTag)(gosaUnitTag='.
-				$this->gosaUnitTag.')))', array('dn'));
+		if ($add){
+			$ldap->search('(!(&(objectClass=gosaAdministrativeUnitTag)(gosaUnitTag='.
+					$this->gosaUnitTag.')))', array('dn'));
+		} else {
+			$ldap->search('objectClass=gosaAdministrativeUnitTag', array('dn'));
+		}
 		while ($attrs= $ldap->fetch()){
-			//FIXME: check if this is below another administrative
-			//       unit
-			echo "Fix: ".$attrs['dn']."\n";
+
+			/* Skip self */
+			if ($attrs['dn'] == $this->dn){
+				continue;
+			}
+
+			/* Check for confilicting administrative units */
+			$fix= true;
+			foreach ($this->config->adepartments as $key => $tag){
+				/* This one is shorter 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).'$/', $attrs['dn'])){
+					$fix= false;
+					break;
+				}
+			}
+			
+			/* Fix entry if needed */
+			if ($fix){
+				$this->handle_object_tagging($attrs['dn'], $this->gosaUnitTag);
+			} else {
+				echo "Don't touch: ".$attrs['dn']."
"; + } } - echo "
"; } - /* Remove the gosaAdministrativeUnitTag from objects */ - function untag_objects() - { - echo "Performing Untag:"; - } /* Move/Rename complete trees */ function recursive_move($src_dn, $dst_dn,$force = false) diff --git a/plugins/admin/departments/generic.tpl b/plugins/admin/departments/generic.tpl index 45392db44..4bb2a07ac 100644 --- a/plugins/admin/departments/generic.tpl +++ b/plugins/admin/departments/generic.tpl @@ -76,7 +76,7 @@

{t}Administrative settings{/t}

- +