Skip to content

Commit

Permalink
MDL-34612 Grade condition range validation allows impossible conditions
Browse files Browse the repository at this point in the history
  • Loading branch information
sammarshallou committed Jan 15, 2013
1 parent 2713f92 commit f84e58d
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 2 deletions.
33 changes: 32 additions & 1 deletion course/editsection_form.php
Expand Up @@ -174,10 +174,41 @@ public function validation($data, $files) {
// Conditions: Don't let them set dates which make no sense // Conditions: Don't let them set dates which make no sense
if (array_key_exists('availablefrom', $data) && if (array_key_exists('availablefrom', $data) &&
$data['availablefrom'] && $data['availableuntil'] && $data['availablefrom'] && $data['availableuntil'] &&
$data['availablefrom'] > $data['availableuntil']) { $data['availablefrom'] >= $data['availableuntil']) {
$errors['availablefrom'] = get_string('badavailabledates', 'condition'); $errors['availablefrom'] = get_string('badavailabledates', 'condition');
} }


// Conditions: Verify that the grade conditions are numbers, and make sense.
if (array_key_exists('conditiongradegroup', $data)) {
foreach ($data['conditiongradegroup'] as $i => $gradedata) {
if ($gradedata['conditiongrademin'] !== '' &&
!is_numeric(unformat_float($gradedata['conditiongrademin']))) {
$errors["conditiongradegroup[{$i}]"] = get_string('gradesmustbenumeric', 'condition');
continue;
}
if ($gradedata['conditiongrademax'] !== '' &&
!is_numeric(unformat_float($gradedata['conditiongrademax']))) {
$errors["conditiongradegroup[{$i}]"] = get_string('gradesmustbenumeric', 'condition');
continue;
}
if ($gradedata['conditiongrademin'] !== '' && $gradedata['conditiongrademax'] !== '' &&
unformat_float($gradedata['conditiongrademax']) <= unformat_float($gradedata['conditiongrademin'])) {
$errors["conditiongradegroup[{$i}]"] = get_string('badgradelimits', 'condition');
continue;
}
if ($gradedata['conditiongrademin'] === '' && $gradedata['conditiongrademax'] === '' &&
$gradedata['conditiongradeitemid']) {
$errors["conditiongradegroup[{$i}]"] = get_string('gradeitembutnolimits', 'condition');
continue;
}
if (($gradedata['conditiongrademin'] !== '' || $gradedata['conditiongrademax'] !== '') &&
!$gradedata['conditiongradeitemid']) {
$errors["conditiongradegroup[{$i}]"] = get_string('gradelimitsbutnoitem', 'condition');
continue;
}
}
}

return $errors; return $errors;
} }
} }
2 changes: 1 addition & 1 deletion course/moodleform_mod.php
Expand Up @@ -332,7 +332,7 @@ function validation($data, $files) {
continue; continue;
} }
if ($gradedata['conditiongrademin'] !== '' && $gradedata['conditiongrademax'] !== '' && if ($gradedata['conditiongrademin'] !== '' && $gradedata['conditiongrademax'] !== '' &&
unformat_float($gradedata['conditiongrademax']) < unformat_float($gradedata['conditiongrademin'])) { unformat_float($gradedata['conditiongrademax']) <= unformat_float($gradedata['conditiongrademin'])) {
$errors["conditiongradegroup[{$i}]"] = get_string('badgradelimits', 'condition'); $errors["conditiongradegroup[{$i}]"] = get_string('badgradelimits', 'condition');
continue; continue;
} }
Expand Down

0 comments on commit f84e58d

Please sign in to comment.