d1d73fb8ae7c778ea78f4777e4f28c33eac36707
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 /* Display phpinfo() dialog when $_GET['info'] is set,
63 * but only do this, if user is allowed to use the setup.
64 * If setupStep_Welcome is_completed, we are allowed to view those infos-
65 */
66 if(isset($_GET['info']) && get_class($this->o_steps[1]) == "Step_Welcome" && $this->o_steps[1]->is_completed()){
67 phpinfo();
68 }
70 /* display step error msgs */
71 $msgs = $this->o_steps[$this->i_current]->check();
72 foreach($msgs as $msg){
73 print_red($msg);
74 }
76 $this->o_steps[$this->i_last]->set_active(FALSE);
77 $this->o_steps[$this->i_current]->set_active();
78 $content = $this->o_steps[$this->i_current]->execute();
79 return($content);
80 }
83 /* Save posted attributes */
84 function save_object()
85 {
86 /* Call save_object for current setup step */
87 $this->o_steps[$this->i_current] -> save_object();
89 /* Get attributes from setup step */
90 $tmp = $this->o_steps[$this->i_current]->get_attributes();
91 foreach($tmp as $name => $value){
92 $this->captured_values[$name] = $value;
93 }
95 /* Set parent */
96 foreach($this->o_steps as $key => $value){
97 $this->o_steps[$key]->parent = $this;
98 }
100 /* Check if image button requests next page */
101 foreach($_POST as $name => $value){
102 if(preg_match("/^next_(x|y)/",$name)){
103 $_POST['next'] = TRUE;
104 }
105 if(preg_match("/^last_(x|y)/",$name)){
106 $_POST['last'] = TRUE;
107 }
108 }
110 /* Check if step was selected */
111 if(isset($_GET['step']) || isset($_POST['next']) || isset($_POST['last'])){
113 /* check if current setup step is completed now
114 and activate the next step if possible */
115 for($i = 1 ; $i <= $this->i_steps ; $i ++ ){
116 if($this->o_steps[$i]->is_completed()){
117 if(isset($this->o_steps[($i+1)])){
118 $this->o_steps[($i+1)]->set_enabled();
119 }
120 }else{
121 $this->disable_steps_from($i+1);
122 }
123 }
124 }
126 /* Disable all following steps, if one step isn't compelted right now .*/
127 for($i = 1 ; $i <= $this->i_steps ; $i ++ ){
128 if($this->o_steps[$i]->is_completed()){
129 }else{
130 $this->disable_steps_from($i+1);
131 }
132 }
134 $step = -1;
136 if(isset($_POST['setup_goto_step'])){
137 $step= $_POST['setup_goto_step'];
138 }
140 if(isset($_GET['step'])){
141 $step = $_GET['step'];
142 }elseif(isset($_POST['next'])){
143 $step = $this->i_current + 1;
144 }elseif(isset($_POST['last'])){
145 $step = $this->i_current - 1;
146 }
148 $once = true;
149 foreach($_POST as $name => $value){
150 if(preg_match("/^step_[0-9]*$/",$name) && $once ){
151 $step = preg_replace("/^step_/","",$name);
152 }
153 }
155 if($this->selectable_step($step)){
156 $this->i_last = $this->i_current;
157 $this->i_current = $step;
158 }
159 }
162 function disable_steps_from($start)
163 {
164 $found = false;
165 foreach($this->o_steps as $key => $step){
166 if($key == $start){
167 $found = true;
168 }
170 if($found){
171 $this->o_steps[$key]->set_enabled(false);
172 $this->o_steps[$key]->set_completed(false);
173 }
174 }
175 }
178 /* Create navigation menu */
179 function get_navigation_html()
180 {
181 $str = "";
182 foreach($this->o_steps as $key => $step){
184 $step -> update_strings();
186 $s_title = $step -> get_title();
187 $s_info = $step -> get_small_info();
188 $b_active = $step -> is_active();
189 $b_enabled = $step -> is_enabled();
190 $b_completed= $step -> is_completed();
192 if($b_completed){
193 $s = "<img src='images/true.png' alt='"._("Completed")."' class='center'> ";
194 }else{
195 $s = "<img src='images/empty.png' alt=' ' class='center'> ";
196 }
198 if($_SESSION['js']){
200 $str .="<div >";
202 if($b_enabled){
203 if($b_active){
204 $str .= "<div class='navigation_element_active'>";
205 $str .= "<div class='navigation_title_active'>".$s.$s_title."</div>";
206 $str .= "<div class='navigation_info'>".$s_info."</div>";
207 $str .= "</div>";
208 }else{
209 $str .= "<div class='navigation_element'>";
210 $str .= "<div onClick='document.mainform.setup_goto_step.value=\"$key\";document.mainform.submit();'
211 class='navigation_title_inactive'>".$s.$s_title."</div>";
212 $str .= "</div>";
213 }
214 }else{
215 $str .= "<div class='navigation_element'>";
216 $str .= "<div class='navigation_title_disabled'>".$s.$s_title."</div>";
217 $str .= "</div>";
218 }
219 $str .= "</div>" ;
220 }else{
221 $str .="<div >";
222 if($b_enabled){
223 if($b_active){
224 $str .= "<div class='navigation_element_active'>";
225 $str .= "<input style='text-align: left; color: #00008F; font-weight: bold; width:100%;'
226 type='button' value='".$s_title."' name='step_".$key."'>";
227 $str .= "</div>";
228 }else{
229 $str .= "<div class='navigation_element'>";
230 $str .= "<input style='text-align: left; color: #00008F; font-weight: bold; width:100%;'
231 type='submit' value='".$s_title."' name='step_".$key."'>";
232 $str .= "</div>";
233 }
234 }else{
235 $str .= "<div class='navigation_element'>";
236 $str .= "<div class='navigation_title_disabled'>".$s_title."</div>";
237 $str .= "</div>";
238 }
239 $str .= "</div>" ;
240 }
241 }
242 return($str);
243 }
247 function get_bottom_html()
248 {
249 /* Skip adding forward/backward button,
250 * if the currently opened step is a sub dialog
251 */
252 if($this->o_steps[$this->i_current]->dialog){
253 $str ="";
254 }else{
255 $str ="<p class='seperator' style='margin-bottom:10px;'> </p>";
256 $str.=" <div style='text-align:right;float:top;'>";
257 if(isset($this->o_steps[$this->i_current -1]) && $this->o_steps[$this->i_current -1]->is_enabled()){
258 $str .= "<input type='submit' name='last' value='"._("Back")."'>";
259 }else{
260 $str .= "<input type='button' name='last' value='"._("Back")."' disabled>";
261 }
262 $str.= " ";
263 $str .= "<input type='submit' name='next' value='"._("Continue")."'>";
264 $str .="</div>";
265 }
266 return($str);
267 }
270 /* Create header entry */
271 function get_header_html()
272 {
273 $str= $this->o_steps[$this->i_current]->print_header();
274 return ($str);
275 }
278 /* Check if the given step id is valid and selectable */
279 function selectable_step($id)
280 {
281 if(isset($this->o_steps[$id]) && $this->o_steps[$id]->is_enabled()){
282 return(true);
283 }
284 return(false);
285 }
286 }
291 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
292 ?>