10f4636d6ac62089839260ca8be6662ccd0f0c24
1 <?php
2 /*
3 This code is part of GOsa (https://gosa.gonicus.de)
4 Copyright (C) 2003 Cajus Pollmeier
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 */
21 /*! \brief The plugin base class
22 \author Cajus Pollmeier <pollmeier@gonicus.de>
23 \version 2.00
24 \date 24.07.2003
26 This is the base class for all plugins. It can be used standalone or
27 can be included by the tabs class. All management should be done
28 within this class. Extend your plugins from this class.
29 */
31 class plugin
32 {
33 /*!
34 \brief Reference to parent object
36 This variable is used when the plugin is included in tabs
37 and keeps reference to the tab class. Communication to other
38 tabs is possible by 'name'. So the 'fax' plugin can ask the
39 'userinfo' plugin for the fax number.
41 \sa tab
42 */
43 var $parent= NULL;
45 /*!
46 \brief Configuration container
48 Access to global configuration
49 */
50 var $config= NULL;
52 /*!
53 \brief Mark plugin as account
55 Defines whether this plugin is defined as an account or not.
56 This has consequences for the plugin to be saved from tab
57 mode. If it is set to 'FALSE' the tab will call the delete
58 function, else the save function. Should be set to 'TRUE' if
59 the construtor detects a valid LDAP object.
61 \sa plugin::plugin()
62 */
63 var $is_account= FALSE;
64 var $initially_was_account= FALSE;
66 /*!
67 \brief Mark plugin as template
69 Defines whether we are creating a template or a normal object.
70 Has conseqences on the way execute() shows the formular and how
71 save() puts the data to LDAP.
73 \sa plugin::save() plugin::execute()
74 */
75 var $is_template= FALSE;
76 var $ignore_account= FALSE;
77 var $is_modified= FALSE;
79 /*!
80 \brief Represent temporary LDAP data
82 This is only used internally.
83 */
84 var $attrs= array();
87 /*!
88 \brief Used standard values
90 dn
91 */
92 var $dn= "";
93 var $uid= "";
94 var $sn= "";
95 var $givenName= "";
96 var $acl= "*none*";
97 var $dialog= FALSE;
99 /* attribute list for save action */
100 var $attributes= array();
101 var $objectclasses= array();
102 var $new= TRUE;
103 var $saved_attributes= array();
105 /*! \brief plugin constructor
107 If 'dn' is set, the node loads the given 'dn' from LDAP
109 \param dn Distinguished name to initialize plugin from
110 \sa plugin()
111 */
112 function plugin ($config, $dn= NULL)
113 {
114 /* Configuration is fine, allways */
115 $this->config= $config;
116 $this->dn= $dn;
118 /* Handle new accounts, don't read information from LDAP */
119 if ($dn == "new"){
120 return;
121 }
123 /* Get LDAP descriptor */
124 $ldap= $this->config->get_ldap_link();
125 if ($dn != NULL){
127 /* Load data to 'attrs' and save 'dn' */
128 $ldap->cat ($dn);
129 $this->attrs= $ldap->fetch();
131 /* Copy needed attributes */
132 foreach ($this->attributes as $val){
133 #if (isset($this->attrs["$val"][0])){
134 $found= array_key_ics($val, $this->attrs);
135 if ($found != ""){
136 $this->$val= $this->attrs["$found"][0];
137 }
138 }
140 /* Set the template flag according to the existence of objectClass
141 gosaUserTemplate */
142 if (isset($this->attrs['objectClass'])){
143 if (in_array ("gosaUserTemplate", $this->attrs['objectClass'])){
144 $this->is_template= TRUE;
145 @DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__,
146 "found", "Template check");
147 }
148 }
150 /* Is Account? */
151 error_reporting(0);
152 $found= TRUE;
153 foreach ($this->objectclasses as $obj){
154 if (preg_match('/top/i', $obj)){
155 continue;
156 }
157 if (!isset($this->attrs['objectClass']) || !in_array_ics ($obj, $this->attrs['objectClass'])){
158 $found= FALSE;
159 break;
160 }
161 }
162 error_reporting(E_ALL);
163 if ($found){
164 $this->is_account= TRUE;
165 @DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__,
166 "found", "Object check");
167 }
169 /* Prepare saved attributes */
170 $this->saved_attributes= $this->attrs;
171 foreach ($this->saved_attributes as $index => $value){
172 if (preg_match('/^[0-9]+$/', $index)){
173 unset($this->saved_attributes[$index]);
174 continue;
175 }
176 if (!in_array($index, $this->attributes) && $index != "objectClass"){
177 unset($this->saved_attributes[$index]);
178 continue;
179 }
180 if ($this->saved_attributes[$index]["count"] == 1){
181 $tmp= $this->saved_attributes[$index][0];
182 unset($this->saved_attributes[$index]);
183 $this->saved_attributes[$index]= $tmp;
184 continue;
185 }
187 unset($this->saved_attributes["$index"]["count"]);
188 }
189 }
191 /* Save initial account state */
192 $this->initially_was_account= $this->is_account;
193 }
195 /*! \brief execute plugin
197 Generates the html output for this node
198 */
199 function execute()
200 {
201 # This one is empty currently. Fabian - please fill in the docu code
202 $_SESSION['current_class_for_help'] = get_class($this);
203 /* Reset Lock message POST/GET check array, to prevent perg_match errors*/
204 $_SESSION['LOCK_VARS_TO_USE'] =array();
205 }
207 /*! \brief execute plugin
208 Removes object from parent
209 */
210 function remove_from_parent()
211 {
212 /* include global link_info */
213 $ldap= $this->config->get_ldap_link();
215 /* Get current objectClasses in order to add the required ones */
216 $ldap->cat($this->dn);
217 $tmp= $ldap->fetch ();
218 if (isset($tmp['objectClass'])){
219 $oc= $tmp['objectClass'];
220 } else {
221 $oc= array("count" => 0);
222 }
224 /* Remove objectClasses from entry */
225 $ldap->cd($this->dn);
226 $this->attrs= array();
227 $this->attrs['objectClass']= array();
228 for ($i= 0; $i<$oc["count"]; $i++){
229 if (!in_array_ics($oc[$i], $this->objectclasses)){
230 $this->attrs['objectClass'][]= $oc[$i];
231 }
232 }
234 /* Unset attributes from entry */
235 foreach ($this->attributes as $val){
236 $this->attrs["$val"]= array();
237 }
239 /* Unset account info */
240 $this->is_account= FALSE;
242 /* Do not write in plugin base class, this must be done by
243 children, since there are normally additional attribs,
244 lists, etc. */
245 /*
246 $ldap->modify($this->attrs);
247 */
248 }
251 /* Save data to object */
252 function save_object()
253 {
254 /* Save values to object */
255 foreach ($this->attributes as $val){
256 if (chkacl ($this->acl, "$val") == "" && isset ($_POST["$val"])){
257 /* Check for modifications */
258 if (get_magic_quotes_gpc()) {
259 $data= stripcslashes($_POST["$val"]);
260 } else {
261 $data= $this->$val = $_POST["$val"];
262 }
263 if ($this->$val != $data){
264 $this->is_modified= TRUE;
265 }
267 /* Okay, how can I explain this fix ...
268 * In firefox, disabled option fields aren't selectable ... but in IE you can select these fileds.
269 * So IE posts these 'unselectable' option, with value = chr(194)
270 * chr(194) seems to be the in between the ...option> </option.. because there is no value=".." specified in these option fields
271 * This was added for W3c compliance, but now causes these ... ldap errors ...
272 * So we set these Fields to ""; a normal empty string, and we can check these values in plugin::check() again ...
273 */
274 if(isset($data[0]) && $data[0] == chr(194)) {
275 $data = "";
276 }
277 $this->$val= $data;
278 }
279 }
280 }
283 /* Save data to LDAP, depending on is_account we save or delete */
284 function save()
285 {
286 /* include global link_info */
287 $ldap= $this->config->get_ldap_link();
289 /* Start with empty array */
290 $this->attrs= array();
292 /* Get current objectClasses in order to add the required ones */
293 $ldap->cat($this->dn);
295 $tmp= $ldap->fetch ();
297 if (isset($tmp['objectClass'])){
298 $oc= $tmp["objectClass"];
299 $this->new= FALSE;
300 } else {
301 $oc= array("count" => 0);
302 $this->new= TRUE;
303 }
305 /* Load (minimum) attributes, add missing ones */
306 $this->attrs['objectClass']= $this->objectclasses;
307 for ($i= 0; $i<$oc["count"]; $i++){
308 if (!in_array_ics($oc[$i], $this->objectclasses)){
309 $this->attrs['objectClass'][]= $oc[$i];
310 }
311 }
313 /* Copy standard attributes */
314 foreach ($this->attributes as $val){
315 if ($this->$val != ""){
316 $this->attrs["$val"]= $this->$val;
317 } elseif (!$this->new) {
318 $this->attrs["$val"]= array();
319 }
320 }
322 }
325 function cleanup()
326 {
327 foreach ($this->attrs as $index => $value){
329 /* Convert arrays with one element to non arrays, if the saved
330 attributes are no array, too */
331 if (is_array($this->attrs[$index]) &&
332 count ($this->attrs[$index]) == 1 &&
333 isset($this->saved_attributes[$index]) &&
334 !is_array($this->saved_attributes[$index])){
336 $tmp= $this->attrs[$index][0];
337 $this->attrs[$index]= $tmp;
338 }
340 /* Remove emtpy arrays if they do not differ */
341 if (is_array($this->attrs[$index]) &&
342 count($this->attrs[$index]) == 0 &&
343 !isset($this->saved_attributes[$index])){
345 unset ($this->attrs[$index]);
346 continue;
347 }
349 /* Remove single attributes that do not differ */
350 if (!is_array($this->attrs[$index]) &&
351 isset($this->saved_attributes[$index]) &&
352 !is_array($this->saved_attributes[$index]) &&
353 $this->attrs[$index] == $this->saved_attributes[$index]){
355 unset ($this->attrs[$index]);
356 continue;
357 }
359 /* Remove arrays that do not differ */
360 if (is_array($this->attrs[$index]) &&
361 isset($this->saved_attributes[$index]) &&
362 is_array($this->saved_attributes[$index])){
364 if (!array_differs($this->attrs[$index],$this->saved_attributes[$index])){
365 unset ($this->attrs[$index]);
366 continue;
367 }
368 }
369 }
370 }
372 /* Check formular input */
373 function check()
374 {
375 $message= array();
377 /* Skip if we've no config object */
378 if (!isset($this->config)){
379 return $message;
380 }
382 /* Find hooks entries for this class */
383 $command= search_config($this->config->data['MENU'], get_class($this), "CHECK");
384 if ($command == "" && isset($this->config->data['TABS'])){
385 $command= search_config($this->config->data['TABS'], get_class($this), "CHECK");
386 }
388 if ($command != ""){
390 if (!check_command($command)){
391 $message[]= sprintf(_("Command '%s', specified as CHECK hook for plugin '%s' doesn't seem to exist."), $command,
392 get_class($this));
393 } else {
395 /* Generate "ldif" for check hook */
396 $ldif= "dn: $this->dn\n";
398 /* ... objectClasses */
399 foreach ($this->objectclasses as $oc){
400 $ldif.= "objectClass: $oc\n";
401 }
403 /* ... attributes */
404 foreach ($this->attributes as $attr){
405 if ($this->$attr == ""){
406 continue;
407 }
408 if (is_array($this->$attr)){
409 foreach ($this->$attr as $val){
410 $ldif.= "$attr: $val\n";
411 }
412 } else {
413 $ldif.= "$attr: ".$this->$attr."\n";
414 }
415 }
417 /* Append empty line */
418 $ldif.= "\n";
420 /* Feed "ldif" into hook and retrieve result*/
421 $descriptorspec = array( 0 => array("pipe", "r"), 1 => array("pipe", "w"), 2 => array("pipe", "w"));
422 $fh= proc_open($command, $descriptorspec, $pipes);
423 if (is_resource($fh)) {
424 fwrite ($pipes[0], $ldif);
425 fclose($pipes[0]);
427 $result= stream_get_contents($pipes[1]);
428 if ($result != ""){
429 $message[]= $result;
430 }
432 fclose($pipes[1]);
433 fclose($pipes[2]);
434 proc_close($fh);
435 }
436 }
438 }
440 return ($message);
441 }
443 /* Adapt from template, using 'dn' */
444 function adapt_from_template($dn)
445 {
446 /* Include global link_info */
447 $ldap= $this->config->get_ldap_link();
449 /* Load requested 'dn' to 'attrs' */
450 $ldap->cat ($dn);
451 $this->attrs= $ldap->fetch();
453 /* Walk through attributes */
454 foreach ($this->attributes as $val){
456 if (isset($this->attrs["$val"][0])){
458 /* If attribute is set, replace dynamic parts:
459 %sn, %givenName and %uid. Fill these in our local variables. */
460 $value= $this->attrs["$val"][0];
462 foreach (array("sn", "givenName", "uid") as $repl){
463 if (preg_match("/%$repl/i", $value)){
464 $value= preg_replace ("/%$repl/i", $this->parent->$repl, $value);
465 }
466 }
467 $this->$val= $value;
468 }
469 }
471 /* Is Account? */
472 $found= TRUE;
473 foreach ($this->objectclasses as $obj){
474 if (preg_match('/top/i', $obj)){
475 continue;
476 }
477 if (!in_array_ics ($obj, $this->attrs['objectClass'])){
478 $found= FALSE;
479 break;
480 }
481 }
482 if ($found){
483 $this->is_account= TRUE;
484 }
485 }
487 /* Indicate whether a password change is needed or not */
488 function password_change_needed()
489 {
490 return FALSE;
491 }
493 /* Show header message for tab dialogs */
494 function show_header($button_text, $text, $disabled= FALSE)
495 {
496 if ($disabled == TRUE){
497 $state= "disabled";
498 } else {
499 $state= "";
500 }
501 $display= "<table summary=\"\" width=\"100%\"><tr>\n<td colspan=2><p><b>$text</b></p>\n";
502 $display.= "<input type=submit value=\"$button_text\" name=\"modify_state\" ".
503 chkacl($this->acl, "all")." ".$state.
504 "><p class=\"seperator\"> </p></td></tr></table>";
506 return($display);
507 }
509 function postcreate($add_attrs= array())
510 {
511 /* Find postcreate entries for this class */
512 $command= search_config($this->config->data['MENU'], get_class($this), "POSTCREATE");
513 if ($command == "" && isset($this->config->data['TABS'])){
514 $command= search_config($this->config->data['TABS'], get_class($this), "POSTCREATE");
515 }
517 if ($command != ""){
518 /* Walk through attribute list */
519 foreach ($this->attributes as $attr){
520 if (!is_array($this->$attr)){
521 $command= preg_replace("/%$attr/", $this->$attr, $command);
522 }
523 }
524 $command= preg_replace("/%dn/", $this->dn, $command);
526 /* Additional attributes */
527 foreach ($add_attrs as $name => $value){
528 $command= preg_replace("/%$name/", $value, $command);
529 }
531 if (check_command($command)){
532 @DEBUG (DEBUG_SHELL, __LINE__, __FUNCTION__, __FILE__,
533 $command, "Execute");
535 exec($command);
536 } else {
537 $message= sprintf(_("Command '%s', specified as POSTCREATE for plugin '%s' doesn't seem to exist."), $command, get_class($this));
538 print_red ($message);
539 }
540 }
541 }
543 function postmodify($add_attrs= array())
544 {
545 /* Find postcreate entries for this class */
546 $command= search_config($this->config->data['MENU'], get_class($this), "POSTMODIFY");
547 if ($command == "" && isset($this->config->data['TABS'])){
548 $command= search_config($this->config->data['TABS'], get_class($this), "POSTMODIFY");
549 }
551 if ($command != ""){
552 /* Walk through attribute list */
553 foreach ($this->attributes as $attr){
554 if (!is_array($this->$attr)){
555 $command= preg_replace("/%$attr/", $this->$attr, $command);
556 }
557 }
558 $command= preg_replace("/%dn/", $this->dn, $command);
560 /* Additional attributes */
561 foreach ($add_attrs as $name => $value){
562 $command= preg_replace("/%$name/", $value, $command);
563 }
565 if (check_command($command)){
566 @DEBUG (DEBUG_SHELL, __LINE__, __FUNCTION__, __FILE__,
567 $command, "Execute");
569 exec($command);
570 } else {
571 $message= sprintf(_("Command '%s', specified as POSTMODIFY for plugin '%s' doesn't seem to exist."), $command, get_class($this));
572 print_red ($message);
573 }
574 }
575 }
577 function postremove($add_attrs= array())
578 {
579 /* Find postremove entries for this class */
580 $command= search_config($this->config->data['MENU'], get_class($this), "POSTREMOVE");
581 if ($command == "" && isset($this->config->data['TABS'])){
582 $command= search_config($this->config->data['TABS'], get_class($this), "POSTREMOVE");
583 }
585 if ($command != ""){
586 /* Walk through attribute list */
587 foreach ($this->attributes as $attr){
588 if (!is_array($this->$attr)){
589 $command= preg_replace("/%$attr/", $this->$attr, $command);
590 }
591 }
592 $command= preg_replace("/%dn/", $this->dn, $command);
594 /* Additional attributes */
595 foreach ($add_attrs as $name => $value){
596 $command= preg_replace("/%$name/", $value, $command);
597 }
599 if (check_command($command)){
600 @DEBUG (DEBUG_SHELL, __LINE__, __FUNCTION__, __FILE__,
601 $command, "Execute");
603 exec($command);
604 } else {
605 $message= sprintf(_("Command '%s', specified as POSTREMOVE for plugin '%s' doesn't seem to exist."), $command, get_class($this));
606 print_red ($message);
607 }
608 }
609 }
611 /* Create unique DN */
612 function create_unique_dn($attribute, $base)
613 {
614 $ldap= $this->config->get_ldap_link();
615 $base= preg_replace("/^,*/", "", $base);
617 /* Try to use plain entry first */
618 $dn= "$attribute=".$this->$attribute.",$base";
619 $ldap->cat ($dn);
620 if (!$ldap->fetch()){
621 return ($dn);
622 }
624 /* Look for additional attributes */
625 foreach ($this->attributes as $attr){
626 if ($attr == $attribute || $this->$attr == ""){
627 continue;
628 }
630 $dn= "$attribute=".$this->$attribute."+$attr=".$this->$attr.",$base";
631 $ldap->cat ($dn);
632 if (!$ldap->fetch()){
633 return ($dn);
634 }
635 }
637 /* None found */
638 return ("none");
639 }
641 function rebind($ldap, $referral)
642 {
643 $credentials= LDAP::get_credentials($referral, $this->config->current['REFERRAL']);
644 if (ldap_bind($ldap, $credentials['ADMIN'], $credentials['PASSWORD'])) {
645 $this->error = "Success";
646 $this->hascon=true;
647 $this->reconnect= true;
648 return (0);
649 } else {
650 $this->error = "Could not bind to " . $credentials['ADMIN'];
651 return NULL;
652 }
653 }
655 /* This is a workaround function. */
656 function copy($src_dn, $dst_dn)
657 {
658 /* Rename dn in possible object groups */
659 $ldap= $this->config->get_ldap_link();
660 $ldap->search('(&(objectClass=gosaGroupOfNames)(member='.$src_dn.'))',
661 array('cn'));
662 while ($attrs= $ldap->fetch()){
663 $og= new ogroup($this->config, $ldap->getDN());
664 unset($og->member[$src_dn]);
665 $og->member[$dst_dn]= $dst_dn;
666 $og->save ();
667 }
669 $ldap->cat($dst_dn);
670 $attrs= $ldap->fetch();
671 if (count($attrs)){
672 trigger_error("Trying to overwrite $dst_dn, which already exists.",
673 E_USER_WARNING);
674 return (FALSE);
675 }
677 $ldap->cat($src_dn);
678 $attrs= array();
679 $attrs= $ldap->fetch();
680 if (!count($attrs)){
681 trigger_error("Trying to move $src_dn, which does not seem to exist.",
682 E_USER_WARNING);
683 return (FALSE);
684 }
686 /* Grummble. This really sucks. PHP ldap doesn't support rdn stuff. */
687 $ds= ldap_connect($this->config->current['SERVER']);
688 ldap_set_option($ds, LDAP_OPT_PROTOCOL_VERSION, 3);
689 if (function_exists("ldap_set_rebind_proc") && isset($this->config->current['REFERRAL'])) {
690 ldap_set_rebind_proc($ds, array(&$this, "rebind"));
691 }
693 $r=ldap_bind($ds,$this->config->current['ADMIN'], $this->config->current['PASSWORD']);
694 error_reporting (0);
695 $sr=ldap_read($ds, $ldap->fix($src_dn), "objectClass=*");
697 /* Fill data from LDAP */
698 $new= array();
699 if ($sr) {
700 $ei=ldap_first_entry($ds, $sr);
701 if ($ei) {
702 foreach($attrs as $attr => $val){
703 if ($info = ldap_get_values_len($ds, $ei, $attr)){
704 for ($i= 0; $i<$info['count']; $i++){
705 if ($info['count'] == 1){
706 $new[$attr]= $info[$i];
707 } else {
708 $new[$attr][]= $info[$i];
709 }
710 }
711 }
712 }
713 }
714 }
716 /* close conncetion */
717 error_reporting (E_ALL);
718 ldap_unbind($ds);
720 /* Adapt naming attribute */
721 $dst_name= preg_replace("/^([^=]+)=.*$/", "\\1", $dst_dn);
722 $dst_val = preg_replace("/^[^=]+=([^,+]+).*,.*$/", "\\1", $dst_dn);
723 $new[$dst_name]= $dst_val;
725 /* Check if this is a department.
726 * If it is a dep. && there is a , override in his ou
727 * change \2C to , again, else this entry can't be saved ...
728 */
729 if((isset($new['ou'])) &&( preg_match("/\\\\2C/",$new['ou']))){
730 $new['ou'] = preg_replace("/\\\\2C/",",",$new['ou']);
731 }
733 /* Save copy */
734 $ldap->connect();
735 $ldap->cd($this->config->current['BASE']);
736 $ldap->create_missing_trees(preg_replace('/^[^,]+,/', '', $dst_dn));
737 $ldap->cd($dst_dn);
738 $ldap->add($new);
740 if ($ldap->error != "Success"){
741 trigger_error("Trying to save $dst_dn failed.",
742 E_USER_WARNING);
743 return(FALSE);
744 }
746 return (TRUE);
747 }
750 function move($src_dn, $dst_dn)
751 {
752 /* Copy source to destination */
753 if (!$this->copy($src_dn, $dst_dn)){
754 return (FALSE);
755 }
757 /* Delete source */
758 $ldap= $this->config->get_ldap_link();
759 $ldap->rmdir($src_dn);
760 if ($ldap->error != "Success"){
761 trigger_error("Trying to delete $src_dn failed.",
762 E_USER_WARNING);
763 return (FALSE);
764 }
766 return (TRUE);
767 }
770 /* Move/Rename complete trees */
771 function recursive_move($src_dn, $dst_dn)
772 {
773 /* Check if the destination entry exists */
774 $ldap= $this->config->get_ldap_link();
776 /* Check if destination exists - abort */
777 $ldap->cat($dst_dn);
778 if ($ldap->fetch()){
779 trigger_error("recursive_move $dst_dn already exists.",
780 E_USER_WARNING);
781 return (FALSE);
782 }
784 /* Perform a search for all objects to be moved */
785 $objects= array();
786 $ldap->cd($src_dn);
787 $ldap->search("(objectClass=*)", array("dn"));
788 while($attrs= $ldap->fetch()){
789 $dn= $attrs['dn'];
790 $objects[$dn]= strlen($dn);
791 }
793 /* Sort objects by indent level */
794 asort($objects);
795 reset($objects);
797 /* Copy objects from small to big indent levels by replacing src_dn by dst_dn */
798 foreach ($objects as $object => $len){
799 $src= $object;
800 $dst= preg_replace("/$src_dn$/", "$dst_dn", $object);
801 if (!$this->copy($src, $dst)){
802 return (FALSE);
803 }
804 }
806 /* Remove src_dn */
807 $ldap->cd($src_dn);
808 $ldap->recursive_remove();
809 return (TRUE);
810 }
813 function handle_post_events($mode, $add_attrs= array())
814 {
815 switch ($mode){
816 case "add":
817 $this->postcreate($add_attrs);
818 break;
820 case "modify":
821 $this->postmodify($add_attrs);
822 break;
824 case "remove":
825 $this->postremove($add_attrs);
826 break;
827 }
828 }
831 function saveCopyDialog(){
832 }
835 function getCopyDialog(){
836 return(array("string"=>"","status"=>""));
837 }
840 function PrepareForCopyPaste($source){
841 $todo = $this->attributes;
842 if(isset($this->CopyPasteVars)){
843 $todo = array_merge($todo,$this->CopyPasteVars);
844 }
845 $todo[] = "is_account";
846 foreach($todo as $var){
847 $this->$var = $source->$var;
848 }
849 }
852 function handle_object_tagging($dn= "", $tag= "")
853 {
854 /* No dn? Self-operation... */
855 if ($dn == ""){
856 $dn= $this->dn;
857 }
859 /* No tag? Find it yourself... */
860 #....
862 /* Set tag? */
863 if ($tag != ""){
864 #echo "Add tagging ($tag) to $dn.<br>";
866 /* Set objectclass and attribute */
867 $ldap= $this->config->get_ldap_link();
868 $ldap->cat($dn);
869 $attrs= $ldap->fetch();
870 $nattrs= array("gosaUnitTag" => $this->gosaUnitTag);
871 $nattrs['objectClass']= array();
872 for ($i= 0; $i<$attrs['objectClass']['count']; $i++){
873 $oc= $attrs['objectClass'][$i];
874 if ($oc != "gosaAdministrativeUnitTag"){
875 $nattrs['objectClass'][]= $oc;
876 }
877 }
878 $nattrs['objectClass'][]= "gosaAdministrativeUnitTag";
879 $ldap->cd($dn);
880 $ldap->modify($nattrs);
881 if ($ldap->error != "Success"){
882 print_red($ldap->get_error());
883 }
884 } else {
885 #echo "Remove tagging from $dn.<br>";
887 /* Remove objectclass and attribute */
888 $ldap= $this->config->get_ldap_link();
889 $ldap->cat($dn);
890 $attrs= $ldap->fetch();
891 $nattrs= array("gosaUnitTag" => array());
892 $nattrs['objectClass']= array();
893 for ($i= 0; $i<$attrs['objectClass']['count']; $i++){
894 $oc= $attrs['objectClass'][$i];
895 if ($oc != "gosaAdministrativeUnitTag"){
896 $nattrs['objectClass'][]= $oc;
897 }
898 }
899 $ldap->cd($dn);
900 $ldap->modify($nattrs);
901 if ($ldap->error != "Success"){
902 print_red($ldap->get_error());
903 }
904 }
906 }
908 }
909 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
910 ?>