function checkDeckAuth($event, $player, $deck = NULL) { if (!Player::isLoggedIn()) { loginRequired(); return false; } $loginname = Player::loginName(); if (is_null($deck)) { // Creating a deck. $entry = new Entry($event, $player); $auth = $entry->canCreateDeck($loginname); } else { // Updating a deck. $auth = $deck->canEdit($loginname); } if ($auth) { return true; } else { authFailed(); } return false; }
function deckForm($deck = NULL) { $mode = is_null($deck) ? "Create Deck" : "Update Deck"; if (!is_null($deck)) { $player = $deck->playername; $event = $deck->eventname; } else { $player = isset($_POST['player']) ? $_POST['player'] : $_GET['player']; $event = isset($_POST['player']) ? $_POST['event'] : $_GET['event']; } $auth = false; if (is_null($deck)) { // Creating a deck. $entry = new Entry($event, $player); $auth = $entry->canCreateDeck($_SESSION['username']); } else { // Updating a deck. $auth = $deck->canEdit($_SESSION['username']); } if (!$auth) { authFailed(); return; } $vals = array(); if (!is_null($deck)) { foreach ($deck->maindeck_cards as $card => $amt) { $line = $amt . " " . $card . "\n"; $vals['contents'] = $vals['contents'] . $line; } foreach ($deck->sideboard_cards as $card => $amt) { $line = $amt . " " . $card . "\n"; $vals['sideboard'] = $vals['sideboard'] . $line; } $vals['desc'] = $deck->notes; $vals['archetype'] = $deck->archetype; $vals['name'] = $deck->name; } echo "<form action=\"deck.php\" method=\"post\">\n"; echo "<table align=\"center\" style=\"border-width: 0px;\">\n"; echo "<tr><td valign=\"top\"><b>Directions:</td>\n"; echo "<td style=\"color: #000000\">To enter your deck, please give it "; echo "a name and select an archetype from the drop-down menu below. If "; echo "you do not specify and archetype, your deck will be labeled as "; echo "\"rogue.\" To enter cards, save your deck a a .txt file using the "; echo "official MTGO client, and then copy and paste the maindeck and "; echo "sideboard into the appropriate text boxes. "; echo "<font color=\"#FF0000\">Do not use a format such as \"1x Card\". "; echo "The parser will not accept this structure. The correct pattern is "; echo "\"1 Card\".</font></td></tr>\n"; echo "<tr><td> </td></tr>\n"; echo "<tr><td><b>Name</td>\n<td>"; echo "<input type=\"text\" name=\"name\" value=\"{$vals['name']}\" "; echo "size=\"40\"></td></tr>\n"; if (!is_null($deck)) { echo "<input type=\"hidden\" name=\"id\" value=\"{$deck->id}\">\n"; } echo "<tr><td><b>Archetype</td>\n<td>"; archetypeDropMenu($vals['archetype']); echo "</td></tr>\n"; echo "<tr><td valign=\"top\"><b>Main Deck</td>\n<td>"; echo "<textarea rows=\"20\" cols=\"60\" name=\"contents\">"; echo "{$vals['contents']}</textarea></td></tr>\n"; echo "<tr><td valign=\"top\"><b>Sideboard</td>\n<td>"; echo "<textarea rows=\"10\" cols=\"60\" name=\"sideboard\">"; echo "{$vals['sideboard']}</textarea></td></tr>\n"; //echo "<tr><td valign=\"top\"><b>Comments</td>\n<td>"; //echo "<textarea rows=\"10\" cols=\"60\" name=\"notes\">"; //echo "{$vals['desc']}</textarea></td></tr>\n"; echo "<tr><td> </td></tr>\n"; echo "<tr><td colspan=\"2\" align=\"center\">\n"; echo "<input type=\"submit\" name=\"mode\" value=\"{$mode}\">\n"; echo "<input type=\"hidden\" name=\"player\" value=\"{$player}\">"; echo "<input type=\"hidden\" name=\"event\" value=\"{$event}\">"; echo "</td></tr></table></form>\n"; }