Code

f94d985014a5a480106ece032e5a44a16dc0a386
[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;
28   var $last= "";
29   var $current= "";
30   var $disabled= "";
31   var $by_name= array();
32   var $by_object= array();
34   function tabs($config, $data, $dn)
35   {
36         /* Save dn */
37         $this->dn= $dn;
38         $this->config= $config;
40         foreach ($data as $tab){
41                 $this->by_name[$tab['CLASS']]= $tab['NAME'];
42                 $this->by_object[$tab['CLASS']]= new $tab['CLASS']($this->config, $this->dn);
43                 $this->by_object[$tab['CLASS']]->parent= &$this;
45                 /* Initialize current */
46                 if ($this->current == ""){
47                         $this->current= $tab['CLASS'];
48                 }
49         }
51   }
53   function execute()
54   {
55         /* Rotate current to last */
56         $this->last= $this->current;
58         /* Look for pressed tab button */
59         foreach ($this->by_object as $class => $obj){
60                 if (isset($_POST[$class]) || (isset($_POST['arg']) && $_POST['arg'] == "$class")){
61                         $this->current= $class;
62                         break;
63                 }
64         }
66         /* Save last tab object */
67         if ($this->last == $this->current){
68                 $this->save_object(TRUE);
69         } else {
70                 $this->save_object(FALSE);
71         }
73         /* Build tab line */
74         $display= $this->gen_tabs();
76         /* Show object */
77         $display.= "<table 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";
78         $display.= "<tr><td>\n";
80         $obj= $this->by_object[$this->current];
81         $display.= $obj->execute ();
82         $this->by_object[$this->current]= $obj;
84         /* Footer for tabbed dialog */
85         $display.= "</td></tr></table>";
86         return ($display);
87   }
89   function save_object($save_current= FALSE)
90   {
91         /* Save last tab */
92         if ($this->last != ""){
93                 @DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__,
94                         $this->last, "Saving");
96                 $obj= $this->by_object[$this->last];
97                 $obj->save_object ();
98                 $this->by_object[$this->last]= $obj;
99         }
101         /* Skip if curent and last are the same object */
102         if ($this->last == $this->current){
103                 return;
104         }
106         $obj= $this->by_object[$this->current];
107         $this->disabled= $obj->parent->disabled;
109         if ($save_current){
110                 @DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__,
111                         $this->current, "Saving (current)");
113                 $obj->save_object ();
114                 $this->by_object[$this->current]= $obj;
115         }
117   }
119   function gen_tabs()
120   {
121         $display= "<input type=\"hidden\" name=\"arg\" value=\"\">";
122         $display.= "<table cellpadding=0 cellspacing=0 border=0 style=\"width:100%;\"><tr>";
123         $index= 0;
124         $style= array("tab_left", "tab_active", "tab_near_active", "tab_right");
125         foreach ($this->by_name as $class => $name){
127                 /* Activate right tabs with style "tab_right"
128                    Activate near current with style "tab_near_active" */
129                 if ($index == 2 || $index == 1){
130                         $index++;
131                 }
133                 /* Activate current tab with style "tab_active " */
134                 if ($class == $this->current){
135                         $index++;
136                 }
138                 /* Paint tab */
139                 $display.= "<td style=\"vertical-align:bottom; width:100px;\">";
140                 if ($_SESSION['js']==FALSE){    
141                         $display.= "<div class=\"$style[$index]\"><input type=\"submit\" name=\"$class\"".
142                                    " class=\"$style[$index]\" value=\""._($name)."\"";
143                 } else {                         
144                         $display.= "<div class=\"$style[$index]\"><a class=\"$style[$index]\" onclick=\"return true;\" href=\"javascript:document.mainform.arg.value='$class';document.mainform.submit();\">"._($name)."</a";
145                 }
146                 $display.= "></div></td>";
147         }
148         $display.= "<td style=\"vertical-align:bottom;\">\n";
149         $display.= "<div class=\"tab_border\">&nbsp;</div></td></tr></table>";
151         return($display);
152   }
155   function set_acl($acl)
156   {
157         /* Set local acl */
158         $this->acl= $acl;
160         /* Setup for all plugins */
161         foreach ($this->by_object as $key => $obj){
162                 $sacl= get_module_permission($acl, "$key", $this->dn);
163                 $obj->acl= $sacl;
164                 $this->by_object[$key]= $obj;
165         }
166   }
168   function delete()
169   {
170         /* Delete for all plugins */
171         foreach (array_reverse($this->by_object) as $key => $obj){
172                 $obj->remove_from_parent();
173         }
174   }
176   function password_change_needed()
177   {
178         /* Ask all plugins for needed password changes */
179         foreach ($this->by_object as $key => $obj){
180                 if ($obj->password_change_needed()){
181                         return TRUE;
182                 }
183         }
185         return FALSE;
186   }
188   function check($ignore_account= FALSE)
189   {
190         $this->save_object(TRUE);
191         $messages= array();
193         /* Check all plugins */
194         foreach ($this->by_object as $key => $obj){
195                 if ($obj->is_account || $ignore_account || $obj->ignore_account){
196                         @DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__,
197                                 $key, "Checking");
199                         $messages= $obj->check();
200                         if (count($messages)){
201                                 $this->current= $key;
202                                 break;
203                         }
204                 }
205         }
207         return ($messages);
208   }
210   function save($ignore_account= FALSE)
211   {
212         /* Save all plugins */
213         foreach ($this->by_object as $key => $obj){
214                 @DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__,
215                         $key, "Saving");
217                 $obj->dn= $this->dn;
218                 
219                 if ($obj->is_account || $ignore_account || $obj->ignore_account){
220                         if ($obj->save() == 1){
221                                 return (1);
222                         }
223                 } else {
224                         $obj->remove_from_parent();
225                 }
226         }
227         return (0);
228   }
230   function adapt_from_template($dn)
231   {
232           foreach ($this->by_object as $key => $obj){
233                   @DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__,
234                                   $key, "Adapting");
235                   $obj->parent= &$this;
236                   $obj->adapt_from_template($dn);
237                   $this->by_object[$key]= $obj;
238           }
239   }
243 ?>