Code

Added new timezone methods
[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;
41         
42         $baseobject= NULL;
44         foreach ($data as $tab){
45                 $this->by_name[$tab['CLASS']]= $tab['NAME'];
47                 if ($baseobject == NULL){
48                         $baseobject= new $tab['CLASS']($this->config, $this->dn);
49                         $this->by_object[$tab['CLASS']]= $baseobject;
50                 } else {
51                         $this->by_object[$tab['CLASS']]= new $tab['CLASS']($this->config, $this->dn, $baseobject);
52                 }
54                 $this->by_object[$tab['CLASS']]->parent= &$this;
55                 $this->by_object[$tab['CLASS']]->set_acl_category($acl_category);
57                 /* Initialize current */
58                 if ($this->current == ""){
59                         $this->current= $tab['CLASS'];
60                 }
61         }
62   }
64   function execute()
65   {
66         /* Rotate current to last */
67         $this->last= $this->current;
69         /* Look for pressed tab button */
70         foreach ($this->by_object as $class => $obj){
71                 if (isset($_POST[$class]) || (isset($_POST['arg']) && $_POST['arg'] == "$class")){
72                         $this->current= $class;
73                         break;
74                 }
75         }
77         /* Save last tab object */
78         if ($this->last == $this->current){
79                 $this->save_object(TRUE);
80         } else {
81                 $this->save_object(FALSE);
82         }
84         /* Build tab line */
85         $display= $this->gen_tabs();
87         /* Show object */
88         $display.= "<table summary=\"\" cellpadding=4 cellspacing=0 border=0 style=\"width:100%; background-color:#F8F8F8; border-style:solid; border-color:#AAA; border-top-width:0px; border-bottom-width:1px; border-left-width:1px; border-right-width:1px;\">\n";
89         $display.= "<tr><td>\n";
91         $obj= $this->by_object[$this->current];
92         $display.= $obj->execute();
93   if (is_php4()){
94     $this->by_object[$this->current]= $obj;
95   }
97         /* Footer for tabbed dialog */
98         $display.= "</td></tr></table>";
99         return ($display);
100   }
102   function save_object($save_current= FALSE)
103   {
104         /* Save last tab */
105         if ($this->last != ""){
106                 @DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__,
107                         $this->last, "Saving");
109                 $obj= $this->by_object[$this->last];
110                 $obj->save_object ();
111     if (is_php4()){
112       $this->by_object[$this->last]= $obj;
113     }
114         }
116         /* Skip if curent and last are the same object */
117         if ($this->last == $this->current){
118                 return;
119         }
121         $obj= $this->by_object[$this->current];
122         $this->disabled= $obj->parent->disabled;
124         if ($save_current){
125                 @DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__,
126                         $this->current, "Saving (current)");
128                 $obj->save_object ();
129     if (is_php4()){
130       $this->by_object[$this->current]= $obj;
131     }
132         }
133   }
135   function gen_tabs()
136   {
137         $display= "<input type=\"hidden\" name=\"arg\" value=\"\">";
138         $display.= "<table summary=\"\" cellpadding=0 cellspacing=0 border=0 style=\"width:100%;\"><tr>";
139         $index= 0;
140         $style= array("tab_left", "tab_active", "tab_near_active", "tab_right");
141         foreach ($this->by_name as $class => $name){
143                 /* Activate right tabs with style "tab_right"
144                    Activate near current with style "tab_near_active" */
145                 if ($index == 2 || $index == 1){
146                         $index++;
147                 }
149                 /* Activate current tab with style "tab_active " */
150                 if ($class == $this->current){
151                         $index++;
152                 }
154                 /* Paint tab */
155                 $display.= "<td style=\"vertical-align:bottom;width:1px;white-space:nowrap;\">";
157                 /* Shorten string if its too long for the tab headers*/
158                 $title= _($name);
159                 if (mb_strlen($title, 'UTF-8') > 28){
160                         $title= mb_substr($title,0, 25, 'UTF-8')."...";
161                 }
162                         
163                 /* nobr causes w3c warnings so we use &nbsp; to keep the tab name in one line */
164                 $title= preg_replace("/ /","&nbsp;",$title);
166                 if ($_SESSION['js']==FALSE){    
167                         $display.= "<div class=\"$style[$index]\"><input type=\"submit\" name=\"$class\"".
168                                    " class=\"$style[$index]\" value=\"$title\"";
169                 } else {                         
170                         $display.= "<div class=\"$style[$index]\"><a class=\"$style[$index]\" onclick=\"return true;\" href=\"javascript:document.mainform.arg.value='$class';document.mainform.submit();\">$title</a";
171                 }
172                 $display.= "></div></td>";
173         }
174         $display.= "<td style=\"vertical-align:bottom;\">\n";
175         $display.= "<div class=\"tab_border\">&nbsp;</div></td></tr></table>";
177         return($display);
178   }
181   function set_acl($acl)
182   {
183         /* Look for attribute in ACL */
184           trigger_error("Don't use tabs::set_acl() its obsolete.");
185   }
187   function delete()
188   {
189         /* Check if all plugins will ACK for deletion */
190         foreach (array_reverse($this->by_object) as $key => $obj){
191                 $reason= $obj->allow_remove();
192                 if ($reason != ""){
193                         print_red(sprintf(_("Delete process has been canceled by plugin '%s': %s"), $key, $reason));
194                         return;
195                 }
196         }
198         /* Delete for all plugins */
199         foreach (array_reverse($this->by_object) as $key => $obj){
200                 $obj->remove_from_parent();
201         }
202   }
204   function password_change_needed()
205   {
206         /* Ask all plugins for needed password changes */
207         foreach ($this->by_object as $key => $obj){
208                 if ($obj->password_change_needed()){
209                         return TRUE;
210                 }
211         }
213         return FALSE;
214   }
216   function check($ignore_account= FALSE)
217   {
218     $this->save_object(TRUE);
219     $messages= array();
221     /* Check all plugins */
222     foreach ($this->by_object as $key => $obj){
223       if ($obj->is_account || $ignore_account || $obj->ignore_account){
224         @DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__,
225             $key, "Checking");
227         $messages= $obj->check();
228         if (is_php4()){
229           $this->by_object[$key]= $obj;
230         }
231         if (count($messages)){
232           $this->current= $key;
233           break;
234         }
235       }
236     }
238     return ($messages);
239   }
241   function save($ignore_account= FALSE)
242   {
243         /* Save all plugins */
244         foreach ($this->by_object as $key => $obj){
245                 @DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__,
246                         $key, "Saving");
248                 $obj->dn= $this->dn;
249                 
250                 if ($obj->is_account || $ignore_account || $obj->ignore_account){
251                         if ($obj->save() == 1){
252                                 return (1);
253                         }
254                 } else {
255                         $obj->remove_from_parent();
256                 }
257         }
258         return (0);
259   }
261   function adapt_from_template($dn)
262   {
263           foreach ($this->by_object as $key => $obj){
264                   @DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__,
265                                   $key, "Adapting");
266                   $obj->parent= &$this;
267                   $obj->adapt_from_template($dn);
268       if (is_php4()){
269         $this->by_object[$key]= $obj;
270       }
271           }
272   }
274         
275   /* Save attributes posted by copy & paste dialog
276    */
277   function saveCopyDialog()
278   {
279           foreach ($this->by_object as $key => $obj){
280                   if($obj->is_account){
281                           $this->by_object[$key]->saveCopyDialog();
282                   }
283           }
284   }
287   /* return copy & paste dialog
288    */
289   function getCopyDialog()
290   {
291     $ret = "";
292     $this->SubDialog = false;
293     foreach ($this->by_object as $key => $obj){
294       if($obj->is_account){
295         $tmp = $this->by_object[$key]->getCopyDialog();
296         if($tmp['status'] == "SubDialog"){
297           $this->SubDialog = true;
298           return($tmp['string']);
299         }else{
300           if(!empty($tmp['string'])){
301             $ret .= $tmp['string'];
302             $ret .= "<p class='seperator'>&nbsp;</p>";
303           }
304         }
305       }
306     }
307     return($ret);
308   }
311   function addSpecialTabs()
312   {
313         $this->by_name['acl']= _("ACL");
314         $this->by_object['acl']= new acl($this->config, $this, $this->dn);
315         $this->by_object['acl']->parent= &$this;
316         $this->by_name['reference']= _("References");
317         $this->by_object['reference']= new reference($this->config, $this->dn);
318         $this->by_object['reference']->parent= &$this;
319   }
322   function set_acl_base($base= "")
323   {
324         /* Update reference, transfer variables */
325         $first= ($base == "");
326         foreach ($this->by_object as $name => $obj){
327                 if ($first){
328                         $first= FALSE;
329                         $base= $obj->acl_base;
330                 } else {
331                         $obj->set_acl_base($base);
332                         $this->by_object[$name]= $obj;
333                 }
334         }
335   }
338 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
339 ?>