Code

Intitial setup rework.
[gosa.git] / setup / class_setup.inc
1 <?php
2 /*
3    This code is part of GOsa (https://gosa.gonicus.de)
4    Copyright (C) 2007 Fabian Hickert
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 require_once("class_setupStep.inc");
23 class setup extends plugin
24 {
26   var $i_steps  = 5;  // Number of setup steps 
27   var $i_current= 1;  // Current step
28   var $i_last   = 1;  // Last setup step;
29   var $o_steps  = array(); 
31   var $captured_values = array();
33   function setup()
34   {
35     for($i = 1 ; $i <= $this->i_steps; $i ++ ){
36       $class= "setup_step_".$i;
37       $this->o_steps[$i] = new $class();
38     }
39   }
41   function execute()
42   {
43     $smarty = get_smarty();
44     $this->o_steps[$this->i_last]->set_active(FALSE);
45     $this->o_steps[$this->i_current]->set_active();
46     $content = $this->o_steps[$this->i_current]->execute();
47     return($content);
48   }
51   /* Save posted attributes  */
52   function save_object()
53   {
54     /* Call save_object for current setup step */
55     $this->o_steps[$this->i_current] -> save_object();
57     /* Get attributes from setup step */
58     $tmp = $this->o_steps[$this->i_current]->get_attributes();
59     foreach($tmp as $name => $value){
60       $this->captured_values[$name] = $value;
61     }
63     /* check if current setup step is completed now 
64         and activate the next step if possible */
65     for($i = 1 ; $i <= $this->i_steps ; $i ++ ){
66       if($this->o_steps[$i]->is_completed()){
67         if(isset($this->o_steps[($i+1)])){
68           $this->o_steps[($i+1)]->set_enabled();
69         }
70       }
71     }
73     /* Check if step was selected */
74     if(isset($_GET['step'])){
75       $step = $_GET['step'];
77       if($this->selectable_step($step)){
78         $this->i_last    = $this->i_current;
79         $this->i_current = $_GET['step'];
80       }
81     }
82   }
85   /* Create navigation menu */
86   function get_navigation_html()
87   {
88     $str = "<table>";
89   
90     foreach($this->o_steps as $key => $step){
92       $s_title    = $step -> get_title();
93       $s_info     = $step -> get_small_info();
94       $b_active   = $step -> is_active();
95       $b_enabled  = $step -> is_enabled();
97       $str .= "<tr><td>";  
98       if($b_enabled){
99         $str .= "<a href='?step=".$key."'>";
100         $str .= "<font color='darkblue' style='font-size:14pt;'>".$s_title."</font>";
101         if($b_active){
102           $str .= "<div style='padding-left:16px;'>";
103           $str .= "  <font style='font-size:10pt;'>".$s_info."</font>";
104           $str .= "</div>";
105         }
106         $str .= "</a>";
107       }else{
108         $str .= "<font color='darkgrey' style='font-size:14pt;'>".$s_title."</font>";
109       }
110       $str .= "<p class='seperator'>&nbsp;</p>";
111       $str .= "</td></tr>";
112     }
113     $str .="</table>";
114     return($str);
115   }
117   
118   /* Create header entry */
119   function get_header_html()
120   {
121     $str ="<font style='font-size:20px;' color='darkblue'>";
122     $str.=   $this->o_steps[$this->i_current]->get_long_title();
123     $str.="</font>";
124     return ($str);
125   }
128   /* Check if the given step id is valid and selectable */
129   function selectable_step($id)
130   {
131     if(isset($this->o_steps[$id]) && $this->o_steps[$id]->is_enabled()){
132       return(true);
133     }
134     return(false);
135   }
141 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
142 ?>