5c3204571425c628e8d6118e679ca81ea6d55fa3
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, $gui= true)
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 if ($gui){
44 $this->by_object[$tab['CLASS']]= new $tab['CLASS']($this->config, $this->dn);
45 } else {
46 $this->by_object[$tab['CLASS']]= new $tab['CLASS']($this->config, $this->dn, false);
47 }
48 $this->by_object[$tab['CLASS']]->parent= &$this;
50 /* Initialize current */
51 if ($this->current == ""){
52 $this->current= $tab['CLASS'];
53 }
54 }
56 }
58 function execute()
59 {
60 /* Rotate current to last */
61 $this->last= $this->current;
63 /* Look for pressed tab button */
64 foreach ($this->by_object as $class => $obj){
65 if (isset($_POST[$class]) || (isset($_POST['arg']) && $_POST['arg'] == "$class")){
66 $this->current= $class;
67 break;
68 }
69 }
71 /* Save last tab object */
72 if ($this->last == $this->current){
73 $this->save_object(TRUE);
74 } else {
75 $this->save_object(FALSE);
76 }
78 /* Build tab line */
79 $display= $this->gen_tabs();
81 /* Show object */
82 $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";
83 $display.= "<tr><td>\n";
85 $obj= $this->by_object[$this->current];
86 $display.= $obj->execute();
87 $this->by_object[$this->current]= $obj;
89 /* Footer for tabbed dialog */
90 $display.= "</td></tr></table>";
91 return ($display);
92 }
94 function save_object($save_current= FALSE)
95 {
96 /* Save last tab */
97 if ($this->last != ""){
98 @DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__,
99 $this->last, "Saving");
101 $obj= $this->by_object[$this->last];
102 $obj->save_object ();
103 $this->by_object[$this->last]= $obj;
104 }
106 /* Skip if curent and last are the same object */
107 if ($this->last == $this->current){
108 return;
109 }
111 $obj= $this->by_object[$this->current];
112 $this->disabled= $obj->parent->disabled;
114 if ($save_current){
115 @DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__,
116 $this->current, "Saving (current)");
118 $obj->save_object ();
119 $this->by_object[$this->current]= $obj;
120 }
122 }
124 function gen_tabs()
125 {
126 $display= "<input type=\"hidden\" name=\"arg\" value=\"\">";
127 $display.= "<table summary=\"\" cellpadding=0 cellspacing=0 border=0 style=\"width:100%;\"><tr>";
128 $index= 0;
129 $style= array("tab_left", "tab_active", "tab_near_active", "tab_right");
130 foreach ($this->by_name as $class => $name){
132 /* Activate right tabs with style "tab_right"
133 Activate near current with style "tab_near_active" */
134 if ($index == 2 || $index == 1){
135 $index++;
136 }
138 /* Activate current tab with style "tab_active " */
139 if ($class == $this->current){
140 $index++;
141 }
143 /* Paint tab */
144 $display.= "<td style=\"vertical-align:bottom; width:100px;\">";
146 /* Shorten string if its too long for the tab headers*/
147 $title= _($name);
148 if (mb_strlen($title, 'UTF-8') > 14){
149 $title= mb_substr($title,0, 12, 'UTF-8')."...";
150 }
152 if ($_SESSION['js']==FALSE){
153 $display.= "<div class=\"$style[$index]\"><input type=\"submit\" name=\"$class\"".
154 " class=\"$style[$index]\" value=\"$title\"";
155 } else {
156 $display.= "<div class=\"$style[$index]\"><a class=\"$style[$index]\" onclick=\"return true;\" href=\"javascript:document.mainform.arg.value='$class';document.mainform.submit();\">$title</a";
157 }
158 $display.= "></div></td>";
159 }
160 $display.= "<td style=\"vertical-align:bottom;\">\n";
161 $display.= "<div class=\"tab_border\"> </div></td></tr></table>";
163 return($display);
164 }
167 function set_acl($acl)
168 {
169 /* Set local acl */
170 $this->acl= $acl;
172 /* Setup for all plugins */
173 foreach ($this->by_object as $key => $obj){
174 $sacl= get_module_permission($acl, "$key", $this->dn);
175 $obj->acl= $sacl;
176 $this->by_object[$key]= $obj;
177 }
178 }
180 function delete()
181 {
182 /* Check if all plugins will ACK for deletion */
183 foreach (array_reverse($this->by_object) as $key => $obj){
184 $reason= $obj->allow_remove();
185 if ($reason != ""){
186 print_red(sprintf(_("Delete process has been canceled by plugin '%s': %s"), $key, $reason));
187 return;
188 }
189 }
191 /* Delete for all plugins */
192 foreach (array_reverse($this->by_object) as $key => $obj){
193 $obj->remove_from_parent();
194 }
195 }
197 function password_change_needed()
198 {
199 /* Ask all plugins for needed password changes */
200 foreach ($this->by_object as $key => $obj){
201 if ($obj->password_change_needed()){
202 return TRUE;
203 }
204 }
206 return FALSE;
207 }
209 function check($ignore_account= FALSE)
210 {
211 $this->save_object(TRUE);
212 $messages= array();
214 /* Check all plugins */
215 foreach ($this->by_object as $key => $obj){
216 if ($obj->is_account || $ignore_account || $obj->ignore_account){
217 @DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__,
218 $key, "Checking");
220 $messages= $obj->check();
221 if (count($messages)){
222 $this->current= $key;
223 break;
224 }
225 }
226 }
228 return ($messages);
229 }
231 function save($ignore_account= FALSE)
232 {
233 /* Save all plugins */
234 foreach ($this->by_object as $key => $obj){
235 @DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__,
236 $key, "Saving");
238 $obj->dn= $this->dn;
240 if ($obj->is_account || $ignore_account || $obj->ignore_account){
241 if ($obj->save() == 1){
242 return (1);
243 }
244 } else {
245 $obj->remove_from_parent();
246 }
247 }
248 return (0);
249 }
251 function adapt_from_template($dn)
252 {
253 foreach ($this->by_object as $key => $obj){
254 @DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__,
255 $key, "Adapting");
256 $obj->parent= &$this;
257 $obj->adapt_from_template($dn);
258 $this->by_object[$key]= $obj;
259 }
260 }
263 /* Save attributes posted by copy & paste dialog
264 */
265 function saveCopyDialog()
266 {
267 foreach ($this->by_object as $key => $obj){
268 if($obj->is_account){
269 $this->by_object[$key]->saveCopyDialog();
270 }
271 }
272 }
275 /* return copy & paste dialog
276 */
277 function getCopyDialog()
278 {
279 $ret = "";
280 $this->SubDialog = false;
281 foreach ($this->by_object as $key => $obj){
282 if($obj->is_account){
283 $tmp = $this->by_object[$key]->getCopyDialog();
284 if($tmp['status'] == "SubDialog"){
285 $this->SubDialog = true;
286 return($tmp['string']);
287 }else{
288 $ret .= $tmp['string'];
289 }
290 }
291 }
292 return($ret);
293 }
295 }
297 ?>