Switch the 'modify' code of admin/field.php to use templates
[bugdar.git] / install / install.php
1 <?php
2 /*=====================================================================*\
3 || ###################################################################
4 || # Bugdar
5 || # Copyright (c)2004-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 define('STOP_MARK', 8);
23 define('ACTIVE_SITE', 'install.php');
24
25 // the collation used for installation
26 $COLLATION = 'utf8_general_ci';
27
28 require_once('./global.php');
29
30 page_start();
31
32 // ###################################################################
33
34 if ($input->in['mark'] == 0)
35 {
36 ?>
37 <h1>Welcome to Bugdar</h1>
38
39 <p>This installer will take you through the procedure of setting up your Bugdar installation. If you are seeing this message, that means that your configuration file was read properly and that your database is accessible.</p>
40
41 <p>The following steps will initialize your database, place the default settings and data in your database, and finally ask you to enter in some settings to allow you to access the system when the installer finishes.</p>
42
43 <p>To begin the installation process, please click the button below.</p>
44 <?php
45 }
46
47 // ###################################################################
48
49 if ($input->in['mark'] == 1)
50 {
51 ?>
52 <h1>Installation Check</h1>
53
54 <style type="text/css" media="screen">
55 <!--
56 .fail
57 {
58 font-weight: bold;
59 color: rgb(255, 0, 0);
60 }
61 .pass
62 {
63 color: rgb(0, 150, 0);
64 }
65 //-->
66 </style>
67
68 <p>This step will ensure that Bugdar can install and run properly. In all of these tests, <span class="pass">green means the test succeeded</span> and <span class="fail">red means it didn't</span>.</p>
69
70 <strong>MySQL Privileges:</strong>
71 <ul>
72 <?php
73
74 $db->showerrors = false;
75
76 $pf = $tests[] = ($db->query("CREATE TABLE install_check (col1 VARCHAR(255) NULL);") ? 'pass' : 'fail');
77 echo "\n\t<li class=\"$pf\">CREATE TABLE</li>";
78
79 $pf = $tests[] = ($db->query("INSERT INTO install_check (col1) VALUES ('example')") ? 'pass' : 'fail');
80 echo "\n\t<li class=\"$pf\">INSERT</li>";
81
82 $pf = $tests[] = ($db->query("UPDATE install_check SET col1 = 'example2'") ? 'pass' : 'fail');
83 echo "\n\t<li class=\"$pf\">UPDATE</li>";
84
85 $pf = $tests[] = ($db->query("SELECT * FROM install_check") ? 'pass' : 'fail');
86 echo "\n\t<li class=\"$pf\">SELECT</li>";
87
88 $pf = $tests[] = ($db->query("DELETE FROM install_check WHERE col1 = 'example2'") ? 'pass' : 'fail');
89 echo "\n\t<li class=\"$pf\">DELETE</li>";
90
91 $pf = $tests[] = ($db->query("ALTER TABLE install_check ADD col3 BOOL") ? 'pass' : 'fail');
92 echo "\n\t<li class=\"$pf\">ALTER</li>";
93
94 $pf = $tests[] = ($db->query("ALTER TABLE install_check ADD INDEX (col1)") ? 'pass' : 'fail');
95 echo "\n\t<li class=\"$pf\">ALTER ADD INDEX</li>";
96
97 $pf = $tests[] = ($db->query("REPLACE INTO install_check (col1) VALUES ('example3')") ? 'pass' : 'fail');
98 echo "\n\t<li class=\"$pf\">REPLACE</li>";
99
100 $pf = $tests[] = ($db->query("OPTIMIZE TABLE install_check") ? 'pass' : 'fail');
101 echo "\n\t<li class=\"$pf\">OPTIMIZE</li>";
102
103 $pf = $tests[] = ($db->query("DROP TABLE install_check") ? 'pass' : 'fail');
104 echo "\n\t<li class=\"$pf\">DROP TABLE</li>";
105
106 echo "\n</ul>";
107
108 $valcount = array_count_values($tests);
109 if ($valcount['fail'] > 0)
110 {
111 echo "<p>Please adjust your MySQL setup and refresh this page to ensure that Bugdar can operate properly. If you do not do so, Bugdar cannot be installed.</p>";
112 page_end(false);
113 }
114 }
115
116 // ###################################################################
117
118 if ($input->in['mark'] == 2)
119 {
120 ?>
121 <h1>Initializing Database</h1>
122
123 <p>This step will load the tables into your database so the rest of the installation can proceed forward.</p>
124
125 <?php
126
127 require './includes/config.php';
128 $db->query("ALTER DATABASE $database COLLATE $COLLATION");
129
130 require_once('./install/schema.php');
131
132 foreach ($schema AS $table => $query)
133 {
134 $db->query($query);
135 echo 'Creating table ' . $table . '<br />' . "\n";
136 }
137 }
138
139 // ###################################################################
140
141 if ($input->in['mark'] == 3)
142 {
143 ?>
144 <h1>Loading Default Data</h1>
145
146 <p>Default table data for usergroups, statuses, priorities, and other various options are being loaded. This will allow you to use Bugdar with minimal setup.</p>
147
148 <?php
149
150 require_once('./install/default_data.php');
151
152 foreach ($data AS $table => $records)
153 {
154 foreach ($records AS $record)
155 {
156 $fields = $values = array();
157 foreach ($record AS $field => $value)
158 {
159 $fields[] = $field;
160 $values[] = addslashes($value);
161 }
162
163 $db->query("INSERT INTO " . TABLE_PREFIX . "$table (" . implode(',', $fields) . ") VALUES ('" . implode("', '", $values) . "')");
164 }
165
166 echo 'Populating table ' . $table . '<br />' . "\n";
167 }
168
169 $db->query("INSERT INTO " . TABLE_PREFIX . "language (title, langcode, charset, direction, userselect) VALUES ('English (US)', 'en_US', 'utf-8', 'ltr', 1)");
170 echo 'Inserting default language<br />' . "\n";
171 }
172
173 // ###################################################################
174
175 if ($input->in['mark'] == 4)
176 {
177 ?>
178 <h1>Loading Settings</h1>
179
180 <p>Default settings are being loaded into the system.</p>
181
182 <?php
183
184 require_once('./install/settings.php');
185
186 foreach ($settings AS $key => $value)
187 {
188 $db->query("INSERT INTO " . TABLE_PREFIX . "setting (varname, value) VALUES ('" . $key . "', '" . $db->escape_string($value) . "')");
189 }
190
191 echo 'Settings loaded...';
192 }
193
194
195 // ###################################################################
196
197 if ($input->in['mark'] == 5)
198 {
199 ?>
200 <h1>Cache Data</h1>
201
202 <p>In order to make Bugdar as efficient as possible, the system caches the portions of data it can. This reduces the load of your server without compromising usability. Currently the caches are being built.</p>
203 <?php
204
205 require_once('./includes/permissions.php');
206
207 build_settings();
208 echo "Cached settings<br />\n";
209
210 build_usergroups();
211 echo "Cached usergroups<br />\n";
212
213 build_statuses();
214 echo "Cached statuses<br />\n";
215
216 build_priorities();
217 echo "Cached priorities<br />\n";
218
219 build_severities();
220 echo "Cached severities<br />\n";
221
222 build_assignedto();
223 echo "Cached assignable users/developers<br />\n";
224
225 build_resolutions();
226 echo "Cached resolutions<br />\n";
227
228 build_products();
229 echo "Cached products<br />\n";
230
231 build_versions();
232 echo "Cached versions<br />\n";
233
234 build_languages();
235 echo "Cached languages<br />\n";
236
237 build_user_help();
238 echo "Cached user help documentation<br />\n";
239 }
240
241 // ###################################################################
242
243 if ($input->in['mark'] == 6)
244 {
245 $value = 'http' . ($_SERVER['HTTPS'] == 'on' ? 's' : '') . '://' . $_SERVER['SERVER_NAME'] . ($_SERVER['SERVER_PORT'] != '80' ? ':' . $_SERVER['SERVER_PORT'] : '') . str_replace('/install/install.php', '', $_SERVER['SCRIPT_NAME']);
246 ?>
247 <h1>General Settings</h1>
248
249 <p>These three settings are fundamental in setting up your bug tracking system. Please fill them in to proceed with the installation.</p>
250
251 <form name="settings-do" action="install.php" method="post">
252 <input type="hidden" name="mark" value="7" />
253
254 <div><strong>Tracker Name (the name of the entire tracking system, for instance "Acme Inc. Bug Tracker"):</strong> <input type="text" name="trackertitle" size="50" /></div>
255 <div><strong>Tracker URL (the root URL of your tracker, we have tried to guess this for you; <em>it does not end with a trailing slash!</em>):</strong> <input type="text" name="trackerurl" size="50" value="<?php echo $value; ?>" /></div>
256 <div><strong>Webmaster Email:</strong> <input type="text" name="webmasteremail" size="50" /></div>
257
258 <input type="submit" name="submit" value="Next Step" />
259
260 </form>
261
262 <?php
263
264 page_end(false);
265 }
266
267 // ###################################################################
268
269 if ($input->in['mark'] == 7)
270 {
271 ?>
272 <h1>New Administrator</h1>
273
274 <p>Your settings have been saved. Now you must create a new administrative account for yourself. This account will have complete control over the system.</p>
275
276 <form name="user-do" action="install.php" method="post">
277 <input type="hidden" name="mark" value="8" />
278
279 <div><strong>Display Name:</strong> <input type="text" name="displayname" size="50" /></div>
280 <div><strong>Email Address:</strong> <input type="text" name="email" size="50" /></div>
281 <div><strong>Password:</strong> <input type="password" name="password" size="50" /></div>
282
283 <input type="submit" name="submit" value="Next Step" />
284 </form>
285
286 <?php
287
288 $db->query("UPDATE " . TABLE_PREFIX . "setting SET value = '" . $bugsys->input_escape('trackertitle') . "' WHERE varname = 'trackertitle'");
289 $db->query("UPDATE " . TABLE_PREFIX . "setting SET value = '" . $bugsys->input_escape('trackerurl') . "' WHERE varname = 'trackerurl'");
290 $db->query("UPDATE " . TABLE_PREFIX . "setting SET value = '" . $bugsys->input_escape('webmasteremail') . "' WHERE varname = 'webmasteremail'");
291
292 build_settings();
293
294 page_end(false);
295 }
296
297 // ###################################################################
298
299 if ($input->in['mark'] == 8)
300 {
301 ?>
302 <h1>User Added</h1>
303
304 <p>Your new user has been added.</p>
305 <?php
306
307 require_once('./includes/api_user.php');
308
309 // we need to do this here because build_assignedto() uses this data and we don't have it loaded in
310 // the installer, so we need to do it manually
311 build_usergroups();
312
313 $user = new UserAPI();
314 $user->set('email', $input->in['email']);
315 $user->set('displayname', $input->in['displayname']);
316 $user->set('password', $input->in['password']);
317 $user->set('showcolors', 1);
318 $user->set('usergroupid', 6, true, false); // don't verify because we haven't cached usergroups yet
319 $user->insert();
320 }
321
322 // ###################################################################
323
324 page_end();
325
326 ?>