From 94c46e4ef57a11a0d6e3bc435796fd2f90bf0ae2 Mon Sep 17 00:00:00 2001
From: Phyks
Date: Thu, 5 Sep 2013 20:09:03 +0200
Subject: [PATCH] Templates handling improved
---
TODO | 4 +---
inc/functions.php | 18 ++++++++++++++++++
index.php | 8 ++++++--
install.php | 1 +
tpl/{ => default}/connection.html | 0
tpl/{ => default}/css/style.css | 0
tpl/{ => default}/edit_users.html | 0
tpl/{ => default}/footer.html | 0
tpl/{ => default}/header.html | 0
tpl/{ => default}/img/toggleVisible.png | Bin
tpl/{ => default}/index.html | 0
tpl/{ => default}/js/jquery-1.10.2.min.js | 0
tpl/{ => default}/js/main.js | 0
tpl/{ => default}/new_invoice.html | 0
tpl/{ => default}/settings.html | 8 ++++++++
15 files changed, 34 insertions(+), 5 deletions(-)
rename tpl/{ => default}/connection.html (100%)
rename tpl/{ => default}/css/style.css (100%)
rename tpl/{ => default}/edit_users.html (100%)
rename tpl/{ => default}/footer.html (100%)
rename tpl/{ => default}/header.html (100%)
rename tpl/{ => default}/img/toggleVisible.png (100%)
rename tpl/{ => default}/index.html (100%)
rename tpl/{ => default}/js/jquery-1.10.2.min.js (100%)
rename tpl/{ => default}/js/main.js (100%)
rename tpl/{ => default}/new_invoice.html (100%)
rename tpl/{ => default}/settings.html (90%)
diff --git a/TODO b/TODO
index 14a5cb8..bf637c4 100755
--- a/TODO
+++ b/TODO
@@ -2,7 +2,7 @@
inc/Invoices.class.php :
========================
-* Modify store() method to handle storage
+* Storage ?
* Modify load() method to handle complex queries (such as WHERE date < DATE_1 AND date > DATE_2)
==========
@@ -17,8 +17,6 @@ TODO :
======
* Add / Edit a bill
* JSON output
-* Arrow to toggle visible password
-* Change tpl easily
To test :
=========
diff --git a/inc/functions.php b/inc/functions.php
index f028f37..b659ae1 100644
--- a/inc/functions.php
+++ b/inc/functions.php
@@ -51,3 +51,21 @@
else
return 18;
}
+
+ function listDirs($dir) {
+ if(strrpos($dir, '/') !== strlen($dir) - 1) {
+ $dir .= '/';
+ }
+
+ $return = array();
+
+ if ($handle = opendir($dir)) {
+ while (false !== ($entry = readdir($handle))) {
+ if ($entry != "." && $entry != ".." && is_dir($dir.$entry)) {
+ $return[] = $entry;
+ }
+ }
+ closedir($handle);
+ }
+ return $return;
+ }
diff --git a/index.php b/index.php
index 9db140f..618ce39 100644
--- a/index.php
+++ b/index.php
@@ -8,7 +8,7 @@
require_once('inc/functions.php');
require_once('inc/Ban.inc.php');
require_once('inc/CSRF.inc.php');
- raintpl::$tpl_dir = 'tpl/';
+ raintpl::$tpl_dir = TEMPLATE_DIR;
raintpl::$cache_dir = 'tmp/';
// Define raintpl instance
@@ -231,7 +231,7 @@
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'])) {
+ 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(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.');
@@ -257,6 +257,8 @@
$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";
}
@@ -284,6 +286,8 @@
$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('current_template', trim(substr(TEMPLATE_DIR, 4), '/'));
$tpl->draw('settings');
break;
diff --git a/install.php b/install.php
index 6207175..dc4e03f 100644
--- a/install.php
+++ b/install.php
@@ -84,6 +84,7 @@
define('SALT', '".$salt."');
define('CURRENCY', '".$_POST['currency']."');
define('EMAIL_WEBMASTER', '".$_POST['email_webmaster']."');
+ define('TEMPLATE_DIR', 'tpl/default/');
date_default_timezone_set('".$_POST['timezone']."');
";
diff --git a/tpl/connection.html b/tpl/default/connection.html
similarity index 100%
rename from tpl/connection.html
rename to tpl/default/connection.html
diff --git a/tpl/css/style.css b/tpl/default/css/style.css
similarity index 100%
rename from tpl/css/style.css
rename to tpl/default/css/style.css
diff --git a/tpl/edit_users.html b/tpl/default/edit_users.html
similarity index 100%
rename from tpl/edit_users.html
rename to tpl/default/edit_users.html
diff --git a/tpl/footer.html b/tpl/default/footer.html
similarity index 100%
rename from tpl/footer.html
rename to tpl/default/footer.html
diff --git a/tpl/header.html b/tpl/default/header.html
similarity index 100%
rename from tpl/header.html
rename to tpl/default/header.html
diff --git a/tpl/img/toggleVisible.png b/tpl/default/img/toggleVisible.png
similarity index 100%
rename from tpl/img/toggleVisible.png
rename to tpl/default/img/toggleVisible.png
diff --git a/tpl/index.html b/tpl/default/index.html
similarity index 100%
rename from tpl/index.html
rename to tpl/default/index.html
diff --git a/tpl/js/jquery-1.10.2.min.js b/tpl/default/js/jquery-1.10.2.min.js
similarity index 100%
rename from tpl/js/jquery-1.10.2.min.js
rename to tpl/default/js/jquery-1.10.2.min.js
diff --git a/tpl/js/main.js b/tpl/default/js/main.js
similarity index 100%
rename from tpl/js/main.js
rename to tpl/default/js/main.js
diff --git a/tpl/new_invoice.html b/tpl/default/new_invoice.html
similarity index 100%
rename from tpl/new_invoice.html
rename to tpl/default/new_invoice.html
diff --git a/tpl/settings.html b/tpl/default/settings.html
similarity index 90%
rename from tpl/settings.html
rename to tpl/default/settings.html
index a5b25ee..8129c2e 100644
--- a/tpl/settings.html
+++ b/tpl/default/settings.html
@@ -49,6 +49,14 @@
For example : Europe/Paris. See the doc for more info.
+
+
+