Invio Email

This commit is contained in:
2025-09-10 16:06:20 +02:00
parent f8988556db
commit f1f7872edd
14 changed files with 701 additions and 312 deletions

View File

@ -11,7 +11,6 @@ $input = $app->getInput();
// Prendo dati dalla view con fallback ai getter
$items = $this->items ?? ($this->get('Items') ?? []);
$pagination = $this->pagination ?? ($this->get('Pagination') ?? null);
// Normalizzo items
if (!is_array($items)) {
$items = (array) $items;
@ -19,64 +18,73 @@ if (!is_array($items)) {
$items = array_values(array_filter($items, static fn($it) => is_object($it) && !empty($it->id)));
$Itemid = (int) $input->getInt('Itemid', 0);
$params = $this->params ?? Factory::getApplication()->getParams();
$title = (string) $params->get('page_title', '');
$desc = (string) $params->get('page_description', '');
?>
<div class="circolari-list">
<?php if (!count($items)) : ?>
<div class="alert alert-info">
<span class="icon-info-circle" aria-hidden="true"></span>
<span class="visually-hidden"><?php echo Text::_('INFO'); ?></span>
<?php echo Text::_('COM_CIRCOLARI_NO_ITEMS') ?: 'Nessuna circolare'; ?>
<div class="com-content-category category-list">
<div class="content-category">
<h1><?php echo $title ? $title : ""; ?> </h1>
<div class="category-desc">
<p><span style="color: #333333; font-family: Tahoma, Helvetica, Arial, sans-serif; font-size: 12.16px; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; background-color: #ffffff; text-decoration-style: initial; text-decoration-color: initial; display: inline !important; float: none;">
<?php echo $desc ? $desc : ""; ?> </span></p>
</div>
<?php else : ?>
<table class="table table-striped table-bordered table-hover">
<caption class="visually-hidden"><?php echo Text::_('COM_CIRCOLARI_ELENCO') ?: 'Elenco circolari'; ?></caption>
<thead class="visually-hidden">
<tr>
<th scope="col">Titolo</th>
<th scope="col" class="text-end">Visite</th>
</tr>
</thead>
<tbody>
<?php foreach ($items as $i => $item) : ?>
<?php
$url = Route::_('index.php?option=com_circolari&view=circolare&id=' . (int) $item->id);
$title = $item->title ?? ('#' . (int) $item->id);
$hits = isset($item->hits) ? (int) $item->hits : null;
?>
<tr class="cat-list-row<?php echo $i % 2; ?>">
<th class="list-title" scope="row">
<a href="<?php echo $url; ?>">
<?php echo htmlspecialchars($title, ENT_QUOTES, 'UTF-8'); ?>
</a>
</th>
<td class="text-end">
<?php if ($hits !== null) : ?>
<span class="btn btn-secondary btn-sm disabled" aria-disabled="true">
<?php echo Text::_('JGLOBAL_HITS') ?: 'Visite'; ?>: <?php echo $hits; ?>
</span>
<?php else : ?>
<span class="text-muted">—</span>
<?php endif; ?>
</td>
</tr>
<?php endforeach; ?>
</tbody>
</table>
<?php endif; ?>
<?php if ($pagination && (int) $pagination->pagesTotal > 1) : ?>
<div class="com-content-category__navigation w-100">
<div class="d-flex align-items-center mt-2">
<div class="flex-grow-1 d-flex justify-content-center">
<?php echo $pagination->getPagesLinks(); ?>
</div>
<p class="com-content-category__counter counter mb-0 ps-3">
<?php echo $pagination->getPagesCounter(); ?>
</p>
<?php if (!count($items)) : ?>
<div class="alert alert-info">
<span class="icon-info-circle" aria-hidden="true"></span>
<span class="visually-hidden"><?php echo Text::_('INFO'); ?></span>
<?php echo Text::_('COM_CIRCOLARI_NO_ITEMS') ?: 'Nessuna circolare'; ?>
</div>
</div>
<?php endif; ?>
<?php else : ?>
<table class="com-content-category__table category table table-striped table-bordered table-hover">
<caption class="visually-hidden"><?php echo Text::_('COM_CIRCOLARI_ELENCO') ?: 'Elenco circolari'; ?></caption>
<thead class="visually-hidden">
<tr>
<th scope="col">Titolo</th>
<th scope="col" class="text-end">Visite</th>
</tr>
</thead>
<tbody>
<?php foreach ($items as $i => $item) : ?>
<?php
$url = Route::_('index.php?option=com_circolari&view=circolare&id=' . (int) $item->id);
$title = $item->title ?? ('#' . (int) $item->id);
$hits = isset($item->hits) ? (int) $item->hits : null;
?>
<tr class="cat-list-row<?php echo $i % 2; ?>">
<th class="list-title text-start" scope="row">
<a href="<?php echo $url; ?>">
<?php echo htmlspecialchars($title, ENT_QUOTES, 'UTF-8'); ?>
</a>
</th>
<td class="list-hits">
<?php if ($hits !== null) : ?>
<span class="badge bg-info" aria-disabled="true">
<?php echo Text::_('JGLOBAL_HITS') ?: 'Visite'; ?>: <?php echo $hits; ?>
</span>
<?php else : ?>
<span class="text-muted">—</span>
<?php endif; ?>
</td>
</tr>
<?php endforeach; ?>
</tbody>
</table>
<?php endif; ?>
<?php if ($pagination && (int) $pagination->pagesTotal > 1) : ?>
<div class="com-content-category__navigation w-100">
<div class="d-flex align-items-center mt-2">
<div class="flex-grow-1 d-flex justify-content-center">
<?php echo $pagination->getPagesLinks(); ?>
</div>
<p class="com-content-category__counter counter mb-0 ps-3">
<?php echo $pagination->getPagesCounter(); ?>
</p>
</div>
</div>
<?php endif; ?>
</div>
</div>

View File

@ -19,43 +19,43 @@ $menu = Factory::getApplication()->getMenu();
$component = ComponentHelper::getComponent('com_circolari');
$cancelItemId = 0;
foreach ((array) $menu->getItems('component_id', (int) $component->id) as $mi) {
$q = is_array($mi->query ?? null) ? $mi->query : [];
if (($q['option'] ?? '') === 'com_circolari' && ($q['view'] ?? '') === 'circolari') {
$cancelItemId = (int) $mi->id;
break;
}
$q = is_array($mi->query ?? null) ? $mi->query : [];
if (($q['option'] ?? '') === 'com_circolari' && ($q['view'] ?? '') === 'circolari') {
$cancelItemId = (int) $mi->id;
break;
}
}
$cancelUrl = $cancelItemId
? Route::_('index.php?Itemid=' . $cancelItemId)
: Uri::root() . 'index.php?option=com_circolari&view=circolari';
? Route::_('index.php?Itemid=' . $cancelItemId)
: Uri::root() . 'index.php?option=com_circolari&view=circolari';
?>
<div class="container py-3">
<h2 class="mb-3"><?php echo Text::_('Nuova circolare'); ?></h2>
<form action="<?php echo Route::_('index.php?option=com_circolari&task=form.save'); ?>" method="post" class="form-validate">
<form action="<?php echo Route::_('index.php?option=com_circolari&task=form.save'); ?>" method="post" class="form-validate">
<div class="mb-3">
<label class="form-label" for="title"><?php echo Text::_('Titolo'); ?></label>
<input type="text" id="title" name="title" required
class="form-control"
value="<?php echo htmlspecialchars($item->title ?? '', ENT_QUOTES, 'UTF-8'); ?>">
class="form-control"
value="<?php echo htmlspecialchars($item->title ?? '', ENT_QUOTES, 'UTF-8'); ?>">
</div>
<div class="mb-3">
<label class="form-label" for="alias"><?php echo Text::_('Alias (opzionale)'); ?></label>
<input type="text" id="alias" name="alias" class="form-control"
value="<?php echo htmlspecialchars($item->alias ?? '', ENT_QUOTES, 'UTF-8'); ?>">
value="<?php echo htmlspecialchars($item->alias ?? '', ENT_QUOTES, 'UTF-8'); ?>">
</div>
<div class="mb-3">
<label class="form-label" for="categoria_id"><?php echo Text::_('Categoria'); ?></label>
<select id="categoria_id" name="categoria_id" class="form-select" required>
<option value="0">-- <?php echo Text::_('Seleziona'); ?> --</option>
<?php foreach ((array) $this->categorie as $c):
$cid = (int) ($c['id'] ?? 0);
$ctitle = (string) ($c['title'] ?? '');
$cstate = (int) ($c['state'] ?? 1);
if ($cstate !== 1) continue; // solo pubblicate
<?php foreach ((array) $this->categorie as $c):
$cid = (int) ($c['id'] ?? 0);
$ctitle = (string) ($c['title'] ?? '');
$cstate = (int) ($c['state'] ?? 1);
if ($cstate !== 1) continue; // solo pubblicate
?>
<option value="<?php echo $cid; ?>"
<?php echo (!empty($item->categoria_id) && (int)$item->categoria_id === $cid) ? 'selected' : ''; ?>>
@ -68,8 +68,8 @@ $cancelUrl = $cancelItemId
<div class="mb-3">
<label class="form-label" for="description"><?php echo Text::_('Testo'); ?></label>
<textarea id="description" name="description" class="form-control" rows="8"><?php
echo htmlspecialchars($item->description ?? '', ENT_QUOTES, 'UTF-8');
?></textarea>
echo htmlspecialchars($item->description ?? '', ENT_QUOTES, 'UTF-8');
?></textarea>
</div>
<div class="row g-3">
@ -89,8 +89,8 @@ $cancelUrl = $cancelItemId
<label class="form-label" for="jform_firma_obbligatoria"><?php echo Text::_('Firma obbligatoria'); ?></label>
<?php $fo = (int) ($item->firma_obbligatoria ?? 0); ?>
<select name="firma_obbligatoria" id="jform_firma_obbligatoria" class="form-select">
<option value="0" <?php echo $fo===0?'selected':''; ?>><?php echo Text::_('No'); ?></option>
<option value="1" <?php echo $fo===1?'selected':''; ?>><?php echo Text::_('Sì'); ?></option>
<option value="0" <?php echo $fo === 0 ? 'selected' : ''; ?>><?php echo Text::_('No'); ?></option>
<option value="1" <?php echo $fo === 1 ? 'selected' : ''; ?>><?php echo Text::_('Sì'); ?></option>
</select>
</div>
@ -101,10 +101,10 @@ $cancelUrl = $cancelItemId
<?php
$selTipo = (int) ($item->tipologia_firma_id ?? 0);
foreach ((array)$this->firmetipi as $t) {
$tid = (int) $t['id'];
$nm = (string) $t['nome'];
echo '<option value="'.$tid.'" '.($selTipo===$tid?'selected':'').'>'
. htmlspecialchars($nm, ENT_QUOTES, 'UTF-8') . '</option>';
$tid = (int) $t['id'];
$nm = (string) $t['nome'];
echo '<option value="' . $tid . '" ' . ($selTipo === $tid ? 'selected' : '') . '>'
. htmlspecialchars($nm, ENT_QUOTES, 'UTF-8') . '</option>';
}
?>
</select>
@ -114,16 +114,55 @@ $cancelUrl = $cancelItemId
</div>
<div class="row g-3 mt-2 firma-block" style="display:none;">
<div class="col-md-6 firma-block" style="display:none;">
<label class="form-label" for="jform_usergroup_ids">
<?php echo Text::_('Gruppi che possono firmare'); ?>
</label>
<select id="jform_usergroup_ids"
name="usergroup_ids[]"
class="form-select"
multiple
size="8">
<?php foreach ((array) ($this->allUserGroups ?? []) as $g):
$gid = (int) ($g['id'] ?? 0);
$gtitle = (string) ($g['title'] ?? '');
$sel = in_array($gid, (array) ($this->selectedGroupIds ?? []), true) ? 'selected' : '';
?>
<option value="<?php echo $gid; ?>" <?php echo $sel; ?>>
<?php echo htmlspecialchars($gtitle, ENT_QUOTES, 'UTF-8'); ?>
</option>
<?php endforeach; ?>
</select>
<div class="form-text pc-muted">
<?php echo Text::_('Seleziona i gruppi utenti abilitati alla firma di questa circolare.'); ?>
</div>
</div>
<div class="col-md-6">
<label class="form-label required" id="jform_scadenza-lbl" for="jform_scadenza">
<?php echo Text::_('Scadenza firma'); ?><span class="star" aria-hidden="true">&nbsp;*</span>
</label>
<input type="datetime-local" name="scadenza" id="jform_scadenza" class="form-control"
value="<?php
$sc = (string) ($item->scadenza ?? '');
if ($sc !== '') { echo htmlspecialchars(str_replace(' ', 'T', substr($sc, 0, 16)), ENT_QUOTES, 'UTF-8'); }
?>">
value="<?php
$sc = (string) ($item->scadenza ?? '');
if ($sc !== '') {
echo htmlspecialchars(str_replace(' ', 'T', substr($sc, 0, 16)), ENT_QUOTES, 'UTF-8');
}
?>">
</div>
</div>
<div class="col-md-4 mt-4 firma-block" style="display:none;">
<label class="form-label" for="jform_notify">Invia email agli aventi diritto</label>
<input type="hidden" name="notify" value="0">
<div class="form-check form-switch">
<input class="form-check-input" type="checkbox" id="jform_notify" name="notify" value="1">
<label class="form-check-label" for="jform_notify">Sì, invia subito</label>
</div>
<div class="form-text">Invia una notifica agli utenti dei gruppi abilitati alla firma.</div>
</div>
<div class="mt-4 d-flex gap-2">
@ -131,79 +170,86 @@ $cancelUrl = $cancelItemId
<a href="<?php echo $cancelUrl; ?>" class="btn btn-outline-secondary"><?php echo Text::_('Annulla'); ?></a>
</div>
<input type="hidden" name="id" value="<?php echo (int) ($this->item->id ?? 0); ?>">
<?php echo \Joomla\CMS\HTML\HTMLHelper::_('form.token'); ?>
<input type="hidden" name="id" value="<?php echo (int) ($this->item->id ?? 0); ?>">
<?php echo \Joomla\CMS\HTML\HTMLHelper::_('form.token'); ?>
<script type="application/json" id="bottoni-map"><?php
<script type="application/json" id="bottoni-map">
<?php
echo json_encode($this->bottoniMap ?? [], JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES);
?></script>
?>
</script>
<script>
(function(){
function byId(id){ return document.getElementById(id); }
const obb = byId('jform_firma_obbligatoria');
const tipo = byId('jform_tipologia_firma_id');
const scad = byId('jform_scadenza');
const blocks= document.querySelectorAll('.firma-block');
const mapEl = byId('bottoni-map');
const prev = byId('anteprima-bottoni');
const map = mapEl ? JSON.parse(mapEl.textContent || '{}') : {};
(function() {
function byId(id) {
return document.getElementById(id);
}
const obb = byId('jform_firma_obbligatoria');
const tipo = byId('jform_tipologia_firma_id');
const scad = byId('jform_scadenza');
const blocks = document.querySelectorAll('.firma-block');
const mapEl = byId('bottoni-map');
const prev = byId('anteprima-bottoni');
const map = mapEl ? JSON.parse(mapEl.textContent || '{}') : {};
function renderPreview(){
if (!prev || !tipo) return;
const fid = tipo.value;
prev.innerHTML = '';
if (!fid || !map[fid] || !map[fid].length) return;
map[fid].forEach(function(lbl){
const span = document.createElement('span');
span.className = 'badge bg-secondary me-1 mb-1';
span.textContent = lbl;
prev.appendChild(span);
});
}
function renderPreview() {
if (!prev || !tipo) return;
const fid = tipo.value;
prev.innerHTML = '';
if (!fid || !map[fid] || !map[fid].length) return;
map[fid].forEach(function(lbl) {
const span = document.createElement('span');
span.className = 'badge bg-secondary me-1 mb-1';
span.textContent = lbl;
prev.appendChild(span);
});
}
function toggleFirma(){
const need = obb && obb.value === '1';
blocks.forEach(function(el){ el.style.display = need ? '' : 'none'; });
if (scad){
if (need){
scad.setAttribute('required','required');
scad.setAttribute('aria-required','true');
// aggiungi asterisco al label se manca
var lbl = document.getElementById('jform_scadenza-lbl');
if (lbl){
lbl.classList.add('required');
if (!lbl.querySelector('.star')){
var s = document.createElement('span');
s.className = 'star';
s.setAttribute('aria-hidden','true');
s.innerHTML = '&nbsp;*';
lbl.appendChild(s);
function toggleFirma() {
const need = obb && obb.value === '1';
blocks.forEach(function(el) {
el.style.display = need ? '' : 'none';
});
if (scad) {
if (need) {
scad.setAttribute('required', 'required');
scad.setAttribute('aria-required', 'true');
// aggiungi asterisco al label se manca
var lbl = document.getElementById('jform_scadenza-lbl');
if (lbl) {
lbl.classList.add('required');
if (!lbl.querySelector('.star')) {
var s = document.createElement('span');
s.className = 'star';
s.setAttribute('aria-hidden', 'true');
s.innerHTML = '&nbsp;*';
lbl.appendChild(s);
}
}
} else {
scad.removeAttribute('required');
scad.removeAttribute('aria-required');
var lbl = document.getElementById('jform_scadenza-lbl');
if (lbl) {
lbl.classList.remove('required');
var st = lbl.querySelector('.star');
if (st) st.remove();
}
}
} else {
scad.removeAttribute('required');
scad.removeAttribute('aria-required');
var lbl = document.getElementById('jform_scadenza-lbl');
if (lbl){
lbl.classList.remove('required');
var st = lbl.querySelector('.star'); if (st) st.remove();
}
}
renderPreview();
}
renderPreview();
}
document.addEventListener('change', function(e){
if (e.target === obb) toggleFirma();
if (e.target === tipo) renderPreview();
});
document.addEventListener('change', function(e) {
if (e.target === obb) toggleFirma();
if (e.target === tipo) renderPreview();
});
document.addEventListener('DOMContentLoaded', function(){
toggleFirma();
renderPreview();
});
})();
document.addEventListener('DOMContentLoaded', function() {
toggleFirma();
renderPreview();
});
})();
</script>
</form>
</div>
</div>