Code

Fixed acls & picture settings
[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         foreach ($data as $tab){
43                 $this->by_name[$tab['CLASS']]= $tab['NAME'];
44                 $this->by_object[$tab['CLASS']]= new $tab['CLASS']($this->config, $this->dn);
45                 $this->by_object[$tab['CLASS']]->parent= &$this;
46                 $this->by_object[$tab['CLASS']]->set_acl_category($acl_category);
48                 /* Initialize current */
49                 if ($this->current == ""){
50                         $this->current= $tab['CLASS'];
51                 }
52         }
53   }
55   function execute()
56   {
57         /* Rotate current to last */
58         $this->last= $this->current;
60         /* Look for pressed tab button */
61         foreach ($this->by_object as $class => $obj){
62                 if (isset($_POST[$class]) || (isset($_POST['arg']) && $_POST['arg'] == "$class")){
63                         $this->current= $class;
64                         break;
65                 }
66         }
68         /* Save last tab object */
69         if ($this->last == $this->current){
70                 $this->save_object(TRUE);
71         } else {
72                 $this->save_object(FALSE);
73         }
75         /* Build tab line */
76         $display= $this->gen_tabs();
78         /* Show object */
79         $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";
80         $display.= "<tr><td>\n";
82         $obj= $this->by_object[$this->current];
83         $display.= $obj->execute();
84         $this->by_object[$this->current]= $obj;
86         /* Footer for tabbed dialog */
87         $display.= "</td></tr></table>";
88         return ($display);
89   }
91   function save_object($save_current= FALSE)
92   {
93         /* Save last tab */
94         if ($this->last != ""){
95                 @DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__,
96                         $this->last, "Saving");
98                 $obj= $this->by_object[$this->last];
99                 $obj->save_object ();
100                 $this->by_object[$this->last]= $obj;
101         }
103         /* Skip if curent and last are the same object */
104         if ($this->last == $this->current){
105                 return;
106         }
108         $obj= $this->by_object[$this->current];
109         $this->disabled= $obj->parent->disabled;
111         if ($save_current){
112                 @DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__,
113                         $this->current, "Saving (current)");
115                 $obj->save_object ();
116                 $this->by_object[$this->current]= $obj;
117         }
119   }
121   function gen_tabs()
122   {
123         $display= "<input type=\"hidden\" name=\"arg\" value=\"\">";
124         $display.= "<table summary=\"\" cellpadding=0 cellspacing=0 border=0 style=\"width:100%;\"><tr>";
125         $index= 0;
126         $style= array("tab_left", "tab_active", "tab_near_active", "tab_right");
127         foreach ($this->by_name as $class => $name){
129                 /* Activate right tabs with style "tab_right"
130                    Activate near current with style "tab_near_active" */
131                 if ($index == 2 || $index == 1){
132                         $index++;
133                 }
135                 /* Activate current tab with style "tab_active " */
136                 if ($class == $this->current){
137                         $index++;
138                 }
140                 /* Paint tab */
141                 $display.= "<td style=\"vertical-align:bottom;width:1px;\">";
143                 /* Shorten string if its too long for the tab headers*/
144                 $title= _($name);
145                 if (mb_strlen($title, 'UTF-8') > 28){
146                         $title= mb_substr($title,0, 25, 'UTF-8')."...";
147                 }
148                         
149                 /* nobr causes w3c warnings so we use &nbsp; to keep the tab name in one line */
150                 $title= preg_replace("/ /","&nbsp;",$title);
152                 if ($_SESSION['js']==FALSE){    
153                         $display.= "<div class=\"$style[$index]\"><input type=\"submit\" name=\"$class\"".
154                                    " class=\"$style[$index]\" value=\"$title\"";
155                 } else {                         
156                         $display.= "<div class=\"$style[$index]\"><a class=\"$style[$index]\" onclick=\"return true;\" href=\"javascript:document.mainform.arg.value='$class';document.mainform.submit();\">$title</a";
157                 }
158                 $display.= "></div></td>";
159         }
160         $display.= "<td style=\"vertical-align:bottom;\">\n";
161         $display.= "<div class=\"tab_border\">&nbsp;</div></td></tr></table>";
163         return($display);
164   }
167   function set_acl($acl)
168   {
169         /* Set local acl */
170         $this->acl= $acl;
172         /* Setup for all plugins */
173         foreach ($this->by_object as $key => $obj){
174                 $sacl= get_module_permission($acl, "$key", $this->dn);
175                 $obj->acl= $sacl;
176                 $this->by_object[$key]= $obj;
177         }
178   }
180   function delete()
181   {
182         /* Check if all plugins will ACK for deletion */
183         foreach (array_reverse($this->by_object) as $key => $obj){
184                 $reason= $obj->allow_remove();
185                 if ($reason != ""){
186                         print_red(sprintf(_("Delete process has been canceled by plugin '%s': %s"), $key, $reason));
187                         return;
188                 }
189         }
191         /* Delete for all plugins */
192         foreach (array_reverse($this->by_object) as $key => $obj){
193                 $obj->remove_from_parent();
194         }
195   }
197   function password_change_needed()
198   {
199         /* Ask all plugins for needed password changes */
200         foreach ($this->by_object as $key => $obj){
201                 if ($obj->password_change_needed()){
202                         return TRUE;
203                 }
204         }
206         return FALSE;
207   }
209   function check($ignore_account= FALSE)
210   {
211         $this->save_object(TRUE);
212         $messages= array();
214         /* Check all plugins */
215         foreach ($this->by_object as $key => $obj){
216                 if ($obj->is_account || $ignore_account || $obj->ignore_account){
217                         @DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__,
218                                 $key, "Checking");
220                         $messages= $obj->check();
221                         if (count($messages)){
222                                 $this->current= $key;
223                                 break;
224                         }
225                 }
226         }
228         return ($messages);
229   }
231   function save($ignore_account= FALSE)
232   {
233         /* Save all plugins */
234         foreach ($this->by_object as $key => $obj){
235                 @DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__,
236                         $key, "Saving");
238                 $obj->dn= $this->dn;
239                 
240                 if ($obj->is_account || $ignore_account || $obj->ignore_account){
241                         if ($obj->save() == 1){
242                                 return (1);
243                         }
244                 } else {
245                         $obj->remove_from_parent();
246                 }
247         }
248         return (0);
249   }
251   function adapt_from_template($dn)
252   {
253           foreach ($this->by_object as $key => $obj){
254                   @DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__,
255                                   $key, "Adapting");
256                   $obj->parent= &$this;
257                   $obj->adapt_from_template($dn);
258                   $this->by_object[$key]= $obj;
259           }
260   }
262         
263   /* Save attributes posted by copy & paste dialog
264    */
265   function saveCopyDialog()
266   {
267           foreach ($this->by_object as $key => $obj){
268                   if($obj->is_account){
269                           $this->by_object[$key]->saveCopyDialog();
270                   }
271           }
272   }
275   /* return copy & paste dialog
276    */
277   function getCopyDialog()
278   {
279           $ret = "";
280           $this->SubDialog = false;
281           foreach ($this->by_object as $key => $obj){
282                   if($obj->is_account){
283                           $tmp = $this->by_object[$key]->getCopyDialog();
284                           if($tmp['status'] == "SubDialog"){
285                                   $this->SubDialog = true;
286                       return($tmp['string']);
287                   }else{
288                  $ret .= $tmp['string'];
289                           }
290                   }
291           }
292           return($ret);
293   }
296   function addSpecialTabs()
297   {
298         $this->by_name['acl']= _("ACL");
299         $this->by_object['acl']= new acl($this->config, $this, $this->dn);
300         $this->by_object['acl']->parent= &$this;
301         $this->by_name['reference']= _("References");
302         $this->by_object['reference']= new reference($this->config, $this->dn);
303         $this->by_object['reference']->parent= &$this;
304   }
307   function set_acl_base($base= "")
308   {
309         /* Update reference, transfer variables */
310         $first= ($base == "");
311         foreach ($this->by_object as $name => $obj){
312                 if ($first){
313                         $first= FALSE;
314                         $base= $obj->acl_base;
315                 } else {
316                         $obj->set_acl_base($base);
317                         $this->by_object[$name]= $obj;
318                 }
319         }
320   }
324 ?>