4f7c68b326a3ad989cf71b732858535c4eb48dc8
1 <?php
2 /*
3 * This code is part of GOsa (http://www.gosa-project.org)
4 * Copyright (C) 2003-2008 GONICUS GmbH
5 *
6 * ID: $$Id$$
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 */
23 require_once("class_setupStep.inc");
26 class setup
27 {
28 var $i_steps = 9; // Number of setup steps
29 var $i_current= 1; // Current step
30 var $i_last = 1; // Last setup step;
31 var $o_steps = array();
32 var $captured_values = array();
34 function setup()
35 {
36 $i = 1;
37 $this->o_steps[$i++] = new Step_Welcome();
38 $this->o_steps[$i++] = new Step_Language();
39 $this->o_steps[$i++] = new Step_Checks();
40 $this->o_steps[$i++] = new Step_License();
41 $this->o_steps[$i++] = new Step_Ldap();
42 $this->o_steps[$i++] = new Step_Schema();
43 $this->o_steps[$i++] = new Step_Config1();
44 $this->o_steps[$i++] = new Step_Config2();
45 $this->o_steps[$i++] = new Step_Config3();
46 $this->o_steps[$i++] = new Step_Migrate();
47 $this->o_steps[$i++] = new Step_Feedback();
48 $this->o_steps[$i++] = new Step_Finish();
49 $this->i_steps = $i-1;
51 /* Ensure that setup is not reachable if gosa.conf (CONFIG_FILE) */
52 if(file_exists(CONFIG_DIR."/".CONFIG_FILE)){
53 session::destroy();
54 header("Location: index.php") ;
55 exit();
56 }
58 foreach($this->o_steps as $key => $step){
59 $this->o_steps[$key]->parent = &$this;
60 }
61 }
63 function execute()
64 {
65 /* Display phpinfo() dialog when $_GET['info'] is set,
66 * but only do this, if user is allowed to use the setup.
67 * If setupStep_Welcome is_completed, we are allowed to view those infos-
68 */
69 if(isset($_GET['info']) && preg_match("/Step_Welcome/i",get_class($this->o_steps[1])) && $this->o_steps[1]->is_completed()){
70 phpinfo();
71 exit();
72 }
74 /* display step error msgs */
75 $msgs = $this->o_steps[$this->i_current]->check();
76 foreach($msgs as $msg){
77 msg_dialog::display(_("Setup error"), $msg, ERROR_DIALOG);
78 }
80 $this->o_steps[$this->i_last]->set_active(FALSE);
81 $this->o_steps[$this->i_current]->set_active();
82 $content = $this->o_steps[$this->i_current]->execute();
83 return($content);
84 }
87 /* Save posted attributes */
88 function save_object()
89 {
90 /* Call save_object for current setup step */
91 $this->o_steps[$this->i_current] -> save_object();
93 /* Get attributes from setup step */
94 $tmp = $this->o_steps[$this->i_current]->get_attributes();
95 foreach($tmp as $name => $value){
96 $this->captured_values[$name] = $value;
97 }
99 /* Set parent */
100 foreach($this->o_steps as $key => $value){
101 $this->o_steps[$key]->parent = $this;
102 }
104 /* Check if image button requests next page */
105 foreach($_POST as $name => $value){
106 if(preg_match("/^next_(x|y)/",$name)){
107 $_POST['next'] = TRUE;
108 }
109 if(preg_match("/^last_(x|y)/",$name)){
110 $_POST['last'] = TRUE;
111 }
112 }
114 /* Check if step was selected */
115 if(isset($_GET['step']) || isset($_POST['next']) || isset($_POST['last'])){
117 /* check if current setup step is completed now
118 and activate the next step if possible */
119 for($i = 1 ; $i <= $this->i_steps ; $i ++ ){
120 if($this->o_steps[$i]->is_completed()){
121 if(isset($this->o_steps[($i+1)])){
122 $this->o_steps[($i+1)]->set_enabled();
123 }
124 }else{
125 $this->disable_steps_from($i+1);
126 }
127 }
128 }
130 /* Disable all following steps, if one step isn't compelted right now .*/
131 for($i = 1 ; $i <= $this->i_steps ; $i ++ ){
132 if($this->o_steps[$i]->is_completed()){
133 }else{
134 $this->disable_steps_from($i+1);
135 }
136 }
138 $step = -1;
140 if(isset($_POST['setup_goto_step'])){
141 $step= $_POST['setup_goto_step'];
142 }
144 if(isset($_GET['step'])){
145 $step = $_GET['step'];
146 }elseif(isset($_POST['next'])){
147 $step = $this->i_current + 1;
148 }elseif(isset($_POST['last'])){
149 $step = $this->i_current - 1;
150 }
152 $once = true;
153 foreach($_POST as $name => $value){
154 if(preg_match("/^step_[0-9]*$/",$name) && $once ){
155 $step = preg_replace("/^step_/","",$name);
156 }
157 }
159 if($this->selectable_step($step)){
160 $this->i_last = $this->i_current;
161 $this->i_current = $step;
162 }
163 }
166 function disable_steps_from($start)
167 {
168 $found = false;
169 foreach($this->o_steps as $key => $step){
170 if($key == $start){
171 $found = true;
172 }
174 if($found){
175 $this->o_steps[$key]->set_enabled(false);
176 $this->o_steps[$key]->set_completed(false);
177 }
178 }
179 }
182 /* Create navigation menu */
183 function get_navigation_html()
184 {
185 $str = "";
186 foreach($this->o_steps as $key => $step){
188 $step -> update_strings();
190 $s_title = $step -> get_title();
191 $s_info = $step -> get_small_info();
192 $b_active = $step -> is_active();
193 $b_enabled = $step -> is_enabled();
194 $b_completed= $step -> is_completed();
196 if($b_completed){
197 $s = "<img src='images/true.png' alt='"._("Completed")."' class='center'> ";
198 }else{
199 $s = "<img src='images/empty.png' alt=' ' class='center'> ";
200 }
202 if(session::get('js')){
204 $str .="<div >";
206 if($b_enabled){
207 if($b_active){
208 $str .= "<div class='navigation_element_active'>";
209 $str .= "<div class='navigation_title_active'>".$s.$s_title."</div>";
210 $str .= "<div class='navigation_info'>".$s_info."</div>";
211 $str .= "</div>";
212 }else{
213 $str .= "<div class='navigation_element'>";
214 $str .= "<div onClick='document.mainform.setup_goto_step.value=\"$key\";document.mainform.submit();'
215 class='navigation_title_inactive'>".$s.$s_title."</div>";
216 $str .= "</div>";
217 }
218 }else{
219 $str .= "<div class='navigation_element'>";
220 $str .= "<div class='navigation_title_disabled'>".$s.$s_title."</div>";
221 $str .= "</div>";
222 }
223 $str .= "</div>" ;
224 }else{
225 $str .="<div >";
226 if($b_enabled){
227 if($b_active){
228 $str .= "<div class='navigation_element_active'>";
229 $str .= "<input style='text-align: left; color: #00008F; font-weight: bold; width:100%;'
230 type='button' value='".$s_title."' name='step_".$key."'>";
231 $str .= "</div>";
232 }else{
233 $str .= "<div class='navigation_element'>";
234 $str .= "<input style='text-align: left; color: #00008F; font-weight: bold; width:100%;'
235 type='submit' value='".$s_title."' name='step_".$key."'>";
236 $str .= "</div>";
237 }
238 }else{
239 $str .= "<div class='navigation_element'>";
240 $str .= "<div class='navigation_title_disabled'>".$s_title."</div>";
241 $str .= "</div>";
242 }
243 $str .= "</div>" ;
244 }
245 }
246 return($str);
247 }
251 function get_bottom_html()
252 {
253 /* Skip adding forward/backward button,
254 * if the currently opened step is a sub dialog
255 */
256 if($this->o_steps[$this->i_current]->dialog){
257 $str ="";
258 }else{
259 $str ="<p class='seperator' style='margin-bottom:10px;'> </p>";
260 $str.=" <div style='text-align:right;float:top;'>";
261 if(isset($this->o_steps[$this->i_current -1]) && $this->o_steps[$this->i_current -1]->is_enabled()){
262 $str .= "<input type='submit' name='last' value='".msgPool::backButton()."'>";
263 }else{
264 $str .= "<input type='button' name='last' value='".msgPool::backButton()."' disabled>";
265 }
266 $str.= " ";
267 $str .= "<input type='submit' name='next' value='"._("Next")."'>";
268 $str .="</div>";
269 }
270 return($str);
271 }
274 /* Create header entry */
275 function get_header_html()
276 {
277 $str= $this->o_steps[$this->i_current]->print_header();
278 return ($str);
279 }
282 /* Check if the given step id is valid and selectable */
283 function selectable_step($id)
284 {
285 if(isset($this->o_steps[$id]) && $this->o_steps[$id]->is_enabled()){
286 return(true);
287 }
288 return(false);
289 }
291 function step_name_to_id($name)
292 {
293 foreach($this->o_steps as $id => $class){
294 if(get_class($class) == $name){
295 return($id);
296 }
297 }
298 return(0);
299 }
301 }
306 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
307 ?>