Version stable, aprelic, connexion CFRS et autres corrections
This commit is contained in:
1 parent
865de8a976
commit
e9d0010451
62 files changed
+17483
-7256
No files matched your search
@@ -1,27 +1,88 @@
|
||||
<?php
|
||||
declare (strict_types = 1);
|
||||
|
||||
require_once __DIR__ . '/../includes/init_client.php';
|
||||
|
||||
header('Content-Type: application/json; charset=utf-8');
|
||||
|
||||
|
||||
|
||||
$client_id = $_SESSION['reference_id'];
|
||||
$praticien_id = intval($_POST['praticien_id'] ?? 0);
|
||||
|
||||
if ($praticien_id > 0) {
|
||||
|
||||
|
||||
// Évite les doublons
|
||||
$check = $pdo->prepare("SELECT * FROM praticien_client WHERE client_id = ? AND praticien_id = ?");
|
||||
$check->execute([$client_id, $praticien_id]);
|
||||
|
||||
if (!$check->fetch()) {
|
||||
$stmt = $pdo->prepare("INSERT INTO praticien_client (client_id, praticien_id) VALUES (?, ?)");
|
||||
$stmt->execute([$client_id, $praticien_id]);
|
||||
echo $translations['praticien_ajoute_favoris'];
|
||||
} else {
|
||||
echo $translations['praticien_deja_ajoute'];
|
||||
}
|
||||
} else {
|
||||
echo $translations['praticien_id_invalide'];
|
||||
if (($_SERVER['REQUEST_METHOD'] ?? '') !== 'POST') {
|
||||
echo json_encode([
|
||||
'ok' => false,
|
||||
'message' => 'Méthode non autorisée.',
|
||||
], JSON_UNESCAPED_UNICODE);
|
||||
exit;
|
||||
}
|
||||
|
||||
require_post_csrf();
|
||||
|
||||
$client_id = (int) ($_SESSION['reference_id'] ?? 0);
|
||||
$praticien_id = (int) ($_POST['praticien_id'] ?? 0);
|
||||
|
||||
if ($client_id <= 0) {
|
||||
echo json_encode([
|
||||
'ok' => false,
|
||||
'message' => $translations['erreur_generique'] ?? 'Erreur.',
|
||||
], JSON_UNESCAPED_UNICODE);
|
||||
exit;
|
||||
}
|
||||
|
||||
if ($praticien_id <= 0) {
|
||||
echo json_encode([
|
||||
'ok' => false,
|
||||
'message' => $translations['praticien_id_invalide'] ?? 'ID praticien invalide.',
|
||||
], JSON_UNESCAPED_UNICODE);
|
||||
exit;
|
||||
}
|
||||
|
||||
try {
|
||||
// Vérifie que le praticien existe
|
||||
$exists = $pdo->prepare("SELECT id FROM praticien WHERE id = ? LIMIT 1");
|
||||
$exists->execute([$praticien_id]);
|
||||
|
||||
if (! $exists->fetchColumn()) {
|
||||
echo json_encode([
|
||||
'ok' => false,
|
||||
'message' => $translations['praticien_id_invalide'] ?? 'ID praticien invalide.',
|
||||
], JSON_UNESCAPED_UNICODE);
|
||||
exit;
|
||||
}
|
||||
|
||||
// Évite les doublons
|
||||
$check = $pdo->prepare("
|
||||
SELECT 1
|
||||
FROM praticien_client
|
||||
WHERE client_id = ? AND praticien_id = ?
|
||||
LIMIT 1
|
||||
");
|
||||
$check->execute([$client_id, $praticien_id]);
|
||||
|
||||
if ($check->fetchColumn()) {
|
||||
echo json_encode([
|
||||
'ok' => true,
|
||||
'already_exists' => true,
|
||||
'message' => $translations['praticien_deja_ajoute'] ?? 'Déjà ajouté aux favoris.',
|
||||
], JSON_UNESCAPED_UNICODE);
|
||||
exit;
|
||||
}
|
||||
|
||||
$stmt = $pdo->prepare("
|
||||
INSERT INTO praticien_client (client_id, praticien_id)
|
||||
VALUES (?, ?)
|
||||
");
|
||||
$stmt->execute([$client_id, $praticien_id]);
|
||||
|
||||
echo json_encode([
|
||||
'ok' => true,
|
||||
'already_exists' => false,
|
||||
'message' => $translations['praticien_ajoute_favoris'] ?? 'Praticien ajouté aux favoris.',
|
||||
], JSON_UNESCAPED_UNICODE);
|
||||
exit;
|
||||
|
||||
} catch (Throwable $e) {
|
||||
error_log('ajouter_favorit.php: ' . $e->getMessage());
|
||||
echo json_encode([
|
||||
'ok' => false,
|
||||
'message' => $translations['erreur_generique'] ?? 'Erreur serveur.',
|
||||
], JSON_UNESCAPED_UNICODE);
|
||||
exit;
|
||||
}
|
||||
Reference in new issue
Block a user