Code

Updated Snapshot & Copy&Paste for FAI
[gosa.git] / include / class_tabs.inc
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         $baseobject->enable_CSN_check();
50         $this->by_object[$tab['CLASS']]= $baseobject;
51       } else {
52         $this->by_object[$tab['CLASS']]= new $tab['CLASS']($this->config, $this->dn, $baseobject);
53       }
55       $this->by_object[$tab['CLASS']]->parent= &$this;
56       $this->by_object[$tab['CLASS']]->set_acl_category($acl_category);
58       /* Initialize current */
59       if ($this->current == ""){
60         $this->current= $tab['CLASS'];
61       }
62     }
63   }
65   
66   function multiple_support_available()
67   {
68     foreach($this->by_object as $name => $obj){
69       if($obj->multiple_support){
70         return(TRUE);
71       }
72     }
73     return(FALSE);
74   }  
76   function enable_multiple_support()
77   {
78     if(!$this->multiple_support_available()){
79       return(FALSE);
80     }else{
81       foreach($this->by_object as $name => $obj){
82         if($obj->multiple_support){
83           $this->by_object[$name]->multiple_support_active = TRUE;
84         }else{
85           unset($this->by_object[$name]);
86           unset($this->by_name[$name]);
87         }
88       }
89     }
90     return(TRUE);
91   }
94   function execute()
95   {
96     /* Rotate current to last */
97     $this->last= $this->current;
99     /* Look for pressed tab button */
100     foreach ($this->by_object as $class => &$obj){
101       if (isset($_POST[$class]) || (isset($_POST['arg']) && $_POST['arg'] == "$class")){
102         $this->current= $class;
103         break;
104       }
105     }
107     /* Save last tab object */
108     if ($this->last == $this->current){
109       $this->save_object(TRUE);
110     } else {
111       $this->save_object(FALSE);
112     }
114     /* Build tab line */
115     $display= $this->gen_tabs();
117     /* Show object */
118     $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";
119     $display.= "<tr><td>\n";
121     $display.= $this->by_object[$this->current]->execute();
123     /* Footer for tabbed dialog */
124     $display.= "</td></tr></table>";
126     return ($display);
127   }
129   function save_object($save_current= FALSE)
130   {
131     /* Save last tab */
132     if ($this->last != ""){
133       @DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__,
134           $this->last, "Saving");
136       $this->by_object[$this->last]->save_object ();
137     }
139     /* Skip if curent and last are the same object */
140     if ($this->last == $this->current){
141       return;
142     }
144     $obj= @$this->by_object[$this->current];
145     $this->disabled= $obj->parent->disabled;
147     if ($save_current){
148       @DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__,
149           $this->current, "Saving (current)");
151       $obj->save_object ();
152     }
153   }
155   function gen_tabs()
156   {
157     $display= "<input type=\"hidden\" name=\"arg\" value=\"\">";
158     $display.= "<table summary=\"\" cellpadding=0 cellspacing=0 border=0 style=\"width:100%;\"><tr>";
159     $index= 0;
160     $style= array("tab_left", "tab_active", "tab_near_active", "tab_right");
161     foreach ($this->by_name as $class => $name){
163       /* Activate right tabs with style "tab_right"
164          Activate near current with style "tab_near_active" */
165       if ($index == 2 || $index == 1){
166         $index++;
167       }
169       /* Activate current tab with style "tab_active " */
170       if ($class == $this->current){
171         $index++;
172       }
174       /* Paint tab */
175       $display.= "<td style=\"vertical-align:bottom;width:1px;white-space:nowrap;\">";
177       /* Shorten string if its too long for the tab headers*/
178       $title= _($name);
179       if (mb_strlen($title, 'UTF-8') > 28){
180         $title= mb_substr($title,0, 25, 'UTF-8')."...";
181       }
183       /* nobr causes w3c warnings so we use &nbsp; to keep the tab name in one line */
184       $title= preg_replace("/ /","&nbsp;",$title);
186       /* Take care about notifications */
187       $obj = $this->by_object[$class];
188       if ( $this->by_object[$class]->pl_notify && ($obj->is_account || $obj->ignore_account)){
189         $notify= "id=\"notify\"";
190       } else {
191         $notify= "";
192       }
194       if ($_SESSION['js']==FALSE){      
195         $display.= "<div ".$notify." class=\"$style[$index]\"><input type=\"submit\" name=\"$class\"".
196           " class=\"$style[$index]\" value=\"$title\"";
197       } else {                   
198         $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";
199       }
200       $display.= "></div></td>";
201     }
202     $display.= "<td style=\"vertical-align:bottom;\">\n";
203     $display.= "<div class=\"tab_border\">&nbsp;</div></td></tr></table>";
205     return($display);
206   }
209   function set_acl($acl)
210   {
211         /* Look for attribute in ACL */
212           trigger_error("Don't use tabs::set_acl() its obsolete.");
213   }
215   function delete()
216   {
217     /* Check if all plugins will ACK for deletion */
218     foreach (array_reverse($this->by_object) as $key => $obj){
219       $reason= $obj->allow_remove();
220       if ($reason != ""){
221         print_red(sprintf(_("Delete process has been canceled by plugin '%s': %s"), $key, $reason));
222         return;
223       }
224     }
226     /* Delete for all plugins */
227     foreach (array_reverse($this->by_object) as $obj){
228       $obj->remove_from_parent();
229     }
230   }
232   function password_change_needed()
233   {
234     /* Ask all plugins for needed password changes */
235     foreach ($this->by_object as &$obj){
236       if ($obj->password_change_needed()){
237         return TRUE;
238       }
239     }
241     return FALSE;
242   }
244   function check($ignore_account= FALSE)
245   {
246     $this->save_object(TRUE);
247     $messages= array();
249     $current_set = FALSE;
251     /* Check all plugins */
252     foreach ($this->by_object as $key => &$obj){
253       if ($obj->is_account || $ignore_account || $obj->ignore_account){
254         @DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__,$key, "Checking");
256         $msg = $obj->check();
258         if (count($msg)){
259           $obj->pl_notify= TRUE;
260           if(!$current_set){
261             $current_set = TRUE;
262             $this->current= $key;
263             $messages = $msg;
264           }
265         }else{
266           $obj->pl_notify= FALSE;
267         }
268       }else{
269         $obj->pl_notify= FALSE;
270       }
271     }
272     return ($messages);
273   }
275   function save($ignore_account= FALSE)
276   {
277     /* Save all plugins */
278     foreach ($this->by_object as $key => &$obj){
279       @DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__,
280           $key, "Saving");
282       $obj->dn= $this->dn;
284       if ($obj->is_account || $ignore_account || $obj->ignore_account){
285         if ($obj->save() == 1){
286           return (1);
287         }
288       } else {
289         $obj->remove_from_parent();
290       }
291     }
292     return (0);
293   }
295   function adapt_from_template($dn)
296   {
297     foreach ($this->by_object as $key => &$obj){
298       @DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__,
299           $key, "Adapting");
300       $obj->parent= &$this;
301       $obj->adapt_from_template($dn);
302     }
303   }
305         
306   /* Save attributes posted by copy & paste dialog
307    */
308   function saveCopyDialog()
309   {
310           foreach ($this->by_object as &$obj){
311                   if($obj->is_account || $obj->ignore_account){
312                           $obj->saveCopyDialog();
313                   }
314           }
315   }
318   /* return copy & paste dialog
319    */
320   function getCopyDialog()
321   {
322     $ret = "";
323     $this->SubDialog = false;
324     foreach ($this->by_object as &$obj){
325       if($obj->is_account || $obj->ignore_account){
326         $tmp = $obj->getCopyDialog();
327         if($tmp['status'] == "SubDialog"){
328           $this->SubDialog = true;
329           return($tmp['string']);
330         }else{
331           if(!empty($tmp['string'])){
332             $ret .= $tmp['string'];
333             $ret .= "<p class='seperator'>&nbsp;</p>";
334           }
335         }
336       }
337     }
338     return($ret);
339   }
342   function addSpecialTabs()
343   {
344     $this->by_name['acl']= _("ACL");
345     $this->by_object['acl']= new acl($this->config, $this, $this->dn);
346     $this->by_object['acl']->parent= &$this;
347     $this->by_name['reference']= _("References");
348     $this->by_object['reference']= new reference($this->config, $this->dn);
349     $this->by_object['reference']->parent= &$this;
350   }
353   function set_acl_base($base= "")
354   {
355     /* Update reference, transfer variables */
356     $first= ($base == "");
357     foreach ($this->by_object as &$obj){
358       if ($first){
359         $first= FALSE;
360         $base= $obj->acl_base;
361       } else {
362         $obj->set_acl_base($base);
363       }
364     }
365   }
367 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
368 ?>