. */ include_once __DIR__.'/core.php'; use Util\Query; // Informazioni fondamentali $columns = (array) filter('columns', null, true); $order = filter('order') ? filter('order')[0] : []; $draw_numer = intval(filter('draw')); if (!empty(filter('order'))) { $order['column'] = $order['column'] - 1; } array_shift($columns); $total = Util\Query::readQuery($structure); // Ricerca $search = []; for ($i = 0; $i < count($columns); ++$i) { if (!empty($columns[$i]['search']['value']) || $columns[$i]['search']['value'] == '0') { $search[$total['fields'][$i]] = $columns[$i]['search']['value']; } } $limit = [ 'start' => filter('start'), 'length' => filter('length'), ]; // Predisposizione della risposta $results = [ 'data' => [], 'recordsTotal' => 0, 'recordsFiltered' => 0, 'summable' => [], 'draw' => $draw_numer, ]; $query = Query::getQuery($structure); if (!empty($query)) { // CONTEGGIO TOTALE $results['recordsTotal'] = $dbo->fetchNum($query); // RISULTATI VISIBILI $query = Query::getQuery($structure, $search, $order, $limit); // Filtri derivanti dai permessi (eventuali) if (empty($id_plugin)) { $query = Modules::replaceAdditionals($id_module, $query); } // Conteggio dei record filtrati $data = Query::executeAndCount($query); $rows = $data['results']; $results['recordsFiltered'] = $data['count']; // SOMME $results['summable'] = Util\Query::getSums($structure, $search); // Allineamento delle righe $align = []; $row = isset($rows[0]) ? $rows[0] : []; foreach ($row as $field => $value) { if (!empty($value)) { $value = trim($value); } // Allineamento a destra se il valore della prima riga risulta numerica if (is_numeric($value) && 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'; } } // Creazione della tabella foreach ($rows as $i => $r) { // Evitare risultati con ID a null // Codice non applicabile in ogni caso: sulla base dei permessi, ID può non essere impostato /* if (empty($r['id'])) { continue; }*/ $result = [ 'id' => $r['id'], '', // Colonna ID ]; 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((string) $r[$field]); // Formattazione HTML if (empty($total['html_format'][$pos]) && !empty($value)) { $value = strip_tags($value); } // Formattazione automatica if (!empty($total['format'][$pos]) && !empty($value)) { if (formatter()->isStandardTimestamp($value)) { $value = Translator::timestampToLocale($value); } elseif (formatter()->isStandardDate($value)) { $value = Translator::dateToLocale($value); } elseif (formatter()->isStandardTime($value)) { $value = Translator::timeToLocale($value); } elseif (formatter()->isStandardNumber($value)) { $value = Translator::numberToLocale($value); } } // Icona if (preg_match('/^color_(.+?)$/', $field, $m)) { $value = isset($r['color_title_'.$m[1]]) ? $r['color_title_'.$m[1]] : ''; $column['class'] = 'text-center small'; $column['data-background'] = $r[$field]; } // Icona di stampa elseif ($field == '_print_') { $print = $r['_print_']; $print_url = Prints::getHref($print, $r['id']); $value = ''; } // Icona elseif (preg_match('/^icon_(.+?)$/', trim($field), $m)) { $value = ' '.$r['icon_title_'.$m[1]].''; } // Colore del testo if (!empty($column['data-background'])) { $column['data-color'] = isset($column['data-color']) ? $column['data-color'] : color_inverse(trim($column['data-background'])); } // Link della colonna if ($field != '_print_') { $id_record = $r['id']; $hash = ''; $id_module = !empty($r['_link_module_']) ? $r['_link_module_'] : $id_module; if (!empty($r['_link_record_'])) { $id_record = $r['_link_record_']; $hash = !empty($r['_link_hash_']) ? '#'.$r['_link_hash_'] : ''; unset($id_plugin); } // Link per i moduli if (empty($id_plugin)) { $column['data-link'] = base_path().'/editor.php?id_module='.$id_module.'&id_record='.$id_record.$hash; } // Link per i plugin else { $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; $column['data-type'] = 'dialog'; } } $attributes = []; foreach ($column as $key => $val) { $val = is_array($val) ? implode(' ', $val) : $val; $attributes[] = $key.'="'.$val.'"'; } // Replace base_link() per le query $value = str_replace('base_link()', base_path(), $value); $result[] = str_replace('|attr|', implode(' ', $attributes), '
'.$value.'
'); } $results['data'][] = $result; } } $json = json_encode($results); echo $json;