2017-08-04 16:28:16 +02:00
|
|
|
<?php
|
2020-09-07 15:04:06 +02:00
|
|
|
/*
|
|
|
|
* OpenSTAManager: il software gestionale open source per l'assistenza tecnica e la fatturazione
|
2021-01-20 15:08:51 +01:00
|
|
|
* Copyright (C) DevCode s.r.l.
|
2020-09-07 15:04:06 +02:00
|
|
|
*
|
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
|
|
*/
|
2017-08-04 16:28:16 +02:00
|
|
|
|
|
|
|
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
|
2023-09-12 10:12:12 +02:00
|
|
|
$columns = (array) filter('columns', null, true);
|
2020-09-23 12:00:21 +02:00
|
|
|
$order = filter('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
|
|
|
|
2020-09-23 12:00:21 +02:00
|
|
|
if (!empty(filter('order'))) {
|
|
|
|
$order['column'] = $order['column'] - 1;
|
|
|
|
}
|
2017-08-04 16:28:16 +02:00
|
|
|
array_shift($columns);
|
|
|
|
|
2024-01-15 15:30:45 +01:00
|
|
|
$total = 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) {
|
2020-06-09 16:59:26 +02:00
|
|
|
if (!empty($columns[$i]['search']['value']) || $columns[$i]['search']['value'] == '0') {
|
2019-02-01 17:44:31 +01:00
|
|
|
$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' => [],
|
2024-05-09 16:51:13 +02:00
|
|
|
'avg' => [],
|
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
|
2024-01-15 15:30:45 +01:00
|
|
|
$results['summable'] = Query::getSums($structure, $search);
|
2019-02-01 17:44:31 +01:00
|
|
|
|
2024-05-09 16:51:13 +02:00
|
|
|
// MEDIE
|
|
|
|
$results['avg'] = Query::getAverages($structure, $search);
|
|
|
|
|
2019-02-01 17:44:31 +01:00
|
|
|
// Allineamento delle righe
|
2017-08-04 16:28:16 +02:00
|
|
|
$align = [];
|
2020-09-23 18:36:33 +02:00
|
|
|
$row = isset($rows[0]) ? $rows[0] : [];
|
2019-02-01 17:44:31 +01:00
|
|
|
foreach ($row as $field => $value) {
|
2023-08-04 14:54:28 +02:00
|
|
|
if (!empty($value)) {
|
2022-03-18 17:43:50 +01:00
|
|
|
$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
|
2022-11-14 12:48:19 +01:00
|
|
|
if (is_numeric($value) && formatter()->isStandardNumber($value)) {
|
2019-02-01 17:44:31 +01:00
|
|
|
$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) {
|
2020-09-24 09:35:36 +02:00
|
|
|
// Evitare risultati con ID a null
|
|
|
|
// Codice non applicabile in ogni caso: sulla base dei permessi, ID può non essere impostato
|
|
|
|
/*
|
2020-09-24 09:25:44 +02:00
|
|
|
if (empty($r['id'])) {
|
|
|
|
continue;
|
2020-09-24 09:35:36 +02:00
|
|
|
}*/
|
2020-09-24 09:25:44 +02:00
|
|
|
|
2019-02-01 17:44:31 +01:00
|
|
|
$result = [
|
2020-07-08 21:12:16 +02:00
|
|
|
'id' => $r['id'],
|
2019-02-01 17:44:31 +01:00
|
|
|
'<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_'])) {
|
2024-02-12 18:13:39 +01:00
|
|
|
if (preg_match('/-light$/', $r['_bg_'])) {
|
2024-02-13 15:50:26 +01:00
|
|
|
$column['data-background'] = substr($r['_bg_'], 0, -6); // Remove the "-light" suffix from the word
|
|
|
|
} else {
|
2024-02-12 18:13:39 +01:00
|
|
|
$column['data-background'] = $r['_bg_'];
|
|
|
|
}
|
2017-08-04 16:28:16 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// Allineamento
|
|
|
|
if (!empty($align[$field])) {
|
|
|
|
$column['class'] = $align[$field];
|
|
|
|
}
|
|
|
|
|
2022-03-23 19:22:43 +01:00
|
|
|
$value = trim((string) $r[$field]);
|
2017-08-04 16:28:16 +02:00
|
|
|
|
2022-02-24 12:55:47 +01:00
|
|
|
// Formattazione HTML
|
|
|
|
if (empty($total['html_format'][$pos]) && !empty($value)) {
|
2024-08-30 09:03:52 +02:00
|
|
|
$value = strip_tags($value?:'');
|
2022-02-24 12:55:47 +01:00
|
|
|
}
|
|
|
|
|
2017-08-04 16:28:16 +02:00
|
|
|
// Formattazione automatica
|
2017-09-19 16:20:44 +02:00
|
|
|
if (!empty($total['format'][$pos]) && !empty($value)) {
|
2020-04-07 16:31:34 +02:00
|
|
|
if (formatter()->isStandardTimestamp($value)) {
|
|
|
|
$value = Translator::timestampToLocale($value);
|
|
|
|
} elseif (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);
|
2020-04-14 08:49:48 +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)) {
|
2024-05-16 18:02:50 +02:00
|
|
|
$value = '<span class=\'badge 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'])) {
|
2021-02-08 17:51:22 +01:00
|
|
|
$column['data-color'] = isset($column['data-color']) ? $column['data-color'] : color_inverse(trim($column['data-background']));
|
2017-08-04 16:28:16 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// Link della colonna
|
|
|
|
if ($field != '_print_') {
|
|
|
|
$id_record = $r['id'];
|
|
|
|
$hash = '';
|
2020-08-27 11:10:55 +02:00
|
|
|
|
2020-09-23 12:00:21 +02:00
|
|
|
$id_module = !empty($r['_link_module_']) ? $r['_link_module_'] : $id_module;
|
2017-08-04 16:28:16 +02:00
|
|
|
if (!empty($r['_link_record_'])) {
|
|
|
|
$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)) {
|
2020-09-23 17:53:19 +02:00
|
|
|
$column['data-link'] = base_path().'/editor.php?id_module='.$id_module.'&id_record='.$id_record.$hash;
|
2018-07-18 15:20:10 +02:00
|
|
|
}
|
|
|
|
// Link per i plugin
|
|
|
|
else {
|
2020-09-23 17:53:19 +02:00
|
|
|
$column['data-link'] = base_path().'/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.'"';
|
|
|
|
}
|
|
|
|
|
2020-09-23 13:36:37 +02:00
|
|
|
// Replace base_link() per le query
|
2020-09-23 17:53:19 +02:00
|
|
|
$value = str_replace('base_link()', base_path(), $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;
|