forked from kohler/hotcrp
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathoffline.php
More file actions
233 lines (202 loc) · 9.53 KB
/
offline.php
File metadata and controls
233 lines (202 loc) · 9.53 KB
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
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
<?php
// offline.php -- HotCRP offline review management page
// Copyright (c) 2006-2019 Eddie Kohler; see LICENSE.
require_once("src/initweb.php");
if (!$Me->email)
$Me->escape();
$rf = $Conf->review_form();
// general error messages
if ($Qreq->post && $Qreq->post_empty())
$Conf->post_missing_msg();
// download blank review form action
if (isset($Qreq->downloadForm)) {
$text = $rf->textFormHeader("blank") . $rf->textForm(null, null, $Me, null) . "\n";
downloadText($text, "review");
}
// upload review form action
if (isset($Qreq->uploadForm)
&& $Qreq->has_file("uploadedFile")
&& $Qreq->post_ok()) {
$tf = ReviewValues::make_text($rf, $Qreq->file_contents("uploadedFile"),
$Qreq->file_filename("uploadedFile"));
while ($tf->parse_text($Qreq->override))
$tf->check_and_save($Me, null, null);
$tf->report();
// Uploading forms may have completed the reviewer's task; recheck roles.
Contact::update_rights();
} else if (isset($Qreq->uploadForm))
Conf::msg_error("Choose a file first.");
// upload tag indexes action
function saveTagIndexes($tag, $filename, &$settings, &$titles, &$linenos, &$errors) {
global $Conf, $Me;
foreach ($Me->paper_set(array_keys($settings)) as $row) {
if ($settings[$row->paperId] !== null
&& !$Me->can_change_tag($row, $tag, null, 1)) {
$errors[$linenos[$row->paperId]] = "You cannot rank paper #$row->paperId.";
unset($settings[$row->paperId]);
} else if ($titles[$row->paperId] !== ""
&& strcmp($row->title, $titles[$row->paperId]) != 0
&& strcasecmp($row->title, simplify_whitespace($titles[$row->paperId])) != 0)
$errors[$linenos[$row->paperId]] = "Warning: Title doesn’t match.";
}
if (!$tag)
$errors["0tag"] = "Tag missing.";
else if (count($settings)) {
$x = array("paper,tag,lineno");
foreach ($settings as $pid => $value)
$x[] = "$pid,$tag#" . ($value === null ? "clear" : $value) . "," . $linenos[$pid];
$assigner = new AssignmentSet($Me);
$assigner->parse(join("\n", $x) . "\n", $filename);
$assigner->report_errors();
$assigner->execute();
}
$settings = $titles = $linenos = array();
}
function check_tag_index_line(&$line) {
if ($line && count($line) >= 2
&& preg_match('/\A\s*(|[Xx=]|>*|\(?([-+]?\d+)\)?)\s*\z/', $line[0], $m1)
&& preg_match('/\A\s*(\d+)\s*\z/', $line[1], $m2)) {
$line[0] = isset($m1[2]) && $m1[2] !== "" ? $m1[2] : $m1[1];
$line[1] = $m2[1];
return true;
} else
return false;
}
function setTagIndexes($qreq) {
global $Conf, $Me;
$filename = null;
if (isset($qreq->upload) && $qreq->has_file("file")) {
if (($text = $qreq->file_contents("file")) === false) {
Conf::msg_error("Internal error: cannot read file.");
return;
}
$filename = $qreq->file_filename("file");
} else if (!($text = $qreq->data)) {
Conf::msg_error("Choose a file first.");
return;
}
$RealMe = $Me;
$tagger = new Tagger($Me);
if (($tag = $qreq->tag))
$tag = $tagger->check($tag, Tagger::NOVALUE);
$curIndex = 0;
$lineno = 1;
$settings = $titles = $linenos = $errors = array();
$csvp = new CsvParser("", CsvParser::TYPE_GUESS);
foreach (explode("\n", rtrim(cleannl($text))) as $l) {
if (substr($l, 0, 4) == "Tag:" || substr($l, 0, 6) == "# Tag:") {
if (!$tag)
$tag = $tagger->check(trim(substr($l, ($l[0] == "#" ? 6 : 4))), Tagger::NOVALUE);
} else if (trim($l) !== "" && $l[0] !== "#") {
$csvp->unshift($l);
$line = $csvp->next_array();
if ($line && check_tag_index_line($line)) {
if (isset($settings[$line[1]]))
$errors[$lineno] = "Paper #$line[1] already given on line " . $linenos[$line[1]];
if ($line[0] === "X" || $line[0] === "x")
$settings[$line[1]] = null;
else if ($line[0] === "" || $line[0] === ">")
$settings[$line[1]] = $curIndex = $curIndex + 1;
else if (is_numeric($line[0]))
$settings[$line[1]] = $curIndex = intval($line[0]);
else if ($line[0] === "=")
$settings[$line[1]] = $curIndex;
else
$settings[$line[1]] = $curIndex = $curIndex + strlen($line[0]);
$titles[$line[1]] = trim(get($line, 2, ""));
$linenos[$line[1]] = $lineno;
} else
$errors[$lineno] = "Syntax error";
}
++$lineno;
}
if (count($settings) && $Me)
saveTagIndexes($tag, $filename, $settings, $titles, $linenos, $errors);
$Me = $RealMe;
if (count($errors)) {
ksort($errors);
foreach ($errors as $lineno => &$error) {
if ($filename && $lineno)
$error = '<span class="lineno">' . htmlspecialchars($filename) . ':' . $lineno . ':</span> ' . $error;
else if ($filename)
$error = '<span class="lineno">' . htmlspecialchars($filename) . ':</span> ' . $error;
}
Conf::msg_error('<div class="parseerr"><p>' . join("</p>\n<p>", $errors) . '</p></div>');
} else if (isset($qreq->setvote)) {
$Conf->confirmMsg("Votes saved.");
} else {
$dtag = $tagger->unparse($tag);
$Conf->confirmMsg('Ranking saved. To view it, <a href="' . hoturl("search", "q=" . urlencode("editsort:#{$dtag}")) . '">search for “editsort:#' . $dtag . '”</a>.');
}
}
if ((isset($Qreq->setvote) || isset($Qreq->setrank))
&& $Me->is_reviewer()
&& $Qreq->post_ok())
setTagIndexes($Qreq);
$pastDeadline = !$Conf->time_review(null, $Me->isPC, true);
if (!$Conf->time_review_open() && !$Me->privChair) {
Conf::msg_error("The site is not open for review.");
go(hoturl("index"));
}
$Conf->header("Offline reviewing", "offline");
if ($Me->is_reviewer()) {
if (!$Conf->time_review_open())
$Conf->infoMsg("The site is not open for review.");
$Conf->infoMsg("Use this page to download a blank review form, or to upload review forms you’ve already filled out.");
if (!$Me->can_clickthrough("review")) {
echo '<div class="js-clickthrough-container">';
PaperTable::echo_review_clickthrough();
echo '</div>';
}
} else
$Conf->infoMsg("You aren’t registered as a reviewer or PC member for this conference, but for your information, you may download the review form anyway.");
echo '<table id="offlineform">';
// Review forms
echo "<tr><td><h3>Download forms</h3>\n<div>";
if ($Me->is_reviewer()) {
echo '<a href="', hoturl("search", "fn=get&getfn=revform&q=&t=r&p=all"), '">Your reviews</a><br>', "\n";
if ($Me->has_outstanding_review())
echo '<a href="', hoturl("search", "fn=get&getfn=revform&q=&t=rout&p=all"), '">Your incomplete reviews</a><br>', "\n";
echo '<a href="', hoturl("offline", "downloadForm=1"), '">Blank form</a></div>
<hr class="g">
<span class="hint"><strong>Tip:</strong> Use <a href="', hoturl("search", "q="), '">Search</a> > Download to choose individual papers.</span>', "\n";
} else
echo '<a href="', hoturl("offline", "downloadForm=1"), '">Blank form</a></div>', "\n";
echo "</td>\n";
if ($Me->is_reviewer()) {
$disabled = ($pastDeadline && !$Me->privChair ? " disabled" : "");
echo "<td><h3>Upload filled-out forms</h3>\n",
Ht::form(hoturl_post("offline", "uploadForm=1")),
Ht::hidden("postnonempty", 1),
'<input type="file" name="uploadedFile" accept="text/plain" size="30"', $disabled, '> ',
Ht::submit("Go", array("disabled" => !!$disabled));
if ($pastDeadline && $Me->privChair)
echo "<br />", Ht::checkbox("override"), " ", Ht::label("Override deadlines");
echo '<br><span class="hint"><strong>Tip:</strong> You may upload a file containing several forms.</span>';
echo "</form></td>\n";
}
echo "</tr>\n";
// Ranks
if ($Conf->setting("tag_rank") && $Me->is_reviewer()) {
$ranktag = $Conf->setting_data("tag_rank");
echo '<tr><td><hr class="g"></td></tr>', "\n",
"<tr><td><h3>Download ranking file</h3>\n<div>";
echo "<a href=\"", hoturl("search", "fn=get&getfn=rank&tag=%7E$ranktag&q=&t=r&p=all"), "\">Your reviews</a>";
if ($Me->isPC)
echo "<br />\n<a href=\"", hoturl("search", "fn=get&getfn=rank&tag=%7E$ranktag&q=&t=s&p=all"), "\">All submitted papers</a>";
echo "</div></td>\n";
$disabled = ($pastDeadline && !$Me->privChair ? " disabled" : "");
echo "<td><h3>Upload ranking file</h3>\n",
Ht::form(hoturl_post("offline", "setrank=1&tag=%7E$ranktag")),
Ht::hidden("upload", 1),
'<input type="file" name="file" accept="text/plain" size="30"', $disabled, '> ',
Ht::submit("Go", array("disabled" => !!$disabled));
if ($pastDeadline && $Me->privChair)
echo "<br>", Ht::checkbox("override"), " ", Ht::label("Override deadlines");
echo '<br><span class="hint"><strong>Tip:</strong> Use “<a href="', hoturl("search", "q=" . urlencode("editsort:#~$ranktag")), '">editsort:#~', $ranktag, '</a>” to drag and drop your ranking.</span>';
echo '<br><span class="hint"><strong>Tip:</strong> “<a href="', hoturl("search", "q=order:%7E$ranktag"), '">order:~', $ranktag, '</a>” searches by your ranking.</span>';
echo "</form></td>\n";
echo "</tr>\n";
}
echo "</table>\n";
$Conf->footer();