Removing a lot of old system variables from BSApp
[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 BSApp::required_modules(array('Input'));
64
65 $methods = get_class_methods($this);
66 foreach ($methods AS $name)
67 {
68 if (preg_match('/step([0-9]+)/', $name))
69 {
70 $this->steps[] = $name;
71 }
72 }
73 natsort($this->steps);
74
75 $this->_runStep(BSApp::registry()->getType('Input')->inputClean('step', TYPE_UINT));
76 }
77
78 // ###################################################################
79 /**
80 * An abstract method that needs to be overridden by a subclass that
81 * populates the page title
82 *
83 * @return string Returns the page title
84 */
85 protected abstract function _pageTitle();
86
87 // ###################################################################
88 /**
89 * Abstract method that will return link to the page after all the
90 * steps are completed. This needs to provide it's own <a>
91 *
92 * @return string Final page link
93 */
94 protected abstract function _finalLink();
95
96 // ###################################################################
97 /**
98 * Abstract method that prints out the first welcome screen that the
99 * user sees when no step has been selected
100 */
101 protected abstract function _welcomePage();
102
103 // ###################################################################
104 /**
105 * Prints out the page header... you really don't do this more than
106 * once
107 */
108 protected function _setUp()
109 {
110 ?>
111 <DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
112 "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
113 <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
114 <head>
115 <meta http-equiv="content-type" content="text/html; charset=iso-8859-1" />
116 <title><?= $this->_pageTitle() ?></title>
117
118 <style type="text/css">
119 <!--
120 body
121 {
122 font-family: Verdana, Arial, Helvetica, sans-serif;
123 font-size: 12px;
124 }
125
126 body a
127 {
128 color: rgb(0, 0, 238);
129 }
130
131 h1
132 {
133 color: rgb(66, 137, 155);
134 }
135
136 .buttonlink
137 {
138 margin-top: 20px;
139 }
140
141 .buttonlink a
142 {
143 font-weight: bold;
144 padding: 5px;
145 border: 1px solid black;
146 text-decoration: none;
147 color: rgb(37, 37, 37);
148 background-color: rgb(239, 239, 239);
149 margin-top: 20px;
150 }
151 //-->
152 </style>
153 </head>
154 <body>
155
156 <?php
157 }
158
159 // ###################################################################
160 /**
161 * Runs the specific step method; if it does not exist, it will throw
162 * an error
163 *
164 * @param integer Step number
165 */
166 protected function _runStep($step)
167 {
168 if ($step == 0)
169 {
170 $this->_setUp();
171 $this->_welcomePage();
172 $this->_setDown(0);
173 }
174 else if (in_array("step$step", $this->steps))
175 {
176 $this->_setUp();
177 $this->{"step$step"}();
178 $this->_setDown($step);
179 }
180 else
181 {
182 throw new Exception("step$step() does not exist in this module");
183 }
184 }
185
186 // ###################################################################
187 /**
188 * Prints out the footer part of the page, and the appropriate forwarding
189 * action button
190 *
191 * @param integer Step number
192 */
193 protected function _setDown($step)
194 {
195 // this is the last step, print the final button
196 if ($step == sizeof($this->steps))
197 {
198 echo '<div class="buttonlink">' . $this->_finalLink() . '</div>';
199 }
200 // just another step
201 else
202 {
203 echo '<div class="buttonlink"><a href="' . $this->fileName . '?step=' . ++$step . '">' . _('Next Step') . '</a></div>';
204 }
205
206 echo '
207 </body>
208
209 </html>';
210 }
211 }
212
213 ?>