Code

* Fixes for department handling and comma characters
authorcajus <cajus@594d385d-05f5-0310-b6e9-bd551577e9d8>
Fri, 28 Apr 2006 13:38:16 +0000 (13:38 +0000)
committercajus <cajus@594d385d-05f5-0310-b6e9-bd551577e9d8>
Fri, 28 Apr 2006 13:38:16 +0000 (13:38 +0000)
* Includes debugging output, currently
* Needs schema update

git-svn-id: https://oss.gonicus.de/repositories/gosa/trunk@3168 594d385d-05f5-0310-b6e9-bd551577e9d8

plugins/admin/departments/class_departmentGeneric.inc
plugins/admin/departments/generic.tpl
plugins/admin/departments/tabs_department.inc

index 97bc429efb0fa555ffcd40184a475ebd6e7a555e..d1689a4f2104f9589dc805e34d1a9944ec4d2748 100644 (file)
@@ -44,7 +44,7 @@ class department extends plugin
 
        /* attribute list for save action */
        var $attributes= array("ou", "description", "businessCategory", "st", "l", "postalAddress",
-                       "telephoneNumber", "facsimileTelephoneNumber");
+                       "telephoneNumber", "facsimileTelephoneNumber", "gosaUnitTag");
        var $objectclasses= array("top", "gosaDepartment", "organizationalUnit");
 
        function department ($config, $dn)
@@ -75,7 +75,7 @@ class department extends plugin
                $this->acl= get_module_permission($acl, "department", $ui->dn);
 
                /* Is administrational Unit? */
-               if ($dn != "new" && in_array_ics('gosaAdministrationalUnit', $this->attrs['objectClass'])){
+               if ($dn != "new" && in_array_ics('gosaAdministrativeUnit', $this->attrs['objectClass'])){
                        $this->is_administrational_unit= true;
                }
        }
@@ -245,16 +245,51 @@ class department extends plugin
        /* Save to LDAP */
        function save()
        {
+               $ldap= $this->config->get_ldap_link();
+
                /* Add tag objects if needed */
                if ($this->is_administrational_unit){
-                       $this->objectclasses[]= "gosaAdministrationalUnit";
-                       $this->attributes[]= "gosaUnitTag";
-               } else {
-                       plugin::handle_object_tagging();
+                       $this->objectclasses[]= "gosaAdministrativeUnit";
+                       if ($this->gosaUnitTag == ""){
+
+                               /* It's unlikely, but check if already used... */
+                               $try= 5;
+                               $ldap->cd($this->config->current['BASE']);
+                               while ($try--){
+
+                                       /* Generate microtime stamp as tag */
+                                       list($usec, $sec)= explode(" ", microtime());
+                                       $time_stamp= preg_replace("/\./", "", $sec.$usec);
+
+                                       $ldap->search("(&(objectClass=gosaAdministrativeUnit)(gosaUnitTag=$time_stamp))",array("gosaUnitTag"));
+                                       if ($ldap->count() == 0){
+                                               break;
+                                       }
+                               }
+                               if($try == 0) {
+                                       print_red(_("Fatal error: Can't find an unused tag to mark the administrative unit!"));
+                                       return;
+                               }
+                               $this->gosaUnitTag= preg_replace("/\./", "", $sec.$usec);
+                       }
                }
 
                plugin::save();
 
+               /* Remove tag information if needed */
+               if (!$this->is_administrational_unit){
+                       $tmp= array();
+
+                       /* Remove gosaAdministrativeUnit from this plugin */
+                       foreach($this->attrs['objectClass'] as $oc){
+                               if (!preg_match("/^gosaAdministrativeUnit$/i", $oc)){
+                                       $tmp[]= $oc;
+                               }
+                       }
+                       $this->attrs['objectClass']= $tmp;
+                       $this->attrs['gosaUnitTag']= array();
+               }
+               
                /* Write back to ldap */
                $ldap= $this->config->get_ldap_link();
                $ldap->cat($this->dn);
@@ -283,16 +318,26 @@ class department extends plugin
        }
 
 
-       /* Tag objects to have the gosaAdministrationalUnitTag */
+       /* Tag objects to have the gosaAdministrativeUnitTag */
        function tag_objects()
        {
-               echo "Tag";
+               echo "<pre>Performing Tag:";
+               $ldap= $this->config->get_ldap_link();
+               $ldap->cd($this->dn);
+               $ldap->search('(!(&(objectClass=gosaAdministrativeUnitTag)(gosaUnitTag='.
+                               $this->gosaUnitTag.')))', array('dn'));
+               while ($attrs= $ldap->fetch()){
+                       //FIXME: check if this is below another administrative
+                       //       unit
+                       echo "Fix: ".$attrs['dn']."\n";
+               }
+               echo "</pre>";
        }
 
-       /* Remove the gosaAdministrationalUnitTag from objects */
+       /* Remove the gosaAdministrativeUnitTag from objects */
        function untag_objects()
        {
-               echo "Untag";
+               echo "Performing Untag:";
        }
 
        /* Move/Rename complete trees */
index 620c971ddddeeec0c6326931cb6137ba0dd2ffaf..45392db44053d5765a10118366e9f7d134b501c6 100644 (file)
@@ -74,7 +74,7 @@
 <table summary="" style="width:100%; vertical-align:top; text-align:left;" cellpadding=4>
  <tr>
    <td style="vertical-align:top; width:100%">
-     <h2><img class="center" alt="" align="middle" src="images/closedlock.png"> {t}Administrational settings{/t}</h2>
+     <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>
    </td>
index 4e8e318aff50761bd4001f24a928c822c947b72c..fb93bcf4b7872674bc2e4494720742f4118f1912 100644 (file)
@@ -20,7 +20,8 @@ class deptabs extends tabs
   {
        if(!$justsave){
                $baseobject= $this->by_object['department'];
-               $new_dn= 'ou='.preg_replace('/,/', '\\\\2C', $baseobject->ou).','.$baseobject->base;
+               $ou= preg_replace('/,/', '\,', $baseobject->ou);
+               $new_dn= @LDAP::convert('ou='.$ou.','.$baseobject->base);
                $disp ="";
                if ($this->dn != $new_dn && $this->dn != "new"){