3b2fe43aad3413ad9bfb566c6c2747ac43d24c96
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 setup_step_1();
35 $this->o_steps[2] = new setup_step_2();
36 $this->o_steps[3] = new setup_step_3();
37 $this->o_steps[4] = new setup_step_4();
38 $this->o_steps[5] = new setup_step_5();
39 $this->o_steps[6] = new setup_step_6();
40 $this->o_steps[7] = new setup_step_6a();
41 $this->o_steps[8] = new setup_step_7();
42 $this->o_steps[9] = new setup_step_8();
44 foreach($this->o_steps as $key => $step){
45 $this->o_steps[$key]->parent = $this;
46 }
47 }
50 function execute()
51 {
52 $smarty = get_smarty();
53 $this->o_steps[$this->i_last]->set_active(FALSE);
54 $this->o_steps[$this->i_current]->set_active();
55 $content = $this->o_steps[$this->i_current]->execute();
56 return($content);
57 }
60 /* Save posted attributes */
61 function save_object()
62 {
63 /* Call save_object for current setup step */
64 $this->o_steps[$this->i_current] -> save_object();
66 /* Get attributes from setup step */
67 $tmp = $this->o_steps[$this->i_current]->get_attributes();
68 foreach($tmp as $name => $value){
69 $this->captured_values[$name] = $value;
70 }
72 /* Set parent */
73 foreach($this->o_steps as $key => $value){
74 $this->o_steps[$key]->parent = $this;
75 }
77 /* Check if image button requests next page */
78 foreach($_POST as $name => $value){
79 if(preg_match("/^next_(x|y)/",$name)){
80 $_POST['next'] = TRUE;
81 }
82 if(preg_match("/^last_(x|y)/",$name)){
83 $_POST['last'] = TRUE;
84 }
85 }
87 /* Check if step was selected */
88 if(isset($_GET['step']) || isset($_POST['next']) || isset($_POST['last']) || isset($_POST['setup_goto_step'])){
90 /* check if current setup step is completed now
91 and activate the next step if possible */
92 for($i = 1 ; $i <= $this->i_steps ; $i ++ ){
93 if($this->o_steps[$i]->is_completed()){
94 if(isset($this->o_steps[($i+1)])){
95 $this->o_steps[($i+1)]->set_enabled();
96 }
97 }else{
98 $this->disable_steps_from($i+1);
99 }
100 }
101 }
103 $step = -1;
105 if(isset($_POST['setup_goto_step'])){
106 $step= $_POST['setup_goto_step'];
107 }
109 if(isset($_GET['step'])){
110 $step = $_GET['step'];
111 }elseif(isset($_POST['next'])){
112 $step = $this->i_current + 1;
113 }elseif(isset($_POST['last'])){
114 $step = $this->i_current - 1;
115 }
117 $once = true;
118 foreach($_POST as $name => $value){
119 if(preg_match("/^step_[0-9]*$/",$name) && $once ){
120 $step = preg_replace("/^step_/","",$name);
121 }
122 }
124 if($this->selectable_step($step)){
125 $this->i_last = $this->i_current;
126 $this->i_current = $step;
127 }
128 }
131 function disable_steps_from($start)
132 {
133 $found = false;
134 foreach($this->o_steps as $key => $step){
135 if($key == $start){
136 $found = true;
137 }
139 if($found){
140 $this->o_steps[$key]->set_enabled(false);
141 $this->o_steps[$key]->set_completed(false);
142 }
143 }
144 }
147 /* Create navigation menu */
148 function get_navigation_html()
149 {
150 $str = "";
151 foreach($this->o_steps as $key => $step){
153 $step -> update_strings();
155 $s_title = $step -> get_title();
156 $s_info = $step -> get_small_info();
157 $b_active = $step -> is_active();
158 $b_enabled = $step -> is_enabled();
160 if($_SESSION['js']){
162 $str .="<div >";
163 if($b_enabled){
164 if($b_active){
165 $str .= "<div class='navigation_element_active'>";
166 $str .= "<div onClick='document.mainform.setup_goto_step.value=\"$key\";document.mainform.submit();'
167 class='navigation_title_active'>".$s_title."</div>";
168 $str .= "<div onClick='document.mainform.setup_goto_step.value=\"$key\";document.mainform.submit();'
169 class='navigation_info'>".$s_info."</div>";
170 $str .= "</div>";
171 }else{
172 $str .= "<div class='navigation_element'>";
173 $str .= "<div onClick='document.mainform.setup_goto_step.value=\"$key\";document.mainform.submit();'
174 class='navigation_title_inactive'>".$s_title."</div>";
175 $str .= "</div>";
176 }
177 }else{
178 $str .= "<div class='navigation_element'>";
179 $str .= "<div class='navigation_title_disabled'>".$s_title."</div>";
180 $str .= "</div>";
181 }
182 $str .= "</div>" ;
183 }else{
184 $str .="<div >";
185 if($b_enabled){
186 if($b_active){
187 $str .= "<div class='navigation_element_active'>";
188 $str .= "<input style='text-align: left; color: #00008F; font-weight: bold; width:100%;'
189 type='submit' value='".$s_title."' name='step_".$key."'>";
190 $str .= "</div>";
191 }else{
192 $str .= "<div class='navigation_element'>";
193 $str .= "<input style='text-align: left; color: #00008F; font-weight: bold; width:100%;'
194 type='submit' value='".$s_title."' name='step_".$key."'>";
195 $str .= "</div>";
196 }
197 }else{
198 $str .= "<div class='navigation_element'>";
199 $str .= "<div class='navigation_title_disabled'>".$s_title."</div>";
200 $str .= "</div>";
201 }
202 $str .= "</div>" ;
203 }
204 }
205 return($str);
206 }
209 /* Create header entry */
210 function get_header_html()
211 {
212 $str ="";
213 $str.=" <div >";
214 $str.=" <div>";
215 $str.=" <font style='font-size:20px;float:top'>";
216 $str.= $this->o_steps[$this->i_current]->get_long_title();
217 $str.=" </font>";
218 $str.=" </div>";
219 $str.=" <div style='text-align:right;float:top;'>";
220 if(isset($this->o_steps[$this->i_current -1]) && $this->o_steps[$this->i_current -1]->is_enabled()){
221 $str.=" <input class='center' type='image' name='last' src='images/setup_step_back.png' title='"._("Last step")."'>";
222 }else{
223 $str.=" <img class='center' src='images/setup_step_back_gray.png' title='"._("Last step")."'>";
224 }
225 # if(isset($this->o_steps[$this->i_current +1]) && $this->o_steps[$this->i_current +1]->is_enabled()){
226 $str.=" <input class='center' type='image' name='next' src='images/setup_step_forward.png' title='"._("Next step")."'>";
227 # }else{
228 # $str.=" <img class='center' src='images/setup_step_forward_gray.png' title='"._("Next step")."'>";
229 # }
230 $str.= " </div>";
231 $str.= "</div>";
232 return ($str);
233 }
236 /* Check if the given step id is valid and selectable */
237 function selectable_step($id)
238 {
239 if(isset($this->o_steps[$id]) && $this->o_steps[$id]->is_enabled()){
240 return(true);
241 }
242 return(false);
243 }
244 }
249 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
250 ?>