<?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, "Bad Request");
$id = intval($_REQUEST['id']);
if ( $id < 1 ) sendResponse(FAILED, "Bad Image Reference");
$image = new MTGImage($id);
if ( $image->getId() == 0 ) sendResponse(FAILED, "Unknown Image");

$image->setEnabled(!$image->getEnabled());
$image->save();
$data["image"] = $image;
sendResponse();
exit();

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