Code

Updated object movement.
[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 {
26   var $i_steps  = 7;  // Number of setup steps 
27   var $i_current= 1;  // Current step
28   var $i_last   = 1;  // Last setup step;
29   var $o_steps  = array(); 
31   var $captured_values = array();
33   function setup()
34   {
35     for($i = 1 ; $i <= $this->i_steps; $i ++ ){
36       $class= "setup_step_".$i;
37     
38       if(class_exists($class)){
39         $this->o_steps[$i] = new $class();
40       }else{
41         $this->o_steps[$i] = new setup_step();
42         trigger_error("Try to create class '".$class."' but it is not available, possibly you have forgotten to add the include in setup.php");
43       }
44       $this->o_steps[$i]->parent = $this;
45     }
46   }
48   function execute()
49   {
50     $smarty = get_smarty();
51     $this->o_steps[$this->i_last]->set_active(FALSE);
52     $this->o_steps[$this->i_current]->set_active();
53     $content = $this->o_steps[$this->i_current]->execute();
54     return($content);
55   }
58   /* Save posted attributes  */
59   function save_object()
60   {
61     /* Call save_object for current setup step */
62     $this->o_steps[$this->i_current] -> save_object();
64     /* Get attributes from setup step */
65     $tmp = $this->o_steps[$this->i_current]->get_attributes();
66     foreach($tmp as $name => $value){
67       $this->captured_values[$name] = $value;
68     }
70     /* Set parent */
71     foreach($this->o_steps as $key => $value){
72       $this->o_steps[$key]->parent = $this;
73     }
75     /* Check if image button requests next page */
76     foreach($_POST as $name => $value){
77       if(preg_match("/^next_(x|y)/",$name)){
78         $_POST['next'] = TRUE;
79       }
80       if(preg_match("/^last_(x|y)/",$name)){
81         $_POST['last'] = TRUE;
82       }
83     }
85     /* Check if step was selected */
86     if(isset($_GET['step']) || isset($_POST['next']) || isset($_POST['last'])){
88       /* check if current setup step is completed now 
89           and activate the next step if possible */
90       for($i = 1 ; $i <= $this->i_steps ; $i ++ ){
91         if($this->o_steps[$i]->is_completed()){
92           if(isset($this->o_steps[($i+1)])){
93             $this->o_steps[($i+1)]->set_enabled();
94           }
95         }
96       }
98       if(isset($_GET['step'])){
99         $step = $_GET['step'];
100       }elseif(isset($_POST['next'])){
101         $step = $this->i_current + 1;
102       }elseif(isset($_POST['last'])){
103         $step = $this->i_current - 1;
104       }
106       if($this->selectable_step($step)){
107         $this->i_last    = $this->i_current;
108         $this->i_current = $step;
109       }
110     }
111   }
114   /* Create navigation menu */
115   function get_navigation_html()
116   {
117     $str = "";
118     foreach($this->o_steps as $key => $step){
120       $s_title    = $step -> get_title();
121       $s_info     = $step -> get_small_info();
122       $b_active   = $step -> is_active();
123       $b_enabled  = $step -> is_enabled();
125       $str .="<div >";
126       if($b_enabled){
127         if($b_active){
128           $str .= "<a href='?step=".$key."' class='navigation_element_active'>";
129           $str .= "<div class='navigation_title_active'>".$s_title."</div>";
130           $str .= "<div class='navigation_info'>".$s_info."</div>";
131           $str .= "</a><br>\n";
132         }else{
133           $str .= "<a href='?step=".$key."' class='navigation_element'>";
134           $str .= "<div class='navigation_title_inactive'>".$s_title."</div>";
135           $str .= "</a><br>\n";
136         }
137       }else{
138         $str .= "<div class='navigation_element'>";
139         $str .= "<div class='navigation_title_disabled'>".$s_title."</div>";
140         $str .= "</div>";
141       }
142       $str .= "</div>" ;
143     }
144     return($str);
145   }
147   
148   /* Create header entry */
149   function get_header_html()
150   {
151     $str ="";
152     $str.=" <div >";
153     $str.="   <div>";
154     $str.="     <font style='font-size:20px;float:top'>";
155     $str.=   $this->o_steps[$this->i_current]->get_long_title();
156     $str.="     </font>";
157     $str.="   </div>";
158     $str.="   <div style='text-align:right;float:top;'>";
159     if(isset($this->o_steps[$this->i_current -1]) && $this->o_steps[$this->i_current -1]->is_enabled()){
160       $str.="   <input class='center' type='image' name='last' src='images/setup_step_back.png'  title='"._("Last step")."'>";
161     }else{
162       $str.="   <img class='center' src='images/setup_step_back_gray.png' title='"._("Last step")."'>";
163     }
164 #   if(isset($this->o_steps[$this->i_current +1]) && $this->o_steps[$this->i_current +1]->is_enabled()){
165       $str.="   <input class='center' type='image' name='next' src='images/setup_step_forward.png'  title='"._("Next step")."'>";
166 #   }else{
167 #     $str.="   <img class='center' src='images/setup_step_forward_gray.png'  title='"._("Next step")."'>";
168 #   }
169     $str.= "  </div>";
170     $str.= "</div>";
171     return ($str);
172   }
175   /* Check if the given step id is valid and selectable */
176   function selectable_step($id)
177   {
178     if(isset($this->o_steps[$id]) && $this->o_steps[$id]->is_enabled()){
179       return(true);
180     }
181     return(false);
182   }
188 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
189 ?>