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_Migrate();
44 $this->o_steps[$i++] = new Step_Feedback();
45 $this->o_steps[$i++] = new Step_Finish();
46 $this->i_steps = $i-1;
48 /* Ensure that setup is not reachable if gosa.conf (CONFIG_FILE) */
49 if(file_exists(CONFIG_DIR."/".CONFIG_FILE)){
50 session::destroy();
51 header("Location: index.php") ;
52 exit();
53 }
55 foreach($this->o_steps as $key => $step){
56 $this->o_steps[$key]->parent = &$this;
57 }
58 }
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']) && preg_match("/Step_Welcome/i",get_class($this->o_steps[1])) && $this->o_steps[1]->is_completed()){
67 phpinfo();
68 exit();
69 }
71 /* display step error msgs */
72 $msgs = $this->o_steps[$this->i_current]->check();
73 foreach($msgs as $msg){
74 msg_dialog::display(_("Setup error"), $msg, ERROR_DIALOG);
75 }
77 $this->o_steps[$this->i_last]->set_active(FALSE);
78 $this->o_steps[$this->i_current]->set_active();
79 $content = $this->o_steps[$this->i_current]->execute();
80 return($content);
81 }
84 /* Save posted attributes */
85 function save_object()
86 {
87 /* Call save_object for current setup step */
88 $this->o_steps[$this->i_current] -> save_object();
90 /* Get attributes from setup step */
91 $tmp = $this->o_steps[$this->i_current]->get_attributes();
92 foreach($tmp as $name => $value){
93 $this->captured_values[$name] = $value;
94 }
96 /* Set parent */
97 foreach($this->o_steps as $key => $value){
98 $this->o_steps[$key]->parent = $this;
99 }
101 /* Check if image button requests next page */
102 foreach($_POST as $name => $value){
103 if(preg_match("/^next_(x|y)/",$name)){
104 $_POST['next'] = TRUE;
105 }
106 if(preg_match("/^last_(x|y)/",$name)){
107 $_POST['last'] = TRUE;
108 }
109 }
111 /* Check if step was selected */
112 if(isset($_GET['step']) || isset($_POST['next']) || isset($_POST['last'])){
114 /* check if current setup step is completed now
115 and activate the next step if possible */
116 for($i = 1 ; $i <= $this->i_steps ; $i ++ ){
117 if($this->o_steps[$i]->is_completed()){
118 if(isset($this->o_steps[($i+1)])){
119 $this->o_steps[($i+1)]->set_enabled();
120 }
121 }else{
122 $this->disable_steps_from($i+1);
123 }
124 }
125 }
127 /* Disable all following steps, if one step isn't compelted right now .*/
128 for($i = 1 ; $i <= $this->i_steps ; $i ++ ){
129 if($this->o_steps[$i]->is_completed()){
130 }else{
131 $this->disable_steps_from($i+1);
132 }
133 }
135 $step = -1;
137 if(isset($_POST['setup_goto_step'])){
138 $step= $_POST['setup_goto_step'];
139 }
141 if(isset($_GET['step'])){
142 $step = $_GET['step'];
143 }elseif(isset($_POST['next'])){
144 $step = $this->i_current + 1;
145 }elseif(isset($_POST['last'])){
146 $step = $this->i_current - 1;
147 }
149 $once = true;
150 foreach($_POST as $name => $value){
151 if(preg_match("/^step_[0-9]*$/",$name) && $once ){
152 $step = preg_replace("/^step_/","",$name);
153 }
154 }
156 if($this->selectable_step($step)){
157 $this->i_last = $this->i_current;
158 $this->i_current = $step;
159 }
160 }
163 function disable_steps_from($start)
164 {
165 $found = false;
166 foreach($this->o_steps as $key => $step){
167 if($key == $start){
168 $found = true;
169 }
171 if($found){
172 $this->o_steps[$key]->set_enabled(false);
173 $this->o_steps[$key]->set_completed(false);
174 }
175 }
176 }
179 /* Create navigation menu */
180 function get_navigation_html()
181 {
182 $str = "<ul>";
183 $str .= "<li class='menu-header'>"._("Setup")."</li>";
184 foreach($this->o_steps as $key => $step){
186 $step -> update_strings();
188 $s_title = $step -> get_title();
189 $s_info = $step -> get_small_info();
190 $b_active = $step -> is_active();
191 $b_enabled = $step -> is_enabled();
192 $b_completed= $step -> is_completed();
194 if($b_completed){
195 $s = "<img src='images/true.png' alt='"._("Completed")."' class='center'> ";
196 }else{
197 $s = "<img src='images/empty.png' alt=' ' class='center'> ";
198 }
200 if($b_enabled){
201 if($b_active){
202 $str .= "<li class='active'>".$s.$s_title."</li>";
203 }else{
204 $str .= "<li onClick='document.mainform.setup_goto_step.value=\"$key\";document.mainform.submit();'
205 class='enabled'>".$s.$s_title."</li>";
206 }
207 }else{
208 $str .= "<li class='disabled'>".$s.$s_title."</li>";
209 }
210 }
211 $str .="</ul>";
212 $str .="<div class='v-spacer'></div>";
213 return($str);
214 }
218 function get_bottom_html()
219 {
220 /* Skip adding forward/backward button,
221 * if the currently opened step is a sub dialog
222 */
223 if($this->o_steps[$this->i_current]->dialog){
224 $str ="";
225 }else{
226 $str ="<div class='plugin-actions'>";
227 if(isset($this->o_steps[$this->i_current -1]) && $this->o_steps[$this->i_current -1]->is_enabled()){
228 $str .= "<button type='submit' name='last'>".msgPool::backButton()."</button>";
229 }else{
230 $str .= "<button disabled type='submit' name='last'>".msgPool::backButton()."</button>";
231 }
233 $str .= "<button type='submit' name='test'>"._("check")."</button>";
234 $str .= "<button type='submit' name='next'>"._("next")."</button>";
235 $str .="</div>";
236 }
237 return($str);
238 }
241 /* Create header entry */
242 function get_header_html()
243 {
244 $title = $this->o_steps[$this->i_current]->getTitle();
245 $image = $this->o_steps[$this->i_current]->getImage();
246 $page = $this->i_current ." / ".count($this->o_steps);
249 $str = "<div style='100%'>
250 <div style='float: left; '>
251 <img src='{$image}' alt=''>
252 </div>
253 <div style='float: left; margin-left:10px;margin-top:10px;font-size:24px;font-weight:bold;'>
254 {$title}
255 </div>
256 <div style='float: right; margin-top:10px;font-size:24px;font-weight:bold;'>
257 {$page}
258 </div>
259 </div>
260 <div class='clear'></div> ";
261 return ($str);
262 }
265 /* Check if the given step id is valid and selectable */
266 function selectable_step($id)
267 {
268 if(isset($this->o_steps[$id]) && $this->o_steps[$id]->is_enabled()){
269 return(true);
270 }
271 return(false);
272 }
274 function step_name_to_id($name)
275 {
276 foreach($this->o_steps as $id => $class){
277 if(get_class($class) == $name){
278 return($id);
279 }
280 }
281 return(0);
282 }
284 }
289 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
290 ?>