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