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 }
64 function execute()
65 {
66 /* Rotate current to last */
67 $this->last= $this->current;
69 /* Look for pressed tab button */
70 foreach ($this->by_object as $class => $obj){
71 if (isset($_POST[$class]) || (isset($_POST['arg']) && $_POST['arg'] == "$class")){
72 $this->current= $class;
73 break;
74 }
75 }
77 /* Save last tab object */
78 if ($this->last == $this->current){
79 $this->save_object(TRUE);
80 } else {
81 $this->save_object(FALSE);
82 }
84 /* Build tab line */
85 $display= $this->gen_tabs();
87 /* Show object */
88 $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";
89 $display.= "<tr><td>\n";
91 $obj= $this->by_object[$this->current];
92 $display.= $obj->execute();
93 $this->by_object[$this->current]= $obj;
95 /* Footer for tabbed dialog */
96 $display.= "</td></tr></table>";
97 return ($display);
98 }
100 function save_object($save_current= FALSE)
101 {
102 /* Save last tab */
103 if ($this->last != ""){
104 @DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__,
105 $this->last, "Saving");
107 $obj= $this->by_object[$this->last];
108 $obj->save_object ();
109 $this->by_object[$this->last]= $obj;
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 $this->by_object[$this->current]= $obj;
126 }
127 }
129 function gen_tabs()
130 {
131 $display= "<input type=\"hidden\" name=\"arg\" value=\"\">";
132 $display.= "<table summary=\"\" cellpadding=0 cellspacing=0 border=0 style=\"width:100%;\"><tr>";
133 $index= 0;
134 $style= array("tab_left", "tab_active", "tab_near_active", "tab_right");
135 foreach ($this->by_name as $class => $name){
137 /* Activate right tabs with style "tab_right"
138 Activate near current with style "tab_near_active" */
139 if ($index == 2 || $index == 1){
140 $index++;
141 }
143 /* Activate current tab with style "tab_active " */
144 if ($class == $this->current){
145 $index++;
146 }
148 /* Paint tab */
149 $display.= "<td style=\"vertical-align:bottom;width:1px;\">";
151 /* Shorten string if its too long for the tab headers*/
152 $title= _($name);
153 if (mb_strlen($title, 'UTF-8') > 28){
154 $title= mb_substr($title,0, 25, 'UTF-8')."...";
155 }
157 /* nobr causes w3c warnings so we use to keep the tab name in one line */
158 $title= preg_replace("/ /"," ",$title);
160 if ($_SESSION['js']==FALSE){
161 $display.= "<div class=\"$style[$index]\"><input type=\"submit\" name=\"$class\"".
162 " class=\"$style[$index]\" value=\"$title\"";
163 } else {
164 $display.= "<div class=\"$style[$index]\"><a class=\"$style[$index]\" onclick=\"return true;\" href=\"javascript:document.mainform.arg.value='$class';document.mainform.submit();\">$title</a";
165 }
166 $display.= "></div></td>";
167 }
168 $display.= "<td style=\"vertical-align:bottom;\">\n";
169 $display.= "<div class=\"tab_border\"> </div></td></tr></table>";
171 return($display);
172 }
175 function set_acl($acl)
176 {
177 /* Look for attribute in ACL */
178 trigger_error("Don't use tabs::set_acl() its obsolete.");
179 }
181 function delete()
182 {
183 /* Check if all plugins will ACK for deletion */
184 foreach (array_reverse($this->by_object) as $key => $obj){
185 $reason= $obj->allow_remove();
186 if ($reason != ""){
187 print_red(sprintf(_("Delete process has been canceled by plugin '%s': %s"), $key, $reason));
188 return;
189 }
190 }
192 /* Delete for all plugins */
193 foreach (array_reverse($this->by_object) as $key => $obj){
194 $obj->remove_from_parent();
195 }
196 }
198 function password_change_needed()
199 {
200 /* Ask all plugins for needed password changes */
201 foreach ($this->by_object as $key => $obj){
202 if ($obj->password_change_needed()){
203 return TRUE;
204 }
205 }
207 return FALSE;
208 }
210 function check($ignore_account= FALSE)
211 {
212 $this->save_object(TRUE);
213 $messages= array();
215 /* Check all plugins */
216 foreach ($this->by_object as $key => $obj){
217 if ($obj->is_account || $ignore_account || $obj->ignore_account){
218 @DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__,
219 $key, "Checking");
221 $messages= $obj->check();
222 if (count($messages)){
223 $this->current= $key;
224 break;
225 }
226 }
227 }
229 return ($messages);
230 }
232 function save($ignore_account= FALSE)
233 {
234 /* Save all plugins */
235 foreach ($this->by_object as $key => $obj){
236 @DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__,
237 $key, "Saving");
239 $obj->dn= $this->dn;
241 if ($obj->is_account || $ignore_account || $obj->ignore_account){
242 if ($obj->save() == 1){
243 return (1);
244 }
245 } else {
246 $obj->remove_from_parent();
247 }
248 }
249 return (0);
250 }
252 function adapt_from_template($dn)
253 {
254 foreach ($this->by_object as $key => $obj){
255 @DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__,
256 $key, "Adapting");
257 $obj->parent= &$this;
258 $obj->adapt_from_template($dn);
259 $this->by_object[$key]= $obj;
260 }
261 }
264 /* Save attributes posted by copy & paste dialog
265 */
266 function saveCopyDialog()
267 {
268 foreach ($this->by_object as $key => $obj){
269 if($obj->is_account){
270 $this->by_object[$key]->saveCopyDialog();
271 }
272 }
273 }
276 /* return copy & paste dialog
277 */
278 function getCopyDialog()
279 {
280 $ret = "";
281 $this->SubDialog = false;
282 foreach ($this->by_object as $key => $obj){
283 if($obj->is_account){
284 $tmp = $this->by_object[$key]->getCopyDialog();
285 if($tmp['status'] == "SubDialog"){
286 $this->SubDialog = true;
287 return($tmp['string']);
288 }else{
289 if(!empty($tmp['string'])){
290 $ret .= $tmp['string'];
291 $ret .= "<p class='seperator'> </p>";
292 }
293 }
294 }
295 }
296 return($ret);
297 }
300 function addSpecialTabs()
301 {
302 $this->by_name['acl']= _("ACL");
303 $this->by_object['acl']= new acl($this->config, $this, $this->dn);
304 $this->by_object['acl']->parent= &$this;
305 $this->by_name['reference']= _("References");
306 $this->by_object['reference']= new reference($this->config, $this->dn);
307 $this->by_object['reference']->parent= &$this;
308 }
311 function set_acl_base($base= "")
312 {
313 /* Update reference, transfer variables */
314 $first= ($base == "");
315 foreach ($this->by_object as $name => $obj){
316 if ($first){
317 $first= FALSE;
318 $base= $obj->acl_base;
319 } else {
320 $obj->set_acl_base($base);
321 $this->by_object[$name]= $obj;
322 }
323 }
324 }
326 }
327 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
328 ?>