diff --git a/TODO b/TODO index 8fb68a2..8c22d70 100755 --- a/TODO +++ b/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 * JSON output inc/Invoices.class.php : ======================== * Storage of users in ?!? +* Add / Edit a bill Manage paybacks : ================= * TODO : Payback system (class should be ok) -TODO : -====== -* Add / Edit a bill - To test : ========= * Connection form diff --git a/inc/Invoices.class.php b/inc/Invoices.class.php index a2c1661..35d705f 100644 --- a/inc/Invoices.class.php +++ b/inc/Invoices.class.php @@ -2,7 +2,6 @@ // TODO : Handle users_in require_once('data/config.php'); require_once('Storage.class.php'); - require_once('UsersIn.class.php'); class Invoice extends Storage { protected $id = 0, $date, $users_in, $guests, $buyer, $amount, $what; @@ -19,7 +18,6 @@ ); public function __construct() { - $users_in = new UsersIn(); parent::__construct(); } diff --git a/inc/Storage.class.php b/inc/Storage.class.php index bd8f193..b5caed4 100644 --- a/inc/Storage.class.php +++ b/inc/Storage.class.php @@ -151,7 +151,7 @@ class Storage { continue; if(substr($value, 0, 1) == ">" || substr($value, 0, 1) == "<") - $query->bindParam(':'.$field, substr($value, 0, 1); + $query->bindParam(':'.$field, substr($value, 0, 1)); else $query->bindParam(':'.$field, $value); } diff --git a/inc/functions.php b/inc/functions.php index b659ae1..fe93172 100644 --- a/inc/functions.php +++ b/inc/functions.php @@ -52,7 +52,7 @@ return 18; } - function listDirs($dir) { + function listTemplates($dir) { if(strrpos($dir, '/') !== strlen($dir) - 1) { $dir .= '/'; } @@ -62,7 +62,10 @@ if ($handle = opendir($dir)) { while (false !== ($entry = readdir($handle))) { 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); diff --git a/index.php b/index.php index 618ce39..f65d801 100644 --- a/index.php +++ b/index.php @@ -1,4 +1,16 @@ 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 if(!file_exists('data/config.php')) { header('location: install.php'); exit(); } require_once('data/config.php'); @@ -74,7 +86,7 @@ $user = new User(); $user->setLogin($_POST['login']); if(ban_canLogin() == false) { - $error = "Unknown username / password."; + $error = $errors['unknown_username_password'][LANG]; } else { $user = $user->exists($_POST['login']); @@ -99,7 +111,7 @@ } else { ban_loginFailed(); - $error = "Unknown username/password."; + $error = $errors['unknown_username_password'][LANG]; } } } @@ -127,11 +139,11 @@ exit(); } else { - $tpl->assign('error', 'Token error. Please resubmit the form.'); + $tpl->assign('error', $errors['token_error'][LANG]); } } 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'); @@ -169,11 +181,11 @@ exit(); } 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 { - $tpl->assign('error', 'Token error. Please resubmit the form.'); + $tpl->assign('error', $errors['token_error'][LANG]); } } @@ -231,51 +243,60 @@ break; 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(!is_writable('data/')) { - $tpl>assign('error', 'The script can\'t write in data/ dir, check permissions set on this folder.'); - } - $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(); + $tpl>assign('error', $errors['write_error_data'][LANG]); } 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 { - $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('show_settings', true); $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('lang', LANG); $tpl->draw('settings'); 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(check_token(600, 'new_invoice')) { if($_POST['amount'] <= 0) { - $tpl->assign('error', 'Negative amount.'); + $tpl->assign('error', $errors['negative_amount'][LANG]); } else { $invoice = new Invoice(); @@ -349,7 +371,7 @@ } } else { - $tpl->assign('error', 'Token error. Please resubmit the form.'); + $tpl->assign('error', $errors['token_error'][LANG]); } } diff --git a/install.php b/install.php index dc4e03f..fc8fed7 100644 --- a/install.php +++ b/install.php @@ -13,7 +13,7 @@ $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_login = $_POST['mysql_login']; $mysql_db = $_POST['mysql_db']; @@ -84,7 +84,8 @@ define('SALT', '".$salt."'); define('CURRENCY', '".$_POST['currency']."'); 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']."'); "; @@ -161,6 +162,7 @@ For example : Europe/Paris. See the doc for more info.

+

Administrator diff --git a/tpl/default/connection.html b/tpl/default_en/connection.html similarity index 100% rename from tpl/default/connection.html rename to tpl/default_en/connection.html diff --git a/tpl/default/css/style.css b/tpl/default_en/css/style.css similarity index 100% rename from tpl/default/css/style.css rename to tpl/default_en/css/style.css diff --git a/tpl/default/edit_users.html b/tpl/default_en/edit_users.html similarity index 100% rename from tpl/default/edit_users.html rename to tpl/default_en/edit_users.html diff --git a/tpl/default/footer.html b/tpl/default_en/footer.html similarity index 100% rename from tpl/default/footer.html rename to tpl/default_en/footer.html diff --git a/tpl/default/header.html b/tpl/default_en/header.html similarity index 100% rename from tpl/default/header.html rename to tpl/default_en/header.html diff --git a/tpl/default/img/toggleVisible.png b/tpl/default_en/img/toggleVisible.png similarity index 100% rename from tpl/default/img/toggleVisible.png rename to tpl/default_en/img/toggleVisible.png diff --git a/tpl/default/index.html b/tpl/default_en/index.html similarity index 100% rename from tpl/default/index.html rename to tpl/default_en/index.html diff --git a/tpl/default/js/jquery-1.10.2.min.js b/tpl/default_en/js/jquery-1.10.2.min.js similarity index 100% rename from tpl/default/js/jquery-1.10.2.min.js rename to tpl/default_en/js/jquery-1.10.2.min.js diff --git a/tpl/default/js/main.js b/tpl/default_en/js/main.js similarity index 100% rename from tpl/default/js/main.js rename to tpl/default_en/js/main.js diff --git a/tpl/default/new_invoice.html b/tpl/default_en/new_invoice.html similarity index 100% rename from tpl/default/new_invoice.html rename to tpl/default_en/new_invoice.html diff --git a/tpl/default/settings.html b/tpl/default_en/settings.html similarity index 91% rename from tpl/default/settings.html rename to tpl/default_en/settings.html index 8129c2e..0b4b156 100644 --- a/tpl/default/settings.html +++ b/tpl/default_en/settings.html @@ -57,6 +57,13 @@ {/loop} +

+ + +