0
|
1 |
<?php
|
|
2 |
/*
|
|
3 |
* Decir
|
|
4 |
* Version 0.1
|
|
5 |
* Copyright (C) 2007 Dan Fuhry
|
|
6 |
* install.php - Database installation wizard
|
|
7 |
*
|
|
8 |
* This program is Free Software; you can redistribute and/or modify it under the terms of the GNU General Public License
|
|
9 |
* as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.
|
|
10 |
*
|
|
11 |
* This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied
|
|
12 |
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for details.
|
|
13 |
*/
|
|
14 |
|
|
15 |
require('common.php');
|
|
16 |
|
|
17 |
if ( $session->auth_level < USER_LEVEL_ADMIN )
|
|
18 |
{
|
|
19 |
header('Location: ' . makeUrlComplete('Special', 'Login/' . $paths->page, 'level=9', true));
|
|
20 |
exit;
|
|
21 |
}
|
|
22 |
|
6
|
23 |
function install_decir()
|
|
24 |
{
|
|
25 |
global $db, $session, $paths, $template, $plugins; // Common objects
|
|
26 |
if ( $session->auth_level < USER_LEVEL_ADMIN )
|
|
27 |
die('Snotty son of a b**** you are being today...');
|
|
28 |
|
|
29 |
// Build an array of queries
|
|
30 |
$schema = @file_get_contents( DECIR_ROOT . '/install.sql' );
|
|
31 |
if ( !$schema )
|
|
32 |
{
|
|
33 |
echo '<pre>Decir installation error: can\'t load schema file</pre>';
|
|
34 |
return false;
|
|
35 |
}
|
|
36 |
|
|
37 |
// Variables
|
|
38 |
$schema = str_replace('{{TABLE_PREFIX}}', table_prefix, $schema);
|
|
39 |
|
|
40 |
$schema = explode("\n", $schema);
|
|
41 |
|
|
42 |
foreach ( $schema as $i => $sql )
|
|
43 |
{
|
|
44 |
$query =& $schema[$i];
|
|
45 |
$t = trim($query);
|
|
46 |
if ( empty($t) || preg_match('/^(\#|--)/i', $t) )
|
|
47 |
{
|
|
48 |
unset($schema[$i]);
|
|
49 |
unset($query);
|
|
50 |
}
|
|
51 |
}
|
|
52 |
|
|
53 |
$schema = array_values($schema);
|
|
54 |
$schema = implode("\n", $schema);
|
|
55 |
$schema = explode(";\n", $schema);
|
|
56 |
|
|
57 |
foreach ( $schema as $i => $sql )
|
|
58 |
{
|
|
59 |
$query =& $schema[$i];
|
|
60 |
if ( substr($query, ( strlen($query) - 1 ), 1 ) != ';' )
|
|
61 |
{
|
|
62 |
$query .= ';';
|
|
63 |
}
|
|
64 |
}
|
|
65 |
|
|
66 |
foreach ( $schema as $sql )
|
|
67 |
{
|
|
68 |
$q = $db->sql_query($sql);
|
|
69 |
if ( !$q )
|
|
70 |
{
|
|
71 |
echo '<pre>Decir installation failed: ' . $db->get_error() . '</pre>';
|
|
72 |
return false;
|
|
73 |
}
|
|
74 |
}
|
|
75 |
|
|
76 |
return true;
|
|
77 |
}
|
|
78 |
|
0
|
79 |
if ( $v = getConfig('decir_version') )
|
|
80 |
{
|
|
81 |
$mode = 'upgrade';
|
|
82 |
$upg_ver = $v;
|
|
83 |
}
|
|
84 |
else
|
|
85 |
{
|
|
86 |
$mode = 'install';
|
|
87 |
}
|
|
88 |
|
|
89 |
$page = ( isset($_POST['step']) && in_array($_POST['step'], array('welcome', 'install', 'finish')) ) ? $_POST['step'] : 'welcome';
|
|
90 |
|
6
|
91 |
if ( $page == 'finish' )
|
|
92 |
{
|
|
93 |
require('forum_index.php');
|
|
94 |
}
|
|
95 |
else
|
0
|
96 |
{
|
6
|
97 |
|
|
98 |
$template->header();
|
|
99 |
|
|
100 |
switch($page)
|
|
101 |
{
|
|
102 |
case 'welcome':
|
|
103 |
?>
|
|
104 |
<h3>Welcome to Decir, the Enano bulletin board suite.</h3>
|
|
105 |
<p>Before you can use your forum, we'll need to run a few database queries to get the forum set up.</p>
|
|
106 |
<form action="<?php echo makeUrl($paths->page); ?>" method="post">
|
|
107 |
<input type="hidden" name="step" value="install" />
|
|
108 |
<input type="submit" value="Continue" style="display: block; margin: 0 auto;" />
|
|
109 |
</form>
|
|
110 |
<?php
|
|
111 |
break;
|
|
112 |
case 'install':
|
|
113 |
$result = install_decir();
|
|
114 |
if ( $result ):
|
|
115 |
setConfig('decir_version', ENANO_DECIR_VERSION);
|
|
116 |
setConfig('decir_install_date', time());
|
|
117 |
?>
|
|
118 |
<p>Decir has been successfully installed.</p>
|
|
119 |
<form action="<?php echo makeUrl($paths->page); ?>" method="post">
|
|
120 |
<input type="hidden" name="step" value="finish" />
|
|
121 |
<input type="submit" name="do_install_finish" value="Next >" style="display: block; margin: 0 auto;" />
|
|
122 |
</form>
|
|
123 |
<?php
|
|
124 |
else:
|
|
125 |
echo 'ERROR: Decir installation failed.';
|
|
126 |
endif;
|
|
127 |
break;
|
|
128 |
}
|
|
129 |
|
|
130 |
$template->footer();
|
|
131 |
|
0
|
132 |
}
|
|
133 |
|