function _ops_update_score()
{
    $OID = max(0, intval($_POST['OID']));
    $CID = max(0, intval($_POST['CID']));
    $msg = "";
    loginRequireMgmt();
    if (!loginCheckPermission(USER::MGMT_TEAM)) {
        redirect("errors/401");
    }
    $itemName = "Team";
    $urlPrefix = "mgmt_team";
    $object = new Team();
    if ($OID) {
        $object->retrieve($OID, $CID);
        if (!$object->exists()) {
            $msg = "{$itemName} not found!";
        } else {
            transactionBegin();
            if ($object->updateTotalScore()) {
                Event::createEvent(EVENT::TYPE_EDIT, $object, Station::getRegistrationStation(), 0, $_POST);
                // just put the post data into the event
                transactionCommit();
                $msg = "{$itemName} updated!";
            } else {
                transactionRollback();
                $msg = "{$itemName} update failed";
            }
        }
    } else {
        $msg = "attempting to create team from ops_update_score which is not supported";
    }
    redirect("{$urlPrefix}/manage", $msg);
}
Exemplo n.º 2
0
function _register()
{
    $json = json_getObjectFromRequest("POST");
    json_checkMembers("team_id,message", $json);
    $teamPIN = $json['team_id'];
    if ($teamPIN === null) {
        trace("missing PIN", __FILE__, __LINE__, __METHOD__);
        rest_sendBadRequestResponse(400, "missing team PIN");
        // doesn't return
    }
    $team = Team::getFromPin($teamPIN);
    if ($team === false) {
        trace("_can't find team PIN=" . $teamPIN, __FILE__, __LINE__, __METHOD__);
        rest_sendBadRequestResponse(404, "missing can't find team PIN=" . $teamPIN);
        // doesn't return
    }
    // we are assuming that the QR code won't include the station tag.
    $station = Station::getRegistrationStation();
    if ($station === false) {
        trace("can't find registration station", __FILE__, __LINE__, __METHOD__);
        rest_sendBadRequestResponse(500, "can't find registration station");
    }
    $points = 3;
    if (Event::createEvent(Event::TYPE_REGISTER, $team, $station, $points) === false) {
        trace("createEvent Fails", __FILE__, __LINE__, __METHOD__);
        rest_sendBadRequestResponse(500, "could not create event object");
    }
    $stationType = StationType::getFromTypeCode($station->get('tag'));
    trace("registration complete", __FILE__, __LINE__, __METHOD__);
    $team->endChallenge();
    // clear any stale challenge data
    $team->_updateScore($stationType, $points);
    $msg = $team->expandMessage($stationType->get('instructions'), null);
    $msg = $team->encodeText($msg);
    json_sendObject(array('message' => $msg));
}