2017-08-04 16:28:16 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
include_once __DIR__.'/core.php';
|
|
|
|
|
2019-02-22 10:37:37 +01:00
|
|
|
use Util\Query;
|
|
|
|
|
2017-08-04 16:28:16 +02:00
|
|
|
// Informazioni fondamentali
|
|
|
|
$columns = filter('columns');
|
|
|
|
$order = filter('order')[0];
|
2019-07-09 12:29:39 +02:00
|
|
|
$draw_numer = intval(filter('draw'));
|
2017-08-04 16:28:16 +02:00
|
|
|
|
|
|
|
$order['column'] = $order['column'] - 1;
|
|
|
|
array_shift($columns);
|
|
|
|
|
2019-02-01 17:44:31 +01:00
|
|
|
$total = Util\Query::readQuery($structure);
|
2018-02-14 11:10:03 +01:00
|
|
|
|
2019-02-01 17:44:31 +01:00
|
|
|
// Ricerca
|
|
|
|
$search = [];
|
|
|
|
for ($i = 0; $i < count($columns); ++$i) {
|
|
|
|
if (!empty($columns[$i]['search']['value'])) {
|
|
|
|
$search[$total['fields'][$i]] = $columns[$i]['search']['value'];
|
2017-12-14 21:46:45 +01:00
|
|
|
}
|
2019-02-01 17:44:31 +01:00
|
|
|
}
|
2017-08-04 16:28:16 +02:00
|
|
|
|
2019-02-01 17:44:31 +01:00
|
|
|
$limit = [
|
|
|
|
'start' => filter('start'),
|
|
|
|
'length' => filter('length'),
|
|
|
|
];
|
2017-08-04 16:28:16 +02:00
|
|
|
|
2019-02-01 17:44:31 +01:00
|
|
|
// Predisposizione della risposta
|
|
|
|
$results = [
|
|
|
|
'data' => [],
|
|
|
|
'recordsTotal' => 0,
|
|
|
|
'recordsFiltered' => 0,
|
|
|
|
'summable' => [],
|
2019-07-09 12:29:39 +02:00
|
|
|
'draw' => $draw_numer,
|
2019-02-01 17:44:31 +01:00
|
|
|
];
|
2017-08-04 16:28:16 +02:00
|
|
|
|
2019-02-22 10:37:37 +01:00
|
|
|
$query = Query::getQuery($structure);
|
2019-02-01 17:44:31 +01:00
|
|
|
if (!empty($query)) {
|
|
|
|
// CONTEGGIO TOTALE
|
|
|
|
$results['recordsTotal'] = $dbo->fetchNum($query);
|
2017-08-04 16:28:16 +02:00
|
|
|
|
2019-02-01 17:44:31 +01:00
|
|
|
// RISULTATI VISIBILI
|
2019-02-22 10:37:37 +01:00
|
|
|
$query = Query::getQuery($structure, $search, $order, $limit);
|
2017-08-04 16:28:16 +02:00
|
|
|
|
2019-02-01 17:44:31 +01:00
|
|
|
// Filtri derivanti dai permessi (eventuali)
|
|
|
|
if (empty($id_plugin)) {
|
|
|
|
$query = Modules::replaceAdditionals($id_module, $query);
|
2017-08-04 16:28:16 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// Conteggio dei record filtrati
|
2019-02-22 10:37:37 +01:00
|
|
|
$data = Query::executeAndCount($query);
|
|
|
|
$rows = $data['results'];
|
|
|
|
$results['recordsFiltered'] = $data['count'];
|
2017-08-04 16:28:16 +02:00
|
|
|
|
2019-02-01 17:44:31 +01:00
|
|
|
// SOMME
|
2019-07-09 12:29:39 +02:00
|
|
|
if ($draw_numer == 1) {
|
|
|
|
$results['summable'] = Util\Query::getSums($structure, $search);
|
|
|
|
}
|
2019-02-01 17:44:31 +01:00
|
|
|
|
|
|
|
// Allineamento delle righe
|
2017-08-04 16:28:16 +02:00
|
|
|
$align = [];
|
2019-02-01 17:44:31 +01:00
|
|
|
$row = $rows[0] ?: [];
|
|
|
|
foreach ($row as $field => $value) {
|
|
|
|
$value = trim($value);
|
2017-08-04 16:28:16 +02:00
|
|
|
|
2019-02-01 17:44:31 +01:00
|
|
|
// Allineamento a destra se il valore della prima riga risulta numerica
|
|
|
|
if (formatter()->isStandardNumber($value)) {
|
|
|
|
$align[$field] = 'text-right';
|
|
|
|
}
|
|
|
|
|
|
|
|
// Allineamento al centro se il valore della prima riga risulta relativo a date o icone
|
|
|
|
elseif (formatter()->isStandardDate($value) || preg_match('/^icon_(.+?)$/', $field)) {
|
|
|
|
$align[$field] = 'text-center';
|
2017-08-04 16:28:16 +02:00
|
|
|
}
|
2019-02-01 17:44:31 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// Creazione della tabella
|
|
|
|
foreach ($rows as $i => $r) {
|
|
|
|
$result = [
|
|
|
|
'<span class="hide" data-id="'.$r['id'].'"></span>', // Colonna ID
|
|
|
|
];
|
2017-08-04 16:28:16 +02:00
|
|
|
|
|
|
|
foreach ($total['fields'] as $pos => $field) {
|
|
|
|
$column = [];
|
|
|
|
|
|
|
|
if (!empty($r['_bg_'])) {
|
|
|
|
$column['data-background'] = $r['_bg_'];
|
|
|
|
}
|
|
|
|
|
|
|
|
// Allineamento
|
|
|
|
if (!empty($align[$field])) {
|
|
|
|
$column['class'] = $align[$field];
|
|
|
|
}
|
|
|
|
|
|
|
|
$value = trim($r[$field]);
|
|
|
|
|
|
|
|
// Formattazione automatica
|
2017-09-19 16:20:44 +02:00
|
|
|
if (!empty($total['format'][$pos]) && !empty($value)) {
|
2018-09-20 12:05:22 +02:00
|
|
|
if (formatter()->isStandardDate($value)) {
|
2017-08-04 16:28:16 +02:00
|
|
|
$value = Translator::dateToLocale($value);
|
2018-09-20 12:05:22 +02:00
|
|
|
} elseif (formatter()->isStandardTime($value)) {
|
2017-08-04 16:28:16 +02:00
|
|
|
$value = Translator::timeToLocale($value);
|
2018-09-20 12:05:22 +02:00
|
|
|
} elseif (formatter()->isStandardTimestamp($value)) {
|
2017-09-19 18:14:23 +02:00
|
|
|
$value = Translator::timestampToLocale($value);
|
2018-09-20 12:05:22 +02:00
|
|
|
} elseif (formatter()->isStandardNumber($value)) {
|
2017-09-19 18:14:23 +02:00
|
|
|
$value = Translator::numberToLocale($value);
|
2017-08-04 16:28:16 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Icona
|
2018-02-08 11:04:26 +01:00
|
|
|
if (preg_match('/^color_(.+?)$/', $field, $m)) {
|
2018-06-23 18:35:08 +02:00
|
|
|
$value = isset($r['color_title_'.$m[1]]) ? $r['color_title_'.$m[1]] : '';
|
2017-08-04 16:28:16 +02:00
|
|
|
|
|
|
|
$column['class'] = 'text-center small';
|
|
|
|
$column['data-background'] = $r[$field];
|
|
|
|
}
|
|
|
|
|
|
|
|
// Icona di stampa
|
|
|
|
elseif ($field == '_print_') {
|
2018-08-09 13:54:04 +02:00
|
|
|
$print = $r['_print_'];
|
2017-08-04 16:28:16 +02:00
|
|
|
|
2018-08-09 13:54:04 +02:00
|
|
|
$print_url = Prints::getHref($print, $r['id']);
|
2017-08-04 16:28:16 +02:00
|
|
|
|
2018-08-09 13:54:04 +02:00
|
|
|
$value = '<a href="'.$print_url.'" target="_blank"><i class="fa fa-2x fa-print"></i></a>';
|
2017-08-04 16:28:16 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// Icona
|
2017-09-04 12:59:03 +02:00
|
|
|
elseif (preg_match('/^icon_(.+?)$/', trim($field), $m)) {
|
2017-11-15 19:32:23 +01:00
|
|
|
$value = '<span class=\'label text-black\' style=\'font-weight:normal;\' ><i class="'.$r[$field].'" title="'.$r['icon_title_'.$m[1]].'" ></i> <span>'.$r['icon_title_'.$m[1]].'</span></span>';
|
2017-08-04 16:28:16 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// Colore del testo
|
|
|
|
if (!empty($column['data-background'])) {
|
2018-06-23 15:41:32 +02:00
|
|
|
$column['data-color'] = isset($column['data-color']) ? $column['data-color'] : color_inverse($column['data-background']);
|
2017-08-04 16:28:16 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// Link della colonna
|
|
|
|
if ($field != '_print_') {
|
|
|
|
$id_record = $r['id'];
|
|
|
|
$hash = '';
|
|
|
|
if (!empty($r['_link_record_'])) {
|
|
|
|
$id_module = $r['_link_module_'];
|
|
|
|
$id_record = $r['_link_record_'];
|
|
|
|
$hash = !empty($r['_link_hash_']) ? '#'.$r['_link_hash_'] : '';
|
|
|
|
unset($id_plugin);
|
|
|
|
}
|
|
|
|
|
2018-07-18 15:20:10 +02:00
|
|
|
// Link per i moduli
|
|
|
|
if (empty($id_plugin)) {
|
|
|
|
$column['data-link'] = $rootdir.'/editor.php?id_module='.$id_module.'&id_record='.$id_record.$hash;
|
|
|
|
}
|
|
|
|
// Link per i plugin
|
|
|
|
else {
|
|
|
|
$column['data-link'] = $rootdir.'/add.php?id_module='.$id_module.'&id_record='.$id_record.'&id_plugin='.$id_plugin.'&id_parent='.$id_parent.'&edit=1'.$hash;
|
2017-08-04 16:28:16 +02:00
|
|
|
|
|
|
|
$column['data-type'] = 'dialog';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
$attributes = [];
|
|
|
|
foreach ($column as $key => $val) {
|
|
|
|
$val = is_array($val) ? implode(' ', $val) : $val;
|
|
|
|
$attributes[] = $key.'="'.$val.'"';
|
|
|
|
}
|
|
|
|
|
2018-02-24 11:23:20 +01:00
|
|
|
// Replace rootdir per le query
|
|
|
|
$value = str_replace('ROOTDIR', ROOTDIR, $value);
|
2017-08-04 16:28:16 +02:00
|
|
|
$result[] = str_replace('|attr|', implode(' ', $attributes), '<div |attr|>'.$value.'</div>');
|
|
|
|
}
|
|
|
|
|
|
|
|
$results['data'][] = $result;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-02-01 17:44:31 +01:00
|
|
|
$json = json_encode($results);
|
|
|
|
echo $json;
|