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 if ($draw_numer == 1) { $results['summable'] = Util\Query::getSums($structure, $search); } // Allineamento delle righe $align = []; $row = $rows[0] ?: []; foreach ($row as $field => $value) { $value = trim($value); // 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'; } } // Creazione della tabella foreach ($rows as $i => $r) { $result = [ '', // 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($r[$field]); // Formattazione automatica if (!empty($total['format'][$pos]) && !empty($value)) { if (formatter()->isStandardDate($value)) { $value = Translator::dateToLocale($value); } elseif (formatter()->isStandardTime($value)) { $value = Translator::timeToLocale($value); } elseif (formatter()->isStandardTimestamp($value)) { $value = Translator::timestampToLocale($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($column['data-background']); } // 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); } // 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; $column['data-type'] = 'dialog'; } } $attributes = []; foreach ($column as $key => $val) { $val = is_array($val) ? implode(' ', $val) : $val; $attributes[] = $key.'="'.$val.'"'; } // Replace rootdir per le query $value = str_replace('ROOTDIR', ROOTDIR, $value); $result[] = str_replace('|attr|', implode(' ', $attributes), '
'.$value.'
'); } $results['data'][] = $result; } } $json = json_encode($results); echo $json;