Code

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