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:1px;\">";
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 /* Check if all plugins will ACK for deletion */
179 foreach (array_reverse($this->by_object) as $key => $obj){
180 $reason= $obj->allow_remove();
181 if ($reason != ""){
182 print_red(sprintf(_("Delete process has been canceled by plugin '%s': %s"), $key, $reason));
183 return;
184 }
185 }
187 /* Delete for all plugins */
188 foreach (array_reverse($this->by_object) as $key => $obj){
189 $obj->remove_from_parent();
190 }
191 }
193 function password_change_needed()
194 {
195 /* Ask all plugins for needed password changes */
196 foreach ($this->by_object as $key => $obj){
197 if ($obj->password_change_needed()){
198 return TRUE;
199 }
200 }
202 return FALSE;
203 }
205 function check($ignore_account= FALSE)
206 {
207 $this->save_object(TRUE);
208 $messages= array();
210 /* Check all plugins */
211 foreach ($this->by_object as $key => $obj){
212 if ($obj->is_account || $ignore_account || $obj->ignore_account){
213 @DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__,
214 $key, "Checking");
216 $messages= $obj->check();
217 if (count($messages)){
218 $this->current= $key;
219 break;
220 }
221 }
222 }
224 return ($messages);
225 }
227 function save($ignore_account= FALSE)
228 {
229 /* Save all plugins */
230 foreach ($this->by_object as $key => $obj){
231 @DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__,
232 $key, "Saving");
234 $obj->dn= $this->dn;
236 if ($obj->is_account || $ignore_account || $obj->ignore_account){
237 if ($obj->save() == 1){
238 return (1);
239 }
240 } else {
241 $obj->remove_from_parent();
242 }
243 }
244 return (0);
245 }
247 function adapt_from_template($dn)
248 {
249 foreach ($this->by_object as $key => $obj){
250 @DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__,
251 $key, "Adapting");
252 $obj->parent= &$this;
253 $obj->adapt_from_template($dn);
254 $this->by_object[$key]= $obj;
255 }
256 }
259 /* Save attributes posted by copy & paste dialog
260 */
261 function saveCopyDialog()
262 {
263 foreach ($this->by_object as $key => $obj){
264 if($obj->is_account){
265 $this->by_object[$key]->saveCopyDialog();
266 }
267 }
268 }
271 /* return copy & paste dialog
272 */
273 function getCopyDialog()
274 {
275 $ret = "";
276 $this->SubDialog = false;
277 foreach ($this->by_object as $key => $obj){
278 if($obj->is_account){
279 $tmp = $this->by_object[$key]->getCopyDialog();
280 if($tmp['status'] == "SubDialog"){
281 $this->SubDialog = true;
282 return($tmp['string']);
283 }else{
284 $ret .= $tmp['string'];
285 }
286 }
287 }
288 return($ret);
289 }
292 function addSpecialTabs()
293 {
294 $this->by_name['acl']= _("ACL");
295 $this->by_object['acl']= new acl($this->config, $this->dn);
296 $this->by_object['acl']->parent= &$this;
297 $this->by_name['reference']= _("References");
298 $this->by_object['reference']= new reference($this->config, $this->dn);
299 $this->by_object['reference']->parent= &$this;
300 }
303 }
305 ?>