These two files need to be swapped
[isso.git] / Installer.php
1 <?php
2 /*=====================================================================*\
3 || ###################################################################
4 || # Blue Static ISSO Framework
5 || # Copyright (c)2005-2008 Blue Static
6 || #
7 || # This program is free software; you can redistribute it and/or modify
8 || # it under the terms of the GNU General Public License as published by
9 || # the Free Software Foundation; version 2 of the License.
10 || #
11 || # This program is distributed in the hope that it will be useful, but
12 || # WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
13 || # or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
14 || # more details.
15 || #
16 || # You should have received a copy of the GNU General Public License along
17 || # with this program; if not, write to the Free Software Foundation, Inc.,
18 || # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
19 || ###################################################################
20 \*=====================================================================*/
21
22 /**
23 * Installer creator (Install.php)
24 *
25 * @package ISSO
26 */
27
28 /**
29 * Installer
30 *
31 * Installer modules should extend this class. In the install module router,
32 * instantiate the right module. Methods beginning with step*() will be executed
33 * in numerical order.
34 *
35 * @author Blue Static
36 * @copyright Copyright (c)2005 - 2008, Blue Static
37 * @package ISSO
38 *
39 */
40 abstract class BSInstaller
41 {
42 /**
43 * All the method steps
44 * @var array
45 */
46 private $steps = array();
47
48 /**
49 * The file name of this module
50 * @var string
51 */
52 protected $fileName;
53
54 /**
55 * Constructor: set up the steps
56 *
57 * @param string The file name for this module
58 */
59 public function __construct($fileName)
60 {
61 $this->fileName = $fileName;
62
63 if (!BSApp::$input instanceof BSInput)
64 {
65 throw new Exception('BSApp::$input is not an instance of BSInput');
66 }
67
68 $methods = get_class_methods($this);
69 foreach ($methods as $name)
70 {
71 if (preg_match('/step([0-9]+)/', $name))
72 {
73 $this->steps[] = $name;
74 }
75 }
76 natsort($this->steps);
77
78 $this->_runStep(BSApp::$input->inputClean('step', TYPE_UINT));
79 }
80
81 // ###################################################################
82 /**
83 * An abstract method that needs to be overridden by a subclass that
84 * populates the page title
85 *
86 * @return string Returns the page title
87 */
88 protected abstract function _pageTitle();
89
90 // ###################################################################
91 /**
92 * Abstract method that will return link to the page after all the
93 * steps are completed. This needs to provide it's own <a>
94 *
95 * @return string Final page link
96 */
97 protected abstract function _finalLink();
98
99 // ###################################################################
100 /**
101 * Abstract method that prints out the first welcome screen that the
102 * user sees when no step has been selected
103 */
104 protected abstract function _welcomePage();
105
106 // ###################################################################
107 /**
108 * Prints out the page header... you really don't do this more than
109 * once
110 */
111 protected function _setUp()
112 {
113 ?>
114 <DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
115 "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
116 <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
117 <head>
118 <meta http-equiv="content-type" content="text/html; charset=iso-8859-1" />
119 <title><?= $this->_pageTitle() ?></title>
120
121 <style type="text/css">
122 <!--
123 body
124 {
125 font-family: Verdana, Arial, Helvetica, sans-serif;
126 font-size: 12px;
127 }
128
129 body a
130 {
131 color: rgb(0, 0, 238);
132 }
133
134 h1
135 {
136 color: rgb(66, 137, 155);
137 }
138
139 .buttonlink
140 {
141 margin-top: 20px;
142 }
143
144 .buttonlink a
145 {
146 font-weight: bold;
147 padding: 5px;
148 border: 1px solid black;
149 text-decoration: none;
150 color: rgb(37, 37, 37);
151 background-color: rgb(239, 239, 239);
152 margin-top: 20px;
153 }
154 //-->
155 </style>
156 </head>
157 <body>
158
159 <?php
160 }
161
162 // ###################################################################
163 /**
164 * Runs the specific step method; if it does not exist, it will throw
165 * an error
166 *
167 * @param integer Step number
168 */
169 protected function _runStep($step)
170 {
171 if ($step == 0)
172 {
173 $this->_setUp();
174 $this->_welcomePage();
175 $this->_setDown(0);
176 }
177 else if (in_array("step$step", $this->steps))
178 {
179 $this->_setUp();
180 $this->{"step$step"}();
181 $this->_setDown($step);
182 }
183 else
184 {
185 throw new Exception("step$step() does not exist in this module");
186 }
187 }
188
189 // ###################################################################
190 /**
191 * Prints out the footer part of the page, and the appropriate forwarding
192 * action button
193 *
194 * @param integer Step number
195 */
196 protected function _setDown($step)
197 {
198 // this is the last step, print the final button
199 if ($step == sizeof($this->steps))
200 {
201 echo '<div class="buttonlink">' . $this->_finalLink() . '</div>';
202 }
203 // just another step
204 else
205 {
206 echo '<div class="buttonlink"><a href="' . $this->fileName . '?step=' . ++$step . '">' . _('Next Step') . '</a></div>';
207 }
208
209 echo '
210 </body>
211
212 </html>';
213 }
214 }
215
216 ?>