-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathajax_update_options.php
More file actions
60 lines (49 loc) · 1.66 KB
/
ajax_update_options.php
File metadata and controls
60 lines (49 loc) · 1.66 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
<?php
// Prevent any HTML error output
error_reporting(E_ALL);
ini_set('display_errors', 0);
header('Content-Type: application/json');
try {
require('requires/json_utilities.php');
session_start();
if ($_SERVER["REQUEST_METHOD"] !== "POST") {
throw new Exception('Méthode non autorisée');
}
$voyageId = $_POST['voyageId'] ?? null;
$options = json_decode($_POST['options'], true) ?? [];
if (!$voyageId) {
throw new Exception('ID voyage manquant');
}
// Récupérer toutes les options possibles pour le voyage
$dispos = recupererOptionsVoyage($voyageId);
$prixBase = recupererPrixVoyage($voyageId);
// Créer un tableau avec toutes les options
$optionsToutes = [];
$montantTotal = $prixBase;
$details = [];
foreach ($dispos as $nom => $prix) {
$optionsToutes[$nom] = in_array($nom, $options) ? "true" : "false";
if ($optionsToutes[$nom] === "true") {
$montantTotal += $prix;
$details[] = ['nom' => $nom, 'prix' => $prix];
}
}
// Mettre à jour la session et le panier
$_SESSION['montant_total'] = $montantTotal;
$_SESSION['options'] = $optionsToutes;
$_SESSION['options2'] = $optionsToutes;
modifierVoyagePanier($_SESSION['id'], $voyageId, $optionsToutes);
echo json_encode([
'success' => true,
'prixBase' => $prixBase,
'prixTotal' => $montantTotal,
'options' => $details
]);
} catch (Exception $e) {
http_response_code(500);
echo json_encode([
'success' => false,
'message' => $e->getMessage()
]);
}
?>