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 }
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 to keep the tab name in one line */
183 $title= preg_replace("/ /"," ",$title);
185 /* Take care about notifications */
186 if ($this->by_object[$class]->pl_notify){
187 $notify= "id=\"notify\"";
188 } else {
189 $notify= "";
190 }
192 if ($_SESSION['js']==FALSE){
193 $display.= "<div ".$notify." class=\"$style[$index]\"><input type=\"submit\" name=\"$class\"".
194 " class=\"$style[$index]\" value=\"$title\"";
195 } else {
196 $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";
197 }
198 $display.= "></div></td>";
199 }
200 $display.= "<td style=\"vertical-align:bottom;\">\n";
201 $display.= "<div class=\"tab_border\"> </div></td></tr></table>";
203 return($display);
204 }
207 function set_acl($acl)
208 {
209 /* Look for attribute in ACL */
210 trigger_error("Don't use tabs::set_acl() its obsolete.");
211 }
213 function delete()
214 {
215 /* Check if all plugins will ACK for deletion */
216 foreach (array_reverse($this->by_object) as $key => $obj){
217 $reason= $obj->allow_remove();
218 if ($reason != ""){
219 print_red(sprintf(_("Delete process has been canceled by plugin '%s': %s"), $key, $reason));
220 return;
221 }
222 }
224 /* Delete for all plugins */
225 foreach (array_reverse($this->by_object) as $obj){
226 $obj->remove_from_parent();
227 }
228 }
230 function password_change_needed()
231 {
232 /* Ask all plugins for needed password changes */
233 foreach ($this->by_object as &$obj){
234 if ($obj->password_change_needed()){
235 return TRUE;
236 }
237 }
239 return FALSE;
240 }
242 function check($ignore_account= FALSE)
243 {
244 $this->save_object(TRUE);
245 $messages= array();
247 $current_set = FALSE;
249 /* Check all plugins */
250 foreach ($this->by_object as $key => &$obj){
251 if ($obj->is_account || $ignore_account || $obj->ignore_account){
252 @DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__,$key, "Checking");
254 $msg = $obj->check();
256 if (count($msg)){
257 $obj->pl_notify= TRUE;
258 if(!$current_set){
259 $current_set = TRUE;
260 $this->current= $key;
261 $messages = $msg;
262 }
263 }else{
264 $obj->pl_notify= FALSE;
265 }
266 }else{
267 $obj->pl_notify= FALSE;
268 }
269 }
270 return ($messages);
271 }
273 function save($ignore_account= FALSE)
274 {
275 /* Save all plugins */
276 foreach ($this->by_object as $key => &$obj){
277 @DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__,
278 $key, "Saving");
280 $obj->dn= $this->dn;
282 if ($obj->is_account || $ignore_account || $obj->ignore_account){
283 if ($obj->save() == 1){
284 return (1);
285 }
286 } else {
287 $obj->remove_from_parent();
288 }
289 }
290 return (0);
291 }
293 function adapt_from_template($dn)
294 {
295 foreach ($this->by_object as $key => &$obj){
296 @DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__,
297 $key, "Adapting");
298 $obj->parent= &$this;
299 $obj->adapt_from_template($dn);
300 }
301 }
304 /* Save attributes posted by copy & paste dialog
305 */
306 function saveCopyDialog()
307 {
308 foreach ($this->by_object as &$obj){
309 if($obj->is_account){
310 $obj->saveCopyDialog();
311 }
312 }
313 }
316 /* return copy & paste dialog
317 */
318 function getCopyDialog()
319 {
320 $ret = "";
321 $this->SubDialog = false;
322 foreach ($this->by_object as &$obj){
323 if($obj->is_account){
324 $tmp = $obj->getCopyDialog();
325 if($tmp['status'] == "SubDialog"){
326 $this->SubDialog = true;
327 return($tmp['string']);
328 }else{
329 if(!empty($tmp['string'])){
330 $ret .= $tmp['string'];
331 $ret .= "<p class='seperator'> </p>";
332 }
333 }
334 }
335 }
336 return($ret);
337 }
340 function addSpecialTabs()
341 {
342 $this->by_name['acl']= _("ACL");
343 $this->by_object['acl']= new acl($this->config, $this, $this->dn);
344 $this->by_object['acl']->parent= &$this;
345 $this->by_name['reference']= _("References");
346 $this->by_object['reference']= new reference($this->config, $this->dn);
347 $this->by_object['reference']->parent= &$this;
348 }
351 function set_acl_base($base= "")
352 {
353 /* Update reference, transfer variables */
354 $first= ($base == "");
355 foreach ($this->by_object as &$obj){
356 if ($first){
357 $first= FALSE;
358 $base= $obj->acl_base;
359 } else {
360 $obj->set_acl_base($base);
361 }
362 }
363 }
365 }
366 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
367 ?>