Code

Added ACL's for ACL's. Currently this was done via "All". Now it is done by a special ACL
[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         $this->by_object[$this->current]= $obj;
91         /* Footer for tabbed dialog */
92         $display.= "</td></tr></table>";
93         return ($display);
94   }
96   function save_object($save_current= FALSE)
97   {
98         /* Save last tab */
99         if ($this->last != ""){
100                 @DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__,
101                         $this->last, "Saving");
103                 $obj= $this->by_object[$this->last];
104                 $obj->save_object ();
105                 $this->by_object[$this->last]= $obj;
106         }
108         /* Skip if curent and last are the same object */
109         if ($this->last == $this->current){
110                 return;
111         }
113         $obj= $this->by_object[$this->current];
114         $this->disabled= $obj->parent->disabled;
116         if ($save_current){
117                 @DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__,
118                         $this->current, "Saving (current)");
120                 $obj->save_object ();
121                 $this->by_object[$this->current]= $obj;
122         }
124   }
126   function gen_tabs()
127   {
128         $display= "<input type=\"hidden\" name=\"arg\" value=\"\">";
129         $display.= "<table summary=\"\" cellpadding=0 cellspacing=0 border=0 style=\"width:100%;\"><tr>";
130         $index= 0;
131         $style= array("tab_left", "tab_active", "tab_near_active", "tab_right");
132         foreach ($this->by_name as $class => $name){
134                 /* Activate right tabs with style "tab_right"
135                    Activate near current with style "tab_near_active" */
136                 if ($index == 2 || $index == 1){
137                         $index++;
138                 }
140                 /* Activate current tab with style "tab_active " */
141                 if ($class == $this->current){
142                         $index++;
143                 }
145                 /* Paint tab */
146                 $display.= "<td style=\"vertical-align:bottom;width:1px;\">";
148                 /* Shorten string if its too long for the tab headers*/
149                 $title= _($name);
150                 if (mb_strlen($title, 'UTF-8') > 14){
151                         $title= mb_substr($title,0, 12, 'UTF-8')."...";
152                 }
154                 $title= preg_replace("/ /", "&nbsp;", $title);
155                 
156                 if ($_SESSION['js']==FALSE){    
157                         $display.= "<div class=\"$style[$index]\"><input type=\"submit\" name=\"$class\"".
158                                    " class=\"$style[$index]\" value=\"$title\"";
159                 } else {                         
160                         $display.= "<div class=\"$style[$index]\"><a class=\"$style[$index]\" onclick=\"return true;\" href=\"javascript:document.mainform.arg.value='$class';document.mainform.submit();\">$title</a";
161                 }
162                 $display.= "></div></td>";
163         }
164         $display.= "<td style=\"vertical-align:bottom;\">\n";
165         $display.= "<div class=\"tab_border\">&nbsp;</div></td></tr></table>";
167         return($display);
168   }
171   function set_acl($acl)
172   {
173     /* Set local acl */
174     $this->acl= $acl;
176     /* Setup for all plugins */
177     foreach ($this->by_object as $key => $obj){
178       $sacl= get_module_permission($acl, "$key", $this->dn);
179       $obj->acl= $sacl;
180       $this->by_object[$key]= $obj;
181     }
182   }
184   function delete()
185   {
186     /* Check if all plugins will ACK for deletion */
187     foreach (array_reverse($this->by_object) as $key => $obj){
188       $reason= $obj->allow_remove();
189       if ($reason != ""){
190         print_red(sprintf(_("Delete process has been canceled by plugin '%s': %s"), $key, $reason));
191         return;
192       }
193     }
195     /* Delete for all plugins */
196     foreach (array_reverse($this->by_object) as $key => $obj){
197       $obj->remove_from_parent();
198     }
199   }
201   function password_change_needed()
202   {
203     /* Ask all plugins for needed password changes */
204     foreach ($this->by_object as $key => $obj){
205       if ($obj->password_change_needed()){
206         return TRUE;
207       }
208     }
210     return FALSE;
211   }
213   function check($ignore_account= FALSE)
214   {
215         $this->save_object(TRUE);
216         $messages= array();
218         /* Check all plugins */
219         foreach ($this->by_object as $key => $obj){
220                 if ($obj->is_account || $ignore_account || $obj->ignore_account){
221                         @DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__,
222                                 $key, "Checking");
224                         $messages= $obj->check();
225                         if (count($messages)){
226                                 $this->current= $key;
227                                 break;
228                         }
229                 }
230         }
232         return ($messages);
233   }
235   function save($ignore_account= FALSE)
236   {
237         /* Save all plugins */
238         foreach ($this->by_object as $key => $obj){
239                 @DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__,
240                         $key, "Saving");
242                 $obj->dn= $this->dn;
243                 
244                 if ($obj->is_account || $ignore_account || $obj->ignore_account){
245                         if ($obj->save() == 1){
246                                 return (1);
247                         }
248                 } else {
249                         $obj->remove_from_parent();
250                 }
251         }
252         return (0);
253   }
255   function adapt_from_template($dn)
256   {
257           foreach ($this->by_object as $key => $obj){
258                   @DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__,
259                                   $key, "Adapting");
260                   $obj->parent= &$this;
261                   $obj->adapt_from_template($dn);
262                   $this->by_object[$key]= $obj;
263           }
264   }
266         
267   /* Save attributes posted by copy & paste dialog
268    */
269   function saveCopyDialog()
270   {
271           foreach ($this->by_object as $key => $obj){
272                   if($obj->is_account){
273                           $this->by_object[$key]->saveCopyDialog();
274                   }
275           }
276   }
279   /* return copy & paste dialog
280    */
281   function getCopyDialog()
282   {
283     $ret = "";
284     $this->SubDialog = false;
285     foreach ($this->by_object as $key => $obj){
286       if($obj->is_account){
287         $tmp = $this->by_object[$key]->getCopyDialog();
288         if($tmp['status'] == "SubDialog"){
289           $this->SubDialog = true;
290           return($tmp['string']);
291         }else{
292           if(!empty($tmp['string'])){
293             $ret .= $tmp['string'];
294             $ret .= "<p class='seperator'>&nbsp;</p>";
295           }
296         }
297       }
298     }
299     return($ret);
300   }
303 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
304 ?>