Started i18n system
This commit is contained in:
parent
0eba71c1dc
commit
285661b00a
6
TODO
6
TODO
@ -1,19 +1,15 @@
|
|||||||
* i18n : i18n of errors in index.php and use a different template for each translation
|
|
||||||
* Don't cache the username
|
* Don't cache the username
|
||||||
* JSON output
|
* JSON output
|
||||||
|
|
||||||
inc/Invoices.class.php :
|
inc/Invoices.class.php :
|
||||||
========================
|
========================
|
||||||
* Storage of users in ?!?
|
* Storage of users in ?!?
|
||||||
|
* Add / Edit a bill
|
||||||
|
|
||||||
Manage paybacks :
|
Manage paybacks :
|
||||||
=================
|
=================
|
||||||
* TODO : Payback system (class should be ok)
|
* TODO : Payback system (class should be ok)
|
||||||
|
|
||||||
TODO :
|
|
||||||
======
|
|
||||||
* Add / Edit a bill
|
|
||||||
|
|
||||||
To test :
|
To test :
|
||||||
=========
|
=========
|
||||||
* Connection form
|
* Connection form
|
||||||
|
@ -2,7 +2,6 @@
|
|||||||
// TODO : Handle users_in
|
// TODO : Handle users_in
|
||||||
require_once('data/config.php');
|
require_once('data/config.php');
|
||||||
require_once('Storage.class.php');
|
require_once('Storage.class.php');
|
||||||
require_once('UsersIn.class.php');
|
|
||||||
|
|
||||||
class Invoice extends Storage {
|
class Invoice extends Storage {
|
||||||
protected $id = 0, $date, $users_in, $guests, $buyer, $amount, $what;
|
protected $id = 0, $date, $users_in, $guests, $buyer, $amount, $what;
|
||||||
@ -19,7 +18,6 @@
|
|||||||
);
|
);
|
||||||
|
|
||||||
public function __construct() {
|
public function __construct() {
|
||||||
$users_in = new UsersIn();
|
|
||||||
parent::__construct();
|
parent::__construct();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -151,7 +151,7 @@ class Storage {
|
|||||||
continue;
|
continue;
|
||||||
|
|
||||||
if(substr($value, 0, 1) == ">" || substr($value, 0, 1) == "<")
|
if(substr($value, 0, 1) == ">" || substr($value, 0, 1) == "<")
|
||||||
$query->bindParam(':'.$field, substr($value, 0, 1);
|
$query->bindParam(':'.$field, substr($value, 0, 1));
|
||||||
else
|
else
|
||||||
$query->bindParam(':'.$field, $value);
|
$query->bindParam(':'.$field, $value);
|
||||||
}
|
}
|
||||||
|
@ -52,7 +52,7 @@
|
|||||||
return 18;
|
return 18;
|
||||||
}
|
}
|
||||||
|
|
||||||
function listDirs($dir) {
|
function listTemplates($dir) {
|
||||||
if(strrpos($dir, '/') !== strlen($dir) - 1) {
|
if(strrpos($dir, '/') !== strlen($dir) - 1) {
|
||||||
$dir .= '/';
|
$dir .= '/';
|
||||||
}
|
}
|
||||||
@ -62,7 +62,10 @@
|
|||||||
if ($handle = opendir($dir)) {
|
if ($handle = opendir($dir)) {
|
||||||
while (false !== ($entry = readdir($handle))) {
|
while (false !== ($entry = readdir($handle))) {
|
||||||
if ($entry != "." && $entry != ".." && is_dir($dir.$entry)) {
|
if ($entry != "." && $entry != ".." && is_dir($dir.$entry)) {
|
||||||
$return[] = $entry;
|
$entry = str_replace(array('_en', '_fr'), array('', ''), $entry);
|
||||||
|
|
||||||
|
if(!in_array($entry, $return))
|
||||||
|
$return[] = $entry;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
closedir($handle);
|
closedir($handle);
|
||||||
|
116
index.php
116
index.php
@ -1,4 +1,16 @@
|
|||||||
<?php
|
<?php
|
||||||
|
// Error translation
|
||||||
|
$errors = array(
|
||||||
|
'unknown_username_password'=>array('fr'=>'Nom d\'utilisateur ou mot de passe inconnu.', 'en'=>'Unknown username or password.'),
|
||||||
|
'token_error'=>array('fr'=>'Erreur de token. Veuillez réessayer.', 'en'=>'Token error. Please resubmit the form.'),
|
||||||
|
'password_mismatch'=>array('fr'=>'Les deux mots de passe ne correspondent pas.', 'en'=>'The content of the two passwords fields doesn\'t match.'),
|
||||||
|
'user_already_exists'=>array('fr'=>'Un utilisateur avec le même login ou nom d\'affichage existe déjà. Choisissez un login ou un nom d\'affichage différent.', 'en'=>'A user with the same login or display name already exists. Choose a different login or display name.'),
|
||||||
|
'write_error_data'=>array('fr'=>'Le script ne peut pas écrire dans le dossier data/, vérifiez les permissions sur ce dossier.', 'en'=>'The script can\'t write in data/ dir, check permissions set on this folder.'),
|
||||||
|
'unable_write_config'=>array('fr'=>'Impossible d\'écrire le fichier data/config.php. Vérifiez les permissions.', 'en'=>'Unable to write data/config.php file. Check permissions.'),
|
||||||
|
'negative_amount'=>array('fr'=>'Montant négatif non autorisé.', 'en'=>'Negative amount not allowed.'),
|
||||||
|
'template_lang_error'=>array('fr'=>'Template non disponible pour la langue choisie. Modifiez les paramètres de langue ou de template.', 'en'=>'Template not available for the selected lang. Change the lang or the template setting.')
|
||||||
|
);
|
||||||
|
|
||||||
// Include necessary files
|
// Include necessary files
|
||||||
if(!file_exists('data/config.php')) { header('location: install.php'); exit(); }
|
if(!file_exists('data/config.php')) { header('location: install.php'); exit(); }
|
||||||
require_once('data/config.php');
|
require_once('data/config.php');
|
||||||
@ -74,7 +86,7 @@
|
|||||||
$user = new User();
|
$user = new User();
|
||||||
$user->setLogin($_POST['login']);
|
$user->setLogin($_POST['login']);
|
||||||
if(ban_canLogin() == false) {
|
if(ban_canLogin() == false) {
|
||||||
$error = "Unknown username / password.";
|
$error = $errors['unknown_username_password'][LANG];
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
$user = $user->exists($_POST['login']);
|
$user = $user->exists($_POST['login']);
|
||||||
@ -99,7 +111,7 @@
|
|||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
ban_loginFailed();
|
ban_loginFailed();
|
||||||
$error = "Unknown username/password.";
|
$error = $errors['unknown_username_password'][LANG];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -127,11 +139,11 @@
|
|||||||
exit();
|
exit();
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
$tpl->assign('error', 'Token error. Please resubmit the form.');
|
$tpl->assign('error', $errors['token_error'][LANG]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
$tpl->assign('error', 'The content of the two password fields doesn\'t match.');
|
$tpl->assign('error', $errors['password_mismatch'][LANG]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
$tpl->assign('view', 'password');
|
$tpl->assign('view', 'password');
|
||||||
@ -169,11 +181,11 @@
|
|||||||
exit();
|
exit();
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
$tpl->assign('error', 'A user with the same login or display name already exists. Choose a different login.');
|
$tpl->assign('error', $errors['user_already_exists'][LANG]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
$tpl->assign('error', 'Token error. Please resubmit the form.');
|
$tpl->assign('error', $errors['token_error'][LANG]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -231,51 +243,60 @@
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
case 'settings':
|
case 'settings':
|
||||||
if(!empty($_POST['mysql_host']) && !empty($_POST['mysql_login']) && !empty($_POST['mysql_db']) && !empty($_POST['currency']) && !empty($_POST['instance_title']) && !empty($_POST['base_url']) && !empty($_POST['timezone']) && !empty($_POST['email_webmaster']) && !empty($_POST['template'])) {
|
if(!empty($_POST['mysql_host']) && !empty($_POST['mysql_login']) && !empty($_POST['mysql_db']) && !empty($_POST['currency']) && !empty($_POST['instance_title']) && !empty($_POST['base_url']) && !empty($_POST['timezone']) && !empty($_POST['email_webmaster']) && !empty($_POST['template']) && !empty($_POST['lang'])) {
|
||||||
if(check_token(600, 'settings')) {
|
if(check_token(600, 'settings')) {
|
||||||
if(!is_writable('data/')) {
|
if(!is_writable('data/')) {
|
||||||
$tpl>assign('error', 'The script can\'t write in data/ dir, check permissions set on this folder.');
|
$tpl>assign('error', $errors['write_error_data'][LANG]);
|
||||||
}
|
|
||||||
$config = file('data/config.php');
|
|
||||||
|
|
||||||
foreach($config as $line_number=>$line) {
|
|
||||||
if(strpos($line, "MYSQL_HOST") !== FALSE)
|
|
||||||
$config[$line_number] = "\tdefine('MYSQL_HOST', '".$_POST['mysql_host']."');\n";
|
|
||||||
elseif(strpos($line, "MYSQL_LOGIN") !== FALSE)
|
|
||||||
$config[$line_number] = "\tdefine('MYSQL_LOGIN', '".$_POST['mysql_login']."');\n";
|
|
||||||
elseif(strpos($line, "MYSQL_PASSWORD") !== FALSE && !empty($_POST['mysql_password']))
|
|
||||||
$config[$line_number] = "\tdefine('MYSQL_PASSWORD', '".$_POST['mysql_password']."');\n";
|
|
||||||
elseif(strpos($line, "MYSQL_DB") !== FALSE)
|
|
||||||
$config[$line_number] = "\tdefine('MYSQL_DB', '".$_POST['mysql_db']."');\n";
|
|
||||||
elseif(strpos($line, "MYSQL_PREFIX") !== FALSE && !empty($_POST['mysql_prefix']))
|
|
||||||
$config[$line_number] = "\tdefine('MYSQL_PREFIX', '".$_POST['mysql_prefix']."');\n";
|
|
||||||
elseif(strpos($line, "INSTANCE_TITLE") !== FALSE)
|
|
||||||
$config[$line_number] = "\tdefine('INSTANCE_TITLE', '".$_POST['instance_title']."');\n";
|
|
||||||
elseif(strpos($line, "BASE_URL") !== FALSE)
|
|
||||||
$config[$line_number] = "\tdefine('BASE_URL', '".$_POST['base_url']."');\n";
|
|
||||||
elseif(strpos($line, "CURRENCY") !== FALSE)
|
|
||||||
$config[$line_number] = "\tdefine('CURRENCY', '".$_POST['currency']."');\n";
|
|
||||||
elseif(strpos($line, "EMAIL_WEBMASTER") !== FALSE)
|
|
||||||
$config[$line_number] = "\tdefine('EMAIL_WEBMASTER', '".$_POST['email_webmaster']."');\n";
|
|
||||||
elseif(strpos($line, "TEMPLATE_DIR") !== FALSE)
|
|
||||||
$config[$line_number] = "\tdefine('TEMPLATE_DIR', 'tpl/".$_POST['template']."/');\n";
|
|
||||||
elseif(strpos($line_number, 'date_default_timezone_set') !== FALSE)
|
|
||||||
$config[$line_number] = "\tdate_default_timezone_set('".$_POST['timezone']."');\n";
|
|
||||||
}
|
|
||||||
|
|
||||||
if(file_put_contents("data/config.php", $config)) {
|
|
||||||
// Clear the cache
|
|
||||||
array_map("unlink", glob(raintpl::$cache_dir."*.rtpl.php"));
|
|
||||||
|
|
||||||
header('location: index.php');
|
|
||||||
exit();
|
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
$tpl->assign('error', 'Unable to write data/config.php file.');
|
if(!is_dir('tpl/'.$_POST['template'].'_'.$_POST['lang'])) {
|
||||||
|
$tpl->assign('error', $errors['template_lang_error'][LANG]);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
$config = file('data/config.php');
|
||||||
|
|
||||||
|
foreach($config as $line_number=>$line) {
|
||||||
|
if(strpos($line, "MYSQL_HOST") !== FALSE)
|
||||||
|
$config[$line_number] = "\tdefine('MYSQL_HOST', '".$_POST['mysql_host']."');\n";
|
||||||
|
elseif(strpos($line, "MYSQL_LOGIN") !== FALSE)
|
||||||
|
$config[$line_number] = "\tdefine('MYSQL_LOGIN', '".$_POST['mysql_login']."');\n";
|
||||||
|
elseif(strpos($line, "MYSQL_PASSWORD") !== FALSE && !empty($_POST['mysql_password']))
|
||||||
|
$config[$line_number] = "\tdefine('MYSQL_PASSWORD', '".$_POST['mysql_password']."');\n";
|
||||||
|
elseif(strpos($line, "MYSQL_DB") !== FALSE)
|
||||||
|
$config[$line_number] = "\tdefine('MYSQL_DB', '".$_POST['mysql_db']."');\n";
|
||||||
|
elseif(strpos($line, "MYSQL_PREFIX") !== FALSE && !empty($_POST['mysql_prefix']))
|
||||||
|
$config[$line_number] = "\tdefine('MYSQL_PREFIX', '".$_POST['mysql_prefix']."');\n";
|
||||||
|
elseif(strpos($line, "INSTANCE_TITLE") !== FALSE)
|
||||||
|
$config[$line_number] = "\tdefine('INSTANCE_TITLE', '".$_POST['instance_title']."');\n";
|
||||||
|
elseif(strpos($line, "BASE_URL") !== FALSE)
|
||||||
|
$config[$line_number] = "\tdefine('BASE_URL', '".$_POST['base_url']."');\n";
|
||||||
|
elseif(strpos($line, "CURRENCY") !== FALSE)
|
||||||
|
$config[$line_number] = "\tdefine('CURRENCY', '".$_POST['currency']."');\n";
|
||||||
|
elseif(strpos($line, "EMAIL_WEBMASTER") !== FALSE)
|
||||||
|
$config[$line_number] = "\tdefine('EMAIL_WEBMASTER', '".$_POST['email_webmaster']."');\n";
|
||||||
|
elseif(strpos($line, "TEMPLATE_DIR") !== FALSE)
|
||||||
|
$config[$line_number] = "\tdefine('TEMPLATE_DIR', 'tpl/".$_POST['template']."_".$_POST['lang']."/');\n";
|
||||||
|
elseif(strpos($line, "LANG") !== FALSE)
|
||||||
|
$config[$line_number] = "\tdefine('LANG', '".$_POST['lang']."');\n";
|
||||||
|
elseif(strpos($line_number, 'date_default_timezone_set') !== FALSE)
|
||||||
|
$config[$line_number] = "\tdate_default_timezone_set('".$_POST['timezone']."');\n";
|
||||||
|
}
|
||||||
|
|
||||||
|
if(file_put_contents("data/config.php", $config)) {
|
||||||
|
// Clear the cache
|
||||||
|
array_map("unlink", glob(raintpl::$cache_dir."*.rtpl.php"));
|
||||||
|
|
||||||
|
header('location: index.php');
|
||||||
|
exit();
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
$tpl->assign('error', $errors['unable_write_config'][LANG]);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
$tpl->assign('error', 'Token error. Please resubmit the form.');
|
$tpl->assign('error', $errors['token_error'][LANG]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -286,8 +307,9 @@
|
|||||||
$tpl->assign('timezone', @date_default_timezone_get());
|
$tpl->assign('timezone', @date_default_timezone_get());
|
||||||
$tpl->assign('show_settings', true);
|
$tpl->assign('show_settings', true);
|
||||||
$tpl->assign('token', generate_token('settings'));
|
$tpl->assign('token', generate_token('settings'));
|
||||||
$tpl->assign('templates', listDirs('tpl/'));
|
$tpl->assign('templates', listTemplates('tpl/'));
|
||||||
$tpl->assign('current_template', trim(substr(TEMPLATE_DIR, 4), '/'));
|
$tpl->assign('current_template', trim(substr(TEMPLATE_DIR, 4), '/'));
|
||||||
|
$tpl->assign('lang', LANG);
|
||||||
$tpl->draw('settings');
|
$tpl->draw('settings');
|
||||||
break;
|
break;
|
||||||
|
|
||||||
@ -317,7 +339,7 @@
|
|||||||
if(!empty($_POST['what']) && !empty($_POST['amount']) && (float) $_POST['amount'] != 0 && !empty($_POST['date_hour']) && !empty($_POST['date_day']) && !empty($_POST['date_month']) && !empty($_POST['date_year']) && !empty($_POST['users_in'])) {
|
if(!empty($_POST['what']) && !empty($_POST['amount']) && (float) $_POST['amount'] != 0 && !empty($_POST['date_hour']) && !empty($_POST['date_day']) && !empty($_POST['date_month']) && !empty($_POST['date_year']) && !empty($_POST['users_in'])) {
|
||||||
if(check_token(600, 'new_invoice')) {
|
if(check_token(600, 'new_invoice')) {
|
||||||
if($_POST['amount'] <= 0) {
|
if($_POST['amount'] <= 0) {
|
||||||
$tpl->assign('error', 'Negative amount.');
|
$tpl->assign('error', $errors['negative_amount'][LANG]);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
$invoice = new Invoice();
|
$invoice = new Invoice();
|
||||||
@ -349,7 +371,7 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
$tpl->assign('error', 'Token error. Please resubmit the form.');
|
$tpl->assign('error', $errors['token_error'][LANG]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -13,7 +13,7 @@
|
|||||||
$block_form = true;
|
$block_form = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!empty($_POST['mysql_host']) && !empty($_POST['mysql_login']) && !empty($_POST['mysql_db']) && !empty($_POST['admin_login']) && !empty($_POST['admin_password']) && !empty($_POST['currency']) && !empty($_POST['instance_title']) && !empty($_POST['base_url']) && !empty($_POST['timezone']) && !empty($_POST['email_webmaster']) && check_token(600, 'install')) {
|
if(!empty($_POST['mysql_host']) && !empty($_POST['mysql_login']) && !empty($_POST['mysql_db']) && !empty($_POST['admin_login']) && !empty($_POST['admin_password']) && !empty($_POST['currency']) && !empty($_POST['instance_title']) && !empty($_POST['base_url']) && !empty($_POST['timezone']) && !empty($_POST['email_webmaster']) && check_token(600, 'install') && !empty($_POST['lang'])) {
|
||||||
$mysql_host = $_POST['mysql_host'];
|
$mysql_host = $_POST['mysql_host'];
|
||||||
$mysql_login = $_POST['mysql_login'];
|
$mysql_login = $_POST['mysql_login'];
|
||||||
$mysql_db = $_POST['mysql_db'];
|
$mysql_db = $_POST['mysql_db'];
|
||||||
@ -84,7 +84,8 @@
|
|||||||
define('SALT', '".$salt."');
|
define('SALT', '".$salt."');
|
||||||
define('CURRENCY', '".$_POST['currency']."');
|
define('CURRENCY', '".$_POST['currency']."');
|
||||||
define('EMAIL_WEBMASTER', '".$_POST['email_webmaster']."');
|
define('EMAIL_WEBMASTER', '".$_POST['email_webmaster']."');
|
||||||
define('TEMPLATE_DIR', 'tpl/default/');
|
define('TEMPLATE_DIR', 'tpl/default_".$_POST['lang']."/');
|
||||||
|
define('LANG', '".$_POST['lang']."');
|
||||||
|
|
||||||
date_default_timezone_set('".$_POST['timezone']."');
|
date_default_timezone_set('".$_POST['timezone']."');
|
||||||
";
|
";
|
||||||
@ -161,6 +162,7 @@
|
|||||||
<em>For example :</em> Europe/Paris. See the doc for more info.
|
<em>For example :</em> Europe/Paris. See the doc for more info.
|
||||||
</p>
|
</p>
|
||||||
<p><label for="email_webmaster">Webmaster's email : </label><input type="text" name="email_webmaster" id="email_webmaster"/></p>
|
<p><label for="email_webmaster">Webmaster's email : </label><input type="text" name="email_webmaster" id="email_webmaster"/></p>
|
||||||
|
<p><label for="lang">Lang : </label><select name="lang" id="lang"><option value="en">English</option><option value="fr">French</option></select></p>
|
||||||
</fieldset>
|
</fieldset>
|
||||||
<fieldset>
|
<fieldset>
|
||||||
<legend>Administrator</legend>
|
<legend>Administrator</legend>
|
||||||
|
Before Width: | Height: | Size: 490 B After Width: | Height: | Size: 490 B |
@ -57,6 +57,13 @@
|
|||||||
{/loop}
|
{/loop}
|
||||||
</select
|
</select
|
||||||
</p>
|
</p>
|
||||||
|
<p>
|
||||||
|
<label for="lang">Lang : </label>
|
||||||
|
<select name="lang" id="lang">
|
||||||
|
<option value="en" {if condition="$lang == 'en'"} selected="selected"{/if}>English</option>
|
||||||
|
<option value="fr" {if condition="$lang == 'fr'"} selected="selected"{/if}>French</option>
|
||||||
|
</select>
|
||||||
|
</p>
|
||||||
<p><label for="email_webmaster">Webmaster's email : </label><input type="text" name="email_webmaster" id="email_webmaster" value="{$email_webmaster}"/></p>
|
<p><label for="email_webmaster">Webmaster's email : </label><input type="text" name="email_webmaster" id="email_webmaster" value="{$email_webmaster}"/></p>
|
||||||
</fieldset>
|
</fieldset>
|
||||||
<p class="center"><input type="submit" value="Update settings"><input type="hidden" name="token" value="{$token}"/></p>
|
<p class="center"><input type="submit" value="Update settings"><input type="hidden" name="token" value="{$token}"/></p>
|
Loading…
Reference in New Issue
Block a user