84c21be3dcc2761cc5e6f8809593dad4fb4eec4f
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_Migrate();
44 $this->o_steps[$i++] = new Step_Finish();
45 $this->i_steps = $i-1;
47 /* Ensure that setup is not reachable if gosa.conf (CONFIG_FILE) */
48 if(file_exists(CONFIG_DIR."/".CONFIG_FILE)){
49 session_destroy();
50 header("Location: index.php") ;
51 exit();
52 }
54 foreach($this->o_steps as $key => $step){
55 $this->o_steps[$key]->parent = $this;
56 }
57 }
60 function execute()
61 {
62 $this->o_steps[$this->i_last]->set_active(FALSE);
63 $this->o_steps[$this->i_current]->set_active();
64 $content = $this->o_steps[$this->i_current]->execute();
65 return($content);
66 }
69 /* Save posted attributes */
70 function save_object()
71 {
72 /* Call save_object for current setup step */
73 $this->o_steps[$this->i_current] -> save_object();
75 /* Get attributes from setup step */
76 $tmp = $this->o_steps[$this->i_current]->get_attributes();
77 foreach($tmp as $name => $value){
78 $this->captured_values[$name] = $value;
79 }
81 /* Set parent */
82 foreach($this->o_steps as $key => $value){
83 $this->o_steps[$key]->parent = $this;
84 }
86 /* Check if image button requests next page */
87 foreach($_POST as $name => $value){
88 if(preg_match("/^next_(x|y)/",$name)){
89 $_POST['next'] = TRUE;
90 }
91 if(preg_match("/^last_(x|y)/",$name)){
92 $_POST['last'] = TRUE;
93 }
94 }
96 /* Check if step was selected */
97 if(isset($_GET['step']) || isset($_POST['next']) || isset($_POST['last'])){
99 /* check if current setup step is completed now
100 and activate the next step if possible */
101 for($i = 1 ; $i <= $this->i_steps ; $i ++ ){
102 if($this->o_steps[$i]->is_completed()){
103 if(isset($this->o_steps[($i+1)])){
104 $this->o_steps[($i+1)]->set_enabled();
105 }
106 }else{
107 $this->disable_steps_from($i+1);
108 }
109 }
110 }
112 /* Disable all following steps, if one step isn't compelted right now .*/
113 for($i = 1 ; $i <= $this->i_steps ; $i ++ ){
114 if($this->o_steps[$i]->is_completed()){
115 }else{
116 $this->disable_steps_from($i+1);
117 }
118 }
120 $step = -1;
122 if(isset($_POST['setup_goto_step'])){
123 $step= $_POST['setup_goto_step'];
124 }
126 if(isset($_GET['step'])){
127 $step = $_GET['step'];
128 }elseif(isset($_POST['next'])){
129 $step = $this->i_current + 1;
130 }elseif(isset($_POST['last'])){
131 $step = $this->i_current - 1;
132 }
134 $once = true;
135 foreach($_POST as $name => $value){
136 if(preg_match("/^step_[0-9]*$/",$name) && $once ){
137 $step = preg_replace("/^step_/","",$name);
138 }
139 }
141 if($this->selectable_step($step)){
142 $this->i_last = $this->i_current;
143 $this->i_current = $step;
144 }
145 }
148 function disable_steps_from($start)
149 {
150 $found = false;
151 foreach($this->o_steps as $key => $step){
152 if($key == $start){
153 $found = true;
154 }
156 if($found){
157 $this->o_steps[$key]->set_enabled(false);
158 $this->o_steps[$key]->set_completed(false);
159 }
160 }
161 }
164 /* Create navigation menu */
165 function get_navigation_html()
166 {
167 $str = "";
168 foreach($this->o_steps as $key => $step){
170 $step -> update_strings();
172 $s_title = $step -> get_title();
173 $s_info = $step -> get_small_info();
174 $b_active = $step -> is_active();
175 $b_enabled = $step -> is_enabled();
176 $b_completed= $step -> is_completed();
178 if($b_completed){
179 $s = "<img src='images/true.png' alt='"._("Completed")."' class='center'> ";
180 }else{
181 $s = "<img src='images/empty.png' alt=' ' class='center'> ";
182 }
184 if($_SESSION['js']){
186 $str .="<div >";
188 if($b_enabled){
189 if($b_active){
190 $str .= "<div class='navigation_element_active'>";
191 $str .= "<div class='navigation_title_active'>".$s.$s_title."</div>";
192 $str .= "<div class='navigation_info'>".$s_info."</div>";
193 $str .= "</div>";
194 }else{
195 $str .= "<div class='navigation_element'>";
196 $str .= "<div onClick='document.mainform.setup_goto_step.value=\"$key\";document.mainform.submit();'
197 class='navigation_title_inactive'>".$s.$s_title."</div>";
198 $str .= "</div>";
199 }
200 }else{
201 $str .= "<div class='navigation_element'>";
202 $str .= "<div class='navigation_title_disabled'>".$s.$s_title."</div>";
203 $str .= "</div>";
204 }
205 $str .= "</div>" ;
206 }else{
207 $str .="<div >";
208 if($b_enabled){
209 if($b_active){
210 $str .= "<div class='navigation_element_active'>";
211 $str .= "<input style='text-align: left; color: #00008F; font-weight: bold; width:100%;'
212 type='button' value='".$s_title."' name='step_".$key."'>";
213 $str .= "</div>";
214 }else{
215 $str .= "<div class='navigation_element'>";
216 $str .= "<input style='text-align: left; color: #00008F; font-weight: bold; width:100%;'
217 type='submit' value='".$s_title."' name='step_".$key."'>";
218 $str .= "</div>";
219 }
220 }else{
221 $str .= "<div class='navigation_element'>";
222 $str .= "<div class='navigation_title_disabled'>".$s_title."</div>";
223 $str .= "</div>";
224 }
225 $str .= "</div>" ;
226 }
227 }
228 return($str);
229 }
233 function get_bottom_html()
234 {
235 /* Skip adding forward/backward button,
236 * if the currently opened step is a sub dialog
237 */
238 if($this->o_steps[$this->i_current]->dialog){
239 $str ="";
240 }else{
241 $str ="<p class='seperator' style='margin-bottom:10px;'> </p>";
242 $str.=" <div style='text-align:right;float:top;'>";
243 if(isset($this->o_steps[$this->i_current -1]) && $this->o_steps[$this->i_current -1]->is_enabled()){
244 $str .= "<input type='submit' name='last' value='"._("Back")."'>";
245 }else{
246 $str .= "<input type='button' name='last' value='"._("Back")."' disabled>";
247 }
248 $str.= " ";
249 if(isset($this->o_steps[$this->i_current + 1])){
250 $str .= "<input type='submit' name='next' value='"._("Continue")."'>";
251 }else{
252 $str .= "<input type='button' value='"._("Continue")."' disabled>";
253 }
254 $str .="</div>";
255 }
256 return($str);
257 }
260 /* Create header entry */
261 function get_header_html()
262 {
263 $str= $this->o_steps[$this->i_current]->print_header();
264 return ($str);
265 }
268 /* Check if the given step id is valid and selectable */
269 function selectable_step($id)
270 {
271 if(isset($this->o_steps[$id]) && $this->o_steps[$id]->is_enabled()){
272 return(true);
273 }
274 return(false);
275 }
276 }
281 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
282 ?>