Skip to content

Commit

Permalink
MDL-27675 - Feedback module abuses data_submitted
Browse files Browse the repository at this point in the history
  • Loading branch information
grabs committed May 27, 2012
1 parent 4631e39 commit 9a2c4db
Show file tree
Hide file tree
Showing 12 changed files with 62 additions and 13 deletions.
8 changes: 3 additions & 5 deletions mod/feedback/complete.php
Original file line number Diff line number Diff line change
Expand Up @@ -507,11 +507,8 @@
//get the value
$frmvaluename = $feedbackitem->typ . '_'. $feedbackitem->id;
if (isset($savereturn)) {
if (isset($formdata->{$frmvaluename})) {
$value = $formdata->{$frmvaluename};
} else {
$value = null;
}
$value = isset($formdata->{$frmvaluename}) ? $formdata->{$frmvaluename} : null;
$value = feedback_clean_input_value($feedbackitem, $value);
} else {
if (isset($feedbackcompletedtmp->id)) {
$value = feedback_get_item_value($feedbackcompletedtmp->id,
Expand All @@ -530,6 +527,7 @@
feedback_print_item_complete($feedbackitem, $value, $highlightrequired);
echo $OUTPUT->box_end();
}

echo $OUTPUT->box_end();

$lastbreakposition = $feedbackitem->position; //last item-pos (item or pagebreak)
Expand Down
10 changes: 4 additions & 6 deletions mod/feedback/complete_guest.php
Original file line number Diff line number Diff line change
Expand Up @@ -441,13 +441,10 @@
echo $OUTPUT->box_start('feedback_item_box_'.$align.$dependstyle);
$value = '';
//get the value
$frmvaluename = $feedbackitem->typ.'_'.$feedbackitem->id;
$frmvaluename = $feedbackitem->typ . '_'. $feedbackitem->id;
if (isset($savereturn)) {
if (isset($formdata->{$frmvaluename})) {
$value = $formdata->{$frmvaluename};
} else {
$value = null;
}
$value = isset($formdata->{$frmvaluename}) ? $formdata->{$frmvaluename} : null;
$value = feedback_clean_input_value($feedbackitem, $value);
} else {
if (isset($feedbackcompletedtmp->id)) {
$value = feedback_get_item_value($feedbackcompletedtmp->id,
Expand All @@ -466,6 +463,7 @@
feedback_print_item_complete($feedbackitem, $value, $highlightrequired);
echo $OUTPUT->box_end();
}

echo $OUTPUT->box_end();

$lastbreakposition = $feedbackitem->position; //last item-pos (item or pagebreak)
Expand Down
4 changes: 4 additions & 0 deletions mod/feedback/item/captcha/lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -326,4 +326,8 @@ public function get_hasvalue() {
public function can_switch_require() {
return false;
}

function clean_input_value($value) {
return clean_param($value, PARAM_RAW);
}
}
12 changes: 10 additions & 2 deletions mod/feedback/item/feedback_item_class.php
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,14 @@ abstract public function print_item_complete($item, $value = '', $highlightrequi
*/
abstract public function print_item_show_value($item, $value = '');

/**
* cleans the userinput while submitting the form
*
* @param mixed $value
* @return mixed
*/
abstract function clean_input_value($value);

}

//a dummy class to realize pagebreaks
Expand Down Expand Up @@ -175,7 +183,7 @@ public function print_item_show_value($item, $value = '') {
}
public function can_switch_require() {
}
public function clean_input_value($value) {
}

}


4 changes: 4 additions & 0 deletions mod/feedback/item/info/lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -388,4 +388,8 @@ public function get_hasvalue() {
public function can_switch_require() {
return false;
}

function clean_input_value($value) {
return clean_param($value, PARAM_INT);
}
}
3 changes: 3 additions & 0 deletions mod/feedback/item/label/lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -270,4 +270,7 @@ public function get_printval($item, $value) {
}
public function get_analysed($item, $groupid = false, $courseid = false) {
}
public function clean_input_value($value) {
return '';
}
}
8 changes: 8 additions & 0 deletions mod/feedback/item/multichoice/lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -826,4 +826,12 @@ public function value_type() {
public function value_is_array() {
return true;
}

function can_switch_require() {
return true;
}

function clean_input_value($value) {
return clean_param_array($value, PARAM_INT);
}
}
3 changes: 3 additions & 0 deletions mod/feedback/item/multichoicerated/lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -678,4 +678,7 @@ public function can_switch_require() {
return true;
}

function clean_input_value($value) {
return clean_param($value, PARAM_INT);
}
}
4 changes: 4 additions & 0 deletions mod/feedback/item/numeric/lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -534,4 +534,8 @@ public function get_hasvalue() {
public function can_switch_require() {
return true;
}

function clean_input_value($value) {
return clean_param($value, PARAM_FLOAT);
}
}
4 changes: 4 additions & 0 deletions mod/feedback/item/textarea/lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -333,4 +333,8 @@ public function get_hasvalue() {
public function can_switch_require() {
return true;
}

function clean_input_value($value) {
return clean_param($value, PARAM_CLEANHTML);
}
}
4 changes: 4 additions & 0 deletions mod/feedback/item/textfield/lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -320,4 +320,8 @@ public function get_hasvalue() {
public function can_switch_require() {
return true;
}

function clean_input_value($value) {
return clean_param($value, PARAM_CLEANHTML);
}
}
11 changes: 11 additions & 0 deletions mod/feedback/lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -2058,6 +2058,17 @@ function feedback_get_page_to_continue($feedbackid, $courseid = false, $guestid
//functions to handle the values
////////////////////////////////////////////////

/**
* cleans the userinput while submitting the form.
*
* @param mixed $value
* @return mixed
*/
function feedback_clean_input_value($item, $value) {
$itemobj = feedback_get_item_class($item->typ);
return $itemobj->clean_input_value($value);
}

/**
* this saves the values of an completed.
* if the param $tmp is set true so the values are saved temporary in table feedback_valuetmp.
Expand Down

0 comments on commit 9a2c4db

Please sign in to comment.