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 class='navigation_title_active'>".$s.$s_title."</div>";
189 $str .= "<div class='navigation_info'>".$s_info."</div>";
190 $str .= "</div>";
191 }else{
192 $str .= "<div class='navigation_element'>";
193 $str .= "<div onClick='document.mainform.setup_goto_step.value=\"$key\";document.mainform.submit();'
194 class='navigation_title_inactive'>".$s.$s_title."</div>";
195 $str .= "</div>";
196 }
197 }else{
198 $str .= "<div class='navigation_element'>";
199 $str .= "<div class='navigation_title_disabled'>".$s.$s_title."</div>";
200 $str .= "</div>";
201 }
202 $str .= "</div>" ;
203 }else{
204 $str .="<div >";
205 if($b_enabled){
206 if($b_active){
207 $str .= "<div class='navigation_element_active'>";
208 $str .= "<input style='text-align: left; color: #00008F; font-weight: bold; width:100%;'
209 type='button' value='".$s_title."' name='step_".$key."'>";
210 $str .= "</div>";
211 }else{
212 $str .= "<div class='navigation_element'>";
213 $str .= "<input style='text-align: left; color: #00008F; font-weight: bold; width:100%;'
214 type='submit' value='".$s_title."' name='step_".$key."'>";
215 $str .= "</div>";
216 }
217 }else{
218 $str .= "<div class='navigation_element'>";
219 $str .= "<div class='navigation_title_disabled'>".$s_title."</div>";
220 $str .= "</div>";
221 }
222 $str .= "</div>" ;
223 }
224 }
225 return($str);
226 }
230 function get_bottom_html()
231 {
232 $str ="";
233 $str.=" <div style='text-align:right;float:top;'>";
234 if(isset($this->o_steps[$this->i_current -1]) && $this->o_steps[$this->i_current -1]->is_enabled()){
235 $str .= "<input type='submit' name='last' value='"._("Back")."'>";
236 }else{
237 $str .= "<input type='button' name='last' value='"._("Back")."' disabled>";
238 }
239 $str.= " ";
240 if(isset($this->o_steps[$this->i_current + 1])){
241 $str .= "<input type='submit' name='next' value='"._("Continue")."'>";
242 }else{
243 $str .= "<input type='button' value='"._("Continue")."' disabled>";
244 }
245 $str .="</div>";
246 return($str);
247 }
250 /* Create header entry */
251 function get_header_html()
252 {
253 $str= $this->o_steps[$this->i_current]->print_header();
254 return ($str);
255 }
258 /* Check if the given step id is valid and selectable */
259 function selectable_step($id)
260 {
261 if(isset($this->o_steps[$id]) && $this->o_steps[$id]->is_enabled()){
262 return(true);
263 }
264 return(false);
265 }
266 }
271 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
272 ?>