static function setReviewPreference($prow)
 {
     global $Conf, $Me, $Error, $OK;
     $ajax = defval($_REQUEST, "ajax", false);
     if (!$Me->allow_administer($prow) || ($contactId = cvtint(@$_REQUEST["reviewer"])) <= 0) {
         $contactId = $Me->contactId;
     }
     if (isset($_REQUEST["revpref"]) && ($v = parse_preference($_REQUEST["revpref"]))) {
         if (self::save_review_preferences(array(array($prow->paperId, $contactId, $v[0], $v[1])))) {
             $Conf->confirmMsg($ajax ? "Saved" : "Review preference saved.");
         } else {
             $Error["revpref"] = true;
         }
         $v = unparse_preference($v);
     } else {
         $v = null;
         Conf::msg_error($ajax ? "Bad preference" : "Bad preference “" . htmlspecialchars($_REQUEST["revpref"]) . "”.");
         $Error["revpref"] = true;
     }
     if ($ajax) {
         $Conf->ajaxExit(array("ok" => $OK && !@$Error["revpref"], "value" => $v));
     }
 }
Exemplo n.º 2
0
function parse_preference($n)
{
    $n = trim($n);
    if (preg_match(',\\A(-+|\\++|[-+]?\\d+(?:\\.\\d*)?|)\\s*([xyz]|)\\z,i', $n, $m)) {
        if ($m[1] === "") {
            $p = 0;
        } else {
            if (is_numeric($m[1])) {
                if ($m[1] <= 1000000) {
                    $p = round($m[1]);
                } else {
                    return null;
                }
            } else {
                if ($m[1][0] === "-") {
                    $p = -strlen($m[1]);
                } else {
                    $p = strlen($m[1]);
                }
            }
        }
        if ($m[2] === "") {
            $e = null;
        } else {
            $e = 9 - (ord($m[2]) & 15);
        }
        return array($p, $e);
    } else {
        if (strpos($n, "�") !== false) {
            // Translate UTF-8 for minus sign into a real minus sign ;)
            return parse_preference(str_replace("−", '-', $n));
        } else {
            if (strcasecmp($n, "none") == 0 || strcasecmp($n, "n/a") == 0) {
                return array(0, null);
            } else {
                if (strcasecmp($n, "conflict") == 0) {
                    return array(-100, null);
                } else {
                    return null;
                }
            }
        }
    }
}
function parseUploadedPreferences($filename, $printFilename, $reviewer)
{
    global $Conf;
    if (($text = file_get_contents($filename)) === false) {
        return Conf::msg_error("Cannot read uploaded file.");
    }
    $printFilename = htmlspecialchars($printFilename);
    $text = cleannl($text);
    $lineno = 0;
    $successes = 0;
    $errors = array();
    $new_qreq = new Qobject();
    foreach (explode("\n", $text) as $line) {
        $line = trim($line);
        $lineno++;
        if ($line == "" || $line[0] == "#" || substr($line, 0, 6) == "==-== ") {
            /* do nothing */
        } else {
            if (preg_match('/^(\\d+)\\s*[\\t,]\\s*([^\\s,]+)\\s*([\\t,]|$)/', $line, $m)) {
                if (parse_preference($m[2])) {
                    $new_qreq["revpref{$m['1']}"] = $m[2];
                    $successes++;
                } else {
                    if (strcasecmp($m[2], "conflict") != 0) {
                        $errors[] = "<span class='lineno'>{$printFilename}:{$lineno}:</span> bad review preference, should be integer";
                    }
                }
            } else {
                if (preg_match('/^\\s*paper(?:id)?\\s*[\\t,]\\s*preference/i', $line)) {
                    /* header; no error */
                } else {
                    if (count($errors) < 20) {
                        $errors[] = "<span class='lineno'>{$printFilename}:{$lineno}:</span> syntax error, expected <code>paper,preference[,title]</code>";
                    } else {
                        $errors[] = "<span class='lineno'>{$printFilename}:{$lineno}:</span> too many syntax errors, giving up";
                        break;
                    }
                }
            }
        }
    }
    if (count($errors) > 0) {
        Conf::msg_error("There were some errors while parsing the uploaded preferences file. <div class='parseerr'><p>" . join("</p>\n<p>", $errors) . "</p></div>");
    }
    if ($successes > 0) {
        savePreferences($new_qreq);
    }
}
Exemplo n.º 4
0
 function apply($pid, $contact, &$req, AssignmentState $state)
 {
     foreach (array("preference", "pref", "revpref") as $k) {
         if (($pref = get($req, $k)) !== null) {
             break;
         }
     }
     if ($pref === null) {
         return "Missing preference";
     }
     $pref = trim((string) $pref);
     if ($pref == "" || $pref == "none") {
         $ppref = array(0, null);
     } else {
         if (($ppref = parse_preference($pref)) === null) {
             return "Invalid preference “" . htmlspecialchars($pref) . "”";
         }
     }
     foreach (array("expertise", "revexp") as $k) {
         if (($exp = get($req, $k)) !== null) {
             break;
         }
     }
     if ($exp && ($exp = trim($exp)) !== "") {
         if (($pexp = parse_preference($exp)) === null || $pexp[0]) {
             return "Invalid expertise “" . htmlspecialchars($exp) . "”";
         }
         $ppref[1] = $pexp[1];
     }
     $state->remove(array("type" => $this->type, "pid" => $pid, "cid" => $contact->contactId ?: null));
     if ($ppref[0] || $ppref[1] !== null) {
         $state->add(array("type" => $this->type, "pid" => $pid, "cid" => $contact->contactId, "_pref" => $ppref[0], "_exp" => $ppref[1]));
     }
 }
Exemplo n.º 5
0
 static function setpref_api($user, $qreq, $prow)
 {
     global $Conf;
     $cid = $user->contactId;
     if ($user->allow_administer($prow) && $qreq->reviewer && ($x = cvtint($qreq->reviewer)) > 0) {
         $cid = $x;
     }
     if ($v = parse_preference($qreq->pref)) {
         if (PaperActions::save_review_preferences([[$prow->paperId, $cid, $v[0], $v[1]]])) {
             $j = ["ok" => true, "response" => "Saved"];
         } else {
             $j = ["ok" => false];
         }
         $j["value"] = unparse_preference($v);
     } else {
         $j = ["ok" => false, "error" => "Bad preference"];
     }
     json_exit($j);
 }