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