function processCreateDataBaseRequest($request) { //test if creation is necessary if (in_array(DB_PREFIX . "user", Data::getTables())) { throwBusinessLogicError(13); } //read queries from file $lines = @file_get_contents("utils/dces-create-db.sql") or throwServerProblem(64); //remove # comments $lines = preg_replace("/^\\s*#.*\$/m", "", $lines); //remove /*! ... */ comments $lines = preg_replace('/\\/\\*!\\d+.*\\*\\//', "", $lines); //replace PREFIX_ with real prefix $lines = preg_replace('/PREFIX_/', DB_PREFIX, $lines); //split requests by ; $requests = preg_split('/\\s*;\\s*$/m', $lines); foreach ($requests as $r) { if (trim($r) !== "") { Data::submitModificationQuery($r); } } $col_value = array('login' => $request->login, 'password' => $request->password, 'user_data' => serialize(array()), 'contest_id' => 0, 'user_type' => 'SuperAdmin'); Data::submitModificationQuery(Data::composeInsertQuery('user', $col_value)); return new AcceptedResponse(); }
public static function _unserialize($val, $default = false) { $res = @unserialize($val); if ($res === false) { if ($default === false) { throwServerProblem(110); } else { $res = $default; } } return $res; }
function processAdjustContestRequest($request) { if (!$request->contest) { throwBusinessLogicError(1, 'contest is null'); } //get user_id or die, if session is invalid $userRow = RequestUtils::testSession($request->sessionID); //authorize user for this operation // get contest ID $user_type = $userRow['user_type']; $contest_id = RequestUtils::getRequestedContest($request->contest->contestID, $userRow['contest_id'], $user_type); if ($user_type === "Participant") { $contest_id = -1; } if ($contest_id < 0) { throwBusinessLogicError(0); } queryForContestDescription($request->contest, $contest_id); //now adjust problems if (!is_null($request->problems)) { $tmp_files = queriesToAdjustProblems($request->problems, $contest_id); } Data::execPendingQueries(); $new_ids = Data::getInsertedIDs(); $id_ind = 0; //rename temporary files and fill responseIDs if (!is_null($request->problems)) { $responseIDs = array(); $probs_cnt = count($request->problems); for ($i = 0; $i < $probs_cnt; $i++) { $p = $request->problems[$i]; $tmp = $tmp_files[$i]; if ($tmp) { $new_id = $p->id; if ($new_id < 0) { $new_id = $new_ids[$id_ind++]; } @rename($tmp, getProblemFile($new_id)); $responseIDs[] = $new_id; } else { $responseIDs[] = $p->id; if ($p->id < 0) { //for new tasks it must have been created a temporary file throwServerProblem(202); } } } } else { $responseIDs = NULL; } $response = new AdjustContestResponse(); $response->problemIDs = $responseIDs; return $response; }