<?php

$table = 'deliverer_offer';
//$id = 1;
include '../includes/functions.php';
include './Angebot_erstellen.php';
include './Offer_HTML_functions.php';
include './eingabeCheck.php';
if ($_SERVER["REQUEST_METHOD"] == "POST") {
    $id = $_POST["id"];
    if ($postOK) {
        try {
            create_Offer($table, $name, $contact, $eMail, $startCountry, $startVillage, $destCountry, $destVillage, reformDatetoDB($startDate), reformDatetoDB($endDate), $products, $id, $text);
            //TO DO leere.php ersetzen mit Auflistung der eingegebenen Daten
            header('Location: leere.php');
        } catch (Exception $e) {
            echo "Fehler beim Datenbankzugriff. Bitte dem Administrator Bescheid geben.";
        }
    }
}
include './create_Offer_allg_HTML.php';
     $statement .= setLimit($startAt, $rowsPerPage);
     echo "Zielland: " . $input1;
 } else {
     if ($_POST["filter"] == "filterDate") {
         if (isset($_GET["in1"])) {
             $input1 = $_GET["in1"];
         } else {
             $input1 = filterfunktion($_POST["filterStartDate"]);
         }
         if (isset($_GET["in2"])) {
             $input2 = $_GET["in2"];
         } else {
             $input2 = filterfunktion($_POST["filterEndDate"]);
         }
         if (validateDate($input1) || validateDate($input2)) {
             $statement = filterDatespan(reformDatetoDB($input1), reformDatetoDB($input2));
             $statement .= " GROUP BY id ";
             $entries = getDBEntryCount($statement);
             $statement .= setLimit($startAt, $rowsPerPage);
             echo "Angebot gültig zwischen " . $input1 . " und " . $input2;
         } else {
             $statement = filterNone();
             $statement .= " GROUP BY id ";
             $entries = getDBEntryCount($statement);
             $statement .= setLimit($startAt, $rowsPerPage);
             echo "Kein Filter gesetzt";
         }
     } else {
         if ($_POST["filter"] == "filterName") {
             if (isset($_GET["in1"])) {
                 $input1 = $_GET["in1"];