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