1<?php
2/**
3 * Installation script.
4 *
5 * Used to actually install PunBB.
6 *
7 * @copyright (C) 2008-2012 PunBB, partially based on code (C) 2008-2009 FluxBB.org
8 * @license http://www.gnu.org/licenses/gpl.html GPL version 2 or higher
9 * @package PunBB
10 */
11
12
13define('MIN_PHP_VERSION', '5.4.0');
14define('MIN_MYSQL_VERSION', '4.1.2');
15
16define('FORUM_ROOT', '../');
17define('FORUM', 1);
18define('FORUM_DEBUG', 1);
19
20if (file_exists(FORUM_ROOT.'config.php'))
21	exit('The file \'config.php\' already exists which would mean that PunBB is already installed. You should go <a href="'.FORUM_ROOT.'index.php">here</a> instead.');
22
23
24// Make sure we are running at least MIN_PHP_VERSION
25if (!function_exists('version_compare') || version_compare(PHP_VERSION, MIN_PHP_VERSION, '<'))
26	exit('You are running PHP version '.PHP_VERSION.'. PunBB requires at least PHP '.MIN_PHP_VERSION.' to run properly. You must upgrade your PHP installation before you can continue.');
27
28// Disable error reporting for uninitialized variables
29error_reporting(E_ALL);
30
31// Turn off PHP time limit
32@set_time_limit(0);
33
34require FORUM_ROOT.'include/constants.php';
35// We need some stuff from functions.php
36require FORUM_ROOT.'include/functions.php';
37
38// Load UTF-8 functions
39require FORUM_ROOT.'include/utf8/utf8.php';
40require FORUM_ROOT.'include/utf8/ucwords.php';
41require FORUM_ROOT.'include/utf8/trim.php';
42
43// Strip out "bad" UTF-8 characters
44forum_remove_bad_characters();
45
46//
47// Generate output to be used for config.php
48//
49function generate_config_file()
50{
51	global $db_type, $db_host, $db_name, $db_username, $db_password, $db_prefix, $base_url, $cookie_name;
52
53	$config_body = '<?php'."\n\n".'$db_type = \''.$db_type."';\n".'$db_host = \''.$db_host."';\n".'$db_name = \''.addslashes($db_name)."';\n".'$db_username = \''.addslashes($db_username)."';\n".'$db_password = \''.addslashes($db_password)."';\n".'$db_prefix = \''.addslashes($db_prefix)."';\n".'$p_connect = false;'."\n\n".'$base_url = \''.$base_url.'\';'."\n\n".'$cookie_name = '."'".$cookie_name."';\n".'$cookie_domain = '."'';\n".'$cookie_path = '."'/';\n".'$cookie_secure = 0;'."\n\ndefine('FORUM', 1);";
54
55	// Add forum options
56	$config_body .= "\n\n// Enable DEBUG mode by removing // from the following line\n//define('FORUM_DEBUG', 1);";
57	$config_body .= "\n\n// Enable show DB Queries mode by removing // from the following line\n//define('FORUM_SHOW_QUERIES', 1);";
58	$config_body .= "\n\n// Enable forum IDNA support by removing // from the following line\n//define('FORUM_ENABLE_IDNA', 1);";
59	$config_body .= "\n\n// Disable forum CSRF checking by removing // from the following line\n//define('FORUM_DISABLE_CSRF_CONFIRM', 1);";
60	$config_body .= "\n\n// Disable forum hooks (extensions) by removing // from the following line\n//define('FORUM_DISABLE_HOOKS', 1);";
61	$config_body .= "\n\n// Disable forum output buffering by removing // from the following line\n//define('FORUM_DISABLE_BUFFERING', 1);";
62	$config_body .= "\n\n// Disable forum async JS loader by removing // from the following line\n//define('FORUM_DISABLE_ASYNC_JS_LOADER', 1);";
63	$config_body .= "\n\n// Disable forum extensions version check by removing // from the following line\n//define('FORUM_DISABLE_EXTENSIONS_VERSION_CHECK', 1);";
64
65	return $config_body;
66}
67
68$language = isset($_GET['lang']) ? $_GET['lang'] : (isset($_POST['req_language']) ? forum_trim($_POST['req_language']) : 'English');
69$language = preg_replace('#[\.\\\/]#', '', $language);
70if (!file_exists(FORUM_ROOT.'lang/'.$language.'/install.php'))
71	exit('The language pack you have chosen doesn\'t seem to exist or is corrupt. Please recheck and try again.');
72
73// Load the language files
74require FORUM_ROOT.'lang/'.$language.'/install.php';
75require FORUM_ROOT.'lang/'.$language.'/admin_settings.php';
76
77if (isset($_POST['generate_config']))
78{
79	header('Content-Type: text/x-delimtext; name="config.php"');
80	header('Content-disposition: attachment; filename=config.php');
81
82	$db_type = $_POST['db_type'];
83	$db_host = $_POST['db_host'];
84	$db_name = $_POST['db_name'];
85	$db_username = $_POST['db_username'];
86	$db_password = $_POST['db_password'];
87	$db_prefix = $_POST['db_prefix'];
88	$base_url = $_POST['base_url'];
89	$cookie_name = $_POST['cookie_name'];
90
91	echo generate_config_file();
92	exit;
93}
94
95header('Content-Type: text/html; charset=utf-8');
96header('Cache-Control: cache-control: no-store', false);
97
98if (!isset($_POST['form_sent']))
99{
100	// Determine available database extensions
101	$db_extensions = array();
102
103	if (function_exists('mysqli_connect'))
104	{
105		$db_extensions[] = array('mysqli', 'MySQL Improved');
106		$db_extensions[] = array('mysqli_innodb', 'MySQL Improved (InnoDB)');
107	}
108
109	if (function_exists('mysql_connect'))
110	{
111		$db_extensions[] = array('mysql', 'MySQL Standard');
112		$db_extensions[] = array('mysql_innodb', 'MySQL Standard (InnoDB)');
113	}
114
115	if (function_exists('sqlite_open'))
116		$db_extensions[] = array('sqlite', 'SQLite');
117
118	if (class_exists('SQLite3'))
119		$db_extensions[] = array('sqlite3', 'SQLite3');
120
121	if (function_exists('pg_connect'))
122		$db_extensions[] = array('pgsql', 'PostgreSQL');
123
124	if (empty($db_extensions))
125		error($lang_install['No database support']);
126
127	// Make an educated guess regarding base_url
128	$base_url_guess = ((isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on') ? 'https://' : 'http://').preg_replace('/:80$/', '', $_SERVER['HTTP_HOST']).substr(str_replace('\\', '/', dirname($_SERVER['SCRIPT_NAME'])), 0, -6);
129	if (substr($base_url_guess, -1) == '/')
130		$base_url_guess = substr($base_url_guess, 0, -1);
131
132	// Check for available language packs
133	$languages = get_language_packs();
134
135?>
136<!DOCTYPE html>
137<!--[if lt IE 7 ]> <html class="oldie ie6" lang="en" dir="ltr"> <![endif]-->
138<!--[if IE 7 ]>    <html class="oldie ie7" lang="en" dir="ltr"> <![endif]-->
139<!--[if IE 8 ]>    <html class="oldie ie8" lang="en" dir="ltr"> <![endif]-->
140<!--[if gt IE 8]><!--> <html lang="en" dir="ltr"> <!--<![endif]-->
141<head>
142	<meta charset="utf-8" />
143	<title>PunBB Installation</title>
144	<link rel="stylesheet" type="text/css" href="<?php echo FORUM_ROOT ?>style/Oxygen/Oxygen.min.css" />
145</head>
146<body>
147<div id="brd-install" class="brd-page">
148<div id="brd-wrap" class="brd">
149
150<div id="brd-head" class="gen-content">
151	<p id="brd-title"><strong><?php printf($lang_install['Install PunBB'], FORUM_VERSION) ?></strong></p>
152	<p id="brd-desc"><?php echo $lang_install['Install intro'] ?></p>
153</div>
154
155<div id="brd-main" class="main">
156
157	<div class="main-head">
158		<h1 class="hn"><span><?php printf($lang_install['Install PunBB'], FORUM_VERSION) ?></span></h1>
159	</div>
160
161<?php
162
163	if (count($languages) > 1)
164	{
165
166?>	<form class="frm-form" method="get" accept-charset="utf-8" action="install.php">
167	<div class="main-subhead">
168		<h2 class="hn"><span><?php echo $lang_install['Choose language'] ?></span></h2>
169	</div>
170	<div class="main-content main-frm">
171		<fieldset class="frm-group group1">
172			<legend class="group-legend"><strong><?php echo $lang_install['Choose language legend'] ?></strong></legend>
173			<div class="sf-set set1">
174				<div class="sf-box text">
175					<label for="fld0"><span><?php echo $lang_install['Installer language'] ?></span> <small><?php echo $lang_install['Choose language help'] ?></small></label><br />
176					<span class="fld-input"><select id="fld0" name="lang">
177<?php
178
179		foreach ($languages as $lang)
180			echo "\t\t\t\t\t".'<option value="'.$lang.'"'.($language == $lang ? ' selected="selected"' : '').'>'.$lang.'</option>'."\n";
181
182?>					</select></span>
183				</div>
184			</div>
185		</fieldset>
186		<div class="frm-buttons">
187			<span class="submit primary"><input type="submit" name="changelang" value="<?php echo $lang_install['Choose language'] ?>" /></span>
188		</div>
189	</div>
190	</form>
191<?php
192
193	}
194
195?>	<form class="frm-form frm-suggest-username" method="post" accept-charset="utf-8" action="install.php">
196	<div class="hidden">
197		<input type="hidden" name="form_sent" value="1" />
198	</div>
199	<div class="main-subhead">
200		<h2 class="hn"><span><?php echo $lang_install['Part1'] ?></span></h2>
201	</div>
202	<div class="main-content main-frm">
203		<div class="ct-box info-box">
204			<p><?php echo $lang_install['Part1 intro'] ?></p>
205			<ul class="spaced list-clean">
206				<li><span><strong><?php echo $lang_install['Database type'] ?></strong> <?php echo $lang_install['Database type info']; if (count($db_extensions) > 1) echo ' '.$lang_install['Mysql type info'] ?></span></li>
207				<li><span><strong><?php echo $lang_install['Database server'] ?></strong> <?php echo $lang_install['Database server info'] ?></span></li>
208				<li><span><strong><?php echo $lang_install['Database name'] ?></strong> <?php echo $lang_install['Database name info'] ?></span></li>
209				<li><span><strong><?php echo $lang_install['Database user pass'] ?></strong> <?php echo $lang_install['Database username info'] ?></span></li>
210				<li><span><strong><?php echo $lang_install['Table prefix'] ?></strong> <?php echo $lang_install['Table prefix info'] ?></span></li>
211			</ul>
212		</div>
213		<div id="req-msg" class="req-warn ct-box error-box">
214			<p class="important"><?php echo $lang_install['Required warn'] ?></p>
215		</div>
216		<fieldset class="frm-group group1">
217			<legend class="group-legend"><strong><?php echo $lang_install['Part1 legend'] ?></strong></legend>
218			<div class="sf-set set1">
219				<div class="sf-box select required">
220					<label for="req_db_type"><span><?php echo $lang_install['Database type'] ?></span> <small><?php echo $lang_install['Database type help'] ?></small></label><br />
221					<span class="fld-input"><select id="req_db_type" name="req_db_type">
222<?php
223
224	foreach ($db_extensions as $db_type)
225		echo "\t\t\t\t\t".'<option value="'.$db_type[0].'">'.$db_type[1].'</option>'."\n";
226
227?>					</select></span>
228				</div>
229			</div>
230			<div class="sf-set set1" id="db_host_block">
231				<div class="sf-box text required">
232					<label for="db_host"><span><?php echo $lang_install['Database server'] ?></span> <small><?php echo $lang_install['Database server help'] ?></small></label><br />
233					<span class="fld-input"><input id="db_host" type="text" name="req_db_host" value="localhost" size="35" maxlength="100" required /></span>
234				</div>
235			</div>
236			<div class="sf-set set2">
237				<div class="sf-box text required">
238					<label for="fld3"><span><?php echo $lang_install['Database name'] ?></span> <small><?php echo $lang_install['Database name help'] ?></small></label><br />
239					<span class="fld-input"><input id="fld3" type="text" name="req_db_name" size="35" maxlength="50" required /></span>
240				</div>
241			</div>
242			<div class="sf-set set3" id="db_username_block">
243				<div class="sf-box text">
244					<label for="fld4"><span><?php echo $lang_install['Database username'] ?></span> <small><?php echo $lang_install['Database username help'] ?></small></label><br />
245					<span class="fld-input"><input id="fld4" type="text" name="db_username" size="35" maxlength="50" /></span>
246				</div>
247			</div>
248			<div class="sf-set set4" id="db_password_block">
249				<div class="sf-box text">
250					<label for="fld5"><span><?php echo $lang_install['Database password'] ?></span> <small><?php echo $lang_install['Database password help'] ?></small></label><br />
251					<span class="fld-input"><input id="fld5" type="text" name="db_password" size="35" autocomplete="off" /></span>
252				</div>
253			</div>
254			<div class="sf-set set5">
255				<div class="sf-box text">
256					<label for="fld6"><span><?php echo $lang_install['Table prefix'] ?></span> <small><?php echo $lang_install['Table prefix help'] ?></small></label><br />
257					<span class="fld-input"><input id="fld6" type="text" name="db_prefix" size="35" maxlength="30" /></span>
258				</div>
259			</div>
260		</fieldset>
261	</div>
262
263	<div class="main-subhead">
264		<h2 class="hn"><span><?php echo $lang_install['Part2'] ?></span></h2>
265	</div>
266	<div class="main-content main-frm">
267		<div class="ct-box info-box">
268			<p><?php echo $lang_install['Part2 intro'] ?></p>
269		</div>
270		<fieldset class="frm-group group1">
271			<legend class="group-legend"><strong><?php echo $lang_install['Part2 legend'] ?></strong></legend>
272			<div class="sf-set set4">
273				<div class="sf-box text required">
274					<label for="admin_email"><span><?php echo $lang_install['Admin e-mail'] ?></span> <small><?php echo $lang_install['E-mail address help'] ?></small></label><br />
275					<span class="fld-input"><input id="admin_email" type="email" data-suggest-role="email" name="req_email" size="35" maxlength="80" required /></span>
276				</div>
277			</div>
278			<div class="sf-set set1 prepend-top">
279				<div class="sf-box text required">
280					<label for="admin_username"><span><?php echo $lang_install['Admin username'] ?></span> <small><?php echo $lang_install['Username help'] ?></small></label><br />
281					<span class="fld-input"><input id="admin_username" type="text" data-suggest-role="username" name="req_username" size="35" maxlength="25" required /></span>
282				</div>
283			</div>
284			<div class="sf-set set2">
285				<div class="sf-box text required">
286					<label for="fld8"><span><?php echo $lang_install['Admin password'] ?></span> <small><?php echo $lang_install['Password help'] ?></small></label><br />
287					<span class="fld-input"><input id="fld8" type="text" name="req_password1" size="35" required autocomplete="off" /></span>
288				</div>
289			</div>
290		</fieldset>
291	</div>
292	<div class="main-subhead">
293		<h2 class="hn"><span><?php echo $lang_install['Part3'] ?></span></h2>
294	</div>
295	<div class="main-content main-frm">
296		<div class="ct-box info-box">
297			<p><?php echo $lang_install['Part3 intro'] ?></p>
298			<ul class="spaced list-clean">
299				<li><span><strong><?php echo $lang_install['Base URL'] ?></strong> <?php echo $lang_install['Base URL info'] ?></span></li>
300			</ul>
301		</div>
302		<fieldset class="frm-group group1">
303			<legend class="group-legend"><strong><?php echo $lang_install['Part3 legend'] ?></strong></legend>
304			<div class="sf-set set3">
305				<div class="sf-box text required">
306					<label for="fld10"><span><?php echo $lang_install['Base URL'] ?></span> <small><?php echo $lang_install['Base URL help'] ?></small></label><br />
307					<span class="fld-input"><input id="fld10" type="url" name="req_base_url" value="<?php echo $base_url_guess ?>" size="35" maxlength="100" required /></span>
308				</div>
309			</div>
310<?php
311
312	if (count($languages) > 1)
313	{
314
315?>			<div class="sf-set set4">
316				<div class="sf-box text">
317					<label for="fld11"><span><?php echo $lang_install['Default language'] ?></span> <small><?php echo $lang_install['Default language help'] ?></small></label><br />
318					<span class="fld-input"><select id="fld11" name="req_language">
319<?php
320
321		foreach ($languages as $lang)
322			echo "\t\t\t\t\t".'<option value="'.$lang.'"'.($language == $lang ? ' selected="selected"' : '').'>'.$lang.'</option>'."\n";
323
324?>					</select></span>
325				</div>
326			</div>
327<?php
328
329	}
330	else
331	{
332
333?>			<div class="hidden">
334				<input type="hidden" name="req_language" value="<?php echo $languages[0] ?>" />
335			</div>
336<?php
337	}
338
339	if (file_exists(FORUM_ROOT.'extensions/pun_repository/manifest.xml'))
340	{
341
342?>			<div class="sf-set set5">
343				<div class="sf-box checkbox">
344					<span class="fld-input"><input id="fld12" type="checkbox" name="install_pun_repository" value="1" checked="checked" /></span>
345					<label for="fld12"><span><?php echo $lang_install['Pun repository'] ?></span> <?php echo $lang_install['Pun repository help'] ?></label><br />
346				</div>
347			</div>
348<?php
349
350	}
351
352?>
353		</fieldset>
354		<div class="frm-buttons">
355			<span class="submit primary"><input type="submit" name="start" value="<?php echo $lang_install['Start install'] ?>" /></span>
356		</div>
357	</div>
358	</form>
359</div>
360
361</div>
362</div>
363	<script src="<?php echo FORUM_ROOT ?>include/js/min/punbb.common.min.js"></script>
364	<script src="<?php echo FORUM_ROOT ?>include/js/min/punbb.install.min.js"></script>
365</body>
366</html>
367<?php
368
369}
370else
371{
372	//
373	// Strip slashes only if magic_quotes_gpc is on.
374	//
375	function unescape($str)
376	{
377		return (get_magic_quotes_gpc() == 1) ? stripslashes($str) : $str;
378	}
379
380
381	$db_type = $_POST['req_db_type'];
382	$db_host = forum_trim($_POST['req_db_host']);
383	$db_name = forum_trim($_POST['req_db_name']);
384	$db_username = unescape(forum_trim($_POST['db_username']));
385	$db_password = unescape(forum_trim($_POST['db_password']));
386	$db_prefix = forum_trim($_POST['db_prefix']);
387	$username = unescape(forum_trim($_POST['req_username']));
388	$email = unescape(strtolower(forum_trim($_POST['req_email'])));
389	$password1 = unescape(forum_trim($_POST['req_password1']));
390	$default_lang = preg_replace('#[\.\\\/]#', '', unescape(forum_trim($_POST['req_language'])));
391	$install_pun_repository = !empty($_POST['install_pun_repository']);
392
393	// Make sure base_url doesn't end with a slash
394	if (substr($_POST['req_base_url'], -1) == '/')
395		$base_url = substr($_POST['req_base_url'], 0, -1);
396	else
397		$base_url = $_POST['req_base_url'];
398
399	// Validate form
400	if (utf8_strlen($db_name) == 0)
401		error($lang_install['Missing database name']);
402	if (utf8_strlen($username) < 2)
403		error($lang_install['Username too short']);
404	if (utf8_strlen($username) > 25)
405		error($lang_install['Username too long']);
406	if (utf8_strlen($password1) < 4)
407		error($lang_install['Pass too short']);
408	if (strtolower($username) == 'guest')
409		error($lang_install['Username guest']);
410	if (preg_match('/[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}/', $username) || preg_match('/((([0-9A-Fa-f]{1,4}:){7}[0-9A-Fa-f]{1,4})|(([0-9A-Fa-f]{1,4}:){6}:[0-9A-Fa-f]{1,4})|(([0-9A-Fa-f]{1,4}:){5}:([0-9A-Fa-f]{1,4}:)?[0-9A-Fa-f]{1,4})|(([0-9A-Fa-f]{1,4}:){4}:([0-9A-Fa-f]{1,4}:){0,2}[0-9A-Fa-f]{1,4})|(([0-9A-Fa-f]{1,4}:){3}:([0-9A-Fa-f]{1,4}:){0,3}[0-9A-Fa-f]{1,4})|(([0-9A-Fa-f]{1,4}:){2}:([0-9A-Fa-f]{1,4}:){0,4}[0-9A-Fa-f]{1,4})|(([0-9A-Fa-f]{1,4}:){6}((\b((25[0-5])|(1\d{2})|(2[0-4]\d)|(\d{1,2}))\b)\.){3}(\b((25[0-5])|(1\d{2})|(2[0-4]\d)|(\d{1,2}))\b))|(([0-9A-Fa-f]{1,4}:){0,5}:((\b((25[0-5])|(1\d{2})|(2[0-4]\d)|(\d{1,2}))\b)\.){3}(\b((25[0-5])|(1\d{2})|(2[0-4]\d)|(\d{1,2}))\b))|(::([0-9A-Fa-f]{1,4}:){0,5}((\b((25[0-5])|(1\d{2})|(2[0-4]\d)|(\d{1,2}))\b)\.){3}(\b((25[0-5])|(1\d{2})|(2[0-4]\d)|(\d{1,2}))\b))|([0-9A-Fa-f]{1,4}::([0-9A-Fa-f]{1,4}:){0,5}[0-9A-Fa-f]{1,4})|(::([0-9A-Fa-f]{1,4}:){0,6}[0-9A-Fa-f]{1,4})|(([0-9A-Fa-f]{1,4}:){1,7}:))/', $username))
411		error($lang_install['Username IP']);
412	if ((strpos($username, '[') !== false || strpos($username, ']') !== false) && strpos($username, '\'') !== false && strpos($username, '"') !== false)
413		error($lang_install['Username reserved chars']);
414	if (preg_match('/(?:\[\/?(?:b|u|i|h|colou?r|quote|code|img|url|email|list)\]|\[(?:code|quote|list)=)/i', $username))
415		error($lang_install['Username BBCode']);
416
417	// Validate email
418	if (!defined('FORUM_EMAIL_FUNCTIONS_LOADED'))
419		require FORUM_ROOT.'include/email.php';
420
421	if (!is_valid_email($email))
422		error($lang_install['Invalid email']);
423
424	// Make sure board title and description aren't left blank
425	$board_title = 'My PunBB forum';
426	$board_descrip = 'Unfortunately no one can be told what PunBB is — you have to see it for yourself';
427
428	if (utf8_strlen($base_url) == 0)
429		error($lang_install['Missing base url']);
430
431	if (!file_exists(FORUM_ROOT.'lang/'.$default_lang.'/common.php'))
432		error($lang_install['Invalid language']);
433
434	// Load the appropriate DB layer class
435	switch ($db_type)
436	{
437		case 'mysql':
438			require FORUM_ROOT.'include/dblayer/mysql.php';
439			break;
440
441		case 'mysql_innodb':
442			require FORUM_ROOT.'include/dblayer/mysql_innodb.php';
443			break;
444
445		case 'mysqli':
446			require FORUM_ROOT.'include/dblayer/mysqli.php';
447			break;
448
449		case 'mysqli_innodb':
450			require FORUM_ROOT.'include/dblayer/mysqli_innodb.php';
451			break;
452
453		case 'pgsql':
454			require FORUM_ROOT.'include/dblayer/pgsql.php';
455			break;
456
457		case 'sqlite':
458			require FORUM_ROOT.'include/dblayer/sqlite.php';
459			break;
460
461		case 'sqlite3':
462			require FORUM_ROOT.'include/dblayer/sqlite3.php';
463			break;
464
465		default:
466			error(sprintf($lang_install['No such database type'], forum_htmlencode($db_type)));
467	}
468
469	// Create the database object (and connect/select db)
470	$forum_db = new DBLayer($db_host, $db_username, $db_password, $db_name, $db_prefix, false);
471
472
473	// If MySQL, make sure it's at least 4.1.2
474	if (in_array($db_type, array('mysql', 'mysqli', 'mysql_innodb', 'mysqli_innodb')))
475	{
476		$mysql_info = $forum_db->get_version();
477		if (version_compare($mysql_info['version'], MIN_MYSQL_VERSION, '<'))
478			error(sprintf($lang_install['Invalid MySQL version'], forum_htmlencode($mysql_info['version']), MIN_MYSQL_VERSION));
479
480		// Check InnoDB support in DB
481		if (in_array($db_type, array('mysql_innodb', 'mysqli_innodb')))
482		{
483			$result = $forum_db->query('SHOW VARIABLES LIKE \'have_innodb\'');
484			$row = $forum_db->fetch_assoc($result);
485
486			if (!$row || !isset($row['Value']) || strtolower($row['Value']) != 'yes')
487			{
488				error($lang_install['MySQL InnoDB Not Supported']);
489			}
490		}
491	}
492
493	// Validate prefix
494	if (strlen($db_prefix) > 0 && (!preg_match('/^[a-zA-Z_][a-zA-Z0-9_]*$/', $db_prefix) || strlen($db_prefix) > 40))
495		error(sprintf($lang_install['Invalid table prefix'], $db_prefix));
496
497	// Check SQLite prefix collision
498	if (in_array($db_type, array('sqlite', 'sqlite3')) && strtolower($db_prefix) == 'sqlite_')
499		error($lang_install['SQLite prefix collision']);
500
501
502	// Make sure PunBB isn't already installed
503	if ($forum_db->table_exists('users'))
504	{
505		$query = array(
506			'SELECT'	=> 'COUNT(id)',
507			'FROM'		=> 'users',
508			'WHERE'		=> 'id=1'
509		);
510
511		$result = $forum_db->query_build($query);
512		if ($forum_db->result($result) > 0)
513			error(sprintf($lang_install['PunBB already installed'], $db_prefix, $db_name));
514	}
515
516	// Start a transaction
517	$forum_db->start_transaction();
518
519
520	// Create all tables
521	$schema = array(
522		'FIELDS'		=> array(
523			'id'			=> array(
524				'datatype'		=> 'SERIAL',
525				'allow_null'	=> false
526			),
527			'username'		=> array(
528				'datatype'		=> 'VARCHAR(200)',
529				'allow_null'	=> true
530			),
531			'ip'			=> array(
532				'datatype'		=> 'VARCHAR(255)',
533				'allow_null'	=> true
534			),
535			'email'			=> array(
536				'datatype'		=> 'VARCHAR(80)',
537				'allow_null'	=> true
538			),
539			'message'		=> array(
540				'datatype'		=> 'VARCHAR(255)',
541				'allow_null'	=> true
542			),
543			'expire'		=> array(
544				'datatype'		=> 'INT(10) UNSIGNED',
545				'allow_null'	=> true
546			),
547			'ban_creator'	=> array(
548				'datatype'		=> 'INT(10) UNSIGNED',
549				'allow_null'	=> false,
550				'default'		=> '0'
551			)
552		),
553		'PRIMARY KEY'	=> array('id')
554	);
555
556	$forum_db->create_table('bans', $schema);
557
558
559	$schema = array(
560		'FIELDS'		=> array(
561			'id'			=> array(
562				'datatype'		=> 'SERIAL',
563				'allow_null'	=> false
564			),
565			'cat_name'		=> array(
566				'datatype'		=> 'VARCHAR(80)',
567				'allow_null'	=> false,
568				'default'		=> '\'New Category\''
569			),
570			'disp_position'	=> array(
571				'datatype'		=> 'INT(10)',
572				'allow_null'	=> false,
573				'default'		=> '0'
574			)
575		),
576		'PRIMARY KEY'	=> array('id')
577	);
578
579	$forum_db->create_table('categories', $schema);
580
581
582	$schema = array(
583		'FIELDS'		=> array(
584			'id'			=> array(
585				'datatype'		=> 'SERIAL',
586				'allow_null'	=> false
587			),
588			'search_for'	=> array(
589				'datatype'		=> 'VARCHAR(60)',
590				'allow_null'	=> false,
591				'default'		=> '\'\''
592			),
593			'replace_with'	=> array(
594				'datatype'		=> 'VARCHAR(60)',
595				'allow_null'	=> false,
596				'default'		=> '\'\''
597			)
598		),
599		'PRIMARY KEY'	=> array('id')
600	);
601
602	$forum_db->create_table('censoring', $schema);
603
604
605	$schema = array(
606		'FIELDS'		=> array(
607			'conf_name'		=> array(
608				'datatype'		=> 'VARCHAR(255)',
609				'allow_null'	=> false,
610				'default'		=> '\'\''
611			),
612			'conf_value'	=> array(
613				'datatype'		=> 'TEXT',
614				'allow_null'	=> true
615			)
616		),
617		'PRIMARY KEY'	=> array('conf_name')
618	);
619
620	$forum_db->create_table('config', $schema);
621
622
623	$schema = array(
624		'FIELDS'		=> array(
625			'id'				=> array(
626				'datatype'		=> 'VARCHAR(150)',
627				'allow_null'	=> false,
628				'default'		=> '\'\''
629			),
630			'title'				=> array(
631				'datatype'		=> 'VARCHAR(255)',
632				'allow_null'	=> false,
633				'default'		=> '\'\''
634			),
635			'version'			=> array(
636				'datatype'		=> 'VARCHAR(25)',
637				'allow_null'	=> false,
638				'default'		=> '\'\''
639			),
640			'description'		=> array(
641				'datatype'		=> 'TEXT',
642				'allow_null'	=> true
643			),
644			'author'			=> array(
645				'datatype'		=> 'VARCHAR(50)',
646				'allow_null'	=> false,
647				'default'		=> '\'\''
648			),
649			'uninstall'			=> array(
650				'datatype'		=> 'TEXT',
651				'allow_null'	=> true
652			),
653			'uninstall_note'	=> array(
654				'datatype'		=> 'TEXT',
655				'allow_null'	=> true
656			),
657			'disabled'			=> array(
658				'datatype'		=> 'TINYINT(1)',
659				'allow_null'	=> false,
660				'default'		=> '0'
661			),
662			'dependencies'		=> array(
663				'datatype'		=> 'VARCHAR(255)',
664				'allow_null'	=> false,
665				'default'		=> '\'\''
666			)
667		),
668		'PRIMARY KEY'	=> array('id')
669	);
670
671	$forum_db->create_table('extensions', $schema);
672
673
674	$schema = array(
675		'FIELDS'		=> array(
676			'id'			=> array(
677				'datatype'		=> 'VARCHAR(150)',
678				'allow_null'	=> false,
679				'default'		=> '\'\''
680			),
681			'extension_id'	=> array(
682				'datatype'		=> 'VARCHAR(50)',
683				'allow_null'	=> false,
684				'default'		=> '\'\''
685			),
686			'code'			=> array(
687				'datatype'		=> 'TEXT',
688				'allow_null'	=> true
689			),
690			'installed'		=> array(
691				'datatype'		=> 'INT(10) UNSIGNED',
692				'allow_null'	=> false,
693				'default'		=> '0'
694			),
695			'priority'		=> array(
696				'datatype'		=> 'TINYINT(1) UNSIGNED',
697				'allow_null'	=> false,
698				'default'		=> '5'
699			)
700		),
701		'PRIMARY KEY'	=> array('id', 'extension_id')
702	);
703
704	$forum_db->create_table('extension_hooks', $schema);
705
706
707	$schema = array(
708		'FIELDS'		=> array(
709			'group_id'		=> array(
710				'datatype'		=> 'INT(10)',
711				'allow_null'	=> false,
712				'default'		=> '0'
713			),
714			'forum_id'		=> array(
715				'datatype'		=> 'INT(10)',
716				'allow_null'	=> false,
717				'default'		=> '0'
718			),
719			'read_forum'	=> array(
720				'datatype'		=> 'TINYINT(1)',
721				'allow_null'	=> false,
722				'default'		=> '1'
723			),
724			'post_replies'	=> array(
725				'datatype'		=> 'TINYINT(1)',
726				'allow_null'	=> false,
727				'default'		=> '1'
728			),
729			'post_topics'	=> array(
730				'datatype'		=> 'TINYINT(1)',
731				'allow_null'	=> false,
732				'default'		=> '1'
733			)
734		),
735		'PRIMARY KEY'	=> array('group_id', 'forum_id')
736	);
737
738	$forum_db->create_table('forum_perms', $schema);
739
740
741	$schema = array(
742		'FIELDS'		=> array(
743			'id'			=> array(
744				'datatype'		=> 'SERIAL',
745				'allow_null'	=> false
746			),
747			'forum_name'	=> array(
748				'datatype'		=> 'VARCHAR(80)',
749				'allow_null'	=> false,
750				'default'		=> '\'New forum\''
751			),
752			'forum_desc'	=> array(
753				'datatype'		=> 'TEXT',
754				'allow_null'	=> true
755			),
756			'redirect_url'	=> array(
757				'datatype'		=> 'VARCHAR(100)',
758				'allow_null'	=> true
759			),
760			'moderators'	=> array(
761				'datatype'		=> 'TEXT',
762				'allow_null'	=> true
763			),
764			'num_topics'	=> array(
765				'datatype'		=> 'MEDIUMINT(8) UNSIGNED',
766				'allow_null'	=> false,
767				'default'		=> '0'
768			),
769			'num_posts'		=> array(
770				'datatype'		=> 'MEDIUMINT(8) UNSIGNED',
771				'allow_null'	=> false,
772				'default'		=> '0'
773			),
774			'last_post'		=> array(
775				'datatype'		=> 'INT(10) UNSIGNED',
776				'allow_null'	=> true
777			),
778			'last_post_id'	=> array(
779				'datatype'		=> 'INT(10) UNSIGNED',
780				'allow_null'	=> true
781			),
782			'last_poster'	=> array(
783				'datatype'		=> 'VARCHAR(200)',
784				'allow_null'	=> true
785			),
786			'sort_by'		=> array(
787				'datatype'		=> 'TINYINT(1)',
788				'allow_null'	=> false,
789				'default'		=> '0'
790			),
791			'disp_position'	=> array(
792				'datatype'		=> 'INT(10)',
793				'allow_null'	=> false,
794				'default'		=>	'0'
795			),
796			'cat_id'		=> array(
797				'datatype'		=> 'INT(10) UNSIGNED',
798				'allow_null'	=> false,
799				'default'		=>	'0'
800			)
801		),
802		'PRIMARY KEY'	=> array('id')
803	);
804
805	$forum_db->create_table('forums', $schema);
806
807
808	$schema = array(
809		'FIELDS'		=> array(
810			'g_id'						=> array(
811				'datatype'		=> 'SERIAL',
812				'allow_null'	=> false
813			),
814			'g_title'					=> array(
815				'datatype'		=> 'VARCHAR(50)',
816				'allow_null'	=> false,
817				'default'		=> '\'\''
818			),
819			'g_user_title'				=> array(
820				'datatype'		=> 'VARCHAR(50)',
821				'allow_null'	=> true
822			),
823			'g_moderator'				=> array(
824				'datatype'		=> 'TINYINT(1)',
825				'allow_null'	=> false,
826				'default'		=> '0'
827			),
828			'g_mod_edit_users'			=> array(
829				'datatype'		=> 'TINYINT(1)',
830				'allow_null'	=> false,
831				'default'		=> '0'
832			),
833			'g_mod_rename_users'		=> array(
834				'datatype'		=> 'TINYINT(1)',
835				'allow_null'	=> false,
836				'default'		=> '0'
837			),
838			'g_mod_change_passwords'	=> array(
839				'datatype'		=> 'TINYINT(1)',
840				'allow_null'	=> false,
841				'default'		=> '0'
842			),
843			'g_mod_ban_users'			=> array(
844				'datatype'		=> 'TINYINT(1)',
845				'allow_null'	=> false,
846				'default'		=> '0'
847			),
848			'g_read_board'				=> array(
849				'datatype'		=> 'TINYINT(1)',
850				'allow_null'	=> false,
851				'default'		=> '1'
852			),
853			'g_view_users'				=> array(
854				'datatype'		=> 'TINYINT(1)',
855				'allow_null'	=> false,
856				'default'		=> '1'
857			),
858			'g_post_replies'			=> array(
859				'datatype'		=> 'TINYINT(1)',
860				'allow_null'	=> false,
861				'default'		=> '1'
862			),
863			'g_post_topics'				=> array(
864				'datatype'		=> 'TINYINT(1)',
865				'allow_null'	=> false,
866				'default'		=> '1'
867			),
868			'g_edit_posts'				=> array(
869				'datatype'		=> 'TINYINT(1)',
870				'allow_null'	=> false,
871				'default'		=> '1'
872			),
873			'g_delete_posts'			=> array(
874				'datatype'		=> 'TINYINT(1)',
875				'allow_null'	=> false,
876				'default'		=> '1'
877			),
878			'g_delete_topics'			=> array(
879				'datatype'		=> 'TINYINT(1)',
880				'allow_null'	=> false,
881				'default'		=> '1'
882			),
883			'g_set_title'				=> array(
884				'datatype'		=> 'TINYINT(1)',
885				'allow_null'	=> false,
886				'default'		=> '1'
887			),
888			'g_search'					=> array(
889				'datatype'		=> 'TINYINT(1)',
890				'allow_null'	=> false,
891				'default'		=> '1'
892			),
893			'g_search_users'			=> array(
894				'datatype'		=> 'TINYINT(1)',
895				'allow_null'	=> false,
896				'default'		=> '1'
897			),
898			'g_send_email'				=> array(
899				'datatype'		=> 'TINYINT(1)',
900				'allow_null'	=> false,
901				'default'		=> '1'
902			),
903			'g_post_flood'				=> array(
904				'datatype'		=> 'SMALLINT(6)',
905				'allow_null'	=> false,
906				'default'		=> '30'
907			),
908			'g_search_flood'			=> array(
909				'datatype'		=> 'SMALLINT(6)',
910				'allow_null'	=> false,
911				'default'		=> '30'
912			),
913			'g_email_flood'				=> array(
914				'datatype'		=> 'SMALLINT(6)',
915				'allow_null'	=> false,
916				'default'		=> '60'
917			)
918		),
919		'PRIMARY KEY'	=> array('g_id')
920	);
921
922	$forum_db->create_table('groups', $schema);
923
924
925	$schema = array(
926		'FIELDS'		=> array(
927			'user_id'		=> array(
928				'datatype'		=> 'INT(10) UNSIGNED',
929				'allow_null'	=> false,
930				'default'		=> '1'
931			),
932			'ident'			=> array(
933				'datatype'		=> 'VARCHAR(200)',
934				'allow_null'	=> false,
935				'default'		=> '\'\''
936			),
937			'logged'		=> array(
938				'datatype'		=> 'INT(10) UNSIGNED',
939				'allow_null'	=> false,
940				'default'		=> '0'
941			),
942			'idle'			=> array(
943				'datatype'		=> 'TINYINT(1)',
944				'allow_null'	=> false,
945				'default'		=> '0'
946			),
947			'csrf_token'	=> array(
948				'datatype'		=> 'VARCHAR(40)',
949				'allow_null'	=> false,
950				'default'		=> '\'\''
951			),
952			'prev_url'		=> array(
953				'datatype'		=> 'VARCHAR(255)',
954				'allow_null'	=> true
955			),
956			'last_post'			=> array(
957				'datatype'		=> 'INT(10) UNSIGNED',
958				'allow_null'	=> true
959			),
960			'last_search'		=> array(
961				'datatype'		=> 'INT(10) UNSIGNED',
962				'allow_null'	=> true
963			),
964		),
965		'UNIQUE KEYS'	=> array(
966			'user_id_ident_idx'	=> array('user_id', 'ident')
967		),
968		'INDEXES'		=> array(
969			'ident_idx'		=> array('ident'),
970			'logged_idx'	=> array('logged')
971		),
972		'ENGINE'		=> 'HEAP'
973	);
974
975	if (in_array($db_type, array('mysql', 'mysqli', 'mysql_innodb', 'mysqli_innodb')))
976	{
977		$schema['UNIQUE KEYS']['user_id_ident_idx'] = array('user_id', 'ident(25)');
978		$schema['INDEXES']['ident_idx'] = array('ident(25)');
979	}
980
981	$forum_db->create_table('online', $schema);
982
983
984	$schema = array(
985		'FIELDS'		=> array(
986			'id'			=> array(
987				'datatype'		=> 'SERIAL',
988				'allow_null'	=> false
989			),
990			'poster'		=> array(
991				'datatype'		=> 'VARCHAR(200)',
992				'allow_null'	=> false,
993				'default'		=> '\'\''
994			),
995			'poster_id'		=> array(
996				'datatype'		=> 'INT(10) UNSIGNED',
997				'allow_null'	=> false,
998				'default'		=> '1'
999			),
1000			'poster_ip'		=> array(
1001				'datatype'		=> 'VARCHAR(39)',
1002				'allow_null'	=> true
1003			),
1004			'poster_email'	=> array(
1005				'datatype'		=> 'VARCHAR(80)',
1006				'allow_null'	=> true
1007			),
1008			'message'		=> array(
1009				'datatype'		=> 'TEXT',
1010				'allow_null'	=> true
1011			),
1012			'hide_smilies'	=> array(
1013				'datatype'		=> 'TINYINT(1)',
1014				'allow_null'	=> false,
1015				'default'		=> '0'
1016			),
1017			'posted'		=> array(
1018				'datatype'		=> 'INT(10) UNSIGNED',
1019				'allow_null'	=> false,
1020				'default'		=> '0'
1021			),
1022			'edited'		=> array(
1023				'datatype'		=> 'INT(10) UNSIGNED',
1024				'allow_null'	=> true
1025			),
1026			'edited_by'		=> array(
1027				'datatype'		=> 'VARCHAR(200)',
1028				'allow_null'	=> true
1029			),
1030			'topic_id'		=> array(
1031				'datatype'		=> 'INT(10) UNSIGNED',
1032				'allow_null'	=> false,
1033				'default'		=> '0'
1034			)
1035		),
1036		'PRIMARY KEY'	=> array('id'),
1037		'INDEXES'		=> array(
1038			'topic_id_idx'	=> array('topic_id'),
1039			'multi_idx'		=> array('poster_id', 'topic_id'),
1040			'posted_idx'	=> array('posted')
1041		)
1042	);
1043
1044	$forum_db->create_table('posts', $schema);
1045
1046
1047	$schema = array(
1048		'FIELDS'		=> array(
1049			'id'			=> array(
1050				'datatype'		=> 'SERIAL',
1051				'allow_null'	=> false
1052			),
1053			'rank'			=> array(
1054				'datatype'		=> 'VARCHAR(50)',
1055				'allow_null'	=> false,
1056				'default'		=> '\'\''
1057			),
1058			'min_posts'		=> array(
1059				'datatype'		=> 'MEDIUMINT(8) UNSIGNED',
1060				'allow_null'	=> false,
1061				'default'		=> '0'
1062			)
1063		),
1064		'PRIMARY KEY'	=> array('id')
1065	);
1066
1067	$forum_db->create_table('ranks', $schema);
1068
1069
1070	$schema = array(
1071		'FIELDS'		=> array(
1072			'id'			=> array(
1073				'datatype'		=> 'SERIAL',
1074				'allow_null'	=> false
1075			),
1076			'post_id'		=> array(
1077				'datatype'		=> 'INT(10) UNSIGNED',
1078				'allow_null'	=> false,
1079				'default'		=> '0'
1080			),
1081			'topic_id'		=> array(
1082				'datatype'		=> 'INT(10) UNSIGNED',
1083				'allow_null'	=> false,
1084				'default'		=> '0'
1085			),
1086			'forum_id'		=> array(
1087				'datatype'		=> 'INT(10) UNSIGNED',
1088				'allow_null'	=> false,
1089				'default'		=> '0'
1090			),
1091			'reported_by'	=> array(
1092				'datatype'		=> 'INT(10) UNSIGNED',
1093				'allow_null'	=> false,
1094				'default'		=> '0'
1095			),
1096			'created'		=> array(
1097				'datatype'		=> 'INT(10) UNSIGNED',
1098				'allow_null'	=> false,
1099				'default'		=> '0'
1100			),
1101			'message'		=> array(
1102				'datatype'		=> 'TEXT',
1103				'allow_null'	=> true
1104			),
1105			'zapped'		=> array(
1106				'datatype'		=> 'INT(10) UNSIGNED',
1107				'allow_null'	=> true
1108			),
1109			'zapped_by'		=> array(
1110				'datatype'		=> 'INT(10) UNSIGNED',
1111				'allow_null'	=> true
1112			)
1113		),
1114		'PRIMARY KEY'	=> array('id'),
1115		'INDEXES'		=> array(
1116			'zapped_idx'	=> array('zapped')
1117		)
1118	);
1119
1120	$forum_db->create_table('reports', $schema);
1121
1122
1123	$schema = array(
1124		'FIELDS'		=> array(
1125			'id'			=> array(
1126				'datatype'		=> 'INT(10) UNSIGNED',
1127				'allow_null'	=> false,
1128				'default'		=> '0'
1129			),
1130			'ident'			=> array(
1131				'datatype'		=> 'VARCHAR(200)',
1132				'allow_null'	=> false,
1133				'default'		=> '\'\''
1134			),
1135			'search_data'	=> array(
1136				'datatype'		=> 'TEXT',
1137				'allow_null'	=> true
1138			)
1139		),
1140		'PRIMARY KEY'	=> array('id'),
1141		'INDEXES'		=> array(
1142			'ident_idx'	=> array('ident')
1143		)
1144	);
1145
1146	if (in_array($db_type, array('mysql', 'mysqli', 'mysql_innodb', 'mysqli_innodb')))
1147		$schema['INDEXES']['ident_idx'] = array('ident(8)');
1148
1149	$forum_db->create_table('search_cache', $schema);
1150
1151
1152	$schema = array(
1153		'FIELDS'		=> array(
1154			'post_id'		=> array(
1155				'datatype'		=> 'INT(10) UNSIGNED',
1156				'allow_null'	=> false,
1157				'default'		=> '0'
1158			),
1159			'word_id'		=> array(
1160				'datatype'		=> 'INT(10) UNSIGNED',
1161				'allow_null'	=> false,
1162				'default'		=> '0'
1163			),
1164			'subject_match'	=> array(
1165				'datatype'		=> 'TINYINT(1)',
1166				'allow_null'	=> false,
1167				'default'		=> '0'
1168			)
1169		),
1170		'INDEXES'		=> array(
1171			'word_id_idx'	=> array('word_id'),
1172			'post_id_idx'	=> array('post_id')
1173		)
1174	);
1175
1176	$forum_db->create_table('search_matches', $schema);
1177
1178
1179	$schema = array(
1180		'FIELDS'		=> array(
1181			'id'			=> array(
1182				'datatype'		=> 'SERIAL',
1183				'allow_null'	=> false
1184			),
1185			'word'			=> array(
1186				'datatype'		=> 'VARCHAR(20)',
1187				'allow_null'	=> false,
1188				'default'		=> '\'\'',
1189				'collation'		=> 'bin'
1190			)
1191		),
1192		'PRIMARY KEY'	=> array('word'),
1193		'INDEXES'		=> array(
1194			'id_idx'	=> array('id')
1195		)
1196	);
1197
1198	if ($db_type == 'sqlite' || $db_type == 'sqlite3')
1199	{
1200		$schema['PRIMARY KEY'] = array('id');
1201		$schema['UNIQUE KEYS'] = array('word_idx'	=> array('word'));
1202	}
1203
1204	$forum_db->create_table('search_words', $schema);
1205
1206
1207	$schema = array(
1208		'FIELDS'		=> array(
1209			'user_id'		=> array(
1210				'datatype'		=> 'INT(10) UNSIGNED',
1211				'allow_null'	=> false,
1212				'default'		=> '0'
1213			),
1214			'topic_id'		=> array(
1215				'datatype'		=> 'INT(10) UNSIGNED',
1216				'allow_null'	=> false,
1217				'default'		=> '0'
1218			)
1219		),
1220		'PRIMARY KEY'	=> array('user_id', 'topic_id')
1221	);
1222
1223	$forum_db->create_table('subscriptions', $schema);
1224
1225
1226	$schema = array(
1227		'FIELDS'		=> array(
1228			'user_id'		=> array(
1229				'datatype'		=> 'INT(10) UNSIGNED',
1230				'allow_null'	=> false,
1231				'default'		=> '0'
1232			),
1233			'forum_id'		=> array(
1234				'datatype'		=> 'INT(10) UNSIGNED',
1235				'allow_null'	=> false,
1236				'default'		=> '0'
1237			)
1238		),
1239		'PRIMARY KEY'	=> array('user_id', 'forum_id')
1240	);
1241
1242	$forum_db->create_table('forum_subscriptions', $schema);
1243
1244
1245	$schema = array(
1246		'FIELDS'		=> array(
1247			'id'			=> array(
1248				'datatype'		=> 'SERIAL',
1249				'allow_null'	=> false
1250			),
1251			'poster'		=> array(
1252				'datatype'		=> 'VARCHAR(200)',
1253				'allow_null'	=> false,
1254				'default'		=> '\'\''
1255			),
1256			'subject'		=> array(
1257				'datatype'		=> 'VARCHAR(255)',
1258				'allow_null'	=> false,
1259				'default'		=> '\'\''
1260			),
1261			'posted'		=> array(
1262				'datatype'		=> 'INT(10) UNSIGNED',
1263				'allow_null'	=> false,
1264				'default'		=> '0'
1265			),
1266			'first_post_id'	=> array(
1267				'datatype'		=> 'INT(10) UNSIGNED',
1268				'allow_null'	=> false,
1269				'default'		=> '0'
1270			),
1271			'last_post'		=> array(
1272				'datatype'		=> 'INT(10) UNSIGNED',
1273				'allow_null'	=> false,
1274				'default'		=> '0'
1275			),
1276			'last_post_id'	=> array(
1277				'datatype'		=> 'INT(10) UNSIGNED',
1278				'allow_null'	=> false,
1279				'default'		=> '0'
1280			),
1281			'last_poster'	=> array(
1282				'datatype'		=> 'VARCHAR(200)',
1283				'allow_null'	=> true
1284			),
1285			'num_views'		=> array(
1286				'datatype'		=> 'MEDIUMINT(8) UNSIGNED',
1287				'allow_null'	=> false,
1288				'default'		=> '0'
1289			),
1290			'num_replies'	=> array(
1291				'datatype'		=> 'MEDIUMINT(8) UNSIGNED',
1292				'allow_null'	=> false,
1293				'default'		=> '0'
1294			),
1295			'closed'		=> array(
1296				'datatype'		=> 'TINYINT(1)',
1297				'allow_null'	=> false,
1298				'default'		=> '0'
1299			),
1300			'sticky'		=> array(
1301				'datatype'		=> 'TINYINT(1)',
1302				'allow_null'	=> false,
1303				'default'		=> '0'
1304			),
1305			'moved_to'		=> array(
1306				'datatype'		=> 'INT(10) UNSIGNED',
1307				'allow_null'	=> true
1308			),
1309			'forum_id'		=> array(
1310				'datatype'		=> 'INT(10) UNSIGNED',
1311				'allow_null'	=> false,
1312				'default'		=> '0'
1313			)
1314		),
1315		'PRIMARY KEY'	=> array('id'),
1316		'INDEXES'		=> array(
1317			'forum_id_idx'		=> array('forum_id'),
1318			'moved_to_idx'		=> array('moved_to'),
1319			'last_post_idx'		=> array('last_post'),
1320			'first_post_id_idx'	=> array('first_post_id')
1321		)
1322	);
1323
1324	$forum_db->create_table('topics', $schema);
1325
1326
1327	$schema = array(
1328		'FIELDS'		=> array(
1329			'id'				=> array(
1330				'datatype'		=> 'SERIAL',
1331				'allow_null'	=> false
1332			),
1333			'group_id'			=> array(
1334				'datatype'		=> 'INT(10) UNSIGNED',
1335				'allow_null'	=> false,
1336				'default'		=> '3'
1337			),
1338			'username'			=> array(
1339				'datatype'		=> 'VARCHAR(200)',
1340				'allow_null'	=> false,
1341				'default'		=> '\'\''
1342			),
1343			'password'			=> array(
1344				'datatype'		=> 'VARCHAR(40)',
1345				'allow_null'	=> false,
1346				'default'		=> '\'\''
1347			),
1348			'salt'				=> array(
1349				'datatype'		=> 'VARCHAR(12)',
1350				'allow_null'	=> true
1351			),
1352			'email'				=> array(
1353				'datatype'		=> 'VARCHAR(80)',
1354				'allow_null'	=> false,
1355				'default'		=> '\'\''
1356			),
1357			'title'				=> array(
1358				'datatype'		=> 'VARCHAR(50)',
1359				'allow_null'	=> true
1360			),
1361			'realname'			=> array(
1362				'datatype'		=> 'VARCHAR(40)',
1363				'allow_null'	=> true
1364			),
1365			'url'				=> array(
1366				'datatype'		=> 'VARCHAR(100)',
1367				'allow_null'	=> true
1368			),
1369			'facebook'			=> array(
1370				'datatype'		=> 'VARCHAR(100)',
1371				'allow_null'	=> true
1372			),
1373			'twitter'			=> array(
1374				'datatype'		=> 'VARCHAR(100)',
1375				'allow_null'	=> true
1376			),
1377			'skype'			=> array(
1378				'datatype'		=> 'VARCHAR(100)',
1379				'allow_null'	=> true
1380			),
1381			'icq'				=> array(
1382				'datatype'		=> 'VARCHAR(12)',
1383				'allow_null'	=> true
1384			),
1385			'linkedin'			=> array(
1386				'datatype'		=> 'VARCHAR(100)',
1387				'allow_null'	=> true
1388			),
1389			'jabber'			=> array(
1390				'datatype'		=> 'VARCHAR(80)',
1391				'allow_null'	=> true
1392			),
1393			'msn'				=> array(
1394				'datatype'		=> 'VARCHAR(80)',
1395				'allow_null'	=> true
1396			),
1397			'aim'				=> array(
1398				'datatype'		=> 'VARCHAR(30)',
1399				'allow_null'	=> true
1400			),
1401			'yahoo'				=> array(
1402				'datatype'		=> 'VARCHAR(30)',
1403				'allow_null'	=> true
1404			),
1405			'location'			=> array(
1406				'datatype'		=> 'VARCHAR(30)',
1407				'allow_null'	=> true
1408			),
1409			'signature'			=> array(
1410				'datatype'		=> 'TEXT',
1411				'allow_null'	=> true
1412			),
1413			'disp_topics'		=> array(
1414				'datatype'		=> 'TINYINT(3) UNSIGNED',
1415				'allow_null'	=> true
1416			),
1417			'disp_posts'		=> array(
1418				'datatype'		=> 'TINYINT(3) UNSIGNED',
1419				'allow_null'	=> true
1420			),
1421			'email_setting'		=> array(
1422				'datatype'		=> 'TINYINT(1)',
1423				'allow_null'	=> false,
1424				'default'		=> '1'
1425			),
1426			'notify_with_post'	=> array(
1427				'datatype'		=> 'TINYINT(1)',
1428				'allow_null'	=> false,
1429				'default'		=> '0'
1430			),
1431			'auto_notify'		=> array(
1432				'datatype'		=> 'TINYINT(1)',
1433				'allow_null'	=> false,
1434				'default'		=> '0'
1435			),
1436			'show_smilies'		=> array(
1437				'datatype'		=> 'TINYINT(1)',
1438				'allow_null'	=> false,
1439				'default'		=> '1'
1440			),
1441			'show_img'			=> array(
1442				'datatype'		=> 'TINYINT(1)',
1443				'allow_null'	=> false,
1444				'default'		=> '1'
1445			),
1446			'show_img_sig'		=> array(
1447				'datatype'		=> 'TINYINT(1)',
1448				'allow_null'	=> false,
1449				'default'		=> '1'
1450			),
1451			'show_avatars'		=> array(
1452				'datatype'		=> 'TINYINT(1)',
1453				'allow_null'	=> false,
1454				'default'		=> '1'
1455			),
1456			'show_sig'			=> array(
1457				'datatype'		=> 'TINYINT(1)',
1458				'allow_null'	=> false,
1459				'default'		=> '1'
1460			),
1461			'access_keys'		=> array(
1462				'datatype'		=> 'TINYINT(1)',
1463				'allow_null'	=> false,
1464				'default'		=> '0'
1465			),
1466			'timezone'			=> array(
1467				'datatype'		=> 'FLOAT',
1468				'allow_null'	=> false,
1469				'default'		=> '0'
1470			),
1471			'dst'				=> array(
1472				'datatype'		=> 'TINYINT(1)',
1473				'allow_null'	=> false,
1474				'default'		=> '0'
1475			),
1476			'time_format'		=> array(
1477				'datatype'		=> 'INT(10) UNSIGNED',
1478				'allow_null'	=> false,
1479				'default'		=> '0'
1480			),
1481			'date_format'		=> array(
1482				'datatype'		=> 'INT(10) UNSIGNED',
1483				'allow_null'	=> false,
1484				'default'		=> '0'
1485			),
1486			'language'			=> array(
1487				'datatype'		=> 'VARCHAR(25)',
1488				'allow_null'	=> false,
1489				'default'		=> '\'English\''
1490			),
1491			'style'				=> array(
1492				'datatype'		=> 'VARCHAR(25)',
1493				'allow_null'	=> false,
1494				'default'		=> '\'Oxygen\''
1495			),
1496			'num_posts'			=> array(
1497				'datatype'		=> 'INT(10) UNSIGNED',
1498				'allow_null'	=> false,
1499				'default'		=> '0'
1500			),
1501			'last_post'			=> array(
1502				'datatype'		=> 'INT(10) UNSIGNED',
1503				'allow_null'	=> true
1504			),
1505			'last_search'		=> array(
1506				'datatype'		=> 'INT(10) UNSIGNED',
1507				'allow_null'	=> true
1508			),
1509			'last_email_sent'	=> array(
1510				'datatype'		=> 'INT(10) UNSIGNED',
1511				'allow_null'	=> true
1512			),
1513			'registered'		=> array(
1514				'datatype'		=> 'INT(10) UNSIGNED',
1515				'allow_null'	=> false,
1516				'default'		=> '0'
1517			),
1518			'registration_ip'	=> array(
1519				'datatype'		=> 'VARCHAR(39)',
1520				'allow_null'	=> false,
1521				'default'		=> '\'0.0.0.0\''
1522			),
1523			'last_visit'		=> array(
1524				'datatype'		=> 'INT(10) UNSIGNED',
1525				'allow_null'	=> false,
1526				'default'		=> '0'
1527			),
1528			'admin_note'		=> array(
1529				'datatype'		=> 'VARCHAR(30)',
1530				'allow_null'	=> true
1531			),
1532			'activate_string'	=> array(
1533				'datatype'		=> 'VARCHAR(80)',
1534				'allow_null'	=> true
1535			),
1536			'activate_key'		=> array(
1537				'datatype'		=> 'VARCHAR(8)',
1538				'allow_null'	=> true
1539			),
1540			'avatar'			=> array(
1541				'datatype'		=> 'TINYINT(3) UNSIGNED',
1542				'allow_null'	=> false,
1543				'default'		=> 0,
1544			),
1545			'avatar_width'		=> array(
1546				'datatype'		=> 'TINYINT(3) UNSIGNED',
1547				'allow_null'	=> false,
1548				'default'		=> 0,
1549			),
1550			'avatar_height'		=> array(
1551				'datatype'		=> 'TINYINT(3) UNSIGNED',
1552				'allow_null'	=> false,
1553				'default'		=> 0,
1554			),
1555		),
1556		'PRIMARY KEY'	=> array('id'),
1557		'INDEXES'		=> array(
1558			'registered_idx'	=> array('registered'),
1559			'username_idx'		=> array('username')
1560		)
1561	);
1562
1563	if (in_array($db_type, array('mysql', 'mysqli', 'mysql_innodb', 'mysqli_innodb')))
1564		$schema['INDEXES']['username_idx'] = array('username(8)');
1565
1566	$forum_db->create_table('users', $schema);
1567
1568
1569
1570	$now = time();
1571
1572	// Insert the four preset groups
1573	$query = array(
1574		'INSERT'	=> 'g_title, g_user_title, g_moderator, g_mod_edit_users, g_mod_rename_users, g_mod_change_passwords, g_mod_ban_users, g_read_board, g_view_users, g_post_replies, g_post_topics, g_edit_posts, g_delete_posts, g_delete_topics, g_set_title, g_search, g_search_users, g_send_email, g_post_flood, g_search_flood, g_email_flood',
1575		'INTO'		=> 'groups',
1576		'VALUES'	=> '\'Administrators\', \'Administrator\', 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0'
1577	);
1578
1579	if ($db_type != 'pgsql')
1580	{
1581		$query['INSERT'] .= ', g_id';
1582		$query['VALUES'] .= ', 1';
1583	}
1584
1585	$forum_db->query_build($query) or error(__FILE__, __LINE__);
1586
1587	$query = array(
1588		'INSERT'	=> 'g_title, g_user_title, g_moderator, g_mod_edit_users, g_mod_rename_users, g_mod_change_passwords, g_mod_ban_users, g_read_board, g_view_users, g_post_replies, g_post_topics, g_edit_posts, g_delete_posts, g_delete_topics, g_set_title, g_search, g_search_users, g_send_email, g_post_flood, g_search_flood, g_email_flood',
1589		'INTO'		=> 'groups',
1590		'VALUES'	=> '\'Guest\', NULL, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 1, 1, 0, 60, 30, 0'
1591	);
1592
1593	if ($db_type != 'pgsql')
1594	{
1595		$query['INSERT'] .= ', g_id';
1596		$query['VALUES'] .= ', 2';
1597	}
1598
1599	$forum_db->query_build($query) or error(__FILE__, __LINE__);
1600
1601	$query = array(
1602		'INSERT'	=> 'g_title, g_user_title, g_moderator, g_mod_edit_users, g_mod_rename_users, g_mod_change_passwords, g_mod_ban_users, g_read_board, g_view_users, g_post_replies, g_post_topics, g_edit_posts, g_delete_posts, g_delete_topics, g_set_title, g_search, g_search_users, g_send_email, g_post_flood, g_search_flood, g_email_flood',
1603		'INTO'		=> 'groups',
1604		'VALUES'	=> '\'Members\', NULL, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 60, 30, 60'
1605	);
1606
1607	if ($db_type != 'pgsql')
1608	{
1609		$query['INSERT'] .= ', g_id';
1610		$query['VALUES'] .= ', 3';
1611	}
1612
1613	$forum_db->query_build($query) or error(__FILE__, __LINE__);
1614
1615	$query = array(
1616		'INSERT'	=> 'g_title, g_user_title, g_moderator, g_mod_edit_users, g_mod_rename_users, g_mod_change_passwords, g_mod_ban_users, g_read_board, g_view_users, g_post_replies, g_post_topics, g_edit_posts, g_delete_posts, g_delete_topics, g_set_title, g_search, g_search_users, g_send_email, g_post_flood, g_search_flood, g_email_flood',
1617		'INTO'		=> 'groups',
1618		'VALUES'	=> '\'Moderators\', \'Moderator\', 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0'
1619	);
1620
1621	if ($db_type != 'pgsql')
1622	{
1623		$query['INSERT'] .= ', g_id';
1624		$query['VALUES'] .= ', 4';
1625	}
1626
1627	$forum_db->query_build($query) or error(__FILE__, __LINE__);
1628
1629	// Insert guest and first admin user
1630	$query = array(
1631		'INSERT'	=> 'group_id, username, password, email',
1632		'INTO'		=> 'users',
1633		'VALUES'	=> '2, \'Guest\', \'Guest\', \'Guest\''
1634	);
1635
1636	if ($db_type != 'pgsql')
1637	{
1638		$query['INSERT'] .= ', id';
1639		$query['VALUES'] .= ', 1';
1640	}
1641
1642	$forum_db->query_build($query) or error(__FILE__, __LINE__);
1643
1644	$salt = random_key(12);
1645
1646	$query = array(
1647		'INSERT'	=> 'group_id, username, password, email, language, num_posts, last_post, registered, registration_ip, last_visit, salt',
1648		'INTO'		=> 'users',
1649		'VALUES'	=> '1, \''.$forum_db->escape($username).'\', \''.forum_hash($password1, $salt).'\', \''.$forum_db->escape($email).'\', \''.$forum_db->escape($default_lang).'\', 1, '.$now.', '.$now.', \'127.0.0.1\', '.$now.', \''.$forum_db->escape($salt).'\''
1650	);
1651
1652	$forum_db->query_build($query) or error(__FILE__, __LINE__);
1653	$new_uid = $forum_db->insert_id();
1654
1655	// Enable/disable avatars depending on file_uploads setting in PHP configuration
1656	$avatars = in_array(strtolower(@ini_get('file_uploads')), array('on', 'true', '1')) ? 1 : 0;
1657
1658	// Enable/disable automatic check for updates depending on PHP environment (require cURL, fsockopen or allow_url_fopen)
1659	$check_for_updates = (function_exists('curl_init') || function_exists('fsockopen') || in_array(strtolower(@ini_get('allow_url_fopen')), array('on', 'true', '1'))) ? 1 : 0;
1660
1661	// Insert config data
1662	$config = array(
1663		'o_cur_version'				=> "'".FORUM_VERSION."'",
1664		'o_database_revision'		=> "'".FORUM_DB_REVISION."'",
1665		'o_board_title'				=> "'".$forum_db->escape($board_title)."'",
1666		'o_board_desc'				=> "'".$forum_db->escape($board_descrip)."'",
1667		'o_default_timezone'		=> "'0'",
1668		'o_time_format'				=> "'H:i:s'",
1669		'o_date_format'				=> "'Y-m-d'",
1670		'o_check_for_updates'		=> "'$check_for_updates'",
1671		'o_check_for_versions'		=> "'$check_for_updates'",
1672		'o_timeout_visit'			=> "'5400'",
1673		'o_timeout_online'			=> "'300'",
1674		'o_redirect_delay'			=> "'0'",
1675		'o_show_version'			=> "'0'",
1676		'o_show_user_info'			=> "'1'",
1677		'o_show_post_count'			=> "'1'",
1678		'o_signatures'				=> "'1'",
1679		'o_smilies'					=> "'1'",
1680		'o_smilies_sig'				=> "'1'",
1681		'o_make_links'				=> "'1'",
1682		'o_default_lang'			=> "'".$forum_db->escape($default_lang)."'",
1683		'o_default_style'			=> "'Oxygen'",
1684		'o_default_user_group'		=> "'3'",
1685		'o_topic_review'			=> "'15'",
1686		'o_disp_topics_default'		=> "'30'",
1687		'o_disp_posts_default'		=> "'25'",
1688		'o_indent_num_spaces'		=> "'4'",
1689		'o_quote_depth'				=> "'3'",
1690		'o_quickpost'				=> "'1'",
1691		'o_users_online'			=> "'1'",
1692		'o_censoring'				=> "'0'",
1693		'o_ranks'					=> "'1'",
1694		'o_show_dot'				=> "'0'",
1695		'o_topic_views'				=> "'1'",
1696		'o_quickjump'				=> "'1'",
1697		'o_gzip'					=> "'0'",
1698		'o_additional_navlinks'		=> "''",
1699		'o_report_method'			=> "'0'",
1700		'o_regs_report'				=> "'0'",
1701		'o_default_email_setting'	=> "'1'",
1702		'o_mailing_list'			=> "'".$forum_db->escape($email)."'",
1703		'o_avatars'					=> "'$avatars'",
1704		'o_avatars_dir'				=> "'img/avatars'",
1705		'o_avatars_width'			=> "'60'",
1706		'o_avatars_height'			=> "'60'",
1707		'o_avatars_size'			=> "'15360'",
1708		'o_search_all_forums'		=> "'1'",
1709		'o_sef'						=> "'Default'",
1710		'o_admin_email'				=> "'".$forum_db->escape($email)."'",
1711		'o_webmaster_email'			=> "'".$forum_db->escape($email)."'",
1712		'o_subscriptions'			=> "'1'",
1713		'o_smtp_host'				=> "NULL",
1714		'o_smtp_user'				=> "NULL",
1715		'o_smtp_pass'				=> "NULL",
1716		'o_smtp_ssl'				=> "'0'",
1717		'o_regs_allow'				=> "'1'",
1718		'o_regs_verify'				=> "'0'",
1719		'o_announcement'			=> "'0'",
1720		'o_announcement_heading'	=> "'".$lang_install['Default announce heading']."'",
1721		'o_announcement_message'	=> "'".$lang_install['Default announce message']."'",
1722		'o_rules'					=> "'0'",
1723		'o_rules_message'			=> "'".$lang_install['Default rules']."'",
1724		'o_maintenance'				=> "'0'",
1725		'o_maintenance_message'		=> "'".$lang_admin_settings['Maintenance message default']."'",
1726		'o_default_dst'				=> "'0'",
1727		'p_message_bbcode'			=> "'1'",
1728		'p_message_img_tag'			=> "'1'",
1729		'p_message_all_caps'		=> "'1'",
1730		'p_subject_all_caps'		=> "'1'",
1731		'p_sig_all_caps'			=> "'1'",
1732		'p_sig_bbcode'				=> "'1'",
1733		'p_sig_img_tag'				=> "'0'",
1734		'p_sig_length'				=> "'400'",
1735		'p_sig_lines'				=> "'4'",
1736		'p_allow_banned_email'		=> "'1'",
1737		'p_allow_dupe_email'		=> "'0'",
1738		'p_force_guest_email'		=> "'1'",
1739		'o_show_moderators'			=> "'0'",
1740		'o_mask_passwords'			=> "'1'"
1741	);
1742
1743	foreach ($config as $conf_name => $conf_value)
1744	{
1745		$query = array(
1746			'INSERT'	=> 'conf_name, conf_value',
1747			'INTO'		=> 'config',
1748			'VALUES'	=> '\''.$conf_name.'\', '.$conf_value.''
1749		);
1750
1751		$forum_db->query_build($query) or error(__FILE__, __LINE__);
1752	}
1753
1754	// Insert some other default data
1755	$query = array(
1756		'INSERT'	=> 'cat_name, disp_position',
1757		'INTO'		=> 'categories',
1758		'VALUES'	=> '\''.$lang_install['Default category name'].'\', 1'
1759	);
1760
1761	$forum_db->query_build($query) or error(__FILE__, __LINE__);
1762
1763	$query = array(
1764		'INSERT'	=> 'forum_name, forum_desc, num_topics, num_posts, last_post, last_post_id, last_poster, disp_position, cat_id',
1765		'INTO'		=> 'forums',
1766		'VALUES'	=> '\''.$lang_install['Default forum name'].'\', \''.$lang_install['Default forum descrip'].'\', 1, 1, '.$now.', 1, \''.$forum_db->escape($username).'\', 1, '.$forum_db->insert_id().''
1767	);
1768
1769	$forum_db->query_build($query) or error(__FILE__, __LINE__);
1770
1771	$query = array(
1772		'INSERT'	=> 'poster, subject, posted, first_post_id, last_post, last_post_id, last_poster, forum_id',
1773		'INTO'		=> 'topics',
1774		'VALUES'	=> '\''.$forum_db->escape($username).'\', \''.$lang_install['Default topic subject'].'\', '.$now.', 1, '.$now.', 1, \''.$forum_db->escape($username).'\', '.$forum_db->insert_id().''
1775	);
1776
1777	$forum_db->query_build($query) or error(__FILE__, __LINE__);
1778
1779	$query = array(
1780		'INSERT'	=> 'poster, poster_id, poster_ip, message, posted, topic_id',
1781		'INTO'		=> 'posts',
1782		'VALUES'	=> '\''.$forum_db->escape($username).'\', '.$new_uid.', \'127.0.0.1\', \''.$lang_install['Default post contents'].'\', '.$now.', '.$forum_db->insert_id().''
1783	);
1784
1785	if ($db_type != 'pgsql')
1786	{
1787		$query['INSERT'] .= ', id';
1788		$query['VALUES'] .= ', 1';
1789	}
1790
1791	$forum_db->query_build($query) or error(__FILE__, __LINE__);
1792
1793	// Add new post to search table
1794	require FORUM_ROOT.'include/search_idx.php';
1795	update_search_index('post', $forum_db->insert_id(), $lang_install['Default post contents'], $lang_install['Default topic subject']);
1796
1797	// Insert the default ranks
1798	$query = array(
1799		'INSERT'	=> 'rank, min_posts',
1800		'INTO'		=> 'ranks',
1801		'VALUES'	=> '\''.$lang_install['Default rank 1'].'\', 0'
1802	);
1803
1804	$forum_db->query_build($query) or error(__FILE__, __LINE__);
1805
1806	$query = array(
1807		'INSERT'	=> 'rank, min_posts',
1808		'INTO'		=> 'ranks',
1809		'VALUES'	=> '\''.$lang_install['Default rank 2'].'\', 10'
1810	);
1811
1812	$forum_db->query_build($query) or error(__FILE__, __LINE__);
1813
1814	$forum_db->end_transaction();
1815
1816
1817	$alerts = array();
1818
1819	// Check if the cache directory is writable and clear cache dir
1820	if (is_writable(FORUM_ROOT.'cache/'))
1821	{
1822		$cache_dir = dir(FORUM_ROOT.'cache/');
1823		if ($cache_dir)
1824		{
1825			while (($entry = $cache_dir->read()) !== false)
1826			{
1827				if (substr($entry, strlen($entry)-4) == '.php')
1828					@unlink(FORUM_ROOT.'cache/'.$entry);
1829			}
1830			$cache_dir->close();
1831		}
1832	}
1833	else
1834	{
1835		$alerts[] = '<li><span>'.$lang_install['No cache write'].'</span></li>';
1836	}
1837
1838	// Check if default avatar directory is writable
1839	if (!is_writable(FORUM_ROOT.'img/avatars/'))
1840		$alerts[] = '<li><span>'.$lang_install['No avatar write'].'</span></li>';
1841
1842	// Check if we disabled uploading avatars because file_uploads was disabled
1843	if ($avatars == '0')
1844		$alerts[] = '<li><span>'.$lang_install['File upload alert'].'</span></li>';
1845
1846	// Add some random bytes at the end of the cookie name to prevent collisions
1847	$cookie_name = 'forum_cookie_'.random_key(6, false, true);
1848
1849	/// Generate the config.php file data
1850	$config = generate_config_file();
1851
1852	// Attempt to write config.php and serve it up for download if writing fails
1853	$written = false;
1854	if (is_writable(FORUM_ROOT))
1855	{
1856		$fh = @fopen(FORUM_ROOT.'config.php', 'wb');
1857		if ($fh)
1858		{
1859			fwrite($fh, $config);
1860			fclose($fh);
1861
1862			$written = true;
1863		}
1864	}
1865
1866
1867	if ($install_pun_repository && is_readable(FORUM_ROOT.'extensions/pun_repository/manifest.xml'))
1868	{
1869		require FORUM_ROOT.'include/xml.php';
1870
1871		$ext_data = xml_to_array(file_get_contents(FORUM_ROOT.'extensions/pun_repository/manifest.xml'));
1872
1873		if (!empty($ext_data))
1874		{
1875			$query = array(
1876				'INSERT'	=> 'id, title, version, description, author, uninstall, uninstall_note, dependencies',
1877				'INTO'		=> 'extensions',
1878				'VALUES'	=> '\'pun_repository\', \''.$forum_db->escape($ext_data['extension']['title']).'\', \''.$forum_db->escape($ext_data['extension']['version']).'\', \''.$forum_db->escape($ext_data['extension']['description']).'\', \''.$forum_db->escape($ext_data['extension']['author']).'\', NULL, NULL, \'||\'',
1879			);
1880
1881			$forum_db->query_build($query) or error(__FILE__, __LINE__);
1882
1883			if (isset($ext_data['extension']['hooks']['hook']))
1884			{
1885				foreach ($ext_data['extension']['hooks']['hook'] as $ext_hook)
1886				{
1887					$cur_hooks = explode(',', $ext_hook['attributes']['id']);
1888					foreach ($cur_hooks as $cur_hook)
1889					{
1890						$query = array(
1891							'INSERT'	=> 'id, extension_id, code, installed, priority',
1892							'INTO'		=> 'extension_hooks',
1893							'VALUES'	=> '\''.$forum_db->escape(forum_trim($cur_hook)).'\', \'pun_repository\', \''.$forum_db->escape(forum_trim($ext_hook['content'])).'\', '.time().', '.(isset($ext_hook['attributes']['priority']) ? $ext_hook['attributes']['priority'] : 5)
1894						);
1895
1896						$forum_db->query_build($query) or error(__FILE__, __LINE__);
1897					}
1898				}
1899			}
1900		}
1901	}
1902
1903    require_once FORUM_ROOT.'include/xml.php';
1904
1905?>
1906<!DOCTYPE html>
1907<!--[if lt IE 7 ]> <html class="oldie ie6" lang="en" dir="ltr"> <![endif]-->
1908<!--[if IE 7 ]>    <html class="oldie ie7" lang="en" dir="ltr"> <![endif]-->
1909<!--[if IE 8 ]>    <html class="oldie ie8" lang="en" dir="ltr"> <![endif]-->
1910<!--[if gt IE 8]><!--> <html lang="en" dir="ltr"> <!--<![endif]-->
1911<head>
1912	<meta charset="utf-8" />
1913	<title>PunBB Installation</title>
1914	<link rel="stylesheet" type="text/css" href="<?php echo FORUM_ROOT ?>style/Oxygen/Oxygen.min.css" />
1915</head>
1916<body>
1917<div id="brd-install" class="brd-page">
1918	<div id="brd-wrap" class="brd">
1919		<div id="brd-head" class="gen-content">
1920			<p id="brd-title"><strong><?php printf($lang_install['Install PunBB'], FORUM_VERSION) ?></strong></p>
1921			<p id="brd-desc"><?php printf($lang_install['Success description'], FORUM_VERSION) ?></p>
1922		</div>
1923		<div id="brd-main" class="main basic">
1924			<div class="main-head">
1925				<h1 class="hn"><span><?php echo $lang_install['Final instructions'] ?></span></h1>
1926			</div>
1927			<div class="main-content main-frm">
1928<?php if (!empty($alerts)): ?>
1929				<div class="ct-box error-box">
1930					<p class="warn"><strong><?php echo $lang_install['Warning'] ?></strong></p>
1931					<ul>
1932						<?php echo implode("\n\t\t\t\t", $alerts)."\n" ?>
1933					</ul>
1934				</div>
1935<?php endif;
1936
1937if (!$written)
1938{
1939?>
1940				<div class="ct-box info-box">
1941					<p class="warn"><?php echo $lang_install['No write info 1'] ?></p>
1942					<p class="warn"><?php printf($lang_install['No write info 2'], '<a href="'.FORUM_ROOT.'index.php">'.$lang_install['Go to index'].'</a>') ?></p>
1943				</div>
1944				<form class="frm-form" method="post" accept-charset="utf-8" action="install.php">
1945					<div class="hidden">
1946					<input type="hidden" name="generate_config" value="1" />
1947					<input type="hidden" name="db_type" value="<?php echo $db_type ?>" />
1948					<input type="hidden" name="db_host" value="<?php echo $db_host ?>" />
1949					<input type="hidden" name="db_name" value="<?php echo forum_htmlencode($db_name) ?>" />
1950					<input type="hidden" name="db_username" value="<?php echo forum_htmlencode($db_username) ?>" />
1951					<input type="hidden" name="db_password" value="<?php echo forum_htmlencode($db_password) ?>" />
1952					<input type="hidden" name="db_prefix" value="<?php echo forum_htmlencode($db_prefix) ?>" />
1953					<input type="hidden" name="base_url" value="<?php echo forum_htmlencode($base_url) ?>" />
1954					<input type="hidden" name="cookie_name" value="<?php echo forum_htmlencode($cookie_name) ?>" />
1955					</div>
1956					<div class="frm-buttons">
1957						<span class="submit"><input type="submit" value="<?php echo $lang_install['Download config'] ?>" /></span>
1958					</div>
1959				</form>
1960<?php
1961}
1962else
1963{
1964?>
1965				<div class="ct-box info-box">
1966					<p class="warn"><?php printf($lang_install['Write info'], '<a href="'.FORUM_ROOT.'index.php">'.$lang_install['Go to index'].'</a>') ?></p>
1967				</div>
1968<?php
1969}
1970?>
1971			</div>
1972		</div>
1973	</div>
1974</div>
1975</body>
1976</html>
1977<?php
1978}
1979