'Méthode non autorisée.']); exit; } $isHttps = ( (!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] === 'on') || (!empty($_SERVER['SERVER_PORT']) && $_SERVER['SERVER_PORT'] === '443') || (!empty($_SERVER['HTTP_X_FORWARDED_PROTO']) && strtolower($_SERVER['HTTP_X_FORWARDED_PROTO']) === 'https') ); if (!$isHttps) { http_response_code(403); echo json_encode(['error' => 'Connexion non sécurisée.']); exit; } $contentType = $_SERVER['CONTENT_TYPE'] ?? ''; if (stripos($contentType, 'application/json') === false) { http_response_code(415); echo json_encode(['error' => 'Type de contenu non supporté.']); exit; } $payload = json_decode(file_get_contents('php://input'), true); if (!is_array($payload)) { http_response_code(400); echo json_encode(['error' => 'Corps JSON invalide.']); exit; } $date = $payload['date'] ?? null; $depart = $payload['depart'] ?? null; if (!is_string($date) || !preg_match('/^\d{4}-\d{2}-\d{2}$/', $date)) { http_response_code(400); echo json_encode(['error' => "Paramètre 'date' invalide (format YYYY-MM-DD requis)."]); exit; } if (!is_string($depart) || trim($depart) === '') { http_response_code(400); echo json_encode(['error' => "Paramètre 'depart' obligatoire."]); exit; } try { $sql = " SELECT VOYAGES.IDVOYAGES AS IDVOYAGES, VOYAGES.Date AS `DATE`, VOYAGES.Heure AS Heure, VOYAGES.Description AS Description, VOYAGES.NbrePlace AS NbrePlace, VOYAGES.Site AS Site, VOYAGES.IDVEHICULES AS IDVEHICULES, VOYAGES.IDAGENCES AS IDAGENCES, VOYAGES.Point AS Point, VOYAGES.IDPROFILE AS IDPROFILE, VOYAGES.Publier AS Publier, VOYAGES.Vehicule AS Vehicule, VOYAGES.Depart AS Depart, VOYAGES.Arrivee AS Arrivee, VOYAGES.Formalite AS Formalite, VOYAGES.Autre3 AS Autre3, VOYAGES.Autre2 AS Autre2 FROM VOYAGES WHERE VOYAGES.Date = :date AND VOYAGES.Enline = 1 AND VOYAGES.Depart LIKE :departLike ORDER BY `DATE` ASC "; $stmt = $pdo->prepare($sql); $stmt->bindValue(':date', $date, PDO::PARAM_STR); $stmt->bindValue(':departLike', '%' . $depart . '%', PDO::PARAM_STR); $stmt->execute(); $rows = $stmt->fetchAll(PDO::FETCH_ASSOC); $count = count($rows); header('X-Total-Count: ' . $count); if ($count === 0) { http_response_code(204); echo json_encode(['message' => 'Aucun voyage trouvé.']); exit; } echo json_encode($rows, JSON_UNESCAPED_UNICODE); } catch (PDOException $e) { http_response_code(500); echo json_encode(['error' => 'Erreur serveur : ' . $e->getMessage()]); } ////////////////////////////////////////////////////////////////////// 'Méthode non autorisée.']); exit; } // --- Vérification HTTPS --- $isHttps = ( (!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] === 'on') || (!empty($_SERVER['SERVER_PORT']) && $_SERVER['SERVER_PORT'] === '443') || (!empty($_SERVER['HTTP_X_FORWARDED_PROTO']) && strtolower($_SERVER['HTTP_X_FORWARDED_PROTO']) === 'https') ); if (!$isHttps) { http_response_code(403); echo json_encode(['error' => 'Connexion non sécurisée.']); exit; } // --- Vérification Content-Type --- $contentType = $_SERVER['CONTENT_TYPE'] ?? ''; if (stripos($contentType, 'application/json') === false) { http_response_code(415); echo json_encode(['error' => 'Type de contenu non supporté. Utilisez application/json.']); exit; } // --- Lecture des données JSON --- $payload = json_decode(file_get_contents('php://input'), true); if (!is_array($payload)) { http_response_code(400); echo json_encode(['error' => 'Corps JSON invalide.']); exit; } $depart = $payload['depart'] ?? null; $arrivee = $payload['arrivee'] ?? null; // --- Validation --- if (!is_string($depart) || trim($depart) === '') { http_response_code(400); echo json_encode(['error' => "Paramètre 'depart' obligatoire."]); exit; } if (!is_string($arrivee) || trim($arrivee) === '') { http_response_code(400); echo json_encode(['error' => "Paramètre 'arrivee' obligatoire."]); exit; } try { $sql = " SELECT TARIFPARCOURS.Depart AS Depart, TARIFPARCOURS.Arrivee AS Arrivee, TARIFPARCOURS.Prix AS Prix, TARIFPARCOURS.PrixEnfant AS PrixEnfant, TARIFPARCOURS.PrixAssurance AS PrixAssurance FROM TARIFPARCOURS WHERE TARIFPARCOURS.Depart = :depart AND TARIFPARCOURS.Arrivee = :arrivee "; $stmt = $pdo->prepare($sql); $stmt->bindValue(':depart', $depart, PDO::PARAM_STR); $stmt->bindValue(':arrivee', $arrivee, PDO::PARAM_STR); $stmt->execute(); $rows = $stmt->fetchAll(PDO::FETCH_ASSOC); $count = count($rows); header('X-Total-Count: ' . $count); if ($count === 0) { http_response_code(204); echo json_encode(['message' => 'Aucun tarif trouvé.']); exit; } echo json_encode($rows, JSON_UNESCAPED_UNICODE); } catch (PDOException $e) { http_response_code(500); echo json_encode(['error' => 'Erreur serveur : ' . $e->getMessage()]); } /////////////////////////////////////////////////////////// 'Méthode non autorisée.']); exit; } // --- Vérification HTTPS --- $isHttps = ( (!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] === 'on') || (!empty($_SERVER['SERVER_PORT']) && $_SERVER['SERVER_PORT'] === '443') || (!empty($_SERVER['HTTP_X_FORWARDED_PROTO']) && strtolower($_SERVER['HTTP_X_FORWARDED_PROTO']) === 'https') ); if (!$isHttps) { http_response_code(403); echo json_encode(['error' => 'Connexion non sécurisée.']); exit; } // --- Vérification Content-Type --- $contentType = $_SERVER['CONTENT_TYPE'] ?? ''; if (stripos($contentType, 'application/json') === false) { http_response_code(415); echo json_encode(['error' => 'Type de contenu non supporté. Utilisez application/json.']); exit; } // --- Lecture des données JSON --- $payload = json_decode(file_get_contents('php://input'), true); if (!is_array($payload)) { http_response_code(400); echo json_encode(['error' => 'Corps JSON invalide.']); exit; } $destination = $payload['destination'] ?? null; // --- Validation --- if (!is_string($destination) || trim($destination) === '') { http_response_code(400); echo json_encode(['error' => "Paramètre 'destination' obligatoire."]); exit; } try { $sql = " SELECT POINTS.IDPOINTS AS IDPOINTS, POINTS.Description AS Description, POINTS.EnLigne AS EnLigne FROM DESTINATION, POINTS WHERE POINTS.IDDESTINATION = DESTINATION.IDDESTINATION AND POINTS.Archiver = 0 AND POINTS.EnLigne = 1 AND DESTINATION.Description = :destination "; $stmt = $pdo->prepare($sql); $stmt->bindValue(':destination', $destination, PDO::PARAM_STR); $stmt->execute(); $rows = $stmt->fetchAll(PDO::FETCH_ASSOC); $count = count($rows); header('X-Total-Count: ' . $count); if ($count === 0) { http_response_code(204); echo json_encode(['message' => 'Aucun site d’arrivée trouvé.']); exit; } echo json_encode($rows, JSON_UNESCAPED_UNICODE); } catch (PDOException $e) { http_response_code(500); echo json_encode(['error' => 'Erreur serveur : ' . $e->getMessage()]); }