4dbd86a48d51d1e1f3bb8647ffd97b6ee32b9efc
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 $smarty = get_smarty();
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 onClick='document.mainform.setup_goto_step.value=\"$key\";document.mainform.submit();'
190 class='navigation_title_active'>".$s.$s_title."</div>";
191 $str .= "<div onClick='document.mainform.setup_goto_step.value=\"$key\";document.mainform.submit();'
192 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='submit' 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 $str ="";
236 $str.=" <div style='text-align:right;float:top;'>";
237 if(isset($this->o_steps[$this->i_current -1]) && $this->o_steps[$this->i_current -1]->is_enabled()){
238 $str .= "<input type='submit' name='last' value='"._("Backward")."'>";
239 }else{
240 $str .= "<input type='button' name='last' value='"._("Backward")."' disabled>";
241 }
243 if(isset($this->o_steps[$this->i_current + 1])){
244 $str .= "<input type='submit' name='next' value='"._("Forward")."'>";
245 }else{
246 $str .= "<input type='button' value='"._("Forward")."' disabled>";
247 }
248 $str .="</div>";
249 return($str);
250 }
253 /* Create header entry */
254 function get_header_html()
255 {
256 $str= $this->o_steps[$this->i_current]->print_header();
257 return ($str);
258 }
261 /* Check if the given step id is valid and selectable */
262 function selectable_step($id)
263 {
264 if(isset($this->o_steps[$id]) && $this->o_steps[$id]->is_enabled()){
265 return(true);
266 }
267 return(false);
268 }
269 }
274 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
275 ?>