static function find($id)
 {
     if (!array_key_exists($id, self::$jmap)) {
         $oj = get(self::option_json_list(), $id);
         self::$jmap[$id] = $oj ? PaperOption::make($oj) : null;
     }
     return self::$jmap[$id];
 }
Exemplo n.º 2
0
 function option_request_to_json($sv, &$new_opts, $id, $current_opts)
 {
     global $Conf;
     $name = simplify_whitespace(defval($sv->req, "optn{$id}", ""));
     if (!isset($sv->req["optn{$id}"]) && $id[0] !== "n") {
         if (get($current_opts, $id)) {
             $new_opts[$id] = $current_opts[$id];
         }
         return;
     } else {
         if ($name === "" || $sv->req["optfp{$id}"] === "delete" || $id[0] === "n" && ($name === "New option" || $name === "(Enter new option)")) {
             return;
         }
     }
     $oarg = ["name" => $name, "id" => (int) $id, "final" => false];
     if ($id[0] === "n") {
         $nextid = max($Conf->setting("next_optionid", 1), 1);
         foreach ($new_opts as $haveid => $o) {
             $nextid = max($nextid, $haveid + 1);
         }
         foreach ($current_opts as $haveid => $o) {
             $nextid = max($nextid, $haveid + 1);
         }
         $oarg["id"] = $nextid;
     }
     if (get($sv->req, "optd{$id}") && trim($sv->req["optd{$id}"]) != "") {
         $t = CleanHTML::basic_clean($sv->req["optd{$id}"], $err);
         if ($t !== false) {
             $oarg["description"] = $t;
         } else {
             $sv->set_error("optd{$id}", $err);
         }
     }
     if ($optvt = get($sv->req, "optvt{$id}")) {
         if (($pos = strpos($optvt, ":")) !== false) {
             $oarg["type"] = substr($optvt, 0, $pos);
             if (preg_match('/:final/', $optvt)) {
                 $oarg["final"] = true;
             }
             if (preg_match('/:ds_(\\d+)/', $optvt, $m)) {
                 $oarg["display_space"] = (int) $m[1];
             }
         } else {
             $oarg["type"] = $optvt;
         }
     } else {
         $oarg["type"] = "checkbox";
     }
     if (PaperOption::type_has_selector($oarg["type"])) {
         $oarg["selector"] = array();
         $seltext = trim(cleannl(defval($sv->req, "optv{$id}", "")));
         if ($seltext != "") {
             foreach (explode("\n", $seltext) as $t) {
                 $oarg["selector"][] = $t;
             }
         } else {
             $sv->set_error("optv{$id}", "Enter selectors one per line.");
         }
     }
     $oarg["visibility"] = defval($sv->req, "optp{$id}", "rev");
     if ($oarg["final"]) {
         $oarg["visibility"] = "rev";
     }
     $oarg["position"] = (int) defval($sv->req, "optfp{$id}", 1);
     $oarg["display"] = defval($sv->req, "optdt{$id}");
     if ($oarg["type"] === "pdf" && $oarg["final"]) {
         $oarg["display"] = "submission";
     }
     $new_opts[$oarg["id"]] = $o = PaperOption::make($oarg);
     $o->req_id = $id;
     $o->is_new = $id[0] === "n";
 }