Code

Updated client dns handling
[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;
41         
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:#F8F8F8; border-style:solid; border-color:#AAA; 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   if (is_php4()){
94     $this->by_object[$this->current]= $obj;
95   }
97         /* Footer for tabbed dialog */
98         $display.= "</td></tr></table>";
99         return ($display);
100   }
102   function save_object($save_current= FALSE)
103   {
104         /* Save last tab */
105         if ($this->last != ""){
106                 @DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__,
107                         $this->last, "Saving");
109                 $obj= $this->by_object[$this->last];
110                 $obj->save_object ();
111     if (is_php4()){
112       $this->by_object[$this->last]= $obj;
113     }
114         }
116         /* Skip if curent and last are the same object */
117         if ($this->last == $this->current){
118                 return;
119         }
121         $obj= $this->by_object[$this->current];
122         $this->disabled= $obj->parent->disabled;
124         if ($save_current){
125                 @DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__,
126                         $this->current, "Saving (current)");
128                 $obj->save_object ();
129     if (is_php4()){
130       $this->by_object[$this->current]= $obj;
131     }
132         }
133   }
135   function gen_tabs()
136   {
137         $display= "<input type=\"hidden\" name=\"arg\" value=\"\">";
138         $display.= "<table summary=\"\" cellpadding=0 cellspacing=0 border=0 style=\"width:100%;\"><tr>";
139         $index= 0;
140         $style= array("tab_left", "tab_active", "tab_near_active", "tab_right");
141         foreach ($this->by_name as $class => $name){
143                 /* Activate right tabs with style "tab_right"
144                    Activate near current with style "tab_near_active" */
145                 if ($index == 2 || $index == 1){
146                         $index++;
147                 }
149                 /* Activate current tab with style "tab_active " */
150                 if ($class == $this->current){
151                         $index++;
152                 }
154                 /* Paint tab */
155                 $display.= "<td style=\"vertical-align:bottom;width:1px;white-space:nowrap;\">";
157                 /* Shorten string if its too long for the tab headers*/
158                 $title= _($name);
159                 if (mb_strlen($title, 'UTF-8') > 28){
160                         $title= mb_substr($title,0, 25, 'UTF-8')."...";
161                 }
162                         
163                 /* nobr causes w3c warnings so we use &nbsp; to keep the tab name in one line */
164                 $title= preg_replace("/ /","&nbsp;",$title);
166     /* Take care about notifications */
167     if ($this->by_object[$class]->pl_notify){
168       $notify= "id=\"notify\"";
169     } else {
170       $notify= "";
171     }
173                 if ($_SESSION['js']==FALSE){    
174                         $display.= "<div ".$notify." class=\"$style[$index]\"><input type=\"submit\" name=\"$class\"".
175                                    " class=\"$style[$index]\" value=\"$title\"";
176                 } else {                         
177                         $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";
178                 }
179                 $display.= "></div></td>";
180         }
181         $display.= "<td style=\"vertical-align:bottom;\">\n";
182         $display.= "<div class=\"tab_border\">&nbsp;</div></td></tr></table>";
184         return($display);
185   }
188   function set_acl($acl)
189   {
190         /* Look for attribute in ACL */
191           trigger_error("Don't use tabs::set_acl() its obsolete.");
192   }
194   function delete()
195   {
196         /* Check if all plugins will ACK for deletion */
197         foreach (array_reverse($this->by_object) as $key => $obj){
198                 $reason= $obj->allow_remove();
199                 if ($reason != ""){
200                         print_red(sprintf(_("Delete process has been canceled by plugin '%s': %s"), $key, $reason));
201                         return;
202                 }
203         }
205         /* Delete for all plugins */
206         foreach (array_reverse($this->by_object) as $key => $obj){
207                 $obj->remove_from_parent();
208         }
209   }
211   function password_change_needed()
212   {
213         /* Ask all plugins for needed password changes */
214         foreach ($this->by_object as $key => $obj){
215                 if ($obj->password_change_needed()){
216                         return TRUE;
217                 }
218         }
220         return FALSE;
221   }
223   function check($ignore_account= FALSE)
224   {
225     $this->save_object(TRUE);
226     $messages= array();
228     $current_set = FALSE;
230     /* Check all plugins */
231     foreach ($this->by_object as $key => $obj){
232       if ($obj->is_account || $ignore_account || $obj->ignore_account){
233         @DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__,$key, "Checking");
235         $msg = $obj->check();
237         if (is_php4()){
238           $this->by_object[$key]= $obj;
239         }
240         if (count($msg)){
241           $this->by_object[$key]->pl_notify= TRUE;
242           if(!$current_set){
243             $current_set = TRUE;
244             $this->current= $key;
245             $messages = $msg;
246           }
247         }else{
248           $this->by_object[$key]->pl_notify= FALSE;
249         }
250       }else{
251         $this->by_object[$key]->pl_notify= FALSE;
252       }
253     }
254     return ($messages);
255   }
257   function save($ignore_account= FALSE)
258   {
259         /* Save all plugins */
260         foreach ($this->by_object as $key => $obj){
261                 @DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__,
262                         $key, "Saving");
264                 $obj->dn= $this->dn;
265                 
266                 if ($obj->is_account || $ignore_account || $obj->ignore_account){
267                         if ($obj->save() == 1){
268                                 return (1);
269                         }
270                 } else {
271                         $obj->remove_from_parent();
272                 }
273         }
274         return (0);
275   }
277   function adapt_from_template($dn)
278   {
279           foreach ($this->by_object as $key => $obj){
280                   @DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__,
281                                   $key, "Adapting");
282                   $obj->parent= &$this;
283                   $obj->adapt_from_template($dn);
284       if (is_php4()){
285         $this->by_object[$key]= $obj;
286       }
287           }
288   }
290         
291   /* Save attributes posted by copy & paste dialog
292    */
293   function saveCopyDialog()
294   {
295           foreach ($this->by_object as $key => $obj){
296                   if($obj->is_account){
297                           $this->by_object[$key]->saveCopyDialog();
298                   }
299           }
300   }
303   /* return copy & paste dialog
304    */
305   function getCopyDialog()
306   {
307     $ret = "";
308     $this->SubDialog = false;
309     foreach ($this->by_object as $key => $obj){
310       if($obj->is_account){
311         $tmp = $this->by_object[$key]->getCopyDialog();
312         if($tmp['status'] == "SubDialog"){
313           $this->SubDialog = true;
314           return($tmp['string']);
315         }else{
316           if(!empty($tmp['string'])){
317             $ret .= $tmp['string'];
318             $ret .= "<p class='seperator'>&nbsp;</p>";
319           }
320         }
321       }
322     }
323     return($ret);
324   }
327   function addSpecialTabs()
328   {
329         $this->by_name['acl']= _("ACL");
330         $this->by_object['acl']= new acl($this->config, $this, $this->dn);
331         $this->by_object['acl']->parent= &$this;
332         $this->by_name['reference']= _("References");
333         $this->by_object['reference']= new reference($this->config, $this->dn);
334         $this->by_object['reference']->parent= &$this;
335   }
338   function set_acl_base($base= "")
339   {
340         /* Update reference, transfer variables */
341         $first= ($base == "");
342         foreach ($this->by_object as $name => $obj){
343                 if ($first){
344                         $first= FALSE;
345                         $base= $obj->acl_base;
346                 } else {
347                         $obj->set_acl_base($base);
348                         $this->by_object[$name]= $obj;
349                 }
350         }
351   }
354 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
355 ?>