install/index.php
changeset 8 c9487b1e7ffc
parent 0 ceef6d64c21d
equal deleted inserted replaced
7:a0100cde92ff 8:c9487b1e7ffc
     1 <?php
       
     2 /**
       
     3 *
       
     4 * @package install
       
     5 * @version $Id$
       
     6 * @copyright (c) 2005 phpBB Group
       
     7 * @license http://opensource.org/licenses/gpl-license.php GNU Public License
       
     8 *
       
     9 */
       
    10 
       
    11 /**#@+
       
    12 * @ignore
       
    13 */
       
    14 define('IN_PHPBB', true);
       
    15 define('IN_INSTALL', true);
       
    16 /**#@-*/
       
    17 
       
    18 $phpbb_root_path = (defined('PHPBB_ROOT_PATH')) ? PHPBB_ROOT_PATH : './../';
       
    19 $phpEx = substr(strrchr(__FILE__, '.'), 1);
       
    20 
       
    21 // @todo Review this test and see if we can find out what it is which prevents PHP 4.2.x from even displaying the page with requirements on it
       
    22 if (version_compare(PHP_VERSION, '4.3.3') < 0)
       
    23 {
       
    24 	die('You are running an unsupported PHP version. Please upgrade to PHP 4.3.3 or higher before trying to install phpBB 3.0');
       
    25 }
       
    26 
       
    27 function phpbb_require_updated($path, $optional = false)
       
    28 {
       
    29 	global $phpbb_root_path;
       
    30 
       
    31 	$new_path = $phpbb_root_path . 'install/update/new/' . $path;
       
    32 	$old_path = $phpbb_root_path . $path;
       
    33 
       
    34 	if (file_exists($new_path))
       
    35 	{
       
    36 		require($new_path);
       
    37 	}
       
    38 	else if (!$optional || file_exists($old_path))
       
    39 	{
       
    40 		require($old_path);
       
    41 	}
       
    42 }
       
    43 
       
    44 phpbb_require_updated('includes/startup.' . $phpEx);
       
    45 
       
    46 // Try to override some limits - maybe it helps some...
       
    47 @set_time_limit(0);
       
    48 $mem_limit = @ini_get('memory_limit');
       
    49 if (!empty($mem_limit))
       
    50 {
       
    51 	$unit = strtolower(substr($mem_limit, -1, 1));
       
    52 	$mem_limit = (int) $mem_limit;
       
    53 
       
    54 	if ($unit == 'k')
       
    55 	{
       
    56 		$mem_limit = floor($mem_limit / 1024);
       
    57 	}
       
    58 	else if ($unit == 'g')
       
    59 	{
       
    60 		$mem_limit *= 1024;
       
    61 	}
       
    62 	else if (is_numeric($unit))
       
    63 	{
       
    64 		$mem_limit = floor((int) ($mem_limit . $unit) / 1048576);
       
    65 	}
       
    66 	$mem_limit = max(128, $mem_limit) . 'M';
       
    67 }
       
    68 else
       
    69 {
       
    70 	$mem_limit = '128M';
       
    71 }
       
    72 @ini_set('memory_limit', $mem_limit);
       
    73 
       
    74 // Include essential scripts
       
    75 require($phpbb_root_path . 'includes/functions.' . $phpEx);
       
    76 
       
    77 phpbb_require_updated('includes/functions_content.' . $phpEx, true);
       
    78 
       
    79 include($phpbb_root_path . 'includes/auth.' . $phpEx);
       
    80 include($phpbb_root_path . 'includes/session.' . $phpEx);
       
    81 include($phpbb_root_path . 'includes/template.' . $phpEx);
       
    82 include($phpbb_root_path . 'includes/acm/acm_file.' . $phpEx);
       
    83 include($phpbb_root_path . 'includes/cache.' . $phpEx);
       
    84 include($phpbb_root_path . 'includes/functions_admin.' . $phpEx);
       
    85 include($phpbb_root_path . 'includes/utf/utf_tools.' . $phpEx);
       
    86 require($phpbb_root_path . 'includes/functions_install.' . $phpEx);
       
    87 
       
    88 // Try and load an appropriate language if required
       
    89 $language = basename(request_var('language', ''));
       
    90 
       
    91 if (!empty($_SERVER['HTTP_ACCEPT_LANGUAGE']) && !$language)
       
    92 {
       
    93 	$accept_lang_ary = explode(',', strtolower($_SERVER['HTTP_ACCEPT_LANGUAGE']));
       
    94 	foreach ($accept_lang_ary as $accept_lang)
       
    95 	{
       
    96 		// Set correct format ... guess full xx_yy form
       
    97 		$accept_lang = substr($accept_lang, 0, 2) . '_' . substr($accept_lang, 3, 2);
       
    98 
       
    99 		if (file_exists($phpbb_root_path . 'language/' . $accept_lang) && is_dir($phpbb_root_path . 'language/' . $accept_lang))
       
   100 		{
       
   101 			$language = $accept_lang;
       
   102 			break;
       
   103 		}
       
   104 		else
       
   105 		{
       
   106 			// No match on xx_yy so try xx
       
   107 			$accept_lang = substr($accept_lang, 0, 2);
       
   108 			if (file_exists($phpbb_root_path . 'language/' . $accept_lang) && is_dir($phpbb_root_path . 'language/' . $accept_lang))
       
   109 			{
       
   110 				$language = $accept_lang;
       
   111 				break;
       
   112 			}
       
   113 		}
       
   114 	}
       
   115 }
       
   116 
       
   117 // No appropriate language found ... so let's use the first one in the language
       
   118 // dir, this may or may not be English
       
   119 if (!$language)
       
   120 {
       
   121 	$dir = @opendir($phpbb_root_path . 'language');
       
   122 
       
   123 	if (!$dir)
       
   124 	{
       
   125 		die('Unable to access the language directory');
       
   126 		exit;
       
   127 	}
       
   128 
       
   129 	while (($file = readdir($dir)) !== false)
       
   130 	{
       
   131 		$path = $phpbb_root_path . 'language/' . $file;
       
   132 
       
   133 		if (!is_file($path) && !is_link($path) && file_exists($path . '/iso.txt'))
       
   134 		{
       
   135 			$language = $file;
       
   136 			break;
       
   137 		}
       
   138 	}
       
   139 	closedir($dir);
       
   140 }
       
   141 
       
   142 if (!file_exists($phpbb_root_path . 'language/' . $language) || !is_dir($phpbb_root_path . 'language/' . $language))
       
   143 {
       
   144 	die('No language found!');
       
   145 }
       
   146 
       
   147 // And finally, load the relevant language files
       
   148 include($phpbb_root_path . 'language/' . $language . '/common.' . $phpEx);
       
   149 include($phpbb_root_path . 'language/' . $language . '/acp/common.' . $phpEx);
       
   150 include($phpbb_root_path . 'language/' . $language . '/acp/board.' . $phpEx);
       
   151 include($phpbb_root_path . 'language/' . $language . '/install.' . $phpEx);
       
   152 include($phpbb_root_path . 'language/' . $language . '/posting.' . $phpEx);
       
   153 
       
   154 // usually we would need every single constant here - and it would be consistent. For 3.0.x, use a dirty hack... :(
       
   155 
       
   156 // Define needed constants
       
   157 define('CHMOD_ALL', 7);
       
   158 define('CHMOD_READ', 4);
       
   159 define('CHMOD_WRITE', 2);
       
   160 define('CHMOD_EXECUTE', 1);
       
   161 
       
   162 $mode = request_var('mode', 'overview');
       
   163 $sub = request_var('sub', '');
       
   164 
       
   165 // Set PHP error handler to ours
       
   166 set_error_handler(defined('PHPBB_MSG_HANDLER') ? PHPBB_MSG_HANDLER : 'msg_handler');
       
   167 
       
   168 $user = new user();
       
   169 $auth = new auth();
       
   170 $cache = new cache();
       
   171 $template = new template();
       
   172 
       
   173 // Add own hook handler, if present. :o
       
   174 if (file_exists($phpbb_root_path . 'includes/hooks/index.' . $phpEx))
       
   175 {
       
   176 	require($phpbb_root_path . 'includes/hooks/index.' . $phpEx);
       
   177 	$phpbb_hook = new phpbb_hook(array('exit_handler', 'phpbb_user_session_handler', 'append_sid', array('template', 'display')));
       
   178 
       
   179 	foreach ($cache->obtain_hooks() as $hook)
       
   180 	{
       
   181 		@include($phpbb_root_path . 'includes/hooks/' . $hook . '.' . $phpEx);
       
   182 	}
       
   183 }
       
   184 else
       
   185 {
       
   186 	$phpbb_hook = false;
       
   187 }
       
   188 
       
   189 // Set some standard variables we want to force
       
   190 $config = array(
       
   191 	'load_tplcompile'	=> '1'
       
   192 );
       
   193 
       
   194 $template->set_custom_template('../adm/style', 'admin');
       
   195 $template->assign_var('T_TEMPLATE_PATH', '../adm/style');
       
   196 
       
   197 // the acp template is never stored in the database
       
   198 $user->theme['template_storedb'] = false;
       
   199 
       
   200 $install = new module();
       
   201 
       
   202 $install->create('install', "index.$phpEx", $mode, $sub);
       
   203 $install->load();
       
   204 
       
   205 // Generate the page
       
   206 $install->page_header();
       
   207 $install->generate_navigation();
       
   208 
       
   209 $template->set_filenames(array(
       
   210 	'body' => $install->get_tpl_name())
       
   211 );
       
   212 
       
   213 $install->page_footer();
       
   214 
       
   215 /**
       
   216 * @package install
       
   217 */
       
   218 class module
       
   219 {
       
   220 	var $id = 0;
       
   221 	var $type = 'install';
       
   222 	var $module_ary = array();
       
   223 	var $filename;
       
   224 	var $module_url = '';
       
   225 	var $tpl_name = '';
       
   226 	var $mode;
       
   227 	var $sub;
       
   228 
       
   229 	/**
       
   230 	* Private methods, should not be overwritten
       
   231 	*/
       
   232 	function create($module_type, $module_url, $selected_mod = false, $selected_submod = false)
       
   233 	{
       
   234 		global $db, $config, $phpEx, $phpbb_root_path;
       
   235 
       
   236 		$module = array();
       
   237 
       
   238 		// Grab module information using Bart's "neat-o-module" system (tm)
       
   239 		$dir = @opendir('.');
       
   240 
       
   241 		if (!$dir)
       
   242 		{
       
   243 			$this->error('Unable to access the installation directory', __LINE__, __FILE__);
       
   244 		}
       
   245 
       
   246 		$setmodules = 1;
       
   247 		while (($file = readdir($dir)) !== false)
       
   248 		{
       
   249 			if (preg_match('#^install_(.*?)\.' . $phpEx . '$#', $file))
       
   250 			{
       
   251 				include($file);
       
   252 			}
       
   253 		}
       
   254 		closedir($dir);
       
   255 
       
   256 		unset($setmodules);
       
   257 
       
   258 		if (!sizeof($module))
       
   259 		{
       
   260 			$this->error('No installation modules found', __LINE__, __FILE__);
       
   261 		}
       
   262 
       
   263 		// Order to use and count further if modules get assigned to the same position or not having an order
       
   264 		$max_module_order = 1000;
       
   265 
       
   266 		foreach ($module as $row)
       
   267 		{
       
   268 			// Module order not specified or module already assigned at this position?
       
   269 			if (!isset($row['module_order']) || isset($this->module_ary[$row['module_order']]))
       
   270 			{
       
   271 				$row['module_order'] = $max_module_order;
       
   272 				$max_module_order++;
       
   273 			}
       
   274 
       
   275 			$this->module_ary[$row['module_order']]['name'] = $row['module_title'];
       
   276 			$this->module_ary[$row['module_order']]['filename'] = $row['module_filename'];
       
   277 			$this->module_ary[$row['module_order']]['subs'] = $row['module_subs'];
       
   278 			$this->module_ary[$row['module_order']]['stages'] = $row['module_stages'];
       
   279 
       
   280 			if (strtolower($selected_mod) == strtolower($row['module_title']))
       
   281 			{
       
   282 				$this->id = (int) $row['module_order'];
       
   283 				$this->filename = (string) $row['module_filename'];
       
   284 				$this->module_url = (string) $module_url;
       
   285 				$this->mode = (string) $selected_mod;
       
   286 				// Check that the sub-mode specified is valid or set a default if not
       
   287 				if (is_array($row['module_subs']))
       
   288 				{
       
   289 					$this->sub = strtolower((in_array(strtoupper($selected_submod), $row['module_subs'])) ? $selected_submod : $row['module_subs'][0]);
       
   290 				}
       
   291 				else if (is_array($row['module_stages']))
       
   292 				{
       
   293 					$this->sub = strtolower((in_array(strtoupper($selected_submod), $row['module_stages'])) ? $selected_submod : $row['module_stages'][0]);
       
   294 				}
       
   295 				else
       
   296 				{
       
   297 					$this->sub = '';
       
   298 				}
       
   299 			}
       
   300 		} // END foreach
       
   301 	} // END create
       
   302 
       
   303 	/**
       
   304 	* Load and run the relevant module if applicable
       
   305 	*/
       
   306 	function load($mode = false, $run = true)
       
   307 	{
       
   308 		global $phpbb_root_path, $phpEx;
       
   309 
       
   310 		if ($run)
       
   311 		{
       
   312 			if (!empty($mode))
       
   313 			{
       
   314 				$this->mode = $mode;
       
   315 			}
       
   316 
       
   317 			$module = $this->filename;
       
   318 			if (!class_exists($module))
       
   319 			{
       
   320 				$this->error('Module "' . htmlspecialchars($module) . '" not accessible.', __LINE__, __FILE__);
       
   321 			}
       
   322 			$this->module = new $module($this);
       
   323 
       
   324 			if (method_exists($this->module, 'main'))
       
   325 			{
       
   326 				$this->module->main($this->mode, $this->sub);
       
   327 			}
       
   328 		}
       
   329 	}
       
   330 
       
   331 	/**
       
   332 	* Output the standard page header
       
   333 	*/
       
   334 	function page_header()
       
   335 	{
       
   336 		if (defined('HEADER_INC'))
       
   337 		{
       
   338 			return;
       
   339 		}
       
   340 
       
   341 		define('HEADER_INC', true);
       
   342 		global $template, $lang, $stage, $phpbb_root_path;
       
   343 
       
   344 		$template->assign_vars(array(
       
   345 			'L_CHANGE'				=> $lang['CHANGE'],
       
   346 			'L_INSTALL_PANEL'		=> $lang['INSTALL_PANEL'],
       
   347 			'L_SELECT_LANG'			=> $lang['SELECT_LANG'],
       
   348 			'L_SKIP'				=> $lang['SKIP'],
       
   349 			'PAGE_TITLE'			=> $this->get_page_title(),
       
   350 			'T_IMAGE_PATH'			=> $phpbb_root_path . 'adm/images/',
       
   351 
       
   352 			'S_CONTENT_DIRECTION' 	=> $lang['DIRECTION'],
       
   353 			'S_CONTENT_FLOW_BEGIN'	=> ($lang['DIRECTION'] == 'ltr') ? 'left' : 'right',
       
   354 			'S_CONTENT_FLOW_END'	=> ($lang['DIRECTION'] == 'ltr') ? 'right' : 'left',
       
   355 			'S_CONTENT_ENCODING' 	=> 'UTF-8',
       
   356 
       
   357 			'S_USER_LANG'			=> $lang['USER_LANG'],
       
   358 			)
       
   359 		);
       
   360 
       
   361 		header('Content-type: text/html; charset=UTF-8');
       
   362 		header('Cache-Control: private, no-cache="set-cookie"');
       
   363 		header('Expires: 0');
       
   364 		header('Pragma: no-cache');
       
   365 
       
   366 		return;
       
   367 	}
       
   368 
       
   369 	/**
       
   370 	* Output the standard page footer
       
   371 	*/
       
   372 	function page_footer()
       
   373 	{
       
   374 		global $db, $template;
       
   375 
       
   376 		$template->display('body');
       
   377 
       
   378 		// Close our DB connection.
       
   379 		if (!empty($db) && is_object($db))
       
   380 		{
       
   381 			$db->sql_close();
       
   382 		}
       
   383 
       
   384 		if (function_exists('exit_handler'))
       
   385 		{
       
   386 			exit_handler();
       
   387 		}
       
   388 	}
       
   389 
       
   390 	/**
       
   391 	* Returns desired template name
       
   392 	*/
       
   393 	function get_tpl_name()
       
   394 	{
       
   395 		return $this->module->tpl_name . '.html';
       
   396 	}
       
   397 
       
   398 	/**
       
   399 	* Returns the desired page title
       
   400 	*/
       
   401 	function get_page_title()
       
   402 	{
       
   403 		global $lang;
       
   404 
       
   405 		if (!isset($this->module->page_title))
       
   406 		{
       
   407 			return '';
       
   408 		}
       
   409 
       
   410 		return (isset($lang[$this->module->page_title])) ? $lang[$this->module->page_title] : $this->module->page_title;
       
   411 	}
       
   412 
       
   413 	/**
       
   414 	* Generate an HTTP/1.1 header to redirect the user to another page
       
   415 	* This is used during the installation when we do not have a database available to call the normal redirect function
       
   416 	* @param string $page The page to redirect to relative to the installer root path
       
   417 	*/
       
   418 	function redirect($page)
       
   419 	{
       
   420 		// HTTP_HOST is having the correct browser url in most cases...
       
   421 		$server_name = (!empty($_SERVER['HTTP_HOST'])) ? strtolower($_SERVER['HTTP_HOST']) : ((!empty($_SERVER['SERVER_NAME'])) ? $_SERVER['SERVER_NAME'] : getenv('SERVER_NAME'));
       
   422 		$server_port = (!empty($_SERVER['SERVER_PORT'])) ? (int) $_SERVER['SERVER_PORT'] : (int) getenv('SERVER_PORT');
       
   423 		$secure = (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on') ? 1 : 0;
       
   424 
       
   425 		$script_name = (!empty($_SERVER['PHP_SELF'])) ? $_SERVER['PHP_SELF'] : getenv('PHP_SELF');
       
   426 		if (!$script_name)
       
   427 		{
       
   428 			$script_name = (!empty($_SERVER['REQUEST_URI'])) ? $_SERVER['REQUEST_URI'] : getenv('REQUEST_URI');
       
   429 		}
       
   430 
       
   431 		// Replace backslashes and doubled slashes (could happen on some proxy setups)
       
   432 		$script_name = str_replace(array('\\', '//'), '/', $script_name);
       
   433 		$script_path = trim(dirname($script_name));
       
   434 
       
   435 		$url = (($secure) ? 'https://' : 'http://') . $server_name;
       
   436 
       
   437 		if ($server_port && (($secure && $server_port <> 443) || (!$secure && $server_port <> 80)))
       
   438 		{
       
   439 			// HTTP HOST can carry a port number...
       
   440 			if (strpos($server_name, ':') === false)
       
   441 			{
       
   442 				$url .= ':' . $server_port;
       
   443 			}
       
   444 		}
       
   445 
       
   446 		$url .= $script_path . '/' . $page;
       
   447 		header('Location: ' . $url);
       
   448 		exit;
       
   449 	}
       
   450 
       
   451 	/**
       
   452 	* Generate the navigation tabs
       
   453 	*/
       
   454 	function generate_navigation()
       
   455 	{
       
   456 		global $lang, $template, $phpEx, $language;
       
   457 
       
   458 		if (is_array($this->module_ary))
       
   459 		{
       
   460 			@ksort($this->module_ary);
       
   461 			foreach ($this->module_ary as $cat_ary)
       
   462 			{
       
   463 				$cat = $cat_ary['name'];
       
   464 				$l_cat = (!empty($lang['CAT_' . $cat])) ? $lang['CAT_' . $cat] : preg_replace('#_#', ' ', $cat);
       
   465 				$cat = strtolower($cat);
       
   466 				$url = $this->module_url . "?mode=$cat&amp;language=$language";
       
   467 
       
   468 				if ($this->mode == $cat)
       
   469 				{
       
   470 					$template->assign_block_vars('t_block1', array(
       
   471 						'L_TITLE'		=> $l_cat,
       
   472 						'S_SELECTED'	=> true,
       
   473 						'U_TITLE'		=> $url,
       
   474 					));
       
   475 
       
   476 					if (is_array($this->module_ary[$this->id]['subs']))
       
   477 					{
       
   478 						$subs = $this->module_ary[$this->id]['subs'];
       
   479 						foreach ($subs as $option)
       
   480 						{
       
   481 							$l_option = (!empty($lang['SUB_' . $option])) ? $lang['SUB_' . $option] : preg_replace('#_#', ' ', $option);
       
   482 							$option = strtolower($option);
       
   483 							$url = $this->module_url . '?mode=' . $this->mode . "&amp;sub=$option&amp;language=$language";
       
   484 
       
   485 							$template->assign_block_vars('l_block1', array(
       
   486 								'L_TITLE'		=> $l_option,
       
   487 								'S_SELECTED'	=> ($this->sub == $option),
       
   488 								'U_TITLE'		=> $url,
       
   489 							));
       
   490 						}
       
   491 					}
       
   492 
       
   493 					if (is_array($this->module_ary[$this->id]['stages']))
       
   494 					{
       
   495 						$subs = $this->module_ary[$this->id]['stages'];
       
   496 						$matched = false;
       
   497 						foreach ($subs as $option)
       
   498 						{
       
   499 							$l_option = (!empty($lang['STAGE_' . $option])) ? $lang['STAGE_' . $option] : preg_replace('#_#', ' ', $option);
       
   500 							$option = strtolower($option);
       
   501 							$matched = ($this->sub == $option) ? true : $matched;
       
   502 
       
   503 							$template->assign_block_vars('l_block2', array(
       
   504 								'L_TITLE'		=> $l_option,
       
   505 								'S_SELECTED'	=> ($this->sub == $option),
       
   506 								'S_COMPLETE'	=> !$matched,
       
   507 							));
       
   508 						}
       
   509 					}
       
   510 				}
       
   511 				else
       
   512 				{
       
   513 					$template->assign_block_vars('t_block1', array(
       
   514 						'L_TITLE'		=> $l_cat,
       
   515 						'S_SELECTED'	=> false,
       
   516 						'U_TITLE'		=> $url,
       
   517 					));
       
   518 				}
       
   519 			}
       
   520 		}
       
   521 	}
       
   522 
       
   523 	/**
       
   524 	* Output an error message
       
   525 	* If skip is true, return and continue execution, else exit
       
   526 	*/
       
   527 	function error($error, $line, $file, $skip = false)
       
   528 	{
       
   529 		global $lang, $db, $template;
       
   530 
       
   531 		if ($skip)
       
   532 		{
       
   533 			$template->assign_block_vars('checks', array(
       
   534 				'S_LEGEND'	=> true,
       
   535 				'LEGEND'	=> $lang['INST_ERR'],
       
   536 			));
       
   537 
       
   538 			$template->assign_block_vars('checks', array(
       
   539 				'TITLE'		=> basename($file) . ' [ ' . $line . ' ]',
       
   540 				'RESULT'	=> '<b style="color:red">' . $error . '</b>',
       
   541 			));
       
   542 
       
   543 			return;
       
   544 		}
       
   545 
       
   546 		echo '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">';
       
   547 		echo '<html xmlns="http://www.w3.org/1999/xhtml" dir="ltr">';
       
   548 		echo '<head>';
       
   549 		echo '<meta http-equiv="content-type" content="text/html; charset=utf-8" />';
       
   550 		echo '<title>' . $lang['INST_ERR_FATAL'] . '</title>';
       
   551 		echo '<link href="../adm/style/admin.css" rel="stylesheet" type="text/css" media="screen" />';
       
   552 		echo '</head>';
       
   553 		echo '<body id="errorpage">';
       
   554 		echo '<div id="wrap">';
       
   555 		echo '	<div id="page-header">';
       
   556 		echo '	</div>';
       
   557 		echo '	<div id="page-body">';
       
   558 		echo '		<div id="acp">';
       
   559 		echo '		<div class="panel">';
       
   560 		echo '			<span class="corners-top"><span></span></span>';
       
   561 		echo '			<div id="content">';
       
   562 		echo '				<h1>' . $lang['INST_ERR_FATAL'] . '</h1>';
       
   563 		echo '		<p>' . $lang['INST_ERR_FATAL'] . "</p>\n";
       
   564 		echo '		<p>' . basename($file) . ' [ ' . $line . " ]</p>\n";
       
   565 		echo '		<p><b>' . $error . "</b></p>\n";
       
   566 		echo '			</div>';
       
   567 		echo '			<span class="corners-bottom"><span></span></span>';
       
   568 		echo '		</div>';
       
   569 		echo '		</div>';
       
   570 		echo '	</div>';
       
   571 		echo '	<div id="page-footer">';
       
   572 		echo '		Powered by <a href="http://www.phpbb.com/">phpBB</a>&reg; Forum Software &copy; phpBB Group';
       
   573 		echo '	</div>';
       
   574 		echo '</div>';
       
   575 		echo '</body>';
       
   576 		echo '</html>';
       
   577 
       
   578 		if (!empty($db) && is_object($db))
       
   579 		{
       
   580 			$db->sql_close();
       
   581 		}
       
   582 
       
   583 		exit_handler();
       
   584 	}
       
   585 
       
   586 	/**
       
   587 	* Output an error message for a database related problem
       
   588 	* If skip is true, return and continue execution, else exit
       
   589 	*/
       
   590 	function db_error($error, $sql, $line, $file, $skip = false)
       
   591 	{
       
   592 		global $lang, $db, $template;
       
   593 
       
   594 		if ($skip)
       
   595 		{
       
   596 			$template->assign_block_vars('checks', array(
       
   597 				'S_LEGEND'	=> true,
       
   598 				'LEGEND'	=> $lang['INST_ERR_FATAL'],
       
   599 			));
       
   600 
       
   601 			$template->assign_block_vars('checks', array(
       
   602 				'TITLE'		=> basename($file) . ' [ ' . $line . ' ]',
       
   603 				'RESULT'	=> '<b style="color:red">' . $error . '</b><br />&#187; SQL:' . $sql,
       
   604 			));
       
   605 
       
   606 			return;
       
   607 		}
       
   608 
       
   609 		$template->set_filenames(array(
       
   610 			'body' => 'install_error.html')
       
   611 		);
       
   612 		$this->page_header();
       
   613 		$this->generate_navigation();
       
   614 
       
   615 		$template->assign_vars(array(
       
   616 			'MESSAGE_TITLE'		=> $lang['INST_ERR_FATAL_DB'],
       
   617 			'MESSAGE_TEXT'		=> '<p>' . basename($file) . ' [ ' . $line . ' ]</p><p>SQL : ' . $sql . '</p><p><b>' . $error . '</b></p>',
       
   618 		));
       
   619 
       
   620 		// Rollback if in transaction
       
   621 		if ($db->transaction)
       
   622 		{
       
   623 			$db->sql_transaction('rollback');
       
   624 		}
       
   625 
       
   626 		$this->page_footer();
       
   627 	}
       
   628 
       
   629 	/**
       
   630 	* Generate the relevant HTML for an input field and the associated label and explanatory text
       
   631 	*/
       
   632 	function input_field($name, $type, $value='', $options='')
       
   633 	{
       
   634 		global $lang;
       
   635 		$tpl_type = explode(':', $type);
       
   636 		$tpl = '';
       
   637 
       
   638 		switch ($tpl_type[0])
       
   639 		{
       
   640 			case 'text':
       
   641 			case 'password':
       
   642 				$size = (int) $tpl_type[1];
       
   643 				$maxlength = (int) $tpl_type[2];
       
   644 
       
   645 				$tpl = '<input id="' . $name . '" type="' . $tpl_type[0] . '"' . (($size) ? ' size="' . $size . '"' : '') . ' maxlength="' . (($maxlength) ? $maxlength : 255) . '" name="' . $name . '" value="' . $value . '" />';
       
   646 			break;
       
   647 
       
   648 			case 'textarea':
       
   649 				$rows = (int) $tpl_type[1];
       
   650 				$cols = (int) $tpl_type[2];
       
   651 
       
   652 				$tpl = '<textarea id="' . $name . '" name="' . $name . '" rows="' . $rows . '" cols="' . $cols . '">' . $value . '</textarea>';
       
   653 			break;
       
   654 
       
   655 			case 'radio':
       
   656 				$key_yes	= ($value) ? ' checked="checked" id="' . $name . '"' : '';
       
   657 				$key_no		= (!$value) ? ' checked="checked" id="' . $name . '"' : '';
       
   658 
       
   659 				$tpl_type_cond = explode('_', $tpl_type[1]);
       
   660 				$type_no = ($tpl_type_cond[0] == 'disabled' || $tpl_type_cond[0] == 'enabled') ? false : true;
       
   661 
       
   662 				$tpl_no = '<label><input type="radio" name="' . $name . '" value="0"' . $key_no . ' class="radio" /> ' . (($type_no) ? $lang['NO'] : $lang['DISABLED']) . '</label>';
       
   663 				$tpl_yes = '<label><input type="radio" name="' . $name . '" value="1"' . $key_yes . ' class="radio" /> ' . (($type_no) ? $lang['YES'] : $lang['ENABLED']) . '</label>';
       
   664 
       
   665 				$tpl = ($tpl_type_cond[0] == 'yes' || $tpl_type_cond[0] == 'enabled') ? $tpl_yes . '&nbsp;&nbsp;' . $tpl_no : $tpl_no . '&nbsp;&nbsp;' . $tpl_yes;
       
   666 			break;
       
   667 
       
   668 			case 'select':
       
   669 				eval('$s_options = ' . str_replace('{VALUE}', $value, $options) . ';');
       
   670 				$tpl = '<select id="' . $name . '" name="' . $name . '">' . $s_options . '</select>';
       
   671 			break;
       
   672 
       
   673 			case 'custom':
       
   674 				eval('$tpl = ' . str_replace('{VALUE}', $value, $options) . ';');
       
   675 			break;
       
   676 
       
   677 			default:
       
   678 			break;
       
   679 		}
       
   680 
       
   681 		return $tpl;
       
   682 	}
       
   683 
       
   684 	/**
       
   685 	* Generate the drop down of available language packs
       
   686 	*/
       
   687 	function inst_language_select($default = '')
       
   688 	{
       
   689 		global $phpbb_root_path, $phpEx;
       
   690 
       
   691 		$dir = @opendir($phpbb_root_path . 'language');
       
   692 
       
   693 		if (!$dir)
       
   694 		{
       
   695 			$this->error('Unable to access the language directory', __LINE__, __FILE__);
       
   696 		}
       
   697 
       
   698 		while ($file = readdir($dir))
       
   699 		{
       
   700 			$path = $phpbb_root_path . 'language/' . $file;
       
   701 
       
   702 			if ($file == '.' || $file == '..' || is_link($path) || is_file($path) || $file == 'CVS')
       
   703 			{
       
   704 				continue;
       
   705 			}
       
   706 
       
   707 			if (file_exists($path . '/iso.txt'))
       
   708 			{
       
   709 				list($displayname, $localname) = @file($path . '/iso.txt');
       
   710 				$lang[$localname] = $file;
       
   711 			}
       
   712 		}
       
   713 		closedir($dir);
       
   714 
       
   715 		@asort($lang);
       
   716 		@reset($lang);
       
   717 
       
   718 		$user_select = '';
       
   719 		foreach ($lang as $displayname => $filename)
       
   720 		{
       
   721 			$selected = (strtolower($default) == strtolower($filename)) ? ' selected="selected"' : '';
       
   722 			$user_select .= '<option value="' . $filename . '"' . $selected . '>' . ucwords($displayname) . '</option>';
       
   723 		}
       
   724 
       
   725 		return $user_select;
       
   726 	}
       
   727 }
       
   728 
       
   729 ?>