Code

Added patches from 2.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;
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:#F0F0F0; border-style:solid; border-color:black; 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         $this->by_object[$this->current]= $obj;
95         /* Footer for tabbed dialog */
96         $display.= "</td></tr></table>";
97         return ($display);
98   }
100   function save_object($save_current= FALSE)
101   {
102         /* Save last tab */
103         if ($this->last != ""){
104                 @DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__,
105                         $this->last, "Saving");
107                 $obj= $this->by_object[$this->last];
108                 $obj->save_object ();
109                 $this->by_object[$this->last]= $obj;
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                 $this->by_object[$this->current]= $obj;
126         }
128   }
130   function gen_tabs()
131   {
132         $display= "<input type=\"hidden\" name=\"arg\" value=\"\">";
133         $display.= "<table summary=\"\" cellpadding=0 cellspacing=0 border=0 style=\"width:100%;\"><tr>";
134         $index= 0;
135         $style= array("tab_left", "tab_active", "tab_near_active", "tab_right");
136         foreach ($this->by_name as $class => $name){
138                 /* Activate right tabs with style "tab_right"
139                    Activate near current with style "tab_near_active" */
140                 if ($index == 2 || $index == 1){
141                         $index++;
142                 }
144                 /* Activate current tab with style "tab_active " */
145                 if ($class == $this->current){
146                         $index++;
147                 }
149                 /* Paint tab */
150                 $display.= "<td style=\"vertical-align:bottom;width:1px;\">";
152                 /* Shorten string if its too long for the tab headers*/
153                 $title= _($name);
154                 if (mb_strlen($title, 'UTF-8') > 28){
155                         $title= mb_substr($title,0, 25, 'UTF-8')."...";
156                 }
157                         
158                 /* nobr causes w3c warnings so we use &nbsp; to keep the tab name in one line */
159                 $title= preg_replace("/ /","&nbsp;",$title);
161                 if ($_SESSION['js']==FALSE){    
162                         $display.= "<div class=\"$style[$index]\"><input type=\"submit\" name=\"$class\"".
163                                    " class=\"$style[$index]\" value=\"$title\"";
164                 } else {                         
165                         $display.= "<div class=\"$style[$index]\"><a class=\"$style[$index]\" onclick=\"return true;\" href=\"javascript:document.mainform.arg.value='$class';document.mainform.submit();\">$title</a";
166                 }
167                 $display.= "></div></td>";
168         }
169         $display.= "<td style=\"vertical-align:bottom;\">\n";
170         $display.= "<div class=\"tab_border\">&nbsp;</div></td></tr></table>";
172         return($display);
173   }
176   function set_acl($acl)
177   {
178         /* Look for attribute in ACL */
179           trigger_error("Don't use tabs::set_acl() its obsolete.");
180   }
182   function delete()
183   {
184         /* Check if all plugins will ACK for deletion */
185         foreach (array_reverse($this->by_object) as $key => $obj){
186                 $reason= $obj->allow_remove();
187                 if ($reason != ""){
188                         print_red(sprintf(_("Delete process has been canceled by plugin '%s': %s"), $key, $reason));
189                         return;
190                 }
191         }
193         /* Delete for all plugins */
194         foreach (array_reverse($this->by_object) as $key => $obj){
195                 $obj->remove_from_parent();
196         }
197   }
199   function password_change_needed()
200   {
201         /* Ask all plugins for needed password changes */
202         foreach ($this->by_object as $key => $obj){
203                 if ($obj->password_change_needed()){
204                         return TRUE;
205                 }
206         }
208         return FALSE;
209   }
211   function check($ignore_account= FALSE)
212   {
213         $this->save_object(TRUE);
214         $messages= array();
216         /* Check all plugins */
217         foreach ($this->by_object as $key => $obj){
218                 if ($obj->is_account || $ignore_account || $obj->ignore_account){
219                         @DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__,
220                                 $key, "Checking");
222                         $messages= $obj->check();
223                         if (count($messages)){
224                                 $this->current= $key;
225                                 break;
226                         }
227                 }
228         }
230         return ($messages);
231   }
233   function save($ignore_account= FALSE)
234   {
235         /* Save all plugins */
236         foreach ($this->by_object as $key => $obj){
237                 @DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__,
238                         $key, "Saving");
240                 $obj->dn= $this->dn;
241                 
242                 if ($obj->is_account || $ignore_account || $obj->ignore_account){
243                         if ($obj->save() == 1){
244                                 return (1);
245                         }
246                 } else {
247                         $obj->remove_from_parent();
248                 }
249         }
250         return (0);
251   }
253   function adapt_from_template($dn)
254   {
255           foreach ($this->by_object as $key => $obj){
256                   @DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__,
257                                   $key, "Adapting");
258                   $obj->parent= &$this;
259                   $obj->adapt_from_template($dn);
260                   $this->by_object[$key]= $obj;
261           }
262   }
264         
265   /* Save attributes posted by copy & paste dialog
266    */
267   function saveCopyDialog()
268   {
269           foreach ($this->by_object as $key => $obj){
270                   if($obj->is_account){
271                           $this->by_object[$key]->saveCopyDialog();
272                   }
273           }
274   }
277   /* return copy & paste dialog
278    */
279   function getCopyDialog()
280   {
281     $ret = "";
282     $this->SubDialog = false;
283     foreach ($this->by_object as $key => $obj){
284       if($obj->is_account){
285         $tmp = $this->by_object[$key]->getCopyDialog();
286         if($tmp['status'] == "SubDialog"){
287           $this->SubDialog = true;
288           return($tmp['string']);
289         }else{
290           if(!empty($tmp['string'])){
291             $ret .= $tmp['string'];
292             $ret .= "<p class='seperator'>&nbsp;</p>";
293           }
294         }
295       }
296     }
297     return($ret);
298   }
301   function addSpecialTabs()
302   {
303         $this->by_name['acl']= _("ACL");
304         $this->by_object['acl']= new acl($this->config, $this, $this->dn);
305         $this->by_object['acl']->parent= &$this;
306         $this->by_name['reference']= _("References");
307         $this->by_object['reference']= new reference($this->config, $this->dn);
308         $this->by_object['reference']->parent= &$this;
309   }
312   function set_acl_base($base= "")
313   {
314         /* Update reference, transfer variables */
315         $first= ($base == "");
316         foreach ($this->by_object as $name => $obj){
317                 if ($first){
318                         $first= FALSE;
319                         $base= $obj->acl_base;
320                 } else {
321                         $obj->set_acl_base($base);
322                         $this->by_object[$name]= $obj;
323                 }
324         }
325   }
328 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
329 ?>