Templates handling improved

This commit is contained in:
Phyks 2013-09-05 20:09:03 +02:00
parent c990823223
commit 94c46e4ef5
15 changed files with 34 additions and 5 deletions

4
TODO
View File

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

View File

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

View File

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

View File

@ -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']."');
";

View File

Before

Width:  |  Height:  |  Size: 490 B

After

Width:  |  Height:  |  Size: 490 B

View File

@ -49,6 +49,14 @@
<label for="timezone">Timezone : </label><input type="text" name="timezone" id="timezone" value="{$timezone}"/><br/>
<em>For example :</em> Europe/Paris. See the doc for more info.
</p>
<p>
<label for="template">Template : </label>
<select name="template" id="template">
{loop="templates"}
<option value="{$value}" {if condition="$value == $current_template"} selected="selected" {/if}>{$value}</option>
{/loop}
</select
</p>
<p><label for="email_webmaster">Webmaster's email : </label><input type="text" name="email_webmaster" id="email_webmaster" value="{$email_webmaster}"/></p>
</fieldset>
<p class="center"><input type="submit" value="Update settings"><input type="hidden" name="token" value="{$token}"/></p>