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 {
26 var $i_steps = 8; // Number of setup steps
27 var $i_current= 1; // Current step
28 var $i_last = 1; // Last setup step;
29 var $o_steps = array();
31 var $captured_values = array();
33 function setup()
34 {
36 $this->o_steps[1] = new setup_step_1();
37 $this->o_steps[2] = new setup_step_2();
38 $this->o_steps[3] = new setup_step_3();
39 $this->o_steps[4] = new setup_step_4();
40 $this->o_steps[5] = new setup_step_5();
41 $this->o_steps[6] = new setup_step_6();
42 $this->o_steps[7] = new setup_step_7();
43 $this->o_steps[8] = new setup_step_8();
45 foreach($this->o_steps as $key => $step){
46 $this->o_steps[$key]->parent = $this;
47 }
49 /*
50 for($i = 1 ; $i <= $this->i_steps; $ii ++ ){
51 $class= "setup_step_".$i;
53 if(class_exists($class)){
54 $this->o_steps[$i] = new $class();
55 }else{
56 $this->o_steps[$i] = new setup_step();
57 trigger_error("Try to create class '".$class."' but it is not available, possibly you have forgotten to add the include in setup.php");
58 }
59 $this->o_steps[$i]->parent = $this;
60 }
61 */
62 }
64 function execute()
65 {
66 $smarty = get_smarty();
67 $this->o_steps[$this->i_last]->set_active(FALSE);
68 $this->o_steps[$this->i_current]->set_active();
69 $content = $this->o_steps[$this->i_current]->execute();
70 return($content);
71 }
74 /* Save posted attributes */
75 function save_object()
76 {
77 /* Call save_object for current setup step */
78 $this->o_steps[$this->i_current] -> save_object();
80 /* Get attributes from setup step */
81 $tmp = $this->o_steps[$this->i_current]->get_attributes();
82 foreach($tmp as $name => $value){
83 $this->captured_values[$name] = $value;
84 }
86 /* Set parent */
87 foreach($this->o_steps as $key => $value){
88 $this->o_steps[$key]->parent = $this;
89 }
91 /* Check if image button requests next page */
92 foreach($_POST as $name => $value){
93 if(preg_match("/^next_(x|y)/",$name)){
94 $_POST['next'] = TRUE;
95 }
96 if(preg_match("/^last_(x|y)/",$name)){
97 $_POST['last'] = TRUE;
98 }
99 }
101 /* Check if step was selected */
102 if(isset($_GET['step']) || isset($_POST['next']) || isset($_POST['last'])){
104 /* check if current setup step is completed now
105 and activate the next step if possible */
106 for($i = 1 ; $i <= $this->i_steps ; $i ++ ){
107 if($this->o_steps[$i]->is_completed()){
108 if(isset($this->o_steps[($i+1)])){
109 $this->o_steps[($i+1)]->set_enabled();
110 }else{
111 $this->o_steps[($i+1)]->set_enabled(false);
113 }
114 }
115 }
117 if(isset($_GET['step'])){
118 $step = $_GET['step'];
119 }elseif(isset($_POST['next'])){
120 $step = $this->i_current + 1;
121 }elseif(isset($_POST['last'])){
122 $step = $this->i_current - 1;
123 }
125 if($this->selectable_step($step)){
126 $this->i_last = $this->i_current;
127 $this->i_current = $step;
128 }
129 }
130 }
133 /* Create navigation menu */
134 function get_navigation_html()
135 {
136 $str = "";
137 foreach($this->o_steps as $key => $step){
139 $s_title = $step -> get_title();
140 $s_info = $step -> get_small_info();
141 $b_active = $step -> is_active();
142 $b_enabled = $step -> is_enabled();
144 $str .="<div >";
145 if($b_enabled){
146 if($b_active){
147 $str .= "<a href='?step=".$key."' class='navigation_element_active'>";
148 $str .= "<div class='navigation_title_active'>".$s_title."</div>";
149 $str .= "<div class='navigation_info'>".$s_info."</div>";
150 $str .= "</a><br>\n";
151 }else{
152 $str .= "<a href='?step=".$key."' class='navigation_element'>";
153 $str .= "<div class='navigation_title_inactive'>".$s_title."</div>";
154 $str .= "</a><br>\n";
155 }
156 }else{
157 $str .= "<div class='navigation_element'>";
158 $str .= "<div class='navigation_title_disabled'>".$s_title."</div>";
159 $str .= "</div>";
160 }
161 $str .= "</div>" ;
162 }
163 return($str);
164 }
167 /* Create header entry */
168 function get_header_html()
169 {
170 $str ="";
171 $str.=" <div >";
172 $str.=" <div>";
173 $str.=" <font style='font-size:20px;float:top'>";
174 $str.= $this->o_steps[$this->i_current]->get_long_title();
175 $str.=" </font>";
176 $str.=" </div>";
177 $str.=" <div style='text-align:right;float:top;'>";
178 if(isset($this->o_steps[$this->i_current -1]) && $this->o_steps[$this->i_current -1]->is_enabled()){
179 $str.=" <input class='center' type='image' name='last' src='images/setup_step_back.png' title='"._("Last step")."'>";
180 }else{
181 $str.=" <img class='center' src='images/setup_step_back_gray.png' title='"._("Last step")."'>";
182 }
183 # if(isset($this->o_steps[$this->i_current +1]) && $this->o_steps[$this->i_current +1]->is_enabled()){
184 $str.=" <input class='center' type='image' name='next' src='images/setup_step_forward.png' title='"._("Next step")."'>";
185 # }else{
186 # $str.=" <img class='center' src='images/setup_step_forward_gray.png' title='"._("Next step")."'>";
187 # }
188 $str.= " </div>";
189 $str.= "</div>";
190 return ($str);
191 }
194 /* Check if the given step id is valid and selectable */
195 function selectable_step($id)
196 {
197 if(isset($this->o_steps[$id]) && $this->o_steps[$id]->is_enabled()){
198 return(true);
199 }
200 return(false);
201 }
202 }
207 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
208 ?>