Exemplo n.º 1
0
 function __construct($contact, $type, $usertype)
 {
     global $Conf;
     if (preg_match(',\\A(?:college|extension|students|all|pc)\\z,', $usertype)) {
         $this->usertype = $usertype;
     } else {
         $this->usertype = "students";
     }
     if (preg_match(',\\A(\\w+):(openrepo|brokenrepo|repo|norepo|workingrepo|partner|nopartner)\\z,', $type, $m) && ($this->pset = Pset::find($m[1]))) {
         $this->type = $m[2];
     } else {
         if (preg_match(',\\A(?:students|all|pc(?::\\S+)?)\\z,', $type)) {
             $this->type = $this->usertype = $type;
         } else {
             $this->type = $this->usertype;
         }
     }
 }
Exemplo n.º 2
0
function load_pset_info()
{
    global $ConfSitePATH, $Conf, $PsetInfo, $PsetOverrides, $Opt;
    // read initial messages
    Messages::$main = new Messages();
    $x = json_decode(file_get_contents("{$ConfSitePATH}/src/messages.json"));
    foreach ($x as $j) {
        Messages::$main->add($j);
    }
    // read psets
    $PsetInfo = load_psets_json(false);
    // parse psets
    foreach ($PsetInfo as $pk => $p) {
        if (!is_object($p) || !isset($p->psetid)) {
            continue;
        }
        object_merge_recursive($p, $PsetInfo->_defaults);
        try {
            $pset = new Pset($pk, $p);
            Pset::register($pset);
        } catch (Exception $exception) {
            // Want to give a good error message, so discover where the error is.
            // - create pset landmark object
            $locinfo = (object) array();
            foreach (psets_json_data(false) as $fname => $data) {
                $x = Json::decode_landmarks($data, $fname);
                object_replace_recursive($locinfo, $x);
            }
            $locp = $locinfo->{$pk};
            if (isset($locinfo->_defaults)) {
                object_merge_recursive($locp, $locinfo->_defaults);
            }
            // - lookup exception path in landmark object
            $path = $exception instanceof PsetConfigException ? $exception->path : array();
            for ($pathpos = 0; $pathpos < count($path) && $locp && !is_string($locp); ++$pathpos) {
                $component = $path[$pathpos];
                $locp = is_array($locp) ? $locp[$component] : $locp->{$component};
            }
            // - report error
            if (is_object($locp) && @$locp->__LANDMARK__) {
                $locp = $locp->__LANDMARK__;
            } else {
                if (!is_string($locp)) {
                    $locp = $locinfo->{$pk}->__LANDMARK__;
                }
            }
            Multiconference::fail_message($locp . ": Configuration error: " . $exception->getMessage());
        }
    }
    // read message data
    if (!@$PsetInfo->_messagedefs) {
        $PsetInfo->_messagedefs = (object) array();
    }
    if (!@$PsetInfo->_messagedefs->SYSTEAM) {
        $PsetInfo->_messagedefs->SYSTEAM = "cs61-staff";
    }
    foreach ($PsetInfo->_messagedefs as $k => $v) {
        Messages::$main->define($k, $v);
    }
    // also create log/ and repo/ directories
    foreach (array("{$ConfSitePATH}/log", "{$ConfSitePATH}/repo") as $d) {
        if (!is_dir($d) && !mkdir($d, 02770, true)) {
            $e = error_get_last();
            Multiconference::fail_message("`{$d}` missing and cannot be created (" . $e["message"] . ").");
        }
        if (!file_exists("{$d}/.htaccess") && ($x = file_get_contents("{$ConfSitePATH}/src/.htaccess")) !== false && file_put_contents("{$d}/.htaccess", $x) != strlen($x)) {
            Multiconference::fail_message("Error creating `{$d}/.htaccess`");
        }
    }
    // if any anonymous problem sets, create anonymous usernames
    foreach (Pset::$all as $p) {
        if (!$p->disabled && $p->anonymous) {
            while ($row = Dbl::fetch_first_row(Dbl::qe("select contactId from ContactInfo where anon_username is null limit 1"))) {
                Dbl::q("update ContactInfo set anon_username='******' where contactId=?", $row[0]);
            }
        }
    }
}
Exemplo n.º 3
0
function reconfig()
{
    global $Conf, $Me, $PsetOverrides, $PsetInfo;
    if (!($pset = Pset::find(@$_REQUEST["pset"]))) {
        return $Conf->errorMsg("No such pset");
    }
    $psetkey = $pset->psetkey;
    $json = load_psets_json(true);
    object_merge_recursive($json->{$psetkey}, $json->_defaults);
    $old_pset = new Pset($psetkey, $json->{$psetkey});
    $o = (object) array();
    $o->disabled = $o->visible = $o->grades_visible = null;
    $state = @$_POST["state"];
    if ($state === "disabled") {
        $o->disabled = true;
    } else {
        if ($old_pset->disabled) {
            $o->disabled = false;
        }
    }
    if ($state === "visible" || $state === "grades_visible") {
        $o->visible = true;
    } else {
        if (!$old_pset->disabled && $old_pset->visible) {
            $o->visible = false;
        }
    }
    if ($state === "grades_visible") {
        $o->grades_visible = true;
    } else {
        if ($state === "visible" && $old_pset->grades_visible) {
            $o->grades_visible = false;
        }
    }
    if (@$_POST["frozen"] === "yes") {
        $o->frozen = true;
    } else {
        $o->frozen = $old_pset->frozen ? false : null;
    }
    if (@$_POST["anonymous"] === "yes") {
        $o->anonymous = true;
    } else {
        $o->anonymous = $old_pset->anonymous ? false : null;
    }
    save_config_overrides($psetkey, $o, $json);
}
Exemplo n.º 4
0
 public function __construct($regex, $d)
 {
     $loc = array("diffs", $regex);
     if (!is_object($d)) {
         throw new PsetConfigException("diff format error", $loc);
     }
     $this->regex = isset($d->regex) ? $d->regex : $regex;
     if (!is_string($this->regex) || $this->regex === "") {
         throw new PsetConfigException("`regex` diff format error", $loc);
     }
     $this->match_priority = (double) Pset::cint($loc, $d, "match_priority");
     $this->priority = Pset::cnum($loc, $d, "priority");
     $this->full = Pset::cbool($loc, $d, "full");
     $this->ignore = Pset::cbool($loc, $d, "ignore");
     $this->boring = Pset::cbool($loc, $d, "boring");
 }
Exemplo n.º 5
0
 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();
     }
 }