Code

Removed PHP5 specific definitions
[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 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";
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 summary=\"\" 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;\">";
141                 /* Shorten string if its too long for the tab headers*/
142                 $title= _($name);
143                 if (mb_strlen($title, 'UTF-8') > 14){
144                         $title= mb_substr($title,0, 12, 'UTF-8')."...";
145                 }
146                 
147                 if ($_SESSION['js']==FALSE){    
148                         $display.= "<div class=\"$style[$index]\"><input type=\"submit\" name=\"$class\"".
149                                    " class=\"$style[$index]\" value=\"$title\"";
150                 } else {                         
151                         $display.= "<div class=\"$style[$index]\"><a class=\"$style[$index]\" onclick=\"return true;\" href=\"javascript:document.mainform.arg.value='$class';document.mainform.submit();\">$title</a";
152                 }
153                 $display.= "></div></td>";
154         }
155         $display.= "<td style=\"vertical-align:bottom;\">\n";
156         $display.= "<div class=\"tab_border\">&nbsp;</div></td></tr></table>";
158         return($display);
159   }
162   function set_acl($acl)
163   {
164         /* Set local acl */
165         $this->acl= $acl;
167         /* Setup for all plugins */
168         foreach ($this->by_object as $key => $obj){
169                 $sacl= get_module_permission($acl, "$key", $this->dn);
170                 $obj->acl= $sacl;
171                 $this->by_object[$key]= $obj;
172         }
173   }
175   function delete()
176   {
177         /* Delete for all plugins */
178         foreach (array_reverse($this->by_object) as $key => $obj){
179                 $obj->remove_from_parent();
180         }
181   }
183   function password_change_needed()
184   {
185         /* Ask all plugins for needed password changes */
186         foreach ($this->by_object as $key => $obj){
187                 if ($obj->password_change_needed()){
188                         return TRUE;
189                 }
190         }
192         return FALSE;
193   }
195   function check($ignore_account= FALSE)
196   {
197         $this->save_object(TRUE);
198         $messages= array();
200         /* Check all plugins */
201         foreach ($this->by_object as $key => $obj){
202                 if ($obj->is_account || $ignore_account || $obj->ignore_account){
203                         @DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__,
204                                 $key, "Checking");
206                         $messages= $obj->check();
207                         if (count($messages)){
208                                 $this->current= $key;
209                                 break;
210                         }
211                 }
212         }
214         return ($messages);
215   }
217   function save($ignore_account= FALSE)
218   {
219         /* Save all plugins */
220         foreach ($this->by_object as $key => $obj){
221                 @DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__,
222                         $key, "Saving");
224                 $obj->dn= $this->dn;
225                 
226                 if ($obj->is_account || $ignore_account || $obj->ignore_account){
227                         if ($obj->save() == 1){
228                                 return (1);
229                         }
230                 } else {
231                         $obj->remove_from_parent();
232                 }
233         }
234         return (0);
235   }
237   function adapt_from_template($dn)
238   {
239           foreach ($this->by_object as $key => $obj){
240                   @DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__,
241                                   $key, "Adapting");
242                   $obj->parent= &$this;
243                   $obj->adapt_from_template($dn);
244                   $this->by_object[$key]= $obj;
245           }
246   }
250 ?>