Code

Removed parameter
[gosa.git] / include / class_plugin.inc
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();
86   /* Keep set of conflicting plugins */
87   var $conflicts= array();
89   /* Save unit tags */
90   var $gosaUnitTag= "";
92   /*!
93     \brief Used standard values
95     dn
96    */
97   var $dn= "";
98   var $uid= "";
99   var $sn= "";
100   var $givenName= "";
101   var $acl= "*none*";
102   var $dialog= FALSE;
103   var $snapDialog = NULL;
105   /* attribute list for save action */
106   var $attributes= array();
107   var $objectclasses= array();
108   var $is_new= TRUE;
109   var $saved_attributes= array();
111   var $acl_base= "";
112   var $acl_category= "";
114   /* Plugin identifier */
115   var $plHeadline= "";
116   var $plDescription= "";
118   /*! \brief plugin constructor
120     If 'dn' is set, the node loads the given 'dn' from LDAP
122     \param dn Distinguished name to initialize plugin from
123     \sa plugin()
124    */
125   function plugin ($config, $dn= NULL, $parent= NULL)
126   {
127     /* Configuration is fine, allways */
128     $this->config= $config;     
129     $this->dn= $dn;
131     /* Handle new accounts, don't read information from LDAP */
132     if ($dn == "new"){
133       return;
134     }
136     /* Save current dn as acl_base */
137     $this->acl_base= $dn;
139     /* Get LDAP descriptor */
140     $ldap= $this->config->get_ldap_link();
141     if ($dn != NULL){
143       /* Load data to 'attrs' and save 'dn' */
144       if ($parent != NULL){
145         $this->attrs= $parent->attrs;
146       } else {
147         $ldap->cat ($dn);
148         $this->attrs= $ldap->fetch();
149       }
151       /* Copy needed attributes */
152       foreach ($this->attributes as $val){
153         $found= array_key_ics($val, $this->attrs);
154         if ($found != ""){
155           $this->$val= $this->attrs["$found"][0];
156         }
157       }
159       /* gosaUnitTag loading... */
160       if (isset($this->attrs['gosaUnitTag'][0])){
161         $this->gosaUnitTag= $this->attrs['gosaUnitTag'][0];
162       }
164       /* Set the template flag according to the existence of objectClass
165          gosaUserTemplate */
166       if (isset($this->attrs['objectClass'])){
167         if (in_array ("gosaUserTemplate", $this->attrs['objectClass'])){
168           $this->is_template= TRUE;
169           @DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__,
170               "found", "Template check");
171         }
172       }
174       /* Is Account? */
175       error_reporting(0);
176       $found= TRUE;
177       foreach ($this->objectclasses as $obj){
178         if (preg_match('/top/i', $obj)){
179           continue;
180         }
181         if (!isset($this->attrs['objectClass']) || !in_array_ics ($obj, $this->attrs['objectClass'])){
182           $found= FALSE;
183           break;
184         }
185       }
186       error_reporting(E_ALL);
187       if ($found){
188         $this->is_account= TRUE;
189         @DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__,
190             "found", "Object check");
191       }
193       /* Prepare saved attributes */
194       $this->saved_attributes= $this->attrs;
195       foreach ($this->saved_attributes as $index => $value){
196         if (preg_match('/^[0-9]+$/', $index)){
197           unset($this->saved_attributes[$index]);
198           continue;
199         }
200         if (!in_array($index, $this->attributes) && $index != "objectClass"){
201           unset($this->saved_attributes[$index]);
202           continue;
203         }
204         if ($this->saved_attributes[$index]["count"] == 1){
205           $tmp= $this->saved_attributes[$index][0];
206           unset($this->saved_attributes[$index]);
207           $this->saved_attributes[$index]= $tmp;
208           continue;
209         }
211         unset($this->saved_attributes["$index"]["count"]);
212       }
213     }
215     /* Save initial account state */
216     $this->initially_was_account= $this->is_account;
217   }
219   /*! \brief execute plugin
221     Generates the html output for this node
222    */
223   function execute()
224   {
225     /* This one is empty currently. Fabian - please fill in the docu code */
226     $_SESSION['current_class_for_help'] = get_class($this);
227     /* Reset Lock message POST/GET check array, to prevent perg_match errors*/
228     $_SESSION['LOCK_VARS_TO_USE'] =array();
229   }
231   /*! \brief execute plugin
232      Removes object from parent
233    */
234   function remove_from_parent()
235   {
236     /* include global link_info */
237     $ldap= $this->config->get_ldap_link();
239     /* Get current objectClasses in order to add the required ones */
240     $ldap->cat($this->dn);
241     $tmp= $ldap->fetch ();
242     if (isset($tmp['objectClass'])){
243       $oc= $tmp['objectClass'];
244     } else {
245       $oc= array("count" => 0);
246     }
248     /* Remove objectClasses from entry */
249     $ldap->cd($this->dn);
250     $this->attrs= array();
251     $this->attrs['objectClass']= array();
252     for ($i= 0; $i<$oc["count"]; $i++){
253       if (!in_array_ics($oc[$i], $this->objectclasses)){
254         $this->attrs['objectClass'][]= $oc[$i];
255       }
256     }
258     /* Unset attributes from entry */
259     foreach ($this->attributes as $val){
260       $this->attrs["$val"]= array();
261     }
263     /* Unset account info */
264     $this->is_account= FALSE;
266     /* Do not write in plugin base class, this must be done by
267        children, since there are normally additional attribs,
268        lists, etc. */
269     /*
270        $ldap->modify($this->attrs);
271      */
272   }
275   /* Save data to object */
276   function save_object()
277   {
278     /* Save values to object */
279     foreach ($this->attributes as $val){
280       if ($this->acl_is_writeable($val) && isset ($_POST["$val"])){
281         /* Check for modifications */
282         if (get_magic_quotes_gpc()) {
283           $data= stripcslashes($_POST["$val"]);
284         } else {
285           $data= $this->$val = $_POST["$val"];
286         }
287         if ($this->$val != $data){
288           $this->is_modified= TRUE;
289         }
290     
291         /* Okay, how can I explain this fix ... 
292          * In firefox, disabled option fields aren't selectable ... but in IE you can select these fileds. 
293          * So IE posts these 'unselectable' option, with value = chr(194) 
294          * chr(194) seems to be the &nbsp; in between the ...option>&nbsp;</option.. because there is no value=".." specified in these option fields  
295          * This &nbsp; was added for W3c compliance, but now causes these ... ldap errors ... 
296          * So we set these Fields to ""; a normal empty string, and we can check these values in plugin::check() again ...
297          */
298         if(isset($data[0]) && $data[0] == chr(194)) {
299           $data = "";  
300         }
301         $this->$val= $data;
302         //echo "<font color='blue'>".$val."</font><br>";
303       }else{
304         //echo "<font color='red'>".$val."</font><br>";
305       }
306     }
307   }
310   /* Save data to LDAP, depending on is_account we save or delete */
311   function save()
312   {
313     /* include global link_info */
314     $ldap= $this->config->get_ldap_link();
316     /* Start with empty array */
317     $this->attrs= array();
319     /* Get current objectClasses in order to add the required ones */
320     $ldap->cat($this->dn);
321     
322     $tmp= $ldap->fetch ();
323     
324     if (isset($tmp['objectClass'])){
325       $oc= $tmp["objectClass"];
326       $this->is_new= FALSE;
327     } else {
328       $oc= array("count" => 0);
329       $this->is_new= TRUE;
330     }
332     /* Load (minimum) attributes, add missing ones */
333     $this->attrs['objectClass']= $this->objectclasses;
334     for ($i= 0; $i<$oc["count"]; $i++){
335       if (!in_array_ics($oc[$i], $this->objectclasses)){
336         $this->attrs['objectClass'][]= $oc[$i];
337       }
338     }
340     /* Copy standard attributes */
341     foreach ($this->attributes as $val){
342       if ($this->$val != ""){
343         $this->attrs["$val"]= $this->$val;
344       } elseif (!$this->is_new) {
345         $this->attrs["$val"]= array();
346       }
347     }
349   }
352   function cleanup()
353   {
354     foreach ($this->attrs as $index => $value){
356       /* Convert arrays with one element to non arrays, if the saved
357          attributes are no array, too */
358       if (is_array($this->attrs[$index]) && 
359           count ($this->attrs[$index]) == 1 &&
360           isset($this->saved_attributes[$index]) &&
361           !is_array($this->saved_attributes[$index])){
362           
363         $tmp= $this->attrs[$index][0];
364         $this->attrs[$index]= $tmp;
365       }
367       /* Remove emtpy arrays if they do not differ */
368       if (is_array($this->attrs[$index]) &&
369           count($this->attrs[$index]) == 0 &&
370           !isset($this->saved_attributes[$index])){
371           
372         unset ($this->attrs[$index]);
373         continue;
374       }
376       /* Remove single attributes that do not differ */
377       if (!is_array($this->attrs[$index]) &&
378           isset($this->saved_attributes[$index]) &&
379           !is_array($this->saved_attributes[$index]) &&
380           $this->attrs[$index] == $this->saved_attributes[$index]){
382         unset ($this->attrs[$index]);
383         continue;
384       }
386       /* Remove arrays that do not differ */
387       if (is_array($this->attrs[$index]) && 
388           isset($this->saved_attributes[$index]) &&
389           is_array($this->saved_attributes[$index])){
390           
391         if (!array_differs($this->attrs[$index],$this->saved_attributes[$index])){
392           unset ($this->attrs[$index]);
393           continue;
394         }
395       }
396     }
397   }
399   /* Check formular input */
400   function check()
401   {
402     $message= array();
404     /* Skip if we've no config object */
405     if (!isset($this->config)){
406       return $message;
407     }
409     /* Find hooks entries for this class */
410     $command= search_config($this->config->data['MENU'], get_class($this), "CHECK");
411     if ($command == "" && isset($this->config->data['TABS'])){
412       $command= search_config($this->config->data['TABS'], get_class($this), "CHECK");
413     }
415     if ($command != ""){
417       if (!check_command($command)){
418         $message[]= sprintf(_("Command '%s', specified as CHECK hook for plugin '%s' doesn't seem to exist."), $command,
419                             get_class($this));
420       } else {
422         /* Generate "ldif" for check hook */
423         $ldif= "dn: $this->dn\n";
424         
425         /* ... objectClasses */
426         foreach ($this->objectclasses as $oc){
427           $ldif.= "objectClass: $oc\n";
428         }
429         
430         /* ... attributes */
431         foreach ($this->attributes as $attr){
432           if ($this->$attr == ""){
433             continue;
434           }
435           if (is_array($this->$attr)){
436             foreach ($this->$attr as $val){
437               $ldif.= "$attr: $val\n";
438             }
439           } else {
440               $ldif.= "$attr: ".$this->$attr."\n";
441           }
442         }
444         /* Append empty line */
445         $ldif.= "\n";
447         /* Feed "ldif" into hook and retrieve result*/
448         $descriptorspec = array( 0 => array("pipe", "r"), 1 => array("pipe", "w"), 2 => array("pipe", "w"));
449         $fh= proc_open($command, $descriptorspec, $pipes);
450         if (is_resource($fh)) {
451           fwrite ($pipes[0], $ldif);
452           fclose($pipes[0]);
453           
454           $result= stream_get_contents($pipes[1]);
455           if ($result != ""){
456             $message[]= $result;
457           }
458           
459           fclose($pipes[1]);
460           fclose($pipes[2]);
461           proc_close($fh);
462         }
463       }
465     }
467     return ($message);
468   }
470   /* Adapt from template, using 'dn' */
471   function adapt_from_template($dn)
472   {
473     /* Include global link_info */
474     $ldap= $this->config->get_ldap_link();
476     /* Load requested 'dn' to 'attrs' */
477     $ldap->cat ($dn);
478     $this->attrs= $ldap->fetch();
480     /* Walk through attributes */
481     foreach ($this->attributes as $val){
483       if (isset($this->attrs["$val"][0])){
485         /* If attribute is set, replace dynamic parts: 
486            %sn, %givenName and %uid. Fill these in our local variables. */
487         $value= $this->attrs["$val"][0];
489         foreach (array("sn", "givenName", "uid") as $repl){
490           if (preg_match("/%$repl/i", $value)){
491             $value= preg_replace ("/%$repl/i", $this->parent->$repl, $value);
492           }
493         }
494         $this->$val= $value;
495       }
496     }
498     /* Is Account? */
499     $found= TRUE;
500     foreach ($this->objectclasses as $obj){
501       if (preg_match('/top/i', $obj)){
502         continue;
503       }
504       if (!in_array_ics ($obj, $this->attrs['objectClass'])){
505         $found= FALSE;
506         break;
507       }
508     }
509     if ($found){
510       $this->is_account= TRUE;
511     }
512   }
514   /* Indicate whether a password change is needed or not */
515   function password_change_needed()
516   {
517     return FALSE;
518   }
521   /* Show header message for tab dialogs */
522   function show_enable_header($button_text, $text, $disabled= FALSE)
523   {
524     if (($disabled == TRUE) || (!$this->acl_is_createable())){
525       $state= "disabled";
526     } else {
527       $state= "";
528     }
529     $display= "<table summary=\"\" width=\"100%\"><tr>\n<td colspan=2><p><b>$text</b></p>\n";
530     $display.= "<input type=submit value=\"$button_text\" name=\"modify_state\" ".$state.
531       "><p class=\"seperator\">&nbsp;</p></td></tr></table>";
533     return($display);
534   }
537   /* Show header message for tab dialogs */
538   function show_disable_header($button_text, $text, $disabled= FALSE)
539   {
540     if (($disabled == TRUE) || !$this->acl_is_removeable()){
541       $state= "disabled";
542     } else {
543       $state= "";
544     }
545     $display= "<table summary=\"\" width=\"100%\"><tr>\n<td colspan=2><p><b>$text</b></p>\n";
546     $display.= "<input type=submit value=\"$button_text\" name=\"modify_state\" ".$state.
547       "><p class=\"seperator\">&nbsp;</p></td></tr></table>";
549     return($display);
550   }
553   /* Show header message for tab dialogs */
554   function show_header($button_text, $text, $disabled= FALSE)
555   {
556     echo "FIXME: show_header should be replaced by show_disable_header and show_enable_header<br>";
557     if ($disabled == TRUE){
558       $state= "disabled";
559     } else {
560       $state= "";
561     }
562     $display= "<table summary=\"\" width=\"100%\"><tr>\n<td colspan=2><p><b>$text</b></p>\n";
563     $display.= "<input type=submit value=\"$button_text\" name=\"modify_state\" ".
564       ($this->acl_is_createable()?'':'disabled')." ".$state.
565       "><p class=\"seperator\">&nbsp;</p></td></tr></table>";
567     return($display);
568   }
571   function postcreate($add_attrs= array())
572   {
573     /* Find postcreate entries for this class */
574     $command= search_config($this->config->data['MENU'], get_class($this), "POSTCREATE");
575     if ($command == "" && isset($this->config->data['TABS'])){
576       $command= search_config($this->config->data['TABS'], get_class($this), "POSTCREATE");
577     }
579     if ($command != ""){
580       /* Walk through attribute list */
581       foreach ($this->attributes as $attr){
582         if (!is_array($this->$attr)){
583           $command= preg_replace("/%$attr/", $this->$attr, $command);
584         }
585       }
586       $command= preg_replace("/%dn/", $this->dn, $command);
588       /* Additional attributes */
589       foreach ($add_attrs as $name => $value){
590         $command= preg_replace("/%$name/", $value, $command);
591       }
593       if (check_command($command)){
594         @DEBUG (DEBUG_SHELL, __LINE__, __FUNCTION__, __FILE__,
595             $command, "Execute");
597         exec($command);
598       } else {
599         $message= sprintf(_("Command '%s', specified as POSTCREATE for plugin '%s' doesn't seem to exist."), $command, get_class($this));
600         print_red ($message);
601       }
602     }
603   }
605   function postmodify($add_attrs= array())
606   {
607     /* Find postcreate entries for this class */
608     $command= search_config($this->config->data['MENU'], get_class($this), "POSTMODIFY");
609     if ($command == "" && isset($this->config->data['TABS'])){
610       $command= search_config($this->config->data['TABS'], get_class($this), "POSTMODIFY");
611     }
613     if ($command != ""){
614       /* Walk through attribute list */
615       foreach ($this->attributes as $attr){
616         if (!is_array($this->$attr)){
617           $command= preg_replace("/%$attr/", $this->$attr, $command);
618         }
619       }
620       $command= preg_replace("/%dn/", $this->dn, $command);
622       /* Additional attributes */
623       foreach ($add_attrs as $name => $value){
624         $command= preg_replace("/%$name/", $value, $command);
625       }
627       if (check_command($command)){
628         @DEBUG (DEBUG_SHELL, __LINE__, __FUNCTION__, __FILE__,
629             $command, "Execute");
631         exec($command);
632       } else {
633         $message= sprintf(_("Command '%s', specified as POSTMODIFY for plugin '%s' doesn't seem to exist."), $command, get_class($this));
634         print_red ($message);
635       }
636     }
637   }
639   function postremove($add_attrs= array())
640   {
641     /* Find postremove entries for this class */
642     $command= search_config($this->config->data['MENU'], get_class($this), "POSTREMOVE");
643     if ($command == "" && isset($this->config->data['TABS'])){
644       $command= search_config($this->config->data['TABS'], get_class($this), "POSTREMOVE");
645     }
647     if ($command != ""){
648       /* Walk through attribute list */
649       foreach ($this->attributes as $attr){
650         if (!is_array($this->$attr)){
651           $command= preg_replace("/%$attr/", $this->$attr, $command);
652         }
653       }
654       $command= preg_replace("/%dn/", $this->dn, $command);
656       /* Additional attributes */
657       foreach ($add_attrs as $name => $value){
658         $command= preg_replace("/%$name/", $value, $command);
659       }
661       if (check_command($command)){
662         @DEBUG (DEBUG_SHELL, __LINE__, __FUNCTION__, __FILE__,
663             $command, "Execute");
665         exec($command);
666       } else {
667         $message= sprintf(_("Command '%s', specified as POSTREMOVE for plugin '%s' doesn't seem to exist."), $command, get_class($this));
668         print_red ($message);
669       }
670     }
671   }
673   /* Create unique DN */
674   function create_unique_dn($attribute, $base)
675   {
676     $ldap= $this->config->get_ldap_link();
677     $base= preg_replace("/^,*/", "", $base);
679     /* Try to use plain entry first */
680     $dn= "$attribute=".$this->$attribute.",$base";
681     $ldap->cat ($dn, array('dn'));
682     if (!$ldap->fetch()){
683       return ($dn);
684     }
686     /* Look for additional attributes */
687     foreach ($this->attributes as $attr){
688       if ($attr == $attribute || $this->$attr == ""){
689         continue;
690       }
692       $dn= "$attribute=".$this->$attribute."+$attr=".$this->$attr.",$base";
693       $ldap->cat ($dn, array('dn'));
694       if (!$ldap->fetch()){
695         return ($dn);
696       }
697     }
699     /* None found */
700     return ("none");
701   }
703   function rebind($ldap, $referral)
704   {
705     $credentials= LDAP::get_credentials($referral, $this->config->current['REFERRAL']);
706     if (ldap_bind($ldap, $credentials['ADMIN'], $credentials['PASSWORD'])) {
707       $this->error = "Success";
708       $this->hascon=true;
709       $this->reconnect= true;
710       return (0);
711     } else {
712       $this->error = "Could not bind to " . $credentials['ADMIN'];
713       return NULL;
714     }
715   }
717   /* This is a workaround function. */
718   function copy($src_dn, $dst_dn)
719   {
720     /* Rename dn in possible object groups */
721     $ldap= $this->config->get_ldap_link();
722     $ldap->search('(&(objectClass=gosaGroupOfNames)(member='.@LDAP::fix($src_dn).'))',
723         array('cn'));
724     while ($attrs= $ldap->fetch()){
725       $og= new ogroup($this->config, $ldap->getDN());
726       unset($og->member[$src_dn]);
727       $og->member[$dst_dn]= $dst_dn;
728       $og->save ();
729     }
731     $ldap->cat($dst_dn);
732     $attrs= $ldap->fetch();
733     if (count($attrs)){
734       trigger_error("Trying to overwrite ".@LDAP::fix($dst_dn).", which already exists.",
735           E_USER_WARNING);
736       return (FALSE);
737     }
739     $ldap->cat($src_dn);
740     $attrs= $ldap->fetch();
741     if (!count($attrs)){
742       trigger_error("Trying to move ".@LDAP::fix($src_dn).", which does not seem to exist.",
743           E_USER_WARNING);
744       return (FALSE);
745     }
747     /* Grummble. This really sucks. PHP ldap doesn't support rdn stuff. */
748     $ds= ldap_connect($this->config->current['SERVER']);
749     ldap_set_option($ds, LDAP_OPT_PROTOCOL_VERSION, 3);
750     if (function_exists("ldap_set_rebind_proc") && isset($this->config->current['REFERRAL'])) {
751       ldap_set_rebind_proc($ds, array(&$this, "rebind"));
752     }
754     $r=ldap_bind($ds,$this->config->current['ADMIN'], $this->config->current['PASSWORD']);
755     error_reporting (0);
756     $sr=ldap_read($ds, @LDAP::fix($src_dn), "objectClass=*");
758     /* Fill data from LDAP */
759     $new= array();
760     if ($sr) {
761       $ei=ldap_first_entry($ds, $sr);
762       if ($ei) {
763         foreach($attrs as $attr => $val){
764           if ($info = ldap_get_values_len($ds, $ei, $attr)){
765             for ($i= 0; $i<$info['count']; $i++){
766               if ($info['count'] == 1){
767                 $new[$attr]= $info[$i];
768               } else {
769                 $new[$attr][]= $info[$i];
770               }
771             }
772           }
773         }
774       }
775     }
777     /* close conncetion */
778     error_reporting (E_ALL);
779     ldap_unbind($ds);
781     /* Adapt naming attribute */
782     $dst_name= preg_replace("/^([^=]+)=.*$/", "\\1", $dst_dn);
783     $dst_val = preg_replace("/^[^=]+=([^,+]+).*,.*$/", "\\1", $dst_dn);
784     $new[$dst_name]= @LDAP::fix($dst_val);
786     /* Check if this is a department.
787      * If it is a dep. && there is a , override in his ou 
788      *  change \2C to , again, else this entry can't be saved ...
789      */
790     if((isset($new['ou'])) &&( preg_match("/\\,/",$new['ou']))){
791       $new['ou'] = preg_replace("/\\\\,/",",",$new['ou']);
792     }
794     /* Save copy */
795     $ldap->connect();
796     $ldap->cd($this->config->current['BASE']);
797     
798     $ldap->create_missing_trees(preg_replace('/^[^,]+,/', '', $dst_dn));
800     /* FAIvariable=.../..., cn=.. 
801         could not be saved, because the attribute FAIvariable was different to 
802         the dn FAIvariable=..., cn=... */
803     if(in_array_ics("FAIdebconfInfo",$new['objectClass'])){
804       $new['FAIvariable'] = $ldap->fix($new['FAIvariable']);
805     }
806     $ldap->cd($dst_dn);
807     $ldap->add($new);
809     if ($ldap->error != "Success"){
810       trigger_error("Trying to save $dst_dn failed.",
811           E_USER_WARNING);
812       return(FALSE);
813     }
815     return (TRUE);
816   }
819   function move($src_dn, $dst_dn)
820   {
821     /* Copy source to destination */
822     if (!$this->copy($src_dn, $dst_dn)){
823       return (FALSE);
824     }
826     /* Delete source */
827     $ldap= $this->config->get_ldap_link();
828     $ldap->rmdir($src_dn);
829     if ($ldap->error != "Success"){
830       trigger_error("Trying to delete $src_dn failed.",
831           E_USER_WARNING);
832       return (FALSE);
833     }
835     return (TRUE);
836   }
839   /* Move/Rename complete trees */
840   function recursive_move($src_dn, $dst_dn)
841   {
842     /* Check if the destination entry exists */
843     $ldap= $this->config->get_ldap_link();
845     /* Check if destination exists - abort */
846     $ldap->cat($dst_dn, array('dn'));
847     if ($ldap->fetch()){
848       trigger_error("recursive_move $dst_dn already exists.",
849           E_USER_WARNING);
850       return (FALSE);
851     }
853     /* Perform a search for all objects to be moved */
854     $objects= array();
855     $ldap->cd($src_dn);
856     $ldap->search("(objectClass=*)", array("dn"));
857     while($attrs= $ldap->fetch()){
858       $dn= $attrs['dn'];
859       $objects[$dn]= strlen($dn);
860     }
862     /* Sort objects by indent level */
863     asort($objects);
864     reset($objects);
866     /* Copy objects from small to big indent levels by replacing src_dn by dst_dn */
867     foreach ($objects as $object => $len){
868       $src= $object;
869       $dst= preg_replace("/$src_dn$/", "$dst_dn", $object);
870       if (!$this->copy($src, $dst)){
871         return (FALSE);
872       }
873     }
875     /* Remove src_dn */
876     $ldap->cd($src_dn);
877     $ldap->recursive_remove();
878     return (TRUE);
879   }
882   function handle_post_events($mode, $add_attrs= array())
883   {
884     switch ($mode){
885       case "add":
886         $this->postcreate($add_attrs);
887       break;
889       case "modify":
890         $this->postmodify($add_attrs);
891       break;
893       case "remove":
894         $this->postremove($add_attrs);
895       break;
896     }
897   }
900   function saveCopyDialog(){
901   }
904   function getCopyDialog(){
905     return(array("string"=>"","status"=>""));
906   }
909   function PrepareForCopyPaste($source){
910     $todo = $this->attributes;
911     if(isset($this->CopyPasteVars)){
912       $todo = array_merge($todo,$this->CopyPasteVars);
913     }
914     $todo[] = "is_account";
915     foreach($todo as $var){
916       $this->$var = $source->$var;
917     }
918   }
921   function handle_object_tagging($dn= "", $tag= "", $show= false)
922   {
923     //FIXME: How to optimize this? We have at least two
924     //       LDAP accesses per object. It would be a good
925     //       idea to have it integrated.
927     /* No dn? Self-operation... */
928     if ($dn == ""){
929       $dn= $this->dn;
931       /* No tag? Find it yourself... */
932       if ($tag == ""){
933         $len= strlen($dn);
935         @DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__, "No tag for $dn - looking for one...", "Tagging");
936         $relevant= array();
937         foreach ($this->config->adepartments as $key => $ntag){
939           /* This one is bigger than our dn, its not relevant... */
940           if ($len <= strlen($key)){
941             continue;
942           }
944           /* This one matches with the latter part. Break and don't fix this entry */
945           if (preg_match('/(^|,)'.normalizePreg($key).'$/', $dn)){
946             @DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__, "DEBUG: Possibly relevant: $key", "Tagging");
947             $relevant[strlen($key)]= $ntag;
948             continue;
949           }
951         }
953         /* If we've some relevant tags to set, just get the longest one */
954         if (count($relevant)){
955           ksort($relevant);
956           $tmp= array_keys($relevant);
957           $idx= end($tmp);
958           $tag= $relevant[$idx];
959           $this->gosaUnitTag= $tag;
960         }
961       }
962     }
965     /* Set tag? */
966     if ($tag != ""){
967       /* Set objectclass and attribute */
968       $ldap= $this->config->get_ldap_link();
969       $ldap->cat($dn, array('gosaUnitTag', 'objectClass'));
970       $attrs= $ldap->fetch();
971       if(isset($attrs['gosaUnitTag'][0]) && $attrs['gosaUnitTag'][0] == $tag){
972         if ($show) {
973           echo sprintf(_("Object '%s' is already tagged"), @LDAP::fix($dn))."<br>";
974           flush();
975         }
976         return;
977       }
978       if (count($attrs)){
979         if ($show){
980           echo sprintf(_("Adding tag (%s) to object '%s'"), $tag, @LDAP::fix($dn))."<br>";
981           flush();
982         }
983         $nattrs= array("gosaUnitTag" => $tag);
984         $nattrs['objectClass']= array();
985         for ($i= 0; $i<$attrs['objectClass']['count']; $i++){
986           $oc= $attrs['objectClass'][$i];
987           if ($oc != "gosaAdministrativeUnitTag"){
988             $nattrs['objectClass'][]= $oc;
989           }
990         }
991         $nattrs['objectClass'][]= "gosaAdministrativeUnitTag";
992         $ldap->cd($dn);
993         $ldap->modify($nattrs);
994         show_ldap_error($ldap->get_error(), sprintf(_("Handle object tagging with dn '%s' failed."),$dn));
995       } else {
996         @DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__, "Not tagging ($tag) $dn - seems to have moved away", "Tagging");
997       }
999     } else {
1000       /* Remove objectclass and attribute */
1001       $ldap= $this->config->get_ldap_link();
1002       $ldap->cat($dn, array('gosaUnitTag', 'objectClass'));
1003       $attrs= $ldap->fetch();
1004       if (isset($attrs['objectClass']) && !in_array_ics("gosaAdministrativeUnitTag", $attrs['objectClass'])){
1005         @DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__, "$dn is not tagged", "Tagging");
1006         return;
1007       }
1008       if (count($attrs)){
1009         if ($show){
1010           echo sprintf(_("Removing tag from object '%s'"), @LDAP::fix($dn))."<br>";
1011           flush();
1012         }
1013         $nattrs= array("gosaUnitTag" => array());
1014         $nattrs['objectClass']= array();
1015         for ($i= 0; $i<$attrs['objectClass']['count']; $i++){
1016           $oc= $attrs['objectClass'][$i];
1017           if ($oc != "gosaAdministrativeUnitTag"){
1018             $nattrs['objectClass'][]= $oc;
1019           }
1020         }
1021         $ldap->cd($dn);
1022         $ldap->modify($nattrs);
1023         show_ldap_error($ldap->get_error(), sprintf(_("Handle object tagging with dn '%s' failed."),$dn));
1024       } else {
1025         @DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__, "Not removing tag ($tag) $dn - seems to have moved away", "Tagging");
1026       }
1027     }
1029   }
1032   /* Add possibility to stop remove process */
1033   function allow_remove()
1034   {
1035     $reason= "";
1036     return $reason;
1037   }
1040   /* Create a snapshot of the current object */
1041   function create_snapshot($type= "snapshot", $description= array())
1042   {
1044     /* Check if snapshot functionality is enabled */
1045     if(!$this->snapshotEnabled()){
1046       return;
1047     }
1049     /* Get configuration from gosa.conf */
1050     $tmp = $this->config->current;
1052     /* Create lokal ldap connection */
1053     $ldap= $this->config->get_ldap_link();
1054     $ldap->cd($this->config->current['BASE']);
1056     /* check if there are special server configurations for snapshots */
1057     if(!isset($tmp['SNAPSHOT_SERVER'])){
1059       /* Source and destination server are both the same, just copy source to dest obj */
1060       $ldap_to      = $ldap;
1061       $snapldapbase = $this->config->current['BASE'];
1063     }else{
1064       $server         = $tmp['SNAPSHOT_SERVER'];
1065       $user           = $tmp['SNAPSHOT_USER'];
1066       $password       = $tmp['SNAPSHOT_PASSWORD'];
1067       $snapldapbase   = $tmp['SNAPSHOT_LDAP_BASE'];
1069       $ldap_to        = new LDAP($user,$password, $server);
1070       $ldap_to -> cd($snapldapbase);
1071       show_ldap_error($ldap->get_error(), sprintf(_("Saving object snapshot with dn '%s' failed."),$snapldapbase));
1072     }
1074     /* check if the dn exists */ 
1075     if ($ldap->dn_exists($this->dn)){
1077       /* Extract seconds & mysecs, they are used as entry index */
1078       list($usec, $sec)= explode(" ", microtime());
1080       /* Collect some infos */
1081       $base           = $this->config->current['BASE'];
1082       $snap_base      = $tmp['SNAPSHOT_BASE'];
1083       $base_of_object = preg_replace ('/^[^,]+,/i', '', $this->dn);
1084       $new_base       = preg_replace("/".normalizePreg($base)."$/","",$base_of_object).$snap_base;
1086       /* Create object */
1087 #$data             = preg_replace('/^dn:.*\n/', '', $ldap->gen_ldif($this->dn,"(!(objectClass=gosaDepartment))"));
1088       $data             = $ldap->gen_ldif($this->dn,"(&(!(objectClass=gosaDepartment))(!(objectClass=FAIclass)))");
1089       $newName          = preg_replace("/\./", "", $sec."-".$usec);
1090       $target= array();
1091       $target['objectClass']            = array("top", "gosaSnapshotObject");
1092       $target['gosaSnapshotData']       = gzcompress($data, 6);
1093       $target['gosaSnapshotType']       = $type;
1094       $target['gosaSnapshotDN']         = $this->dn;
1095       $target['description']            = $description;
1096       $target['gosaSnapshotTimestamp']  = $newName;
1098       /* Insert the new snapshot 
1099          But we have to check first, if the given gosaSnapshotTimestamp
1100          is already used, in this case we should increment this value till there is 
1101          an unused value. */ 
1102       $new_dn                           = "gosaSnapshotTimestamp=".$newName.",".$new_base;
1103       $ldap_to->cat($new_dn);
1104       while($ldap_to->count()){
1105         $ldap_to->cat($new_dn);
1106         $newName = preg_replace("/\./", "", $sec."-".($usec++));
1107         $new_dn                           = "gosaSnapshotTimestamp=".$newName.",".$new_base;
1108         $target['gosaSnapshotTimestamp']  = $newName;
1109       } 
1111       /* Inset this new snapshot */
1112       $ldap_to->cd($snapldapbase);
1113       $ldap_to->create_missing_trees($new_base);
1114       $ldap_to->cd($new_dn);
1115       $ldap_to->add($target);
1117       show_ldap_error($ldap->get_error(), sprintf(_("Saving object snapshot with dn '%s' failed."),$new_base));
1118       show_ldap_error($ldap_to->get_error(), sprintf(_("Saving object snapshot with dn '%s' failed."),$new_base));
1119     }
1120   }
1122   function remove_snapshot($dn)
1123   {
1124     $ui   = get_userinfo();
1126     if($this->acl_is_removeable()){
1127       $ldap = $this->config->get_ldap_link();
1128       $ldap->cd($this->config->current['BASE']);
1129       $ldap->rmdir_recursive($dn);
1130     }else{
1131       print_red (_("You are not allowed to delete this snapshot!"));
1132     }
1133   }
1136   /* returns true if snapshots are enabled, and false if it is disalbed
1137      There will also be some errors psoted, if the configuration failed */
1138   function snapshotEnabled()
1139   {
1140     $tmp = $this->config->current;
1141     if(isset($tmp['ENABLE_SNAPSHOT'])){
1142       if (preg_match("/^true$/i", $tmp['ENABLE_SNAPSHOT']) || preg_match("/yes/i", $tmp['ENABLE_SNAPSHOT'])){
1144         /* Check if the snapshot_base is defined */
1145         if(!isset($tmp['SNAPSHOT_BASE'])){
1146           print_red(sprintf(_("The snapshot functionality is enabled, but the required variable '%s' is not configured in your gosa.conf."),$missing));
1147           return(FALSE);
1148         }
1150         /* check if there are special server configurations for snapshots */
1151         if(isset($tmp['SNAPSHOT_SERVER'])){
1153           /* check if all required vars are available to create a new ldap connection */
1154           $missing = "";
1155           foreach(array("SNAPSHOT_SERVER","SNAPSHOT_USER","SNAPSHOT_PASSWORD","SNAPSHOT_LDAP_BASE") as $var){
1156             if(!isset($tmp[$var])){
1157               $missing .= $var." ";
1158               print_red(sprintf(_("The snapshot functionality is enabled, but the required variable(s) '%s' is not configured in your gosa.conf."),$missing));
1159               return(FALSE);
1160             }
1161           }
1162         }
1163         return(TRUE);
1164       }
1165     }
1166     return(FALSE);
1167   }
1170   /* Return available snapshots for the given base 
1171    */
1172   function Available_SnapsShots($dn,$raw = false)
1173   {
1174     if(!$this->snapshotEnabled()) return(array());
1176     /* Create an additional ldap object which
1177        points to our ldap snapshot server */
1178     $ldap= $this->config->get_ldap_link();
1179     $ldap->cd($this->config->current['BASE']);
1180     $tmp = $this->config->current;
1182     /* check if there are special server configurations for snapshots */
1183     if(isset($tmp['SNAPSHOT_SERVER'])){
1184       $server       = $tmp['SNAPSHOT_SERVER'];
1185       $user         = $tmp['SNAPSHOT_USER'];
1186       $password     = $tmp['SNAPSHOT_PASSWORD'];
1187       $snapldapbase = $tmp['SNAPSHOT_LDAP_BASE'];
1188       $ldap_to      = new LDAP($user,$password, $server);
1189       $ldap_to -> cd ($snapldapbase);
1190       show_ldap_error($ldap->get_error(), sprintf(_("Method get available snapshots with dn '%s' failed."),$this->dn));
1191     }else{
1192       $ldap_to    = $ldap;
1193     }
1195     /* Prepare bases and some other infos */
1196     $base           = $this->config->current['BASE'];
1197     $snap_base      = $tmp['SNAPSHOT_BASE'];
1198     $base_of_object = preg_replace ('/^[^,]+,/i', '', $dn);
1199     $new_base       = preg_replace("/".normalizePreg($base)."$/","",$base_of_object).$snap_base;
1200     $tmp            = array(); 
1202     /* Fetch all objects with  gosaSnapshotDN=$dn */
1203     $ldap_to->cd($new_base);
1204     $ldap_to->ls("(&(objectClass=gosaSnapshotObject)(gosaSnapshotDN=".$dn."))",$new_base,
1205         array("gosaSnapshotType","gosaSnapshotTimestamp","gosaSnapshotDN","description")); 
1207     /* Put results into a list and add description if missing */
1208     while($entry = $ldap_to->fetch()){ 
1209       if(!isset($entry['description'][0])){
1210         $entry['description'][0]  = "";
1211       }
1212       $tmp[] = $entry; 
1213     }
1215     /* Return the raw array, or format the result */
1216     if($raw){
1217       return($tmp);
1218     }else{  
1219       $tmp2 = array();
1220       foreach($tmp as $entry){
1221         $tmp2[base64_encode($entry['dn'])] = $entry['description'][0]; 
1222       }
1223     }
1224     return($tmp2);
1225   }
1228   function getAllDeletedSnapshots($base_of_object,$raw = false)
1229   {
1230     if(!$this->snapshotEnabled()) return(array());
1232     /* Create an additional ldap object which
1233        points to our ldap snapshot server */
1234     $ldap= $this->config->get_ldap_link();
1235     $ldap->cd($this->config->current['BASE']);
1236     $tmp = $this->config->current;
1238     /* check if there are special server configurations for snapshots */
1239     if(isset($tmp['SNAPSHOT_SERVER'])){
1240       $server       = $tmp['SNAPSHOT_SERVER'];
1241       $user         = $tmp['SNAPSHOT_USER'];
1242       $password     = $tmp['SNAPSHOT_PASSWORD'];
1243       $snapldapbase = $tmp['SNAPSHOT_LDAP_BASE'];
1244       $ldap_to      = new LDAP($user,$password, $server);
1245       $ldap_to->cd ($snapldapbase);
1246       show_ldap_error($ldap->get_error(), sprintf(_("Method get deleted snapshots with dn '%s' failed."),$this->dn));
1247     }else{
1248       $ldap_to    = $ldap;
1249     }
1251     /* Prepare bases */ 
1252     $base           = $this->config->current['BASE'];
1253     $snap_base      = $tmp['SNAPSHOT_BASE'];
1254     $new_base       = preg_replace("/".normalizePreg($base)."$/","",$base_of_object).$snap_base;
1256     /* Fetch all objects and check if they do not exist anymore */
1257     $ui = get_userinfo();
1258     $tmp = array();
1259     $ldap_to->cd($new_base);
1260     $ldap_to->ls("(objectClass=gosaSnapshotObject)",$new_base,array("gosaSnapshotType","gosaSnapshotTimestamp","gosaSnapshotDN","description"));
1261     while($entry = $ldap_to->fetch()){
1263       $chk =  str_replace($new_base,"",$entry['dn']);
1264       if(preg_match("/,ou=/",$chk)) continue;
1266       if(!isset($entry['description'][0])){
1267         $entry['description'][0]  = "";
1268       }
1269       $tmp[] = $entry; 
1270     }
1272     /* Check if entry still exists */
1273     foreach($tmp as $key => $entry){
1274       $ldap->cat($entry['gosaSnapshotDN'][0]);
1275       if($ldap->count()){
1276         unset($tmp[$key]);
1277       }
1278     }
1280     /* Format result as requested */
1281     if($raw) {
1282       return($tmp);
1283     }else{
1284       $tmp2 = array();
1285       foreach($tmp as $key => $entry){
1286         $tmp2[base64_encode($entry['dn'])] = $entry['description'][0]; 
1287       }
1288     }
1289     return($tmp2);
1290   } 
1293   /* Restore selected snapshot */
1294   function restore_snapshot($dn)
1295   {
1296     if(!$this->snapshotEnabled()) return(array());
1298     $ldap= $this->config->get_ldap_link();
1299     $ldap->cd($this->config->current['BASE']);
1300     $tmp = $this->config->current;
1302     /* check if there are special server configurations for snapshots */
1303     if(isset($tmp['SNAPSHOT_SERVER'])){
1304       $server       = $tmp['SNAPSHOT_SERVER'];
1305       $user         = $tmp['SNAPSHOT_USER'];
1306       $password     = $tmp['SNAPSHOT_PASSWORD'];
1307       $snapldapbase = $tmp['SNAPSHOT_LDAP_BASE'];
1308       $ldap_to      = new LDAP($user,$password, $server);
1309       $ldap_to->cd ($snapldapbase);
1310       show_ldap_error($ldap->get_error(), sprintf(_("Restore snapshot with dn '%s' failed."),$snapldapbase));
1311     }else{
1312       $ldap_to    = $ldap;
1313     }
1315     /* Get the snapshot */ 
1316     $ldap_to->cat($dn);
1317     $restoreObject = $ldap_to->fetch();
1319     /* Prepare import string */
1320     $data  = gzuncompress($ldap_to->get_attribute($dn,'gosaSnapshotData'));
1322     /* Import the given data */
1323     $ldap->import_complete_ldif($data,$err,false,false);
1324     show_ldap_error($ldap->get_error(), sprintf(_("Restore snapshot with dn '%s' failed."),$dn));
1325   }
1328   function showSnapshotDialog($base,$baseSuffixe)
1329   {
1330     $once = true;
1331     foreach($_POST as $name => $value){
1333       /* Create a new snapshot, display a dialog */
1334       if(preg_match("/^CreateSnapShotDialog_/",$name) && $once){
1335         $once = false;
1336         $entry = preg_replace("/^CreateSnapShotDialog_/","",$name);
1337         $entry = base64_decode(preg_replace("/_[xy]$/","",$entry));
1338         $this->snapDialog = new SnapShotDialog($this->config,$entry,$this);
1339       }
1341       /* Restore a snapshot, display a dialog with all snapshots of the current object */
1342       if(preg_match("/^RestoreSnapShotDialog_/",$name) && $once){
1343         $once = false;
1344         $entry = preg_replace("/^RestoreSnapShotDialog_/","",$name);
1345         $entry = base64_decode(preg_replace("/_[xy]$/","",$entry));
1346         $this->snapDialog = new SnapShotDialog($this->config,$entry,$this);
1347         $this->snapDialog->display_restore_dialog = true;
1348       }
1350       /* Restore one of the already deleted objects */
1351       if(preg_match("/^RestoreDeletedSnapShot_/",$name) && $once){
1352         $once = false;
1353         $this->snapDialog = new SnapShotDialog($this->config,$baseSuffixe,$this);
1354         $this->snapDialog->display_restore_dialog      = true;
1355         $this->snapDialog->display_all_removed_objects  = true;
1356       }
1358       /* Restore selected snapshot */
1359       if(preg_match("/^RestoreSnapShot_/",$name) && $once){
1360         $once = false;
1361         $entry = preg_replace("/^RestoreSnapShot_/","",$name);
1362         $entry = base64_decode(trim(preg_replace("/_[xy]$/","",$entry)));
1363         if(!empty($entry)){
1364           $this->restore_snapshot($entry);
1365           $this->snapDialog = NULL;
1366         }
1367       }
1368     }
1370     /* Create a new snapshot requested, check
1371        the given attributes and create the snapshot*/
1372     if(isset($_POST['CreateSnapshot'])){
1373       $this->snapDialog->save_object();
1374       $msgs = $this->snapDialog->check();
1375       if(count($msgs)){
1376         foreach($msgs as $msg){
1377           print_red($msg);
1378         }
1379       }else{
1380         $this->dn =  $this->snapDialog->dn;
1381         $this->create_snapshot("snapshot",$this->snapDialog->CurrentDescription);
1382         $this->snapDialog = NULL;
1383       }
1384     }
1386     /* Restore is requested, restore the object with the posted dn .*/
1387     if((isset($_POST['RestoreSnapshot'])) && (isset($_POST['SnapShot']))){
1388     }
1390     if(isset($_POST['CancelSnapshot'])){
1391       $this->snapDialog = NULL;
1392     }
1394     if($this->snapDialog){
1395       $this->snapDialog->save_object();
1396       return($this->snapDialog->execute());
1397     }
1398   }
1401   function plInfo()
1402   {
1403     return array();
1404   }
1407   function set_acl_base($base)
1408   {
1409     $this->acl_base= $base;
1410   }
1413   function set_acl_category($category)
1414   {
1415     $this->acl_category= "$category/";
1416   }
1419   function acl_is_writeable($attribute,$skip_write = FALSE)
1420   {
1421     $ui= get_userinfo();
1422     return preg_match('/w/', $ui->get_permissions($this->acl_base, $this->acl_category.get_class($this), $attribute, $skip_write));
1423   }
1426   function acl_is_readable($attribute)
1427   {
1428     $ui= get_userinfo();
1429     return preg_match('/r/', $ui->get_permissions($this->acl_base, $this->acl_category.get_class($this), $attribute));
1430   }
1433   function acl_is_createable()
1434   {
1435     $ui= get_userinfo();
1436     return preg_match('/c/', $ui->get_permissions($this->acl_base, $this->acl_category.get_class($this), '0'));
1437   }
1440   function acl_is_removeable()
1441   {
1442     $ui= get_userinfo();
1443     return preg_match('/d/', $ui->get_permissions($this->acl_base, $this->acl_category.get_class($this), '0'));
1444   }
1447   function acl_is_moveable()
1448   {
1449     $ui= get_userinfo();
1450     return preg_match('/m/', $ui->get_permissions($this->acl_base, $this->acl_category.get_class($this), '0'));
1451   }
1454   function acl_have_any_permissions()
1455   {
1456   }
1459   function getacl($attribute,$skip_write= FALSE)
1460   {
1461     $ui= get_userinfo();
1462     return  $ui->get_permissions($this->acl_base, $this->acl_category.get_class($this), $attribute,$skip_write);
1463   }
1465   /* Get all allowed bases to move an object to or to create a new object.
1466      Idepartments also contains all base departments which lead to the allowed bases */
1467   function get_allowed_bases($category = "")
1468   {
1469     $ui = get_userinfo();
1470     $deps = array();
1472     /* Set category */ 
1473     if(empty($category)){
1474       $category = $this->acl_category.get_class($this);
1475     }
1477     /* Is this a new object ? Or just an edited existing object */
1478     if(!$this->initially_was_account && $this->is_account){
1479       $new = true;
1480     }else{
1481       $new = false;
1482     }
1484     /* Add current base */      
1485     if(isset($this->base) && isset($this->config->idepartments[$this->base])){
1486       $deps[$this->base] = $this->config->idepartments[$this->base];
1487     }else{
1488       echo "No default base found. ".$this->base."<br> ";
1489     }
1491     $cat_bases = $ui->get_module_departments(preg_replace("/\/.*$/","",$category));
1492     foreach($this->config->idepartments as $dn => $name){
1493       
1494       if(!in_array_ics($dn,$cat_bases)){
1495         continue;
1496       }
1497       
1498       $acl = $ui->get_permissions($dn,$category);
1499       if($new && preg_match("/c/",$acl)){
1500         $deps[$dn] = $name;
1501       }elseif(!$new && preg_match("/m/",$acl)){
1502         $deps[$dn] = $name;
1503       }
1504     }
1505     return($deps);
1506   }
1509 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
1510 ?>