function run(Contact $user, $qreq, $ssel) { global $Conf; $o = cvtint($qreq->decision); $decision_map = $Conf->decision_map(); if ($o === null || !isset($decision_map[$o])) { return Conf::msg_error("Bad decision value."); } $result = Dbl::qe_raw($Conf->paperQuery($user, array("paperId" => $ssel->selection()))); $success = $fails = array(); while ($prow = PaperInfo::fetch($result, $user)) { if ($user->can_set_decision($prow, true)) { $success[] = $prow->paperId; } else { $fails[] = "#" . $prow->paperId; } } if (count($fails)) { Conf::msg_error("You cannot set paper decisions for " . pluralx($fails, "paper") . " " . commajoin($fails) . "."); } if (count($success)) { Dbl::qe("update Paper set outcome={$o} where paperId ?a", $success); $Conf->update_paperacc_setting($o > 0); redirectSelf(array("atab" => "decide", "decision" => $o)); } }
static function save_clickthrough($user) { global $Conf, $Now; $confirmed = false; if (@$_REQUEST["clickthrough_accept"] && @$_REQUEST["clickthrough_sha1"]) { $user->merge_and_save_data(array("clickthrough" => array($_REQUEST["clickthrough_sha1"] => $Now))); $confirmed = true; } else { if (@$_REQUEST["clickthrough_decline"]) { $Conf->errorMsg("You can’t continue until you accept these terms."); } } if (@$_REQUEST["ajax"]) { $Conf->ajaxExit(array("ok" => $confirmed)); } redirectSelf(); }
<?php // diff.php -- Peteramati diff page // HotCRP and Peteramati are Copyright (c) 2006-2015 Eddie Kohler and others // See LICENSE for open-source distribution terms require_once "src/initweb.php"; ContactView::set_path_request(array("/@", "/@/p", "/@/p/h", "/@/p/h/h", "/p/h/h")); if ($Me->is_empty()) { $Me->escape(); } global $User, $Pset, $Info; $User = $Me; if (isset($_REQUEST["u"]) && !($User = ContactView::prepare_user($_REQUEST["u"]))) { redirectSelf(array("u" => null)); } assert($User == $Me || $Me->isPC); Ht::stash_script("peteramati_uservalue=" . json_encode($Me->user_linkpart($User))); $Pset = ContactView::find_pset_redirect(@$_REQUEST["pset"]); $Info = ContactView::user_pset_info($User, $Pset); if (!get($_GET, "commit") || !get($_GET, "commit1") || $Pset->gitless) { $Me->escape(); } $diff_options = ["wdiff" => false]; $hasha = $hashb = $hasha_mine = $hashb_mine = null; $hrecent = $Pset->handout_commits(); if ($hasha = git_commit_in_list($hrecent, $_GET["commit"])) { $diff_options["hasha_hrepo"] = true; } else { $hasha = $hasha_mine = $Info->set_commit($_GET["commit"]); } if ($hashb = git_commit_in_list($hrecent, $_GET["commit1"])) {
if (@$_POST["update"] && check_post()) { $ck = $cv = array(); $roles = 0; if (@$_POST["pctype"] === "chair") { $roles |= Contact::ROLE_CHAIR | Contact::ROLE_PC; } else { if (@$_POST["pctype"] === "pc") { $roles |= Contact::ROLE_PC; } } if (@$_POST["sysadmin"]) { $roles |= Contact::ROLE_ADMIN; } $ck[] = "roles={$roles}"; Dbl::qe_apply("update ContactInfo set " . join($ck, ",") . " where contactId=" . $User->contactId, $cv); redirectSelf(); } $Conf->header("Profile", "profile"); $xsep = " <span class='barsep'> | </span> "; echo "<div id='homeinfo'>"; echo "<h2 class='homeemail'>", Text::user_html($User), "</h2>"; if ($User->seascode_username || $User->huid) { echo '<h3><a href="', hoturl("index", array("u" => $Me->user_linkpart($User))), '">', htmlspecialchars($User->seascode_username ?: $User->huid), '</a>'; if ($Me->privChair) { echo " ", become_user_link($User); } echo "</h3>"; } if ($User->dropped) { ContactView::echo_group("", '<strong class="err">You have dropped the course.</strong> If this is incorrect, contact us.'); }
function save_config_overrides($psetkey, $overrides, $json = null) { global $Conf; $dbjson = $Conf->setting_json("psets_override") ?: (object) array(); $all_overrides = (object) array(); $all_overrides->{$psetkey} = $overrides; object_replace_recursive($dbjson, $all_overrides); $dbjson = psets_json_diff_from($json ?: load_psets_json(true), $dbjson); $Conf->save_setting("psets_override", 1, $dbjson); unset($_GET["pset"], $_REQUEST["pset"]); redirectSelf(array("anchor" => $psetkey)); }
function do_setting_update($sv) { global $Conf, $Group, $Me, $Now, $Opt, $OptOverride; // parse settings foreach (Si::$all as $si) { account_value($sv, $si); } // check date relationships foreach (array("sub_reg" => "sub_sub", "final_soft" => "final_done") as $dn1 => $dn2) { list($dv1, $dv2) = [$sv->savedv($dn1), $sv->savedv($dn2)]; } if (!$dv1 && $dv2) { $sv->save($dn1, $dv2); } else { if ($dv2 && $dv1 > $dv2) { $sv->set_error($dn1, unparse_setting_error(Si::get($dn1), "Must come before " . Si::get($dn2, "short_description") . ".")); $sv->set_error($dn2); } } if ($sv->has_savedv("sub_sub")) { $sv->save("sub_update", $sv->savedv("sub_sub")); } if (get($Opt, "defaultSiteContact")) { if ($sv->has_savedv("opt.contactName") && get($Opt, "contactName") === $sv->savedv("opt.contactName")) { $sv->save("opt.contactName", null); } if ($sv->has_savedv("opt.contactEmail") && get($Opt, "contactEmail") === $sv->savedv("opt.contactEmail")) { $sv->save("opt.contactEmail", null); } } if ($sv->has_savedv("resp_active") && $sv->savedv("resp_active")) { foreach (explode(" ", $sv->newv("resp_rounds")) as $i => $rname) { $isuf = $i ? "_{$i}" : ""; if ($sv->newv("resp_open{$isuf}") > $sv->newv("resp_done{$isuf}")) { $sv->set_error("resp_open{$isuf}", unparse_setting_error(Si::get("resp_open"), "Must come before " . Si::get("resp_done", "short_description") . ".")); $sv->set_error("resp_done{$isuf}"); } } } // update 'papersub' if ($sv->has_savedv("pc_seeall")) { // see also conference.php if ($sv->savedv("pc_seeall") <= 0) { $x = "timeSubmitted>0"; } else { $x = "timeWithdrawn<=0"; } $num = Dbl::fetch_ivalue("select paperId from Paper where {$x} limit 1") ? 1 : 0; if ($num != $Conf->setting("papersub")) { $sv->save("papersub", $num); } } // Setting relationships if ($sv->has_savedv("sub_open") && $sv->newv("sub_open", 1) <= 0 && $sv->oldv("sub_open") > 0 && $sv->newv("sub_sub") <= 0) { $sv->save("sub_close", $Now); } if ($sv->has_savedv("msg.clickthrough_submit")) { $sv->save("clickthrough_submit", null); } // make settings $changedn = []; if (!$sv->has_errors() && (count($sv->savedv) || count($sv->save_callbacks))) { $tables = "Settings write"; foreach ($sv->need_lock as $t => $need) { if ($need) { $tables .= ", {$t} write"; } } $Conf->qe("lock tables {$tables}"); // load db settings, pre-crosscheck $dbsettings = array(); $result = Dbl::qe("select name, value, data from Settings"); while ($row = edb_row($result)) { $dbsettings[$row[0]] = $row; } Dbl::free($result); // apply settings foreach ($sv->save_callbacks as $si) { $p = $sv->parser($si); $p->save($sv, $si); } $dv = $aq = $av = array(); foreach ($sv->savedv as $n => $v) { if (substr($n, 0, 4) === "opt." && $v !== null) { $okey = substr($n, 4); $oldv = array_key_exists($okey, $OptOverride) ? $OptOverride[$okey] : get($Opt, $okey); $Opt[$okey] = $v[1] === null ? $v[0] : $v[1]; if ($oldv === $Opt[$okey]) { $v = null; } else { if (!array_key_exists($okey, $OptOverride)) { $OptOverride[$okey] = $oldv; } } } if ($v === null ? !isset($dbsettings[$n]) : isset($dbsettings[$n]) && (int) $dbsettings[$n][1] === $v[0] && $dbsettings[$n][2] === $v[1]) { continue; } $changedn[] = $n; if ($v !== null) { $aq[] = "(?, ?, ?)"; array_push($av, $n, $v[0], $v[1]); } else { $dv[] = $n; } } if (count($dv)) { Dbl::qe_apply("delete from Settings where name?a", array($dv)); //Conf::msg_info(Ht::pre_text_wrap(Dbl::format_query_apply("delete from Settings where name?a", array($dv)))); } if (count($aq)) { Dbl::qe_apply("insert into Settings (name, value, data) values\n\t" . join(",\n\t", $aq) . "\n\ton duplicate key update value=values(value), data=values(data)", $av); //Conf::msg_info(Ht::pre_text_wrap(Dbl::format_query_apply("insert into Settings (name, value, data) values\n\t" . join(",\n\t", $aq) . "\n\ton duplicate key update value=values(value), data=values(data)", $av))); } $Conf->qe("unlock tables"); if (count($changedn)) { $Me->log_activity("Updated settings " . join(", ", $changedn)); } $Conf->load_settings(); // contactdb may need to hear about changes to shortName if ($sv->has_savedv("opt.shortName") && get($Opt, "contactdb_dsn") && ($cdb = Contact::contactdb())) { Dbl::ql($cdb, "update Conferences set shortName=? where dbName=?", $Opt["shortName"], $Opt["dbName"]); } } // update the review form in case it's changed ReviewForm::clear_cache(); if (!$sv->has_errors()) { $Conf->save_session("settings_highlight", $sv->error_fields()); if (count($changedn)) { $Conf->confirmMsg("Changes saved."); } else { $Conf->warnMsg("No changes."); } $sv->report(); redirectSelf(); } else { SettingGroup::crosscheck($sv, $Group); $sv->report(); } }
function installerInit() { sessionInit(); //handle streamed content first if (isset($_SERVER['PATH_INFO'])) { $path_bits = preg_split('/\\//', $_SERVER['PATH_INFO']); $path_bits = cleanPath($path_bits); if (count($path_bits) == 3) { if ($path_bits[0] == "stream") { streamContent($path_bits[2], $path_bits[1]); } } else { redirectSelf(); } } $result = array(); if (installerStep() !== STEP_DONE && getLock()) { installerStepSet(STEP_DONE); redirectSelf(); } $is_redirect = FALSE; if (isset($_GET['restart'])) { session_destroy(); redirectSelf(); } if (isset($_GET['next'])) { transitionNextStep(); } if (isset($_GET['prev'])) { installerStepSet(prevStep(installerStep())); } if (dbEnabled()) { $result['with_db'] = TRUE; } else { $result['with_db'] = FALSE; } $result['step'] = installerStep(); return $result; }
function saveAssignments($qreq, $reviewer) { global $Conf, $Me, $Now, $pcm; $reviewer_contact = $pcm[$reviewer]; $round_number = null; if (!count($qreq->assrev)) { return; } $result = Dbl::qe_raw($Conf->paperQuery($Me, array("paperId" => array_keys($qreq->assrev), "reviewer" => $reviewer))); $lastPaperId = -1; $del = $ins = ""; while ($row = PaperInfo::fetch($result, $Me)) { if ($row->paperId == $lastPaperId || !$Me->can_administer($row) || $row->reviewerConflictType >= CONFLICT_AUTHOR || !isset($qreq->assrev[$row->paperId])) { continue; } $lastPaperId = $row->paperId; $type = $qreq->assrev[$row->paperId]; if ($type >= 0 && $row->reviewerConflictType > 0 && $row->reviewerConflictType < CONFLICT_AUTHOR) { $del .= " or paperId={$row->paperId}"; } if ($type < 0 && $row->reviewerConflictType < CONFLICT_CHAIRMARK) { $ins .= ", ({$row->paperId}, {$reviewer}, " . CONFLICT_CHAIRMARK . ")"; } if ($qreq->kind == "a" && $type != $row->reviewerReviewType && ($type <= 0 || $reviewer_contact->can_accept_review_assignment_ignore_conflict($row))) { if ($type > 0 && $round_number === null) { $round_number = $Conf->round_number($qreq->rev_roundtag, true); } $Me->assign_review($row->paperId, $reviewer, $type, array("round_number" => $round_number)); } } if ($ins) { $Conf->qe("insert into PaperConflict (paperId, contactId, conflictType) values " . substr($ins, 2) . " on duplicate key update conflictType=greatest(conflictType,values(conflictType))"); } if ($del) { $Conf->qe("delete from PaperConflict where contactId={$reviewer} and (" . substr($del, 4) . ")"); } $Conf->update_rev_tokens_setting(false); if ($Conf->setting("pcrev_assigntime") == $Now) { $Conf->confirmMsg("Assignments saved! You may want to <a href=\"" . hoturl("mail", "template=newpcrev") . "\">send mail about the new assignments</a>."); } redirectSelf(["kind" => $qreq->kind]); }
// collect allowed graphs $Graphs = array(); if ($Me->isPC) { $Graphs["procrastination"] = "Procrastination"; $Graphs["formula"] = "Formula"; } if (!count($Graphs)) { $Me->escape(); } reset($Graphs); $GraphSynonym = array("reviewerlameness" => "procrastination"); if ($Graph && isset($GraphSynonym[$Graph])) { $Graph = $GraphSynonym[$Graph]; } if (!$Graph || !isset($Graphs[$Graph])) { redirectSelf(array("g" => key($Graphs))); } // Header and body $Conf->header("Graphs", "graphbody", actionBar()); $Conf->echoScript(""); echo $Conf->make_script_file("scripts/d3.min.js", true); echo $Conf->make_script_file("scripts/graph.js"); function echo_graph() { echo '<div id="hotgraph" style="position:relative;max-width:960px;margin-bottom:4em"></div>', "\n"; } // Procrastination report if ($Graph == "procrastination") { echo "<h2>Procrastination</h2>\n"; echo_graph(); $rt = new ReviewTimes($Me);
} } // Double-encoding bugs found? if ($Conf->setting("bug_doubleencoding")) { $m[] = "Double-encoded URLs have been detected. Incorrect uses of Apache’s <code>mod_rewrite</code>, and other middleware, can encode URL parameters twice. This can cause problems, for instance when users log in via links in email. (“<code>a@b.com</code>” should be encoded as “<code>a%40b.com</code>”; a double encoding will produce “<code>a%2540b.com</code>”.) HotCRP has tried to compensate, but you really should fix the problem. For <code>mod_rewrite</code> add <a href='http://httpd.apache.org/docs/current/mod/mod_rewrite.html'>the <code>[NE]</code> option</a> to the relevant RewriteRule. <a href=\"" . hoturl_post("index", "clearbug=doubleencoding") . "\">(Clear this message)</a>"; } // Unnotified reviews? if ($Conf->setting("pcrev_assigntime", 0) > $Conf->setting("pcrev_informtime", 0)) { $assigntime = $Conf->setting("pcrev_assigntime"); $result = $Conf->qe("select paperId from PaperReview where reviewType>" . REVIEW_PC . " and timeRequested>timeRequestNotified and reviewSubmitted is null and reviewNeedsSubmit!=0 limit 1"); if (edb_nrows($result)) { $m[] = "PC review assignments have changed. You may want to <a href=\"" . hoturl("mail", "template=newpcrev") . "\">send mail about the new assignments</a>. <a href=\"" . hoturl_post("index", "clearnewpcrev={$assigntime}") . "\">(Clear this message)</a>"; } else { $Conf->save_setting("pcrev_informtime", $assigntime); } } if (count($m)) { $Conf->warnMsg("<div>" . join('</div><div style="margin-top:0.5em">', $m) . "</div>"); } } assert($Me->privChair); if (isset($_REQUEST["clearbug"]) && check_post()) { $Conf->save_setting("bug_" . $_REQUEST["clearbug"], null); } if (isset($_REQUEST["clearnewpcrev"]) && ctype_digit($_REQUEST["clearnewpcrev"]) && check_post() && $Conf->setting("pcrev_informtime", 0) <= $_REQUEST["clearnewpcrev"]) { $Conf->save_setting("pcrev_informtime", $_REQUEST["clearnewpcrev"]); } if (isset($_REQUEST["clearbug"]) || isset($_REQUEST["clearnewpcrev"])) { redirectSelf(array("clearbug" => null, "clearnewpcrev" => null)); } admin_home_messages();
function change_review_tokens() { global $Conf, $Me; $cleared = $Me->change_review_token(false, false); $tokeninfo = array(); foreach (preg_split('/\\s+/', $_REQUEST["token"]) as $x) { if ($x == "") { /* no complaints */ } else { if (!($token = decode_token($x, "V"))) { Conf::msg_error("Invalid review token “" . htmlspecialchars($x) . "”. Check your typing and try again."); } else { if ($Conf->session("rev_token_fail", 0) >= 5) { Conf::msg_error("Too many failed attempts to use a review token. <a href='" . hoturl("index", "signout=1") . "'>Sign out</a> and in to try again."); } else { $result = Dbl::qe("select paperId from PaperReview where reviewToken=" . $token); if ($row = edb_row($result)) { $tokeninfo[] = "Review token “" . htmlspecialchars($x) . "” lets you review <a href='" . hoturl("paper", "p={$row['0']}") . "'>paper #" . $row[0] . "</a>."; $Me->change_review_token($token, true); } else { Conf::msg_error("Review token “" . htmlspecialchars($x) . "” hasn’t been assigned."); $nfail = $Conf->session("rev_token_fail", 0) + 1; $Conf->save_session("rev_token_fail", $nfail); } } } } } if ($cleared && !count($tokeninfo)) { $tokeninfo[] = "Review tokens cleared."; } if (count($tokeninfo)) { $Conf->infoMsg(join("<br />\n", $tokeninfo)); } redirectSelf(); }
function do_tags() { global $Conf, $Me, $papersel; // check tags $tagger = new Tagger($Me); $t1 = array(); $errors = array(); foreach (preg_split('/[\\s,]+/', (string) @$_REQUEST["tag"]) as $t) { if ($t === "") { /* nada */ } else { if (!($t = $tagger->check($t, Tagger::NOPRIVATE))) { $errors[] = $tagger->error_html; } else { if (TagInfo::base($t) === "pc") { $errors[] = "The “pc” user tag is set automatically for all PC members."; } else { $t1[] = $t; } } } } if (count($errors)) { return Conf::msg_error(join("<br>", $errors)); } else { if (!count($t1)) { return $Conf->warnMsg("Nothing to do."); } } // modify database Dbl::qe("lock tables ContactInfo write"); Conf::$no_invalidate_caches = true; $users = array(); if ($_REQUEST["tagtype"] === "s") { // erase existing tags $likes = array(); $removes = array(); foreach ($t1 as $t) { list($tag, $index) = TagInfo::split_index($t); $removes[] = $t; $likes[] = "contactTags like " . Dbl::utf8ci("'% " . sqlq_for_like($tag) . "#%'"); } foreach (Dbl::fetch_first_columns(Dbl::qe("select contactId from ContactInfo where " . join(" or ", $likes))) as $cid) { $users[(int) $cid] = (object) array("id" => (int) $cid, "add_tags" => [], "remove_tags" => $removes); } } // account for request $key = $_REQUEST["tagtype"] === "d" ? "remove_tags" : "add_tags"; foreach ($papersel as $cid) { if (!isset($users[(int) $cid])) { $users[(int) $cid] = (object) array("id" => (int) $cid, "add_tags" => [], "remove_tags" => []); } $users[(int) $cid]->{$key} = array_merge($users[(int) $cid]->{$key}, $t1); } // apply modifications foreach ($users as $cid => $cj) { $us = new UserStatus(array("send_email" => false)); if (!$us->save($cj)) { $errors = array_merge($errors, $us->error_messages()); } } Dbl::qe("unlock tables"); Conf::$no_invalidate_caches = false; $Conf->invalidateCaches(["pc" => true]); // report if (!count($errors)) { $Conf->confirmMsg("Tags saved."); redirectSelf(array("tagact" => null, "tag" => null)); } else { Conf::msg_error(join("<br>", $errors)); } }
function run(Contact $user, $qreq, $ssel) { global $Conf; $papers = $ssel->selection(); $act = $qreq->tagfn; $tagreq = trim(str_replace(",", " ", (string) $qreq->tag)); $tags = preg_split('/\\s+/', $tagreq); if ($act == "da") { $otags = $tags; foreach ($otags as $t) { $tags[] = "all~" . preg_replace(',\\A.*~([^~]+)\\z', '$1', $t); } $act = "d"; } else { if ($act == "sor") { shuffle($papers); } } $x = array("action,paper,tag\n"); if ($act == "s" || $act == "so" || $act == "sos" || $act == "sor") { foreach ($tags as $t) { $x[] = "cleartag,all," . TagInfo::base($t) . "\n"; } } if ($act == "s" || $act == "a") { $action = "tag"; } else { if ($act == "d") { $action = "cleartag"; } else { if ($act == "so" || $act == "sor" || $act == "ao") { $action = "nexttag"; } else { if ($act == "sos" || $act == "aos") { $action = "seqnexttag"; } else { $action = null; } } } } $assignset = new AssignmentSet($user, $user->privChair); if (count($papers) && $action) { foreach ($papers as $p) { foreach ($tags as $t) { $x[] = "{$action},{$p},{$t}\n"; } } $assignset->parse(join("", $x)); } else { if (count($papers) && $act == "cr" && $user->privChair) { $source_tag = trim((string) $qreq->tagcr_source); if ($source_tag == "") { $source_tag = substr($tagreq, 0, 2) == "~~" ? substr($tagreq, 2) : $tagreq; } $tagger = new Tagger($user); if ($tagger->check($tagreq, Tagger::NOPRIVATE | Tagger::NOVALUE) && $tagger->check($source_tag, Tagger::NOPRIVATE | Tagger::NOCHAIR | Tagger::NOVALUE)) { $r = new PaperRank($source_tag, $tagreq, $papers, $qreq->tagcr_gapless, "Search", "search"); $r->run($qreq->tagcr_method); $r->apply($assignset); $assignset->finish(); if ($qreq->q === "") { $qreq->q = "order:{$tagreq}"; } } else { $assignset->error($tagger->error_html); } } } if ($errors = join("<br />\n", $assignset->errors_html())) { if ($assignset->has_assigners()) { Conf::msg_warning("Some tag assignments were ignored:<br />\n{$errors}"); $assignset->clear_errors(); } else { Conf::msg_error($errors); } } $success = $assignset->execute(); if (!$Conf->headerPrinted && $qreq->ajax) { $Conf->ajaxExit(array("ok" => $success)); } else { if (!$Conf->headerPrinted && $success) { if (!$errors) { $Conf->confirmMsg("Tags saved."); } $args = array("atab" => "tag"); foreach (array("tag", "tagfn", "tagcr_method", "tagcr_source", "tagcr_gapless") as $arg) { if (isset($qreq[$arg])) { $args[$arg] = $qreq[$arg]; } } redirectSelf($args); } } }
function savePreferences($Qreq) { global $Conf, $Me, $OK, $reviewer, $incorrect_reviewer; if ($incorrect_reviewer) { Conf::msg_error("Preferences not saved."); return; } $setting = array(); $error = false; $pmax = 0; foreach ($Qreq as $k => $v) { if (strlen($k) > 7 && $k[0] == "r" && substr($k, 0, 7) == "revpref" && ($p = cvtint(substr($k, 7))) > 0) { if ($pref = parse_preference($v)) { $setting[$p] = $pref; $pmax = max($pmax, $p); } else { $error = true; } } } if ($error) { Conf::msg_error("Preferences must be small positive or negative integers."); } if ($pmax == 0 && !$error) { Conf::msg_error("No reviewer preferences to update."); } if ($pmax == 0) { return; } $deletes = array(); for ($p = 1; $p <= $pmax; $p++) { if (isset($setting[$p])) { $p0 = $p; while (isset($setting[$p + 1])) { ++$p; } if ($p0 == $p) { $deletes[] = "paperId={$p0}"; } else { $deletes[] = "paperId between {$p0} and {$p}"; } } } if (count($deletes)) { $Conf->qe("delete from PaperReviewPreference where contactId={$reviewer} and (" . join(" or ", $deletes) . ")"); } $q = array(); for ($p = 1; $p <= $pmax; $p++) { if (($pref = get($setting, $p)) && ($pref[0] || $pref[1] !== null)) { $q[] = array($p, $reviewer, $pref[0], $pref[1]); } } PaperActions::save_review_preferences($q); if ($OK) { $Conf->confirmMsg("Preferences saved."); redirectSelf(); } }
static function set_repo_action($user) { global $Conf, $Me, $ConfSitePATH; if (!($Me->has_database_account() && check_post() && ($pset = $Conf->pset_by_key(req("pset"))))) { return; } if (!$Me->can_set_repo($pset, $user)) { return Conf::msg_error("You can’t edit repository information for that problem set now."); } // clean up repo url $repo_url = trim(req("repo")); if ($pset->repo_guess_patterns) { for ($i = 0; $i + 1 < count($pset->repo_guess_patterns); $i += 2) { $x = preg_replace('`' . str_replace("`", "\\`", $pset->repo_guess_patterns[$i]) . '`s', $pset->repo_guess_patterns[$i + 1], $repo_url, -1, $nreplace); if ($x !== null && $nreplace) { $repo_url = $x; break; } } } // does it contain odd characters? if (preg_match('_[,;\\[\\](){}\\<>&#=\\000-\\027]_', $repo_url)) { return Conf::msg_error("That repository contains funny characters. Remove them."); } // record interested repositories $try_classes = []; foreach (RepositorySite::site_classes($user->conf) as $sitek) { $sniff = $sitek::sniff_url($repo_url); if ($sniff == 2) { $try_classes = [$sitek]; break; } else { if ($sniff) { $try_classes[] = $sitek; } } } if (empty($try_classes)) { return Conf::msg_error("Invalid repository URL “" . htmlspecialchars($repo_url) . "”."); } // check repositories $working = false; $ms = new MessageSet($user); foreach ($try_classes as $sitek) { $reposite = $sitek::make_url($repo_url, $user->conf); if ($reposite && $reposite->validate_working($ms) > 0) { $working = true; break; } } // if !working, complain if (!$working && !$ms->has_problems()) { return Conf::msg_error("Invalid repository URL “" . htmlspecialchars($repo_url) . "” (tried " . join(", ", array_map(function ($m) { return $m::global_friendly_siteclass(); }, $try_classes)) . ")."); } else { if (!$working) { $msgs = join("<br />", $ms->messages()) ?: "Repository unreachable at the moment."; return Conf::msg_error($msgs); } } // store repo $repo = Repository::find_or_create_url($reposite->url, $user->conf); $repo && $repo->check_open(); if ($user->set_repo($pset, $repo)) { redirectSelf(); } }
static function set_seascode_repo_action($user) { global $Conf, $Me; if (!($Me->has_database_account() && check_post() && ($pset = Pset::find(@$_REQUEST["pset"])))) { return; } if (!$Me->can_set_repo($pset, $user)) { return $Conf->errorMsg("You can’t edit repository information for that problem set now."); } if ($user->set_seascode_repo($pset, $_REQUEST["repo"])) { redirectSelf(); } }