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);
}
function _cpaMeasure($stationTag = null)
{
    if ($stationTag === null) {
        rest_sendBadRequestResponse(400, "missing station Tag");
        // doesn't return
    }
    $station = Station::getFromTag($stationTag);
    if ($station === false) {
        rest_sendBadRequestResponse(404, "can find station stationTag=" . $stationTag);
        // doesn't return
    }
    $stationType = new StationType($station->get('typeId'), -1);
    if ($stationType === false) {
        trace("can't find station type stationTag = " . $stationTag, __FILE__, __LINE__, __METHOD__);
        rest_sendBadRequestResponse(500, "can't find station type stationTag=" . $stationTag);
    }
    $json = json_getObjectFromRequest("POST");
    json_checkMembers("team_id,message", $json);
    $teamPIN = $json['team_id'];
    $team = Team::getFromPin($teamPIN);
    if ($team === false) {
        trace("_cpaMeasure can't find team teamPin=" . $teamPIN, __FILE__, __LINE__, __METHOD__);
        rest_sendBadRequestResponse(404, "team not found PIN=" . $teamPIN);
        // doesn't return
    }
    $stationId = $station->get('OID');
    $parms = null;
    // compute challenge parameters into a message
    switch ($stationType->get('typeCode')) {
        case StationType::STATION_TYPE_CPA:
            $random = new CPAData();
            $parms = $random->getItemsToMeasure();
            trace("CPA measure generated for team " . $teamPIN . " this data " . print_r($parms, true));
            // record the challenge data randomly generated
            $team->setChallengeData($parms);
            break;
        default:
            trace("_cpaMeasure can't find station tyecode=" . $teamPIN, __FILE__, __LINE__, __METHOD__);
            rest_sendBadRequestResponse(404, "station tyecode not found =" . $stationType->get('typeCode'));
            // doesn't return
    }
    if (Event::createEvent(Event::TYPE_START, $team, $station, 0) === false) {
        trace("create event failed", __FILE__, __LINE__, __METHOD__);
        rest_sendBadRequestResponse(500, "database create failed");
    }
    $msg = $team->expandMessage("PA is trying to escape. Quickly measure [fence=[label]] [building=[label]] and scan Start QR Code.", $parms);
    trace("message before decode {$msg}", __FILE__, __LINE__, __METHOD__);
    $msg = $team->encodeText($msg);
    json_sendObject(array('message' => $msg));
}
Esempio n. 3
0
 function startChallenge($team, $station, $stationType)
 {
     $this->retrieveRandom();
     // now replace that object with a real ramdon object.
     $state = $this->generateParameters();
     trace("state " . print_r($state, true), __FILE__, __LINE__, __METHOD__);
     $team->startFSLChallenge($state);
     if (Event::createEvent(Event::TYPE_START, $team, $station, 0, $state) === false) {
         trace("create event failed", __FILE__, __LINE__, __METHOD__);
         rest_sendBadRequestResponse(500, "database create failed");
     }
     $msg = $team->expandMessage($stationType->get('instructions'), $state['msg_values']);
     $msg = $team->encodeText($msg);
     return $msg;
 }
Esempio n. 4
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));
}
Esempio n. 5
0
 function brataSubmit($msg, $team, $station, $stationType)
 {
     $isCorrect = false;
     $challengeComplete = false;
     $rpi = null;
     if ($stationType->get('hasrPI')) {
         $rpi = RPI::getFromStationId($station->get('OID'));
         if ($rpi === false) {
             trace("_start_challenge can't find RPI stationTag=" . $stationTag, __FILE__, __LINE__, __METHOD__);
             throw new InternalError("can't find RPI stationTag=" . $stationTag);
         }
     }
     $count = $team->get('count');
     switch ($stationType->get('typeCode')) {
         case StationType::STATION_TYPE_CTS:
             break;
         case StationType::STATION_TYPE_FSL:
             break;
         case StationType::STATION_TYPE_HMB:
             $team->set('count', $count + 1);
             break;
         case StationType::STATION_TYPE_CPA:
             break;
         case StationType::STATION_TYPE_EXT:
             break;
     }
     $isCorrect = $this->testRpiSolution($team->getChallengeData());
     $points = 1;
     // one for showing up
     if (!$isCorrect) {
         $challenge_complete = $count < 3 ? false : true;
         if ($challenge_complete) {
             $points = 2;
             // two points even if you fail out completely
         }
     } else {
         $challenge_complete = true;
         $points = 3;
         // full points as long as you eventually got it right
         trace('SUCCESS');
     }
     $this->updateTeamScore($team, $points);
     // save score
     if ($challenge_complete) {
         $station->endChallenge();
         $team->endChallenge();
     }
     if (Event::createEvent(Event::TYPE_SUBMIT, $team, $station, $points) === false) {
         trace("can't create event object", __FILE__, __LINE__, __METHOD__);
         throw new InternalError("Can't create event object");
     }
     if ($isCorrect) {
         $msg = $stationType->get('success_msg');
     } else {
         if ($count >= 2) {
             $msg = $stationType->get('failed_msg');
         } else {
             $msg = $stationType->get('retry_msg');
         }
     }
     if ($stationType->get('typeCode') == StationType::STATION_TYPE_CPA) {
         // The CPA has 5 messages not 4 but new DB structure only supports 4 so shift
         if ($isCorrect) {
             $msg = $stationType->get('failed_msg');
         } else {
             if ($count >= 2) {
                 $msg = $stationType->get('retry_msg');
             } else {
                 $msg = "Miss! Try again!";
             }
         }
     }
     // TODO this is broek from merge
     //$msg = $team->expandMessage($msg, $parms );
     trace("isCorrect=" . $isCorrect . " challenge complete=" . $challenge_complete . " msg =" . $msg);
     trace("success_msg=" . $stationType->get('success_msg'));
     // TODO ineresing this is still needed afer the refactoring
     $msg = $team->encodeText($msg);
     return $msg;
 }
Esempio n. 6
0
     $data['client_id'] = $_POST['client'];
     $data['description'] = addslashes($_POST['description']);
     $data['url'] = $_POST['url'];
     return Event::AdminCreateEvent($data);
     break;
 case "send":
     $data['Title'] = $_POST['Title'];
     $data['Location'] = $_POST['Location'];
     $data['Start_Date'] = $_POST['Start_Date'];
     $data['End_Date'] = $_POST['End_Date'];
     $manufacturers = $_POST['manufacturer'];
     $data['Location'] = $_POST['Location'];
     $data['Service'] = $_POST['service'];
     $data['Sales'] = $_POST['sales'];
     $data['Link'] = $_POST['Link'];
     return Event::createEvent($data, $manufacturers);
     break;
 case "delete":
     $id = $_POST['id'];
     return Event::deleteEvent($id);
     break;
 case "saveChange":
     $id = $_POST['id'];
     $field = $_POST['field'];
     $value = addslashes($_POST['value']);
     Event::saveChange($id, $field, $value);
     break;
 case "saveClient":
     $id = $_POST['id'];
     $field = $_POST['field'];
     $value = addslashes($_POST['value']);
function _start_challengeOLD($stationTag = null)
{
    if ($stationTag === null) {
        rest_sendBadRequestResponse(400, "missing station Tag");
        // doesn't return
    }
    $station = Station::getFromTag($stationTag);
    if ($station === false) {
        rest_sendBadRequestResponse(404, "can find station stationTag=" . $stationTag);
        // doesn't return
    }
    $stationType = new StationType($station->get('typeId'), -1);
    if ($stationType === false) {
        trace("can't find station type stationTag = " . $stationTag, __FILE__, __LINE__, __METHOD__);
        rest_sendBadRequestResponse(500, "can't find station type stationTag=" . $stationTag);
    }
    if ($stationType->get('hasrPI')) {
        $rpi = RPI::getFromStationId($station->get('OID'));
        if ($rpi === false) {
            trace("_start_challenge can't find RPI stationTag=" . $stationTag, __FILE__, __LINE__, __METHOD__);
            rest_sendBadRequestResponse(500, "can't find RPI stationTag=" . $stationTag);
        }
    } else {
        $rpi = null;
    }
    $json = json_getObjectFromRequest("POST");
    json_checkMembers("team_id,message", $json);
    $teamPIN = $json['team_id'];
    $team = Team::getFromPin($teamPIN);
    if ($team === false) {
        trace("_start_challenge can't find team teamPin=" . $teamPIN, __FILE__, __LINE__, __METHOD__);
        rest_sendBadRequestResponse(404, "team not found PIN=" . $teamPIN);
        // doesn't return
    }
    $stationId = $station->get('OID');
    $parms = null;
    // compute challenge parameters into a php hash which will be sent to rPI and used to populate message sent to team
    $state = null;
    switch ($stationType->get('typeCode')) {
        case StationType::STATION_TYPE_CTS:
            $parms = CTSData::_startChallenge($stationId);
            break;
        case StationType::STATION_TYPE_HMB:
            $parms = HMBData::_startChallenge($stationId);
            break;
        case StationType::STATION_TYPE_CPA:
            $parms = CPAData::_startChallenge($stationId);
            break;
        case StationType::STATION_TYPE_FSL:
            $state = FSLData::_startChallenge($stationId);
            $parms = $state['msg_values'];
            break;
        case StationType::STATION_TYPE_EXT:
            $state = EXTData::_startChallenge($stationId);
            $parms = $state;
            break;
    }
    if ($rpi != null) {
        trace("sending to rPI");
        $rpi->start_challenge($stationType->get('delay'), $parms);
    }
    trace("station and team start calls");
    //TODO transaction
    $station->startChallenge($team);
    $team->startChallenge($parms, $stationType->get('typeCode'), $state);
    // $state
    if (Event::createEvent(Event::TYPE_START, $team, $station, 0, $state) === false) {
        trace("create event failed", __FILE__, __LINE__, __METHOD__);
        rest_sendBadRequestResponse(500, "database create failed");
    }
    $msg = $team->expandMessage($stationType->get('instructions'), $parms);
    if ($GLOBALS['SYSCONFIG_ENCODE'] == 1) {
        // if not in student mode encode, if in student mode we only encrypt the even team numbers responses
        if ($GLOBALS['SYSCONFIG_STUDENT'] == 0 or $GLOBALS['SYSCONFIG_STUDENT'] == 1 and $teamPIN % 2 == 0) {
            $msg = $team->encodeText($msg);
        }
    }
    json_sendObject(array('message' => $msg));
}
function _submit($stationTag = null)
{
    if ($stationTag === null) {
        trace("brata missing stationId", __FILE__, __LINE__, __METHOD__);
        rest_sendBadRequestResponse(400, "missing stationId");
        // doesn't return
    }
    $station = Station::getFromTag($stationTag);
    if ($station === false) {
        trace("brata can't find station stationTag=" . $stationTag, __FILE__, __LINE__, __METHOD__);
        rest_sendBadRequestResponse(404, "can't find station stationTag=" . $stationTag);
        // doesn't return
    }
    $stationType = new StationType($station->get('typeId'), -1);
    if ($stationType === false) {
        trace("can't find station type stationTag = " . $stationTag, __FILE__, __LINE__, __METHOD__);
        rest_sendBadRequestResponse(500, "can't find station type stationTag=" . $stationTag);
    }
    if ($stationType->get('hasrPI')) {
        $rpi = RPI::getFromStationId($station->get('OID'));
        if ($rpi === false) {
            trace("_submit can't find RPI stationTag=" . $stationTag, __FILE__, __LINE__, __METHOD__);
            rest_sendBadRequestResponse(500, "can't find RPI stationTag=" . $stationTag);
        }
    } else {
        $rpi = null;
    }
    $json = json_getObjectFromRequest("POST");
    // won't return if an error happens
    json_checkMembers("message,team_id", $json);
    $team = Team::getFromPin($json['team_id']);
    if ($team === false) {
        trace("can't find team from team " . $json['team_id']);
        rest_sendBadRequestResponse(404, "can't find team pin=" . $json['team_id']);
    }
    $count = $team->get('count');
    $isCorrect = false;
    $challengeComplete = false;
    $matches = array();
    // for regex matches
    switch ($stationType->get('typeCode')) {
        case StationType::STATION_TYPE_FSL:
            break;
        case StationType::STATION_TYPE_HMB:
            preg_match("/.*answer.*=.*(\\d)/", $json['message'], $matches);
            trace('calling handle_challenge');
            $json = $rpi->handle_submission($stationType->get('delay'), $isCorrect, $challengeComplete);
            //TODO if ($json === false) ERROR???
            //TODO json_checkMembers("message,team_id", $json);
            //$isCorrect=$json['is_correct'];
            break;
        case StationType::STATION_TYPE_EXT:
            $ext = new ExtData(1, -1);
            //TODO get from team
            $ext->submit($json['message'], $team);
            goto hack;
    }
    $count = $team->get('count');
    $points = 3 - $count;
    $team->updateScore($stationType, $points);
    if (!$json['is_correct']) {
        $count++;
        $team->set('count', $count);
        $challenge_complete = $count < 3 ? false : true;
    } else {
        $challenge_complete = true;
    }
    if ($challenge_complete) {
        $station->endChallenge();
        $team->endChallenge();
    }
    if (Event::createEvent(Event::TYPE_SUBMIT, $team, $station, $points) === false) {
        trace("can't create event object", __FILE__, __LINE__, __METHOD__);
        json_sendBadRequestResponse(500, "Can't create event object");
    }
    if ($isCorrect) {
        $msg = $stationType->get('success_msg');
    } else {
        if ($count >= 3) {
            $msg = $stationType->get('failed_msg');
        } else {
            $msg = $stationType->get('retry_msg');
        }
    }
    $msg = $team->expandMessage($msg, $parms);
    if ($GLOBALS['SYSCONFIG_ENCODE'] == 1) {
        // if not in student mode encode, if in student mode we only encrypt the even team numbers responses
        if ($GLOBALS['SYSCONFIG_STUDENT'] == 0 or $GLOBALS['SYSCONFIG_STUDENT'] == 1 and $teamPIN % 2 == 0) {
            $msg = $team->encodeText($msg);
        }
    }
    hack:
    json_sendObject(array('message' => $msg));
}
Esempio n. 9
0
if (isset($_REQUEST[$debug_parameter])) {
    $XML_debug = true;
}
if (isset($_REQUEST['action'])) {
    if ($_REQUEST['action'] == "createevent") {
        $fp->log("createevent");
        $name = aq($_REQUEST['name']);
        $description = aq($_REQUEST['description']);
        $time = aq($_REQUEST['time']);
        $owner = $u;
        $phone_number = aq($_REQUEST['phone_number']);
        $hide_lastname = aq($_REQUEST['hide_lastname']);
        $quota = aq($_REQUEST['quota']);
        $gender = aq($_REQUEST['gender']);
        $location = aq($_REQUEST['location']);
        if (!Event::createEvent($owner, $name, $description, $location, $time, $phone_number, $hide_lastname, $quota, $gender)) {
            echo '{"status":"ERROR","results":"Problem on DB"}';
        } else {
            echo '{"status":"OK","results":"DONE"}';
        }
    } else {
        if ($_REQUEST['action'] == "getuserevents") {
            $fp->log("getuserevents");
            $o = Event::getUserEvents($u);
            if ($o) {
                echo json_encode($o);
            } else {
                error("Problem with the DB");
            }
        } else {
            if ($_REQUEST['action'] == "getnearbyevents") {
Esempio n. 10
0
function _submit($stationTag = null)
{
    if ($stationTag === null) {
        trace("missing station id");
        rest_sendBadRequestResponse(401, "missing stationId");
        // doesn't return
    }
    $station = Station::getFromTag($stationTag);
    if ($station === false) {
        trace("can't find station from tag");
        rest_sendBadRequestResponse(404, "can find station stationTag=" . $stationTag);
        // doesn't return
    }
    $team = new Team($station->get('teamAtStation'), -1);
    if ($team === false) {
        trace("can't find team", __FILE__, __LINE__, __METHOD__);
        rest_sendBadRequestResponse(404, "can find team at station stationTag=" . $stationTag . " teamId=" . $team->get('OID'));
        // doesn't return
    }
    $stationType = new StationType($station->get('typeId'), -1);
    if ($stationType === false) {
        trace("can't find station type stationTag = " . $stationTag, __FILE__, __LINE__, __METHOD__);
        rest_sendBadRequestResponse(500, "can't find station type stationTag=" . $stationTag);
    }
    $rpi = RPI::getFromStationId($station->get('OID'));
    if ($rpi === false) {
        trace("_start_challenge can't find RPI stationTag=" . $stationTag, __FILE__, __LINE__, __METHOD__);
        rest_sendBadRequestResponse(500, "can't find RPI stationTag=" . $stationTag);
    }
    $json = json_getObjectFromRequest("POST");
    // won't return if an error happens
    json_checkMembers("candidate_answer,is_correct,fail_message", $json);
    $count = $team->get('count');
    $team->setChallengeData($json);
    trace("count=" . $count);
    $points = 3 - $count;
    if (!$json['is_correct']) {
        $count++;
        $team->set('count', $count);
        trace("count=" . $count);
        $challenge_complete = $count > 2;
        $team->_updateScore($stationType, 0);
        //TODO add legacy update score
    } else {
        $challenge_complete = true;
    }
    if ($challenge_complete) {
        switch ($stationType->get('typeCode')) {
            case StationType::STATION_TYPE_HMB:
                // Leave scoring up to brata submit for CPA and CTS but HMB needs it
                $team->_updateScore($stationType, $points);
                $station->endChallenge();
                $team->endChallenge();
                break;
            default:
                // FSL does not have pi, CPA and CTS not done until scan last qr
                // so technically challenge not complete until the brata submit
                break;
        }
    }
    if (Event::createEvent(Event::TYPE_SUBMIT, $team, $station, $points) === false) {
        trace("create event failed " . $team->get('OID') . " " . $station->get('OID'), __FILE__, __LINE__, __METHOD__);
        rest_sendBadRequestResponse(500, "database create failed");
    }
    $json = array("message_version" => 0, "message_timestamp" => date("Y-m-d H:i:s"), "theatric_delay_ms" => $stationType->get('delay'), "challenge_complete" => $challenge_complete);
    json_sendObject($json);
}
Esempio n. 11
0
 function brataSubmit($msg, $team, $station, $stationType)
 {
     $isCorrect = false;
     $challengeComplete = false;
     $json = $team->getChallengeData();
     trace("the jsons is" . print_r($json, true));
     $this->rs['_1st_on'] = $json['hmb_vibration_pattern_ms'][0];
     $this->rs['_1st_off'] = $json['hmb_vibration_pattern_ms'][1];
     $this->rs['_2nd_on'] = $json['hmb_vibration_pattern_ms'][2];
     $this->rs['_2nd_off'] = $json['hmb_vibration_pattern_ms'][3];
     $this->rs['_3rd_on'] = $json['hmb_vibration_pattern_ms'][4];
     $this->rs['_3rd_off'] = $json['hmb_vibration_pattern_ms'][5];
     //	$this->rs['cycle']    = $json['hmb_vibration_pattern_ms'][6];
     $count = $team->get('count');
     $points = 1;
     // 1 for showing up
     $team->set('count', $count + 1);
     $team->updateHMBScore(0);
     // save count
     $isCorrect = $this->testSolution($msg);
     $challengeComplete = $count + 1 < 3 ? false : true;
     if ($challengeComplete) {
         $points = 2;
     }
     if ($isCorrect) {
         $points = 3;
     }
     $rpi = RPI::getFromStationId($station->get('OID'));
     if ($rpi != null) {
         $json = $rpi->handle_hmb_submission($stationType->get('delay'), $isCorrect, $challengeComplete);
     } else {
         trace("RPI null not allowed for HMB configuration see admin for DB integrity check.", __FILE__, __LINE__, __METHOD__);
         rest_sendBadRequestResponse(500, "MS DB configuration is suspect as HMB requires an RPI.");
     }
     trace("count before update = " . $count);
     $team->updateHMBScore($points);
     if ($challengeComplete) {
         $station->endChallenge();
         $team->endChallenge();
     }
     if (Event::createEvent(Event::TYPE_SUBMIT, $team, $station, $points) === false) {
         trace("can't create event object", __FILE__, __LINE__, __METHOD__);
         throw new InternalError("Can't create event object");
     }
     if ($isCorrect) {
         $msg = $stationType->get('success_msg');
     } else {
         if ($count >= 2) {
             $msg = $stationType->get('failed_msg');
         } else {
             $msg = $stationType->get('retry_msg');
         }
     }
     //$msg = $team->expandMessage($msg, $parms ); // nothing to expand
     $msg = $team->encodeText($msg);
     return $msg;
 }