Add validation on survey's no-question records - loosely refs BT#11698

pull/2487/head
Yannick Warnier 9 years ago
parent 84eb2946a1
commit 80a293bca6
  1. 15
      main/survey/fillsurvey.php
  2. 6
      main/survey/survey.lib.php

@ -203,10 +203,15 @@ if (count($_POST) > 0) {
// Looping through all the post values
foreach ($_POST as $key => & $value) {
// If the post value key contains the string 'question' then it is an answer on a question
if (strpos($key, 'question') !== false) {
if (strpos($key, 'question') !== false && ($key != '_qf__question')) {
// Finding the question id by removing 'question'
$survey_question_id = str_replace('question', '', $key);
// If not question ID was defined, we're on the start
// screen or something else that doesn't require
// saving an answer
if (empty($survey_question_id)) {
continue;
}
/* If the post value is an array then we have a multiple response question or a scoring question type
remark: when it is a multiple response then the value of the array is the option_id
when it is a scoring question then the key of the array is the option_id and the value is the value
@ -302,6 +307,12 @@ if (count($_POST) > 0) {
if (strpos($key, 'question') !== false) {
// Finding the question id by removing 'question'
$survey_question_id = str_replace('question', '', $key);
// If not question ID was defined, we're on the start
// screen or something else that doesn't require
// saving an answer
if (empty($survey_question_id)) {
continue;
}
// We select the correct answer and the puntuacion
$sql = "SELECT value FROM $table_survey_question_option
WHERE c_id = $course_id AND question_option_id='".intval($value)."'";

@ -1793,12 +1793,17 @@ class SurveyUtil
* @param integer Option id
* @param string Option value
* @param array Survey data settings
* @return bool False if insufficient data, true otherwise
*
* @author Patrick Cool <patrick.cool@UGent.be>, Ghent University
* @version January 2007
*/
public static function store_answer($user, $survey_id, $question_id, $option_id, $option_value, $survey_data)
{
// If the question_id is empty, don't store an answer
if (empty($question_id)) {
return false;
}
// Table definition
$table_survey_answer = Database :: get_course_table(TABLE_SURVEY_ANSWER);
@ -1827,6 +1832,7 @@ class SurveyUtil
$sql = "UPDATE $table_survey_answer SET answer_id = $insertId WHERE iid = $insertId";
Database::query($sql);
return true;
}
/**

Loading…
Cancel
Save