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 if (is_php4()){
90 $this->by_object[$this->current]= $obj;
91 }
93 /* Footer for tabbed dialog */
94 $display.= "</td></tr></table>";
95 return ($display);
96 }
98 function save_object($save_current= FALSE)
99 {
100 /* Save last tab */
101 if ($this->last != ""){
102 @DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__,
103 $this->last, "Saving");
105 $obj= $this->by_object[$this->last];
106 $obj->save_object ();
107 if (is_php4()){
108 $this->by_object[$this->last]= $obj;
109 }
110 }
112 /* Skip if curent and last are the same object */
113 if ($this->last == $this->current){
114 return;
115 }
117 $obj= $this->by_object[$this->current];
118 $this->disabled= $obj->parent->disabled;
120 if ($save_current){
121 @DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__,
122 $this->current, "Saving (current)");
124 $obj->save_object ();
125 if (is_php4()){
126 $this->by_object[$this->current]= $obj;
127 }
128 }
130 }
132 function gen_tabs()
133 {
134 $display= "<input type=\"hidden\" name=\"arg\" value=\"\">";
135 $display.= "<table summary=\"\" cellpadding=0 cellspacing=0 border=0 style=\"width:100%;\"><tr>";
136 $index= 0;
137 $style= array("tab_left", "tab_active", "tab_near_active", "tab_right");
138 foreach ($this->by_name as $class => $name){
140 /* Activate right tabs with style "tab_right"
141 Activate near current with style "tab_near_active" */
142 if ($index == 2 || $index == 1){
143 $index++;
144 }
146 /* Activate current tab with style "tab_active " */
147 if ($class == $this->current){
148 $index++;
149 }
151 /* Paint tab */
152 $display.= "<td style=\"vertical-align:bottom;width:1px;white-space:nowrap;\">";
154 /* Shorten string if its too long for the tab headers*/
155 $title= _($name);
156 if (mb_strlen($title, 'UTF-8') > 14){
157 $title= mb_substr($title,0, 12, 'UTF-8')."...";
158 }
160 $title= preg_replace("/ /", " ", $title);
162 /* Take care about notifications */
163 if ($this->by_object[$class]->pl_notify){
164 $notify= "id=\"notify\"";
165 } else {
166 $notify= "";
167 }
168 if ($_SESSION['js']==FALSE){
169 $display.= "<div class=\"$style[$index]\" $notify><input type=\"submit\" name=\"$class\"".
170 " class=\"$style[$index]\" value=\"$title\"";
171 } else {
172 $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";
173 }
174 $display.= "></div></td>";
175 }
176 $display.= "<td style=\"vertical-align:bottom;\">\n";
177 $display.= "<div class=\"tab_border\"> </div></td></tr></table>";
179 return($display);
180 }
183 function set_acl($acl)
184 {
185 /* Set local acl */
186 $this->acl= $acl;
188 /* Setup for all plugins */
189 foreach ($this->by_object as $key => $obj){
190 $sacl= get_module_permission($acl, "$key", $this->dn, false);
191 $obj->acl= $sacl;
192 if (is_php4()){
193 $this->by_object[$key]= $obj;
194 }
195 }
196 }
198 function delete()
199 {
200 /* Check if all plugins will ACK for deletion */
201 foreach (array_reverse($this->by_object) as $key => $obj){
202 $reason= $obj->allow_remove();
203 if ($reason != ""){
204 print_red(sprintf(_("Delete process has been canceled by plugin '%s': %s"), $key, $reason));
205 return;
206 }
207 }
209 /* Delete for all plugins */
210 foreach (array_reverse($this->by_object) as $key => $obj){
211 $obj->remove_from_parent();
212 }
213 }
215 function password_change_needed()
216 {
217 /* Ask all plugins for needed password changes */
218 foreach ($this->by_object as $key => $obj){
219 if ($obj->password_change_needed()){
220 return TRUE;
221 }
222 }
224 return FALSE;
225 }
227 function check($ignore_account= FALSE)
228 {
229 $this->save_object(TRUE);
230 $messages= array();
232 $current_set = FALSE;
234 /* Check all plugins */
235 foreach ($this->by_object as $key => $obj){
236 if ($obj->is_account || $ignore_account || $obj->ignore_account){
237 @DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__,
238 $key, "Checking");
240 $msg= $obj->check();
241 if (is_php4()){
242 $this->by_object[$key]= $obj;
243 }
244 if (count($msg)){
245 $this->by_object[$key]->pl_notify= TRUE;
246 if(!$current_set){
247 $current_set = TRUE;
248 $this->current= $key;
249 $messages = $msg;
250 }
251 }else{
252 $this->by_object[$key]->pl_notify= FALSE;
253 }
254 }else{
255 $this->by_object[$key]->pl_notify= FALSE;
256 }
257 }
259 return ($messages);
260 }
262 function save($ignore_account= FALSE)
263 {
264 /* Save all plugins */
265 foreach ($this->by_object as $key => $obj){
266 @DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__,
267 $key, "Saving");
269 $obj->dn= $this->dn;
271 if ($obj->is_account || $ignore_account || $obj->ignore_account){
272 if ($obj->save() == 1){
273 return (1);
274 }
275 } else {
276 $obj->remove_from_parent();
277 }
278 }
279 return (0);
280 }
282 function adapt_from_template($dn)
283 {
284 foreach ($this->by_object as $key => $obj){
285 @DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__,
286 $key, "Adapting");
287 $obj->parent= &$this;
288 $obj->adapt_from_template($dn);
289 if (is_php4()){
290 $this->by_object[$key]= $obj;
291 }
292 }
293 }
296 /* Save attributes posted by copy & paste dialog
297 */
298 function saveCopyDialog()
299 {
300 foreach ($this->by_object as $key => $obj){
301 if($obj->is_account){
302 $this->by_object[$key]->saveCopyDialog();
303 }
304 }
305 }
308 /* return copy & paste dialog
309 */
310 function getCopyDialog()
311 {
312 $ret = "";
313 $this->SubDialog = false;
314 foreach ($this->by_object as $key => $obj){
315 if($obj->is_account){
316 $tmp = $this->by_object[$key]->getCopyDialog();
317 if($tmp['status'] == "SubDialog"){
318 $this->SubDialog = true;
319 return($tmp['string']);
320 }else{
321 if(!empty($tmp['string'])){
322 $ret .= $tmp['string'];
323 $ret .= "<p class='seperator'> </p>";
324 }
325 }
326 }
327 }
328 return($ret);
329 }
330 }
332 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
333 ?>