459 lines
19 KiB
PHP
459 lines
19 KiB
PHP
<?php
|
|
require_once('include/headscript.php');
|
|
|
|
/**
|
|
* Connessione unica PDO (singleton). $iduserlogin dalla sessione autenticata.
|
|
*/
|
|
$pdo = DBHandlerSelect::getInstance()->getConnection();
|
|
$iduserlogin = (int) $iduserlogin;
|
|
|
|
function e($value): string
|
|
{
|
|
return htmlspecialchars((string) $value, ENT_QUOTES, 'UTF-8');
|
|
}
|
|
|
|
$uploadFeedback = null; // ['type' => 'success'|'error', 'text' => '...']
|
|
|
|
/* -------------------------------------------------------------------------
|
|
* Upload certificato (POST) con validazione robusta
|
|
* ---------------------------------------------------------------------- */
|
|
$allowedExt = ['pdf', 'jpg', 'jpeg', 'png'];
|
|
$allowedMime = ['application/pdf', 'image/jpeg', 'image/png'];
|
|
$maxBytes = 16 * 1024 * 1024; // 16 MB
|
|
$uploadDir = 'user/document/';
|
|
|
|
if (
|
|
$_SERVER['REQUEST_METHOD'] === 'POST'
|
|
&& isset($_FILES['fileToUpload'])
|
|
&& $_FILES['fileToUpload']['error'] === UPLOAD_ERR_OK
|
|
) {
|
|
|
|
$file = $_FILES['fileToUpload'];
|
|
$documentDescription = trim($_POST['documentDescription'] ?? '');
|
|
$expiryDate = trim($_POST['expiryDate'] ?? '');
|
|
|
|
if ($documentDescription === '' || $expiryDate === '') {
|
|
$uploadFeedback = ['type' => 'error', 'text' => 'Descrizione e data di scadenza sono obbligatorie.'];
|
|
} elseif ($file['size'] > $maxBytes) {
|
|
$uploadFeedback = ['type' => 'error', 'text' => 'Il file supera la dimensione massima di 16 MB.'];
|
|
} else {
|
|
$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)) {
|
|
$uploadFeedback = ['type' => 'error', 'text' => 'Formato non consentito. Carica un PDF, JPG o PNG.'];
|
|
} else {
|
|
$safeName = bin2hex(random_bytes(16)) . '.' . $ext;
|
|
$destination = $uploadDir . $safeName;
|
|
|
|
if (!is_dir($uploadDir)) {
|
|
@mkdir($uploadDir, 0755, true);
|
|
}
|
|
|
|
if (move_uploaded_file($file['tmp_name'], $destination)) {
|
|
$sql = "INSERT INTO certificateuserprofile
|
|
(iduser, documentdescription, filenamedocument, expirydatedocument, uploaded_at)
|
|
VALUES (:iduser, :descr, :fname, :expiry, :uploaded)";
|
|
$stmt = $pdo->prepare($sql);
|
|
$ok = $stmt->execute([
|
|
':iduser' => $iduserlogin,
|
|
':descr' => $documentDescription,
|
|
':fname' => $safeName,
|
|
':expiry' => $expiryDate,
|
|
':uploaded' => date('Y-m-d'),
|
|
]);
|
|
|
|
$uploadFeedback = $ok
|
|
? ['type' => 'success', 'text' => 'Documento caricato correttamente.']
|
|
: ['type' => 'error', 'text' => 'Errore nel salvataggio del documento. Riprova.'];
|
|
} else {
|
|
$uploadFeedback = ['type' => 'error', 'text' => 'Caricamento del file non riuscito. Riprova.'];
|
|
}
|
|
}
|
|
}
|
|
} elseif (
|
|
$_SERVER['REQUEST_METHOD'] === 'POST'
|
|
&& isset($_FILES['fileToUpload'])
|
|
&& $_FILES['fileToUpload']['error'] !== UPLOAD_ERR_NO_FILE
|
|
) {
|
|
$uploadFeedback = ['type' => 'error', 'text' => 'Si è verificato un problema durante il caricamento. Riprova.'];
|
|
}
|
|
|
|
/* -------------------------------------------------------------------------
|
|
* Elenco documenti dell'utente
|
|
* ---------------------------------------------------------------------- */
|
|
$stmtDocs = $pdo->prepare("SELECT * FROM certificateuserprofile WHERE iduser = :iduser ORDER BY uploaded_at DESC");
|
|
$stmtDocs->execute([':iduser' => $iduserlogin]);
|
|
$documents = $stmtDocs->fetchAll();
|
|
?>
|
|
<!doctype html>
|
|
<html lang="it">
|
|
|
|
<head>
|
|
<meta charset="utf-8" />
|
|
<title>YogiBook - Carica Certificati</title>
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
<meta content="YogiBook - Prenotazione facile YogaSoul" name="description" />
|
|
<meta content="Advanced Creative Solutions" name="author" />
|
|
<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@10"></script>
|
|
<link rel="stylesheet" href="https://code.jquery.com/ui/1.12.1/themes/base/jquery-ui.css">
|
|
<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
|
|
<script src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"></script>
|
|
|
|
<script>
|
|
$(function() {
|
|
$("#expiryDate").datepicker({
|
|
dateFormat: "yy-mm-dd",
|
|
changeYear: true,
|
|
changeMonth: true,
|
|
minDate: 0
|
|
});
|
|
});
|
|
|
|
function confirmDeleteCertificate(id) {
|
|
Swal.fire({
|
|
title: "Sei sicuro?",
|
|
text: "Questo certificato verrà cancellato definitivamente.",
|
|
icon: "warning",
|
|
showCancelButton: true,
|
|
confirmButtonColor: "#d33",
|
|
cancelButtonColor: "#3085d6",
|
|
confirmButtonText: "Sì, cancella",
|
|
cancelButtonText: "Annulla"
|
|
}).then((result) => {
|
|
if (result.isConfirmed) {
|
|
window.location.href = `deletecertificate.php?id=${id}&source=user`;
|
|
}
|
|
});
|
|
}
|
|
|
|
function handleFileChange(input) {
|
|
var label = document.getElementById('fileChosenLabel');
|
|
if (!input.files.length) {
|
|
label.textContent = 'Nessun file selezionato';
|
|
return;
|
|
}
|
|
var f = input.files[0];
|
|
var allowed = ['application/pdf', 'image/jpeg', 'image/png'];
|
|
var maxBytes = 16 * 1024 * 1024;
|
|
if (allowed.indexOf(f.type) === -1) {
|
|
label.textContent = 'Formato non valido: usa PDF, JPG o PNG';
|
|
label.style.color = '#dc3545';
|
|
input.value = '';
|
|
return;
|
|
}
|
|
if (f.size > maxBytes) {
|
|
label.textContent = 'File troppo grande (max 16 MB)';
|
|
label.style.color = '#dc3545';
|
|
input.value = '';
|
|
return;
|
|
}
|
|
label.textContent = f.name;
|
|
label.style.color = '#198754';
|
|
}
|
|
</script>
|
|
|
|
<style>
|
|
.cert-card {
|
|
border: none;
|
|
border-radius: 14px;
|
|
box-shadow: 0 4px 20px rgba(0, 0, 0, 0.06);
|
|
}
|
|
|
|
.cert-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;
|
|
}
|
|
|
|
.cert-table {
|
|
margin-bottom: 0;
|
|
}
|
|
|
|
.cert-table thead th {
|
|
font-size: 12px;
|
|
text-transform: uppercase;
|
|
letter-spacing: 0.03em;
|
|
color: #6b7280;
|
|
border-bottom: 2px solid #eef0f3;
|
|
}
|
|
|
|
.cert-table td {
|
|
vertical-align: middle;
|
|
}
|
|
|
|
.doc-link {
|
|
display: inline-flex;
|
|
align-items: center;
|
|
gap: 6px;
|
|
color: #1ebf73;
|
|
font-weight: 600;
|
|
text-decoration: none;
|
|
}
|
|
|
|
.doc-link:hover {
|
|
text-decoration: underline;
|
|
}
|
|
|
|
.empty-state {
|
|
text-align: center;
|
|
padding: 30px 10px;
|
|
color: #9ca3af;
|
|
}
|
|
|
|
.empty-state i {
|
|
font-size: 34px;
|
|
margin-bottom: 10px;
|
|
display: block;
|
|
color: #d5d9e0;
|
|
}
|
|
|
|
.form-field {
|
|
margin-bottom: 20px;
|
|
}
|
|
|
|
.form-field label {
|
|
display: block;
|
|
font-weight: 600;
|
|
font-size: 14px;
|
|
color: #374151;
|
|
margin-bottom: 6px;
|
|
}
|
|
|
|
.form-field .form-control {
|
|
border-radius: 8px;
|
|
border: 1px solid #e2e4e9;
|
|
padding: 10px 12px;
|
|
}
|
|
|
|
.form-field .form-control:focus {
|
|
border-color: #1ebf73;
|
|
box-shadow: 0 0 0 3px rgba(30, 191, 115, 0.12);
|
|
}
|
|
|
|
.upload-drop {
|
|
border: 2px dashed #d5d9e0;
|
|
border-radius: 12px;
|
|
padding: 24px;
|
|
text-align: center;
|
|
transition: border-color 0.2s, background 0.2s;
|
|
background: #fafbfc;
|
|
}
|
|
|
|
.upload-drop:hover {
|
|
border-color: #1ebf73;
|
|
background: #f6fdf9;
|
|
}
|
|
|
|
.upload-icon {
|
|
font-size: 30px;
|
|
color: #1ebf73;
|
|
margin-bottom: 8px;
|
|
}
|
|
|
|
.file-chosen {
|
|
display: block;
|
|
margin-top: 10px;
|
|
font-size: 13px;
|
|
color: #6b7280;
|
|
}
|
|
|
|
.btn-save {
|
|
border-radius: 8px;
|
|
padding: 10px 26px;
|
|
font-weight: 600;
|
|
}
|
|
|
|
.privacy-note {
|
|
font-size: 12px;
|
|
color: #9ca3af;
|
|
margin: 12px 0 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">Certificati Medici</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 (isset($_GET['message']) && $_GET['message'] === 'success') : ?>
|
|
<div class="alert alert-success" role="alert">
|
|
Certificato rimosso con successo.
|
|
</div>
|
|
<?php endif; ?>
|
|
|
|
<?php if ($uploadFeedback) : ?>
|
|
<div class="alert alert-<?php echo $uploadFeedback['type'] === 'success' ? 'success' : 'danger'; ?>" role="alert">
|
|
<?php echo e($uploadFeedback['text']); ?>
|
|
</div>
|
|
<?php endif; ?>
|
|
|
|
<!-- Elenco documenti -->
|
|
<div class="row">
|
|
<div class="col-12">
|
|
<div class="card cert-card mb-4">
|
|
<div class="card-body">
|
|
<div class="section-title">I tuoi documenti</div>
|
|
<p class="section-lead">
|
|
Ciao <?php echo e($firstname); ?>, qui trovi i certificati medici di liberatoria alla pratica Yoga che hai caricato.
|
|
</p>
|
|
|
|
<div class="table-responsive">
|
|
<table class="table cert-table">
|
|
<thead>
|
|
<tr>
|
|
<th>Descrizione</th>
|
|
<th>Scadenza</th>
|
|
<th>Documento</th>
|
|
<th class="text-end">Azione</th>
|
|
</tr>
|
|
</thead>
|
|
<tbody>
|
|
<?php if (empty($documents)) : ?>
|
|
<tr>
|
|
<td colspan="4">
|
|
<div class="empty-state">
|
|
<i class="fas fa-folder-open"></i>
|
|
Nessun documento caricato. Usa il modulo qui sotto per aggiungere il primo.
|
|
</div>
|
|
</td>
|
|
</tr>
|
|
<?php else : ?>
|
|
<?php foreach ($documents as $document) : ?>
|
|
<tr>
|
|
<td><?php echo e($document['documentdescription']); ?></td>
|
|
<td><?php echo e($document['expirydatedocument']); ?></td>
|
|
<td>
|
|
<a class="doc-link" href="user/document/<?php echo e(rawurlencode($document['filenamedocument'])); ?>" target="_blank" rel="noopener">
|
|
<i class="fas fa-file-arrow-down"></i> Apri
|
|
</a>
|
|
</td>
|
|
<td class="text-end">
|
|
<button class="btn btn-danger btn-sm" onclick="confirmDeleteCertificate(<?php echo (int) $document['idcertificateuserprofile']; ?>)">
|
|
<i class="fas fa-trash"></i> Cancella
|
|
</button>
|
|
</td>
|
|
</tr>
|
|
<?php endforeach; ?>
|
|
<?php endif; ?>
|
|
</tbody>
|
|
</table>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<!-- Upload -->
|
|
<div class="row">
|
|
<div class="col-12">
|
|
<div class="card cert-card">
|
|
<div class="card-body">
|
|
<div class="section-title">Carica un nuovo documento</div>
|
|
<p class="section-lead">Formati accettati: PDF, JPG o PNG (max 16 MB).</p>
|
|
|
|
<form method="post" enctype="multipart/form-data">
|
|
<div class="row">
|
|
<div class="col-md-6">
|
|
<div class="form-field">
|
|
<label for="documentDescription">Descrizione del documento</label>
|
|
<input type="text" id="documentDescription" class="form-control"
|
|
name="documentDescription" value="Certificato Medico" required>
|
|
</div>
|
|
</div>
|
|
<div class="col-md-6">
|
|
<div class="form-field">
|
|
<label for="expiryDate">Data di scadenza</label>
|
|
<input type="text" id="expiryDate" class="form-control" name="expiryDate" placeholder="AAAA-MM-GG" required>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<div class="form-field">
|
|
<label>File</label>
|
|
<label class="upload-drop d-block" for="fileToUpload" style="cursor:pointer;">
|
|
<div class="upload-icon"><i class="fas fa-cloud-arrow-up"></i></div>
|
|
<div>Clicca per selezionare un file</div>
|
|
<span class="file-chosen" id="fileChosenLabel">Nessun file selezionato</span>
|
|
</label>
|
|
<input type="file" id="fileToUpload" name="fileToUpload" class="d-none"
|
|
accept=".pdf,.jpg,.jpeg,.png" onchange="handleFileChange(this)" required>
|
|
</div>
|
|
|
|
<p class="privacy-note">
|
|
I documenti caricati sono trattati solo a fini di sicurezza. Caricando il documento accetti il regolamento sulla privacy.
|
|
</p>
|
|
|
|
<button type="submit" class="btn btn-primary btn-save" name="submit">Carica documento</button>
|
|
</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>
|
|
</body>
|
|
|
|
</html>
|