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;
41 foreach ($data as $tab){
42 $this->by_name[$tab['CLASS']]= $tab['NAME'];
43 $this->by_object[$tab['CLASS']]= new $tab['CLASS']($this->config, $this->dn);
44 $this->by_object[$tab['CLASS']]->parent= &$this;
46 /* Initialize current */
47 if ($this->current == ""){
48 $this->current= $tab['CLASS'];
49 }
50 }
52 }
54 function execute()
55 {
56 /* Rotate current to last */
57 $this->last= $this->current;
59 /* Look for pressed tab button */
60 foreach ($this->by_object as $class => $obj){
61 if (isset($_POST[$class]) || (isset($_POST['arg']) && $_POST['arg'] == "$class")){
62 $this->current= $class;
63 break;
64 }
65 }
67 /* Save last tab object */
68 if ($this->last == $this->current){
69 $this->save_object(TRUE);
70 } else {
71 $this->save_object(FALSE);
72 }
74 /* Build tab line */
75 $display= $this->gen_tabs();
77 /* Show object */
78 $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";
79 $display.= "<tr><td>\n";
81 $obj= $this->by_object[$this->current];
82 $display.= $obj->execute();
83 $this->by_object[$this->current]= $obj;
85 /* Footer for tabbed dialog */
86 $display.= "</td></tr></table>";
87 return ($display);
88 }
90 function save_object($save_current= FALSE)
91 {
92 /* Save last tab */
93 if ($this->last != ""){
94 @DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__,
95 $this->last, "Saving");
97 $obj= $this->by_object[$this->last];
98 $obj->save_object ();
99 $this->by_object[$this->last]= $obj;
100 }
102 /* Skip if curent and last are the same object */
103 if ($this->last == $this->current){
104 return;
105 }
107 $obj= $this->by_object[$this->current];
108 $this->disabled= $obj->parent->disabled;
110 if ($save_current){
111 @DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__,
112 $this->current, "Saving (current)");
114 $obj->save_object ();
115 $this->by_object[$this->current]= $obj;
116 }
118 }
120 function gen_tabs()
121 {
122 $display= "<input type=\"hidden\" name=\"arg\" value=\"\">";
123 $display.= "<table summary=\"\" cellpadding=0 cellspacing=0 border=0 style=\"width:100%;\"><tr>";
124 $index= 0;
125 $style= array("tab_left", "tab_active", "tab_near_active", "tab_right");
126 foreach ($this->by_name as $class => $name){
128 /* Activate right tabs with style "tab_right"
129 Activate near current with style "tab_near_active" */
130 if ($index == 2 || $index == 1){
131 $index++;
132 }
134 /* Activate current tab with style "tab_active " */
135 if ($class == $this->current){
136 $index++;
137 }
139 /* Paint tab */
140 $display.= "<td style=\"vertical-align:bottom; width:100px;\">";
142 /* Shorten string if its too long for the tab headers*/
143 $title= _($name);
144 if (mb_strlen($title, 'UTF-8') > 14){
145 $title= mb_substr($title,0, 12, 'UTF-8')."...";
146 }
148 if ($_SESSION['js']==FALSE){
149 $display.= "<div class=\"$style[$index]\"><input type=\"submit\" name=\"$class\"".
150 " class=\"$style[$index]\" value=\"$title\"";
151 } else {
152 $display.= "<div class=\"$style[$index]\"><a class=\"$style[$index]\" onclick=\"return true;\" href=\"javascript:document.mainform.arg.value='$class';document.mainform.submit();\">$title</a";
153 }
154 $display.= "></div></td>";
155 }
156 $display.= "<td style=\"vertical-align:bottom;\">\n";
157 $display.= "<div class=\"tab_border\"> </div></td></tr></table>";
159 return($display);
160 }
163 function set_acl($acl)
164 {
165 /* Set local acl */
166 $this->acl= $acl;
168 /* Setup for all plugins */
169 foreach ($this->by_object as $key => $obj){
170 $sacl= get_module_permission($acl, "$key", $this->dn);
171 $obj->acl= $sacl;
172 $this->by_object[$key]= $obj;
173 }
174 }
176 function delete()
177 {
178 /* Delete for all plugins */
179 foreach (array_reverse($this->by_object) as $key => $obj){
180 $obj->remove_from_parent();
181 }
182 }
184 function password_change_needed()
185 {
186 /* Ask all plugins for needed password changes */
187 foreach ($this->by_object as $key => $obj){
188 if ($obj->password_change_needed()){
189 return TRUE;
190 }
191 }
193 return FALSE;
194 }
196 function check($ignore_account= FALSE)
197 {
198 $this->save_object(TRUE);
199 $messages= array();
201 /* Check all plugins */
202 foreach ($this->by_object as $key => $obj){
203 if ($obj->is_account || $ignore_account || $obj->ignore_account){
204 @DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__,
205 $key, "Checking");
207 $messages= $obj->check();
208 if (count($messages)){
209 $this->current= $key;
210 break;
211 }
212 }
213 }
215 return ($messages);
216 }
218 function save($ignore_account= FALSE)
219 {
220 /* Save all plugins */
221 foreach ($this->by_object as $key => $obj){
222 @DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__,
223 $key, "Saving");
225 $obj->dn= $this->dn;
227 if ($obj->is_account || $ignore_account || $obj->ignore_account){
228 if ($obj->save() == 1){
229 return (1);
230 }
231 } else {
232 $obj->remove_from_parent();
233 }
234 }
235 return (0);
236 }
238 function adapt_from_template($dn)
239 {
240 foreach ($this->by_object as $key => $obj){
241 @DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__,
242 $key, "Adapting");
243 $obj->parent= &$this;
244 $obj->adapt_from_template($dn);
245 $this->by_object[$key]= $obj;
246 }
247 }
250 /* Save attributes posted by copy & paste dialog
251 */
252 function saveCopyDialog()
253 {
254 foreach ($this->by_object as $key => $obj){
255 if($obj->is_account){
256 $this->by_object[$key]->saveCopyDialog();
257 }
258 }
259 }
262 /* return copy & paste dialog
263 */
264 function getCopyDialog()
265 {
266 $ret = "";
267 $this->SubDialog = false;
268 foreach ($this->by_object as $key => $obj){
269 if($obj->is_account){
270 $tmp = $this->by_object[$key]->getCopyDialog();
271 if($tmp['status'] == "SubDialog"){
272 $this->SubDialog = true;
273 return($tmp['string']);
274 }else{
275 $ret .= $tmp['string'];
276 }
277 }
278 }
279 return($ret);
280 }
282 }
284 ?>