<?php
session_start();
require_once '../model/LocalArticleManager.php';
require_once '../model/ArticleManager.php';

if ($_SERVER["REQUEST_METHOD"] === "GET") {
    if(!isset($_GET["q"])){
        $_SESSION["message"] = "missing_parameters";
        header("location: ../../index.php?pfad=search-results");
    } else {

        $search = trim($_GET["q"]);

        try {
            $articleManager = ArticleManager::getInstance();
            $results = $articleManager->search($search);

            $_SESSION["search_results"] = $results;
            $_SESSION["search_query"] = $search;
            $_SESSION["search_status"] = "new_search_results";
        } catch (Exception $e){
            $_SESSION["search_status"] = "internal_error";
        }
        $_SESSION["search_status"] = "new_search_results";
        // Weiterleitung zur Suchergebnisanzeige
        header("location: ../../index.php?pfad=search-results");
        exit();

    }
}

?>