From 7f5f38447701b87076e3aff2c62fa98f168621cd Mon Sep 17 00:00:00 2001 From: Tim Hunt Date: Thu, 7 Jun 2012 12:55:53 +0100 Subject: [PATCH] MDL-33532 quiz editing: let uses enter locale floats. So, for example, Croatian users can set the maximum grade to 65,5. --- lib/moodlelib.php | 8 ++++++++ mod/quiz/edit.php | 4 ++-- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/lib/moodlelib.php b/lib/moodlelib.php index 23ee2f5630c..40c55aa1975 100644 --- a/lib/moodlelib.php +++ b/lib/moodlelib.php @@ -132,6 +132,14 @@ define('PARAM_FILE', 'file'); /** * PARAM_FLOAT - a real/floating point number. + * + * Note that you should not use PARAM_FLOAT for numbers typed in by the user. + * It does not work for languages that use , as a decimal separator. + * Instead, do something like + * $rawvalue = required_param('name', PARAM_RAW); + * // ... other code including require_login, which sets current lang ... + * $realvalue = unformat_float($rawvalue); + * // ... then use $realvalue */ define('PARAM_FLOAT', 'float'); diff --git a/mod/quiz/edit.php b/mod/quiz/edit.php index 503999fd7f9..e2f24d2d504 100644 --- a/mod/quiz/edit.php +++ b/mod/quiz/edit.php @@ -318,7 +318,7 @@ if (optional_param('savechanges', false, PARAM_BOOL) && confirm_sesskey()) { if (preg_match('!^g([0-9]+)$!', $key, $matches)) { // Parse input for question -> grades. $questionid = $matches[1]; - $quiz->grades[$questionid] = clean_param($value, PARAM_FLOAT); + $quiz->grades[$questionid] = unformat_float($value); quiz_update_question_instance($quiz->grades[$questionid], $questionid, $quiz); $deletepreviews = true; $recomputesummarks = true; @@ -385,7 +385,7 @@ if (optional_param('savechanges', false, PARAM_BOOL) && confirm_sesskey()) { } // If rescaling is required save the new maximum. - $maxgrade = optional_param('maxgrade', -1, PARAM_FLOAT); + $maxgrade = unformat_float(optional_param('maxgrade', -1, PARAM_RAW)); if ($maxgrade >= 0) { quiz_set_grade($maxgrade, $quiz); } -- 2.36.1