forked from kohler/hotcrp
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmail.php
811 lines (737 loc) · 31.8 KB
/
mail.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
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
<?php
// mail.php -- HotCRP mail tool
// Copyright (c) 2006-2020 Eddie Kohler; see LICENSE.
require_once("src/initweb.php");
require_once("src/papersearch.php");
require_once("src/mailclasses.php");
if (!$Me->is_manager() && !$Me->isPC) {
$Me->escape();
}
if (isset($Qreq->recipients) && !isset($Qreq->to)) {
$Qreq->to = $Qreq->recipients;
}
// load mail from log
if (isset($Qreq->fromlog)
&& ctype_digit($Qreq->fromlog)
&& $Me->privChair) {
$result = $Conf->qe_raw("select * from MailLog where mailId=" . $Qreq->fromlog);
if (($row = $result->fetch_object())) {
foreach (["recipients", "q", "t", "cc", "replyto", "subject", "emailBody"] as $field) {
if (isset($row->$field) && !isset($Qreq[$field]))
$Qreq[$field] = $row->$field;
}
if (isset($row->recipients) && !isset($Qreq->to)) {
$Qreq->to = $row->recipients;
}
if ($row->q) {
$Qreq["plimit"] = 1;
}
}
}
// create options
$tOpt = array();
if ($Me->privChair) {
$tOpt["s"] = "Submitted papers";
if ($Conf->time_pc_view_decision(false) && $Conf->has_any_accepted()) {
$tOpt["acc"] = "Accepted papers";
}
$tOpt["unsub"] = "Unsubmitted papers";
$tOpt["all"] = "All papers";
}
if ($Me->privChair ? $Conf->has_any_manager() : $Me->is_manager()) {
$tOpt["admin"] = "Papers you administer";
}
$tOpt["req"] = "Your review requests";
if (!isset($Qreq->t) || !isset($tOpt[$Qreq->t])) {
$Qreq->t = key($tOpt);
}
// mailer options
if (isset($Qreq->cc) && $Me->is_manager()) {
// XXX should only apply to papers you administer
$Qreq->cc = simplify_whitespace($Qreq->cc);
} else {
$Qreq->cc = $Conf->opt("emailCc") ?? "";
}
if (isset($Qreq->replyto) && $Me->is_manager()) {
// XXX should only apply to papers you administer
$Qreq->replyto = simplify_whitespace($Qreq->replyto);
} else {
$Qreq->replyto = $Conf->opt("emailReplyTo") ?? "";
}
global $mailer_options;
$mailer_options = ["requester_contact" => $Me, "cc" => $Qreq->cc, "reply-to" => $Qreq->replyto];
$null_mailer = new HotCRPMailer($Conf, null, array_merge(["width" => false], $mailer_options));
// template options
if (isset($Qreq->monreq)) {
$Qreq->template = "myreviewremind";
}
if (isset($Qreq->template) && !isset($Qreq->check)) {
$Qreq->loadtmpl = -1;
}
// paper selection
if (!isset($Qreq->q) || trim($Qreq->q) == "(All)") {
$Qreq->q = "";
}
$Qreq->allow_a("p", "pap");
if (!isset($Qreq->p) && isset($Qreq->pap)) { // support p= and pap=
$Qreq->p = $Qreq->pap;
}
if (isset($Qreq->p) && is_string($Qreq->p)) {
$Qreq->p = preg_split('/\s+/', $Qreq->p);
}
// It's OK to just set $Qreq->p from the input without
// validation because MailRecipients filters internally
if (isset($Qreq->prevt) && isset($Qreq->prevq)) {
if (!isset($Qreq->plimit))
unset($Qreq->p);
else if (($Qreq->prevt !== $Qreq->t || $Qreq->prevq !== $Qreq->q)
&& !isset($Qreq->psearch)) {
$Conf->warnMsg("You changed the paper search. Please review the paper list.");
$Qreq->psearch = true;
}
}
$papersel = null;
if (isset($Qreq->p) && is_array($Qreq->p)
&& !isset($Qreq->psearch)) {
$papersel = array();
foreach ($Qreq->p as $p)
if (($p = cvtint($p)) > 0)
$papersel[] = $p;
sort($papersel);
$Qreq->q = join(" ", $papersel);
$Qreq->plimit = 1;
} else if (isset($Qreq->plimit)) {
$search = new PaperSearch($Me, ["t" => $Qreq->t, "q" => $Qreq->q]);
$papersel = $search->paper_ids();
sort($papersel);
} else {
$Qreq->q = "";
}
// Load template if requested
if (isset($Qreq->loadtmpl)) {
$t = $Qreq->get("template", "generic");
$template = (array) $Conf->mail_template($t);
if (((!isset($template["title"]) || $template["title"] === false)
&& !isset($template["allow_template"]))
|| (isset($template["allow_template"]) && $template["allow_template"] === false)) {
$template = (array) $Conf->mail_template("generic");
}
if (!isset($Qreq->to) || $Qreq->loadtmpl != -1) {
$Qreq->to = get($template, "default_recipients", "s");
}
if (isset($template["default_search_type"])) {
$Qreq->t = $template["default_search_type"];
}
$Qreq->subject = $null_mailer->expand($template["subject"]);
$Qreq->emailBody = $null_mailer->expand($template["body"]);
}
// Clean subject and body
if (!isset($Qreq->subject)) {
$t = $Conf->mail_template("generic");
$Qreq->subject = $null_mailer->expand($t->subject, "subject");
}
$Qreq->subject = trim($Qreq->subject);
if (str_starts_with($Qreq->subject, "[{$Conf->short_name}] ")) {
$Qreq->subject = substr($Qreq->subject, strlen($Conf->short_name) + 3);
}
if (!isset($Qreq->emailBody)) {
$t = $Conf->mail_template("generic");
$Qreq->emailBody = $null_mailer->expand($t->body, "body");
}
// Set recipients list, now that template is loaded
$recip = new MailRecipients($Me, $Qreq->to, $papersel, $Qreq->newrev_since);
// warn if no papers match
if (isset($papersel)
&& empty($papersel)
&& !isset($Qreq->loadtmpl)
&& !isset($Qreq->psearch)
&& $recip->need_papers()) {
Conf::msg_error("No papers match that search.");
unset($papersel);
unset($Qreq->check, $Qreq->send);
}
class MailSender {
public $conf;
public $user;
private $recip;
private $phase;
private $sending;
private $qreq;
private $started = false;
private $group;
private $recipients;
private $groupable = false;
private $mcount = 0;
private $skipcount = 0;
private $mrecipients = [];
private $prep_recipients = [];
private $cbcount = 0;
private $mailid_text = "";
function __construct(Contact $user, $recip, $phase, Qrequest $qreq) {
$this->conf = $user->conf;
$this->user = $user;
$this->recip = $recip;
$this->phase = $phase;
$this->sending = $phase === 2;
$this->qreq = $qreq;
$this->group = $qreq->group || !$qreq->ungroup;
$this->recipients = (string) $qreq->to;
}
static function check($user, $recip, $qreq) {
$ms = new MailSender($user, $recip, 0, $qreq);
$ms->run();
}
static function send1($user, $recip, $qreq) {
$ms = new MailSender($user, $recip, 1, $qreq);
$result = $user->conf->qe("insert into MailLog set
recipients=?, cc=?, replyto=?, subject=?, emailBody=?, q=?, t=?,
fromNonChair=?, status=-1",
(string) $qreq->to, $qreq->cc, $qreq->replyto,
$qreq->subject, $qreq->emailBody, $qreq->q, $qreq->t,
$user->privChair ? 0 : 1);
$ms->echo_request_form(true);
echo Ht::hidden("mailid", $result->insert_id),
Ht::hidden("send", 1),
Ht::submit("Send mail"),
"</form>",
Ht::unstash_script('$("#mailform").submit()'),
'<div class="warning">About to send mail.</div>';
$user->conf->footer();
exit;
}
static function send2($user, $recip, $qreq) {
$mailid = isset($qreq->mailid) && ctype_digit($qreq->mailid) ? intval($qreq->mailid) : -1;
$result = $user->conf->qe("update MailLog set status=1 where mailId=? and status=-1", $mailid);
if (!$result->affected_rows) {
return Conf::msg_error("That mail was already sent.");
}
$ms = new MailSender($user, $recip, 2, $qreq);
$ms->run();
}
private function echo_actions($extra_class = "") {
echo '<div class="aa', $extra_class, '">',
Ht::submit("send", "Send", array("style" => "margin-right:4em")),
' ';
$class = $this->groupable ? "" : " hidden";
if (!$this->qreq->group && $this->qreq->ungroup) {
echo Ht::submit("group", "Gather recipients", ["class" => "mail_groupable" . $class]);
} else {
echo Ht::submit("ungroup", "Separate recipients", ["class" => "mail_groupable" . $class]);
}
echo ' ', Ht::submit("cancel", "Cancel"), '</div>';
}
private function echo_request_form($include_cb) {
echo Ht::form($this->conf->hoturl_post("mail"), ["id" => "mailform"]);
foreach (["to", "subject", "emailBody", "cc", "replyto", "q", "t", "plimit", "newrev_since"] as $x) {
if (isset($this->qreq[$x]))
echo Ht::hidden($x, $this->qreq[$x]);
}
if (!$this->group) {
echo Ht::hidden("ungroup", 1);
}
if ($include_cb) {
foreach ($this->qreq as $k => $v) {
if ($k[0] === "c" && preg_match('{\Ac[\d_]+p-?\d+\z}', $k))
echo Ht::hidden($k, $v);
}
}
}
private function echo_prologue() {
if ($this->started) {
return;
}
$this->echo_request_form(false);
if ($this->phase === 2) {
echo '<div id="foldmail" class="foldc fold2c">',
'<div class="fn fx2 merror">In the process of sending mail. <strong>Do not leave this page until this message disappears!</strong><br><span id="mailcount"></span></div>',
'<div id="mailwarnings"></div>',
'<div class="fx"><div class="confirm">Sent to: ', $this->recip->unparse(),
'<span id="mailinfo"></span></div>',
'<div class="aa">',
Ht::submit("again", "Prepare more mail"),
"</div></div>",
// This next is only displayed when Javascript is off
'<div class="fn2 warning">Sending mail. <strong>Do not leave this page until it finishes rendering!</strong></div>',
"</div>";
} else if ($this->phase === 0) {
if (isset($this->qreq->emailBody)
&& $this->user->privChair
&& (strpos($this->qreq->emailBody, "%REVIEWS%")
|| strpos($this->qreq->emailBody, "%COMMENTS%"))) {
if (!$this->conf->can_some_author_view_review()) {
echo '<div class="warning">Although these mails contain reviews and/or comments, authors can’t see reviews or comments on the site. (<a href="', $this->conf->hoturl("settings", "group=dec"), '" class="nw">Change this setting</a>)</div>', "\n";
} else if (!$this->conf->can_some_author_view_review(true)) {
echo '<div class="warning">Mails to users who have not completed their own reviews will not include reviews or comments. (<a href="', $this->conf->hoturl("settings", "group=dec"), '" class="nw">Change the setting</a>)</div>', "\n";
}
}
if (isset($this->qreq->emailBody)
&& $this->user->privChair
&& substr($this->recipients, 0, 4) == "dec:") {
if (!$this->conf->can_some_author_view_decision()) {
echo '<div class="warning">You appear to be sending an acceptance or rejection notification, but authors can’t see paper decisions on the site. (<a href="', $this->conf->hoturl("settings", "group=dec"), '" class="nw">Change this setting</a>)</div>', "\n";
}
}
echo '<div id="foldmail" class="foldc fold2c">',
'<div class="fn fx2 warning">In the process of preparing mail. You will be able to send the prepared mail once this message disappears.<br><span id="mailcount"></span></div>',
'<div id="mailwarnings"></div>',
'<div class="fx info">Verify that the mails look correct, then select “Send” to send the checked mails.<br>',
"Mailing to: ", $this->recip->unparse(),
'<span id="mailinfo"></span>';
if (!preg_match('/\A(?:pc\z|pc:|all\z)/', $this->recipients)
&& $this->qreq->plimit
&& (string) $this->qreq->q !== "") {
echo "<br />Paper selection: ", htmlspecialchars($this->qreq->q);
}
echo "</div>";
$this->echo_actions(" fx");
// This next is only displayed when Javascript is off
echo '<div class="fn2 warning">Scroll down to send the prepared mail once the page finishes loading.</div>',
"</div>\n";
}
echo Ht::unstash_script("hotcrp.fold('mail',0,2)");
$this->started = true;
}
private function echo_mailinfo($nrows_done, $nrows_total) {
if (!$this->started) {
$this->echo_prologue();
}
$s = "document.getElementById('mailcount').innerHTML=\"";
if ($nrows_done >= $nrows_total) {
$s .= "100";
} else {
$s .= min(round(100 * $nrows_done / max(1, $nrows_total)), 99);
}
$s .= "% done.\";";
$m = plural($this->mcount, "mail") . ", "
. plural($this->mrecipients, "recipient");
$s .= "document.getElementById('mailinfo').innerHTML=\"<span class='barsep'>·</span>" . $m . "\";";
if (!$this->sending && $this->groupable) {
$s .= "\$('.mail_groupable').show();";
}
echo Ht::unstash_script($s);
}
private static function fix_body($prep) {
if (preg_match('^\ADear (author|reviewer)\(s\)([,;!.\s].*)\z^s', $prep->body, $m))
$prep->body = "Dear " . $m[1] . (count($prep->to) == 1 ? "" : "s") . $m[2];
}
/** @param HotCRPMailPreparation $prep
* @param HotCRPMailPreparation &$last_prep
* @param ?Contact $recipient
* @return bool */
private function process_prep($prep, &$last_prep, $recipient) {
// Don't combine senders if anything differs. Also, don't combine
// mails from different papers, unless those mails are to the same
// person.
$mail_differs = !$prep->can_merge($last_prep);
if (!$mail_differs) {
$this->groupable = true;
}
if ($mail_differs || !$this->group) {
if (!$last_prep->fake) {
$this->send_prep($last_prep);
}
$last_prep = $prep;
$must_include = true;
} else {
$must_include = false;
}
if (!$prep->fake
&& ($must_include
|| !$recipient
|| !in_array($recipient->contactId, $last_prep->contactIds))) {
if ($last_prep !== $prep) {
$last_prep->merge($prep);
}
return true;
} else {
return false;
}
}
private function send_prep($prep) {
$cbkey = "c" . join("_", $prep->contactIds) . "p" . $prep->paperId;
if ($this->sending && !$this->qreq[$cbkey]) {
++$this->skipcount;
return;
}
set_time_limit(30);
$this->echo_prologue();
self::fix_body($prep);
if ($this->sending) {
$prep->send();
}
++$this->mcount;
foreach ($prep->contactIds as $cid) {
$this->mrecipients[$cid] = true;
if ($this->sending) {
// Log format matters
$this->conf->log_for($this->user, $cid, "Sent mail" . $this->mailid_text, $prep->paperId);
}
}
// hide passwords from non-chair users
$show_prep = $prep;
if ($prep->censored_preparation) {
$show_prep = $prep->censored_preparation;
$show_prep->to = $prep->to;
self::fix_body($show_prep);
}
echo '<div class="mail"><table>';
$nprintrows = 0;
foreach (["To", "cc", "bcc", "reply-to", "Subject"] as $k) {
if ($k == "To") {
$vh = array();
foreach ($show_prep->to as $to) {
$vh[] = htmlspecialchars(MimeText::decode_header($to));
}
$vh = '<div style="max-width:60em"><span class="nw">' . join(',</span> <span class="nw">', $vh) . '</span></div>';
} else if ($k == "Subject") {
$vh = htmlspecialchars(MimeText::decode_header($show_prep->subject));
} else if (($line = $show_prep->headers[$k] ?? null)) {
$k = substr($line, 0, strlen($k));
$vh = htmlspecialchars(MimeText::decode_header(substr($line, strlen($k) + 2)));
} else {
continue;
}
echo " <tr>";
if (++$nprintrows > 1) {
echo '<td class="mhpad"></td>';
} else if ($this->sending) {
echo '<td class="mhx"></td>';
} else {
++$this->cbcount;
echo '<td class="mhcb"><input type="checkbox" class="uic js-range-click" name="', $cbkey,
'" value="1" checked="checked" data-range-type="mhcb" id="psel', $this->cbcount,
'" /></td>';
}
echo '<td class="mhnp nw">', $k, ":</td>",
'<td class="mhdp text-monospace">', $vh, "</td></tr>\n";
}
echo ' <tr><td></td><td></td><td class="mhb"><pre class="email">',
Ht::link_urls(htmlspecialchars($show_prep->body)),
"</pre></td></tr>\n",
'<tr><td class="mhpad"></td><td></td><td class="mhpad"></td></tr>',
"</table></div>\n";
}
private function run() {
global $mailer_options;
$subject = trim($this->qreq->subject);
if ($subject === "") {
$subject = "Message";
}
$subject = "[{$this->conf->short_name}] $subject";
$emailBody = $this->qreq->emailBody;
$template = ["subject" => $subject, "body" => $emailBody];
$rest = array_merge(["no_error_quit" => true], $mailer_options);
// test whether this mail is paper-sensitive
$mailer = new HotCRPMailer($this->conf, $this->user, $rest);
$prep = $mailer->prepare($template, $rest);
$paper_sensitive = preg_match('/%[A-Z0-9]+[(%]/', $prep->subject . $prep->body);
$q = $this->recip->query($paper_sensitive);
if (!$q) {
return Conf::msg_error("Bad recipients value");
}
$result = $this->conf->qe_raw($q);
if (Dbl::is_error($result)) {
return;
}
if ($this->sending) {
$this->mailid_text = " #" . intval($this->qreq->mailid);
// Mail format matters
$this->user->log_activity("Sending mail$this->mailid_text \"$subject\"");
$rest["censor"] = Mailer::CENSOR_NONE;
} else {
$rest["no_send"] = true;
$rest["censor"] = Mailer::CENSOR_DISPLAY;
}
$mailer = new HotCRPMailer($this->conf);
$mailer->combination_type = $this->recip->combination_type($paper_sensitive);
$fake_prep = new HotCRPMailPreparation($this->conf, null);
$fake_prep->fake = true;
$last_prep = $fake_prep;
$nrows_done = 0;
$nrows_total = $result->num_rows;
$nwarnings = 0;
$preperrors = array();
$revinform = ($this->recipients == "newpcrev" ? array() : null);
while (($rowdata = $result->fetch_assoc())) {
$row = new PaperInfo($rowdata, $this->user, $this->conf);
$contact = new Contact($rowdata, $this->conf);
++$nrows_done;
$rest["prow"] = $prow = $row->paperId > 0 ? $row : null;
$rest["newrev_since"] = $this->recip->newrev_since;
$mailer->reset($contact, $rest);
$prep = $mailer->prepare($template, $rest);
if ($prep->errors) {
foreach ($prep->errors as $lcfield => $hline) {
$reqfield = ($lcfield == "reply-to" ? "replyto" : $lcfield);
Ht::error_at($reqfield);
$emsg = "Malformed " . Mailer::$email_fields[$lcfield] . " field: " . $hline . " Put names in \"double quotes\" and email addresses in <angle brackets>, and separate destinations with commas.";
if (!isset($preperrors[$emsg])) {
Conf::msg_error($emsg);
}
$preperrors[$emsg] = true;
}
} else if ($this->process_prep($prep, $last_prep, $contact)) {
if ((!$this->user->privChair || $this->conf->opt("chairHidePasswords"))
&& !$last_prep->censored_preparation
&& $rest["censor"] === Mailer::CENSOR_NONE) {
$rest["censor"] = Mailer::CENSOR_DISPLAY;
$mailer->reset($contact, $rest);
$last_prep->censored_preparation = $mailer->prepare($template, $rest);
$rest["censor"] = Mailer::CENSOR_NONE;
}
}
if ($nwarnings !== $mailer->warning_count() || $nrows_done % 5 == 0) {
$this->echo_mailinfo($nrows_done, $nrows_total);
}
if ($nwarnings !== $mailer->warning_count()) {
$this->echo_prologue();
$nwarnings = $mailer->warning_count();
echo "<div id=\"foldmailwarn$nwarnings\" class=\"hidden\"><div class=\"warning\">", join("<br>", $mailer->warning_htmls()), "</div></div>";
echo Ht::unstash_script("document.getElementById('mailwarnings').innerHTML = document.getElementById('foldmailwarn$nwarnings').innerHTML;");
}
if ($this->sending && $revinform !== null && $prow) {
$revinform[] = "(paperId=$prow->paperId and contactId=$contact->contactId)";
}
}
$this->process_prep($fake_prep, $last_prep, null);
$this->echo_mailinfo($nrows_done, $nrows_total);
if ($this->mcount === 0) {
if (empty($preperrors)) {
Conf::msg_error("No users match “" . $this->recip->unparse() . "” for that search.");
}
echo Ht::unstash_script("\$(\"#foldmail\").addClass('hidden');document.getElementById('mailform').action=" . json_encode_browser($this->conf->hoturl("mail", "check=1", Conf::HOTURL_RAW | Conf::HOTURL_POST)));
return false;
}
if (!$this->sending) {
$this->echo_actions();
} else {
$this->conf->qe("update MailLog set status=0 where mailId=?", intval($this->qreq->mailid));
if ($revinform) {
$this->conf->qe_raw("update PaperReview set timeRequestNotified=" . time() . " where " . join(" or ", $revinform));
}
}
echo "</form>";
echo Ht::unstash_script("hotcrp.fold('mail', null);");
$this->conf->footer();
exit;
}
}
// Header
if (isset($Qreq->monreq)) {
$Conf->header("Monitor external reviews", "mail");
} else {
$Conf->header("Mail", "mail");
}
// Check or send
if (!$Qreq->loadtmpl
&& !$Qreq->cancel
&& !$Qreq->psearch
&& !$Qreq->again
&& !$recip->error
&& $Qreq->valid_post()) {
if ($Qreq->send && $Qreq->mailid) {
MailSender::send2($Me, $recip, $Qreq);
} else if ($Qreq->send) {
MailSender::send1($Me, $recip, $Qreq);
} else if ($Qreq->check || $Qreq->group || $Qreq->ungroup) {
MailSender::check($Me, $recip, $Qreq);
}
}
if (isset($Qreq->monreq)) {
$plist = new PaperList("reqrevs", new PaperSearch($Me, ["t" => "req", "q" => ""]));
$plist->set_table_id_class("foldpl", "pltable-fullw");
if ($plist->is_empty()) {
$Conf->infoMsg('You have not requested any external reviews. <a href="' . hoturl("index") . '">Return home</a>');
} else {
echo "<h2>Requested reviews</h2>\n\n";
$plist->echo_table_html(["list" => true]);
echo '<div class="info">';
if ($plist->has("need_review")) {
echo "Some of your requested external reviewers have not completed their reviews. To send them an email reminder, check the text below and then select “Prepare mail.” You’ll get a chance to review the emails and select specific reviewers to remind.";
} else {
echo 'All of your requested external reviewers have completed their reviews. <a href="', hoturl("index"), '">Return home</a>';
}
echo "</div>\n";
}
if (!$plist->has("need_review")) {
$Conf->footer();
exit;
}
}
echo Ht::form($Conf->hoturl_post("mail", "check=1")),
Ht::hidden_default_submit("default", 1), '
<div class="aa" style="padding-left:8px">
<strong>Template:</strong> ';
$tmpl = $tmploptions = [];
foreach (array_keys($Conf->mail_template_map()) as $tname) {
if (($template = $Conf->mail_template($tname))
&& (isset($template->title) && $template->title !== false)
&& (!isset($template->allow_template) || $template->allow_template)
&& ($Me->privChair || get($template, "allow_pc")))
$tmpl[] = $template;
}
usort($tmpl, "Conf::xt_position_compare");
foreach ($tmpl as $t) {
$tmploptions[$t->name] = $t->title;
}
if (!isset($Qreq->template) || !isset($tmploptions[$Qreq->template])) {
$Qreq->template = "generic";
}
echo Ht::select("template", $tmploptions, $Qreq->template),
" ",
Ht::submit("loadtmpl", "Load", ["id" => "loadtmpl"]),
'
<span class="hint">Templates are mail texts tailored for common conference tasks.</span>
</div>
<div class="mail" style="float:left;margin:4px 1em 12px 0"><table id="foldpsel" class="fold8c fold9o fold10c">', "\n";
// ** TO
echo '<tr><td class="mhnp nw"><label for="to">To:</label></td><td class="mhdd">',
$recip->selectors(),
"<div class=\"g\"></div>\n";
// paper selection
echo '<table class="fx9"><tr>';
if ($Me->privChair)
echo '<td class="nw">',
Ht::checkbox("plimit", 1, isset($Qreq->plimit), ["id" => "plimit"]),
" </td><td>", Ht::label("Choose papers", "plimit"),
"<span class=\"fx8\">: ";
else
echo '<td class="nw">Papers: </td><td>',
Ht::hidden("plimit", 1), '<span>';
echo Ht::entry("q", (string) $Qreq->q,
array("id" => "q", "placeholder" => "(All)",
"class" => "papersearch need-suggest", "size" => 36)),
" in ";
if (count($tOpt) == 1) {
echo htmlspecialchars($tOpt[$Qreq->t]);
} else {
echo " ", Ht::select("t", $tOpt, $Qreq->t, array("id" => "t"));
}
echo " ", Ht::submit("psearch", "Search");
echo "</span>";
if (isset($Qreq->plimit)
&& !isset($Qreq->monreq)
&& (isset($Qreq->loadtmpl) || isset($Qreq->psearch))) {
$plist = new PaperList("reviewers", new PaperSearch($Me, ["t" => $Qreq->t, "q" => $Qreq->q]));
echo "<div class=\"fx8";
if ($plist->is_empty()) {
echo "\">No papers match that search.";
} else {
echo " g\">";
$plist->echo_table_html(["noheader" => true, "nofooter" => true]);
}
echo '</div>', Ht::hidden("prevt", $Qreq->t),
Ht::hidden("prevq", $Qreq->q);
}
echo "</td></tr></table>\n";
echo '<div class="fx10" style="margin-top:0.35em">';
if (!$Qreq->newrev_since && ($t = $Conf->setting("pcrev_informtime")))
$Qreq->newrev_since = $Conf->parseableTime($t, true);
echo 'Assignments since: ',
Ht::entry("newrev_since", $Qreq->newrev_since,
array("placeholder" => "(all)", "size" => 30)),
'</div>';
echo '<div class="fx9 g"></div>';
Ht::stash_script('function mail_recipients_fold(event) {
var plimit = document.getElementById("plimit");
hotcrp.foldup.call(this, null, {f: !!plimit && !plimit.checked, n: 8});
var sopt = $(this).find("option[value=\'" + this.value + "\']");
hotcrp.foldup.call(this, null, {f: sopt.hasClass("mail-want-no-papers"), n: 9});
hotcrp.foldup.call(this, null, {f: !sopt.hasClass("mail-want-since"), n: 10});
}
$("#to, #plimit").on("change", mail_recipients_fold);
$(function () { $("#to").trigger("change"); })');
echo "</td></tr>\n";
// ** CC, REPLY-TO
if ($Me->is_manager()) {
foreach (Mailer::$email_fields as $lcfield => $field)
if ($lcfield !== "to" && $lcfield !== "bcc") {
$xfield = ($lcfield == "reply-to" ? "replyto" : $lcfield);
echo " <tr><td class=\"",
Ht::control_class($xfield, "mhnp nw"),
"\"><label for=\"$xfield\">$field:</label></td><td class=\"mhdp\">",
Ht::entry($xfield, $Qreq[$xfield], ["size" => 64, "class" => Ht::control_class($xfield, "text-monospace"), "id" => $xfield]),
($xfield == "replyto" ? "<hr class=\"g\">" : ""),
"</td></tr>\n\n";
}
}
// ** SUBJECT
echo " <tr><td class=\"mhnp nw\"><label for=\"subject\">Subject:</label></td><td class=\"mhdp\">",
"<samp>[", htmlspecialchars($Conf->short_name), "] </samp>",
Ht::entry("subject", $Qreq->subject, ["size" => 64, "class" => Ht::control_class("subject", "text-monospace"), "id" => "subject"]),
"</td></tr>
<tr><td></td><td class=\"mhb\">\n",
Ht::textarea("emailBody", $Qreq->emailBody,
array("class" => "text-monospace", "rows" => 20, "cols" => 80, "spellcheck" => "true")),
"</td></tr>
</table></div>\n\n";
if ($Me->privChair) {
$result = $Conf->qe_raw("select mailId, subject, emailBody from MailLog where fromNonChair=0 and status>=0 order by mailId desc limit 200");
if ($result->num_rows) {
echo '<div style="padding-top:12px;max-height:24em;overflow-y:auto">',
"<strong>Recent mails:</strong>\n";
$i = 1;
while (($row = $result->fetch_object())) {
echo '<div class="mhdd"><div style="position:relative;overflow:hidden">',
'<div style="position:absolute;white-space:nowrap"><span style="min-width:2em;text-align:right;display:inline-block" class="dim">', $i, '.</span> <a class="q" href="', hoturl("mail", "fromlog=" . $row->mailId), '">', htmlspecialchars($row->subject), ' – <span class="dim">', htmlspecialchars(UnicodeHelper::utf8_prefix($row->emailBody, 100)), "</span></a></div>",
"<br></div></div>\n";
++$i;
}
echo "</div>\n\n";
}
}
echo '<div class="aa c">',
Ht::submit("Prepare mail"), ' <span class="hint">You’ll be able to review the mails before they are sent.</span>
</div>
<div id="mailref">Keywords enclosed in percent signs, such as <code>%NAME%</code> or <code>%REVIEWDEADLINE%</code>, are expanded for each mail. Use the following syntax:
<hr class="g">
<div class="ctable no-hmargin">
<dl class="ctelt" style="margin-bottom:1.5em">
<dt><code>%URL%</code></dt>
<dd>Site URL.</dd>
<dt><code>%NUMSUBMITTED%</code></dt>
<dd>Number of papers submitted.</dd>
<dt><code>%NUMACCEPTED%</code></dt>
<dd>Number of papers accepted.</dd>
<dt><code>%NAME%</code></dt>
<dd>Full name of recipient.</dd>
<dt><code>%FIRST%</code>, <code>%LAST%</code></dt>
<dd>First and last names, if any, of recipient.</dd>
<dt><code>%EMAIL%</code></dt>
<dd>Email address of recipient.</dd>
<dt><code>%REVIEWDEADLINE%</code></dt>
<dd>Reviewing deadline appropriate for recipient.</dd>
</dl><dl class="ctelt" style="margin-bottom:1.5em">
<dt><code>%NUMBER%</code></dt>
<dd>Paper number relevant for mail.</dd>
<dt><code>%TITLE%</code></dt>
<dd>Paper title.</dd>
<dt><code>%TITLEHINT%</code></dt>
<dd>First couple words of paper title (useful for mail subject).</dd>
<dt><code>%OPT(AUTHORS)%</code></dt>
<dd>Paper authors (if recipient is allowed to see the authors).</dd>
</dl><dl class="ctelt" style="margin-bottom:1.5em">
<dt><code>%REVIEWS%</code></dt>
<dd>Pretty-printed paper reviews.</dd>
<dt><code>%COMMENTS%</code></dt>
<dd>Pretty-printed paper comments, if any.</dd>
<dt><code>%COMMENTS(<i>tag</i>)%</code></dt>
<dd>Comments tagged #<code><i>tag</i></code>, if any.</dd>
</dl><dl class="ctelt" style="margin-bottom:1.5em">
<dt><code>%IF(SHEPHERD)%...%ENDIF%</code></dt>
<dd>Include text if a shepherd is assigned.</dd>
<dt><code>%SHEPHERD%</code></dt>
<dd>Shepherd name and email, if any.</dd>
<dt><code>%SHEPHERDNAME%</code></dt>
<dd>Shepherd name, if any.</dd>
<dt><code>%SHEPHERDEMAIL%</code></dt>
<dd>Shepherd email, if any.</dd>
</dl><dl class="ctelt" style="margin-bottom:1.5em">
<dt><code>%IF(#<i>tag</i>)%...%ENDIF%</code></dt>
<dd>Include text if paper has tag <code><i>tag</i></code>.</dd>
<dt><code>%TAGVALUE(<i>tag</i>)%</code></dt>
<dd>Value of paper’s <code><i>tag</i></code>.</dd>
</dl>
</div></div>
</form>';
$Conf->footer();