<?php
require_once 'Medienverwaltung.php';

try {
    $signatur   = strip_tags($_POST["signatur"]);
    $autor      = strip_tags($_POST["autor"]);
    $titel      = strip_tags($_POST["titel"]);
    $typ        = strip_tags($_POST["typ"]);
    $seitenzahl = strip_tags($_POST["seitenzahl"]);
    $spieldauer = strip_tags($_POST["spieldauer"]);
    
    //$basisdaten = "$signatur, $autor, $titel";
    switch ($typ) {
        case "B":
            //echo "<p>Folgendes Buch wurde eingegeben:</p>";
            //echo "<p>$basisdaten, $seitenzahl</p>";
            break;
        case "C":
            //echo "<p>Folgende CD wurde eingegeben:</p>";
            //echo "<p>$basisdaten, $spieldauer</p>";
            break;
        default:
            throw new Exception ("Unbekannter Medientyp: $typ");
    }
    $rc = checkMedium($signatur, $autor, $titel, $typ, $seitenzahl, $spieldauer);
    if ($rc !== true) exit ($rc);
    
    $rc = addMedium($signatur, $autor, $titel, $typ, $seitenzahl, $spieldauer);
    if ($rc != RC_OK) {
        header("Location: error_view.php?code=$rc");
        exit;
    }
    header("Location: show_media.php");
    exit;
}
catch (Throwable $t) {
    syslog(LOG_ERR, $t);
    header("Location: error_view.php?code=".RC_EXCEPTION);
    exit;
    
    //echo "Es ist eine Exception aufgetreten<br>";
    //echo $t->getMessage()."<br>";
}

?>