8bd1e7bf1ec9c9bb3838229091e51a5793ba04e2
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 extends plugin
24 {
26 var $i_steps = 7; // 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 {
35 for($i = 1 ; $i <= $this->i_steps; $i ++ ){
36 $class= "setup_step_".$i;
38 if(class_exists($class)){
39 $this->o_steps[$i] = new $class();
40 }else{
41 $this->o_steps[$i] = new setup_step();
42 trigger_error("Try to create class '".$class."' but it is not available, possibly you have forgotten to add the include in setup.php");
43 }
44 }
45 }
47 function execute()
48 {
49 $smarty = get_smarty();
50 $this->o_steps[$this->i_last]->set_active(FALSE);
51 $this->o_steps[$this->i_current]->set_active();
52 $content = $this->o_steps[$this->i_current]->execute();
53 return($content);
54 }
57 /* Save posted attributes */
58 function save_object()
59 {
60 /* Call save_object for current setup step */
61 $this->o_steps[$this->i_current] -> save_object();
63 /* Get attributes from setup step */
64 $tmp = $this->o_steps[$this->i_current]->get_attributes();
65 foreach($tmp as $name => $value){
66 $this->captured_values[$name] = $value;
67 }
69 /* Check if image button requests next page */
70 foreach($_POST as $name => $value){
71 if(preg_match("/^next_(x|y)/",$name)){
72 $_POST['next'] = TRUE;
73 }
74 if(preg_match("/^last_(x|y)/",$name)){
75 $_POST['last'] = TRUE;
76 }
77 }
79 /* Check if step was selected */
80 if(isset($_GET['step']) || isset($_POST['next']) || isset($_POST['last'])){
82 /* check if current setup step is completed now
83 and activate the next step if possible */
84 for($i = 1 ; $i <= $this->i_steps ; $i ++ ){
85 if($this->o_steps[$i]->is_completed()){
86 if(isset($this->o_steps[($i+1)])){
87 $this->o_steps[($i+1)]->set_enabled();
88 }
89 }
90 }
92 if(isset($_GET['step'])){
93 $step = $_GET['step'];
94 }elseif(isset($_POST['next'])){
95 $step = $this->i_current + 1;
96 }elseif(isset($_POST['last'])){
97 $step = $this->i_current - 1;
98 }
100 if($this->selectable_step($step)){
101 $this->i_last = $this->i_current;
102 $this->i_current = $step;
103 }
104 }
105 }
108 /* Create navigation menu */
109 function get_navigation_html()
110 {
111 $str = "";
112 foreach($this->o_steps as $key => $step){
114 $s_title = $step -> get_title();
115 $s_info = $step -> get_small_info();
116 $b_active = $step -> is_active();
117 $b_enabled = $step -> is_enabled();
119 $str .="<div >";
120 if($b_enabled){
121 if($b_active){
122 $str .= "<a href='?step=".$key."' class='navigation_element_active'>";
123 $str .= "<div class='navigation_title_active'>".$s_title."</div>";
124 $str .= "<div class='navigation_info'>".$s_info."</div>";
125 $str .= "</a><br>\n";
126 }else{
127 $str .= "<a href='?step=".$key."' class='navigation_element'>";
128 $str .= "<div class='navigation_title_inactive'>".$s_title."</div>";
129 $str .= "</a><br>\n";
130 }
131 }else{
132 $str .= "<div class='navigation_element'>";
133 $str .= "<div class='navigation_title_disabled'>".$s_title."</div>";
134 $str .= "</div>";
135 }
136 $str .= "</div>" ;
137 }
138 return($str);
139 }
142 /* Create header entry */
143 function get_header_html()
144 {
145 $str ="";
146 $str.=" <div >";
147 $str.=" <div>";
148 $str.=" <font style='font-size:20px;float:top'>";
149 $str.= $this->o_steps[$this->i_current]->get_long_title();
150 $str.=" </font>";
151 $str.=" </div>";
152 $str.=" <div style='text-align:right;float:top;'>";
153 if(isset($this->o_steps[$this->i_current -1]) && $this->o_steps[$this->i_current -1]->is_enabled()){
154 $str.=" <input class='center' type='image' name='last' src='images/setup_step_back.png' title='"._("Last step")."'>";
155 }else{
156 $str.=" <img class='center' src='images/setup_step_back_gray.png' title='"._("Last step")."'>";
157 }
158 # if(isset($this->o_steps[$this->i_current +1]) && $this->o_steps[$this->i_current +1]->is_enabled()){
159 $str.=" <input class='center' type='image' name='next' src='images/setup_step_forward.png' title='"._("Next step")."'>";
160 # }else{
161 # $str.=" <img class='center' src='images/setup_step_forward_gray.png' title='"._("Next step")."'>";
162 # }
163 $str.= " </div>";
164 $str.= "</div>";
165 return ($str);
166 }
169 /* Check if the given step id is valid and selectable */
170 function selectable_step($id)
171 {
172 if(isset($this->o_steps[$id]) && $this->o_steps[$id]->is_enabled()){
173 return(true);
174 }
175 return(false);
176 }
177 }
182 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
183 ?>