diff --git a/cron/class_report.php b/cron/class_report.php index 92d4cce..00f7384 100644 --- a/cron/class_report.php +++ b/cron/class_report.php @@ -1,13 +1,19 @@ versione riservata: nomi "Mario R.", senza email dei partecipanti + * - al titolare, se diverso dall'insegnante (se notifiche attive e con email) + * -> copia separata con i dati completi + * - se l'insegnante È il titolare: una sola mail completa * * Uso: * php cron/class_report.php -> classi di oggi * php cron/class_report.php 2026-09-25 -> classi di una data specifica * php cron/class_report.php --dry-run -> NON invia, salva le anteprime HTML in cron/preview/ + * php cron/class_report.php --only-at=17 -> esce senza fare nulla se in Italia non sono le 17 */ use PHPMailer\PHPMailer\PHPMailer; @@ -56,12 +62,35 @@ function chip(string $label, string $bg, string $fg): string return '' . h($label) . ''; } +/** Nome completo (versione titolare) */ function fullName(array $p): string { $n = trim(($p['first_name'] ?? '') . ' ' . ($p['last_name'] ?? '')); return $n !== '' ? $n : 'Utente #' . (int) ($p['iduser'] ?? 0); } +/** Nome + iniziale del cognome (versione insegnante): "Mario R." */ +function shortName(array $p): string +{ + $first = trim((string) ($p['first_name'] ?? '')); + $last = trim((string) ($p['last_name'] ?? '')); + if ($first === '' && $last === '') { + return 'Utente #' . (int) ($p['iduser'] ?? 0); + } + $ini = $last !== '' ? ' ' . mb_strtoupper(mb_substr($last, 0, 1)) . '.' : ''; + return ($first !== '' ? $first : '') . $ini; +} + +function personName(array $p, bool $full): string +{ + return $full ? fullName($p) : shortName($p); +} + +function teacherName(?array $t): string +{ + return $t ? trim($t['nameemployee'] . ' ' . $t['surnameemployee']) : ''; +} + function italianDate(DateTime $d): string { $days = ['Domenica', 'Lunedì', 'Martedì', 'Mercoledì', 'Giovedì', 'Venerdì', 'Sabato']; @@ -69,6 +98,27 @@ function italianDate(DateTime $d): string return $days[(int) $d->format('w')] . ' ' . (int) $d->format('j') . ' ' . $months[(int) $d->format('n')] . ' ' . $d->format('Y'); } +/** Motivo per cui non può ricevere ('' = può ricevere) */ +function whyNot(?array $t): string +{ + if (!$t) return 'nessun insegnante assegnato'; + if (($t['active'] ?? 'N') !== 'Y') return 'insegnante non attivo'; + if (($t['notifications'] ?? 'N') !== 'Y') return 'notifiche disattivate'; + if (empty($t['email'])) return 'email mancante'; + if (!filter_var($t['email'], FILTER_VALIDATE_EMAIL)) return 'email non valida'; + return ''; +} + +/** Può ricevere mail? notifiche attive, attivo, email valida */ +function canReceive(?array $t): bool +{ + return $t + && ($t['notifications'] ?? 'N') === 'Y' + && ($t['active'] ?? 'N') === 'Y' + && !empty($t['email']) + && filter_var($t['email'], FILTER_VALIDATE_EMAIL); +} + /* ----------------------------------------------------------- argomenti */ $dryRun = in_array('--dry-run', $argv, true); @@ -79,18 +129,27 @@ foreach (array_slice($argv, 1) as $a) { } } -$recipients = array_values(array_filter(array_map('trim', explode(',', (string) cfg('TEACHER_EMAIL', ''))))); -if (!$recipients && !$dryRun) { - logmsg('ERRORE: TEACHER_EMAIL non impostato nel .env'); - exit(1); -} - $location = cfg('CLASS_LOCATION', 'via Valassina 62/B Seregno - Sala Contesto Yoga'); +// Le mail agli insegnanti (non titolari) partono solo se l'opzione "Mostra insegnante" è attiva +$optRow = $pdo->query("SELECT show_teacher FROM `option` LIMIT 1")->fetch(); +$teacherMailsEnabled = ($optRow['show_teacher'] ?? 'N') === 'Y'; + +/* ---------------------------------------------------------- insegnanti */ + +$employees = []; +$owner = null; +foreach ($pdo->query("SELECT idemployee, nameemployee, surnameemployee, email, is_owner, notifications, active FROM employee")->fetchAll() as $t) { + $employees[(int) $t['idemployee']] = $t; + if ($t['is_owner'] === 'Y' && $owner === null) { + $owner = $t; + } +} + /* ------------------------------------------------------ classi del giorno */ $stmt = $pdo->prepare( - "SELECT ss.idserviceschedule, ss.dateschedule, s.servicename, s.colorclass, s.maxcapacity + "SELECT ss.idserviceschedule, ss.dateschedule, s.servicename, s.colorclass, s.maxcapacity, s.idteacher FROM serviceschedule ss LEFT JOIN service s ON ss.idservice = s.idservice WHERE ss.dateschedule >= :d1 AND ss.dateschedule < :d2 @@ -127,7 +186,7 @@ foreach ($stmtB->fetchAll() as $b) { /* ------------------------------------------------------------ template */ -function personRows(array $list, string $type): string +function personRows(array $list, string $type, bool $full): string { if (!$list) { return '
| ' . $i . ($type === 'waiting' ? '°' : '.') . ' | ' - . '' . h(fullName($p)) . $email . ' | ' + . '' . h(personName($p, $full)) . $email . ' | ' . '' . $chipHtml . ' | ' . '
| ' . ' |
Propaga una classe sul calendario, associala o modificane i dettagli.
+Propaga una classe sul calendario, associala, assegna l'insegnante o modificane i dettagli.
| Orario | Durata | Categoria | +Insegnante | Azioni | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
| Nessuna classe presente. | +Nessuna classe presente. | |||||||||||
| @@ -391,6 +528,25 @@ foreach ($propRows as $pr) { | + | + + | @@ -407,7 +563,7 @@ foreach ($propRows as $pr) { | |||||||||
| + | ||||||||||||