}
    Dbl::qx_raw("unlock tables");
    unset($_REQUEST["email"], $_GET["email"], $_POST["email"]);
    unset($_REQUEST["name"], $_GET["name"], $_POST["name"]);
}
// add primary or secondary reviewer
if (isset($_REQUEST["addpc"]) && $Me->allow_administer($prow) && check_post()) {
    if (($pcid = cvtint(@$_REQUEST["pcid"])) <= 0) {
        Conf::msg_error("Enter a PC member.");
    } else {
        if (($pctype = cvtint(@$_REQUEST["pctype"])) == REVIEW_PRIMARY || $pctype == REVIEW_SECONDARY || $pctype == REVIEW_PC) {
            $Me->assign_review($prow->paperId, $pcid, $pctype);
            $Conf->update_rev_tokens_setting(false);
        }
    }
    loadRows();
}
// paper table
$paperTable = new PaperTable($prow, make_qreq(), "assign");
$paperTable->initialize(false, false);
confHeader();
// begin form and table
$loginUrl = hoturl_post("assign", "p={$prow->paperId}");
$paperTable->paptabBegin();
// reviewer information
$proposals = null;
if (setting("extrev_chairreq")) {
    if ($Me->allow_administer($prow)) {
        $q = "";
    } else {
        $q = " and requestedBy={$Me->contactId}";
function update_paper($pj, $opj, $qreq, $action, $diffs)
{
    global $Conf, $Me, $Opt, $OK, $Error, $prow;
    // XXX lock tables
    $ps = new PaperStatus($Me);
    $saved = $ps->save_paper_json($pj);
    if (!$saved && !$prow && count($qreq->_FILES)) {
        $ps->set_error_html("paper", "<strong>Your uploaded files were ignored.</strong>");
    }
    if (!get($pj, "collaborators") && $Conf->setting("sub_collab")) {
        $field = $Conf->setting("sub_pcconf") ? "Other conflicts" : "Potential conflicts";
        $ps->set_warning_html("collaborators", "Please enter the authors’ potential conflicts in the {$field} field. If none of the authors have potential conflicts, just enter “None”.");
    }
    $Error = $ps->error_fields();
    if (!$saved) {
        $emsg = $ps->error_html();
        Conf::msg_error("There were errors in saving your paper. Please fix them and try again." . (count($emsg) ? "<ul><li>" . join("</li><li>", $emsg) . "</li></ul>" : ""));
        return false;
    }
    // note differences in contacts
    $contacts = $ocontacts = [];
    foreach (get($pj, "contacts", []) as $v) {
        $contacts[] = strtolower(is_string($v) ? $v : $v->email);
    }
    if ($opj && get($opj, "contacts")) {
        foreach ($opj->contacts as $v) {
            $ocontacts[] = strtolower($v->email);
        }
    }
    sort($contacts);
    sort($ocontacts);
    if (json_encode($contacts) !== json_encode($ocontacts)) {
        $diffs["contacts"] = true;
    }
    // submit paper if no error so far
    $_REQUEST["paperId"] = $_GET["paperId"] = $qreq->paperId = $pj->pid;
    loadRows();
    if ($action === "final") {
        $submitkey = "timeFinalSubmitted";
        $storekey = "finalPaperStorageId";
    } else {
        $submitkey = "timeSubmitted";
        $storekey = "paperStorageId";
    }
    $wasSubmitted = $opj && get($opj, "submitted");
    if (get($pj, "submitted") || $Conf->can_pc_see_all_submissions()) {
        $Conf->update_papersub_setting(true);
    }
    if ($wasSubmitted != get($pj, "submitted")) {
        $diffs["submission"] = 1;
    }
    // confirmation message
    if ($action == "final") {
        $actiontext = "Updated final version of";
        $template = "@submitfinalpaper";
    } else {
        if (get($pj, "submitted") && !$wasSubmitted) {
            $actiontext = "Submitted";
            $template = "@submitpaper";
        } else {
            if (!$opj) {
                $actiontext = "Registered new";
                $template = "@registerpaper";
            } else {
                $actiontext = "Updated";
                $template = "@updatepaper";
            }
        }
    }
    // additional information
    $notes = array();
    if ($action == "final") {
        if ($prow->{$submitkey} === null || $prow->{$submitkey} <= 0) {
            $notes[] = "The final version has not yet been submitted.";
        }
        $deadline = $Conf->printableTimeSetting("final_soft", "span");
        if ($deadline != "N/A" && $Conf->deadlinesAfter("final_soft")) {
            $notes[] = "<strong>The deadline for submitting final versions was {$deadline}.</strong>";
        } else {
            if ($deadline != "N/A") {
                $notes[] = "You have until {$deadline} to make further changes.";
            }
        }
    } else {
        if (get($pj, "submitted")) {
            $notes[] = "You will receive email when reviews are available.";
        } else {
            if ($prow->size == 0 && !opt("noPapers")) {
                $notes[] = "The submission has not yet been uploaded.";
            } else {
                if ($Conf->setting("sub_freeze") > 0) {
                    $notes[] = "The submission has not yet been completed.";
                } else {
                    $notes[] = "The submission is marked as not ready for review.";
                }
            }
        }
        $deadline = $Conf->printableTimeSetting("sub_update", "span");
        if ($deadline != "N/A" && ($prow->timeSubmitted <= 0 || $Conf->setting("sub_freeze") <= 0)) {
            $notes[] = "Further updates are allowed until {$deadline}.";
        }
        $deadline = $Conf->printableTimeSetting("sub_sub", "span");
        if ($deadline != "N/A" && $prow->timeSubmitted <= 0) {
            $notes[] = "<strong>If the submission " . ($Conf->setting("sub_freeze") > 0 ? "is not completed" : "is not ready for review") . " by {$deadline}, it will not be considered.</strong>";
        }
    }
    $notes = join(" ", $notes);
    $webnotes = "";
    if (count($ps->error_html())) {
        $webnotes .= " <ul><li>" . join("</li><li>", $ps->error_html()) . "</li></ul>";
    }
    if (!count($diffs)) {
        $Conf->warnMsg("There were no changes to submission #{$prow->paperId}. " . $notes . $webnotes);
        return true;
    }
    // HTML confirmation
    if ($prow->{$submitkey} > 0) {
        $Conf->confirmMsg($actiontext . " submission #{$prow->paperId}. " . $notes . $webnotes);
    } else {
        $Conf->warnMsg($actiontext . " submission #{$prow->paperId}. " . $notes . $webnotes);
    }
    // mail confirmation to all contact authors
    if (!$Me->privChair || $qreq->doemail > 0) {
        $options = array("infoNames" => 1);
        if ($Me->privChair && $prow->conflictType < CONFLICT_AUTHOR) {
            $options["adminupdate"] = true;
        }
        if ($Me->privChair && isset($qreq->emailNote)) {
            $options["reason"] = $qreq->emailNote;
        }
        if ($notes !== "") {
            $options["notes"] = preg_replace(",</?(?:span.*?|strong)>,", "", $notes) . "\n\n";
        }
        HotCRPMailer::send_contacts($template, $prow, $options);
    }
    // other mail confirmations
    if ($action == "final" && $OK && !count($Error)) {
        $prow->notify(WATCHTYPE_FINAL_SUBMIT, "final_submit_watch_callback", $Me);
    }
    $Me->log_activity($actiontext, $prow->paperId);
    return true;
}