diff --git a/administrator/forms/filter_reportfirme.xml b/administrator/forms/filter_reportfirme.xml new file mode 100644 index 0000000..fbdadf0 --- /dev/null +++ b/administrator/forms/filter_reportfirme.xml @@ -0,0 +1,43 @@ + +
diff --git a/administrator/src/Controller/ReportfirmeController.php b/administrator/src/Controller/ReportfirmeController.php new file mode 100644 index 0000000..539e06c --- /dev/null +++ b/administrator/src/Controller/ReportfirmeController.php @@ -0,0 +1,75 @@ +getIdentity(); + + if (!$user->authorise('core.manage', 'com_circolari') && !$user->authorise('core.admin', 'com_circolari')) { + throw new \RuntimeException(\Joomla\CMS\Language\Text::_('JERROR_ALERTNOAUTHOR'), 403); + } + + /** @var \Pcrt\Component\Circolari\Administrator\Model\ReportfirmeModel $model */ + $model = $this->getModel('Reportfirme', 'Administrator'); + + // ✅ Inizializza lo state (richiama internamente populateState()) + $model->getState(); + + // ✅ Esporta TUTTI i risultati che rispettano i filtri correnti (niente paginazione) + $model->setState('list.start', 0); + $model->setState('list.limit', 0); + + // Prendi i dati + $rows = $model->getItems(); + + // Pulisci output e invia header per download + while (ob_get_level() > 0) { @ob_end_clean(); } + + $filename = 'report_firme_' . date('Ymd_His') . '.csv'; + $app->clearHeaders(); + $app->setHeader('Content-Description', 'File Transfer', true); + $app->setHeader('Content-Type', 'application/vnd.ms-excel; charset=utf-8', true); + $app->setHeader('Content-Disposition', 'attachment; filename="' . $filename . '"', true); + $app->setHeader('Content-Transfer-Encoding', 'binary', true); + $app->setHeader('Expires', '0', true); + $app->setHeader('Cache-Control', 'must-revalidate, post-check=0, pre-check=0', true); + $app->setHeader('Pragma', 'public', true); + $app->sendHeaders(); + + // CSV con BOM UTF-8, separatore ';' + $out = fopen('php://output', 'w'); + fwrite($out, chr(0xEF).chr(0xBB).chr(0xBF)); + fputcsv($out, ['ID','Circolare','ID Utente','Nome','Username','Email','Scelta','Data firma'], ';'); + + foreach ($rows as $r) { + $date = \Joomla\CMS\Factory::getDate($r->data_firma)->format('d/m/Y H:i'); + fputcsv($out, [ + $r->id, + $r->circolare_title, + $r->user_id, + $r->user_name, + $r->username, + $r->email, + $r->scelta_label, // ✅ nessun uso di f.firma + $date, + ], ';'); + } + + fclose($out); + $app->close(); +} + +} diff --git a/administrator/src/Model/ReportfirmeModel.php b/administrator/src/Model/ReportfirmeModel.php new file mode 100644 index 0000000..3f645b4 --- /dev/null +++ b/administrator/src/Model/ReportfirmeModel.php @@ -0,0 +1,92 @@ +setState('filter.search', $app->getUserStateFromRequest($this->context.'.filter.search', 'filter_search', '', 'string')); + $this->setState('filter.circolare_id', $app->getUserStateFromRequest($this->context.'.filter.circolare_id', 'filter_circolare_id', 0, 'int')); + $this->setState('filter.scelta', $app->getUserStateFromRequest($this->context.'.filter.scelta', 'filter_scelta', '', 'string')); + $this->setState('filter.date_from', $app->getUserStateFromRequest($this->context.'.filter.date_from', 'filter_date_from', '', 'string')); + $this->setState('filter.date_to', $app->getUserStateFromRequest($this->context.'.filter.date_to', 'filter_date_to', '', 'string')); + + parent::populateState($ordering, $direction); + } + + protected function getListQuery() + { + $db = $this->getDatabase(); + $q = $db->getQuery(true); + + $q->select([ + 'f.id','f.circolare_id','f.user_id','f.data_firma', + 'u.name AS user_name','u.username','u.email', + 'c.title AS circolare_title', + 'f.firma_label', + 'b.label AS bottone_label', + // scelta normalizzata: prima firma_label (copia al momento della firma), altrimenti label del bottone + 'COALESCE(f.firma_label, b.label) AS scelta_label', + ]) + ->from($db->quoteName('#__circolari_firme','f')) + ->join('INNER', $db->quoteName('#__users','u') . ' ON u.id = f.user_id') + ->join('INNER', $db->quoteName('#__circolari','c') . ' ON c.id = f.circolare_id') + ->join('LEFT', $db->quoteName('#__circolari_firmetipi_bottoni','b') . ' ON b.id = f.firmatipo_bottone_id'); + + // Filtri + $search = (string) $this->getState('filter.search', ''); + if ($search !== '') { + $like = $db->quote('%' . $db->escape($search, true) . '%'); + $q->where('(' + . 'u.name LIKE ' . $like + . ' OR u.username LIKE ' . $like + . ' OR u.email LIKE ' . $like + . ' OR c.title LIKE ' . $like + . ')'); + } + + $circolareId = (int) $this->getState('filter.circolare_id', 0); + if ($circolareId > 0) { + $q->where('f.circolare_id = ' . (int)$circolareId); + } + + $scelta = (string) $this->getState('filter.scelta', ''); + if ($scelta !== '') { + $q->where('(f.firma_label = ' . $db->quote($scelta) . ' OR b.label = ' . $db->quote($scelta) . ')'); + } + + $from = (string) $this->getState('filter.date_from', ''); + if ($from !== '') { + $q->where('f.data_firma >= ' . $db->quote($from . ' 00:00:00')); + } + $to = (string) $this->getState('filter.date_to', ''); + if ($to !== '') { + $q->where('f.data_firma <= ' . $db->quote($to . ' 23:59:59')); + } + + // Ordinamento + $orderCol = $this->state->get('list.ordering', 'f.data_firma'); + $orderDirn = $this->state->get('list.direction', 'DESC'); + $q->order($db->escape($orderCol . ' ' . $orderDirn)); + + return $q; + } + + public function getItems() + { + $rows = parent::getItems(); + foreach ($rows as $r) { + $r->scelta_label = $r->scelta_label ?: '-'; + } + return $rows; + } +} diff --git a/administrator/src/View/Reportfirme/HtmlView.php b/administrator/src/View/Reportfirme/HtmlView.php new file mode 100644 index 0000000..8ab9dc4 --- /dev/null +++ b/administrator/src/View/Reportfirme/HtmlView.php @@ -0,0 +1,27 @@ +state = $this->get('State'); + $this->items = $this->get('Items'); + $this->pagination = $this->get('Pagination'); + $this->filterForm = $this->get('FilterForm'); // JForm dei filtri (forms/filter_reportfirme.xml) + $this->activeFilters = $this->get('ActiveFilters'); + + parent::display($tpl); + } +} diff --git a/administrator/tmpl/reportfirme/default.php b/administrator/tmpl/reportfirme/default.php new file mode 100644 index 0000000..2eedadb --- /dev/null +++ b/administrator/tmpl/reportfirme/default.php @@ -0,0 +1,58 @@ +state->get('list.ordering', 'f.data_firma'); +$listDirn = $this->state->get('list.direction', 'DESC'); + +// Carica CSS base +HTMLHelper::_('bootstrap.tooltip'); +HTMLHelper::_('behavior.multiselect'); +HTMLHelper::_('formbehavior.chosen', 'select'); +?> + diff --git a/circolari.xml b/circolari.xml index caf55c4..7444a36 100644 --- a/circolari.xml +++ b/circolari.xml @@ -10,9 +10,8 @@