c7be1b78462ceddbb2109e8db8c5609e1a66559b
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 var $multiple_entries = FALSE;
38 function tabs(&$config, $data, $dn, $acl_category= "")
39 {
40 /* Save dn */
41 $this->dn= $dn;
42 $this->config= &$config;
44 $baseobject= NULL;
46 /* Check specified dn
47 */
48 if(is_string($dn)){
50 }elseif(is_array($dn)&&count($dn) == 1){
51 $this->dn = $dn[key($dn)];
52 }elseif(is_array($dn)&&count($dn) > 1){
53 $this->multiple_entries = TRUE;
54 }
57 foreach ($data as &$tab){
59 /* Check we want to handle multiple obejcts at once
60 * and if this is supported by enabled plugins
61 */
62 $tmp = get_class_vars($tab['CLASS']);
63 if($this->multiple_entries && !$tmp['multiple_support']){
64 continue;
65 }
67 $this->by_name[$tab['CLASS']]= $tab['NAME'];
69 if ($baseobject === NULL){
70 $baseobject= new $tab['CLASS']($this->config, $this->dn);
71 $this->by_object[$tab['CLASS']]= $baseobject;
72 } else {
73 $this->by_object[$tab['CLASS']]= new $tab['CLASS']($this->config, $this->dn, $baseobject);
74 }
76 $this->by_object[$tab['CLASS']]->parent= &$this;
77 $this->by_object[$tab['CLASS']]->set_acl_category($acl_category);
79 /* Initialize current */
80 if ($this->current == ""){
81 $this->current= $tab['CLASS'];
82 }
83 }
85 /* Return false if tabs */
86 if(!count($this->by_object)){
87 return(FALSE);
88 }
89 }
91 function execute()
92 {
93 /* Rotate current to last */
94 $this->last= $this->current;
96 /* Look for pressed tab button */
97 foreach ($this->by_object as $class => &$obj){
98 if (isset($_POST[$class]) || (isset($_POST['arg']) && $_POST['arg'] == "$class")){
99 $this->current= $class;
100 break;
101 }
102 }
104 /* Save last tab object */
105 if ($this->last == $this->current){
106 $this->save_object(TRUE);
107 } else {
108 $this->save_object(FALSE);
109 }
111 /* Build tab line */
112 $display= $this->gen_tabs();
114 /* Show object */
115 $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";
116 $display.= "<tr><td>\n";
118 $display.= $this->by_object[$this->current]->execute();
120 /* Footer for tabbed dialog */
121 $display.= "</td></tr></table>";
123 return ($display);
124 }
126 function save_object($save_current= FALSE)
127 {
128 /* Save last tab */
129 if ($this->last != ""){
130 @DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__,
131 $this->last, "Saving");
133 $this->by_object[$this->last]->save_object ();
134 }
136 /* Skip if curent and last are the same object */
137 if ($this->last == $this->current){
138 return;
139 }
141 $obj= @$this->by_object[$this->current];
142 $this->disabled= $obj->parent->disabled;
144 if ($save_current){
145 @DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__,
146 $this->current, "Saving (current)");
148 $obj->save_object ();
149 }
150 }
152 function gen_tabs()
153 {
154 $display= "<input type=\"hidden\" name=\"arg\" value=\"\">";
155 $display.= "<table summary=\"\" cellpadding=0 cellspacing=0 border=0 style=\"width:100%;\"><tr>";
156 $index= 0;
157 $style= array("tab_left", "tab_active", "tab_near_active", "tab_right");
158 foreach ($this->by_name as $class => $name){
160 /* Activate right tabs with style "tab_right"
161 Activate near current with style "tab_near_active" */
162 if ($index == 2 || $index == 1){
163 $index++;
164 }
166 /* Activate current tab with style "tab_active " */
167 if ($class == $this->current){
168 $index++;
169 }
171 /* Paint tab */
172 $display.= "<td style=\"vertical-align:bottom;width:1px;white-space:nowrap;\">";
174 /* Shorten string if its too long for the tab headers*/
175 $title= _($name);
176 if (mb_strlen($title, 'UTF-8') > 28){
177 $title= mb_substr($title,0, 25, 'UTF-8')."...";
178 }
180 /* nobr causes w3c warnings so we use to keep the tab name in one line */
181 $title= preg_replace("/ /"," ",$title);
183 /* Take care about notifications */
184 if ($this->by_object[$class]->pl_notify){
185 $notify= "id=\"notify\"";
186 } else {
187 $notify= "";
188 }
190 if ($_SESSION['js']==FALSE){
191 $display.= "<div ".$notify." class=\"$style[$index]\"><input type=\"submit\" name=\"$class\"".
192 " class=\"$style[$index]\" value=\"$title\"";
193 } else {
194 $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";
195 }
196 $display.= "></div></td>";
197 }
198 $display.= "<td style=\"vertical-align:bottom;\">\n";
199 $display.= "<div class=\"tab_border\"> </div></td></tr></table>";
201 return($display);
202 }
205 function set_acl($acl)
206 {
207 /* Look for attribute in ACL */
208 trigger_error("Don't use tabs::set_acl() its obsolete.");
209 }
211 function delete()
212 {
213 /* Check if all plugins will ACK for deletion */
214 foreach (array_reverse($this->by_object) as $key => $obj){
215 $reason= $obj->allow_remove();
216 if ($reason != ""){
217 print_red(sprintf(_("Delete process has been canceled by plugin '%s': %s"), $key, $reason));
218 return;
219 }
220 }
222 /* Delete for all plugins */
223 foreach (array_reverse($this->by_object) as $obj){
224 $obj->remove_from_parent();
225 }
226 }
228 function password_change_needed()
229 {
230 /* Ask all plugins for needed password changes */
231 foreach ($this->by_object as &$obj){
232 if ($obj->password_change_needed()){
233 return TRUE;
234 }
235 }
237 return FALSE;
238 }
240 function check($ignore_account= FALSE)
241 {
242 $this->save_object(TRUE);
243 $messages= array();
245 $current_set = FALSE;
247 /* Check all plugins */
248 foreach ($this->by_object as $key => &$obj){
249 if ($obj->is_account || $ignore_account || $obj->ignore_account){
250 @DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__,$key, "Checking");
252 $msg = $obj->check();
254 if (count($msg)){
255 $obj->pl_notify= TRUE;
256 if(!$current_set){
257 $current_set = TRUE;
258 $this->current= $key;
259 $messages = $msg;
260 }
261 }else{
262 $obj->pl_notify= FALSE;
263 }
264 }else{
265 $obj->pl_notify= FALSE;
266 }
267 }
268 return ($messages);
269 }
271 function save($ignore_account= FALSE)
272 {
273 /* Save all plugins */
274 foreach ($this->by_object as $key => &$obj){
275 @DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__,
276 $key, "Saving");
278 $obj->dn= $this->dn;
280 if ($obj->is_account || $ignore_account || $obj->ignore_account){
281 if ($obj->save() == 1){
282 return (1);
283 }
284 } else {
285 $obj->remove_from_parent();
286 }
287 }
288 return (0);
289 }
291 function adapt_from_template($dn)
292 {
293 foreach ($this->by_object as $key => &$obj){
294 @DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__,
295 $key, "Adapting");
296 $obj->parent= &$this;
297 $obj->adapt_from_template($dn);
298 }
299 }
302 /* Save attributes posted by copy & paste dialog
303 */
304 function saveCopyDialog()
305 {
306 foreach ($this->by_object as &$obj){
307 if($obj->is_account){
308 $obj->saveCopyDialog();
309 }
310 }
311 }
314 /* return copy & paste dialog
315 */
316 function getCopyDialog()
317 {
318 $ret = "";
319 $this->SubDialog = false;
320 foreach ($this->by_object as &$obj){
321 if($obj->is_account){
322 $tmp = $obj->getCopyDialog();
323 if($tmp['status'] == "SubDialog"){
324 $this->SubDialog = true;
325 return($tmp['string']);
326 }else{
327 if(!empty($tmp['string'])){
328 $ret .= $tmp['string'];
329 $ret .= "<p class='seperator'> </p>";
330 }
331 }
332 }
333 }
334 return($ret);
335 }
338 function addSpecialTabs()
339 {
340 if(!is_array($this->dn)){
341 $this->by_name['acl']= _("ACL");
342 $this->by_object['acl']= new acl($this->config, $this, $this->dn);
343 $this->by_object['acl']->parent= &$this;
344 $this->by_name['reference']= _("References");
345 $this->by_object['reference']= new reference($this->config, $this->dn);
346 $this->by_object['reference']->parent= &$this;
347 }
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 ?>