punbb/install.php
changeset 7 98bbc533541c
equal deleted inserted replaced
6:5e1f1e916419 7:98bbc533541c
       
     1 <?php
       
     2 /***********************************************************************
       
     3 
       
     4   Copyright (C) 2002-2008  PunBB.org
       
     5 
       
     6   This file is part of PunBB.
       
     7 
       
     8   PunBB is free software; you can redistribute it and/or modify it
       
     9   under the terms of the GNU General Public License as published
       
    10   by the Free Software Foundation; either version 2 of the License,
       
    11   or (at your option) any later version.
       
    12 
       
    13   PunBB is distributed in the hope that it will be useful, but
       
    14   WITHOUT ANY WARRANTY; without even the implied warranty of
       
    15   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
       
    16   GNU General Public License for more details.
       
    17 
       
    18   You should have received a copy of the GNU General Public License
       
    19   along with this program; if not, write to the Free Software
       
    20   Foundation, Inc., 59 Temple Place, Suite 330, Boston,
       
    21   MA  02111-1307  USA
       
    22 
       
    23 ************************************************************************/
       
    24 
       
    25 
       
    26 define('PUN_VERSION', '1.3 Beta');
       
    27 define('MIN_PHP_VERSION', '4.3.0');
       
    28 define('MIN_MYSQL_VERSION', '4.1.2');
       
    29 
       
    30 define('PUN_ROOT', './');
       
    31 define('PUN', 1);
       
    32 define('PUN_DEBUG', 1);
       
    33 
       
    34 if (file_exists(PUN_ROOT.'config.php'))
       
    35 	exit('The file \'config.php\' already exists which would mean that PunBB is already installed. You should go <a href="index.php">here</a> instead.');
       
    36 
       
    37 
       
    38 // Make sure we are running at least MIN_PHP_VERSION
       
    39 if (!function_exists('version_compare') || version_compare(PHP_VERSION, MIN_PHP_VERSION, '<'))
       
    40 	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.');
       
    41 
       
    42 // Disable error reporting for uninitialized variables
       
    43 error_reporting(E_ALL);
       
    44 
       
    45 // Turn off PHP time limit
       
    46 @set_time_limit(0);
       
    47 
       
    48 // We need some stuff from functions.php
       
    49 require PUN_ROOT.'include/functions.php';
       
    50 
       
    51 // Load the language file
       
    52 require PUN_ROOT.'lang/English/install.php';
       
    53 
       
    54 
       
    55 if (isset($_POST['generate_config']))
       
    56 {
       
    57 	header('Content-Type: text/x-delimtext; name="config.php"');
       
    58 	header('Content-disposition: attachment; filename=config.php');
       
    59 
       
    60 	$db_type = $_POST['db_type'];
       
    61 	$db_host = $_POST['db_host'];
       
    62 	$db_name = $_POST['db_name'];
       
    63 	$db_username = $_POST['db_username'];
       
    64 	$db_password = $_POST['db_password'];
       
    65 	$db_prefix = $_POST['db_prefix'];
       
    66 	$base_url = $_POST['base_url'];
       
    67 	$cookie_name = $_POST['cookie_name'];
       
    68 
       
    69 	echo get_config_file();
       
    70 	exit;
       
    71 }
       
    72 
       
    73 
       
    74 if (!isset($_POST['form_sent']))
       
    75 {
       
    76 	// Determine available database extensions
       
    77 	$dual_mysql = false;
       
    78 	$db_extensions = array();
       
    79 	if (function_exists('mysqli_connect'))
       
    80 		$db_extensions[] = array('mysqli', 'MySQL Improved');
       
    81 	if (function_exists('mysql_connect'))
       
    82 	{
       
    83 		$db_extensions[] = array('mysql', 'MySQL Standard');
       
    84 
       
    85 		if (count($db_extensions) > 1)
       
    86 			$dual_mysql = true;
       
    87 	}
       
    88 	if (function_exists('sqlite_open'))
       
    89 		$db_extensions[] = array('sqlite', 'SQLite');
       
    90 	if (function_exists('pg_connect'))
       
    91 		$db_extensions[] = array('pgsql', 'PostgreSQL');
       
    92 
       
    93 	if (empty($db_extensions))
       
    94 		error('This PHP environment does not have support for any of the databases that PunBB supports. PHP needs to have support for either MySQL, PostgreSQL or SQLite in order for PunBB to be installed.');
       
    95 
       
    96 ?>
       
    97 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
       
    98 
       
    99 <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en" dir="ltr">
       
   100 <head>
       
   101 <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
       
   102 <title>PunBB Installation</title>
       
   103 <link rel="stylesheet" type="text/css" href="style/Oxygen/Oxygen.css" />
       
   104 <link rel="stylesheet" type="text/css" href="style/Oxygen/Oxygen_cs.css" />
       
   105 <!--[if lte IE 6]><link rel="stylesheet" type="text/css" href="style/Oxygen/Oxygen_ie6.css" /><![endif]-->
       
   106 <!--[if IE 7]><link rel="stylesheet" type="text/css" href="style/Oxygen/Oxygen_ie7.css" /><![endif]-->
       
   107 </head>
       
   108 <body>
       
   109 
       
   110 <div id="pun-install" class="pun-page">
       
   111 <div class="pun">
       
   112 
       
   113 <div id="pun-title">
       
   114 	<div><strong><?php printf($lang_install['Install PunBB'], PUN_VERSION) ?></strong></div>
       
   115 </div>
       
   116 
       
   117 <div id="pun-desc">
       
   118 	<div><?php printf ($lang_install['Install welcome'], PUN_VERSION) ?></div>
       
   119 </div>
       
   120 
       
   121 <div id="pun-head">
       
   122 	<div id="pun-visit">
       
   123 		<p><?php echo $lang_install['Install intro'] ?></p>
       
   124 	</div>
       
   125 </div>
       
   126 
       
   127 
       
   128 <div id="pun-main" class="main">
       
   129 
       
   130 	<div class="main-head">
       
   131 		<h1><span><?php printf($lang_install['Install PunBB'], PUN_VERSION) ?></span></h1>
       
   132 	</div>
       
   133 
       
   134 	<div class="main-content frm parted">
       
   135 		<div class="frm-head">
       
   136 			<h2><span><?php echo $lang_install['Install head'] ?></span></h2>
       
   137 		</div>
       
   138 		<form class="frm-form" method="post" accept-charset="utf-8" action="install.php">
       
   139 			<div class="hidden">
       
   140 				<input type="hidden" name="form_sent" value="1" />
       
   141 			</div>
       
   142 			<div class="frm-part part1">
       
   143 				<h3><span><?php echo $lang_install['Part1'] ?></span></h3>
       
   144 				<div class="frm-info">
       
   145 					<p><?php echo $lang_install['Part1 intro'] ?></p>
       
   146 					<ul class="pair">
       
   147 						<li><strong><?php echo $lang_install['Database type'] ?></strong> <span><?php echo $lang_install['Database type info'] ?><?php if ($dual_mysql) echo ' '.$lang_install['Mysql type info'] ?></span></li>
       
   148 						<li><strong><?php echo $lang_install['Database server'] ?></strong> <span><?php echo $lang_install['Database server info'] ?></span></li>
       
   149 						<li><strong><?php echo $lang_install['Database name'] ?></strong> <span><?php echo $lang_install['Database name info'] ?></span></li>
       
   150 						<li><strong><?php echo $lang_install['Database user pass'] ?></strong> <span><?php echo $lang_install['Database username info'] ?></span></li>
       
   151 						<li><strong><?php echo $lang_install['Table prefix'] ?></strong> <span><?php echo $lang_install['Table prefix info'] ?></span></li>
       
   152 					</ul>
       
   153 				</div>
       
   154 				<fieldset class="frm-set set1">
       
   155 					<legend class="frm-legend"><strong><?php echo $lang_install['Part1 legend'] ?></strong></legend>
       
   156 					<div class="frm-fld select required">
       
   157 						<label for="fld1">
       
   158 							<span class="fld-label"><?php echo $lang_install['Database type'] ?></span><br />
       
   159 							<span class="fld-input"><select id="fld1" name="req_db_type">
       
   160 <?php
       
   161 
       
   162 	foreach ($db_extensions as $db_type)
       
   163 		echo "\t\t\t\t\t\t\t".'<option value="'.$db_type[0].'">'.$db_type[1].'</option>'."\n";
       
   164 
       
   165 ?>
       
   166 							</select></span><br />
       
   167 							<em class="req-text"><?php echo $lang_install['Required'] ?></em>
       
   168 							<span class="fld-help"><?php echo $lang_install['Database type help'] ?></span>
       
   169 						</label>
       
   170 					</div>
       
   171 					<div class="frm-fld text required">
       
   172 						<label for="fld2">
       
   173 							<span class="fld-label"><?php echo $lang_install['Database server'] ?></span><br />
       
   174 							<span class="fld-input"><input id="fld2" type="text" name="req_db_host" value="localhost" size="50" maxlength="100" /></span><br />
       
   175 							<em class="req-text"><?php echo $lang_install['Required'] ?></em>
       
   176 							<span class="fld-help"><?php echo $lang_install['Database server help'] ?></span>
       
   177 						</label>
       
   178 					</div>
       
   179 					<div class="frm-fld text required">
       
   180 						<label for="req_db_name">
       
   181 							<span class="fld-label"><?php echo $lang_install['Database name'] ?></span><br />
       
   182 							<span class="fld-input"><input id="req_db_name" type="text" name="req_db_name" size="35" maxlength="50" /></span><br />
       
   183 							<em class="req-text"><?php echo $lang_install['Required'] ?></em>
       
   184 							<span class="fld-help"><?php echo $lang_install['Database name help'] ?></span>
       
   185 						</label>
       
   186 					</div>
       
   187 					<div class="frm-fld text">
       
   188 						<label for="fld3">
       
   189 							<span class="fld-label"><?php echo $lang_install['Database username'] ?></span><br />
       
   190 							<span class="fld-input"><input id="fld3" type="text" name="db_username" size="35" maxlength="50" /></span><br />
       
   191 							<span class="fld-help"><?php echo $lang_install['Database username help'] ?></span>
       
   192 						</label>
       
   193 					</div>
       
   194 					<div class="frm-fld text">
       
   195 						<label for="fld4">
       
   196 							<span class="fld-label"><?php echo $lang_install['Database password'] ?></span><br />
       
   197 							<span class="fld-input"><input id="fld4" type="text" name="db_password" size="35" maxlength="50" /></span><br />
       
   198 							<span class="fld-help"><?php echo $lang_install['Database password help'] ?></span>
       
   199 						</label>
       
   200 					</div>
       
   201 					<div class="frm-fld text">
       
   202 						<label for="fld5">
       
   203 							<span class="fld-label"><?php echo $lang_install['Table prefix'] ?></span><br />
       
   204 							<span class="fld-input"><input id="fld5" type="text" name="db_prefix" size="20" maxlength="30" /></span><br />
       
   205 							<span class="fld-help"><?php echo $lang_install['Table prefix help'] ?></span>
       
   206 						</label>
       
   207 					</div>
       
   208 				</fieldset>
       
   209 			</div>
       
   210 			<div class="frm-part part2">
       
   211 				<h3><span><?php echo $lang_install['Part2'] ?></span></h3>
       
   212 				<div class="frm-info">
       
   213 					<p><?php echo $lang_install['Part2 intro'] ?></p>
       
   214 					<ul class="pair">
       
   215 						<li><strong><?php echo $lang_install['Admin username'] ?></strong> <span><?php echo $lang_install['Admin username info'] ?></span></li>
       
   216 						<li><strong><?php echo $lang_install['Admin password'] ?></strong> <span><?php echo $lang_install['Admin password info'] ?></span></li>
       
   217 						<li><strong><?php echo $lang_install['Admin e-mail'] ?></strong> <span><?php echo $lang_install['Admin e-mail info'] ?></span></li>
       
   218 					</ul>
       
   219 				</div>
       
   220 				<fieldset class="frm-set set1">
       
   221 					<legend class="frm-legend"><strong><?php echo $lang_install['Part2 legend'] ?></strong></legend>
       
   222 					<div class="frm-fld text required">
       
   223 						<label for="fld6">
       
   224 							<span class="fld-label"><?php echo $lang_install['Username'] ?></span><br />
       
   225 							<span class="fld-input"><input type="text" name="req_username" size="35" maxlength="25" /></span><br />
       
   226 							<em class="req-text"><?php echo $lang_install['Required'] ?></em>
       
   227 							<span class="fld-help"><?php echo $lang_install['Username help'] ?></span>
       
   228 						</label>
       
   229 					</div>
       
   230 					<div class="frm-fld text required">
       
   231 						<label for="fld7">
       
   232 							<span class="fld-label"><?php echo $lang_install['Password'] ?></span><br />
       
   233 							<span class="fld-input"><input id="fld7" type="text" name="req_password1" size="35" /></span><br />
       
   234 							<em class="req-text"><?php echo $lang_install['Required'] ?></em>
       
   235 							<span class="fld-help"><?php echo $lang_install['Password help'] ?></span>
       
   236 						</label>
       
   237 					</div>
       
   238 					<div class="frm-fld text required">
       
   239 						<label for="fld8">
       
   240 							<span class="fld-label"><?php echo $lang_install['Admin confirm password'] ?></span><br />
       
   241 							<span class="fld-input"><input id="fld8" type="text" name="req_password2" size="35" /></span><br />
       
   242 							<em class="req-text"><?php echo $lang_install['Required'] ?></em>
       
   243 							<span class="fld-help"><?php echo $lang_install['Confirm password help'] ?></span>
       
   244 						</label>
       
   245 					</div>
       
   246 					<div class="frm-fld text required">
       
   247 						<label for="fld9">
       
   248 							<span class="fld-label"><?php echo $lang_install['E-mail address'] ?></span><br />
       
   249 							<span class="fld-input"><input id="fld9" type="text" name="req_email" size="50" maxlength="80" /></span><br />
       
   250 							<em class="req-text"><?php echo $lang_install['Required'] ?></em>
       
   251 							<span class="fld-help"><?php echo $lang_install['E-mail address help'] ?></span>
       
   252 						</label>
       
   253 					</div>
       
   254 				</fieldset>
       
   255 			</div>
       
   256 
       
   257 			<div class="frm-part part3">
       
   258 				<h3><span><?php echo $lang_install['Part3'] ?></span></h3>
       
   259 				<div class="frm-info">
       
   260 					<p><?php echo $lang_install['Part3 intro'] ?></p>
       
   261 					<ul class="pair">
       
   262 						<li><strong><?php echo $lang_install['Board title and desc'] ?></strong> <span><?php echo $lang_install['Board title info'] ?></span></li>
       
   263 						<li><strong><?php echo $lang_install['Base URL'] ?></strong> <span><?php echo $lang_install['Base URL info'] ?></span></li>
       
   264 					</ul>
       
   265 				</div>
       
   266 				<fieldset class="frm-set set1">
       
   267 					<legend class="frm-legend"><strong><?php echo $lang_install['Part3 legend'] ?></strong></legend>
       
   268 					<div class="frm-fld text">
       
   269 						<label for="fld10">
       
   270 							<span class="fld-label"><?php echo $lang_install['Board title'] ?></span><br />
       
   271 							<span class="fld-input"><input id="fld10" type="text" name="board_title" size="50" maxlength="255" /></span>
       
   272 						</label>
       
   273 					</div>
       
   274 					<div class="frm-fld text">
       
   275 						<label for="fld11">
       
   276 							<span class="fld-label"><?php echo $lang_install['Board description'] ?></span><br />
       
   277 							<span class="fld-input"><input id="fld11" type="text" name="board_descrip" size="50" maxlength="255" /></span>
       
   278 						</label>
       
   279 					</div>
       
   280 					<div class="frm-fld text required">
       
   281 						<label for="fld12">
       
   282 							<span class="fld-label"><?php echo $lang_install['Base URL'] ?></span><br />
       
   283 							<span class="fld-input"><input id="fld12" type="text" name="req_base_url" value="<?php echo ((isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on') ? 'https://' : 'http://').preg_replace('/:80$/', '', $_SERVER['HTTP_HOST']).str_replace('\\', '/', dirname($_SERVER['SCRIPT_NAME'])) ?>" size="60" maxlength="100" /></span><br />
       
   284 							<em class="req-text"><?php echo $lang_install['Required'] ?></em>
       
   285 							<span class="fld-help"><?php echo $lang_install['Base URL help'] ?></span>
       
   286 						</label>
       
   287 					</div>
       
   288 				</fieldset>
       
   289 			</div>
       
   290 			<div class="frm-buttons">
       
   291 				<span class="submit"><input type="submit" name="start" value="Start install" /></span>
       
   292 			</div>
       
   293 		</form>
       
   294 	</div>
       
   295 </div>
       
   296 
       
   297 </div>
       
   298 </div>
       
   299 </body>
       
   300 </html>
       
   301 <?php
       
   302 
       
   303 }
       
   304 else
       
   305 {
       
   306 	//
       
   307 	// Strip slashes only if magic_quotes_gpc is on.
       
   308 	//
       
   309 	function unescape($str)
       
   310 	{
       
   311 		return (get_magic_quotes_gpc() == 1) ? stripslashes($str) : $str;
       
   312 	}
       
   313 
       
   314 
       
   315 	$db_type = $_POST['req_db_type'];
       
   316 	$db_host = trim($_POST['req_db_host']);
       
   317 	$db_name = trim($_POST['req_db_name']);
       
   318 	$db_username = unescape(trim($_POST['db_username']));
       
   319 	$db_password = unescape(trim($_POST['db_password']));
       
   320 	$db_prefix = trim($_POST['db_prefix']);
       
   321 	$username = unescape(trim($_POST['req_username']));
       
   322 	$email = unescape(strtolower(trim($_POST['req_email'])));
       
   323 	$password1 = unescape(trim($_POST['req_password1']));
       
   324 	$password2 = unescape(trim($_POST['req_password2']));
       
   325 	$board_title = unescape(trim($_POST['board_title']));
       
   326 	$board_descrip = unescape(trim($_POST['board_descrip']));
       
   327 
       
   328 
       
   329 	// Make sure base_url doesn't end with a slash
       
   330 	if (substr($_POST['req_base_url'], -1) == '/')
       
   331 		$base_url = substr($_POST['req_base_url'], 0, -1);
       
   332 	else
       
   333 		$base_url = $_POST['req_base_url'];
       
   334 
       
   335 	// Validate form
       
   336 	if (pun_strlen($db_name) == 0)
       
   337 		error('You must enter a database name. Please go back and correct.');
       
   338 	if (pun_strlen($username) < 2)
       
   339 		error('Usernames must be at least 2 characters long. Please go back and correct.');
       
   340 	if (pun_strlen($password1) < 4)
       
   341 		error('Passwords must be at least 4 characters long. Please go back and correct.');
       
   342 	if ($password1 != $password2)
       
   343 		error('Passwords do not match. Please go back and correct.');
       
   344 	if (strtolower($username) == 'guest')
       
   345 		error('The username guest is reserved. Please go back and correct.');
       
   346 	if (preg_match('/[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}/', $username))
       
   347 		error('Usernames may not be in the form of an IP address. Please go back and correct.');
       
   348 	if (preg_match('#\[b\]|\[/b\]|\[u\]|\[/u\]|\[i\]|\[/i\]|\[color|\[/color\]|\[quote\]|\[/quote\]|\[code\]|\[/code\]|\[img\]|\[/img\]|\[url|\[/url\]|\[email|\[/email\]#i', $username))
       
   349 		error('Usernames may not contain any of the text formatting tags (BBCode) that the forum uses. Please go back and correct.');
       
   350 
       
   351 	// Validate email
       
   352 	if (strlen($email) > 80 || !preg_match('/^(([^<>()[\]\\.,;:\s@"\']+(\.[^<>()[\]\\.,;:\s@"\']+)*)|("[^"\']+"))@((\[\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}\])|(([a-zA-Z\d\-]+\.)+[a-zA-Z]{2,}))$/', $email))
       
   353 		error('The administrator e-mail address you entered is invalid. Please go back and correct.');
       
   354 
       
   355 	// Make sure board title and description aren't left blank
       
   356 	if ($board_title == '')
       
   357 		$board_title = 'My PunBB forum';
       
   358 	if ($board_descrip == '')
       
   359 		$board_descrip = 'Unfortunately no one can be told what PunBB is - you have to see it for yourself.';
       
   360 
       
   361 	if (pun_strlen($base_url) == 0)
       
   362 		error('You must enter a base URL. Please go back and correct.');
       
   363 
       
   364 
       
   365 	// Load the appropriate DB layer class
       
   366 	switch ($db_type)
       
   367 	{
       
   368 		case 'mysql':
       
   369 			require PUN_ROOT.'include/dblayer/mysql.php';
       
   370 			break;
       
   371 
       
   372 		case 'mysqli':
       
   373 			require PUN_ROOT.'include/dblayer/mysqli.php';
       
   374 			break;
       
   375 
       
   376 		case 'pgsql':
       
   377 			require PUN_ROOT.'include/dblayer/pgsql.php';
       
   378 			break;
       
   379 
       
   380 		case 'sqlite':
       
   381 			require PUN_ROOT.'include/dblayer/sqlite.php';
       
   382 			break;
       
   383 
       
   384 		default:
       
   385 			error('\''.$db_type.'\' is not a valid database type.');
       
   386 	}
       
   387 
       
   388 	// Create the database object (and connect/select db)
       
   389 	$pun_db = new DBLayer($db_host, $db_username, $db_password, $db_name, $db_prefix, false);
       
   390 
       
   391 
       
   392 	// If MySQL, make sure it's at least 4.1.2
       
   393 	if ($db_type == 'mysql' || $db_type == 'mysqli')
       
   394 	{
       
   395 		$result = $pun_db->query('SELECT VERSION()') or error(__FILE__, __LINE__);
       
   396 		$mysql_version = $pun_db->result($result);
       
   397 		if (version_compare($mysql_version, MIN_MYSQL_VERSION, '<'))
       
   398 			error('You are running MySQL version '.$mysql_version.'. PunBB requires at least MySQL '.MIN_MYSQL_VERSION.' to run properly. You must upgrade your MySQL installation before you can continue.');
       
   399 	}
       
   400 
       
   401 	// Validate prefix
       
   402 	if (strlen($db_prefix) > 0 && (!preg_match('/^[a-zA-Z_][a-zA-Z0-9_]*$/', $db_prefix) || strlen($db_prefix) > 40))
       
   403 		error('The table prefix \''.$db_prefix.'\' contains illegal characters or is too long. The prefix may contain the letters a to z, any numbers and the underscore character. They must however not start with a number. The maximum length is 40 characters. Please choose a different prefix.');
       
   404 
       
   405 	// Check SQLite prefix collision
       
   406 	if ($db_type == 'sqlite' && strtolower($db_prefix) == 'sqlite_')
       
   407 		error('The table prefix \'sqlite_\' is reserved for use by the SQLite engine. Please choose a different prefix.');
       
   408 
       
   409 
       
   410 	// Make sure PunBB isn't already installed
       
   411 	$result = $pun_db->query('SELECT 1 FROM '.$db_prefix.'users WHERE id=1');
       
   412 	if ($pun_db->num_rows($result))
       
   413 		error('A table called "'.$db_prefix.'users" is already present in the database "'.$db_name.'". This could mean that PunBB is already installed or that another piece of software is installed and is occupying one or more of the table names PunBB requires. If you want to install multiple copies of PunBB in the same database, you must choose a different table prefix.');
       
   414 
       
   415 
       
   416 	// Create all tables
       
   417 	switch ($db_type)
       
   418 	{
       
   419 		case 'mysql':
       
   420 		case 'mysqli':
       
   421 			$sql = 'CREATE TABLE '.$db_prefix."bans (
       
   422 					id INT(10) UNSIGNED NOT NULL AUTO_INCREMENT,
       
   423 					username VARCHAR(200),
       
   424 					ip VARCHAR(255),
       
   425 					email VARCHAR(80),
       
   426 					message VARCHAR(255),
       
   427 					expire INT(10) UNSIGNED,
       
   428 					ban_creator INT(10) UNSIGNED NOT NULL DEFAULT 0,
       
   429 					PRIMARY KEY (id)
       
   430 					) ENGINE = MyISAM CHARACTER SET utf8";
       
   431 			break;
       
   432 
       
   433 		case 'pgsql':
       
   434 			$pun_db->start_transaction();
       
   435 
       
   436 			$sql = 'CREATE TABLE '.$db_prefix."bans (
       
   437 					id SERIAL,
       
   438 					username VARCHAR(200),
       
   439 					ip VARCHAR(255),
       
   440 					email VARCHAR(80),
       
   441 					message VARCHAR(255),
       
   442 					expire INT,
       
   443 					ban_creator INT NOT NULL DEFAULT 0,
       
   444 					PRIMARY KEY (id)
       
   445 					)";
       
   446 			break;
       
   447 
       
   448 		case 'sqlite':
       
   449 			$pun_db->start_transaction();
       
   450 
       
   451 			$sql = 'CREATE TABLE '.$db_prefix."bans (
       
   452 					id INTEGER NOT NULL,
       
   453 					username VARCHAR(200),
       
   454 					ip  VARCHAR(255),
       
   455 					email VARCHAR(80),
       
   456 					message VARCHAR(255),
       
   457 					expire INTEGER,
       
   458 					ban_creator INTEGER NOT NULL DEFAULT 0,
       
   459 					PRIMARY KEY (id)
       
   460 					)";
       
   461 			break;
       
   462 
       
   463 	}
       
   464 
       
   465 	$pun_db->query($sql) or error(__FILE__, __LINE__);
       
   466 
       
   467 
       
   468 	switch ($db_type)
       
   469 	{
       
   470 		case 'mysql':
       
   471 		case 'mysqli':
       
   472 			$sql = 'CREATE TABLE '.$db_prefix."categories (
       
   473 					id INT(10) UNSIGNED NOT NULL AUTO_INCREMENT,
       
   474 					cat_name VARCHAR(80) NOT NULL DEFAULT 'New Category',
       
   475 					disp_position INT(10) NOT NULL DEFAULT 0,
       
   476 					PRIMARY KEY (id)
       
   477 					) ENGINE = MyISAM CHARACTER SET utf8";
       
   478 			break;
       
   479 
       
   480 		case 'pgsql':
       
   481 			$sql = 'CREATE TABLE '.$db_prefix."categories (
       
   482 					id SERIAL,
       
   483 					cat_name VARCHAR(80) NOT NULL DEFAULT 'New Category',
       
   484 					disp_position INT NOT NULL DEFAULT 0,
       
   485 					PRIMARY KEY (id)
       
   486 					)";
       
   487 			break;
       
   488 
       
   489 		case 'sqlite':
       
   490 			$sql = 'CREATE TABLE '.$db_prefix."categories (
       
   491 					id INTEGER NOT NULL,
       
   492 					cat_name VARCHAR(80) NOT NULL DEFAULT 'New Category',
       
   493 					disp_position INTEGER NOT NULL DEFAULT 0,
       
   494 					PRIMARY KEY (id)
       
   495 					)";
       
   496 			break;
       
   497 	}
       
   498 
       
   499 	$pun_db->query($sql) or error(__FILE__, __LINE__);
       
   500 
       
   501 
       
   502 
       
   503 	switch ($db_type)
       
   504 	{
       
   505 		case 'mysql':
       
   506 		case 'mysqli':
       
   507 			$sql = 'CREATE TABLE '.$db_prefix."censoring (
       
   508 					id INT(10) UNSIGNED NOT NULL AUTO_INCREMENT,
       
   509 					search_for VARCHAR(60) NOT NULL DEFAULT '',
       
   510 					replace_with VARCHAR(60) NOT NULL DEFAULT '',
       
   511 					PRIMARY KEY (id)
       
   512 					) ENGINE = MyISAM CHARACTER SET utf8";
       
   513 			break;
       
   514 
       
   515 		case 'pgsql':
       
   516 			$sql = 'CREATE TABLE '.$db_prefix."censoring (
       
   517 					id SERIAL,
       
   518 					search_for VARCHAR(60) NOT NULL DEFAULT '',
       
   519 					replace_with VARCHAR(60) NOT NULL DEFAULT '',
       
   520 					PRIMARY KEY (id)
       
   521 					)";
       
   522 			break;
       
   523 
       
   524 		case 'sqlite':
       
   525 			$sql = 'CREATE TABLE '.$db_prefix."censoring (
       
   526 					id INTEGER NOT NULL,
       
   527 					search_for VARCHAR(60) NOT NULL DEFAULT '',
       
   528 					replace_with VARCHAR(60) NOT NULL DEFAULT '',
       
   529 					PRIMARY KEY (id)
       
   530 					)";
       
   531 			break;
       
   532 	}
       
   533 
       
   534 	$pun_db->query($sql) or error(__FILE__, __LINE__);
       
   535 
       
   536 
       
   537 
       
   538 	switch ($db_type)
       
   539 	{
       
   540 		case 'mysql':
       
   541 		case 'mysqli':
       
   542 			$sql = 'CREATE TABLE '.$db_prefix."config (
       
   543 					conf_name VARCHAR(255) NOT NULL DEFAULT '',
       
   544 					conf_value TEXT,
       
   545 					PRIMARY KEY (conf_name)
       
   546 					) ENGINE = MyISAM CHARACTER SET utf8";
       
   547 			break;
       
   548 
       
   549 		case 'pgsql':
       
   550 			$sql = 'CREATE TABLE '.$db_prefix."config (
       
   551 					conf_name VARCHAR(255) NOT NULL DEFAULT '',
       
   552 					conf_value TEXT,
       
   553 					PRIMARY KEY (conf_name)
       
   554 					)";
       
   555 			break;
       
   556 
       
   557 		case 'sqlite':
       
   558 			$sql = 'CREATE TABLE '.$db_prefix."config (
       
   559 					conf_name VARCHAR(255) NOT NULL DEFAULT '',
       
   560 					conf_value TEXT,
       
   561 					PRIMARY KEY (conf_name)
       
   562 					)";
       
   563 			break;
       
   564 	}
       
   565 
       
   566 	$pun_db->query($sql) or error(__FILE__, __LINE__);
       
   567 
       
   568 
       
   569 
       
   570 	switch ($db_type)
       
   571 	{
       
   572 		case 'mysql':
       
   573 		case 'mysqli':
       
   574 			$sql = 'CREATE TABLE '.$db_prefix."extensions (
       
   575 					id VARCHAR(50) NOT NULL DEFAULT '',
       
   576 					title VARCHAR(255) NOT NULL DEFAULT '',
       
   577 					version VARCHAR(25) NOT NULL DEFAULT '',
       
   578 					description TEXT,
       
   579 					author VARCHAR(50) NOT NULL DEFAULT '',
       
   580 					uninstall TEXT,
       
   581 					uninstall_note TEXT,
       
   582 					disabled TINYINT(1) NOT NULL DEFAULT 0,
       
   583 					PRIMARY KEY(id)
       
   584 					) ENGINE = MyISAM CHARACTER SET utf8";
       
   585 			break;
       
   586 
       
   587 		case 'pgsql':
       
   588 			$sql = 'CREATE TABLE '.$db_prefix."extensions (
       
   589 					id VARCHAR(50) NOT NULL DEFAULT '',
       
   590 					title VARCHAR(255) NOT NULL DEFAULT '',
       
   591 					version VARCHAR(25) NOT NULL DEFAULT '',
       
   592 					description TEXT,
       
   593 					author VARCHAR(50) NOT NULL DEFAULT '',
       
   594 					uninstall TEXT,
       
   595 					uninstall_note TEXT,
       
   596 					disabled SMALLINT NOT NULL DEFAULT 0,
       
   597 					PRIMARY KEY(id)
       
   598 					)";
       
   599 			break;
       
   600 
       
   601 		case 'sqlite':
       
   602 			$sql = 'CREATE TABLE '.$db_prefix."extensions (
       
   603 					id VARCHAR(50) NOT NULL DEFAULT '',
       
   604 					title VARCHAR(255) NOT NULL DEFAULT '',
       
   605 					version VARCHAR(25) NOT NULL DEFAULT '',
       
   606 					description TEXT,
       
   607 					author VARCHAR(50) NOT NULL DEFAULT '',
       
   608 					uninstall TEXT,
       
   609 					uninstall_note TEXT,
       
   610 					disabled INTEGER NOT NULL DEFAULT 0,
       
   611 					PRIMARY KEY(id)
       
   612 					)";
       
   613 			break;
       
   614 	}
       
   615 
       
   616 	$pun_db->query($sql) or error(__FILE__, __LINE__);
       
   617 
       
   618 
       
   619 
       
   620 	switch ($db_type)
       
   621 	{
       
   622 		case 'mysql':
       
   623 		case 'mysqli':
       
   624 			$sql = 'CREATE TABLE '.$db_prefix."extension_hooks (
       
   625 					id VARCHAR(50) NOT NULL DEFAULT '',
       
   626 					extension_id VARCHAR(50) NOT NULL DEFAULT '',
       
   627 					code TEXT,
       
   628 					installed INT(10) UNSIGNED NOT NULL DEFAULT 0,
       
   629 					PRIMARY KEY(id, extension_id)
       
   630 					) ENGINE = MyISAM CHARACTER SET utf8";
       
   631 			break;
       
   632 
       
   633 		case 'pgsql':
       
   634 			$sql = 'CREATE TABLE '.$db_prefix."extension_hooks (
       
   635 					id VARCHAR(50) NOT NULL DEFAULT '',
       
   636 					extension_id VARCHAR(50) NOT NULL DEFAULT '',
       
   637 					code TEXT,
       
   638 					installed INT NOT NULL DEFAULT 0,
       
   639 					PRIMARY KEY(id, extension_id)
       
   640 					)";
       
   641 			break;
       
   642 
       
   643 		case 'sqlite':
       
   644 			$sql = 'CREATE TABLE '.$db_prefix."extension_hooks (
       
   645 					id VARCHAR(50) NOT NULL DEFAULT '',
       
   646 					extension_id VARCHAR(50) NOT NULL DEFAULT '',
       
   647 					code TEXT,
       
   648 					installed INTEGER NOT NULL DEFAULT 0,
       
   649 					PRIMARY KEY(id, extension_id)
       
   650 					)";
       
   651 			break;
       
   652 	}
       
   653 
       
   654 	$pun_db->query($sql) or error(__FILE__, __LINE__);
       
   655 
       
   656 
       
   657 
       
   658 	switch ($db_type)
       
   659 	{
       
   660 		case 'mysql':
       
   661 		case 'mysqli':
       
   662 			$sql = 'CREATE TABLE '.$db_prefix."forum_perms (
       
   663 					group_id INT(10) NOT NULL DEFAULT 0,
       
   664 					forum_id INT(10) NOT NULL DEFAULT 0,
       
   665 					read_forum TINYINT(1) NOT NULL DEFAULT 1,
       
   666 					post_replies TINYINT(1) NOT NULL DEFAULT 1,
       
   667 					post_topics TINYINT(1) NOT NULL DEFAULT 1,
       
   668 					PRIMARY KEY (group_id, forum_id)
       
   669 					) ENGINE = MyISAM CHARACTER SET utf8";
       
   670 			break;
       
   671 
       
   672 		case 'pgsql':
       
   673 			$sql = 'CREATE TABLE '.$db_prefix."forum_perms (
       
   674 					group_id INT NOT NULL DEFAULT 0,
       
   675 					forum_id INT NOT NULL DEFAULT 0,
       
   676 					read_forum SMALLINT NOT NULL DEFAULT 1,
       
   677 					post_replies SMALLINT NOT NULL DEFAULT 1,
       
   678 					post_topics SMALLINT NOT NULL DEFAULT 1,
       
   679 					PRIMARY KEY (group_id, forum_id)
       
   680 					)";
       
   681 			break;
       
   682 
       
   683 		case 'sqlite':
       
   684 			$sql = 'CREATE TABLE '.$db_prefix."forum_perms (
       
   685 					group_id INTEGER NOT NULL DEFAULT 0,
       
   686 					forum_id INTEGER NOT NULL DEFAULT 0,
       
   687 					read_forum INTEGER NOT NULL DEFAULT 1,
       
   688 					post_replies INTEGER NOT NULL DEFAULT 1,
       
   689 					post_topics INTEGER NOT NULL DEFAULT 1,
       
   690 					PRIMARY KEY (group_id, forum_id)
       
   691 					)";
       
   692 			break;
       
   693 	}
       
   694 
       
   695 	$pun_db->query($sql) or error(__FILE__, __LINE__);
       
   696 
       
   697 
       
   698 
       
   699 	switch ($db_type)
       
   700 	{
       
   701 		case 'mysql':
       
   702 		case 'mysqli':
       
   703 			$sql = 'CREATE TABLE '.$db_prefix."forums (
       
   704 					id INT(10) UNSIGNED NOT NULL AUTO_INCREMENT,
       
   705 					forum_name VARCHAR(80) NOT NULL DEFAULT 'New forum',
       
   706 					forum_desc TEXT,
       
   707 					redirect_url VARCHAR(100),
       
   708 					moderators TEXT,
       
   709 					num_topics MEDIUMINT(8) UNSIGNED NOT NULL DEFAULT 0,
       
   710 					num_posts MEDIUMINT(8) UNSIGNED NOT NULL DEFAULT 0,
       
   711 					last_post INT(10) UNSIGNED,
       
   712 					last_post_id INT(10) UNSIGNED,
       
   713 					last_poster VARCHAR(200),
       
   714 					sort_by TINYINT(1) NOT NULL DEFAULT 0,
       
   715 					disp_position INT(10) NOT NULL DEFAULT 0,
       
   716 					cat_id INT(10) UNSIGNED NOT NULL DEFAULT 0,
       
   717 					PRIMARY KEY (id)
       
   718 					) ENGINE = MyISAM CHARACTER SET utf8";
       
   719 			break;
       
   720 
       
   721 		case 'pgsql':
       
   722 			$sql = 'CREATE TABLE '.$db_prefix."forums (
       
   723 					id SERIAL,
       
   724 					forum_name VARCHAR(80) NOT NULL DEFAULT 'New forum',
       
   725 					forum_desc TEXT,
       
   726 					redirect_url VARCHAR(100),
       
   727 					moderators TEXT,
       
   728 					num_topics INT NOT NULL DEFAULT 0,
       
   729 					num_posts INT NOT NULL DEFAULT 0,
       
   730 					last_post INT,
       
   731 					last_post_id INT,
       
   732 					last_poster VARCHAR(200),
       
   733 					sort_by SMALLINT NOT NULL DEFAULT 0,
       
   734 					disp_position INT NOT NULL DEFAULT 0,
       
   735 					cat_id INT NOT NULL DEFAULT 0,
       
   736 					PRIMARY KEY (id)
       
   737 					)";
       
   738 			break;
       
   739 
       
   740 		case 'sqlite':
       
   741 			$sql = 'CREATE TABLE '.$db_prefix."forums (
       
   742 					id INTEGER NOT NULL,
       
   743 					forum_name VARCHAR(80) NOT NULL DEFAULT 'New forum',
       
   744 					forum_desc TEXT,
       
   745 					redirect_url VARCHAR(100),
       
   746 					moderators TEXT,
       
   747 					num_topics INTEGER NOT NULL DEFAULT 0,
       
   748 					num_posts INTEGER NOT NULL DEFAULT 0,
       
   749 					last_post INTEGER,
       
   750 					last_post_id INTEGER,
       
   751 					last_poster VARCHAR(200),
       
   752 					sort_by INTEGER NOT NULL DEFAULT 0,
       
   753 					disp_position INTEGER NOT NULL DEFAULT 0,
       
   754 					cat_id INTEGER NOT NULL DEFAULT 0,
       
   755 					PRIMARY KEY (id)
       
   756 					)";
       
   757 			break;
       
   758 	}
       
   759 
       
   760 	$pun_db->query($sql) or error(__FILE__, __LINE__);
       
   761 
       
   762 
       
   763 
       
   764 	switch ($db_type)
       
   765 	{
       
   766 		case 'mysql':
       
   767 		case 'mysqli':
       
   768 			$sql = 'CREATE TABLE '.$db_prefix."groups (
       
   769 					g_id INT(10) UNSIGNED NOT NULL AUTO_INCREMENT,
       
   770 					g_title VARCHAR(50) NOT NULL DEFAULT '',
       
   771 					g_user_title VARCHAR(50),
       
   772 					g_moderator TINYINT(1) NOT NULL DEFAULT 0,
       
   773 					g_mod_edit_users TINYINT(1) NOT NULL DEFAULT 0,
       
   774 					g_mod_rename_users TINYINT(1) NOT NULL DEFAULT 0,
       
   775 					g_mod_change_passwords TINYINT(1) NOT NULL DEFAULT 0,
       
   776 					g_mod_ban_users TINYINT(1) NOT NULL DEFAULT 0,
       
   777 					g_read_board TINYINT(1) NOT NULL DEFAULT 1,
       
   778 					g_view_users TINYINT(1) NOT NULL DEFAULT 1,
       
   779 					g_post_replies TINYINT(1) NOT NULL DEFAULT 1,
       
   780 					g_post_topics TINYINT(1) NOT NULL DEFAULT 1,
       
   781 					g_edit_posts TINYINT(1) NOT NULL DEFAULT 1,
       
   782 					g_delete_posts TINYINT(1) NOT NULL DEFAULT 1,
       
   783 					g_delete_topics TINYINT(1) NOT NULL DEFAULT 1,
       
   784 					g_set_title TINYINT(1) NOT NULL DEFAULT 1,
       
   785 					g_search TINYINT(1) NOT NULL DEFAULT 1,
       
   786 					g_search_users TINYINT(1) NOT NULL DEFAULT 1,
       
   787 					g_edit_subjects_interval SMALLINT(6) NOT NULL DEFAULT 300,
       
   788 					g_post_flood SMALLINT(6) NOT NULL DEFAULT 30,
       
   789 					g_search_flood SMALLINT(6) NOT NULL DEFAULT 30,
       
   790 					PRIMARY KEY (g_id)
       
   791 					) ENGINE = MyISAM CHARACTER SET utf8";
       
   792 			break;
       
   793 
       
   794 		case 'pgsql':
       
   795 			$sql = 'CREATE TABLE '.$db_prefix."groups (
       
   796 					g_id SERIAL,
       
   797 					g_title VARCHAR(50) NOT NULL DEFAULT '',
       
   798 					g_user_title VARCHAR(50),
       
   799 					g_moderator SMALLINT NOT NULL DEFAULT 0,
       
   800 					g_mod_edit_users SMALLINT NOT NULL DEFAULT 0,
       
   801 					g_mod_rename_users SMALLINT NOT NULL DEFAULT 0,
       
   802 					g_mod_change_passwords SMALLINT NOT NULL DEFAULT 0,
       
   803 					g_mod_ban_users SMALLINT NOT NULL DEFAULT 0,
       
   804 					g_read_board SMALLINT NOT NULL DEFAULT 1,
       
   805 					g_view_users SMALLINT NOT NULL DEFAULT 1,
       
   806 					g_post_replies SMALLINT NOT NULL DEFAULT 1,
       
   807 					g_post_topics SMALLINT NOT NULL DEFAULT 1,
       
   808 					g_edit_posts SMALLINT NOT NULL DEFAULT 1,
       
   809 					g_delete_posts SMALLINT NOT NULL DEFAULT 1,
       
   810 					g_delete_topics SMALLINT NOT NULL DEFAULT 1,
       
   811 					g_set_title SMALLINT NOT NULL DEFAULT 1,
       
   812 					g_search SMALLINT NOT NULL DEFAULT 1,
       
   813 					g_search_users SMALLINT NOT NULL DEFAULT 1,
       
   814 					g_edit_subjects_interval SMALLINT NOT NULL DEFAULT 300,
       
   815 					g_post_flood SMALLINT NOT NULL DEFAULT 30,
       
   816 					g_search_flood SMALLINT NOT NULL DEFAULT 30,
       
   817 					PRIMARY KEY (g_id)
       
   818 					)";
       
   819 			break;
       
   820 
       
   821 		case 'sqlite':
       
   822 			$sql = 'CREATE TABLE '.$db_prefix."groups (
       
   823 					g_id INTEGER NOT NULL,
       
   824 					g_title VARCHAR(50) NOT NULL DEFAULT '',
       
   825 					g_user_title VARCHAR(50),
       
   826 					g_moderator INTEGER NOT NULL DEFAULT 0,
       
   827 					g_mod_edit_users INTEGER NOT NULL DEFAULT 0,
       
   828 					g_mod_rename_users INTEGER NOT NULL DEFAULT 0,
       
   829 					g_mod_change_passwords INTEGER NOT NULL DEFAULT 0,
       
   830 					g_mod_ban_users INTEGER NOT NULL DEFAULT 0,
       
   831 					g_read_board INTEGER NOT NULL DEFAULT 1,
       
   832 					g_view_users INTEGER NOT NULL DEFAULT 1,
       
   833 					g_post_replies INTEGER NOT NULL DEFAULT 1,
       
   834 					g_post_topics INTEGER NOT NULL DEFAULT 1,
       
   835 					g_edit_posts INTEGER NOT NULL DEFAULT 1,
       
   836 					g_delete_posts INTEGER NOT NULL DEFAULT 1,
       
   837 					g_delete_topics INTEGER NOT NULL DEFAULT 1,
       
   838 					g_set_title INTEGER NOT NULL DEFAULT 1,
       
   839 					g_search INTEGER NOT NULL DEFAULT 1,
       
   840 					g_search_users INTEGER NOT NULL DEFAULT 1,
       
   841 					g_edit_subjects_interval INTEGER NOT NULL DEFAULT 300,
       
   842 					g_post_flood INTEGER NOT NULL DEFAULT 30,
       
   843 					g_search_flood INTEGER NOT NULL DEFAULT 30,
       
   844 					PRIMARY KEY (g_id)
       
   845 					)";
       
   846 			break;
       
   847 	}
       
   848 
       
   849 	$pun_db->query($sql) or error(__FILE__, __LINE__);
       
   850 
       
   851 
       
   852 
       
   853 	switch ($db_type)
       
   854 	{
       
   855 		case 'mysql':
       
   856 		case 'mysqli':
       
   857 			$sql = 'CREATE TABLE '.$db_prefix."online (
       
   858 					user_id INT(10) UNSIGNED NOT NULL DEFAULT 1,
       
   859 					ident VARCHAR(200) NOT NULL DEFAULT '',
       
   860 					logged INT(10) UNSIGNED NOT NULL DEFAULT 0,
       
   861 					idle TINYINT(1) NOT NULL DEFAULT 0,
       
   862 					csrf_token VARCHAR(40) NOT NULL DEFAULT '',
       
   863 					prev_url VARCHAR(255)
       
   864 					) TYPE=HEAP;";
       
   865 			break;
       
   866 
       
   867 		case 'pgsql':
       
   868 			$sql = 'CREATE TABLE '.$db_prefix."online (
       
   869 					user_id INT NOT NULL DEFAULT 1,
       
   870 					ident VARCHAR(200) NOT NULL DEFAULT '',
       
   871 					logged INT NOT NULL DEFAULT 0,
       
   872 					idle SMALLINT NOT NULL DEFAULT 0,
       
   873 					csrf_token VARCHAR(40) NOT NULL DEFAULT '',
       
   874 					prev_url VARCHAR(255)
       
   875 					)";
       
   876 			break;
       
   877 
       
   878 		case 'sqlite':
       
   879 			$sql = 'CREATE TABLE '.$db_prefix."online (
       
   880 					user_id INTEGER NOT NULL DEFAULT 1,
       
   881 					ident VARCHAR(200) NOT NULL DEFAULT '',
       
   882 					logged INTEGER NOT NULL DEFAULT 0,
       
   883 					idle INTEGER NOT NULL DEFAULT 0,
       
   884 					csrf_token VARCHAR(40) NOT NULL DEFAULT '',
       
   885 					prev_url VARCHAR(255)
       
   886 					)";
       
   887 			break;
       
   888 	}
       
   889 
       
   890 	$pun_db->query($sql) or error(__FILE__, __LINE__);
       
   891 
       
   892 
       
   893 
       
   894 	switch ($db_type)
       
   895 	{
       
   896 		case 'mysql':
       
   897 		case 'mysqli':
       
   898 			$sql = 'CREATE TABLE '.$db_prefix."posts (
       
   899 					id INT(10) UNSIGNED NOT NULL AUTO_INCREMENT,
       
   900 					poster VARCHAR(200) NOT NULL DEFAULT '',
       
   901 					poster_id INT(10) UNSIGNED NOT NULL DEFAULT 1,
       
   902 					poster_ip VARCHAR(15),
       
   903 					poster_email VARCHAR(80),
       
   904 					message TEXT,
       
   905 					hide_smilies TINYINT(1) NOT NULL DEFAULT 0,
       
   906 					posted INT(10) UNSIGNED NOT NULL DEFAULT 0,
       
   907 					edited INT(10) UNSIGNED,
       
   908 					edited_by VARCHAR(200),
       
   909 					topic_id INT(10) UNSIGNED NOT NULL DEFAULT 0,
       
   910 					PRIMARY KEY (id)
       
   911 					) ENGINE = MyISAM CHARACTER SET utf8";
       
   912 			break;
       
   913 
       
   914 		case 'pgsql':
       
   915 			$sql = 'CREATE TABLE '.$db_prefix."posts (
       
   916 					id SERIAL,
       
   917 					poster VARCHAR(200) NOT NULL DEFAULT '',
       
   918 					poster_id INT NOT NULL DEFAULT 1,
       
   919 					poster_ip VARCHAR(15),
       
   920 					poster_email VARCHAR(80),
       
   921 					message TEXT,
       
   922 					hide_smilies SMALLINT NOT NULL DEFAULT 0,
       
   923 					posted INT NOT NULL DEFAULT 0,
       
   924 					edited INT,
       
   925 					edited_by VARCHAR(200),
       
   926 					topic_id INT NOT NULL DEFAULT 0,
       
   927 					PRIMARY KEY (id)
       
   928 					)";
       
   929 			break;
       
   930 
       
   931 		case 'sqlite':
       
   932 			$sql = 'CREATE TABLE '.$db_prefix."posts (
       
   933 					id INTEGER NOT NULL,
       
   934 					poster VARCHAR(200) NOT NULL DEFAULT '',
       
   935 					poster_id INTEGER NOT NULL DEFAULT 1,
       
   936 					poster_ip VARCHAR(15),
       
   937 					poster_email VARCHAR(80),
       
   938 					message TEXT,
       
   939 					hide_smilies INTEGER NOT NULL DEFAULT 0,
       
   940 					posted INTEGER NOT NULL DEFAULT 0,
       
   941 					edited INTEGER,
       
   942 					edited_by VARCHAR(200),
       
   943 					topic_id INTEGER NOT NULL DEFAULT 0,
       
   944 					PRIMARY KEY (id)
       
   945 					)";
       
   946 			break;
       
   947 	}
       
   948 
       
   949 	$pun_db->query($sql) or error(__FILE__, __LINE__);
       
   950 
       
   951 
       
   952 
       
   953 	switch ($db_type)
       
   954 	{
       
   955 		case 'mysql':
       
   956 		case 'mysqli':
       
   957 			$sql = 'CREATE TABLE '.$db_prefix."ranks (
       
   958 					id INT(10) UNSIGNED NOT NULL AUTO_INCREMENT,
       
   959 					rank VARCHAR(50) NOT NULL DEFAULT '',
       
   960 					min_posts MEDIUMINT(8) UNSIGNED NOT NULL DEFAULT 0,
       
   961 					PRIMARY KEY (id)
       
   962 					) ENGINE = MyISAM CHARACTER SET utf8";
       
   963 			break;
       
   964 
       
   965 		case 'pgsql':
       
   966 			$sql = 'CREATE TABLE '.$db_prefix."ranks (
       
   967 					id SERIAL,
       
   968 					rank VARCHAR(50) NOT NULL DEFAULT '',
       
   969 					min_posts INT NOT NULL DEFAULT 0,
       
   970 					PRIMARY KEY (id)
       
   971 					)";
       
   972 			break;
       
   973 
       
   974 		case 'sqlite':
       
   975 			$sql = 'CREATE TABLE '.$db_prefix."ranks (
       
   976 					id INTEGER NOT NULL,
       
   977 					rank VARCHAR(50) NOT NULL DEFAULT '',
       
   978 					min_posts INTEGER NOT NULL DEFAULT 0,
       
   979 					PRIMARY KEY (id)
       
   980 					)";
       
   981 			break;
       
   982 	}
       
   983 
       
   984 	$pun_db->query($sql) or error(__FILE__, __LINE__);
       
   985 
       
   986 
       
   987 
       
   988 	switch ($db_type)
       
   989 	{
       
   990 		case 'mysql':
       
   991 		case 'mysqli':
       
   992 			$sql = 'CREATE TABLE '.$db_prefix."reports (
       
   993 					id INT(10) UNSIGNED NOT NULL AUTO_INCREMENT,
       
   994 					post_id INT(10) UNSIGNED NOT NULL DEFAULT 0,
       
   995 					topic_id INT(10) UNSIGNED NOT NULL DEFAULT 0,
       
   996 					forum_id INT(10) UNSIGNED NOT NULL DEFAULT 0,
       
   997 					reported_by INT(10) UNSIGNED NOT NULL DEFAULT 0,
       
   998 					created INT(10) UNSIGNED NOT NULL DEFAULT 0,
       
   999 					message TEXT,
       
  1000 					zapped INT(10) UNSIGNED,
       
  1001 					zapped_by INT(10) UNSIGNED,
       
  1002 					PRIMARY KEY (id)
       
  1003 					) ENGINE = MyISAM CHARACTER SET utf8";
       
  1004 			break;
       
  1005 
       
  1006 		case 'pgsql':
       
  1007 			$sql = 'CREATE TABLE '.$db_prefix."reports (
       
  1008 					id SERIAL,
       
  1009 					post_id INT NOT NULL DEFAULT 0,
       
  1010 					topic_id INT NOT NULL DEFAULT 0,
       
  1011 					forum_id INT NOT NULL DEFAULT 0,
       
  1012 					reported_by INT NOT NULL DEFAULT 0,
       
  1013 					created INT NOT NULL DEFAULT 0,
       
  1014 					message TEXT,
       
  1015 					zapped INT,
       
  1016 					zapped_by INT,
       
  1017 					PRIMARY KEY (id)
       
  1018 					)";
       
  1019 			break;
       
  1020 
       
  1021 		case 'sqlite':
       
  1022 			$sql = 'CREATE TABLE '.$db_prefix."reports (
       
  1023 					id INTEGER NOT NULL,
       
  1024 					post_id INTEGER NOT NULL DEFAULT 0,
       
  1025 					topic_id INTEGER NOT NULL DEFAULT 0,
       
  1026 					forum_id INTEGER NOT NULL DEFAULT 0,
       
  1027 					reported_by INTEGER NOT NULL DEFAULT 0,
       
  1028 					created INTEGER NOT NULL DEFAULT 0,
       
  1029 					message TEXT,
       
  1030 					zapped INTEGER,
       
  1031 					zapped_by INTEGER,
       
  1032 					PRIMARY KEY (id)
       
  1033 					)";
       
  1034 			break;
       
  1035 	}
       
  1036 
       
  1037 	$pun_db->query($sql) or error(__FILE__, __LINE__);
       
  1038 
       
  1039 
       
  1040 
       
  1041 	switch ($db_type)
       
  1042 	{
       
  1043 		case 'pgsql':
       
  1044 			$sql = 'CREATE TABLE '.$db_prefix."search_cache (
       
  1045 					id INT NOT NULL DEFAULT 0,
       
  1046 					ident VARCHAR(200) NOT NULL DEFAULT '',
       
  1047 					search_data TEXT,
       
  1048 					PRIMARY KEY (id)
       
  1049 					)";
       
  1050 			break;
       
  1051 
       
  1052 		case 'sqlite':
       
  1053 			$sql = 'CREATE TABLE '.$db_prefix."search_cache (
       
  1054 					id INTEGER NOT NULL DEFAULT 0,
       
  1055 					ident VARCHAR(200) NOT NULL DEFAULT '',
       
  1056 					search_data TEXT,
       
  1057 					PRIMARY KEY (id)
       
  1058 					)";
       
  1059 			break;
       
  1060 	}
       
  1061 
       
  1062 	if ($db_type != 'mysql' && $db_type != 'mysqli')
       
  1063 		$pun_db->query($sql) or error(__FILE__, __LINE__);
       
  1064 
       
  1065 
       
  1066 
       
  1067 	switch ($db_type)
       
  1068 	{
       
  1069 		case 'pgsql':
       
  1070 			$sql = 'CREATE TABLE '.$db_prefix."search_matches (
       
  1071 					post_id INT NOT NULL DEFAULT 0,
       
  1072 					word_id INT NOT NULL DEFAULT 0,
       
  1073 					subject_match SMALLINT NOT NULL DEFAULT 0
       
  1074 					)";
       
  1075 			break;
       
  1076 
       
  1077 		case 'sqlite':
       
  1078 			$sql = 'CREATE TABLE '.$db_prefix."search_matches (
       
  1079 					post_id INTEGER NOT NULL DEFAULT 0,
       
  1080 					word_id INTEGER NOT NULL DEFAULT 0,
       
  1081 					subject_match INTEGER NOT NULL DEFAULT 0
       
  1082 					)";
       
  1083 			break;
       
  1084 	}
       
  1085 
       
  1086 	if ($db_type != 'mysql' && $db_type != 'mysqli')
       
  1087 		$pun_db->query($sql) or error(__FILE__, __LINE__);
       
  1088 
       
  1089 
       
  1090 
       
  1091 	switch ($db_type)
       
  1092 	{
       
  1093 		case 'pgsql':
       
  1094 			$sql = 'CREATE TABLE '.$db_prefix."search_words (
       
  1095 					id SERIAL,
       
  1096 					word VARCHAR(20) NOT NULL DEFAULT '',
       
  1097 					PRIMARY KEY (word)
       
  1098 					)";
       
  1099 			break;
       
  1100 
       
  1101 		case 'sqlite':
       
  1102 			$sql = 'CREATE TABLE '.$db_prefix."search_words (
       
  1103 					id INTEGER NOT NULL,
       
  1104 					word VARCHAR(20) NOT NULL DEFAULT '',
       
  1105 					PRIMARY KEY (id),
       
  1106 					UNIQUE (word)
       
  1107 					)";
       
  1108 			break;
       
  1109 	}
       
  1110 
       
  1111 	if ($db_type != 'mysql' && $db_type != 'mysqli')
       
  1112 		$pun_db->query($sql) or error(__FILE__, __LINE__);
       
  1113 
       
  1114 
       
  1115 
       
  1116 	switch ($db_type)
       
  1117 	{
       
  1118 		case 'mysql':
       
  1119 		case 'mysqli':
       
  1120 			$sql = 'CREATE TABLE '.$db_prefix."subscriptions (
       
  1121 					user_id INT(10) UNSIGNED NOT NULL DEFAULT 0,
       
  1122 					topic_id INT(10) UNSIGNED NOT NULL DEFAULT 0,
       
  1123 					PRIMARY KEY (user_id, topic_id)
       
  1124 					) ENGINE = MyISAM CHARACTER SET utf8";
       
  1125 			break;
       
  1126 
       
  1127 		case 'pgsql':
       
  1128 			$sql = 'CREATE TABLE '.$db_prefix."subscriptions (
       
  1129 					user_id INT NOT NULL DEFAULT 0,
       
  1130 					topic_id INT NOT NULL DEFAULT 0,
       
  1131 					PRIMARY KEY (user_id, topic_id)
       
  1132 					)";
       
  1133 			break;
       
  1134 
       
  1135 		case 'sqlite':
       
  1136 			$sql = 'CREATE TABLE '.$db_prefix."subscriptions (
       
  1137 					user_id INTEGER NOT NULL DEFAULT 0,
       
  1138 					topic_id INTEGER NOT NULL DEFAULT 0,
       
  1139 					PRIMARY KEY (user_id, topic_id)
       
  1140 					)";
       
  1141 			break;
       
  1142 	}
       
  1143 
       
  1144 	$pun_db->query($sql) or error(__FILE__, __LINE__);
       
  1145 
       
  1146 
       
  1147 
       
  1148 	switch ($db_type)
       
  1149 	{
       
  1150 		case 'mysql':
       
  1151 		case 'mysqli':
       
  1152 			$sql = 'CREATE TABLE '.$db_prefix."topics (
       
  1153 					id INT(10) UNSIGNED NOT NULL AUTO_INCREMENT,
       
  1154 					poster VARCHAR(200) NOT NULL DEFAULT '',
       
  1155 					subject VARCHAR(255) NOT NULL DEFAULT '',
       
  1156 					posted INT(10) UNSIGNED NOT NULL DEFAULT 0,
       
  1157 					first_post_id INT(10) UNSIGNED NOT NULL DEFAULT 0,
       
  1158 					last_post INT(10) UNSIGNED NOT NULL DEFAULT 0,
       
  1159 					last_post_id INT(10) UNSIGNED NOT NULL DEFAULT 0,
       
  1160 					last_poster VARCHAR(200),
       
  1161 					num_views MEDIUMINT(8) UNSIGNED NOT NULL DEFAULT 0,
       
  1162 					num_replies MEDIUMINT(8) UNSIGNED NOT NULL DEFAULT 0,
       
  1163 					closed TINYINT(1) NOT NULL DEFAULT 0,
       
  1164 					sticky TINYINT(1) NOT NULL DEFAULT 0,
       
  1165 					moved_to INT(10) UNSIGNED,
       
  1166 					forum_id INT(10) UNSIGNED NOT NULL DEFAULT 0,
       
  1167 					PRIMARY KEY (id)
       
  1168 					) ENGINE = MyISAM CHARACTER SET utf8";
       
  1169 			break;
       
  1170 
       
  1171 		case 'pgsql':
       
  1172 			$sql = 'CREATE TABLE '.$db_prefix."topics (
       
  1173 					id SERIAL,
       
  1174 					poster VARCHAR(200) NOT NULL DEFAULT '',
       
  1175 					subject VARCHAR(255) NOT NULL DEFAULT '',
       
  1176 					posted INT NOT NULL DEFAULT 0,
       
  1177 					first_post_id INT NOT NULL DEFAULT 0,
       
  1178 					last_post INT NOT NULL DEFAULT 0,
       
  1179 					last_post_id INT NOT NULL DEFAULT 0,
       
  1180 					last_poster VARCHAR(200),
       
  1181 					num_views INT NOT NULL DEFAULT 0,
       
  1182 					num_replies INT NOT NULL DEFAULT 0,
       
  1183 					closed SMALLINT NOT NULL DEFAULT 0,
       
  1184 					sticky SMALLINT NOT NULL DEFAULT 0,
       
  1185 					moved_to INT,
       
  1186 					forum_id INT NOT NULL DEFAULT 0,
       
  1187 					PRIMARY KEY (id)
       
  1188 					)";
       
  1189 			break;
       
  1190 
       
  1191 		case 'sqlite':
       
  1192 			$sql = 'CREATE TABLE '.$db_prefix."topics (
       
  1193 					id INTEGER NOT NULL,
       
  1194 					poster VARCHAR(200) NOT NULL DEFAULT '',
       
  1195 					subject VARCHAR(255) NOT NULL DEFAULT '',
       
  1196 					posted INTEGER NOT NULL DEFAULT 0,
       
  1197 					first_post_id INTEGER NOT NULL DEFAULT 0,
       
  1198 					last_post INTEGER NOT NULL DEFAULT 0,
       
  1199 					last_post_id INTEGER NOT NULL DEFAULT 0,
       
  1200 					last_poster VARCHAR(200),
       
  1201 					num_views INTEGER NOT NULL DEFAULT 0,
       
  1202 					num_replies INTEGER NOT NULL DEFAULT 0,
       
  1203 					closed INTEGER NOT NULL DEFAULT 0,
       
  1204 					sticky INTEGER NOT NULL DEFAULT 0,
       
  1205 					moved_to INTEGER,
       
  1206 					forum_id INTEGER NOT NULL DEFAULT 0,
       
  1207 					PRIMARY KEY (id)
       
  1208 					)";
       
  1209 			break;
       
  1210 	}
       
  1211 
       
  1212 	$pun_db->query($sql) or error(__FILE__, __LINE__);
       
  1213 
       
  1214 
       
  1215 
       
  1216 	switch ($db_type)
       
  1217 	{
       
  1218 		case 'mysql':
       
  1219 		case 'mysqli':
       
  1220 			$sql = 'CREATE TABLE '.$db_prefix."users (
       
  1221 					id INT(10) UNSIGNED NOT NULL AUTO_INCREMENT,
       
  1222 					group_id INT(10) UNSIGNED NOT NULL DEFAULT 4,
       
  1223 					username VARCHAR(200) NOT NULL DEFAULT '',
       
  1224 					password VARCHAR(40) NOT NULL DEFAULT '',
       
  1225 					salt VARCHAR(12),
       
  1226 					email VARCHAR(80) NOT NULL DEFAULT '',
       
  1227 					title VARCHAR(50),
       
  1228 					realname VARCHAR(40),
       
  1229 					url VARCHAR(100),
       
  1230 					jabber VARCHAR(80),
       
  1231 					icq VARCHAR(12),
       
  1232 					msn VARCHAR(80),
       
  1233 					aim VARCHAR(30),
       
  1234 					yahoo VARCHAR(30),
       
  1235 					location VARCHAR(30),
       
  1236 					signature TEXT,
       
  1237 					disp_topics TINYINT(3) UNSIGNED,
       
  1238 					disp_posts TINYINT(3) UNSIGNED,
       
  1239 					email_setting TINYINT(1) NOT NULL DEFAULT 1,
       
  1240 					save_pass TINYINT(1) NOT NULL DEFAULT 1,
       
  1241 					notify_with_post TINYINT(1) NOT NULL DEFAULT 0,
       
  1242 					auto_notify TINYINT(1) NOT NULL DEFAULT 0,
       
  1243 					show_smilies TINYINT(1) NOT NULL DEFAULT 1,
       
  1244 					show_img TINYINT(1) NOT NULL DEFAULT 1,
       
  1245 					show_img_sig TINYINT(1) NOT NULL DEFAULT 1,
       
  1246 					show_avatars TINYINT(1) NOT NULL DEFAULT 1,
       
  1247 					show_sig TINYINT(1) NOT NULL DEFAULT 1,
       
  1248 					timezone FLOAT NOT NULL DEFAULT 0,
       
  1249 					dst TINYINT(1) NOT NULL DEFAULT 0,
       
  1250 					time_format INT(10) UNSIGNED NOT NULL DEFAULT 0,
       
  1251 					date_format INT(10) UNSIGNED NOT NULL DEFAULT 0,
       
  1252 					language VARCHAR(25) NOT NULL DEFAULT 'English',
       
  1253 					style VARCHAR(25) NOT NULL DEFAULT 'Oxygen',
       
  1254 					num_posts INT(10) UNSIGNED NOT NULL DEFAULT 0,
       
  1255 					last_post INT(10) UNSIGNED,
       
  1256 					registered INT(10) UNSIGNED NOT NULL DEFAULT 0,
       
  1257 					registration_ip VARCHAR(15) NOT NULL DEFAULT '0.0.0.0',
       
  1258 					last_visit INT(10) UNSIGNED NOT NULL DEFAULT 0,
       
  1259 					admin_note VARCHAR(30),
       
  1260 					activate_string VARCHAR(80),
       
  1261 					activate_key VARCHAR(8),
       
  1262 					PRIMARY KEY (id)
       
  1263 					) ENGINE = MyISAM CHARACTER SET utf8";
       
  1264 			break;
       
  1265 
       
  1266 		case 'pgsql':
       
  1267 			$sql = 'CREATE TABLE '.$db_prefix."users (
       
  1268 					id SERIAL,
       
  1269 					group_id INT NOT NULL DEFAULT 4,
       
  1270 					username VARCHAR(200) NOT NULL DEFAULT '',
       
  1271 					password VARCHAR(40) NOT NULL DEFAULT '',
       
  1272 					salt VARCHAR(12),
       
  1273 					email VARCHAR(80) NOT NULL DEFAULT '',
       
  1274 					title VARCHAR(50),
       
  1275 					realname VARCHAR(40),
       
  1276 					url VARCHAR(100),
       
  1277 					jabber VARCHAR(80),
       
  1278 					icq VARCHAR(12),
       
  1279 					msn VARCHAR(80),
       
  1280 					aim VARCHAR(30),
       
  1281 					yahoo VARCHAR(30),
       
  1282 					location VARCHAR(30),
       
  1283 					signature TEXT,
       
  1284 					disp_topics SMALLINT,
       
  1285 					disp_posts SMALLINT,
       
  1286 					email_setting SMALLINT NOT NULL DEFAULT 1,
       
  1287 					save_pass SMALLINT NOT NULL DEFAULT 1,
       
  1288 					notify_with_post SMALLINT NOT NULL DEFAULT 0,
       
  1289 					auto_notify SMALLINT NOT NULL DEFAULT 0,
       
  1290 					show_smilies SMALLINT NOT NULL DEFAULT 1,
       
  1291 					show_img SMALLINT NOT NULL DEFAULT 1,
       
  1292 					show_img_sig SMALLINT NOT NULL DEFAULT 1,
       
  1293 					show_avatars SMALLINT NOT NULL DEFAULT 1,
       
  1294 					show_sig SMALLINT NOT NULL DEFAULT 1,
       
  1295 					timezone REAL NOT NULL DEFAULT 0,
       
  1296 					dst SMALLINT NOT NULL DEFAULT 0,
       
  1297 					time_format INT NOT NULL DEFAULT 0,
       
  1298 					date_format INT NOT NULL DEFAULT 0,
       
  1299 					language VARCHAR(25) NOT NULL DEFAULT 'English',
       
  1300 					style VARCHAR(25) NOT NULL DEFAULT 'Oxygen',
       
  1301 					num_posts INT NOT NULL DEFAULT 0,
       
  1302 					last_post INT,
       
  1303 					registered INT NOT NULL DEFAULT 0,
       
  1304 					registration_ip VARCHAR(15) NOT NULL DEFAULT '0.0.0.0',
       
  1305 					last_visit INT NOT NULL DEFAULT 0,
       
  1306 					admin_note VARCHAR(30),
       
  1307 					activate_string VARCHAR(80),
       
  1308 					activate_key VARCHAR(8),
       
  1309 					PRIMARY KEY (id)
       
  1310 					)";
       
  1311 			break;
       
  1312 
       
  1313 		case 'sqlite':
       
  1314 			$sql = 'CREATE TABLE '.$db_prefix."users (
       
  1315 					id INTEGER NOT NULL,
       
  1316 					group_id INTEGER NOT NULL DEFAULT 4,
       
  1317 					username VARCHAR(200) NOT NULL DEFAULT '',
       
  1318 					password VARCHAR(40) NOT NULL DEFAULT '',
       
  1319 					salt VARCHAR(12),
       
  1320 					email VARCHAR(80) NOT NULL DEFAULT '',
       
  1321 					title VARCHAR(50),
       
  1322 					realname VARCHAR(40),
       
  1323 					url VARCHAR(100),
       
  1324 					jabber VARCHAR(80),
       
  1325 					icq VARCHAR(12),
       
  1326 					msn VARCHAR(80),
       
  1327 					aim VARCHAR(30),
       
  1328 					yahoo VARCHAR(30),
       
  1329 					location VARCHAR(30),
       
  1330 					signature TEXT,
       
  1331 					disp_topics INTEGER,
       
  1332 					disp_posts INTEGER,
       
  1333 					email_setting INTEGER NOT NULL DEFAULT 1,
       
  1334 					save_pass INTEGER NOT NULL DEFAULT 1,
       
  1335 					notify_with_post INTEGER NOT NULL DEFAULT 0,
       
  1336 					auto_notify INTEGER NOT NULL DEFAULT 0,
       
  1337 					show_smilies INTEGER NOT NULL DEFAULT 1,
       
  1338 					show_img INTEGER NOT NULL DEFAULT 1,
       
  1339 					show_img_sig INTEGER NOT NULL DEFAULT 1,
       
  1340 					show_avatars INTEGER NOT NULL DEFAULT 1,
       
  1341 					show_sig INTEGER NOT NULL DEFAULT 1,
       
  1342 					timezone FLOAT NOT NULL DEFAULT 0,
       
  1343 					dst INTEGER NOT NULL DEFAULT 0,
       
  1344 					time_format INTEGER NOT NULL DEFAULT 0,
       
  1345 					date_format INTEGER NOT NULL DEFAULT 0,
       
  1346 					language VARCHAR(25) NOT NULL DEFAULT 'English',
       
  1347 					style VARCHAR(25) NOT NULL DEFAULT 'Oxygen',
       
  1348 					num_posts INTEGER NOT NULL DEFAULT 0,
       
  1349 					last_post INTEGER,
       
  1350 					registered INTEGER NOT NULL DEFAULT 0,
       
  1351 					registration_ip VARCHAR(15) NOT NULL DEFAULT '0.0.0.0',
       
  1352 					last_visit INTEGER NOT NULL DEFAULT 0,
       
  1353 					admin_note VARCHAR(30),
       
  1354 					activate_string VARCHAR(80),
       
  1355 					activate_key VARCHAR(8),
       
  1356 					PRIMARY KEY (id)
       
  1357 					)";
       
  1358 			break;
       
  1359 	}
       
  1360 
       
  1361 	$pun_db->query($sql) or error(__FILE__, __LINE__);
       
  1362 
       
  1363 
       
  1364 	// Add some indexes
       
  1365 	switch ($db_type)
       
  1366 	{
       
  1367 		case 'mysql':
       
  1368 		case 'mysqli':
       
  1369 			// We use MySQL's ALTER TABLE ... ADD INDEX syntax instead of CREATE INDEX to avoid problems with users lacking the INDEX privilege
       
  1370 			$queries[] = 'ALTER TABLE '.$db_prefix.'online ADD UNIQUE INDEX '.$db_prefix.'online_user_id_ident_idx(user_id,ident(25))';
       
  1371 			$queries[] = 'ALTER TABLE '.$db_prefix.'online ADD INDEX '.$db_prefix.'online_user_id_idx(user_id)';
       
  1372 			$queries[] = 'ALTER TABLE '.$db_prefix.'posts ADD INDEX '.$db_prefix.'posts_topic_id_idx(topic_id)';
       
  1373 			$queries[] = 'ALTER TABLE '.$db_prefix.'posts ADD INDEX '.$db_prefix.'posts_multi_idx(poster_id, topic_id)';
       
  1374 			$queries[] = 'ALTER TABLE '.$db_prefix.'posts ADD FULLTEXT '.$db_prefix.'posts_message_idx(message)';
       
  1375 			$queries[] = 'ALTER TABLE '.$db_prefix.'reports ADD INDEX '.$db_prefix.'reports_zapped_idx(zapped)';
       
  1376 			$queries[] = 'ALTER TABLE '.$db_prefix.'topics ADD INDEX '.$db_prefix.'topics_forum_id_idx(forum_id)';
       
  1377 			$queries[] = 'ALTER TABLE '.$db_prefix.'topics ADD INDEX '.$db_prefix.'topics_moved_to_idx(moved_to)';
       
  1378 			$queries[] = 'ALTER TABLE '.$db_prefix.'topics ADD INDEX '.$db_prefix.'topics_last_post_idx(last_post)';
       
  1379 			$queries[] = 'ALTER TABLE '.$db_prefix.'topics ADD INDEX '.$db_prefix.'topics_first_post_id_idx(first_post_id)';
       
  1380 			$queries[] = 'ALTER TABLE '.$db_prefix.'topics ADD FULLTEXT '.$db_prefix.'topics_subject_idx(subject)';
       
  1381 			$queries[] = 'ALTER TABLE '.$db_prefix.'users ADD INDEX '.$db_prefix.'users_registered_idx(registered)';
       
  1382 			$queries[] = 'ALTER TABLE '.$db_prefix.'users ADD INDEX '.$db_prefix.'users_username_idx(username(8))';
       
  1383 			break;
       
  1384 
       
  1385 		default:
       
  1386 			$queries[] = 'CREATE UNIQUE INDEX '.$db_prefix.'online_user_id_ident_idx ON '.$db_prefix.'online(user_id,ident)';
       
  1387 			$queries[] = 'CREATE INDEX '.$db_prefix.'online_user_id_idx ON '.$db_prefix.'online(user_id)';
       
  1388 			$queries[] = 'CREATE INDEX '.$db_prefix.'posts_topic_id_idx ON '.$db_prefix.'posts(topic_id)';
       
  1389 			$queries[] = 'CREATE INDEX '.$db_prefix.'posts_multi_idx ON '.$db_prefix.'posts(poster_id, topic_id)';
       
  1390 			$queries[] = 'CREATE INDEX '.$db_prefix.'reports_zapped_idx ON '.$db_prefix.'reports(zapped)';
       
  1391 			$queries[] = 'CREATE INDEX '.$db_prefix.'search_matches_word_id_idx ON '.$db_prefix.'search_matches(word_id)';
       
  1392 			$queries[] = 'CREATE INDEX '.$db_prefix.'search_matches_post_id_idx ON '.$db_prefix.'search_matches(post_id)';
       
  1393 			$queries[] = 'CREATE INDEX '.$db_prefix.'topics_forum_id_idx ON '.$db_prefix.'topics(forum_id)';
       
  1394 			$queries[] = 'CREATE INDEX '.$db_prefix.'topics_moved_to_idx ON '.$db_prefix.'topics(moved_to)';
       
  1395 			$queries[] = 'CREATE INDEX '.$db_prefix.'topics_last_post_idx ON '.$db_prefix.'topics(last_post)';
       
  1396 			$queries[] = 'CREATE INDEX '.$db_prefix.'topics_first_post_id_idx ON '.$db_prefix.'topics(first_post_id)';
       
  1397 			$queries[] = 'CREATE INDEX '.$db_prefix.'users_registered_idx ON '.$db_prefix.'users(registered)';
       
  1398 			$queries[] = 'CREATE INDEX '.$db_prefix.'users_username_idx ON '.$db_prefix.'users(username)';
       
  1399 			$queries[] = 'CREATE INDEX '.$db_prefix.'search_cache_ident_idx ON '.$db_prefix.'search_cache(ident)';
       
  1400 			$queries[] = 'CREATE INDEX '.$db_prefix.'search_words_id_idx ON '.$db_prefix.'search_words(id)';
       
  1401 			break;
       
  1402 	}
       
  1403 
       
  1404 	@reset($queries);
       
  1405 	while (list(, $sql) = @each($queries))
       
  1406 		$pun_db->query($sql) or error(__FILE__, __LINE__);
       
  1407 
       
  1408 
       
  1409 
       
  1410 	$now = time();
       
  1411 
       
  1412 	// Insert the four preset groups
       
  1413 	$pun_db->query('INSERT INTO '.$pun_db->prefix."groups (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_edit_subjects_interval, g_post_flood, g_search_flood) VALUES('Administrators', 'Administrator', 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0)") or error(__FILE__, __LINE__);
       
  1414 	$pun_db->query('INSERT INTO '.$pun_db->prefix."groups (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_edit_subjects_interval, g_post_flood, g_search_flood) VALUES('Guest', NULL, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0)") or error(__FILE__, __LINE__);
       
  1415 	$pun_db->query('INSERT INTO '.$pun_db->prefix."groups (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_edit_subjects_interval, g_post_flood, g_search_flood) VALUES('Members', NULL, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 300, 60, 30)") or error(__FILE__, __LINE__);
       
  1416 	$pun_db->query('INSERT INTO '.$pun_db->prefix."groups (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_edit_subjects_interval, g_post_flood, g_search_flood) VALUES('Moderators', 'Moderator', 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0)") or error(__FILE__, __LINE__);
       
  1417 
       
  1418 	// Insert guest and first admin user
       
  1419 	$pun_db->query('INSERT INTO '.$db_prefix."users (group_id, username, password, email) VALUES(2, 'Guest', 'Guest', 'Guest')") or error(__FILE__, __LINE__);
       
  1420 
       
  1421 	$salt = random_key(12);
       
  1422 
       
  1423 	$pun_db->query('INSERT INTO '.$db_prefix."users (group_id, username, password, email, num_posts, last_post, registered, registration_ip, last_visit, salt) VALUES(1, '".$pun_db->escape($username)."', '".sha1($salt.sha1($password1))."', '$email', 1, ".$now.", ".$now.", '127.0.0.1', ".$now.", '".$pun_db->escape($salt)."')") or error(__FILE__, __LINE__);
       
  1424 
       
  1425 	// Enable/disable avatars depending on file_uploads setting in PHP configuration
       
  1426 	$avatars = in_array(strtolower(@ini_get('file_uploads')), array('on', 'true', '1')) ? 1 : 0;
       
  1427 
       
  1428 	// Enable/disable automatic check for updates depending on PHP environment (require cURL, fsockopen or allow_url_fopen)
       
  1429 	$check_for_updates = (function_exists('curl_init') || function_exists('fsockopen') || in_array(strtolower(@ini_get('allow_url_fopen')), array('on', 'true', '1'))) ? 1 : 0;
       
  1430 
       
  1431 	// Insert config data
       
  1432 	$config = array(
       
  1433 		'o_cur_version'				=> "'".PUN_VERSION."'",
       
  1434 		'o_board_title'				=> "'".$pun_db->escape($board_title)."'",
       
  1435 		'o_board_desc'				=> "'".$pun_db->escape($board_descrip)."'",
       
  1436 		'o_default_timezone'		=> "'0'",
       
  1437 		'o_time_format'				=> "'H:i:s'",
       
  1438 		'o_date_format'				=> "'Y-m-d'",
       
  1439 		'o_check_for_updates'		=> "'$check_for_updates'",
       
  1440 		'o_timeout_visit'			=> "'1800'",
       
  1441 		'o_timeout_online'			=> "'300'",
       
  1442 		'o_redirect_delay'			=> "'1'",
       
  1443 		'o_show_version'			=> "'0'",
       
  1444 		'o_show_user_info'			=> "'1'",
       
  1445 		'o_show_post_count'			=> "'1'",
       
  1446 		'o_signatures'				=> "'1'",
       
  1447 		'o_smilies'					=> "'1'",
       
  1448 		'o_smilies_sig'				=> "'1'",
       
  1449 		'o_make_links'				=> "'1'",
       
  1450 		'o_default_lang'			=> "'English'",
       
  1451 		'o_default_style'			=> "'Oxygen'",
       
  1452 		'o_default_user_group'		=> "'3'",
       
  1453 		'o_topic_review'			=> "'15'",
       
  1454 		'o_disp_topics_default'		=> "'30'",
       
  1455 		'o_disp_posts_default'		=> "'25'",
       
  1456 		'o_indent_num_spaces'		=> "'4'",
       
  1457 		'o_quickpost'				=> "'1'",
       
  1458 		'o_users_online'			=> "'1'",
       
  1459 		'o_censoring'				=> "'0'",
       
  1460 		'o_ranks'					=> "'1'",
       
  1461 		'o_show_dot'				=> "'0'",
       
  1462 		'o_topic_views'				=> "'1'",
       
  1463 		'o_quickjump'				=> "'1'",
       
  1464 		'o_gzip'					=> "'0'",
       
  1465 		'o_additional_navlinks'		=> "''",
       
  1466 		'o_report_method'			=> "'0'",
       
  1467 		'o_regs_report'				=> "'0'",
       
  1468 		'o_mailing_list'			=> "'$email'",
       
  1469 		'o_avatars'					=> "'$avatars'",
       
  1470 		'o_avatars_dir'				=> "'img/avatars'",
       
  1471 		'o_avatars_width'			=> "'60'",
       
  1472 		'o_avatars_height'			=> "'60'",
       
  1473 		'o_avatars_size'			=> "'10240'",
       
  1474 		'o_search_all_forums'		=> "'1'",
       
  1475 		'o_sef'						=> "'Default'",
       
  1476 		'o_admin_email'				=> "'$email'",
       
  1477 		'o_webmaster_email'			=> "'$email'",
       
  1478 		'o_subscriptions'			=> "'1'",
       
  1479 		'o_smtp_host'				=> "NULL",
       
  1480 		'o_smtp_user'				=> "NULL",
       
  1481 		'o_smtp_pass'				=> "NULL",
       
  1482 		'o_smtp_ssl'				=> "'0'",
       
  1483 		'o_regs_allow'				=> "'1'",
       
  1484 		'o_regs_verify'				=> "'0'",
       
  1485 		'o_announcement'			=> "'0'",
       
  1486 		'o_announcement_heading'	=> "'Sample announcement'",
       
  1487 		'o_announcement_message'	=> "'<p>Enter your announcement here.</p>'",
       
  1488 		'o_rules'					=> "'0'",
       
  1489 		'o_rules_message'			=> "'Enter your rules here.'",
       
  1490 		'o_maintenance'				=> "'0'",
       
  1491 		'o_maintenance_message'		=> "'The forums are temporarily down for maintenance. Please try again in a few minutes.<br />\\n<br />\\n/Administrator'",
       
  1492 		'p_message_bbcode'			=> "'1'",
       
  1493 		'p_message_img_tag'			=> "'1'",
       
  1494 		'p_message_all_caps'		=> "'1'",
       
  1495 		'p_subject_all_caps'		=> "'1'",
       
  1496 		'p_sig_all_caps'			=> "'1'",
       
  1497 		'p_sig_bbcode'				=> "'1'",
       
  1498 		'p_sig_img_tag'				=> "'0'",
       
  1499 		'p_sig_length'				=> "'400'",
       
  1500 		'p_sig_lines'				=> "'4'",
       
  1501 		'p_allow_banned_email'		=> "'1'",
       
  1502 		'p_allow_dupe_email'		=> "'0'",
       
  1503 		'p_force_guest_email'		=> "'1'"
       
  1504 	);
       
  1505 
       
  1506 	while (list($conf_name, $conf_value) = @each($config))
       
  1507 		$pun_db->query('INSERT INTO '.$db_prefix."config (conf_name, conf_value) VALUES('$conf_name', $conf_value)") or error(__FILE__, __LINE__);
       
  1508 
       
  1509 	// Insert some other default data
       
  1510 	$pun_db->query('INSERT INTO '.$db_prefix."categories (cat_name, disp_position) VALUES('Test category', 1)") or error(__FILE__, __LINE__);
       
  1511 
       
  1512 	$pun_db->query('INSERT INTO '.$db_prefix."forums (forum_name, forum_desc, num_topics, num_posts, last_post, last_post_id, last_poster, disp_position, cat_id) VALUES('Test forum', 'This is just a test forum', 1, 1, ".$now.", 1, '".$pun_db->escape($username)."', 1, 1)") or error(__FILE__, __LINE__);
       
  1513 
       
  1514 	$subject = 'Test post';
       
  1515 	$pun_db->query('INSERT INTO '.$db_prefix.'topics (poster, subject, posted, first_post_id, last_post, last_post_id, last_poster, forum_id) VALUES(\''.$pun_db->escape($username).'\', \''.$subject.'\', '.$now.', 1, '.$now.', 1, \''.$pun_db->escape($username).'\', 1)') or error(__FILE__, __LINE__);
       
  1516 
       
  1517 	$message = 'If you are looking at this (which I guess you are), the install of PunBB appears to have worked! Now log in and head over to the administration control panel to configure your forum.';
       
  1518 	$pun_db->query('INSERT INTO '.$db_prefix.'posts (poster, poster_id, poster_ip, message, posted, topic_id) VALUES(\''.$pun_db->escape($username).'\', 2, \'127.0.0.1\', \''.$message.'\', '.$now.', 1)') or error(__FILE__, __LINE__);
       
  1519 
       
  1520 	// Add new post to search table
       
  1521 	if ($db_type != 'mysql' && $db_type != 'mysqli')
       
  1522 	{
       
  1523 		require PUN_ROOT.'include/search_idx.php';
       
  1524 		update_search_index('post', $pun_db->insert_id(), $message, $subject);
       
  1525 	}
       
  1526 
       
  1527 	$pun_db->query('INSERT INTO '.$db_prefix."ranks (rank, min_posts) VALUES('New member', 0)") or error(__FILE__, __LINE__);
       
  1528 	$pun_db->query('INSERT INTO '.$db_prefix."ranks (rank, min_posts) VALUES('Member', 10)") or error(__FILE__, __LINE__);
       
  1529 
       
  1530 
       
  1531 	if ($db_type == 'pgsql' || $db_type == 'sqlite')
       
  1532 		$pun_db->end_transaction();
       
  1533 
       
  1534 
       
  1535 
       
  1536 	$alerts = array();
       
  1537 	// Check if the cache directory is writable
       
  1538 	if (!@is_writable('./cache/'))
       
  1539 		$alerts[] = '<li>'.$lang_install['No cache write'].'</li>';
       
  1540 
       
  1541 	// Check if default avatar directory is writable
       
  1542 	if (!@is_writable('./img/avatars/'))
       
  1543 		$alerts[] = '<li>'.$lang_install['No avatar write'].'</li>';
       
  1544 
       
  1545 	// Check if we disabled uploading avatars because file_uploads was disabled
       
  1546 	if ($avatars == '0')
       
  1547 		$alerts[] = '<li>'.$lang_install['File upload alert'].'</li>';
       
  1548 
       
  1549 	// Add some random bytes at the end of the cookie name to prevent collisions
       
  1550 	$cookie_name = 'punbb_cookie_'.random_key(6, false, true);
       
  1551 
       
  1552 	/// Generate the config.php file data
       
  1553 	$config = get_config_file();
       
  1554 
       
  1555 	// Attempt to write config.php and serve it up for download if writing fails
       
  1556 	$written = false;
       
  1557 	if (is_writable(PUN_ROOT))
       
  1558 	{
       
  1559 		$fh = @fopen(PUN_ROOT.'config.php', 'wb');
       
  1560 		if ($fh)
       
  1561 		{
       
  1562 			fwrite($fh, $config);
       
  1563 			fclose($fh);
       
  1564 
       
  1565 			$written = true;
       
  1566 		}
       
  1567 	}
       
  1568 
       
  1569 
       
  1570 ?>
       
  1571 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
       
  1572 
       
  1573 <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en" dir="ltr">
       
  1574 <head>
       
  1575 <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
       
  1576 <title>PunBB Installation</title>
       
  1577 <link rel="stylesheet" type="text/css" href="style/Oxygen/Oxygen.css" />
       
  1578 <link rel="stylesheet" type="text/css" href="style/Oxygen/Oxygen_forms.css" />
       
  1579 <link rel="stylesheet" type="text/css" href="style/Oxygen/Oxygen_cs.css" />
       
  1580 <!--[if lte IE 7]><link rel="stylesheet" type="text/css" href="style/Oxygen/Oxygen_ie.css" /><![endif]-->
       
  1581 </head>
       
  1582 
       
  1583 <body>
       
  1584 
       
  1585 <div id="pun-install" class="pun-page">
       
  1586 <div class="pun">
       
  1587 
       
  1588 <div id="pun-title">
       
  1589 	<div id="logo"><strong><?php printf($lang_install['Install PunBB'], PUN_VERSION) ?></strong></div>
       
  1590 </div>
       
  1591 
       
  1592 <div id="pun-desc">
       
  1593 	<div id="desc"><?php printf($lang_install['Success description'], PUN_VERSION) ?></div>
       
  1594 </div>
       
  1595 
       
  1596 <div id="pun-visit">
       
  1597 	<p><?php echo $lang_install['Success welcome'] ?></p>
       
  1598 </div>
       
  1599 
       
  1600 <?php
       
  1601 ?>
       
  1602 
       
  1603 <div id="pun-main" class="main">
       
  1604 
       
  1605 	<div class="main-head">
       
  1606 		<h1><span><?php echo $lang_install['Final instructions'] ?></span></h1>
       
  1607 	</div>
       
  1608 
       
  1609 	<div class="main-content frm">
       
  1610 <?php
       
  1611 
       
  1612 if (!$written)
       
  1613 {
       
  1614 
       
  1615 ?>
       
  1616 		<div class="frm-info">
       
  1617 			<p class="warn"><?php echo $lang_install['No write info 1'] ?></p>
       
  1618 			<p class="warn"><?php printf($lang_install['No write info 2'], '<a href="index.php">'.$lang_install['Go to index'].'</a>') ?></p>
       
  1619 		</div>
       
  1620 <?php if (!empty($alerts)): ?>		<div class="frm-error">
       
  1621 			<?php echo $lang_install['Warning'] ?></p>
       
  1622 			<ul>
       
  1623 				<?php echo implode("\n\t\t\t\t", $alerts)."\n" ?>
       
  1624 			</ul>
       
  1625 		</div>
       
  1626 <?php endif; ?>		<form class="frm-form" method="post" accept-charset="utf-8" action="install.php">
       
  1627 			<div class="hidden">
       
  1628 			<input type="hidden" name="generate_config" value="1" />
       
  1629 			<input type="hidden" name="db_type" value="<?php echo $db_type; ?>" />
       
  1630 			<input type="hidden" name="db_host" value="<?php echo $db_host; ?>" />
       
  1631 			<input type="hidden" name="db_name" value="<?php echo htmlspecialchars($db_name); ?>" />
       
  1632 			<input type="hidden" name="db_username" value="<?php echo htmlspecialchars($db_username); ?>" />
       
  1633 			<input type="hidden" name="db_password" value="<?php echo htmlspecialchars($db_password); ?>" />
       
  1634 			<input type="hidden" name="db_prefix" value="<?php echo htmlspecialchars($db_prefix); ?>" />
       
  1635 			<input type="hidden" name="base_url" value="<?php echo htmlspecialchars($base_url); ?>" />
       
  1636 			<input type="hidden" name="cookie_name" value="<?php echo htmlspecialchars($cookie_name); ?>" />
       
  1637 			</div>
       
  1638 			<div class="frm-buttons">
       
  1639 				<span class="submit"><input type="submit" value="<?php echo $lang_install['Download config'] ?>" /></span>
       
  1640 			</div>
       
  1641 		</form>
       
  1642 <?php
       
  1643 
       
  1644 }
       
  1645 else
       
  1646 {
       
  1647 
       
  1648 ?>
       
  1649 		<div class="frm-info">
       
  1650 			<p class="warn"><?php printf($lang_install['Write info'], '<a href="index.php">'.$lang_install['Go to index'].'</a>') ?></p>
       
  1651 		</div>
       
  1652 <?php
       
  1653 }
       
  1654 
       
  1655 ?>
       
  1656 	</div>
       
  1657 
       
  1658 </div>
       
  1659 </div>
       
  1660 </div>
       
  1661 </body>
       
  1662 </html>
       
  1663 
       
  1664 <?php
       
  1665 
       
  1666 }
       
  1667 
       
  1668 function get_config_file ()
       
  1669 {
       
  1670 	global $db_type, $db_host, $db_name, $db_username, $db_password, $db_prefix, $base_url, $cookie_name;
       
  1671 
       
  1672 	return '<?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('PUN', 1);";
       
  1673 }