<?PHP

if (!CheckAuthorization(PRIV_RESOURCEADMIN, PRIV_MYRESOURCEADMIN, PRIV_RELEASEADMIN)) {  return;  }

$DB = new Database();

if (isset($_GET["Id"]) && isset($_GET["A"]))
{
    $ResourceId = intval($_GET["Id"]);
    $Action = $_GET["A"];

    if ($Action == "Approve" )
    {
        $Resource = new Resource($ResourceId);

        $ImageId = $DB->Query("SELECT ImageId FROM AutoScreenshotApprovalQueue "
                              ."WHERE ResourceId=".$ResourceId,"ImageId");

        $Resource->Set("Screenshot", $ImageId);

        $DB->Query("DELETE FROM AutoScreenshotApprovalQueue "
                   ."WHERE ResourceId=".$ResourceId);
    }
    elseif ($Action == "Retry" )
    {
        $ImageId = $DB->Query("SELECT ImageId FROM AutoScreenshotApprovalQueue "
                              ."WHERE ResourceId=".$ResourceId,"ImageId");

        if ($ImageId !== NULL)
        {
            $ThisImage = new SPTImage($ImageId);
            $ThisImage->Delete();
        }

        $DB->Query("DELETE FROM AutoScreenshotApprovalQueue "
                   ."WHERE ResourceId=".$ResourceId);
        $DB->Query("DELETE FROM AutoScreenshotFailures "
                   ."WHERE ResourceId=".$ResourceId);
    }
    elseif ($Action == "Blacklist")
    {
        $ImageId = $DB->Query("SELECT ImageId FROM AutoScreenshotApprovalQueue "
                              ."WHERE ResourceId=".$ResourceId,"ImageId");

        if ($ImageId !== NULL)
        {
            $ThisImage = new SPTImage($ImageId);
            $ThisImage->Delete();
        }

        $DB->Query("DELETE FROM AutoScreenshotApprovalQueue "
                   ."WHERE ResourceId=".$ResourceId);
        $DB->Query("DELETE FROM AutoScreenshotFailures "
                   ."WHERE ResourceId=".$ResourceId);
        $DB->Query("INSERT INTO AutoScreenshotBlacklist (ResourceId) "
                   ."VALUES (".$ResourceId.")");
    }
    elseif ($Action == "Deblacklist")
    {
        $DB->Query("DELETE FROM AutoScreenshotBlacklist "
                   ."WHERE ResourceId=".$ResourceId);
    }
}

if (!isset($_GET["Ajax"]))
{
    global $AF;
    $AF->SetJumpToPage("P_AutoScreenshot_ApprovalQueue");
}

?>