2023-01-31 00:30:04 +01:00
|
|
|
<?php
|
|
|
|
|
2023-02-12 00:30:36 +01:00
|
|
|
use EesyPHP\App;
|
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;
|
2023-02-28 20:52:29 +01:00
|
|
|
use EesyPHP\Url;
|
|
|
|
|
2024-02-18 19:40:58 +01:00
|
|
|
use EesyPHPExample\Db\Item;
|
2023-01-31 00:30:04 +01:00
|
|
|
|
2023-01-31 00:58:26 +01:00
|
|
|
use function EesyPHP\format_size;
|
|
|
|
|
2023-01-31 01:06:41 +01:00
|
|
|
if (php_sapi_name() == "cli")
|
|
|
|
return true;
|
|
|
|
|
2023-01-31 00:30:04 +01:00
|
|
|
// 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')
|
|
|
|
);
|
|
|
|
|
|
|
|
function define_common_template_variables($event) {
|
2024-02-18 19:40:58 +01:00
|
|
|
global $admin;
|
|
|
|
Tpl :: assign('statuses', Item :: statuses());
|
2023-01-31 00:30:04 +01:00
|
|
|
Tpl :: assign('admin', isset($admin) && $admin);
|
|
|
|
}
|
|
|
|
Hook :: register('before_displaying_template', 'define_common_template_variables');
|
|
|
|
|
|
|
|
// Templates functions
|
|
|
|
function smarty_item_status($params) {
|
2024-02-18 19:40:58 +01:00
|
|
|
$statuses = Item :: statuses();
|
2023-01-31 00:30:04 +01:00
|
|
|
$status2class = array (
|
|
|
|
'pending' => 'info',
|
|
|
|
'validated' => 'success',
|
|
|
|
'refused' => 'danger',
|
|
|
|
'archived' => 'secondary',
|
|
|
|
);
|
2024-02-18 17:21:54 +01:00
|
|
|
if (array_key_exists($params['item']->status, $status2class)) {
|
|
|
|
$class = $status2class[$params['item']->status];
|
2023-01-31 00:30:04 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
$class='danger';
|
2023-03-05 00:32:16 +01:00
|
|
|
echo "<span class='badge bg-$class'>";
|
2023-01-31 00:30:04 +01:00
|
|
|
echo (
|
2024-02-18 19:40:58 +01:00
|
|
|
array_key_exists($params['item']->status, $statuses)?
|
|
|
|
$statuses[$params['item']->status]:
|
2024-02-18 17:21:54 +01:00
|
|
|
"Inconnu (".$params['item']->status.")"
|
2023-01-31 00:30:04 +01:00
|
|
|
);
|
|
|
|
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'])) {
|
2023-02-28 20:52:29 +01:00
|
|
|
$params['url'] = Url::add_url_parameter($params['url'], 'order', $params['order']);
|
|
|
|
printf("<a href='%s'>%s</a>", $params['url'], $params['text']);
|
2023-01-31 00:30:04 +01:00
|
|
|
}
|
2023-02-28 20:52:29 +01:00
|
|
|
if ($params['order'] == $params['search']['order']) {
|
|
|
|
printf(
|
|
|
|
' <i class="fa fa-sort-%s" aria-hidden="true"></i>',
|
|
|
|
strtolower($params['search']['order_direction']) == 'asc'?
|
|
|
|
'up':'down'
|
|
|
|
);
|
2023-01-31 00:30:04 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
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
|