254 lines
10 KiB
PHP
254 lines
10 KiB
PHP
<?php
|
|
require_once __DIR__ . '/../includes/init_client.php';
|
|
|
|
$pdo->prepare("
|
|
INSERT INTO push_badge_counters (compte_id, msg_unread, rdv_unread, updated_at)
|
|
VALUES (:cid, 0, 0, NOW())
|
|
ON DUPLICATE KEY UPDATE
|
|
rdv_unread = 0,
|
|
updated_at = NOW()
|
|
")->execute([':cid' => (int) $_SESSION['compte_id']]);
|
|
|
|
$client_id = $_SESSION['reference_id'];
|
|
|
|
$stmt = $pdo->prepare("
|
|
SELECT
|
|
rv.*,
|
|
p.nom AS nom_praticien,
|
|
p.prenom AS prenom_praticien,
|
|
p.email AS email_praticien,
|
|
p.adresse AS p_adresse,
|
|
p.ville AS p_ville,
|
|
p.code_postal AS p_cp
|
|
FROM rendez_vous rv
|
|
JOIN praticien p ON rv.praticien_id = p.id
|
|
WHERE rv.client_id = ? AND rv.date_rdv >= NOW()
|
|
ORDER BY rv.date_rdv ASC
|
|
");
|
|
$stmt->execute([$client_id]);
|
|
$rdvs = $stmt->fetchAll(PDO::FETCH_ASSOC);
|
|
|
|
$PAGE_TITLE = $translations['mes_rdv_title'] ?? 'Mes rendez-vous';
|
|
$HEAD_EXTRA = <<<HTML
|
|
<script src="/js/sweetalert2@11.js"></script>
|
|
HTML;
|
|
require_once '../includes/header.php';
|
|
?>
|
|
<div class="main1">
|
|
<div class="container py-5">
|
|
<div class="shadow p-4 rounded bg-light">
|
|
<h2 class="mb-4 text-center">📅 <?php echo $translations['mes_rdv_heading'] ?></h2>
|
|
|
|
<div class="table-responsive">
|
|
<table class="table table-striped table-hover align-middle mobile-cards" id="table_rdv">
|
|
<thead class="table-light">
|
|
<tr align="center">
|
|
<th><?php echo $translations['col_date'] ?></th>
|
|
<th><?php echo $translations['col_heure'] ?></th>
|
|
<th><?php echo $translations['col_praticien'] ?></th>
|
|
<th><?php echo $translations['col_duree'] ?></th>
|
|
<th><?php echo $translations['col_statut'] ?></th>
|
|
<th><?php echo $translations['col_action'] ?></th>
|
|
<!-- Chat -->
|
|
<th><?php echo $translations['btn_chat'] ?></th>
|
|
<!-- Visio / Adresse -->
|
|
<th><?php echo htmlspecialchars($translations['status_online']) ?></th>
|
|
</tr>
|
|
</thead>
|
|
<tbody>
|
|
<?php if (empty($rdvs)): ?>
|
|
<tr><td colspan="8" class="text-center"><?php echo $translations['aucun_rdv_a_venir'] ?></td></tr>
|
|
<?php else: ?>
|
|
<?php foreach ($rdvs as $r):
|
|
$dt = new DateTime($r['date_rdv']);
|
|
$id = (int) $r['id'];
|
|
$ficheUrl = '/specialiste?id=' . (int) $r['praticien_id'];
|
|
?>
|
|
<tr>
|
|
<td><?php echo $dt->format('d/m/Y') ?></td>
|
|
<td><?php echo $dt->format('H:i') ?></td>
|
|
<td>
|
|
<a href="/public/client/detail_praticien.php?id=<?php echo (int) $r['praticien_id'] ?>">
|
|
<?php echo htmlspecialchars($r['prenom_praticien'] . ' ' . $r['nom_praticien']) ?>
|
|
</a>
|
|
</td>
|
|
<td><?php echo (int) $r['duree_minutes'] ?> <?php echo $translations['min_abbr'] ?></td>
|
|
|
|
<td id="statut_<?php echo $id ?>">
|
|
<span class="badge rounded-pill <?php echo $r['statut'] === 'confirmé' ? 'bg-success' : ($r['statut'] === 'prévu' ? 'bg-warning text-dark' : 'bg-secondary') ?>">
|
|
<?php echo $r['statut'] === 'confirmé' ? $translations['statut_confirme'] : ($r['statut'] === 'prévu' ? $translations['statut_prevu'] : $translations['statut_annule']) ?>
|
|
</span>
|
|
</td>
|
|
|
|
<td>
|
|
<?php if ($r['statut'] !== 'annulé'): ?>
|
|
<button class="btn btn-outline-danger btn-sm" onclick="annulerRdv(<?php echo $id ?>)"> <?php echo $translations['btn_annuler'] ?></button>
|
|
<?php else: ?>
|
|
<em class="text-muted"><?php echo $translations['statut_annule'] ?></em>
|
|
<?php endif; ?>
|
|
</td>
|
|
|
|
<!-- Chat -->
|
|
<td>
|
|
<a class="btn btn-outline-secondary btn-sm btn-table" href="/messages/start.php?praticien_id=<?php echo (int) $r['praticien_id'] ?>">
|
|
<?php echo $translations['chat_praticien'] ?>
|
|
</a>
|
|
</td>
|
|
|
|
<!-- Visio (online) OU Adresse/Lien (offline) -->
|
|
<td>
|
|
<?php
|
|
$lieu = strtolower(trim((string) ($r['lieu'] ?? '')));
|
|
if ($lieu === 'online') {
|
|
// --- Affichage visio comme avant ---
|
|
$statut = $r['statut']; // 'confirmé' | 'prévu' | 'annulé'
|
|
|
|
$tzParis = new DateTimeZone('Europe/Paris');
|
|
$now = new DateTime('now', $tzParis);
|
|
$start = new DateTime($r['date_rdv'], $tzParis);
|
|
$open = (clone $start)->modify('-15 minutes');
|
|
$close = (clone $start)->modify('+' . (int) ($r['duree_minutes'] ?? 120) . ' minutes');
|
|
|
|
if ($statut === 'confirmé') {
|
|
if ($now >= $open && $now <= $close) {
|
|
// Bouton actif
|
|
?>
|
|
<a href="/visio/join.php?rdv=<?php echo (int) $r['id'] ?>&start=1" class="btn btn-outline-secondary btn-sm btn-table">
|
|
<?php echo htmlspecialchars($translations['visio_nachalo']) ?>
|
|
</a>
|
|
<?php
|
|
} else {
|
|
// Messages hors fenêtre
|
|
?>
|
|
<small class="text-muted d-block mt-1">
|
|
<?php
|
|
if ($now < $open) {
|
|
echo htmlspecialchars(($translations['ouvert_a'] ?? 'Откроется в')) . ' ' . $open->format('H:i');
|
|
} elseif ($now > $close) {
|
|
echo htmlspecialchars(($translations['ferme_a'] ?? 'Закрыто в')) . ' ' . $close->format('H:i');
|
|
} else {
|
|
echo htmlspecialchars(($translations['prev_a'] ?? 'Запланировано на')) . ' ' . $start->format('d/m/Y \à H:i') . '.';
|
|
}
|
|
|
|
?>
|
|
</small>
|
|
<?php
|
|
}
|
|
} elseif ($statut === 'prévu') {
|
|
// Pas encore confirmé
|
|
?>
|
|
<small class="text-danger d-block mt-1">
|
|
<?php echo htmlspecialchars($translations['votre_rdv_jdet'] ?? 'En attente de confirmation') ?>
|
|
</small>
|
|
<?php
|
|
} else {
|
|
?>
|
|
<small class="text-muted d-block mt-1">
|
|
<?php echo htmlspecialchars($translations['statut_annule'] ?? 'Annulé') ?>
|
|
</small>
|
|
<?php
|
|
}
|
|
|
|
} else {
|
|
// --- OFFLINE : afficher adresse (si dispo) + lien fiche praticien ---
|
|
$addrParts = array_filter([
|
|
trim((string) ($r['p_adresse'] ?? '')),
|
|
trim((string) ($r['p_cp'] ?? '')) . ' ' . trim((string) ($r['p_ville'] ?? '')),
|
|
], fn($x) => $x !== '' && $x !== ' ');
|
|
$addr = trim(implode(', ', $addrParts));
|
|
|
|
if ($addr !== '') {
|
|
//echo '<div class="mb-1"> '.htmlspecialchars($addr).'</div>';
|
|
}
|
|
?>
|
|
<a href="<?php echo htmlspecialchars($ficheUrl) ?>" class="btn btn-outline-secondary btn-sm btn-table">
|
|
<?php echo htmlspecialchars($translations['voir_fiche_praticien'] ?? 'Voir la fiche') ?>
|
|
</a>
|
|
<?php
|
|
}
|
|
?>
|
|
</td>
|
|
</tr>
|
|
<?php endforeach; ?>
|
|
<?php endif; ?>
|
|
</tbody>
|
|
</table>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
<script>
|
|
const csrfToken = <?php echo json_encode(ensure_csrf_token(), JSON_UNESCAPED_UNICODE) ?>;
|
|
function annulerRdv(id) {
|
|
Swal.fire({
|
|
title: <?php echo json_encode($translations['confirm_annulation_title']) ?>,
|
|
icon: 'warning',
|
|
showCancelButton: true,
|
|
confirmButtonText: <?php echo json_encode($translations['btn_oui_annuler']) ?>,
|
|
cancelButtonText: <?php echo json_encode($translations['btn_annuler']) ?>,
|
|
confirmButtonColor: '#dc3545',
|
|
cancelButtonColor: '#6c757d'
|
|
}).then((result) => {
|
|
if (!result.isConfirmed) return;
|
|
|
|
fetch('/public/client/annuler_rdv.php', {
|
|
method: 'POST',
|
|
headers: {'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8'},
|
|
body: new URLSearchParams({
|
|
id: String(id),
|
|
csrf_token: csrfToken
|
|
})
|
|
})
|
|
.then(r => r.json().catch(() => ({ok:false, message:'Bad JSON'})))
|
|
.then(data => {
|
|
if (data.ok) {
|
|
Swal.fire({ icon:'success', title: <?php echo json_encode($translations['rdv_annule_ok']) ?>, text: data.message, timer: 1600, showConfirmButton:false });
|
|
const statutEl = document.getElementById("statut_" + id);
|
|
if (statutEl) {
|
|
statutEl.innerHTML = '<span class="badge bg-secondary"><?php echo htmlspecialchars($translations['statut_annule']) ?></span>';
|
|
}
|
|
} else {
|
|
Swal.fire({ icon:'error', title: 'Oops', text: data.message || 'Erreur' });
|
|
}
|
|
})
|
|
.catch(() => {
|
|
Swal.fire({ icon:'error', title:'Erreur réseau', text:'Veuillez réessayer.' });
|
|
});
|
|
});
|
|
}
|
|
</script>
|
|
|
|
<!-- Affichage mobile -->
|
|
<script defer>
|
|
(function(){
|
|
function initMobileCards(tbl){
|
|
if (!tbl) return;
|
|
const heads = Array.from(tbl.querySelectorAll('thead th')).map(th => th.textContent.trim());
|
|
tbl.querySelectorAll('tbody tr').forEach(tr => {
|
|
Array.from(tr.children).forEach((td, i) => {
|
|
if (!td.hasAttribute('data-label')) {
|
|
td.setAttribute('data-label', heads[i] || '');
|
|
}
|
|
});
|
|
});
|
|
document.documentElement.classList.add('mc-ready');
|
|
}
|
|
function ready(fn){
|
|
if (document.readyState === 'loading') document.addEventListener('DOMContentLoaded', fn);
|
|
else fn();
|
|
}
|
|
ready(function(){
|
|
const tbl = document.getElementById('table_rdv') || document.querySelector('table.mobile-cards');
|
|
initMobileCards(tbl);
|
|
});
|
|
})();
|
|
</script>
|
|
</div>
|
|
<footer class="site-footer">
|
|
<div class="container">
|
|
<p><?php echo $translations['copyr'] ?></p>
|
|
</div>
|
|
</footer>
|
|
</body>
|
|
</html>
|
|
|