a51d922c51e4d8ab6ae2925a88208c63df96b456
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
24 {
25 var $i_steps = 9; // Number of setup steps
26 var $i_current= 1; // Current step
27 var $i_last = 1; // Last setup step;
28 var $o_steps = array();
29 var $captured_values = array();
31 function setup()
32 {
33 $i = 1;
34 $this->o_steps[$i++] = new Step_Welcome();
35 $this->o_steps[$i++] = new Step_Language();
36 $this->o_steps[$i++] = new Step_Checks();
37 $this->o_steps[$i++] = new Step_License();
38 $this->o_steps[$i++] = new Step_Ldap();
39 $this->o_steps[$i++] = new Step_Schema();
40 $this->o_steps[$i++] = new Step_Config1();
41 $this->o_steps[$i++] = new Step_Config2();
42 $this->o_steps[$i++] = new Step_Config3();
43 $this->o_steps[$i++] = new Step_Finish();
45 /* Ensure that setup is not reachable if gosa.conf (CONFIG_FILE) */
46 if(file_exists(CONFIG_DIR."/".CONFIG_FILE)){
47 session_destroy();
48 header("Location: index.php") ;
49 exit();
50 }
52 foreach($this->o_steps as $key => $step){
53 $this->o_steps[$key]->parent = $this;
54 }
55 }
58 function execute()
59 {
60 $this->o_steps[$this->i_last]->set_active(FALSE);
61 $this->o_steps[$this->i_current]->set_active();
62 $content = $this->o_steps[$this->i_current]->execute();
63 return($content);
64 }
67 /* Save posted attributes */
68 function save_object()
69 {
70 /* Call save_object for current setup step */
71 $this->o_steps[$this->i_current] -> save_object();
73 /* Get attributes from setup step */
74 $tmp = $this->o_steps[$this->i_current]->get_attributes();
75 foreach($tmp as $name => $value){
76 $this->captured_values[$name] = $value;
77 }
79 /* Set parent */
80 foreach($this->o_steps as $key => $value){
81 $this->o_steps[$key]->parent = $this;
82 }
84 /* Check if image button requests next page */
85 foreach($_POST as $name => $value){
86 if(preg_match("/^next_(x|y)/",$name)){
87 $_POST['next'] = TRUE;
88 }
89 if(preg_match("/^last_(x|y)/",$name)){
90 $_POST['last'] = TRUE;
91 }
92 }
94 /* Check if step was selected */
95 if(isset($_GET['step']) || isset($_POST['next']) || isset($_POST['last'])){
97 /* check if current setup step is completed now
98 and activate the next step if possible */
99 for($i = 1 ; $i <= $this->i_steps ; $i ++ ){
100 if($this->o_steps[$i]->is_completed()){
101 if(isset($this->o_steps[($i+1)])){
102 $this->o_steps[($i+1)]->set_enabled();
103 }
104 }else{
105 $this->disable_steps_from($i+1);
106 }
107 }
108 }
110 /* Disable all following steps, if one step isn't compelted right now .*/
111 for($i = 1 ; $i <= $this->i_steps ; $i ++ ){
112 if($this->o_steps[$i]->is_completed()){
113 }else{
114 $this->disable_steps_from($i+1);
115 }
116 }
118 $step = -1;
120 if(isset($_POST['setup_goto_step'])){
121 $step= $_POST['setup_goto_step'];
122 }
124 if(isset($_GET['step'])){
125 $step = $_GET['step'];
126 }elseif(isset($_POST['next'])){
127 $step = $this->i_current + 1;
128 }elseif(isset($_POST['last'])){
129 $step = $this->i_current - 1;
130 }
132 $once = true;
133 foreach($_POST as $name => $value){
134 if(preg_match("/^step_[0-9]*$/",$name) && $once ){
135 $step = preg_replace("/^step_/","",$name);
136 }
137 }
139 if($this->selectable_step($step)){
140 $this->i_last = $this->i_current;
141 $this->i_current = $step;
142 }
143 }
146 function disable_steps_from($start)
147 {
148 $found = false;
149 foreach($this->o_steps as $key => $step){
150 if($key == $start){
151 $found = true;
152 }
154 if($found){
155 $this->o_steps[$key]->set_enabled(false);
156 $this->o_steps[$key]->set_completed(false);
157 }
158 }
159 }
162 /* Create navigation menu */
163 function get_navigation_html()
164 {
165 $str = "";
166 foreach($this->o_steps as $key => $step){
168 $step -> update_strings();
170 $s_title = $step -> get_title();
171 $s_info = $step -> get_small_info();
172 $b_active = $step -> is_active();
173 $b_enabled = $step -> is_enabled();
174 $b_completed= $step -> is_completed();
176 if($b_completed){
177 $s = "<img src='images/true.png' alt='"._("Completed")."' class='center'> ";
178 }else{
179 $s = "<img src='images/empty.png' alt=' ' class='center'> ";
180 }
182 if($_SESSION['js']){
184 $str .="<div >";
186 if($b_enabled){
187 if($b_active){
188 $str .= "<div class='navigation_element_active'>";
189 $str .= "<div class='navigation_title_active'>".$s.$s_title."</div>";
190 $str .= "<div class='navigation_info'>".$s_info."</div>";
191 $str .= "</div>";
192 }else{
193 $str .= "<div class='navigation_element'>";
194 $str .= "<div onClick='document.mainform.setup_goto_step.value=\"$key\";document.mainform.submit();'
195 class='navigation_title_inactive'>".$s.$s_title."</div>";
196 $str .= "</div>";
197 }
198 }else{
199 $str .= "<div class='navigation_element'>";
200 $str .= "<div class='navigation_title_disabled'>".$s.$s_title."</div>";
201 $str .= "</div>";
202 }
203 $str .= "</div>" ;
204 }else{
205 $str .="<div >";
206 if($b_enabled){
207 if($b_active){
208 $str .= "<div class='navigation_element_active'>";
209 $str .= "<input style='text-align: left; color: #00008F; font-weight: bold; width:100%;'
210 type='button' value='".$s_title."' name='step_".$key."'>";
211 $str .= "</div>";
212 }else{
213 $str .= "<div class='navigation_element'>";
214 $str .= "<input style='text-align: left; color: #00008F; font-weight: bold; width:100%;'
215 type='submit' value='".$s_title."' name='step_".$key."'>";
216 $str .= "</div>";
217 }
218 }else{
219 $str .= "<div class='navigation_element'>";
220 $str .= "<div class='navigation_title_disabled'>".$s_title."</div>";
221 $str .= "</div>";
222 }
223 $str .= "</div>" ;
224 }
225 }
226 return($str);
227 }
231 function get_bottom_html()
232 {
233 /* Skip adding forward/backward button,
234 * if the currently opened step is a sub dialog
235 */
236 if($this->o_steps[$this->i_current]->dialog){
237 $str ="";
238 }else{
239 $str ="";
240 $str.=" <div style='text-align:right;float:top;'>";
241 if(isset($this->o_steps[$this->i_current -1]) && $this->o_steps[$this->i_current -1]->is_enabled()){
242 $str .= "<input type='submit' name='last' value='"._("Back")."'>";
243 }else{
244 $str .= "<input type='button' name='last' value='"._("Back")."' disabled>";
245 }
246 $str.= " ";
247 if(isset($this->o_steps[$this->i_current + 1])){
248 $str .= "<input type='submit' name='next' value='"._("Continue")."'>";
249 }else{
250 $str .= "<input type='button' value='"._("Continue")."' disabled>";
251 }
252 $str .="</div>";
253 }
254 return($str);
255 }
258 /* Create header entry */
259 function get_header_html()
260 {
261 $str= $this->o_steps[$this->i_current]->print_header();
262 return ($str);
263 }
266 /* Check if the given step id is valid and selectable */
267 function selectable_step($id)
268 {
269 if(isset($this->o_steps[$id]) && $this->o_steps[$id]->is_enabled()){
270 return(true);
271 }
272 return(false);
273 }
274 }
279 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
280 ?>