Code

Removed debug output.
[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 $is_administrational_unit= false;
36         var $gosaUnitTag= "";
37   var $view_logged = FALSE;
39   var $type ="ou";
40   var $namingAttr = "ou";
42         /* Headpage attributes */
43         var $last_dep_sorting= "invalid";
44         var $departments= array();
45   var $must_be_tagged = false;
47         /* attribute list for save action */
48         var $attributes= array("ou", "description", "businessCategory", "st", "l", "postalAddress",
49                         "telephoneNumber", "facsimileTelephoneNumber", "gosaUnitTag");
51   /* Do not append the structural object classes here, they are added dynamically in the constructor */
52         var $objectclasses= array("top", "gosaDepartment");
53   var $structuralOC = array("organizationalUnit");
55   var $initially_was_tagged = false;
56   var $orig_base = "";
57   var $orig_ou = "";
59         function department (&$config, $dn)
60         {
61     /* Add the default structural obejct class 'locality' if this is a new entry
62      */
63     $ldap = $config->get_ldap_link();
64     $ldap->cd($config->current['BASE']);
65     if($dn == "" || $dn == "new" || !$ldap->dn_exists($dn)){
66       $this->objectclasses = array_merge($this->structuralOC,$this->objectclasses);
67     }else{
68       $ldap->cat($dn, array("structuralObjectClass"));
69       $attrs= $ldap->fetch();
70       if(isset($attrs['structuralObjectClass']['count'])){
71         for($i = 0 ; $i < $attrs['structuralObjectClass']['count'] ; $i++){
72           $this->objectclasses[] = $attrs['structuralObjectClass'][$i];
73         }
74       }else{
76         /* Could not detect structural object class for this object, fall back to the default 'locality'
77          */
78         $this->objectclasses = array_merge($this->structuralOC,$this->objectclasses);
79       }
80     }
81     $this->objectclasses = array_unique($this->objectclasses);
83                 plugin::plugin($config, $dn);
84                 $this->is_account= TRUE;
85                 $this->ui= get_userinfo();
86                 $this->dn= $dn;
87                 $this->orig_dn= $dn;
89     /* Save current naming attribuet 
90      */
91     $nA      = $this->namingAttr;
92     $orig_nA = "orig_".$nA;
93     $this->$orig_nA = $this->$nA;
95                 $this->config= $config;
97                 /* Set base */
98                 if ($this->dn == "new"){
99                         $ui= get_userinfo();
100                         if(session::is_set('CurrentMainBase')){
101                                 $this->base = session::get('CurrentMainBase');
102                         }else{
103                                 $this->base= dn2base($ui->dn);
104                         }
105                 } else {
106                         $this->base= preg_replace ("/^[^,]+,/", "", $this->dn);
107                 }
109     $this->orig_base = $this->base;
111                 /* Is administrational Unit? */
112                 if ($dn != "new" && in_array_ics('gosaAdministrativeUnit', $this->attrs['objectClass'])){
113                         $this->is_administrational_unit= true;
114       $this->initially_was_tagged = true;
115                 }
116         }
118         function execute()
119         {
120                 /* Call parent execute */
121                 plugin::execute();
123     /* Log view */
124     if($this->is_account && !$this->view_logged){
125       $this->view_logged = TRUE;
126       new log("view","department/".get_class($this),$this->dn);
127     }
129                 /* Reload departments */
130                 $this->config->get_departments($this->dn);
131                 $this->config->make_idepartments();
132                 $smarty= get_smarty();
134     $tmp = $this->plInfo();
135     foreach($tmp['plProvidedAcls'] as $name => $translation){
136       $smarty->assign($name."ACL",$this->getacl($name));
137     }
139     /* Hide base selector, if this object represents the base itself 
140      */
141     $smarty->assign("is_root_dse", FALSE);
142     if($this->dn == $this->config->current['BASE']){
143       $smarty->assign("is_root_dse", TRUE);
144       $nA = $this->namingAttr."ACL";
145       $smarty->assign($nA,$this->getacl($this->namingAttr,TRUE));
146     }
148                 /* Base select dialog */
149                 $once = true;
150                 foreach($_POST as $name => $value){
151                         if((preg_match("/^chooseBase/",$name) && $once) && ($this->acl_is_moveable())){
152                                 $once = false;
153                                 $this->dialog = new baseSelectDialog($this->config,$this,$this->get_allowed_bases());
154                                 $this->dialog->setCurrentBase($this->base);
155                         }
156                 }
158                 /* Dialog handling */
159                 if(is_object($this->dialog)){
160                         /* Must be called before save_object */
161                         $this->dialog->save_object();
163                         if($this->dialog->isClosed()){
164                                 $this->dialog = false;
165                         }elseif($this->dialog->isSelected()){
167         /* A new base was selected, check if it is a valid one */
168         $tmp = $this->get_allowed_bases();
169         if(isset($tmp[$this->dialog->isSelected()])){
170           $this->base = $this->dialog->isSelected();
171         }
172   
173                                 $this->dialog= false;
174                         }else{
175                                 return($this->dialog->execute());
176                         }
177                 }
179                 /* Hide all departments, that are subtrees of this department */
180     $bases = $this->get_allowed_bases();
181                 if(($this->dn == "new")||($this->dn == "")){
182                         $tmp = $bases;
183                 }else{
184                         $tmp    = array();      
185                         foreach($bases as $dn=>$base){
186                                 /* Only attach departments which are not a subtree of this one */
187         if(!preg_match("/".preg_quote($this->dn)."/",$dn)){
188                                         $tmp[$dn]=$base;
189                                 }
190                         }
191                 }
192                 $smarty->assign("bases", $tmp);
194                 foreach ($this->attributes as $val){
195                         $smarty->assign("$val", $this->$val);
196                 }
197                 $smarty->assign("base_select", $this->base);
199     /* Set admin unit flag */
200     if ($this->is_administrational_unit) {
201       $smarty->assign("gosaUnitTag", "checked");
202     } else {
203       $smarty->assign("gosaUnitTag", "");
204     }
206     $smarty->assign("dep_type",$this->type);
207     
209     $dep_types = departmentManagement::get_support_departments();
210     $tpl ="";
211     foreach($dep_types as $key => $data){
212       if($data['ATTR'] == $this->type){
213         $tpl = $data['TPL'];
214         break;
215       }
216     }
217     if($tpl == "") {
218       trigger_error("No template specified for container type '".$this->type."', please update epartmentManagement::get_support_departments().");
219       $tpl = "generic.tpl";
220     }
221                 return($smarty->fetch (get_template_path($tpl, TRUE)));
222         }
224         function clear_fields()
225         {
226                 $this->dn   = "";
227                 $this->base = "";
229                 foreach ($this->attributes as $val){
230                         $this->$val= "";
231                 }
232         }
234         function remove_from_parent()
235         {
236                 $ldap= $this->config->get_ldap_link();
237                 $ldap->cd ($this->dn);
238                 $ldap->rmdir_recursive($this->dn);
239     new log("remove","department/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error());
240     if (!$ldap->success()){
241       msg_dialog::display(_("LDAP error"), msgPool::ldaperror($ldap->get_error(), $this->dn, LDAP_DEL, get_class()));
242     }
244                 /* Optionally execute a command after we're done */
245                 $this->handle_post_events('remove');
246         }
248         function must_be_tagged()
249         {
250                 return $this->must_be_tagged;
251         }
253         /* Save data to object */
254         function save_object()
255         {
256     if (isset($_POST['dep_generic_posted'])){
258       $nA = $this->namingAttr;
259       $old_nA = $this->$nA;
263       /* Create a base backup and reset the
264          base directly after calling plugin::save_object();
265          Base will be set seperatly a few lines below */
266       $base_tmp = $this->base;
267       plugin::save_object();
268       $this->base = $base_tmp;
270       /* Set new base if allowed */
271       $tmp = $this->get_allowed_bases();
272       if(isset($_POST['base'])){
273         if(isset($tmp[$_POST['base']])){
274           $this->base= $_POST['base'];
275         }
276       }
278       /* Save tagging flag */
279       if ($this->acl_is_writeable("gosaUnitTag")){
280         if (isset($_POST['is_administrational_unit'])){
281           $this->is_administrational_unit= true;
282         } else {
283           $this->is_administrational_unit= false;
284         }
285       }
287       /* If this is the root directory service entry (rootDSE)
288          then avoid changing the naming attribute of this entry.
289        */
290       if($this->dn == $this->config->current['BASE']){
291         $this->$nA = $old_nA;
292       }
293     }
294         }
297         /* Check values */
298         function check()
299         {
300                 /* Call common method to give check the hook */
301                 $message= plugin::check();
303                 /* Check for presence of this department */
304                 $ldap= $this->config->get_ldap_link();
305     $ldap->ls ("(&(ou=".$this->ou.")(objectClass=organizationalUnit))", $this->base, array('dn'));
306     if ($this->orig_dn == "new" && $ldap->count()){
307                         $message[]= msgPool::duplicated(_("Name"));
308                 } elseif ($this->orig_dn != $this->dn && $ldap->count()){
309                         $message[]= msgPool::duplicated(_("Name"));
310                 }
312                 /* All required fields are set? */
313                 if ($this->ou == ""){
314                         $message[]= msgPool::required(_("Name"));
315                 }
316                 if ($this->description == ""){
317                         $message[]= msgPool::required(_("Description"));
318                 }
320     if(tests::is_department_name_reserved($this->ou,$this->base)){
321       $message[]= msgPool::reserved(_("Name"));
322     }
324                 if (preg_match ('/[#+:=>\\\\\/]/', $this->ou)){
325                         $message[]= msgPool::invalid(_("Name"), $this->ou, "/[^#+:=>\\\\\/]/");
326                 }
327                 if (!tests::is_phone_nr($this->telephoneNumber)){
328                         $message[]= msgPool::invalid(_("Phone"), $this->telephoneNumber, "/[\/0-9 ()+*-]/");
329                 }
330                 if (!tests::is_phone_nr($this->facsimileTelephoneNumber)){
331                         $message[]= msgPool::invalid(_("Fax"), $this->facsimileTelephoneNumber, "/[\/0-9 ()+*-]/");
332                 }
334     /* Check if we are allowed to create or move this object
335      */
336     if($this->orig_dn == "new" && !$this->acl_is_createable($this->base)){
337       $message[] = msgPool::permCreate();
338     }elseif($this->orig_dn != "new" && $this->base != $this->orig_base && !$this->acl_is_moveable($this->base)){
339       $message[] = msgPool::permMove();
340     }
342     return $message;
343         }
346         /* Save to LDAP */
347         function save()
348         {
349                 $ldap= $this->config->get_ldap_link();
351     /* Ensure that ou is saved too, it is required by objectClass gosaDepartment 
352      */
353     $nA = $this->namingAttr;
354     $this->ou = $this->$nA;
356     /* Add tag objects if needed */
357     if ($this->is_administrational_unit){
359       /* If this wasn't tagged before add oc an reset unit tag */
360       if(!$this->initially_was_tagged){
361         $this->objectclasses[]= "gosaAdministrativeUnit";
362         $this->gosaUnitTag= "";
364         /* It seams that this method is called twice, 
365            set this to true. to avoid adding this oc twice */
366         $this->initially_was_tagged = true;
367       }
369       if ($this->gosaUnitTag == ""){
371         /* It's unlikely, but check if already used... */
372         $try= 5;
373         $ldap->cd($this->config->current['BASE']);
374         while ($try--){
376           /* Generate microtime stamp as tag */
377           list($usec, $sec)= explode(" ", microtime());
378           $time_stamp= preg_replace("/\./", "", $sec.$usec);
380           $ldap->search("(&(objectClass=gosaAdministrativeUnit)(gosaUnitTag=$time_stamp))",array("gosaUnitTag"));
381           if ($ldap->count() == 0){
382             break;
383           }
384         }
385         if($try == 0) {
386           msg_dialog::display(_("Fatal error"), _("Cannot find an unused tag for this administrative unit!"), WARNING_DIALOG);
387           return;
388         }
389         $this->gosaUnitTag= preg_replace("/\./", "", $sec.$usec);
390       }
391     }
392     $this->skipTagging = TRUE;
393     plugin::save();
396     /* Remove tag information if needed */
397     if (!$this->is_administrational_unit && $this->initially_was_tagged){
398       $tmp= array();
400       /* Remove gosaAdministrativeUnit from this plugin */
401       $has_unit_tag= false;
402       foreach($this->attrs['objectClass'] as $oc){
403         if (!preg_match("/^gosaAdministrativeUnit$/i", $oc)){
404           $tmp[]= $oc;
405         }
406         if (preg_match("/^gosaAdministrativeUnitTag$/i", $oc)){
407           $has_unit_tag= true;
408         }
409       }
410       $this->attrs['objectClass']= $tmp;
411       $this->attrs['gosaUnitTag']= array();
412       $this->gosaUnitTag = "";
413     }
416                 /* Write back to ldap */
417                 $ldap->cat($this->dn, array('dn'));
418                 $ldap->cd($this->dn);
420                 if ($ldap->count()){
421                         $this->cleanup();
422                         $ldap->modify ($this->attrs); 
423       new log("modify","department/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error());
424                         $this->handle_post_events('modify');
425                 } else {
426                         $ldap->add($this->attrs);
427                         $this->handle_post_events('add');
428       new log("create","department/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error());
429                 }
430     if (!$ldap->success()){
431       msg_dialog::display(_("LDAP error"), msgPool::ldaperror($ldap->get_error(), $this->dn, 0, get_class()));
432     }
434     /* The parameter forces only to set must_be_tagged, and don't touch any objects 
435        This will be done later */
436     $this->tag_objects(true);
437     
438     /* Optionally execute a command after we're done */
439                 $this->postcreate();
440     return(false);
441         }
444         /* Tag objects to have the gosaAdministrativeUnitTag */
445         function tag_objects($OnlySetTagFlag = false)
446         {
447     if(!$OnlySetTagFlag){
448       $smarty= get_smarty();
449       /* Print out html introduction */
450       echo '  <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN">
451         <html>
452         <head>
453         <title></title>
454         <style type="text/css">@import url("themes/default/style.css");</style>
455         <script language="javascript" src="include/focus.js" type="text/javascript"></script>
456         </head>
457         <body style="background: none; margin:4px;" id="body" >
458         ';
459       echo "<h3>".sprintf(_("Tagging '%s'."),"<i>".LDAP::fix($this->dn)."</i>")."</h3>";
460     }
462     $add= $this->is_administrational_unit;
463     $len= strlen($this->dn);
464     $ldap= $this->config->get_ldap_link();
465     $ldap->cd($this->dn);
466     if ($add){
467             $ldap->search('(!(&(objectClass=gosaAdministrativeUnitTag)(gosaUnitTag='.
468                                                     $this->gosaUnitTag.')))', array('dn'));
469     } else {
470             $ldap->search('objectClass=gosaAdministrativeUnitTag', array('dn'));
471     }
473     $objects = array();
474     while ($attrs= $ldap->fetch()){
475       $objects[] = $attrs;
476     }
477     foreach($objects as $attrs){
479             /* Skip self */
480             if ($attrs['dn'] == $this->dn){
481                     continue;
482             }
484             /* Check for confilicting administrative units */
485             $fix= true;
486             foreach ($this->config->adepartments as $key => $tag){
487                     /* This one is shorter than our dn, its not relevant... */
488                     if ($len >= strlen($key)){
489                             continue;
490                     }
492                     /* This one matches with the latter part. Break and don't fix this entry */
493                     if (preg_match('/(^|,)'.preg_quote($key, '/').'$/', $attrs['dn'])){
494                             $fix= false;
495                             break;
496                     }
497             }
499             /* Fix entry if needed */
500             if ($fix){
501                     if($OnlySetTagFlag){
502                             $this->must_be_tagged =true;
503                             return;
504                     }
505                     $this->handle_object_tagging($attrs['dn'], $this->gosaUnitTag, TRUE );
506         echo "<script language=\"javascript\" type=\"text/javascript\">scrollDown2();</script>" ;
507             }
508     }
509     
510     if(!$OnlySetTagFlag){
511       $this->must_be_tagged = FALSE;
512             echo '<p class="seperator">&nbsp;</p>';
513       echo "<div style='width:100%;text-align:right;'>".
514         "<form name='form' method='post' action='?plug=".$_GET['plug']."' target='_parent'>".
515         "<br>".
516         "<input type='submit' name='back' value='"._("Continue")."'>".
517         "<input type='hidden' name='php_c_check' value='1'>".
518         "</form>".
519         "</div>";
520       echo "<script language=\"javascript\" type=\"text/javascript\">scrollDown2();</script>" ;
521     }
522         }
525         /* Move/Rename complete trees */
526         function recursive_move($src_dn, $dst_dn,$force = false)
527         {
528     /* Print header to have styles included */
529     $smarty= get_smarty();
531     echo '  <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN">
532       <html>
533       <head>
534       <title></title>
535       <style type="text/css">@import url("themes/default/style.css");</style>
536       <script language="javascript" src="include/focus.js" type="text/javascript"></script>
537       </head>
538       <body style="background: none; margin:4px;" id="body" >
539       ';
540     echo "<h3>".sprintf(_("Moving '%s' to '%s'"),"<i>".LDAP::fix($src_dn)."</i>","<i>".LDAP::fix($dst_dn)."</i>")."</h3>";
543     /* Check if the destination entry exists */
544     $ldap= $this->config->get_ldap_link();
546     /* Check if destination exists - abort */
547     $ldap->cat($dst_dn, array('dn'));
548     if ($ldap->fetch()){
549       trigger_error("Recursive_move ".LDAP::fix($dst_dn)." already exists.",
550           E_USER_WARNING);
551       echo sprintf("Recursive_move: '%s' already exists", LDAP::fix($dst_dn))."<br>"; 
552       return (FALSE);
553     }
555     /* Perform a search for all objects to be moved */
556     $objects= array();
557     $ldap->cd($src_dn);
558     $ldap->search("(objectClass=*)", array("dn"));
559     while($attrs= $ldap->fetch()){
560       $dn= $attrs['dn'];
561       $objects[$dn]= strlen($dn);
562     }
564     /* Sort objects by indent level */
565     asort($objects);
566     reset($objects);
568     /* Copy objects from small to big indent levels by replacing src_dn by dst_dn */
569     foreach ($objects as $object => $len){
572       $src= str_replace("\\","\\\\",$object);
573       $dst= preg_replace("/".str_replace("\\","\\\\",$src_dn)."$/", "$dst_dn", $object);
574       $dst= str_replace($src_dn,$dst_dn,$object);
576       echo "<b>"._("Object").":</b> ".LDAP::fix($src)."<br>";
578       $this->update_acls($object, $dst,TRUE);
580       if (!$this->copy($src, $dst)){
581         echo "<font color='#FF0000'><br>".sprintf(_("FAILED to copy %s, aborting operation"),LDAP::fix($src))."</font>";
582         return (FALSE);
583       }
584       echo "<script language=\"javascript\" type=\"text/javascript\">scrollDown2();</script>" ;
585       flush();
586     }
588     /* Remove src_dn */
589     $ldap->cd($src_dn);
590     $ldap->recursive_remove();
591     $this->orig_dn  = $this->dn = $dst_dn;
592     $this->orig_base= $this->base;     
593     $this->entryCSN = getEntryCSN($this->dn);
595     echo '<p class="seperator">&nbsp;</p>';
597     echo "<div style='width:100%;text-align:right;'><form name='form' method='post' action='?plug=".$_GET['plug']."' target='_parent'>
598       <br><input type='submit' name='back' value='"._("Continue")."'>
599       </form></div>";
601     echo "<script language=\"javascript\" type=\"text/javascript\">scrollDown2();</script>" ;
602     echo "</body></html>";
604     return (TRUE);
605   }
608   /* Return plugin informations for acl handling */ 
609   static function plInfo()
610   {
611     return (array("plShortName"   => _("Generic"),
612                   "plDescription" => _("Departments"),
613                   "plSelfModify"  => FALSE,
614                   "plPriority"    => 0,
615                   "plDepends"     => array(),
616                   "plSection"     => array("administration"),
617                   "plCategory"    => array("department" => array("objectClass" => "gosaDepartment", "description" => _("Departments"))),
618             
619                   "plProvidedAcls" => array(
620                     "ou"                => _("Department name"),
621                     "description"       => _("Description"),
622                     "businessCategory"  => _("Category"),
623                     "base"              => _("Base"),
625                     "st"                => _("State"),
626                     "l"                 => _("Location"),
627                     "postalAddress"     => _("Address"),
628                     "telephoneNumber"   => _("Telephone"),
629                     "facsimileTelephoneNumber" => _("Fax"),
631                     "gosaUnitTag"       => _("Administrative settings"))
632                   ));
633   }
635   function handle_object_tagging($dn= "", $tag= "", $show= false)
636   {
637     /* No dn? Self-operation... */
638     if ($dn == ""){
639       $dn= $this->dn;
641       /* No tag? Find it yourself... */
642       if ($tag == ""){
643         $len= strlen($dn);
645         @DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__, "No tag for $dn - looking for one...", "Tagging");
646         $relevant= array();
647         foreach ($this->config->adepartments as $key => $ntag){
649           /* This one is bigger than our dn, its not relevant... */
650           if ($len <= strlen($key)){
651             continue;
652           }
654           /* This one matches with the latter part. Break and don't fix this entry */
655           if (preg_match('/(^|,)'.preg_quote($key, '/').'$/', $dn)){
656             @DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__, "DEBUG: Possibly relevant: $key", "Tagging");
657             $relevant[strlen($key)]= $ntag;
658             continue;
659           }
661         }
663         /* If we've some relevant tags to set, just get the longest one */
664         if (count($relevant)){
665           ksort($relevant);
666           $tmp= array_keys($relevant);
667           $idx= end($tmp);
668           $tag= $relevant[$idx];
669           $this->gosaUnitTag= $tag;
670         }
671       }
672     }
674     /* Set tag? */
675     if ($tag != ""){
676       /* Set objectclass and attribute */
677       $ldap= $this->config->get_ldap_link();
678       $ldap->cat($dn, array('gosaUnitTag', 'objectClass'));
679       $attrs= $ldap->fetch();
680       if(isset($attrs['gosaUnitTag'][0]) && $attrs['gosaUnitTag'][0] == $tag){
681         if ($show) {
682           echo sprintf(_("Object '%s' is already tagged"), LDAP::fix($dn))."<br>";
683           flush();
684         }
685         return;
686       }
687       if (count($attrs)){
688         if ($show){
689           echo sprintf(_("Adding tag (%s) to object '%s'"), $tag, LDAP::fix($dn))."<br>";
690           flush();
691         }
692         $nattrs= array("gosaUnitTag" => $tag);
693         $nattrs['objectClass']= array();
694         for ($i= 0; $i<$attrs['objectClass']['count']; $i++){
695           $oc= $attrs['objectClass'][$i];
696           if ($oc != "gosaAdministrativeUnitTag"){
697             $nattrs['objectClass'][]= $oc;
698           }
699         }
700         $nattrs['objectClass'][]= "gosaAdministrativeUnitTag";
701         $ldap->cd($dn);
702         $ldap->modify($nattrs);
703         if (!$ldap->success()){
704           msg_dialog::display(_("LDAP error"), msgPool::ldaperror($ldap->get_error(), $dn, LDAP_MOD, get_class()));
705         }
706       } else {
707         @DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__, "Not tagging ($tag) $dn - seems to have moved away", "Tagging");
708       }
710     } else {
711       /* Remove objectclass and attribute */
712       $ldap= $this->config->get_ldap_link();
713       $ldap->cat($dn, array('gosaUnitTag', 'objectClass'));
714       $attrs= $ldap->fetch();
715       if (isset($attrs['objectClass']) && !in_array_ics("gosaAdministrativeUnitTag", $attrs['objectClass'])){
716         @DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__, "$dn is not tagged", "Tagging");
717         return;
718       }
719       if (count($attrs)){
720         if ($show){
721           echo sprintf(_("Removing tag from object '%s'"), LDAP::fix($dn))."<br>";
722           flush();
723         }
724         $nattrs= array("gosaUnitTag" => array());
725         $nattrs['objectClass']= array();
726         for ($i= 0; $i<$attrs['objectClass']['count']; $i++){
727           $oc= $attrs['objectClass'][$i];
728           if ($oc != "gosaAdministrativeUnitTag"){
729             $nattrs['objectClass'][]= $oc;
730           }
731         }
732         $ldap->cd($dn);
733         $ldap->modify($nattrs);
734         if (!$ldap->success()){
735           msg_dialog::display(_("LDAP error"), msgPool::ldaperror($ldap->get_error(), $dn, LDAP_MOD, get_class()));
736         }
737       } else {
738         @DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__, "Not removing tag ($tag) $dn - seems to have moved away", "Tagging");
739       }
740     }
741   }
745 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
746 ?>