Code

Plug header style changes
[gosa.git] / setup / class_setup.inc
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   {
33     
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     /* Ensure that setup is not reachable if gosa.conf (CONFIG_FILE) */
45     if(file_exists(CONFIG_DIR."/".CONFIG_FILE)){
46       session_destroy();
47       header("Location: index.php")    ;
48       exit();
49     }
50     
51     foreach($this->o_steps as $key => $step){
52       $this->o_steps[$key]->parent = $this;
53     }
54   }
57   function execute()
58   {
59     $smarty = get_smarty();
60     $this->o_steps[$this->i_last]->set_active(FALSE);
61     $this->o_steps[$this->i_current]->set_active();
62     $content = $this->o_steps[$this->i_current]->execute();
63     return($content);
64   }
67   /* Save posted attributes  */
68   function save_object()
69   {
70     /* Call save_object for current setup step */
71     $this->o_steps[$this->i_current] -> save_object();
73     /* Get attributes from setup step */
74     $tmp = $this->o_steps[$this->i_current]->get_attributes();
75     foreach($tmp as $name => $value){
76       $this->captured_values[$name] = $value;
77     }
79     /* Set parent */
80     foreach($this->o_steps as $key => $value){
81       $this->o_steps[$key]->parent = $this;
82     }
84     /* Check if image button requests next page */
85     foreach($_POST as $name => $value){
86       if(preg_match("/^next_(x|y)/",$name)){
87         $_POST['next'] = TRUE;
88       }
89       if(preg_match("/^last_(x|y)/",$name)){
90         $_POST['last'] = TRUE;
91       }
92     }
94     /* Check if step was selected */
95     if(isset($_GET['step']) || isset($_POST['next']) || isset($_POST['last']) || isset($_POST['setup_goto_step'])){
97       /* check if current setup step is completed now 
98           and activate the next step if possible */
99       for($i = 1 ; $i <= $this->i_steps ; $i ++ ){
100         if($this->o_steps[$i]->is_completed()){
101           if(isset($this->o_steps[($i+1)])){
102             $this->o_steps[($i+1)]->set_enabled();
103           }
104         }else{
105           $this->disable_steps_from($i+1);
106         }
107       }
108     }
109   
110     $step = -1;
112     if(isset($_POST['setup_goto_step'])){
113       $step= $_POST['setup_goto_step'];
114     }
116     if(isset($_GET['step'])){
117       $step = $_GET['step'];
118     }elseif(isset($_POST['next'])){
119       $step = $this->i_current + 1;
120     }elseif(isset($_POST['last'])){
121       $step = $this->i_current - 1;
122     }
123   
124     $once = true;
125     foreach($_POST as $name => $value){
126       if(preg_match("/^step_[0-9]*$/",$name) && $once ){
127         $step = preg_replace("/^step_/","",$name);
128       }
129     }
131     if($this->selectable_step($step)){
132       $this->i_last    = $this->i_current;
133       $this->i_current = $step;
134     }
135   }
138   function disable_steps_from($start)
139   {
140     $found = false;
141     foreach($this->o_steps as $key => $step){
142       if($key == $start){
143         $found = true;
144       }
146       if($found){ 
147         $this->o_steps[$key]->set_enabled(false);
148         $this->o_steps[$key]->set_completed(false);
149       }
150     }
151   }
154   /* Create navigation menu */
155   function get_navigation_html()
156   {
157     $str = "";
158     foreach($this->o_steps as $key => $step){
160       $step -> update_strings();
162       $s_title    = $step -> get_title();
163       $s_info     = $step -> get_small_info();
164       $b_active   = $step -> is_active();
165       $b_enabled  = $step -> is_enabled();
167       if($_SESSION['js']){
169         $str .="<div >";
170         if($b_enabled){
171           if($b_active){
172             $str .= "<div class='navigation_element_active'>";
173             $str .= "<div onClick='document.mainform.setup_goto_step.value=\"$key\";document.mainform.submit();'
174               class='navigation_title_active'>".$s_title."</div>";
175             $str .= "<div onClick='document.mainform.setup_goto_step.value=\"$key\";document.mainform.submit();'
176               class='navigation_info'>".$s_info."</div>";
177             $str .= "</div>";
178           }else{
179             $str .= "<div class='navigation_element'>";
180             $str .= "<div onClick='document.mainform.setup_goto_step.value=\"$key\";document.mainform.submit();'
181               class='navigation_title_inactive'>".$s_title."</div>";
182             $str .= "</div>";
183           }
184         }else{
185           $str .= "<div class='navigation_element'>";
186           $str .= "<div class='navigation_title_disabled'>".$s_title."</div>";
187           $str .= "</div>";
188         }
189         $str .= "</div>" ;
190       }else{
191         $str .="<div >";
192         if($b_enabled){
193           if($b_active){
194             $str .= "<div class='navigation_element_active'>";
195             $str .= "<input style='text-align: left; color: #00008F; font-weight: bold; width:100%;' 
196                         type='submit' value='".$s_title."' name='step_".$key."'>";
197             $str .= "</div>";
198           }else{
199             $str .= "<div class='navigation_element'>";
200             $str .= "<input style='text-align: left; color: #00008F; font-weight: bold; width:100%;' 
201                         type='submit' value='".$s_title."' name='step_".$key."'>";
202             $str .= "</div>";
203           }
204         }else{
205           $str .= "<div class='navigation_element'>";
206           $str .= "<div class='navigation_title_disabled'>".$s_title."</div>";
207           $str .= "</div>";
208         }
209         $str .= "</div>" ;
210       }
211     }
212     return($str);
213   }
215   
217   function get_bottom_html()
218   {
219     $str ="";
220     $str.="   <div style='text-align:right;float:top;'>";
221     if(isset($this->o_steps[$this->i_current -1]) && $this->o_steps[$this->i_current -1]->is_enabled()){
222       $str .= "<input type='submit' name='last' value='"._("Backward")."'>";
223     }else{
224       $str .= "<input type='button' name='last' value='"._("Backward")."' disabled>";
225     }
227     $str .= "<input type='submit' name='next' value='"._("Forward")."'>";
228     $str .="</div>";
229     return($str);
230   }
232   
233   /* Create header entry */
234   function get_header_html()
235   {
236     $str ="";
237     $str.=" <div >";
238     $str.="   <div style='padding:3px;'>";
239     $str.="     <img src='images/system.png' alt='' class='center'>";
240     $str.=   $this->o_steps[$this->i_current]->get_long_title();
241     $str.="     ";
242     $str.="   </div>";
243 #     $str.="   <div style='text-align:right;float:top;'>";
244 #     if(isset($this->o_steps[$this->i_current -1]) && $this->o_steps[$this->i_current -1]->is_enabled()){
245 #       $str.="   <input class='center' type='image' name='last' src='images/setup_step_back.png'  title='"._("Last step")."'>";
246 #     }else{
247 #       $str.="   <img class='center' src='images/setup_step_back_gray.png' title='"._("Last step")."'>";
248 #     }
249 #     if(isset($this->o_steps[$this->i_current +1]) && $this->o_steps[$this->i_current +1]->is_enabled()){
250 #       $str.="   <input class='center' type='image' name='next' src='images/setup_step_forward.png'  title='"._("Next step")."'>";
251 #     }else{
252 #       $str.="   <img class='center' src='images/setup_step_forward_gray.png'  title='"._("Next step")."'>";
253 #     }
254 #     $str.= "  </div>";
255     $str.= "</div>";
256     return ($str);
257   }
260   /* Check if the given step id is valid and selectable */
261   function selectable_step($id)
262   {
263     if(isset($this->o_steps[$id]) && $this->o_steps[$id]->is_enabled()){
264       return(true);
265     }
266     return(false);
267   }
273 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
274 ?>