Esempio n. 1
0
function handle_set_round()
{
    global $Conf, $Me, $prow, $rrows;
    // check permissions
    if (!@$_REQUEST["r"] || !($rr = rrow_by_reviewid($_REQUEST["r"]))) {
        $Conf->ajaxExit(array("ok" => false, "error" => "No such review."));
    }
    if (!$Me->can_administer($prow)) {
        $Conf->ajaxExit(array("ok" => false, "error" => "Permission denied."));
    }
    $rname = trim((string) $_POST["round"]);
    $round = $Conf->sanitize_round_name($rname);
    if ($round === false) {
        $Conf->ajaxExit(array("ok" => false, "error" => Conf::round_name_error($rname)));
    }
    // assign round
    $rnum = $Conf->round_number($rname, true);
    Dbl::qe("update PaperReview set reviewRound={$rnum} where reviewId={$rr->reviewId}");
    $Conf->ajaxExit(array("ok" => true));
}
 public function check()
 {
     global $Error, $Qreq;
     $atypes = array("rev" => "r", "revadd" => "r", "revpc" => "r", "lead" => true, "shepherd" => true, "prefconflict" => true, "clear" => true, "discorder" => true);
     $this->atype = $Qreq->a;
     if (!$this->atype || !isset($atypes[$this->atype])) {
         $Error["ass"] = true;
         return Conf::msg_error("Malformed request!");
     }
     $this->atype_review = $atypes[$this->atype] === "r";
     $r = false;
     if ($this->atype_review) {
         $r = $Qreq[$this->atype . "type"];
         if ($r != REVIEW_PRIMARY && $r != REVIEW_SECONDARY && $r != REVIEW_PC) {
             $Error["ass"] = true;
             return Conf::msg_error("Malformed request!");
         }
     } else {
         if ($this->atype === "clear") {
             $r = $Qreq->cleartype;
             if ($r != REVIEW_PRIMARY && $r != REVIEW_SECONDARY && $r != REVIEW_PC && $r !== "conflict" && $r !== "lead" && $r !== "shepherd") {
                 $Error["clear"] = true;
                 return Conf::msg_error("Malformed request!");
             }
         }
     }
     $this->reviewtype = $r;
     if ($this->atype_review && $Qreq->rev_roundtag !== "" && ($err = Conf::round_name_error($Qreq->rev_roundtag))) {
         $Error["rev_roundtag"] = true;
         return Conf::msg_error($err);
     }
     if ($this->atype === "rev" && cvtint($Qreq->revct, -1) <= 0) {
         $Error["rev"] = true;
         return Conf::msg_error("Enter the number of reviews you want to assign.");
     } else {
         if ($this->atype === "revadd" && cvtint($Qreq->revaddct, -1) <= 0) {
             $Error["revadd"] = true;
             return Conf::msg_error("You must assign at least one review.");
         } else {
             if ($this->atype === "revpc" && cvtint($Qreq->revpcct, -1) <= 0) {
                 $Error["revpc"] = true;
                 return Conf::msg_error("You must assign at least one review.");
             }
         }
     }
     if ($this->atype === "discorder") {
         $tag = trim((string) $Qreq->discordertag);
         $tag = $tag === "" ? "discuss" : $tag;
         $tagger = new Tagger();
         if (!($tag = $tagger->check($tag, Tagger::NOVALUE))) {
             $Error["discordertag"] = true;
             return Conf::msg_error($tagger->error_html);
         }
         $this->discordertag = $tag;
     }
     return $this->ok = true;
 }
 function apply($pid, $contact, &$req, AssignmentState $state)
 {
     global $Conf;
     // parse round and reviewtype arguments
     $rarg0 = trim(get_s($req, "round"));
     $oldround = null;
     if ($rarg0 !== "" && strcasecmp($rarg0, "any") != 0 && ($oldround = $Conf->sanitize_round_name($rarg0)) === false) {
         return Conf::round_name_error($rarg0);
     }
     $targ0 = trim(get_s($req, "reviewtype"));
     $oldtype = null;
     if ($targ0 !== "" && ($oldtype = ReviewAssigner_Data::parse_type($targ0)) === false) {
         return "Invalid reviewtype.";
     }
     // remove existing review
     $revmatch = ["type" => "review", "pid" => $pid, "cid" => $contact ? $contact->contactId : null, "_rtype" => $oldtype, "_round" => $oldround, "_rsubmitted" => 1];
     $matches = $state->remove($revmatch);
     foreach ($matches as $r) {
         $r["_rsubmitted"] = 0;
         $state->add($r);
     }
 }
 function parse($sv, $si)
 {
     global $Conf;
     if (!isset($sv->req["rev_roundtag"])) {
         $sv->save("rev_roundtag", null);
         return false;
     }
     // round names
     $roundnames = $roundnames_set = array();
     $roundname0 = $round_deleted = null;
     for ($i = 0; isset($sv->req["roundname_{$i}"]) || isset($sv->req["deleteround_{$i}"]) || !$i; ++$i) {
         $rname = trim(get_s($sv->req, "roundname_{$i}"));
         if ($rname === "(no name)" || $rname === "default" || $rname === "unnamed") {
             $rname = "";
         }
         if ((get($sv->req, "deleteround_{$i}") || $rname === "") && $i) {
             $roundnames[] = ";";
             if (Dbl::fetch_ivalue("select reviewId from PaperReview where reviewRound={$i} limit 1")) {
                 $this->rev_round_changes[] = array($i, 0);
             }
             if ($round_deleted === null && !isset($sv->req["roundname_0"]) && $i < $sv->req["oldroundcount"]) {
                 $round_deleted = $i;
             }
         } else {
             if ($rname === "") {
                 /* ignore */
             } else {
                 if ($rerror = Conf::round_name_error($rname)) {
                     $sv->set_error("roundname_{$i}", $rerror);
                 } else {
                     if ($i == 0) {
                         $roundname0 = $rname;
                     } else {
                         if (get($roundnames_set, strtolower($rname))) {
                             $roundnames[] = ";";
                             $this->rev_round_changes[] = array($i, $roundnames_set[strtolower($rname)]);
                         } else {
                             $roundnames[] = $rname;
                             $roundnames_set[strtolower($rname)] = $i;
                         }
                     }
                 }
             }
         }
     }
     if ($roundname0 && !get($roundnames_set, strtolower($roundname0))) {
         $roundnames[] = $roundname0;
         $roundnames_set[strtolower($roundname0)] = count($roundnames);
     }
     if ($roundname0) {
         array_unshift($this->rev_round_changes, array(0, $roundnames_set[strtolower($roundname0)]));
     }
     // round deadlines
     foreach ($Conf->round_list() as $i => $rname) {
         $suffix = $i ? "_{$i}" : "";
         foreach (Conf::$review_deadlines as $k) {
             $sv->save($k . $suffix, null);
         }
     }
     $rtransform = array();
     if ($roundname0 && ($ri = $roundnames_set[strtolower($roundname0)]) && !isset($sv->req["pcrev_soft_{$ri}"])) {
         $rtransform[0] = "_{$ri}";
         $rtransform[$ri] = false;
     }
     if ($round_deleted) {
         $rtransform[$round_deleted] = "";
         if (!isset($rtransform[0])) {
             $rtransform[0] = false;
         }
     }
     for ($i = 0; $i < count($roundnames) + 1; ++$i) {
         if ((isset($rtransform[$i]) || ($i ? $roundnames[$i - 1] !== ";" : !isset($sv->req["deleteround_0"]))) && get($rtransform, $i) !== false) {
             $isuffix = $i ? "_{$i}" : "";
             if (($osuffix = get($rtransform, $i)) === null) {
                 $osuffix = $isuffix;
             }
             $ndeadlines = 0;
             foreach (Conf::$review_deadlines as $k) {
                 $v = parse_value($sv, $k . $isuffix, Si::get($k));
                 $sv->save($k . $osuffix, $v <= 0 ? null : $v);
                 $ndeadlines += $v > 0;
             }
             if ($ndeadlines == 0 && $osuffix) {
                 $sv->save("pcrev_soft{$osuffix}", 0);
             }
             foreach (array("pcrev_", "extrev_") as $k) {
                 list($soft, $hard) = ["{$k}soft{$osuffix}", "{$k}hard{$osuffix}"];
                 list($softv, $hardv) = [$sv->savedv($soft), $sv->savedv($hard)];
                 if (!$softv && $hardv) {
                     $sv->save($soft, $hardv);
                 } else {
                     if ($hardv && $softv > $hardv) {
                         $desc = $i ? ", round " . htmlspecialchars($roundnames[$i - 1]) : "";
                         $sv->set_error($soft, Si::get("{$k}soft", "short_description") . $desc . ": Must come before " . Si::get("{$k}hard", "short_description") . ".");
                         $sv->set_error($hard);
                     }
                 }
             }
         }
     }
     // round list (save after deadlines processing)
     while (count($roundnames) && $roundnames[count($roundnames) - 1] === ";") {
         array_pop($roundnames);
     }
     $sv->save("tag_rounds", join(" ", $roundnames));
     // default round
     $t = trim($sv->req["rev_roundtag"]);
     $sv->save("rev_roundtag", null);
     if (preg_match('/\\A(?:|\\(none\\)|\\(no name\\)|default|unnamed)\\z/i', $t)) {
         /* do nothing */
     } else {
         if ($t === "#0") {
             if ($roundname0) {
                 $sv->save("rev_roundtag", $roundname0);
             }
         } else {
             if (preg_match('/^#[1-9][0-9]*$/', $t)) {
                 $rname = get($roundnames, substr($t, 1) - 1);
                 if ($rname && $rname !== ";") {
                     $sv->save("rev_roundtag", $rname);
                 }
             } else {
                 if (!($rerror = Conf::round_name_error($t))) {
                     $sv->save("rev_roundtag", $t);
                 } else {
                     $sv->set_error("rev_roundtag", $rerror);
                 }
             }
         }
     }
     if (count($this->rev_round_changes)) {
         $sv->need_lock["PaperReview"] = true;
         return true;
     } else {
         return false;
     }
 }