コード例 #1
0
function account_value($sv, $si)
{
    if ($si->internal) {
        return;
    }
    $xname = str_replace(".", "_", $si->name);
    if ($si->parser) {
        $has_value = truthy(get($sv->req, "has_{$xname}"));
    } else {
        $has_value = isset($sv->req[$xname]) || ($si->type === "cdate" || $si->type === "checkbox") && truthy(get($sv->req, "has_{$xname}"));
    }
    if (!$has_value) {
        return;
    }
    if ($si->disabled || $si->novalue || !$si->type || $si->type === "none") {
        /* ignore changes to disabled/novalue settings */
    } else {
        if ($si->parser) {
            $p = $sv->parser($si);
            if ($p->parse($sv, $si)) {
                $sv->save_callbacks[$si->name] = $si;
            }
        } else {
            $v = parse_value($sv, $si->name, $si);
            if ($v === null) {
                return;
            }
            if (is_int($v) && $v <= 0 && $si->type !== "radio" && $si->type !== "zint") {
                $v = null;
            }
            $sv->save($si->name, $v);
            if ($si->ifnonempty) {
                $sv->save($si->ifnonempty, $v === null ? null : 1);
            }
        }
    }
}
コード例 #2
0
function get_db_values($sql, $values_before, $shown_symbols = 0)
{
    global $db;
    $values = array();
    $db_list = new VA_SQL();
    $db_list->DBType = $db->DBType;
    $db_list->DBDatabase = $db->DBDatabase;
    $db_list->DBUser = $db->DBUser;
    $db_list->DBPassword = $db->DBPassword;
    $db_list->DBHost = $db->DBHost;
    $db_list->DBPort = $db->DBPort;
    $db_list->DBPersistent = $db->DBPersistent;
    $i = 0;
    if (is_array($values_before)) {
        for ($j = 0; $j < sizeof($values_before); $j++) {
            $value_desciption = get_translation($values_before[$j][1]);
            $value_desciption = parse_value($value_desciption);
            if ($shown_symbols > 0 && strlen($value_desciption) > $shown_symbols) {
                $value_desciption = substr($value_desciption, 0, $shown_symbols) . "...";
            }
            $values[$i][0] = $values_before[$j][0];
            $values[$i][1] = $value_desciption;
            $i++;
        }
    }
    $db_list->query($sql);
    if ($db_list->next_record()) {
        do {
            $value_desciption = get_translation($db_list->f(1));
            $value_desciption = parse_value($value_desciption);
            if ($shown_symbols > 0 && strlen($value_desciption) > $shown_symbols) {
                $value_desciption = substr($value_desciption, 0, $shown_symbols) . "...";
            }
            $values[$i][0] = $db_list->f(0);
            $values[$i][1] = $value_desciption;
            $i++;
        } while ($db_list->next_record());
    }
    return $values;
}
コード例 #3
0
 function parse($sv, $si)
 {
     global $Conf;
     if (!$sv->newv("resp_active")) {
         return false;
     }
     $old_roundnames = $Conf->resp_round_list();
     $roundnames = array(1);
     $roundnames_set = array();
     if (isset($sv->req["resp_roundname"])) {
         $rname = trim(get_s($sv->req, "resp_roundname"));
         if ($rname === "" || $rname === "none" || $rname === "1") {
             /* do nothing */
         } else {
             if ($rerror = Conf::resp_round_name_error($rname)) {
                 $sv->set_error("resp_roundname", $rerror);
             } else {
                 $roundnames[0] = $rname;
                 $roundnames_set[strtolower($rname)] = 0;
             }
         }
     }
     for ($i = 1; isset($sv->req["resp_roundname_{$i}"]); ++$i) {
         $rname = trim(get_s($sv->req, "resp_roundname_{$i}"));
         if ($rname === "" && get($old_roundnames, $i)) {
             $rname = $old_roundnames[$i];
         }
         if ($rname === "") {
             continue;
         } else {
             if ($rerror = Conf::resp_round_name_error($rname)) {
                 $sv->set_error("resp_roundname_{$i}", $rerror);
             } else {
                 if (get($roundnames_set, strtolower($rname)) !== null) {
                     $sv->set_error("resp_roundname_{$i}", "Response round name “" . htmlspecialchars($rname) . "” has already been used.");
                 } else {
                     $roundnames[] = $rname;
                     $roundnames_set[strtolower($rname)] = $i;
                 }
             }
         }
     }
     foreach ($roundnames_set as $i) {
         $isuf = $i ? "_{$i}" : "";
         if (($v = parse_value($sv, "resp_open{$isuf}", Si::get("resp_open"))) !== null) {
             $sv->save("resp_open{$isuf}", $v <= 0 ? null : $v);
         }
         if (($v = parse_value($sv, "resp_done{$isuf}", Si::get("resp_done"))) !== null) {
             $sv->save("resp_done{$isuf}", $v <= 0 ? null : $v);
         }
         if (($v = parse_value($sv, "resp_grace{$isuf}", Si::get("resp_grace"))) !== null) {
             $sv->save("resp_grace{$isuf}", $v <= 0 ? null : $v);
         }
         if (($v = parse_value($sv, "resp_words{$isuf}", Si::get("resp_words"))) !== null) {
             $sv->save("resp_words{$isuf}", $v < 0 ? null : $v);
         }
         if (($v = parse_value($sv, "msg.resp_instrux{$isuf}", Si::get("msg.resp_instrux"))) !== null) {
             $sv->save("msg.resp_instrux{$isuf}", $v);
         }
     }
     if (count($roundnames) > 1 || $roundnames[0] !== 1) {
         $sv->save("resp_rounds", join(" ", $roundnames));
     } else {
         $sv->save("resp_rounds", null);
     }
     return false;
 }
コード例 #4
0
 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;
     }
 }