Code

Divlist 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     $i = 1; 
34     $this->o_steps[$i++] = new Step_Welcome();
35     $this->o_steps[$i++] = new Step_Language();
36     $this->o_steps[$i++] = new Step_Checks();
37     $this->o_steps[$i++] = new Step_License();
38     $this->o_steps[$i++] = new Step_Ldap();
39     $this->o_steps[$i++] = new Step_Schema();
40     $this->o_steps[$i++] = new Step_Config1();
41     $this->o_steps[$i++] = new Step_Config2();
42     $this->o_steps[$i++] = new Step_Config3();
43     $this->o_steps[$i++] = new Step_Migrate();
44     $this->o_steps[$i++] = new Step_Finish();
45     $this->i_steps = $i-1;
47     /* Ensure that setup is not reachable if gosa.conf (CONFIG_FILE) */
48     if(file_exists(CONFIG_DIR."/".CONFIG_FILE)){
49       session_destroy();
50       header("Location: index.php")    ;
51       exit();
52     }
53     
54     foreach($this->o_steps as $key => $step){
55       $this->o_steps[$key]->parent = $this;
56     }
57   }
60   function execute()
61   {
62     /* display step error msgs */
63     $msgs = $this->o_steps[$this->i_current]->check();
64     foreach($msgs as $msg){
65       print_red($msg);
66     }
68     $this->o_steps[$this->i_last]->set_active(FALSE);
69     $this->o_steps[$this->i_current]->set_active();
70     $content = $this->o_steps[$this->i_current]->execute();
71     return($content);
72   }
75   /* Save posted attributes  */
76   function save_object()
77   {
78     /* Call save_object for current setup step */
79     $this->o_steps[$this->i_current] -> save_object();
81     /* Get attributes from setup step */
82     $tmp = $this->o_steps[$this->i_current]->get_attributes();
83     foreach($tmp as $name => $value){
84       $this->captured_values[$name] = $value;
85     }
87     /* Set parent */
88     foreach($this->o_steps as $key => $value){
89       $this->o_steps[$key]->parent = $this;
90     }
92     /* Check if image button requests next page */
93     foreach($_POST as $name => $value){
94       if(preg_match("/^next_(x|y)/",$name)){
95         $_POST['next'] = TRUE;
96       }
97       if(preg_match("/^last_(x|y)/",$name)){
98         $_POST['last'] = TRUE;
99       }
100     }
102     /* Check if step was selected */
103     if(isset($_GET['step']) || isset($_POST['next']) || isset($_POST['last'])){
105       /* check if current setup step is completed now 
106           and activate the next step if possible */
107       for($i = 1 ; $i <= $this->i_steps ; $i ++ ){
108         if($this->o_steps[$i]->is_completed()){
109           if(isset($this->o_steps[($i+1)])){
110             $this->o_steps[($i+1)]->set_enabled();
111           }
112         }else{
113           $this->disable_steps_from($i+1);
114         }
115       }
116     }
117  
118     /* Disable all following steps, if one step isn't compelted right now .*/
119     for($i = 1 ; $i <= $this->i_steps ; $i ++ ){
120       if($this->o_steps[$i]->is_completed()){
121       }else{
122         $this->disable_steps_from($i+1);
123       }
124     }
125  
126     $step = -1;
128     if(isset($_POST['setup_goto_step'])){
129       $step= $_POST['setup_goto_step'];
130     }
132     if(isset($_GET['step'])){
133       $step = $_GET['step'];
134     }elseif(isset($_POST['next'])){
135       $step = $this->i_current + 1;
136     }elseif(isset($_POST['last'])){
137       $step = $this->i_current - 1;
138     }
139   
140     $once = true;
141     foreach($_POST as $name => $value){
142       if(preg_match("/^step_[0-9]*$/",$name) && $once ){
143         $step = preg_replace("/^step_/","",$name);
144       }
145     }
147     if($this->selectable_step($step)){
148       $this->i_last    = $this->i_current;
149       $this->i_current = $step;
150     }
151   }
154   function disable_steps_from($start)
155   {
156     $found = false;
157     foreach($this->o_steps as $key => $step){
158       if($key == $start){
159         $found = true;
160       }
162       if($found){ 
163         $this->o_steps[$key]->set_enabled(false);
164         $this->o_steps[$key]->set_completed(false);
165       }
166     }
167   }
170   /* Create navigation menu */
171   function get_navigation_html()
172   {
173     $str = "";
174     foreach($this->o_steps as $key => $step){
176       $step -> update_strings();
178       $s_title    = $step -> get_title();
179       $s_info     = $step -> get_small_info();
180       $b_active   = $step -> is_active();
181       $b_enabled  = $step -> is_enabled();
182       $b_completed= $step -> is_completed();
184       if($b_completed){
185         $s = "<img src='images/true.png' alt='"._("Completed")."' class='center'>&nbsp;"; 
186       }else{
187         $s = "<img src='images/empty.png' alt=' ' class='center'>&nbsp;";
188       }
190       if($_SESSION['js']){
192         $str .="<div >";
193     
194         if($b_enabled){
195           if($b_active){
196             $str .= "<div class='navigation_element_active'>";
197             $str .= "<div class='navigation_title_active'>".$s.$s_title."</div>";
198             $str .= "<div class='navigation_info'>".$s_info."</div>";
199             $str .= "</div>";
200           }else{
201             $str .= "<div class='navigation_element'>";
202             $str .= "<div onClick='document.mainform.setup_goto_step.value=\"$key\";document.mainform.submit();'
203               class='navigation_title_inactive'>".$s.$s_title."</div>";
204             $str .= "</div>";
205           }
206         }else{
207           $str .= "<div class='navigation_element'>";
208           $str .= "<div class='navigation_title_disabled'>".$s.$s_title."</div>";
209           $str .= "</div>";
210         }
211         $str .= "</div>" ;
212       }else{
213         $str .="<div >";
214         if($b_enabled){
215           if($b_active){
216             $str .= "<div class='navigation_element_active'>";
217             $str .= "<input style='text-align: left; color: #00008F; font-weight: bold; width:100%;' 
218                         type='button' value='".$s_title."' name='step_".$key."'>";
219             $str .= "</div>";
220           }else{
221             $str .= "<div class='navigation_element'>";
222             $str .= "<input style='text-align: left; color: #00008F; font-weight: bold; width:100%;' 
223                         type='submit' value='".$s_title."' name='step_".$key."'>";
224             $str .= "</div>";
225           }
226         }else{
227           $str .= "<div class='navigation_element'>";
228           $str .= "<div class='navigation_title_disabled'>".$s_title."</div>";
229           $str .= "</div>";
230         }
231         $str .= "</div>" ;
232       }
233     }
234     return($str);
235   }
237   
239   function get_bottom_html()
240   {
241     /* Skip adding forward/backward button,   
242      *  if the currently opened step is a sub dialog 
243      */
244     if($this->o_steps[$this->i_current]->dialog){
245       $str ="";
246     }else{
247       $str ="<p class='seperator' style='margin-bottom:10px;'>&nbsp;</p>";
248       $str.="   <div style='text-align:right;float:top;'>";
249       if(isset($this->o_steps[$this->i_current -1]) && $this->o_steps[$this->i_current -1]->is_enabled()){
250         $str .= "<input type='submit' name='last' value='"._("Back")."'>";
251       }else{
252         $str .= "<input type='button' name='last' value='"._("Back")."' disabled>";
253       }
254       $str.= "&nbsp;";
255         $str .= "<input type='submit' name='next' value='"._("Continue")."'>";
256       $str .="</div>";
257     }
258     return($str);
259   }
261   
262   /* Create header entry */
263   function get_header_html()
264   {
265     $str=   $this->o_steps[$this->i_current]->print_header();
266     return ($str);
267   }
270   /* Check if the given step id is valid and selectable */
271   function selectable_step($id)
272   {
273     if(isset($this->o_steps[$id]) && $this->o_steps[$id]->is_enabled()){
274       return(true);
275     }
276     return(false);
277   }
283 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
284 ?>