dokuwiki/install.php

711 lines
21 KiB
PHP
Raw Permalink Normal View History

<?php
2023-08-31 22:44:40 +02:00
/*><div style="width:60%; margin: auto; background-color: #fcc;
border: 1px solid #faa; padding: 0.5em 1em;">
<h1 style="font-size: 120%">No PHP Support</h1>
It seems this server has no PHP support enabled. You will need to
enable PHP before you can install and run DokuWiki. Contact your hosting
provider if you're unsure what this means.
</div>*/
2023-08-30 14:51:30 +02:00
use dokuwiki\PassHash;
2023-08-30 14:48:22 +02:00
if (!defined('DOKU_INC')) define('DOKU_INC', __DIR__ . '/');
2022-02-15 22:48:45 +01:00
if (!defined('DOKU_CONF')) define('DOKU_CONF', DOKU_INC . 'conf/');
if (!defined('DOKU_LOCAL')) define('DOKU_LOCAL', DOKU_INC . 'conf/');
// load and initialize the core system
2022-02-15 22:48:45 +01:00
require_once(DOKU_INC . 'inc/init.php');
require_once(DOKU_INC . 'inc/pageutils.php');
// check for error reporting override or set error reporting to sane values
2022-02-15 22:48:45 +01:00
if (!defined('DOKU_E_LEVEL')) {
error_reporting(E_ALL ^ E_NOTICE);
} else {
error_reporting(DOKU_E_LEVEL);
}
// language strings
2022-02-15 22:48:45 +01:00
require_once(DOKU_INC . 'inc/lang/en/lang.php');
if (isset($_REQUEST['l']) && !is_array($_REQUEST['l'])) {
$LC = preg_replace('/[^a-z\-]+/', '', $_REQUEST['l']);
2012-06-25 00:24:07 +02:00
}
2022-02-15 22:48:45 +01:00
if (empty($LC)) $LC = 'en';
if ($LC && $LC != 'en') {
require_once(DOKU_INC . 'inc/lang/' . $LC . '/lang.php');
}
// initialise variables ...
2023-08-30 14:48:22 +02:00
$error = [];
// begin output
header('Content-Type: text/html; charset=utf-8');
?>
2023-08-31 00:55:36 +02:00
<!DOCTYPE html>
<html lang="<?php echo $LC ?>" dir="<?php echo $lang['direction'] ?>">
<head>
<meta charset="utf-8"/>
<title><?php echo $lang['i_installer'] ?></title>
<style>
body {
width: 90%;
margin: 0 auto;
font: 84% Verdana, Helvetica, Arial, sans-serif;
}
2023-08-31 00:55:36 +02:00
img {
border: none
}
br.cl {
clear: both;
}
code {
font-size: 110%;
color: #800000;
}
fieldset {
border: none
}
label {
display: block;
margin-top: 0.5em;
}
select.text, input.text {
width: 30em;
margin: 0 0.5em;
}
a {
text-decoration: none
}
</style>
<script>
function acltoggle() {
var cb = document.getElementById('acl');
var fs = document.getElementById('acldep');
if (!cb || !fs) return;
if (cb.checked) {
fs.style.display = '';
} else {
fs.style.display = 'none';
}
}
window.onload = function () {
acltoggle();
var cb = document.getElementById('acl');
if (cb) cb.onchange = acltoggle;
};
</script>
</head>
<body style="">
<h1 style="float:left">
<img src="lib/exe/fetch.php?media=wiki:dokuwiki-128.png"
2023-08-31 00:55:36 +02:00
style="vertical-align: middle;" alt="" height="64" width="64"/>
<?php echo $lang['i_installer'] ?>
</h1>
<div style="float:right; margin: 1em;">
2023-08-31 00:55:36 +02:00
<?php langsel() ?>
</div>
2023-08-31 00:55:36 +02:00
<br class="cl"/>
<div style="float: right; width: 34%;">
<?php
2022-02-15 22:48:45 +01:00
if (file_exists(DOKU_INC . 'inc/lang/' . $LC . '/install.html')) {
include(DOKU_INC . 'inc/lang/' . $LC . '/install.html');
} else {
2023-08-31 22:00:27 +02:00
echo "<div lang=\"en\" dir=\"ltr\">\n";
2022-02-15 22:48:45 +01:00
include(DOKU_INC . 'inc/lang/en/install.html');
2023-08-31 22:00:27 +02:00
echo "</div>\n";
2022-02-15 22:48:45 +01:00
}
?>
<a style="
background: transparent
url(data/dont-panic-if-you-see-this-in-your-logs-it-means-your-directory-permissions-are-correct.png)
left top no-repeat;
display: block; width:380px; height:73px; border:none; clear:both;"
target="_blank"
2023-08-31 00:59:34 +02:00
href="https://www.dokuwiki.org/security#web_access_security"></a>
</div>
<div style="float: left; width: 58%;">
<?php
2022-02-15 22:48:45 +01:00
try {
2023-08-31 00:55:36 +02:00
if (!(check_functions() && check_permissions())) {
2022-02-15 22:48:45 +01:00
echo '<p>' . $lang['i_problems'] . '</p>';
print_errors();
print_retry();
} elseif (!check_configs()) {
echo '<p>' . $lang['i_modified'] . '</p>';
print_errors();
} elseif (check_data($_REQUEST['d'])) {
// check_data has sanitized all input parameters
if (!store_data($_REQUEST['d'])) {
echo '<p>' . $lang['i_failure'] . '</p>';
print_errors();
2022-02-15 22:48:45 +01:00
} else {
echo '<p>' . $lang['i_success'] . '</p>';
}
2022-02-15 22:48:45 +01:00
} else {
print_errors();
print_form($_REQUEST['d']);
}
2022-02-15 22:48:45 +01:00
} catch (Exception $e) {
2023-08-31 00:55:36 +02:00
echo 'Caught exception: ', $e->getMessage(), "\n";
2022-02-15 22:48:45 +01:00
}
?>
</div>
2023-08-31 00:55:36 +02:00
<div style="clear: both">
2023-08-31 00:59:34 +02:00
<a href="https://dokuwiki.org/"><img src="lib/tpl/dokuwiki/images/button-dw.png" alt="driven by DokuWiki"/></a>
<a href="https://php.net"><img src="lib/tpl/dokuwiki/images/button-php.gif" alt="powered by PHP"/></a>
2023-08-31 00:55:36 +02:00
</div>
</body>
</html>
<?php
/**
* Print the input form
*
* @param array $d submitted entry 'd' of request data
*/
2022-02-15 22:48:45 +01:00
function print_form($d)
{
global $lang;
global $LC;
2022-02-15 22:48:45 +01:00
include(DOKU_CONF . 'license.php');
2023-08-30 14:48:22 +02:00
if (!is_array($d)) $d = [];
2022-02-15 22:48:45 +01:00
$d = array_map('hsc', $d);
2022-02-15 22:48:45 +01:00
if (!isset($d['acl'])) $d['acl'] = 1;
if (!isset($d['pop'])) $d['pop'] = 1;
?>
<form action="" method="post">
2023-08-31 00:55:36 +02:00
<input type="hidden" name="l" value="<?php echo $LC ?>"/>
<fieldset>
<label for="title"><?php echo $lang['i_wikiname'] ?>
<input type="text" name="d[title]" id="title" value="<?php echo $d['title'] ?>" style="width: 20em;"/>
</label>
<fieldset style="margin-top: 1em;">
<label for="acl">
<input type="checkbox" name="d[acl]"
id="acl" <?php echo(($d['acl'] ? ' checked="checked"' : '')); ?> />
<?php echo $lang['i_enableacl'] ?></label>
<fieldset id="acldep">
<label for="superuser"><?php echo $lang['i_superuser'] ?></label>
<input class="text" type="text" name="d[superuser]" id="superuser"
value="<?php echo $d['superuser'] ?>"/>
<label for="fullname"><?php echo $lang['fullname'] ?></label>
<input class="text" type="text" name="d[fullname]" id="fullname"
value="<?php echo $d['fullname'] ?>"/>
<label for="email"><?php echo $lang['email'] ?></label>
<input class="text" type="text" name="d[email]" id="email" value="<?php echo $d['email'] ?>"/>
<label for="password"><?php echo $lang['pass'] ?></label>
<input class="text" type="password" name="d[password]" id="password"/>
<label for="confirm"><?php echo $lang['passchk'] ?></label>
<input class="text" type="password" name="d[confirm]" id="confirm"/>
<label for="policy"><?php echo $lang['i_policy'] ?></label>
<select class="text" name="d[policy]" id="policy">
<option value="0" <?php echo ($d['policy'] == 0) ? 'selected="selected"' : '' ?>><?php
echo $lang['i_pol0'] ?></option>
<option value="1" <?php echo ($d['policy'] == 1) ? 'selected="selected"' : '' ?>><?php
echo $lang['i_pol1'] ?></option>
<option value="2" <?php echo ($d['policy'] == 2) ? 'selected="selected"' : '' ?>><?php
echo $lang['i_pol2'] ?></option>
</select>
<label for="allowreg">
<input type="checkbox" name="d[allowreg]" id="allowreg" <?php
echo(($d['allowreg'] ? ' checked="checked"' : '')); ?> />
<?php echo $lang['i_allowreg'] ?>
</label>
</fieldset>
</fieldset>
<fieldset>
<p><?php echo $lang['i_license'] ?></p>
<?php
$license[] = ['name' => $lang['i_license_none'], 'url' => ''];
if (empty($d['license'])) $d['license'] = 'cc-by-sa';
foreach ($license as $key => $lic) {
echo '<label for="lic_' . $key . '">';
echo '<input type="radio" name="d[license]" value="' . hsc($key) . '" id="lic_' . $key . '"' .
(($d['license'] === $key) ? ' checked="checked"' : '') . '>';
echo hsc($lic['name']);
if ($lic['url']) echo ' <a href="' . $lic['url'] . '" target="_blank"><sup>[?]</sup></a>';
echo '</label>';
}
?>
</fieldset>
<fieldset>
<p><?php echo $lang['i_pop_field'] ?></p>
<label for="pop">
<input type="checkbox" name="d[pop]" id="pop" <?php
echo(($d['pop'] ? ' checked="checked"' : '')); ?> />
<?php echo $lang['i_pop_label'] ?>
2023-08-31 00:59:34 +02:00
<a href="https://www.dokuwiki.org/popularity" target="_blank"><sup>[?]</sup></a>
</label>
</fieldset>
</fieldset>
2023-08-31 00:55:36 +02:00
<fieldset id="process">
<button type="submit" name="submit"><?php echo $lang['btn_save'] ?></button>
</fieldset>
</form>
<?php
}
2022-02-15 22:48:45 +01:00
function print_retry()
{
global $lang;
global $LC;
?>
<form action="" method="get">
2023-08-31 00:55:36 +02:00
<fieldset>
<input type="hidden" name="l" value="<?php echo $LC ?>"/>
<button type="submit"><?php echo $lang['i_retry']; ?></button>
</fieldset>
</form>
<?php
}
/**
* Check validity of data
*
* @param array $d
* @return bool ok?
2023-08-31 00:55:36 +02:00
* @author Andreas Gohr
*
*/
2022-02-15 22:48:45 +01:00
function check_data(&$d)
{
2023-08-30 14:48:22 +02:00
static $form_default = [
2023-08-31 00:55:36 +02:00
'title' => '',
'acl' => '1',
2012-06-25 00:24:07 +02:00
'superuser' => '',
2023-08-31 00:55:36 +02:00
'fullname' => '',
'email' => '',
'password' => '',
'confirm' => '',
'policy' => '0',
'allowreg' => '0',
'license' => 'cc-by-sa'
2023-08-30 14:48:22 +02:00
];
global $lang;
global $error;
2023-08-30 14:48:22 +02:00
if (!is_array($d)) $d = [];
2022-02-15 22:48:45 +01:00
foreach ($d as $k => $v) {
if (is_array($v))
2012-06-25 00:24:07 +02:00
unset($d[$k]);
2022-02-15 22:48:45 +01:00
else $d[$k] = (string)$v;
2012-06-25 00:24:07 +02:00
}
//autolowercase the username
2012-06-25 00:24:07 +02:00
$d['superuser'] = isset($d['superuser']) ? strtolower($d['superuser']) : "";
2012-06-25 00:24:07 +02:00
$ok = false;
2022-02-15 22:48:45 +01:00
if (isset($_REQUEST['submit'])) {
2012-06-25 00:24:07 +02:00
$ok = true;
// check input
2022-02-15 22:48:45 +01:00
if (empty($d['title'])) {
$error[] = sprintf($lang['i_badval'], $lang['i_wikiname']);
2023-08-31 00:55:36 +02:00
$ok = false;
}
2022-02-15 22:48:45 +01:00
if (isset($d['acl'])) {
if (empty($d['superuser']) || ($d['superuser'] !== cleanID($d['superuser']))) {
2022-02-15 22:48:45 +01:00
$error[] = sprintf($lang['i_badval'], $lang['i_superuser']);
2023-08-31 00:55:36 +02:00
$ok = false;
2012-06-25 00:24:07 +02:00
}
2022-02-15 22:48:45 +01:00
if (empty($d['password'])) {
$error[] = sprintf($lang['i_badval'], $lang['pass']);
2023-08-31 00:55:36 +02:00
$ok = false;
2022-02-15 22:48:45 +01:00
} elseif (!isset($d['confirm']) || $d['confirm'] != $d['password']) {
$error[] = sprintf($lang['i_badval'], $lang['passchk']);
2023-08-31 00:55:36 +02:00
$ok = false;
2012-06-25 00:24:07 +02:00
}
2022-02-15 22:48:45 +01:00
if (empty($d['fullname']) || strstr($d['fullname'], ':')) {
$error[] = sprintf($lang['i_badval'], $lang['fullname']);
2023-08-31 00:55:36 +02:00
$ok = false;
2012-06-25 00:24:07 +02:00
}
2022-02-15 22:48:45 +01:00
if (empty($d['email']) || strstr($d['email'], ':') || !strstr($d['email'], '@')) {
$error[] = sprintf($lang['i_badval'], $lang['email']);
2023-08-31 00:55:36 +02:00
$ok = false;
2012-06-25 00:24:07 +02:00
}
2022-02-15 22:48:45 +01:00
} else {
// Since default = 1, browser won't send acl=0 when user untick acl
$d['acl'] = '0';
}
}
2012-06-25 00:24:07 +02:00
$d = array_merge($form_default, $d);
return $ok;
}
/**
* Writes the data to the config files
*
* @param array $d
* @return bool
2023-08-31 00:55:36 +02:00
* @throws Exception
*
* @author Chris Smith <chris@jalakai.co.uk>
*/
2022-02-15 22:48:45 +01:00
function store_data($d)
{
global $LC;
$ok = true;
2023-08-31 00:55:36 +02:00
$d['policy'] = (int)$d['policy'];
// create local.php
2023-08-31 00:55:36 +02:00
$now = gmdate('r');
$output = <<<EOT
<?php
/**
* Dokuwiki's Main Configuration File - Local Settings
* Auto-generated by install script
* Date: $now
*/
EOT;
// add any config options set by a previous installer
2022-02-15 22:48:45 +01:00
$preset = __DIR__ . '/install.conf';
if (file_exists($preset)) {
$output .= "# preset config options\n";
$output .= file_get_contents($preset);
$output .= "\n\n";
$output .= "# options selected in installer\n";
@unlink($preset);
}
2022-02-15 22:48:45 +01:00
$output .= '$conf[\'title\'] = \'' . addslashes($d['title']) . "';\n";
$output .= '$conf[\'lang\'] = \'' . addslashes($LC) . "';\n";
$output .= '$conf[\'license\'] = \'' . addslashes($d['license']) . "';\n";
if ($d['acl']) {
$output .= '$conf[\'useacl\'] = 1' . ";\n";
$output .= "\$conf['superuser'] = '@admin';\n";
}
2022-02-15 22:48:45 +01:00
if (!$d['allowreg']) {
$output .= '$conf[\'disableactions\'] = \'register\'' . ";\n";
}
2022-02-15 22:48:45 +01:00
$ok = $ok && fileWrite(DOKU_LOCAL . 'local.php', $output);
if ($d['acl']) {
// hash the password
2023-08-30 14:48:22 +02:00
$phash = new PassHash();
$pass = $phash->hash_bcrypt($d['password']);
// create users.auth.php
$output = <<<EOT
# users.auth.php
# <?php exit()?>
# Don't modify the lines above
#
# Userfile
#
# Auto-generated by install script
# Date: $now
#
# Format:
# login:passwordhash:Real Name:email:groups,comma,separated
EOT;
2020-06-10 02:16:25 +02:00
// --- user:bcryptpasswordhash:Real Name:email:groups,comma,seperated
2023-08-30 14:48:22 +02:00
$output = $output . "\n" . implode(':', [
$d['superuser'],
$pass,
$d['fullname'],
$d['email'],
'admin,user',
]) . "\n";
2022-02-15 22:48:45 +01:00
$ok = $ok && fileWrite(DOKU_LOCAL . 'users.auth.php', $output);
// create acl.auth.php
$output = <<<EOT
# acl.auth.php
# <?php exit()?>
# Don't modify the lines above
#
# Access Control Lists
#
# Auto-generated by install script
# Date: $now
EOT;
2022-02-15 22:48:45 +01:00
if ($d['policy'] == 2) {
2023-08-31 00:55:36 +02:00
$output .= "* @ALL 0\n";
$output .= "* @user 8\n";
2022-02-15 22:48:45 +01:00
} elseif ($d['policy'] == 1) {
2023-08-31 00:55:36 +02:00
$output .= "* @ALL 1\n";
$output .= "* @user 8\n";
2022-02-15 22:48:45 +01:00
} else {
2023-08-31 00:55:36 +02:00
$output .= "* @ALL 8\n";
}
2022-02-15 22:48:45 +01:00
$ok = $ok && fileWrite(DOKU_LOCAL . 'acl.auth.php', $output);
}
// enable popularity submission
2022-02-15 22:48:45 +01:00
if (isset($d['pop']) && $d['pop']) {
@touch(DOKU_INC . 'data/cache/autosubmit.txt');
}
// disable auth plugins til needed
$output = <<<EOT
<?php
/*
* Local plugin enable/disable settings
*
* Auto-generated by install script
* Date: $now
*/
\$plugins['authad'] = 0;
\$plugins['authldap'] = 0;
\$plugins['authmysql'] = 0;
\$plugins['authpgsql'] = 0;
EOT;
2022-02-15 22:48:45 +01:00
$ok = $ok && fileWrite(DOKU_LOCAL . 'plugins.local.php', $output);
return $ok;
}
/**
* Write the given content to a file
*
* @param string $filename
* @param string $data
* @return bool
2023-08-31 00:55:36 +02:00
*
* @author Chris Smith <chris@jalakai.co.uk>
*/
2022-02-15 22:48:45 +01:00
function fileWrite($filename, $data)
{
global $error;
global $lang;
if (($fp = @fopen($filename, 'wb')) === false) {
2022-02-15 22:48:45 +01:00
$filename = str_replace($_SERVER['DOCUMENT_ROOT'], '{DOCUMENT_ROOT}/', $filename);
2023-08-31 00:55:36 +02:00
$error[] = sprintf($lang['i_writeerr'], $filename);
return false;
}
2022-02-15 22:48:45 +01:00
if (!empty($data)) {
fwrite($fp, $data);
}
fclose($fp);
return true;
}
/**
* check installation dependent local config files and tests for a known
* unmodified main config file
*
* @return bool
2023-08-31 00:55:36 +02:00
*
* @author Chris Smith <chris@jalakai.co.uk>
*/
2022-02-15 22:48:45 +01:00
function check_configs()
{
global $error;
global $lang;
$ok = true;
2023-08-30 14:48:22 +02:00
$config_files = [
2022-02-15 22:48:45 +01:00
'local' => DOKU_LOCAL . 'local.php',
'users' => DOKU_LOCAL . 'users.auth.php',
2023-08-31 00:55:36 +02:00
'auth' => DOKU_LOCAL . 'acl.auth.php'
2023-08-30 14:48:22 +02:00
];
// configs shouldn't exist
foreach ($config_files as $file) {
if (file_exists($file) && filesize($file)) {
2023-08-31 00:55:36 +02:00
$file = str_replace($_SERVER['DOCUMENT_ROOT'], '{DOCUMENT_ROOT}/', $file);
2022-02-15 22:48:45 +01:00
$error[] = sprintf($lang['i_confexists'], $file);
2023-08-31 00:55:36 +02:00
$ok = false;
}
}
return $ok;
}
/**
* Check other installation dir/file permission requirements
*
* @return bool
2023-08-31 00:55:36 +02:00
*
* @author Chris Smith <chris@jalakai.co.uk>
*/
2022-02-15 22:48:45 +01:00
function check_permissions()
{
global $error;
global $lang;
2023-08-30 14:48:22 +02:00
$dirs = [
2023-08-31 00:55:36 +02:00
'conf' => DOKU_LOCAL,
'data' => DOKU_INC . 'data',
'pages' => DOKU_INC . 'data/pages',
'attic' => DOKU_INC . 'data/attic',
'media' => DOKU_INC . 'data/media',
2022-02-15 22:48:45 +01:00
'media_attic' => DOKU_INC . 'data/media_attic',
2023-08-31 00:55:36 +02:00
'media_meta' => DOKU_INC . 'data/media_meta',
'meta' => DOKU_INC . 'data/meta',
'cache' => DOKU_INC . 'data/cache',
'locks' => DOKU_INC . 'data/locks',
'index' => DOKU_INC . 'data/index',
'tmp' => DOKU_INC . 'data/tmp'
2023-08-30 14:48:22 +02:00
];
$ok = true;
2022-02-15 22:48:45 +01:00
foreach ($dirs as $dir) {
if (!file_exists("$dir/.") || !is_writable($dir)) {
2023-08-31 00:55:36 +02:00
$dir = str_replace($_SERVER['DOCUMENT_ROOT'], '{DOCUMENT_ROOT}', $dir);
2022-02-15 22:48:45 +01:00
$error[] = sprintf($lang['i_permfail'], $dir);
2023-08-31 00:55:36 +02:00
$ok = false;
}
}
return $ok;
}
/**
* Check the availability of functions used in DokuWiki and the PHP version
*
* @return bool
2023-08-31 00:55:36 +02:00
*
* @author Andreas Gohr <andi@splitbrain.org>
*/
2022-02-15 22:48:45 +01:00
function check_functions()
{
global $error;
global $lang;
$ok = true;
2023-06-09 21:10:11 +02:00
if (version_compare(phpversion(), '7.4.0', '<')) {
$error[] = sprintf($lang['i_phpver'], phpversion(), '7.4.0');
$ok = false;
}
2022-02-15 22:48:45 +01:00
if (ini_get('mbstring.func_overload') != 0) {
$error[] = $lang['i_mbfuncoverload'];
$ok = false;
}
try {
random_bytes(1);
2023-08-31 00:55:36 +02:00
} catch (Exception $th) {
// If an appropriate source of randomness cannot be found, an Exception will be thrown by PHP 7+
$error[] = $lang['i_urandom'];
$ok = false;
}
2022-02-15 22:48:45 +01:00
if (ini_get('mbstring.func_overload') != 0) {
$error[] = $lang['i_mbfuncoverload'];
$ok = false;
}
2022-02-15 22:48:45 +01:00
$funcs = explode(' ', 'addslashes call_user_func chmod copy fgets ' .
2023-08-31 00:55:36 +02:00
'file file_exists fseek flush filesize ftell fopen ' .
'glob header ignore_user_abort ini_get mkdir ' .
'ob_start opendir parse_ini_file readfile realpath ' .
'rename rmdir serialize session_start unlink usleep ' .
'preg_replace file_get_contents htmlspecialchars_decode ' .
'spl_autoload_register stream_select fsockopen pack xml_parser_create');
if (!function_exists('mb_substr')) {
$funcs[] = 'utf8_encode';
$funcs[] = 'utf8_decode';
}
2022-02-15 22:48:45 +01:00
if (!function_exists('mail')) {
if (strpos(ini_get('disable_functions'), 'mail') !== false) {
$disabled = $lang['i_disabled'];
2022-02-15 22:48:45 +01:00
} else {
$disabled = "";
}
2022-02-15 22:48:45 +01:00
$error[] = sprintf($lang['i_funcnmail'], $disabled);
}
2022-02-15 22:48:45 +01:00
foreach ($funcs as $func) {
if (!function_exists($func)) {
$error[] = sprintf($lang['i_funcna'], $func);
$ok = false;
}
}
return $ok;
}
/**
* Print language selection
*
* @author Andreas Gohr <andi@splitbrain.org>
*/
2022-02-15 22:48:45 +01:00
function langsel()
{
global $lang;
global $LC;
2022-02-15 22:48:45 +01:00
$dir = DOKU_INC . 'inc/lang';
2023-08-31 00:55:36 +02:00
$dh = opendir($dir);
2022-02-15 22:48:45 +01:00
if (!$dh) return;
2023-08-30 14:48:22 +02:00
$langs = [];
while (($file = readdir($dh)) !== false) {
2023-08-31 00:59:34 +02:00
if (preg_match('/^[._]/', $file)) continue;
2022-02-15 22:48:45 +01:00
if (is_dir($dir . '/' . $file) && file_exists($dir . '/' . $file . '/lang.php')) {
$langs[] = $file;
}
}
closedir($dh);
sort($langs);
echo '<form action="">';
echo $lang['i_chooselang'];
echo ': <select name="l" onchange="submit()">';
2022-02-15 22:48:45 +01:00
foreach ($langs as $l) {
$sel = ($l == $LC) ? 'selected="selected"' : '';
2022-02-15 22:48:45 +01:00
echo '<option value="' . $l . '" ' . $sel . '>' . $l . '</option>';
}
echo '</select> ';
2022-02-15 22:48:45 +01:00
echo '<button type="submit">' . $lang['btn_update'] . '</button>';
echo '</form>';
}
/**
* Print global error array
*
* @author Andreas Gohr <andi@splitbrain.org>
*/
2022-02-15 22:48:45 +01:00
function print_errors()
{
global $error;
2022-02-15 22:48:45 +01:00
if (!empty($error)) {
2012-06-25 00:24:07 +02:00
echo '<ul>';
2022-02-15 22:48:45 +01:00
foreach ($error as $err) {
2012-06-25 00:24:07 +02:00
echo "<li>$err</li>";
}
echo '</ul>';
}
}