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