prepare($sql); $stmt->execute([ "game_id" => $_GET["game"], "member_id" => $_SESSION["account"]->id, ]); $HAS_SUBMISSION = $stmt->fetch(PDO::FETCH_COLUMN) !== false; if ($HAS_SUBMISSION) { http_response_code(303); header("Location: /games/" . $_GET["game"] . "/update"); die(); } $sql = "SELECT id, name, status_id FROM games WHERE id = :id"; $stmt = $db["data"]->prepare($sql); $stmt->execute([ "id" => $_GET["game"], ]); $game = $stmt->fetch(PDO::FETCH_OBJ); $title = "Submit: {$game->name}"; $description = "Enter a work into the " . $game->name . " vote."; } if ($_SERVER["REQUEST_METHOD"] === "POST"): $stmt = $db["data"]->prepare("SELECT id FROM games WHERE id = :id"); $stmt->execute([ "id" => $_GET["game"], ]); $game_id = $stmt->fetch(PDO::FETCH_COLUMN) ?? false; $errors = []; $RULES_FOLLOWED = isset($_POST["agree-toc"]) && $_POST["agree-toc"] === "1" && (isset($_POST["agree-guidelines"]) && $_POST["agree-guidelines"] === "1"); if (!$RULES_FOLLOWED) { http_response_code(400); $errors["agreements"] = "Please accept the Terms & Conditions and the Submission Guidelines."; } if ($_FILES["manuscript"]["size"] === 0) { http_response_code(400); $errors["filesize"] = "A file upload is required."; } elseif ($_FILES["manuscript"]["size"] > UPLOAD_MAX_FILESIZE) { http_response_code(400); $errors["filesize"] = "Your document is too large."; } else { $finfo = finfo_open(FILEINFO_MIME_TYPE); $mime_type = finfo_file($finfo, $_FILES["manuscript"]["tmp_name"]); finfo_close($finfo); $PROPER_MIMETYPE = $mime_type === "application/pdf"; } if (isset($PROPER_MIMETYPE) && !$PROPER_MIMETYPE) { http_response_code(400); $errors["mimetype"] = "Only PDF submissions are allowed."; } if (!isset($_POST["title"]) || !trim($_POST["title"])) { http_response_code(400); $errors["title"] = "Please enter a title."; } if (!isset($_SESSION["account"]) && !isset($_SESSION["account"]->id)) { http_response_code(500); $errors["account"] = "We can't upload a document without knowing which account it belongs to."; } if (!$game_id) { http_response_code(400); $errors["game"] = "The chosen game doesn't exist."; } if (!isset($_POST["tx-id"])) { $errors["payment"] = "No transaction ID was provided."; } if (count($errors) > 0) { if (!isset($errors["filesize"]) && !isset($errors["mimetype"])) { $errors["upload"] = "Fix all other errors and choose your file again."; } } else { $new_basename = md5(microtime() . $game_id . $_SESSION["account"]->id) . ".pdf"; $lookup_hash = md5( $_SESSION["account"]->id . $game_id . microtime() . "salt" ); $file_destination = sprintf( "%s/%s/%s", DIRECTORY_DOCS, $game_id, $new_basename ); try { $file_moved = move_uploaded_file( $_FILES["manuscript"]["tmp_name"], $file_destination ); if ($file_moved) { $show_doc = isset($_POST["public-doc"]) ? 1 : 0; $show_name = isset($_POST["public-name"]) ? 1 : 0; $stmt = $db["data"] ->prepare("INSERT INTO submissions (member_id, game_id, title, basename, hash, doc_is_public, name_is_public, transaction_id, status, is_freeroll, created_at) VALUES (:member_id, :game_id, :title, :basename, :hash, :doc_is_public, :name_is_public, :transaction_id, :status, :is_freeroll, :created_at)"); $stmt->execute([ "member_id" => $_SESSION["account"]->id, "game_id" => $_GET["game"], "title" => $_POST["title"], "basename" => "$new_basename", "hash" => $lookup_hash, "doc_is_public" => $show_doc, "name_is_public" => $show_name, "transaction_id" => $_POST["tx-id"], "status" => 1, "is_freeroll" => 0, "created_at" => date("Y-m-d\TH:i:s\Z"), ]); http_response_code(303); header("Location: /games/" . $_GET["game"]); } } catch (Exception $e) { http_response_code(500); unlink($file_destination); $errors["upload"] = "There was an error adding your submission to our database. Please try again."; } } endif; include "partials/head.php"; ?>

" method="post" enctype="multipart/form-data" class="flow">

Manuscript details
Privacy settings
Payment

Payment is required before a submission will be processed.

Payment successful! (Transaction ID: )