forked from kohler/hotcrp
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathreview.php
372 lines (327 loc) · 13 KB
/
review.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
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
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
<?php
// review.php -- HotCRP paper review display/edit page
// Copyright (c) 2006-2020 Eddie Kohler; see LICENSE.
require_once("src/initweb.php");
require_once("src/papertable.php");
$rf = $Conf->review_form();
$Me->add_overrides(Contact::OVERRIDE_CHECK_TIME);
if (session_id() === "" && $Me->is_reviewer()) {
ensure_session();
}
// header
function review_header() {
global $paperTable, $Qreq;
PaperTable::do_header($paperTable, "review", $Qreq->mode, $Qreq);
}
function review_error($msg) {
review_header();
Ht::stash_script("hotcrp.shortcut().add()");
$msg && Conf::msg_error($msg);
Conf::$main->footer();
exit;
}
// collect paper ID
function review_load() {
global $Conf, $Me, $Qreq, $prow, $paperTable;
if (!($prow = PaperTable::fetch_paper_request($Qreq, $Me))) {
$whyNot = $Qreq->checked_annex("paper_whynot", "PermissionProblem");
review_error(whyNotText($whyNot->set("listViewable", true)));
}
$paperTable = new PaperTable($prow, $Qreq);
$paperTable->resolveReview(true);
}
review_load();
// general error messages
if ($Qreq->post && $Qreq->post_empty()) {
$Conf->post_missing_msg();
} else if ($Qreq->post && $Qreq->default) {
if ($Qreq->has_file("uploadedFile")) {
$Qreq->uploadForm = 1;
} else {
$Qreq->update = 1;
}
} else if ($Qreq->submitreview) {
$Qreq->update = $Qreq->ready = 1;
} else if ($Qreq->savedraft) {
$Qreq->update = 1;
unset($Qreq->ready);
}
// cancel action
if ($Qreq->cancel) {
$Conf->redirect_self($Qreq);
}
// upload review form action
if (isset($Qreq->uploadForm)
&& $Qreq->has_file("uploadedFile")
&& $Qreq->valid_post()) {
// parse form, store reviews
$tf = ReviewValues::make_text($rf, $Qreq->file_contents("uploadedFile"),
$Qreq->file_filename("uploadedFile"));
if ($tf->parse_text($Qreq->override)) {
$tf->check_and_save($Me, $prow, $paperTable->editrrow);
}
if (!$tf->has_error() && $tf->parse_text($Qreq->override)) {
$tf->msg_at(null, 'Only the first review form in the file was parsed. <a href="' . hoturl("offline") . '">Upload multiple-review files here.</a>', MessageSet::WARNING);
}
$tf->report();
review_load();
} else if (isset($Qreq->uploadForm)) {
Conf::msg_error("Select a review form to upload.");
}
// check review submit requirements
if (isset($Qreq->unsubmitreview)
&& $paperTable->editrrow
&& $paperTable->editrrow->reviewStatus >= ReviewInfo::RS_DELIVERED
&& $Me->can_administer($prow)
&& $Qreq->valid_post()) {
$result = $Me->unsubmit_review_row($paperTable->editrrow);
if (!Dbl::is_error($result) && $result->affected_rows) {
$Me->log_activity_for($paperTable->editrrow->contactId, "Review {$paperTable->editrrow->reviewId} unsubmitted", $prow);
$Conf->confirmMsg("Unsubmitted review.");
}
$Conf->redirect_self($Qreq); // normally does not return
review_load();
} else if (isset($Qreq->update)
&& $paperTable->editrrow
&& $paperTable->editrrow->reviewStatus >= ReviewInfo::RS_COMPLETED) {
$Qreq->ready = 1;
}
// update review action
if (isset($Qreq->update) && $Qreq->valid_post()) {
$tf = new ReviewValues($rf);
$tf->paperId = $prow->paperId;
if (($whyNot = $Me->perm_submit_review($prow, $paperTable->editrrow))) {
$tf->msg_at(null, whyNotText($whyNot), MessageSet::ERROR);
} else if ($tf->parse_web($Qreq, $Qreq->override)) {
if (isset($Qreq->approvesubreview)
&& $paperTable->editrrow
&& $Me->can_approve_review($prow, $paperTable->editrrow)) {
$tf->set_adopt();
}
if ($tf->check_and_save($Me, $prow, $paperTable->editrrow)
&& !$tf->has_problem_at("ready")) {
$tf->report();
$Conf->redirect_self($Qreq); // normally does not return
}
}
review_load();
$tf->report();
$paperTable->set_review_values($tf);
} else if ($Qreq->has_annex("after_login")) {
$tf = new ReviewValues($rf);
$tf->parse_web($Qreq, $Qreq->override);
$paperTable->set_review_values($tf);
}
// adopt review action
if (isset($Qreq->adoptreview)
&& $Qreq->valid_post()
&& $paperTable->editrrow
&& $Me->can_approve_review($prow, $paperTable->editrrow)) {
$tf = new ReviewValues($rf);
$tf->paperId = $prow->paperId;
$my_rrow = $prow->review_of_user($Me);
if (($whyNot = $Me->perm_submit_review($prow, $my_rrow))) {
$tf->msg_at(null, whyNotText($whyNot), MessageSet::ERROR);
} else if ($tf->parse_web($Qreq, $Qreq->override)) {
$tf->set_ready($Qreq->adoptsubmit);
if ($tf->check_and_save($Me, $prow, $my_rrow)
&& !$tf->has_problem_at("ready")) {
$tf->report();
// mark the review as approved
$tfx = new ReviewValues($rf);
$tfx->set_adopt();
$tfx->check_and_save($Me, $prow, $paperTable->editrrow);
}
}
if (($my_rrow = $prow->fresh_review_of_user($Me))) {
$Qreq->r = $my_rrow->reviewId;
}
$Conf->redirect_self($Qreq); // normally does not return
}
// delete review action
if (isset($Qreq->deletereview)
&& $Qreq->valid_post()
&& $Me->can_administer($prow)) {
if (!$paperTable->editrrow) {
Conf::msg_error("No review to delete.");
} else {
$result = $Conf->qe("delete from PaperReview where paperId=? and reviewId=?", $prow->paperId, $paperTable->editrrow->reviewId);
if (!Dbl::is_error($result) && $result->affected_rows) {
$Me->log_activity_for($paperTable->editrrow->contactId, "Review {$paperTable->editrrow->reviewId} deleted", $prow);
$Conf->confirmMsg("Deleted review.");
$Conf->qe("delete from ReviewRating where paperId=? and reviewId=?", $prow->paperId, $paperTable->editrrow->reviewId);
if ($paperTable->editrrow->reviewToken !== 0) {
$Conf->update_rev_tokens_setting(-1);
}
if ($paperTable->editrrow->reviewType == REVIEW_META) {
$Conf->update_metareviews_setting(-1);
}
// perhaps a delegatee needs to redelegate
if ($paperTable->editrrow->reviewType < REVIEW_SECONDARY
&& $paperTable->editrrow->requestedBy > 0) {
$Me->update_review_delegation($paperTable->editrrow->paperId, $paperTable->editrrow->requestedBy, -1);
}
unset($Qreq->r, $Qreq->reviewId);
$Qreq->paperId = $Qreq->p = $paperTable->editrrow->paperId;
$Conf->redirect_hoturl("paper", ["p" => $Qreq->paperId]);
}
$Conf->redirect_self($Qreq); // normally does not return
review_load();
}
}
// download review form action
function downloadForm($qreq) {
global $rf, $Conf, $Me, $prow, $paperTable;
$rrow = $paperTable->rrow;
$use_request = (!$rrow || $rrow->contactId == $Me->contactId)
&& $prow->review_type($Me) > 0;
$filename = "review-{$prow->paperId}";
if ($rrow && $rrow->reviewOrdinal) {
$filename .= unparseReviewOrdinal($rrow->reviewOrdinal);
}
$Conf->make_csvg($filename, CsvGenerator::TYPE_STRING)
->set_inline(false)
->add_string($rf->textFormHeader(false) . $rf->textForm($prow, $rrow, $Me, $use_request ? $qreq : null))
->download();
exit;
}
if (isset($Qreq->downloadForm)) {
downloadForm($Qreq);
}
function download_all_text_reviews() {
global $rf, $Conf, $Me, $prow, $paperTable;
$lastrc = null;
$text = "";
foreach ($prow->viewable_submitted_reviews_and_comments($Me) as $rc) {
$text .= PaperInfo::review_or_comment_text_separator($lastrc, $rc);
if (isset($rc->reviewId)) {
$text .= $rf->unparse_text($prow, $rc, $Me, ReviewForm::UNPARSE_NO_TITLE);
} else {
$text .= $rc->unparse_text($Me, ReviewForm::UNPARSE_NO_TITLE);
}
$lastrc = $rc;
}
if ($text === "") {
$whyNot = $Me->perm_view_review($prow, null) ? : $prow->make_whynot();
return Conf::msg_error(whyNotText($whyNot));
}
$Conf->make_csvg("reviews-{$prow->paperId}", CsvGenerator::TYPE_STRING)
->add_string($Conf->short_name . " Paper #{$prow->paperId} Reviews and Comments\n"
. str_repeat("=", 75) . "\n"
. prefix_word_wrap("", "Paper #{$prow->paperId} {$prow->title}", 0, 75)
. "\n\n" . $text)
->download();
exit;
}
function download_one_text_review(ReviewInfo $rrow) {
global $rf, $Conf, $Me, $prow, $paperTable;
$filename = "review-{$prow->paperId}";
if ($rrow->reviewOrdinal) {
$filename .= unparseReviewOrdinal($rrow->reviewOrdinal);
}
$Conf->make_csvg($filename, CsvGenerator::TYPE_STRING)
->add_string($rf->unparse_text($prow, $rrow, $Me))
->download();
exit;
}
if (isset($Qreq->text)) {
if ($paperTable->rrow) {
download_one_text_review($paperTable->rrow);
} else {
download_all_text_reviews();
}
}
// retract review request
if ((isset($Qreq->refuse) || isset($Qreq->decline))
&& ($Qreq->valid_post()
|| ($Me->capability("@ra" . $prow->paperId) && !$Qreq->is_head()))) {
$decline_email = null;
if ($paperTable->editrrow) {
$Qreq->email = $decline_email = $paperTable->editrrow->email;
} else if (($ra_cid = $Me->capability("@ra" . $prow->paperId))
&& ($ra_user = $Conf->cached_user_by_id($ra_cid))) {
$Qreq->email = $decline_email = $ra_user->email;
}
$result = RequestReview_API::declinereview($Me, $Qreq, $prow);
$result = JsonResult::make($result);
if ($result->content["ok"]) {
if (($Qreq->refuse === "1" || $Qreq->decline === "1")
&& $decline_email
&& !isset($Qreq->reason)) {
$Conf->confirmMsg("<p>Thank you for telling us that you cannot complete your review. If you’d like, you may enter a brief explanation here.</p>"
. Ht::form($Conf->hoturl_post("api/declinereview", ["p" => $prow->paperId, "email" => $decline_email, "redirect" => $Conf->hoturl_site_relative_raw("index")]))
. Ht::textarea("reason", $result->content["reason"], ["rows" => 3, "cols" => 40, "spellcheck" => true])
. '<hr class="c">'
. Ht::submit("Update explanation", ["class" => "btn-primary"])
. '</form>');
} else {
$Conf->confirmMsg("Review declined. Thank you for telling us that you cannot complete your review.");
unset($Qreq->email, $Qreq->firstName, $Qreq->lastName, $Qreq->affiliation, $Qreq->round, $Qreq->reason, $Qreq->override, $Qreq->retract);
$Conf->redirect_self($Qreq);
}
} else {
$result->export_errors();
}
review_load();
}
if (isset($Qreq->accept)
&& ($Qreq->valid_post()
|| ($Me->capability("@ra" . $prow->paperId) && !$Qreq->is_head()))) {
$rrow = $paperTable->editrrow;
if (!$rrow
|| (!$Me->is_my_review($rrow) && !$Me->can_administer($prow))) {
Conf::msg_error("This review was not assigned to you, so you cannot confirm your intention to write it.");
} else {
if ($rrow->reviewStatus < ReviewInfo::RS_ACCEPTED) {
Dbl::qe("update PaperReview set reviewModified=1, timeRequestNotified=greatest(?,timeRequestNotified)
where paperId=? and reviewId=? and reviewModified<=0",
Conf::$now, $prow->paperId, $rrow->reviewId);
if ($Me->is_signed_in()) {
$rrow->delete_acceptor();
}
$Me->log_activity_for($rrow->contactId, "Review {$rrow->reviewId} accepted", $prow);
}
$Conf->confirmMsg("Thank you for confirming your intention to finish this review. You can download the paper and review form below.");
$Conf->redirect_self($Qreq);
review_load();
}
}
// can we view/edit reviews?
$viewAny = $Me->can_view_review($prow, null);
$editAny = $Me->can_review($prow, null);
// can we see any reviews?
if (!$viewAny && !$editAny) {
if (($whyNotPaper = $Me->perm_view_paper($prow))) {
review_error(whyNotText($whyNotPaper->set("listViewable", true)));
}
if (isset($Qreq->reviewId)) {
Conf::msg_error("You can’t see the reviews for this paper. "
. whyNotText($Me->perm_view_review($prow, null)));
$Conf->redirect_hoturl("paper", "p=$prow->paperId");
}
}
// mode
$paperTable->fixReviewMode();
if ($paperTable->mode == "edit") {
$Conf->redirect_hoturl("paper", ["p" => $prow->paperId]);
}
// paper table
review_header();
$paperTable->initialize(false, false);
$paperTable->paptabBegin();
$paperTable->resolveComments();
if (!$viewAny
&& !$editAny
&& (!$paperTable->rrow
|| !$Me->can_view_review($prow, $paperTable->rrow))) {
$paperTable->paptabEndWithReviewMessage();
} else {
if ($paperTable->mode === "re") {
$paperTable->paptabEndWithEditableReview();
$paperTable->paptabComments();
} else {
$paperTable->paptabEndWithReviewsAndComments();
}
}
echo "</article>\n";
$Conf->footer();