function displayAnswers($uid, $pid) { $currentAnswers = getAnswersForPuzzle($pid); $availableAnswers = getAvailableAnswers(); ?> <tr class='hideFromTest'> <td> <strong>Answers: <?php echo getAnswersForPuzzleAsList($pid); ?> </strong> <?php if (canChangeAnswers($uid) && ($currentAnswers != NULL || $availableAnswers != NULL)) { ?> <a href="#" class="changeLink">[Change]</a> </td> </tr> <tr> <td> <table> <form method="post" action="form-submit.php"> <input type="hidden" name="uid" value="<?php echo $uid; ?> " /> <input type="hidden" name="pid" value="<?php echo $pid; ?> " /> <tr> <?php if ($currentAnswers != NULL) { ?> <td> <p><strong>Remove Answer(s):</strong></p> <?php makeOptionElements($currentAnswers, 'removeAns'); ?> </td> <?php } if ($availableAnswers != NULL) { ?> <td> <p><strong>Add Answer(s):</strong></p> <?php makeOptionElements($availableAnswers, 'addAns'); ?> </td> <?php } ?> </tr> <tr> <td colspan="2"> <input type="submit" name="changeAnswers" value="Change Answers" /> </td> </tr> </form> </table> <?php } ?> </td> </tr> <?php }
function checkAnswer($pid, $attempt) { $actual = getAnswersForPuzzle($pid); if (!$actual) { return FALSE; } foreach ($actual as $a) { $answers = explode(',', $a); foreach ($answers as $ans) { if (strcasecmp(preg_replace("/[^a-zA-Z0-9]/", "", $attempt), preg_replace("/[^a-zA-Z0-9]/", "", $ans)) == 0) { $_SESSION['answer'] = $ans; return $ans; } } } return FALSE; }
function checkAnsForm($uid, $pid) { ?> <form method="post" action="form-submit.php"> Check an answer: <?php if (!getAnswersForPuzzle($pid)) { echo "<strong>Answer not in Puzzletron, so this will always reject your answer.</strong>"; } ?> <input type="hidden" name="pid" value="<?php echo $pid; ?> " /> <input type="hidden" name="uid" value="<?php echo $uid; ?> " /> <input type="input" name="ans" /> <input type="submit" name="checkAns" value="Check" /> </form> <?php }