Code

Updated tagging
[gosa.git] / gosa-core / plugins / admin / departments / class_departmentGeneric.inc
1 <?php
2 /*
3  * This code is part of GOsa (http://www.gosa-project.org)
4  * Copyright (C) 2003-2008 GONICUS GmbH
5  *
6  * ID: $$Id$$
7  *
8  * This program is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License as published by
10  * the Free Software Foundation; either version 2 of the License, or
11  * (at your option) any later version.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with this program; if not, write to the Free Software
20  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
21  */
23 class department extends plugin
24 {
25         /* department attributes */
26         var $ou= "";
27         var $description= "";
28         var $base= "";
29         var $st= "";
30         var $l= "";
31         var $postalAddress= "";
32         var $businessCategory= "";
33         var $telephoneNumber= "";
34         var $facsimileTelephoneNumber= "";
35         var $orig_dn= "";
36         var $is_administrational_unit= false;
37         var $gosaUnitTag= "";
38   var $view_logged = FALSE;
39         var $rec_dst=false;     // Destination for recursive move
40         var $rec_src=false;     // Source for recursive move 
41         var $rec_cpy=false;     // Is recursive move requested ? 
43         /* Headpage attributes */
44         var $last_dep_sorting= "invalid";
45         var $departments= array();
47   var $must_be_tagged = false;
49         /* attribute list for save action */
50         var $attributes= array("ou", "description", "businessCategory", "st", "l", "postalAddress",
51                         "telephoneNumber", "facsimileTelephoneNumber", "gosaUnitTag");
52         var $objectclasses= array("top", "gosaDepartment", "organizationalUnit");
53   var $initially_was_tagged = false;
55   var $orig_base = "";
56   var $orig_ou = "";
58         function department (&$config, $dn)
59         {
60   echo __FUNCTION__;
61                 plugin::plugin($config, $dn);
62                 $this->is_account= TRUE;
63                 $this->ui= get_userinfo();
64                 $this->dn= $dn;
65                 $this->orig_dn= $dn;
66                 $this->orig_ou= $this->ou;
67                 $this->config= $config;
69                 /* Set base */
70                 if ($this->dn == "new"){
71                         $ui= get_userinfo();
72                         if(session::is_set('CurrentMainBase')){
73                                 $this->base = session::get('CurrentMainBase');
74                         }else{
75                                 $this->base= dn2base($ui->dn);
76                         }
77                 } else {
78                         $this->base= preg_replace ("/^[^,]+,/", "", $this->dn);
79                 }
81     $this->orig_base = $this->base;
83                 /* Is administrational Unit? */
84                 if ($dn != "new" && in_array_ics('gosaAdministrativeUnit', $this->attrs['objectClass'])){
85                         $this->is_administrational_unit= true;
86       $this->initially_was_tagged = true;
87                 }
88         }
90         function execute()
91         {
92   echo __FUNCTION__."<br>";
93                 /* Call parent execute */
94                 plugin::execute();
96     /* Log view */
97     if($this->is_account && !$this->view_logged){
98       $this->view_logged = TRUE;
99       new log("view","department/".get_class($this),$this->dn);
100     }
102                 /* Reload departments */
103                 $this->config->get_departments($this->dn);
104                 $this->config->make_idepartments();
105                 $smarty= get_smarty();
107     $tmp = $this->plInfo();
108     foreach($tmp['plProvidedAcls'] as $name => $translation){
109       $smarty->assign($name."ACL",$this->getacl($name));
110     }
112                 /* Base select dialog */
113                 $once = true;
114                 foreach($_POST as $name => $value){
115                         if((preg_match("/^chooseBase/",$name) && $once) && ($this->acl_is_moveable())){
116                                 $once = false;
117                                 $this->dialog = new baseSelectDialog($this->config,$this,$this->get_allowed_bases());
118                                 $this->dialog->setCurrentBase($this->base);
119                         }
120                 }
122                 /* Dialog handling */
123                 if(is_object($this->dialog)){
124                         /* Must be called before save_object */
125                         $this->dialog->save_object();
127                         if($this->dialog->isClosed()){
128                                 $this->dialog = false;
129                         }elseif($this->dialog->isSelected()){
131         /* A new base was selected, check if it is a valid one */
132         $tmp = $this->get_allowed_bases();
133         if(isset($tmp[$this->dialog->isSelected()])){
134           $this->base = $this->dialog->isSelected();
135         }
136   
137                                 $this->dialog= false;
138                         }else{
139                                 return($this->dialog->execute());
140                         }
141                 }
143                 /* Hide all departments, that are subtrees of this department */
144     $bases = $this->get_allowed_bases();
145                 if(($this->dn == "new")||($this->dn == "")){
146                         $tmp = $bases;
147                 }else{
148                         $tmp    = array();      
149                         foreach($bases as $dn=>$base){
150                                 $fixed = str_replace("/","\\",$this->dn);
151                                 /* Only attach departments which are not a subtree of this one */
152                                 if(!preg_match("/".$fixed."/",$dn)){
153                                         $tmp[$dn]=$base;
154                                 }
155                         }
156                 }
157                 $smarty->assign("bases", $tmp);
159                 foreach ($this->attributes as $val){
160                         $smarty->assign("$val", $this->$val);
161                 }
162                 $smarty->assign("base_select", $this->base);
164     /* Set admin unit flag */
165     if ($this->is_administrational_unit) {
166       $smarty->assign("unitTag", "checked");
167     } else {
168       $smarty->assign("unitTag", "");
169     }
171                 return($smarty->fetch (get_template_path('generic.tpl', TRUE)));
172         }
174         function clear_fields()
175         {
176   echo __FUNCTION__."<br>";
177                 $this->dn   = "";
178                 $this->base = "";
180                 foreach ($this->attributes as $val){
181                         $this->$val= "";
182                 }
183         }
185         function remove_from_parent()
186         {
187   echo __FUNCTION__."<br>";
188                 $ldap= $this->config->get_ldap_link();
189                 $ldap->cd ($this->dn);
190                 $ldap->recursive_remove();
191     new log("remove","department/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error());
192     if (!$ldap->success()){
193       msg_dialog::display(_("LDAP error"), msgPool::ldaperror($ldap->get_error(), $this->dn, LDAP_DEL, get_class()));
194     }
196                 /* Optionally execute a command after we're done */
197                 $this->handle_post_events('remove');
198         }
200         function must_be_tagged()
201         {
202   echo __FUNCTION__."<br>";
203                 return $this->must_be_tagged;
204         }
206         function am_i_moved()
207         {
208   echo __FUNCTION__."<br>";
209                 return $this->rec_cpy;
210         }
213         /* Save data to object */
214         function save_object()
215         {
216   echo __FUNCTION__."<br>";
217                 if (isset($_POST['dep_generic_posted'])){
219       /* Create a base backup and reset the
220          base directly after calling plugin::save_object();
221          Base will be set seperatly a few lines below */
222       $base_tmp = $this->base;
223       plugin::save_object();
224       $this->base = $base_tmp;
226       /* Set new base if allowed */
227       $tmp = $this->get_allowed_bases();
228       if(isset($_POST['base'])){
229         if(isset($tmp[$_POST['base']])){
230           $this->base= $_POST['base'];
231         }
232       }
234       /* Save tagging flag */
235       if ($this->acl_is_writeable("unitTag")){
236         if (isset($_POST['unitTag'])){
237           $this->is_administrational_unit= true;
238         } else {
239           $this->is_administrational_unit= false;
240         }
241       }
242     }
243         }
246         /* Check values */
247         function check()
248         {
249   echo __FUNCTION__."<br>";
250                 /* Call common method to give check the hook */
251                 $message= plugin::check();
253                 /* Check for presence of this department */
254                 $ldap= $this->config->get_ldap_link();
255     $ldap->ls ("(&(ou=".$this->ou.")(objectClass=organizationalUnit))", $this->base, array('dn'));
256     if ($this->orig_dn == "new" && $ldap->count()){
257                         $message[]= msgPool::duplicated(_("Name"));
258                 } elseif ($this->orig_dn != $this->dn && !($attrs === FALSE)){
259                         $message[]= msgPool::duplicated(_("Name"));
260                 }
262                 /* All required fields are set? */
263                 if ($this->ou == ""){
264                         $message[]= _("Required field 'Name' is not set.");
265                         $message[]= msgPool::required(_("Name"));
266                 }
267                 if ($this->description == ""){
268                         $message[]= _("Required field 'Description' is not set.");
269                         $message[]= msgPool::required(_("Description"));
270                 }
272     if(tests::is_department_name_reserved($this->ou,$this->base)){
273       $message[]= msgPool::reserved(_("Name"));
274     }
276                 if (preg_match ('/[#+:=>\\\\\/]/', $this->ou)){
277                         $message[]= msgPool::invalid(_("Name"), $this->ou, "/[^#+:=>\\\\\/]/");
278                 }
279                 if (!tests::is_phone_nr($this->telephoneNumber)){
280                         $message[]= msgPool::invalid(_("Phone"), $this->telephoneNumber, "/[\/0-9 ()+*-]/");
281                 }
282                 if (!tests::is_phone_nr($this->facsimileTelephoneNumber)){
283                         $message[]= msgPool::invalid(_("Fax"), $this->facsimileTelephoneNumber, "/[\/0-9 ()+*-]/");
284                 }
286                 return $message;
287         }
290         /* Save to LDAP */
291         function save()
292         {
293   echo __FUNCTION__."<br>";
294                 $ldap= $this->config->get_ldap_link();
296     /* Add tag objects if needed */
297     if ($this->is_administrational_unit){
299       /* If this wasn't tagged before add oc an reset unit tag */
300       if(!$this->initially_was_tagged){
301         $this->objectclasses[]= "gosaAdministrativeUnit";
302         $this->gosaUnitTag= "";
304         /* It seams that this method is called twice, 
305            set this to true. to avoid adding this oc twice */
306         $this->initially_was_tagged = true;
307       }
309       if ($this->gosaUnitTag == ""){
311         /* It's unlikely, but check if already used... */
312         $try= 5;
313         $ldap->cd($this->config->current['BASE']);
314         while ($try--){
316           /* Generate microtime stamp as tag */
317           list($usec, $sec)= explode(" ", microtime());
318           $time_stamp= preg_replace("/\./", "", $sec.$usec);
320           $ldap->search("(&(objectClass=gosaAdministrativeUnit)(gosaUnitTag=$time_stamp))",array("gosaUnitTag"));
321           if ($ldap->count() == 0){
322             break;
323           }
324         }
325         if($try == 0) {
326           msg_dialog::display(_("Fatal error"), _("Cannot find an unused tag for this administrative unit!"), WARNING_DIALOG);
327           return;
328         }
329         $this->gosaUnitTag= preg_replace("/\./", "", $sec.$usec);
330       }
331     }
332     $this->skipTagging = TRUE;
333     plugin::save();
335     /* Remove tag information if needed */
336     if (!$this->is_administrational_unit){
337       $tmp= array();
339       /* Remove gosaAdministrativeUnit from this plugin */
340       foreach($this->attrs['objectClass'] as $oc){
341         if (!preg_match("/^gosaAdministrativeUnit$/i", $oc)){
342           $tmp[]= $oc;
343         }
344       }
345       $this->attrs['objectClass']= $tmp;
346     }
348     /* Do we need to remove the tag itself? */
349     $has_unit_tag= false;
350     foreach($this->attrs['objectClass'] as $oc){
351       if (preg_match("/^gosaAdministrativeUnitTag$/i", $oc)){
352         $has_unit_tag= true;
353       }
354     }
355     if ($has_unit_tag == false && $this->is_administrational_unit == false){
356       $this->attrs['gosaUnitTag']= array();
357     } else {
358       $this->attrs['gosaUnitTag']= $this->gosaUnitTag;
359     }
361                 /* Write back to ldap */
362                 $ldap->cat($this->dn, array('dn'));
363                 $ldap->cd($this->dn);
365                 if ($ldap->count()){
366                         $this->cleanup();
367                         $ldap->modify ($this->attrs); 
368       new log("modify","department/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error());
369                         $this->handle_post_events('modify');
370                 } else {
371                         $ldap->add($this->attrs);
372                         $this->handle_post_events('add');
373       new log("create","department/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error());
374                 }
375     if (!$ldap->success()){
376       msg_dialog::display(_("LDAP error"), msgPool::ldaperror($ldap->get_error(), $this->dn, 0, get_class()));
377     }
379     /* The parameter forces only to set must_be_tagged, and don't touch any objects 
380        This will be done later */
381     $this->tag_objects(true);
382     
383     /* Optionally execute a command after we're done */
384                 $this->postcreate();
385     return(false);
386         }
389   function ShowMoveFrame()
390   {
391   echo __FUNCTION__."<br>";
392     $smarty = get_smarty();
393     $smarty->assign("src","?plug=".$_GET['plug']."&amp;PerformRecMove&no_output_compression");
394     $smarty->assign("message","As soon as the move operation has finished, you can scroll down to end of the page and press the 'Continue' button to continue with the department management dialog.");
395     $display=  $smarty->fetch(get_template_path("dep_iframe.tpl",TRUE));
396     return($display);
397   }
399   function ShowTagFrame()
400   {
401   echo __FUNCTION__."<br>";
402     $smarty = get_smarty();
403     $smarty->assign("src","?plug=".$_GET['plug']."&TagDepartment&no_output_compression");
404     $smarty->assign("message","As soon as the tag operation has finished, you can scroll down to end of the page and press the 'Continue' button to continue with the department management dialog.");
405     $display=  $smarty->fetch(get_template_path("dep_iframe.tpl",TRUE));
406     return($display);
407   }
409         /* Tag objects to have the gosaAdministrativeUnitTag */
410         function tag_objects($OnlySetTagFlag = false)
411         {
412   echo __FUNCTION__."<br>";
413     if(!$OnlySetTagFlag){
414       $smarty= get_smarty();
415       /* Print out html introduction */
416       echo '  <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN">
417         <html>
418         <head>
419         <title></title>
420         <style type="text/css">@import url("themes/default/style.css");</style>
421         <script language="javascript" src="include/focus.js" type="text/javascript"></script>
422         </head>
423         <body style="background: none; margin:4px;" id="body" >
424         ';
425       echo "<h3>".sprintf(_("Tagging '%s'."),"<i>".@LDAP::fix($this->dn)."</i>")."</h3>";
426     }
428     $add= $this->is_administrational_unit;
429     $len= strlen($this->dn);
430     $ldap= $this->config->get_ldap_link();
431     $ldap->cd($this->dn);
432     if ($add){
433             $ldap->search('(!(&(objectClass=gosaAdministrativeUnitTag)(gosaUnitTag='.
434                                                     $this->gosaUnitTag.')))', array('dn'));
435     } else {
436             $ldap->search('objectClass=gosaAdministrativeUnitTag', array('dn'));
437     }
439     $objects = array();
440     while ($attrs= $ldap->fetch()){
441       $objects[] = $attrs;
442     }
443     foreach($objects as $attrs){
445             /* Skip self */
446             if ($attrs['dn'] == $this->dn){
447                     continue;
448             }
450             /* Check for confilicting administrative units */
451             $fix= true;
452             foreach ($this->config->adepartments as $key => $tag){
453                     /* This one is shorter than our dn, its not relevant... */
454                     if ($len >= strlen($key)){
455                             continue;
456                     }
458                     /* This one matches with the latter part. Break and don't fix this entry */
459                     if (preg_match('/(^|,)'.normalizePreg($key).'$/', $attrs['dn'])){
460                             $fix= false;
461                             break;
462                     }
463             }
465             /* Fix entry if needed */
466             if ($fix){
467                     if($OnlySetTagFlag){
468                             $this->must_be_tagged =true;
469                             return;
470                     }
471                     $this->handle_object_tagging($attrs['dn'], $this->gosaUnitTag, TRUE );
472             }
473     }
474     if(!$OnlySetTagFlag){
475             echo '<p class="seperator">&nbsp;</p>';
476             echo "<div style='width:100%;text-align:right;'><form name='form' method='post' action='?plug=".$_GET['plug']."' target='_parent'>
477                     <br><input type='submit' name='back' value='"._("Continue")."'>
478                     </form></div>";
479     }
480         }
483         /* Move/Rename complete trees */
484         function recursive_move($src_dn, $dst_dn,$force = false)
485         {
486   echo __FUNCTION__."<br>";
487     /* If force == false prepare to recursive move this object from src to dst 
488         on the next call. */
489                 if(!$force){
490                         $this->rec_cpy  = true;
491                         $this->rec_src  = $src_dn;
492                         $this->rec_dst  = $dst_dn;
493                 }else{
495       /* If this is called, but not wanted, abort */
496                         if(!$this->rec_cpy){ 
497                                 return;
498                         }
500                         $src_dn = $this->rec_src;
501                         $dst_dn = $this->rec_dst;
503                         /* Print header to have styles included */
504                         $smarty= get_smarty();
506       echo '  <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN">
507         <html>
508         <head>
509         <title></title>
510         <style type="text/css">@import url("themes/default/style.css");</style>
511         <script language="javascript" src="include/focus.js" type="text/javascript"></script>
512         </head>
513         <body style="background: none; margin:4px;" id="body" >
514         ';
515                         echo "<h3>".sprintf(_("Moving '%s' to '%s'"),"<i>".@LDAP::fix($src_dn)."</i>","<i>".@LDAP::fix($dst_dn)."</i>")."</h3>";
518                         /* Check if the destination entry exists */
519                         $ldap= $this->config->get_ldap_link();
521                         /* Check if destination exists - abort */
522                         $ldap->cat($dst_dn, array('dn'));
523                         if ($ldap->fetch()){
524                                 trigger_error("Recursive_move ".@LDAP::fix($dst_dn)." already exists.",
525                                                 E_USER_WARNING);
526                                 echo sprintf("Recursive_move: '%s' already exists", @LDAP::fix($dst_dn))."<br>"; 
527                                 return (FALSE);
528                         }
530                         /* Perform a search for all objects to be moved */
531                         $objects= array();
532                         $ldap->cd($src_dn);
533                         $ldap->search("(objectClass=*)", array("dn"));
534                         while($attrs= $ldap->fetch()){
535                                 $dn= $attrs['dn'];
536                                 $objects[$dn]= strlen($dn);
537                         }
539                         /* Sort objects by indent level */
540                         asort($objects);
541                         reset($objects);
543                         /* Copy objects from small to big indent levels by replacing src_dn by dst_dn */
544                         foreach ($objects as $object => $len){
547                                 $src= str_replace("\\","\\\\",$object);
548                                 $dst= preg_replace("/".str_replace("\\","\\\\",$src_dn)."$/", "$dst_dn", $object);
549                                 $dst= str_replace($src_dn,$dst_dn,$object);
551                                 echo "<b>"._("Object").":</b> ".@LDAP::fix($src)."<br>";
553         $this->update_acls($object, $dst,TRUE);
555                                 if (!$this->copy($src, $dst)){
556                                         echo "<font color='#FF0000'><br>".sprintf(_("FAILED to copy %s, aborting operation"),@LDAP::fix($src))."</font>";
557                                         return (FALSE);
558                                 }
559         echo "<script language=\"javascript\" type=\"text/javascript\">scrollDown2();</script>" ;
560                                 flush();
561                         }
563                         /* Remove src_dn */
564                         $ldap->cd($src_dn);
565                         $ldap->recursive_remove();
566       $this->dn = $this->rec_dst;
567                         $this->rec_src = $this->rec_dst = "";
568                         $this->rec_cpy =false;
570                         echo '<p class="seperator">&nbsp;</p>';
572                         echo "<div style='width:100%;text-align:right;'><form name='form' method='post' action='?plug=".$_GET['plug']."' target='_parent'>
573                                 <br><input type='submit' name='back' value='"._("Continue")."'>
574                                 </form></div>";
576       echo "<script language=\"javascript\" type=\"text/javascript\">scrollDown2();</script>" ;
577                         echo "</body></html>";
579                         return (TRUE);
580                 }
581         }
584   /* Return plugin informations for acl handling */ 
585   static function plInfo()
586   {
587   echo __FUNCTION__."<br>";
588     return (array("plShortName"   => _("Generic"),
589                   "plDescription" => _("Departments"),
590                   "plSelfModify"  => FALSE,
591                   "plPriority"    => 0,
592                   "plDepends"     => array(),
593                   "plSection"     => array("admin"),
594                   "plCategory"    => array("department" => array("objectClass" => "gosaDepartment", "description" => _("Departments"))),
595             
596                   "plProvidedAcls" => array(
597                     "description"       => _("Description"),
598                     "c"                 => _("Country"),
599                     "base"              => _("Base"),
600                     "l"                 => _("Location"),
601                     "telephoneNumber"   => _("Telephone"),
602                     "ou"                => _("Department name"),
603                     "businessCategory"  => _("Category"),
604                     "st"                => _("State"),
605                     "postalAddress"     => _("Address"),
606                     "gosaUnitTag"       => _("Administrative settings"),
607                     "facsimileTelephoneNumber" => _("Fax"))
608                   ));
609   }
611   function handle_object_tagging($dn= "", $tag= "", $show= false)
612   {
613   echo __FUNCTION__."<br>";
614     /* No dn? Self-operation... */
615     if ($dn == ""){
616       $dn= $this->dn;
618       /* No tag? Find it yourself... */
619       if ($tag == ""){
620         $len= strlen($dn);
622         @DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__, "No tag for $dn - looking for one...", "Tagging");
623         $relevant= array();
624         foreach ($this->config->adepartments as $key => $ntag){
626           /* This one is bigger than our dn, its not relevant... */
627           if ($len <= strlen($key)){
628             continue;
629           }
631           /* This one matches with the latter part. Break and don't fix this entry */
632           if (preg_match('/(^|,)'.normalizePreg($key).'$/', $dn)){
633             @DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__, "DEBUG: Possibly relevant: $key", "Tagging");
634             $relevant[strlen($key)]= $ntag;
635             continue;
636           }
638         }
640         /* If we've some relevant tags to set, just get the longest one */
641         if (count($relevant)){
642           ksort($relevant);
643           $tmp= array_keys($relevant);
644           $idx= end($tmp);
645           $tag= $relevant[$idx];
646           $this->gosaUnitTag= $tag;
647         }
648       }
649     }
651     /* Set tag? */
652     if ($tag != ""){
653       /* Set objectclass and attribute */
654       $ldap= $this->config->get_ldap_link();
655       $ldap->cat($dn, array('gosaUnitTag', 'objectClass'));
656       $attrs= $ldap->fetch();
657       if(isset($attrs['gosaUnitTag'][0]) && $attrs['gosaUnitTag'][0] == $tag){
658         if ($show) {
659           echo sprintf(_("Object '%s' is already tagged"), @LDAP::fix($dn))."<br>";
660           flush();
661         }
662         return;
663       }
664       if (count($attrs)){
665         if ($show){
666           echo sprintf(_("Adding tag (%s) to object '%s'"), $tag, @LDAP::fix($dn))."<br>";
667           flush();
668         }
669         $nattrs= array("gosaUnitTag" => $tag);
670         $nattrs['objectClass']= array();
671         for ($i= 0; $i<$attrs['objectClass']['count']; $i++){
672           $oc= $attrs['objectClass'][$i];
673           if ($oc != "gosaAdministrativeUnitTag"){
674             $nattrs['objectClass'][]= $oc;
675           }
676         }
677         $nattrs['objectClass'][]= "gosaAdministrativeUnitTag";
678         $ldap->cd($dn);
679         $ldap->modify($nattrs);
680         if (!$ldap->success()){
681           msg_dialog::display(_("LDAP error"), msgPool::ldaperror($ldap->get_error(), $dn, LDAP_MOD, get_class()));
682         }
683       } else {
684         @DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__, "Not tagging ($tag) $dn - seems to have moved away", "Tagging");
685       }
687     } else {
688       /* Remove objectclass and attribute */
689       $ldap= $this->config->get_ldap_link();
690       $ldap->cat($dn, array('gosaUnitTag', 'objectClass'));
691       $attrs= $ldap->fetch();
692       if (isset($attrs['objectClass']) && !in_array_ics("gosaAdministrativeUnitTag", $attrs['objectClass'])){
693         @DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__, "$dn is not tagged", "Tagging");
694         return;
695       }
696       if (count($attrs)){
697         if ($show){
698           echo sprintf(_("Removing tag from object '%s'"), @LDAP::fix($dn))."<br>";
699           flush();
700         }
701         $nattrs= array("gosaUnitTag" => array());
702         $nattrs['objectClass']= array();
703         for ($i= 0; $i<$attrs['objectClass']['count']; $i++){
704           $oc= $attrs['objectClass'][$i];
705           if ($oc != "gosaAdministrativeUnitTag"){
706             $nattrs['objectClass'][]= $oc;
707           }
708         }
709         $ldap->cd($dn);
710         $ldap->modify($nattrs);
711         if (!$ldap->success()){
712           msg_dialog::display(_("LDAP error"), msgPool::ldaperror($ldap->get_error(), $dn, LDAP_MOD, get_class()));
713         }
714       } else {
715         @DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__, "Not removing tag ($tag) $dn - seems to have moved away", "Tagging");
716       }
717     }
719   }
723 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
724 ?>