Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
96 changes: 48 additions & 48 deletions app/controllers/DashboardController.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ class DashboardController extends ApplicationController
public function index()
{
if (!User::can('manage-site')) {
fMessaging::create('error', 'You are not allowed to view the dashboard.');
fMessaging::create('error', T('You are not allowed to view the dashboard.'));
fURL::redirect(Util::getReferer());
}

Expand Down Expand Up @@ -44,7 +44,7 @@ private function gitPullOriginMaster()
{
$data_base_dir = Variable::getString('data-base-path');
if (!is_dir($data_base_dir)) {
throw new fValidationException("Data base directory {$data_base_dir} does not exist.");
throw new fValidationException(T('Data base directory %s does not exist.'),$data_base_dir);
}
$pwd = getcwd();
chdir($data_base_dir);
Expand All @@ -61,15 +61,15 @@ private function showProblem($id, $ignore_git=FALSE)
try {
$problem = new Problem($id);
if ($problem->exists()) {
throw new fValidationException("Problem {$id} already exists.");
throw new fValidationException(T('Problem %s already exists.'),$id);
}
} catch (fNotFoundException $e) {
// fall through
}

$data_base_dir = Variable::getString('data-base-path');
if (!is_dir($data_base_dir)) {
throw new fValidationException("Data base directory {$data_base_dir} does not exist.");
throw new fValidationException(T('Data base directory %s does not exist.'),$data_base_dir);
}

if (!$ignore_git) {
Expand All @@ -78,47 +78,47 @@ private function showProblem($id, $ignore_git=FALSE)

$problem_dir = "{$data_base_dir}/problems/{$id}";
if (!is_dir($problem_dir)) {
throw new fValidationException("Problem directory {$problem_dir} does not exist.");
throw new fValidationException(T('Problem directory %s does not exist.'),$problem_dir);
}

$problem_conf = "{$problem_dir}/problem.conf";
if (!is_file($problem_conf)) {
throw new fValidationException("Problem configuration file {$problem_conf} does not exist.");
throw new fValidationException(T('Problem configuration file %s does not exist.'),$problem_conf);
}

$problem_text = "{$problem_dir}/problem.text";
if (!is_file($problem_text)) {
throw new fValidationException("Problem description file {$problem_text} does not exist.");
throw new fValidationException(T('Problem description file %s does not exist.'),$problem_text);
}

$data_dir = "{$problem_dir}/data";
if (!is_dir($data_dir)) {
throw new fValidationException("Problem {$id} does not have a data directory at {$data_dir}");
throw new fValidationException(T('Problem %s does not have a data directory at %s.'),$id,$data_dir);
}

$properties_content = file_get_contents($problem_conf);
$ini_content = str_replace(': ', ' = ', $properties_content);
$ini = parse_ini_string($ini_content);
if (!array_key_exists('title', $ini) or empty($ini['title'])) {
throw new fValidationException('Problem title is not specified in problem.conf');
throw new fValidationException(T('Problem title is not specified in problem.conf'));
}
if (!array_key_exists('author', $ini)) {
throw new fValidationException('Problem author is not specified in problem.conf');
throw new fValidationException(T('Problem author is not specified in problem.conf'));
}
if (!array_key_exists('case_count', $ini) or empty($ini['case_count'])) {
throw new fValidationException('Problem case count is not specified in problem.conf');
throw new fValidationException(T('Problem case count is not specified in problem.conf'));
}
if (!array_key_exists('case_score', $ini) or empty($ini['case_score'])) {
throw new fValidationException('Problem case score is not specified in problem.conf');
throw new fValidationException(T('Problem case score is not specified in problem.conf'));
}
if (!array_key_exists('time_limit', $ini) or empty($ini['time_limit'])) {
throw new fValidationException('Problem time limit is not specified in problem.conf');
throw new fValidationException(T('Problem time limit is not specified in problem.conf'));
}
if (!array_key_exists('memory_limit', $ini) or empty($ini['memory_limit'])) {
throw new fValidationException('Problem memory limit is not specified in problem.conf');
throw new fValidationException(T('Problem memory limit is not specified in problem.conf'));
}
if (!array_key_exists('secret_before', $ini) or empty($ini['secret_before'])) {
throw new fValidationException('Problem secret-before time is not specified in problem.conf');
throw new fValidationException(T('Problem secret-before time is not specified in problem.conf'));
}

if (empty($ini['author'])) {
Expand All @@ -140,11 +140,11 @@ private function showProblem($id, $ignore_git=FALSE)
for ($t = 1; $t <= $problem->getCaseCount(); $t++) {
$input = "{$data_dir}/$t.in";
if (!is_file($input)) {
throw new fValidationException("Case input file {$input} is not found in {$data_dir}");
throw new fValidationException(T('Case input file %s is not found in %s.'),$input,$data_dir);
}
$output = "{$data_dir}/$t.out";
if (!is_file($output)) {
throw new fValidationException("Case output file {$output} is not found in {$data_dir}");
throw new fValidationException(T('Case out file %s is not found in %s.'),$output,$data_dir);
}
}

Expand Down Expand Up @@ -198,23 +198,23 @@ public function manageProblem($id, $action)
{
try {
if (!User::can('manage-site')) {
throw new fAuthorizationException('You are not allowed to manage problems.');
throw new fAuthorizationException(T('You are not allowed to manage problems.'));
}
if ($action == 'Show') {
$this->showProblem($id);
fMessaging::create('success', "Problem {$id} showed successfully.");
fMessaging::create('success', T('Problem %s showed successfully.',$id));
} else if ($action == 'Hide') {
$this->hideProblem($id);
fMessaging::create('success', "Problem {$id} hidden successfully.");
fMessaging::create('success', T('Problem %s hidden successfully.',$id));
} else if ($action == 'Refresh') {
$this->refreshProblem($id);
fMessaging::create('success', "Problem {$id} refreshed successfully.");
fMessaging::create('success', T('Problem %s refreshed successfully.',$id));
} else if ($action == 'Refresh All' and User::can('refresh-all')) {
$this->refreshAllProblems();
fMessaging::create('success', 'All problems refreshed successfully.');
fMessaging::create('success', T('All problems refreshed successfully.'));
}
} catch (fException $e) {
fMessaging::create('error', $e->getMessage());
fMessaging::create('error', T($e->getMessage()));
}
fURL::redirect(Util::getReferer());
}
Expand All @@ -223,7 +223,7 @@ public function rejudge($id)
{
try {
if (!User::can('rejudge-record')) {
throw new fAuthorizationException('You are not allowed to rejudge records.');
throw new fAuthorizationException(T('You are not allowed to rejudge records.'));
}
$old_record = new Record($id);
$new_record = new Record();
Expand All @@ -236,9 +236,9 @@ public function rejudge($id)
$new_record->setJudgeMessage('Rejudging... PROB=' . $old_record->getProblemId() . ' LANG=' . $old_record->getLanguageName());
$new_record->setVerdict(Verdict::UNKNOWN);
$new_record->store();
fMessaging::create('success', "Record {$id} rejudged.");
fMessaging::create('success', T('Record %s rejudged.',$id));
} catch (fException $e) {
fMessaging::create('error', $e->getMessage());
fMessaging::create('error', T($e->getMessage()));
}
fURL::redirect(Util::getReferer());
}
Expand All @@ -247,17 +247,17 @@ public function manjudge($id, $score)
{
try {
if (!User::can('rejudge-record')) {
throw new fAuthorizationException('You are not allowed to rejudge records.');
throw new fAuthorizationException(T('You are not allowed to rejudge records.'));
}
if ($score < 0) {
throw new fValidationException('Score cannot be negative.');
throw new fValidationException(T('Score cannot be negative.'));
}
$record = new Record($id);
$record->manjudge($score);
$record->store();
fMessaging::create('success', "Record {$id} manually judged.");
fMessaging::create('success', T('Record %s manually judged.',$id));
} catch (fException $e) {
fMessaging::create('error', $e->getMessage());
fMessaging::create('error', T($e->getMessage()));
}
fURL::redirect(Util::getReferer());
}
Expand All @@ -266,7 +266,7 @@ public function createReport()
{
try {
if (!User::can('create-report')) {
throw new fAuthorizationException('You are not allowed to create reports.');
throw new fAuthorizationException(T('You are not allowed to create reports.'));
}
$report = new Report();
$report->setVisible(fRequest::get('visible', 'integer'));
Expand All @@ -276,9 +276,9 @@ public function createReport()
$report->setStartDatetime(fRequest::get('start_time', 'timestamp'));
$report->setEndDatetime(fRequest::get('end_time', 'timestamp'));
$report->store();
fMessaging::create('success', 'Report created successfully.');
fMessaging::create('success', T('Report created successfully.'));
} catch (fException $e) {
fMessaging::create('error', $e->getMessage());
fMessaging::create('error', T($e->getMessage()));
}
fURL::redirect(Util::getReferer());
}
Expand All @@ -291,28 +291,28 @@ public function manageReport($id, $action)
if (User::can('view-any-report')) {
$report->setVisible(1);
$report->store();
fMessaging::create('success', "Report {$id} showed successfully.");
fMessaging::create('success', T('Report %s showed successfully.',$id));
} else {
throw new fAuthorizationException('You are not allowed to show this report.');
throw new fAuthorizationException(T('You are not allowed to show this report.'));
}
} else if ($action == 'Hide') {
if (User::can('view-any-report')) {
$report->setVisible(0);
$report->store();
fMessaging::create('success', "Report {$id} hidden successfully.");
fMessaging::create('success', T('Report %s hidden successfully.',$id));
} else {
throw new fAuthorizationException('You are not allowed to hide this report.');
throw new fAuthorizationException(T('You are not allowed to hide this report.'));
}
} else if ($action == 'Remove') {
if (User::can('remove-report')) {
$report->delete();
fMessaging::create('success', "Report {$id} removed successfully.");
fMessaging::create('success', T('Report %s removed successfully.',$id));
} else {
throw new fAuthorizationException('You are not allowed to remove this report.');
throw new fAuthorizationException(T('You are not allowed to remove this report.'));
}
}
} catch (fException $e) {
fMessaging::create('error', $e->getMessage());
fMessaging::create('error', T($e->getMessage()));
}
fURL::redirect(Util::getReferer());
}
Expand All @@ -328,21 +328,21 @@ public function managePermission($action)
$permission->setUserName($user_name);
$permission->setPermissionName($permission_name);
$permission->store();
fMessaging::create('success', 'Permission added successfully.');
fMessaging::create('success', T('Permission added successfully.'));
} else {
throw new fAuthorizationException('You are not allowed to add permissions.');
throw new fAuthorizationException(T('You are not allowed to add permissions.'));
}
} else if ($action == 'Remove') {
if (User::can('remove-permission')) {
$permission = new Permission(array('user_name' => $user_name, 'permission_name' => $permission_name));
$permission->delete();
fMessaging::create('success', 'Permission removed successfully.');
fMessaging::create('success', T('Permission removed successfully.'));
} else {
throw new fAuthorizationException('You are not allowed to remove permissions.');
throw new fAuthorizationException(T('You are not allowed to remove permissions.'));
}
}
} catch (fException $e) {
fMessaging::create('error', $e->getMessage());
fMessaging::create('error', T($e->getMessage()));
}
fURL::redirect(Util::getReferer());
}
Expand All @@ -353,7 +353,7 @@ public function setVariable()
if (fRequest::get('remove', 'boolean')) {
$variable = new Variable(fRequest::get('name'));
$variable->delete();
fMessaging::create('success', 'Variable removed successfully.');
fMessaging::create('success', T('Variable removed successfully.'));
} else {
try {
$variable = new Variable(fRequest::get('name'));
Expand All @@ -363,10 +363,10 @@ public function setVariable()
}
$variable->setValue(fRequest::get('value'));
$variable->store();
fMessaging::create('success', 'Variable set successfully.');
fMessaging::create('success', T('Variable set successfully.'));
}
} catch (fException $e) {
fMessaging::create('error', $e->getMessage());
fMessaging::create('error', T($e->getMessage()));
}
fURL::redirect(Util::getReferer());
}
Expand Down
4 changes: 2 additions & 2 deletions app/controllers/ProblemController.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,13 @@ public function show($id)
$this->problem = new Problem($id);
if ($this->problem->isSecretNow()) {
if (!User::can('view-any-problem')) {
throw new fAuthorizationException('Problem is secret now.');
throw new fAuthorizationException(T('Problem is secret now.'));
}
}
$this->nav_class = 'problems';
$this->render('problem/show');
} catch (fExpectedException $e) {
fMessaging::create('warning', $e->getMessage());
fMessaging::create('warning', T($e->getMessage()));
fURL::redirect(Util::getReferer());
} catch (fUnexpectedException $e) {
fMessaging::create('error', $e->getMessage());
Expand Down
4 changes: 2 additions & 2 deletions app/controllers/RecordController.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,12 @@ public function show($id)
try {
$this->record = new Record($id);
if (!$this->record->isReadable()) {
throw new fAuthorizationException('You are not allowed to read this record.');
throw new fAuthorizationException(T('You are not allowed to read this record.'));
}
$this->nav_class = 'status';
$this->render('record/show');
} catch (fExpectedException $e) {
fMessaging::create('warning', $e->getMessage());
fMessaging::create('warning', T($e->getMessage()));
fURL::redirect(Util::getReferer());
} catch (fUnexpectedException $e) {
fMessaging::create('error', $e->getMessage());
Expand Down
Loading