Files
yogibook_aury_new/public/userprofile.php
T

318 lines
12 KiB
PHP

<?php
require_once('include/headscript.php');
/**
* Profilo allievo per la scuola corrente (dati personali e di salute).
* Il salvataggio avviene in process.php. I certificati si gestiscono in userprofiledoc.php.
*/
$pdo = DBHandlerSelect::getInstance()->getConnection();
$iduserlogin = (int) $iduserlogin;
function e($value): string
{
return htmlspecialchars((string) $value, ENT_QUOTES, 'UTF-8');
}
$message = $_GET['message'] ?? '';
$stmtProfile = $pdo->prepare("SELECT * FROM userprofile WHERE iduser = ? AND idschool = ? LIMIT 1");
$stmtProfile->execute([$iduserlogin, $idschool]);
$rowdata = $stmtProfile->fetch() ?: [];
$datebirthFromDatabase = $rowdata['datebirth'] ?? '';
$yogaforFromDatabase = $rowdata['yogafor'] ?? '';
$healthissueFromDatabase = $rowdata['healthissue'] ?? '';
$generalcommentFromDatabase = $rowdata['generalcomment'] ?? '';
$isUpdate = !empty($rowdata);
// Numero certificati validi (per il riquadro di collegamento)
$stmtCert = $pdo->prepare(
"SELECT COUNT(*) FROM certificateuserprofile
WHERE iduser = ? AND idschool = ? AND (expirydatedocument IS NULL OR expirydatedocument >= CURDATE())"
);
$stmtCert->execute([$iduserlogin, $idschool]);
$validCertificates = (int) $stmtCert->fetchColumn();
$currentYear = date('Y');
$uploadFeedback = null;
?>
<!doctype html>
<html lang="it">
<head>
<meta charset="utf-8" />
<title>YogiBook - Profilo Utente</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() {
$("#datebirth").datepicker({
changeYear: true,
changeMonth: true,
yearRange: "1900:<?php echo $currentYear; ?>",
dateFormat: "yy-mm-dd"
});
$("#expiryDate").datepicker({
changeYear: true,
changeMonth: true,
dateFormat: "yy-mm-dd"
});
});
// Mostra il nome del file scelto e valida lato client (feedback immediato)
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 = 8 * 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 8 MB)';
label.style.color = '#dc3545';
input.value = '';
return;
}
label.textContent = f.name;
label.style.color = '#198754';
}
</script>
<style>
.profile-wrap {
width: 100%;
}
.profile-card {
border: none;
border-radius: 14px;
box-shadow: 0 4px 20px rgba(0, 0, 0, 0.06);
}
.profile-card .card-body {
padding: 28px 32px;
}
.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-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);
}
.divider {
height: 1px;
background: #eef0f3;
margin: 30px 0;
}
/* Area upload */
.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;
}
.hint {
font-size: 12px;
color: #9ca3af;
margin-top: 6px;
}
</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">Profilo Utente</h4>
</div>
</div>
<div class="d-flex">
<?php include('include/schoolswitcher.php'); ?><?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="profile-wrap">
<?php if ($message === 'success') : ?>
<div class="alert alert-success" role="alert">Profilo aggiornato con successo.</div>
<?php elseif ($message === 'baddate') : ?>
<div class="alert alert-danger" role="alert">Data di nascita non valida (formato AAAA-MM-GG).</div>
<?php elseif ($message === 'error') : ?>
<div class="alert alert-danger" role="alert">Errore durante il salvataggio. Riprova.</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; ?>
<!-- Dati profilo -->
<div class="card profile-card mb-4">
<div class="card-body">
<div class="section-title">I tuoi dati</div>
<p class="section-lead">Compila o aggiorna le informazioni del tuo profilo.</p>
<form action="process.php" method="post">
<div class="form-field">
<label for="datebirth">Data di nascita</label>
<input type="text" id="datebirth" class="form-control" name="datebirth"
value="<?php echo e($datebirthFromDatabase); ?>" placeholder="AAAA-MM-GG" required>
</div>
<div class="form-field">
<label for="yogafor">Yoga praticato</label>
<textarea id="yogafor" name="yogafor" class="form-control" rows="3"><?php echo e($yogaforFromDatabase); ?></textarea>
</div>
<div class="form-field">
<label for="healthissue">Problemi di salute</label>
<textarea id="healthissue" name="healthissue" class="form-control" rows="3"><?php echo e($healthissueFromDatabase); ?></textarea>
</div>
<div class="form-field">
<label for="generalcomment">Commenti generali</label>
<textarea id="generalcomment" name="generalcomment" class="form-control" rows="3"><?php echo e($generalcommentFromDatabase); ?></textarea>
</div>
<button type="submit" class="btn btn-primary btn-save" name="submit">
<?php echo $isUpdate ? 'Aggiorna profilo' : 'Salva profilo'; ?>
</button>
</form>
</div>
</div>
<!-- Certificati: collegamento alla pagina dedicata -->
<div class="card profile-card">
<div class="card-body d-flex align-items-center justify-content-between flex-wrap gap-3">
<div>
<div class="section-title">Certificato medico</div>
<?php if ($validCertificates > 0) : ?>
<p class="mb-0" style="color:#1a7f52;"><i class="fas fa-circle-check me-1"></i> Hai un certificato valido caricato.</p>
<?php else : ?>
<p class="mb-0" style="color:#c0392b;"><i class="fas fa-triangle-exclamation me-1"></i> Nessun certificato valido: caricalo per praticare.</p>
<?php endif; ?>
</div>
<a href="userprofiledoc.php" class="btn btn-primary btn-save"><i class="fas fa-file-medical me-1"></i> Gestisci certificati</a>
</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>