2023-01-31 00:30:04 +01:00
|
|
|
<?php
|
|
|
|
|
2023-01-31 00:56:44 +01:00
|
|
|
use EesyPHP\Date;
|
2023-01-31 00:30:04 +01:00
|
|
|
use EesyPHP\Hook;
|
|
|
|
use EesyPHP\Log;
|
|
|
|
use EesyPHP\Tpl;
|
|
|
|
|
|
|
|
if (php_sapi_name() == "cli")
|
|
|
|
return true;
|
|
|
|
|
|
|
|
Tpl :: init(
|
|
|
|
isset($smarty_templates_dir)?$smarty_templates_dir:null,
|
|
|
|
isset($smarty_templates_c_dir)?$smarty_templates_c_dir:null,
|
|
|
|
isset($debug_ajax)?$debug_ajax:false
|
|
|
|
);
|
|
|
|
|
|
|
|
// Enable Smarty security
|
|
|
|
Tpl :: enable_security_mode(
|
|
|
|
// Allow some functions in IF clauses
|
|
|
|
array(
|
|
|
|
'isset', 'empty', 'count', 'in_array', 'is_array', 'array_key_exists', 'is_null',
|
|
|
|
'can_modify', 'can_archive', 'can_delete'
|
|
|
|
),
|
|
|
|
// Allow some modifier functions
|
|
|
|
array('range', 'implode', 'stripslashes')
|
|
|
|
);
|
|
|
|
|
|
|
|
// Defined some global template variables
|
|
|
|
Tpl :: assign('public_root_url', isset($public_root_url)?$public_root_url:'/');
|
|
|
|
Tpl :: assign('main_pagetitle', isset($main_pagetitle)?$main_pagetitle:null);
|
|
|
|
Tpl :: assign('session_key', $_SESSION['session_key']);
|
|
|
|
|
|
|
|
// Handle CSS & JS files included
|
|
|
|
if (isset($included_css_files) && is_array($included_css_files))
|
|
|
|
Tpl :: add_css_file($included_css_files);
|
|
|
|
if (isset($included_js_files) && is_array($included_js_files))
|
|
|
|
Tpl :: add_css_file($included_js_files);
|
|
|
|
|
|
|
|
function define_common_template_variables($event) {
|
|
|
|
global $status_list, $admin, $webstats_js_code;
|
|
|
|
Tpl :: assign(
|
|
|
|
'status_list',
|
|
|
|
isset($status_list) && is_array($status_list)?
|
|
|
|
$status_list:array()
|
|
|
|
);
|
|
|
|
Tpl :: assign('admin', isset($admin) && $admin);
|
|
|
|
Tpl :: assign(
|
|
|
|
'webstats_js_code',
|
|
|
|
isset($webstats_js_code)?$webstats_js_code:null);
|
|
|
|
}
|
|
|
|
Hook :: register('before_displaying_template', 'define_common_template_variables');
|
|
|
|
|
|
|
|
// Templates functions
|
|
|
|
function smarty_item_status($params) {
|
|
|
|
global $status_list;
|
|
|
|
$status2class = array (
|
|
|
|
'pending' => 'info',
|
|
|
|
'validated' => 'success',
|
|
|
|
'refused' => 'danger',
|
|
|
|
'archived' => 'secondary',
|
|
|
|
);
|
|
|
|
if (array_key_exists($params['item']['status'], $status2class)) {
|
|
|
|
$class = $status2class[$params['item']['status']];
|
|
|
|
}
|
|
|
|
else
|
|
|
|
$class='danger';
|
|
|
|
echo "<span class='badge badge-$class'>";
|
|
|
|
echo (
|
|
|
|
array_key_exists($params['item']['status'], $status_list)?
|
|
|
|
$status_list[$params['item']['status']]:
|
|
|
|
"Inconnu (".$params['item']['status'].")"
|
|
|
|
);
|
|
|
|
echo "</span>";
|
|
|
|
}
|
|
|
|
Tpl :: register_function('item_status','smarty_item_status');
|
|
|
|
|
|
|
|
function smarty_format_time($params) {
|
2023-01-31 00:56:44 +01:00
|
|
|
echo Date :: format($params['time'], (!isset($params['with_time']) || (bool)$params['with_time']));
|
2023-01-31 00:30:04 +01:00
|
|
|
}
|
|
|
|
Tpl :: register_function('format_time','smarty_format_time');
|
|
|
|
|
|
|
|
function smarty_format_size($params, $smarty) {
|
|
|
|
if(!isset($params['digit'])) $params['digit'] = 2;
|
|
|
|
echo format_size($params['size'],$params['digit']);
|
|
|
|
}
|
|
|
|
Tpl :: register_function('format_size','smarty_format_size');
|
|
|
|
|
|
|
|
function smarty_table_ordered_th($params, $smarty) {
|
|
|
|
if ($params['order'] && $params['url'] && $params['text'] && is_array($params['search'])) {
|
|
|
|
$params['url'] .= (strpos($params['url'], '?') === false?'?':'&')."order=".$params['order'];
|
|
|
|
echo "<a href='".$params['url']."'>".$params['text']."</a>";
|
|
|
|
}
|
|
|
|
if ($params['order']==$params['search']['order']) {
|
|
|
|
echo (
|
|
|
|
' <i class="fa fa-sort-'.
|
|
|
|
(strtolower($params['search']['order_direction'])=='asc'?'up':'down').
|
|
|
|
'" aria-hidden="true"></i>');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
Tpl :: register_function('table_ordered_th','smarty_table_ordered_th');
|
|
|
|
|
|
|
|
function smarty_encodeJsonBase64($params, $smarty) {
|
|
|
|
if (isset($params['data']))
|
|
|
|
echo base64_encode(json_encode($params['data']));
|
|
|
|
}
|
|
|
|
Tpl :: register_function('encodeJsonBase64','smarty_encodeJsonBase64');
|
|
|
|
|
|
|
|
# vim: tabstop=2 shiftwidth=2 softtabstop=2 expandtab
|