Code

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