Compare commits
1
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
f206b0db9a |
+1
-4
@@ -34,7 +34,4 @@ public/yogasoulscript/logs/
|
||||
public/user/document/
|
||||
|
||||
# Python venv
|
||||
public/yogasoulscript/venv//index.html
|
||||
/public/.well-known/
|
||||
/index.html
|
||||
/public/.well-known/
|
||||
public/yogasoulscript/venv/
|
||||
+1
-1
@@ -40,7 +40,7 @@
|
||||
"laravel/tinker": "^2.7",
|
||||
"laravel/ui": "^4.0",
|
||||
"laravelcollective/html": "^6.3",
|
||||
"phpmailer/phpmailer": "^7.1",
|
||||
"phpmailer/phpmailer": "^6.8",
|
||||
"proengsoft/laravel-jsvalidation": "^4.0.0",
|
||||
"robmorgan/phinx": "^0.16.12",
|
||||
"spatie/laravel-query-builder": "^5.0",
|
||||
|
||||
Generated
+10
-11
@@ -4,7 +4,7 @@
|
||||
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
|
||||
"This file is @generated automatically"
|
||||
],
|
||||
"content-hash": "9307a6b8f5f1c5b0a5efb10e35038f7f",
|
||||
"content-hash": "9b689efb6d29cb572794705682d6edc4",
|
||||
"packages": [
|
||||
{
|
||||
"name": "akaunting/laravel-setting",
|
||||
@@ -3428,16 +3428,16 @@
|
||||
},
|
||||
{
|
||||
"name": "phpmailer/phpmailer",
|
||||
"version": "v7.1.1",
|
||||
"version": "v6.9.3",
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/PHPMailer/PHPMailer.git",
|
||||
"reference": "1bc1716a507a65e039d4ac9d9adebbbd0d346e15"
|
||||
"reference": "2f5c94fe7493efc213f643c23b1b1c249d40f47e"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://api.github.com/repos/PHPMailer/PHPMailer/zipball/1bc1716a507a65e039d4ac9d9adebbbd0d346e15",
|
||||
"reference": "1bc1716a507a65e039d4ac9d9adebbbd0d346e15",
|
||||
"url": "https://api.github.com/repos/PHPMailer/PHPMailer/zipball/2f5c94fe7493efc213f643c23b1b1c249d40f47e",
|
||||
"reference": "2f5c94fe7493efc213f643c23b1b1c249d40f47e",
|
||||
"shasum": ""
|
||||
},
|
||||
"require": {
|
||||
@@ -3451,14 +3451,13 @@
|
||||
"doctrine/annotations": "^1.2.6 || ^1.13.3",
|
||||
"php-parallel-lint/php-console-highlighter": "^1.0.0",
|
||||
"php-parallel-lint/php-parallel-lint": "^1.3.2",
|
||||
"phpcompatibility/php-compatibility": "^10.0.0@dev",
|
||||
"squizlabs/php_codesniffer": "^3.13.5",
|
||||
"phpcompatibility/php-compatibility": "^9.3.5",
|
||||
"roave/security-advisories": "dev-latest",
|
||||
"squizlabs/php_codesniffer": "^3.7.2",
|
||||
"yoast/phpunit-polyfills": "^1.0.4"
|
||||
},
|
||||
"suggest": {
|
||||
"decomplexity/SendOauth2": "Adapter for using XOAUTH2 authentication",
|
||||
"directorytree/imapengine": "For uploading sent messages via IMAP, see gmail example",
|
||||
"ext-imap": "Needed to support advanced email address parsing according to RFC822",
|
||||
"ext-mbstring": "Needed to send email in multibyte encoding charset or decode encoded addresses",
|
||||
"ext-openssl": "Needed for secure SMTP sending and DKIM signing",
|
||||
"greew/oauth2-azure-provider": "Needed for Microsoft Azure XOAUTH2 authentication",
|
||||
@@ -3498,7 +3497,7 @@
|
||||
"description": "PHPMailer is a full-featured email creation and transfer class for PHP",
|
||||
"support": {
|
||||
"issues": "https://github.com/PHPMailer/PHPMailer/issues",
|
||||
"source": "https://github.com/PHPMailer/PHPMailer/tree/v7.1.1"
|
||||
"source": "https://github.com/PHPMailer/PHPMailer/tree/v6.9.3"
|
||||
},
|
||||
"funding": [
|
||||
{
|
||||
@@ -3506,7 +3505,7 @@
|
||||
"type": "github"
|
||||
}
|
||||
],
|
||||
"time": "2026-05-18T08:06:14+00:00"
|
||||
"time": "2024-11-24T18:04:13+00:00"
|
||||
},
|
||||
{
|
||||
"name": "phpoption/phpoption",
|
||||
|
||||
@@ -1,447 +0,0 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* YogiBook - Riepilogo classi giornaliero.
|
||||
* Invia UNA mail per ogni classe del giorno:
|
||||
* - all'insegnante della classe (se notifiche attive, attivo e con email)
|
||||
* -> 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;
|
||||
use PHPMailer\PHPMailer\Exception as MailException;
|
||||
|
||||
if (PHP_SAPI !== 'cli') {
|
||||
http_response_code(403);
|
||||
exit('Accesso consentito solo da CLI');
|
||||
}
|
||||
|
||||
date_default_timezone_set('Europe/Rome');
|
||||
|
||||
// --only-at=17 : esce senza fare nulla se in Italia non sono le 17 (server in UTC)
|
||||
foreach ($argv as $a) {
|
||||
if (preg_match('/^--only-at=(\d{1,2})$/', $a, $m) && (int) date('G') !== (int) $m[1]) {
|
||||
exit(0);
|
||||
}
|
||||
}
|
||||
|
||||
$root = dirname(__DIR__);
|
||||
chdir($root);
|
||||
require_once $root . '/public/class/db-functions.php'; // include anche vendor/autoload.php
|
||||
|
||||
$pdo = DBHandlerSelect::getInstance()->getConnection(); // carica anche il .env
|
||||
|
||||
/* ---------------------------------------------------------------- helper */
|
||||
|
||||
function cfg(string $key, $default = null)
|
||||
{
|
||||
$v = $_ENV[$key] ?? $_SERVER[$key] ?? getenv($key);
|
||||
return ($v === false || $v === null || $v === '') ? $default : $v;
|
||||
}
|
||||
|
||||
function h($v): string
|
||||
{
|
||||
return htmlspecialchars((string) $v, ENT_QUOTES, 'UTF-8');
|
||||
}
|
||||
|
||||
function logmsg(string $m): void
|
||||
{
|
||||
echo '[' . date('Y-m-d H:i:s') . '] ' . $m . PHP_EOL;
|
||||
}
|
||||
|
||||
function chip(string $label, string $bg, string $fg): string
|
||||
{
|
||||
return '<span style="display:inline-block;background:' . $bg . ';color:' . $fg . ';font-size:11px;font-weight:700;padding:3px 10px;border-radius:20px;white-space:nowrap;">' . h($label) . '</span>';
|
||||
}
|
||||
|
||||
/** 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'];
|
||||
$months = ['', 'Gennaio', 'Febbraio', 'Marzo', 'Aprile', 'Maggio', 'Giugno', 'Luglio', 'Agosto', 'Settembre', 'Ottobre', 'Novembre', 'Dicembre'];
|
||||
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);
|
||||
$day = date('Y-m-d');
|
||||
foreach (array_slice($argv, 1) as $a) {
|
||||
if (preg_match('/^\d{4}-\d{2}-\d{2}$/', $a)) {
|
||||
$day = $a;
|
||||
}
|
||||
}
|
||||
|
||||
$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, s.idteacher
|
||||
FROM serviceschedule ss
|
||||
LEFT JOIN service s ON ss.idservice = s.idservice
|
||||
WHERE ss.dateschedule >= :d1 AND ss.dateschedule < :d2
|
||||
ORDER BY ss.dateschedule"
|
||||
);
|
||||
$stmt->execute([
|
||||
':d1' => $day . ' 00:00:00',
|
||||
':d2' => date('Y-m-d', strtotime($day . ' +1 day')) . ' 00:00:00',
|
||||
]);
|
||||
$classes = $stmt->fetchAll();
|
||||
|
||||
if (!$classes) {
|
||||
logmsg("Nessuna classe il $day. Nessuna mail inviata.");
|
||||
exit(0);
|
||||
}
|
||||
|
||||
$ids = array_map(fn($c) => (int) $c['idserviceschedule'], $classes);
|
||||
$ph = implode(',', array_fill(0, count($ids), '?'));
|
||||
$stmtB = $pdo->prepare(
|
||||
"SELECT bc.idbookingclass, bc.idserviceschedule, bc.lostlesson, bc.status,
|
||||
u.id AS iduser, u.first_name, u.last_name, u.email
|
||||
FROM bookingclass bc
|
||||
LEFT JOIN auth_users u ON bc.iduser = u.id
|
||||
WHERE bc.idserviceschedule IN ($ph)
|
||||
AND bc.status IN ('booked', 'pending', 'waiting')
|
||||
ORDER BY bc.created_at, u.last_name, u.first_name"
|
||||
);
|
||||
$stmtB->execute($ids);
|
||||
|
||||
$bookingsBySchedule = [];
|
||||
foreach ($stmtB->fetchAll() as $b) {
|
||||
$bookingsBySchedule[(int) $b['idserviceschedule']][] = $b;
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------ template */
|
||||
|
||||
function personRows(array $list, string $type, bool $full): string
|
||||
{
|
||||
if (!$list) {
|
||||
return '<tr><td style="padding:16px;color:#9ca3af;font-size:14px;text-align:center;">Nessun partecipante</td></tr>';
|
||||
}
|
||||
$numColor = ['booked' => '#1ebf73', 'pending' => '#8a6d00', 'waiting' => '#d1698a'][$type];
|
||||
$html = '';
|
||||
$i = 1;
|
||||
foreach ($list as $p) {
|
||||
$isLost = ($type === 'booked' && ($p['lostlesson'] ?? '') === 'Y');
|
||||
if ($type === 'booked') {
|
||||
$chipHtml = $isLost ? chip('Persa', '#1f2937', '#ffffff') : chip('Confermata', '#e3f2ec', '#1a7f52');
|
||||
} elseif ($type === 'pending') {
|
||||
$chipHtml = chip('In attesa', '#fff4d6', '#8a6d00');
|
||||
} else {
|
||||
$chipHtml = chip('In coda', '#fbeef3', '#d1698a');
|
||||
}
|
||||
$nameColor = $isLost ? '#9ca3af' : '#1f2937';
|
||||
$email = ($full && !empty($p['email']))
|
||||
? '<br><span style="font-size:12px;color:#6b7280;font-weight:400;">' . h($p['email']) . '</span>'
|
||||
: '';
|
||||
|
||||
$html .= '<tr><td style="padding:10px 14px;border-bottom:1px solid #eef0f3;">'
|
||||
. '<table role="presentation" width="100%" cellpadding="0" cellspacing="0"><tr>'
|
||||
. '<td width="34" valign="top" style="font-weight:800;color:' . $numColor . ';font-size:14px;padding-top:1px;">' . $i . ($type === 'waiting' ? '°' : '.') . '</td>'
|
||||
. '<td valign="top" style="font-size:15px;color:' . $nameColor . ';font-weight:600;">' . h(personName($p, $full)) . $email . '</td>'
|
||||
. '<td valign="top" align="right" width="100">' . $chipHtml . '</td>'
|
||||
. '</tr></table></td></tr>';
|
||||
$i++;
|
||||
}
|
||||
return $html;
|
||||
}
|
||||
|
||||
function section(string $title, string $color, string $rows): string
|
||||
{
|
||||
return '<tr><td style="padding:22px 28px 0;">'
|
||||
. '<div style="font-size:13px;font-weight:700;color:' . $color . ';text-transform:uppercase;letter-spacing:0.04em;margin-bottom:8px;">' . $title . '</div>'
|
||||
. '<table role="presentation" width="100%" cellpadding="0" cellspacing="0" style="background:#f8fafc;border:1px solid #eef0f3;border-radius:10px;">' . $rows . '</table>'
|
||||
. '</td></tr>';
|
||||
}
|
||||
|
||||
function statBox(string $value, string $label, string $color): string
|
||||
{
|
||||
return '<td align="center" style="padding:12px 6px;background:#f8fafc;border-radius:10px;">'
|
||||
. '<div style="font-size:22px;font-weight:800;color:' . $color . ';line-height:1.1;">' . $value . '</div>'
|
||||
. '<div style="font-size:11px;color:#6b7280;text-transform:uppercase;letter-spacing:0.04em;margin-top:4px;">' . $label . '</div>'
|
||||
. '</td>';
|
||||
}
|
||||
|
||||
/**
|
||||
* @param bool $full true = versione titolare (nomi completi + email)
|
||||
* @param string $teacherFull nome insegnante da mostrare in testata
|
||||
* @param string|null $copyNote nota "copia per il titolare" (solo se il titolare non è l'insegnante)
|
||||
*/
|
||||
function renderEmail(array $cls, array $booked, array $pending, array $waiting, string $location, bool $full, string $teacherFull, ?string $copyNote): string
|
||||
{
|
||||
$d = new DateTime($cls['dateschedule']);
|
||||
$accent = $cls['colorclass'] ?: '#1ebf73';
|
||||
$max = (int) $cls['maxcapacity'];
|
||||
$nBooked = count($booked);
|
||||
$nLost = count(array_filter($booked, fn($b) => ($b['lostlesson'] ?? '') === 'Y'));
|
||||
$free = $max > 0 ? max(0, $max - $nBooked) : '–';
|
||||
$isFull = $max > 0 && $nBooked >= $max;
|
||||
|
||||
$stats = '<table role="presentation" width="100%" cellpadding="0" cellspacing="6"><tr>'
|
||||
. statBox($nBooked . '/' . $max, 'Iscritti', $isFull ? '#c0392b' : '#1a7f52')
|
||||
. statBox((string) $free, 'Posti liberi', '#374151')
|
||||
. statBox((string) count($pending), 'In attesa', '#8a6d00')
|
||||
. statBox((string) count($waiting), 'In coda', '#d1698a')
|
||||
. '</tr></table>';
|
||||
|
||||
$lostNote = $nLost > 0
|
||||
? '<div style="font-size:13px;color:#6b7280;margin-top:6px;">di cui ' . $nLost . ' segnat' . ($nLost === 1 ? 'a' : 'e') . ' come pers' . ($nLost === 1 ? 'a' : 'e') . '</div>'
|
||||
: '';
|
||||
|
||||
$body = section('Partecipanti confermati (' . $nBooked . ')', '#374151', personRows($booked, 'booked', $full));
|
||||
if ($pending) {
|
||||
$body .= section('In attesa di conferma (' . count($pending) . ')', '#8a6d00', personRows($pending, 'pending', $full));
|
||||
}
|
||||
if ($waiting) {
|
||||
$body .= section('Lista d\'attesa (' . count($waiting) . ')', '#d1698a', personRows($waiting, 'waiting', $full));
|
||||
}
|
||||
|
||||
$copyBanner = $copyNote
|
||||
? '<tr><td style="padding:14px 28px 0;"><div style="background:#f5eee4;color:#5a4630;border-radius:10px;padding:10px 14px;font-size:13px;">' . $copyNote . '</div></td></tr>'
|
||||
: '';
|
||||
|
||||
$teacherLine = $teacherFull !== ''
|
||||
? '<div style="font-size:13px;color:#6b7280;margin-top:4px;">Insegnante: <strong style="color:#374151;">' . h($teacherFull) . '</strong></div>'
|
||||
: '';
|
||||
|
||||
return '<!doctype html><html lang="it"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width,initial-scale=1"><title>' . h($cls['servicename']) . '</title></head>'
|
||||
. '<body style="margin:0;padding:0;background:#f3f5f7;font-family:-apple-system,Segoe UI,Roboto,Helvetica,Arial,sans-serif;">'
|
||||
. '<table role="presentation" width="100%" cellpadding="0" cellspacing="0" style="background:#f3f5f7;padding:24px 12px;"><tr><td align="center">'
|
||||
. '<table role="presentation" width="600" cellpadding="0" cellspacing="0" style="max-width:600px;width:100%;background:#ffffff;border-radius:14px;overflow:hidden;box-shadow:0 3px 16px rgba(0,0,0,0.06);">'
|
||||
. '<tr><td style="height:8px;background:' . h($accent) . ';font-size:0;line-height:0;"> </td></tr>'
|
||||
. $copyBanner
|
||||
. '<tr><td style="padding:26px 28px 6px;">'
|
||||
. '<div style="font-size:12px;font-weight:700;color:#1ebf73;text-transform:uppercase;letter-spacing:0.06em;">YogiBook · Riepilogo classe</div>'
|
||||
. '<h1 style="margin:8px 0 6px;font-size:24px;color:#1f2937;">' . h($cls['servicename']) . '</h1>'
|
||||
. '<div style="font-size:15px;color:#374151;font-weight:600;">' . h(italianDate($d)) . ' · ore ' . $d->format('H:i') . '</div>'
|
||||
. '<div style="font-size:13px;color:#6b7280;margin-top:4px;">' . h($location) . '</div>'
|
||||
. $teacherLine
|
||||
. '</td></tr>'
|
||||
. '<tr><td style="padding:16px 22px 0;">' . $stats . '<div style="padding:0 6px;">' . $lostNote . '</div></td></tr>'
|
||||
. $body
|
||||
. '<tr><td style="padding:26px 28px;font-size:12px;color:#9ca3af;text-align:center;">Generato automaticamente da YogiBook il ' . date('d/m/Y \a\l\l\e H:i') . '</td></tr>'
|
||||
. '</table></td></tr></table></body></html>';
|
||||
}
|
||||
|
||||
function renderText(array $cls, array $booked, array $pending, array $waiting, string $location, bool $full, string $teacherFull, ?string $copyNote): string
|
||||
{
|
||||
$d = new DateTime($cls['dateschedule']);
|
||||
$max = (int) $cls['maxcapacity'];
|
||||
$t = '';
|
||||
if ($copyNote) {
|
||||
$t .= strip_tags($copyNote) . "\n\n";
|
||||
}
|
||||
$t .= $cls['servicename'] . "\n" . italianDate($d) . ' ore ' . $d->format('H:i') . "\n" . $location . "\n";
|
||||
if ($teacherFull !== '') {
|
||||
$t .= 'Insegnante: ' . $teacherFull . "\n";
|
||||
}
|
||||
$t .= "\nIscritti: " . count($booked) . '/' . $max . ' | In attesa: ' . count($pending) . ' | In coda: ' . count($waiting) . "\n\n";
|
||||
$blocks = ['CONFERMATI' => $booked, 'IN ATTESA DI CONFERMA' => $pending, "LISTA D'ATTESA" => $waiting];
|
||||
foreach ($blocks as $title => $list) {
|
||||
if ($title !== 'CONFERMATI' && !$list) {
|
||||
continue;
|
||||
}
|
||||
$t .= $title . "\n";
|
||||
if (!$list) {
|
||||
$t .= " Nessun partecipante\n";
|
||||
}
|
||||
$i = 1;
|
||||
foreach ($list as $p) {
|
||||
$lost = ($p['status'] === 'booked' && ($p['lostlesson'] ?? '') === 'Y') ? ' (PERSA)' : '';
|
||||
$t .= ' ' . $i++ . '. ' . personName($p, $full) . $lost . "\n";
|
||||
}
|
||||
$t .= "\n";
|
||||
}
|
||||
return $t;
|
||||
}
|
||||
|
||||
/* -------------------------------------------------------------- mailer */
|
||||
|
||||
function makeMailer(): PHPMailer
|
||||
{
|
||||
$m = new PHPMailer(true);
|
||||
$m->isSMTP();
|
||||
$m->Host = cfg('MAIL_HOST');
|
||||
$m->Port = (int) cfg('MAIL_PORT', 465);
|
||||
$m->SMTPAuth = true;
|
||||
$m->Username = cfg('MAIL_USERNAME');
|
||||
$m->Password = cfg('MAIL_PASSWORD');
|
||||
$enc = strtolower((string) cfg('MAIL_ENCRYPTION', 'ssl'));
|
||||
$m->SMTPSecure = $enc === 'ssl' ? PHPMailer::ENCRYPTION_SMTPS : ($enc === 'tls' ? PHPMailer::ENCRYPTION_STARTTLS : '');
|
||||
$m->SMTPKeepAlive = true;
|
||||
$m->CharSet = 'UTF-8';
|
||||
$m->Encoding = 'base64';
|
||||
$m->setFrom(cfg('MAIL_FROM_ADDRESS'), cfg('MAIL_FROM_NAME', 'YogiBook'));
|
||||
$m->isHTML(true);
|
||||
return $m;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------- invio */
|
||||
|
||||
$mailer = $dryRun ? null : makeMailer();
|
||||
$sent = 0;
|
||||
$failed = 0;
|
||||
$skipped = 0;
|
||||
|
||||
foreach ($classes as $cls) {
|
||||
$sid = (int) $cls['idserviceschedule'];
|
||||
$all = $bookingsBySchedule[$sid] ?? [];
|
||||
$booked = array_values(array_filter($all, fn($b) => $b['status'] === 'booked'));
|
||||
$pending = array_values(array_filter($all, fn($b) => $b['status'] === 'pending'));
|
||||
$waiting = array_values(array_filter($all, fn($b) => $b['status'] === 'waiting'));
|
||||
|
||||
$teacher = $employees[(int) $cls['idteacher']] ?? null;
|
||||
$teacherIsOwner = $teacher && $owner && (int) $teacher['idemployee'] === (int) $owner['idemployee'];
|
||||
$tName = teacherName($teacher);
|
||||
|
||||
$d = new DateTime($cls['dateschedule']);
|
||||
$baseSubject = $cls['servicename'] . ' · ' . $d->format('d/m') . ' ore ' . $d->format('H:i')
|
||||
. ' · ' . count($booked) . '/' . (int) $cls['maxcapacity'] . ' iscritti';
|
||||
if ($pending) {
|
||||
$baseSubject .= ' · ' . count($pending) . ' in attesa';
|
||||
}
|
||||
if ($waiting) {
|
||||
$baseSubject .= ' · ' . count($waiting) . ' in coda';
|
||||
}
|
||||
|
||||
// Chi riceve cosa
|
||||
$deliveries = [];
|
||||
if ($teacherIsOwner) {
|
||||
if (canReceive($owner)) {
|
||||
$deliveries[] = ['to' => $owner, 'full' => true, 'copy' => null, 'tag' => 'titolare'];
|
||||
}
|
||||
} else {
|
||||
if (!$teacherMailsEnabled) {
|
||||
logmsg("Classe #$sid ({$cls['servicename']}): mail all'insegnante non inviata (opzione insegnanti disattivata)");
|
||||
} elseif (canReceive($teacher)) {
|
||||
$deliveries[] = ['to' => $teacher, 'full' => false, 'copy' => null, 'tag' => 'insegnante'];
|
||||
} else {
|
||||
logmsg("Classe #$sid ({$cls['servicename']}): insegnante " . ($tName ?: '-') . " escluso: " . whyNot($teacher));
|
||||
}
|
||||
if (canReceive($owner)) {
|
||||
$note = $tName !== ''
|
||||
? '<strong>Copia per il titolare</strong> · classe di ' . h($tName)
|
||||
: '<strong>Copia per il titolare</strong> · classe senza insegnante assegnato';
|
||||
$deliveries[] = ['to' => $owner, 'full' => true, 'copy' => $note, 'tag' => 'titolare'];
|
||||
}
|
||||
}
|
||||
|
||||
if (!$deliveries) {
|
||||
$skipped++;
|
||||
logmsg("SALTATA classe #$sid ({$cls['servicename']}): nessun destinatario (notifiche disattivate o email mancante).");
|
||||
continue;
|
||||
}
|
||||
|
||||
foreach ($deliveries as $dv) {
|
||||
$subject = ($dv['copy'] ? '[Copia] ' : '') . $baseSubject;
|
||||
$html = renderEmail($cls, $booked, $pending, $waiting, $location, $dv['full'], $tName, $dv['copy']);
|
||||
$text = renderText($cls, $booked, $pending, $waiting, $location, $dv['full'], $tName, $dv['copy']);
|
||||
$toName = teacherName($dv['to']);
|
||||
|
||||
if ($dryRun) {
|
||||
$dir = __DIR__ . '/preview';
|
||||
if (!is_dir($dir)) {
|
||||
mkdir($dir, 0775, true);
|
||||
}
|
||||
$file = $dir . '/classe_' . $sid . '_' . $dv['tag'] . '.html';
|
||||
file_put_contents($file, $html);
|
||||
logmsg("[DRY-RUN] a {$toName} <{$dv['to']['email']}> ({$dv['tag']}): $subject -> $file");
|
||||
continue;
|
||||
}
|
||||
|
||||
try {
|
||||
$mailer->clearAddresses();
|
||||
$mailer->addAddress($dv['to']['email'], $toName);
|
||||
$mailer->Subject = $subject;
|
||||
$mailer->Body = $html;
|
||||
$mailer->AltBody = $text;
|
||||
$mailer->send();
|
||||
$sent++;
|
||||
logmsg("OK a {$toName} ({$dv['tag']}): $subject");
|
||||
} catch (MailException $e) {
|
||||
$failed++;
|
||||
logmsg("ERRORE classe #$sid a {$dv['to']['email']}: " . $mailer->ErrorInfo);
|
||||
}
|
||||
sleep(1); // evita limiti di invio del server SMTP
|
||||
}
|
||||
}
|
||||
|
||||
if ($mailer) {
|
||||
$mailer->smtpClose();
|
||||
}
|
||||
|
||||
logmsg("Fine: $sent inviate, $failed errori, $skipped classi senza destinatari (" . count($classes) . " classi il $day).");
|
||||
exit($failed > 0 ? 1 : 0);
|
||||
@@ -1 +0,0 @@
|
||||
<!doctype html><html lang="it"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width,initial-scale=1"><title>Hatha Yoga</title></head><body style="margin:0;padding:0;background:#f3f5f7;font-family:-apple-system,Segoe UI,Roboto,Helvetica,Arial,sans-serif;"><table role="presentation" width="100%" cellpadding="0" cellspacing="0" style="background:#f3f5f7;padding:24px 12px;"><tr><td align="center"><table role="presentation" width="600" cellpadding="0" cellspacing="0" style="max-width:600px;width:100%;background:#ffffff;border-radius:14px;overflow:hidden;box-shadow:0 3px 16px rgba(0,0,0,0.06);"><tr><td style="height:8px;background:#fa9b9b;font-size:0;line-height:0;"> </td></tr><tr><td style="padding:26px 28px 6px;"><div style="font-size:12px;font-weight:700;color:#1ebf73;text-transform:uppercase;letter-spacing:0.06em;">YogiBook · Riepilogo classe</div><h1 style="margin:8px 0 6px;font-size:24px;color:#1f2937;">Hatha Yoga</h1><div style="font-size:15px;color:#374151;font-weight:600;">Lunedì 5 Ottobre 2026 · ore 19:30</div><div style="font-size:13px;color:#6b7280;margin-top:4px;">via Valassina 62/B Seregno - Sala Contesto Yoga</div></td></tr><tr><td style="padding:16px 22px 0;"><table role="presentation" width="100%" cellpadding="0" cellspacing="6"><tr><td align="center" style="padding:12px 6px;background:#f8fafc;border-radius:10px;"><div style="font-size:22px;font-weight:800;color:#c0392b;line-height:1.1;">1/1</div><div style="font-size:11px;color:#6b7280;text-transform:uppercase;letter-spacing:0.04em;margin-top:4px;">Iscritti</div></td><td align="center" style="padding:12px 6px;background:#f8fafc;border-radius:10px;"><div style="font-size:22px;font-weight:800;color:#374151;line-height:1.1;">0</div><div style="font-size:11px;color:#6b7280;text-transform:uppercase;letter-spacing:0.04em;margin-top:4px;">Posti liberi</div></td><td align="center" style="padding:12px 6px;background:#f8fafc;border-radius:10px;"><div style="font-size:22px;font-weight:800;color:#8a6d00;line-height:1.1;">0</div><div style="font-size:11px;color:#6b7280;text-transform:uppercase;letter-spacing:0.04em;margin-top:4px;">In attesa</div></td><td align="center" style="padding:12px 6px;background:#f8fafc;border-radius:10px;"><div style="font-size:22px;font-weight:800;color:#d1698a;line-height:1.1;">0</div><div style="font-size:11px;color:#6b7280;text-transform:uppercase;letter-spacing:0.04em;margin-top:4px;">In coda</div></td></tr></table><div style="padding:0 6px;"></div></td></tr><tr><td style="padding:22px 28px 0;"><div style="font-size:13px;font-weight:700;color:#374151;text-transform:uppercase;letter-spacing:0.04em;margin-bottom:8px;">Partecipanti confermati (1)</div><table role="presentation" width="100%" cellpadding="0" cellspacing="0" style="background:#f8fafc;border:1px solid #eef0f3;border-radius:10px;"><tr><td style="padding:10px 14px;border-bottom:1px solid #eef0f3;"><table role="presentation" width="100%" cellpadding="0" cellspacing="0"><tr><td width="34" valign="top" style="font-weight:800;color:#1ebf73;font-size:14px;padding-top:1px;">1.</td><td valign="top" style="font-size:15px;color:#1f2937;font-weight:600;">Amelia Benucci<br><span style="font-size:12px;color:#6b7280;font-weight:400;">info@claudiosironi.com</span></td><td valign="top" align="right" width="100"><span style="display:inline-block;background:#e3f2ec;color:#1a7f52;font-size:11px;font-weight:700;padding:3px 10px;border-radius:20px;white-space:nowrap;">Confermata</span></td></tr></table></td></tr></table></td></tr><tr><td style="padding:26px 28px;font-size:12px;color:#9ca3af;text-align:center;">Generato automaticamente da YogiBook il 01/10/2026 alle 11:15</td></tr></table></td></tr></table></body></html>
|
||||
@@ -1 +0,0 @@
|
||||
<!doctype html><html lang="it"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width,initial-scale=1"><title>Hatha Yoga</title></head><body style="margin:0;padding:0;background:#f3f5f7;font-family:-apple-system,Segoe UI,Roboto,Helvetica,Arial,sans-serif;"><table role="presentation" width="100%" cellpadding="0" cellspacing="0" style="background:#f3f5f7;padding:24px 12px;"><tr><td align="center"><table role="presentation" width="600" cellpadding="0" cellspacing="0" style="max-width:600px;width:100%;background:#ffffff;border-radius:14px;overflow:hidden;box-shadow:0 3px 16px rgba(0,0,0,0.06);"><tr><td style="height:8px;background:#fa9b9b;font-size:0;line-height:0;"> </td></tr><tr><td style="padding:26px 28px 6px;"><div style="font-size:12px;font-weight:700;color:#1ebf73;text-transform:uppercase;letter-spacing:0.06em;">YogiBook · Riepilogo classe</div><h1 style="margin:8px 0 6px;font-size:24px;color:#1f2937;">Hatha Yoga</h1><div style="font-size:15px;color:#374151;font-weight:600;">Lunedì 5 Ottobre 2026 · ore 19:30</div><div style="font-size:13px;color:#6b7280;margin-top:4px;">via Valassina 62/B Seregno - Sala Contesto Yoga</div><div style="font-size:13px;color:#6b7280;margin-top:4px;">Insegnante: <strong style="color:#374151;">Francesca -</strong></div></td></tr><tr><td style="padding:16px 22px 0;"><table role="presentation" width="100%" cellpadding="0" cellspacing="6"><tr><td align="center" style="padding:12px 6px;background:#f8fafc;border-radius:10px;"><div style="font-size:22px;font-weight:800;color:#c0392b;line-height:1.1;">1/1</div><div style="font-size:11px;color:#6b7280;text-transform:uppercase;letter-spacing:0.04em;margin-top:4px;">Iscritti</div></td><td align="center" style="padding:12px 6px;background:#f8fafc;border-radius:10px;"><div style="font-size:22px;font-weight:800;color:#374151;line-height:1.1;">0</div><div style="font-size:11px;color:#6b7280;text-transform:uppercase;letter-spacing:0.04em;margin-top:4px;">Posti liberi</div></td><td align="center" style="padding:12px 6px;background:#f8fafc;border-radius:10px;"><div style="font-size:22px;font-weight:800;color:#8a6d00;line-height:1.1;">0</div><div style="font-size:11px;color:#6b7280;text-transform:uppercase;letter-spacing:0.04em;margin-top:4px;">In attesa</div></td><td align="center" style="padding:12px 6px;background:#f8fafc;border-radius:10px;"><div style="font-size:22px;font-weight:800;color:#d1698a;line-height:1.1;">0</div><div style="font-size:11px;color:#6b7280;text-transform:uppercase;letter-spacing:0.04em;margin-top:4px;">In coda</div></td></tr></table><div style="padding:0 6px;"></div></td></tr><tr><td style="padding:22px 28px 0;"><div style="font-size:13px;font-weight:700;color:#374151;text-transform:uppercase;letter-spacing:0.04em;margin-bottom:8px;">Partecipanti confermati (1)</div><table role="presentation" width="100%" cellpadding="0" cellspacing="0" style="background:#f8fafc;border:1px solid #eef0f3;border-radius:10px;"><tr><td style="padding:10px 14px;border-bottom:1px solid #eef0f3;"><table role="presentation" width="100%" cellpadding="0" cellspacing="0"><tr><td width="34" valign="top" style="font-weight:800;color:#1ebf73;font-size:14px;padding-top:1px;">1.</td><td valign="top" style="font-size:15px;color:#1f2937;font-weight:600;">Amelia B.</td><td valign="top" align="right" width="100"><span style="display:inline-block;background:#e3f2ec;color:#1a7f52;font-size:11px;font-weight:700;padding:3px 10px;border-radius:20px;white-space:nowrap;">Confermata</span></td></tr></table></td></tr></table></td></tr><tr><td style="padding:26px 28px;font-size:12px;color:#9ca3af;text-align:center;">Generato automaticamente da YogiBook il 01/10/2026 alle 11:30</td></tr></table></td></tr></table></body></html>
|
||||
@@ -1 +0,0 @@
|
||||
<!doctype html><html lang="it"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width,initial-scale=1"><title>Hatha Yoga</title></head><body style="margin:0;padding:0;background:#f3f5f7;font-family:-apple-system,Segoe UI,Roboto,Helvetica,Arial,sans-serif;"><table role="presentation" width="100%" cellpadding="0" cellspacing="0" style="background:#f3f5f7;padding:24px 12px;"><tr><td align="center"><table role="presentation" width="600" cellpadding="0" cellspacing="0" style="max-width:600px;width:100%;background:#ffffff;border-radius:14px;overflow:hidden;box-shadow:0 3px 16px rgba(0,0,0,0.06);"><tr><td style="height:8px;background:#fa9b9b;font-size:0;line-height:0;"> </td></tr><tr><td style="padding:14px 28px 0;"><div style="background:#f5eee4;color:#5a4630;border-radius:10px;padding:10px 14px;font-size:13px;"><strong>Copia per il titolare</strong> · classe di Francesca -</div></td></tr><tr><td style="padding:26px 28px 6px;"><div style="font-size:12px;font-weight:700;color:#1ebf73;text-transform:uppercase;letter-spacing:0.06em;">YogiBook · Riepilogo classe</div><h1 style="margin:8px 0 6px;font-size:24px;color:#1f2937;">Hatha Yoga</h1><div style="font-size:15px;color:#374151;font-weight:600;">Lunedì 5 Ottobre 2026 · ore 19:30</div><div style="font-size:13px;color:#6b7280;margin-top:4px;">via Valassina 62/B Seregno - Sala Contesto Yoga</div><div style="font-size:13px;color:#6b7280;margin-top:4px;">Insegnante: <strong style="color:#374151;">Francesca -</strong></div></td></tr><tr><td style="padding:16px 22px 0;"><table role="presentation" width="100%" cellpadding="0" cellspacing="6"><tr><td align="center" style="padding:12px 6px;background:#f8fafc;border-radius:10px;"><div style="font-size:22px;font-weight:800;color:#c0392b;line-height:1.1;">1/1</div><div style="font-size:11px;color:#6b7280;text-transform:uppercase;letter-spacing:0.04em;margin-top:4px;">Iscritti</div></td><td align="center" style="padding:12px 6px;background:#f8fafc;border-radius:10px;"><div style="font-size:22px;font-weight:800;color:#374151;line-height:1.1;">0</div><div style="font-size:11px;color:#6b7280;text-transform:uppercase;letter-spacing:0.04em;margin-top:4px;">Posti liberi</div></td><td align="center" style="padding:12px 6px;background:#f8fafc;border-radius:10px;"><div style="font-size:22px;font-weight:800;color:#8a6d00;line-height:1.1;">0</div><div style="font-size:11px;color:#6b7280;text-transform:uppercase;letter-spacing:0.04em;margin-top:4px;">In attesa</div></td><td align="center" style="padding:12px 6px;background:#f8fafc;border-radius:10px;"><div style="font-size:22px;font-weight:800;color:#d1698a;line-height:1.1;">0</div><div style="font-size:11px;color:#6b7280;text-transform:uppercase;letter-spacing:0.04em;margin-top:4px;">In coda</div></td></tr></table><div style="padding:0 6px;"></div></td></tr><tr><td style="padding:22px 28px 0;"><div style="font-size:13px;font-weight:700;color:#374151;text-transform:uppercase;letter-spacing:0.04em;margin-bottom:8px;">Partecipanti confermati (1)</div><table role="presentation" width="100%" cellpadding="0" cellspacing="0" style="background:#f8fafc;border:1px solid #eef0f3;border-radius:10px;"><tr><td style="padding:10px 14px;border-bottom:1px solid #eef0f3;"><table role="presentation" width="100%" cellpadding="0" cellspacing="0"><tr><td width="34" valign="top" style="font-weight:800;color:#1ebf73;font-size:14px;padding-top:1px;">1.</td><td valign="top" style="font-size:15px;color:#1f2937;font-weight:600;">Amelia Benucci<br><span style="font-size:12px;color:#6b7280;font-weight:400;">info@claudiosironi.com</span></td><td valign="top" align="right" width="100"><span style="display:inline-block;background:#e3f2ec;color:#1a7f52;font-size:11px;font-weight:700;padding:3px 10px;border-radius:20px;white-space:nowrap;">Confermata</span></td></tr></table></td></tr></table></td></tr><tr><td style="padding:26px 28px;font-size:12px;color:#9ca3af;text-align:center;">Generato automaticamente da YogiBook il 01/10/2026 alle 11:30</td></tr></table></td></tr></table></body></html>
|
||||
@@ -1 +0,0 @@
|
||||
<!doctype html><html lang="it"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width,initial-scale=1"><title>Aerial Yoga - mix</title></head><body style="margin:0;padding:0;background:#f3f5f7;font-family:-apple-system,Segoe UI,Roboto,Helvetica,Arial,sans-serif;"><table role="presentation" width="100%" cellpadding="0" cellspacing="0" style="background:#f3f5f7;padding:24px 12px;"><tr><td align="center"><table role="presentation" width="600" cellpadding="0" cellspacing="0" style="max-width:600px;width:100%;background:#ffffff;border-radius:14px;overflow:hidden;box-shadow:0 3px 16px rgba(0,0,0,0.06);"><tr><td style="height:8px;background:#6ED4E4;font-size:0;line-height:0;"> </td></tr><tr><td style="padding:26px 28px 6px;"><div style="font-size:12px;font-weight:700;color:#1ebf73;text-transform:uppercase;letter-spacing:0.06em;">YogiBook · Riepilogo classe</div><h1 style="margin:8px 0 6px;font-size:24px;color:#1f2937;">Aerial Yoga - mix</h1><div style="font-size:15px;color:#374151;font-weight:600;">Giovedì 24 Settembre 2026 · ore 19:00</div><div style="font-size:13px;color:#6b7280;margin-top:4px;">via Valassina 62/B Seregno - Sala Contesto Yoga</div></td></tr><tr><td style="padding:16px 22px 0;"><table role="presentation" width="100%" cellpadding="0" cellspacing="6"><tr><td align="center" style="padding:12px 6px;background:#f8fafc;border-radius:10px;"><div style="font-size:22px;font-weight:800;color:#1a7f52;line-height:1.1;">2/8</div><div style="font-size:11px;color:#6b7280;text-transform:uppercase;letter-spacing:0.04em;margin-top:4px;">Iscritti</div></td><td align="center" style="padding:12px 6px;background:#f8fafc;border-radius:10px;"><div style="font-size:22px;font-weight:800;color:#374151;line-height:1.1;">6</div><div style="font-size:11px;color:#6b7280;text-transform:uppercase;letter-spacing:0.04em;margin-top:4px;">Posti liberi</div></td><td align="center" style="padding:12px 6px;background:#f8fafc;border-radius:10px;"><div style="font-size:22px;font-weight:800;color:#8a6d00;line-height:1.1;">0</div><div style="font-size:11px;color:#6b7280;text-transform:uppercase;letter-spacing:0.04em;margin-top:4px;">In attesa</div></td><td align="center" style="padding:12px 6px;background:#f8fafc;border-radius:10px;"><div style="font-size:22px;font-weight:800;color:#d1698a;line-height:1.1;">0</div><div style="font-size:11px;color:#6b7280;text-transform:uppercase;letter-spacing:0.04em;margin-top:4px;">In coda</div></td></tr></table><div style="padding:0 6px;"></div></td></tr><tr><td style="padding:22px 28px 0;"><div style="font-size:13px;font-weight:700;color:#374151;text-transform:uppercase;letter-spacing:0.04em;margin-bottom:8px;">Partecipanti confermati (2)</div><table role="presentation" width="100%" cellpadding="0" cellspacing="0" style="background:#f8fafc;border:1px solid #eef0f3;border-radius:10px;"><tr><td style="padding:10px 14px;border-bottom:1px solid #eef0f3;"><table role="presentation" width="100%" cellpadding="0" cellspacing="0"><tr><td width="34" valign="top" style="font-weight:800;color:#1ebf73;font-size:14px;padding-top:1px;">1.</td><td valign="top" style="font-size:15px;color:#1f2937;font-weight:600;">Amelia Benucci<br><span style="font-size:12px;color:#6b7280;font-weight:400;">info@claudiosironi.com</span></td><td valign="top" align="right" width="100"><span style="display:inline-block;background:#e3f2ec;color:#1a7f52;font-size:11px;font-weight:700;padding:3px 10px;border-radius:20px;white-space:nowrap;">Confermata</span></td></tr></table></td></tr><tr><td style="padding:10px 14px;border-bottom:1px solid #eef0f3;"><table role="presentation" width="100%" cellpadding="0" cellspacing="0"><tr><td width="34" valign="top" style="font-weight:800;color:#1ebf73;font-size:14px;padding-top:1px;">2.</td><td valign="top" style="font-size:15px;color:#1f2937;font-weight:600;">Aurora Masiero<br><span style="font-size:12px;color:#6b7280;font-weight:400;">info@yogasoul.it</span></td><td valign="top" align="right" width="100"><span style="display:inline-block;background:#e3f2ec;color:#1a7f52;font-size:11px;font-weight:700;padding:3px 10px;border-radius:20px;white-space:nowrap;">Confermata</span></td></tr></table></td></tr></table></td></tr><tr><td style="padding:26px 28px;font-size:12px;color:#9ca3af;text-align:center;">Generato automaticamente da YogiBook il 24/09/2026 alle 10:55</td></tr></table></td></tr></table></body></html>
|
||||
@@ -0,0 +1,51 @@
|
||||
<?php
|
||||
|
||||
use Phinx\Migration\AbstractMigration;
|
||||
|
||||
/**
|
||||
* Token dei dispositivi per le notifiche push (Firebase Cloud Messaging).
|
||||
* Un utente puo' avere piu' dispositivi, quindi piu' token.
|
||||
*/
|
||||
final class CreateUserdevicetokenTable extends AbstractMigration
|
||||
{
|
||||
public function change(): void
|
||||
{
|
||||
$this->table('userdevicetoken', ['id' => 'iduserdevicetoken'])
|
||||
->addColumn('iduser', 'integer', [
|
||||
'null' => false,
|
||||
'comment' => 'auth_users.id',
|
||||
])
|
||||
->addColumn('devicetoken', 'string', [
|
||||
'limit' => 255,
|
||||
'null' => false,
|
||||
'comment' => 'Token FCM del dispositivo',
|
||||
])
|
||||
->addColumn('platform', 'string', [
|
||||
'limit' => 20,
|
||||
'null' => false,
|
||||
'default' => 'android',
|
||||
'comment' => 'android / ios',
|
||||
])
|
||||
->addColumn('appversion', 'string', [
|
||||
'limit' => 20,
|
||||
'null' => true,
|
||||
])
|
||||
->addColumn('active', 'char', [
|
||||
'limit' => 1,
|
||||
'null' => false,
|
||||
'default' => 'Y',
|
||||
'comment' => 'N quando FCM segnala il token come non valido',
|
||||
])
|
||||
->addColumn('created_at', 'datetime', [
|
||||
'default' => 'CURRENT_TIMESTAMP',
|
||||
'null' => false,
|
||||
])
|
||||
->addColumn('lastseen_at', 'datetime', [
|
||||
'null' => true,
|
||||
'comment' => 'Ultima volta che l\'app ha registrato questo token',
|
||||
])
|
||||
->addIndex(['devicetoken'], ['unique' => true, 'name' => 'uq_userdevicetoken_token'])
|
||||
->addIndex(['iduser', 'active'], ['name' => 'idx_userdevicetoken_user'])
|
||||
->create();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,88 @@
|
||||
<?php
|
||||
|
||||
use Phinx\Migration\AbstractMigration;
|
||||
|
||||
final class CreateNotificationsettingTable extends AbstractMigration
|
||||
{
|
||||
public function change(): void
|
||||
{
|
||||
$this->table('notificationsetting', ['id' => 'idnotificationsetting'])
|
||||
->addColumn('notificationtype', 'string', [
|
||||
'limit' => 30,
|
||||
'null' => false,
|
||||
'comment' => 'lesson / order / certificate',
|
||||
])
|
||||
->addColumn('daysbefore', 'integer', [
|
||||
'null' => false,
|
||||
'default' => 0,
|
||||
'comment' => 'Giorni di anticipo; 0 = il giorno stesso',
|
||||
])
|
||||
->addColumn('sendhour', 'string', [
|
||||
'limit' => 5,
|
||||
'null' => false,
|
||||
'default' => '08:00',
|
||||
'comment' => 'Ora di invio del cron (HH:MM)',
|
||||
])
|
||||
->addColumn('active', 'char', [
|
||||
'limit' => 1,
|
||||
'null' => false,
|
||||
'default' => 'Y',
|
||||
])
|
||||
->addColumn('title', 'string', [
|
||||
'limit' => 150,
|
||||
'null' => false,
|
||||
])
|
||||
->addColumn('body', 'text', [
|
||||
'null' => false,
|
||||
])
|
||||
->addIndex(
|
||||
['notificationtype', 'daysbefore'],
|
||||
['unique' => true, 'name' => 'uq_notificationsetting_type']
|
||||
)
|
||||
->insert([
|
||||
[
|
||||
'notificationtype' => 'lesson',
|
||||
'daysbefore' => 0,
|
||||
'sendhour' => '08:00',
|
||||
'active' => 'Y',
|
||||
'title' => 'La tua lezione di oggi',
|
||||
'body' => 'Ciao {first_name}, oggi hai {servicename} alle {time}. Ti aspettiamo!',
|
||||
],
|
||||
[
|
||||
'notificationtype' => 'order',
|
||||
'daysbefore' => 5,
|
||||
'sendhour' => '08:00',
|
||||
'active' => 'Y',
|
||||
'title' => 'Il tuo abbonamento sta per scadere',
|
||||
'body' => 'Ciao {first_name}, il tuo abbonamento scade il {expiredate}. '
|
||||
. 'Ricordati di prenotare le lezioni rimaste.',
|
||||
],
|
||||
[
|
||||
'notificationtype' => 'order',
|
||||
'daysbefore' => 0,
|
||||
'sendhour' => '08:00',
|
||||
'active' => 'Y',
|
||||
'title' => 'Il tuo abbonamento scade oggi',
|
||||
'body' => 'Ciao {first_name}, oggi e\' l\'ultimo giorno del tuo abbonamento.',
|
||||
],
|
||||
[
|
||||
'notificationtype' => 'certificate',
|
||||
'daysbefore' => 7,
|
||||
'sendhour' => '08:00',
|
||||
'active' => 'Y',
|
||||
'title' => 'Certificato medico in scadenza',
|
||||
'body' => 'Ciao {first_name}, il tuo certificato medico scade il {expiredate}.',
|
||||
],
|
||||
[
|
||||
'notificationtype' => 'certificate',
|
||||
'daysbefore' => 5,
|
||||
'sendhour' => '08:00',
|
||||
'active' => 'Y',
|
||||
'title' => 'Certificato medico in scadenza',
|
||||
'body' => 'Ciao {first_name}, mancano pochi giorni: il tuo certificato medico '
|
||||
. 'scade il {expiredate}.',
|
||||
],
|
||||
])
|
||||
->create();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,53 @@
|
||||
<?php
|
||||
|
||||
use Phinx\Migration\AbstractMigration;
|
||||
|
||||
final class CreateNotificationlogTable extends AbstractMigration
|
||||
{
|
||||
public function change(): void
|
||||
{
|
||||
$this->table('notificationlog', ['id' => 'idnotificationlog'])
|
||||
->addColumn('iduser', 'integer', [
|
||||
'null' => false,
|
||||
'comment' => 'auth_users.id',
|
||||
])
|
||||
->addColumn('notificationtype', 'string', [
|
||||
'limit' => 30,
|
||||
'null' => false,
|
||||
'comment' => 'lesson / order / certificate',
|
||||
])
|
||||
->addColumn('idreference', 'integer', [
|
||||
'null' => false,
|
||||
'comment' => 'Id della lezione, ordine o certificato',
|
||||
])
|
||||
->addColumn('daysbefore', 'integer', [
|
||||
'null' => false,
|
||||
'default' => 0,
|
||||
])
|
||||
->addColumn('sent_at', 'datetime', [
|
||||
'default' => 'CURRENT_TIMESTAMP',
|
||||
'null' => false,
|
||||
])
|
||||
->addColumn('status', 'string', [
|
||||
'limit' => 20,
|
||||
'null' => false,
|
||||
'default' => 'sent',
|
||||
'comment' => 'sent / failed',
|
||||
])
|
||||
->addColumn('devicecount', 'integer', [
|
||||
'null' => false,
|
||||
'default' => 0,
|
||||
'comment' => 'A quanti dispositivi e stata inviata',
|
||||
])
|
||||
->addColumn('errormessage', 'string', [
|
||||
'limit' => 255,
|
||||
'null' => true,
|
||||
])
|
||||
->addIndex(
|
||||
['iduser', 'notificationtype', 'idreference', 'daysbefore'],
|
||||
['unique' => true, 'name' => 'uq_notificationlog_invio']
|
||||
)
|
||||
->addIndex(['sent_at'], ['name' => 'idx_notificationlog_data'])
|
||||
->create();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
<?php
|
||||
|
||||
use Phinx\Migration\AbstractMigration;
|
||||
|
||||
final class AddMultiTextsToNotificationsetting extends AbstractMigration
|
||||
{
|
||||
public function up(): void
|
||||
{
|
||||
$this->table('notificationsetting')
|
||||
->addColumn('title_multi', 'string', [
|
||||
'limit' => 150,
|
||||
'null' => true,
|
||||
'after' => 'title',
|
||||
'comment' => 'Titolo usato quando la notifica raggruppa piu elementi',
|
||||
])
|
||||
->addColumn('body_multi', 'text', [
|
||||
'null' => true,
|
||||
'after' => 'body',
|
||||
'comment' => 'Testo usato quando la notifica raggruppa piu elementi',
|
||||
])
|
||||
->update();
|
||||
|
||||
$this->execute("
|
||||
UPDATE notificationsetting
|
||||
SET title_multi = 'Le tue lezioni di oggi',
|
||||
body_multi = 'Ciao {first_name}, oggi hai {count} lezioni: {lessons}. Ti aspettiamo!'
|
||||
WHERE notificationtype = 'lesson'
|
||||
");
|
||||
}
|
||||
|
||||
public function down(): void
|
||||
{
|
||||
$this->table('notificationsetting')
|
||||
->removeColumn('title_multi')
|
||||
->removeColumn('body_multi')
|
||||
->update();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
<?php
|
||||
|
||||
use Phinx\Migration\AbstractMigration;
|
||||
|
||||
final class AddMultiTextsDefaults extends AbstractMigration
|
||||
{
|
||||
public function up(): void
|
||||
{
|
||||
$this->execute("
|
||||
UPDATE notificationsetting
|
||||
SET title_multi = 'I tuoi abbonamenti in scadenza',
|
||||
body_multi = 'Ciao {first_name}, hai {count} abbonamenti in scadenza il {expiredate}: {orders}.'
|
||||
WHERE notificationtype = 'order' AND daysbefore > 0
|
||||
");
|
||||
|
||||
$this->execute("
|
||||
UPDATE notificationsetting
|
||||
SET title_multi = 'I tuoi abbonamenti scadono oggi',
|
||||
body_multi = 'Ciao {first_name}, oggi scadono {count} dei tuoi abbonamenti: {orders}.'
|
||||
WHERE notificationtype = 'order' AND daysbefore = 0
|
||||
");
|
||||
|
||||
$this->execute("
|
||||
UPDATE notificationsetting
|
||||
SET title_multi = 'Certificati medici in scadenza',
|
||||
body_multi = 'Ciao {first_name}, hai {count} certificati in scadenza il {expiredate}: {documents}.'
|
||||
WHERE notificationtype = 'certificate'
|
||||
");
|
||||
}
|
||||
|
||||
public function down(): void
|
||||
{
|
||||
$this->execute("
|
||||
UPDATE notificationsetting
|
||||
SET title_multi = NULL, body_multi = NULL
|
||||
WHERE notificationtype IN ('order', 'certificate')
|
||||
");
|
||||
}
|
||||
}
|
||||
@@ -1,49 +0,0 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
use Phinx\Migration\AbstractMigration;
|
||||
|
||||
/**
|
||||
* Converte orderbook.quantityclass da varchar(20) a INT.
|
||||
*
|
||||
* quantityclass rappresenta il numero di ticket acquistati: viene usato in
|
||||
* confronti e aritmetica (offset, LIMIT, conteggi). Tenerlo come stringa
|
||||
* causa confronti errati ("10" < "9") e comportamenti imprevisti.
|
||||
*
|
||||
* PRIMA di cambiare il tipo, bonifica i valori esistenti: elimina spazi e
|
||||
* azzera i valori non numerici / vuoti, altrimenti la conversione li
|
||||
* troncherebbe in modo silenzioso.
|
||||
*/
|
||||
final class ConvertQuantityclassToInt extends AbstractMigration
|
||||
{
|
||||
public function up(): void
|
||||
{
|
||||
// 1) Bonifica: rimuovi spazi ai bordi
|
||||
$this->execute("UPDATE orderbook SET quantityclass = TRIM(quantityclass) WHERE quantityclass IS NOT NULL");
|
||||
|
||||
// 2) Bonifica: i valori non interamente numerici o vuoti diventano 0
|
||||
// (REGEXP '^[0-9]+$' = solo cifre). Rivedi manualmente eventuali 0
|
||||
// risultanti dopo la migration se non te li aspetti.
|
||||
$this->execute("UPDATE orderbook SET quantityclass = '0' WHERE quantityclass IS NULL OR quantityclass = '' OR quantityclass NOT REGEXP '^[0-9]+$'");
|
||||
|
||||
// 3) Cambia il tipo di colonna a INT
|
||||
$table = $this->table('orderbook');
|
||||
$table->changeColumn('quantityclass', 'integer', [
|
||||
'null' => true,
|
||||
'default' => null,
|
||||
'signed' => true,
|
||||
])->update();
|
||||
}
|
||||
|
||||
public function down(): void
|
||||
{
|
||||
// Ripristina varchar(20). I valori numerici restano validi come stringa.
|
||||
$table = $this->table('orderbook');
|
||||
$table->changeColumn('quantityclass', 'string', [
|
||||
'limit' => 20,
|
||||
'null' => true,
|
||||
'default' => null,
|
||||
])->update();
|
||||
}
|
||||
}
|
||||
@@ -1,47 +0,0 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
use Phinx\Migration\AbstractMigration;
|
||||
|
||||
/**
|
||||
* Aggiunge orderbook.is_openflexy CHAR(1) DEFAULT 'N'.
|
||||
*
|
||||
* Marca esplicitamente un ordine come carnet OpenFlexy (biglietti liberi,
|
||||
* nessuna propagazione). Sostituisce il riconoscimento fragile basato sul
|
||||
* nome del servizio (service.servicename = 'OpenFlexy'), che si rompe se
|
||||
* qualcuno rinomina il servizio dal pannello.
|
||||
*
|
||||
* Dopo questa migration puoi popolare il flag sugli ordini OpenFlexy già
|
||||
* esistenti (vedi nota nel metodo up) e poi aggiornare propagatesingleorder.php
|
||||
* per leggere il flag invece del nome.
|
||||
*/
|
||||
final class AddIsOpenflexyToOrderbook extends AbstractMigration
|
||||
{
|
||||
public function up(): void
|
||||
{
|
||||
$table = $this->table('orderbook');
|
||||
$table->addColumn('is_openflexy', 'char', [
|
||||
'limit' => 1,
|
||||
'null' => false,
|
||||
'default' => 'N',
|
||||
'after' => 'idservice',
|
||||
])->update();
|
||||
|
||||
// Popola il flag sugli ordini già collegati alla classe OpenFlexy
|
||||
// esistente (riconosciuta per nome, una tantum). Usa lower() per
|
||||
// sicurezza sul confronto.
|
||||
$this->execute(
|
||||
"UPDATE orderbook o
|
||||
JOIN service s ON s.idservice = o.idservice
|
||||
SET o.is_openflexy = 'Y'
|
||||
WHERE LOWER(TRIM(s.servicename)) = 'openflexy'"
|
||||
);
|
||||
}
|
||||
|
||||
public function down(): void
|
||||
{
|
||||
$table = $this->table('orderbook');
|
||||
$table->removeColumn('is_openflexy')->update();
|
||||
}
|
||||
}
|
||||
@@ -1,44 +0,0 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
use Phinx\Migration\AbstractMigration;
|
||||
|
||||
/**
|
||||
* Aggiunge la foreign key bookingclass.idorder -> orderbook.idorderbook.
|
||||
*
|
||||
* Con ON DELETE SET NULL: cancellare un ordine NON cancella le prenotazioni
|
||||
* collegate, ma ne slega il riferimento (idorder = NULL). Questo preserva la
|
||||
* storia delle prenotazioni ed evita errori di vincolo alla cancellazione.
|
||||
*
|
||||
* IMPORTANTE: se esistono righe in bookingclass con un idorder che non
|
||||
* corrisponde a nessun orderbook (dati orfani), la creazione della FK
|
||||
* fallisce. Il metodo up() bonifica prima questi orfani portandoli a NULL.
|
||||
*/
|
||||
final class AddForeignKeyBookingclassOrder extends AbstractMigration
|
||||
{
|
||||
public function up(): void
|
||||
{
|
||||
// 1) Bonifica orfani: idorder che non esiste in orderbook -> NULL
|
||||
$this->execute(
|
||||
"UPDATE bookingclass b
|
||||
LEFT JOIN orderbook o ON o.idorderbook = b.idorder
|
||||
SET b.idorder = NULL
|
||||
WHERE b.idorder IS NOT NULL AND o.idorderbook IS NULL"
|
||||
);
|
||||
|
||||
// 2) Crea la foreign key
|
||||
$table = $this->table('bookingclass');
|
||||
$table->addForeignKey('idorder', 'orderbook', 'idorderbook', [
|
||||
'delete' => 'SET_NULL',
|
||||
'update' => 'NO_ACTION',
|
||||
'constraint' => 'fk_bookingclass_orderbook',
|
||||
])->update();
|
||||
}
|
||||
|
||||
public function down(): void
|
||||
{
|
||||
$table = $this->table('bookingclass');
|
||||
$table->dropForeignKey('idorder', null, ['constraint' => 'fk_bookingclass_orderbook'])->update();
|
||||
}
|
||||
}
|
||||
@@ -1,35 +0,0 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
use Phinx\Migration\AbstractMigration;
|
||||
|
||||
/**
|
||||
* Aggiunge la colonna is_gift a bookingclass.
|
||||
*
|
||||
* is_gift = 'Y' indica una lezione OMAGGIO inserita dall'insegnante:
|
||||
* - non consuma ticket dell'ordine (esclusa dai conteggi residui)
|
||||
* - non è riprogrammabile (legata alla data della classe)
|
||||
* - tipicamente ha idorder = NULL
|
||||
*
|
||||
* Default 'N' = prenotazione normale.
|
||||
*/
|
||||
final class AddIsGiftToBookingclass extends AbstractMigration
|
||||
{
|
||||
public function up(): void
|
||||
{
|
||||
$table = $this->table('bookingclass');
|
||||
$table->addColumn('is_gift', 'char', [
|
||||
'limit' => 1,
|
||||
'null' => false,
|
||||
'default' => 'N',
|
||||
'after' => 'is_reprogrammed',
|
||||
])->update();
|
||||
}
|
||||
|
||||
public function down(): void
|
||||
{
|
||||
$table = $this->table('bookingclass');
|
||||
$table->removeColumn('is_gift')->update();
|
||||
}
|
||||
}
|
||||
@@ -1,30 +0,0 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
use Phinx\Migration\AbstractMigration;
|
||||
|
||||
final class AddPropagationTracking extends AbstractMigration
|
||||
{
|
||||
public function change(): void
|
||||
{
|
||||
// Tabella che raggruppa ogni propagazione
|
||||
$table = $this->table('propagation', ['id' => 'idpropagation']);
|
||||
$table->addColumn('idservice', 'integer')
|
||||
->addColumn('token', 'string', ['limit' => 64])
|
||||
->addColumn('startdate', 'date', ['null' => true])
|
||||
->addColumn('enddate', 'date', ['null' => true])
|
||||
->addColumn('created_at', 'datetime', ['default' => 'CURRENT_TIMESTAMP'])
|
||||
->addIndex(['token'], ['unique' => true])
|
||||
->addIndex(['idservice'])
|
||||
->create();
|
||||
|
||||
// Campo token sulle singole occorrenze del calendario
|
||||
$schedule = $this->table('serviceschedule');
|
||||
if (!$schedule->hasColumn('propagation_token')) {
|
||||
$schedule->addColumn('propagation_token', 'string', ['limit' => 64, 'null' => true])
|
||||
->addIndex(['propagation_token'])
|
||||
->update();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,22 +0,0 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
use Phinx\Migration\AbstractMigration;
|
||||
|
||||
final class FixPropagationCollation extends AbstractMigration
|
||||
{
|
||||
public function up(): void
|
||||
{
|
||||
$this->execute(
|
||||
"ALTER TABLE propagation CONVERT TO CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci"
|
||||
);
|
||||
}
|
||||
|
||||
public function down(): void
|
||||
{
|
||||
$this->execute(
|
||||
"ALTER TABLE propagation CONVERT TO CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci"
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -1,20 +0,0 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
use Phinx\Migration\AbstractMigration;
|
||||
|
||||
final class AddWaitingListSupport extends AbstractMigration
|
||||
{
|
||||
public function change(): void
|
||||
{
|
||||
$table = $this->table('bookingclass');
|
||||
$table
|
||||
->addColumn('created_at', 'timestamp', [
|
||||
'default' => 'CURRENT_TIMESTAMP',
|
||||
'null' => false,
|
||||
'after' => 'cancellation_token',
|
||||
])
|
||||
->update();
|
||||
}
|
||||
}
|
||||
@@ -1,20 +0,0 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
use Phinx\Migration\AbstractMigration;
|
||||
|
||||
final class AddWaitingListEnabledToOption extends AbstractMigration
|
||||
{
|
||||
public function change(): void
|
||||
{
|
||||
$this->table('option')
|
||||
->addColumn('waitinglist_enabled', 'char', [
|
||||
'limit' => 1,
|
||||
'default' => 'N',
|
||||
'null' => false,
|
||||
'after' => 'maxbeforetimecancell',
|
||||
])
|
||||
->update();
|
||||
}
|
||||
}
|
||||
@@ -1,51 +0,0 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
use Phinx\Migration\AbstractMigration;
|
||||
use Phinx\Db\Adapter\MysqlAdapter;
|
||||
|
||||
final class CreateEventsTable extends AbstractMigration
|
||||
{
|
||||
public function change(): void
|
||||
{
|
||||
$table = $this->table('events', [
|
||||
'id' => false,
|
||||
'primary_key' => ['id'],
|
||||
'engine' => 'InnoDB',
|
||||
'encoding' => 'utf8mb4',
|
||||
'collation' => 'utf8mb4_unicode_ci',
|
||||
]);
|
||||
|
||||
$table
|
||||
->addColumn('id', 'biginteger', ['identity' => true, 'signed' => false])
|
||||
->addColumn('user_id', 'integer', ['signed' => false, 'null' => true, 'comment' => 'insegnante/creatore -> auth_users.id'])
|
||||
->addColumn('title', 'string', ['limit' => 191, 'null' => false])
|
||||
->addColumn('slug', 'string', ['limit' => 191, 'null' => false, 'comment' => 'URL pubblico / widget'])
|
||||
->addColumn('description', 'text', ['limit' => MysqlAdapter::TEXT_LONG, 'null' => true, 'comment' => 'HTML editor'])
|
||||
->addColumn('organizer_name', 'string', ['limit' => 191, 'null' => true, 'comment' => 'nome libero; se null usa il creatore'])
|
||||
->addColumn('starts_at', 'datetime', ['null' => false])
|
||||
->addColumn('ends_at', 'datetime', ['null' => true])
|
||||
->addColumn('address', 'string', ['limit' => 255, 'null' => true, 'comment' => 'testo per Google Maps'])
|
||||
->addColumn('lat', 'decimal', ['precision' => 10, 'scale' => 7, 'null' => true])
|
||||
->addColumn('lng', 'decimal', ['precision' => 10, 'scale' => 7, 'null' => true])
|
||||
->addColumn('cost', 'decimal', ['precision' => 8, 'scale' => 2, 'null' => false, 'default' => 0])
|
||||
->addColumn('currency', 'string', ['limit' => 3, 'null' => false, 'default' => 'EUR'])
|
||||
->addColumn('max_seats', 'integer', ['signed' => false, 'null' => false, 'default' => 0])
|
||||
->addColumn('max_per_booking', 'integer', ['signed' => false, 'null' => false, 'default' => 1])
|
||||
->addColumn('color', 'string', ['limit' => 7, 'null' => false, 'default' => '#4CAF50', 'comment' => 'hex card'])
|
||||
->addColumn('cover_image', 'string', ['limit' => 191, 'null' => true, 'comment' => 'gallery in futuro'])
|
||||
->addColumn('status', 'string', ['limit' => 20, 'null' => false, 'default' => 'draft', 'comment' => 'draft|published|cancelled'])
|
||||
->addColumn('created_at', 'timestamp', ['null' => true, 'default' => null])
|
||||
->addColumn('updated_at', 'timestamp', ['null' => true, 'default' => null])
|
||||
->addIndex(['slug'], ['unique' => true, 'name' => 'events_slug_unique'])
|
||||
->addIndex(['status', 'starts_at'], ['name' => 'events_status_starts_at_index'])
|
||||
->addIndex(['user_id'], ['name' => 'events_user_id_index'])
|
||||
->addForeignKey('user_id', 'auth_users', 'id', [
|
||||
'delete' => 'SET_NULL',
|
||||
'update' => 'NO_ACTION',
|
||||
'constraint' => 'events_user_id_foreign',
|
||||
])
|
||||
->create();
|
||||
}
|
||||
}
|
||||
@@ -1,50 +0,0 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
use Phinx\Migration\AbstractMigration;
|
||||
|
||||
final class CreateEventBookingsTable extends AbstractMigration
|
||||
{
|
||||
public function change(): void
|
||||
{
|
||||
$table = $this->table('event_bookings', [
|
||||
'id' => false,
|
||||
'primary_key' => ['id'],
|
||||
'engine' => 'InnoDB',
|
||||
'encoding' => 'utf8mb4',
|
||||
'collation' => 'utf8mb4_unicode_ci',
|
||||
]);
|
||||
|
||||
$table
|
||||
->addColumn('id', 'biginteger', ['identity' => true, 'signed' => false])
|
||||
->addColumn('event_id', 'biginteger', ['signed' => false, 'null' => false])
|
||||
->addColumn('user_id', 'integer', ['signed' => false, 'null' => true, 'comment' => 'null = ospite non registrato'])
|
||||
->addColumn('name', 'string', ['limit' => 191, 'null' => false])
|
||||
->addColumn('email', 'string', ['limit' => 191, 'null' => false, 'comment' => 'raccolta contatti'])
|
||||
->addColumn('phone', 'string', ['limit' => 40, 'null' => true])
|
||||
->addColumn('seats', 'integer', ['signed' => false, 'null' => false, 'default' => 1])
|
||||
->addColumn('status', 'string', ['limit' => 20, 'null' => false, 'default' => 'pending', 'comment' => 'pending|confirmed|cancelled'])
|
||||
->addColumn('amount', 'decimal', ['precision' => 8, 'scale' => 2, 'null' => true, 'comment' => 'pronto per pagamenti'])
|
||||
->addColumn('token', 'string', ['limit' => 64, 'null' => false, 'comment' => 'gestione/annullo ospite via link email'])
|
||||
->addColumn('consent_at', 'datetime', ['null' => true, 'comment' => 'accettazione privacy/termini'])
|
||||
->addColumn('marketing_opt_in', 'char', ['limit' => 1, 'null' => false, 'default' => 'N', 'comment' => 'consenso marketing Y/N'])
|
||||
->addColumn('created_at', 'timestamp', ['null' => true, 'default' => null])
|
||||
->addColumn('updated_at', 'timestamp', ['null' => true, 'default' => null])
|
||||
->addIndex(['token'], ['unique' => true, 'name' => 'event_bookings_token_unique'])
|
||||
->addIndex(['event_id'], ['name' => 'event_bookings_event_id_index'])
|
||||
->addIndex(['email'], ['name' => 'event_bookings_email_index'])
|
||||
->addIndex(['user_id'], ['name' => 'event_bookings_user_id_index'])
|
||||
->addForeignKey('event_id', 'events', 'id', [
|
||||
'delete' => 'CASCADE',
|
||||
'update' => 'NO_ACTION',
|
||||
'constraint' => 'event_bookings_event_id_foreign',
|
||||
])
|
||||
->addForeignKey('user_id', 'auth_users', 'id', [
|
||||
'delete' => 'SET_NULL',
|
||||
'update' => 'NO_ACTION',
|
||||
'constraint' => 'event_bookings_user_id_foreign',
|
||||
])
|
||||
->create();
|
||||
}
|
||||
}
|
||||
@@ -1,18 +0,0 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
use Phinx\Migration\AbstractMigration;
|
||||
|
||||
final class AddEventDefaultsToOptionTable extends AbstractMigration
|
||||
{
|
||||
public function change(): void
|
||||
{
|
||||
$this->table('option')
|
||||
->addColumn('event_default_color', 'string', ['limit' => 7, 'null' => true, 'default' => '#4CAF50', 'after' => 'colorcancelled'])
|
||||
->addColumn('event_default_max_per_booking', 'integer', ['null' => false, 'default' => 1, 'after' => 'event_default_color'])
|
||||
->addColumn('event_notify_email', 'string', ['limit' => 191, 'null' => true, 'after' => 'event_default_max_per_booking'])
|
||||
->addColumn('event_terms_text', 'text', ['null' => true, 'after' => 'event_notify_email'])
|
||||
->update();
|
||||
}
|
||||
}
|
||||
@@ -1,42 +0,0 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
use Phinx\Migration\AbstractMigration;
|
||||
|
||||
final class CreateEventLocationsTable extends AbstractMigration
|
||||
{
|
||||
public function change(): void
|
||||
{
|
||||
$table = $this->table('event_locations', [
|
||||
'id' => false,
|
||||
'primary_key' => ['id'],
|
||||
'engine' => 'InnoDB',
|
||||
'encoding' => 'utf8mb4',
|
||||
'collation' => 'utf8mb4_unicode_ci',
|
||||
]);
|
||||
|
||||
$table
|
||||
->addColumn('id', 'biginteger', ['identity' => true, 'signed' => false])
|
||||
->addColumn('name', 'string', ['limit' => 191, 'null' => false, 'comment' => 'etichetta sede, es. "Studio YogaSoul"'])
|
||||
->addColumn('address', 'string', ['limit' => 255, 'null' => false])
|
||||
->addColumn('lat', 'decimal', ['precision' => 10, 'scale' => 7, 'null' => true])
|
||||
->addColumn('lng', 'decimal', ['precision' => 10, 'scale' => 7, 'null' => true])
|
||||
->addColumn('is_default', 'char', ['limit' => 1, 'null' => false, 'default' => 'N', 'comment' => 'Y = preselezionata'])
|
||||
->addColumn('created_at', 'timestamp', ['null' => true, 'default' => null])
|
||||
->addColumn('updated_at', 'timestamp', ['null' => true, 'default' => null])
|
||||
->addIndex(['is_default'], ['name' => 'event_locations_is_default_index'])
|
||||
->create();
|
||||
|
||||
// Sede di default (MODIFICA con indirizzo e coordinate reali della scuola)
|
||||
$this->table('event_locations')->insert([
|
||||
'name' => 'Studio YogaSoul',
|
||||
'address' => 'Indirizzo da compilare',
|
||||
'lat' => null,
|
||||
'lng' => null,
|
||||
'is_default' => 'Y',
|
||||
'created_at' => date('Y-m-d H:i:s'),
|
||||
'updated_at' => date('Y-m-d H:i:s'),
|
||||
])->saveData();
|
||||
}
|
||||
}
|
||||
@@ -1,18 +0,0 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
use Phinx\Migration\AbstractMigration;
|
||||
|
||||
final class AddDetailsAndGalleryToEvents extends AbstractMigration
|
||||
{
|
||||
public function change(): void
|
||||
{
|
||||
$this->table('events')
|
||||
->addColumn('instructions', 'text', ['null' => true, 'after' => 'description'])
|
||||
->addColumn('what_to_bring', 'text', ['null' => true, 'after' => 'instructions'])
|
||||
->addColumn('suitable_for', 'text', ['null' => true, 'after' => 'what_to_bring'])
|
||||
->addColumn('gallery', 'text', ['null' => true, 'comment' => 'JSON: array di path immagini', 'after' => 'suitable_for'])
|
||||
->update();
|
||||
}
|
||||
}
|
||||
@@ -1,21 +0,0 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
use Phinx\Migration\AbstractMigration;
|
||||
|
||||
final class AddWaitlistToEvents extends AbstractMigration
|
||||
{
|
||||
public function change(): void
|
||||
{
|
||||
$this->table('events')
|
||||
->addColumn('waitlist_enabled', 'char', [
|
||||
'limit' => 1,
|
||||
'null' => false,
|
||||
'default' => 'Y',
|
||||
'comment' => "Y = lista d'attesa quando pieno",
|
||||
'after' => 'max_per_booking'
|
||||
])
|
||||
->update();
|
||||
}
|
||||
}
|
||||
@@ -1,25 +0,0 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
use Phinx\Migration\AbstractMigration;
|
||||
|
||||
final class AddEventEmailOptions extends AbstractMigration
|
||||
{
|
||||
public function change(): void
|
||||
{
|
||||
$this->table('option')
|
||||
->addColumn('event_cc_booking', 'char', ['limit' => 1, 'null' => false, 'default' => 'N', 'after' => 'event_terms_text'])
|
||||
->addColumn('event_cc_promotion', 'char', ['limit' => 1, 'null' => false, 'default' => 'N', 'after' => 'event_cc_booking'])
|
||||
->addColumn('event_cc_user_cancel', 'char', ['limit' => 1, 'null' => false, 'default' => 'N', 'after' => 'event_cc_promotion'])
|
||||
->addColumn('event_cc_event_cancel', 'char', ['limit' => 1, 'null' => false, 'default' => 'Y', 'after' => 'event_cc_user_cancel'])
|
||||
->addColumn('event_cc_reminder', 'char', ['limit' => 1, 'null' => false, 'default' => 'N', 'after' => 'event_cc_event_cancel'])
|
||||
->addColumn('event_reminder_enabled', 'char', ['limit' => 1, 'null' => false, 'default' => 'N', 'after' => 'event_cc_reminder'])
|
||||
->addColumn('event_reminder_hours', 'integer', ['null' => false, 'default' => 24, 'after' => 'event_reminder_enabled'])
|
||||
->update();
|
||||
|
||||
$this->table('event_bookings')
|
||||
->addColumn('offered_at', 'datetime', ['null' => true, 'comment' => 'promozione lista attesa in attesa di riconferma', 'after' => 'consent_at'])
|
||||
->update();
|
||||
}
|
||||
}
|
||||
@@ -1,24 +0,0 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
use Phinx\Migration\AbstractMigration;
|
||||
|
||||
final class AddReminderAndOfferSettings extends AbstractMigration
|
||||
{
|
||||
public function change(): void
|
||||
{
|
||||
// Default generali (scuola)
|
||||
$this->table('option')
|
||||
->addColumn('event_offer_expiry_hours', 'integer', ['null' => false, 'default' => 24, 'after' => 'event_reminder_hours'])
|
||||
->update();
|
||||
|
||||
// Override per singolo evento (NULL = usa il default scuola)
|
||||
$this->table('events')
|
||||
->addColumn('reminder_enabled', 'char', ['limit' => 1, 'null' => true, 'default' => null, 'comment' => 'NULL=default scuola; Y/N override', 'after' => 'waitlist_enabled'])
|
||||
->addColumn('reminder_hours', 'integer', ['null' => true, 'default' => null, 'comment' => 'NULL=default scuola', 'after' => 'reminder_enabled'])
|
||||
->addColumn('offer_expiry_hours', 'integer', ['null' => true, 'default' => null, 'comment' => 'NULL=default scuola', 'after' => 'reminder_hours'])
|
||||
->addColumn('reminder_sent_at', 'datetime', ['null' => true, 'after' => 'offer_expiry_hours'])
|
||||
->update();
|
||||
}
|
||||
}
|
||||
@@ -1,15 +0,0 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
use Phinx\Migration\AbstractMigration;
|
||||
|
||||
final class AddPublishAtToEvents extends AbstractMigration
|
||||
{
|
||||
public function change(): void
|
||||
{
|
||||
$this->table('events')
|
||||
->addColumn('publish_at', 'datetime', ['null' => true, 'comment' => 'apertura prenotazioni programmata', 'after' => 'status'])
|
||||
->update();
|
||||
}
|
||||
}
|
||||
@@ -1,51 +0,0 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
use Phinx\Migration\AbstractMigration;
|
||||
|
||||
final class ExtendEmployeeForTeachers extends AbstractMigration
|
||||
{
|
||||
public function up(): void
|
||||
{
|
||||
$this->table('employee')
|
||||
->addColumn('email', 'string', ['limit' => 150, 'null' => true, 'after' => 'surnameemployee'])
|
||||
->addColumn('phone', 'string', ['limit' => 40, 'null' => true, 'after' => 'email'])
|
||||
->addColumn('photo', 'string', ['limit' => 191, 'null' => true, 'after' => 'phone'])
|
||||
->addColumn('is_owner', 'char', [
|
||||
'limit' => 1,
|
||||
'null' => false,
|
||||
'default' => 'N',
|
||||
'comment' => 'Y = titolare della scuola (uno solo)',
|
||||
'after' => 'photo',
|
||||
])
|
||||
->addColumn('notifications', 'char', [
|
||||
'limit' => 1,
|
||||
'null' => false,
|
||||
'default' => 'Y',
|
||||
'comment' => 'Y = riceve le email',
|
||||
'after' => 'is_owner',
|
||||
])
|
||||
->addColumn('active', 'char', ['limit' => 1, 'null' => false, 'default' => 'Y', 'after' => 'notifications'])
|
||||
->addColumn('created_at', 'timestamp', ['null' => true, 'default' => 'CURRENT_TIMESTAMP'])
|
||||
->addColumn('updated_at', 'timestamp', ['null' => true, 'default' => null, 'update' => 'CURRENT_TIMESTAMP'])
|
||||
->update();
|
||||
|
||||
// L'insegnante già presente (id più basso) diventa il titolare
|
||||
$this->execute("UPDATE `employee` SET `is_owner` = 'Y' ORDER BY `idemployee` LIMIT 1");
|
||||
}
|
||||
|
||||
public function down(): void
|
||||
{
|
||||
$this->table('employee')
|
||||
->removeColumn('email')
|
||||
->removeColumn('phone')
|
||||
->removeColumn('photo')
|
||||
->removeColumn('is_owner')
|
||||
->removeColumn('notifications')
|
||||
->removeColumn('active')
|
||||
->removeColumn('created_at')
|
||||
->removeColumn('updated_at')
|
||||
->update();
|
||||
}
|
||||
}
|
||||
@@ -1,21 +0,0 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
use Phinx\Migration\AbstractMigration;
|
||||
|
||||
final class AddShowTeacherToOption extends AbstractMigration
|
||||
{
|
||||
public function change(): void
|
||||
{
|
||||
$this->table('option')
|
||||
->addColumn('show_teacher', 'char', [
|
||||
'limit' => 1,
|
||||
'null' => false,
|
||||
'default' => 'N',
|
||||
'comment' => 'Y = mostra l\'insegnante nelle card delle classi',
|
||||
'after' => 'waitinglist_enabled',
|
||||
])
|
||||
->update();
|
||||
}
|
||||
}
|
||||
@@ -1,52 +0,0 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
use Phinx\Migration\AbstractMigration;
|
||||
|
||||
final class CreateSchoolsTable extends AbstractMigration
|
||||
{
|
||||
public function up(): void
|
||||
{
|
||||
$this->table('schools', [
|
||||
'id' => false,
|
||||
'primary_key' => ['idschool'],
|
||||
'engine' => 'InnoDB',
|
||||
'collation' => 'utf8mb4_unicode_ci',
|
||||
])
|
||||
->addColumn('idschool', 'integer', ['signed' => false, 'identity' => true])
|
||||
->addColumn('name', 'string', ['limit' => 191])
|
||||
->addColumn('slug', 'string', ['limit' => 100, 'comment' => 'usato per URL/sottodominio/widget'])
|
||||
->addColumn('email', 'string', ['limit' => 191, 'null' => true])
|
||||
->addColumn('phone', 'string', ['limit' => 40, 'null' => true])
|
||||
->addColumn('address', 'string', ['limit' => 255, 'null' => true])
|
||||
->addColumn('city', 'string', ['limit' => 100, 'null' => true])
|
||||
->addColumn('postcode', 'string', ['limit' => 20, 'null' => true])
|
||||
->addColumn('country', 'string', ['limit' => 2, 'default' => 'IT'])
|
||||
->addColumn('vat_number', 'string', ['limit' => 30, 'null' => true])
|
||||
->addColumn('logo', 'string', ['limit' => 191, 'null' => true])
|
||||
->addColumn('timezone', 'string', ['limit' => 50, 'default' => 'Europe/Rome'])
|
||||
->addColumn('locale', 'string', ['limit' => 5, 'default' => 'it'])
|
||||
->addColumn('currency', 'string', ['limit' => 3, 'default' => 'EUR'])
|
||||
->addColumn('status', 'string', ['limit' => 20, 'default' => 'active', 'comment' => 'active|suspended|trial'])
|
||||
->addColumn('created_at', 'timestamp', ['null' => true, 'default' => 'CURRENT_TIMESTAMP'])
|
||||
->addColumn('updated_at', 'timestamp', ['null' => true, 'default' => null, 'update' => 'CURRENT_TIMESTAMP'])
|
||||
->addIndex(['slug'], ['unique' => true, 'name' => 'schools_slug_unique'])
|
||||
->addIndex(['status'], ['name' => 'schools_status_index'])
|
||||
->create();
|
||||
|
||||
// Seregno = scuola 1 (dati da completare poi dal pannello)
|
||||
$this->table('schools')->insert([
|
||||
'idschool' => 1,
|
||||
'name' => 'Scuola Yoga Seregno',
|
||||
'slug' => 'seregno',
|
||||
'city' => 'Seregno',
|
||||
'country' => 'IT',
|
||||
])->saveData();
|
||||
}
|
||||
|
||||
public function down(): void
|
||||
{
|
||||
$this->table('schools')->drop()->save();
|
||||
}
|
||||
}
|
||||
@@ -1,40 +0,0 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
use Phinx\Migration\AbstractMigration;
|
||||
|
||||
final class CreateSchoolUserTable extends AbstractMigration
|
||||
{
|
||||
public function up(): void
|
||||
{
|
||||
$this->table('school_user', [
|
||||
'id' => false,
|
||||
'primary_key' => ['idschooluser'],
|
||||
'engine' => 'InnoDB',
|
||||
'collation' => 'utf8mb4_unicode_ci',
|
||||
])
|
||||
->addColumn('idschooluser', 'integer', ['signed' => false, 'identity' => true])
|
||||
->addColumn('user_id', 'integer', ['signed' => false, 'comment' => 'auth_users.id'])
|
||||
->addColumn('idschool', 'integer', ['signed' => false])
|
||||
->addColumn('school_role', 'string', ['limit' => 20, 'default' => 'student', 'comment' => 'student|teacher|admin|owner'])
|
||||
->addColumn('active', 'char', ['limit' => 1, 'default' => 'Y'])
|
||||
->addColumn('joined_at', 'timestamp', ['null' => true, 'default' => 'CURRENT_TIMESTAMP'])
|
||||
->addIndex(['user_id', 'idschool'], ['unique' => true, 'name' => 'school_user_unique'])
|
||||
->addIndex(['idschool'], ['name' => 'school_user_idschool_index'])
|
||||
->addForeignKey('user_id', 'auth_users', 'id', ['delete' => 'CASCADE', 'update' => 'NO_ACTION'])
|
||||
->addForeignKey('idschool', 'schools', 'idschool', ['delete' => 'CASCADE', 'update' => 'NO_ACTION'])
|
||||
->create();
|
||||
|
||||
// Tutti gli utenti esistenti appartengono a Seregno (1)
|
||||
$this->execute("
|
||||
INSERT INTO school_user (user_id, idschool, school_role)
|
||||
SELECT id, 1, 'student' FROM auth_users
|
||||
");
|
||||
}
|
||||
|
||||
public function down(): void
|
||||
{
|
||||
$this->table('school_user')->drop()->save();
|
||||
}
|
||||
}
|
||||
@@ -1,79 +0,0 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
use Phinx\Migration\AbstractMigration;
|
||||
|
||||
final class AddIdschoolToDomainTables extends AbstractMigration
|
||||
{
|
||||
/**
|
||||
* Tabelle applicative che diventano "per scuola".
|
||||
* Le tabelle auth_* (Vanguard) restano globali: il legame
|
||||
* utente-scuola passa da school_user.
|
||||
*/
|
||||
private const TABLES = [
|
||||
'associateclass',
|
||||
'bookingclass',
|
||||
'certificateuserprofile',
|
||||
'copyorder',
|
||||
'copyorder_items',
|
||||
'dayoff',
|
||||
'employee',
|
||||
'events',
|
||||
'event_bookings',
|
||||
'event_locations',
|
||||
'expiryparameter',
|
||||
'location',
|
||||
'option',
|
||||
'orderbook',
|
||||
'propagation',
|
||||
'service',
|
||||
'servicecategory',
|
||||
'serviceschedule',
|
||||
'userprofile',
|
||||
];
|
||||
|
||||
public function up(): void
|
||||
{
|
||||
foreach (self::TABLES as $name) {
|
||||
$this->table($name)
|
||||
->addColumn('idschool', 'integer', [
|
||||
'signed' => false,
|
||||
'null' => false,
|
||||
'default' => 1, // TEMPORANEO: verrà rimosso quando tutte le INSERT passeranno idschool
|
||||
])
|
||||
->addIndex(['idschool'], ['name' => "idx_{$name}_idschool"])
|
||||
->update();
|
||||
}
|
||||
|
||||
// Slug eventi: unico per scuola, non più globale
|
||||
$this->table('events')
|
||||
->removeIndexByName('events_slug_unique')
|
||||
->addIndex(['idschool', 'slug'], ['unique' => true, 'name' => 'events_school_slug_unique'])
|
||||
->update();
|
||||
|
||||
// Impostazioni: una sola riga per scuola
|
||||
$this->table('option')
|
||||
->addIndex(['idschool'], ['unique' => true, 'name' => 'option_idschool_unique'])
|
||||
->update();
|
||||
}
|
||||
|
||||
public function down(): void
|
||||
{
|
||||
$this->table('option')
|
||||
->removeIndexByName('option_idschool_unique')
|
||||
->update();
|
||||
|
||||
$this->table('events')
|
||||
->removeIndexByName('events_school_slug_unique')
|
||||
->addIndex(['slug'], ['unique' => true, 'name' => 'events_slug_unique'])
|
||||
->update();
|
||||
|
||||
foreach (self::TABLES as $name) {
|
||||
$this->table($name)
|
||||
->removeIndexByName("idx_{$name}_idschool")
|
||||
->removeColumn('idschool')
|
||||
->update();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,79 +0,0 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
use Phinx\Migration\AbstractMigration;
|
||||
|
||||
final class AddIdschoolToDomainTables extends AbstractMigration
|
||||
{
|
||||
/**
|
||||
* Tabelle applicative che diventano "per scuola".
|
||||
* Le tabelle auth_* (Vanguard) restano globali: il legame
|
||||
* utente-scuola passa da school_user.
|
||||
*/
|
||||
private const TABLES = [
|
||||
'associateclass',
|
||||
'bookingclass',
|
||||
'certificateuserprofile',
|
||||
'copyorder',
|
||||
'copyorder_items',
|
||||
'dayoff',
|
||||
'employee',
|
||||
'events',
|
||||
'event_bookings',
|
||||
'event_locations',
|
||||
'expiryparameter',
|
||||
'location',
|
||||
'option',
|
||||
'orderbook',
|
||||
'propagation',
|
||||
'service',
|
||||
'servicecategory',
|
||||
'serviceschedule',
|
||||
'userprofile',
|
||||
];
|
||||
|
||||
public function up(): void
|
||||
{
|
||||
foreach (self::TABLES as $name) {
|
||||
$this->table($name)
|
||||
->addColumn('idschool', 'integer', [
|
||||
'signed' => false,
|
||||
'null' => false,
|
||||
'default' => 1, // TEMPORANEO: verrà rimosso quando tutte le INSERT passeranno idschool
|
||||
])
|
||||
->addIndex(['idschool'], ['name' => "idx_{$name}_idschool"])
|
||||
->update();
|
||||
}
|
||||
|
||||
// Slug eventi: unico per scuola, non più globale
|
||||
$this->table('events')
|
||||
->removeIndexByName('events_slug_unique')
|
||||
->addIndex(['idschool', 'slug'], ['unique' => true, 'name' => 'events_school_slug_unique'])
|
||||
->update();
|
||||
|
||||
// Impostazioni: una sola riga per scuola
|
||||
$this->table('option')
|
||||
->addIndex(['idschool'], ['unique' => true, 'name' => 'option_idschool_unique'])
|
||||
->update();
|
||||
}
|
||||
|
||||
public function down(): void
|
||||
{
|
||||
$this->table('option')
|
||||
->removeIndexByName('option_idschool_unique')
|
||||
->update();
|
||||
|
||||
$this->table('events')
|
||||
->removeIndexByName('events_school_slug_unique')
|
||||
->addIndex(['slug'], ['unique' => true, 'name' => 'events_slug_unique'])
|
||||
->update();
|
||||
|
||||
foreach (self::TABLES as $name) {
|
||||
$this->table($name)
|
||||
->removeIndexByName("idx_{$name}_idschool")
|
||||
->removeColumn('idschool')
|
||||
->update();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,40 +0,0 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
use Phinx\Migration\AbstractMigration;
|
||||
|
||||
final class CreateSchoolUserTable extends AbstractMigration
|
||||
{
|
||||
public function up(): void
|
||||
{
|
||||
$this->table('school_user', [
|
||||
'id' => false,
|
||||
'primary_key' => ['idschooluser'],
|
||||
'engine' => 'InnoDB',
|
||||
'collation' => 'utf8mb4_unicode_ci',
|
||||
])
|
||||
->addColumn('idschooluser', 'integer', ['signed' => false, 'identity' => true])
|
||||
->addColumn('user_id', 'integer', ['signed' => false, 'comment' => 'auth_users.id'])
|
||||
->addColumn('idschool', 'integer', ['signed' => false])
|
||||
->addColumn('school_role', 'string', ['limit' => 20, 'default' => 'student', 'comment' => 'student|teacher|admin|owner'])
|
||||
->addColumn('active', 'char', ['limit' => 1, 'default' => 'Y'])
|
||||
->addColumn('joined_at', 'timestamp', ['null' => true, 'default' => 'CURRENT_TIMESTAMP'])
|
||||
->addIndex(['user_id', 'idschool'], ['unique' => true, 'name' => 'school_user_unique'])
|
||||
->addIndex(['idschool'], ['name' => 'school_user_idschool_index'])
|
||||
->addForeignKey('user_id', 'auth_users', 'id', ['delete' => 'CASCADE', 'update' => 'NO_ACTION'])
|
||||
->addForeignKey('idschool', 'schools', 'idschool', ['delete' => 'CASCADE', 'update' => 'NO_ACTION'])
|
||||
->create();
|
||||
|
||||
// Tutti gli utenti esistenti appartengono a Seregno (1)
|
||||
$this->execute("
|
||||
INSERT INTO school_user (user_id, idschool, school_role)
|
||||
SELECT id, 1, 'student' FROM auth_users
|
||||
");
|
||||
}
|
||||
|
||||
public function down(): void
|
||||
{
|
||||
$this->table('school_user')->drop()->save();
|
||||
}
|
||||
}
|
||||
@@ -1,52 +0,0 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
use Phinx\Migration\AbstractMigration;
|
||||
|
||||
final class CreateSchoolsTable extends AbstractMigration
|
||||
{
|
||||
public function up(): void
|
||||
{
|
||||
$this->table('schools', [
|
||||
'id' => false,
|
||||
'primary_key' => ['idschool'],
|
||||
'engine' => 'InnoDB',
|
||||
'collation' => 'utf8mb4_unicode_ci',
|
||||
])
|
||||
->addColumn('idschool', 'integer', ['signed' => false, 'identity' => true])
|
||||
->addColumn('name', 'string', ['limit' => 191])
|
||||
->addColumn('slug', 'string', ['limit' => 100, 'comment' => 'usato per URL/sottodominio/widget'])
|
||||
->addColumn('email', 'string', ['limit' => 191, 'null' => true])
|
||||
->addColumn('phone', 'string', ['limit' => 40, 'null' => true])
|
||||
->addColumn('address', 'string', ['limit' => 255, 'null' => true])
|
||||
->addColumn('city', 'string', ['limit' => 100, 'null' => true])
|
||||
->addColumn('postcode', 'string', ['limit' => 20, 'null' => true])
|
||||
->addColumn('country', 'string', ['limit' => 2, 'default' => 'IT'])
|
||||
->addColumn('vat_number', 'string', ['limit' => 30, 'null' => true])
|
||||
->addColumn('logo', 'string', ['limit' => 191, 'null' => true])
|
||||
->addColumn('timezone', 'string', ['limit' => 50, 'default' => 'Europe/Rome'])
|
||||
->addColumn('locale', 'string', ['limit' => 5, 'default' => 'it'])
|
||||
->addColumn('currency', 'string', ['limit' => 3, 'default' => 'EUR'])
|
||||
->addColumn('status', 'string', ['limit' => 20, 'default' => 'active', 'comment' => 'active|suspended|trial'])
|
||||
->addColumn('created_at', 'timestamp', ['null' => true, 'default' => 'CURRENT_TIMESTAMP'])
|
||||
->addColumn('updated_at', 'timestamp', ['null' => true, 'default' => null, 'update' => 'CURRENT_TIMESTAMP'])
|
||||
->addIndex(['slug'], ['unique' => true, 'name' => 'schools_slug_unique'])
|
||||
->addIndex(['status'], ['name' => 'schools_status_index'])
|
||||
->create();
|
||||
|
||||
// Seregno = scuola 1 (dati da completare poi dal pannello)
|
||||
$this->table('schools')->insert([
|
||||
'idschool' => 1,
|
||||
'name' => 'Scuola Yoga Seregno',
|
||||
'slug' => 'seregno',
|
||||
'city' => 'Seregno',
|
||||
'country' => 'IT',
|
||||
])->saveData();
|
||||
}
|
||||
|
||||
public function down(): void
|
||||
{
|
||||
$this->table('schools')->drop()->save();
|
||||
}
|
||||
}
|
||||
@@ -1,18 +1,17 @@
|
||||
<?php
|
||||
// Connessione al database (adattare le informazioni di connessione)
|
||||
include('include/headscript.php');
|
||||
require_once __DIR__ . '/class/mailer.php';
|
||||
|
||||
use PHPMailer\PHPMailer\PHPMailer;
|
||||
use PHPMailer\PHPMailer\Exception;
|
||||
?>
|
||||
<?php
|
||||
// Connessione al database (adattare le informazioni di connessione)
|
||||
include('include/headscript.php');
|
||||
|
||||
$conn = $bkngstm; // riusa la connessione già aperta da bkngstm.php
|
||||
|
||||
// Recupera il parametro "idbookingclass" dalla richiesta GET
|
||||
$conn = new mysqli($servername, $username, $password, $dbname);
|
||||
|
||||
// Recupera il parametro "idbookingclass" dalla richiesta GET
|
||||
if (isset($_GET['idbookingclass'])) {
|
||||
$idbookingclass = (int) $_GET['idbookingclass'];
|
||||
$idbookingclass = $_GET['idbookingclass'];
|
||||
|
||||
// Aggiorna lo status a "booked" e is_reprogrammed a "Y" nella tabella "bookingclass"
|
||||
$query = "UPDATE bookingclass SET status = 'booked', is_reprogrammed = 'Y' WHERE idbookingclass = ?";
|
||||
@@ -39,7 +38,9 @@ if (isset($_GET['idbookingclass'])) {
|
||||
$firstname = $row['first_name'];
|
||||
|
||||
$newtimeformat = date("d-m-Y H:i", strtotime($newtime));
|
||||
|
||||
require 'phpmailer/src/Exception.php';
|
||||
require 'phpmailer/src/PHPMailer.php';
|
||||
require 'phpmailer/src/SMTP.php';
|
||||
// Mail to client
|
||||
$messageedit = "
|
||||
<p style='font-size: 14px; line-height: 190%;'><span style='font-size: 18px; line-height: 34.2px;'><strong><span style='line-height: 34.2px; font-size: 18px;'> Ciao $firstname , </span></strong></span></p>
|
||||
@@ -48,9 +49,9 @@ if (isset($_GET['idbookingclass'])) {
|
||||
<br>
|
||||
<p style='font-size: 14px; line-height: 190%;'><span style='font-size: 16px; line-height: 30.4px;'>Per vedere e gestire le tue lezioni clicca qui: https://yogibook.yogasoul.it </span></p>
|
||||
<br>
|
||||
<p style='font-size: 14px; line-height: 190%;'><span style='font-size: 16px; line-height: 30.4px;'>Se non ricordi la password o non hai sei mai entrata in Yogibbok, per prima cosa resettare la password cliccando di seguito</span></p>
|
||||
<p style='font-size: 14px; line-height: 190%;'><span style='font-size: 16px; line-height: 30.4px;'>Per il primo accesso devi per prima cosa resettare la password cliccando di seguito</span></p>
|
||||
<br>
|
||||
<a href='https://yogibook.yogasoul.it/password/reset' target='_blank' class='v-button v-font-size' style='box-sizing: border-box;display: inline-block;text-decoration: none;-webkit-text-size-adjust: none;text-align: center;color: #FFFFFF; background-color: #3AAEE0; border-radius: 4px;-webkit-border-radius: 4px; -moz-border-radius: 4px; width:auto; max-width:100%; overflow-wrap: break-word; word-break: break-word; word-wrap:break-word; mso-border-alt: none;font-size: 14px;'>
|
||||
<a href='https://yogibook.yogasoul.it/public/password/reset' target='_blank' class='v-button v-font-size' style='box-sizing: border-box;display: inline-block;text-decoration: none;-webkit-text-size-adjust: none;text-align: center;color: #FFFFFF; background-color: #3AAEE0; border-radius: 4px;-webkit-border-radius: 4px; -moz-border-radius: 4px; width:auto; max-width:100%; overflow-wrap: break-word; word-break: break-word; word-wrap:break-word; mso-border-alt: none;font-size: 14px;'>
|
||||
<span style='display:block;padding:10px 20px;line-height:120%;'><span style='line-height: 16.8px;'>Reset Password</span></span>
|
||||
</a>
|
||||
<br>
|
||||
@@ -64,21 +65,20 @@ if (isset($_GET['idbookingclass'])) {
|
||||
|
||||
$mail = new PHPMailer(true);
|
||||
|
||||
$mail->isSMTP();
|
||||
$mail->Host = $_ENV['MAIL_HOST'];
|
||||
$mail->SMTPAuth = true;
|
||||
$mail->Username = $_ENV['MAIL_USERNAME'];
|
||||
$mail->Password = $_ENV['MAIL_PASSWORD'];
|
||||
$mail->SMTPSecure = $_ENV['MAIL_ENCRYPTION']; // ssl
|
||||
$mail->Port = (int) $_ENV['MAIL_PORT']; // 465
|
||||
$mail->CharSet = 'UTF-8';
|
||||
$mail->isSMTP(); // Set mailer to use SMTP
|
||||
$mail->Host = 'mail.yogasoul.it'; // Specify main and backup server
|
||||
$mail->SMTPAuth = true; // Enable SMTP authentication
|
||||
$mail->Username = 'info@yogasoul.it'; // SMTP username
|
||||
$mail->Password = '!Testolina88'; // SMTP password
|
||||
$mail->SMTPSecure = 'tls'; // Enable encryption, 'ssl' also accepted
|
||||
$mail->Port = '587';
|
||||
|
||||
include('mail/emailtemplate2.php');
|
||||
// Email body content
|
||||
$htmlContent = $mailmessage1;
|
||||
|
||||
$mail->From = $_ENV['MAIL_FROM_ADDRESS'];
|
||||
$mail->FromName = $_ENV['MAIL_FROM_NAME'];
|
||||
$mail->From = 'info@yogasoul.it';
|
||||
$mail->FromName = 'YogiBook [YogaSoul]';
|
||||
$mail->addAddress($emailuser); // Add a recipient
|
||||
|
||||
$mail->Subject = "YogiBook - Lezione riprogrammata con successo!";
|
||||
@@ -104,3 +104,7 @@ if (isset($_GET['idbookingclass'])) {
|
||||
} else {
|
||||
echo "Parametro 'idbookingclass' non trovato nella richiesta GET.";
|
||||
}
|
||||
|
||||
// Chiudi la connessione al database
|
||||
$conn->close();
|
||||
?>
|
||||
+13
-246
@@ -11,56 +11,9 @@ function e($value): string
|
||||
return htmlspecialchars((string) $value, ENT_QUOTES, 'UTF-8');
|
||||
}
|
||||
|
||||
function teacherInitials(string $first, string $last): string
|
||||
{
|
||||
$ini = mb_strtoupper(mb_substr(trim($first), 0, 1) . mb_substr(trim($last), 0, 1));
|
||||
return $ini !== '' ? $ini : '?';
|
||||
}
|
||||
|
||||
function teacherColor(string $seed): string
|
||||
{
|
||||
$palette = ['#1ebf73', '#2980b9', '#8e44ad', '#e67e22', '#16a085', '#c0392b', '#2c3e50', '#b08d57'];
|
||||
return $palette[abs(crc32($seed)) % count($palette)];
|
||||
}
|
||||
|
||||
$message = $_GET['message'] ?? 'N';
|
||||
$insertFeedback = null;
|
||||
|
||||
/* -------------------------------------------------------------------------
|
||||
* Insegnanti (titolare per primo, poi attivi, poi alfabetico)
|
||||
* ---------------------------------------------------------------------- */
|
||||
$teachers = $pdo->query(
|
||||
"SELECT idemployee, nameemployee, surnameemployee, photo, is_owner, active
|
||||
FROM employee
|
||||
ORDER BY is_owner DESC, active DESC, surnameemployee, nameemployee"
|
||||
)->fetchAll();
|
||||
|
||||
$teachersById = [];
|
||||
$ownerId = 0;
|
||||
foreach ($teachers as $t) {
|
||||
$teachersById[(int) $t['idemployee']] = $t;
|
||||
if ($t['is_owner'] === 'Y' && !$ownerId) {
|
||||
$ownerId = (int) $t['idemployee'];
|
||||
}
|
||||
}
|
||||
|
||||
/* -------------------------------------------------------------------------
|
||||
* Assegnazione insegnante a una classe esistente (POST)
|
||||
* ---------------------------------------------------------------------- */
|
||||
if (($_POST['action'] ?? '') === 'assignteacher') {
|
||||
$idservice = (int) ($_POST['idservice'] ?? 0);
|
||||
$idteacher = (int) ($_POST['idteacher'] ?? 0);
|
||||
|
||||
if ($idservice > 0 && isset($teachersById[$idteacher])) {
|
||||
$stmt = $pdo->prepare("UPDATE service SET idteacher = :t WHERE idservice = :s");
|
||||
$stmt->execute([':t' => $idteacher, ':s' => $idservice]);
|
||||
header('Location: ' . $_SERVER['PHP_SELF'] . '?message=teacherassigned');
|
||||
} else {
|
||||
header('Location: ' . $_SERVER['PHP_SELF'] . '?message=teachererror');
|
||||
}
|
||||
exit;
|
||||
}
|
||||
|
||||
/* -------------------------------------------------------------------------
|
||||
* Inserimento nuova classe (POST) con prepared statement
|
||||
* ---------------------------------------------------------------------- */
|
||||
@@ -73,17 +26,14 @@ if (isset($_POST['classinsert']) && $_POST['classinsert'] === 'Y') {
|
||||
$maxcapacity = $_POST['maxcapacity'] ?? '';
|
||||
$colorclass = trim($_POST['colorclass'] ?? '');
|
||||
$classduration = $_POST['classduration'] ?? '';
|
||||
$idteacher = (int) ($_POST['idteacher'] ?? 0);
|
||||
|
||||
if ($servicename === '') {
|
||||
$insertFeedback = ['type' => 'error', 'text' => 'La descrizione della classe è obbligatoria.'];
|
||||
} elseif (!isset($teachersById[$idteacher])) {
|
||||
$insertFeedback = ['type' => 'error', 'text' => 'Seleziona l\'insegnante della classe.'];
|
||||
} else {
|
||||
$sql = "INSERT INTO service
|
||||
(servicename, wpcatalognumber, day, time, category, maxcapacity, colorclass, classduration, idteacher)
|
||||
(servicename, wpcatalognumber, day, time, category, maxcapacity, colorclass, classduration)
|
||||
VALUES
|
||||
(:servicename, :wpcatalog, :day, :time, :category, :maxcapacity, :colorclass, :classduration, :idteacher)";
|
||||
(:servicename, :wpcatalog, :day, :time, :category, :maxcapacity, :colorclass, :classduration)";
|
||||
$stmt = $pdo->prepare($sql);
|
||||
$ok = $stmt->execute([
|
||||
':servicename' => $servicename,
|
||||
@@ -94,7 +44,6 @@ if (isset($_POST['classinsert']) && $_POST['classinsert'] === 'Y') {
|
||||
':maxcapacity' => $maxcapacity !== '' ? (int) $maxcapacity : null,
|
||||
':colorclass' => $colorclass,
|
||||
':classduration' => $classduration !== '' ? (float) $classduration : null,
|
||||
':idteacher' => $idteacher,
|
||||
]);
|
||||
|
||||
if ($ok) {
|
||||
@@ -120,46 +69,6 @@ $services = $pdo->query(
|
||||
LEFT JOIN servicecategory ON service.category = servicecategory.idservicecategory
|
||||
ORDER BY service.servicename"
|
||||
)->fetchAll();
|
||||
|
||||
// Propagazioni già effettuate, raggruppate per servizio
|
||||
$propagationsByService = [];
|
||||
$propRows = $pdo->query(
|
||||
"SELECT p.idpropagation, p.idservice, p.token, p.startdate, p.enddate, p.created_at,
|
||||
COUNT(s.idserviceschedule) AS occorrenze
|
||||
FROM propagation p
|
||||
LEFT JOIN serviceschedule s ON s.propagation_token = p.token
|
||||
GROUP BY p.idpropagation
|
||||
ORDER BY p.created_at DESC"
|
||||
)->fetchAll();
|
||||
foreach ($propRows as $pr) {
|
||||
$propagationsByService[$pr['idservice']][] = $pr;
|
||||
}
|
||||
|
||||
/**
|
||||
* Opzioni del select insegnanti.
|
||||
* Gli insegnanti non attivi compaiono solo se già assegnati a quella classe.
|
||||
*/
|
||||
function teacherOptions(array $teachers, int $selectedId): string
|
||||
{
|
||||
$html = '';
|
||||
$found = false;
|
||||
foreach ($teachers as $t) {
|
||||
$tid = (int) $t['idemployee'];
|
||||
$isSel = $tid === $selectedId;
|
||||
if ($t['active'] !== 'Y' && !$isSel) {
|
||||
continue;
|
||||
}
|
||||
if ($isSel) $found = true;
|
||||
$label = trim($t['nameemployee'] . ' ' . $t['surnameemployee'])
|
||||
. ($t['is_owner'] === 'Y' ? ' (titolare)' : '')
|
||||
. ($t['active'] !== 'Y' ? ' (non attivo)' : '');
|
||||
$html .= '<option value="' . $tid . '"' . ($isSel ? ' selected' : '') . '>' . e($label) . '</option>';
|
||||
}
|
||||
if (!$found) {
|
||||
$html = '<option value="" selected disabled>— Non assegnato —</option>' . $html;
|
||||
}
|
||||
return $html;
|
||||
}
|
||||
?>
|
||||
<!doctype html>
|
||||
<html lang="it">
|
||||
@@ -274,43 +183,6 @@ function teacherOptions(array $teachers, int $selectedId): string
|
||||
.action-btns .btn {
|
||||
margin: 2px;
|
||||
}
|
||||
|
||||
.teacher-cell {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 8px;
|
||||
min-width: 210px;
|
||||
}
|
||||
|
||||
.teacher-mini {
|
||||
flex: 0 0 30px;
|
||||
width: 30px;
|
||||
height: 30px;
|
||||
border-radius: 50%;
|
||||
object-fit: cover;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
color: #fff;
|
||||
font-size: 11px;
|
||||
font-weight: 800;
|
||||
}
|
||||
|
||||
.teacher-mini.none {
|
||||
background: #f3f4f6;
|
||||
color: #c0c4cc;
|
||||
}
|
||||
|
||||
.teacher-select {
|
||||
padding: 5px 30px 5px 10px !important;
|
||||
font-size: 13px;
|
||||
}
|
||||
|
||||
.teacher-select.unassigned {
|
||||
border-color: #f0b27a;
|
||||
background-color: #fff8f1;
|
||||
color: #b9770e;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
|
||||
@@ -352,40 +224,14 @@ function teacherOptions(array $teachers, int $selectedId): string
|
||||
<?php if ($message === 'inserted') : ?>
|
||||
<div class="alert alert-success" role="alert">Classe inserita con successo.</div>
|
||||
<?php endif; ?>
|
||||
<?php if ($message === 'teacherassigned') : ?>
|
||||
<div class="alert alert-success" role="alert">Insegnante assegnato con successo.</div>
|
||||
<?php endif; ?>
|
||||
<?php if ($message === 'teachererror') : ?>
|
||||
<div class="alert alert-danger" role="alert">Impossibile assegnare l'insegnante. Riprova.</div>
|
||||
<?php endif; ?>
|
||||
<?php if ($message === 'success') : ?>
|
||||
<div class="alert alert-success" role="alert">Propagazione avvenuta con successo.</div>
|
||||
<?php endif; ?>
|
||||
<?php if ($message === 'propdeleted') : ?>
|
||||
<div class="alert alert-success" role="alert">Propagazione eliminata con successo.</div>
|
||||
<?php endif; ?>
|
||||
<?php if ($message === 'confirmdelete') : ?>
|
||||
<div class="alert alert-warning" role="alert">
|
||||
Attenzione: questa propagazione ha <strong><?php echo (int) ($_GET['count'] ?? 0); ?></strong> prenotazioni utente collegate.
|
||||
Vuoi eliminarla comunque insieme alle lezioni?
|
||||
<a href="cancelpropagation.php?token=<?php echo e($_GET['token'] ?? ''); ?>&confirm=Y"
|
||||
class="btn btn-danger btn-sm ms-2"
|
||||
onclick="return confirm('Confermi la cancellazione definitiva?');">
|
||||
Sì, elimina tutto
|
||||
</a>
|
||||
<a href="admin-services.php" class="btn btn-secondary btn-sm ms-1">Annulla</a>
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
<?php if ($insertFeedback) : ?>
|
||||
<div class="alert alert-<?php echo $insertFeedback['type'] === 'success' ? 'success' : 'danger'; ?>" role="alert">
|
||||
<?php echo e($insertFeedback['text']); ?>
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
<?php if (empty($teachers)) : ?>
|
||||
<div class="alert alert-warning" role="alert">
|
||||
Non ci sono insegnanti: <a href="insegnanti.php">aggiungine almeno uno</a> prima di creare una classe.
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
|
||||
<!-- Form inserimento classe -->
|
||||
<div class="row">
|
||||
@@ -468,14 +314,6 @@ function teacherOptions(array $teachers, int $selectedId): string
|
||||
<input type="text" class="form-control" id="colorclass" name="colorclass" value="#1ebf73">
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-lg-4">
|
||||
<div class="mb-3">
|
||||
<label for="idteacher" class="form-label">Insegnante</label>
|
||||
<select name="idteacher" id="idteacher" class="form-select" required>
|
||||
<?php echo teacherOptions($teachers, $ownerId); ?>
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<button type="submit" class="btn btn-primary btn-save">Inserisci classe</button>
|
||||
@@ -491,7 +329,7 @@ function teacherOptions(array $teachers, int $selectedId): string
|
||||
<div class="card admin-card">
|
||||
<div class="card-body">
|
||||
<div class="section-title">Classi esistenti</div>
|
||||
<p class="section-lead">Propaga una classe sul calendario, associala, assegna l'insegnante o modificane i dettagli.</p>
|
||||
<p class="section-lead">Propaga una classe sul calendario, associala o modificane i dettagli.</p>
|
||||
|
||||
<div class="table-responsive">
|
||||
<table class="table class-table align-middle mb-0">
|
||||
@@ -502,20 +340,16 @@ function teacherOptions(array $teachers, int $selectedId): string
|
||||
<th>Orario</th>
|
||||
<th>Durata</th>
|
||||
<th>Categoria</th>
|
||||
<th>Insegnante</th>
|
||||
<th class="text-end">Azioni</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<?php if (empty($services)) : ?>
|
||||
<tr>
|
||||
<td colspan="7" class="text-center text-muted py-4">Nessuna classe presente.</td>
|
||||
<td colspan="6" class="text-center text-muted py-4">Nessuna classe presente.</td>
|
||||
</tr>
|
||||
<?php else : ?>
|
||||
<?php foreach ($services as $svc) :
|
||||
$svcTeacherId = (int) $svc['idteacher'];
|
||||
$svcTeacher = $teachersById[$svcTeacherId] ?? null;
|
||||
?>
|
||||
<?php foreach ($services as $svc) : ?>
|
||||
<tr>
|
||||
<td>
|
||||
<span class="color-dot" style="background-color: <?php echo e($svc['colorclass'] ?: '#ccc'); ?>;"></span>
|
||||
@@ -528,32 +362,15 @@ function teacherOptions(array $teachers, int $selectedId): string
|
||||
<?php echo e($svc['classduration']); ?>
|
||||
</td>
|
||||
<td><?php echo e($svc['namecategory']); ?></td>
|
||||
<td>
|
||||
<form method="post" class="teacher-cell">
|
||||
<input type="hidden" name="action" value="assignteacher">
|
||||
<input type="hidden" name="idservice" value="<?php echo (int) $svc['idservice']; ?>">
|
||||
<?php if ($svcTeacher && $svcTeacher['photo']) : ?>
|
||||
<img class="teacher-mini" src="assets/images/teachers/<?php echo e($svcTeacher['photo']); ?>" alt="">
|
||||
<?php elseif ($svcTeacher) :
|
||||
$tName = trim($svcTeacher['nameemployee'] . ' ' . $svcTeacher['surnameemployee']); ?>
|
||||
<span class="teacher-mini" style="background:<?php echo teacherColor($tName); ?>;"><?php echo e(teacherInitials($svcTeacher['nameemployee'], $svcTeacher['surnameemployee'])); ?></span>
|
||||
<?php else : ?>
|
||||
<span class="teacher-mini none"><i class="fas fa-user"></i></span>
|
||||
<?php endif; ?>
|
||||
<select name="idteacher" class="form-select teacher-select <?php echo $svcTeacher ? '' : 'unassigned'; ?>"
|
||||
data-current="<?php echo $svcTeacherId; ?>"
|
||||
data-classname="<?php echo e($svc['servicename'] . ' ' . $svc['day'] . ' ' . $svc['time']); ?>">
|
||||
<?php echo teacherOptions($teachers, $svcTeacherId); ?>
|
||||
</select>
|
||||
</form>
|
||||
</td>
|
||||
<td class="text-end action-btns">
|
||||
<button type="button" class="btn btn-primary btn-sm toggle-form">Propaga</button>
|
||||
<a href="associate-services.php?id=<?php echo (int) $svc['idservice']; ?>">
|
||||
<button type="button" class="btn btn-info btn-sm">Associa</button>
|
||||
</a>
|
||||
<a href="updateservice.php?idservice=<?php echo (int) $svc['idservice']; ?>" class="btn btn-warning btn-sm">
|
||||
<i class="mdi mdi-lead-pencil font-size-16 align-middle"></i>
|
||||
<a href="updateservice.php?idservice=<?php echo (int) $svc['idservice']; ?>">
|
||||
<button type="button" class="btn btn-warning btn-sm">
|
||||
<i class="mdi mdi-lead-pencil font-size-16 align-middle"></i>
|
||||
</button>
|
||||
</a>
|
||||
<a href="cancelservice.php?idservice=<?php echo (int) $svc['idservice']; ?>">
|
||||
<button type="button" class="btn btn-danger btn-sm">
|
||||
@@ -563,7 +380,7 @@ function teacherOptions(array $teachers, int $selectedId): string
|
||||
</td>
|
||||
</tr>
|
||||
<tr class="expanded-row">
|
||||
<td colspan="7">
|
||||
<td colspan="6">
|
||||
<div class="expanded-content">
|
||||
<form class="calendar-form" method="post" action="nextdateclass.php">
|
||||
<div class="row">
|
||||
@@ -586,40 +403,6 @@ function teacherOptions(array $teachers, int $selectedId): string
|
||||
<input type="hidden" name="durationtime" value="<?php echo e($svc['classduration']); ?>">
|
||||
<button type="submit" class="btn btn-primary btn-save">Propaga sul calendario</button>
|
||||
</form>
|
||||
|
||||
<?php $props = $propagationsByService[$svc['idservice']] ?? []; ?>
|
||||
<?php if (!empty($props)) : ?>
|
||||
<hr>
|
||||
<div class="section-title" style="font-size:13px;">Propagazioni effettuate</div>
|
||||
<table class="table table-sm mt-2 mb-0">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Inizio</th>
|
||||
<th>Fine</th>
|
||||
<th>Lezioni</th>
|
||||
<th>Token</th>
|
||||
<th class="text-end">Azioni</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<?php foreach ($props as $p) : ?>
|
||||
<tr>
|
||||
<td><?php echo e($p['startdate']); ?></td>
|
||||
<td><?php echo e($p['enddate']); ?></td>
|
||||
<td><?php echo e($p['occorrenze']); ?></td>
|
||||
<td><code style="font-size:11px;"><?php echo e(substr((string)$p['token'], 0, 10)); ?>…</code></td>
|
||||
<td class="text-end">
|
||||
<a href="cancelpropagation.php?token=<?php echo e($p['token']); ?>"
|
||||
class="btn btn-danger btn-sm"
|
||||
onclick="return confirm('Eliminare questa propagazione e tutte le sue lezioni?');">
|
||||
Elimina
|
||||
</a>
|
||||
</td>
|
||||
</tr>
|
||||
<?php endforeach; ?>
|
||||
</tbody>
|
||||
</table>
|
||||
<?php endif; ?>
|
||||
</div>
|
||||
</td>
|
||||
</tr>
|
||||
@@ -660,25 +443,9 @@ function teacherOptions(array $teachers, int $selectedId): string
|
||||
palette: [
|
||||
["#FF0000", "#00FF00", "#0000FF"],
|
||||
["#1ebf73", "#f39c12", "#8e44ad"]
|
||||
]
|
||||
});
|
||||
|
||||
// Forza il valore del colore nel campo prima dell'invio del form
|
||||
$('#insertclass').on('submit', function() {
|
||||
var col = $('#colorclass').spectrum('get');
|
||||
if (col) {
|
||||
$('#colorclass').val(col.toHexString());
|
||||
}
|
||||
});
|
||||
|
||||
// Cambio insegnante dalla tabella: conferma e salva
|
||||
$('.teacher-select').on('change', function() {
|
||||
var sel = $(this);
|
||||
var teacherName = sel.find('option:selected').text();
|
||||
if (confirm('Assegnare ' + teacherName + ' alla classe ' + sel.data('classname') + '?')) {
|
||||
sel.closest('form')[0].submit();
|
||||
} else {
|
||||
sel.val(String(sel.data('current')) === '0' ? '' : String(sel.data('current')));
|
||||
],
|
||||
change: function(color) {
|
||||
$('#colorclass').val(color.toHexString());
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
+13
-429
@@ -28,16 +28,8 @@ function avatarColor(string $seed): string
|
||||
return $palette[$idx];
|
||||
}
|
||||
|
||||
$optRow = $pdo->query("SELECT maxbeforetimecancell, show_teacher FROM `option` LIMIT 1")->fetch();
|
||||
$optRow = $pdo->query("SELECT maxbeforetimecancell FROM `option` LIMIT 1")->fetch();
|
||||
$timetocancel = $optRow ? (int) $optRow['maxbeforetimecancell'] : 24;
|
||||
$showTeacher = ($optRow['show_teacher'] ?? 'N') === 'Y';
|
||||
|
||||
$teachersById = [];
|
||||
if ($showTeacher) {
|
||||
foreach ($pdo->query("SELECT idemployee, nameemployee, surnameemployee, photo FROM employee")->fetchAll() as $t) {
|
||||
$teachersById[(int) $t['idemployee']] = $t;
|
||||
}
|
||||
}
|
||||
|
||||
if (isset($_GET['prev_month'])) {
|
||||
$currentMonthStart = preg_replace('/[^0-9\-]/', '', $_GET['prev_month']) . '-01';
|
||||
@@ -52,7 +44,7 @@ if (strtotime($currentMonthStart) === false) {
|
||||
$currentMonthEnd = date("Y-m-t", strtotime($currentMonthStart));
|
||||
|
||||
$sqlSchedule = "SELECT serviceschedule.*, service.servicename, service.colorclass,
|
||||
service.maxcapacity, service.idservice, service.idteacher
|
||||
service.maxcapacity, service.idservice
|
||||
FROM serviceschedule
|
||||
LEFT JOIN service ON serviceschedule.idservice = service.idservice
|
||||
WHERE serviceschedule.dateschedule BETWEEN :start AND DATE_ADD(:end, INTERVAL 1 DAY)
|
||||
@@ -61,16 +53,6 @@ $stmtSchedule = $pdo->prepare($sqlSchedule);
|
||||
$stmtSchedule->execute([':start' => $currentMonthStart, ':end' => $currentMonthEnd]);
|
||||
$scheduleRows = $stmtSchedule->fetchAll();
|
||||
|
||||
// Tipologie di classe presenti nel mese (per la barra filtri), con relativo colore
|
||||
$classTypes = [];
|
||||
foreach ($scheduleRows as $r) {
|
||||
$name = $r['servicename'] ?? '';
|
||||
if ($name !== '' && !isset($classTypes[$name])) {
|
||||
$classTypes[$name] = $r['colorclass'] ?: '#1ebf73';
|
||||
}
|
||||
}
|
||||
ksort($classTypes);
|
||||
|
||||
$bookingsBySchedule = [];
|
||||
$scheduleIds = array_filter(array_map(fn($r) => (int) $r['idserviceschedule'], $scheduleRows));
|
||||
|
||||
@@ -81,9 +63,9 @@ if (!empty($scheduleIds)) {
|
||||
auth_users.first_name, auth_users.last_name, auth_users.id AS iduser
|
||||
FROM bookingclass
|
||||
LEFT JOIN auth_users ON bookingclass.iduser = auth_users.id
|
||||
WHERE bookingclass.idserviceschedule IN ($ph)
|
||||
AND bookingclass.status IN ('booked', 'pending', 'waiting')
|
||||
ORDER BY bookingclass.created_at, auth_users.last_name, auth_users.first_name";
|
||||
WHERE bookingclass.idserviceschedule IN ($ph)
|
||||
AND bookingclass.status = 'booked'
|
||||
ORDER BY auth_users.last_name, auth_users.first_name";
|
||||
$stmtBookings = $pdo->prepare($sqlBookings);
|
||||
$stmtBookings->execute(array_values($scheduleIds));
|
||||
foreach ($stmtBookings->fetchAll() as $b) {
|
||||
@@ -132,46 +114,6 @@ $italianMonths = [
|
||||
margin: 10px 0 26px;
|
||||
}
|
||||
|
||||
.class-filters {
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
gap: 8px;
|
||||
justify-content: center;
|
||||
margin: 0 0 26px;
|
||||
}
|
||||
|
||||
.filter-chip {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
gap: 7px;
|
||||
border: 1px solid #e2e4e9;
|
||||
background: #fff;
|
||||
color: #374151;
|
||||
font-size: 13px;
|
||||
font-weight: 600;
|
||||
padding: 7px 14px;
|
||||
border-radius: 20px;
|
||||
cursor: pointer;
|
||||
transition: all 0.15s;
|
||||
}
|
||||
|
||||
.filter-chip:hover {
|
||||
border-color: #1ebf73;
|
||||
}
|
||||
|
||||
.filter-chip.active {
|
||||
background: #1ebf73;
|
||||
border-color: #1ebf73;
|
||||
color: #fff;
|
||||
}
|
||||
|
||||
.filter-dot {
|
||||
width: 12px;
|
||||
height: 12px;
|
||||
border-radius: 50%;
|
||||
border: 1px solid rgba(0, 0, 0, 0.1);
|
||||
}
|
||||
|
||||
.month-navigation h2 {
|
||||
margin: 0;
|
||||
font-size: 22px;
|
||||
@@ -206,8 +148,8 @@ $italianMonths = [
|
||||
|
||||
.class-date {
|
||||
flex: 0 0 110px;
|
||||
background: #E1D0B8;
|
||||
color: #ffffff;
|
||||
background: #1ebf73;
|
||||
color: #fff;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
justify-content: center;
|
||||
@@ -239,38 +181,6 @@ $italianMonths = [
|
||||
margin: 0 0 4px;
|
||||
}
|
||||
|
||||
.class-teacher {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 8px;
|
||||
margin-top: 4px;
|
||||
}
|
||||
|
||||
.class-teacher strong {
|
||||
color: #374151;
|
||||
font-weight: 600;
|
||||
}
|
||||
|
||||
.teacher-avatar-sm {
|
||||
flex: 0 0 26px;
|
||||
width: 26px;
|
||||
height: 26px;
|
||||
border-radius: 50%;
|
||||
object-fit: cover;
|
||||
background: #E1D0B8;
|
||||
color: #5a4630;
|
||||
font-size: 11px;
|
||||
font-weight: 800;
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
}
|
||||
|
||||
.teacher-avatar-sm.none {
|
||||
background: #fdf0e3;
|
||||
color: #e67e22;
|
||||
}
|
||||
|
||||
.class-meta {
|
||||
color: #6b7280;
|
||||
font-size: 14px;
|
||||
@@ -562,7 +472,6 @@ $italianMonths = [
|
||||
'2' => ['success', 'Lezione ripristinata con successo.'],
|
||||
'3' => ['success', 'Lezione riprogrammata con successo.'],
|
||||
'4' => ['success', 'Classe eliminata con successo.'],
|
||||
'5' => ['success', 'Prenotazione confermata con successo.'],
|
||||
];
|
||||
$m = $msgMap[$_GET['success']] ?? null;
|
||||
if ($m) : ?>
|
||||
@@ -570,35 +479,12 @@ $italianMonths = [
|
||||
<?php endif;
|
||||
endif; ?>
|
||||
|
||||
<?php if (isset($_GET['error'])) :
|
||||
$errMap = [
|
||||
'duplicate' => 'Questo utente è già prenotato in questa classe.',
|
||||
'insert' => 'Errore durante l\'inserimento. Riprova.',
|
||||
'missingdata' => 'Dati mancanti per l\'inserimento.',
|
||||
];
|
||||
$em = $errMap[$_GET['error']] ?? 'Si è verificato un errore.';
|
||||
?>
|
||||
<div class="alert alert-danger" role="alert"><?php echo e($em); ?></div>
|
||||
<?php endif; ?>
|
||||
|
||||
<div class="month-navigation">
|
||||
<a href="?prev_month=<?php echo e(date('Y-m', strtotime('-1 month', strtotime($currentMonthStart)))); ?>"><i class="fas fa-chevron-left fa-2x"></i></a>
|
||||
<h2><?php echo e($italianMonths[date("F", strtotime($currentMonthStart))] . ' ' . date("Y", strtotime($currentMonthStart))); ?></h2>
|
||||
<a href="?next_month=<?php echo e(date('Y-m', strtotime('+1 month', strtotime($currentMonthStart)))); ?>"><i class="fas fa-chevron-right fa-2x"></i></a>
|
||||
</div>
|
||||
|
||||
<?php if (!empty($classTypes)) : ?>
|
||||
<div class="class-filters">
|
||||
<button type="button" class="filter-chip active" data-filter="__all__">Tutte</button>
|
||||
<?php foreach ($classTypes as $typeName => $typeColor) : ?>
|
||||
<button type="button" class="filter-chip" data-filter="<?php echo e($typeName); ?>">
|
||||
<span class="filter-dot" style="background: <?php echo e($typeColor); ?>;"></span>
|
||||
<?php echo e($typeName); ?>
|
||||
</button>
|
||||
<?php endforeach; ?>
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
|
||||
<?php if (empty($scheduleRows)) : ?>
|
||||
<div class="empty-month">
|
||||
<i class="fas fa-calendar-xmark fa-2x mb-2"></i>
|
||||
@@ -611,61 +497,27 @@ $italianMonths = [
|
||||
$monthIt = $italianMonths[$dateObj->format("F")];
|
||||
$whenFmt = $dateObj->format("d-m-Y H:i");
|
||||
$scheduleId = (int) $sch['idserviceschedule'];
|
||||
$allRows = $bookingsBySchedule[$scheduleId] ?? [];
|
||||
// separa confermati (booked) da in attesa (pending)
|
||||
$bookings = array_filter($allRows, fn($b) => $b['status'] === 'booked');
|
||||
$pendings = array_filter($allRows, fn($b) => $b['status'] === 'pending');
|
||||
$waitings = array_filter($allRows, fn($b) => $b['status'] === 'waiting');
|
||||
$countPersons = count($bookings); // contatore = solo confermati
|
||||
$countPending = count($pendings);
|
||||
$countWaiting = count($waitings);
|
||||
$bookings = $bookingsBySchedule[$scheduleId] ?? [];
|
||||
$countPersons = count($bookings);
|
||||
$maxcap = (int) $sch['maxcapacity'];
|
||||
$isFull = $maxcap > 0 && $countPersons >= $maxcap;
|
||||
$colorclass = $sch['colorclass'] ?: '#e6f3ff';
|
||||
?>
|
||||
<div class="class-card" data-date="<?php echo e($dateObj->format('Y-m-d')); ?>" data-type="<?php echo e($sch['servicename']); ?>">
|
||||
<div class="class-card">
|
||||
<div class="class-date">
|
||||
<div class="day"><?php echo e($dayNum); ?></div>
|
||||
<div class="month"><?php echo e($monthIt); ?></div>
|
||||
</div>
|
||||
<div class="class-body" style="border-left: 20px solid <?php echo e($colorclass); ?>;">
|
||||
<div class="class-body" style="border-left: 6px solid <?php echo e($colorclass); ?>;">
|
||||
<h3 class="class-title">
|
||||
<?php echo e($sch['servicename']); ?>
|
||||
<span class="capacity-pill <?php echo $isFull ? 'full' : ''; ?>">
|
||||
<i class="fas fa-user-group" style="font-size:11px;"></i>
|
||||
<?php echo $countPersons; ?>/<?php echo $maxcap; ?>
|
||||
</span>
|
||||
<?php if ($countPending > 0) : ?>
|
||||
<span class="capacity-pill" style="background:#fff4d6;color:#8a6d00;">
|
||||
<i class="fas fa-hourglass-half" style="font-size:11px;"></i>
|
||||
<?php echo $countPending; ?> in attesa
|
||||
</span>
|
||||
<?php endif; ?>
|
||||
<?php if ($countWaiting > 0) : ?>
|
||||
<span class="capacity-pill" style="background:#fbeef3;color:#d1698a;">
|
||||
<i class="fas fa-list-ol" style="font-size:11px;"></i>
|
||||
<?php echo $countWaiting; ?> in coda
|
||||
</span>
|
||||
<?php endif; ?>
|
||||
</h3>
|
||||
<p class="class-meta"><i class="far fa-clock me-1"></i><?php echo e($whenFmt); ?></p>
|
||||
<p class="class-meta"><i class="fas fa-location-dot me-1"></i>via Valassina 62/B Seregno - Sala Contesto Yoga</p>
|
||||
<?php if ($showTeacher) :
|
||||
$tch = $teachersById[(int) ($sch['idteacher'] ?? 0)] ?? null; ?>
|
||||
<p class="class-meta class-teacher">
|
||||
<?php if ($tch) : ?>
|
||||
<?php if (!empty($tch['photo'])) : ?>
|
||||
<img class="teacher-avatar-sm" src="assets/images/teachers/<?php echo e($tch['photo']); ?>" alt="">
|
||||
<?php else : ?>
|
||||
<span class="teacher-avatar-sm"><?php echo e(initials($tch['nameemployee'], $tch['surnameemployee'])); ?></span>
|
||||
<?php endif; ?>
|
||||
Insegnante: <strong><?php echo e(trim($tch['nameemployee'] . ' ' . $tch['surnameemployee'])); ?></strong>
|
||||
<?php else : ?>
|
||||
<span class="teacher-avatar-sm none"><i class="fas fa-user" style="font-size:10px;"></i></span>
|
||||
<span style="color:#e67e22;font-weight:600;">Insegnante non assegnato</span>
|
||||
<?php endif; ?>
|
||||
</p>
|
||||
<?php endif; ?>
|
||||
|
||||
<div class="class-toolbar">
|
||||
<button class="btn-soft btn-bookings" onclick="togglePanel(this)"><i class="fas fa-list-ul me-1"></i> Vedi prenotazioni</button>
|
||||
@@ -690,7 +542,7 @@ $italianMonths = [
|
||||
$ini = initials($b['first_name'] ?? '', $b['last_name'] ?? '');
|
||||
$avColor = avatarColor($fullName);
|
||||
?>
|
||||
<div class="booking-item <?php echo $isLost ? 'is-lost' : ''; ?>" data-iduser="<?php echo (int) $b['iduser']; ?>">
|
||||
<div class="booking-item <?php echo $isLost ? 'is-lost' : ''; ?>">
|
||||
<div class="avatar" style="background: <?php echo $isLost ? '#7f8c8d' : $avColor; ?>;"><?php echo e($ini); ?></div>
|
||||
<div class="booking-info">
|
||||
<span class="booking-name"><?php echo e($fullName); ?></span>
|
||||
@@ -714,62 +566,6 @@ $italianMonths = [
|
||||
<?php endif; ?>
|
||||
</div>
|
||||
|
||||
<?php if ($countPending > 0) : ?>
|
||||
<div class="bookings-header" style="margin-top:18px;">
|
||||
<span class="title" style="color:#8a6d00;"><i class="fas fa-hourglass-half me-1"></i> In attesa di conferma (<?php echo $countPending; ?>)</span>
|
||||
</div>
|
||||
<div class="booking-list">
|
||||
<?php foreach ($pendings as $b) :
|
||||
$idbc = (int) $b['idbookingclass'];
|
||||
$fullName = trim($b['first_name'] . ' ' . $b['last_name']);
|
||||
$ini = initials($b['first_name'] ?? '', $b['last_name'] ?? '');
|
||||
$avColor = avatarColor($fullName);
|
||||
?>
|
||||
<div class="booking-item" style="background:#fffbf0;border-color:#f5e6b8;" data-iduser="<?php echo (int) $b['iduser']; ?>">
|
||||
<div class="avatar" style="background: <?php echo $avColor; ?>;"><?php echo e($ini); ?></div>
|
||||
<div class="booking-info">
|
||||
<span class="booking-name"><?php echo e($fullName); ?></span>
|
||||
<span class="status-chip" style="background:#fff4d6;color:#8a6d00;">In attesa</span>
|
||||
</div>
|
||||
<div class="booking-actions">
|
||||
<button class="mini-btn restore confirm-pending" data-idbookingclass="<?php echo $idbc; ?>"><i class="fas fa-check"></i> Conferma</button>
|
||||
<button class="mini-btn remove" onclick="handleRemoveClick(<?php echo $idbc; ?>)"><i class="fas fa-trash"></i></button>
|
||||
</div>
|
||||
</div>
|
||||
<?php endforeach; ?>
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
|
||||
<?php if ($countWaiting > 0) : ?>
|
||||
<div class="bookings-header" style="margin-top:18px;">
|
||||
<span class="title" style="color:#d1698a;"><i class="fas fa-list-ol me-1"></i> Lista d'attesa (<?php echo $countWaiting; ?>)</span>
|
||||
</div>
|
||||
<div class="booking-list">
|
||||
<?php $qpos = 1;
|
||||
foreach ($waitings as $b) :
|
||||
$idbc = (int) $b['idbookingclass'];
|
||||
$fullName = trim($b['first_name'] . ' ' . $b['last_name']);
|
||||
$ini = initials($b['first_name'] ?? '', $b['last_name'] ?? '');
|
||||
$avColor = avatarColor($fullName);
|
||||
?>
|
||||
<div class="booking-item" style="background:#fdf4f8;border-color:#f0d6e2;" data-iduser="<?php echo (int) $b['iduser']; ?>">
|
||||
<div class="avatar" style="background: <?php echo $avColor; ?>;"><?php echo e($ini); ?></div>
|
||||
<div class="booking-info">
|
||||
<span class="booking-name">
|
||||
<span style="display:inline-block;min-width:22px;font-weight:800;color:#d1698a;"><?php echo $qpos; ?>°</span>
|
||||
<?php echo e($fullName); ?>
|
||||
</span>
|
||||
<span class="status-chip" style="background:#fbeef3;color:#d1698a;">In coda</span>
|
||||
</div>
|
||||
<div class="booking-actions">
|
||||
<button class="mini-btn remove" onclick="handleRemoveClick(<?php echo $idbc; ?>)"><i class="fas fa-trash"></i></button>
|
||||
</div>
|
||||
</div>
|
||||
<?php $qpos++;
|
||||
endforeach; ?>
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
|
||||
<div class="add-box">
|
||||
<strong class="d-block mb-2" style="font-size:14px;"><i class="fas fa-user-plus me-1" style="color:#1ebf73;"></i> Aggiungi partecipante</strong>
|
||||
<form class="add-booking-form" action="inserisci_record.php" method="post">
|
||||
@@ -848,42 +644,6 @@ $italianMonths = [
|
||||
}
|
||||
|
||||
$(document).ready(function() {
|
||||
// Filtro per tipologia di classe
|
||||
$(document).on('click', '.filter-chip', function() {
|
||||
var filter = $(this).data('filter');
|
||||
$('.filter-chip').removeClass('active');
|
||||
$(this).addClass('active');
|
||||
$('.class-card').each(function() {
|
||||
var show = (filter === '__all__') || ($(this).data('type') === filter);
|
||||
$(this).toggle(show);
|
||||
});
|
||||
});
|
||||
|
||||
// Scroll automatico alla classe di oggi o alla prima futura
|
||||
(function scrollToToday() {
|
||||
var cards = document.querySelectorAll('.class-card[data-date]');
|
||||
if (!cards.length) return;
|
||||
var today = new Date();
|
||||
today.setHours(0, 0, 0, 0);
|
||||
var target = null;
|
||||
for (var i = 0; i < cards.length; i++) {
|
||||
var d = new Date(cards[i].getAttribute('data-date') + 'T00:00:00');
|
||||
if (d >= today) {
|
||||
target = cards[i];
|
||||
break;
|
||||
}
|
||||
target = cards[i]; // se tutte passate, resta sull'ultima
|
||||
}
|
||||
if (target) {
|
||||
setTimeout(function() {
|
||||
target.scrollIntoView({
|
||||
behavior: 'smooth',
|
||||
block: 'start'
|
||||
});
|
||||
}, 200);
|
||||
}
|
||||
})();
|
||||
|
||||
$(document).on('click', '.mini-btn.lost', function() {
|
||||
var id = $(this).data('idbookingclass');
|
||||
Swal.fire({
|
||||
@@ -901,7 +661,7 @@ $italianMonths = [
|
||||
}
|
||||
});
|
||||
});
|
||||
$(document).on('click', '.mini-btn.restore:not(.confirm-pending)', function() {
|
||||
$(document).on('click', '.mini-btn.restore', function() {
|
||||
var id = $(this).data('idbookingclass');
|
||||
Swal.fire({
|
||||
title: 'Ripristinare questa lezione?',
|
||||
@@ -918,25 +678,6 @@ $italianMonths = [
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
$(document).on('click', '.confirm-pending', function() {
|
||||
var id = $(this).data('idbookingclass');
|
||||
Swal.fire({
|
||||
title: 'Confermare la prenotazione?',
|
||||
text: 'La lezione passerà da "in attesa" a confermata.',
|
||||
icon: 'question',
|
||||
showCancelButton: true,
|
||||
confirmButtonText: 'Sì, conferma',
|
||||
cancelButtonText: 'Annulla'
|
||||
})
|
||||
.then((r) => {
|
||||
if (r.isConfirmed) {
|
||||
$.post('conferma_pending.php', {
|
||||
idbookingclass: id
|
||||
}).done(() => window.location.href = 'adminpanel.php?success=5').fail(() => Swal.fire('Errore durante la conferma', '', 'error'));
|
||||
}
|
||||
});
|
||||
});
|
||||
$(document).on('click', '.mini-btn.reprogram', function() {
|
||||
var idbookingclass = $(this).data('idbookingclass');
|
||||
$.ajax({
|
||||
@@ -1014,163 +755,6 @@ $italianMonths = [
|
||||
});
|
||||
});
|
||||
|
||||
// === Intercetta submit "Aggiungi partecipante" ===
|
||||
$(document).on('submit', '.add-booking-form', function(e) {
|
||||
e.preventDefault();
|
||||
const form = $(this);
|
||||
const userid = form.find('.userid').val();
|
||||
const name = form.find('.name').val().trim();
|
||||
const surname = form.find('.surname').val().trim();
|
||||
|
||||
if (!name || !surname) {
|
||||
Swal.fire('Dati mancanti', 'Inserisci nome e cognome.', 'warning');
|
||||
return;
|
||||
}
|
||||
|
||||
const hasUser = userid && parseInt(userid) > 0;
|
||||
|
||||
// Controllo anti-duplicato PRIMA di aprire il modale:
|
||||
// l'utente è già presente in questa classe?
|
||||
if (hasUser) {
|
||||
const panel = form.closest('.bookings-panel');
|
||||
const already = panel.find('.booking-item[data-iduser="' + parseInt(userid) + '"]').length > 0;
|
||||
if (already) {
|
||||
Swal.fire(
|
||||
'Già prenotato',
|
||||
'Questa persona è già presente in questa classe.',
|
||||
'info'
|
||||
);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (hasUser) {
|
||||
$.getJSON('get_user_orders.php', {
|
||||
userid: userid
|
||||
}).done(function(data) {
|
||||
showBookingModal(form, data.orders || []);
|
||||
}).fail(function() {
|
||||
showBookingModal(form, []);
|
||||
});
|
||||
} else {
|
||||
showBookingModal(form, []);
|
||||
}
|
||||
});
|
||||
|
||||
function showBookingModal(form, orders) {
|
||||
const usableOrders = orders.filter(o => o.remaining > 0);
|
||||
let orderOptions = '';
|
||||
usableOrders.forEach(function(o) {
|
||||
const exp = o.expireon ? ' - scade ' + o.expireon : '';
|
||||
orderOptions += '<option value="' + o.idorderbook + '">' +
|
||||
o.service_name + ' (' + o.remaining + '/' + o.tickets + ' residui)' + exp +
|
||||
'</option>';
|
||||
});
|
||||
|
||||
const hasUsableOrders = usableOrders.length > 0;
|
||||
|
||||
const d = new Date();
|
||||
d.setMonth(d.getMonth() + 3);
|
||||
const defExpiry = d.toISOString().slice(0, 10);
|
||||
|
||||
const html =
|
||||
'<div style="text-align:left;">' +
|
||||
'<label style="display:block;margin:8px 0;">' +
|
||||
'<input type="radio" name="bkmode" value="scala" ' + (hasUsableOrders ? 'checked' : 'disabled') + '> ' +
|
||||
'<strong>Scala da un pacchetto</strong>' + (hasUsableOrders ? '' : ' (nessun pacchetto con residui)') +
|
||||
'</label>' +
|
||||
'<select id="bk-order" class="form-control" style="margin:6px 0 14px;" ' + (hasUsableOrders ? '' : 'disabled') + '>' +
|
||||
orderOptions +
|
||||
'</select>' +
|
||||
'<label style="display:block;margin:8px 0;">' +
|
||||
'<input type="radio" name="bkmode" value="omaggio" ' + (hasUsableOrders ? '' : 'checked') + '> ' +
|
||||
'<strong>Aggiungi come omaggio</strong> <span style="color:#6b7280;font-size:12px;">(non consuma pacchetti, non spostabile)</span>' +
|
||||
'</label>' +
|
||||
'<label style="display:block;margin:8px 0;">' +
|
||||
'<input type="radio" name="bkmode" value="nuovo"> ' +
|
||||
'<strong>Crea nuovo ordine</strong> <span style="color:#6b7280;font-size:12px;">(1 lezione)</span>' +
|
||||
'</label>' +
|
||||
'<div id="bk-nuovo-fields" style="display:none;margin:6px 0 0;padding-left:22px;">' +
|
||||
'<label style="font-size:13px;">Scadenza ordine:</label>' +
|
||||
'<input type="date" id="bk-expiry" class="form-control" value="' + defExpiry + '">' +
|
||||
'</div>' +
|
||||
'</div>';
|
||||
|
||||
Swal.fire({
|
||||
title: 'Aggiungi partecipante',
|
||||
html: html,
|
||||
showCancelButton: true,
|
||||
confirmButtonText: 'Inserisci',
|
||||
cancelButtonText: 'Annulla',
|
||||
confirmButtonColor: '#1ebf73',
|
||||
didOpen: () => {
|
||||
document.querySelectorAll('input[name="bkmode"]').forEach(function(r) {
|
||||
r.addEventListener('change', function() {
|
||||
document.getElementById('bk-nuovo-fields').style.display =
|
||||
(this.value === 'nuovo') ? 'block' : 'none';
|
||||
});
|
||||
});
|
||||
},
|
||||
preConfirm: () => {
|
||||
const mode = document.querySelector('input[name="bkmode"]:checked');
|
||||
if (!mode) {
|
||||
Swal.showValidationMessage('Seleziona una modalità');
|
||||
return false;
|
||||
}
|
||||
const result = {
|
||||
mode: mode.value
|
||||
};
|
||||
if (mode.value === 'scala') {
|
||||
const sel = document.getElementById('bk-order').value;
|
||||
if (!sel) {
|
||||
Swal.showValidationMessage('Seleziona un pacchetto');
|
||||
return false;
|
||||
}
|
||||
result.idorder = sel;
|
||||
}
|
||||
if (mode.value === 'nuovo') {
|
||||
const exp = document.getElementById('bk-expiry').value;
|
||||
if (!exp) {
|
||||
Swal.showValidationMessage('Inserisci la scadenza');
|
||||
return false;
|
||||
}
|
||||
result.expiry = exp;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
}).then((res) => {
|
||||
if (!res.isConfirmed) return;
|
||||
submitBooking(form, res.value);
|
||||
});
|
||||
}
|
||||
|
||||
function submitBooking(form, choice) {
|
||||
form.find('input[name="bkmode"]').remove();
|
||||
form.find('input[name="new_expiry"]').remove();
|
||||
|
||||
$('<input>').attr({
|
||||
type: 'hidden',
|
||||
name: 'bkmode',
|
||||
value: choice.mode
|
||||
}).appendTo(form);
|
||||
|
||||
if (choice.mode === 'scala') {
|
||||
form.find('input[name="idorder"]').val(choice.idorder);
|
||||
} else if (choice.mode === 'omaggio') {
|
||||
form.find('input[name="idorder"]').val('');
|
||||
} else if (choice.mode === 'nuovo') {
|
||||
form.find('input[name="idorder"]').val('');
|
||||
$('<input>').attr({
|
||||
type: 'hidden',
|
||||
name: 'new_expiry',
|
||||
value: choice.expiry
|
||||
}).appendTo(form);
|
||||
}
|
||||
|
||||
form.off('submit');
|
||||
form[0].submit();
|
||||
}
|
||||
|
||||
let searchTimeout;
|
||||
$(document).on('input', '.surname, .name', function() {
|
||||
clearTimeout(searchTimeout);
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
ini_set('display_errors', 1);
|
||||
error_reporting(E_ALL);
|
||||
header('Content-Type: application/json');
|
||||
|
||||
require_once dirname(__DIR__) . '/class/db-functions.php';
|
||||
|
||||
@@ -1,33 +0,0 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* api_me_role.php
|
||||
* --------------------------------------------------------------------------
|
||||
* Restituisce il ruolo dell'utente autenticato e un flag comodo
|
||||
* "is_staff" (Admin o teacher) per abilitare le funzioni insegnante nell'app.
|
||||
*
|
||||
* Posizione: public/api/api_me_role.php
|
||||
* Metodo: GET
|
||||
* Auth: Bearer token (Sanctum) via _bootstrap.php
|
||||
* --------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
require_once __DIR__ . '/_bootstrap.php';
|
||||
|
||||
$roleId = (int) $user->role_id;
|
||||
|
||||
// nome ruolo da auth_roles (per debug / display)
|
||||
$stmt = $db->prepare("SELECT name FROM auth_roles WHERE id = :rid LIMIT 1");
|
||||
$stmt->execute([':rid' => $roleId]);
|
||||
$roleRow = $stmt->fetch(PDO::FETCH_ASSOC);
|
||||
$roleName = $roleRow ? (string) $roleRow['name'] : '';
|
||||
|
||||
// Admin = 1, teacher = 3 → staff (accesso pannello classi)
|
||||
$isStaff = in_array($roleId, [1, 3], true);
|
||||
|
||||
echo json_encode([
|
||||
'success' => true,
|
||||
'role_id' => $roleId,
|
||||
'role_name' => $roleName,
|
||||
'is_staff' => $isStaff,
|
||||
], JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES);
|
||||
@@ -1,91 +0,0 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* api_medical_certificates_delete.php
|
||||
* --------------------------------------------------------------------------
|
||||
* Elimina un certificato medico dell'utente autenticato (con ownership check).
|
||||
*
|
||||
* Posizione: public/api/api_medical_certificates_delete.php
|
||||
* Metodo: POST
|
||||
* Auth: Bearer token (Sanctum) via _bootstrap.php
|
||||
*
|
||||
* Body:
|
||||
* - cert_id (int) id del certificato (idcertificateuserprofile)
|
||||
* accettato sia via form-urlencoded sia via JSON.
|
||||
*
|
||||
* Tabella: certificateuserprofile
|
||||
* --------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
require_once __DIR__ . '/_bootstrap.php';
|
||||
$userId = (int) $user->id;
|
||||
|
||||
$uploadDir = __DIR__ . '/../user/document/';
|
||||
|
||||
// ==========================================================================
|
||||
// INPUT (JSON o form-urlencoded)
|
||||
// ==========================================================================
|
||||
$raw = file_get_contents('php://input');
|
||||
$json = json_decode($raw, true);
|
||||
if (is_array($json) && isset($json['cert_id'])) {
|
||||
$certId = (int) $json['cert_id'];
|
||||
} else {
|
||||
$certId = (int) ($_POST['cert_id'] ?? 0);
|
||||
}
|
||||
|
||||
if ($certId <= 0) {
|
||||
http_response_code(400);
|
||||
echo json_encode(['success' => false, 'message' => 'Parametro cert_id mancante.']);
|
||||
exit;
|
||||
}
|
||||
|
||||
// ==========================================================================
|
||||
// 1) Recupera il certificato e verifica ownership
|
||||
// ==========================================================================
|
||||
$stmt = $db->prepare("
|
||||
SELECT idcertificateuserprofile, filenamedocument
|
||||
FROM certificateuserprofile
|
||||
WHERE idcertificateuserprofile = :cid AND iduser = :uid
|
||||
LIMIT 1
|
||||
");
|
||||
$stmt->execute([':cid' => $certId, ':uid' => $userId]);
|
||||
$cert = $stmt->fetch();
|
||||
|
||||
if (!$cert) {
|
||||
http_response_code(404);
|
||||
echo json_encode(['success' => false, 'message' => 'Certificato non trovato.']);
|
||||
exit;
|
||||
}
|
||||
|
||||
// ==========================================================================
|
||||
// 2) Elimina record + file
|
||||
// ==========================================================================
|
||||
try {
|
||||
$del = $db->prepare("
|
||||
DELETE FROM certificateuserprofile
|
||||
WHERE idcertificateuserprofile = :cid AND iduser = :uid
|
||||
LIMIT 1
|
||||
");
|
||||
$del->execute([':cid' => $certId, ':uid' => $userId]);
|
||||
} catch (Throwable $e) {
|
||||
http_response_code(500);
|
||||
echo json_encode(['success' => false, 'message' => 'Errore durante la cancellazione.']);
|
||||
exit;
|
||||
}
|
||||
|
||||
// Rimuovi il file fisico (best effort)
|
||||
$filename = (string) ($cert['filenamedocument'] ?? '');
|
||||
if ($filename !== '') {
|
||||
$path = $uploadDir . $filename;
|
||||
if (is_file($path)) {
|
||||
@unlink($path);
|
||||
}
|
||||
}
|
||||
|
||||
// ==========================================================================
|
||||
// OUTPUT
|
||||
// ==========================================================================
|
||||
echo json_encode([
|
||||
'success' => true,
|
||||
'message' => 'Certificato eliminato.',
|
||||
], JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES);
|
||||
@@ -1,54 +0,0 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* api_medical_certificates_list.php
|
||||
* --------------------------------------------------------------------------
|
||||
* Restituisce i certificati medici dell'utente autenticato.
|
||||
*
|
||||
* Posizione: public/api/api_medical_certificates_list.php
|
||||
* Metodo: GET
|
||||
* Auth: Bearer token (Sanctum) via _bootstrap.php
|
||||
*
|
||||
* Tabella: certificateuserprofile
|
||||
* idcertificateuserprofile, documentdescription, filenamedocument,
|
||||
* iduser, expirydatedocument, uploaded_at
|
||||
* --------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
require_once __DIR__ . '/_bootstrap.php';
|
||||
$userId = (int) $user->id;
|
||||
|
||||
$today = date('Y-m-d');
|
||||
|
||||
$stmt = $db->prepare("
|
||||
SELECT idcertificateuserprofile, documentdescription, filenamedocument,
|
||||
expirydatedocument, uploaded_at
|
||||
FROM certificateuserprofile
|
||||
WHERE iduser = :uid
|
||||
ORDER BY uploaded_at DESC, idcertificateuserprofile DESC
|
||||
");
|
||||
$stmt->execute([':uid' => $userId]);
|
||||
$rows = $stmt->fetchAll();
|
||||
|
||||
$certificates = [];
|
||||
foreach ($rows as $r) {
|
||||
$filename = (string) ($r['filenamedocument'] ?? '');
|
||||
$expiry = $r['expirydatedocument'] ?? null;
|
||||
$isExpired = ($expiry !== null && $expiry !== '' && $expiry < $today);
|
||||
|
||||
$certificates[] = [
|
||||
'id' => (int) $r['idcertificateuserprofile'],
|
||||
'document_name' => (string) ($r['documentdescription'] ?? ''),
|
||||
'filename' => $filename,
|
||||
'uploaded_at' => $r['uploaded_at'] ?? null,
|
||||
'expiry_date' => $expiry,
|
||||
'is_expired' => $isExpired,
|
||||
// percorso file relativo (la webapp li serve da public/user/document/)
|
||||
'file_url' => $filename !== '' ? '/user/document/' . $filename : null,
|
||||
];
|
||||
}
|
||||
|
||||
echo json_encode([
|
||||
'success' => true,
|
||||
'certificates' => $certificates,
|
||||
], JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES);
|
||||
@@ -1,137 +0,0 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* api_medical_certificates_upload.php
|
||||
* --------------------------------------------------------------------------
|
||||
* Carica un certificato medico per l'utente autenticato.
|
||||
*
|
||||
* Posizione: public/api/api_medical_certificates_upload.php
|
||||
* Metodo: POST (multipart/form-data)
|
||||
* Auth: Bearer token (Sanctum) via _bootstrap.php
|
||||
*
|
||||
* Campi attesi (form-data):
|
||||
* - certificate (file) campo file (PDF/JPG/PNG, max 16MB)
|
||||
* - document_name (text) descrizione documento
|
||||
* - expiry_date (text) YYYY-MM-DD
|
||||
*
|
||||
* Logica ricalcata da certificate.php (webapp).
|
||||
* Tabella: certificateuserprofile
|
||||
* --------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
require_once __DIR__ . '/_bootstrap.php';
|
||||
$userId = (int) $user->id;
|
||||
|
||||
// La cartella upload è public/user/document/. Questo file sta in public/api/,
|
||||
// quindi saliamo di un livello.
|
||||
$uploadDir = __DIR__ . '/../user/document/';
|
||||
|
||||
$allowedExt = ['pdf', 'jpg', 'jpeg', 'png'];
|
||||
$allowedMime = ['application/pdf', 'image/jpeg', 'image/png'];
|
||||
$maxBytes = 16 * 1024 * 1024; // 16 MB
|
||||
|
||||
// ==========================================================================
|
||||
// INPUT
|
||||
// ==========================================================================
|
||||
$documentName = trim($_POST['document_name'] ?? '');
|
||||
$expiryDate = trim($_POST['expiry_date'] ?? '');
|
||||
|
||||
if ($documentName === '') {
|
||||
$documentName = 'Certificato Medico';
|
||||
}
|
||||
|
||||
if ($expiryDate === '') {
|
||||
http_response_code(400);
|
||||
echo json_encode(['success' => false, 'message' => 'Data di scadenza obbligatoria.']);
|
||||
exit;
|
||||
}
|
||||
|
||||
// Validazione formato data YYYY-MM-DD
|
||||
$d = DateTime::createFromFormat('Y-m-d', $expiryDate);
|
||||
if ($d === false || $d->format('Y-m-d') !== $expiryDate) {
|
||||
http_response_code(400);
|
||||
echo json_encode(['success' => false, 'message' => 'Formato data non valido (YYYY-MM-DD).']);
|
||||
exit;
|
||||
}
|
||||
|
||||
// File
|
||||
if (!isset($_FILES['certificate']) || $_FILES['certificate']['error'] !== UPLOAD_ERR_OK) {
|
||||
http_response_code(400);
|
||||
echo json_encode(['success' => false, 'message' => 'Nessun file ricevuto o errore upload.']);
|
||||
exit;
|
||||
}
|
||||
|
||||
$file = $_FILES['certificate'];
|
||||
|
||||
if ($file['size'] > $maxBytes) {
|
||||
http_response_code(400);
|
||||
echo json_encode(['success' => false, 'message' => 'Il file supera i 16 MB.']);
|
||||
exit;
|
||||
}
|
||||
|
||||
$ext = strtolower(pathinfo($file['name'], PATHINFO_EXTENSION));
|
||||
$finfo = new finfo(FILEINFO_MIME_TYPE);
|
||||
$realMime = $finfo->file($file['tmp_name']);
|
||||
|
||||
if (!in_array($ext, $allowedExt, true) || !in_array($realMime, $allowedMime, true)) {
|
||||
http_response_code(400);
|
||||
echo json_encode(['success' => false, 'message' => 'Formato non consentito. Usa PDF, JPG o PNG.']);
|
||||
exit;
|
||||
}
|
||||
|
||||
// ==========================================================================
|
||||
// SALVATAGGIO FILE
|
||||
// ==========================================================================
|
||||
if (!is_dir($uploadDir)) {
|
||||
@mkdir($uploadDir, 0755, true);
|
||||
}
|
||||
|
||||
$safeName = bin2hex(random_bytes(16)) . '.' . $ext;
|
||||
$destination = $uploadDir . $safeName;
|
||||
|
||||
if (!move_uploaded_file($file['tmp_name'], $destination)) {
|
||||
http_response_code(500);
|
||||
echo json_encode(['success' => false, 'message' => 'Salvataggio del file non riuscito.']);
|
||||
exit;
|
||||
}
|
||||
|
||||
// ==========================================================================
|
||||
// INSERT DB
|
||||
// ==========================================================================
|
||||
try {
|
||||
$sql = "INSERT INTO certificateuserprofile
|
||||
(iduser, documentdescription, filenamedocument, expirydatedocument, uploaded_at)
|
||||
VALUES (:iduser, :descr, :fname, :expiry, :uploaded)";
|
||||
$stmt = $db->prepare($sql);
|
||||
$stmt->execute([
|
||||
':iduser' => $userId,
|
||||
':descr' => $documentName,
|
||||
':fname' => $safeName,
|
||||
':expiry' => $expiryDate,
|
||||
':uploaded' => date('Y-m-d'),
|
||||
]);
|
||||
$newId = (int) $db->lastInsertId();
|
||||
} catch (Throwable $e) {
|
||||
// rollback file se l'insert fallisce
|
||||
@unlink($destination);
|
||||
http_response_code(500);
|
||||
echo json_encode(['success' => false, 'message' => 'Errore nel salvataggio del documento.']);
|
||||
exit;
|
||||
}
|
||||
|
||||
// ==========================================================================
|
||||
// OUTPUT
|
||||
// ==========================================================================
|
||||
echo json_encode([
|
||||
'success' => true,
|
||||
'message' => 'Documento caricato correttamente.',
|
||||
'certificate' => [
|
||||
'id' => $newId,
|
||||
'document_name' => $documentName,
|
||||
'filename' => $safeName,
|
||||
'uploaded_at' => date('Y-m-d'),
|
||||
'expiry_date' => $expiryDate,
|
||||
'is_expired' => false,
|
||||
'file_url' => '/user/document/' . $safeName,
|
||||
],
|
||||
], JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES);
|
||||
@@ -1,255 +0,0 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* api_teacher_add_booking.php
|
||||
* --------------------------------------------------------------------------
|
||||
* Inserisce un partecipante in una classe. Solo staff (Admin=1 / teacher=3).
|
||||
* Replica inserisci_record.php della webapp (risposta JSON invece di redirect).
|
||||
*
|
||||
* Posizione: public/api/api_teacher_add_booking.php
|
||||
* Metodo: POST
|
||||
* Auth: Bearer token (Sanctum) via _bootstrap.php
|
||||
*
|
||||
* Body:
|
||||
* idserviceschedule=<int> classe destinazione
|
||||
* idservice=<int> servizio della classe
|
||||
* bookingstart=<datetime> data/ora lezione (dateschedule)
|
||||
* bkmode=<scala|omaggio|nuovo>
|
||||
* user_id=<int> utente esistente (0 se nuovo)
|
||||
* name, surname, email per creare l'utente se user_id=0
|
||||
* idorder=<int> solo per 'scala'
|
||||
* new_expiry=<YYYY-MM-DD> solo per 'nuovo'
|
||||
*
|
||||
* Regole identiche alla webapp:
|
||||
* - status sempre 'booked'
|
||||
* - omaggio: idorder NULL, is_gift='Y'
|
||||
* - nuovo: crea orderbook (1 ticket, maxreschedule 0), is_gift='N'
|
||||
* - scala: aggancia ordine esistente (verifica proprietà + scadenza)
|
||||
* - idorder mai 0 (FK): NULL o id reale
|
||||
* - crea utente se user_id=0 (riusa email esistente)
|
||||
* - anti-duplicato: stesso utente già in questa classe
|
||||
* --------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
require_once __DIR__ . '/_bootstrap.php';
|
||||
|
||||
// Gate staff
|
||||
$roleId = (int) $user->role_id;
|
||||
if (!in_array($roleId, [1, 3], true)) {
|
||||
http_response_code(403);
|
||||
echo json_encode(['success' => false, 'message' => 'Forbidden']);
|
||||
exit;
|
||||
}
|
||||
|
||||
// --- Input ---
|
||||
$name = trim($_POST['name'] ?? '');
|
||||
$surname = trim($_POST['surname'] ?? '');
|
||||
$email = trim($_POST['email'] ?? '');
|
||||
$userid = isset($_POST['user_id']) ? (int) $_POST['user_id'] : 0;
|
||||
$idserviceschedule = isset($_POST['idserviceschedule']) ? (int) $_POST['idserviceschedule'] : 0;
|
||||
$idservice = isset($_POST['idservice']) ? (int) $_POST['idservice'] : 0;
|
||||
$bookingstart = trim($_POST['bookingstart'] ?? '');
|
||||
$bkmode = trim($_POST['bkmode'] ?? 'scala'); // scala | omaggio | nuovo
|
||||
$idorderRaw = $_POST['idorder'] ?? '';
|
||||
$newExpiry = trim($_POST['new_expiry'] ?? '');
|
||||
|
||||
$status = 'booked'; // inserimento da insegnante: sempre booked
|
||||
|
||||
// --- Validazione minima ---
|
||||
if ($idserviceschedule <= 0 || $idservice <= 0) {
|
||||
http_response_code(400);
|
||||
echo json_encode(['success' => false, 'message' => 'Dati mancanti (classe/servizio)']);
|
||||
exit;
|
||||
}
|
||||
// Se nuovo utente, servono almeno nome e cognome
|
||||
if ($userid <= 0 && ($name === '' || $surname === '')) {
|
||||
http_response_code(400);
|
||||
echo json_encode(['success' => false, 'message' => 'Nome e cognome obbligatori per un nuovo utente']);
|
||||
exit;
|
||||
}
|
||||
|
||||
try {
|
||||
$db->beginTransaction();
|
||||
|
||||
// ------------------------------------------------------------------
|
||||
// 1) Risolvi / crea utente
|
||||
// ------------------------------------------------------------------
|
||||
if ($userid <= 0) {
|
||||
if ($email !== '') {
|
||||
$check = $db->prepare("SELECT id FROM auth_users WHERE email = :email LIMIT 1");
|
||||
$check->execute([':email' => $email]);
|
||||
$existing = $check->fetchColumn();
|
||||
if ($existing) {
|
||||
$userid = (int) $existing;
|
||||
}
|
||||
}
|
||||
|
||||
if ($userid <= 0) {
|
||||
$randomPassword = bin2hex(random_bytes(8));
|
||||
$hashed = password_hash($randomPassword, PASSWORD_BCRYPT);
|
||||
|
||||
$insUser = $db->prepare(
|
||||
"INSERT INTO auth_users
|
||||
(first_name, last_name, email, password, role_id, status, created_at, avatar)
|
||||
VALUES
|
||||
(:first, :last, :email, :password, :role, :status, :created, :avatar)"
|
||||
);
|
||||
$insUser->execute([
|
||||
':first' => $name,
|
||||
':last' => $surname,
|
||||
':email' => $email !== '' ? $email : null,
|
||||
':password' => $hashed,
|
||||
':role' => 2,
|
||||
':status' => 'Active',
|
||||
':created' => date('Y-m-d H:i:s'),
|
||||
':avatar' => 'mediationb.png',
|
||||
]);
|
||||
$userid = (int) $db->lastInsertId();
|
||||
}
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------
|
||||
// 2) Determina idorder e is_gift in base alla modalità
|
||||
// ------------------------------------------------------------------
|
||||
$idorder = null;
|
||||
$isGift = 'N';
|
||||
|
||||
if ($bkmode === 'omaggio') {
|
||||
$idorder = null;
|
||||
$isGift = 'Y';
|
||||
} elseif ($bkmode === 'nuovo') {
|
||||
if ($newExpiry === '') {
|
||||
throw new RuntimeException('Scadenza mancante per il nuovo ordine.');
|
||||
}
|
||||
|
||||
$uStmt = $db->prepare(
|
||||
"SELECT first_name, last_name, email FROM auth_users WHERE id = :uid LIMIT 1"
|
||||
);
|
||||
$uStmt->execute([':uid' => $userid]);
|
||||
$uRow = $uStmt->fetch(PDO::FETCH_ASSOC) ?: [];
|
||||
$uEmail = $uRow['email'] ?? ($email !== '' ? $email : null);
|
||||
$uFirst = $uRow['first_name'] ?? $name;
|
||||
$uLast = $uRow['last_name'] ?? $surname;
|
||||
|
||||
$sStmt = $db->prepare(
|
||||
"SELECT servicename FROM service WHERE idservice = :sid LIMIT 1"
|
||||
);
|
||||
$sStmt->execute([':sid' => $idservice]);
|
||||
$serviceName = (string) ($sStmt->fetchColumn() ?: '');
|
||||
|
||||
$firstLessonDate = null;
|
||||
if ($bookingstart !== '') {
|
||||
try {
|
||||
$firstLessonDate = (new DateTime($bookingstart))->format('Y-m-d');
|
||||
} catch (Throwable $e) {
|
||||
$firstLessonDate = null;
|
||||
}
|
||||
}
|
||||
|
||||
$insOrder = $db->prepare(
|
||||
"INSERT INTO orderbook
|
||||
(iduser, idservice, nticket, quantity, quantityclass,
|
||||
expireon, maxreschedule, reprogrammed, status,
|
||||
order_billing_email, cod, product_name,
|
||||
first_name, last_name, first_lesson_date, order_date_created)
|
||||
VALUES
|
||||
(:uid, :service, 1, 1, 1,
|
||||
:expire, 0, 0, 'booked',
|
||||
:bemail, :cod, :pname,
|
||||
:first, :last, :firstlesson, :created)"
|
||||
);
|
||||
$insOrder->execute([
|
||||
':uid' => $userid,
|
||||
':service' => $idservice,
|
||||
':expire' => $newExpiry,
|
||||
':bemail' => $uEmail,
|
||||
':cod' => $serviceName,
|
||||
':pname' => $serviceName,
|
||||
':first' => $uFirst,
|
||||
':last' => $uLast,
|
||||
':firstlesson' => $firstLessonDate,
|
||||
':created' => date('Y-m-d'),
|
||||
]);
|
||||
$idorder = (int) $db->lastInsertId();
|
||||
$isGift = 'N';
|
||||
} else {
|
||||
// 'scala'
|
||||
$idorder = ($idorderRaw !== '' && (int) $idorderRaw > 0) ? (int) $idorderRaw : null;
|
||||
|
||||
if ($idorder !== null) {
|
||||
$chk = $db->prepare(
|
||||
"SELECT expireon FROM orderbook
|
||||
WHERE idorderbook = :oid AND iduser = :uid LIMIT 1"
|
||||
);
|
||||
$chk->execute([':oid' => $idorder, ':uid' => $userid]);
|
||||
$row = $chk->fetch(PDO::FETCH_ASSOC);
|
||||
if (!$row) {
|
||||
throw new RuntimeException('Ordine non valido per questo utente.');
|
||||
}
|
||||
$exp = $row['expireon'] ?? null;
|
||||
if ($exp !== null && $exp < date('Y-m-d')) {
|
||||
throw new RuntimeException('Il pacchetto selezionato è scaduto.');
|
||||
}
|
||||
} else {
|
||||
throw new RuntimeException('Nessun pacchetto selezionato.');
|
||||
}
|
||||
$isGift = 'N';
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------
|
||||
// 2b) Anti-duplicato
|
||||
// ------------------------------------------------------------------
|
||||
$dup = $db->prepare(
|
||||
"SELECT status FROM bookingclass
|
||||
WHERE iduser = :uid
|
||||
AND idserviceschedule = :idschedule
|
||||
AND status != 'cancelled'
|
||||
LIMIT 1"
|
||||
);
|
||||
$dup->execute([':uid' => $userid, ':idschedule' => $idserviceschedule]);
|
||||
$dupStatus = $dup->fetchColumn();
|
||||
if ($dupStatus !== false) {
|
||||
$db->rollBack();
|
||||
http_response_code(409);
|
||||
$msg = ($dupStatus === 'pending')
|
||||
? 'Questo utente ha una prenotazione in attesa in questa classe: confermala o rimuovila dalla sezione "In attesa".'
|
||||
: 'Questo utente è già prenotato in questa classe.';
|
||||
echo json_encode(['success' => false, 'message' => $msg]);
|
||||
exit;
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------
|
||||
// 3) Inserimento prenotazione
|
||||
// ------------------------------------------------------------------
|
||||
$insBooking = $db->prepare(
|
||||
"INSERT INTO bookingclass
|
||||
(iduser, idserviceschedule, status, idorder, idservice, bookingstart, is_gift)
|
||||
VALUES
|
||||
(:iduser, :idschedule, :status, :idorder, :idservice, :bookingstart, :isgift)"
|
||||
);
|
||||
$insBooking->execute([
|
||||
':iduser' => $userid,
|
||||
':idschedule' => $idserviceschedule,
|
||||
':status' => $status,
|
||||
':idorder' => $idorder,
|
||||
':idservice' => $idservice,
|
||||
':bookingstart' => $bookingstart !== '' ? $bookingstart : null,
|
||||
':isgift' => $isGift,
|
||||
]);
|
||||
|
||||
$db->commit();
|
||||
|
||||
echo json_encode([
|
||||
'success' => true,
|
||||
'user_id' => $userid,
|
||||
'is_gift' => $isGift,
|
||||
'idorder' => $idorder,
|
||||
], JSON_UNESCAPED_UNICODE);
|
||||
} catch (Throwable $ex) {
|
||||
if ($db->inTransaction()) {
|
||||
$db->rollBack();
|
||||
}
|
||||
error_log('api_teacher_add_booking error: ' . $ex->getMessage());
|
||||
http_response_code(500);
|
||||
echo json_encode(['success' => false, 'message' => 'Errore inserimento: ' . $ex->getMessage()]);
|
||||
}
|
||||
@@ -1,109 +0,0 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* api_teacher_available_classes.php
|
||||
* --------------------------------------------------------------------------
|
||||
* Classi schedulate candidate come destinazione di una riprogrammazione.
|
||||
* Solo staff (Admin=1 / teacher=3).
|
||||
*
|
||||
* Restituisce le classi FUTURE con posti liberi (non piene), escludendo
|
||||
* quelle dove l'allievo indicato è già prenotato.
|
||||
*
|
||||
* Posizione: public/api/api_teacher_available_classes.php
|
||||
* Metodo: GET
|
||||
* Auth: Bearer token (Sanctum) via _bootstrap.php
|
||||
* Query: ?booking_id=<int> (la prenotazione che si vuole spostare)
|
||||
* --------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
require_once __DIR__ . '/_bootstrap.php';
|
||||
|
||||
// Gate staff
|
||||
$roleId = (int) $user->role_id;
|
||||
if (!in_array($roleId, [1, 3], true)) {
|
||||
http_response_code(403);
|
||||
echo json_encode(['success' => false, 'message' => 'Forbidden']);
|
||||
exit;
|
||||
}
|
||||
|
||||
$bookingId = isset($_GET['booking_id']) ? (int) $_GET['booking_id'] : 0;
|
||||
if ($bookingId <= 0) {
|
||||
http_response_code(400);
|
||||
echo json_encode(['success' => false, 'message' => 'ID prenotazione non valido']);
|
||||
exit;
|
||||
}
|
||||
|
||||
try {
|
||||
// Trova utente e classe attuale della prenotazione da spostare
|
||||
$stmt = $db->prepare(
|
||||
"SELECT iduser, idserviceschedule
|
||||
FROM bookingclass
|
||||
WHERE idbookingclass = :id
|
||||
LIMIT 1"
|
||||
);
|
||||
$stmt->execute([':id' => $bookingId]);
|
||||
$booking = $stmt->fetch(PDO::FETCH_ASSOC);
|
||||
|
||||
if (!$booking) {
|
||||
http_response_code(404);
|
||||
echo json_encode(['success' => false, 'message' => 'Prenotazione non trovata']);
|
||||
exit;
|
||||
}
|
||||
|
||||
$iduser = (int) $booking['iduser'];
|
||||
$currentSchedule = (int) $booking['idserviceschedule'];
|
||||
|
||||
// Classi future con conteggio prenotati (status='booked', coerente col pannello)
|
||||
$sql = "SELECT
|
||||
ss.idserviceschedule,
|
||||
ss.idservice,
|
||||
s.servicename,
|
||||
COALESCE(s.maxcapacity, 0) AS maxcapacity,
|
||||
ss.dateschedule,
|
||||
(SELECT COUNT(*) FROM bookingclass bc
|
||||
WHERE bc.idserviceschedule = ss.idserviceschedule
|
||||
AND bc.status = 'booked') AS booked_count,
|
||||
(SELECT COUNT(*) FROM bookingclass bc2
|
||||
WHERE bc2.idserviceschedule = ss.idserviceschedule
|
||||
AND bc2.iduser = :iduser
|
||||
AND bc2.status = 'booked') AS already_here
|
||||
FROM serviceschedule ss
|
||||
LEFT JOIN service s ON ss.idservice = s.idservice
|
||||
WHERE ss.dateschedule >= NOW()
|
||||
ORDER BY ss.dateschedule ASC";
|
||||
$stmt = $db->prepare($sql);
|
||||
$stmt->execute([':iduser' => $iduser]);
|
||||
$rows = $stmt->fetchAll(PDO::FETCH_ASSOC);
|
||||
|
||||
$classes = [];
|
||||
foreach ($rows as $r) {
|
||||
$sid = (int) $r['idserviceschedule'];
|
||||
$maxcap = (int) $r['maxcapacity'];
|
||||
$booked = (int) $r['booked_count'];
|
||||
$alreadyHere = ((int) $r['already_here']) > 0;
|
||||
$isFull = $maxcap > 0 && $booked >= $maxcap;
|
||||
|
||||
// Escludi: classe attuale, classi piene, classi dove è già iscritto
|
||||
if ($sid === $currentSchedule) continue;
|
||||
if ($isFull) continue;
|
||||
if ($alreadyHere) continue;
|
||||
|
||||
$classes[] = [
|
||||
'schedule_id' => $sid,
|
||||
'service_id' => (int) $r['idservice'],
|
||||
'class_name' => (string) ($r['servicename'] ?? ''),
|
||||
'date_time' => $r['dateschedule'],
|
||||
'max_capacity' => $maxcap,
|
||||
'booked_count' => $booked,
|
||||
];
|
||||
}
|
||||
|
||||
echo json_encode([
|
||||
'success' => true,
|
||||
'classes' => $classes,
|
||||
], JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES);
|
||||
} catch (Throwable $ex) {
|
||||
error_log('api_teacher_available_classes error: ' . $ex->getMessage());
|
||||
http_response_code(500);
|
||||
echo json_encode(['success' => false, 'message' => 'Errore recupero classi']);
|
||||
}
|
||||
@@ -1,127 +0,0 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* api_teacher_classes.php
|
||||
* --------------------------------------------------------------------------
|
||||
* Classi programmate in un mese, CON i partecipanti di ciascuna.
|
||||
* Solo staff (Admin=1 / teacher=3). Sola lettura.
|
||||
*
|
||||
* Posizione: public/api/api_teacher_classes.php
|
||||
* Metodo: GET
|
||||
* Auth: Bearer token (Sanctum) via _bootstrap.php
|
||||
* Query: ?month=YYYY-MM (default: mese corrente)
|
||||
*
|
||||
* Replica la logica di adminpanel.php:
|
||||
* - schedule del mese (serviceschedule + service)
|
||||
* - bookings con status='booked' (le "perse" sono booked + lostlesson='Y')
|
||||
* - conteggio posti = tutti i booked (perse incluse)
|
||||
* --------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
require_once __DIR__ . '/_bootstrap.php';
|
||||
|
||||
// --- Gate di sicurezza: solo staff ---
|
||||
$roleId = (int) $user->role_id;
|
||||
if (!in_array($roleId, [1, 3], true)) {
|
||||
http_response_code(403);
|
||||
echo json_encode(['success' => false, 'message' => 'Forbidden']);
|
||||
exit;
|
||||
}
|
||||
|
||||
// --- Mese richiesto (default: corrente) ---
|
||||
$month = isset($_GET['month']) ? preg_replace('/[^0-9\-]/', '', $_GET['month']) : date('Y-m');
|
||||
if (!preg_match('/^\d{4}-\d{2}$/', $month)) {
|
||||
$month = date('Y-m');
|
||||
}
|
||||
$monthStart = $month . '-01';
|
||||
if (strtotime($monthStart) === false) {
|
||||
$monthStart = date('Y-m-01');
|
||||
}
|
||||
$monthEnd = date('Y-m-t', strtotime($monthStart));
|
||||
|
||||
// --- Classi del mese ---
|
||||
$sqlSchedule = "SELECT serviceschedule.idserviceschedule,
|
||||
serviceschedule.idservice,
|
||||
serviceschedule.dateschedule,
|
||||
service.servicename,
|
||||
service.colorclass,
|
||||
service.maxcapacity
|
||||
FROM serviceschedule
|
||||
LEFT JOIN service ON serviceschedule.idservice = service.idservice
|
||||
WHERE serviceschedule.dateschedule BETWEEN :start AND DATE_ADD(:end, INTERVAL 1 DAY)
|
||||
ORDER BY serviceschedule.dateschedule";
|
||||
$stmt = $db->prepare($sqlSchedule);
|
||||
$stmt->execute([':start' => $monthStart, ':end' => $monthEnd]);
|
||||
$scheduleRows = $stmt->fetchAll(PDO::FETCH_ASSOC);
|
||||
|
||||
// --- Bookings di tutte le classi del mese (una query sola) ---
|
||||
$bookingsBySchedule = [];
|
||||
$scheduleIds = array_filter(array_map(fn($r) => (int) $r['idserviceschedule'], $scheduleRows));
|
||||
|
||||
if (!empty($scheduleIds)) {
|
||||
$ph = implode(',', array_fill(0, count($scheduleIds), '?'));
|
||||
$sqlBookings = "SELECT bookingclass.idbookingclass,
|
||||
bookingclass.idserviceschedule,
|
||||
bookingclass.lostlesson,
|
||||
bookingclass.status,
|
||||
auth_users.first_name,
|
||||
auth_users.last_name,
|
||||
auth_users.avatar
|
||||
FROM bookingclass
|
||||
LEFT JOIN auth_users ON bookingclass.iduser = auth_users.id
|
||||
WHERE bookingclass.idserviceschedule IN ($ph)
|
||||
AND bookingclass.status IN ('booked', 'pending')
|
||||
ORDER BY auth_users.last_name, auth_users.first_name";
|
||||
$stmtB = $db->prepare($sqlBookings);
|
||||
$stmtB->execute(array_values($scheduleIds));
|
||||
foreach ($stmtB->fetchAll(PDO::FETCH_ASSOC) as $b) {
|
||||
$sid = (int) $b['idserviceschedule'];
|
||||
$first = trim((string) ($b['first_name'] ?? ''));
|
||||
$last = trim((string) ($b['last_name'] ?? ''));
|
||||
$avatar = trim((string) ($b['avatar'] ?? ''));
|
||||
|
||||
$bookingsBySchedule[$sid][] = [
|
||||
'booking_id' => (int) $b['idbookingclass'],
|
||||
'first_name' => $first,
|
||||
'last_name' => $last,
|
||||
'full_name' => trim($first . ' ' . $last),
|
||||
'is_lost' => ($b['lostlesson'] === 'Y'),
|
||||
'is_pending' => ($b['status'] === 'pending'),
|
||||
// avatar: solo il filename; l'app compone l'URL se serve
|
||||
'avatar' => $avatar !== '' ? $avatar : null,
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
// --- Composizione risposta ---
|
||||
$classes = [];
|
||||
foreach ($scheduleRows as $sch) {
|
||||
$sid = (int) $sch['idserviceschedule'];
|
||||
$participants = $bookingsBySchedule[$sid] ?? [];
|
||||
// contatore: solo confermati (booked, perse incluse); i pending NON contano
|
||||
$count = 0;
|
||||
foreach ($participants as $pp) {
|
||||
if (empty($pp['is_pending'])) {
|
||||
$count++;
|
||||
}
|
||||
}
|
||||
$maxcap = (int) $sch['maxcapacity'];
|
||||
|
||||
$classes[] = [
|
||||
'schedule_id' => $sid,
|
||||
'service_id' => (int) $sch['idservice'],
|
||||
'class_name' => (string) ($sch['servicename'] ?? ''),
|
||||
'color_class' => $sch['colorclass'] ?: null,
|
||||
'date_time' => $sch['dateschedule'], // "YYYY-MM-DD HH:MM:SS"
|
||||
'max_capacity' => $maxcap,
|
||||
'booked_count' => $count,
|
||||
'is_full' => $maxcap > 0 && $count >= $maxcap,
|
||||
'participants' => $participants,
|
||||
];
|
||||
}
|
||||
|
||||
echo json_encode([
|
||||
'success' => true,
|
||||
'month' => $month,
|
||||
'classes' => $classes,
|
||||
], JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES);
|
||||
@@ -1,51 +0,0 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* api_teacher_confirm_pending.php
|
||||
* --------------------------------------------------------------------------
|
||||
* Conferma una prenotazione in attesa: pending -> booked.
|
||||
* Solo staff (Admin=1 / teacher=3).
|
||||
*
|
||||
* Posizione: public/api/api_teacher_confirm_pending.php
|
||||
* Metodo: POST
|
||||
* Auth: Bearer token (Sanctum) via _bootstrap.php
|
||||
* Body: booking_id=<int>
|
||||
* --------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
require_once __DIR__ . '/_bootstrap.php';
|
||||
|
||||
// Gate staff
|
||||
$roleId = (int) $user->role_id;
|
||||
if (!in_array($roleId, [1, 3], true)) {
|
||||
http_response_code(403);
|
||||
echo json_encode(['success' => false, 'message' => 'Forbidden']);
|
||||
exit;
|
||||
}
|
||||
|
||||
$bookingId = isset($_POST['booking_id']) ? (int) $_POST['booking_id'] : 0;
|
||||
|
||||
if ($bookingId <= 0) {
|
||||
http_response_code(400);
|
||||
echo json_encode(['success' => false, 'message' => 'ID prenotazione non valido']);
|
||||
exit;
|
||||
}
|
||||
|
||||
try {
|
||||
// Conferma solo se davvero in pending
|
||||
$stmt = $db->prepare(
|
||||
"UPDATE bookingclass SET status = 'booked'
|
||||
WHERE idbookingclass = :id AND status = 'pending'"
|
||||
);
|
||||
$stmt->execute([':id' => $bookingId]);
|
||||
|
||||
echo json_encode([
|
||||
'success' => true,
|
||||
'booking_id' => $bookingId,
|
||||
'confirmed' => $stmt->rowCount(),
|
||||
], JSON_UNESCAPED_UNICODE);
|
||||
} catch (Throwable $ex) {
|
||||
error_log('api_teacher_confirm_pending error: ' . $ex->getMessage());
|
||||
http_response_code(500);
|
||||
echo json_encode(['success' => false, 'message' => 'Errore conferma']);
|
||||
}
|
||||
@@ -1,47 +0,0 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* api_teacher_delete_booking.php
|
||||
* --------------------------------------------------------------------------
|
||||
* Elimina una prenotazione (record bookingclass). Libera il ticket:
|
||||
* l'allievo se lo ritrova disponibile. Solo staff (Admin=1 / teacher=3).
|
||||
*
|
||||
* Posizione: public/api/api_teacher_delete_booking.php
|
||||
* Metodo: POST
|
||||
* Auth: Bearer token (Sanctum) via _bootstrap.php
|
||||
* Body: booking_id=<int>
|
||||
* --------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
require_once __DIR__ . '/_bootstrap.php';
|
||||
|
||||
// Gate staff
|
||||
$roleId = (int) $user->role_id;
|
||||
if (!in_array($roleId, [1, 3], true)) {
|
||||
http_response_code(403);
|
||||
echo json_encode(['success' => false, 'message' => 'Forbidden']);
|
||||
exit;
|
||||
}
|
||||
|
||||
$bookingId = isset($_POST['booking_id']) ? (int) $_POST['booking_id'] : 0;
|
||||
|
||||
if ($bookingId <= 0) {
|
||||
http_response_code(400);
|
||||
echo json_encode(['success' => false, 'message' => 'ID prenotazione non valido']);
|
||||
exit;
|
||||
}
|
||||
|
||||
try {
|
||||
$stmt = $db->prepare("DELETE FROM bookingclass WHERE idbookingclass = :id");
|
||||
$stmt->execute([':id' => $bookingId]);
|
||||
|
||||
echo json_encode([
|
||||
'success' => true,
|
||||
'booking_id' => $bookingId,
|
||||
'deleted' => $stmt->rowCount(),
|
||||
], JSON_UNESCAPED_UNICODE);
|
||||
} catch (Throwable $ex) {
|
||||
error_log('api_teacher_delete_booking error: ' . $ex->getMessage());
|
||||
http_response_code(500);
|
||||
echo json_encode(['success' => false, 'message' => 'Errore eliminazione']);
|
||||
}
|
||||
@@ -1,51 +0,0 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* api_teacher_mark_lost.php
|
||||
* --------------------------------------------------------------------------
|
||||
* Segna una prenotazione come persa o la ripristina (lostlesson Y/N).
|
||||
* Solo staff (Admin=1 / teacher=3).
|
||||
*
|
||||
* Posizione: public/api/api_teacher_mark_lost.php
|
||||
* Metodo: POST
|
||||
* Auth: Bearer token (Sanctum) via _bootstrap.php
|
||||
* Body: booking_id=<int>&lost=<Y|N>
|
||||
* --------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
require_once __DIR__ . '/_bootstrap.php';
|
||||
|
||||
// Gate staff
|
||||
$roleId = (int) $user->role_id;
|
||||
if (!in_array($roleId, [1, 3], true)) {
|
||||
http_response_code(403);
|
||||
echo json_encode(['success' => false, 'message' => 'Forbidden']);
|
||||
exit;
|
||||
}
|
||||
|
||||
$bookingId = isset($_POST['booking_id']) ? (int) $_POST['booking_id'] : 0;
|
||||
$lostRaw = isset($_POST['lost']) ? strtoupper(trim((string) $_POST['lost'])) : '';
|
||||
$lost = ($lostRaw === 'Y') ? 'Y' : 'N';
|
||||
|
||||
if ($bookingId <= 0) {
|
||||
http_response_code(400);
|
||||
echo json_encode(['success' => false, 'message' => 'ID prenotazione non valido']);
|
||||
exit;
|
||||
}
|
||||
|
||||
try {
|
||||
$stmt = $db->prepare(
|
||||
"UPDATE bookingclass SET lostlesson = :lost WHERE idbookingclass = :id"
|
||||
);
|
||||
$stmt->execute([':lost' => $lost, ':id' => $bookingId]);
|
||||
|
||||
echo json_encode([
|
||||
'success' => true,
|
||||
'booking_id' => $bookingId,
|
||||
'lost' => $lost,
|
||||
], JSON_UNESCAPED_UNICODE);
|
||||
} catch (Throwable $ex) {
|
||||
error_log('api_teacher_mark_lost error: ' . $ex->getMessage());
|
||||
http_response_code(500);
|
||||
echo json_encode(['success' => false, 'message' => 'Errore aggiornamento']);
|
||||
}
|
||||
@@ -1,159 +0,0 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* api_teacher_reprogram.php
|
||||
* --------------------------------------------------------------------------
|
||||
* Sposta una prenotazione su una nuova classe schedulata.
|
||||
* Replica reprogramclass.php della webapp, con gate staff.
|
||||
* Solo staff (Admin=1 / teacher=3).
|
||||
*
|
||||
* Posizione: public/api/api_teacher_reprogram.php
|
||||
* Metodo: POST
|
||||
* Auth: Bearer token (Sanctum) via _bootstrap.php
|
||||
* Body: booking_id=<int>&schedule_id=<int>&is_reprogrammed=<Y|N>
|
||||
*
|
||||
* Regole (identiche alla webapp):
|
||||
* - status resta 'booked', lostlesson non toccato
|
||||
* - is_reprogrammed sulla prenotazione va sempre a 'Y'
|
||||
* - orderbook.reprogrammed +1 solo se flag='Y' e idorder valido
|
||||
* --------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
require_once __DIR__ . '/_bootstrap.php';
|
||||
|
||||
// Gate staff
|
||||
$roleId = (int) $user->role_id;
|
||||
if (!in_array($roleId, [1, 3], true)) {
|
||||
http_response_code(403);
|
||||
echo json_encode(['success' => false, 'message' => 'Forbidden']);
|
||||
exit;
|
||||
}
|
||||
|
||||
$bookingId = isset($_POST['booking_id']) ? (int) $_POST['booking_id'] : 0;
|
||||
$newSchedId = isset($_POST['schedule_id']) ? (int) $_POST['schedule_id'] : 0;
|
||||
$flagReprogrammed =
|
||||
(isset($_POST['is_reprogrammed']) && $_POST['is_reprogrammed'] === 'Y') ? 'Y' : 'N';
|
||||
|
||||
if ($bookingId <= 0 || $newSchedId <= 0) {
|
||||
http_response_code(400);
|
||||
echo json_encode(['success' => false, 'message' => 'Dati mancanti']);
|
||||
exit;
|
||||
}
|
||||
|
||||
try {
|
||||
$db->beginTransaction();
|
||||
|
||||
// Prenotazione corrente (lock)
|
||||
$stmt = $db->prepare(
|
||||
"SELECT idbookingclass, idserviceschedule, bookingstart, idorder, iduser
|
||||
FROM bookingclass
|
||||
WHERE idbookingclass = :id
|
||||
FOR UPDATE"
|
||||
);
|
||||
$stmt->execute([':id' => $bookingId]);
|
||||
$booking = $stmt->fetch(PDO::FETCH_ASSOC);
|
||||
|
||||
if (!$booking) {
|
||||
$db->rollBack();
|
||||
http_response_code(404);
|
||||
echo json_encode(['success' => false, 'message' => 'Prenotazione non trovata']);
|
||||
exit;
|
||||
}
|
||||
|
||||
// Classe destinazione
|
||||
$stmt = $db->prepare(
|
||||
"SELECT idserviceschedule, idservice, dateschedule
|
||||
FROM serviceschedule
|
||||
WHERE idserviceschedule = :id"
|
||||
);
|
||||
$stmt->execute([':id' => $newSchedId]);
|
||||
$newSchedule = $stmt->fetch(PDO::FETCH_ASSOC);
|
||||
|
||||
if (!$newSchedule) {
|
||||
$db->rollBack();
|
||||
http_response_code(404);
|
||||
echo json_encode(['success' => false, 'message' => 'Classe destinazione non trovata']);
|
||||
exit;
|
||||
}
|
||||
|
||||
// Stessa classe: niente da fare
|
||||
if ((int) $booking['idserviceschedule'] === $newSchedId) {
|
||||
$db->rollBack();
|
||||
http_response_code(400);
|
||||
echo json_encode(['success' => false, 'message' => 'Classe destinazione uguale a quella attuale']);
|
||||
exit;
|
||||
}
|
||||
|
||||
// Anti-duplicato: già prenotato (attivo) nella destinazione?
|
||||
$dup = $db->prepare(
|
||||
"SELECT COUNT(*)
|
||||
FROM bookingclass
|
||||
WHERE idserviceschedule = :newsched
|
||||
AND iduser = :iduser
|
||||
AND status = 'booked'
|
||||
AND idbookingclass <> :id"
|
||||
);
|
||||
$dup->execute([
|
||||
':newsched' => $newSchedId,
|
||||
':iduser' => (int) $booking['iduser'],
|
||||
':id' => $bookingId,
|
||||
]);
|
||||
if ((int) $dup->fetchColumn() > 0) {
|
||||
$db->rollBack();
|
||||
http_response_code(409);
|
||||
echo json_encode(['success' => false, 'message' => 'Allievo già prenotato in questa classe']);
|
||||
exit;
|
||||
}
|
||||
|
||||
// Valori precedenti da conservare
|
||||
$prevSchedule = $booking['idserviceschedule'];
|
||||
$prevStart = $booking['bookingstart'];
|
||||
|
||||
// Aggiorna in place
|
||||
$upd = $db->prepare(
|
||||
"UPDATE bookingclass SET
|
||||
idserviceschedule = :newsched,
|
||||
idservice = :newservice,
|
||||
bookingstart = :newstart,
|
||||
idprevserviceschedule = :prevsched,
|
||||
prevbookingstart = :prevstart,
|
||||
is_reprogrammed = 'Y',
|
||||
status = 'booked'
|
||||
WHERE idbookingclass = :id"
|
||||
);
|
||||
$upd->execute([
|
||||
':newsched' => (int) $newSchedule['idserviceschedule'],
|
||||
':newservice' => (int) $newSchedule['idservice'],
|
||||
':newstart' => $newSchedule['dateschedule'],
|
||||
':prevsched' => $prevSchedule,
|
||||
':prevstart' => $prevStart,
|
||||
':id' => $bookingId,
|
||||
]);
|
||||
|
||||
// Incrementa contatore riprogrammazioni se richiesto e possibile
|
||||
$idorder = $booking['idorder'] !== null ? (int) $booking['idorder'] : 0;
|
||||
if ($flagReprogrammed === 'Y' && $idorder > 0) {
|
||||
$incr = $db->prepare(
|
||||
"UPDATE orderbook
|
||||
SET reprogrammed = reprogrammed + 1
|
||||
WHERE idorderbook = :idorder"
|
||||
);
|
||||
$incr->execute([':idorder' => $idorder]);
|
||||
}
|
||||
|
||||
$db->commit();
|
||||
|
||||
echo json_encode([
|
||||
'success' => true,
|
||||
'booking_id' => $bookingId,
|
||||
'schedule_id' => $newSchedId,
|
||||
'reprogrammed_counted' => ($flagReprogrammed === 'Y' && $idorder > 0),
|
||||
], JSON_UNESCAPED_UNICODE);
|
||||
} catch (Throwable $ex) {
|
||||
if ($db->inTransaction()) {
|
||||
$db->rollBack();
|
||||
}
|
||||
error_log('api_teacher_reprogram error: ' . $ex->getMessage());
|
||||
http_response_code(500);
|
||||
echo json_encode(['success' => false, 'message' => 'Errore riprogrammazione']);
|
||||
}
|
||||
@@ -1,75 +0,0 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* api_teacher_search_users.php
|
||||
* --------------------------------------------------------------------------
|
||||
* Ricerca utenti per nome e/o cognome (OR). Solo staff (Admin=1 / teacher=3).
|
||||
* Replica searchemail.php della webapp.
|
||||
*
|
||||
* Posizione: public/api/api_teacher_search_users.php
|
||||
* Metodo: GET
|
||||
* Auth: Bearer token (Sanctum) via _bootstrap.php
|
||||
* Query: ?first=<str>&last=<str> (min 2 caratteri in almeno uno)
|
||||
* --------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
require_once __DIR__ . '/_bootstrap.php';
|
||||
|
||||
// Gate staff
|
||||
$roleId = (int) $user->role_id;
|
||||
if (!in_array($roleId, [1, 3], true)) {
|
||||
http_response_code(403);
|
||||
echo json_encode(['success' => false, 'message' => 'Forbidden']);
|
||||
exit;
|
||||
}
|
||||
|
||||
$firstName = trim($_GET['first'] ?? '');
|
||||
$lastName = trim($_GET['last'] ?? '');
|
||||
|
||||
// Serve almeno 2 caratteri in uno dei due campi
|
||||
if (mb_strlen($firstName) < 2 && mb_strlen($lastName) < 2) {
|
||||
echo json_encode(['success' => true, 'results' => []], JSON_UNESCAPED_UNICODE);
|
||||
exit;
|
||||
}
|
||||
|
||||
try {
|
||||
$conditions = [];
|
||||
$params = [];
|
||||
|
||||
if (mb_strlen($firstName) >= 2) {
|
||||
$conditions[] = "first_name LIKE :fn";
|
||||
$params[':fn'] = '%' . $firstName . '%';
|
||||
}
|
||||
if (mb_strlen($lastName) >= 2) {
|
||||
$conditions[] = "last_name LIKE :ln";
|
||||
$params[':ln'] = '%' . $lastName . '%';
|
||||
}
|
||||
|
||||
$where = implode(' OR ', $conditions);
|
||||
|
||||
$sql = "SELECT id, first_name, last_name, email
|
||||
FROM auth_users
|
||||
WHERE $where
|
||||
ORDER BY last_name, first_name
|
||||
LIMIT 15";
|
||||
|
||||
$stmt = $db->prepare($sql);
|
||||
$stmt->execute($params);
|
||||
$rows = $stmt->fetchAll(PDO::FETCH_ASSOC);
|
||||
|
||||
$results = [];
|
||||
foreach ($rows as $r) {
|
||||
$results[] = [
|
||||
'id' => (int) $r['id'],
|
||||
'first_name' => (string) ($r['first_name'] ?? ''),
|
||||
'last_name' => (string) ($r['last_name'] ?? ''),
|
||||
'email' => (string) ($r['email'] ?? ''),
|
||||
];
|
||||
}
|
||||
|
||||
echo json_encode(['success' => true, 'results' => $results], JSON_UNESCAPED_UNICODE);
|
||||
} catch (Throwable $ex) {
|
||||
error_log('api_teacher_search_users error: ' . $ex->getMessage());
|
||||
http_response_code(500);
|
||||
echo json_encode(['success' => false, 'message' => 'Errore ricerca']);
|
||||
}
|
||||
@@ -1,88 +0,0 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* api_teacher_user_orders.php
|
||||
* --------------------------------------------------------------------------
|
||||
* Ordini attivi (non scaduti) di un utente, con ticket residui.
|
||||
* Solo staff (Admin=1 / teacher=3). Replica get_user_orders.php.
|
||||
*
|
||||
* Metodo: GET | Auth: Bearer (Sanctum) via _bootstrap.php | Query: ?user_id=<int>
|
||||
* Residui = ticket - (prenotazioni non cancellate e NON omaggio).
|
||||
* --------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
require_once __DIR__ . '/_bootstrap.php';
|
||||
|
||||
// Gate staff
|
||||
$roleId = (int) $user->role_id;
|
||||
if (!in_array($roleId, [1, 3], true)) {
|
||||
http_response_code(403);
|
||||
echo json_encode(['success' => false, 'message' => 'Forbidden']);
|
||||
exit;
|
||||
}
|
||||
|
||||
$userId = isset($_GET['user_id']) ? (int) $_GET['user_id'] : 0;
|
||||
if ($userId <= 0) {
|
||||
http_response_code(400);
|
||||
echo json_encode(['success' => false, 'message' => 'Utente non valido', 'orders' => []]);
|
||||
exit;
|
||||
}
|
||||
|
||||
try {
|
||||
$today = date('Y-m-d');
|
||||
|
||||
$sql = "SELECT ob.idorderbook, ob.idservice, ob.nticket, ob.quantityclass,
|
||||
ob.expireon, ob.maxreschedule, ob.reprogrammed,
|
||||
s.servicename
|
||||
FROM orderbook ob
|
||||
LEFT JOIN service s ON ob.idservice = s.idservice
|
||||
WHERE ob.iduser = :uid
|
||||
AND (ob.expireon IS NULL OR ob.expireon >= :today)
|
||||
ORDER BY ob.idorderbook DESC";
|
||||
$stmt = $db->prepare($sql);
|
||||
$stmt->execute([':uid' => $userId, ':today' => $today]);
|
||||
$rows = $stmt->fetchAll(PDO::FETCH_ASSOC);
|
||||
|
||||
// conta le prenotazioni che consumano ticket (non cancellate, non omaggio)
|
||||
$usedStmt = $db->prepare(
|
||||
"SELECT COUNT(*) AS n
|
||||
FROM bookingclass
|
||||
WHERE idorder = :oid
|
||||
AND status != 'cancelled'
|
||||
AND is_gift = 'N'"
|
||||
);
|
||||
|
||||
$orders = [];
|
||||
foreach ($rows as $o) {
|
||||
$orderId = (int) $o['idorderbook'];
|
||||
|
||||
$tickets = (int) (($o['quantityclass'] !== null && $o['quantityclass'] !== '')
|
||||
? $o['quantityclass']
|
||||
: ($o['nticket'] ?? 0));
|
||||
|
||||
$usedStmt->execute([':oid' => $orderId]);
|
||||
$used = (int) ($usedStmt->fetch(PDO::FETCH_ASSOC)['n'] ?? 0);
|
||||
|
||||
$remaining = $tickets - $used;
|
||||
if ($remaining < 0) {
|
||||
$remaining = 0;
|
||||
}
|
||||
|
||||
$orders[] = [
|
||||
'idorderbook' => $orderId,
|
||||
'service_name' => (string) ($o['servicename'] ?? ''),
|
||||
'tickets' => $tickets,
|
||||
'used' => $used,
|
||||
'remaining' => $remaining,
|
||||
'expireon' => $o['expireon'] ?? null,
|
||||
'maxreschedule' => (int) ($o['maxreschedule'] ?? 0),
|
||||
'reprogrammed' => (int) ($o['reprogrammed'] ?? 0),
|
||||
];
|
||||
}
|
||||
|
||||
echo json_encode(['success' => true, 'orders' => $orders], JSON_UNESCAPED_UNICODE);
|
||||
} catch (Throwable $ex) {
|
||||
error_log('api_teacher_user_orders error: ' . $ex->getMessage());
|
||||
http_response_code(500);
|
||||
echo json_encode(['success' => false, 'message' => 'Errore ordini: ' . $ex->getMessage(), 'orders' => []]);
|
||||
}
|
||||
@@ -173,7 +173,7 @@ try {
|
||||
(idserviceschedule, iduser, prevbookingstart, idprevserviceschedule,
|
||||
idservice, idorder, bookingstart, status)
|
||||
VALUES
|
||||
(:sched, :uid, NULL, 0, :service, :order, :newstart, 'pending')
|
||||
(:sched, :uid, '0', '0', :service, :order, :newstart, 'pending')
|
||||
");
|
||||
$ins->execute([
|
||||
':sched' => $newScheduleId,
|
||||
|
||||
@@ -88,7 +88,6 @@ $stmt = $db->prepare("
|
||||
ON bc.idserviceschedule = ss.idserviceschedule
|
||||
WHERE bc.iduser = :uid
|
||||
AND bc.status != 'cancelled'
|
||||
AND bc.is_gift = 'N'
|
||||
");
|
||||
$stmt->execute([
|
||||
':now1' => $now,
|
||||
@@ -129,7 +128,6 @@ $stmt = $db->prepare("
|
||||
bc.idservice,
|
||||
bc.idorder,
|
||||
bc.lostlesson,
|
||||
bc.is_gift,
|
||||
ss.dateschedule,
|
||||
s.servicename,
|
||||
s.colorclass,
|
||||
@@ -194,21 +192,13 @@ foreach ($rows as $r) {
|
||||
$reprogrammed = (int) ($r['reprogrammed'] ?? 0);
|
||||
$canReprogram = $reprogrammed < $maxreschedule;
|
||||
|
||||
$isGift = ($r['is_gift'] ?? 'N') === 'Y';
|
||||
|
||||
if ($isGift) {
|
||||
// Omaggio: mai riprogrammabile, cancellabile in base al tempo.
|
||||
$canReschedule = false;
|
||||
$canDelete = $canByTime;
|
||||
} else {
|
||||
// Lezione normale: entrambi soggetti a tempo + limite riprogrammazioni.
|
||||
$canReschedule = $canByTime && $canReprogram;
|
||||
$canDelete = $canByTime && $canReprogram;
|
||||
}
|
||||
// Nella webapp i bottoni "Riprogramma" e "Cancella" compaiono entrambi
|
||||
// solo se ($canByTime && $canReprogram). Riproduciamo la stessa condizione.
|
||||
$canReschedule = $canByTime && $canReprogram;
|
||||
$canDelete = $canByTime && $canReprogram;
|
||||
|
||||
$lessons[] = [
|
||||
'booking_id' => (int) $r['idbookingclass'],
|
||||
'service_id' => (int) ($r['idservice'] ?? 0),
|
||||
'datetime' => $classDt->format('Y-m-d H:i:s'),
|
||||
'date' => $classDt->format('Y-m-d'),
|
||||
'time' => $classDt->format('H:i'),
|
||||
|
||||
@@ -0,0 +1,37 @@
|
||||
<?php
|
||||
|
||||
require_once __DIR__ . '/_bootstrap.php';
|
||||
|
||||
$userId = (int) $user->id;
|
||||
$metodo = $_SERVER['REQUEST_METHOD'] ?? 'GET';
|
||||
|
||||
if ($metodo === 'POST' || $metodo === 'PUT' || $metodo === 'PATCH') {
|
||||
$input = json_decode((string) file_get_contents('php://input'), true);
|
||||
if (!is_array($input) || !array_key_exists('enabled', $input)) {
|
||||
http_response_code(422);
|
||||
echo json_encode(['success' => false, 'error' => 'Parametro enabled mancante']);
|
||||
exit;
|
||||
}
|
||||
|
||||
$valore = $input['enabled'];
|
||||
|
||||
if (is_bool($valore)) {
|
||||
$nuovo = $valore ? 'Y' : 'N';
|
||||
} else {
|
||||
$nuovo = strtoupper(trim((string) $valore)) === 'Y' ? 'Y' : 'N';
|
||||
}
|
||||
|
||||
$stmt = $db->prepare("UPDATE auth_users SET pushnotification = :valore WHERE id = :uid");
|
||||
$stmt->execute([':valore' => $nuovo, ':uid' => $userId]);
|
||||
|
||||
echo json_encode(['success' => true, 'push_enabled' => $nuovo]);
|
||||
exit;
|
||||
}
|
||||
|
||||
$stmt = $db->prepare("SELECT pushnotification FROM auth_users WHERE id = :uid LIMIT 1");
|
||||
$stmt->execute([':uid' => $userId]);
|
||||
|
||||
echo json_encode([
|
||||
'success' => true,
|
||||
'push_enabled' => (string) ($stmt->fetchColumn() ?: 'Y'),
|
||||
]);
|
||||
@@ -0,0 +1,68 @@
|
||||
<?php
|
||||
|
||||
require_once __DIR__ . '/_bootstrap.php';
|
||||
|
||||
$userId = (int) $user->id;
|
||||
$metodo = $_SERVER['REQUEST_METHOD'] ?? 'POST';
|
||||
|
||||
$input = json_decode((string) file_get_contents('php://input'), true);
|
||||
if (!is_array($input)) {
|
||||
$input = [];
|
||||
}
|
||||
|
||||
$deviceToken = trim((string) ($input['device_token'] ?? ''));
|
||||
|
||||
if ($deviceToken === '') {
|
||||
http_response_code(422);
|
||||
echo json_encode(['success' => false, 'error' => 'device_token mancante']);
|
||||
exit;
|
||||
}
|
||||
|
||||
if ($metodo === 'DELETE') {
|
||||
$stmt = $db->prepare("
|
||||
UPDATE userdevicetoken
|
||||
SET active = 'N'
|
||||
WHERE devicetoken = :token AND iduser = :uid
|
||||
");
|
||||
$stmt->execute([':token' => $deviceToken, ':uid' => $userId]);
|
||||
|
||||
echo json_encode(['success' => true, 'deactivated' => $stmt->rowCount()]);
|
||||
exit;
|
||||
}
|
||||
|
||||
$platform = strtolower(trim((string) ($input['platform'] ?? 'android')));
|
||||
if (!in_array($platform, ['android', 'ios'], true)) {
|
||||
$platform = 'android';
|
||||
}
|
||||
|
||||
$appVersion = trim((string) ($input['app_version'] ?? ''));
|
||||
if ($appVersion === '') {
|
||||
$appVersion = null;
|
||||
}
|
||||
|
||||
$stmt = $db->prepare("
|
||||
INSERT INTO userdevicetoken (iduser, devicetoken, platform, appversion, active, lastseen_at)
|
||||
VALUES (:uid, :token, :platform, :versione, 'Y', NOW())
|
||||
ON DUPLICATE KEY UPDATE
|
||||
iduser = VALUES(iduser),
|
||||
platform = VALUES(platform),
|
||||
appversion = COALESCE(VALUES(appversion), appversion),
|
||||
active = 'Y',
|
||||
lastseen_at = NOW()
|
||||
");
|
||||
|
||||
$stmt->execute([
|
||||
':uid' => $userId,
|
||||
':token' => $deviceToken,
|
||||
':platform' => $platform,
|
||||
':versione' => $appVersion,
|
||||
]);
|
||||
|
||||
$stmt = $db->prepare("SELECT pushnotification FROM auth_users WHERE id = :uid LIMIT 1");
|
||||
$stmt->execute([':uid' => $userId]);
|
||||
$pushEnabled = (string) ($stmt->fetchColumn() ?: 'Y');
|
||||
|
||||
echo json_encode([
|
||||
'success' => true,
|
||||
'push_enabled' => $pushEnabled,
|
||||
]);
|
||||
@@ -1,189 +0,0 @@
|
||||
<?php
|
||||
require_once __DIR__ . '/bootstrap.php';
|
||||
require_once dirname(__DIR__) . '/include/event_mailer.php';
|
||||
|
||||
/**
|
||||
* Endpoint pubblico PRENOTAZIONE (POST).
|
||||
* Riceve i dati dal widget WordPress e crea la prenotazione.
|
||||
*
|
||||
* Campi attesi (POST form-encoded o JSON):
|
||||
* event_id, name, surname, email, seats, consent (1), marketing (1|0)
|
||||
* website -> honeypot anti-spam (deve restare vuoto)
|
||||
*
|
||||
* Logica posti (conferma immediata):
|
||||
* - seats <= posti rimanenti -> status 'confirmed'
|
||||
* - evento pieno + lista d'attesa ON -> status 'waiting'
|
||||
* - evento pieno + lista d'attesa OFF -> errore sold_out
|
||||
* - 0 < rimanenti < seats -> errore 'partial' (avvisa: solo N posti)
|
||||
*
|
||||
* Anti-oversell: transazione + lock della riga evento (SELECT ... FOR UPDATE),
|
||||
* così due prenotazioni simultanee non sforano la capienza.
|
||||
*/
|
||||
if (($_SERVER['REQUEST_METHOD'] ?? 'GET') !== 'POST') {
|
||||
send_json(['ok' => false, 'code' => 'method', 'error' => 'Metodo non consentito.'], 405);
|
||||
}
|
||||
|
||||
// Input: form-encoded oppure JSON
|
||||
$in = $_POST;
|
||||
if (empty($in)) {
|
||||
$raw = file_get_contents('php://input');
|
||||
if ($raw) {
|
||||
$j = json_decode($raw, true);
|
||||
if (is_array($j)) {
|
||||
$in = $j;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Honeypot: se compilato, è un bot
|
||||
if (!empty($in['website'])) {
|
||||
send_json(['ok' => false, 'code' => 'invalid', 'error' => 'Richiesta non valida.'], 400);
|
||||
}
|
||||
|
||||
$eventId = (int) ($in['event_id'] ?? 0);
|
||||
$name = trim((string) ($in['name'] ?? ''));
|
||||
$surname = trim((string) ($in['surname'] ?? ''));
|
||||
$email = trim((string) ($in['email'] ?? ''));
|
||||
$seats = (int) ($in['seats'] ?? 0);
|
||||
$consent = !empty($in['consent']) && $in['consent'] !== '0';
|
||||
$marketing = (!empty($in['marketing']) && $in['marketing'] !== '0') ? 'Y' : 'N';
|
||||
|
||||
// Validazioni
|
||||
if ($eventId <= 0 || $name === '' || $surname === '') {
|
||||
send_json(['ok' => false, 'code' => 'invalid', 'error' => 'Compila nome, cognome ed evento.'], 400);
|
||||
}
|
||||
if (!filter_var($email, FILTER_VALIDATE_EMAIL)) {
|
||||
send_json(['ok' => false, 'code' => 'invalid', 'error' => 'Email non valida.'], 400);
|
||||
}
|
||||
if (!$consent) {
|
||||
send_json(['ok' => false, 'code' => 'consent', 'error' => "Devi accettare l'informativa privacy."], 400);
|
||||
}
|
||||
if ($seats < 1) {
|
||||
$seats = 1;
|
||||
}
|
||||
|
||||
$pdo = pdo_conn();
|
||||
|
||||
try {
|
||||
$pdo->beginTransaction();
|
||||
|
||||
// Lock della riga evento: serializza le prenotazioni dello stesso evento
|
||||
$es = $pdo->prepare("SELECT * FROM events WHERE id = ? FOR UPDATE");
|
||||
$es->execute([$eventId]);
|
||||
$event = $es->fetch(PDO::FETCH_ASSOC);
|
||||
|
||||
if (!$event || $event['status'] !== 'published') {
|
||||
$pdo->rollBack();
|
||||
send_json(['ok' => false, 'code' => 'not_available', 'error' => 'Evento non disponibile.'], 404);
|
||||
}
|
||||
|
||||
// Prenotazioni chiuse all'orario di inizio
|
||||
if (strtotime($event['starts_at']) <= time()) {
|
||||
$pdo->rollBack();
|
||||
send_json(['ok' => false, 'code' => 'closed', 'error' => 'Le prenotazioni per questo evento sono chiuse.'], 409);
|
||||
}
|
||||
|
||||
$maxSeats = (int) $event['max_seats'];
|
||||
$maxPerBooking = max(1, (int) $event['max_per_booking']);
|
||||
$waitlistOn = ($event['waitlist_enabled'] ?? 'N') === 'Y';
|
||||
|
||||
if ($seats > $maxPerBooking) {
|
||||
$pdo->rollBack();
|
||||
send_json([
|
||||
'ok' => false,
|
||||
'code' => 'too_many',
|
||||
'max' => $maxPerBooking,
|
||||
'error' => "Puoi prenotare al massimo {$maxPerBooking} posti per prenotazione."
|
||||
], 400);
|
||||
}
|
||||
|
||||
// Posti occupati (solo confermate/pending): protetto dal lock evento
|
||||
$os = $pdo->prepare("SELECT COALESCE(SUM(seats),0) FROM event_bookings
|
||||
WHERE event_id = ? AND status IN ('confirmed','pending','offered')");
|
||||
$os->execute([$eventId]);
|
||||
$occupied = (int) $os->fetchColumn();
|
||||
$remaining = max(0, $maxSeats - $occupied);
|
||||
|
||||
// Decisione stato
|
||||
if ($seats <= $remaining) {
|
||||
$status = 'confirmed';
|
||||
} elseif ($remaining <= 0 && $waitlistOn) {
|
||||
$status = 'waiting';
|
||||
} elseif ($remaining <= 0 && !$waitlistOn) {
|
||||
$pdo->rollBack();
|
||||
send_json(['ok' => false, 'code' => 'sold_out', 'error' => 'Evento esaurito.'], 409);
|
||||
} else {
|
||||
// 0 < remaining < seats: avvisa, non prenota
|
||||
$pdo->rollBack();
|
||||
send_json([
|
||||
'ok' => false,
|
||||
'code' => 'partial',
|
||||
'remaining' => $remaining,
|
||||
'error' => "Sono rimasti solo {$remaining} posti. Riduci il numero di persone; per gli altri potrai iscriverti alla lista d'attesa.",
|
||||
], 409);
|
||||
}
|
||||
|
||||
// Token univoco per gestione/disdetta da link email
|
||||
$token = '';
|
||||
for ($i = 0; $i < 5; $i++) {
|
||||
$candidate = bin2hex(random_bytes(16));
|
||||
$ck = $pdo->prepare("SELECT 1 FROM event_bookings WHERE token = ? LIMIT 1");
|
||||
$ck->execute([$candidate]);
|
||||
if (!$ck->fetchColumn()) {
|
||||
$token = $candidate;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if ($token === '') {
|
||||
throw new RuntimeException('Impossibile generare il token.');
|
||||
}
|
||||
|
||||
$amount = round($seats * (float) $event['cost'], 2);
|
||||
$fullName = trim($name . ' ' . $surname);
|
||||
|
||||
$ins = $pdo->prepare("INSERT INTO event_bookings
|
||||
(event_id, user_id, name, email, phone, seats, status, amount, token,
|
||||
consent_at, marketing_opt_in, created_at, updated_at)
|
||||
VALUES
|
||||
(:event_id, NULL, :name, :email, NULL, :seats, :status, :amount, :token,
|
||||
NOW(), :marketing, NOW(), NOW())");
|
||||
$ins->execute([
|
||||
':event_id' => $eventId,
|
||||
':name' => $fullName,
|
||||
':email' => $email,
|
||||
':seats' => $seats,
|
||||
':status' => $status,
|
||||
':amount' => $amount,
|
||||
':token' => $token,
|
||||
':marketing' => $marketing,
|
||||
]);
|
||||
|
||||
$pdo->commit();
|
||||
|
||||
// Email di conferma / lista d'attesa (best-effort: non blocca la prenotazione)
|
||||
try {
|
||||
$bookingRow = ['email' => $email, 'name' => $fullName, 'seats' => $seats, 'status' => $status, 'token' => $token];
|
||||
yse_mail_booking($bookingRow, $event);
|
||||
} catch (Throwable $mailEx) {
|
||||
error_log('[book mail] ' . $mailEx->getMessage());
|
||||
}
|
||||
|
||||
$msg = $status === 'confirmed'
|
||||
? 'Prenotazione confermata! Ti abbiamo inviato una email di riepilogo.'
|
||||
: "Sei in lista d'attesa: ti avviseremo appena si libera un posto.";
|
||||
|
||||
send_json([
|
||||
'ok' => true,
|
||||
'status' => $status,
|
||||
'seats' => $seats,
|
||||
'amount' => $amount,
|
||||
'token' => $token,
|
||||
'message' => $msg,
|
||||
]);
|
||||
} catch (Throwable $ex) {
|
||||
if ($pdo->inTransaction()) {
|
||||
$pdo->rollBack();
|
||||
}
|
||||
error_log('[apiwp/book] ' . $ex->getMessage());
|
||||
send_json(['ok' => false, 'code' => 'server', 'error' => 'Errore durante la prenotazione. Riprova.'], 500);
|
||||
}
|
||||
@@ -1,63 +0,0 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Bootstrap per gli endpoint PUBBLICI del modulo Eventi (cartella /api).
|
||||
* NON include headscript.php: niente login/redirect. Serve solo il DB.
|
||||
*
|
||||
* Posiziona la cartella /api allo stesso livello di events.php, class/, include/.
|
||||
* Requisito: class/db-functions.php (DBHandlerSelect) già presente e autonomo.
|
||||
*/
|
||||
|
||||
// Path assoluto a DBHandlerSelect (api/ -> ../class/db-functions.php)
|
||||
require_once dirname(__DIR__) . '/class/db-functions.php';
|
||||
|
||||
// URL pubblico di yogibook: usato per rendere assoluti i path delle immagini.
|
||||
if (!defined('YB_PUBLIC_BASE')) {
|
||||
define('YB_PUBLIC_BASE', 'https://yogibook.yogasoul.it/');
|
||||
}
|
||||
|
||||
// Domini WordPress autorizzati (per la prenotazione via browser).
|
||||
$YB_ALLOWED_ORIGINS = ['https://yogasoul.it', 'https://www.yogasoul.it'];
|
||||
|
||||
$origin = $_SERVER['HTTP_ORIGIN'] ?? '';
|
||||
if ($origin !== '' && in_array($origin, $YB_ALLOWED_ORIGINS, true)) {
|
||||
header('Access-Control-Allow-Origin: ' . $origin);
|
||||
header('Vary: Origin');
|
||||
header('Access-Control-Allow-Methods: GET, POST, OPTIONS');
|
||||
header('Access-Control-Allow-Headers: Content-Type');
|
||||
}
|
||||
|
||||
// Preflight CORS
|
||||
if (($_SERVER['REQUEST_METHOD'] ?? 'GET') === 'OPTIONS') {
|
||||
http_response_code(204);
|
||||
exit();
|
||||
}
|
||||
|
||||
function pdo_conn(): PDO
|
||||
{
|
||||
return DBHandlerSelect::getInstance()->getConnection();
|
||||
}
|
||||
|
||||
/** Rende assoluto un path immagine relativo (es. assets/uploads/events/x.jpg). */
|
||||
function public_url(?string $rel): ?string
|
||||
{
|
||||
if ($rel === null || $rel === '') {
|
||||
return null;
|
||||
}
|
||||
if (preg_match('#^https?://#i', $rel)) {
|
||||
return $rel;
|
||||
}
|
||||
return YB_PUBLIC_BASE . ltrim($rel, '/');
|
||||
}
|
||||
|
||||
/** Risponde in JSON e termina. */
|
||||
function send_json($data, int $code = 200): void
|
||||
{
|
||||
if (function_exists('ob_get_level') && ob_get_level()) {
|
||||
ob_clean();
|
||||
}
|
||||
http_response_code($code);
|
||||
header('Content-Type: application/json; charset=utf-8');
|
||||
echo json_encode($data, JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES);
|
||||
exit();
|
||||
}
|
||||
@@ -1,283 +0,0 @@
|
||||
<?php
|
||||
require_once __DIR__ . '/bootstrap.php';
|
||||
require_once dirname(__DIR__) . '/include/event_waitlist.php';
|
||||
require_once dirname(__DIR__) . '/include/event_mailer.php';
|
||||
|
||||
/**
|
||||
* Disdetta pubblica di una prenotazione tramite token (link email, senza login).
|
||||
*
|
||||
* GET apiwp/cancel.php?token=... -> mostra pagina di conferma (NON annulla:
|
||||
* evita che gli scanner email prefetchino il link e annullino da soli)
|
||||
* POST (token + confirm=1) -> annulla e, se la prenotazione occupava posti,
|
||||
* promuove automaticamente la prima in lista d'attesa.
|
||||
*/
|
||||
$pdo = pdo_conn();
|
||||
$token = trim($_POST['token'] ?? $_GET['token'] ?? '');
|
||||
$isPost = ($_SERVER['REQUEST_METHOD'] ?? 'GET') === 'POST';
|
||||
|
||||
$booking = null;
|
||||
if ($token !== '') {
|
||||
$q = $pdo->prepare("SELECT b.*, e.title AS ev_title, e.starts_at AS ev_starts, e.id AS eid
|
||||
FROM event_bookings b JOIN events e ON e.id = b.event_id
|
||||
WHERE b.token = ?");
|
||||
$q->execute([$token]);
|
||||
$booking = $q->fetch(PDO::FETCH_ASSOC);
|
||||
}
|
||||
|
||||
$state = 'form'; // form | notfound | already | toolate | done
|
||||
$promotedCount = 0;
|
||||
$didCancel = false;
|
||||
$promoted = [];
|
||||
|
||||
if (!$booking) {
|
||||
$state = 'notfound';
|
||||
} elseif ($booking['status'] === 'cancelled') {
|
||||
$state = 'already';
|
||||
} elseif (strtotime($booking['ev_starts']) <= time()) {
|
||||
$state = 'toolate';
|
||||
} elseif ($isPost && !empty($_POST['confirm'])) {
|
||||
try {
|
||||
$pdo->beginTransaction();
|
||||
// Lock evento per serializzare con eventuali prenotazioni concorrenti
|
||||
$pdo->prepare("SELECT id FROM events WHERE id = ? FOR UPDATE")->execute([(int) $booking['eid']]);
|
||||
|
||||
// Rileggo lo stato aggiornato della prenotazione
|
||||
$bl = $pdo->prepare("SELECT * FROM event_bookings WHERE id = ?");
|
||||
$bl->execute([(int) $booking['id']]);
|
||||
$fresh = $bl->fetch(PDO::FETCH_ASSOC);
|
||||
|
||||
if ($fresh && $fresh['status'] !== 'cancelled') {
|
||||
$wasOccupying = in_array($fresh['status'], ['confirmed', 'pending', 'offered'], true);
|
||||
$pdo->prepare("UPDATE event_bookings SET status = 'cancelled', updated_at = NOW() WHERE id = ?")
|
||||
->execute([(int) $fresh['id']]);
|
||||
|
||||
if ($wasOccupying) {
|
||||
$promoted = promoteFromWaitlist($pdo, (int) $booking['eid']);
|
||||
$promotedCount = count($promoted);
|
||||
}
|
||||
$didCancel = true;
|
||||
}
|
||||
$pdo->commit();
|
||||
$state = 'done';
|
||||
|
||||
// Email dopo il commit (best-effort)
|
||||
if ($didCancel) {
|
||||
try {
|
||||
$evStmt = pdo_conn()->prepare("SELECT * FROM events WHERE id = ?");
|
||||
$evStmt->execute([(int) $booking['eid']]);
|
||||
$evRow = $evStmt->fetch(PDO::FETCH_ASSOC);
|
||||
if ($evRow) {
|
||||
yse_mail_user_cancel($booking, $evRow); // B: conferma disdetta
|
||||
foreach ($promoted as $pr) { // E: promozione con riconferma
|
||||
try {
|
||||
yse_mail_promotion($pr, $evRow);
|
||||
} catch (Throwable $pe) {
|
||||
error_log('[promo mail] ' . $pe->getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (Throwable $mailEx) {
|
||||
error_log('[cancel mail] ' . $mailEx->getMessage());
|
||||
}
|
||||
}
|
||||
} catch (Throwable $ex) {
|
||||
if ($pdo->inTransaction()) {
|
||||
$pdo->rollBack();
|
||||
}
|
||||
error_log('[apiwp/cancel] ' . $ex->getMessage());
|
||||
$state = 'error';
|
||||
}
|
||||
}
|
||||
|
||||
if (!function_exists('e')) {
|
||||
function e($v): string
|
||||
{
|
||||
return htmlspecialchars((string) $v, ENT_QUOTES, 'UTF-8');
|
||||
}
|
||||
}
|
||||
?>
|
||||
<!doctype html>
|
||||
<html lang="it">
|
||||
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<title>Disdetta prenotazione — YogaSoul</title>
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<link rel="preconnect" href="https://fonts.googleapis.com">
|
||||
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
|
||||
<link href="https://fonts.googleapis.com/css2?family=Fraunces:opsz,wght@9..144,500;9..144,600&family=Inter:wght@400;500;600&display=swap" rel="stylesheet">
|
||||
<style>
|
||||
:root {
|
||||
--accent: #b07aa1;
|
||||
--ink: #2b2622;
|
||||
--muted: #8c837c;
|
||||
--line: #ece7e2;
|
||||
--paper: #faf8f6;
|
||||
}
|
||||
|
||||
* {
|
||||
box-sizing: border-box;
|
||||
}
|
||||
|
||||
body {
|
||||
margin: 0;
|
||||
background: var(--paper);
|
||||
color: var(--ink);
|
||||
font-family: 'Inter', system-ui, sans-serif;
|
||||
display: flex;
|
||||
min-height: 100vh;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
padding: 24px;
|
||||
}
|
||||
|
||||
.card {
|
||||
background: #fff;
|
||||
border-radius: 18px;
|
||||
box-shadow: 0 14px 40px rgba(43, 38, 34, .10);
|
||||
max-width: 460px;
|
||||
width: 100%;
|
||||
padding: 34px 30px;
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
.icn {
|
||||
width: 58px;
|
||||
height: 58px;
|
||||
border-radius: 50%;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
margin: 0 auto 16px;
|
||||
}
|
||||
|
||||
.icn.warn {
|
||||
background: #fdecea;
|
||||
color: #c0392b;
|
||||
}
|
||||
|
||||
.icn.ok {
|
||||
background: #e7f7ee;
|
||||
color: #1a7f52;
|
||||
}
|
||||
|
||||
.icn.info {
|
||||
background: #eef0f3;
|
||||
color: #6b7280;
|
||||
}
|
||||
|
||||
h1 {
|
||||
font-family: 'Fraunces', serif;
|
||||
font-weight: 600;
|
||||
font-size: 23px;
|
||||
margin: 0 0 8px;
|
||||
}
|
||||
|
||||
p {
|
||||
color: #4a433d;
|
||||
font-size: 15px;
|
||||
margin: 6px 0;
|
||||
}
|
||||
|
||||
.ev {
|
||||
background: var(--paper);
|
||||
border-radius: 12px;
|
||||
padding: 14px 16px;
|
||||
margin: 18px 0;
|
||||
}
|
||||
|
||||
.ev .t {
|
||||
font-weight: 600;
|
||||
}
|
||||
|
||||
.ev .d {
|
||||
color: var(--muted);
|
||||
font-size: 14px;
|
||||
margin-top: 2px;
|
||||
}
|
||||
|
||||
.btn {
|
||||
border: none;
|
||||
border-radius: 11px;
|
||||
padding: 14px 20px;
|
||||
font-size: 15px;
|
||||
font-weight: 600;
|
||||
font-family: inherit;
|
||||
cursor: pointer;
|
||||
width: 100%;
|
||||
margin-top: 6px;
|
||||
}
|
||||
|
||||
.btn-danger {
|
||||
background: #e74c3c;
|
||||
color: #fff;
|
||||
}
|
||||
|
||||
.btn-danger:hover {
|
||||
filter: brightness(.94);
|
||||
}
|
||||
|
||||
.btn-light {
|
||||
background: #f3f4f6;
|
||||
color: #374151;
|
||||
text-decoration: none;
|
||||
display: inline-block;
|
||||
}
|
||||
|
||||
.muted {
|
||||
color: var(--muted);
|
||||
font-size: 13px;
|
||||
margin-top: 14px;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<div class="card">
|
||||
<?php if ($state === 'notfound') : ?>
|
||||
<div class="icn warn">✕</div>
|
||||
<h1>Link non valido</h1>
|
||||
<p>Questa prenotazione non esiste o il link è errato.</p>
|
||||
|
||||
<?php elseif ($state === 'already') : ?>
|
||||
<div class="icn info">✓</div>
|
||||
<h1>Già annullata</h1>
|
||||
<p>Questa prenotazione risulta già annullata.</p>
|
||||
|
||||
<?php elseif ($state === 'toolate') : ?>
|
||||
<div class="icn info">⏱</div>
|
||||
<h1>Non più annullabile</h1>
|
||||
<p>L'evento è già iniziato: non è più possibile annullare online. Contattaci per assistenza.</p>
|
||||
|
||||
<?php elseif ($state === 'error') : ?>
|
||||
<div class="icn warn">!</div>
|
||||
<h1>Si è verificato un errore</h1>
|
||||
<p>Riprova tra poco. Se il problema persiste, contattaci.</p>
|
||||
|
||||
<?php elseif ($state === 'done') : ?>
|
||||
<div class="icn ok">✓</div>
|
||||
<h1>Prenotazione annullata</h1>
|
||||
<p>La tua prenotazione per <strong><?php echo e($booking['ev_title']); ?></strong> è stata annullata.</p>
|
||||
<?php if ($promotedCount > 0) : ?>
|
||||
<p class="muted">Un posto è stato assegnato alla prima persona in lista d'attesa.</p>
|
||||
<?php endif; ?>
|
||||
|
||||
<?php else : /* form */ ?>
|
||||
<div class="icn warn">?</div>
|
||||
<h1>Annullare la prenotazione?</h1>
|
||||
<div class="ev">
|
||||
<div class="t"><?php echo e($booking['ev_title']); ?></div>
|
||||
<div class="d"><?php echo e(date('d/m/Y H:i', strtotime($booking['ev_starts']))); ?> · <?php echo (int) $booking['seats']; ?> post<?php echo (int) $booking['seats'] === 1 ? 'o' : 'i'; ?><?php echo $booking['status'] === 'waiting' ? ' (in lista d\'attesa)' : ''; ?></div>
|
||||
</div>
|
||||
<p>Confermi di voler annullare la prenotazione a nome di <strong><?php echo e($booking['name']); ?></strong>?</p>
|
||||
<form method="POST">
|
||||
<input type="hidden" name="token" value="<?php echo e($token); ?>">
|
||||
<input type="hidden" name="confirm" value="1">
|
||||
<button type="submit" class="btn btn-danger">Sì, annulla la prenotazione</button>
|
||||
</form>
|
||||
<p class="muted">Se hai cambiato idea, chiudi pure questa pagina.</p>
|
||||
<?php endif; ?>
|
||||
</div>
|
||||
</body>
|
||||
|
||||
</html>
|
||||
@@ -1,247 +0,0 @@
|
||||
<?php
|
||||
require_once __DIR__ . '/bootstrap.php';
|
||||
require_once dirname(__DIR__) . '/include/event_mailer.php';
|
||||
|
||||
/**
|
||||
* Riconferma di una promozione da lista d'attesa (stato 'offered' -> 'confirmed').
|
||||
* GET confirm.php?token=... -> pagina di conferma (non modifica nulla)
|
||||
* POST (token + confirm=1) -> conferma il posto e invia l'email di conferma.
|
||||
*/
|
||||
$pdo = pdo_conn();
|
||||
$token = trim($_POST['token'] ?? $_GET['token'] ?? '');
|
||||
$isPost = ($_SERVER['REQUEST_METHOD'] ?? 'GET') === 'POST';
|
||||
|
||||
$booking = null;
|
||||
if ($token !== '') {
|
||||
$q = $pdo->prepare("SELECT b.*, e.title AS ev_title, e.starts_at AS ev_starts, e.id AS eid
|
||||
FROM event_bookings b JOIN events e ON e.id = b.event_id
|
||||
WHERE b.token = ?");
|
||||
$q->execute([$token]);
|
||||
$booking = $q->fetch(PDO::FETCH_ASSOC);
|
||||
}
|
||||
|
||||
$state = 'form'; // form | notfound | already | invalid | toolate | done | error
|
||||
|
||||
if (!$booking) {
|
||||
$state = 'notfound';
|
||||
} elseif ($booking['status'] === 'confirmed') {
|
||||
$state = 'already';
|
||||
} elseif ($booking['status'] !== 'offered') {
|
||||
// waiting / cancelled / ecc.: non c'è un'offerta da confermare
|
||||
$state = 'invalid';
|
||||
} elseif (strtotime($booking['ev_starts']) <= time()) {
|
||||
$state = 'toolate';
|
||||
} elseif ($isPost && !empty($_POST['confirm'])) {
|
||||
try {
|
||||
$upd = $pdo->prepare("UPDATE event_bookings SET status = 'confirmed', updated_at = NOW() WHERE id = ? AND status = 'offered'");
|
||||
$upd->execute([(int) $booking['id']]);
|
||||
|
||||
if ($upd->rowCount() > 0) {
|
||||
$state = 'done';
|
||||
// Email di conferma definitiva (best-effort)
|
||||
try {
|
||||
$ev = $pdo->prepare("SELECT * FROM events WHERE id = ?");
|
||||
$ev->execute([(int) $booking['eid']]);
|
||||
$evRow = $ev->fetch(PDO::FETCH_ASSOC);
|
||||
if ($evRow) {
|
||||
$booking['status'] = 'confirmed';
|
||||
yse_mail_booking($booking, $evRow);
|
||||
}
|
||||
} catch (Throwable $me) {
|
||||
error_log('[confirm mail] ' . $me->getMessage());
|
||||
}
|
||||
} else {
|
||||
$state = 'invalid';
|
||||
}
|
||||
} catch (Throwable $ex) {
|
||||
error_log('[apiwp/confirm] ' . $ex->getMessage());
|
||||
$state = 'error';
|
||||
}
|
||||
}
|
||||
|
||||
function e($v): string
|
||||
{
|
||||
return htmlspecialchars((string) $v, ENT_QUOTES, 'UTF-8');
|
||||
}
|
||||
?>
|
||||
<!doctype html>
|
||||
<html lang="it">
|
||||
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<title>Conferma posto — YogaSoul</title>
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<link rel="preconnect" href="https://fonts.googleapis.com">
|
||||
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
|
||||
<link href="https://fonts.googleapis.com/css2?family=Fraunces:opsz,wght@9..144,500;9..144,600&family=Inter:wght@400;500;600&display=swap" rel="stylesheet">
|
||||
<style>
|
||||
:root {
|
||||
--accent: #1a7f52;
|
||||
--ink: #2b2622;
|
||||
--muted: #8c837c;
|
||||
--line: #ece7e2;
|
||||
--paper: #faf8f6;
|
||||
}
|
||||
|
||||
* {
|
||||
box-sizing: border-box;
|
||||
}
|
||||
|
||||
body {
|
||||
margin: 0;
|
||||
background: var(--paper);
|
||||
color: var(--ink);
|
||||
font-family: 'Inter', system-ui, sans-serif;
|
||||
display: flex;
|
||||
min-height: 100vh;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
padding: 24px;
|
||||
}
|
||||
|
||||
.card {
|
||||
background: #fff;
|
||||
border-radius: 18px;
|
||||
box-shadow: 0 14px 40px rgba(43, 38, 34, .10);
|
||||
max-width: 460px;
|
||||
width: 100%;
|
||||
padding: 34px 30px;
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
.icn {
|
||||
width: 58px;
|
||||
height: 58px;
|
||||
border-radius: 50%;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
margin: 0 auto 16px;
|
||||
font-size: 26px;
|
||||
}
|
||||
|
||||
.icn.ok {
|
||||
background: #e7f7ee;
|
||||
color: #1a7f52;
|
||||
}
|
||||
|
||||
.icn.info {
|
||||
background: #eef0f3;
|
||||
color: #6b7280;
|
||||
}
|
||||
|
||||
.icn.warn {
|
||||
background: #fdecea;
|
||||
color: #c0392b;
|
||||
}
|
||||
|
||||
h1 {
|
||||
font-family: 'Fraunces', serif;
|
||||
font-weight: 600;
|
||||
font-size: 23px;
|
||||
margin: 0 0 8px;
|
||||
}
|
||||
|
||||
p {
|
||||
color: #4a433d;
|
||||
font-size: 15px;
|
||||
margin: 6px 0;
|
||||
}
|
||||
|
||||
.ev {
|
||||
background: var(--paper);
|
||||
border-radius: 12px;
|
||||
padding: 14px 16px;
|
||||
margin: 18px 0;
|
||||
}
|
||||
|
||||
.ev .t {
|
||||
font-weight: 600;
|
||||
}
|
||||
|
||||
.ev .d {
|
||||
color: var(--muted);
|
||||
font-size: 14px;
|
||||
margin-top: 2px;
|
||||
}
|
||||
|
||||
.btn {
|
||||
border: none;
|
||||
border-radius: 11px;
|
||||
padding: 14px 20px;
|
||||
font-size: 15px;
|
||||
font-weight: 600;
|
||||
font-family: inherit;
|
||||
cursor: pointer;
|
||||
width: 100%;
|
||||
margin-top: 6px;
|
||||
}
|
||||
|
||||
.btn-ok {
|
||||
background: #1a7f52;
|
||||
color: #fff;
|
||||
}
|
||||
|
||||
.btn-ok:hover {
|
||||
filter: brightness(.94);
|
||||
}
|
||||
|
||||
.muted {
|
||||
color: var(--muted);
|
||||
font-size: 13px;
|
||||
margin-top: 14px;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<div class="card">
|
||||
<?php if ($state === 'notfound') : ?>
|
||||
<div class="icn warn">✕</div>
|
||||
<h1>Link non valido</h1>
|
||||
<p>Questo link non è valido o è scaduto.</p>
|
||||
|
||||
<?php elseif ($state === 'already') : ?>
|
||||
<div class="icn ok">✓</div>
|
||||
<h1>Posto già confermato</h1>
|
||||
<p>Il tuo posto per <strong><?php echo e($booking['ev_title']); ?></strong> è già confermato. Ci vediamo lì!</p>
|
||||
|
||||
<?php elseif ($state === 'invalid') : ?>
|
||||
<div class="icn info">i</div>
|
||||
<h1>Offerta non più disponibile</h1>
|
||||
<p>Questa offerta non è più valida. Se pensi ci sia un errore, contattaci.</p>
|
||||
|
||||
<?php elseif ($state === 'toolate') : ?>
|
||||
<div class="icn info">⏱</div>
|
||||
<h1>Evento già iniziato</h1>
|
||||
<p>Non è più possibile confermare online. Contattaci per assistenza.</p>
|
||||
|
||||
<?php elseif ($state === 'error') : ?>
|
||||
<div class="icn warn">!</div>
|
||||
<h1>Si è verificato un errore</h1>
|
||||
<p>Riprova tra poco. Se il problema persiste, contattaci.</p>
|
||||
|
||||
<?php elseif ($state === 'done') : ?>
|
||||
<div class="icn ok">✓</div>
|
||||
<h1>Posto confermato!</h1>
|
||||
<p>Grazie <strong><?php echo e($booking['name']); ?></strong>, il tuo posto per <strong><?php echo e($booking['ev_title']); ?></strong> è confermato. Ti abbiamo inviato l'email con tutti i dettagli.</p>
|
||||
|
||||
<?php else : /* form */ ?>
|
||||
<div class="icn ok">🎉</div>
|
||||
<h1>Si è liberato un posto!</h1>
|
||||
<div class="ev">
|
||||
<div class="t"><?php echo e($booking['ev_title']); ?></div>
|
||||
<div class="d"><?php echo e(date('d/m/Y H:i', strtotime($booking['ev_starts']))); ?> · <?php echo (int) $booking['seats']; ?> post<?php echo (int) $booking['seats'] === 1 ? 'o' : 'i'; ?></div>
|
||||
</div>
|
||||
<p>Confermi la tua presenza, <strong><?php echo e($booking['name']); ?></strong>?</p>
|
||||
<form method="POST">
|
||||
<input type="hidden" name="token" value="<?php echo e($token); ?>">
|
||||
<input type="hidden" name="confirm" value="1">
|
||||
<button type="submit" class="btn btn-ok">Sì, confermo il posto</button>
|
||||
</form>
|
||||
<p class="muted">Se non puoi partecipare, ignora pure questa email: il posto passerà a un'altra persona.</p>
|
||||
<?php endif; ?>
|
||||
</div>
|
||||
</body>
|
||||
|
||||
</html>
|
||||
@@ -1,127 +0,0 @@
|
||||
<?php
|
||||
require_once __DIR__ . '/bootstrap.php';
|
||||
require_once dirname(__DIR__) . '/include/event_waitlist.php';
|
||||
require_once dirname(__DIR__) . '/include/event_mailer.php';
|
||||
|
||||
/**
|
||||
* CRON unico del modulo Eventi. Da richiamare periodicamente (es. ogni 10 min).
|
||||
* Protezione: chiave segreta in .env (YSE_CRON_KEY) passata come ?key=...
|
||||
*
|
||||
* Fa tre cose a ogni giro:
|
||||
* 1) Pubblica gli eventi programmati arrivati alla data di apertura.
|
||||
* 2) Invia i promemoria automatici (ore effettive per-evento o default), 1 sola volta.
|
||||
* 3) Applica la scadenza delle offerte lista d'attesa (offered non riconfermati):
|
||||
* li annulla e offre il posto al prossimo in coda (email E).
|
||||
*/
|
||||
|
||||
$pdo = pdo_conn(); // carica anche il .env (per la chiave e le MAIL_*)
|
||||
|
||||
$expected = $_ENV['YSE_CRON_KEY'] ?? '';
|
||||
$provided = (string) ($_GET['key'] ?? '');
|
||||
if ($expected === '' || !hash_equals($expected, $provided)) {
|
||||
send_json(['ok' => false, 'error' => 'Forbidden'], 403);
|
||||
}
|
||||
|
||||
$report = ['published' => 0, 'reminders' => 0, 'offers_expired' => 0, 'promoted' => 0];
|
||||
|
||||
// Default scuola
|
||||
$opt = [];
|
||||
try {
|
||||
$opt = $pdo->query("SELECT * FROM `option` LIMIT 1")->fetch(PDO::FETCH_ASSOC) ?: [];
|
||||
} catch (Throwable $e) {
|
||||
$opt = [];
|
||||
}
|
||||
$defRemEnabled = ($opt['event_reminder_enabled'] ?? 'N') === 'Y';
|
||||
$defRemHours = (int) ($opt['event_reminder_hours'] ?? 24);
|
||||
$defOfferHours = (int) ($opt['event_offer_expiry_hours'] ?? 24);
|
||||
|
||||
/* 1) Pubblica gli eventi programmati arrivati a scadenza */
|
||||
try {
|
||||
$pub = $pdo->prepare("UPDATE events SET status = 'published', updated_at = NOW()
|
||||
WHERE status = 'scheduled' AND publish_at IS NOT NULL AND publish_at <= NOW()");
|
||||
$pub->execute();
|
||||
$report['published'] = $pub->rowCount();
|
||||
} catch (Throwable $e) {
|
||||
error_log('[cron publish] ' . $e->getMessage());
|
||||
}
|
||||
|
||||
/* 2) Promemoria automatici (una sola volta per evento) */
|
||||
try {
|
||||
$evs = $pdo->query("SELECT * FROM events
|
||||
WHERE status = 'published' AND reminder_sent_at IS NULL AND starts_at > NOW()")
|
||||
->fetchAll(PDO::FETCH_ASSOC);
|
||||
foreach ($evs as $ev) {
|
||||
$enabled = $ev['reminder_enabled'] !== null ? ($ev['reminder_enabled'] === 'Y') : $defRemEnabled;
|
||||
if (!$enabled) {
|
||||
continue;
|
||||
}
|
||||
$hours = $ev['reminder_hours'] !== null ? (int) $ev['reminder_hours'] : $defRemHours;
|
||||
if (strtotime($ev['starts_at']) - $hours * 3600 > time()) {
|
||||
continue; // non ancora l'ora del promemoria
|
||||
}
|
||||
$ps = $pdo->prepare("SELECT * FROM event_bookings WHERE event_id = ? AND status = 'confirmed'");
|
||||
$ps->execute([$ev['id']]);
|
||||
foreach ($ps->fetchAll(PDO::FETCH_ASSOC) as $p) {
|
||||
try {
|
||||
yse_mail_reminder($p, $ev);
|
||||
$report['reminders']++;
|
||||
} catch (Throwable $me) {
|
||||
error_log('[cron reminder] ' . $me->getMessage());
|
||||
}
|
||||
}
|
||||
$pdo->prepare("UPDATE events SET reminder_sent_at = NOW() WHERE id = ?")->execute([$ev['id']]);
|
||||
}
|
||||
} catch (Throwable $e) {
|
||||
error_log('[cron reminders] ' . $e->getMessage());
|
||||
}
|
||||
|
||||
/* 3) Scadenza offerte lista d'attesa */
|
||||
try {
|
||||
$offers = $pdo->query("SELECT b.*, e.offer_expiry_hours AS ev_offer_hours
|
||||
FROM event_bookings b JOIN events e ON e.id = b.event_id
|
||||
WHERE b.status = 'offered' AND b.offered_at IS NOT NULL")
|
||||
->fetchAll(PDO::FETCH_ASSOC);
|
||||
foreach ($offers as $o) {
|
||||
$hours = $o['ev_offer_hours'] !== null ? (int) $o['ev_offer_hours'] : $defOfferHours;
|
||||
if (strtotime($o['offered_at']) + $hours * 3600 > time()) {
|
||||
continue; // offerta ancora valida
|
||||
}
|
||||
$promoted = [];
|
||||
try {
|
||||
$pdo->beginTransaction();
|
||||
$pdo->prepare("SELECT id FROM events WHERE id = ? FOR UPDATE")->execute([(int) $o['event_id']]);
|
||||
$st = $pdo->prepare("SELECT status FROM event_bookings WHERE id = ?");
|
||||
$st->execute([(int) $o['id']]);
|
||||
if ($st->fetchColumn() === 'offered') {
|
||||
$pdo->prepare("UPDATE event_bookings SET status = 'cancelled', updated_at = NOW() WHERE id = ?")
|
||||
->execute([(int) $o['id']]);
|
||||
$promoted = promoteFromWaitlist($pdo, (int) $o['event_id']);
|
||||
$report['offers_expired']++;
|
||||
}
|
||||
$pdo->commit();
|
||||
|
||||
if (!empty($promoted)) {
|
||||
$ev = $pdo->prepare("SELECT * FROM events WHERE id = ?");
|
||||
$ev->execute([(int) $o['event_id']]);
|
||||
$evRow = $ev->fetch(PDO::FETCH_ASSOC);
|
||||
foreach ($promoted as $pr) {
|
||||
try {
|
||||
yse_mail_promotion($pr, $evRow);
|
||||
$report['promoted']++;
|
||||
} catch (Throwable $pe) {
|
||||
error_log('[cron promo] ' . $pe->getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (Throwable $te) {
|
||||
if ($pdo->inTransaction()) {
|
||||
$pdo->rollBack();
|
||||
}
|
||||
error_log('[cron offer] ' . $te->getMessage());
|
||||
}
|
||||
}
|
||||
} catch (Throwable $e) {
|
||||
error_log('[cron offers] ' . $e->getMessage());
|
||||
}
|
||||
|
||||
send_json(['ok' => true, 'report' => $report, 'at' => date('c')]);
|
||||
@@ -1,133 +0,0 @@
|
||||
<?php
|
||||
require_once __DIR__ . '/bootstrap.php';
|
||||
|
||||
/**
|
||||
* Endpoint pubblico LISTA eventi (sola lettura).
|
||||
* Ritorna gli eventi PUBBLICATI e NON ancora terminati, con posti/prezzo/gallery.
|
||||
*
|
||||
* Parametri (query string):
|
||||
* ?id=12 -> un solo evento
|
||||
* ?ids=12,15,20 -> solo questi eventi (nell'ordine per data)
|
||||
* ?limit=3 -> massimo N eventi
|
||||
* Senza parametri: tutti i pubblicati futuri, per data crescente.
|
||||
*
|
||||
* Regole di visibilità:
|
||||
* status = 'published' AND COALESCE(ends_at, starts_at) >= NOW()
|
||||
* (l'evento sparisce da solo quando è terminato)
|
||||
*/
|
||||
try {
|
||||
$pdo = pdo_conn();
|
||||
|
||||
$id = isset($_GET['id']) ? (int) $_GET['id'] : 0;
|
||||
$idsParam = trim($_GET['ids'] ?? '');
|
||||
$limit = isset($_GET['limit']) ? max(1, min(50, (int) $_GET['limit'])) : 0;
|
||||
|
||||
$where = ["e.status IN ('published','scheduled')", "COALESCE(e.ends_at, e.starts_at) >= NOW()"];
|
||||
$params = [];
|
||||
|
||||
if ($id > 0) {
|
||||
$where[] = 'e.id = ?';
|
||||
$params[] = $id;
|
||||
} elseif ($idsParam !== '') {
|
||||
$ids = array_values(array_filter(array_map('intval', explode(',', $idsParam)), function ($v) {
|
||||
return $v > 0;
|
||||
}));
|
||||
if (!empty($ids)) {
|
||||
$where[] = 'e.id IN (' . implode(',', array_fill(0, count($ids), '?')) . ')';
|
||||
foreach ($ids as $v) {
|
||||
$params[] = $v;
|
||||
}
|
||||
} else {
|
||||
send_json(['ok' => true, 'count' => 0, 'events' => []]);
|
||||
}
|
||||
}
|
||||
|
||||
$sql = "SELECT e.*, u.first_name AS cf, u.last_name AS cl,
|
||||
COALESCE(b.occupied, 0) AS occupied,
|
||||
COALESCE(w.waiting, 0) AS waiting
|
||||
FROM events e
|
||||
LEFT JOIN auth_users u ON u.id = e.user_id
|
||||
LEFT JOIN (
|
||||
SELECT event_id, SUM(seats) AS occupied
|
||||
FROM event_bookings WHERE status IN ('confirmed','pending','offered')
|
||||
GROUP BY event_id
|
||||
) b ON b.event_id = e.id
|
||||
LEFT JOIN (
|
||||
SELECT event_id, SUM(seats) AS waiting
|
||||
FROM event_bookings WHERE status = 'waiting'
|
||||
GROUP BY event_id
|
||||
) w ON w.event_id = e.id
|
||||
WHERE " . implode(' AND ', $where) . "
|
||||
ORDER BY e.starts_at ASC";
|
||||
|
||||
if ($limit > 0) {
|
||||
$sql .= ' LIMIT ' . (int) $limit;
|
||||
}
|
||||
|
||||
$stmt = $pdo->prepare($sql);
|
||||
$stmt->execute($params);
|
||||
$rows = $stmt->fetchAll(PDO::FETCH_ASSOC);
|
||||
|
||||
$symbols = ['EUR' => '€', 'USD' => '$', 'GBP' => '£', 'CHF' => 'CHF'];
|
||||
$events = [];
|
||||
|
||||
foreach ($rows as $r) {
|
||||
$maxSeats = (int) $r['max_seats'];
|
||||
$occupied = (int) $r['occupied'];
|
||||
$remaining = max(0, $maxSeats - $occupied);
|
||||
|
||||
$gallery = [];
|
||||
if (!empty($r['gallery'])) {
|
||||
$g = json_decode($r['gallery'], true);
|
||||
if (is_array($g)) {
|
||||
foreach ($g as $path) {
|
||||
if (is_string($path) && $path !== '') {
|
||||
$gallery[] = public_url($path);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$organizer = trim((string) $r['organizer_name']) !== ''
|
||||
? $r['organizer_name']
|
||||
: trim(($r['cf'] ?? '') . ' ' . ($r['cl'] ?? ''));
|
||||
|
||||
$events[] = [
|
||||
'id' => (int) $r['id'],
|
||||
'title' => $r['title'],
|
||||
'slug' => $r['slug'],
|
||||
'status' => $r['status'],
|
||||
'scheduled' => $r['status'] === 'scheduled',
|
||||
'bookable' => $r['status'] === 'published',
|
||||
'publish_at' => $r['publish_at'],
|
||||
'description' => $r['description'], // HTML (sanificare al rendering in WP)
|
||||
'instructions' => $r['instructions'],
|
||||
'what_to_bring' => $r['what_to_bring'],
|
||||
'suitable_for' => $r['suitable_for'],
|
||||
'organizer' => $organizer !== '' ? $organizer : null,
|
||||
'starts_at' => $r['starts_at'],
|
||||
'ends_at' => $r['ends_at'],
|
||||
'address' => $r['address'],
|
||||
'lat' => $r['lat'] !== null ? (float) $r['lat'] : null,
|
||||
'lng' => $r['lng'] !== null ? (float) $r['lng'] : null,
|
||||
'cost' => (float) $r['cost'],
|
||||
'currency' => $r['currency'],
|
||||
'currency_symbol' => $symbols[$r['currency']] ?? $r['currency'],
|
||||
'color' => $r['color'],
|
||||
'cover_image' => public_url($r['cover_image']),
|
||||
'gallery' => $gallery,
|
||||
'max_seats' => $maxSeats,
|
||||
'max_per_booking' => (int) $r['max_per_booking'],
|
||||
'occupied' => $occupied,
|
||||
'remaining' => $remaining,
|
||||
'sold_out' => $remaining <= 0,
|
||||
'waitlist_enabled' => ($r['waitlist_enabled'] ?? 'N') === 'Y',
|
||||
'waiting' => (int) $r['waiting'],
|
||||
];
|
||||
}
|
||||
|
||||
send_json(['ok' => true, 'count' => count($events), 'events' => $events]);
|
||||
} catch (Throwable $ex) {
|
||||
error_log('[api/events] ' . $ex->getMessage());
|
||||
send_json(['ok' => false, 'error' => 'Errore nel recupero degli eventi.'], 500);
|
||||
}
|
||||
Binary file not shown.
|
Before Width: | Height: | Size: 132 KiB |
Binary file not shown.
|
Before Width: | Height: | Size: 222 KiB |
Binary file not shown.
|
Before Width: | Height: | Size: 222 KiB |
Binary file not shown.
|
Before Width: | Height: | Size: 163 KiB |
Binary file not shown.
|
Before Width: | Height: | Size: 132 KiB |
Binary file not shown.
|
Before Width: | Height: | Size: 160 KiB |
@@ -33,29 +33,17 @@ if (isset($_POST['formclass']) && $_POST['formclass'] === 'Y') {
|
||||
$idassociateservice = (int) ($_POST['servicelist'] ?? 0);
|
||||
|
||||
if ($idmainservice > 0 && $idassociateservice > 0) {
|
||||
// Evita duplicati: inserisci solo se l'associazione non esiste già
|
||||
$stmtCheck = $pdo->prepare(
|
||||
"SELECT COUNT(*) FROM associateclass
|
||||
WHERE idmainservice = :main AND idassociateservice = :assoc"
|
||||
$stmt = $pdo->prepare(
|
||||
"INSERT INTO associateclass (idmainservice, idassociateservice)
|
||||
VALUES (:main, :assoc)"
|
||||
);
|
||||
$stmtCheck->execute([':main' => $idmainservice, ':assoc' => $idassociateservice]);
|
||||
$alreadyExists = (int) $stmtCheck->fetchColumn() > 0;
|
||||
|
||||
if ($alreadyExists) {
|
||||
$insertFeedback = ['type' => 'error', 'text' => 'Questa classe è già associata.'];
|
||||
} else {
|
||||
$stmt = $pdo->prepare(
|
||||
"INSERT INTO associateclass (idmainservice, idassociateservice)
|
||||
VALUES (:main, :assoc)"
|
||||
);
|
||||
$ok = $stmt->execute([
|
||||
':main' => $idmainservice,
|
||||
':assoc' => $idassociateservice,
|
||||
]);
|
||||
$insertFeedback = $ok
|
||||
? ['type' => 'success', 'text' => 'Associazione aggiunta con successo.']
|
||||
: ['type' => 'error', 'text' => 'Errore durante l\'associazione. Riprova.'];
|
||||
}
|
||||
$ok = $stmt->execute([
|
||||
':main' => $idmainservice,
|
||||
':assoc' => $idassociateservice,
|
||||
]);
|
||||
$insertFeedback = $ok
|
||||
? ['type' => 'success', 'text' => 'Associazione aggiunta con successo.']
|
||||
: ['type' => 'error', 'text' => 'Errore durante l\'associazione. Riprova.'];
|
||||
} else {
|
||||
$insertFeedback = ['type' => 'error', 'text' => 'Seleziona una classe da associare.'];
|
||||
}
|
||||
@@ -78,21 +66,12 @@ if ($idmain > 0) {
|
||||
}
|
||||
|
||||
/* -------------------------------------------------------------------------
|
||||
* Elenco delle classi per il dropdown:
|
||||
* esclude la principale E quelle già associate a questa principale.
|
||||
* Elenco di tutte le classi (per il dropdown), escludendo la principale
|
||||
* ---------------------------------------------------------------------- */
|
||||
$stmtAll = $pdo->prepare(
|
||||
"SELECT idservice, servicename
|
||||
FROM service
|
||||
WHERE idservice != :idmain
|
||||
AND idservice NOT IN (
|
||||
SELECT idassociateservice
|
||||
FROM associateclass
|
||||
WHERE idmainservice = :idmain2
|
||||
)
|
||||
ORDER BY servicename"
|
||||
"SELECT idservice, servicename FROM service WHERE idservice != :idmain ORDER BY servicename"
|
||||
);
|
||||
$stmtAll->execute([':idmain' => $idmain, ':idmain2' => $idmain]);
|
||||
$stmtAll->execute([':idmain' => $idmain]);
|
||||
$allServices = $stmtAll->fetchAll();
|
||||
|
||||
/* -------------------------------------------------------------------------
|
||||
@@ -272,9 +251,6 @@ $associatedClasses = $stmtAssoc->fetchAll();
|
||||
</option>
|
||||
<?php endforeach; ?>
|
||||
</select>
|
||||
<?php if (empty($allServices)) : ?>
|
||||
<small class="text-muted">Tutte le classi disponibili sono già state associate.</small>
|
||||
<?php endif; ?>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
+36
-56
@@ -1,24 +1,33 @@
|
||||
<?php
|
||||
require_once('include/headscript.php');
|
||||
require_once __DIR__ . '/class/mailer.php';
|
||||
require_once('include/waitinglist.php');
|
||||
|
||||
use PHPMailer\PHPMailer\PHPMailer;
|
||||
use PHPMailer\PHPMailer\Exception;
|
||||
|
||||
require_once('include/headscript.php');
|
||||
require 'phpmailer/src/Exception.php';
|
||||
require 'phpmailer/src/PHPMailer.php';
|
||||
require 'phpmailer/src/SMTP.php';
|
||||
|
||||
// Abilita il reporting degli errori per il debug
|
||||
ini_set('display_errors', 1);
|
||||
error_reporting(E_ALL);
|
||||
|
||||
// Recupera i parametri GET
|
||||
$idorder = isset($_GET['idorder']) ? (int) $_GET['idorder'] : 0;
|
||||
$idnewbooking = isset($_GET['idnewbooking']) ? (int) $_GET['idnewbooking'] : 0;
|
||||
$iduser = isset($_GET['iduser']) ? (int) $_GET['iduser'] : 0;
|
||||
$idservicenew = isset($_GET['idservicenew']) ? (int) $_GET['idservicenew'] : 0;
|
||||
$idorder = isset($_GET['idorder']) ? (int)$_GET['idorder'] : 0;
|
||||
$idnewbooking = isset($_GET['idnewbooking']) ? (int)$_GET['idnewbooking'] : 0;
|
||||
$iduser = isset($_GET['iduser']) ? (int)$_GET['iduser'] : 0;
|
||||
$idservicenew = isset($_GET['idservicenew']) ? (int)$_GET['idservicenew'] : 0;
|
||||
|
||||
// Valida i parametri richiesti
|
||||
if ($idorder === 0 || $idnewbooking === 0 || $iduser === 0 || $idservicenew === 0) {
|
||||
die("Errore: Parametri mancanti.");
|
||||
}
|
||||
|
||||
// Riusa la connessione già aperta da bkngstm.php
|
||||
$conn = $bkngstm;
|
||||
// Crea la connessione al database
|
||||
$conn = new mysqli($servername, $username, $password, $dbname);
|
||||
if ($conn->connect_error) {
|
||||
die("Connessione al database fallita: " . $conn->connect_error);
|
||||
}
|
||||
|
||||
// Recupera dateschedule e servicename
|
||||
$query = "SELECT serviceschedule.dateschedule, service.servicename
|
||||
@@ -36,6 +45,7 @@ if ($resultnew->num_rows > 0) {
|
||||
$servicename = $rownew['servicename'] ?? 'N/D';
|
||||
} else {
|
||||
$stmt->close();
|
||||
$conn->close();
|
||||
die("Errore: Nessun orario trovato per idserviceschedule = $idnewbooking.");
|
||||
}
|
||||
$stmt->close();
|
||||
@@ -43,35 +53,14 @@ $stmt->close();
|
||||
// Formatta la data per l'email
|
||||
$newtimeformat = date("d-m-Y H:i", strtotime($newtime));
|
||||
|
||||
// Recupera nome ed email dell'utente per la mail
|
||||
$firstname = '';
|
||||
$emailuser = '';
|
||||
$stmtUser = $conn->prepare("SELECT first_name, email FROM auth_users WHERE id = ?");
|
||||
$stmtUser->bind_param("i", $iduser);
|
||||
$stmtUser->execute();
|
||||
$resUser = $stmtUser->get_result();
|
||||
if ($rowUser = $resUser->fetch_assoc()) {
|
||||
$firstname = $rowUser['first_name'] ?? '';
|
||||
$emailuser = $rowUser['email'] ?? '';
|
||||
}
|
||||
$stmtUser->close();
|
||||
|
||||
// Decide lo stato: pending se c'è posto, waiting se la classe è piena
|
||||
$bookingStatus = decideBookingStatus($conn, $idnewbooking);
|
||||
|
||||
if ($bookingStatus === 'full') {
|
||||
// Classe piena e lista d'attesa disattivata: non inseriamo nulla
|
||||
header("Location: userpanel.php?full=Y");
|
||||
exit();
|
||||
}
|
||||
|
||||
// Inserisce la nuova prenotazione in bookingclass
|
||||
$insertQuery = "INSERT INTO bookingclass (idserviceschedule, iduser, prevbookingstart, idprevserviceschedule, idservice, idorder, bookingstart, status)
|
||||
VALUES (?, ?, NULL, '0', ?, ?, ?, ?)";
|
||||
VALUES (?, ?, '0', '0', ?, ?, ?, 'pending')";
|
||||
$stmt = $conn->prepare($insertQuery);
|
||||
$stmt->bind_param("iiiiss", $idnewbooking, $iduser, $idservicenew, $idorder, $newtime, $bookingStatus);
|
||||
$stmt->bind_param("iiiis", $idnewbooking, $iduser, $idservicenew, $idorder, $newtime);
|
||||
if (!$stmt->execute()) {
|
||||
$stmt->close();
|
||||
$conn->close();
|
||||
die("Errore durante l'inserimento della nuova prenotazione: " . $conn->error);
|
||||
}
|
||||
$stmt->close();
|
||||
@@ -86,16 +75,8 @@ $stmt->bind_param("ii", $iduser, $idorder);
|
||||
$stmt->execute();
|
||||
$stmt->close();
|
||||
|
||||
// Connessione $bkngstm gestita globalmente: non la chiudiamo qui
|
||||
|
||||
// Parametro di ritorno diverso se finito in lista d'attesa
|
||||
$redirectFlag = ($bookingStatus === 'waiting') ? 'waiting=Y' : 'reprogram=Y';
|
||||
|
||||
// Se non abbiamo un'email valida, salta l'invio ma completa comunque il flusso
|
||||
if ($emailuser === '') {
|
||||
header("Location: userpanel.php?$redirectFlag");
|
||||
exit();
|
||||
}
|
||||
// Chiudi la connessione al database
|
||||
$conn->close();
|
||||
|
||||
// Configura il contenuto dell'email
|
||||
$messageedit = "
|
||||
@@ -129,11 +110,11 @@ $messageedit = "
|
||||
<br>
|
||||
<p style='font-size: 14px; line-height: 190%;'>
|
||||
<span style='font-size: 16px; line-height: 30.4px;'>
|
||||
Se non ricordi la password o non hai sei mai entrata in Yogibbok, per prima cosa resettare la password cliccando di seguito:
|
||||
Per il primo accesso devi prima resettare la password cliccando qui:
|
||||
</span>
|
||||
</p>
|
||||
<br>
|
||||
<a href='https://yogibook.yogasoul.it/password/reset' target='_blank' style='box-sizing: border-box; display: inline-block; text-decoration: none; text-align: center; color: #FFFFFF; background-color: #3AAEE0; border-radius: 4px; width: auto; max-width: 100%; font-size: 14px;'>
|
||||
<a href='https://yogibook.yogasoul.it/public/password/reset' target='_blank' style='box-sizing: border-box; display: inline-block; text-decoration: none; text-align: center; color: #FFFFFF; background-color: #3AAEE0; border-radius: 4px; width: auto; max-width: 100%; font-size: 14px;'>
|
||||
<span style='display: block; padding: 10px 20px; line-height: 120%;'>Reset Password</span>
|
||||
</a>
|
||||
<br>
|
||||
@@ -160,26 +141,25 @@ include('mail/emailtemplate2.php');
|
||||
$mail = new PHPMailer(true);
|
||||
try {
|
||||
$mail->isSMTP();
|
||||
$mail->Host = $_ENV['MAIL_HOST'];
|
||||
$mail->SMTPAuth = true;
|
||||
$mail->Username = $_ENV['MAIL_USERNAME'];
|
||||
$mail->Password = $_ENV['MAIL_PASSWORD'];
|
||||
$mail->SMTPSecure = $_ENV['MAIL_ENCRYPTION'];
|
||||
$mail->Port = (int) $_ENV['MAIL_PORT'];
|
||||
$mail->Host = 'mail.yogasoul.it';
|
||||
$mail->SMTPAuth = true;
|
||||
$mail->Username = 'info@yogasoul.it';
|
||||
$mail->Password = '!Testolina88';
|
||||
$mail->SMTPSecure = 'tls';
|
||||
$mail->Port = 587;
|
||||
|
||||
$mail->setFrom($_ENV['MAIL_FROM_ADDRESS'], $_ENV['MAIL_FROM_NAME']);
|
||||
$mail->setFrom('info@yogasoul.it', 'YogiBook [YogaSoul]');
|
||||
$mail->addAddress($emailuser);
|
||||
|
||||
$mail->Subject = "Proposta di riprogrammazione!";
|
||||
$mail->Body = $mailmessage1;
|
||||
$mail->Body = $mailmessage1;
|
||||
$mail->AltBody = 'Hai inviato una richiesta di riprogrammazione della tua lezione per il servizio ' . $servicename . ' il ' . $newtimeformat . '. La tua richiesta è in fase di accettazione.';
|
||||
|
||||
$mail->send();
|
||||
} catch (Exception $e) {
|
||||
// La prenotazione è già salvata: logghiamo l'errore mail ma non blocchiamo l'utente
|
||||
error_log("Errore invio mail riprogrammazione (iduser $iduser): " . $mail->ErrorInfo);
|
||||
die("Errore durante l'invio dell'email: " . $mail->ErrorInfo);
|
||||
}
|
||||
|
||||
// Esegui il reindirizzamento
|
||||
header("Location: userpanel.php?$redirectFlag");
|
||||
header("Location: userpanel.php?reprogram=Y");
|
||||
exit();
|
||||
|
||||
+41
-58
@@ -177,70 +177,66 @@ $conn->close();
|
||||
|
||||
<style>
|
||||
.custom-card {
|
||||
background: #fff;
|
||||
border-radius: 14px;
|
||||
box-shadow: 0 3px 16px rgba(0, 0, 0, 0.06);
|
||||
overflow: hidden;
|
||||
margin-bottom: 18px;
|
||||
margin: 10px auto;
|
||||
display: flex;
|
||||
width: 90%;
|
||||
max-width: 700px;
|
||||
background-color: white;
|
||||
box-shadow: 0px 2px 4px rgba(0, 0, 0, 0.1);
|
||||
border-radius: 8px;
|
||||
overflow: hidden;
|
||||
cursor: pointer;
|
||||
transition: box-shadow 0.2s;
|
||||
transition: transform 0.2s;
|
||||
}
|
||||
|
||||
.custom-card:hover {
|
||||
box-shadow: 0 6px 22px rgba(0, 0, 0, 0.1);
|
||||
transform: translateY(-5px);
|
||||
}
|
||||
|
||||
.custom-date-box {
|
||||
flex: 0 0 110px;
|
||||
color: #fff;
|
||||
flex: 1;
|
||||
background-color: red;
|
||||
color: white;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
padding: 16px;
|
||||
padding: 0;
|
||||
font-size: 60px;
|
||||
font-weight: bold;
|
||||
border-top-left-radius: 8px;
|
||||
border-bottom-left-radius: 8px;
|
||||
}
|
||||
|
||||
.custom-day {
|
||||
font-size: 44px;
|
||||
font-weight: 800;
|
||||
line-height: 1;
|
||||
}
|
||||
|
||||
.custom-month {
|
||||
font-size: 18px;
|
||||
text-transform: uppercase;
|
||||
letter-spacing: 0.05em;
|
||||
font-size: 28px;
|
||||
}
|
||||
|
||||
.custom-event-details {
|
||||
flex: 1;
|
||||
flex: 2;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
padding: 18px 22px;
|
||||
background: #fff;
|
||||
border-left: 20px solid #ccc;
|
||||
/* colore impostato inline per ogni card in base allo stato */
|
||||
padding: 10px 20px;
|
||||
background-color: lightblue;
|
||||
}
|
||||
|
||||
.custom-heading {
|
||||
font-size: 19px;
|
||||
font-weight: 700;
|
||||
color: #1f2937;
|
||||
margin: 0 0 4px;
|
||||
margin-top: 0;
|
||||
font-size: 24px;
|
||||
}
|
||||
|
||||
.custom-paragraph {
|
||||
color: #6b7280;
|
||||
font-size: 14px;
|
||||
margin-bottom: 3px;
|
||||
margin-bottom: 5px;
|
||||
}
|
||||
|
||||
.custom-actions {
|
||||
display: none;
|
||||
flex-direction: row;
|
||||
gap: 8px;
|
||||
flex-wrap: wrap;
|
||||
justify-content: space-between;
|
||||
margin-top: 10px;
|
||||
}
|
||||
|
||||
@@ -249,19 +245,16 @@ $conn->close();
|
||||
}
|
||||
|
||||
.custom-action-button {
|
||||
background-color: #f0f0f0;
|
||||
border: none;
|
||||
border-radius: 8px;
|
||||
padding: 7px 14px;
|
||||
font-size: 13px;
|
||||
font-weight: 600;
|
||||
background: #eef2f7;
|
||||
color: #374151;
|
||||
padding: 8px 12px;
|
||||
border-radius: 4px;
|
||||
cursor: pointer;
|
||||
transition: filter 0.15s;
|
||||
transition: background-color 0.2s;
|
||||
}
|
||||
|
||||
.custom-action-button:hover {
|
||||
filter: brightness(0.94);
|
||||
background-color: #e0e0e0;
|
||||
}
|
||||
|
||||
@media (max-width: 768px) {
|
||||
@@ -269,20 +262,14 @@ $conn->close();
|
||||
flex-direction: column;
|
||||
}
|
||||
|
||||
.custom-date-box {
|
||||
flex: 0 0 auto;
|
||||
.custom-date-box,
|
||||
.custom-event-details {
|
||||
width: 100%;
|
||||
flex-direction: row;
|
||||
gap: 10px;
|
||||
padding: 12px;
|
||||
border-radius: 0;
|
||||
}
|
||||
|
||||
.custom-day {
|
||||
font-size: 30px;
|
||||
}
|
||||
|
||||
.custom-month {
|
||||
font-size: 18px;
|
||||
.custom-event-time {
|
||||
font-size: 24px;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -507,7 +494,7 @@ $conn->close();
|
||||
|
||||
$mysqli = new mysqli($servername, $username, $password, $dbname);
|
||||
$eventId = $bookedclass->getColumnVal("idserviceschedule");
|
||||
$bookingQuery = "SELECT iduser FROM bookingclass WHERE bookingclass.idserviceschedule = ? AND bookingclass.status IN ('booked','pending')";
|
||||
$bookingQuery = "SELECT iduser FROM bookingclass WHERE bookingclass.idserviceschedule = ? AND bookingclass.status='booked'";
|
||||
$stmt = $mysqli->prepare($bookingQuery);
|
||||
$stmt->bind_param("i", $eventId);
|
||||
$stmt->execute();
|
||||
@@ -538,17 +525,17 @@ $conn->close();
|
||||
<?php } elseif ($freeplace > 0) { ?>
|
||||
<div class="custom-date-box" style="background-color:#1ebf73">
|
||||
<?php } else { ?>
|
||||
<div class="custom-date-box" style="background-color:#d1698a">
|
||||
<div class="custom-date-box" style="background-color:#9C9C9C">
|
||||
<?php } ?>
|
||||
<div class="custom-day"><?php echo $dayInItalian; ?></div>
|
||||
<div class="custom-month"><?php echo $monthInItalian; ?></div>
|
||||
</div>
|
||||
<?php if ($alreadybooked == 'Y') { ?>
|
||||
<div class="custom-event-details" style="background-color:#FFAC7A;border-left-color:#FF6609">
|
||||
<div class="custom-event-details" style="background-color:#FFAC7A">
|
||||
<?php } elseif ($freeplace > 0) { ?>
|
||||
<div class="custom-event-details" style="border-left-color:<?php echo ($bookedclass->getColumnVal("colorclass")); ?>">
|
||||
<div class="custom-event-details" style="background-color:<?php echo ($bookedclass->getColumnVal("colorclass")); ?>">
|
||||
<?php } else { ?>
|
||||
<div class="custom-event-details" style="background-color:#fbeef3;border-left-color:#d1698a">
|
||||
<div class="custom-event-details" style="background-color:#CDCDCD">
|
||||
<?php } ?>
|
||||
<h2 class="custom-heading"><?php echo ($bookedclass->getColumnVal("servicename")); ?> -<?php echo $countPersons; ?>/<?php echo ($bookedclass->getColumnVal("maxcapacity")); ?></h2>
|
||||
<p class="custom-paragraph">Quando: <?php echo $newDateFormat; ?></p>
|
||||
@@ -561,11 +548,7 @@ $conn->close();
|
||||
<?php } elseif ($freeplace > 0) { ?>
|
||||
<a href="rebookandgo.php?idpreviousbooking=<?php echo $idpreviousbooking; ?>&idservicenew=<?php echo $idservicenew; ?>&idnewbooking=<?php echo $idnewbooking; ?>&iduser=<?php echo $iduserlogin; ?>"><button class="booking-button"><i class="fas fa-arrow-circle-right"></i> Riprogramma Classe</button></a>
|
||||
<?php } else { ?>
|
||||
<?php if ($optionquery->getColumnVal("waitinglist_enabled") === 'Y') { ?>
|
||||
<a href="rebookandgo.php?idpreviousbooking=<?php echo $idpreviousbooking; ?>&idservicenew=<?php echo $idservicenew; ?>&idnewbooking=<?php echo $idnewbooking; ?>&iduser=<?php echo $iduserlogin; ?>"><button class="booking-button" style="background-color:#d1698a;color:#fff;"><i class="fas fa-hourglass-half"></i> Mettiti in lista d'attesa</button></a>
|
||||
<?php } else { ?>
|
||||
<button class="booking-button"><i class="fa fa-stop"></i> Classe Piena</button>
|
||||
<?php } ?>
|
||||
<button class="booking-button"><i class="fa fa-stop"></i> Classe Piena</button>
|
||||
<?php } ?>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
+547
-567
File diff suppressed because it is too large
Load Diff
@@ -1,13 +1,20 @@
|
||||
<?php
|
||||
// Connessione al database
|
||||
include('include/headscript.php');
|
||||
require_once __DIR__ . '/class/mailer.php';
|
||||
// Abilita visualizzazione errori PHP (solo per debug)
|
||||
ini_set('display_errors', 1);
|
||||
ini_set('display_startup_errors', 1);
|
||||
error_reporting(E_ALL);
|
||||
|
||||
use PHPMailer\PHPMailer\PHPMailer;
|
||||
use PHPMailer\PHPMailer\Exception;
|
||||
|
||||
// Riusa la connessione già aperta da bkngstm.php
|
||||
$conn = $bkngstm;
|
||||
// Connessione al database
|
||||
include('include/headscript.php');
|
||||
|
||||
$conn = new mysqli($servername, $username, $password, $dbname);
|
||||
if ($conn->connect_error) {
|
||||
die("Connessione al database fallita: " . $conn->connect_error);
|
||||
}
|
||||
|
||||
// Inizializza log
|
||||
$logFile = 'cancella_prenotazione_log.txt';
|
||||
$logMessage = "Esecuzione cancellazione: " . date('Y-m-d H:i:s') . "\n";
|
||||
@@ -40,7 +47,7 @@ if (!$idbookingclass) {
|
||||
// Verifica validità: token corrisponde, lezione futura
|
||||
$query = "SELECT bc.*, ob.expireon, au.email, au.first_name, s.servicename
|
||||
FROM bookingclass bc
|
||||
LEFT JOIN orderbook ob ON bc.idorder = ob.idorderbook
|
||||
LEFT JOIN orderbook ob ON bc.idorder = ob.order_id
|
||||
LEFT JOIN auth_users au ON bc.iduser = au.id
|
||||
LEFT JOIN service s ON bc.idservice = s.idservice
|
||||
WHERE bc.idbookingclass = ?
|
||||
@@ -169,15 +176,19 @@ if (isset($_GET['action']) && $_GET['action'] === 'cancel') {
|
||||
<span style='display:block;padding:10px 20px;line-height:120%;'><span style='line-height: 16.8px;'>YogiBook - YogaSoul</span></span>
|
||||
</a>";
|
||||
|
||||
require_once 'phpmailer/src/Exception.php';
|
||||
require_once 'phpmailer/src/PHPMailer.php';
|
||||
require_once 'phpmailer/src/SMTP.php';
|
||||
|
||||
$mail = new PHPMailer(true);
|
||||
try {
|
||||
$mail->isSMTP();
|
||||
$mail->Host = $_ENV['MAIL_HOST'];
|
||||
$mail->SMTPAuth = true;
|
||||
$mail->Username = $_ENV['MAIL_USERNAME'];
|
||||
$mail->Password = $_ENV['MAIL_PASSWORD'];
|
||||
$mail->SMTPSecure = $_ENV['MAIL_ENCRYPTION'];
|
||||
$mail->Port = (int) $_ENV['MAIL_PORT'];
|
||||
$mail->Host = 'mail.yogasoul.it';
|
||||
$mail->SMTPAuth = true;
|
||||
$mail->Username = 'info@yogasoul.it';
|
||||
$mail->Password = '!Testolina88';
|
||||
$mail->SMTPSecure = 'tls';
|
||||
$mail->Port = 587;
|
||||
|
||||
if (!file_exists('mail/emailtemplate2.php')) {
|
||||
throw new Exception("File emailtemplate2.php non trovato.");
|
||||
@@ -190,8 +201,8 @@ if (isset($_GET['action']) && $_GET['action'] === 'cancel') {
|
||||
|
||||
$htmlContent = str_replace('{message}', $messagecancel, $mailmessage1);
|
||||
|
||||
$mail->From = $_ENV['MAIL_FROM_ADDRESS'];
|
||||
$mail->FromName = $_ENV['MAIL_FROM_NAME'];
|
||||
$mail->From = 'info@yogasoul.it';
|
||||
$mail->FromName = 'YogiBook [YogaSoul]';
|
||||
$mail->addAddress($emailuser);
|
||||
$mail->Subject = "YogiBook - Lezione cancellata con successo!";
|
||||
$mail->Body = $htmlContent;
|
||||
@@ -303,5 +314,5 @@ file_put_contents($logFile, $logMessage, FILE_APPEND);
|
||||
</html>
|
||||
<?php
|
||||
$stmt->close();
|
||||
// Connessione $bkngstm gestita globalmente: non la chiudiamo qui
|
||||
$conn->close();
|
||||
?>
|
||||
@@ -1,36 +0,0 @@
|
||||
<?php
|
||||
require_once('include/headscript.php');
|
||||
$pdo = DBHandlerSelect::getInstance()->getConnection();
|
||||
|
||||
$token = $_GET['token'] ?? '';
|
||||
$confirm = ($_GET['confirm'] ?? '') === 'Y';
|
||||
|
||||
if ($token === '') {
|
||||
header('Location: admin-services.php');
|
||||
exit;
|
||||
}
|
||||
|
||||
// Conta le prenotazioni utente collegate alle lezioni di questa propagazione
|
||||
$stmt = $pdo->prepare(
|
||||
"SELECT COUNT(*) FROM bookingclass b
|
||||
JOIN serviceschedule s ON b.idserviceschedule = s.idserviceschedule
|
||||
WHERE s.propagation_token = :token"
|
||||
);
|
||||
$stmt->execute([':token' => $token]);
|
||||
$prenotazioni = (int) $stmt->fetchColumn();
|
||||
|
||||
// Se ci sono prenotazioni e non è ancora arrivata la conferma esplicita -> chiedi
|
||||
if ($prenotazioni > 0 && !$confirm) {
|
||||
header('Location: admin-services.php?message=confirmdelete&token=' . urlencode($token) . '&count=' . $prenotazioni);
|
||||
exit;
|
||||
}
|
||||
|
||||
// Procedi con la cancellazione
|
||||
$stmt = $pdo->prepare("DELETE FROM serviceschedule WHERE propagation_token = :token");
|
||||
$stmt->execute([':token' => $token]);
|
||||
|
||||
$stmt = $pdo->prepare("DELETE FROM propagation WHERE token = :token");
|
||||
$stmt->execute([':token' => $token]);
|
||||
|
||||
header('Location: admin-services.php?message=propdeleted');
|
||||
exit;
|
||||
@@ -1,10 +1,14 @@
|
||||
<?php
|
||||
// Debug iniziale
|
||||
error_log("== Inizio mailer.php ==");
|
||||
|
||||
// Percorso assoluto alla root (es. /home/wnunknek/yogibook.yogasoul.it/)
|
||||
$rootPath = dirname(__DIR__, 2);
|
||||
error_log("Root path: $rootPath");
|
||||
|
||||
// Percorso al vendor
|
||||
$vendorPath = $rootPath . '/vendor/autoload.php';
|
||||
error_log("Vendor path: $vendorPath");
|
||||
|
||||
if (!file_exists($vendorPath)) {
|
||||
die("❌ vendor/autoload.php non trovato in $vendorPath");
|
||||
@@ -20,3 +24,5 @@ use PHPMailer\PHPMailer\Exception;
|
||||
// ✅ Caricamento variabili .env
|
||||
$dotenv = Dotenv::createImmutable($rootPath);
|
||||
$dotenv->load();
|
||||
|
||||
error_log("✅ Variabili .env caricate: " . print_r($_ENV, true));
|
||||
|
||||
@@ -0,0 +1,374 @@
|
||||
<?php
|
||||
|
||||
require_once dirname(__DIR__, 2) . '/vendor/autoload.php';
|
||||
|
||||
use Dotenv\Dotenv;
|
||||
|
||||
date_default_timezone_set('Europe/Rome');
|
||||
|
||||
class PushSender
|
||||
{
|
||||
/** @var string */
|
||||
private $projectId;
|
||||
|
||||
/**
|
||||
* @var string Endpoint di Google. Si puo' sovrascrivere con FCM_OAUTH_URL /
|
||||
* FCM_BASE_URL nel .env: serve SOLO per i test locali, che puntano a un
|
||||
* finto server FCM. In produzione queste variabili non vanno impostate.
|
||||
*/
|
||||
private $oauthUrl;
|
||||
|
||||
/** @var string */
|
||||
private $baseUrl;
|
||||
|
||||
/** @var array Contenuto del service account JSON */
|
||||
private $credentials;
|
||||
|
||||
/** @var string|null Token OAuth2 in cache per la durata dello script */
|
||||
private $accessToken = null;
|
||||
|
||||
/** @var int Timestamp di scadenza del token in cache */
|
||||
private $accessTokenExpiry = 0;
|
||||
|
||||
/**
|
||||
* @var string|null Se l'autenticazione con Google fallisce, il motivo resta qui:
|
||||
* gli invii successivi escono subito invece di ritentare per ogni utente.
|
||||
*/
|
||||
private $authFallita = null;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$rootPath = dirname(__DIR__, 2);
|
||||
|
||||
// Le variabili possono essere gia' state caricate da un altro require:
|
||||
// safeLoad non esplode se il .env manca o e' gia' in memoria.
|
||||
$dotenv = Dotenv::createImmutable($rootPath);
|
||||
$dotenv->safeLoad();
|
||||
|
||||
$this->projectId = $_ENV['FCM_PROJECT_ID'] ?? '';
|
||||
$credentialsPath = $_ENV['FCM_CREDENTIALS_PATH'] ?? '';
|
||||
$this->oauthUrl = $_ENV['FCM_OAUTH_URL'] ?? 'https://oauth2.googleapis.com/token';
|
||||
$this->baseUrl = $_ENV['FCM_BASE_URL'] ?? 'https://fcm.googleapis.com';
|
||||
|
||||
if ($this->projectId === '' || $credentialsPath === '') {
|
||||
throw new RuntimeException(
|
||||
'FCM_PROJECT_ID o FCM_CREDENTIALS_PATH mancanti nel file .env'
|
||||
);
|
||||
}
|
||||
|
||||
// Percorso relativo -> lo consideriamo a partire dalla root del progetto.
|
||||
if ($credentialsPath[0] !== '/') {
|
||||
$credentialsPath = $rootPath . '/' . $credentialsPath;
|
||||
}
|
||||
|
||||
if (!is_readable($credentialsPath)) {
|
||||
throw new RuntimeException("Service account non leggibile: $credentialsPath");
|
||||
}
|
||||
|
||||
$json = json_decode((string) file_get_contents($credentialsPath), true);
|
||||
|
||||
if (!is_array($json) || empty($json['client_email']) || empty($json['private_key'])) {
|
||||
throw new RuntimeException("Service account non valido: $credentialsPath");
|
||||
}
|
||||
|
||||
$this->credentials = $json;
|
||||
}
|
||||
|
||||
/**
|
||||
* Invia la notifica a tutti i dispositivi attivi dell'utente.
|
||||
* I token rifiutati da FCM vengono disattivati (active = 'N').
|
||||
*
|
||||
* @return array ['sent' => int, 'failed' => int, 'errors' => string[], 'no_devices' => bool]
|
||||
* no_devices = l'utente non ha dispositivi registrati: non e'
|
||||
* un errore, semplicemente non ha (ancora) aperto l'app.
|
||||
*/
|
||||
public function sendToUser(PDO $db, int $iduser, string $title, string $body, array $data = []): array
|
||||
{
|
||||
$stmt = $db->prepare("
|
||||
SELECT iduserdevicetoken, devicetoken
|
||||
FROM userdevicetoken
|
||||
WHERE iduser = :uid AND active = 'Y'
|
||||
");
|
||||
$stmt->execute([':uid' => $iduser]);
|
||||
$devices = $stmt->fetchAll(PDO::FETCH_ASSOC);
|
||||
|
||||
$esito = ['sent' => 0, 'failed' => 0, 'errors' => [], 'no_devices' => !$devices];
|
||||
|
||||
foreach ($devices as $device) {
|
||||
$risultato = $this->sendToToken($device['devicetoken'], $title, $body, $data);
|
||||
|
||||
if ($risultato['ok']) {
|
||||
$esito['sent']++;
|
||||
continue;
|
||||
}
|
||||
|
||||
$esito['failed']++;
|
||||
$esito['errors'][] = $risultato['error'];
|
||||
|
||||
// Token non piu' valido (app disinstallata, token rigenerato):
|
||||
// lo spegniamo per non riprovarci ad ogni giro di cron.
|
||||
if ($risultato['invalid_token']) {
|
||||
$upd = $db->prepare("
|
||||
UPDATE userdevicetoken SET active = 'N' WHERE iduserdevicetoken = :id
|
||||
");
|
||||
$upd->execute([':id' => $device['iduserdevicetoken']]);
|
||||
}
|
||||
}
|
||||
|
||||
return $esito;
|
||||
}
|
||||
|
||||
/**
|
||||
* Invia la notifica a un singolo token.
|
||||
*
|
||||
* @return array ['ok' => bool, 'error' => string, 'invalid_token' => bool]
|
||||
*/
|
||||
public function sendToToken(string $deviceToken, string $title, string $body, array $data = []): array
|
||||
{
|
||||
// Autenticazione gia' fallita in questo giro: inutile riprovare per ogni
|
||||
// singolo utente, il cron deve solo finire in fretta e scrivere il log.
|
||||
if ($this->authFallita !== null) {
|
||||
return ['ok' => false, 'error' => $this->authFallita, 'invalid_token' => false];
|
||||
}
|
||||
|
||||
try {
|
||||
$accessToken = $this->getAccessToken();
|
||||
} catch (Throwable $e) {
|
||||
// Un problema di credenziali o di rete non deve interrompere il cron:
|
||||
// lo registriamo e le notifiche restanti risulteranno "failed".
|
||||
$this->authFallita = 'auth: ' . $e->getMessage();
|
||||
|
||||
return ['ok' => false, 'error' => $this->authFallita, 'invalid_token' => false];
|
||||
}
|
||||
|
||||
$url = "{$this->baseUrl}/v1/projects/{$this->projectId}/messages:send";
|
||||
|
||||
// FCM accetta solo stringhe dentro "data".
|
||||
$payloadData = [];
|
||||
foreach ($data as $chiave => $valore) {
|
||||
$payloadData[(string) $chiave] = (string) $valore;
|
||||
}
|
||||
|
||||
$messaggio = [
|
||||
'message' => [
|
||||
'token' => $deviceToken,
|
||||
'notification' => [
|
||||
'title' => $title,
|
||||
'body' => $body,
|
||||
],
|
||||
// Attenzione: un array PHP vuoto diventa [] in JSON, ma FCM si
|
||||
// aspetta un oggetto e risponde 400. Se non ci sono dati da
|
||||
// mandare, il campo va proprio omesso.
|
||||
'data' => (object) $payloadData,
|
||||
'android' => ['priority' => 'high'],
|
||||
'apns' => [
|
||||
'headers' => ['apns-priority' => '10'],
|
||||
'payload' => ['aps' => ['sound' => 'default']],
|
||||
],
|
||||
],
|
||||
];
|
||||
|
||||
$ch = curl_init($url);
|
||||
curl_setopt_array($ch, [
|
||||
CURLOPT_POST => true,
|
||||
CURLOPT_RETURNTRANSFER => true,
|
||||
CURLOPT_TIMEOUT => 15,
|
||||
CURLOPT_HTTPHEADER => [
|
||||
'Authorization: Bearer ' . $accessToken,
|
||||
'Content-Type: application/json; charset=UTF-8',
|
||||
],
|
||||
CURLOPT_POSTFIELDS => json_encode($messaggio, JSON_UNESCAPED_UNICODE),
|
||||
]);
|
||||
|
||||
$risposta = curl_exec($ch);
|
||||
$codice = (int) curl_getinfo($ch, CURLINFO_HTTP_CODE);
|
||||
$errCurl = curl_error($ch);
|
||||
curl_close($ch);
|
||||
|
||||
if ($risposta === false) {
|
||||
return ['ok' => false, 'error' => "curl: $errCurl", 'invalid_token' => false];
|
||||
}
|
||||
|
||||
if ($codice >= 200 && $codice < 300) {
|
||||
return ['ok' => true, 'error' => '', 'invalid_token' => false];
|
||||
}
|
||||
|
||||
$decodificata = json_decode((string) $risposta, true);
|
||||
$statoErrore = $decodificata['error']['status'] ?? '';
|
||||
|
||||
// UNREGISTERED / NOT_FOUND = app disinstallata o token non piu' valido.
|
||||
//
|
||||
// INVALID_ARGUMENT NON va messo qui: quasi sempre vuol dire che siamo
|
||||
// noi a mandare un messaggio malformato, e spegnere i dispositivi degli
|
||||
// utenti per un nostro errore li lascerebbe senza notifiche per sempre.
|
||||
$tokenNonValido = in_array($statoErrore, ['UNREGISTERED', 'NOT_FOUND'], true);
|
||||
|
||||
return [
|
||||
'ok' => false,
|
||||
'error' => "HTTP $codice: " . substr((string) $risposta, 0, 300),
|
||||
'invalid_token' => $tokenNonValido,
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Token OAuth2 per FCM: JWT firmato con la chiave del service account,
|
||||
* scambiato con un access token da Google. Vale un'ora, lo teniamo in cache.
|
||||
*/
|
||||
private function getAccessToken(): string
|
||||
{
|
||||
if ($this->accessToken !== null && time() < $this->accessTokenExpiry - 60) {
|
||||
return $this->accessToken;
|
||||
}
|
||||
|
||||
$adesso = time();
|
||||
|
||||
$header = ['alg' => 'RS256', 'typ' => 'JWT'];
|
||||
$claim = [
|
||||
'iss' => $this->credentials['client_email'],
|
||||
'scope' => 'https://www.googleapis.com/auth/firebase.messaging',
|
||||
'aud' => 'https://oauth2.googleapis.com/token',
|
||||
'iat' => $adesso,
|
||||
'exp' => $adesso + 3600,
|
||||
];
|
||||
|
||||
$daFirmare = $this->base64UrlEncode(json_encode($header))
|
||||
. '.' . $this->base64UrlEncode(json_encode($claim));
|
||||
|
||||
$firma = '';
|
||||
if (!openssl_sign($daFirmare, $firma, $this->credentials['private_key'], OPENSSL_ALGO_SHA256)) {
|
||||
throw new RuntimeException('Firma del JWT fallita (chiave del service account non valida?)');
|
||||
}
|
||||
|
||||
$jwt = $daFirmare . '.' . $this->base64UrlEncode($firma);
|
||||
|
||||
$ch = curl_init($this->oauthUrl);
|
||||
curl_setopt_array($ch, [
|
||||
CURLOPT_POST => true,
|
||||
CURLOPT_RETURNTRANSFER => true,
|
||||
CURLOPT_TIMEOUT => 15,
|
||||
CURLOPT_POSTFIELDS => http_build_query([
|
||||
'grant_type' => 'urn:ietf:params:oauth:grant-type:jwt-bearer',
|
||||
'assertion' => $jwt,
|
||||
]),
|
||||
]);
|
||||
|
||||
$risposta = curl_exec($ch);
|
||||
$codice = (int) curl_getinfo($ch, CURLINFO_HTTP_CODE);
|
||||
curl_close($ch);
|
||||
|
||||
$decodificata = json_decode((string) $risposta, true);
|
||||
|
||||
if ($codice !== 200 || empty($decodificata['access_token'])) {
|
||||
throw new RuntimeException(
|
||||
'Impossibile ottenere il token OAuth2 da Google: ' . substr((string) $risposta, 0, 300)
|
||||
);
|
||||
}
|
||||
|
||||
$this->accessToken = $decodificata['access_token'];
|
||||
$this->accessTokenExpiry = $adesso + (int) ($decodificata['expires_in'] ?? 3600);
|
||||
|
||||
return $this->accessToken;
|
||||
}
|
||||
|
||||
private function base64UrlEncode(string $dati): string
|
||||
{
|
||||
return rtrim(strtr(base64_encode($dati), '+/', '-_'), '=');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Sostituisce i segnaposto nei testi presi da notificationsetting.
|
||||
* Esempio: pushRender('Ciao {first_name}', ['first_name' => 'Anna'])
|
||||
*/
|
||||
function pushRender(string $testo, array $valori): string
|
||||
{
|
||||
foreach ($valori as $chiave => $valore) {
|
||||
$testo = str_replace('{' . $chiave . '}', (string) $valore, $testo);
|
||||
}
|
||||
|
||||
return $testo;
|
||||
}
|
||||
|
||||
/**
|
||||
* Legge le impostazioni di un tipo di notifica (lesson / order / certificate).
|
||||
* Ritorna solo le righe attive, ordinate dal preavviso piu' lungo.
|
||||
*/
|
||||
function pushSettings(PDO $db, string $tipo): array
|
||||
{
|
||||
$stmt = $db->prepare("
|
||||
SELECT idnotificationsetting, notificationtype, daysbefore, sendhour,
|
||||
title, title_multi, body, body_multi
|
||||
FROM notificationsetting
|
||||
WHERE notificationtype = :tipo AND active = 'Y'
|
||||
ORDER BY daysbefore DESC
|
||||
");
|
||||
$stmt->execute([':tipo' => $tipo]);
|
||||
|
||||
return $stmt->fetchAll(PDO::FETCH_ASSOC);
|
||||
}
|
||||
|
||||
/**
|
||||
* Verifica se una notifica e' gia' stata inviata (chiave anti-duplicato).
|
||||
*
|
||||
* Contano solo gli invii andati a buon fine: se il tentativo precedente era
|
||||
* fallito (Firebase irraggiungibile, credenziali sbagliate) il giro successivo
|
||||
* del cron deve riprovare.
|
||||
*/
|
||||
function pushGiaInviata(PDO $db, int $iduser, string $tipo, int $idreference, int $daysbefore): bool
|
||||
{
|
||||
$stmt = $db->prepare("
|
||||
SELECT 1
|
||||
FROM notificationlog
|
||||
WHERE iduser = :uid
|
||||
AND notificationtype = :tipo
|
||||
AND idreference = :idref
|
||||
AND daysbefore = :giorni
|
||||
AND status = 'sent'
|
||||
LIMIT 1
|
||||
");
|
||||
$stmt->execute([
|
||||
':uid' => $iduser,
|
||||
':tipo' => $tipo,
|
||||
':idref' => $idreference,
|
||||
':giorni' => $daysbefore,
|
||||
]);
|
||||
|
||||
return (bool) $stmt->fetchColumn();
|
||||
}
|
||||
|
||||
/**
|
||||
* Scrive l'esito dell'invio nello storico.
|
||||
*
|
||||
* La chiave unica impedisce i doppioni; se la riga esiste gia' (tentativo
|
||||
* precedente fallito) viene aggiornata con l'esito nuovo.
|
||||
*/
|
||||
function pushRegistraInvio(
|
||||
PDO $db,
|
||||
int $iduser,
|
||||
string $tipo,
|
||||
int $idreference,
|
||||
int $daysbefore,
|
||||
array $esito
|
||||
): void {
|
||||
$stmt = $db->prepare("
|
||||
INSERT INTO notificationlog
|
||||
(iduser, notificationtype, idreference, daysbefore, status, devicecount, errormessage)
|
||||
VALUES
|
||||
(:uid, :tipo, :idref, :giorni, :stato, :dispositivi, :errore)
|
||||
ON DUPLICATE KEY UPDATE
|
||||
status = VALUES(status),
|
||||
devicecount = VALUES(devicecount),
|
||||
errormessage = VALUES(errormessage),
|
||||
sent_at = NOW()
|
||||
");
|
||||
|
||||
$stmt->execute([
|
||||
':uid' => $iduser,
|
||||
':tipo' => $tipo,
|
||||
':idref' => $idreference,
|
||||
':giorni' => $daysbefore,
|
||||
':stato' => $esito['sent'] > 0 ? 'sent' : 'failed',
|
||||
':dispositivi' => $esito['sent'],
|
||||
':errore' => $esito['errors'] ? substr(implode(' | ', $esito['errors']), 0, 255) : null,
|
||||
]);
|
||||
}
|
||||
@@ -1,38 +0,0 @@
|
||||
<?php
|
||||
// Buffer per scartare eventuale HTML degli include: risposta JSON pulita
|
||||
ob_start();
|
||||
require_once('include/headscript.php');
|
||||
|
||||
/**
|
||||
* Conferma una prenotazione in attesa: pending -> booked.
|
||||
*/
|
||||
$pdo = DBHandlerSelect::getInstance()->getConnection();
|
||||
|
||||
function jsonOut(array $payload): void
|
||||
{
|
||||
if (ob_get_length() !== false) {
|
||||
ob_end_clean();
|
||||
}
|
||||
header('Content-Type: application/json; charset=utf-8');
|
||||
echo json_encode($payload, JSON_UNESCAPED_UNICODE);
|
||||
exit;
|
||||
}
|
||||
|
||||
$idbookingclass = isset($_POST['idbookingclass']) ? (int) $_POST['idbookingclass'] : 0;
|
||||
|
||||
if ($idbookingclass <= 0) {
|
||||
jsonOut(['success' => false, 'error' => 'ID prenotazione non valido.']);
|
||||
}
|
||||
|
||||
try {
|
||||
// Conferma solo se effettivamente in pending (evita conferme accidentali)
|
||||
$stmt = $pdo->prepare(
|
||||
"UPDATE bookingclass SET status = 'booked'
|
||||
WHERE idbookingclass = :id AND status = 'pending'"
|
||||
);
|
||||
$stmt->execute([':id' => $idbookingclass]);
|
||||
jsonOut(['success' => true]);
|
||||
} catch (Throwable $ex) {
|
||||
error_log('conferma_pending error: ' . $ex->getMessage());
|
||||
jsonOut(['success' => false, 'error' => 'Errore durante la conferma.']);
|
||||
}
|
||||
@@ -30,7 +30,10 @@ $userId = (int)$iduserlogin;
|
||||
/***********************
|
||||
* DB
|
||||
***********************/
|
||||
$conn = $bkngstm;
|
||||
$conn = new mysqli($servername, $username, $password, $dbname);
|
||||
if ($conn->connect_error) {
|
||||
die("Connessione fallita: " . $conn->connect_error);
|
||||
}
|
||||
|
||||
/***********************
|
||||
* 1) USER INFO (auth_users)
|
||||
@@ -66,6 +69,7 @@ $bk = $res->fetch_assoc();
|
||||
$stmt->close();
|
||||
|
||||
if (!$bk) {
|
||||
$conn->close();
|
||||
header("Location: userpanel.php?deleted=0&err=notfound");
|
||||
exit();
|
||||
}
|
||||
@@ -85,11 +89,12 @@ $stmt->bind_param("ii", $id, $userId);
|
||||
if (!$stmt->execute()) {
|
||||
$err = $stmt->error;
|
||||
$stmt->close();
|
||||
$conn->close();
|
||||
die("Errore durante la cancellazione del record: " . htmlspecialchars($err));
|
||||
}
|
||||
|
||||
$stmt->close();
|
||||
// Connessione $bkngstm gestita globalmente: non la chiudiamo qui
|
||||
$conn->close();
|
||||
|
||||
/***********************
|
||||
* 4) EMAIL (TO utente + CC info@yogasoul.it)
|
||||
|
||||
@@ -1,43 +0,0 @@
|
||||
<?php
|
||||
$conn = new mysqli($servername, $username, $password, $dbname);
|
||||
require_once('include/headscript.php'); // per avere le credenziali DB, se sono lì
|
||||
|
||||
// Se le credenziali sono in headscript.php, sposta la connessione DOPO il require.
|
||||
// Adatta questa parte a come sono definite $servername ecc. nelle tue altre pagine.
|
||||
|
||||
if ($conn->connect_error) {
|
||||
die("Connessione fallita: " . $conn->connect_error);
|
||||
}
|
||||
|
||||
if (!isset($_GET['id']) || !is_numeric($_GET['id'])) {
|
||||
header("Location: riepilogo.php?message=error_delete");
|
||||
exit();
|
||||
}
|
||||
|
||||
$idorder = (int) $_GET['id'];
|
||||
|
||||
$conn->begin_transaction();
|
||||
|
||||
try {
|
||||
// 1. Cancella tutte le prenotazioni di questo ordine
|
||||
$stmt1 = $conn->prepare("DELETE FROM bookingclass WHERE idorder = ?");
|
||||
$stmt1->bind_param("i", $idorder);
|
||||
$stmt1->execute();
|
||||
$stmt1->close();
|
||||
|
||||
// 2. Cancella l'ordine
|
||||
$stmt2 = $conn->prepare("DELETE FROM orderbook WHERE idorderbook = ?");
|
||||
$stmt2->bind_param("i", $idorder);
|
||||
$stmt2->execute();
|
||||
$stmt2->close();
|
||||
|
||||
$conn->commit();
|
||||
header("Location: riepilogo.php?message=success_delete");
|
||||
exit();
|
||||
} catch (Exception $e) {
|
||||
$conn->rollback();
|
||||
header("Location: riepilogo.php?message=error_delete");
|
||||
exit();
|
||||
}
|
||||
|
||||
$conn->close();
|
||||
+40
-25
@@ -1,36 +1,51 @@
|
||||
<?php
|
||||
require_once __DIR__ . '/class/mailer.php';
|
||||
|
||||
use PHPMailer\PHPMailer\PHPMailer;
|
||||
use PHPMailer\PHPMailer\Exception;
|
||||
ini_set ('display_errors', 1);
|
||||
ini_set ('display_startup_errors', 1);
|
||||
error_reporting (E_ALL);
|
||||
|
||||
$name = "Claudio";
|
||||
//Now include the following following files based
|
||||
//on the correct file path. Third file is required only if you want to enable SMTP.
|
||||
|
||||
|
||||
|
||||
require 'phpmailer/src/Exception.php';
|
||||
require 'phpmailer/src/PHPMailer.php';
|
||||
require 'phpmailer/src/SMTP.php';
|
||||
$name="Claudio";
|
||||
//mail to client
|
||||
|
||||
$mail = new PHPMailer(true);
|
||||
try {
|
||||
$mail->isSMTP();
|
||||
$mail->Host = $_ENV['MAIL_HOST'];
|
||||
$mail->SMTPAuth = true;
|
||||
$mail->Username = $_ENV['MAIL_USERNAME'];
|
||||
$mail->Password = $_ENV['MAIL_PASSWORD'];
|
||||
$mail->SMTPSecure = $_ENV['MAIL_ENCRYPTION'];
|
||||
$mail->Port = (int) $_ENV['MAIL_PORT'];
|
||||
$mail->CharSet = 'UTF-8';
|
||||
$mail->isHTML(true);
|
||||
|
||||
include('mail/emailtemplate2.php');
|
||||
$htmlContent = $mailmessage1;
|
||||
$mail->isSMTP(); // Set mailer to use SMTP
|
||||
$mail->Host = 'mail.yogasoul.it'; // Specify main and backup server
|
||||
$mail->SMTPAuth = true; // Enable SMTP authentication
|
||||
$mail->Username = 'info@yogasoul.it'; // SMTP username
|
||||
$mail->Password = '!Testolina88'; // SMTP password
|
||||
$mail->SMTPSecure = 'tls'; // Enable encryption, 'ssl' also accepted
|
||||
$mail->Port = '587';
|
||||
|
||||
|
||||
$mail->setFrom($_ENV['MAIL_FROM_ADDRESS'], $_ENV['MAIL_FROM_NAME']);
|
||||
$mail->addAddress('info@claudiosironi.com');
|
||||
include('mail/emailtemplate2.php');
|
||||
// Email body content
|
||||
|
||||
$mail->Subject = 'Comunicazione YogiBook';
|
||||
$mail->Body = $htmlContent;
|
||||
$mail->AltBody = 'This is the body in plain text for non-HTML mail clients';
|
||||
//$trfnmbmail=$appformn.'r'.$revnumb;
|
||||
$htmlContent = $mailmessage1;
|
||||
|
||||
|
||||
$mail->From = 'info@yogasoul.it';
|
||||
$mail->FromName = 'YogiBook [YogaSoul]';
|
||||
$mail->addAddress('info@claudiosironi.com'); // Add a recipient
|
||||
|
||||
|
||||
|
||||
|
||||
$mail->Subject = 'Comunicazione YogiBook';
|
||||
$mail->Body = $htmlContent;
|
||||
$mail->AltBody = 'This is the body in plain text for non-HTML mail clients';
|
||||
|
||||
$mail->send();
|
||||
echo 'Message has been sent';
|
||||
} catch (Exception $e) {
|
||||
error_log("Errore invio mail (emailsend): " . $mail->ErrorInfo);
|
||||
echo 'Invio non riuscito';
|
||||
}
|
||||
// echo 'Message has been sent';
|
||||
|
||||
?>
|
||||
@@ -1,58 +0,0 @@
|
||||
<?php
|
||||
require_once('include/headscript.php');
|
||||
require_once('include/event_mailer.php'); // stub mailer (template vero: step successivo)
|
||||
|
||||
/**
|
||||
* Annullamento evento.
|
||||
* Sceglierne uno soft (consigliato): imposta status='cancelled' e mantiene le
|
||||
* prenotazioni/contatti raccolti. Se notify=1 invia la mail di annullamento a
|
||||
* tutti i partecipanti attivi (recuperati PRIMA di annullare).
|
||||
*
|
||||
* Chiamato da events.php: event_delete.php?id=123¬ify=1|0
|
||||
*/
|
||||
$pdo = DBHandlerSelect::getInstance()->getConnection();
|
||||
|
||||
$id = isset($_GET['id']) ? (int) $_GET['id'] : 0;
|
||||
$notify = (int) ($_GET['notify'] ?? 0) === 1;
|
||||
|
||||
if ($id <= 0) {
|
||||
header('Location: events.php');
|
||||
exit();
|
||||
}
|
||||
|
||||
$stmt = $pdo->prepare("SELECT * FROM events WHERE id = ?");
|
||||
$stmt->execute([$id]);
|
||||
$event = $stmt->fetch(PDO::FETCH_ASSOC);
|
||||
if (!$event) {
|
||||
header('Location: events.php?message=error');
|
||||
exit();
|
||||
}
|
||||
|
||||
// 1) Recupera i partecipanti attivi PRIMA di annullare (servono per la mail)
|
||||
$pStmt = $pdo->prepare("SELECT * FROM event_bookings WHERE event_id = ? AND status <> 'cancelled'");
|
||||
$pStmt->execute([$id]);
|
||||
$participants = $pStmt->fetchAll(PDO::FETCH_ASSOC);
|
||||
|
||||
try {
|
||||
// 2) Annulla l'evento (soft) e le relative prenotazioni
|
||||
$pdo->prepare("UPDATE events SET status = 'cancelled', updated_at = NOW() WHERE id = ?")->execute([$id]);
|
||||
$pdo->prepare("UPDATE event_bookings SET status = 'cancelled', updated_at = NOW() WHERE event_id = ? AND status <> 'cancelled'")->execute([$id]);
|
||||
|
||||
// 3) Notifica (opzionale). Il template vero arriva nello step successivo.
|
||||
if ($notify && !empty($participants)) {
|
||||
foreach ($participants as $p) {
|
||||
try {
|
||||
yse_mail_event_cancel($p, $event);
|
||||
} catch (Throwable $mailEx) {
|
||||
error_log('[event_delete mail] ' . $mailEx->getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
header('Location: events.php?message=cancelled');
|
||||
exit();
|
||||
} catch (Throwable $ex) {
|
||||
error_log('[event_delete] ' . $ex->getMessage());
|
||||
header('Location: events.php?message=error');
|
||||
exit();
|
||||
}
|
||||
@@ -1,964 +0,0 @@
|
||||
<?php
|
||||
require_once('include/headscript.php');
|
||||
|
||||
/**
|
||||
* Modulo Eventi - form creazione/modifica (una sola pagina).
|
||||
* - event_form.php -> nuovo evento
|
||||
* - event_form.php?id=123 -> modifica evento esistente
|
||||
* Invia a event_save.php (insert/update + redirect).
|
||||
*
|
||||
* Extra rispetto alla v1:
|
||||
* - flatpickr per data/ora (fine = inizio + 1h automatica)
|
||||
* - sede da event_locations (default scuola) o indirizzo personalizzato
|
||||
* - "Calcola coordinate" da indirizzo (geocoding via event_geocode.php)
|
||||
* - copertina drag&drop -> event_upload_cover.php -> assets/uploads/events/
|
||||
*/
|
||||
$pdo = DBHandlerSelect::getInstance()->getConnection();
|
||||
|
||||
function e($value): string
|
||||
{
|
||||
return htmlspecialchars((string) $value, ENT_QUOTES, 'UTF-8');
|
||||
}
|
||||
|
||||
$id = isset($_GET['id']) ? (int) $_GET['id'] : 0;
|
||||
$ev = null;
|
||||
|
||||
if ($id > 0) {
|
||||
$stmt = $pdo->prepare("SELECT * FROM events WHERE id = ?");
|
||||
$stmt->execute([$id]);
|
||||
$ev = $stmt->fetch(PDO::FETCH_ASSOC);
|
||||
if (!$ev) {
|
||||
header('Location: events.php?message=error');
|
||||
exit();
|
||||
}
|
||||
}
|
||||
|
||||
// Default dal record unico di `option`
|
||||
$opt = $pdo->query("SELECT * FROM `option` LIMIT 1")->fetch(PDO::FETCH_ASSOC);
|
||||
$defaultColor = $opt['event_default_color'] ?? '#4CAF50';
|
||||
$defaultMaxPerBooking = (int) ($opt['event_default_max_per_booking'] ?? 1);
|
||||
$defReminderEnabled = ($opt['event_reminder_enabled'] ?? 'N') === 'Y';
|
||||
$defReminderHours = (int) ($opt['event_reminder_hours'] ?? 24);
|
||||
$defOfferHours = (int) ($opt['event_offer_expiry_hours'] ?? 24);
|
||||
|
||||
// Sedi salvate (se la tabella non esiste ancora, si degrada su indirizzo libero)
|
||||
$locations = [];
|
||||
try {
|
||||
$locations = $pdo->query("SELECT * FROM event_locations ORDER BY is_default DESC, name ASC")->fetchAll(PDO::FETCH_ASSOC);
|
||||
} catch (Throwable $e) {
|
||||
$locations = [];
|
||||
}
|
||||
|
||||
$val = [
|
||||
'title' => $ev['title'] ?? '',
|
||||
'slug' => $ev['slug'] ?? '',
|
||||
'organizer_name' => $ev['organizer_name'] ?? '',
|
||||
'starts_at' => !empty($ev['starts_at']) ? date('Y-m-d H:i', strtotime($ev['starts_at'])) : '',
|
||||
'ends_at' => !empty($ev['ends_at']) ? date('Y-m-d H:i', strtotime($ev['ends_at'])) : '',
|
||||
'address' => $ev['address'] ?? '',
|
||||
'lat' => $ev['lat'] ?? '',
|
||||
'lng' => $ev['lng'] ?? '',
|
||||
'cost' => $ev['cost'] ?? '0.00',
|
||||
'currency' => $ev['currency'] ?? 'EUR',
|
||||
'max_seats' => $ev['max_seats'] ?? '',
|
||||
'max_per_booking' => $ev['max_per_booking'] ?? $defaultMaxPerBooking,
|
||||
'color' => $ev['color'] ?? $defaultColor,
|
||||
'cover_image' => $ev['cover_image'] ?? '',
|
||||
'status' => $ev['status'] ?? 'draft',
|
||||
'description' => $ev['description'] ?? '',
|
||||
'instructions' => $ev['instructions'] ?? '',
|
||||
'what_to_bring' => $ev['what_to_bring'] ?? '',
|
||||
'suitable_for' => $ev['suitable_for'] ?? '',
|
||||
'gallery' => $ev['gallery'] ?? '',
|
||||
'waitlist_enabled' => ($ev['waitlist_enabled'] ?? 'Y') === 'Y',
|
||||
'reminder_enabled' => $ev['reminder_enabled'] ?? null,
|
||||
'reminder_hours' => $ev['reminder_hours'] ?? '',
|
||||
'offer_expiry_hours' => $ev['offer_expiry_hours'] ?? '',
|
||||
'schedule_enabled' => (($ev['status'] ?? '') === 'scheduled') || !empty($ev['publish_at']),
|
||||
'publish_at' => !empty($ev['publish_at']) ? date('Y-m-d H:i', strtotime($ev['publish_at'])) : '',
|
||||
];
|
||||
|
||||
$isEdit = $id > 0;
|
||||
$pageTitle = $isEdit ? 'Modifica evento' : 'Nuovo evento';
|
||||
?>
|
||||
<!doctype html>
|
||||
<html lang="it">
|
||||
|
||||
<head>
|
||||
<meta charset="utf-8" />
|
||||
<title>YogiBook - <?php echo e($pageTitle); ?></title>
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<link rel="shortcut icon" href="assets/images/favicon.ico">
|
||||
<link href="assets/css/bootstrap.min.css" id="bootstrap-style" rel="stylesheet" type="text/css" />
|
||||
<link href="assets/css/icons.min.css" rel="stylesheet" type="text/css" />
|
||||
<link href="assets/css/app.min.css" id="app-style" rel="stylesheet" type="text/css" />
|
||||
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.0.0-beta3/css/all.min.css">
|
||||
<!-- Date/ora -->
|
||||
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/flatpickr/4.6.13/flatpickr.min.css">
|
||||
<script src="https://cdnjs.cloudflare.com/ajax/libs/flatpickr/4.6.13/flatpickr.min.js"></script>
|
||||
<script src="https://cdnjs.cloudflare.com/ajax/libs/flatpickr/4.6.13/l10n/it.min.js"></script>
|
||||
<!-- Editor testo ricco -->
|
||||
<link href="https://cdn.jsdelivr.net/npm/quill@2/dist/quill.snow.css" rel="stylesheet">
|
||||
<script src="https://cdn.jsdelivr.net/npm/quill@2/dist/quill.js"></script>
|
||||
<script src="https://cdn.jsdelivr.net/npm/sweetalert2@11"></script>
|
||||
|
||||
<style>
|
||||
.admin-card {
|
||||
border: none;
|
||||
border-radius: 14px;
|
||||
box-shadow: 0 4px 20px rgba(0, 0, 0, 0.06);
|
||||
}
|
||||
|
||||
.admin-card .card-body {
|
||||
padding: 26px 30px;
|
||||
}
|
||||
|
||||
.section-title {
|
||||
font-size: 15px;
|
||||
font-weight: 700;
|
||||
letter-spacing: 0.04em;
|
||||
text-transform: uppercase;
|
||||
color: #6b7280;
|
||||
margin-bottom: 4px;
|
||||
}
|
||||
|
||||
.section-lead {
|
||||
color: #9ca3af;
|
||||
font-size: 14px;
|
||||
margin-bottom: 22px;
|
||||
}
|
||||
|
||||
.form-label {
|
||||
font-weight: 600;
|
||||
font-size: 14px;
|
||||
color: #374151;
|
||||
}
|
||||
|
||||
.form-control,
|
||||
.form-select {
|
||||
border-radius: 8px;
|
||||
border: 1px solid #e2e4e9;
|
||||
padding: 10px 12px;
|
||||
}
|
||||
|
||||
.form-control:focus,
|
||||
.form-select:focus {
|
||||
border-color: #1ebf73;
|
||||
box-shadow: 0 0 0 3px rgba(30, 191, 115, 0.12);
|
||||
}
|
||||
|
||||
.form-control[readonly] {
|
||||
background: #f7f8fa;
|
||||
color: #6b7280;
|
||||
}
|
||||
|
||||
.hint {
|
||||
color: #9ca3af;
|
||||
font-size: 12px;
|
||||
margin-top: 4px;
|
||||
}
|
||||
|
||||
#editor {
|
||||
height: 240px;
|
||||
border-bottom-left-radius: 8px;
|
||||
border-bottom-right-radius: 8px;
|
||||
}
|
||||
|
||||
.ql-toolbar.ql-snow,
|
||||
.ql-container.ql-snow {
|
||||
border-color: #e2e4e9;
|
||||
}
|
||||
|
||||
.ql-toolbar.ql-snow {
|
||||
border-top-left-radius: 8px;
|
||||
border-top-right-radius: 8px;
|
||||
}
|
||||
|
||||
input[type="color"].form-control {
|
||||
padding: 4px;
|
||||
height: 44px;
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
.btn-geocode {
|
||||
border: 1px solid #e2e4e9;
|
||||
background: #fff;
|
||||
border-radius: 8px;
|
||||
padding: 10px 14px;
|
||||
font-weight: 600;
|
||||
font-size: 13px;
|
||||
color: #2f7be7;
|
||||
white-space: nowrap;
|
||||
}
|
||||
|
||||
.btn-geocode:hover {
|
||||
background: #f3f4f6;
|
||||
}
|
||||
|
||||
.btn-save {
|
||||
border-radius: 8px;
|
||||
padding: 10px 26px;
|
||||
font-weight: 600;
|
||||
}
|
||||
|
||||
.btn-back {
|
||||
border-radius: 8px;
|
||||
padding: 10px 20px;
|
||||
font-weight: 600;
|
||||
}
|
||||
|
||||
/* Dropzone copertina */
|
||||
.dropzone {
|
||||
border: 2px dashed #d5d9e0;
|
||||
border-radius: 12px;
|
||||
background: #fafbfc;
|
||||
padding: 22px;
|
||||
text-align: center;
|
||||
transition: border-color 0.15s, background 0.15s;
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
.dropzone.dragover {
|
||||
border-color: #1ebf73;
|
||||
background: #eef6f1;
|
||||
}
|
||||
|
||||
.dz-empty i {
|
||||
font-size: 34px;
|
||||
color: #b6bcc6;
|
||||
display: block;
|
||||
margin-bottom: 8px;
|
||||
}
|
||||
|
||||
.dz-empty p {
|
||||
margin: 0;
|
||||
color: #4b5563;
|
||||
font-size: 14px;
|
||||
}
|
||||
|
||||
.dz-empty small {
|
||||
color: #9ca3af;
|
||||
}
|
||||
|
||||
.dz-browse {
|
||||
color: #2f7be7;
|
||||
font-weight: 600;
|
||||
text-decoration: underline;
|
||||
}
|
||||
|
||||
.dz-preview img {
|
||||
max-height: 170px;
|
||||
border-radius: 10px;
|
||||
box-shadow: 0 2px 10px rgba(0, 0, 0, 0.12);
|
||||
}
|
||||
|
||||
.dz-remove {
|
||||
margin-top: 12px;
|
||||
border: 1px solid #f2c9c4;
|
||||
background: #fff;
|
||||
color: #c0392b;
|
||||
border-radius: 8px;
|
||||
padding: 6px 14px;
|
||||
font-weight: 600;
|
||||
font-size: 13px;
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
.dz-remove:hover {
|
||||
background: #fdecea;
|
||||
}
|
||||
|
||||
.dz-progress {
|
||||
color: #6b7280;
|
||||
font-weight: 600;
|
||||
}
|
||||
|
||||
.coord-flash {
|
||||
border-color: #1ebf73 !important;
|
||||
box-shadow: 0 0 0 3px rgba(30, 191, 115, 0.18) !important;
|
||||
transition: box-shadow .2s;
|
||||
}
|
||||
|
||||
.gallery-grid {
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
gap: 10px;
|
||||
margin-top: 12px;
|
||||
}
|
||||
|
||||
.gallery-cell {
|
||||
position: relative;
|
||||
width: 92px;
|
||||
height: 92px;
|
||||
border-radius: 10px;
|
||||
overflow: hidden;
|
||||
box-shadow: 0 2px 8px rgba(0, 0, 0, 0.10);
|
||||
}
|
||||
|
||||
.gallery-cell img {
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
object-fit: cover;
|
||||
display: block;
|
||||
}
|
||||
|
||||
.gallery-remove {
|
||||
position: absolute;
|
||||
top: 4px;
|
||||
right: 4px;
|
||||
width: 22px;
|
||||
height: 22px;
|
||||
border: none;
|
||||
border-radius: 50%;
|
||||
background: rgba(0, 0, 0, 0.55);
|
||||
color: #fff;
|
||||
font-size: 15px;
|
||||
line-height: 1;
|
||||
cursor: pointer;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
}
|
||||
|
||||
.gallery-remove:hover {
|
||||
background: #c0392b;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<div id="layout-wrapper">
|
||||
<header id="page-topbar" class="isvertical-topbar">
|
||||
<div class="navbar-header">
|
||||
<div class="d-flex">
|
||||
<?php include('include/logoarea.php'); ?>
|
||||
<button type="button" class="btn btn-sm px-3 font-size-24 header-item waves-effect vertical-menu-btn">
|
||||
<i class="bx bx-menu align-middle"></i>
|
||||
</button>
|
||||
<div class="page-title-box align-self-center d-none d-md-block">
|
||||
<h4 class="page-title mb-0"><?php echo e($pageTitle); ?></h4>
|
||||
</div>
|
||||
</div>
|
||||
<div class="d-flex">
|
||||
<?php include('include/languageselection.php'); ?>
|
||||
<?php include('include/profiletopbar.php'); ?>
|
||||
</div>
|
||||
</div>
|
||||
</header>
|
||||
<?php include('include/sidebar.php'); ?>
|
||||
<header class="ishorizontal-topbar">
|
||||
<div class="navbar-header">
|
||||
<div class="d-flex"></div>
|
||||
</div>
|
||||
<div class="topnav">
|
||||
<div class="container-fluid">
|
||||
<nav class="navbar navbar-light navbar-expand-lg topnav-menu"></nav>
|
||||
</div>
|
||||
</div>
|
||||
</header>
|
||||
|
||||
<div class="main-content">
|
||||
<div class="page-content">
|
||||
<div class="container-fluid">
|
||||
<div class="row">
|
||||
<div class="col-lg-9">
|
||||
<div class="card admin-card">
|
||||
<div class="card-body">
|
||||
<div class="section-title"><?php echo e($pageTitle); ?></div>
|
||||
<p class="section-lead">Compila i dati dell'evento. I campi con * sono obbligatori.</p>
|
||||
|
||||
<form action="event_save.php" method="POST" id="event-form">
|
||||
<input type="hidden" name="id" value="<?php echo (int) $id; ?>">
|
||||
|
||||
<div class="row">
|
||||
<div class="col-md-8 mb-3">
|
||||
<label class="form-label">Titolo *</label>
|
||||
<input type="text" class="form-control" name="title" required
|
||||
value="<?php echo e($val['title']); ?>" placeholder="Es. Yoga in Gravidanza & Amaca">
|
||||
</div>
|
||||
<div class="col-md-4 mb-3">
|
||||
<label class="form-label">Slug</label>
|
||||
<input type="text" class="form-control" name="slug"
|
||||
value="<?php echo e($val['slug']); ?>" placeholder="generato dal titolo">
|
||||
<div class="hint">URL pubblico del widget. Vuoto = generato dal titolo.</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="row">
|
||||
<div class="col-md-6 mb-3">
|
||||
<label class="form-label">Data e ora inizio *</label>
|
||||
<input type="text" class="form-control" id="starts_at" name="starts_at" required
|
||||
value="<?php echo e($val['starts_at']); ?>" placeholder="Scegli data e ora" autocomplete="off">
|
||||
</div>
|
||||
<div class="col-md-6 mb-3">
|
||||
<label class="form-label">Data e ora fine</label>
|
||||
<input type="text" class="form-control" id="ends_at" name="ends_at"
|
||||
value="<?php echo e($val['ends_at']); ?>" placeholder="Auto: inizio + 1h" autocomplete="off">
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Sede / indirizzo -->
|
||||
<div class="row">
|
||||
<?php if (!empty($locations)) : ?>
|
||||
<div class="col-md-5 mb-3">
|
||||
<label class="form-label">Sede</label>
|
||||
<select id="location-select" class="form-select">
|
||||
<?php foreach ($locations as $loc) : ?>
|
||||
<option value="<?php echo (int) $loc['id']; ?>"
|
||||
data-address="<?php echo e($loc['address']); ?>"
|
||||
data-lat="<?php echo e($loc['lat']); ?>"
|
||||
data-lng="<?php echo e($loc['lng']); ?>">
|
||||
<?php echo e($loc['name']); ?>
|
||||
</option>
|
||||
<?php endforeach; ?>
|
||||
<option value="custom">➕ Indirizzo personalizzato</option>
|
||||
</select>
|
||||
</div>
|
||||
<div class="col-md-7 mb-3">
|
||||
<label class="form-label">Indirizzo</label>
|
||||
<div class="d-flex gap-2">
|
||||
<input type="text" class="form-control" id="address-input" name="address"
|
||||
value="<?php echo e($val['address']); ?>" placeholder="Via, numero, città">
|
||||
<button type="button" class="btn-geocode" id="btn-geocode"><i class="bx bx-map-pin"></i> Calcola</button>
|
||||
</div>
|
||||
<div class="hint" id="geo-hint">Per un indirizzo personalizzato, premi "Calcola" per ottenere le coordinate mappa.</div>
|
||||
</div>
|
||||
<?php else : ?>
|
||||
<div class="col-md-12 mb-3">
|
||||
<label class="form-label">Indirizzo</label>
|
||||
<div class="d-flex gap-2">
|
||||
<input type="text" class="form-control" id="address-input" name="address"
|
||||
value="<?php echo e($val['address']); ?>" placeholder="Via, numero, città">
|
||||
<button type="button" class="btn-geocode" id="btn-geocode"><i class="bx bx-map-pin"></i> Calcola coordinate</button>
|
||||
</div>
|
||||
<div class="hint" id="geo-hint">Premi "Calcola coordinate" per ottenere lat/lng dall'indirizzo.</div>
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
</div>
|
||||
|
||||
<div class="row" id="coords-row">
|
||||
<div class="col-md-3 mb-3">
|
||||
<label class="form-label">Latitudine</label>
|
||||
<input type="text" class="form-control" id="lat-input" name="lat" value="<?php echo e($val['lat']); ?>" placeholder="45.6600">
|
||||
</div>
|
||||
<div class="col-md-3 mb-3">
|
||||
<label class="form-label">Longitudine</label>
|
||||
<input type="text" class="form-control" id="lng-input" name="lng" value="<?php echo e($val['lng']); ?>" placeholder="8.7900">
|
||||
</div>
|
||||
<div class="col-md-6 mb-3">
|
||||
<label class="form-label">Organizzatore</label>
|
||||
<input type="text" class="form-control" name="organizer_name"
|
||||
value="<?php echo e($val['organizer_name']); ?>" placeholder="Lascia vuoto = tu">
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="mb-3">
|
||||
<label class="form-label">Descrizione</label>
|
||||
<div id="editor"></div>
|
||||
<input type="hidden" name="description" id="description-input">
|
||||
<div class="hint">Testo formattato, elenchi, link e immagini.</div>
|
||||
</div>
|
||||
|
||||
<!-- Dettagli aggiuntivi (facoltativi) -->
|
||||
<div class="row">
|
||||
<div class="col-md-4 mb-3">
|
||||
<label class="form-label">Istruzioni</label>
|
||||
<textarea class="form-control" name="instructions" rows="3" placeholder="Come arrivare, orari, note pratiche…"><?php echo e($val['instructions']); ?></textarea>
|
||||
</div>
|
||||
<div class="col-md-4 mb-3">
|
||||
<label class="form-label">Cosa portare</label>
|
||||
<textarea class="form-control" name="what_to_bring" rows="3" placeholder="Tappetino, acqua, abbigliamento comodo…"><?php echo e($val['what_to_bring']); ?></textarea>
|
||||
</div>
|
||||
<div class="col-md-4 mb-3">
|
||||
<label class="form-label">Per chi è adatto</label>
|
||||
<textarea class="form-control" name="suitable_for" rows="3" placeholder="Principianti, gravidanza, tutti i livelli…"><?php echo e($val['suitable_for']); ?></textarea>
|
||||
</div>
|
||||
</div>
|
||||
<p class="hint" style="margin-top:-8px;">Questi campi sono facoltativi e verranno usati anche nella card pubblica e nelle email.</p>
|
||||
|
||||
<!-- Copertina drag&drop -->
|
||||
<div class="mb-3">
|
||||
<label class="form-label">Immagine di copertina</label>
|
||||
<div class="dropzone" id="cover-dropzone">
|
||||
<div class="dz-empty" id="dz-empty" style="<?php echo $val['cover_image'] ? 'display:none;' : ''; ?>">
|
||||
<i class="bx bx-cloud-upload"></i>
|
||||
<p>Trascina qui l'immagine oppure <span class="dz-browse">sfoglia</span></p>
|
||||
<small>JPG, PNG, WEBP o GIF · max 5 MB</small>
|
||||
</div>
|
||||
<div class="dz-preview" id="dz-preview" style="<?php echo $val['cover_image'] ? '' : 'display:none;'; ?>">
|
||||
<img id="dz-img" src="<?php echo e($val['cover_image']); ?>" alt="Copertina">
|
||||
<div><button type="button" class="dz-remove" id="dz-remove"><i class="bx bx-trash"></i> Rimuovi</button></div>
|
||||
</div>
|
||||
<div class="dz-progress" id="dz-progress" style="display:none;"><i class="bx bx-loader bx-spin"></i> Caricamento…</div>
|
||||
<input type="file" id="cover-file" accept="image/*" hidden>
|
||||
</div>
|
||||
<input type="hidden" name="cover_image" id="cover_image" value="<?php echo e($val['cover_image']); ?>">
|
||||
<div class="hint">Immagine principale mostrata nella card.</div>
|
||||
</div>
|
||||
|
||||
<!-- Galleria foto -->
|
||||
<div class="mb-3">
|
||||
<label class="form-label">Galleria foto</label>
|
||||
<div class="dropzone" id="gallery-dropzone">
|
||||
<div class="dz-empty">
|
||||
<i class="bx bx-images"></i>
|
||||
<p>Trascina qui le immagini oppure <span class="dz-browse">sfoglia</span></p>
|
||||
<small>Più immagini insieme · JPG, PNG, WEBP o GIF · max 5 MB l'una</small>
|
||||
</div>
|
||||
<input type="file" id="gallery-file" accept="image/*" multiple hidden>
|
||||
</div>
|
||||
<div class="gallery-grid" id="gallery-grid"></div>
|
||||
<input type="hidden" name="gallery" id="gallery-input" value="<?php echo e($val['gallery']); ?>">
|
||||
</div>
|
||||
|
||||
<div class="row">
|
||||
<div class="col-md-3 mb-3">
|
||||
<label class="form-label">Costo</label>
|
||||
<input type="number" step="0.01" min="0" class="form-control" name="cost" value="<?php echo e($val['cost']); ?>">
|
||||
<div class="hint">0 = gratuito.</div>
|
||||
</div>
|
||||
<div class="col-md-3 mb-3">
|
||||
<label class="form-label">Valuta</label>
|
||||
<select name="currency" class="form-select">
|
||||
<?php foreach (['EUR', 'USD', 'GBP', 'CHF'] as $cur) : ?>
|
||||
<option value="<?php echo $cur; ?>" <?php echo $val['currency'] === $cur ? 'selected' : ''; ?>><?php echo $cur; ?></option>
|
||||
<?php endforeach; ?>
|
||||
</select>
|
||||
</div>
|
||||
<div class="col-md-3 mb-3">
|
||||
<label class="form-label">Posti totali *</label>
|
||||
<input type="number" min="1" class="form-control" name="max_seats" required value="<?php echo e($val['max_seats']); ?>" placeholder="Es. 15">
|
||||
</div>
|
||||
<div class="col-md-3 mb-3">
|
||||
<label class="form-label">Max posti per persona</label>
|
||||
<input type="number" min="1" class="form-control" name="max_per_booking" value="<?php echo e($val['max_per_booking']); ?>">
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="row">
|
||||
<div class="col-md-3 mb-3">
|
||||
<label class="form-label">Colore card</label>
|
||||
<input type="color" class="form-control" name="color" value="<?php echo e($val['color']); ?>">
|
||||
</div>
|
||||
<div class="col-md-5 mb-3">
|
||||
<label class="form-label">Stato</label>
|
||||
<select name="status" class="form-select">
|
||||
<option value="draft" <?php echo $val['status'] === 'draft' ? 'selected' : ''; ?>>Bozza</option>
|
||||
<option value="published" <?php echo $val['status'] === 'published' ? 'selected' : ''; ?>>Pubblicato</option>
|
||||
<option value="cancelled" <?php echo $val['status'] === 'cancelled' ? 'selected' : ''; ?>>Annullato</option>
|
||||
</select>
|
||||
</div>
|
||||
<div class="col-md-4 mb-3">
|
||||
<label class="form-label">Lista d'attesa</label>
|
||||
<div class="form-check form-switch" style="padding-top:8px;">
|
||||
<input class="form-check-input" type="checkbox" role="switch" id="waitlist_enabled" name="waitlist_enabled" value="Y" <?php echo $val['waitlist_enabled'] ? 'checked' : ''; ?>>
|
||||
<label class="form-check-label" for="waitlist_enabled" style="font-weight:400;">Consenti iscrizione a evento pieno</label>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Apertura programmata -->
|
||||
<div class="row">
|
||||
<div class="col-md-5 mb-3">
|
||||
<label class="form-label">Apertura prenotazioni</label>
|
||||
<div class="form-check form-switch" style="padding-top:8px;">
|
||||
<input class="form-check-input" type="checkbox" role="switch" id="schedule_enabled" name="schedule_enabled" value="Y" <?php echo $val['schedule_enabled'] ? 'checked' : ''; ?>>
|
||||
<label class="form-check-label" for="schedule_enabled" style="font-weight:400;">Apri in una data futura (programmato)</label>
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-md-4 mb-3" id="publish-at-wrap" style="<?php echo $val['schedule_enabled'] ? '' : 'display:none;'; ?>">
|
||||
<label class="form-label">Data/ora apertura</label>
|
||||
<input type="text" class="form-control" id="publish_at" name="publish_at" value="<?php echo e($val['publish_at']); ?>" placeholder="Quando aprire le prenotazioni" autocomplete="off">
|
||||
</div>
|
||||
</div>
|
||||
<p class="hint" style="margin-top:-8px;">Se attivo, l'evento resta "Programmato" (visibile ma non prenotabile) finché il cron non lo apre alla data indicata.</p>
|
||||
|
||||
<!-- Promemoria e lista d'attesa (override per evento) -->
|
||||
<div class="row">
|
||||
<div class="col-md-4 mb-3">
|
||||
<label class="form-label">Promemoria automatico</label>
|
||||
<select name="reminder_enabled" class="form-select">
|
||||
<option value="">Predefinito (scuola: <?php echo $defReminderEnabled ? 'attivo' : 'disattivo'; ?>)</option>
|
||||
<option value="Y" <?php echo $val['reminder_enabled'] === 'Y' ? 'selected' : ''; ?>>Attivo</option>
|
||||
<option value="N" <?php echo $val['reminder_enabled'] === 'N' ? 'selected' : ''; ?>>Disattivo</option>
|
||||
</select>
|
||||
</div>
|
||||
<div class="col-md-4 mb-3">
|
||||
<label class="form-label">Promemoria: ore prima</label>
|
||||
<input type="number" min="1" max="168" class="form-control" name="reminder_hours" value="<?php echo e($val['reminder_hours']); ?>" placeholder="Default: <?php echo $defReminderHours; ?>">
|
||||
</div>
|
||||
<div class="col-md-4 mb-3">
|
||||
<label class="form-label">Scadenza offerta lista d'attesa (ore)</label>
|
||||
<input type="number" min="1" max="336" class="form-control" name="offer_expiry_hours" value="<?php echo e($val['offer_expiry_hours']); ?>" placeholder="Default: <?php echo $defOfferHours; ?>">
|
||||
</div>
|
||||
</div>
|
||||
<p class="hint" style="margin-top:-8px;">Lascia vuoto o "Predefinito" per usare le impostazioni generali (Opzioni Eventi).</p>
|
||||
|
||||
<div class="d-flex justify-content-between mt-2">
|
||||
<a href="events.php" class="btn btn-light btn-back"><i class="bx bx-arrow-back"></i> Indietro</a>
|
||||
<button type="submit" class="btn btn-primary btn-save">
|
||||
<i class="bx bx-save"></i> <?php echo $isEdit ? 'Salva modifiche' : 'Crea evento'; ?>
|
||||
</button>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<?php include('include/footer.php'); ?>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<script src="assets/libs/bootstrap/js/bootstrap.bundle.min.js"></script>
|
||||
<script src="assets/libs/metismenujs/metismenujs.min.js"></script>
|
||||
<script src="assets/libs/simplebar/simplebar.min.js"></script>
|
||||
<script src="assets/libs/eva-icons/eva.min.js"></script>
|
||||
<script src="assets/js/app.js"></script>
|
||||
|
||||
<script>
|
||||
/* ---------- Date/ora con flatpickr (fine = inizio + 1h) ---------- */
|
||||
var fpOpts = {
|
||||
enableTime: true,
|
||||
time_24hr: true,
|
||||
minuteIncrement: 15,
|
||||
dateFormat: "Y-m-d H:i",
|
||||
altInput: true,
|
||||
altFormat: "l j F Y, H:i",
|
||||
locale: "it"
|
||||
};
|
||||
|
||||
var endPicker = flatpickr("#ends_at", fpOpts);
|
||||
flatpickr("#publish_at", fpOpts);
|
||||
document.getElementById('schedule_enabled').addEventListener('change', function() {
|
||||
document.getElementById('publish-at-wrap').style.display = this.checked ? '' : 'none';
|
||||
});
|
||||
var startPicker = flatpickr("#starts_at", Object.assign({}, fpOpts, {
|
||||
onChange: function(dates) {
|
||||
if (!dates[0]) return;
|
||||
endPicker.set('minDate', dates[0]);
|
||||
var end = endPicker.selectedDates[0];
|
||||
if (!end || end <= dates[0]) {
|
||||
endPicker.setDate(new Date(dates[0].getTime() + 60 * 60 * 1000), false);
|
||||
}
|
||||
}
|
||||
}));
|
||||
|
||||
/* ---------- Sede / indirizzo ---------- */
|
||||
var addressInput = document.getElementById('address-input');
|
||||
var latInput = document.getElementById('lat-input');
|
||||
var lngInput = document.getElementById('lng-input');
|
||||
var geoHint = document.getElementById('geo-hint');
|
||||
var locationSelect = document.getElementById('location-select');
|
||||
var currentAddress = <?php echo json_encode($val['address'], JSON_UNESCAPED_UNICODE); ?>;
|
||||
|
||||
function clearCoords() {
|
||||
latInput.value = '';
|
||||
lngInput.value = '';
|
||||
}
|
||||
|
||||
// Dichiarazione (hoisted): usata anche in fase di preselezione qui sotto.
|
||||
function applyLocation() {
|
||||
if (!locationSelect) return;
|
||||
var opt = locationSelect.options[locationSelect.selectedIndex];
|
||||
if (locationSelect.value === 'custom') {
|
||||
// Indirizzo personalizzato: campo vuoto, nessuna coordinata finché non premi "Calcola"
|
||||
addressInput.value = '';
|
||||
clearCoords();
|
||||
geoHint.textContent = 'Scrivi l\'indirizzo e premi "Calcola" per le coordinate.';
|
||||
addressInput.focus();
|
||||
} else {
|
||||
// Sede salvata: indirizzo e coordinate REALI della sede
|
||||
addressInput.value = opt.getAttribute('data-address') || '';
|
||||
latInput.value = opt.getAttribute('data-lat') || '';
|
||||
lngInput.value = opt.getAttribute('data-lng') || '';
|
||||
geoHint.textContent = (latInput.value && lngInput.value) ?
|
||||
'Coordinate della sede caricate.' :
|
||||
'Questa sede non ha coordinate salvate: premi "Calcola".';
|
||||
}
|
||||
}
|
||||
|
||||
if (locationSelect) {
|
||||
var matched = null;
|
||||
Array.prototype.forEach.call(locationSelect.options, function(opt) {
|
||||
if (opt.value !== 'custom' && currentAddress !== '' && opt.getAttribute('data-address') === currentAddress) {
|
||||
matched = opt.value;
|
||||
}
|
||||
});
|
||||
if (currentAddress === '') {
|
||||
locationSelect.selectedIndex = 0; // nuovo evento -> sede di default (scuola)
|
||||
applyLocation();
|
||||
} else if (matched) {
|
||||
locationSelect.value = matched; // l'indirizzo salvato combacia con una sede
|
||||
applyLocation();
|
||||
} else {
|
||||
locationSelect.value = 'custom'; // indirizzo personalizzato salvato: NON toccare i valori esistenti
|
||||
}
|
||||
locationSelect.addEventListener('change', applyLocation);
|
||||
}
|
||||
|
||||
// Se modifichi l'indirizzo a mano, le vecchie coordinate non valgono più:
|
||||
// le azzero subito, così non restano valori "di default" fuorvianti.
|
||||
addressInput.addEventListener('input', function() {
|
||||
clearCoords();
|
||||
geoHint.textContent = 'Indirizzo modificato: premi "Calcola" per aggiornare le coordinate.';
|
||||
});
|
||||
|
||||
/* ---------- Geocoding indirizzo -> lat/lng ---------- */
|
||||
document.getElementById('btn-geocode').addEventListener('click', function() {
|
||||
var q = addressInput.value.trim();
|
||||
if (q === '') {
|
||||
addressInput.focus();
|
||||
return;
|
||||
}
|
||||
geoHint.textContent = 'Ricerca coordinate…';
|
||||
fetch('event_geocode.php?q=' + encodeURIComponent(q))
|
||||
.then(function(r) {
|
||||
return r.json();
|
||||
})
|
||||
.then(function(data) {
|
||||
if (data.ok) {
|
||||
latInput.value = data.lat;
|
||||
lngInput.value = data.lng;
|
||||
latInput.classList.add('coord-flash');
|
||||
lngInput.classList.add('coord-flash');
|
||||
setTimeout(function() {
|
||||
latInput.classList.remove('coord-flash');
|
||||
lngInput.classList.remove('coord-flash');
|
||||
}, 900);
|
||||
geoHint.innerHTML = '<span style="color:#1a7f52;font-weight:600;">✓ Coordinate aggiornate:</span> ' +
|
||||
data.lat + ', ' + data.lng + (data.display ? ' — ' + data.display : '');
|
||||
} else {
|
||||
geoHint.textContent = data.error || 'Indirizzo non trovato.';
|
||||
}
|
||||
})
|
||||
.catch(function() {
|
||||
geoHint.textContent = 'Errore durante il geocoding.';
|
||||
});
|
||||
});
|
||||
|
||||
/* ---------- Editor Quill ---------- */
|
||||
var quill = new Quill('#editor', {
|
||||
theme: 'snow',
|
||||
modules: {
|
||||
toolbar: [
|
||||
[{
|
||||
'header': [2, 3, false]
|
||||
}],
|
||||
['bold', 'italic', 'underline'],
|
||||
[{
|
||||
'list': 'ordered'
|
||||
}, {
|
||||
'list': 'bullet'
|
||||
}],
|
||||
['link', 'image'],
|
||||
['clean']
|
||||
]
|
||||
}
|
||||
});
|
||||
var initialHtml = <?php echo json_encode($val['description'], JSON_UNESCAPED_UNICODE | JSON_HEX_TAG | JSON_HEX_APOS | JSON_HEX_QUOT | JSON_HEX_AMP); ?>;
|
||||
if (initialHtml && initialHtml.trim() !== '') {
|
||||
quill.clipboard.dangerouslyPasteHTML(initialHtml);
|
||||
}
|
||||
|
||||
/* ---------- Copertina drag&drop ---------- */
|
||||
var dz = document.getElementById('cover-dropzone');
|
||||
var fileInput = document.getElementById('cover-file');
|
||||
var dzEmpty = document.getElementById('dz-empty');
|
||||
var dzPreview = document.getElementById('dz-preview');
|
||||
var dzProgress = document.getElementById('dz-progress');
|
||||
var dzImg = document.getElementById('dz-img');
|
||||
var coverHidden = document.getElementById('cover_image');
|
||||
|
||||
dz.addEventListener('click', function(ev) {
|
||||
if (ev.target.id === 'dz-remove' || ev.target.closest('#dz-remove')) return;
|
||||
fileInput.click();
|
||||
});
|
||||
['dragenter', 'dragover'].forEach(function(t) {
|
||||
dz.addEventListener(t, function(ev) {
|
||||
ev.preventDefault();
|
||||
dz.classList.add('dragover');
|
||||
});
|
||||
});
|
||||
['dragleave', 'drop'].forEach(function(t) {
|
||||
dz.addEventListener(t, function(ev) {
|
||||
ev.preventDefault();
|
||||
dz.classList.remove('dragover');
|
||||
});
|
||||
});
|
||||
dz.addEventListener('drop', function(ev) {
|
||||
if (ev.dataTransfer.files.length) uploadCover(ev.dataTransfer.files[0]);
|
||||
});
|
||||
fileInput.addEventListener('change', function() {
|
||||
if (fileInput.files.length) uploadCover(fileInput.files[0]);
|
||||
});
|
||||
document.getElementById('dz-remove').addEventListener('click', function() {
|
||||
coverHidden.value = '';
|
||||
dzImg.src = '';
|
||||
dzPreview.style.display = 'none';
|
||||
dzEmpty.style.display = '';
|
||||
fileInput.value = '';
|
||||
});
|
||||
|
||||
function uploadCover(file) {
|
||||
if (!file.type.startsWith('image/')) {
|
||||
Swal.fire('Formato non valido', 'Seleziona un file immagine.', 'warning');
|
||||
return;
|
||||
}
|
||||
if (file.size > 5 * 1024 * 1024) {
|
||||
Swal.fire('File troppo grande', "L'immagine supera i 5 MB.", 'warning');
|
||||
return;
|
||||
}
|
||||
dzEmpty.style.display = 'none';
|
||||
dzPreview.style.display = 'none';
|
||||
dzProgress.style.display = 'block';
|
||||
|
||||
var fd = new FormData();
|
||||
fd.append('cover', file);
|
||||
fetch('event_upload_cover.php', {
|
||||
method: 'POST',
|
||||
body: fd
|
||||
})
|
||||
.then(function(r) {
|
||||
return r.json();
|
||||
})
|
||||
.then(function(data) {
|
||||
dzProgress.style.display = 'none';
|
||||
if (data.ok) {
|
||||
coverHidden.value = data.path;
|
||||
dzImg.src = data.path + '?t=' + Date.now();
|
||||
dzPreview.style.display = 'block';
|
||||
} else {
|
||||
dzEmpty.style.display = '';
|
||||
Swal.fire('Errore', data.error || 'Caricamento non riuscito.', 'error');
|
||||
}
|
||||
})
|
||||
.catch(function() {
|
||||
dzProgress.style.display = 'none';
|
||||
dzEmpty.style.display = '';
|
||||
Swal.fire('Errore', 'Caricamento non riuscito.', 'error');
|
||||
});
|
||||
}
|
||||
|
||||
/* ---------- Galleria foto (multi-upload) ---------- */
|
||||
var galleryInput = document.getElementById('gallery-input');
|
||||
var galleryGrid = document.getElementById('gallery-grid');
|
||||
var galleryFile = document.getElementById('gallery-file');
|
||||
var galleryDz = document.getElementById('gallery-dropzone');
|
||||
var galleryItems = [];
|
||||
try {
|
||||
galleryItems = JSON.parse(galleryInput.value || '[]');
|
||||
if (!Array.isArray(galleryItems)) galleryItems = [];
|
||||
} catch (e) {
|
||||
galleryItems = [];
|
||||
}
|
||||
|
||||
function renderGallery() {
|
||||
galleryGrid.innerHTML = '';
|
||||
galleryItems.forEach(function(path, idx) {
|
||||
var cell = document.createElement('div');
|
||||
cell.className = 'gallery-cell';
|
||||
var img = document.createElement('img');
|
||||
img.src = path;
|
||||
var btn = document.createElement('button');
|
||||
btn.type = 'button';
|
||||
btn.className = 'gallery-remove';
|
||||
btn.setAttribute('data-idx', idx);
|
||||
btn.innerHTML = '×';
|
||||
cell.appendChild(img);
|
||||
cell.appendChild(btn);
|
||||
galleryGrid.appendChild(cell);
|
||||
});
|
||||
galleryInput.value = JSON.stringify(galleryItems);
|
||||
}
|
||||
renderGallery();
|
||||
|
||||
galleryGrid.addEventListener('click', function(ev) {
|
||||
var btn = ev.target.closest('.gallery-remove');
|
||||
if (!btn) return;
|
||||
galleryItems.splice(parseInt(btn.getAttribute('data-idx'), 10), 1);
|
||||
renderGallery();
|
||||
});
|
||||
galleryDz.addEventListener('click', function() {
|
||||
galleryFile.click();
|
||||
});
|
||||
['dragenter', 'dragover'].forEach(function(t) {
|
||||
galleryDz.addEventListener(t, function(ev) {
|
||||
ev.preventDefault();
|
||||
galleryDz.classList.add('dragover');
|
||||
});
|
||||
});
|
||||
['dragleave', 'drop'].forEach(function(t) {
|
||||
galleryDz.addEventListener(t, function(ev) {
|
||||
ev.preventDefault();
|
||||
galleryDz.classList.remove('dragover');
|
||||
});
|
||||
});
|
||||
galleryDz.addEventListener('drop', function(ev) {
|
||||
if (ev.dataTransfer.files.length) uploadGallery(ev.dataTransfer.files);
|
||||
});
|
||||
galleryFile.addEventListener('change', function() {
|
||||
if (galleryFile.files.length) uploadGallery(galleryFile.files);
|
||||
});
|
||||
|
||||
function uploadGallery(files) {
|
||||
Array.prototype.forEach.call(files, function(file) {
|
||||
if (!file.type.startsWith('image/')) return;
|
||||
if (file.size > 5 * 1024 * 1024) {
|
||||
Swal.fire('File troppo grande', file.name + ' supera i 5 MB.', 'warning');
|
||||
return;
|
||||
}
|
||||
var fd = new FormData();
|
||||
fd.append('cover', file); // stesso handler della copertina
|
||||
fetch('event_upload_cover.php', {
|
||||
method: 'POST',
|
||||
body: fd
|
||||
})
|
||||
.then(function(r) {
|
||||
return r.json();
|
||||
})
|
||||
.then(function(data) {
|
||||
if (data.ok) {
|
||||
galleryItems.push(data.path);
|
||||
renderGallery();
|
||||
} else {
|
||||
Swal.fire('Errore', data.error || 'Caricamento non riuscito.', 'error');
|
||||
}
|
||||
})
|
||||
.catch(function() {
|
||||
Swal.fire('Errore', 'Caricamento non riuscito.', 'error');
|
||||
});
|
||||
});
|
||||
galleryFile.value = '';
|
||||
}
|
||||
|
||||
/* ---------- Slug suggerito dal titolo ---------- */
|
||||
(function() {
|
||||
var titleInput = document.querySelector('input[name="title"]');
|
||||
var slugInput = document.querySelector('input[name="slug"]');
|
||||
if (!titleInput || !slugInput) return;
|
||||
// In modifica lo slug esiste già: lo consideriamo "toccato" e non lo sovrascriviamo.
|
||||
var slugEdited = slugInput.value.trim() !== '';
|
||||
|
||||
function slugify(s) {
|
||||
return s.toString().normalize('NFD').replace(/[\u0300-\u036f]/g, '')
|
||||
.toLowerCase().trim().replace(/[^a-z0-9]+/g, '-').replace(/^-+|-+$/g, '');
|
||||
}
|
||||
slugInput.addEventListener('input', function() {
|
||||
slugEdited = slugInput.value.trim() !== '';
|
||||
});
|
||||
titleInput.addEventListener('input', function() {
|
||||
if (!slugEdited) slugInput.value = slugify(titleInput.value);
|
||||
});
|
||||
})();
|
||||
|
||||
/* ---------- Submit ---------- */
|
||||
document.getElementById('event-form').addEventListener('submit', function() {
|
||||
var html = quill.root.innerHTML;
|
||||
document.getElementById('description-input').value = (html === '<p><br></p>') ? '' : html;
|
||||
});
|
||||
</script>
|
||||
</body>
|
||||
|
||||
</html>
|
||||
@@ -1,61 +0,0 @@
|
||||
<?php
|
||||
require_once('include/headscript.php');
|
||||
|
||||
/**
|
||||
* Geocoding indirizzo -> coordinate. Proxy server-side verso OpenStreetMap /
|
||||
* Nominatim (gratuito, senza API key). Ritorna JSON:
|
||||
* { ok:true, lat:45.66, lng:8.79, display:"..." } oppure { ok:false, error:"..." }
|
||||
*
|
||||
* Nota: Nominatim chiede max 1 richiesta/secondo e uno User-Agent identificativo
|
||||
* (impostato sotto). Quando avrai la chiave Google Maps si può passare alla
|
||||
* Geocoding API di Google per maggiore precisione, cambiando solo questo file.
|
||||
*/
|
||||
if (function_exists('ob_get_level') && ob_get_level()) {
|
||||
ob_clean();
|
||||
}
|
||||
header('Content-Type: application/json; charset=utf-8');
|
||||
|
||||
$q = trim($_GET['q'] ?? '');
|
||||
if ($q === '') {
|
||||
echo json_encode(['ok' => false, 'error' => 'Indirizzo mancante.']);
|
||||
exit();
|
||||
}
|
||||
|
||||
$url = 'https://nominatim.openstreetmap.org/search?format=json&limit=1&addressdetails=0&q=' . rawurlencode($q);
|
||||
$ua = 'YogiBook/1.0 (info@yogasoul.it)';
|
||||
$json = false;
|
||||
|
||||
if (function_exists('curl_init')) {
|
||||
$ch = curl_init($url);
|
||||
curl_setopt_array($ch, [
|
||||
CURLOPT_RETURNTRANSFER => true,
|
||||
CURLOPT_USERAGENT => $ua,
|
||||
CURLOPT_TIMEOUT => 8,
|
||||
CURLOPT_FOLLOWLOCATION => true,
|
||||
]);
|
||||
$json = curl_exec($ch);
|
||||
curl_close($ch);
|
||||
}
|
||||
|
||||
if ($json === false) {
|
||||
$ctx = stream_context_create(['http' => [
|
||||
'method' => 'GET',
|
||||
'header' => "User-Agent: {$ua}\r\n",
|
||||
'timeout' => 8,
|
||||
]]);
|
||||
$json = @file_get_contents($url, false, $ctx);
|
||||
}
|
||||
|
||||
$data = $json ? json_decode($json, true) : null;
|
||||
|
||||
if (!empty($data[0]['lat']) && !empty($data[0]['lon'])) {
|
||||
echo json_encode([
|
||||
'ok' => true,
|
||||
'lat' => round((float) $data[0]['lat'], 7),
|
||||
'lng' => round((float) $data[0]['lon'], 7),
|
||||
'display' => $data[0]['display_name'] ?? '',
|
||||
]);
|
||||
} else {
|
||||
echo json_encode(['ok' => false, 'error' => 'Indirizzo non trovato. Prova a essere più specifico.']);
|
||||
}
|
||||
exit();
|
||||
@@ -1,471 +0,0 @@
|
||||
<?php
|
||||
require_once('include/headscript.php');
|
||||
|
||||
/**
|
||||
* Modulo Eventi - gestione Sedi (event_locations): elenco, aggiungi, modifica,
|
||||
* elimina e "imposta come predefinita".
|
||||
* - event_locations.php -> elenco + form nuovo
|
||||
* - event_locations.php?edit=ID -> form in modifica
|
||||
* - event_locations.php?delete=ID -> elimina (con conferma via modale)
|
||||
* - event_locations.php?makedefault=ID -> imposta predefinita
|
||||
* Il salvataggio (insert/update) passa da event_locations_save.php.
|
||||
*/
|
||||
$pdo = DBHandlerSelect::getInstance()->getConnection();
|
||||
|
||||
function e($value): string
|
||||
{
|
||||
return htmlspecialchars((string) $value, ENT_QUOTES, 'UTF-8');
|
||||
}
|
||||
|
||||
// Azioni inline (prima di ogni output)
|
||||
if (isset($_GET['delete'])) {
|
||||
$delId = (int) $_GET['delete'];
|
||||
$pdo->prepare("DELETE FROM event_locations WHERE id = ?")->execute([$delId]);
|
||||
header('Location: event_locations.php?message=deleted');
|
||||
exit();
|
||||
}
|
||||
if (isset($_GET['makedefault'])) {
|
||||
$defId = (int) $_GET['makedefault'];
|
||||
// Una sola predefinita: Y su questa, N su tutte le altre
|
||||
$pdo->prepare("UPDATE event_locations SET is_default = IF(id = ?, 'Y', 'N'), updated_at = NOW()")->execute([$defId]);
|
||||
header('Location: event_locations.php?message=default');
|
||||
exit();
|
||||
}
|
||||
|
||||
$editId = isset($_GET['edit']) ? (int) $_GET['edit'] : 0;
|
||||
$edit = null;
|
||||
if ($editId > 0) {
|
||||
$st = $pdo->prepare("SELECT * FROM event_locations WHERE id = ?");
|
||||
$st->execute([$editId]);
|
||||
$edit = $st->fetch(PDO::FETCH_ASSOC);
|
||||
}
|
||||
|
||||
$tableMissing = false;
|
||||
$locations = [];
|
||||
try {
|
||||
$locations = $pdo->query("SELECT * FROM event_locations ORDER BY is_default DESC, name ASC")->fetchAll(PDO::FETCH_ASSOC);
|
||||
} catch (Throwable $ex) {
|
||||
$tableMissing = true;
|
||||
}
|
||||
|
||||
$message = $_GET['message'] ?? '';
|
||||
|
||||
$val = [
|
||||
'id' => $edit['id'] ?? 0,
|
||||
'name' => $edit['name'] ?? '',
|
||||
'address' => $edit['address'] ?? '',
|
||||
'lat' => $edit['lat'] ?? '',
|
||||
'lng' => $edit['lng'] ?? '',
|
||||
'is_default' => ($edit['is_default'] ?? 'N') === 'Y',
|
||||
];
|
||||
$isEdit = $editId > 0 && $edit;
|
||||
?>
|
||||
<!doctype html>
|
||||
<html lang="it">
|
||||
|
||||
<head>
|
||||
<meta charset="utf-8" />
|
||||
<title>YogiBook - Sedi</title>
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<link rel="shortcut icon" href="assets/images/favicon.ico">
|
||||
<link href="assets/css/bootstrap.min.css" id="bootstrap-style" rel="stylesheet" type="text/css" />
|
||||
<link href="assets/css/icons.min.css" rel="stylesheet" type="text/css" />
|
||||
<link href="assets/css/app.min.css" id="app-style" rel="stylesheet" type="text/css" />
|
||||
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.0.0-beta3/css/all.min.css">
|
||||
<script src="https://cdn.jsdelivr.net/npm/sweetalert2@11"></script>
|
||||
<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
|
||||
|
||||
<style>
|
||||
.admin-card {
|
||||
border: none;
|
||||
border-radius: 14px;
|
||||
box-shadow: 0 4px 20px rgba(0, 0, 0, 0.06);
|
||||
}
|
||||
|
||||
.admin-card .card-body {
|
||||
padding: 26px 30px;
|
||||
}
|
||||
|
||||
.section-title {
|
||||
font-size: 15px;
|
||||
font-weight: 700;
|
||||
letter-spacing: 0.04em;
|
||||
text-transform: uppercase;
|
||||
color: #6b7280;
|
||||
margin-bottom: 4px;
|
||||
}
|
||||
|
||||
.section-lead {
|
||||
color: #9ca3af;
|
||||
font-size: 14px;
|
||||
margin-bottom: 22px;
|
||||
}
|
||||
|
||||
.form-label {
|
||||
font-weight: 600;
|
||||
font-size: 14px;
|
||||
color: #374151;
|
||||
}
|
||||
|
||||
.form-control {
|
||||
border-radius: 8px;
|
||||
border: 1px solid #e2e4e9;
|
||||
padding: 10px 12px;
|
||||
}
|
||||
|
||||
.form-control:focus {
|
||||
border-color: #1ebf73;
|
||||
box-shadow: 0 0 0 3px rgba(30, 191, 115, 0.12);
|
||||
}
|
||||
|
||||
.hint {
|
||||
color: #9ca3af;
|
||||
font-size: 12px;
|
||||
margin-top: 4px;
|
||||
}
|
||||
|
||||
.btn-geocode {
|
||||
border: 1px solid #e2e4e9;
|
||||
background: #fff;
|
||||
border-radius: 8px;
|
||||
padding: 10px 14px;
|
||||
font-weight: 600;
|
||||
font-size: 13px;
|
||||
color: #2f7be7;
|
||||
white-space: nowrap;
|
||||
}
|
||||
|
||||
.btn-geocode:hover {
|
||||
background: #f3f4f6;
|
||||
}
|
||||
|
||||
.coord-flash {
|
||||
border-color: #1ebf73 !important;
|
||||
box-shadow: 0 0 0 3px rgba(30, 191, 115, 0.18) !important;
|
||||
transition: box-shadow .2s;
|
||||
}
|
||||
|
||||
.loc-table thead th {
|
||||
font-size: 12px;
|
||||
text-transform: uppercase;
|
||||
letter-spacing: 0.03em;
|
||||
color: #6b7280;
|
||||
border-bottom: 2px solid #eef0f3;
|
||||
white-space: nowrap;
|
||||
}
|
||||
|
||||
.loc-table td {
|
||||
vertical-align: middle;
|
||||
}
|
||||
|
||||
.loc-name {
|
||||
font-weight: 600;
|
||||
color: #1f2937;
|
||||
}
|
||||
|
||||
.default-badge {
|
||||
display: inline-block;
|
||||
font-size: 12px;
|
||||
font-weight: 700;
|
||||
padding: 3px 10px;
|
||||
border-radius: 20px;
|
||||
background: #e7f7ee;
|
||||
color: #1a7f52;
|
||||
}
|
||||
|
||||
.btn-act {
|
||||
border: 1px solid #e2e4e9;
|
||||
background: #fff;
|
||||
border-radius: 8px;
|
||||
padding: 6px 12px;
|
||||
font-size: 13px;
|
||||
font-weight: 600;
|
||||
color: #374151;
|
||||
cursor: pointer;
|
||||
text-decoration: none;
|
||||
white-space: nowrap;
|
||||
}
|
||||
|
||||
.btn-act:hover {
|
||||
background: #f3f4f6;
|
||||
color: #111827;
|
||||
}
|
||||
|
||||
.btn-act.danger {
|
||||
color: #c0392b;
|
||||
border-color: #f2c9c4;
|
||||
}
|
||||
|
||||
.btn-act.danger:hover {
|
||||
background: #fdecea;
|
||||
}
|
||||
|
||||
.empty-state {
|
||||
text-align: center;
|
||||
padding: 40px 10px;
|
||||
color: #9ca3af;
|
||||
}
|
||||
|
||||
.empty-state i {
|
||||
font-size: 34px;
|
||||
margin-bottom: 10px;
|
||||
display: block;
|
||||
color: #d5d9e0;
|
||||
}
|
||||
|
||||
.btn-save {
|
||||
border-radius: 8px;
|
||||
padding: 10px 26px;
|
||||
font-weight: 600;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<div id="layout-wrapper">
|
||||
<header id="page-topbar" class="isvertical-topbar">
|
||||
<div class="navbar-header">
|
||||
<div class="d-flex">
|
||||
<?php include('include/logoarea.php'); ?>
|
||||
<button type="button" class="btn btn-sm px-3 font-size-24 header-item waves-effect vertical-menu-btn">
|
||||
<i class="bx bx-menu align-middle"></i>
|
||||
</button>
|
||||
<div class="page-title-box align-self-center d-none d-md-block">
|
||||
<h4 class="page-title mb-0">Sedi</h4>
|
||||
</div>
|
||||
</div>
|
||||
<div class="d-flex">
|
||||
<?php include('include/languageselection.php'); ?>
|
||||
<?php include('include/profiletopbar.php'); ?>
|
||||
</div>
|
||||
</div>
|
||||
</header>
|
||||
<?php include('include/sidebar.php'); ?>
|
||||
<header class="ishorizontal-topbar">
|
||||
<div class="navbar-header">
|
||||
<div class="d-flex"></div>
|
||||
</div>
|
||||
<div class="topnav">
|
||||
<div class="container-fluid">
|
||||
<nav class="navbar navbar-light navbar-expand-lg topnav-menu"></nav>
|
||||
</div>
|
||||
</div>
|
||||
</header>
|
||||
|
||||
<div class="main-content">
|
||||
<div class="page-content">
|
||||
<div class="container-fluid">
|
||||
|
||||
<?php if ($message === 'success') : ?>
|
||||
<div class="alert alert-success" role="alert">Sede salvata.</div>
|
||||
<?php elseif ($message === 'deleted') : ?>
|
||||
<div class="alert alert-warning" role="alert">Sede eliminata.</div>
|
||||
<?php elseif ($message === 'default') : ?>
|
||||
<div class="alert alert-success" role="alert">Sede predefinita aggiornata.</div>
|
||||
<?php elseif ($message === 'error') : ?>
|
||||
<div class="alert alert-danger" role="alert">Errore: nome e indirizzo sono obbligatori.</div>
|
||||
<?php endif; ?>
|
||||
|
||||
<?php if ($tableMissing) : ?>
|
||||
<div class="alert alert-danger" role="alert">
|
||||
La tabella <code>event_locations</code> non esiste ancora. Esegui la migration Phinx <code>CreateEventLocationsTable</code> e ricarica.
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
|
||||
<div class="row">
|
||||
<!-- Form -->
|
||||
<div class="col-12">
|
||||
<div class="card admin-card mb-4">
|
||||
<div class="card-body">
|
||||
<div class="section-title"><?php echo $isEdit ? 'Modifica sede' : 'Nuova sede'; ?></div>
|
||||
<p class="section-lead">Le sedi salvate compaiono nella tendina "Sede" del form evento.</p>
|
||||
|
||||
<form action="event_locations_save.php" method="POST" id="loc-form">
|
||||
<input type="hidden" name="id" value="<?php echo (int) $val['id']; ?>">
|
||||
|
||||
<div class="mb-3">
|
||||
<label class="form-label">Nome sede *</label>
|
||||
<input type="text" class="form-control" name="name" required
|
||||
value="<?php echo e($val['name']); ?>" placeholder="Es. Studio YogaSoul">
|
||||
</div>
|
||||
|
||||
<div class="mb-3">
|
||||
<label class="form-label">Indirizzo *</label>
|
||||
<div class="d-flex gap-2">
|
||||
<input type="text" class="form-control" id="address-input" name="address" required
|
||||
value="<?php echo e($val['address']); ?>" placeholder="Via, numero, città">
|
||||
<button type="button" class="btn-geocode" id="btn-geocode"><i class="bx bx-map-pin"></i> Calcola</button>
|
||||
</div>
|
||||
<div class="hint" id="geo-hint">Premi "Calcola" per ottenere le coordinate dall'indirizzo.</div>
|
||||
</div>
|
||||
|
||||
<div class="row">
|
||||
<div class="col-6 mb-3">
|
||||
<label class="form-label">Latitudine</label>
|
||||
<input type="text" class="form-control" id="lat-input" name="lat" value="<?php echo e($val['lat']); ?>" placeholder="45.6600">
|
||||
</div>
|
||||
<div class="col-6 mb-3">
|
||||
<label class="form-label">Longitudine</label>
|
||||
<input type="text" class="form-control" id="lng-input" name="lng" value="<?php echo e($val['lng']); ?>" placeholder="8.7900">
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="form-check mb-3">
|
||||
<input class="form-check-input" type="checkbox" id="is_default" name="is_default" value="Y" <?php echo $val['is_default'] ? 'checked' : ''; ?>>
|
||||
<label class="form-check-label" for="is_default">Imposta come sede predefinita</label>
|
||||
</div>
|
||||
|
||||
<div class="d-flex gap-2">
|
||||
<button type="submit" class="btn btn-primary btn-save"><i class="bx bx-save"></i> <?php echo $isEdit ? 'Salva' : 'Aggiungi'; ?></button>
|
||||
<?php if ($isEdit) : ?>
|
||||
<a href="event_locations.php" class="btn btn-light btn-save">Annulla</a>
|
||||
<?php endif; ?>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Elenco -->
|
||||
<div class="col-12">
|
||||
<div class="card admin-card">
|
||||
<div class="card-body">
|
||||
<div class="section-title">Sedi salvate</div>
|
||||
<p class="section-lead">Rubrica delle sedi riutilizzabili.</p>
|
||||
|
||||
<div class="table-responsive">
|
||||
<table class="table loc-table align-middle">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Sede</th>
|
||||
<th>Indirizzo</th>
|
||||
<th>Coordinate</th>
|
||||
<th class="text-end">Azioni</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<?php if (empty($locations)) : ?>
|
||||
<tr>
|
||||
<td colspan="4">
|
||||
<div class="empty-state">
|
||||
<i class="fas fa-map-marker-alt"></i>
|
||||
Nessuna sede salvata. Aggiungine una dal form a sinistra.
|
||||
</div>
|
||||
</td>
|
||||
</tr>
|
||||
<?php else :
|
||||
foreach ($locations as $loc) :
|
||||
$hasCoords = $loc['lat'] !== null && $loc['lng'] !== null && $loc['lat'] !== '' && $loc['lng'] !== '';
|
||||
?>
|
||||
<tr>
|
||||
<td>
|
||||
<span class="loc-name"><?php echo e($loc['name']); ?></span>
|
||||
<?php if ($loc['is_default'] === 'Y') : ?>
|
||||
<span class="default-badge"><i class="bx bxs-star"></i> Predefinita</span>
|
||||
<?php endif; ?>
|
||||
</td>
|
||||
<td><?php echo e($loc['address']); ?></td>
|
||||
<td><?php echo $hasCoords ? e($loc['lat']) . ', ' . e($loc['lng']) : '<span style="color:#9ca3af;">—</span>'; ?></td>
|
||||
<td class="text-end">
|
||||
<a href="event_locations.php?edit=<?php echo (int) $loc['id']; ?>" class="btn-act"><i class="bx bx-edit"></i> Modifica</a>
|
||||
<?php if ($loc['is_default'] !== 'Y') : ?>
|
||||
<a href="event_locations.php?makedefault=<?php echo (int) $loc['id']; ?>" class="btn-act"><i class="bx bx-star"></i> Predefinita</a>
|
||||
<?php endif; ?>
|
||||
<button type="button" class="btn-act danger btn-del"
|
||||
data-id="<?php echo (int) $loc['id']; ?>"
|
||||
data-name="<?php echo e($loc['name']); ?>">
|
||||
<i class="bx bx-trash"></i> Elimina
|
||||
</button>
|
||||
</td>
|
||||
</tr>
|
||||
<?php endforeach; ?>
|
||||
<?php endif; ?>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
<?php include('include/footer.php'); ?>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<script src="assets/libs/bootstrap/js/bootstrap.bundle.min.js"></script>
|
||||
<script src="assets/libs/metismenujs/metismenujs.min.js"></script>
|
||||
<script src="assets/libs/simplebar/simplebar.min.js"></script>
|
||||
<script src="assets/libs/eva-icons/eva.min.js"></script>
|
||||
<script src="assets/js/app.js"></script>
|
||||
|
||||
<script>
|
||||
var addressInput = document.getElementById('address-input');
|
||||
var latInput = document.getElementById('lat-input');
|
||||
var lngInput = document.getElementById('lng-input');
|
||||
var geoHint = document.getElementById('geo-hint');
|
||||
|
||||
// Modifica indirizzo -> le vecchie coordinate non valgono più
|
||||
addressInput.addEventListener('input', function() {
|
||||
latInput.value = '';
|
||||
lngInput.value = '';
|
||||
geoHint.textContent = 'Indirizzo modificato: premi "Calcola" per aggiornare le coordinate.';
|
||||
});
|
||||
|
||||
document.getElementById('btn-geocode').addEventListener('click', function() {
|
||||
var q = addressInput.value.trim();
|
||||
if (q === '') {
|
||||
addressInput.focus();
|
||||
return;
|
||||
}
|
||||
geoHint.textContent = 'Ricerca coordinate…';
|
||||
fetch('event_geocode.php?q=' + encodeURIComponent(q))
|
||||
.then(function(r) {
|
||||
return r.json();
|
||||
})
|
||||
.then(function(data) {
|
||||
if (data.ok) {
|
||||
latInput.value = data.lat;
|
||||
lngInput.value = data.lng;
|
||||
latInput.classList.add('coord-flash');
|
||||
lngInput.classList.add('coord-flash');
|
||||
setTimeout(function() {
|
||||
latInput.classList.remove('coord-flash');
|
||||
lngInput.classList.remove('coord-flash');
|
||||
}, 900);
|
||||
geoHint.innerHTML = '<span style="color:#1a7f52;font-weight:600;">✓ Coordinate aggiornate:</span> ' +
|
||||
data.lat + ', ' + data.lng + (data.display ? ' — ' + data.display : '');
|
||||
} else {
|
||||
geoHint.textContent = data.error || 'Indirizzo non trovato.';
|
||||
}
|
||||
})
|
||||
.catch(function() {
|
||||
geoHint.textContent = 'Errore durante il geocoding.';
|
||||
});
|
||||
});
|
||||
|
||||
$(document).ready(function() {
|
||||
$('.btn-del').on('click', function() {
|
||||
var id = $(this).data('id');
|
||||
var name = $(this).data('name');
|
||||
Swal.fire({
|
||||
title: 'Eliminare la sede?',
|
||||
html: 'Stai per eliminare <strong>' + $('<div>').text(name).html() + '</strong>.<br><small>Gli eventi che la usavano mantengono il loro indirizzo.</small>',
|
||||
icon: 'warning',
|
||||
showCancelButton: true,
|
||||
confirmButtonText: 'Elimina',
|
||||
cancelButtonText: 'Chiudi',
|
||||
confirmButtonColor: '#e74c3c',
|
||||
reverseButtons: true
|
||||
}).then(function(result) {
|
||||
if (result.isConfirmed) {
|
||||
window.location.href = 'event_locations.php?delete=' + id;
|
||||
}
|
||||
});
|
||||
});
|
||||
});
|
||||
</script>
|
||||
</body>
|
||||
|
||||
</html>
|
||||
@@ -1,67 +0,0 @@
|
||||
<?php
|
||||
require_once('include/headscript.php');
|
||||
|
||||
/**
|
||||
* Salvataggio sede (insert/update) da event_locations.php.
|
||||
* Se "predefinita" è spuntata, la imposta come unica default.
|
||||
*/
|
||||
if ($_SERVER['REQUEST_METHOD'] !== 'POST') {
|
||||
header('Location: event_locations.php');
|
||||
exit();
|
||||
}
|
||||
|
||||
$pdo = DBHandlerSelect::getInstance()->getConnection();
|
||||
|
||||
$id = isset($_POST['id']) ? (int) $_POST['id'] : 0;
|
||||
$name = trim($_POST['name'] ?? '');
|
||||
$address = trim($_POST['address'] ?? '');
|
||||
$isDefault = (isset($_POST['is_default']) && $_POST['is_default'] === 'Y') ? 'Y' : 'N';
|
||||
|
||||
$lat = ($_POST['lat'] ?? '') !== '' ? (float) $_POST['lat'] : null;
|
||||
$lng = ($_POST['lng'] ?? '') !== '' ? (float) $_POST['lng'] : null;
|
||||
|
||||
if ($name === '' || $address === '') {
|
||||
header('Location: event_locations.php?message=error');
|
||||
exit();
|
||||
}
|
||||
|
||||
try {
|
||||
if ($id > 0) {
|
||||
$stmt = $pdo->prepare("UPDATE event_locations
|
||||
SET name = :name, address = :address, lat = :lat, lng = :lng,
|
||||
is_default = :is_default, updated_at = NOW()
|
||||
WHERE id = :id");
|
||||
$stmt->execute([
|
||||
':name' => $name,
|
||||
':address' => $address,
|
||||
':lat' => $lat,
|
||||
':lng' => $lng,
|
||||
':is_default' => $isDefault,
|
||||
':id' => $id,
|
||||
]);
|
||||
$savedId = $id;
|
||||
} else {
|
||||
$stmt = $pdo->prepare("INSERT INTO event_locations (name, address, lat, lng, is_default, created_at, updated_at)
|
||||
VALUES (:name, :address, :lat, :lng, :is_default, NOW(), NOW())");
|
||||
$stmt->execute([
|
||||
':name' => $name,
|
||||
':address' => $address,
|
||||
':lat' => $lat,
|
||||
':lng' => $lng,
|
||||
':is_default' => $isDefault,
|
||||
]);
|
||||
$savedId = (int) $pdo->lastInsertId();
|
||||
}
|
||||
|
||||
// Una sola predefinita
|
||||
if ($isDefault === 'Y') {
|
||||
$pdo->prepare("UPDATE event_locations SET is_default = IF(id = ?, 'Y', 'N'), updated_at = NOW()")->execute([$savedId]);
|
||||
}
|
||||
|
||||
header('Location: event_locations.php?message=success');
|
||||
exit();
|
||||
} catch (Throwable $ex) {
|
||||
error_log('[event_locations_save] ' . $ex->getMessage());
|
||||
header('Location: event_locations.php?message=error');
|
||||
exit();
|
||||
}
|
||||
@@ -1,249 +0,0 @@
|
||||
<?php
|
||||
require_once('include/headscript.php');
|
||||
|
||||
/**
|
||||
* Opzioni Eventi (lato scuola): indirizzo per le copie, quali email mettere in
|
||||
* copia (per tipo), e impostazioni promemoria. Salva in event_options_save.php.
|
||||
*/
|
||||
$pdo = DBHandlerSelect::getInstance()->getConnection();
|
||||
|
||||
function e($value): string
|
||||
{
|
||||
return htmlspecialchars((string) $value, ENT_QUOTES, 'UTF-8');
|
||||
}
|
||||
|
||||
$opt = $pdo->query("SELECT * FROM `option` LIMIT 1")->fetch(PDO::FETCH_ASSOC) ?: [];
|
||||
$message = $_GET['message'] ?? '';
|
||||
|
||||
$ccEmail = $opt['event_notify_email'] ?? '';
|
||||
$reminderH = (int) ($opt['event_reminder_hours'] ?? 24);
|
||||
$offerH = (int) ($opt['event_offer_expiry_hours'] ?? 24);
|
||||
function isY($opt, $k)
|
||||
{
|
||||
return ($opt[$k] ?? 'N') === 'Y';
|
||||
}
|
||||
|
||||
$types = [
|
||||
['event_cc_booking', 'Prenotazione', 'Quando qualcuno prenota (o entra in lista d\'attesa).'],
|
||||
['event_cc_promotion', 'Promozione lista d\'attesa', 'Quando una persona in attesa viene promossa.'],
|
||||
['event_cc_user_cancel', 'Disdetta utente', 'Quando un iscritto annulla la sua prenotazione.'],
|
||||
['event_cc_event_cancel', 'Annullo evento', 'Quando annulli un intero evento (a tutti gli iscritti).'],
|
||||
['event_cc_reminder', 'Promemoria', 'Il promemoria inviato prima dell\'evento.'],
|
||||
];
|
||||
?>
|
||||
<!doctype html>
|
||||
<html lang="it">
|
||||
|
||||
<head>
|
||||
<meta charset="utf-8" />
|
||||
<title>YogiBook - Opzioni Eventi</title>
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<link rel="shortcut icon" href="assets/images/favicon.ico">
|
||||
<link href="assets/css/bootstrap.min.css" id="bootstrap-style" rel="stylesheet" type="text/css" />
|
||||
<link href="assets/css/icons.min.css" rel="stylesheet" type="text/css" />
|
||||
<link href="assets/css/app.min.css" id="app-style" rel="stylesheet" type="text/css" />
|
||||
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.0.0-beta3/css/all.min.css">
|
||||
|
||||
<style>
|
||||
.admin-card {
|
||||
border: none;
|
||||
border-radius: 14px;
|
||||
box-shadow: 0 4px 20px rgba(0, 0, 0, 0.06);
|
||||
}
|
||||
|
||||
.admin-card .card-body {
|
||||
padding: 26px 30px;
|
||||
}
|
||||
|
||||
.section-title {
|
||||
font-size: 15px;
|
||||
font-weight: 700;
|
||||
letter-spacing: 0.04em;
|
||||
text-transform: uppercase;
|
||||
color: #6b7280;
|
||||
margin-bottom: 4px;
|
||||
}
|
||||
|
||||
.section-lead {
|
||||
color: #9ca3af;
|
||||
font-size: 14px;
|
||||
margin-bottom: 22px;
|
||||
}
|
||||
|
||||
.form-label {
|
||||
font-weight: 600;
|
||||
font-size: 14px;
|
||||
color: #374151;
|
||||
}
|
||||
|
||||
.form-control {
|
||||
border-radius: 8px;
|
||||
border: 1px solid #e2e4e9;
|
||||
padding: 10px 12px;
|
||||
}
|
||||
|
||||
.form-control:focus {
|
||||
border-color: #1ebf73;
|
||||
box-shadow: 0 0 0 3px rgba(30, 191, 115, 0.12);
|
||||
}
|
||||
|
||||
.opt-row {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
padding: 16px 0;
|
||||
border-bottom: 1px solid #f0f0f0;
|
||||
}
|
||||
|
||||
.opt-row:last-child {
|
||||
border-bottom: none;
|
||||
}
|
||||
|
||||
.opt-label {
|
||||
font-weight: 600;
|
||||
color: #1f2937;
|
||||
font-size: 15px;
|
||||
}
|
||||
|
||||
.opt-help {
|
||||
color: #9ca3af;
|
||||
font-size: 13px;
|
||||
margin-top: 3px;
|
||||
}
|
||||
|
||||
.form-switch .form-check-input {
|
||||
width: 3em;
|
||||
height: 1.5em;
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
.save-bar {
|
||||
margin-top: 24px;
|
||||
text-align: right;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<div id="layout-wrapper">
|
||||
<header id="page-topbar" class="isvertical-topbar">
|
||||
<div class="navbar-header">
|
||||
<div class="d-flex">
|
||||
<?php include('include/logoarea.php'); ?>
|
||||
<button type="button" class="btn btn-sm px-3 font-size-24 header-item waves-effect vertical-menu-btn">
|
||||
<i class="bx bx-menu align-middle"></i>
|
||||
</button>
|
||||
<div class="page-title-box align-self-center d-none d-md-block">
|
||||
<h4 class="page-title mb-0">Opzioni Eventi</h4>
|
||||
</div>
|
||||
</div>
|
||||
<div class="d-flex">
|
||||
<?php include('include/languageselection.php'); ?>
|
||||
<?php include('include/profiletopbar.php'); ?>
|
||||
</div>
|
||||
</div>
|
||||
</header>
|
||||
<?php include('include/sidebar.php'); ?>
|
||||
<header class="ishorizontal-topbar">
|
||||
<div class="navbar-header">
|
||||
<div class="d-flex"></div>
|
||||
</div>
|
||||
<div class="topnav">
|
||||
<div class="container-fluid">
|
||||
<nav class="navbar navbar-light navbar-expand-lg topnav-menu"></nav>
|
||||
</div>
|
||||
</div>
|
||||
</header>
|
||||
|
||||
<div class="main-content">
|
||||
<div class="page-content">
|
||||
<div class="container-fluid">
|
||||
<?php if ($message === 'success') : ?>
|
||||
<div class="alert alert-success" role="alert">Opzioni salvate.</div>
|
||||
<?php elseif ($message === 'error') : ?>
|
||||
<div class="alert alert-danger" role="alert">Errore durante il salvataggio.</div>
|
||||
<?php endif; ?>
|
||||
|
||||
<form action="event_options_save.php" method="POST">
|
||||
<div class="row">
|
||||
<div class="col-lg-8">
|
||||
<div class="card admin-card mb-4">
|
||||
<div class="card-body">
|
||||
<div class="section-title">Copie alla scuola</div>
|
||||
<p class="section-lead">Scegli su quali email l'insegnante/scuola riceve una copia (CC).</p>
|
||||
|
||||
<div class="mb-3">
|
||||
<label class="form-label">Email della scuola per le copie</label>
|
||||
<input type="email" class="form-control" name="event_notify_email" value="<?php echo e($ccEmail); ?>" placeholder="info@yogasoul.it">
|
||||
<div class="opt-help">Se vuota, non viene inviata nessuna copia anche se le voci sotto sono attive.</div>
|
||||
</div>
|
||||
|
||||
<?php foreach ($types as $t) : ?>
|
||||
<div class="opt-row">
|
||||
<div>
|
||||
<div class="opt-label"><?php echo e($t[1]); ?></div>
|
||||
<div class="opt-help"><?php echo e($t[2]); ?></div>
|
||||
</div>
|
||||
<div class="form-check form-switch">
|
||||
<input class="form-check-input" type="checkbox" role="switch" name="<?php echo e($t[0]); ?>" value="Y" <?php echo isY($opt, $t[0]) ? 'checked' : ''; ?>>
|
||||
</div>
|
||||
</div>
|
||||
<?php endforeach; ?>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="card admin-card">
|
||||
<div class="card-body">
|
||||
<div class="section-title">Promemoria</div>
|
||||
<p class="section-lead">Invio automatico del promemoria agli iscritti prima dell'evento (richiede il cron, vedi setup).</p>
|
||||
|
||||
<div class="opt-row">
|
||||
<div>
|
||||
<div class="opt-label">Attiva promemoria</div>
|
||||
<div class="opt-help">Invia un'email di promemoria agli iscritti confermati.</div>
|
||||
</div>
|
||||
<div class="form-check form-switch">
|
||||
<input class="form-check-input" type="checkbox" role="switch" name="event_reminder_enabled" value="Y" <?php echo isY($opt, 'event_reminder_enabled') ? 'checked' : ''; ?>>
|
||||
</div>
|
||||
</div>
|
||||
<div class="opt-row">
|
||||
<div>
|
||||
<div class="opt-label">Ore prima dell'evento</div>
|
||||
<div class="opt-help">Quante ore prima dell'inizio inviare il promemoria.</div>
|
||||
</div>
|
||||
<div style="width:120px;">
|
||||
<input type="number" min="1" max="168" class="form-control" name="event_reminder_hours" value="<?php echo e($reminderH); ?>">
|
||||
</div>
|
||||
</div>
|
||||
<div class="opt-row">
|
||||
<div>
|
||||
<div class="opt-label">Scadenza offerta lista d'attesa (ore)</div>
|
||||
<div class="opt-help">Default: quanto tempo una persona promossa ha per riconfermare prima che il posto passi al prossimo. Modificabile per singolo evento.</div>
|
||||
</div>
|
||||
<div style="width:120px;">
|
||||
<input type="number" min="1" max="336" class="form-control" name="event_offer_expiry_hours" value="<?php echo e($offerH); ?>">
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="save-bar">
|
||||
<button type="submit" class="btn btn-success"><i class="fas fa-save me-1"></i> Salva opzioni</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
<?php include('include/footer.php'); ?>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<script src="assets/libs/bootstrap/js/bootstrap.bundle.min.js"></script>
|
||||
<script src="assets/libs/metismenujs/metismenujs.min.js"></script>
|
||||
<script src="assets/libs/simplebar/simplebar.min.js"></script>
|
||||
<script src="assets/libs/eva-icons/eva.min.js"></script>
|
||||
<script src="assets/js/app.js"></script>
|
||||
</body>
|
||||
|
||||
</html>
|
||||
@@ -1,57 +0,0 @@
|
||||
<?php
|
||||
require_once('include/headscript.php');
|
||||
|
||||
/**
|
||||
* Salvataggio Opzioni Eventi (email/copie/promemoria) nella tabella `option`.
|
||||
*/
|
||||
if ($_SERVER['REQUEST_METHOD'] !== 'POST') {
|
||||
header('Location: event_options.php');
|
||||
exit();
|
||||
}
|
||||
|
||||
$pdo = DBHandlerSelect::getInstance()->getConnection();
|
||||
|
||||
function yn(string $k): string
|
||||
{
|
||||
return (isset($_POST[$k]) && $_POST[$k] === 'Y') ? 'Y' : 'N';
|
||||
}
|
||||
|
||||
$ccEmail = trim($_POST['event_notify_email'] ?? '');
|
||||
$reminderH = max(1, min(168, (int) ($_POST['event_reminder_hours'] ?? 24)));
|
||||
$offerH = max(1, min(336, (int) ($_POST['event_offer_expiry_hours'] ?? 24)));
|
||||
|
||||
try {
|
||||
// Individua la riga singola di configurazione
|
||||
$idption = (int) $pdo->query("SELECT idption FROM `option` ORDER BY idption ASC LIMIT 1")->fetchColumn();
|
||||
|
||||
$sql = "UPDATE `option` SET
|
||||
event_notify_email = :cc_email,
|
||||
event_cc_booking = :cc_booking,
|
||||
event_cc_promotion = :cc_promotion,
|
||||
event_cc_user_cancel = :cc_user_cancel,
|
||||
event_cc_event_cancel = :cc_event_cancel,
|
||||
event_cc_reminder = :cc_reminder,
|
||||
event_reminder_enabled = :rem_enabled,
|
||||
event_reminder_hours = :rem_hours,
|
||||
event_offer_expiry_hours = :offer_hours
|
||||
WHERE idption = :idption";
|
||||
$pdo->prepare($sql)->execute([
|
||||
':cc_email' => $ccEmail !== '' ? $ccEmail : null,
|
||||
':cc_booking' => yn('event_cc_booking'),
|
||||
':cc_promotion' => yn('event_cc_promotion'),
|
||||
':cc_user_cancel' => yn('event_cc_user_cancel'),
|
||||
':cc_event_cancel' => yn('event_cc_event_cancel'),
|
||||
':cc_reminder' => yn('event_cc_reminder'),
|
||||
':rem_enabled' => yn('event_reminder_enabled'),
|
||||
':rem_hours' => $reminderH,
|
||||
':offer_hours' => $offerH,
|
||||
':idption' => $idption,
|
||||
]);
|
||||
|
||||
header('Location: event_options.php?message=success');
|
||||
exit();
|
||||
} catch (Throwable $ex) {
|
||||
error_log('[event_options_save] ' . $ex->getMessage());
|
||||
header('Location: event_options.php?message=error');
|
||||
exit();
|
||||
}
|
||||
@@ -1,489 +0,0 @@
|
||||
<?php
|
||||
require_once('include/headscript.php');
|
||||
require_once('include/event_waitlist.php');
|
||||
require_once('include/event_mailer.php');
|
||||
|
||||
/**
|
||||
* Modulo Eventi - elenco partecipanti di un evento.
|
||||
* Mostra riepilogo (posti, iscrizioni, incasso) e la tabella delle prenotazioni.
|
||||
* Gestisce anche l'annullamento della singola iscrizione via ?cancel_booking=ID.
|
||||
*/
|
||||
$pdo = DBHandlerSelect::getInstance()->getConnection();
|
||||
|
||||
function e($value): string
|
||||
{
|
||||
return htmlspecialchars((string) $value, ENT_QUOTES, 'UTF-8');
|
||||
}
|
||||
|
||||
function initials(string $first, string $last): string
|
||||
{
|
||||
$ini = strtoupper(mb_substr(trim($first), 0, 1) . mb_substr(trim($last), 0, 1));
|
||||
return $ini !== '' ? $ini : '?';
|
||||
}
|
||||
|
||||
function avatarColor(string $seed): string
|
||||
{
|
||||
$palette = ['#1ebf73', '#2980b9', '#8e44ad', '#e67e22', '#16a085', '#c0392b', '#2c3e50', '#d35400'];
|
||||
return $palette[abs(crc32($seed)) % count($palette)];
|
||||
}
|
||||
|
||||
$eventId = isset($_GET['id']) ? (int) $_GET['id'] : 0;
|
||||
if ($eventId <= 0) {
|
||||
header('Location: events.php');
|
||||
exit();
|
||||
}
|
||||
|
||||
// Annullamento singola iscrizione (deve avvenire prima di ogni output)
|
||||
if (isset($_GET['cancel_booking'])) {
|
||||
$bookingId = (int) $_GET['cancel_booking'];
|
||||
$promoted = [];
|
||||
try {
|
||||
$pdo->beginTransaction();
|
||||
$pdo->prepare("SELECT id FROM events WHERE id = ? FOR UPDATE")->execute([$eventId]);
|
||||
|
||||
$bl = $pdo->prepare("SELECT status FROM event_bookings WHERE id = ? AND event_id = ?");
|
||||
$bl->execute([$bookingId, $eventId]);
|
||||
$bStatus = $bl->fetchColumn();
|
||||
|
||||
if ($bStatus !== false && $bStatus !== 'cancelled') {
|
||||
$wasOccupying = in_array($bStatus, ['confirmed', 'pending', 'offered'], true);
|
||||
$pdo->prepare("UPDATE event_bookings SET status = 'cancelled', updated_at = NOW() WHERE id = ? AND event_id = ?")
|
||||
->execute([$bookingId, $eventId]);
|
||||
if ($wasOccupying) {
|
||||
// libera posti -> offre alla prima in lista d'attesa
|
||||
$promoted = promoteFromWaitlist($pdo, $eventId);
|
||||
}
|
||||
}
|
||||
$pdo->commit();
|
||||
|
||||
// Email di promozione (E, con riconferma) ai nuovi "offered"
|
||||
if (!empty($promoted)) {
|
||||
$ev = $pdo->prepare("SELECT * FROM events WHERE id = ?");
|
||||
$ev->execute([$eventId]);
|
||||
$evRow = $ev->fetch(PDO::FETCH_ASSOC);
|
||||
if ($evRow) {
|
||||
foreach ($promoted as $pr) {
|
||||
try {
|
||||
yse_mail_promotion($pr, $evRow);
|
||||
} catch (Throwable $me) {
|
||||
error_log('[promo mail] ' . $me->getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (Throwable $ex) {
|
||||
if ($pdo->inTransaction()) {
|
||||
$pdo->rollBack();
|
||||
}
|
||||
error_log('[participants cancel] ' . $ex->getMessage());
|
||||
}
|
||||
header('Location: event_participants.php?id=' . $eventId . '&message=booking_cancelled');
|
||||
exit();
|
||||
}
|
||||
|
||||
$stmt = $pdo->prepare("SELECT * FROM events WHERE id = ?");
|
||||
$stmt->execute([$eventId]);
|
||||
$event = $stmt->fetch(PDO::FETCH_ASSOC);
|
||||
if (!$event) {
|
||||
header('Location: events.php?message=error');
|
||||
exit();
|
||||
}
|
||||
|
||||
$bStmt = $pdo->prepare("SELECT * FROM event_bookings WHERE event_id = ? ORDER BY created_at DESC, id DESC");
|
||||
$bStmt->execute([$eventId]);
|
||||
$bookings = $bStmt->fetchAll(PDO::FETCH_ASSOC);
|
||||
|
||||
// Riepilogo: posti occupati = confermate/pending/offerte (in riconferma); lista d'attesa a parte
|
||||
$bookedSeats = 0;
|
||||
$waitingSeats = 0;
|
||||
$activeCount = 0;
|
||||
$revenue = 0.0;
|
||||
foreach ($bookings as $b) {
|
||||
if (in_array($b['status'], ['confirmed', 'pending', 'offered'], true)) {
|
||||
$bookedSeats += (int) $b['seats'];
|
||||
$activeCount++;
|
||||
$revenue += (float) $b['amount'];
|
||||
} elseif ($b['status'] === 'waiting') {
|
||||
$waitingSeats += (int) $b['seats'];
|
||||
}
|
||||
}
|
||||
$maxSeats = (int) $event['max_seats'];
|
||||
$message = $_GET['message'] ?? '';
|
||||
|
||||
function bookingBadge(string $status): array
|
||||
{
|
||||
switch ($status) {
|
||||
case 'confirmed':
|
||||
return ['Confermata', '#e7f7ee', '#1a7f52'];
|
||||
case 'cancelled':
|
||||
return ['Annullata', '#fdecea', '#c0392b'];
|
||||
case 'waiting':
|
||||
return ["Lista d'attesa", '#eef2fb', '#3a5bb8'];
|
||||
case 'offered':
|
||||
return ['Da riconfermare', '#fff4e5', '#b26a00'];
|
||||
default:
|
||||
return ['In attesa', '#fff4e5', '#b26a00'];
|
||||
}
|
||||
}
|
||||
?>
|
||||
<!doctype html>
|
||||
<html lang="it">
|
||||
|
||||
<head>
|
||||
<meta charset="utf-8" />
|
||||
<title>YogiBook - Partecipanti</title>
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<link rel="shortcut icon" href="assets/images/favicon.ico">
|
||||
<link href="assets/css/bootstrap.min.css" id="bootstrap-style" rel="stylesheet" type="text/css" />
|
||||
<link href="assets/css/icons.min.css" rel="stylesheet" type="text/css" />
|
||||
<link href="assets/css/app.min.css" id="app-style" rel="stylesheet" type="text/css" />
|
||||
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.0.0-beta3/css/all.min.css">
|
||||
<script src="https://cdn.jsdelivr.net/npm/sweetalert2@11"></script>
|
||||
<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
|
||||
|
||||
<style>
|
||||
.admin-card {
|
||||
border: none;
|
||||
border-radius: 14px;
|
||||
box-shadow: 0 4px 20px rgba(0, 0, 0, 0.06);
|
||||
}
|
||||
|
||||
.admin-card .card-body {
|
||||
padding: 26px 30px;
|
||||
}
|
||||
|
||||
.section-title {
|
||||
font-size: 15px;
|
||||
font-weight: 700;
|
||||
letter-spacing: 0.04em;
|
||||
text-transform: uppercase;
|
||||
color: #6b7280;
|
||||
margin-bottom: 4px;
|
||||
}
|
||||
|
||||
.section-lead {
|
||||
color: #9ca3af;
|
||||
font-size: 14px;
|
||||
margin-bottom: 22px;
|
||||
}
|
||||
|
||||
.stat-box {
|
||||
background: #f7f8fa;
|
||||
border-radius: 12px;
|
||||
padding: 18px 20px;
|
||||
}
|
||||
|
||||
.stat-value {
|
||||
font-size: 26px;
|
||||
font-weight: 700;
|
||||
color: #1f2937;
|
||||
}
|
||||
|
||||
.stat-label {
|
||||
color: #6b7280;
|
||||
font-size: 13px;
|
||||
font-weight: 600;
|
||||
text-transform: uppercase;
|
||||
letter-spacing: 0.03em;
|
||||
}
|
||||
|
||||
.part-table thead th {
|
||||
font-size: 12px;
|
||||
text-transform: uppercase;
|
||||
letter-spacing: 0.03em;
|
||||
color: #6b7280;
|
||||
border-bottom: 2px solid #eef0f3;
|
||||
white-space: nowrap;
|
||||
}
|
||||
|
||||
.part-table td {
|
||||
vertical-align: middle;
|
||||
}
|
||||
|
||||
.user-cell {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 10px;
|
||||
}
|
||||
|
||||
.avatar {
|
||||
width: 36px;
|
||||
height: 36px;
|
||||
border-radius: 50%;
|
||||
color: #fff;
|
||||
font-weight: 700;
|
||||
font-size: 13px;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
flex-shrink: 0;
|
||||
}
|
||||
|
||||
.user-name {
|
||||
font-weight: 600;
|
||||
color: #1f2937;
|
||||
}
|
||||
|
||||
.guest-tag {
|
||||
font-size: 11px;
|
||||
font-weight: 600;
|
||||
color: #6b7280;
|
||||
background: #eef0f3;
|
||||
border-radius: 10px;
|
||||
padding: 1px 7px;
|
||||
margin-left: 6px;
|
||||
}
|
||||
|
||||
.status-badge {
|
||||
display: inline-block;
|
||||
font-size: 12px;
|
||||
font-weight: 700;
|
||||
padding: 3px 10px;
|
||||
border-radius: 20px;
|
||||
}
|
||||
|
||||
.btn-cancel-b {
|
||||
border: 1px solid #f2c9c4;
|
||||
background: #fff;
|
||||
color: #c0392b;
|
||||
border-radius: 8px;
|
||||
padding: 5px 11px;
|
||||
font-size: 13px;
|
||||
font-weight: 600;
|
||||
cursor: pointer;
|
||||
white-space: nowrap;
|
||||
}
|
||||
|
||||
.btn-cancel-b:hover {
|
||||
background: #fdecea;
|
||||
}
|
||||
|
||||
.empty-state {
|
||||
text-align: center;
|
||||
padding: 44px 10px;
|
||||
color: #9ca3af;
|
||||
}
|
||||
|
||||
.empty-state i {
|
||||
font-size: 34px;
|
||||
margin-bottom: 10px;
|
||||
display: block;
|
||||
color: #d5d9e0;
|
||||
}
|
||||
|
||||
.yes-mark {
|
||||
color: #1a7f52;
|
||||
font-weight: 700;
|
||||
}
|
||||
|
||||
.no-mark {
|
||||
color: #c0392b;
|
||||
font-weight: 700;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<div id="layout-wrapper">
|
||||
<header id="page-topbar" class="isvertical-topbar">
|
||||
<div class="navbar-header">
|
||||
<div class="d-flex">
|
||||
<?php include('include/logoarea.php'); ?>
|
||||
<button type="button" class="btn btn-sm px-3 font-size-24 header-item waves-effect vertical-menu-btn">
|
||||
<i class="bx bx-menu align-middle"></i>
|
||||
</button>
|
||||
<div class="page-title-box align-self-center d-none d-md-block">
|
||||
<h4 class="page-title mb-0">Partecipanti</h4>
|
||||
</div>
|
||||
</div>
|
||||
<div class="d-flex">
|
||||
<?php include('include/languageselection.php'); ?>
|
||||
<?php include('include/profiletopbar.php'); ?>
|
||||
</div>
|
||||
</div>
|
||||
</header>
|
||||
<?php include('include/sidebar.php'); ?>
|
||||
<header class="ishorizontal-topbar">
|
||||
<div class="navbar-header">
|
||||
<div class="d-flex"></div>
|
||||
</div>
|
||||
<div class="topnav">
|
||||
<div class="container-fluid">
|
||||
<nav class="navbar navbar-light navbar-expand-lg topnav-menu"></nav>
|
||||
</div>
|
||||
</div>
|
||||
</header>
|
||||
|
||||
<div class="main-content">
|
||||
<div class="page-content">
|
||||
<div class="container-fluid">
|
||||
|
||||
<?php if ($message === 'booking_cancelled') : ?>
|
||||
<div class="alert alert-warning" role="alert">Iscrizione annullata.</div>
|
||||
<?php endif; ?>
|
||||
|
||||
<div class="row">
|
||||
<div class="col-12">
|
||||
<div class="card admin-card mb-4">
|
||||
<div class="card-body">
|
||||
<div class="d-flex justify-content-between align-items-start">
|
||||
<div>
|
||||
<div class="section-title">Partecipanti</div>
|
||||
<p class="section-lead mb-0">
|
||||
<strong style="color:#1f2937;"><?php echo e($event['title']); ?></strong>
|
||||
· <?php echo e(date('d-m-Y H:i', strtotime($event['starts_at']))); ?>
|
||||
</p>
|
||||
</div>
|
||||
<a href="events.php" class="btn btn-light" style="border-radius:8px;font-weight:600;"><i class="bx bx-arrow-back"></i> Tutti gli eventi</a>
|
||||
</div>
|
||||
|
||||
<div class="row mt-4">
|
||||
<div class="col-md-3 mb-3">
|
||||
<div class="stat-box">
|
||||
<div class="stat-value"><?php echo $bookedSeats; ?> / <?php echo $maxSeats; ?></div>
|
||||
<div class="stat-label">Posti prenotati</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-md-3 mb-3">
|
||||
<div class="stat-box">
|
||||
<div class="stat-value"><?php echo $waitingSeats; ?></div>
|
||||
<div class="stat-label">In lista d'attesa</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-md-3 mb-3">
|
||||
<div class="stat-box">
|
||||
<div class="stat-value"><?php echo $activeCount; ?></div>
|
||||
<div class="stat-label">Iscrizioni attive</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-md-3 mb-3">
|
||||
<div class="stat-box">
|
||||
<div class="stat-value"><?php echo e(number_format($revenue, 2, ',', '.')); ?> <?php echo e($event['currency']); ?></div>
|
||||
<div class="stat-label">Incasso stimato</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="row">
|
||||
<div class="col-12">
|
||||
<div class="card admin-card">
|
||||
<div class="card-body">
|
||||
<div class="table-responsive">
|
||||
<table class="table part-table align-middle">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Partecipante</th>
|
||||
<th>Email</th>
|
||||
<th>Telefono</th>
|
||||
<th>Posti</th>
|
||||
<th>Marketing</th>
|
||||
<th>Iscritto il</th>
|
||||
<th>Stato</th>
|
||||
<th class="text-end">Azioni</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<?php if (empty($bookings)) : ?>
|
||||
<tr>
|
||||
<td colspan="8">
|
||||
<div class="empty-state">
|
||||
<i class="fas fa-users"></i>
|
||||
Ancora nessun iscritto a questo evento.
|
||||
</div>
|
||||
</td>
|
||||
</tr>
|
||||
<?php else :
|
||||
foreach ($bookings as $b) :
|
||||
// Il nome può essere un unico campo: proviamo a spezzarlo per le iniziali
|
||||
$nameParts = preg_split('/\s+/', trim($b['name']), 2);
|
||||
$first = $nameParts[0] ?? '';
|
||||
$last = $nameParts[1] ?? '';
|
||||
$isGuest = empty($b['user_id']);
|
||||
[$stLabel, $stBg, $stColor] = bookingBadge($b['status']);
|
||||
?>
|
||||
<tr>
|
||||
<td>
|
||||
<div class="user-cell">
|
||||
<div class="avatar" style="background: <?php echo avatarColor($b['name']); ?>;">
|
||||
<?php echo e(initials($first, $last)); ?>
|
||||
</div>
|
||||
<span class="user-name"><?php echo e($b['name']); ?>
|
||||
<?php if ($isGuest) : ?><span class="guest-tag">ospite</span><?php endif; ?>
|
||||
</span>
|
||||
</div>
|
||||
</td>
|
||||
<td><?php echo e($b['email']); ?></td>
|
||||
<td><?php echo e($b['phone'] ?: '—'); ?></td>
|
||||
<td><?php echo (int) $b['seats']; ?></td>
|
||||
<td>
|
||||
<?php if (($b['marketing_opt_in'] ?? 'N') === 'Y') : ?>
|
||||
<span class="yes-mark">Sì</span>
|
||||
<?php else : ?>
|
||||
<span class="no-mark">No</span>
|
||||
<?php endif; ?>
|
||||
</td>
|
||||
<td><?php echo e($b['created_at'] ? date('d-m-Y', strtotime($b['created_at'])) : '—'); ?></td>
|
||||
<td><span class="status-badge" style="background: <?php echo $stBg; ?>; color: <?php echo $stColor; ?>;"><?php echo e($stLabel); ?></span></td>
|
||||
<td class="text-end">
|
||||
<?php if ($b['status'] !== 'cancelled') : ?>
|
||||
<button type="button" class="btn-cancel-b btn-cancel-booking"
|
||||
data-id="<?php echo (int) $b['id']; ?>"
|
||||
data-name="<?php echo e($b['name']); ?>">
|
||||
<i class="bx bx-block"></i> Annulla
|
||||
</button>
|
||||
<?php else : ?>
|
||||
<span style="color:#9ca3af;font-size:13px;">—</span>
|
||||
<?php endif; ?>
|
||||
</td>
|
||||
</tr>
|
||||
<?php endforeach; ?>
|
||||
<?php endif; ?>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
<?php include('include/footer.php'); ?>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<script src="assets/libs/bootstrap/js/bootstrap.bundle.min.js"></script>
|
||||
<script src="assets/libs/metismenujs/metismenujs.min.js"></script>
|
||||
<script src="assets/libs/simplebar/simplebar.min.js"></script>
|
||||
<script src="assets/libs/eva-icons/eva.min.js"></script>
|
||||
<script src="assets/js/app.js"></script>
|
||||
|
||||
<script>
|
||||
$(document).ready(function() {
|
||||
$('.btn-cancel-booking').on('click', function() {
|
||||
var id = $(this).data('id');
|
||||
var name = $(this).data('name');
|
||||
Swal.fire({
|
||||
title: 'Annullare iscrizione?',
|
||||
html: 'Stai per annullare l\'iscrizione di <strong>' + $('<div>').text(name).html() + '</strong>.',
|
||||
icon: 'warning',
|
||||
showCancelButton: true,
|
||||
confirmButtonText: 'Annulla iscrizione',
|
||||
cancelButtonText: 'Chiudi',
|
||||
confirmButtonColor: '#e74c3c',
|
||||
reverseButtons: true
|
||||
}).then(function(result) {
|
||||
if (result.isConfirmed) {
|
||||
window.location.href = 'event_participants.php?id=<?php echo $eventId; ?>&cancel_booking=' + id;
|
||||
}
|
||||
});
|
||||
});
|
||||
});
|
||||
</script>
|
||||
</body>
|
||||
|
||||
</html>
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,222 +0,0 @@
|
||||
<?php
|
||||
require_once('include/headscript.php');
|
||||
require_once('include/event_mailer.php');
|
||||
|
||||
/**
|
||||
* Promemoria manuale: apre un editor col testo prefissato (modificabile) e il
|
||||
* punto di ritrovo come link mappa (prefill dal luogo evento). Invio da
|
||||
* event_reminder_send.php a tutti gli iscritti confermati.
|
||||
*/
|
||||
$pdo = DBHandlerSelect::getInstance()->getConnection();
|
||||
|
||||
function e($value): string
|
||||
{
|
||||
return htmlspecialchars((string) $value, ENT_QUOTES, 'UTF-8');
|
||||
}
|
||||
|
||||
$eventId = isset($_GET['id']) ? (int) $_GET['id'] : 0;
|
||||
if ($eventId <= 0) {
|
||||
header('Location: events.php');
|
||||
exit();
|
||||
}
|
||||
|
||||
$stmt = $pdo->prepare("SELECT * FROM events WHERE id = ?");
|
||||
$stmt->execute([$eventId]);
|
||||
$event = $stmt->fetch(PDO::FETCH_ASSOC);
|
||||
if (!$event) {
|
||||
header('Location: events.php?message=error');
|
||||
exit();
|
||||
}
|
||||
|
||||
$cnt = $pdo->prepare("SELECT COUNT(*) FROM event_bookings WHERE event_id = ? AND status = 'confirmed'");
|
||||
$cnt->execute([$eventId]);
|
||||
$recipients = (int) $cnt->fetchColumn();
|
||||
|
||||
$defaultMsg = "Ti ricordiamo il tuo prossimo appuntamento. Ti aspettiamo, a presto!";
|
||||
$meetingLink = yse_maps_link($event); // prefill: link mappa derivato dall'indirizzo/coordinate
|
||||
$message = $_GET['message'] ?? '';
|
||||
?>
|
||||
<!doctype html>
|
||||
<html lang="it">
|
||||
|
||||
<head>
|
||||
<meta charset="utf-8" />
|
||||
<title>YogiBook - Promemoria</title>
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<link rel="shortcut icon" href="assets/images/favicon.ico">
|
||||
<link href="assets/css/bootstrap.min.css" id="bootstrap-style" rel="stylesheet" type="text/css" />
|
||||
<link href="assets/css/icons.min.css" rel="stylesheet" type="text/css" />
|
||||
<link href="assets/css/app.min.css" id="app-style" rel="stylesheet" type="text/css" />
|
||||
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.0.0-beta3/css/all.min.css">
|
||||
<script src="https://cdn.jsdelivr.net/npm/sweetalert2@11"></script>
|
||||
|
||||
<style>
|
||||
.admin-card {
|
||||
border: none;
|
||||
border-radius: 14px;
|
||||
box-shadow: 0 4px 20px rgba(0, 0, 0, 0.06);
|
||||
}
|
||||
|
||||
.admin-card .card-body {
|
||||
padding: 26px 30px;
|
||||
}
|
||||
|
||||
.section-title {
|
||||
font-size: 15px;
|
||||
font-weight: 700;
|
||||
letter-spacing: 0.04em;
|
||||
text-transform: uppercase;
|
||||
color: #6b7280;
|
||||
margin-bottom: 4px;
|
||||
}
|
||||
|
||||
.section-lead {
|
||||
color: #9ca3af;
|
||||
font-size: 14px;
|
||||
margin-bottom: 22px;
|
||||
}
|
||||
|
||||
.form-label {
|
||||
font-weight: 600;
|
||||
font-size: 14px;
|
||||
color: #374151;
|
||||
}
|
||||
|
||||
.form-control {
|
||||
border-radius: 8px;
|
||||
border: 1px solid #e2e4e9;
|
||||
padding: 10px 12px;
|
||||
}
|
||||
|
||||
.form-control:focus {
|
||||
border-color: #1ebf73;
|
||||
box-shadow: 0 0 0 3px rgba(30, 191, 115, 0.12);
|
||||
}
|
||||
|
||||
.hint {
|
||||
color: #9ca3af;
|
||||
font-size: 12px;
|
||||
margin-top: 4px;
|
||||
}
|
||||
|
||||
.recap {
|
||||
background: #f7f8fa;
|
||||
border-radius: 10px;
|
||||
padding: 12px 14px;
|
||||
font-size: 14px;
|
||||
color: #4b5563;
|
||||
margin-bottom: 18px;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<div id="layout-wrapper">
|
||||
<header id="page-topbar" class="isvertical-topbar">
|
||||
<div class="navbar-header">
|
||||
<div class="d-flex">
|
||||
<?php include('include/logoarea.php'); ?>
|
||||
<button type="button" class="btn btn-sm px-3 font-size-24 header-item waves-effect vertical-menu-btn">
|
||||
<i class="bx bx-menu align-middle"></i>
|
||||
</button>
|
||||
<div class="page-title-box align-self-center d-none d-md-block">
|
||||
<h4 class="page-title mb-0">Promemoria</h4>
|
||||
</div>
|
||||
</div>
|
||||
<div class="d-flex">
|
||||
<?php include('include/languageselection.php'); ?>
|
||||
<?php include('include/profiletopbar.php'); ?>
|
||||
</div>
|
||||
</div>
|
||||
</header>
|
||||
<?php include('include/sidebar.php'); ?>
|
||||
<header class="ishorizontal-topbar">
|
||||
<div class="navbar-header">
|
||||
<div class="d-flex"></div>
|
||||
</div>
|
||||
<div class="topnav">
|
||||
<div class="container-fluid">
|
||||
<nav class="navbar navbar-light navbar-expand-lg topnav-menu"></nav>
|
||||
</div>
|
||||
</div>
|
||||
</header>
|
||||
|
||||
<div class="main-content">
|
||||
<div class="page-content">
|
||||
<div class="container-fluid">
|
||||
<?php if ($message === 'sent') : ?>
|
||||
<div class="alert alert-success" role="alert">Promemoria inviato.</div>
|
||||
<?php elseif ($message === 'error') : ?>
|
||||
<div class="alert alert-danger" role="alert">Errore durante l'invio.</div>
|
||||
<?php endif; ?>
|
||||
|
||||
<div class="row">
|
||||
<div class="col-lg-8">
|
||||
<div class="card admin-card">
|
||||
<div class="card-body">
|
||||
<div class="section-title">Invia promemoria</div>
|
||||
<p class="section-lead">Controlla il testo e il punto di ritrovo, poi invia agli iscritti confermati.</p>
|
||||
|
||||
<div class="recap">
|
||||
<strong style="color:#1f2937;"><?php echo e($event['title']); ?></strong> · <?php echo e(date('d-m-Y H:i', strtotime($event['starts_at']))); ?><br>
|
||||
Destinatari confermati: <strong><?php echo $recipients; ?></strong>
|
||||
</div>
|
||||
|
||||
<form action="event_reminder_send.php" method="POST" id="rem-form">
|
||||
<input type="hidden" name="id" value="<?php echo (int) $eventId; ?>">
|
||||
|
||||
<div class="mb-3">
|
||||
<label class="form-label">Messaggio</label>
|
||||
<textarea class="form-control" name="message" rows="5"><?php echo e($defaultMsg); ?></textarea>
|
||||
<div class="hint">Data, ora e luogo dell'evento vengono aggiunti automaticamente sotto al messaggio.</div>
|
||||
</div>
|
||||
|
||||
<div class="mb-3">
|
||||
<label class="form-label">Punto di ritrovo (link mappa)</label>
|
||||
<input type="url" class="form-control" name="meeting_link" value="<?php echo e($meetingLink); ?>" placeholder="Incolla qui il link di Google Maps del punto di ritrovo">
|
||||
<div class="hint">Prefissato dal luogo dell'evento. Puoi incollare un link di Google Maps più preciso (es. la condivisione della posizione). Lascia vuoto per non includerlo.</div>
|
||||
</div>
|
||||
|
||||
<div class="d-flex justify-content-between mt-2">
|
||||
<a href="events.php" class="btn btn-light" style="border-radius:8px;font-weight:600;"><i class="bx bx-arrow-back"></i> Indietro</a>
|
||||
<button type="submit" class="btn btn-success" style="border-radius:8px;font-weight:600;" <?php echo $recipients === 0 ? 'disabled' : ''; ?>>
|
||||
<i class="bx bx-send"></i> Invia a <?php echo $recipients; ?> iscritt<?php echo $recipients === 1 ? 'o' : 'i'; ?>
|
||||
</button>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<?php include('include/footer.php'); ?>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<script src="assets/libs/bootstrap/js/bootstrap.bundle.min.js"></script>
|
||||
<script src="assets/libs/metismenujs/metismenujs.min.js"></script>
|
||||
<script src="assets/libs/simplebar/simplebar.min.js"></script>
|
||||
<script src="assets/libs/eva-icons/eva.min.js"></script>
|
||||
<script src="assets/js/app.js"></script>
|
||||
<script>
|
||||
document.getElementById('rem-form').addEventListener('submit', function(ev) {
|
||||
ev.preventDefault();
|
||||
var form = this;
|
||||
Swal.fire({
|
||||
title: 'Inviare il promemoria?',
|
||||
text: 'Verrà inviato a <?php echo $recipients; ?> iscritti confermati.',
|
||||
icon: 'question',
|
||||
showCancelButton: true,
|
||||
confirmButtonText: 'Invia',
|
||||
cancelButtonText: 'Annulla',
|
||||
confirmButtonColor: '#1ebf73',
|
||||
reverseButtons: true
|
||||
}).then(function(r) {
|
||||
if (r.isConfirmed) form.submit();
|
||||
});
|
||||
});
|
||||
</script>
|
||||
</body>
|
||||
|
||||
</html>
|
||||
@@ -1,58 +0,0 @@
|
||||
<?php
|
||||
require_once('include/headscript.php');
|
||||
require_once('include/event_mailer.php');
|
||||
|
||||
/**
|
||||
* Invio del promemoria manuale a tutti gli iscritti confermati di un evento.
|
||||
*/
|
||||
if ($_SERVER['REQUEST_METHOD'] !== 'POST') {
|
||||
header('Location: events.php');
|
||||
exit();
|
||||
}
|
||||
|
||||
$pdo = DBHandlerSelect::getInstance()->getConnection();
|
||||
|
||||
$eventId = (int) ($_POST['id'] ?? 0);
|
||||
$message = trim($_POST['message'] ?? '');
|
||||
$meetingLink = trim($_POST['meeting_link'] ?? '');
|
||||
|
||||
if ($eventId <= 0) {
|
||||
header('Location: events.php');
|
||||
exit();
|
||||
}
|
||||
|
||||
// Accetta solo link http/https come punto di ritrovo
|
||||
if ($meetingLink !== '' && !preg_match('#^https?://#i', $meetingLink)) {
|
||||
$meetingLink = '';
|
||||
}
|
||||
|
||||
try {
|
||||
$es = $pdo->prepare("SELECT * FROM events WHERE id = ?");
|
||||
$es->execute([$eventId]);
|
||||
$event = $es->fetch(PDO::FETCH_ASSOC);
|
||||
if (!$event) {
|
||||
header('Location: events.php?message=error');
|
||||
exit();
|
||||
}
|
||||
|
||||
$ps = $pdo->prepare("SELECT * FROM event_bookings WHERE event_id = ? AND status = 'confirmed'");
|
||||
$ps->execute([$eventId]);
|
||||
$participants = $ps->fetchAll(PDO::FETCH_ASSOC);
|
||||
|
||||
foreach ($participants as $p) {
|
||||
try {
|
||||
yse_mail_reminder($p, $event, $message, $meetingLink);
|
||||
} catch (Throwable $me) {
|
||||
error_log('[reminder send] ' . $me->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
$pdo->prepare("UPDATE events SET reminder_sent_at = NOW() WHERE id = ?")->execute([$eventId]);
|
||||
|
||||
header('Location: event_reminder.php?id=' . $eventId . '&message=sent');
|
||||
exit();
|
||||
} catch (Throwable $ex) {
|
||||
error_log('[event_reminder_send] ' . $ex->getMessage());
|
||||
header('Location: event_reminder.php?id=' . $eventId . '&message=error');
|
||||
exit();
|
||||
}
|
||||
@@ -1,214 +0,0 @@
|
||||
<?php
|
||||
require_once('include/headscript.php');
|
||||
|
||||
/**
|
||||
* Handler salvataggio evento (insert + update). Riceve il POST di event_form.php,
|
||||
* genera lo slug se mancante, valida i campi e fa redirect con ?message=.
|
||||
*/
|
||||
if ($_SERVER['REQUEST_METHOD'] !== 'POST') {
|
||||
header('Location: events.php');
|
||||
exit();
|
||||
}
|
||||
|
||||
$pdo = DBHandlerSelect::getInstance()->getConnection();
|
||||
|
||||
// --- ID insegnante loggato -------------------------------------------------
|
||||
// headscript.php popola $iduserlogin da Auth::user()->present()->id
|
||||
$currentUserId = $iduserlogin ?? ($_SESSION['iduserlogin'] ?? null);
|
||||
|
||||
// --- Helper ----------------------------------------------------------------
|
||||
function slugify(string $text): string
|
||||
{
|
||||
$text = trim($text);
|
||||
if (function_exists('iconv')) {
|
||||
$conv = @iconv('UTF-8', 'ASCII//TRANSLIT//IGNORE', $text);
|
||||
if ($conv !== false) {
|
||||
$text = $conv;
|
||||
}
|
||||
}
|
||||
$text = strtolower($text);
|
||||
$text = preg_replace('/[^a-z0-9]+/', '-', $text);
|
||||
$text = trim($text, '-');
|
||||
return $text !== '' ? $text : 'evento';
|
||||
}
|
||||
|
||||
function uniqueSlug(PDO $pdo, string $base, int $excludeId): string
|
||||
{
|
||||
$slug = $base;
|
||||
$i = 2;
|
||||
while (true) {
|
||||
if ($excludeId > 0) {
|
||||
$st = $pdo->prepare("SELECT COUNT(*) FROM events WHERE slug = ? AND id <> ?");
|
||||
$st->execute([$slug, $excludeId]);
|
||||
} else {
|
||||
$st = $pdo->prepare("SELECT COUNT(*) FROM events WHERE slug = ?");
|
||||
$st->execute([$slug]);
|
||||
}
|
||||
if ((int) $st->fetchColumn() === 0) {
|
||||
return $slug;
|
||||
}
|
||||
$slug = $base . '-' . $i;
|
||||
$i++;
|
||||
}
|
||||
}
|
||||
|
||||
function toDateTime(?string $v): ?string
|
||||
{
|
||||
if (!$v) {
|
||||
return null;
|
||||
}
|
||||
$v = str_replace('T', ' ', $v);
|
||||
$ts = strtotime($v);
|
||||
return $ts ? date('Y-m-d H:i:s', $ts) : null;
|
||||
}
|
||||
|
||||
// --- Lettura e validazione input -------------------------------------------
|
||||
$id = isset($_POST['id']) ? (int) $_POST['id'] : 0;
|
||||
$title = trim($_POST['title'] ?? '');
|
||||
|
||||
$startsAt = toDateTime($_POST['starts_at'] ?? null);
|
||||
$maxSeats = (int) ($_POST['max_seats'] ?? 0);
|
||||
|
||||
$redirectOnError = $id > 0 ? "event_form.php?id={$id}&message=error" : "event_form.php?message=error";
|
||||
if ($title === '' || $startsAt === null || $maxSeats < 1) {
|
||||
header("Location: {$redirectOnError}");
|
||||
exit();
|
||||
}
|
||||
|
||||
$slugInput = trim($_POST['slug'] ?? '');
|
||||
$slugBase = slugify($slugInput !== '' ? $slugInput : $title);
|
||||
$slug = uniqueSlug($pdo, $slugBase, $id);
|
||||
|
||||
$endsAt = toDateTime($_POST['ends_at'] ?? null);
|
||||
$address = trim($_POST['address'] ?? '');
|
||||
$organizer = trim($_POST['organizer_name'] ?? '');
|
||||
$description = $_POST['description'] ?? '';
|
||||
$cost = round((float) ($_POST['cost'] ?? 0), 2);
|
||||
$maxPerBooking = max(1, (int) ($_POST['max_per_booking'] ?? 1));
|
||||
$coverImage = trim($_POST['cover_image'] ?? '');
|
||||
|
||||
$lat = ($_POST['lat'] ?? '') !== '' ? (float) $_POST['lat'] : null;
|
||||
$lng = ($_POST['lng'] ?? '') !== '' ? (float) $_POST['lng'] : null;
|
||||
|
||||
$currency = strtoupper(trim($_POST['currency'] ?? 'EUR'));
|
||||
if (!in_array($currency, ['EUR', 'USD', 'GBP', 'CHF'], true)) {
|
||||
$currency = 'EUR';
|
||||
}
|
||||
|
||||
$color = trim($_POST['color'] ?? '#4CAF50');
|
||||
if (!preg_match('/^#[0-9a-fA-F]{6}$/', $color)) {
|
||||
$color = '#4CAF50';
|
||||
}
|
||||
|
||||
$status = $_POST['status'] ?? 'draft';
|
||||
if (!in_array($status, ['draft', 'published', 'cancelled'], true)) {
|
||||
$status = 'draft';
|
||||
}
|
||||
|
||||
// Apertura programmata: se attiva con data futura -> stato 'scheduled' + publish_at
|
||||
$scheduleEnabled = isset($_POST['schedule_enabled']) && $_POST['schedule_enabled'] === 'Y';
|
||||
$publishAt = toDateTime($_POST['publish_at'] ?? null);
|
||||
if ($scheduleEnabled && $publishAt && strtotime($publishAt) > time()) {
|
||||
$status = 'scheduled';
|
||||
} else {
|
||||
$publishAt = null; // niente programmazione (o data già passata)
|
||||
}
|
||||
|
||||
// Campi facoltativi (testo)
|
||||
$instructions = trim($_POST['instructions'] ?? '');
|
||||
$whatToBring = trim($_POST['what_to_bring'] ?? '');
|
||||
$suitableFor = trim($_POST['suitable_for'] ?? '');
|
||||
|
||||
$waitlistEnabled = (isset($_POST['waitlist_enabled']) && $_POST['waitlist_enabled'] === 'Y') ? 'Y' : 'N';
|
||||
|
||||
// Override per-evento (NULL = usa default scuola)
|
||||
$reminderEnabled = (isset($_POST['reminder_enabled']) && in_array($_POST['reminder_enabled'], ['Y', 'N'], true)) ? $_POST['reminder_enabled'] : null;
|
||||
$reminderHours = (($_POST['reminder_hours'] ?? '') !== '') ? max(1, min(168, (int) $_POST['reminder_hours'])) : null;
|
||||
$offerHours = (($_POST['offer_expiry_hours'] ?? '') !== '') ? max(1, min(336, (int) $_POST['offer_expiry_hours'])) : null;
|
||||
|
||||
// Galleria: array JSON di path -> validazione e re-encode pulito
|
||||
$gallery = null;
|
||||
$galleryRaw = $_POST['gallery'] ?? '';
|
||||
if ($galleryRaw !== '') {
|
||||
$decoded = json_decode($galleryRaw, true);
|
||||
if (is_array($decoded)) {
|
||||
$clean = [];
|
||||
foreach ($decoded as $p) {
|
||||
if (is_string($p) && $p !== '') {
|
||||
$clean[] = $p;
|
||||
}
|
||||
}
|
||||
$gallery = !empty($clean) ? json_encode(array_values($clean), JSON_UNESCAPED_SLASHES) : null;
|
||||
}
|
||||
}
|
||||
|
||||
// --- Insert / Update -------------------------------------------------------
|
||||
try {
|
||||
if ($id > 0) {
|
||||
$sql = "UPDATE events SET
|
||||
title = :title, slug = :slug, description = :description,
|
||||
instructions = :instructions, what_to_bring = :what_to_bring, suitable_for = :suitable_for,
|
||||
organizer_name = :organizer_name, starts_at = :starts_at, ends_at = :ends_at,
|
||||
address = :address, lat = :lat, lng = :lng, cost = :cost, currency = :currency,
|
||||
max_seats = :max_seats, max_per_booking = :max_per_booking, color = :color,
|
||||
waitlist_enabled = :waitlist_enabled,
|
||||
reminder_enabled = :reminder_enabled, reminder_hours = :reminder_hours, offer_expiry_hours = :offer_expiry_hours,
|
||||
cover_image = :cover_image, gallery = :gallery, status = :status, publish_at = :publish_at, updated_at = NOW()
|
||||
WHERE id = :id";
|
||||
$params = [':id' => $id];
|
||||
} else {
|
||||
$sql = "INSERT INTO events
|
||||
(user_id, title, slug, description, instructions, what_to_bring, suitable_for,
|
||||
organizer_name, starts_at, ends_at,
|
||||
address, lat, lng, cost, currency, max_seats, max_per_booking, color,
|
||||
waitlist_enabled,
|
||||
reminder_enabled, reminder_hours, offer_expiry_hours,
|
||||
cover_image, gallery, status, publish_at, created_at, updated_at)
|
||||
VALUES
|
||||
(:user_id, :title, :slug, :description, :instructions, :what_to_bring, :suitable_for,
|
||||
:organizer_name, :starts_at, :ends_at,
|
||||
:address, :lat, :lng, :cost, :currency, :max_seats, :max_per_booking, :color,
|
||||
:waitlist_enabled,
|
||||
:reminder_enabled, :reminder_hours, :offer_expiry_hours,
|
||||
:cover_image, :gallery, :status, :publish_at, NOW(), NOW())";
|
||||
$params = [':user_id' => $currentUserId];
|
||||
}
|
||||
|
||||
$params += [
|
||||
':title' => $title,
|
||||
':slug' => $slug,
|
||||
':description' => $description !== '' ? $description : null,
|
||||
':instructions' => $instructions !== '' ? $instructions : null,
|
||||
':what_to_bring' => $whatToBring !== '' ? $whatToBring : null,
|
||||
':suitable_for' => $suitableFor !== '' ? $suitableFor : null,
|
||||
':organizer_name' => $organizer !== '' ? $organizer : null,
|
||||
':starts_at' => $startsAt,
|
||||
':ends_at' => $endsAt,
|
||||
':address' => $address !== '' ? $address : null,
|
||||
':lat' => $lat,
|
||||
':lng' => $lng,
|
||||
':cost' => $cost,
|
||||
':currency' => $currency,
|
||||
':max_seats' => $maxSeats,
|
||||
':max_per_booking' => $maxPerBooking,
|
||||
':waitlist_enabled' => $waitlistEnabled,
|
||||
':reminder_enabled' => $reminderEnabled,
|
||||
':reminder_hours' => $reminderHours,
|
||||
':offer_expiry_hours' => $offerHours,
|
||||
':color' => $color,
|
||||
':cover_image' => $coverImage !== '' ? $coverImage : null,
|
||||
':gallery' => $gallery,
|
||||
':publish_at' => $publishAt,
|
||||
':status' => $status,
|
||||
];
|
||||
|
||||
$stmt = $pdo->prepare($sql);
|
||||
$stmt->execute($params);
|
||||
|
||||
header('Location: events.php?message=success');
|
||||
exit();
|
||||
} catch (Throwable $ex) {
|
||||
error_log('[event_save] ' . $ex->getMessage());
|
||||
header("Location: {$redirectOnError}");
|
||||
exit();
|
||||
}
|
||||
@@ -1,62 +0,0 @@
|
||||
<?php
|
||||
require_once('include/headscript.php');
|
||||
|
||||
/**
|
||||
* Upload copertina evento (chiamato in AJAX dalla dropzone di event_form.php).
|
||||
* Valida tipo/dimensione, salva in assets/uploads/events/ e ritorna JSON:
|
||||
* { ok:true, path:"assets/uploads/events/xxxx.jpg" } oppure { ok:false, error:"..." }
|
||||
*/
|
||||
if (function_exists('ob_get_level') && ob_get_level()) {
|
||||
ob_clean(); // pulisce eventuali whitespace dell'include prima del JSON
|
||||
}
|
||||
header('Content-Type: application/json; charset=utf-8');
|
||||
|
||||
$fail = function (string $msg): void {
|
||||
echo json_encode(['ok' => false, 'error' => $msg]);
|
||||
exit();
|
||||
};
|
||||
|
||||
if ($_SERVER['REQUEST_METHOD'] !== 'POST' || !isset($_FILES['cover'])) {
|
||||
$fail('Richiesta non valida.');
|
||||
}
|
||||
|
||||
$file = $_FILES['cover'];
|
||||
if ($file['error'] !== UPLOAD_ERR_OK) {
|
||||
$fail('Errore nel caricamento (codice ' . (int) $file['error'] . ').');
|
||||
}
|
||||
if ($file['size'] > 5 * 1024 * 1024) {
|
||||
$fail("L'immagine supera i 5 MB.");
|
||||
}
|
||||
|
||||
// Validazione MIME reale (non ci si fida dell'estensione)
|
||||
$allowed = ['image/jpeg' => 'jpg', 'image/png' => 'png', 'image/webp' => 'webp', 'image/gif' => 'gif'];
|
||||
$info = @getimagesize($file['tmp_name']);
|
||||
$mime = $info['mime'] ?? '';
|
||||
if (!isset($allowed[$mime])) {
|
||||
$fail('Formato non supportato. Usa JPG, PNG, WEBP o GIF.');
|
||||
}
|
||||
$ext = $allowed[$mime];
|
||||
|
||||
$relDir = 'assets/uploads/events';
|
||||
$absDir = __DIR__ . '/' . $relDir;
|
||||
if (!is_dir($absDir)) {
|
||||
@mkdir($absDir, 0775, true);
|
||||
}
|
||||
if (!is_dir($absDir) || !is_writable($absDir)) {
|
||||
$fail('Cartella non scrivibile: ' . $relDir . ' (crea la cartella e dai permessi di scrittura).');
|
||||
}
|
||||
|
||||
try {
|
||||
$rand = bin2hex(random_bytes(6));
|
||||
} catch (Throwable $e) {
|
||||
$rand = uniqid('', true);
|
||||
}
|
||||
$name = date('Ymd_His') . '_' . $rand . '.' . $ext;
|
||||
$dest = $absDir . '/' . $name;
|
||||
|
||||
if (!move_uploaded_file($file['tmp_name'], $dest)) {
|
||||
$fail('Impossibile salvare il file.');
|
||||
}
|
||||
|
||||
echo json_encode(['ok' => true, 'path' => $relDir . '/' . $name]);
|
||||
exit();
|
||||
@@ -1,59 +0,0 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Lista d'attesa — promozione automatica.
|
||||
*
|
||||
* IMPORTANTE: chiamare DENTRO una transazione in cui la riga dell'evento è già
|
||||
* bloccata (SELECT ... FOR UPDATE), tipicamente subito dopo aver liberato posti
|
||||
* (cancellazione di una prenotazione confermata). Così due operazioni simultanee
|
||||
* non promuovono oltre la capienza.
|
||||
*
|
||||
* Promuove in ordine di arrivo (FIFO) le prenotazioni 'waiting' che entrano nei
|
||||
* posti liberi e si ferma alla prima che non ci sta, per rispettare la coda
|
||||
* (non "salta" chi è davanti).
|
||||
*
|
||||
* @return array<int,array> le prenotazioni promosse (per inviare le email nello Step 4)
|
||||
*/
|
||||
if (!function_exists('promoteFromWaitlist')) {
|
||||
function promoteFromWaitlist(PDO $pdo, int $eventId): array
|
||||
{
|
||||
$ev = $pdo->prepare("SELECT max_seats FROM events WHERE id = ?");
|
||||
$ev->execute([$eventId]);
|
||||
$maxSeats = (int) $ev->fetchColumn();
|
||||
if ($maxSeats <= 0) {
|
||||
return [];
|
||||
}
|
||||
|
||||
$os = $pdo->prepare("SELECT COALESCE(SUM(seats),0) FROM event_bookings
|
||||
WHERE event_id = ? AND status IN ('confirmed','pending')");
|
||||
$os->execute([$eventId]);
|
||||
$free = $maxSeats - (int) $os->fetchColumn();
|
||||
if ($free <= 0) {
|
||||
return [];
|
||||
}
|
||||
|
||||
$ws = $pdo->prepare("SELECT * FROM event_bookings
|
||||
WHERE event_id = ? AND status = 'waiting'
|
||||
ORDER BY created_at ASC, id ASC");
|
||||
$ws->execute([$eventId]);
|
||||
$waiting = $ws->fetchAll(PDO::FETCH_ASSOC);
|
||||
|
||||
$promoted = [];
|
||||
$upd = $pdo->prepare("UPDATE event_bookings SET status = 'confirmed', updated_at = NOW() WHERE id = ?");
|
||||
foreach ($waiting as $w) {
|
||||
$need = (int) $w['seats'];
|
||||
if ($need <= $free) {
|
||||
$upd->execute([$w['id']]);
|
||||
$free -= $need;
|
||||
$w['status'] = 'confirmed';
|
||||
$promoted[] = $w;
|
||||
if ($free <= 0) {
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
break; // rispetta la coda
|
||||
}
|
||||
}
|
||||
return $promoted;
|
||||
}
|
||||
}
|
||||
@@ -1,523 +0,0 @@
|
||||
<?php
|
||||
require_once('include/headscript.php');
|
||||
|
||||
/**
|
||||
* Modulo Eventi - elenco lato insegnante (stile Amelia).
|
||||
* Mostra gli eventi raggruppati per data con posti prenotati, stato e azioni:
|
||||
* - Partecipanti -> event_participants.php
|
||||
* - Modifica -> event_form.php?id=
|
||||
* - Annulla -> modale (SweetAlert2) che chiede se inviare la mail di
|
||||
* annullamento a tutti i partecipanti, poi event_delete.php
|
||||
*/
|
||||
$pdo = DBHandlerSelect::getInstance()->getConnection();
|
||||
|
||||
function e($value): string
|
||||
{
|
||||
return htmlspecialchars((string) $value, ENT_QUOTES, 'UTF-8');
|
||||
}
|
||||
|
||||
$message = $_GET['message'] ?? '';
|
||||
|
||||
// Posti prenotati = SOMMA dei posti delle prenotazioni non annullate.
|
||||
$sql = "SELECT e.*,
|
||||
COALESCE(b.booked, 0) AS booked,
|
||||
COALESCE(b.bookings_count, 0) AS bookings_count,
|
||||
COALESCE(w.waiting, 0) AS waiting,
|
||||
u.first_name AS creator_first,
|
||||
u.last_name AS creator_last
|
||||
FROM events e
|
||||
LEFT JOIN (
|
||||
SELECT event_id,
|
||||
SUM(seats) AS booked,
|
||||
COUNT(*) AS bookings_count
|
||||
FROM event_bookings
|
||||
WHERE status IN ('confirmed','pending','offered')
|
||||
GROUP BY event_id
|
||||
) b ON b.event_id = e.id
|
||||
LEFT JOIN (
|
||||
SELECT event_id, SUM(seats) AS waiting
|
||||
FROM event_bookings
|
||||
WHERE status = 'waiting'
|
||||
GROUP BY event_id
|
||||
) w ON w.event_id = e.id
|
||||
LEFT JOIN auth_users u ON u.id = e.user_id
|
||||
ORDER BY e.starts_at ASC";
|
||||
$events = $pdo->query($sql)->fetchAll(PDO::FETCH_ASSOC);
|
||||
|
||||
$mesi = [
|
||||
1 => 'gennaio',
|
||||
2 => 'febbraio',
|
||||
3 => 'marzo',
|
||||
4 => 'aprile',
|
||||
5 => 'maggio',
|
||||
6 => 'giugno',
|
||||
7 => 'luglio',
|
||||
8 => 'agosto',
|
||||
9 => 'settembre',
|
||||
10 => 'ottobre',
|
||||
11 => 'novembre',
|
||||
12 => 'dicembre'
|
||||
];
|
||||
|
||||
function dataItaliana(string $dt, array $mesi): string
|
||||
{
|
||||
$t = strtotime($dt);
|
||||
return date('j', $t) . ' ' . $mesi[(int) date('n', $t)] . ' ' . date('Y', $t);
|
||||
}
|
||||
|
||||
/** @return array [label, bgColor, textColor] */
|
||||
function statusBadge(string $status): array
|
||||
{
|
||||
switch ($status) {
|
||||
case 'published':
|
||||
return ['Aperto', '#e7f7ee', '#1a7f52'];
|
||||
case 'scheduled':
|
||||
return ['Programmato', '#eef2fb', '#3a5bb8'];
|
||||
case 'cancelled':
|
||||
return ['Annullato', '#fdecea', '#c0392b'];
|
||||
default:
|
||||
return ['Bozza', '#eef0f3', '#6b7280'];
|
||||
}
|
||||
}
|
||||
?>
|
||||
<!doctype html>
|
||||
<html lang="it">
|
||||
|
||||
<head>
|
||||
<meta charset="utf-8" />
|
||||
<title>YogiBook - Eventi</title>
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<meta content="YogiBook - Prenotazione facile YogaSoul" name="description" />
|
||||
<link rel="shortcut icon" href="assets/images/favicon.ico">
|
||||
<link href="assets/css/bootstrap.min.css" id="bootstrap-style" rel="stylesheet" type="text/css" />
|
||||
<link href="assets/css/icons.min.css" rel="stylesheet" type="text/css" />
|
||||
<link href="assets/css/app.min.css" id="app-style" rel="stylesheet" type="text/css" />
|
||||
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.0.0-beta3/css/all.min.css">
|
||||
<script src="https://cdn.jsdelivr.net/npm/sweetalert2@11"></script>
|
||||
<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
|
||||
|
||||
<style>
|
||||
.admin-card {
|
||||
border: none;
|
||||
border-radius: 14px;
|
||||
box-shadow: 0 4px 20px rgba(0, 0, 0, 0.06);
|
||||
}
|
||||
|
||||
.admin-card .card-body {
|
||||
padding: 26px 30px;
|
||||
}
|
||||
|
||||
.section-title {
|
||||
font-size: 15px;
|
||||
font-weight: 700;
|
||||
letter-spacing: 0.04em;
|
||||
text-transform: uppercase;
|
||||
color: #6b7280;
|
||||
margin-bottom: 4px;
|
||||
}
|
||||
|
||||
.section-lead {
|
||||
color: #9ca3af;
|
||||
font-size: 14px;
|
||||
margin-bottom: 22px;
|
||||
}
|
||||
|
||||
.events-head {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
margin-bottom: 4px;
|
||||
}
|
||||
|
||||
.btn-new-event {
|
||||
background: #2f7be7;
|
||||
border: none;
|
||||
color: #fff;
|
||||
border-radius: 8px;
|
||||
padding: 9px 18px;
|
||||
font-weight: 600;
|
||||
font-size: 14px;
|
||||
white-space: nowrap;
|
||||
}
|
||||
|
||||
.btn-new-event:hover {
|
||||
filter: brightness(0.94);
|
||||
color: #fff;
|
||||
}
|
||||
|
||||
.events-table thead th {
|
||||
font-size: 12px;
|
||||
text-transform: uppercase;
|
||||
letter-spacing: 0.03em;
|
||||
color: #6b7280;
|
||||
border-bottom: 2px solid #eef0f3;
|
||||
white-space: nowrap;
|
||||
}
|
||||
|
||||
.events-table td {
|
||||
vertical-align: middle;
|
||||
}
|
||||
|
||||
.date-group td {
|
||||
background: #f7f8fa;
|
||||
font-weight: 600;
|
||||
color: #4b5563;
|
||||
font-size: 13px;
|
||||
text-transform: capitalize;
|
||||
}
|
||||
|
||||
.event-name {
|
||||
font-weight: 600;
|
||||
color: #1f2937;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 9px;
|
||||
}
|
||||
|
||||
.color-dot {
|
||||
display: inline-block;
|
||||
width: 12px;
|
||||
height: 12px;
|
||||
border-radius: 3px;
|
||||
flex-shrink: 0;
|
||||
}
|
||||
|
||||
.event-thumb {
|
||||
width: 42px;
|
||||
height: 42px;
|
||||
border-radius: 8px;
|
||||
object-fit: cover;
|
||||
flex-shrink: 0;
|
||||
}
|
||||
|
||||
.event-thumb.placeholder {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
font-size: 20px;
|
||||
}
|
||||
|
||||
.event-id {
|
||||
color: #9ca3af;
|
||||
font-weight: 400;
|
||||
font-size: 12px;
|
||||
}
|
||||
|
||||
.seats-pill {
|
||||
display: inline-block;
|
||||
background: #eef6f1;
|
||||
color: #1a7f52;
|
||||
font-weight: 700;
|
||||
font-size: 13px;
|
||||
padding: 2px 10px;
|
||||
border-radius: 20px;
|
||||
}
|
||||
|
||||
.seats-pill.full {
|
||||
background: #fdecea;
|
||||
color: #c0392b;
|
||||
}
|
||||
|
||||
.wait-pill {
|
||||
display: inline-block;
|
||||
background: #eef2fb;
|
||||
color: #3a5bb8;
|
||||
font-weight: 700;
|
||||
font-size: 12px;
|
||||
padding: 2px 9px;
|
||||
border-radius: 20px;
|
||||
margin-left: 6px;
|
||||
}
|
||||
|
||||
.id-chip {
|
||||
display: inline-block;
|
||||
background: #eef0f3;
|
||||
color: #4b5563;
|
||||
font-weight: 700;
|
||||
font-size: 11px;
|
||||
padding: 1px 8px;
|
||||
border-radius: 6px;
|
||||
margin-left: 6px;
|
||||
font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
|
||||
}
|
||||
|
||||
.status-badge {
|
||||
display: inline-block;
|
||||
font-size: 12px;
|
||||
font-weight: 700;
|
||||
padding: 3px 10px;
|
||||
border-radius: 20px;
|
||||
}
|
||||
|
||||
.btn-act {
|
||||
border: 1px solid #e2e4e9;
|
||||
background: #fff;
|
||||
border-radius: 8px;
|
||||
padding: 6px 12px;
|
||||
font-size: 13px;
|
||||
font-weight: 600;
|
||||
color: #374151;
|
||||
cursor: pointer;
|
||||
transition: background 0.15s, border-color 0.15s;
|
||||
white-space: nowrap;
|
||||
text-decoration: none;
|
||||
}
|
||||
|
||||
.btn-act:hover {
|
||||
background: #f3f4f6;
|
||||
color: #111827;
|
||||
}
|
||||
|
||||
.btn-act.danger {
|
||||
color: #c0392b;
|
||||
border-color: #f2c9c4;
|
||||
}
|
||||
|
||||
.btn-act.danger:hover {
|
||||
background: #fdecea;
|
||||
}
|
||||
|
||||
.empty-state {
|
||||
text-align: center;
|
||||
padding: 44px 10px;
|
||||
color: #9ca3af;
|
||||
}
|
||||
|
||||
.empty-state i {
|
||||
font-size: 34px;
|
||||
margin-bottom: 10px;
|
||||
display: block;
|
||||
color: #d5d9e0;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<div id="layout-wrapper">
|
||||
<header id="page-topbar" class="isvertical-topbar">
|
||||
<div class="navbar-header">
|
||||
<div class="d-flex">
|
||||
<?php include('include/logoarea.php'); ?>
|
||||
<button type="button" class="btn btn-sm px-3 font-size-24 header-item waves-effect vertical-menu-btn">
|
||||
<i class="bx bx-menu align-middle"></i>
|
||||
</button>
|
||||
<div class="page-title-box align-self-center d-none d-md-block">
|
||||
<h4 class="page-title mb-0">Eventi</h4>
|
||||
</div>
|
||||
</div>
|
||||
<div class="d-flex">
|
||||
<?php include('include/languageselection.php'); ?>
|
||||
<?php include('include/profiletopbar.php'); ?>
|
||||
</div>
|
||||
</div>
|
||||
</header>
|
||||
<?php include('include/sidebar.php'); ?>
|
||||
<header class="ishorizontal-topbar">
|
||||
<div class="navbar-header">
|
||||
<div class="d-flex"></div>
|
||||
</div>
|
||||
<div class="topnav">
|
||||
<div class="container-fluid">
|
||||
<nav class="navbar navbar-light navbar-expand-lg topnav-menu"></nav>
|
||||
</div>
|
||||
</div>
|
||||
</header>
|
||||
|
||||
<div class="main-content">
|
||||
<div class="page-content">
|
||||
<div class="container-fluid">
|
||||
|
||||
<?php if ($message === 'success') : ?>
|
||||
<div class="alert alert-success" role="alert">Evento salvato con successo.</div>
|
||||
<?php elseif ($message === 'cancelled') : ?>
|
||||
<div class="alert alert-warning" role="alert">Evento annullato.</div>
|
||||
<?php elseif ($message === 'error') : ?>
|
||||
<div class="alert alert-danger" role="alert">Si è verificato un errore. Controlla i dati e riprova.</div>
|
||||
<?php endif; ?>
|
||||
|
||||
<div class="row">
|
||||
<div class="col-12">
|
||||
<div class="card admin-card">
|
||||
<div class="card-body">
|
||||
<div class="events-head">
|
||||
<div>
|
||||
<div class="section-title">Eventi</div>
|
||||
<p class="section-lead mb-0">Ciao <?php echo e($firstname ?? ''); ?>, gestisci qui i tuoi eventi: crea, modifica, vedi i partecipanti o annulla.</p>
|
||||
</div>
|
||||
<a href="event_form.php" class="btn btn-new-event"><i class="bx bx-plus align-middle"></i> Nuovo evento</a>
|
||||
</div>
|
||||
|
||||
<div class="table-responsive mt-3">
|
||||
<table class="table events-table align-middle">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Orario</th>
|
||||
<th>Nome</th>
|
||||
<th>Organizzatore</th>
|
||||
<th>Prenotato</th>
|
||||
<th>Stato</th>
|
||||
<th class="text-end">Azioni</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<?php if (empty($events)) : ?>
|
||||
<tr>
|
||||
<td colspan="6">
|
||||
<div class="empty-state">
|
||||
<i class="fas fa-calendar-plus"></i>
|
||||
Nessun evento ancora. Crea il primo con "Nuovo evento".
|
||||
</div>
|
||||
</td>
|
||||
</tr>
|
||||
<?php else :
|
||||
$currentDate = null;
|
||||
foreach ($events as $ev) :
|
||||
$d = date('Y-m-d', strtotime($ev['starts_at']));
|
||||
if ($d !== $currentDate) :
|
||||
$currentDate = $d; ?>
|
||||
<tr class="date-group">
|
||||
<td colspan="6"><?php echo e(dataItaliana($ev['starts_at'], $mesi)); ?></td>
|
||||
</tr>
|
||||
<?php endif;
|
||||
|
||||
$organizer = trim((string) $ev['organizer_name']) !== ''
|
||||
? $ev['organizer_name']
|
||||
: trim(($ev['creator_first'] ?? '') . ' ' . ($ev['creator_last'] ?? ''));
|
||||
if ($organizer === '') {
|
||||
$organizer = '—';
|
||||
}
|
||||
|
||||
$booked = (int) $ev['booked'];
|
||||
$maxSeats = (int) $ev['max_seats'];
|
||||
$isFull = $maxSeats > 0 && $booked >= $maxSeats;
|
||||
[$stLabel, $stBg, $stColor] = statusBadge($ev['status']);
|
||||
|
||||
$timeLabel = date('H:i', strtotime($ev['starts_at']));
|
||||
if (!empty($ev['ends_at'])) {
|
||||
$timeLabel .= ' - ' . date('H:i', strtotime($ev['ends_at']));
|
||||
}
|
||||
?>
|
||||
<tr>
|
||||
<td><?php echo e($timeLabel); ?></td>
|
||||
<td>
|
||||
<div class="event-name">
|
||||
<?php if (!empty($ev['cover_image'])) : ?>
|
||||
<img class="event-thumb" src="<?php echo e($ev['cover_image']); ?>" alt="">
|
||||
<?php else : ?>
|
||||
<span class="event-thumb placeholder" style="background: <?php echo e($ev['color']); ?>22;"><i class="bx bx-image" style="color: <?php echo e($ev['color']); ?>;"></i></span>
|
||||
<?php endif; ?>
|
||||
<span class="color-dot" style="background: <?php echo e($ev['color']); ?>;"></span>
|
||||
<span><?php echo e($ev['title']); ?> <span class="id-chip">ID <?php echo (int) $ev['id']; ?></span></span>
|
||||
</div>
|
||||
</td>
|
||||
<td><?php echo e($organizer); ?></td>
|
||||
<td>
|
||||
<span class="seats-pill <?php echo $isFull ? 'full' : ''; ?>">
|
||||
<?php echo $booked; ?> / <?php echo $maxSeats; ?>
|
||||
</span>
|
||||
<?php if ((int) $ev['waiting'] > 0) : ?>
|
||||
<span class="wait-pill" title="In lista d'attesa">+<?php echo (int) $ev['waiting']; ?> in lista</span>
|
||||
<?php endif; ?>
|
||||
</td>
|
||||
<td>
|
||||
<span class="status-badge" style="background: <?php echo $stBg; ?>; color: <?php echo $stColor; ?>;"><?php echo e($stLabel); ?></span>
|
||||
</td>
|
||||
<td class="text-end">
|
||||
<button type="button" class="btn-act btn-shortcode" data-code='[yogasoul_eventi ids="<?php echo (int) $ev['id']; ?>"]'><i class="bx bx-code-alt"></i> Shortcode</button>
|
||||
<a href="event_preview.php?id=<?php echo (int) $ev['id']; ?>" target="_blank" class="btn-act"><i class="bx bx-show"></i> Anteprima</a>
|
||||
<a href="event_participants.php?id=<?php echo (int) $ev['id']; ?>" class="btn-act"><i class="bx bx-group"></i> Partecipanti</a>
|
||||
<a href="event_form.php?id=<?php echo (int) $ev['id']; ?>" class="btn-act"><i class="bx bx-edit"></i> Modifica</a>
|
||||
<?php if ($ev['status'] === 'published' && strtotime($ev['starts_at']) > time()) : ?>
|
||||
<a href="event_reminder.php?id=<?php echo (int) $ev['id']; ?>" class="btn-act"><i class="bx bx-bell"></i> Promemoria</a>
|
||||
<?php endif; ?>
|
||||
<?php if ($ev['status'] !== 'cancelled') : ?>
|
||||
<button type="button" class="btn-act danger btn-annulla"
|
||||
data-id="<?php echo (int) $ev['id']; ?>"
|
||||
data-title="<?php echo e($ev['title']); ?>"
|
||||
data-booked="<?php echo $booked; ?>">
|
||||
<i class="bx bx-block"></i> Annulla
|
||||
</button>
|
||||
<?php endif; ?>
|
||||
</td>
|
||||
</tr>
|
||||
<?php endforeach; ?>
|
||||
<?php endif; ?>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
<?php include('include/footer.php'); ?>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<script src="assets/libs/bootstrap/js/bootstrap.bundle.min.js"></script>
|
||||
<script src="assets/libs/metismenujs/metismenujs.min.js"></script>
|
||||
<script src="assets/libs/simplebar/simplebar.min.js"></script>
|
||||
<script src="assets/libs/eva-icons/eva.min.js"></script>
|
||||
<script src="assets/js/app.js"></script>
|
||||
|
||||
<script>
|
||||
$(document).ready(function() {
|
||||
// Copia shortcode
|
||||
$('.btn-shortcode').on('click', function() {
|
||||
var code = $(this).data('code');
|
||||
var btn = $(this);
|
||||
var original = btn.html();
|
||||
|
||||
function done() {
|
||||
btn.html('<i class="bx bx-check"></i> Copiato!');
|
||||
setTimeout(function() {
|
||||
btn.html(original);
|
||||
}, 1500);
|
||||
}
|
||||
if (navigator.clipboard && navigator.clipboard.writeText) {
|
||||
navigator.clipboard.writeText(code).then(done).catch(function() {
|
||||
window.prompt('Copia lo shortcode:', code);
|
||||
});
|
||||
} else {
|
||||
window.prompt('Copia lo shortcode:', code);
|
||||
}
|
||||
});
|
||||
|
||||
$('.btn-annulla').on('click', function() {
|
||||
var id = $(this).data('id');
|
||||
var title = $(this).data('title');
|
||||
var booked = parseInt($(this).data('booked'), 10) || 0;
|
||||
|
||||
Swal.fire({
|
||||
title: "Annullare l'evento?",
|
||||
html: '<p style="margin-bottom:12px;">Stai per annullare <strong>' + $('<div>').text(title).html() + '</strong>.</p>' +
|
||||
'<div style="text-align:left; background:#f7f8fa; border-radius:8px; padding:12px;">' +
|
||||
' <label style="display:flex; align-items:flex-start; gap:8px; cursor:pointer; margin:0;">' +
|
||||
' <input type="checkbox" id="notify-check" ' + (booked > 0 ? 'checked' : '') + '>' +
|
||||
' <span>Invia email di annullamento ai partecipanti' +
|
||||
(booked > 0 ? ' <strong>(' + booked + ' post' + (booked === 1 ? 'o' : 'i') + ' prenotat' + (booked === 1 ? 'o' : 'i') + ')</strong>' : ' <em>(nessun iscritto)</em>') +
|
||||
'</span>' +
|
||||
' </label>' +
|
||||
'</div>',
|
||||
icon: 'warning',
|
||||
showCancelButton: true,
|
||||
confirmButtonText: 'Annulla evento',
|
||||
cancelButtonText: 'Chiudi',
|
||||
confirmButtonColor: '#e74c3c',
|
||||
reverseButtons: true,
|
||||
preConfirm: function() {
|
||||
return document.getElementById('notify-check').checked ? 1 : 0;
|
||||
}
|
||||
}).then(function(result) {
|
||||
if (result.isConfirmed) {
|
||||
window.location.href = 'event_delete.php?id=' + id + '¬ify=' + result.value;
|
||||
}
|
||||
});
|
||||
});
|
||||
});
|
||||
</script>
|
||||
</body>
|
||||
|
||||
</html>
|
||||
@@ -1,101 +0,0 @@
|
||||
<?php
|
||||
// Bufferizziamo da subito così la risposta resta JSON puro
|
||||
// (headscript.php può emettere HTML).
|
||||
ob_start();
|
||||
|
||||
require_once('include/headscript.php');
|
||||
|
||||
/**
|
||||
* get_user_orders.php
|
||||
* --------------------------------------------------------------------------
|
||||
* Restituisce gli ordini ATTIVI (non scaduti) di un utente, con il numero
|
||||
* di ticket residui, per popolare il modale "Aggiungi partecipante"
|
||||
* nell'adminpanel.
|
||||
*
|
||||
* Pattern: webapp (sessione + PDO), come searchemail.php.
|
||||
* Metodo: GET o POST
|
||||
* Param: userid (int)
|
||||
*
|
||||
* Residui = nticket - (prenotazioni non cancellate e NON omaggio)
|
||||
* -> is_gift = 'N' esclude gli omaggi dal consumo.
|
||||
* --------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
$pdo = DBHandlerSelect::getInstance()->getConnection();
|
||||
|
||||
function jsonOut(array $payload): void
|
||||
{
|
||||
if (ob_get_length() !== false) {
|
||||
ob_end_clean();
|
||||
}
|
||||
header('Content-Type: application/json; charset=utf-8');
|
||||
echo json_encode($payload, JSON_UNESCAPED_UNICODE);
|
||||
exit;
|
||||
}
|
||||
|
||||
$userid = isset($_REQUEST['userid']) ? (int) $_REQUEST['userid'] : 0;
|
||||
|
||||
if ($userid <= 0) {
|
||||
jsonOut(['error' => 'Utente non valido', 'orders' => []]);
|
||||
}
|
||||
|
||||
try {
|
||||
$today = date('Y-m-d');
|
||||
|
||||
// Ordini dell'utente NON scaduti
|
||||
$sql = "SELECT ob.idorderbook, ob.idservice, ob.nticket, ob.quantityclass,
|
||||
ob.expireon, ob.maxreschedule, ob.reprogrammed,
|
||||
s.servicename
|
||||
FROM orderbook ob
|
||||
LEFT JOIN service s ON ob.idservice = s.idservice
|
||||
WHERE ob.iduser = :uid
|
||||
AND (ob.expireon IS NULL OR ob.expireon >= :today)
|
||||
ORDER BY ob.idorderbook DESC";
|
||||
$stmt = $pdo->prepare($sql);
|
||||
$stmt->execute([':uid' => $userid, ':today' => $today]);
|
||||
$rows = $stmt->fetchAll();
|
||||
|
||||
// Prepared per contare le prenotazioni che consumano ticket
|
||||
// (non cancellate e non omaggio)
|
||||
$usedStmt = $pdo->prepare(
|
||||
"SELECT COUNT(*) AS n
|
||||
FROM bookingclass
|
||||
WHERE idorder = :oid
|
||||
AND status != 'cancelled'
|
||||
AND is_gift = 'N'"
|
||||
);
|
||||
|
||||
$orders = [];
|
||||
foreach ($rows as $o) {
|
||||
$orderId = (int) $o['idorderbook'];
|
||||
|
||||
// tickets totali: quantityclass se valorizzato, altrimenti nticket
|
||||
$tickets = (int) (($o['quantityclass'] !== null && $o['quantityclass'] !== '')
|
||||
? $o['quantityclass']
|
||||
: ($o['nticket'] ?? 0));
|
||||
|
||||
$usedStmt->execute([':oid' => $orderId]);
|
||||
$used = (int) ($usedStmt->fetch()['n'] ?? 0);
|
||||
|
||||
$remaining = $tickets - $used;
|
||||
if ($remaining < 0) {
|
||||
$remaining = 0;
|
||||
}
|
||||
|
||||
$orders[] = [
|
||||
'idorderbook' => $orderId,
|
||||
'service_name' => (string) ($o['servicename'] ?? ''),
|
||||
'tickets' => $tickets,
|
||||
'used' => $used,
|
||||
'remaining' => $remaining,
|
||||
'expireon' => $o['expireon'] ?? null,
|
||||
'maxreschedule' => (int) ($o['maxreschedule'] ?? 0),
|
||||
'reprogrammed' => (int) ($o['reprogrammed'] ?? 0),
|
||||
];
|
||||
}
|
||||
|
||||
jsonOut(['orders' => $orders]);
|
||||
} catch (Throwable $ex) {
|
||||
error_log('get_user_orders error: ' . $ex->getMessage());
|
||||
jsonOut(['error' => 'Errore durante il recupero degli ordini.', 'orders' => []]);
|
||||
}
|
||||
@@ -1,299 +0,0 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Motore email del modulo Eventi (PHPMailer, legge le MAIL_* dal .env).
|
||||
*
|
||||
* Requisito una tantum: composer require phpmailer/phpmailer
|
||||
*
|
||||
* Builder per i 5 tipi:
|
||||
* A) yse_mail_booking() prenotazione (confermata o lista d'attesa)
|
||||
* B) yse_mail_user_cancel() disdetta fatta dall'utente
|
||||
* C) yse_mail_event_cancel() evento annullato dall'insegnante (a ciascun iscritto)
|
||||
* E) yse_mail_promotion() promozione da lista d'attesa (con RICONFERMA)
|
||||
* D) yse_mail_reminder() promemoria prima dell'evento
|
||||
*
|
||||
* Le copie alla scuola (CC) sono decise per-tipo dalla pagina "Opzioni Eventi".
|
||||
* L'indirizzo di copia è option.event_notify_email.
|
||||
*/
|
||||
|
||||
// Assicura l'autoload (di norma già caricato da db-functions.php)
|
||||
if (!class_exists('PHPMailer\\PHPMailer\\PHPMailer')) {
|
||||
$__al = dirname(__DIR__, 2) . '/vendor/autoload.php';
|
||||
if (is_file($__al)) {
|
||||
require_once $__al;
|
||||
}
|
||||
}
|
||||
|
||||
if (!defined('YB_PUBLIC_BASE')) {
|
||||
define('YB_PUBLIC_BASE', 'https://yogibook.yogasoul.it/');
|
||||
}
|
||||
|
||||
/* ---------- Opzioni ---------- */
|
||||
function yse_mail_options(): array
|
||||
{
|
||||
static $opt = null;
|
||||
if ($opt !== null) {
|
||||
return $opt;
|
||||
}
|
||||
$row = [];
|
||||
try {
|
||||
$pdo = DBHandlerSelect::getInstance()->getConnection();
|
||||
$row = $pdo->query("SELECT * FROM `option` LIMIT 1")->fetch(PDO::FETCH_ASSOC) ?: [];
|
||||
} catch (Throwable $e) {
|
||||
$row = [];
|
||||
}
|
||||
$opt = [
|
||||
'cc_email' => trim((string) ($row['event_notify_email'] ?? '')),
|
||||
'cc' => [
|
||||
'booking' => ($row['event_cc_booking'] ?? 'N') === 'Y',
|
||||
'user_cancel' => ($row['event_cc_user_cancel'] ?? 'N') === 'Y',
|
||||
'event_cancel' => ($row['event_cc_event_cancel'] ?? 'N') === 'Y',
|
||||
'reminder' => ($row['event_cc_reminder'] ?? 'N') === 'Y',
|
||||
'promotion' => ($row['event_cc_promotion'] ?? 'N') === 'Y',
|
||||
],
|
||||
];
|
||||
return $opt;
|
||||
}
|
||||
|
||||
/* ---------- Invio base ---------- */
|
||||
function yse_send(string $to, string $toName, string $subject, string $html, bool $ccSchool): bool
|
||||
{
|
||||
$env = $_ENV;
|
||||
try {
|
||||
$mail = new \PHPMailer\PHPMailer\PHPMailer(true);
|
||||
$mail->isSMTP();
|
||||
$mail->Host = $env['MAIL_HOST'] ?? '';
|
||||
$mail->SMTPAuth = true;
|
||||
$mail->Username = $env['MAIL_USERNAME'] ?? '';
|
||||
$mail->Password = $env['MAIL_PASSWORD'] ?? '';
|
||||
$enc = strtolower($env['MAIL_ENCRYPTION'] ?? 'ssl');
|
||||
$mail->SMTPSecure = ($enc === 'tls')
|
||||
? \PHPMailer\PHPMailer\PHPMailer::ENCRYPTION_STARTTLS
|
||||
: \PHPMailer\PHPMailer\PHPMailer::ENCRYPTION_SMTPS;
|
||||
$mail->Port = (int) ($env['MAIL_PORT'] ?? 465);
|
||||
$mail->CharSet = 'UTF-8';
|
||||
|
||||
$mail->setFrom($env['MAIL_FROM_ADDRESS'] ?? 'info@yogasoul.it', $env['MAIL_FROM_NAME'] ?? 'YogiBook');
|
||||
$mail->addAddress($to, $toName);
|
||||
|
||||
if ($ccSchool) {
|
||||
$ccEmail = yse_mail_options()['cc_email'];
|
||||
if ($ccEmail !== '' && strcasecmp($ccEmail, $to) !== 0) {
|
||||
$mail->addCC($ccEmail);
|
||||
}
|
||||
}
|
||||
|
||||
$mail->isHTML(true);
|
||||
$mail->Subject = $subject;
|
||||
$mail->Body = $html;
|
||||
$mail->AltBody = trim(preg_replace(
|
||||
'/\n{3,}/',
|
||||
"\n\n",
|
||||
strip_tags(str_replace(['</p>', '<br>', '<br/>', '<br />', '</div>'], "\n", $html))
|
||||
));
|
||||
|
||||
return $mail->send();
|
||||
} catch (Throwable $e) {
|
||||
error_log('[event mail] ' . $e->getMessage());
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/* ---------- Helper contenuto ---------- */
|
||||
function yse_h($v): string
|
||||
{
|
||||
return htmlspecialchars((string) $v, ENT_QUOTES, 'UTF-8');
|
||||
}
|
||||
|
||||
function yse_fmt_datetime(array $event): string
|
||||
{
|
||||
$mesi = [
|
||||
1 => 'gennaio',
|
||||
2 => 'febbraio',
|
||||
3 => 'marzo',
|
||||
4 => 'aprile',
|
||||
5 => 'maggio',
|
||||
6 => 'giugno',
|
||||
7 => 'luglio',
|
||||
8 => 'agosto',
|
||||
9 => 'settembre',
|
||||
10 => 'ottobre',
|
||||
11 => 'novembre',
|
||||
12 => 'dicembre'
|
||||
];
|
||||
$t = strtotime($event['starts_at']);
|
||||
$s = (int) date('j', $t) . ' ' . $mesi[(int) date('n', $t)] . ' ' . date('Y', $t) . ' · ' . date('H:i', $t);
|
||||
if (!empty($event['ends_at'])) {
|
||||
$s .= '–' . date('H:i', strtotime($event['ends_at']));
|
||||
}
|
||||
return $s;
|
||||
}
|
||||
|
||||
function yse_maps_link(array $event): string
|
||||
{
|
||||
$q = trim((string) ($event['address'] ?? ''));
|
||||
if ($q === '' && !empty($event['lat']) && !empty($event['lng'])) {
|
||||
$q = $event['lat'] . ',' . $event['lng'];
|
||||
}
|
||||
return $q !== '' ? 'https://www.google.com/maps/search/?api=1&query=' . rawurlencode($q) : '';
|
||||
}
|
||||
|
||||
function yse_event_info_block(array $event): string
|
||||
{
|
||||
$accent = (isset($event['color']) && preg_match('/^#[0-9a-fA-F]{6}$/', $event['color'])) ? $event['color'] : '#4CAF50';
|
||||
$when = yse_h(yse_fmt_datetime($event));
|
||||
$addr = trim((string) ($event['address'] ?? ''));
|
||||
$maps = yse_maps_link($event);
|
||||
|
||||
$rows = '<tr><td style="padding:6px 0;color:#8c837c;width:90px;">Quando</td><td style="padding:6px 0;color:#2b2622;font-weight:600;">' . $when . '</td></tr>';
|
||||
if ($addr !== '') {
|
||||
$mapsLink = $maps !== '' ? ' <a href="' . yse_h($maps) . '" style="color:' . $accent . ';">apri mappa</a>' : '';
|
||||
$rows .= '<tr><td style="padding:6px 0;color:#8c837c;">Dove</td><td style="padding:6px 0;color:#2b2622;font-weight:600;">' . yse_h($addr) . $mapsLink . '</td></tr>';
|
||||
}
|
||||
|
||||
$info = '';
|
||||
foreach ([['suitable_for', 'Per chi è adatto'], ['what_to_bring', 'Cosa portare'], ['instructions', 'Istruzioni']] as $f) {
|
||||
$val = trim((string) ($event[$f[0]] ?? ''));
|
||||
if ($val !== '') {
|
||||
$info .= '<p style="margin:10px 0 0;"><strong style="color:#2b2622;">' . $f[1] . ':</strong><br>' . nl2br(yse_h($val)) . '</p>';
|
||||
}
|
||||
}
|
||||
|
||||
$html = '<table role="presentation" width="100%" cellpadding="0" cellspacing="0" style="font-size:14px;border-collapse:collapse;margin:10px 0;">' . $rows . '</table>';
|
||||
if ($info !== '') {
|
||||
$html .= '<div style="background:#faf8f6;border-radius:10px;padding:12px 14px;font-size:14px;color:#4a433d;">' . $info . '</div>';
|
||||
}
|
||||
return $html;
|
||||
}
|
||||
|
||||
function yse_email_layout(array $event, string $heading, string $bodyHtml): string
|
||||
{
|
||||
$accent = (isset($event['color']) && preg_match('/^#[0-9a-fA-F]{6}$/', $event['color'])) ? $event['color'] : '#4CAF50';
|
||||
$from = $_ENV['MAIL_FROM_NAME'] ?? 'YogaSoul';
|
||||
$title = yse_h($event['title'] ?? '');
|
||||
return '
|
||||
<div style="background:#f2efec;padding:24px 0;font-family:Arial,Helvetica,sans-serif;">
|
||||
<table role="presentation" width="100%" cellpadding="0" cellspacing="0"><tr><td align="center">
|
||||
<table role="presentation" width="600" cellpadding="0" cellspacing="0" style="max-width:600px;width:100%;background:#fff;border-radius:16px;overflow:hidden;">
|
||||
<tr><td style="background:' . $accent . ';height:6px;"></td></tr>
|
||||
<tr><td style="padding:28px 30px 6px;">
|
||||
<div style="font-size:13px;letter-spacing:.05em;text-transform:uppercase;color:#8c837c;">' . yse_h($from) . '</div>
|
||||
<h1 style="margin:6px 0 2px;font-size:22px;color:#2b2622;">' . $heading . '</h1>
|
||||
<div style="font-size:17px;color:' . $accent . ';font-weight:600;">' . $title . '</div>
|
||||
</td></tr>
|
||||
<tr><td style="padding:10px 30px 26px;color:#4a433d;font-size:15px;line-height:1.6;">' . $bodyHtml . '</td></tr>
|
||||
<tr><td style="padding:16px 30px;background:#faf8f6;color:#9ca3af;font-size:12px;">Questa email è stata inviata da ' . yse_h($from) . '.</td></tr>
|
||||
</table>
|
||||
</td></tr></table>
|
||||
</div>';
|
||||
}
|
||||
|
||||
function yse_button(string $url, string $label, string $accent): string
|
||||
{
|
||||
return '<a href="' . yse_h($url) . '" style="display:inline-block;background:' . $accent . ';color:#fff;text-decoration:none;font-weight:600;padding:12px 22px;border-radius:10px;">' . yse_h($label) . '</a>';
|
||||
}
|
||||
|
||||
function yse_cancel_url(array $booking): string
|
||||
{
|
||||
return YB_PUBLIC_BASE . 'apiwp/cancel.php?token=' . rawurlencode($booking['token']);
|
||||
}
|
||||
|
||||
function yse_confirm_url(array $booking): string
|
||||
{
|
||||
return YB_PUBLIC_BASE . 'apiwp/confirm.php?token=' . rawurlencode($booking['token']);
|
||||
}
|
||||
|
||||
/* ---------- Builder per tipo ---------- */
|
||||
|
||||
/** A) Prenotazione (confermata o lista d'attesa) */
|
||||
function yse_mail_booking(array $booking, array $event): bool
|
||||
{
|
||||
$accent = $event['color'] ?? '#4CAF50';
|
||||
$waiting = ($booking['status'] ?? '') === 'waiting';
|
||||
$parts = explode(' ', trim($booking['name']));
|
||||
$name = $parts[0] ?? '';
|
||||
|
||||
if ($waiting) {
|
||||
$heading = "Sei in lista d'attesa";
|
||||
$intro = '<p>Ciao ' . yse_h($name) . ", ti abbiamo messo in lista d'attesa per questo evento. Ti avviseremo appena si libera un posto.</p>";
|
||||
} else {
|
||||
$heading = 'Prenotazione confermata';
|
||||
$intro = '<p>Ciao ' . yse_h($name) . ', la tua prenotazione è confermata. Ecco i dettagli:</p>';
|
||||
}
|
||||
|
||||
$body = $intro;
|
||||
$body .= yse_event_info_block($event);
|
||||
$body .= '<p style="margin-top:8px;">Posti prenotati: <strong>' . (int) $booking['seats'] . '</strong></p>';
|
||||
$body .= '<p style="margin:22px 0 6px;">Se non puoi più partecipare, puoi annullare qui:</p>';
|
||||
$body .= '<p>' . yse_button(yse_cancel_url($booking), 'Annulla prenotazione', $accent) . '</p>';
|
||||
|
||||
$subject = ($waiting ? "Lista d'attesa: " : 'Prenotazione confermata: ') . $event['title'];
|
||||
$html = yse_email_layout($event, $heading, $body);
|
||||
return yse_send($booking['email'], $booking['name'], $subject, $html, yse_mail_options()['cc']['booking']);
|
||||
}
|
||||
|
||||
/** B) Disdetta fatta dall'utente */
|
||||
function yse_mail_user_cancel(array $booking, array $event): bool
|
||||
{
|
||||
$parts = explode(' ', trim($booking['name']));
|
||||
$name = $parts[0] ?? '';
|
||||
$body = '<p>Ciao ' . yse_h($name) . ', la tua prenotazione per questo evento è stata <strong>annullata</strong>.</p>';
|
||||
$body .= yse_event_info_block($event);
|
||||
$body .= '<p style="margin-top:14px;">Ci dispiace non vederti questa volta. A presto!</p>';
|
||||
|
||||
$subject = 'Prenotazione annullata: ' . $event['title'];
|
||||
$html = yse_email_layout($event, 'Prenotazione annullata', $body);
|
||||
return yse_send($booking['email'], $booking['name'], $subject, $html, yse_mail_options()['cc']['user_cancel']);
|
||||
}
|
||||
|
||||
/** C) Evento annullato dall'insegnante (a ciascun iscritto) */
|
||||
function yse_mail_event_cancel(array $booking, array $event): bool
|
||||
{
|
||||
$parts = explode(' ', trim($booking['name']));
|
||||
$name = $parts[0] ?? '';
|
||||
$body = '<p>Ciao ' . yse_h($name) . ", ci dispiace: l'evento è stato <strong>annullato</strong>.</p>";
|
||||
$body .= yse_event_info_block($event);
|
||||
$body .= '<p style="margin-top:14px;">La tua prenotazione è stata annullata automaticamente. Per informazioni, rispondi pure a questa email.</p>';
|
||||
|
||||
$subject = 'Evento annullato: ' . $event['title'];
|
||||
$html = yse_email_layout($event, 'Evento annullato', $body);
|
||||
return yse_send($booking['email'], $booking['name'], $subject, $html, yse_mail_options()['cc']['event_cancel']);
|
||||
}
|
||||
|
||||
/** E) Promozione da lista d'attesa — con RICONFERMA */
|
||||
function yse_mail_promotion(array $booking, array $event): bool
|
||||
{
|
||||
$accent = $event['color'] ?? '#4CAF50';
|
||||
$parts = explode(' ', trim($booking['name']));
|
||||
$name = $parts[0] ?? '';
|
||||
$body = '<p>Ciao ' . yse_h($name) . ", buone notizie: si è liberato un posto e tocca a te!</p>";
|
||||
$body .= yse_event_info_block($event);
|
||||
$body .= '<p style="margin:22px 0 6px;"><strong>Conferma entro breve</strong> per tenere il posto:</p>';
|
||||
$body .= '<p>' . yse_button(yse_confirm_url($booking), 'Confermo, ci sarò', $accent) . '</p>';
|
||||
$body .= '<p style="margin-top:16px;font-size:13px;color:#8c837c;">Se non puoi partecipare, <a href="' . yse_h(yse_cancel_url($booking)) . '" style="color:' . $accent . ';">annulla qui</a> così offriamo il posto a un\'altra persona.</p>';
|
||||
|
||||
$subject = 'Si è liberato un posto: ' . $event['title'];
|
||||
$html = yse_email_layout($event, 'Un posto per te', $body);
|
||||
return yse_send($booking['email'], $booking['name'], $subject, $html, yse_mail_options()['cc']['promotion']);
|
||||
}
|
||||
|
||||
/** D) Promemoria prima dell'evento (testo e punto di ritrovo opzionali) */
|
||||
function yse_mail_reminder(array $booking, array $event, string $message = '', string $meetingLink = ''): bool
|
||||
{
|
||||
$accent = $event['color'] ?? '#4CAF50';
|
||||
$parts = explode(' ', trim($booking['name']));
|
||||
$name = $parts[0] ?? '';
|
||||
$note = $message !== '' ? nl2br(yse_h($message)) : 'Ti ricordiamo il tuo prossimo appuntamento.';
|
||||
|
||||
$body = '<p>Ciao ' . yse_h($name) . ',<br>' . $note . '</p>';
|
||||
$body .= yse_event_info_block($event);
|
||||
if ($meetingLink !== '') {
|
||||
$body .= '<p style="margin:16px 0 6px;"><strong>Punto di ritrovo:</strong> <a href="' . yse_h($meetingLink) . '" style="color:' . $accent . ';">apri la posizione sulla mappa</a></p>';
|
||||
}
|
||||
$body .= '<p style="margin:22px 0 6px;">Se non puoi più partecipare, avvisaci annullando:</p>';
|
||||
$body .= '<p>' . yse_button(yse_cancel_url($booking), 'Annulla prenotazione', $accent) . '</p>';
|
||||
|
||||
$subject = 'Promemoria: ' . $event['title'];
|
||||
$html = yse_email_layout($event, 'Ci vediamo presto', $body);
|
||||
return yse_send($booking['email'], $booking['name'], $subject, $html, yse_mail_options()['cc']['reminder']);
|
||||
}
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user