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