2017-08-04 16:28:16 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
include_once __DIR__.'/core.php';
|
|
|
|
|
|
|
|
// Informazioni fondamentali
|
|
|
|
$start = filter('start');
|
|
|
|
$length = filter('length');
|
|
|
|
$columns = filter('columns');
|
|
|
|
$order = filter('order')[0];
|
|
|
|
|
|
|
|
$order['column'] = $order['column'] - 1;
|
|
|
|
array_shift($columns);
|
|
|
|
|
2018-09-19 10:44:32 +02:00
|
|
|
$total = App::readQuery($structure);
|
2017-08-04 16:28:16 +02:00
|
|
|
|
|
|
|
// Lettura parametri modulo
|
2018-02-14 11:10:03 +01:00
|
|
|
$result_query = $total['query'];
|
2017-08-04 16:28:16 +02:00
|
|
|
|
|
|
|
// Predisposizione dela risposta
|
|
|
|
$results = [];
|
|
|
|
$results['data'] = [];
|
|
|
|
$results['recordsTotal'] = 0;
|
|
|
|
$results['recordsFiltered'] = 0;
|
|
|
|
$results['summable'] = [];
|
|
|
|
|
2018-02-14 11:10:03 +01:00
|
|
|
if (!empty($result_query) && $result_query != 'menu' && $result_query != 'custom') {
|
2017-08-04 16:28:16 +02:00
|
|
|
// Conteggio totale
|
2018-07-03 15:05:27 +02:00
|
|
|
$results['recordsTotal'] = $dbo->fetchNum($result_query);
|
2017-08-04 16:28:16 +02:00
|
|
|
|
|
|
|
// Filtri di ricerica
|
|
|
|
$search_filters = [];
|
|
|
|
for ($i = 0; $i < count($columns); ++$i) {
|
|
|
|
if (!empty($columns[$i]['search']['value'])) {
|
2017-08-28 15:29:03 +02:00
|
|
|
if (str_contains($total['search_inside'][$i], '|search|')) {
|
2017-08-04 16:28:16 +02:00
|
|
|
$pieces = explode(',', $columns[$i]['search']['value']);
|
|
|
|
foreach ($pieces as $piece) {
|
|
|
|
$piece = trim($piece);
|
|
|
|
$search_filters[] = str_replace('|search|', prepare('%'.$piece.'%'), $total['search_inside'][$i]);
|
|
|
|
}
|
|
|
|
} else {
|
2018-07-14 13:34:00 +02:00
|
|
|
// Per le icone cerco nel campo icon_title
|
|
|
|
if (preg_match('/^icon_(.+?)$/', $total['fields'][$i], $m)) {
|
|
|
|
$total['search_inside'][$i] = '`icon_title_'.$m[1].'`';
|
2017-12-14 21:46:45 +01:00
|
|
|
}
|
|
|
|
|
2018-07-14 13:34:00 +02:00
|
|
|
// Per i colori cerco nel campo color_title
|
|
|
|
elseif (preg_match('/^color_(.+?)$/', $total['fields'][$i], $m)) {
|
|
|
|
$total['search_inside'][$i] = '`color_title_'.$m[1].'`';
|
|
|
|
}
|
|
|
|
|
|
|
|
$search_filters[] = $total['search_inside'][$i].' LIKE '.prepare('%'.trim($columns[$i]['search']['value'].'%'));
|
2017-08-04 16:28:16 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2018-02-14 11:10:03 +01:00
|
|
|
|
2018-02-15 16:44:16 +01:00
|
|
|
// Ricerca
|
|
|
|
if (!empty($search_filters)) {
|
|
|
|
$result_query = str_replace('2=2', '2=2 AND ('.implode(' AND ', $search_filters).') ', $result_query);
|
2018-02-14 11:10:03 +01:00
|
|
|
}
|
|
|
|
|
2017-08-04 16:28:16 +02:00
|
|
|
// Filtri derivanti dai permessi (eventuali)
|
2017-12-14 21:46:45 +01:00
|
|
|
if (empty($id_plugin)) {
|
2018-02-14 11:10:03 +01:00
|
|
|
$result_query = Modules::replaceAdditionals($id_module, $result_query);
|
2017-12-14 21:46:45 +01:00
|
|
|
}
|
2017-08-04 16:28:16 +02:00
|
|
|
|
|
|
|
// Ordinamento dei risultati
|
|
|
|
if (isset($order['dir']) && isset($order['column'])) {
|
2018-02-14 11:10:03 +01:00
|
|
|
$pieces = explode('ORDER', $result_query);
|
2017-08-04 16:28:16 +02:00
|
|
|
|
2018-02-14 11:10:03 +01:00
|
|
|
$count = count($pieces);
|
|
|
|
if ($count > 1) {
|
|
|
|
unset($pieces[$count - 1]);
|
2017-08-04 16:28:16 +02:00
|
|
|
}
|
|
|
|
|
2018-02-14 11:10:03 +01:00
|
|
|
$result_query = implode('ORDER', $pieces).' ORDER BY '.$total['order_by'][$order['column']].' '.$order['dir'];
|
2017-08-04 16:28:16 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// Calcolo di eventuali somme
|
|
|
|
if (!empty($total['summable'])) {
|
2018-02-14 11:10:03 +01:00
|
|
|
$sum_query = str_replace_once('SELECT', 'SELECT '.implode(', ', $total['summable']).' FROM(SELECT ', $result_query).') AS `z`';
|
|
|
|
$sums = $dbo->fetchArray($sum_query)[0];
|
2017-08-04 16:28:16 +02:00
|
|
|
if (!empty($sums)) {
|
|
|
|
$r = [];
|
|
|
|
foreach ($sums as $key => $sum) {
|
2017-08-28 15:29:03 +02:00
|
|
|
if (str_contains($key, 'sum_')) {
|
2017-08-04 16:28:16 +02:00
|
|
|
$r[str_replace('sum_', '', $key)] = Translator::numberToLocale($sum);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
$results['summable'] = $r;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Paginazione
|
|
|
|
if ($length > 0) {
|
2018-02-14 11:10:03 +01:00
|
|
|
$result_query .= ' LIMIT '.$start.', '.$length;
|
2017-08-04 16:28:16 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// Query effettiva
|
2018-02-14 11:10:03 +01:00
|
|
|
$query = str_replace_once('SELECT', 'SELECT SQL_CALC_FOUND_ROWS', $result_query);
|
2018-06-23 15:41:32 +02:00
|
|
|
|
2017-08-04 16:28:16 +02:00
|
|
|
$rs = $dbo->fetchArray($query);
|
|
|
|
|
|
|
|
// Conteggio dei record filtrati
|
2018-02-14 11:10:03 +01:00
|
|
|
$count = $dbo->fetchArray('SELECT FOUND_ROWS()');
|
|
|
|
if (!empty($count)) {
|
|
|
|
$results['recordsFiltered'] = $count[0]['FOUND_ROWS()'];
|
2017-08-04 16:28:16 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// Creazione della tabella
|
|
|
|
$align = [];
|
|
|
|
foreach ($rs as $i => $r) {
|
|
|
|
if ($i == 0) {
|
|
|
|
foreach ($total['fields'] as $field) {
|
|
|
|
$value = trim($r[$field]);
|
|
|
|
|
|
|
|
// Allineamento a destra se il valore della prima riga risulta numerica
|
2017-09-19 16:20:44 +02:00
|
|
|
if (Translator::getFormatter()->isStandardNumber($value)) {
|
2017-08-04 16:28:16 +02:00
|
|
|
$align[$field] = 'text-right';
|
|
|
|
}
|
|
|
|
|
|
|
|
// Allineamento al centro se il valore della prima riga risulta relativo a date o icone
|
2018-02-08 11:04:26 +01:00
|
|
|
elseif (Translator::getFormatter()->isStandardDate($value) || preg_match('/^icon_(.+?)$/', $field)) {
|
2017-08-04 16:28:16 +02:00
|
|
|
$align[$field] = 'text-center';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
$result = [];
|
|
|
|
$result[] = '<span class="hide" data-id="'.$r['id'].'"></span>';
|
|
|
|
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)) {
|
2017-09-19 18:14:23 +02:00
|
|
|
if (Translator::getFormatter()->isStandardDate($value)) {
|
2017-08-04 16:28:16 +02:00
|
|
|
$value = Translator::dateToLocale($value);
|
2017-09-19 16:20:44 +02:00
|
|
|
} elseif (Translator::getFormatter()->isStandardTime($value)) {
|
2017-08-04 16:28:16 +02:00
|
|
|
$value = Translator::timeToLocale($value);
|
2017-09-19 18:14:23 +02:00
|
|
|
} elseif (Translator::getFormatter()->isStandardTimestamp($value)) {
|
|
|
|
$value = Translator::timestampToLocale($value);
|
|
|
|
} elseif (Translator::getFormatter()->isStandardNumber($value)) {
|
|
|
|
$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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-05-22 14:41:42 +02:00
|
|
|
$rows = json_encode($results);
|
|
|
|
echo $rows;
|