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 }
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);
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;
394 /* Remove tag information if needed */
395 if (!$this->is_administrational_unit && $this->initially_was_tagged){
396 $tmp= array();
398 /* Remove gosaAdministrativeUnit from this plugin */
399 foreach($this->attrs['objectClass'] as $oc){
400 if (preg_match("/^gosaAdministrativeUnitTag$/i", $oc)){
401 continue;
402 }
403 if (!preg_match("/^gosaAdministrativeUnit$/i", $oc)){
404 $tmp[]= $oc;
405 }
406 }
407 $this->attrs['objectClass']= $tmp;
408 $this->attrs['gosaUnitTag']= array();
409 $this->gosaUnitTag = "";
410 }
413 /* Write back to ldap */
414 $ldap->cat($this->dn, array('dn'));
415 $ldap->cd($this->dn);
417 if ($ldap->count()){
418 $this->cleanup();
419 $ldap->modify ($this->attrs);
420 new log("modify","department/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error());
421 $this->handle_post_events('modify');
422 } else {
423 $ldap->add($this->attrs);
424 $this->handle_post_events('add');
425 new log("create","department/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error());
426 }
427 if (!$ldap->success()){
428 msg_dialog::display(_("LDAP error"), msgPool::ldaperror($ldap->get_error(), $this->dn, 0, get_class()));
429 }
431 /* The parameter forces only to set must_be_tagged, and don't touch any objects
432 This will be done later */
433 $this->tag_objects(true);
435 /* Optionally execute a command after we're done */
436 $this->postcreate();
437 return(false);
438 }
441 /* Tag objects to have the gosaAdministrativeUnitTag */
442 function tag_objects($OnlySetTagFlag = false)
443 {
444 if(!$OnlySetTagFlag){
445 $smarty= get_smarty();
446 /* Print out html introduction */
447 echo ' <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN">
448 <html>
449 <head>
450 <title></title>
451 <style type="text/css">@import url("themes/default/style.css");</style>
452 <script language="javascript" src="include/focus.js" type="text/javascript"></script>
453 </head>
454 <body style="background: none; margin:4px;" id="body" >
455 ';
456 echo "<h3>".sprintf(_("Tagging '%s'."),"<i>".LDAP::fix($this->dn)."</i>")."</h3>";
457 }
459 $add= $this->is_administrational_unit;
460 $len= strlen($this->dn);
461 $ldap= $this->config->get_ldap_link();
462 $ldap->cd($this->dn);
463 if ($add){
464 $ldap->search('(!(&(objectClass=gosaAdministrativeUnitTag)(gosaUnitTag='.
465 $this->gosaUnitTag.')))', array('dn'));
466 } else {
467 $ldap->search('objectClass=gosaAdministrativeUnitTag', array('dn'));
468 }
470 $objects = array();
471 while ($attrs= $ldap->fetch()){
472 $objects[] = $attrs;
473 }
474 foreach($objects as $attrs){
476 /* Skip self */
477 if ($attrs['dn'] == $this->dn){
478 continue;
479 }
481 /* Check for confilicting administrative units */
482 $fix= true;
483 foreach ($this->config->adepartments as $key => $tag){
484 /* This one is shorter than our dn, its not relevant... */
485 if ($len >= strlen($key)){
486 continue;
487 }
489 /* This one matches with the latter part. Break and don't fix this entry */
490 if (preg_match('/(^|,)'.preg_quote($key, '/').'$/', $attrs['dn'])){
491 $fix= false;
492 break;
493 }
494 }
496 /* Fix entry if needed */
497 if ($fix){
498 if($OnlySetTagFlag){
499 $this->must_be_tagged =true;
500 return;
501 }
502 $this->handle_object_tagging($attrs['dn'], $this->gosaUnitTag, TRUE );
503 echo "<script language=\"javascript\" type=\"text/javascript\">scrollDown2();</script>" ;
504 }
505 }
507 if(!$OnlySetTagFlag){
508 $this->must_be_tagged = FALSE;
509 echo '<p class="seperator"> </p>';
510 echo "<div style='width:100%;text-align:right;'>".
511 "<form name='form' method='post' action='?plug=".$_GET['plug']."' target='_parent'>".
512 "<br>".
513 "<input type='submit' name='back' value='"._("Continue")."'>".
514 "<input type='hidden' name='php_c_check' value='1'>".
515 "</form>".
516 "</div>";
517 echo "<script language=\"javascript\" type=\"text/javascript\">scrollDown2();</script>" ;
518 }
519 }
522 /* Move/Rename complete trees */
523 function recursive_move($src_dn, $dst_dn,$force = false)
524 {
525 /* Print header to have styles included */
526 $smarty= get_smarty();
528 echo ' <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN">
529 <html>
530 <head>
531 <title></title>
532 <style type="text/css">@import url("themes/default/style.css");</style>
533 <script language="javascript" src="include/focus.js" type="text/javascript"></script>
534 </head>
535 <body style="background: none; margin:4px;" id="body" >
536 ';
537 echo "<h3>".sprintf(_("Moving '%s' to '%s'"),"<i>".LDAP::fix($src_dn)."</i>","<i>".LDAP::fix($dst_dn)."</i>")."</h3>";
540 /* Check if the destination entry exists */
541 $ldap= $this->config->get_ldap_link();
543 /* Check if destination exists - abort */
544 $ldap->cat($dst_dn, array('dn'));
545 if ($ldap->fetch()){
546 trigger_error("Recursive_move ".LDAP::fix($dst_dn)." already exists.",
547 E_USER_WARNING);
548 echo sprintf("Recursive_move: '%s' already exists", LDAP::fix($dst_dn))."<br>";
549 return (FALSE);
550 }
552 /* Perform a search for all objects to be moved */
553 $objects= array();
554 $ldap->cd($src_dn);
555 $ldap->search("(objectClass=*)", array("dn"));
556 while($attrs= $ldap->fetch()){
557 $dn= $attrs['dn'];
558 $objects[$dn]= strlen($dn);
559 }
561 /* Sort objects by indent level */
562 asort($objects);
563 reset($objects);
565 /* Copy objects from small to big indent levels by replacing src_dn by dst_dn */
566 foreach ($objects as $object => $len){
569 $src= str_replace("\\","\\\\",$object);
570 $dst= preg_replace("/".str_replace("\\","\\\\",$src_dn)."$/", "$dst_dn", $object);
571 $dst= str_replace($src_dn,$dst_dn,$object);
573 echo "<b>"._("Object").":</b> ".LDAP::fix($src)."<br>";
575 $this->update_acls($object, $dst,TRUE);
577 if (!$this->copy($src, $dst)){
578 echo "<font color='#FF0000'><br>".sprintf(_("FAILED to copy %s, aborting operation"),LDAP::fix($src))."</font>";
579 return (FALSE);
580 }
581 echo "<script language=\"javascript\" type=\"text/javascript\">scrollDown2();</script>" ;
582 flush();
583 }
585 /* Remove src_dn */
586 $ldap->cd($src_dn);
587 $ldap->recursive_remove();
588 $this->orig_dn = $this->dn = $dst_dn;
589 $this->orig_base= $this->base;
590 $this->entryCSN = getEntryCSN($this->dn);
592 echo '<p class="seperator"> </p>';
594 echo "<div style='width:100%;text-align:right;'><form name='form' method='post' action='?plug=".$_GET['plug']."' target='_parent'>
595 <br><input type='submit' name='back' value='"._("Continue")."'>
596 </form></div>";
598 echo "<script language=\"javascript\" type=\"text/javascript\">scrollDown2();</script>" ;
599 echo "</body></html>";
601 return (TRUE);
602 }
605 /* Return plugin informations for acl handling */
606 static function plInfo()
607 {
608 return (array("plShortName" => _("Generic"),
609 "plDescription" => _("Departments"),
610 "plSelfModify" => FALSE,
611 "plPriority" => 0,
612 "plDepends" => array(),
613 "plSection" => array("administration"),
614 "plCategory" => array("department" => array("objectClass" => "gosaDepartment", "description" => _("Departments"))),
616 "plProvidedAcls" => array(
617 "ou" => _("Department name"),
618 "description" => _("Description"),
619 "businessCategory" => _("Category"),
620 "base" => _("Base"),
622 "st" => _("State"),
623 "l" => _("Location"),
624 "postalAddress" => _("Address"),
625 "telephoneNumber" => _("Telephone"),
626 "facsimileTelephoneNumber" => _("Fax"),
628 "gosaUnitTag" => _("Administrative settings"))
629 ));
630 }
632 function handle_object_tagging($dn= "", $tag= "", $show= false)
633 {
634 /* No dn? Self-operation... */
635 if ($dn == ""){
636 $dn= $this->dn;
638 /* No tag? Find it yourself... */
639 if ($tag == ""){
640 $len= strlen($dn);
642 @DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__, "No tag for $dn - looking for one...", "Tagging");
643 $relevant= array();
644 foreach ($this->config->adepartments as $key => $ntag){
646 /* This one is bigger than our dn, its not relevant... */
647 if ($len <= strlen($key)){
648 continue;
649 }
651 /* This one matches with the latter part. Break and don't fix this entry */
652 if (preg_match('/(^|,)'.preg_quote($key, '/').'$/', $dn)){
653 @DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__, "DEBUG: Possibly relevant: $key", "Tagging");
654 $relevant[strlen($key)]= $ntag;
655 continue;
656 }
658 }
660 /* If we've some relevant tags to set, just get the longest one */
661 if (count($relevant)){
662 ksort($relevant);
663 $tmp= array_keys($relevant);
664 $idx= end($tmp);
665 $tag= $relevant[$idx];
666 $this->gosaUnitTag= $tag;
667 }
668 }
669 }
671 /* Set tag? */
672 if ($tag != ""){
673 /* Set objectclass and attribute */
674 $ldap= $this->config->get_ldap_link();
675 $ldap->cat($dn, array('gosaUnitTag', 'objectClass'));
676 $attrs= $ldap->fetch();
677 if(isset($attrs['gosaUnitTag'][0]) && $attrs['gosaUnitTag'][0] == $tag){
678 if ($show) {
679 echo sprintf(_("Object '%s' is already tagged"), LDAP::fix($dn))."<br>";
680 flush();
681 }
682 return;
683 }
684 if (count($attrs)){
685 if ($show){
686 echo sprintf(_("Adding tag (%s) to object '%s'"), $tag, LDAP::fix($dn))."<br>";
687 flush();
688 }
689 $nattrs= array("gosaUnitTag" => $tag);
690 $nattrs['objectClass']= array();
691 for ($i= 0; $i<$attrs['objectClass']['count']; $i++){
692 $oc= $attrs['objectClass'][$i];
693 if ($oc != "gosaAdministrativeUnitTag"){
694 $nattrs['objectClass'][]= $oc;
695 }
696 }
697 $nattrs['objectClass'][]= "gosaAdministrativeUnitTag";
698 $ldap->cd($dn);
699 $ldap->modify($nattrs);
700 if (!$ldap->success()){
701 msg_dialog::display(_("LDAP error"), msgPool::ldaperror($ldap->get_error(), $dn, LDAP_MOD, get_class()));
702 }
703 } else {
704 @DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__, "Not tagging ($tag) $dn - seems to have moved away", "Tagging");
705 }
707 } else {
708 /* Remove objectclass and attribute */
709 $ldap= $this->config->get_ldap_link();
710 $ldap->cat($dn, array('gosaUnitTag', 'objectClass'));
711 $attrs= $ldap->fetch();
712 if (isset($attrs['objectClass']) && !in_array_ics("gosaAdministrativeUnitTag", $attrs['objectClass'])){
713 @DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__, "$dn is not tagged", "Tagging");
714 return;
715 }
716 if (count($attrs)){
717 if ($show){
718 echo sprintf(_("Removing tag from object '%s'"), LDAP::fix($dn))."<br>";
719 flush();
720 }
721 $nattrs= array("gosaUnitTag" => array());
722 $nattrs['objectClass']= array();
723 for ($i= 0; $i<$attrs['objectClass']['count']; $i++){
724 $oc= $attrs['objectClass'][$i];
725 if ($oc != "gosaAdministrativeUnitTag"){
726 $nattrs['objectClass'][]= $oc;
727 }
728 }
729 $ldap->cd($dn);
730 $ldap->modify($nattrs);
731 if (!$ldap->success()){
732 msg_dialog::display(_("LDAP error"), msgPool::ldaperror($ldap->get_error(), $dn, LDAP_MOD, get_class()));
733 }
734 } else {
735 @DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__, "Not removing tag ($tag) $dn - seems to have moved away", "Tagging");
736 }
737 }
738 }
740 }
742 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
743 ?>