Code

Added fix for divlist department selection
[gosa.git] / include / class_tabs.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 class tabs
22 {
23   var $dn;
24   var $config;
25   var $acl;
26   var $is_template;
27   var $is_new= FALSE;
29   var $last= "";
30   var $current= "";
31   var $disabled= "";
32   var $by_name= array();
33   var $by_object= array();
34   var $SubDialog = false;
36   function tabs($config, $data, $dn, $acl_category= "")
37   {
38         /* Save dn */
39         $this->dn= $dn;
40         $this->config= $config;
42         foreach ($data as $tab){
43                 $this->by_name[$tab['CLASS']]= $tab['NAME'];
44                 $this->by_object[$tab['CLASS']]= new $tab['CLASS']($this->config, $this->dn);
45                 $this->by_object[$tab['CLASS']]->parent= &$this;
46                 $this->by_object[$tab['CLASS']]->set_acl_category($acl_category);
48                 /* Initialize current */
49                 if ($this->current == ""){
50                         $this->current= $tab['CLASS'];
51                 }
52         }
53   }
55   function execute()
56   {
57         /* Rotate current to last */
58         $this->last= $this->current;
60         /* Look for pressed tab button */
61         foreach ($this->by_object as $class => $obj){
62                 if (isset($_POST[$class]) || (isset($_POST['arg']) && $_POST['arg'] == "$class")){
63                         $this->current= $class;
64                         break;
65                 }
66         }
68         /* Save last tab object */
69         if ($this->last == $this->current){
70                 $this->save_object(TRUE);
71         } else {
72                 $this->save_object(FALSE);
73         }
75         /* Build tab line */
76         $display= $this->gen_tabs();
78         /* Show object */
79         $display.= "<table summary=\"\" cellpadding=4 cellspacing=0 border=0 style=\"width:100%; background-color:#F0F0F0; border-style:solid; border-color:black; border-top-width:0px; border-bottom-width:1px; border-left-width:1px; border-right-width:1px;\">\n";
80         $display.= "<tr><td>\n";
82         $obj= $this->by_object[$this->current];
83         $display.= $obj->execute();
84         $this->by_object[$this->current]= $obj;
86         /* Footer for tabbed dialog */
87         $display.= "</td></tr></table>";
88         return ($display);
89   }
91   function save_object($save_current= FALSE)
92   {
93         /* Save last tab */
94         if ($this->last != ""){
95                 @DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__,
96                         $this->last, "Saving");
98                 $obj= $this->by_object[$this->last];
99                 $obj->save_object ();
100                 $this->by_object[$this->last]= $obj;
101         }
103         /* Skip if curent and last are the same object */
104         if ($this->last == $this->current){
105                 return;
106         }
108         $obj= $this->by_object[$this->current];
109         $this->disabled= $obj->parent->disabled;
111         if ($save_current){
112                 @DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__,
113                         $this->current, "Saving (current)");
115                 $obj->save_object ();
116                 $this->by_object[$this->current]= $obj;
117         }
119   }
121   function gen_tabs()
122   {
123         $display= "<input type=\"hidden\" name=\"arg\" value=\"\">";
124         $display.= "<table summary=\"\" cellpadding=0 cellspacing=0 border=0 style=\"width:100%;\"><tr>";
125         $index= 0;
126         $style= array("tab_left", "tab_active", "tab_near_active", "tab_right");
127         foreach ($this->by_name as $class => $name){
129                 /* Activate right tabs with style "tab_right"
130                    Activate near current with style "tab_near_active" */
131                 if ($index == 2 || $index == 1){
132                         $index++;
133                 }
135                 /* Activate current tab with style "tab_active " */
136                 if ($class == $this->current){
137                         $index++;
138                 }
140                 /* Paint tab */
141                 $display.= "<td style=\"vertical-align:bottom;width:1px;\">";
143                 /* Shorten string if its too long for the tab headers*/
144                 $title= '<nobr>'._($name).'</nobr>';
145                 if (mb_strlen($title, 'UTF-8') > 28){
146                         $title= mb_substr($title,0, 25, 'UTF-8')."...";
147                 }
148                 
149                 if ($_SESSION['js']==FALSE){    
150                         $display.= "<div class=\"$style[$index]\"><input type=\"submit\" name=\"$class\"".
151                                    " class=\"$style[$index]\" value=\"$title\"";
152                 } else {                         
153                         $display.= "<div class=\"$style[$index]\"><a class=\"$style[$index]\" onclick=\"return true;\" href=\"javascript:document.mainform.arg.value='$class';document.mainform.submit();\">$title</a";
154                 }
155                 $display.= "></div></td>";
156         }
157         $display.= "<td style=\"vertical-align:bottom;\">\n";
158         $display.= "<div class=\"tab_border\">&nbsp;</div></td></tr></table>";
160         return($display);
161   }
164   function set_acl($acl)
165   {
166         /* Set local acl */
167         $this->acl= $acl;
169         /* Setup for all plugins */
170         foreach ($this->by_object as $key => $obj){
171                 $sacl= get_module_permission($acl, "$key", $this->dn);
172                 $obj->acl= $sacl;
173                 $this->by_object[$key]= $obj;
174         }
175   }
177   function delete()
178   {
179         /* Check if all plugins will ACK for deletion */
180         foreach (array_reverse($this->by_object) as $key => $obj){
181                 $reason= $obj->allow_remove();
182                 if ($reason != ""){
183                         print_red(sprintf(_("Delete process has been canceled by plugin '%s': %s"), $key, $reason));
184                         return;
185                 }
186         }
188         /* Delete for all plugins */
189         foreach (array_reverse($this->by_object) as $key => $obj){
190                 $obj->remove_from_parent();
191         }
192   }
194   function password_change_needed()
195   {
196         /* Ask all plugins for needed password changes */
197         foreach ($this->by_object as $key => $obj){
198                 if ($obj->password_change_needed()){
199                         return TRUE;
200                 }
201         }
203         return FALSE;
204   }
206   function check($ignore_account= FALSE)
207   {
208         $this->save_object(TRUE);
209         $messages= array();
211         /* Check all plugins */
212         foreach ($this->by_object as $key => $obj){
213                 if ($obj->is_account || $ignore_account || $obj->ignore_account){
214                         @DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__,
215                                 $key, "Checking");
217                         $messages= $obj->check();
218                         if (count($messages)){
219                                 $this->current= $key;
220                                 break;
221                         }
222                 }
223         }
225         return ($messages);
226   }
228   function save($ignore_account= FALSE)
229   {
230         /* Save all plugins */
231         foreach ($this->by_object as $key => $obj){
232                 @DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__,
233                         $key, "Saving");
235                 $obj->dn= $this->dn;
236                 
237                 if ($obj->is_account || $ignore_account || $obj->ignore_account){
238                         if ($obj->save() == 1){
239                                 return (1);
240                         }
241                 } else {
242                         $obj->remove_from_parent();
243                 }
244         }
245         return (0);
246   }
248   function adapt_from_template($dn)
249   {
250           foreach ($this->by_object as $key => $obj){
251                   @DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__,
252                                   $key, "Adapting");
253                   $obj->parent= &$this;
254                   $obj->adapt_from_template($dn);
255                   $this->by_object[$key]= $obj;
256           }
257   }
259         
260   /* Save attributes posted by copy & paste dialog
261    */
262   function saveCopyDialog()
263   {
264           foreach ($this->by_object as $key => $obj){
265                   if($obj->is_account){
266                           $this->by_object[$key]->saveCopyDialog();
267                   }
268           }
269   }
272   /* return copy & paste dialog
273    */
274   function getCopyDialog()
275   {
276           $ret = "";
277           $this->SubDialog = false;
278           foreach ($this->by_object as $key => $obj){
279                   if($obj->is_account){
280                           $tmp = $this->by_object[$key]->getCopyDialog();
281                           if($tmp['status'] == "SubDialog"){
282                                   $this->SubDialog = true;
283                       return($tmp['string']);
284                   }else{
285                  $ret .= $tmp['string'];
286                           }
287                   }
288           }
289           return($ret);
290   }
293   function addSpecialTabs()
294   {
295         $this->by_name['acl']= _("ACL");
296         $this->by_object['acl']= new acl($this->config, $this, $this->dn);
297         $this->by_object['acl']->parent= &$this;
298         $this->by_name['reference']= _("References");
299         $this->by_object['reference']= new reference($this->config, $this->dn);
300         $this->by_object['reference']->parent= &$this;
301   }
304   function set_acl_base($base= "")
305   {
306         /* Update reference, transfer variables */
307         $first= ($base == "");
308         foreach ($this->by_object as $name => $obj){
309                 if ($first){
310                         $first= FALSE;
311                         $base= $obj->acl_base;
312                 } else {
313                         $obj->set_acl_base($base);
314                         $this->by_object[$name]= $obj;
315                 }
316         }
317   }
321 ?>