148 lines
4.8 KiB
PHP
148 lines
4.8 KiB
PHP
<?php
|
|
require_once __DIR__ . '/../includes/init_client.php';
|
|
|
|
$client_id = $_SESSION['reference_id'];
|
|
|
|
$stmt = $pdo->prepare("
|
|
SELECT p.*
|
|
FROM praticien_client pc
|
|
JOIN praticien p ON pc.praticien_id = p.id
|
|
WHERE pc.client_id = ?
|
|
ORDER BY p.nom ASC
|
|
");
|
|
$stmt->execute([$client_id]);
|
|
$favoris = $stmt->fetchAll();
|
|
|
|
// util pour couper les mots de la description texte
|
|
function h($s)
|
|
{return htmlspecialchars((string) $s, ENT_QUOTES, 'UTF-8');}
|
|
function excerpt($text, $len = 160)
|
|
{
|
|
$t = trim(strip_tags((string) $text));
|
|
if (mb_strlen($t, 'UTF-8') <= $len) {
|
|
return $t;
|
|
}
|
|
|
|
return mb_substr($t, 0, $len, 'UTF-8') . '…';
|
|
}
|
|
|
|
$PAGE_TITLE = $translations['mes_praticiens_favoris_title'] ?? 'Mes praticiens favoris';
|
|
$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_praticiens_favoris_heading'] ?></h2>
|
|
|
|
<?php if (empty($favoris)): ?>
|
|
<div class="alert alert-info"><?php echo $translations['aucun_favori_pour_le_moment'] ?></div>
|
|
<?php else: ?>
|
|
<?php foreach ($favoris as $p): ?>
|
|
<div class="card mb-4 shadow-sm" id="praticien_<?php echo $p['id'] ?>">
|
|
<div class="card-body praticien-card">
|
|
<div>
|
|
<?php if ($p['photo']): ?>
|
|
<img src="/public/uploads/<?php echo htmlspecialchars($p['photo']) ?>" alt="<?php echo $translations['alt_photo'] ?>" class="card-img-top">
|
|
<?php else: ?>
|
|
<img src="/public/uploads/img/user_placeholder.png" alt="<?php echo $translations['alt_photo'] ?>" class="card-img-top">
|
|
<?php endif; ?>
|
|
</div>
|
|
<div class="card-body p-0">
|
|
<h2 class="pro-name"><?php echo htmlspecialchars($p['prenom'] ?? '') . ' ' . htmlspecialchars($p['nom'] ?? '') ?></h5>
|
|
<p class="mb-1"><strong><?php echo $translations['label_ville'] ?> :</strong> <?php echo htmlspecialchars($p['ville'] ?? '') ?></p>
|
|
<p class="mb-2">
|
|
<?php if (! empty($p['presentation'])): ?>
|
|
<?php echo h(excerpt($p['presentation'], 300)) ?>
|
|
<?php endif; ?>
|
|
</p>
|
|
|
|
<div class="d-flex gap-3">
|
|
<button class="btn btn-danger btn-sm" onclick="supprimerFavori(<?php echo $p['id'] ?>)"> <?php echo $translations['btn_retirer'] ?></button>
|
|
<a class="btn btn-outline-secondary btn-sm btn-table" href="/public/client/reserver_rdv.php?praticien_id=<?php echo $p['id'] ?>"> <?php echo $translations['btn_rendez_vous'] ?></a>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
<?php endforeach; ?>
|
|
<?php endif; ?>
|
|
</div>
|
|
</div>
|
|
<script>
|
|
const csrfToken = <?php echo json_encode(ensure_csrf_token(), JSON_UNESCAPED_UNICODE) ?>;
|
|
</script>
|
|
<script>
|
|
function supprimerFavori(praticienId) {
|
|
Swal.fire({
|
|
title: <?php echo json_encode($translations['confirm_supprimer_favori_title']) ?>,
|
|
text: <?php echo json_encode($translations['confirm_supprimer_favori_text']) ?>,
|
|
icon: 'warning',
|
|
showCancelButton: true,
|
|
confirmButtonColor: '#dc3545',
|
|
cancelButtonColor: '#6c757d',
|
|
confirmButtonText: <?php echo json_encode($translations['btn_oui_supprimer']) ?>,
|
|
cancelButtonText: <?php echo json_encode($translations['btn_annuler']) ?>
|
|
}).then((result) => {
|
|
if (!result.isConfirmed) return;
|
|
|
|
const formData = new FormData();
|
|
formData.append('praticien_id', String(praticienId));
|
|
formData.append('csrf_token', csrfToken);
|
|
|
|
fetch('/public/client/supprimer_favori.php', {
|
|
method: 'POST',
|
|
headers: {
|
|
'Accept': 'application/json',
|
|
'X-Requested-With': 'XMLHttpRequest'
|
|
},
|
|
body: formData
|
|
})
|
|
.then(async (res) => {
|
|
const text = await res.text();
|
|
let data;
|
|
|
|
try {
|
|
data = JSON.parse(text);
|
|
} catch (e) {
|
|
throw new Error(text || 'Erreur réseau');
|
|
}
|
|
|
|
if (!res.ok || !data.ok) {
|
|
throw new Error(data.message || 'Erreur.');
|
|
}
|
|
|
|
Swal.fire({
|
|
icon: 'success',
|
|
title: <?php echo json_encode($translations['favori_supprime_title']) ?>,
|
|
text: data.message || '',
|
|
timer: 1500,
|
|
showConfirmButton: false
|
|
});
|
|
|
|
const element = document.getElementById('praticien_' + praticienId);
|
|
if (element) {
|
|
element.remove();
|
|
}
|
|
})
|
|
.catch((err) => {
|
|
Swal.fire({
|
|
icon: 'error',
|
|
title: 'Oups',
|
|
text: err.message || 'Erreur.'
|
|
});
|
|
});
|
|
});
|
|
}
|
|
</script>
|
|
</div>
|
|
<footer class="site-footer">
|
|
<div class="container">
|
|
<p><?php echo $translations['copyr'] ?></p>
|
|
</div>
|
|
</footer>
|
|
</body>
|
|
</html>
|