[go: up one dir, main page]

Menu

[r63]: / trunk / install.php  Maximize  Restore  History

Download this file

491 lines (459 with data), 23.7 kB

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
<?php
include_once('inc/util.inc');
echo '
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="'._('lang').'" lang="'._('lang').'">
<head>
<title>SAM: Simple Application Management</title>
<link rel="stylesheet" type="text/css" href="http://yui.yahooapis.com/2.8.0r4/build/reset/reset-min.css"/>
<link rel="stylesheet" type="text/css" href="themes/default/style.css"/>
<style>
body { text-align: center; }
#content { margin: 0 auto; width: 750px; text-align: left; }
h1 { font: bold 26px/160% Arial, Helvetica, sans-serif; padding: 0 0 30px 0; }
#install-progress { float: left; width: 200px; font: normal 20px/160% Arial, Helvetica, sans-serif; }
#install-progress ul li { border: 1px solid #ddd; background-color: #eee; padding: 10px; }
#install-progress ul li a { color: #000; font: 16px/100% Arial, Helvetica, sans-serif; }
#install-progress ul li.current { padding-left: 35px; background: #fff url(http://simpleappmanagement.com/themes/images/install-current.png) 10px 50% no-repeat; }
#install-progress ul li.finished { padding-left: 35px; background: #eee url(http://simpleappmanagement.com/themes/images/install-success.png) 10px 50% no-repeat; color: #ccc; }
#install { margin: 0 0 0 230px; }
#install .sub1 { float: right; }
.passed { background-color: #79b933; font-weight: bold; padding: 10px; }
.failed { background-color: #cd5a38; font-weight: bold; padding: 10px; }
#first { width: 180px; }
#last { width: 240px; }
</style>
<script type="text/javascript" src="inc/prototype.js"></script>
</head>
<body>
<div id="header" class="clearfix"><ul id="header-nav"><li>'._('SAM Installation').'</li></ul></div>
<div id="content">
<div id="content-wrapper">';
//----------------------------------------------------------------------------------------
// Progress through steps
//----------------------------------------------------------------------------------------
if (isset($_POST['step1'])) {
displayInstallCheck();
} else if (isset($_POST['step2'])) {
displayConfigDBSetup();
} else if (isset($_POST['step3'])) {
displaySiteConfigSetup();
} else if (isset($_POST['step4'])) {
displayModuleSetup();
} else {
// If config exists then the site is installed already
if (file_exists('inc/config.php')) {
echo '
<h1>'._('Installation Complete').'</h1>
<p>'._('SAM has already been installed, please delete the inc/config.php file if you wish to continue.').'</p>';
displayFooter();
exit();
// Else begin the installation process
} else {
displayStepOne();
}
}
//----------------------------------------------------------------------------------------
// Step One
//----------------------------------------------------------------------------------------
function displayStepOne () {
displayProgress(1);
echo '
<div id="install">
<h1>'._('Simple Application Management Installation').'</h1>
<p>'._('Thank you for choosing Simple Application Management.').'</p>
<p>'._('You will now be guided through a series of steps that will install your version of SAM.').'</p>
<p>'._('On each step, please fill out all required fields and click the \'Next\' button to proceed to the next step.').'</p>
<p>'._('Once all steps are complete, you can login and begin managing your open source project.').'</p>
<form action="install.php" method="post">
<div><input type="submit" class="sub1" name="step1" id="step1" value="'._('Next').'"/></div>
</form>
</div>';
}
//----------------------------------------------------------------------------------------
// Installation Check
//----------------------------------------------------------------------------------------
function displayInstallCheck () {
if (isWritable('inc/')) {
displayStepTwo();
} else {
displayProgress(1);
echo '
<div id="install">
<h1>'._('Installation Check').'</h1>
<div class="failed">'._('Failed').'</div>
<p>'._('The inc/ directory is not writable, either this directory is missing or you need to change the permissions before continuing.').'</p>
</div>';
}
}
//----------------------------------------------------------------------------------------
// Step Two
//----------------------------------------------------------------------------------------
function displayStepTwo ($error = false, $msg = '', $server = '', $username = '', $database = '') {
displayProgress(2);
echo '
<script type="text/javascript">
Event.observe(window, \'load\', function() { $(\'server\').focus(); });
</script>
<div id="install">
<h1>'._('Database').'</h1>';
if ($error) {
echo '
<div class="error-alert">'.$msg.'</div>';
}
echo '
<form action="install.php" method="post">
<p>
<label for="server">'._('Server').'</label><br/>
<input type="text" class="txt" name="server" id="server" value="'.$server.'"/>
</p>
<p>
<label for="username">'._('Username').'</label><br/>
<input type="text" class="txt" name="username" id="username" value="'.$username.'"/>
</p>
<p>
<label for="password">'._('Password').'</label><br/>
<input type="text" class="txt" name="password" id="password"/>
</p>
<p>
<label for="database">'._('Database').'</label><br/>
<input type="text" class="txt" name="database" id="database" value="'.$database.'"/>
</p>
<div><input type="submit" class="sub1" name="step2" id="step2" value="'._('Next').'"/></div>
</form>
</div>';
}
//----------------------------------------------------------------------------------------
// Config File and DB Setup
//----------------------------------------------------------------------------------------
function displayConfigDBSetup () {
if (
empty($_POST['server']) ||
empty($_POST['username']) ||
empty($_POST['password']) ||
empty($_POST['database'])
) {
// Missing req field
$msg = _('All fields are required.');
displayStepTwo(true, $msg, $_POST['server'], $_POST['username'], $_POST['database']);
} else {
// Try and create config
$file = @fopen('inc/config.php', 'w');
if (!$file) {
$msg = _('Could not create inc/config.php');
displayStepTwo(true, $msg, $_POST['server'], $_POST['username'], $_POST['database']);
return;
}
$str = "<?php \$db_server = '".$_POST['server']."'; \$db_database = '".$_POST['database']."'; \$db_username = '".$_POST['username']."'; \$db_password = '".$_POST['password']."'; ?".">";
fwrite($file, $str) or die("Could not write to inc/config.php");
fclose($file) or die("Could not close inc/config.php");
// Try to connect to DB
$connection = @mysql_connect($_POST['server'], $_POST['username'], $_POST['password']);
if (!$connection) {
// Bad Connection
unlink('inc/config.php') or print("Could not delete inc/config.php. Please manually delete this file and run the installation again.");
$msg = _('A connection to the database could not be made.');
displayStepTwo(true, $msg, $_POST['server'], $_POST['username'], $_POST['database']);
exit();
} else {
// Create Configuration Table
mysql_select_db($_POST['database']);
mysql_query("DROP TABLE IF EXISTS `sam_configuration`") or die(mysql_error());
$sql = "CREATE TABLE `sam_configuration` (
`sitename` VARCHAR(100) NOT NULL,
`contact` VARCHAR(100) NOT NULL,
`theme` VARCHAR(50) NOT NULL DEFAULT 'default',
`repo` VARCHAR(255) NOT NULL,
`projects` VARCHAR(50) NOT NULL DEFAULT 'Projects',
`components` VARCHAR(50) NOT NULL DEFAULT 'Components',
`use_type` TINYINT(1) NOT NULL DEFAULT '1',
`use_priority` TINYINT(1) NOT NULL DEFAULT '1',
`use_project` TINYINT(1) NOT NULL DEFAULT '1',
`use_component` TINYINT(1) NOT NULL DEFAULT '1',
`use_start` TINYINT(1) NOT NULL DEFAULT '1',
`use_due` TINYINT(1) NOT NULL DEFAULT '1',
`use_discovered` TINYINT(1) NOT NULL DEFAULT '1',
`use_target` TINYINT(1) NOT NULL DEFAULT '1',
`use_fixed` TINYINT(1) NOT NULL DEFAULT '1',
`use_progress` TINYINT(1) NOT NULL DEFAULT '1',
`use_est_hours` TINYINT(1) NOT NULL DEFAULT '1',
`use_dev_hours` TINYINT(1) NOT NULL DEFAULT '1',
`use_tested` TINYINT(1) NOT NULL DEFAULT '1'
) DEFAULT CHARSET=utf8";
mysql_query($sql) or die('ERROR ' . __FILE__ . ' [' . __LINE__ . ']<br/><br/>' . mysql_error() . "<br/><br/>$sql");
displayStepThree();
}
}
}
//----------------------------------------------------------------------------------------
// Step Three
//----------------------------------------------------------------------------------------
function displayStepThree ($error = false, $msg = '', $sitename = '', $username = '', $first = '', $last = '', $email = '') {
displayProgress(3);
echo '
<script type="text/javascript">
Event.observe(window, \'load\', function() { $(\'sitename\').focus(); });
</script>
<div id="install">
<h1>'._('Configuration').'</h1>';
if ($error) {
echo '
<div class="error-alert">'.$msg.'</div>';
}
echo '
<form action="install.php" method="post">
<p>
<label for="sitename">'._('Site Name').'</label><br/>
<input type="text" class="txt" name="sitename" id="sitename" value="'.$sitename.'"/>
</p>
<p>
<label for="username">'._('Admin Username').'</label><br/>
<input type="text" class="txt" name="username" id="username" value="'.$username.'"/>
</p>
<p>
<label for="password">'._('Admin Password').'</label><br/>
<input type="text" class="txt" name="password" id="password"/>
</p>
<p>
<label for="first">'._('Admin Name (first, last)').'</label><br/>
<input type="text" class="txt" name="first" id="first" value="'.$first.'"/>
<input type="text" class="txt" name="last" id="last" value="'.$last.'"/>
</p>
<p>
<label for="email">'._('Admin Email').'</label><br/>
<input type="text" class="txt" name="email" id="email" value="'.$email.'"/>
</p>
<div><input type="submit" class="sub1" name="step3" id="step3" value="'._('Next').'"/></div>
</form>
</div>';
}
//----------------------------------------------------------------------------------------
// Site Config Setup
//----------------------------------------------------------------------------------------
function displaySiteConfigSetup () {
include_once('inc/config.php');
$connection = @mysql_connect($db_server, $db_username, $db_password);
mysql_select_db($db_database);
if (
empty($_POST['sitename']) ||
empty($_POST['username']) ||
empty($_POST['password']) ||
empty($_POST['first']) ||
empty($_POST['last']) ||
empty($_POST['email'])
) {
// Missing req field
$msg = _('All fields are required.');
displayStepThree(true, $msg, $_POST['sitename'], $_POST['username'], $_POST['password'], $_POST['first'], $_POST['last'], $_POST['email']);
} else {
// Create User Table
mysql_query("DROP TABLE IF EXISTS `sam_user`") or die(mysql_error());
$sql = "CREATE TABLE `sam_user` (
`id` INT(11) PRIMARY KEY AUTO_INCREMENT,
`username` VARCHAR(20) NOT NULL,
`first` VARCHAR(50) NOT NULL,
`last` VARCHAR(50) NOT NULL,
`password` VARCHAR(255) NOT NULL DEFAULT '0',
`email` VARCHAR(100) NOT NULL,
`admin` TINYINT(1) NOT NULL DEFAULT '0',
`joindate` DATETIME NOT NULL DEFAULT '0000-00-00 00:00:00'
)";
mysql_query($sql) or die('ERROR ' . __FILE__ . ' [' . __LINE__ . ']<br/><br/>' . mysql_error() . "<br/><br/>$sql");
// Escape input
$sitename = stripMagicQuotes($_POST['sitename']);
$sitename = escape_string($sitename);
$username = stripMagicQuotes($_POST['username']);
$username = escape_string($username);
$first = stripMagicQuotes($_POST['first']);
$first = escape_string($first);
$last = stripMagicQuotes($_POST['last']);
$last = escape_string($last);
$password = md5($_POST['password']);
$email = stripMagicQuotes($_POST['email']);
$email = escape_string($email);
$sql = "INSERT INTO `sam_configuration` (`sitename`, `contact`)
VALUES ('$sitename', '$email')";
mysql_query($sql) or die('ERROR ' . __FILE__ . ' [' . __LINE__ . ']<br/><br/>' . mysql_error() . "<br/><br/>$sql");
$sql = "INSERT INTO `sam_user` (`username`, `first`, `last`, `password`, `email`, `admin`, `joindate`)
VALUES ('$username', '$first', '$last', '$password', '$email', 1, NOW())";
mysql_query($sql) or die('ERROR ' . __FILE__ . ' [' . __LINE__ . ']<br/><br/>' . mysql_error() . "<br/><br/>$sql");
// Setup the rest of the tables
setupTables();
displayStepFour();
}
}
//----------------------------------------------------------------------------------------
// Step Four
//----------------------------------------------------------------------------------------
function displayStepFour ($error = false, $msg = '') {
displayProgress(4);
echo '
<script type="text/javascript">
Event.observe(window, \'load\', function() { $(\'sitename\').focus(); });
</script>
<div id="install">
<h1>'._('Module Setup').'</h1>';
if ($error) {
echo '
<div class="error-alert">'.$msg.'</div>';
}
echo '
<form action="install.php" method="post">
<p>
'._('Choose the Modules you would like to use. These can be changed/configured after installation also.').'
</p>
<p>
<input type="checkbox" class="chk" name="tracker" id="tracker" checked="checked" value="tracker"/>
<label for="tracker">'._('Tracker').'</label><br/>
<input type="checkbox" class="chk" name="progress" id="progress" value="progress"/>
<label for="progress">'._('Progress').'</label><br/>
<input type="checkbox" class="chk" name="code" id="code" value="code"/>
<label for="code">'._('Source Code').'</label><br/>
<input type="checkbox" class="chk" name="ideas" id="ideas" value="ideas"/>
<label for="ideas">'._('Idea Management').'</label><br/>
<input type="checkbox" class="chk" name="blog" id="blog" value="blog"/>
<label for="blog">'._('Blog').'</label><br/>
</p>
<div><input type="submit" class="sub1" name="step4" id="step4" value="'._('Next').'"/></div>
</form>
</div>';
}
//----------------------------------------------------------------------------------------
// Module Setup
//----------------------------------------------------------------------------------------
function displayModuleSetup () {
include_once('inc/config.php');
$connection = @mysql_connect($db_server, $db_username, $db_password);
mysql_select_db($db_database);
if (count($_POST) <= 1) {
$msg = _('You must choose at least one module.');
displayStepFour(true, $msg);
} else {
// Setup modules
$order = 1;
if (isset($_POST['tracker'])) {
$sql = "INSERT INTO `sam_module` (`type`, `order`)
VALUES ('tracker', '$order')";
mysql_query($sql) or die('ERROR ' . __FILE__ . ' [' . __LINE__ . ']<br/><br/>' . mysql_error() . "<br/><br/>$sql");
$order++;
include('install/tracker.php');
}
if (isset($_POST['progress'])) {
$sql = "INSERT INTO `sam_module` (`type`, `order`)
VALUES ('progress', '$order')";
mysql_query($sql) or die('ERROR ' . __FILE__ . ' [' . __LINE__ . ']<br/><br/>' . mysql_error() . "<br/><br/>$sql");
$order++;
}
if (isset($_POST['code'])) {
$sql = "INSERT INTO `sam_module` (`type`, `order`)
VALUES ('code', '$order')";
mysql_query($sql) or die('ERROR ' . __FILE__ . ' [' . __LINE__ . ']<br/><br/>' . mysql_error() . "<br/><br/>$sql");
$order++;
}
if (isset($_POST['ideas'])) {
$sql = "INSERT INTO `sam_module` (`type`, `order`)
VALUES ('ideas', '$order')";
mysql_query($sql) or die('ERROR ' . __FILE__ . ' [' . __LINE__ . ']<br/><br/>' . mysql_error() . "<br/><br/>$sql");
$order++;
include('install/ideas.php');
}
if (isset($_POST['blog'])) {
$sql = "INSERT INTO `sam_module` (`type`, `order`)
VALUES ('blog', '$order')";
mysql_query($sql) or die('ERROR ' . __FILE__ . ' [' . __LINE__ . ']<br/><br/>' . mysql_error() . "<br/><br/>$sql");
$order++;
include('install/blog.php');
}
// Installation complete
displayProgress(5);
echo '
<div id="install">
<h1>'._('Installation Complete').'</h1>
<p>'._('Simple Application Management has been installed.').'</p>
<p><a href="index.php">'._('View Website').'</a></p>
</div>';
}
}
//----------------------------------------------------------------------------------------
// Progress
//----------------------------------------------------------------------------------------
function displayProgress ($sel) {
$start = '';
if ($sel > 1) {
$start = '<a href="install.php">'._('Start Over').'</a>';
}
echo '
<div id="install-progress" class="clearfix">
<ul class="clearfix">
<li class="'; if ($sel == 1) echo 'current'; if (1 < $sel) echo 'finished'; echo '"><div>'._('Step 1').'</div>'.$start.'</li>
<li class="'; if ($sel == 2) echo 'current'; if (2 < $sel) echo 'finished'; echo '"><div>'._('Step 2').'</div></li>
<li class="'; if ($sel == 3) echo 'current'; if (3 < $sel) echo 'finished'; echo '"><div>'._('Step 3').'</div></li>
<li class="'; if ($sel == 4) echo 'current'; if (4 < $sel) echo 'finished'; echo '"><div>'._('Step 4').'</div></li>
<li class="'; if ($sel == 5) echo 'current'; if (5 < $sel) echo 'finished'; echo '"><div>'._('Step 5').'</div></li>
</ul>
</div>';
}
//----------------------------------------------------------------------------------------
// Footer
//----------------------------------------------------------------------------------------
function displayFooter () {
echo '
<div id="footer">
'.sprintf(_('Powered by %s'), '<a href="http://www.simpleappmanagement.com/">SAM</a>').'
</div>
</div><! /#content-wrapper >
</div><! /#content >
</div><! /#wrapper >
</body>
</html>';
}
//----------------------------------------------------------------------------------------
// Setup Tables
//----------------------------------------------------------------------------------------
function setupTables () {
// Drop existing tables
mysql_query("DROP TABLE IF EXISTS `sam_category`") or die(mysql_error());
mysql_query("DROP TABLE IF EXISTS `sam_comment`") or die(mysql_error());
mysql_query("DROP TABLE IF EXISTS `sam_module`") or die(mysql_error());
mysql_query("DROP TABLE IF EXISTS `sam_module_type`") or die(mysql_error());
mysql_query("DROP TABLE IF EXISTS `sam_layout`") or die(mysql_error());
// Create Category Table
$sql = "CREATE TABLE `sam_category` (
`id` INT(11) PRIMARY KEY AUTO_INCREMENT,
`name` VARCHAR(100) NOT NULL,
`type` VARCHAR(10) NOT NULL,
`parent` INT(11) NOT NULL DEFAULT '0',
`date` DATETIME NOT NULL DEFAULT '0000-00-00 00:00:00'
) DEFAULT CHARSET=utf8";
mysql_query($sql) or die('ERROR ' . __FILE__ . ' [' . __LINE__ . ']<br/><br/>' . mysql_error() . "<br/><br/>$sql");
// Create Comment Table
$sql = "CREATE TABLE `sam_comment` (
`id` INT(11) PRIMARY KEY AUTO_INCREMENT,
`type` VARCHAR(10) NOT NULL,
`type_id` INT(11) NOT NULL DEFAULT '0',
`user` INT(11) NOT NULL DEFAULT '0',
`comment` TEXT,
`date` DATETIME NOT NULL DEFAULT '0000-00-00 00:00:00'
) DEFAULT CHARSET=utf8";
mysql_query($sql) or die('ERROR ' . __FILE__ . ' [' . __LINE__ . ']<br/><br/>' . mysql_error() . "<br/><br/>$sql");
// Create Module Table
$sql = "CREATE TABLE `sam_module` (
`id` INT(11) PRIMARY KEY AUTO_INCREMENT,
`type` VARCHAR(20) NOT NULL,
`order` TINYINT(1) NOT NULL
) DEFAULT CHARSET=utf8";
mysql_query($sql) or die('ERROR ' . __FILE__ . ' [' . __LINE__ . ']<br/><br/>' . mysql_error() . "<br/><br/>$sql");
// Create Layout Table
$sql = "CREATE TABLE `sam_layout` (
`id` INT(11) PRIMARY KEY AUTO_INCREMENT,
`type` VARCHAR(20) NOT NULL,
`row` TINYINT(2) NOT NULL,
`position` TINYINT(1) NOT NULL,
`data` TEXT
) DEFAULT CHARSET=utf8";
mysql_query($sql) or die('ERROR ' . __FILE__ . ' [' . __LINE__ . ']<br/><br/>' . mysql_error() . "<br/><br/>$sql");
$sql = "INSERT INTO `sam_layout` (`type`, `row`, `position`, `data`)
VALUES ('text', 1, 3, 'Welcome to SAM, check out the Widgets page of the Administration section to edit what is displayed here.')";
mysql_query($sql) or die('ERROR ' . __FILE__ . ' [' . __LINE__ . ']<br/><br/>' . mysql_error() . "<br/><br/>$sql");
}
displayFooter();