Code

Removed debug stuff
[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  = 8;  // 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_7();
41     $this->o_steps[8] = new setup_step_8();
43     foreach($this->o_steps as $key => $step){
44       $this->o_steps[$key]->parent = $this;
45     }
46   }
49   function execute()
50   {
51     $smarty = get_smarty();
52     $this->o_steps[$this->i_last]->set_active(FALSE);
53     $this->o_steps[$this->i_current]->set_active();
54     $content = $this->o_steps[$this->i_current]->execute();
55     return($content);
56   }
59   /* Save posted attributes  */
60   function save_object()
61   {
62     /* Call save_object for current setup step */
63     $this->o_steps[$this->i_current] -> save_object();
65     /* Get attributes from setup step */
66     $tmp = $this->o_steps[$this->i_current]->get_attributes();
67     foreach($tmp as $name => $value){
68       $this->captured_values[$name] = $value;
69     }
71     /* Set parent */
72     foreach($this->o_steps as $key => $value){
73       $this->o_steps[$key]->parent = $this;
74     }
76     /* Check if image button requests next page */
77     foreach($_POST as $name => $value){
78       if(preg_match("/^next_(x|y)/",$name)){
79         $_POST['next'] = TRUE;
80       }
81       if(preg_match("/^last_(x|y)/",$name)){
82         $_POST['last'] = TRUE;
83       }
84     }
86     /* Check if step was selected */
87     if(isset($_GET['step']) || isset($_POST['next']) || isset($_POST['last']) || isset($_POST['setup_goto_step'])){
89       /* check if current setup step is completed now 
90           and activate the next step if possible */
91       for($i = 1 ; $i <= $this->i_steps ; $i ++ ){
92         if($this->o_steps[$i]->is_completed()){
93           if(isset($this->o_steps[($i+1)])){
94             $this->o_steps[($i+1)]->set_enabled();
95           }
96         }else{
97           $this->disable_steps_from($i+1);
98         }
99       }
100     }
101   
102     $step = -1;
104     if(isset($_GET['step'])){
105       $step = $_GET['step'];
106     }elseif(isset($_POST['next'])){
107       $step = $this->i_current + 1;
108     }elseif(isset($_POST['last'])){
109       $step = $this->i_current - 1;
110     }
111   
112     if(isset($_POST['setup_goto_step'])){
113       $step= $_POST['setup_goto_step'];
114     }
116     $once = true;
117     foreach($_POST as $name => $value){
118       if(preg_match("/^step_[0-9]*$/",$name) && $once ){
119         $step = preg_replace("/^step_/","",$name);
120       }
121     }
123     if($this->selectable_step($step)){
124       $this->i_last    = $this->i_current;
125       $this->i_current = $step;
126     }
127   }
130   function disable_steps_from($start)
131   {
132     $found = false;
133     foreach($this->o_steps as $key => $step){
134       if($key == $start){
135         $found = true;
136       }
138       if($found){ 
139         $this->o_steps[$key]->set_enabled(false);
140         $this->o_steps[$key]->set_completed(false);
141       }
142     }
143   }
146   /* Create navigation menu */
147   function get_navigation_html()
148   {
149     $str = "";
150     foreach($this->o_steps as $key => $step){
152       $s_title    = $step -> get_title();
153       $s_info     = $step -> get_small_info();
154       $b_active   = $step -> is_active();
155       $b_enabled  = $step -> is_enabled();
157       if($_SESSION['js']){
159         $str .="<div >";
160         if($b_enabled){
161           if($b_active){
162             $str .= "<div class='navigation_element_active'>";
163             $str .= "<div onClick='document.mainform.setup_goto_step.value=\"$key\";document.mainform.submit();'
164               class='navigation_title_active'>".$s_title."</div>";
165             $str .= "<div onClick='document.mainform.setup_goto_step.value=\"$key\";document.mainform.submit();'
166               class='navigation_info'>".$s_info."</div>";
167             $str .= "</div>";
168           }else{
169             $str .= "<div class='navigation_element'>";
170             $str .= "<div onClick='document.mainform.setup_goto_step.value=\"$key\";document.mainform.submit();'
171               class='navigation_title_inactive'>".$s_title."</div>";
172             $str .= "</div>";
173           }
174         }else{
175           $str .= "<div class='navigation_element'>";
176           $str .= "<div class='navigation_title_disabled'>".$s_title."</div>";
177           $str .= "</div>";
178         }
179         $str .= "</div>" ;
180       }else{
181         $str .="<div >";
182         if($b_enabled){
183           if($b_active){
184             $str .= "<div class='navigation_element_active'>";
185             $str .= "<input style='text-align: left; color: #00008F; font-weight: bold; width:100%;' 
186                         type='submit' value='".$s_title."' name='step_".$key."'>";
187             $str .= "</div>";
188           }else{
189             $str .= "<div class='navigation_element'>";
190             $str .= "<input style='text-align: left; color: #00008F; font-weight: bold; width:100%;' 
191                         type='submit' value='".$s_title."' name='step_".$key."'>";
192             $str .= "</div>";
193           }
194         }else{
195           $str .= "<div class='navigation_element'>";
196           $str .= "<div class='navigation_title_disabled'>".$s_title."</div>";
197           $str .= "</div>";
198         }
199         $str .= "</div>" ;
200       }
201     }
202     return($str);
203   }
205   
206   /* Create header entry */
207   function get_header_html()
208   {
209     $str ="";
210     $str.=" <div >";
211     $str.="   <div>";
212     $str.="     <font style='font-size:20px;float:top'>";
213     $str.=   $this->o_steps[$this->i_current]->get_long_title();
214     $str.="     </font>";
215     $str.="   </div>";
216     $str.="   <div style='text-align:right;float:top;'>";
217     if(isset($this->o_steps[$this->i_current -1]) && $this->o_steps[$this->i_current -1]->is_enabled()){
218       $str.="   <input class='center' type='image' name='last' src='images/setup_step_back.png'  title='"._("Last step")."'>";
219     }else{
220       $str.="   <img class='center' src='images/setup_step_back_gray.png' title='"._("Last step")."'>";
221     }
222 #   if(isset($this->o_steps[$this->i_current +1]) && $this->o_steps[$this->i_current +1]->is_enabled()){
223       $str.="   <input class='center' type='image' name='next' src='images/setup_step_forward.png'  title='"._("Next step")."'>";
224 #   }else{
225 #     $str.="   <img class='center' src='images/setup_step_forward_gray.png'  title='"._("Next step")."'>";
226 #   }
227     $str.= "  </div>";
228     $str.= "</div>";
229     return ($str);
230   }
233   /* Check if the given step id is valid and selectable */
234   function selectable_step($id)
235   {
236     if(isset($this->o_steps[$id]) && $this->o_steps[$id]->is_enabled()){
237       return(true);
238     }
239     return(false);
240   }
246 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
247 ?>