This repository has been archived by the owner on Feb 21, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 11
/
answers.php
154 lines (142 loc) · 4.91 KB
/
answers.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
<?php // vim:set ts=4 sw=4 sts=4 et:
require_once "config.php";
require_once "html.php";
require_once "db-func.php";
require_once "utils.php";
// Redirect to the login page, if not logged in
$uid = isLoggedIn();
// Start HTML
head("answers", "Answers");
// Check for answers permissions
if (!canChangeAnswers($uid) && !hasApproverPermission($uid)) {
echo "<div class='errormsg'>You do not have permission for this page.</div>";
foot();
exit(1);
}
if (isset($_POST['newAnswer'])) {
$result = submitAnswersForm(strtoupper($_POST['newAnswer']), $_POST['round']);
if ($result == FALSE) {
echo '<div class="errormsg">Error in submitting new answer</div>';
}
}
if (isset($_POST['newRound'])) {
$result = submitNewRound($_POST['newRound'], strtoupper($_POST['roundAnswer']));
if ($result == FALSE) {
echo '<div class="errormsg">Error in submitting new round</div>';
}
}
if (isset($_POST['deleteAnswer'])) {
$result = submitDeleteAnswer($_POST['deleteAnswer']);
if ($result == FALSE) {
echo '<div class="errormsg">Error in deleting answer</div>';
}
}
displayAnswers($uid);
// End HTML
foot();
//------------------------------------------------------------------------
function displayAnswers($uid) {
$rounds = getRounds();
if (!$rounds) {
?>
<span class="emptylist">No rounds to list</span>
<?php
}
foreach ($rounds as $round) {
$answers = getAnswersForRound($round['rid']);
?>
<table class="boxed">
<tr><th colspan="7"><b><?php echo "{$round['name']}: {$round['answer']}"; ?></b></th></tr>
<tr>
<td></td>
<td><b>Answer</b></td>
<td><b>ID</b></td>
<td><b>Title</b></td>
<td><b>Status</b></td>
<td><b>Editor Notes</b></td>
<td><b>Status Notes</b></td>
</tr>
<?php
if (!$answers) {
?>
<tr><td colspan="6"><span class="emptylist">No answers added yet</span></td></tr>
<?php
}
foreach ($answers as $answer) {
$pid = $answer['pid'];
?>
<tr>
<td>
<?php
if (!$pid) {
?>
<form method="post" action="answers.php" />
<input type="hidden" name="deleteAnswer" value='<?php echo $answer['aid']; ?>'/>
<input type="submit" value="Delete" />
</form>
<?php
}
?>
</td>
<td><?php echo $answer['answer'] ?></td>
<td><?php echo ($pid ? "<a href=\"puzzle.php?pid=$pid\">".$pid."</a>" : "unassigned") ?></td>
<td><?php echo ($pid ? getTitle($pid) : "") ?></td>
<td><?php echo ($pid ? getStatusNameForPuzzle($pid) : "") ?></td>
<td><?php echo ($pid ? getEditorNotes($pid) : "") ?></td>
<td><?php echo ($pid ? getNotes($pid) : "") ?></td>
</tr>
<?php
}
?>
<tr>
<form method="post" action="answers.php" />
<td colspan="2"><input type="text" name="newAnswer" />
<input type="hidden" name="round" value='<?php echo $round['rid']; ?>'/></td>
<td colspan="5"><input type="submit" value='Add Answer For Round <?php echo ($round['rid']); ?>' /></td></form>
</tr>
</table>
<br />
<?php
}
?>
<table class="boxed">
<tr><th colspan="3"><b>New Round</b></th></tr>
<tr>
<td>Round Name</td><td>Meta Answer Word</td><td></td>
</tr>
<tr>
<form method="post" action="answers.php" />
<td><input type="text" name="newRound" /></td>
<td><input type="text" name="roundAnswer" /></td>
<td><input type="submit" value="Add New Round" /></td></form>
</tr>
</table>
<?php
}
function submitAnswersForm($newAnswer, $round) {
if ($newAnswer == "") {
echo("<div class='errormsg'>Blank Answer is unacceptable. Try again</div>\n");
return FALSE;
}
createAnswer($newAnswer, $round);
printf("<div class='okmsg'>Added new Answer: %s for Round %s</div>\n", htmlspecialchars($newAnswer), $round);
return TRUE;
}
function submitNewRound($roundname, $roundanswer) {
if ($roundname == "") {
printf("<div class='errormsg'>Blank Round Name is unacceptable. Try again</div>\n");
return FALSE;
}
if ($roundanswer == "") {
printf("<div class='errormsg'>Blank Round Answer is unacceptable. Try again</div>\n");
return FALSE;
}
createRound ($roundname, $roundanswer);
printf("<div class='okmsg'>Added new Round: %s with meta answer: %s</div>\n", htmlspecialchars($roundname), htmlspecialchars($roundanswer));
return TRUE;
}
function submitDeleteAnswer($aid) {
deleteAnswer ($aid);
printf("<div class='okmsg'>Deleted Answer</div>\n");
return TRUE;
}