Update version.php to 3.3.0
[isso.git] / Installer.php
1 <?php
2 /*=====================================================================*\
3 || ###################################################################
4 || # Blue Static ISSO Framework
5 || # Copyright (c)2005-2009 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 - 2009, 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 * An abstract method that needs to be overridden by a subclass that
83 * populates the page title
84 *
85 * @return string Returns the page title
86 */
87 protected abstract function _pageTitle();
88
89 /**
90 * Abstract method that will return link to the page after all the
91 * steps are completed. This needs to provide it's own <a>
92 *
93 * @return string Final page link
94 */
95 protected abstract function _finalLink();
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 * Prints out the page header... you really don't do this more than
105 * once
106 */
107 protected function _setUp()
108 {
109 ?>
110 <DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
111 "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
112 <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
113 <head>
114 <meta http-equiv="content-type" content="text/html; charset=iso-8859-1" />
115 <title><?= $this->_pageTitle() ?></title>
116
117 <style type="text/css">
118 <!--
119 body
120 {
121 font-family: Verdana, Arial, Helvetica, sans-serif;
122 font-size: 12px;
123 }
124
125 body a
126 {
127 color: rgb(0, 0, 238);
128 }
129
130 h1
131 {
132 color: rgb(66, 137, 155);
133 }
134
135 .buttonlink
136 {
137 margin-top: 20px;
138 }
139
140 .buttonlink a
141 {
142 font-weight: bold;
143 padding: 5px;
144 border: 1px solid black;
145 text-decoration: none;
146 color: rgb(37, 37, 37);
147 background-color: rgb(239, 239, 239);
148 margin-top: 20px;
149 }
150 //-->
151 </style>
152 </head>
153 <body>
154
155 <?php
156 }
157
158 /**
159 * Runs the specific step method; if it does not exist, it will throw
160 * an error
161 *
162 * @param integer Step number
163 */
164 protected function _runStep($step)
165 {
166 if ($step == 0)
167 {
168 $this->_setUp();
169 $this->_welcomePage();
170 $this->_setDown(0);
171 }
172 else if (in_array("step$step", $this->steps))
173 {
174 $this->_setUp();
175 $this->{"step$step"}();
176 $this->_setDown($step);
177 }
178 else
179 {
180 throw new Exception("step$step() does not exist in this module");
181 }
182 }
183
184 /**
185 * Prints out the footer part of the page, and the appropriate forwarding
186 * action button
187 *
188 * @param integer Step number
189 */
190 protected function _setDown($step)
191 {
192 // this is the last step, print the final button
193 if ($step == sizeof($this->steps))
194 {
195 echo '<div class="buttonlink">' . $this->_finalLink() . '</div>';
196 }
197 // just another step
198 else
199 {
200 echo '<div class="buttonlink"><a href="' . $this->fileName . '?step=' . ++$step . '">' . _('Next Step') . '</a></div>';
201 }
202
203 echo '
204 </body>
205
206 </html>';
207 }
208 }
209
210 ?>