283 lines
12 KiB
PHP
283 lines
12 KiB
PHP
<?php
|
|
require_once __DIR__ . '/../includes/bootstrap_global.php';
|
|
require_once APP_HTDOCS . '/includes/avatar_initiales.php';
|
|
|
|
$praticien_id = (int) ($_GET['praticien_id'] ?? 0);
|
|
if ($praticien_id <= 0) {echo "<div class='container py-5'>ID invalide.</div>";exit;}
|
|
|
|
function h($s)
|
|
{return htmlspecialchars((string) $s, ENT_QUOTES, 'UTF-8');}
|
|
function percent_from_5($n)
|
|
{$n = max(0, min(5, (float) $n));return (int) round($n / 5 * 100);}
|
|
function pseudo_from($prenom, $nom)
|
|
{
|
|
$p = trim((string) $prenom);
|
|
$n = trim((string) $nom);
|
|
$p = $p !== '' ? mb_convert_case($p, MB_CASE_TITLE, 'UTF-8') : 'Client';
|
|
$i = $n !== '' ? mb_strtoupper(mb_substr($n, 0, 1, 'UTF-8'), 'UTF-8') : '';
|
|
return $i ? ($p . '.' . $i) : $p;
|
|
}
|
|
|
|
// Titre + stats
|
|
$pp = $pdo->prepare("SELECT titre, prenom, nom FROM praticien WHERE id=?");
|
|
$pp->execute([$praticien_id]);
|
|
$pr = $pp->fetch(PDO::FETCH_ASSOC);
|
|
if (! $pr) {echo "<div class='container py-5'>" . $translations['praticien_introuvable'] . "</div>";exit;}
|
|
|
|
$avg = $pdo->prepare("SELECT ROUND(AVG(note),1) AS m, COUNT(*) AS c FROM avis_praticien WHERE praticien_id=? AND statut='publie'");
|
|
$avg->execute([$praticien_id]);
|
|
$stats = $avg->fetch(PDO::FETCH_ASSOC) ?: ['m' => null, 'c' => 0];
|
|
|
|
// Form POST
|
|
$flash = null;
|
|
if ($_SERVER['REQUEST_METHOD'] === 'POST' && ($_POST['do'] ?? '') === 'add') {
|
|
if (! hash_equals($_SESSION['csrf_token'] ?? '', $_POST['csrf'] ?? '')) {
|
|
$flash = ['type' => 'danger', 'msg' => $translations['avis_form_err']];
|
|
} elseif ($_SESSION['role'] !== 'client') {
|
|
$flash = ['type' => 'danger', 'msg' => $translations['non_autorise'] ?? 'Non autorisé'];
|
|
} else {
|
|
$note = (int) ($_POST['note'] ?? 0);
|
|
$titre = trim((string) ($_POST['titre'] ?? ''));
|
|
$commentaire = trim((string) ($_POST['commentaire'] ?? ''));
|
|
$visit_date = trim((string) ($_POST['visit_date'] ?? ''));
|
|
|
|
$ok = $note >= 1 && $note <= 5 && mb_strlen($commentaire, 'UTF-8') >= 10;
|
|
$date_ok = true;
|
|
if ($visit_date !== '') {
|
|
$ts = strtotime($visit_date . ' 00:00:00');
|
|
$date_ok = $ts && $ts <= time() + 86400; // pas dans le futur
|
|
}
|
|
if ($ok && $date_ok) {
|
|
$st = $pdo->prepare("INSERT INTO avis_praticien (praticien_id, client_id, note, titre, commentaire, visit_date, statut)
|
|
VALUES (?, ?, ?, ?, ?, ?, 'publie')");
|
|
$st->execute([$praticien_id, (int) $_SESSION['reference_id'], $note,
|
|
($titre !== '' ? $titre : null), ($commentaire !== '' ? $commentaire : null),
|
|
($visit_date !== '' ? $visit_date : null)]);
|
|
$flash = ['type' => 'success', 'msg' => $translations['avis_form_ok']];
|
|
// refresh stats
|
|
$avg->execute([$praticien_id]);
|
|
$stats = $avg->fetch(PDO::FETCH_ASSOC) ?: ['m' => null, 'c' => 0];
|
|
} else {
|
|
$flash = ['type' => 'danger', 'msg' => $translations['avis_form_err']];
|
|
}
|
|
}
|
|
}
|
|
|
|
// Pagination
|
|
$perPage = 10;
|
|
$page = max(1, (int) ($_GET['page'] ?? 1));
|
|
$offset = ($page - 1) * $perPage;
|
|
|
|
$cnt = $pdo->prepare("SELECT COUNT(*) FROM avis_praticien WHERE praticien_id = :pid AND statut = 'publie'");
|
|
$cnt->execute([':pid' => $praticien_id]);
|
|
$total = (int) $cnt->fetchColumn();
|
|
$pages = max(1, (int) ceil($total / $perPage));
|
|
|
|
$sql = "SELECT a.note, a.titre, a.commentaire, a.visit_date, a.created_at,
|
|
c.prenom, c.nom
|
|
FROM avis_praticien a
|
|
LEFT JOIN client c ON c.id = a.client_id
|
|
WHERE a.praticien_id = :pid AND a.statut = 'publie'
|
|
ORDER BY a.created_at DESC
|
|
LIMIT :o, :l";
|
|
|
|
$ls = $pdo->prepare($sql);
|
|
$ls->bindValue(':pid', $praticien_id, PDO::PARAM_INT);
|
|
$ls->bindValue(':o', (int) $offset, PDO::PARAM_INT);
|
|
$ls->bindValue(':l', (int) $perPage, PDO::PARAM_INT);
|
|
$ls->execute();
|
|
|
|
$avis = $ls->fetchAll(PDO::FETCH_ASSOC);
|
|
|
|
// ID depuis l'URL (on passe bien ?praticien_id=...)
|
|
$praticien_id = (int) ($_GET['praticien_id'] ?? 0);
|
|
if ($praticien_id <= 0) {echo "<div class='container py-5'>ID invalide.</div>";exit;}
|
|
|
|
// Charger le praticien
|
|
$pp = $pdo->prepare("SELECT titre, prenom, nom FROM praticien WHERE id = :id");
|
|
$pp->execute([':id' => $praticien_id]);
|
|
$pr = $pp->fetch(PDO::FETCH_ASSOC);
|
|
|
|
if (! $pr) {
|
|
echo "<div class='container py-5'>" . $translations['praticien_introuvable'] . "</div>";
|
|
exit;
|
|
}
|
|
|
|
// Définir $name AVANT de l'utiliser
|
|
$name = trim(
|
|
($pr['prenom'] ?? '')
|
|
. ' '
|
|
. ($pr['nom'] ?? '')
|
|
);
|
|
$CSRF = $_SESSION['csrf_token'] ?? '';
|
|
?>
|
|
<!doctype html>
|
|
<html lang="ru">
|
|
<head>
|
|
<meta charset="utf-8">
|
|
<title><?php echo htmlspecialchars($translations['seo_avis_title'], ENT_QUOTES, 'UTF-8') ?></title>
|
|
<meta name="description" content="<?php echo htmlspecialchars($translations['seo_avis_desc'], ENT_QUOTES, 'UTF-8') ?>">
|
|
<meta name="keywords" content="<?php echo htmlspecialchars($translations['seo_avis_keywords'], ENT_QUOTES, 'UTF-8') ?>">
|
|
<meta name="author" content="Uslugi.fr">
|
|
|
|
|
|
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
|
|
|
<link href="/css/bootstrap.min.css" rel="stylesheet">
|
|
<link rel="stylesheet" href="<?php echo asset('/includes/site_style.css') ?>">
|
|
<link rel="stylesheet" href="<?php echo asset('/includes/custom_style.css') ?>">
|
|
<link rel="stylesheet" href="<?php echo asset('/includes/mobil_style.css') ?>">
|
|
<?php include_once __DIR__ . '/includes/tracking.php'; ?>
|
|
</head>
|
|
<body class="layout">
|
|
|
|
<?php if ($logged):
|
|
include_header_clean(APP_HTDOCS . '/public/includes/header.php');
|
|
else: ?>
|
|
<!-- Header public (Connexion + “?”) -->
|
|
<header class="site-header">
|
|
<div class="container">
|
|
<div class="header-left">
|
|
<div class="brand">
|
|
<a href="/index.php"><img src="/public/uploads/img/logo_u.png"
|
|
alt="uslugi.fr"
|
|
class="logo-mobile"></a>
|
|
|
|
<a href="/index.php"><img src="/public/uploads/img/logo.png"
|
|
alt="uslugi.fr"
|
|
class="logo-desktop"></a>
|
|
</div>
|
|
<div class="lang-switch">
|
|
<?php require __DIR__ . '/includes/menu_langue.php'; ?>
|
|
</div>
|
|
</div>
|
|
<nav class="header-actions">
|
|
<a class="btn-login" href="/connexion.php">
|
|
<span class="d-sm-none"><?php echo $translations['btn_se_connecter'] ?></span>
|
|
<span class="d-none d-sm-inline"><?php echo $translations['ja_spec'] ?></span>
|
|
</a>
|
|
<!--<a class="btn-login" href="/connexion.php"><?php echo $translations['ja_spec'] ?></a>-->
|
|
|
|
<div class="dropdown">
|
|
<button class="btn btn-logo rounded-circle d-inline-flex align-items-center justify-content-center question-btn"
|
|
type="button" data-bs-toggle="dropdown" data-bs-auto-close="true"
|
|
aria-expanded="false" aria-label="Помощь">?</button>
|
|
<ul class="dropdown-menu dropdown-menu-end shadow help-menu menu-panel">
|
|
<li><a href="/how-it-work.php"><?php echo $translations['kak_rabotaet'] ?></a></a></li>
|
|
<li><a href="/about.php"><?php echo $translations['pro_nas'] ?></a></li>
|
|
<li><a href="/faq.php"><?php echo $translations['faq'] ?></a></li>
|
|
<li><a href="/contact.php"><?php echo $translations['nam_pisat'] ?></a></li>
|
|
</ul>
|
|
</div>
|
|
</nav>
|
|
</div>
|
|
</header>
|
|
<?php endif; ?>
|
|
|
|
<div class="main">
|
|
<div class="container py-5">
|
|
<div class="shadow p-4 rounded bg-light">
|
|
<h2 class="mb-2"><?php echo h($translations['avis_titre_page']) ?> — <?php echo h($name) ?></h2>
|
|
|
|
<div class="d-flex align-items-center gap-3 mb-3">
|
|
<?php $m = (float) ($stats['m'] ?? 0);
|
|
$c = (int) ($stats['c'] ?? 0);
|
|
$w = percent_from_5($m); ?>
|
|
<div class="rating" aria-label="Note">
|
|
<div class="stars-base">★★★★★</div>
|
|
<div class="stars-fill" style="width:<?php echo $w ?>%">★★★★★</div>
|
|
</div>
|
|
<div class="text-muted"><?php echo $m ? number_format($m, 1, ',', ' ') : '—' ?>/5 • <?php echo $c . ' ' . h($translations['avis_total']) ?></div>
|
|
</div>
|
|
|
|
<?php if ($flash): ?>
|
|
<div class="alert alert-<?php echo h($flash['type']) ?>"><?php echo h($flash['msg']) ?></div>
|
|
<?php endif; ?>
|
|
|
|
<?php if (($_SESSION['role'] ?? '') === 'client'): ?>
|
|
<div class="card shadow-sm mb-4">
|
|
<div class="card-body">
|
|
<h5 class="mb-3"><?php echo h($translations['avis_form_titre']) ?></h5>
|
|
<form method="post" class="row g-3">
|
|
<div class="col-12 col-md-4">
|
|
<label class="form-label"><?php echo h($translations['avis_form_note']) ?></label>
|
|
<select name="note" class="form-select" required>
|
|
<?php for ($i = 5; $i >= 1; $i--): ?>
|
|
<option value="<?php echo $i ?>"> <?php echo $i ?> ★</option>
|
|
<?php endfor; ?>
|
|
</select>
|
|
</div>
|
|
<div class="col-12 col-md-4">
|
|
<label class="form-label"><?php echo h($translations['avis_form_date_visite']) ?></label>
|
|
<input type="date" name="visit_date" class="form-control">
|
|
</div>
|
|
<div class="col-12">
|
|
<label class="form-label"><?php echo h($translations['avis_form_titre_lbl']) ?></label>
|
|
<input type="text" name="titre" class="form-control" maxlength="150">
|
|
</div>
|
|
<div class="col-12">
|
|
<label class="form-label"><?php echo h($translations['avis_form_commentaire']) ?></label>
|
|
<textarea name="commentaire" class="form-control" rows="4" minlength="10" required></textarea>
|
|
</div>
|
|
<div class="col-12">
|
|
<input type="hidden" name="csrf" value="<?php echo h($CSRF) ?>">
|
|
<input type="hidden" name="do" value="add">
|
|
<button class="btn btn-primary"><?php echo h($translations['avis_form_envoyer']) ?></button>
|
|
</div>
|
|
</form>
|
|
</div>
|
|
</div>
|
|
<?php endif; ?>
|
|
|
|
<?php if (! $avis): ?>
|
|
<div class="text-muted"><?php echo h($translations['avis_aucun']) ?></div>
|
|
<?php else: foreach ($avis as $a): $pw = percent_from_5((float) $a['note']); ?>
|
|
<div class="card shadow-sm mb-3">
|
|
<div class="card-body">
|
|
<div class="d-flex justify-content-between align-items-start mb-1">
|
|
<div>
|
|
<div class="rating mb-1">
|
|
<div class="stars-base">★★★★★</div>
|
|
<div class="stars-fill" style="width:<?php echo $pw ?>%">★★★★★</div>
|
|
</div>
|
|
<div class="small text-muted">
|
|
<strong><?php echo h(pseudo_from($a['prenom'] ?? '', $a['nom'] ?? '')) ?></strong>
|
|
<?php if (! empty($a['visit_date'])): ?> • <?php echo date('d/m/Y', strtotime($a['visit_date'])) ?><?php endif; ?>
|
|
</div>
|
|
</div>
|
|
<div class="small text-muted"><?php echo date('d/m/Y', strtotime($a['created_at'])) ?></div>
|
|
</div>
|
|
<?php if (! empty($a['titre'])): ?><div class="fw-semibold mb-1"><?php echo h($a['titre']) ?></div><?php endif; ?>
|
|
<div><?php echo nl2br(h($a['commentaire'] ?? '')) ?></div>
|
|
</div>
|
|
</div>
|
|
<?php endforeach;endif; ?>
|
|
|
|
<?php if ($pages > 1): ?>
|
|
<nav class="mt-3">
|
|
<?php for ($i = 1; $i <= $pages; $i++):
|
|
$href = '/public/client/avis.php?praticien_id=' . $praticien_id . '&page=' . $i;
|
|
$cls = $i === $page ? 'btn btn-sm btn-primary me-1' : 'btn btn-sm btn-outline-primary me-1';
|
|
?>
|
|
<a class="<?php echo $cls ?>" href="<?php echo h($href) ?>"><?php echo $i ?></a>
|
|
<?php endfor; ?>
|
|
</nav>
|
|
<?php endif; ?>
|
|
|
|
<div class="mt-4">
|
|
<a class="btn btn-outline-secondary" href="/detail_public.php?id=<?php echo (int) $praticien_id ?>">⬅️ <?php echo $translations['retour_avis_profil'] ?></a>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<footer class="site-footer">
|
|
<div class="container">
|
|
<p><?php echo $translations['copyr'] ?></p>
|
|
</div>
|
|
</footer>
|
|
<script src="/js/bootstrap.bundle.min.js"></script>
|
|
|
|
</body>
|
|
</html>
|