Code

Added timezone handling for PHP4 and 5.
[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();
33   var $SubDialog = false;
35   function tabs($config, $data, $dn)
36   {
37         /* Save dn */
38         $this->dn= $dn;
39         $this->config= $config;
40         $baseobject= NULL;
42         foreach ($data as $tab){
43                 $this->by_name[$tab['CLASS']]= $tab['NAME'];
44                 if ($baseobject == NULL){
45                         $baseobject= new $tab['CLASS']($this->config, $this->dn);
46                         $this->by_object[$tab['CLASS']]= $baseobject;
47                 } else {
48                         $this->by_object[$tab['CLASS']]= new $tab['CLASS']($this->config, $this->dn, $baseobject);
49                 }
50                 $this->by_object[$tab['CLASS']]->parent= &$this;
52                 /* Initialize current */
53                 if ($this->current == ""){
54                         $this->current= $tab['CLASS'];
55                 }
56         }
58   }
60   function execute()
61   {
62         /* Rotate current to last */
63         $this->last= $this->current;
65         /* Look for pressed tab button */
66         foreach ($this->by_object as $class => $obj){
67                 if (isset($_POST[$class]) || (isset($_POST['arg']) && $_POST['arg'] == "$class")){
68                         $this->current= $class;
69                         break;
70                 }
71         }
73         /* Save last tab object */
74         if ($this->last == $this->current){
75                 $this->save_object(TRUE);
76         } else {
77                 $this->save_object(FALSE);
78         }
80         /* Build tab line */
81         $display= $this->gen_tabs();
83         /* Show object */
84         $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";
85         $display.= "<tr><td>\n";
87         $obj= $this->by_object[$this->current];
88         $display.= $obj->execute();
89   if (is_php4()){
90     $this->by_object[$this->current]= $obj;
91   }
93         /* Footer for tabbed dialog */
94         $display.= "</td></tr></table>";
95         return ($display);
96   }
98   function save_object($save_current= FALSE)
99   {
100         /* Save last tab */
101         if ($this->last != ""){
102                 @DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__,
103                         $this->last, "Saving");
105                 $obj= $this->by_object[$this->last];
106                 $obj->save_object ();
107     if (is_php4()){
108       $this->by_object[$this->last]= $obj;
109     }
110         }
112         /* Skip if curent and last are the same object */
113         if ($this->last == $this->current){
114                 return;
115         }
117         $obj= $this->by_object[$this->current];
118         $this->disabled= $obj->parent->disabled;
120         if ($save_current){
121                 @DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__,
122                         $this->current, "Saving (current)");
124                 $obj->save_object ();
125     if (is_php4()){
126       $this->by_object[$this->current]= $obj;
127     }
128         }
130   }
132   function gen_tabs()
133   {
134         $display= "<input type=\"hidden\" name=\"arg\" value=\"\">";
135         $display.= "<table summary=\"\" cellpadding=0 cellspacing=0 border=0 style=\"width:100%;\"><tr>";
136         $index= 0;
137         $style= array("tab_left", "tab_active", "tab_near_active", "tab_right");
138         foreach ($this->by_name as $class => $name){
140                 /* Activate right tabs with style "tab_right"
141                    Activate near current with style "tab_near_active" */
142                 if ($index == 2 || $index == 1){
143                         $index++;
144                 }
146                 /* Activate current tab with style "tab_active " */
147                 if ($class == $this->current){
148                         $index++;
149                 }
151                 /* Paint tab */
152                 $display.= "<td style=\"vertical-align:bottom;width:1px;white-space:nowrap;\">";
154                 /* Shorten string if its too long for the tab headers*/
155                 $title= _($name);
156                 if (mb_strlen($title, 'UTF-8') > 14){
157                         $title= mb_substr($title,0, 12, 'UTF-8')."...";
158                 }
160                 $title= preg_replace("/ /", "&nbsp;", $title);
161                 
162                 if ($_SESSION['js']==FALSE){    
163                         $display.= "<div class=\"$style[$index]\"><input type=\"submit\" name=\"$class\"".
164                                    " class=\"$style[$index]\" value=\"$title\"";
165                 } else {                         
166                         $display.= "<div class=\"$style[$index]\"><a class=\"$style[$index]\" onclick=\"return true;\" href=\"javascript:document.mainform.arg.value='$class';document.mainform.submit();\">$title</a";
167                 }
168                 $display.= "></div></td>";
169         }
170         $display.= "<td style=\"vertical-align:bottom;\">\n";
171         $display.= "<div class=\"tab_border\">&nbsp;</div></td></tr></table>";
173         return($display);
174   }
177   function set_acl($acl)
178   {
179     /* Set local acl */
180     $this->acl= $acl;
182     /* Setup for all plugins */
183     foreach ($this->by_object as $key => $obj){
184       $sacl= get_module_permission($acl, "$key", $this->dn);
185       $obj->acl= $sacl;
186       if (is_php4()){
187         $this->by_object[$key]= $obj;
188       }
189     }
190   }
192   function delete()
193   {
194     /* Check if all plugins will ACK for deletion */
195     foreach (array_reverse($this->by_object) as $key => $obj){
196       $reason= $obj->allow_remove();
197       if ($reason != ""){
198         print_red(sprintf(_("Delete process has been canceled by plugin '%s': %s"), $key, $reason));
199         return;
200       }
201     }
203     /* Delete for all plugins */
204     foreach (array_reverse($this->by_object) as $key => $obj){
205       $obj->remove_from_parent();
206     }
207   }
209   function password_change_needed()
210   {
211     /* Ask all plugins for needed password changes */
212     foreach ($this->by_object as $key => $obj){
213       if ($obj->password_change_needed()){
214         return TRUE;
215       }
216     }
218     return FALSE;
219   }
221   function check($ignore_account= FALSE)
222   {
223         $this->save_object(TRUE);
224         $messages= array();
226         /* Check all plugins */
227         foreach ($this->by_object as $key => $obj){
228                 if ($obj->is_account || $ignore_account || $obj->ignore_account){
229                         @DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__,
230                                 $key, "Checking");
232                         $messages= $obj->check();
233       if (is_php4()){
234         $this->by_object[$key]= $obj;
235       }
236                         if (count($messages)){
237                                 $this->current= $key;
238                                 break;
239                         }
240                 }
241         }
243         return ($messages);
244   }
246   function save($ignore_account= FALSE)
247   {
248         /* Save all plugins */
249         foreach ($this->by_object as $key => $obj){
250                 @DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__,
251                         $key, "Saving");
253                 $obj->dn= $this->dn;
254                 
255                 if ($obj->is_account || $ignore_account || $obj->ignore_account){
256                         if ($obj->save() == 1){
257                                 return (1);
258                         }
259                 } else {
260                         $obj->remove_from_parent();
261                 }
262         }
263         return (0);
264   }
266   function adapt_from_template($dn)
267   {
268           foreach ($this->by_object as $key => $obj){
269                   @DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__,
270                                   $key, "Adapting");
271                   $obj->parent= &$this;
272                   $obj->adapt_from_template($dn);
273       if (is_php4()){
274         $this->by_object[$key]= $obj;
275       }
276           }
277   }
279         
280   /* Save attributes posted by copy & paste dialog
281    */
282   function saveCopyDialog()
283   {
284           foreach ($this->by_object as $key => $obj){
285                   if($obj->is_account){
286                           $this->by_object[$key]->saveCopyDialog();
287                   }
288           }
289   }
292   /* return copy & paste dialog
293    */
294   function getCopyDialog()
295   {
296     $ret = "";
297     $this->SubDialog = false;
298     foreach ($this->by_object as $key => $obj){
299       if($obj->is_account){
300         $tmp = $this->by_object[$key]->getCopyDialog();
301         if($tmp['status'] == "SubDialog"){
302           $this->SubDialog = true;
303           return($tmp['string']);
304         }else{
305           if(!empty($tmp['string'])){
306             $ret .= $tmp['string'];
307             $ret .= "<p class='seperator'>&nbsp;</p>";
308           }
309         }
310       }
311     }
312     return($ret);
313   }
316 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
317 ?>