<?php

require "../header.php";

define("FAILED", true);

$data = array();
$data["error"] = false;
$data["message"] = "";

function sendResponse($error = false, $message = "") {
   global $data;
   $data["error"] = $error;
   if ( $error ) $data["message"] = $message;
   header('Content-Type: application/json');
   echo json_encode($data);
   exit();
}

if ( !$_SESSION["validated"] ) sendResponse(FAILED, "Login Required");

if ( !isset($_REQUEST["id"]) ) {
   sendResponse(FAILED, "Invalid Request");
}

$id = intval($_REQUEST["id"]);
if ( $id <= 0 ) sendResponse(FAILED, "Invalid Image Reference");
$image = new MTGImage($id);
if ( $image->getId() == 0 ) sendResponse(FAILED, "Unknown Image Reference");
$data["filename"] = $image->getFileName();

if ( !$image->delete() ) {
   sendResponse(FAILED, "Could not delete card!");
}

sendResponse();

// vim:ts=3 sw=3 et:
