Code

Fixed Post Problems
[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 */
22 /* Returns contents of the given POST variable and check magic quotes settings */
23 function get_post($name)
24 {
25   if(!isset($_POST[$name])){
26     trigger_error("Requested POST value (".$name.") does not exists, you should add a check to prevent this message.");
27     return(FALSE);
28   }
29   if(get_magic_quotes_gpc()){
30     return(stripcslashes($_POST[$name]));
31   }else{
32     return($_POST[$name]);
33   }
34 }
36 require_once("class_setupStep.inc");
39 class setup 
40 {
41   var $i_steps  = 9;  // Number of setup steps 
42   var $i_current= 1;  // Current step
43   var $i_last   = 1;  // Last setup step;
44   var $o_steps  = array(); 
45   var $captured_values = array();
47   function setup()
48   {
49     $i = 1; 
50     $this->o_steps[$i++] = new Step_Welcome();
51     $this->o_steps[$i++] = new Step_Language();
52     $this->o_steps[$i++] = new Step_Checks();
53     $this->o_steps[$i++] = new Step_License();
54     $this->o_steps[$i++] = new Step_Ldap();
55     $this->o_steps[$i++] = new Step_Schema();
56     $this->o_steps[$i++] = new Step_Config1();
57     $this->o_steps[$i++] = new Step_Config2();
58     $this->o_steps[$i++] = new Step_Config3();
59     $this->o_steps[$i++] = new Step_Migrate();
60     $this->o_steps[$i++] = new Step_Finish();
61     $this->i_steps = $i-1;
63     /* Ensure that setup is not reachable if gosa.conf (CONFIG_FILE) */
64     if(file_exists(CONFIG_DIR."/".CONFIG_FILE)){
65       session_destroy();
66       header("Location: index.php")    ;
67       exit();
68     }
69     
70     foreach($this->o_steps as $key => $step){
71       $this->o_steps[$key]->parent = $this;
72     }
73   }
75   function execute()
76   {
77     /* Display phpinfo() dialog when $_GET['info'] is set,
78      *  but only do this, if user is allowed to use the setup.
79      * If setupStep_Welcome is_completed, we are allowed to view those infos-
80      */
81     if(isset($_GET['info']) && get_class($this->o_steps[1]) == "Step_Welcome" && $this->o_steps[1]->is_completed()){
82       phpinfo();
83       exit();
84     }
86     /* display step error msgs */
87     $msgs = $this->o_steps[$this->i_current]->check();
88     foreach($msgs as $msg){
89       print_red($msg);
90     }
92     $this->o_steps[$this->i_last]->set_active(FALSE);
93     $this->o_steps[$this->i_current]->set_active();
94     $content = $this->o_steps[$this->i_current]->execute();
95     return($content);
96   }
99   /* Save posted attributes  */
100   function save_object()
101   {
102     /* Call save_object for current setup step */
103     $this->o_steps[$this->i_current] -> save_object();
105     /* Get attributes from setup step */
106     $tmp = $this->o_steps[$this->i_current]->get_attributes();
107     foreach($tmp as $name => $value){
108       $this->captured_values[$name] = $value;
109     }
111     /* Set parent */
112     foreach($this->o_steps as $key => $value){
113       $this->o_steps[$key]->parent = $this;
114     }
116     /* Check if image button requests next page */
117     foreach($_POST as $name => $value){
118       if(preg_match("/^next_(x|y)/",$name)){
119         $_POST['next'] = TRUE;
120       }
121       if(preg_match("/^last_(x|y)/",$name)){
122         $_POST['last'] = TRUE;
123       }
124     }
126     /* Check if step was selected */
127     if(isset($_GET['step']) || isset($_POST['next']) || isset($_POST['last'])){
129       /* check if current setup step is completed now 
130           and activate the next step if possible */
131       for($i = 1 ; $i <= $this->i_steps ; $i ++ ){
132         if($this->o_steps[$i]->is_completed()){
133           if(isset($this->o_steps[($i+1)])){
134             $this->o_steps[($i+1)]->set_enabled();
135           }
136         }else{
137           $this->disable_steps_from($i+1);
138         }
139       }
140     }
141  
142     /* Disable all following steps, if one step isn't compelted right now .*/
143     for($i = 1 ; $i <= $this->i_steps ; $i ++ ){
144       if($this->o_steps[$i]->is_completed()){
145       }else{
146         $this->disable_steps_from($i+1);
147       }
148     }
149  
150     $step = -1;
152     if(isset($_POST['setup_goto_step'])){
153       $step= $_POST['setup_goto_step'];
154     }
156     if(isset($_GET['step'])){
157       $step = $_GET['step'];
158     }elseif(isset($_POST['next'])){
159       $step = $this->i_current + 1;
160     }elseif(isset($_POST['last'])){
161       $step = $this->i_current - 1;
162     }
163   
164     $once = true;
165     foreach($_POST as $name => $value){
166       if(preg_match("/^step_[0-9]*$/",$name) && $once ){
167         $step = preg_replace("/^step_/","",$name);
168       }
169     }
171     if($this->selectable_step($step)){
172       $this->i_last    = $this->i_current;
173       $this->i_current = $step;
174     }
175   }
178   function disable_steps_from($start)
179   {
180     $found = false;
181     foreach($this->o_steps as $key => $step){
182       if($key == $start){
183         $found = true;
184       }
186       if($found){ 
187         $this->o_steps[$key]->set_enabled(false);
188         $this->o_steps[$key]->set_completed(false);
189       }
190     }
191   }
194   /* Create navigation menu */
195   function get_navigation_html()
196   {
197     $str = "";
198     foreach($this->o_steps as $key => $step){
200       $step -> update_strings();
202       $s_title    = $step -> get_title();
203       $s_info     = $step -> get_small_info();
204       $b_active   = $step -> is_active();
205       $b_enabled  = $step -> is_enabled();
206       $b_completed= $step -> is_completed();
208       if($b_completed){
209         $s = "<img src='images/true.png' alt='"._("Completed")."' class='center'>&nbsp;"; 
210       }else{
211         $s = "<img src='images/empty.png' alt=' ' class='center'>&nbsp;";
212       }
214       if($_SESSION['js']){
216         $str .="<div >";
217     
218         if($b_enabled){
219           if($b_active){
220             $str .= "<div class='navigation_element_active'>";
221             $str .= "<div class='navigation_title_active'>".$s.$s_title."</div>";
222             $str .= "<div class='navigation_info'>".$s_info."</div>";
223             $str .= "</div>";
224           }else{
225             $str .= "<div class='navigation_element'>";
226             $str .= "<div onClick='document.mainform.setup_goto_step.value=\"$key\";document.mainform.submit();'
227               class='navigation_title_inactive'>".$s.$s_title."</div>";
228             $str .= "</div>";
229           }
230         }else{
231           $str .= "<div class='navigation_element'>";
232           $str .= "<div class='navigation_title_disabled'>".$s.$s_title."</div>";
233           $str .= "</div>";
234         }
235         $str .= "</div>" ;
236       }else{
237         $str .="<div >";
238         if($b_enabled){
239           if($b_active){
240             $str .= "<div class='navigation_element_active'>";
241             $str .= "<input style='text-align: left; color: #00008F; font-weight: bold; width:100%;' 
242                         type='button' value='".$s_title."' name='step_".$key."'>";
243             $str .= "</div>";
244           }else{
245             $str .= "<div class='navigation_element'>";
246             $str .= "<input style='text-align: left; color: #00008F; font-weight: bold; width:100%;' 
247                         type='submit' value='".$s_title."' name='step_".$key."'>";
248             $str .= "</div>";
249           }
250         }else{
251           $str .= "<div class='navigation_element'>";
252           $str .= "<div class='navigation_title_disabled'>".$s_title."</div>";
253           $str .= "</div>";
254         }
255         $str .= "</div>" ;
256       }
257     }
258     return($str);
259   }
261   
263   function get_bottom_html()
264   {
265     /* Skip adding forward/backward button,   
266      *  if the currently opened step is a sub dialog 
267      */
268     if($this->o_steps[$this->i_current]->dialog){
269       $str ="";
270     }else{
271       $str ="<p class='seperator' style='margin-bottom:10px;'>&nbsp;</p>";
272       $str.="   <div style='text-align:right;float:top;'>";
273       if(isset($this->o_steps[$this->i_current -1]) && $this->o_steps[$this->i_current -1]->is_enabled()){
274         $str .= "<input type='submit' name='last' value='"._("Back")."'>";
275       }else{
276         $str .= "<input type='button' name='last' value='"._("Back")."' disabled>";
277       }
278       $str.= "&nbsp;";
279         $str .= "<input type='submit' name='next' value='"._("Continue")."'>";
280       $str .="</div>";
281     }
282     return($str);
283   }
285   
286   /* Create header entry */
287   function get_header_html()
288   {
289     $str=   $this->o_steps[$this->i_current]->print_header();
290     return ($str);
291   }
294   /* Check if the given step id is valid and selectable */
295   function selectable_step($id)
296   {
297     if(isset($this->o_steps[$id]) && $this->o_steps[$id]->is_enabled()){
298       return(true);
299     }
300     return(false);
301   }
307 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
308 ?>