Started i18n system

This commit is contained in:
Phyks 2013-09-05 23:46:51 +02:00
parent 0eba71c1dc
commit 285661b00a
17 changed files with 87 additions and 59 deletions

6
TODO
View File

@ -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

View File

@ -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();
} }

View File

@ -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);
} }

View File

@ -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,6 +62,9 @@
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)) {
$entry = str_replace(array('_en', '_fr'), array('', ''), $entry);
if(!in_array($entry, $return))
$return[] = $entry; $return[] = $entry;
} }
} }

View File

@ -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,11 +243,16 @@
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]);
} }
else {
if(!is_dir('tpl/'.$_POST['template'].'_'.$_POST['lang'])) {
$tpl->assign('error', $errors['template_lang_error'][LANG]);
}
else {
$config = file('data/config.php'); $config = file('data/config.php');
foreach($config as $line_number=>$line) { foreach($config as $line_number=>$line) {
@ -258,7 +275,9 @@
elseif(strpos($line, "EMAIL_WEBMASTER") !== FALSE) elseif(strpos($line, "EMAIL_WEBMASTER") !== FALSE)
$config[$line_number] = "\tdefine('EMAIL_WEBMASTER', '".$_POST['email_webmaster']."');\n"; $config[$line_number] = "\tdefine('EMAIL_WEBMASTER', '".$_POST['email_webmaster']."');\n";
elseif(strpos($line, "TEMPLATE_DIR") !== FALSE) elseif(strpos($line, "TEMPLATE_DIR") !== FALSE)
$config[$line_number] = "\tdefine('TEMPLATE_DIR', 'tpl/".$_POST['template']."/');\n"; $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) elseif(strpos($line_number, 'date_default_timezone_set') !== FALSE)
$config[$line_number] = "\tdate_default_timezone_set('".$_POST['timezone']."');\n"; $config[$line_number] = "\tdate_default_timezone_set('".$_POST['timezone']."');\n";
} }
@ -271,11 +290,13 @@
exit(); exit();
} }
else { else {
$tpl->assign('error', 'Unable to write data/config.php file.'); $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]);
} }
} }

View File

@ -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>

View File

Before

Width:  |  Height:  |  Size: 490 B

After

Width:  |  Height:  |  Size: 490 B

View File

@ -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>