function show_pset_actions($pset) { global $Conf; echo Ht::form_div(hoturl_post("index", array("pset" => $pset->urlkey, "reconfig" => 1)), ["divstyle" => "margin-bottom:1em", "class" => "need-pa-pset-actions"]); $options = array("disabled" => "Disabled", "invisible" => "Hidden", "visible" => "Visible without grades", "grades_visible" => "Visible with grades"); if ($pset->disabled) { $state = "disabled"; } else { if (!$pset->visible) { $state = "invisible"; } else { if (!$pset->grades_visible) { $state = "visible"; } else { $state = "grades_visible"; } } } echo Ht::select("state", $options, $state); echo '<span class="pa-if-visible"> <span class="barsep">·</span> ', Ht::select("frozen", array("no" => "Student updates allowed", "yes" => "Submissions frozen"), $pset->frozen ? "yes" : "no"), '</span>'; echo '<span class="pa-if-enabled"> <span class="barsep">·</span> ', Ht::select("anonymous", array("no" => "Open grading", "yes" => "Anonymous grading"), $pset->anonymous ? "yes" : "no"), '</span>'; echo ' ', Ht::submit("reconfig", "Save"); if (!$pset->disabled) { echo ' <span class="barsep">·</span> '; echo Ht::js_button("Grade report", "window.location=\"" . hoturl_post("index", ["pset" => $pset->urlkey, "report" => 1]) . "\""); } echo "</div></form>"; echo Ht::unstash_script("\$('.need-pa-pset-actions').each(pa_pset_actions)"); }
private function run() { global $Conf, $Opt, $Me, $Error, $subjectPrefix, $mailer_options; $subject = trim(defval($_REQUEST, "subject", "")); if (substr($subject, 0, strlen($subjectPrefix)) != $subjectPrefix) { $subject = $subjectPrefix . $subject; } $emailBody = $_REQUEST["emailBody"]; $template = array("subject" => $subject, "body" => $emailBody); $rest = array("cc" => $_REQUEST["cc"], "reply-to" => $_REQUEST["replyto"], "pset" => $this->recip->pset, "no_error_quit" => true); $rest = array_merge($rest, $mailer_options); $mailer = new CS61Mailer($Me, null, $rest); $prep = $mailer->make_preparation($template, $rest); $paper_sensitive = preg_match('/%[A-Z0-9]+[(%]/', $prep->subject . $prep->body); $q = $this->recip->query($paper_sensitive); if (!$q) { return $Conf->errorMsg("Bad recipients value"); } $result = $Conf->qe_raw($q); if (!$result) { return; } $recipients = defval($_REQUEST, "recipients", ""); if ($this->sending) { $q = "recipients='" . sqlq($recipients) . "', cc='" . sqlq($_REQUEST["cc"]) . "', replyto='" . sqlq($_REQUEST["replyto"]) . "', subject='" . sqlq($_REQUEST["subject"]) . "', emailBody='" . sqlq($_REQUEST["emailBody"]) . "'"; if ($Conf->sversion >= 79) { $q .= ", q='" . sqlq($_REQUEST["q"]) . "', t='" . sqlq($_REQUEST["t"]) . "'"; } if ($log_result = Dbl::query_raw("insert into MailLog set {$q}")) { $this->mailid_text = " #" . $log_result->insert_id; } $Me->log_activity("Sending mail{$this->mailid_text} \"{$subject}\""); } else { $rest["no_send"] = true; } $mailer = new CS61Mailer(); $fake_prep = (object) array("subject" => "", "body" => "", "to" => array(), "contactId" => array(), "fake" => 1); $last_prep = $fake_prep; $nrows_done = 0; $nrows_left = edb_nrows($result); $nwarnings = 0; $preperrors = array(); while ($row = edb_orow($result)) { ++$nrows_done; $contact = new Contact($row); $mailer->reset($contact, $row, $rest); $prep = $mailer->make_preparation($template, $rest); if (@$prep->errors) { foreach ($prep->errors as $lcfield => $hline) { $reqfield = $lcfield == "reply-to" ? "replyto" : $lcfield; $Error[$reqfield] = true; $emsg = Mailer::$email_fields[$lcfield] . " destination isn’t a valid email list: <blockquote><tt>" . htmlspecialchars($hline) . "</tt></blockquote> Make sure email address are separated by commas; put names in \"quotes\" and email addresses in <angle brackets>."; if (!isset($preperrors[$emsg])) { $Conf->errorMsg($emsg); } $preperrors[$emsg] = true; } } else { if ($this->process_prep($prep, $last_prep, $row)) { if ((!$Me->privChair || @$Opt["chairHidePasswords"]) && !@$last_prep->sensitive) { $srest = array_merge($rest, array("sensitivity" => "display")); $mailer->reset($contact, $row, $srest); $last_prep->sensitive = $mailer->make_preparation($template, $srest); } } } if ($nwarnings != $mailer->nwarnings() || $nrows_done % 5 == 0) { $this->echo_mailinfo($nrows_done, $nrows_left); } if ($nwarnings != $mailer->nwarnings()) { $this->echo_prologue(); $nwarnings = $mailer->nwarnings(); echo "<div id='foldmailwarn{$nwarnings}' class='hidden'><div class='warning'>", join("<br />", $mailer->warnings()), "</div></div>"; echo Ht::unstash_script("\$\$('mailwarnings').innerHTML = \$\$('foldmailwarn{$nwarnings}').innerHTML;"); } } $this->process_prep($fake_prep, $last_prep, (object) array()); $this->echo_mailinfo($nrows_done, $nrows_left); if (!$this->started && !count($preperrors)) { return $Conf->errorMsg("No users match “" . $this->recip->unparse() . "” for that search."); } else { if (!$this->started) { return false; } else { if (!$this->sending) { $this->echo_actions(); } } } echo "</div></form>"; echo Ht::unstash_script("fold('mail', null);"); $Conf->footer(); exit; }