|
| 1 | +<?php |
| 2 | +/* |
| 3 | + * OpenSTAManager: il software gestionale open source per l'assistenza tecnica e la fatturazione |
| 4 | + * Copyright (C) DevCode s.r.l. |
| 5 | + * |
| 6 | + * This program is free software: you can redistribute it and/or modify |
| 7 | + * it under the terms of the GNU General Public License as published by |
| 8 | + * the Free Software Foundation, either version 3 of the License, or |
| 9 | + * (at your option) any later version. |
| 10 | + * |
| 11 | + * This program is distributed in the hope that it will be useful, |
| 12 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 14 | + * GNU General Public License for more details. |
| 15 | + * |
| 16 | + * You should have received a copy of the GNU General Public License |
| 17 | + * along with this program. If not, see <https://www.gnu.org/licenses/>. |
| 18 | + */ |
| 19 | + |
| 20 | +include_once __DIR__.'/../../core.php'; |
| 21 | + |
| 22 | +use Models\User; |
| 23 | + |
| 24 | +// Parametri per la paginazione |
| 25 | +$offset = intval(filter('offset') ?: 0); |
| 26 | +$limit = intval(filter('limit') ?: 20); |
| 27 | + |
| 28 | +// Limitiamo a massimo 100 operazioni totali |
| 29 | +$max_operations = 100; |
| 30 | + |
| 31 | +// Query per recuperare le operazioni |
| 32 | +$query = "SELECT |
| 33 | + zz_operations.id_module, |
| 34 | + zz_operations.id_plugin, |
| 35 | + zz_operations.id_record, |
| 36 | + zz_operations.op, |
| 37 | + zz_operations.created_at, |
| 38 | + zz_operations.id_utente, |
| 39 | + zz_users.username, |
| 40 | + an_anagrafiche.ragione_sociale, |
| 41 | + COALESCE(zz_modules_lang.title, 'Sistema') as module_name, |
| 42 | + zz_plugins_lang.title as plugin_name |
| 43 | +FROM zz_operations |
| 44 | +LEFT JOIN zz_users ON zz_operations.id_utente = zz_users.id |
| 45 | +LEFT JOIN an_anagrafiche ON zz_users.idanagrafica = an_anagrafiche.idanagrafica |
| 46 | +LEFT JOIN zz_modules_lang ON zz_operations.id_module = zz_modules_lang.id_record AND zz_modules_lang.id_lang = ".prepare(Models\Locale::getDefault()->id)." |
| 47 | +LEFT JOIN zz_plugins_lang ON zz_operations.id_plugin = zz_plugins_lang.id_record AND zz_plugins_lang.id_lang = ".prepare(Models\Locale::getDefault()->id)." |
| 48 | +ORDER BY zz_operations.created_at DESC |
| 49 | +LIMIT ".$limit." OFFSET ".$offset; |
| 50 | + |
| 51 | +$operazioni = $dbo->fetchArray($query); |
| 52 | + |
| 53 | +// Query per contare il totale delle operazioni |
| 54 | +$count_query = "SELECT COUNT(*) as total FROM zz_operations"; |
| 55 | +$total_count = $dbo->fetchOne($count_query)['total']; |
| 56 | + |
| 57 | +if (!empty($operazioni)) { |
| 58 | + echo ' |
| 59 | +<table class="table table-hover table-sm mb-0"> |
| 60 | + <thead> |
| 61 | + <tr> |
| 62 | + <th width="25%">'.tr('Modulo/Plugin').'</th> |
| 63 | + <th width="15%">'.tr('Record').'</th> |
| 64 | + <th width="20%">'.tr('Operazione').'</th> |
| 65 | + <th width="20%">'.tr('Utente').'</th> |
| 66 | + <th width="20%">'.tr('Data e ora').'</th> |
| 67 | + </tr> |
| 68 | + </thead> |
| 69 | + <tbody>'; |
| 70 | + |
| 71 | + foreach ($operazioni as $operazione) { |
| 72 | + // Determina il nome del modulo/plugin |
| 73 | + $nome_modulo = $operazione['module_name']; |
| 74 | + if (!empty($operazione['plugin_name'])) { |
| 75 | + $nome_modulo .= ' - '.$operazione['plugin_name']; |
| 76 | + } |
| 77 | + |
| 78 | + // Formatta l'operazione e determina il colore |
| 79 | + $operazione_formattata = ucfirst(str_replace('_', ' ', $operazione['op'])); |
| 80 | + |
| 81 | + // Determina il colore in base al tipo di operazione |
| 82 | + $color_class = 'text-primary'; // Default blu |
| 83 | + $op_lower = strtolower($operazione['op']); |
| 84 | + |
| 85 | + if (strpos($op_lower, 'delete') !== false || strpos($op_lower, 'elimina') !== false || strpos($op_lower, 'rimuovi') !== false) { |
| 86 | + $color_class = 'text-danger'; // Rosso per eliminazioni |
| 87 | + } elseif (strpos($op_lower, 'add') !== false || strpos($op_lower, 'aggiungi') !== false || strpos($op_lower, 'crea') !== false || strpos($op_lower, 'nuovo') !== false) { |
| 88 | + $color_class = 'text-success'; // Verde per aggiunte |
| 89 | + } elseif (strpos($op_lower, 'update') !== false || strpos($op_lower, 'modifica') !== false || strpos($op_lower, 'salva') !== false || strpos($op_lower, 'edit') !== false) { |
| 90 | + $color_class = 'text-warning'; // Arancione per modifiche |
| 91 | + } |
| 92 | + |
| 93 | + // Formatta la data |
| 94 | + $data_formattata = Translator::timestampToLocale($operazione['created_at']); |
| 95 | + |
| 96 | + // Recupera informazioni complete dell'utente |
| 97 | + $user = User::find($operazione['id_utente']); |
| 98 | + $username = $operazione['username']; |
| 99 | + |
| 100 | + // Foto e nome completo dell'utente |
| 101 | + $user_photo = null; |
| 102 | + $nome_completo = $username; |
| 103 | + if ($user) { |
| 104 | + $user_photo = $user->photo; |
| 105 | + $nome_completo = $user->nome_completo; |
| 106 | + } |
| 107 | + |
| 108 | + echo ' |
| 109 | + <tr> |
| 110 | + <td> |
| 111 | + <strong>'.$nome_modulo.'</strong> |
| 112 | + </td> |
| 113 | + <td class="text-center"> |
| 114 | + '.($operazione['id_record'] ? '<span class="badge badge-secondary">'.$operazione['id_record'].'</span>' : '-').' |
| 115 | + </td> |
| 116 | + <td> |
| 117 | + <small class="'.$color_class.' font-weight-bold">'.$operazione_formattata.'</small> |
| 118 | + </td> |
| 119 | + <td> |
| 120 | + '.($user_photo ? '<img class="attachment-img tip mr-2" src="'.$user_photo.'" title="'.$nome_completo.'" style="width: 20px; height: 20px;">' : '<i class="fa fa-user-circle-o mr-2 tip" title="'.$nome_completo.'"></i>').' |
| 121 | + <strong>'.$username.'</strong> |
| 122 | + </td> |
| 123 | + <td> |
| 124 | + <small>'.$data_formattata.'</small> |
| 125 | + </td> |
| 126 | + </tr>'; |
| 127 | + } |
| 128 | + |
| 129 | + echo ' |
| 130 | + </tbody> |
| 131 | +</table>'; |
| 132 | + |
| 133 | + // Pulsante "Carica di più" se ci sono altre operazioni da mostrare |
| 134 | + $next_offset = $offset + $limit; |
| 135 | + $max_offset = $max_operations; // Limitiamo a 100 operazioni totali |
| 136 | + |
| 137 | + if ($next_offset < $total_count && $next_offset < $max_offset) { |
| 138 | + $remaining = min($max_offset - $next_offset, $total_count - $next_offset); |
| 139 | + echo ' |
| 140 | + <div class="text-center p-3"> |
| 141 | + <button type="button" class="btn btn-sm btn-outline-primary" onclick="caricaAltreOperazioni('.$next_offset.', '.$remaining.')"> |
| 142 | + <i class="fa fa-plus mr-1"></i>'.tr('Carica altre _NUM_ operazioni', ['_NUM_' => $remaining]).' |
| 143 | + </button> |
| 144 | + </div>'; |
| 145 | + } |
| 146 | +} else { |
| 147 | + echo ' |
| 148 | + <div class="alert alert-info mb-0"> |
| 149 | + <i class="fa fa-info-circle mr-1"></i>'.tr('Nessuna operazione trovata.').' |
| 150 | + </div>'; |
| 151 | +} |
0 commit comments