diff --git a/app/controllers/DashboardController.php b/app/controllers/DashboardController.php index 6c587b7..6c8734e 100644 --- a/app/controllers/DashboardController.php +++ b/app/controllers/DashboardController.php @@ -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()); } @@ -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); @@ -61,7 +61,7 @@ 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 @@ -69,7 +69,7 @@ private function showProblem($id, $ignore_git=FALSE) $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) { @@ -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'])) { @@ -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); } } @@ -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()); } @@ -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(); @@ -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()); } @@ -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()); } @@ -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')); @@ -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()); } @@ -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()); } @@ -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()); } @@ -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')); @@ -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()); } diff --git a/app/controllers/ProblemController.php b/app/controllers/ProblemController.php index 7a07da9..fd21d35 100644 --- a/app/controllers/ProblemController.php +++ b/app/controllers/ProblemController.php @@ -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()); diff --git a/app/controllers/RecordController.php b/app/controllers/RecordController.php index 39f6c8e..081240a 100644 --- a/app/controllers/RecordController.php +++ b/app/controllers/RecordController.php @@ -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()); diff --git a/app/controllers/ReportController.php b/app/controllers/ReportController.php index c613f60..89f94b6 100644 --- a/app/controllers/ReportController.php +++ b/app/controllers/ReportController.php @@ -25,7 +25,7 @@ public function show($id) try { $this->report = new Report($id); if (!$this->report->isReadable()) { - throw new fAuthorizationException('You are not allowed to view this report.'); + throw new fAuthorizationException(T('You are not allowed to view this report.')); } global $cache; @@ -51,7 +51,7 @@ public function show($id) $this->nav_class = 'reports'; $this->render('report/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()); @@ -64,16 +64,16 @@ public function newRegistration($id) try { $report = new Report($id); if (!$report->isRegistrable()) { - throw new fValidationException('This contest is not registrable.'); + throw new fValidationException(T('This contest is not registrable.')); } $registration = new Registration(); $registration->setUsername(fAuthorization::getUserToken()); $registration->setReportId($report->getId()); $registration->store(); BoardCacheInvalidator::invalidateByReport($report); - fMessaging::create('success', 'Registered successfully.'); + fMessaging::create('success', T('Registered successfully.')); } catch (fExpectedException $e) { - fMessaging::create('warning', $e->getMessage()); + fMessaging::create('warning', T($e->getMessage())); } catch (fUnexpectedException $e) { fMessaging::create('error', $e->getMessage()); } @@ -85,11 +85,11 @@ public function newQuestion($id) try { $report = new Report($id); if (!$report->allowQuestion()) { - throw new fValidationException('Not allowed to ask question.'); + throw new fValidationException(T('Not allowed to ask question.')); } $category = fRequest::get('category', 'integer'); if ($category == 0) { - throw new fValidationException('Please choose a category.'); + throw new fValidationException(T('Please choose a category.')); } $question = new Question(); $question->setUsername(fAuthorization::getUserToken()); @@ -104,15 +104,15 @@ public function newQuestion($id) $question->setAskTime(new fTimestamp()); $question->setQuestion(trim(fRequest::get('question'))); if (strlen($question->getQuestion()) < 10) { - throw new fValidationException('Question too short (minimum 10 bytes).'); + throw new fValidationException(T('Question too short (minimum 10 bytes).')); } if (strlen($question->getQuestion()) > 500) { - throw new fValidationException('Question too long (maximum 500 bytes).'); + throw new fValidationException(T('Question too long (maximum 500 bytes).')); } $question->store(); - fMessaging::create('success', 'Question saved.'); + fMessaging::create('success', T('Question saved.')); } catch (fExpectedException $e) { - fMessaging::create('warning', $e->getMessage()); + fMessaging::create('warning', T($e->getMessage())); } catch (fUnexpectedException $e) { fMessaging::create('error', $e->getMessage()); } @@ -125,14 +125,14 @@ public function replyQuestion($id) $question = new Question($id); $report = new Report($report_id = $question->getReportId()); if (!$report->allowAnswer()) { - throw new fValidationException('Not allowed to answer question.'); + throw new fValidationException(T('Not allowed to answer question.')); } $question->setAnswerTime(new fTimestamp()); $question->setAnswer(trim(fRequest::get('reply'))); $question->store(); - fMessaging::create('success', 'Question answered.'); + fMessaging::create('success', T('Question answered.')); } catch (fExpectedException $e) { - fMessaging::create('warning', $e->getMessage()); + fMessaging::create('warning', T($e->getMessage())); } catch (fUnexpectedException $e) { fMessaging::create('error', $e->getMessage()); } @@ -145,13 +145,13 @@ public function toggleQuestionVisibility($id) $question = new Question($id); $report = new Report($report_id = $question->getReportId()); if (!$report->allowAnswer()) { - throw new fValidationException('Not allowed to toggle question visibility.'); + throw new fValidationException(T('Not allowed to toggle question visibility.')); } $question->setCategory(-$question->getCategory()); $question->store(); - fMessaging::create('success', 'Visibility toggled.'); + fMessaging::create('success', T('Visibility toggled.')); } catch (fExpectedException $e) { - fMessaging::create('warning', $e->getMessage()); + fMessaging::create('warning', T($e->getMessage())); } catch (fUnexpectedException $e) { fMessaging::create('error', $e->getMessage()); } diff --git a/app/controllers/SubmitController.php b/app/controllers/SubmitController.php index e7ab59f..ceea9d5 100644 --- a/app/controllers/SubmitController.php +++ b/app/controllers/SubmitController.php @@ -27,11 +27,11 @@ public function submit($problem_id) fSession::set('last_language', $language); $code = trim(fRequest::get('code', 'string')); if (strlen($code) == 0) { - throw new fValidationException('Code cannot be empty.'); + throw new fValidationException(T('Code cannot be empty.')); } if ($problem->isSecretNow()) { if (!User::can('view-any-problem')) { - throw new fAuthorizationException('Problem is secret now. You are not allowed to submit this problem.'); + throw new fAuthorizationException(T('Problem is secret now. You are not allowed to submit this problem.')); } } @@ -48,7 +48,7 @@ public function submit($problem_id) Util::redirect('/status'); } catch (fException $e) { - fMessaging::create('error', $e->getMessage()); + fMessaging::create('error', T($e->getMessage())); fMessaging::create('code', '/submit', fRequest::get('code', 'string')); Util::redirect("/submit?problem={$problem_id}"); } diff --git a/app/controllers/UserController.php b/app/controllers/UserController.php index 695ce03..145729b 100644 --- a/app/controllers/UserController.php +++ b/app/controllers/UserController.php @@ -46,39 +46,39 @@ public function login() $user = new User($username); if ($user->getPassword() == $password_hash) { fAuthorization::setUserToken($user->getUsername()); - fMessaging::create('success', 'Logged in successfully.'); + fMessaging::create('success', T('Logged in successfully.')); fURL::redirect(fAuthorization::getRequestedURL(TRUE, Util::getReferer())); } else { - throw new fValidationException('Password mismatch.'); + throw new fValidationException(T('Password mismatch.')); } } else if (fRequest::get('action') == '注册') { if (strlen($username) < 4) { - throw new fValidationException('Username is too short.'); + throw new fValidationException(T('Username is too short.')); } if (strlen($username) > 20) { - throw new fValidationException('Username is too long.'); + throw new fValidationException(T('Username is too long.')); } if (strlen($password) < 6) { - throw new fValidationException('Password is too short.'); + throw new fValidationException(T('Password is too short.')); } if (Util::contains('`~!@#$%^&*()-+=[]\\;\',/{}|:"<>?', $username) or preg_match('/\s/', $username)) { - throw new fValidationException('Username is illegal.'); + throw new fValidationException(T('Username is illegal.')); } try { $user = new User($username); - throw new fValidationException('User already exists.'); + throw new fValidationException(T('User already exists.')); } catch (fNotFoundException $e) { $user = new User(); $user->setUsername($username); $user->setPassword($password_hash); $user->store(); fAuthorization::setUserToken($user->getUsername()); - fMessaging::create('success', 'Registered successfully.'); + fMessaging::create('success', T('Registered successfully.')); Util::redirect('/email/verify'); } } } catch (fException $e) { - fMessaging::create('error', $e->getMessage()); + fMessaging::create('error', T($e->getMessage())); fURL::redirect(fAuthorization::getRequestedURL(TRUE, Util::getReferer())); } } @@ -86,7 +86,7 @@ public function login() public function logout() { fAuthorization::destroyUserInfo(); - fMessaging::create('success', 'Logged out successfully.'); + fMessaging::create('success', T('Logged out successfully.')); if (strstr(Util::getReferer(), 'contest')) { fURL::redirect(SITE_BASE); } else { @@ -118,10 +118,10 @@ public function updateInfo() $profile->setPhoneNumber($phone_number); $profile->store(); - fMessaging::create('success', 'Information updated successfully.'); + fMessaging::create('success', T('Information updated successfully.')); fURL::redirect(Util::getReferer()); } catch (fException $e) { - fMessaging::create('error', $e->getMessage()); + fMessaging::create('error', T($e->getMessage())); Util::redirect('/change/info'); } } @@ -139,26 +139,26 @@ public function updatePassword() $new_password = fRequest::get('new_password'); $repeat_password = fRequest::get('repeat_password'); if (strlen($old_password) < 6) { - throw new fValidationException('Old password is too short.'); + throw new fValidationException(T('Old password is too short.')); } if (strlen($new_password) < 6) { - throw new fValidationException('New password is too short.'); + throw new fValidationException(T('New password is too short.')); } if ($new_password != $repeat_password) { - throw new fValidationException('Repeat password mismatch.'); + throw new fValidationException(T('Repeat password mismatch.')); } $user = new User(fAuthorization::getUserToken()); $old_password_hash = static::hashPassword($old_password); if ($user->getPassword() != $old_password_hash) { - throw new fValidationException('Old password mismatch.'); + throw new fValidationException(T('Old password mismatch.')); } $new_password_hash = static::hashPassword($new_password); $user->setPassword($new_password_hash); $user->store(); - fMessaging::create('success', 'Password updated successfully.'); + fMessaging::create('success', T('Password updated successfully.')); fURL::redirect(Util::getReferer()); } catch (fException $e) { - fMessaging::create('error', $e->getMessage()); + fMessaging::create('error', T($e->getMessage())); Util::redirect('/change/password'); } } @@ -178,7 +178,7 @@ public function sendVericode() try { $email = fRequest::get('email', 'string'); if (filter_var($email, FILTER_VALIDATE_EMAIL) == FALSE) { - throw new fValidationException('Invalid email address.'); + throw new fValidationException(T('Invalid email address.')); } $v = new Vericode(); @@ -208,7 +208,7 @@ public function sendVericode() ); Util::redirect('/email/verify/sent'); } catch (fException $e) { - fMessaging::create('error', $e->getMessage()); + fMessaging::create('error', T($e->getMessage())); Util::redirect('/email/verify'); } } @@ -224,7 +224,7 @@ public function checkVericode($id, $vericode) try { $v = new Vericode($id); if ($v->getUsername() != fAuthorization::getUserToken() or $v->getVericode() != $vericode) { - throw new fValidationException('Invalid verification code.'); + throw new fValidationException(T('Invalid verification code.')); } $ue = new UserEmail(); @@ -232,12 +232,12 @@ public function checkVericode($id, $vericode) $ue->setEmail($v->getEmail()); $ue->store(); - fMessaging::create('success', 'Your email address is verified successfully.'); + fMessaging::create('success', T('Your email address is verified successfully.')); $referer = fMessaging::retrieve('referer', SITE_BASE . '/email/verify'); if ($referer == NULL) $referer = SITE_BASE; fURL::redirect($referer); } catch (fException $e) { - fMessaging::create('error', 'Email verification failed: ' . $e->getMessage()); + fMessaging::create('error', T('Email verification failed: ') . $e->getMessage()); Util::redirect('/email/verify'); } } diff --git a/app/helpers/ReportGenerator.php b/app/helpers/ReportGenerator.php index 2a5f7ee..df6e1e7 100644 --- a/app/helpers/ReportGenerator.php +++ b/app/helpers/ReportGenerator.php @@ -76,20 +76,18 @@ private static function prepareReport($records, $problem_ids, $usernames, &$firs $score[$row_average][$col_score] = 0; } else { + $totalsum = 0; // this is the normal case, calculate average scores for ($prob_i = 0; $prob_i < $p_size; $prob_i++) { $sum = 0; for ($user_i = 0; $user_i < $row_average; $user_i++) { $sum += $score[$user_i][$prob_i]; } + $totalsum += $sum; $score[$row_average][$prob_i] = round($sum / ($u_size - 1)); } // calculate average total score - $sum = 0; - for ($user_i = 0; $user_i < $row_average; $user_i++) { - $sum += $score[$user_i][$col_score]; - } - $score[$row_average][$col_score] = round($sum / ($u_size - 1)); + $score[$row_average][$col_score] = round($totalsum / ($u_size - 1)); } } diff --git a/app/models/User.php b/app/models/User.php index d9bd256..0adeb4f 100644 --- a/app/models/User.php +++ b/app/models/User.php @@ -44,7 +44,7 @@ public static function getVerifiedEmail($username=NULL) } $email = UserEmail::fetch($username); if ($email === NULL) { - return '点击此处进行邮件验证'; + return T('Click here to verify your email address.'); } return $email; } @@ -65,7 +65,7 @@ public static function requireEmailVerified() { if (!fAuthorization::checkLoggedIn()) return; if (User::hasEmailVerified()) return; - fMessaging::create('warning', 'You are required to verify your email address before doing this action.'); + fMessaging::create('warning', T('You are required to verify your email address before doing this action.')); Util::redirect('/email/verify'); } } diff --git a/app/translate.php b/app/translate.php index af0bcaf..04f94bc 100644 --- a/app/translate.php +++ b/app/translate.php @@ -30,3 +30,130 @@ function translate($string) } return $string; } + +function T($english) +{ + $numargs=func_num_args(); + static $translations = array( + 'chinese' => array( + + //app/controllers/DashboardController.php + 'You are not allowed to view the dashboard.' => '你没有进入控制台的权限。', + 'Problem title is not specified in problem.conf'=>'题目名称在 problem.conf 中没有指出。', + 'Problem author is not specified in problem.conf'=>'题目作者在 problem.conf 中没有指出。', + 'Problem case count is not specified in problem.conf'=>'题目数据组数在 problem.conf 中没有指出。', + 'Problem case score is not specified in problem.conf'=>'题目各组数据分数在 problem.conf 中没有指出。', + 'Problem time limit is not specified in problem.conf'=>'题目时间限制在 problem.conf 中没有指出。', + 'Problem memory limit is not specified in problem.conf'=>'题目内存限制在 problem.conf 中没有指出。', + 'Problem secret-before time is not specified in problem.conf'=>'题目隐藏截止时间在 problem.conf 中没有指出。', + 'You are not allowed to manage problems.'=>'你没有管理题目的权限。', + 'All problems refreshed successfully.'=>'所有题目成功刷新。', + 'You are not allowed to rejudge records.'=>'你没有重判记录的权限。', + 'Score cannot be negative.'=>'分数不能为负。', + 'You are not allowed to create reports.'=>'你没有创建比赛的权限。', + 'Report created successfully.'=>'比赛创建成功。', + 'You are not allowed to show this report.'=>'你没有显示此比赛的权限。', + 'You are not allowed to hide this report.'=>'你没有隐藏此比赛的权限。', + 'You are not allowed to remove this report.'=>'你没有删除此比赛的权限。', + 'Permission added successfully.'=>'权限添加成功。', + 'You are not allowed to add permissions.'=>'你没有添加权限的权限。', + 'Permission removed successfully.'=>'权限删除成功。', + 'You are not allowed to remove permissions.'=>'你没有删除权限的权限。', + 'Variable removed successfully.'=>'变量删除成功。', + 'Variable set successfully.'=>'变量设置成功。', + 'Data base directory %s does not exist.'=>'数据目录 %s 不存在。', + 'Problem %s already exists.'=>'题目 %s 已存在。', + 'Problem directory %s does not exist.'=>'题目目录 %s 不存在。', + 'Problem configuration file %s does not exist.'=>'题目配置文件 %s 不存在。', + 'Problem description file %s does not exist.'=>'题目描述文件 %s 不存在。', + 'Problem %s does not have a data directory at %s.'=>'题目 %s 在 %s 没有数据目录。', + 'Case input file %s is not found in %s.'=>'数据输入文件 %s 在 %s 没有找到。', + 'Case output file %s is not found in %s.'=>'数据输出文件 %s 在 %s 没有找到。', + 'Problem %s showed successfully.'=>'题目 %s 显示成功。', + 'Problem %s hidden successfully.'=>'题目 %s 隐藏成功。', + 'Problem %s refreshed successfully.'=>'题目 %s 刷新成功。', + 'Record %s rejudged.'=>'提交记录 %s 已重判。', + 'Record %s manually judged.'=>'提交记录 %s 已人工判定。', + 'Report %s showed successfully.'=>'比赛 %s 已成功显示。', + 'Report %s hidden successfully.'=>'比赛 %s 已成功隐藏。', + 'Report %s removed successfully.'=>'比赛 %s 已成功移除。', + 'The Record requested could not be found'=>'提交记录不存在。', + 'The Report requested could not be found'=>'比赛不存在。', + 'The Permission requested could not be found'=>'权限不存在。', + 'The Variable requested could not be found'=>'变量不存在。', + + //app/controllers/ProblemController.php + 'Problem is secret now.'=>'题目现在处于隐藏状态。', + 'The Problem requested could not be found'=>'题目不存在。', + + //app/controllers/RecordController.php + 'You are not allowed to read this record.'=>'你没有查看此记录的权限。', + + //app/controllers/ReportController.php + 'You are not allowed to view this report.'=>'你没有查看此比赛的权限。', + 'This contest is not registrable.'=>'比赛不可注册。', + 'Registered successfully.'=>'注册成功。', + 'Not allowed to ask question.'=>'不允许提问。', + 'Please choose a category.'=>'请选择一个分类。', + 'Question too short (minimum 10 bytes).'=>'问题过短 (最少 10 字节)。', + 'Question too long (maximum 500 bytes).'=>'问题过长 (最大 500 字节)。', + 'Question saved.'=>'问题已保存。', + 'Not allowed to answer question.'=>'没有回答问题的权限。', + 'Question answered.'=>'问题已回答。', + 'Not allowed to toggle question visibility.'=>'没有更改此问题可见度的权限。', + 'Visibility toggled.'=>'可见度已更改。', + 'The Question requested could not be found'=>'问题不存在。', + + //app/controllers/UserController.php + 'Logged in successfully.'=>'登录成功。', + 'Password mismatch.'=>'密码错误。', + 'Username is too short.'=>'用户名过短。', + 'Username is too long.'=>'用户名过长。', + 'Password is too short.'=>'密码过短。', + 'Username is illegal.'=>'用户名包含非法字符。', + 'User already exists.'=>'用户已存在。', + 'Registered successfully.'=>'注册成功。', + 'Logged out successfully.'=>'注销成功。', + 'Information updated successfully.'=>'信息更新成功。', + 'Old password is too short.'=>'旧密码过短。', + 'New password is too short.'=>'新密码过短。', + 'Repeat password mismatch.'=>'两次输入密码不相同。', + 'Old password mismatch.'=>'旧密码错误。', + 'Password updated successfully.'=>'密码更改成功。', + 'Invalid email address.'=>'邮箱地址无效。', + 'Invalid verification code.'=>'验证码无效。', + 'Your email address is verified successfully.'=>'你的邮箱已成功验证。', + 'Email verification failed: '=>'邮箱验证失败: ', + 'The User requested could not be found'=>'用户不存在。', + + //app/controllers/SubmitController.php + 'Code cannot be empty.'=>'代码不能为空。', + 'Problem is secret now. You are not allowed to submit this problem.'=>'题目现在处于隐藏状态,不能提交此题目。', + 'Invalid language.'=>'无效语言。', + + //app/models/User.php + 'Click here to verify your email address.'=>'点击此处验证你的邮箱地址。', + 'You are required to verify your email address before doing this action.'=>'请先验证你的邮箱地址。' + + + ) + ); + $language = 'chinese'; // 这里先固定为 chinese,以后会修改成根据用户来决定语言 + if (isset($translations[$language][$english])) { + if($numargs==2){ + $arg2=func_get_arg(1); + $t=$translations[$language][$english]; + $translation=sprintf("$t",$arg2); + return $translation; + } + if($numargs==3){ + $arg2=func_get_arg(1); + $arg3=func_get_arg(2); + $t=$translations[$language][$english]; + $translation=sprintf("$t",$arg2,$arg3); + return $translation; + } + return $translations[$language][$english]; + } + return $english; +} diff --git a/app/views/layout/header.php b/app/views/layout/header.php index ac685fd..007f219 100644 --- a/app/views/layout/header.php +++ b/app/views/layout/header.php @@ -126,24 +126,24 @@
× - Warning! + 警告!
× - Oh snap! + 喔唷!
× - Well done! + 很好!
× - Heads up! + 注意!
diff --git a/app/views/problem/show.php b/app/views/problem/show.php index 03e536b..ad5e92c 100644 --- a/app/views/problem/show.php +++ b/app/views/problem/show.php @@ -12,7 +12,12 @@ 提交此题 + report->getId(); -$meta_refresh = Variable::getInteger('status-refresh', 30); +if ($this->report->getElapsedRatio() < 100) { + $meta_refresh = Variable::getInteger('status-refresh', 30); +} if (fAuthorization::checkLoggedIn() and $this->report->isRunning()) { $javascripts = array('jquery.tablesorter.min', 'board', 'ts-alert'); } else {