Code

Fixed step validation
[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'])){
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       }
101       if(isset($_GET['step'])){
102         $step = $_GET['step'];
103       }elseif(isset($_POST['next'])){
104         $step = $this->i_current + 1;
105       }elseif(isset($_POST['last'])){
106         $step = $this->i_current - 1;
107       }
109       if($this->selectable_step($step)){
110         $this->i_last    = $this->i_current;
111         $this->i_current = $step;
112       }
113     }
114   }
117   function disable_steps_from($start)
118   {
119     $found = false;
120     foreach($this->o_steps as $key => $step){
121       if($key == $start){
122         $found = true;
123       }
125       if($found){ 
126         echo $key." ";
127         $this->o_steps[$key]->set_enabled(false);
128         $this->o_steps[$key]->set_completed(false);
129       }
130     }
131   }
134   /* Create navigation menu */
135   function get_navigation_html()
136   {
137     $str = "";
138     foreach($this->o_steps as $key => $step){
140       $s_title    = $step -> get_title();
141       $s_info     = $step -> get_small_info();
142       $b_active   = $step -> is_active();
143       $b_enabled  = $step -> is_enabled();
145       $str .="<div >";
146       if($b_enabled){
147         if($b_active){
148           $str .= "<a href='?step=".$key."' class='navigation_element_active'>";
149           $str .= "<div class='navigation_title_active'>".$s_title."</div>";
150           $str .= "<div class='navigation_info'>".$s_info."</div>";
151           $str .= "</a><br>\n";
152         }else{
153           $str .= "<a href='?step=".$key."' class='navigation_element'>";
154           $str .= "<div class='navigation_title_inactive'>".$s_title."</div>";
155           $str .= "</a><br>\n";
156         }
157       }else{
158         $str .= "<div class='navigation_element'>";
159         $str .= "<div class='navigation_title_disabled'>".$s_title."</div>";
160         $str .= "</div>";
161       }
162       $str .= "</div>" ;
163     }
164     return($str);
165   }
167   
168   /* Create header entry */
169   function get_header_html()
170   {
171     $str ="";
172     $str.=" <div >";
173     $str.="   <div>";
174     $str.="     <font style='font-size:20px;float:top'>";
175     $str.=   $this->o_steps[$this->i_current]->get_long_title();
176     $str.="     </font>";
177     $str.="   </div>";
178     $str.="   <div style='text-align:right;float:top;'>";
179     if(isset($this->o_steps[$this->i_current -1]) && $this->o_steps[$this->i_current -1]->is_enabled()){
180       $str.="   <input class='center' type='image' name='last' src='images/setup_step_back.png'  title='"._("Last step")."'>";
181     }else{
182       $str.="   <img class='center' src='images/setup_step_back_gray.png' title='"._("Last step")."'>";
183     }
184 #   if(isset($this->o_steps[$this->i_current +1]) && $this->o_steps[$this->i_current +1]->is_enabled()){
185       $str.="   <input class='center' type='image' name='next' src='images/setup_step_forward.png'  title='"._("Next step")."'>";
186 #   }else{
187 #     $str.="   <img class='center' src='images/setup_step_forward_gray.png'  title='"._("Next step")."'>";
188 #   }
189     $str.= "  </div>";
190     $str.= "</div>";
191     return ($str);
192   }
195   /* Check if the given step id is valid and selectable */
196   function selectable_step($id)
197   {
198     if(isset($this->o_steps[$id]) && $this->o_steps[$id]->is_enabled()){
199       return(true);
200     }
201     return(false);
202   }
208 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
209 ?>