Code

Added ability to do department tagging
authorcajus <cajus@594d385d-05f5-0310-b6e9-bd551577e9d8>
Tue, 2 May 2006 05:08:31 +0000 (05:08 +0000)
committercajus <cajus@594d385d-05f5-0310-b6e9-bd551577e9d8>
Tue, 2 May 2006 05:08:31 +0000 (05:08 +0000)
git-svn-id: https://oss.gonicus.de/repositories/gosa/trunk@3176 594d385d-05f5-0310-b6e9-bd551577e9d8

include/class_config.inc
include/class_plugin.inc
plugins/admin/departments/class_departmentGeneric.inc
plugins/admin/departments/generic.tpl

index fa1823503c2786c6d0adaa39f61a5d2d93cf2b63..d13bcf5d919b2d3e1c477dbccc692ea8736de9b5 100644 (file)
@@ -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){
index 0926763c92172d08f8ec41c2d7172f3a5c04a4c8..10f4636d6ac62089839260ca8be6662ccd0f0c24 100644 (file)
@@ -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<br>";
-    /* Watch out for an administrative unit below own base */
-    #echo "<b>handle_object_tagging()</b><br><pre>";
-    #echo "DN  : ".$this->dn."\n";
-    #echo "Base: ".$this->config->current['BASE']."\n";
-    #echo "</pre>";
-
-    /* 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.<br>";
+
+      /* 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.<br>";
+
+      /* 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());
+      }
+    }
     
   }
 
index d1689a4f2104f9589dc805e34d1a9944ec4d2748..b9e54e3ca91d5b985bc3614a26b22f8f8f8e4695 100644 (file)
@@ -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 "<pre>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']."<br>";
+                       }
                }
-               echo "</pre>";
        }
 
-       /* Remove the gosaAdministrativeUnitTag from objects */
-       function untag_objects()
-       {
-               echo "Performing Untag:";
-       }
 
        /* Move/Rename complete trees */
        function recursive_move($src_dn, $dst_dn,$force = false)
index 45392db44053d5765a10118366e9f7d134b501c6..4bb2a07ac292cdcb2aa351d11085bf7d93cc3c77 100644 (file)
@@ -76,7 +76,7 @@
    <td style="vertical-align:top; width:100%">
      <h2><img class="center" alt="" align="middle" src="images/closedlock.png"> {t}Administrative settings{/t}</h2>
 
-     <input id="unitTag" type=checkbox name="unitTag" value="1" {$unitTag} {$unitTagACL}><label for="unitTag">{t}Tag department as an independent administrational unit{/t}</label>
+     <input id="unitTag" type=checkbox name="unitTag" value="1" {$unitTag} {$unitTagACL}><label for="unitTag">{t}Tag department as an independent administrative unit{/t}</label>
    </td>
   </tr>
 </table>