Code

Closes #272 Remove notification image (lamp.png) from tabs, if plugin was disabled
[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;
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   
65   function multiple_support_available()
66   {
67     foreach($this->by_object as $name => $obj){
68       if($obj->multiple_support){
69         return(TRUE);
70       }
71     }
72     return(FALSE);
73   }  
75   function enable_multiple_support()
76   {
77     if(!$this->multiple_support_available()){
78       return(FALSE);
79     }else{
80       foreach($this->by_object as $name => $obj){
81         if($obj->multiple_support){
82           $this->by_object[$name]->multiple_support_active = TRUE;
83         }else{
84           unset($this->by_object[$name]);
85           unset($this->by_name[$name]);
86         }
87       }
88     }
89     return(TRUE);
90   }
93   function execute()
94   {
95     /* Rotate current to last */
96     $this->last= $this->current;
98     /* Look for pressed tab button */
99     foreach ($this->by_object as $class => &$obj){
100       if (isset($_POST[$class]) || (isset($_POST['arg']) && $_POST['arg'] == "$class")){
101         $this->current= $class;
102         break;
103       }
104     }
106     /* Save last tab object */
107     if ($this->last == $this->current){
108       $this->save_object(TRUE);
109     } else {
110       $this->save_object(FALSE);
111     }
113     /* Build tab line */
114     $display= $this->gen_tabs();
116     /* Show object */
117     $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";
118     $display.= "<tr><td>\n";
120     $display.= $this->by_object[$this->current]->execute();
122     /* Footer for tabbed dialog */
123     $display.= "</td></tr></table>";
125     return ($display);
126   }
128   function save_object($save_current= FALSE)
129   {
130     /* Save last tab */
131     if ($this->last != ""){
132       @DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__,
133           $this->last, "Saving");
135       $this->by_object[$this->last]->save_object ();
136     }
138     /* Skip if curent and last are the same object */
139     if ($this->last == $this->current){
140       return;
141     }
143     $obj= @$this->by_object[$this->current];
144     $this->disabled= $obj->parent->disabled;
146     if ($save_current){
147       @DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__,
148           $this->current, "Saving (current)");
150       $obj->save_object ();
151     }
152   }
154   function gen_tabs()
155   {
156     $display= "<input type=\"hidden\" name=\"arg\" value=\"\">";
157     $display.= "<table summary=\"\" cellpadding=0 cellspacing=0 border=0 style=\"width:100%;\"><tr>";
158     $index= 0;
159     $style= array("tab_left", "tab_active", "tab_near_active", "tab_right");
160     foreach ($this->by_name as $class => $name){
162       /* Activate right tabs with style "tab_right"
163          Activate near current with style "tab_near_active" */
164       if ($index == 2 || $index == 1){
165         $index++;
166       }
168       /* Activate current tab with style "tab_active " */
169       if ($class == $this->current){
170         $index++;
171       }
173       /* Paint tab */
174       $display.= "<td style=\"vertical-align:bottom;width:1px;white-space:nowrap;\">";
176       /* Shorten string if its too long for the tab headers*/
177       $title= _($name);
178       if (mb_strlen($title, 'UTF-8') > 28){
179         $title= mb_substr($title,0, 25, 'UTF-8')."...";
180       }
182       /* nobr causes w3c warnings so we use &nbsp; to keep the tab name in one line */
183       $title= preg_replace("/ /","&nbsp;",$title);
185       /* Take care about notifications */
186       $obj = $this->by_object[$class];
187       if ( $this->by_object[$class]->pl_notify && ($obj->is_account || $obj->ignore_account)){
188         $notify= "id=\"notify\"";
189       } else {
190         $notify= "";
191       }
193       if ($_SESSION['js']==FALSE){      
194         $display.= "<div ".$notify." class=\"$style[$index]\"><input type=\"submit\" name=\"$class\"".
195           " class=\"$style[$index]\" value=\"$title\"";
196       } else {                   
197         $display.= "<div ".$notify." class=\"$style[$index]\"><a class=\"$style[$index]\" onclick=\"return true;\" href=\"javascript:document.mainform.arg.value='$class';document.mainform.submit();\">$title</a";
198       }
199       $display.= "></div></td>";
200     }
201     $display.= "<td style=\"vertical-align:bottom;\">\n";
202     $display.= "<div class=\"tab_border\">&nbsp;</div></td></tr></table>";
204     return($display);
205   }
208   function set_acl($acl)
209   {
210         /* Look for attribute in ACL */
211           trigger_error("Don't use tabs::set_acl() its obsolete.");
212   }
214   function delete()
215   {
216     /* Check if all plugins will ACK for deletion */
217     foreach (array_reverse($this->by_object) as $key => $obj){
218       $reason= $obj->allow_remove();
219       if ($reason != ""){
220         print_red(sprintf(_("Delete process has been canceled by plugin '%s': %s"), $key, $reason));
221         return;
222       }
223     }
225     /* Delete for all plugins */
226     foreach (array_reverse($this->by_object) as $obj){
227       $obj->remove_from_parent();
228     }
229   }
231   function password_change_needed()
232   {
233     /* Ask all plugins for needed password changes */
234     foreach ($this->by_object as &$obj){
235       if ($obj->password_change_needed()){
236         return TRUE;
237       }
238     }
240     return FALSE;
241   }
243   function check($ignore_account= FALSE)
244   {
245     $this->save_object(TRUE);
246     $messages= array();
248     $current_set = FALSE;
250     /* Check all plugins */
251     foreach ($this->by_object as $key => &$obj){
252       if ($obj->is_account || $ignore_account || $obj->ignore_account){
253         @DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__,$key, "Checking");
255         $msg = $obj->check();
257         if (count($msg)){
258           $obj->pl_notify= TRUE;
259           if(!$current_set){
260             $current_set = TRUE;
261             $this->current= $key;
262             $messages = $msg;
263           }
264         }else{
265           $obj->pl_notify= FALSE;
266         }
267       }else{
268         $obj->pl_notify= FALSE;
269       }
270     }
271     return ($messages);
272   }
274   function save($ignore_account= FALSE)
275   {
276     /* Save all plugins */
277     foreach ($this->by_object as $key => &$obj){
278       @DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__,
279           $key, "Saving");
281       $obj->dn= $this->dn;
283       if ($obj->is_account || $ignore_account || $obj->ignore_account){
284         if ($obj->save() == 1){
285           return (1);
286         }
287       } else {
288         $obj->remove_from_parent();
289       }
290     }
291     return (0);
292   }
294   function adapt_from_template($dn)
295   {
296     foreach ($this->by_object as $key => &$obj){
297       @DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__,
298           $key, "Adapting");
299       $obj->parent= &$this;
300       $obj->adapt_from_template($dn);
301     }
302   }
304         
305   /* Save attributes posted by copy & paste dialog
306    */
307   function saveCopyDialog()
308   {
309           foreach ($this->by_object as &$obj){
310                   if($obj->is_account){
311                           $obj->saveCopyDialog();
312                   }
313           }
314   }
317   /* return copy & paste dialog
318    */
319   function getCopyDialog()
320   {
321     $ret = "";
322     $this->SubDialog = false;
323     foreach ($this->by_object as &$obj){
324       if($obj->is_account){
325         $tmp = $obj->getCopyDialog();
326         if($tmp['status'] == "SubDialog"){
327           $this->SubDialog = true;
328           return($tmp['string']);
329         }else{
330           if(!empty($tmp['string'])){
331             $ret .= $tmp['string'];
332             $ret .= "<p class='seperator'>&nbsp;</p>";
333           }
334         }
335       }
336     }
337     return($ret);
338   }
341   function addSpecialTabs()
342   {
343     $this->by_name['acl']= _("ACL");
344     $this->by_object['acl']= new acl($this->config, $this, $this->dn);
345     $this->by_object['acl']->parent= &$this;
346     $this->by_name['reference']= _("References");
347     $this->by_object['reference']= new reference($this->config, $this->dn);
348     $this->by_object['reference']->parent= &$this;
349   }
352   function set_acl_base($base= "")
353   {
354     /* Update reference, transfer variables */
355     $first= ($base == "");
356     foreach ($this->by_object as &$obj){
357       if ($first){
358         $first= FALSE;
359         $base= $obj->acl_base;
360       } else {
361         $obj->set_acl_base($base);
362       }
363     }
364   }
367 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
368 ?>