<?php include_once '../database/connection.php'; include_once '../database/events.php'; $title = 'Search results'; include_once '../templates/header.php'; if (!isset($_SESSION['userId'])) { header('Location: ../index.php'); } $result = searchEvents($_GET['query']); include_once '../templates/event_list.php'; include_once '../templates/footer.php';
function searchController() { $contents['types'] = getTypes(); if (!empty($_POST)) { // On est arrivé en postant un formulaire require MODELES . 'events/searchEvents.php'; if (isset($_POST['searchType']) && (isset($_POST['searchKeywords']) || isset($_POST['searchPlace']) || isset($_POST['searchDate']))) { // On est arrivé en postant le form de la page d'accueil //NB : searchType = menu déroulant sur la gauche de la recherche condensée de l'accueil switch ($_POST['searchType']) { case "place": $results = searchEvents($_POST['searchPlace'], ['adresse']); $contents['previousSearch'] = $_POST['searchPlace']; break; case "date": $results = []; break; case "keywords": default: $results = searchEvents($_POST['searchKeywords']); $contents['previousSearch'] = $_POST['searchKeywords']; break; } // Charger le bon champ avec la bonne valeur // Afficher les résultats } else { // On est arrivé en postant le form de la page de recherche avancée // On traite la recherche : $criteres = []; if (isset($_POST['criteres_all']) && $_POST['criteres_all']) { $criteres = []; } else { if (isset($_POST['criteres_nom']) && $_POST['criteres_nom']) { $criteres[] = 'nom'; } if (isset($_POST['criteres_lieu']) && $_POST['criteres_lieu']) { $criteres[] = 'adresse'; } if (isset($_POST['criteres_description']) && $_POST['criteres_description']) { $criteres[] = 'description'; } if (isset($_POST['criteres_type']) && $_POST['criteres_type']) { $criteres[] = 'type'; } } $results = searchEvents($_POST['keywords'], $criteres); $contents['previousSearch'] = $_POST['keywords']; } // echo '<pre>'; // var_dump($results); // echo '</pre>'; // On prépare pour affichage les résultats de recherche : if ($results) { $results = detailsToStrings($results); // Afficher les résultats $contents['searchResults'] = $results; } else { } } else { // On n'a pas encore posté de formulaire } // Préparation et appel de la vue : $title = 'Recherche d\'évènements'; $styles = ['form.css', 'prettyform.css', 'search_v2.css', 'eventPreview.css']; $blocks = ['searchForm', 'search']; $scripts = ['searchForm.js', 'filter.js']; vue($blocks, $styles, $title, $contents, $scripts); }
<tr> <td colspan="3" align="left"> <?php $bysport = cleanInput($_GET['sport']); $byzip = cleanInput($_GET['zip']); $bylocation = cleanInput($_GET['location']); if ($bysport || $byzip || $bylocation) { echo "<hr /><b><center>RESULTS</center></b><hr />"; if ($bysport) { echo searchEvents("sport", $bysport); } else { if ($byzip) { echo searchEvents("zip", $byzip); } else { if ($bylocation) { echo searchEvents("location", $bylocation); } else { echo "<b>NO RESULTS</b>"; } } } } ?> </td> </tr> </table> </div> </div> </div> <!-- end #content --> <div id="sidebar">
require_once __DIR__ . "/../config.php"; require_once TEMPLATES_PATH . "/utils.php"; require_once INCLUDES_PATH . "/authentication.php"; require_once DATABASE_PATH . "/events.php"; require_once TEMPLATES_PATH . "/view_event_brief.php"; try { if (!isset($_POST["query"])) { http_response_code(400); showError('Query missing.'); } else { if (!isUserLoggedIn()) { http_response_code(403); showError('You need to login to search for events.'); } else { $time = microtime(true); $events = searchEvents(addslashes($_POST["query"]), getUserID()); $time = microtime(true) - $time; $time = sprintf('%0.5f', $time); $numEvents = count($events); if ($numEvents === 0) { showError("No matching events found. Search took " . $time . " seconds."); } else { showSuccess("Found " . $numEvents . " entr" . ($numEvents == 1 ? "y" : "ies") . " in " . $time . " seconds."); foreach ($events as $event) { showEventBrief($event["id"]); } } } } } catch (Exception $e) { showError($e->getMessage());