<?php

include_once '../bootstrap.php';
use Models\LoginManager;
use Models\ImageManager;
LoginManager::startSessionAndRedirectIfNotLoggedIn();
$auctionID = (int) $_REQUEST['id'];
if ($auctionID) {
    $imageManager = new ImageManager();
    $imageDetail = $imageManager->getImage($auctionID);
    $imageType = $imageDetail['imageType'];
    $imageData = $imageDetail['imageData'];
    header("Content-type:", $imageType);
    echo $imageData;
}
 $item_condition = $_POST['item_condition'];
 $start_price = $_POST['start_price'];
 $reserve_price = $_POST['reserve_price'];
 $start_date = $_POST['start_date'];
 $start_time = $_POST['start_time'];
 $end_date = $_POST['end_date'];
 $end_time = $_POST['end_time'];
 $fileName = $_FILES['userfile']['name'];
 //image name
 $tmpName = $_FILES['userfile']['tmp_name'];
 // data
 $fileSize = $_FILES['userfile']['size'];
 $fileType = $_FILES['userfile']['type'];
 $categories = $_POST['category'];
 $auctionManager = new AuctionManager();
 $imageManager = new ImageManager();
 $imageAuctionID = -1;
 if ($tmpName != null) {
     $imageID = $imageManager->uploadImage($tmpName, $fileType);
     \Models\Logger::log($imageID);
     if ($imageID > 0) {
         $auctionID = $auctionManager->createNewItem($title, $description, $item_condition, $start_price, $reserve_price, $start_date, $start_time, $end_date, $end_time, $categories);
         if ($auctionID > 0) {
             $imageAuctionID = $auctionManager->registerImage($auctionID, $imageID);
             \Models\Logger::log($imageAuctionID);
         }
     }
 }
 if ($imageAuctionID > 0) {
     $auctionDetail = $auctionManager->getAuctionDetail($auctionID);
     $uploadSuccessView = new UploadSuccessView($auctionDetail);