diff --git a/main/img/percentagequestion.gif b/main/img/percentagequestion.gif new file mode 100644 index 0000000000..040aa57eeb Binary files /dev/null and b/main/img/percentagequestion.gif differ diff --git a/main/inc/lib/add_course.lib.inc.php b/main/inc/lib/add_course.lib.inc.php index cb59f8761a..b38f87ab23 100644 --- a/main/inc/lib/add_course.lib.inc.php +++ b/main/inc/lib/add_course.lib.inc.php @@ -1271,6 +1271,7 @@ function update_Db_course($courseDbName) display varchar(10) NOT NULL, sort int NOT NULL, shared_question_id int(11), + max_value int(11), PRIMARY KEY (question_id) )"; $result = mysql_query($sql) or die(mysql_error($sql)); @@ -1302,6 +1303,7 @@ function update_Db_course($courseDbName) survey_id int unsigned NOT NULL, question_id int unsigned NOT NULL, option_id int unsigned NOT NULL, + value int unsigned NOT NULL, user varchar(250) NOT NULL, PRIMARY KEY (answer_id) )"; @@ -1375,9 +1377,9 @@ function fill_course_repository($courseRepository) fputs($fp, $enreg); } fclose($fp); - + $default_document_array=array(); - + if(api_get_setting('example_material_course_creation')<>'false') { $img_code_path = api_get_path(SYS_CODE_PATH)."default_course_document/images/"; @@ -1388,14 +1390,14 @@ function fill_course_repository($courseRepository) $course_documents_folder_audio=$sys_course_path.$courseRepository.'/document/audio/'; $course_documents_folder_flash=$sys_course_path.$courseRepository.'/document/flash/'; $course_documents_folder_video=$sys_course_path.$courseRepository.'/document/video/'; - + /* * Images */ $files=array(); $files=browse_folders($img_code_path,$files,'images'); - + $pictures_array = sort_pictures($files,"dir"); $pictures_array = array_merge($pictures_array,sort_pictures($files,"file")); @@ -1414,16 +1416,16 @@ function fill_course_repository($courseRepository) } } - + $default_document_array['images']=$pictures_array; - + /* * Audio */ $files=array(); $files=browse_folders($audio_code_path,$files,'audio'); - + $audio_array = sort_pictures($files,"dir"); $audio_array = array_merge($audio_array,sort_pictures($files,"file")); @@ -1443,14 +1445,14 @@ function fill_course_repository($courseRepository) } $default_document_array['audio']=$audio_array; - + /* * Flash */ $files=array(); $files=browse_folders($flash_code_path,$files,'flash'); - + $flash_array = sort_pictures($files,"dir"); $flash_array = array_merge($flash_array,sort_pictures($files,"file")); @@ -1470,14 +1472,14 @@ function fill_course_repository($courseRepository) } $default_document_array['flash']=$flash_array; - + /* * Video */ $files=array(); $files=browse_folders($video_code_path,$files,'video'); - + $video_array = sort_pictures($files,"dir"); $video_array = array_merge($video_array,sort_pictures($files,"file")); @@ -1496,7 +1498,7 @@ function fill_course_repository($courseRepository) } } - $default_document_array['video']=$video_array; + $default_document_array['video']=$video_array; } return $default_document_array; @@ -1940,8 +1942,8 @@ function register_course($courseSysCode, $courseScreenCode, $courseRepository, $ sort='". ($sort +1) . "', user_course_cat='0'"; api_sql_query($sql, __FILE__, __LINE__); - - if(count($teachers)>0){ + + if(count($teachers)>0){ foreach($teachers as $key){ $sql = "INSERT INTO ".$TABLECOURSUSER . " SET course_code = '".addslashes($courseSysCode) . "', diff --git a/main/inc/lib/database.lib.php b/main/inc/lib/database.lib.php index 610e286c56..fe9a06f334 100644 --- a/main/inc/lib/database.lib.php +++ b/main/inc/lib/database.lib.php @@ -585,10 +585,15 @@ class Database * @param string The string to escape * @return string The escaped string * @author Yannick Warnier + * @author Patrick Cool , Ghent University */ function escape_string($string) { - return mysql_escape_string($string); + if (get_magic_quotes_gpc()) + { + $string = stripslashes($string); + } + return mysql_real_escape_string($string); } /** * Gets the array from a SQL result (as returned by api_sql_query) - help achieving database independence diff --git a/main/survey/fillsurvey.php b/main/survey/fillsurvey.php index 0c490416f5..96484c71c8 100644 --- a/main/survey/fillsurvey.php +++ b/main/survey/fillsurvey.php @@ -66,7 +66,7 @@ if (!isset($_GET['course']) OR !isset($_GET['invitationcode'])) } // now we check if the invitationcode is valid -$sql = "SELECT * FROM $table_survey_invitation WHERE invitation_code = '".mysql_real_escape_string($_GET['invitationcode'])."'"; +$sql = "SELECT * FROM $table_survey_invitation WHERE invitation_code = '".Database::escape_string($_GET['invitationcode'])."'"; $result = api_sql_query($sql, __FILE__, __LINE__); if (mysql_num_rows($result) < 1) { @@ -86,7 +86,7 @@ if ($survey_invitation['answered'] == 1) // checking if there is another survey with this code. // If this is the case there will be a language choice -$sql = "SELECT * FROM $table_survey WHERE code='".mysql_real_escape_string($survey_invitation['survey_code'])."'"; +$sql = "SELECT * FROM $table_survey WHERE code='".Database::escape_string($survey_invitation['survey_code'])."'"; $result = api_sql_query($sql, __FILE__, __LINE__); if (mysql_num_rows($result) > 1) { @@ -118,24 +118,70 @@ else // storing the answers if ($_POST) { + /* + echo '
';
+	print_r($_POST);
+	echo '
'; + */ + + // getting all the types of the question (because of the special treatment of the score question type + $sql = "SELECT * FROM $table_survey_question WHERE survey_id = '".Database::escape_string($survey_invitation['survey_id'])."'"; + $result = api_sql_query($sql, __FILE__, __LINE__); + while ($row = mysql_fetch_assoc($result)) + { + $types[$row['question_id']] = $row['type']; + } + + + // 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 (strstr($key,'question')) { + // finding the question id by removing 'question' $survey_question_id = str_replace('question', '',$key); + + // 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 if (is_array($value)) { remove_answer($survey_invitation['user'], $survey_invitation['survey_id'], $survey_question_id); foreach ($value as $answer_key => $answer_value) { - store_answer($survey_invitation['user'], $survey_invitation['survey_id'], $survey_question_id, $answer_value); + if ($types[$survey_question_id] == 'score') + { + $option_id = $answer_key; + $option_value = $answer_value; + } + else + { + $option_id = $answer_value; + $option_value = ''; + } + store_answer($survey_invitation['user'], $survey_invitation['survey_id'], $survey_question_id, $option_id, $option_value); } } - else // multipleresponse + // all the other question types (open question, multiple choice, percentage, ...) + else { + if ($types[$survey_question_id] == 'percentage') + { + $sql = "SELECT * FROM $table_survey_question_option WHERE question_option_id='".Database::escape_string($value)."'"; + $result = api_sql_query($sql, __FILE__, __LINE__); + $row = mysql_fetch_assoc($result); + $option_value = $row['option_text']; + } + else + { + $option_value = 0; + } + + $survey_question_answer = $value; remove_answer($survey_invitation['user'], $survey_invitation['survey_id'], $survey_question_id); - store_answer($survey_invitation['user'], $survey_invitation['survey_id'], $survey_question_id, $value); + store_answer($survey_invitation['user'], $survey_invitation['survey_id'], $survey_question_id, $value, $option_value); } } } @@ -168,12 +214,12 @@ if ($_POST['finish_survey']) if (isset($_GET['show'])) { // Getting all the questions for this page - $sql = "SELECT survey_question.question_id, survey_question.survey_id, survey_question.survey_question, survey_question.display, survey_question.sort, survey_question.type, + $sql = "SELECT survey_question.question_id, survey_question.survey_id, survey_question.survey_question, survey_question.display, survey_question.sort, survey_question.type, max_value, survey_question_option.question_option_id, survey_question_option.option_text, survey_question_option.sort as option_sort FROM $table_survey_question survey_question LEFT JOIN $table_survey_question_option survey_question_option ON survey_question.question_id = survey_question_option.question_id - WHERE survey_question.survey_id = '".mysql_real_escape_string($survey_invitation['survey_id'])."' + WHERE survey_question.survey_id = '".Database::escape_string($survey_invitation['survey_id'])."' ORDER BY survey_question.sort ASC"; if ($_GET['show']) { @@ -185,6 +231,7 @@ if (isset($_GET['show'])) while ($row = mysql_fetch_assoc($result)) { // if the type is not a pagebreak we store it in the $questions array + // which is used for displaying the page if($row['type'] <> 'pagebreak') { $questions[$row['sort']]['question_id'] = $row['question_id']; @@ -193,6 +240,10 @@ if (isset($_GET['show'])) $questions[$row['sort']]['display'] = $row['display']; $questions[$row['sort']]['type'] = $row['type']; $questions[$row['sort']]['options'][$row['question_option_id']] = $row['option_text']; + $questions[$row['sort']]['maximum_score'] = $row['max_value']; + + // we also store the type of the questions in an array + $types[$row['question_id']] = $row['type']; } // if the type is a pagebreak we are finished loading the questions for this page else @@ -239,18 +290,22 @@ Display :: display_footer(); * @author Patrick Cool , Ghent University * @version January 2007 */ -function store_answer($user, $survey_id, $question_id, $option_id) +function store_answer($user, $survey_id, $question_id, $option_id, $option_value) { global $_course; + global $types; + + // table definition $table_survey_answer = Database :: get_course_table(TABLE_SURVEY_ANSWER, $_course['db_name']); - $sql = "INSERT INTO $table_survey_answer (user, survey_id, question_id, option_id) VALUES ( - '".mysql_real_escape_string($user)."', - '".mysql_real_escape_string($survey_id)."', - '".mysql_real_escape_string($question_id)."', - '".mysql_real_escape_string($option_id)."' + $sql = "INSERT INTO $table_survey_answer (user, survey_id, question_id, option_id, value) VALUES ( + '".Database::escape_string($user)."', + '".Database::escape_string($survey_id)."', + '".Database::escape_string($question_id)."', + '".Database::escape_string($option_id)."', + '".Database::escape_string($option_value)."' )"; $result = api_sql_query($sql, __FILE__, __LINE__); } @@ -274,9 +329,9 @@ function remove_answer($user, $survey_id, $question_id) $table_survey_answer = Database :: get_course_table(TABLE_SURVEY_ANSWER, $_course['db_name']); $sql = "DELETE FROM $table_survey_answer - WHERE user = '".mysql_real_escape_string($user)."' - AND survey_id = '".mysql_real_escape_string($survey_id)."' - AND question_id = '".mysql_real_escape_string($question_id)."'"; + WHERE user = '".Database::escape_string($user)."' + AND survey_id = '".Database::escape_string($survey_id)."' + AND question_id = '".Database::escape_string($question_id)."'"; $result = api_sql_query($sql, __FILE__, __LINE__); } ?> \ No newline at end of file diff --git a/main/survey/preview.php b/main/survey/preview.php index 55f97b4008..6d31585a06 100644 --- a/main/survey/preview.php +++ b/main/survey/preview.php @@ -93,12 +93,12 @@ else if (isset($_GET['show'])) { // Getting all the questions for this page - $sql = "SELECT survey_question.question_id, survey_question.survey_id, survey_question.survey_question, survey_question.display, survey_question.sort, survey_question.type, + $sql = "SELECT survey_question.question_id, survey_question.survey_id, survey_question.survey_question, survey_question.display, survey_question.sort, survey_question.type, survey_question.max_value, survey_question_option.question_option_id, survey_question_option.option_text, survey_question_option.sort as option_sort FROM $table_survey_question survey_question LEFT JOIN $table_survey_question_option survey_question_option ON survey_question.question_id = survey_question_option.question_id - WHERE survey_question.survey_id = '".mysql_real_escape_string($_GET['survey_id'])."' + WHERE survey_question.survey_id = '".Database::escape_string($_GET['survey_id'])."' ORDER BY survey_question.sort ASC"; if ($_GET['show']) { @@ -119,6 +119,7 @@ else $questions[$row['sort']]['display'] = $row['display']; $questions[$row['sort']]['type'] = $row['type']; $questions[$row['sort']]['options'][$row['option_sort']] = $row['option_text']; + $questions[$row['sort']]['maximum_score'] = $row['max_value']; } // if the type is a pagebreak we are finished loading the questions for this page else diff --git a/main/survey/question.php b/main/survey/question.php index d62ffdd34e..55eecbac70 100644 --- a/main/survey/question.php +++ b/main/survey/question.php @@ -21,7 +21,7 @@ * @package dokeos.survey * @author unknown, the initial survey that did not make it in 1.8 because of bad code * @author Patrick Cool , Ghent University: cleanup, refactoring and rewriting large parts of the code -* @version $Id: question.php 11451 2007-03-06 21:54:30Z pcool $ +* @version $Id: question.php 11685 2007-03-25 21:14:55Z pcool $ */ // name of the language file that needs to be included @@ -76,7 +76,7 @@ if ($_GET['action'] == 'edit') // the possible question types -$possible_types = array('yesno', 'multiplechoice', 'multipleresponse', 'open', 'dropdown', 'comment', 'pagebreak'); +$possible_types = array('yesno', 'multiplechoice', 'multipleresponse', 'open', 'dropdown', 'comment', 'pagebreak', 'percentage', 'score'); // checking if it is a valid type if (!in_array($_GET['type'], $possible_types)) diff --git a/main/survey/reporting.php b/main/survey/reporting.php index 3c23a3f7f5..47f2a7020c 100644 --- a/main/survey/reporting.php +++ b/main/survey/reporting.php @@ -21,9 +21,9 @@ * @package dokeos.survey * @author unknown, the initial survey that did not make it in 1.8 because of bad code * @author Patrick Cool , Ghent University: cleanup, refactoring and rewriting large parts of the code -* @version $Id: reporting.php 11462 2007-03-07 07:49:38Z pcool $ +* @version $Id: reporting.php 11685 2007-03-25 21:14:55Z pcool $ * -* @todo use quickforms for the forms +* @todo The question has to be more clearly indicated (same style as when filling the survey) */ // name of the language file that needs to be included @@ -109,8 +109,21 @@ if (!$_GET['action'] OR $_GET['action'] == 'overview') else { $interbreadcrumb[] = array ("url" => "reporting.php?survey_id=".$_GET['survey_id'], "name" => get_lang('Reporting')); - /** @todo fix this language problem **/ - $tool_name = get_lang($_GET['action']); + switch ($_GET['action']) + { + case 'questionreport': + $tool_name = get_lang('DetailedReportByQuestion'); + break; + case 'userreport': + $tool_name = get_lang('DetailedReportByUser'); + break; + case 'comparativereport': + $tool_name = get_lang('ComparativeReport'); + break; + case 'completereport': + $tool_name = get_lang('CompleteReport'); + break; + } } // Displaying the header @@ -201,7 +214,18 @@ function check_parameters() function handle_reporting_actions() { // getting the number of question - $questions_data = survey_manager::get_questions($_GET['survey_id']); + $temp_questions_data = survey_manager::get_questions($_GET['survey_id']); + + // sorting like they should be displayed and removing the non-answer question types (comment and pagebreak) + foreach ($temp_questions_data as $key=>$value) + { + if ($value['type'] <> 'comment' AND $value['type']<>'pagebreak') + { + $questions_data[$value['sort']]=$value; + } + } + + // counting the number of questions that are relevant for the reporting $survey_data['number_of_questions'] = count($questions_data); if ($_GET['action'] == 'questionreport') @@ -271,40 +295,58 @@ function display_user_report() Display::display_normal_message(get_lang('AllQuestionsOnOnePage'), false); // getting all the questions and options - $sql = "SELECT survey_question.question_id, survey_question.survey_id, survey_question.survey_question, survey_question.display, survey_question.sort, survey_question.type, + $sql = "SELECT survey_question.question_id, survey_question.survey_id, survey_question.survey_question, survey_question.display, survey_question.max_value, survey_question.sort, survey_question.type, survey_question_option.question_option_id, survey_question_option.option_text, survey_question_option.sort as option_sort FROM $table_survey_question survey_question LEFT JOIN $table_survey_question_option survey_question_option ON survey_question.question_id = survey_question_option.question_id - WHERE survey_question.survey_id = '".mysql_real_escape_string($_GET['survey_id'])."' + WHERE survey_question.survey_id = '".Database::escape_string($_GET['survey_id'])."' ORDER BY survey_question.sort ASC"; $result = api_sql_query($sql, __FILE__, __LINE__); while ($row = mysql_fetch_assoc($result)) { if($row['type'] <> 'pagebreak') { - $questions[$row['sort']]['question_id'] = $row['question_id']; - $questions[$row['sort']]['survey_id'] = $row['survey_id']; - $questions[$row['sort']]['survey_question'] = $row['survey_question']; - $questions[$row['sort']]['display'] = $row['display']; - $questions[$row['sort']]['type'] = $row['type']; + $questions[$row['sort']]['question_id'] = $row['question_id']; + $questions[$row['sort']]['survey_id'] = $row['survey_id']; + $questions[$row['sort']]['survey_question'] = $row['survey_question']; + $questions[$row['sort']]['display'] = $row['display']; + $questions[$row['sort']]['type'] = $row['type']; + $questions[$row['sort']]['maximum_score'] = $row['max_value']; $questions[$row['sort']]['options'][$row['question_option_id']] = $row['option_text']; } } // getting all the answers of the user - $sql = "SELECT * FROM $table_survey_answer WHERE survey_id = '".mysql_real_escape_string($_GET['survey_id'])."' AND user = '".mysql_real_escape_string($_GET['user'])."'"; + $sql = "SELECT * FROM $table_survey_answer WHERE survey_id = '".Database::escape_string($_GET['survey_id'])."' AND user = '".Database::escape_string($_GET['user'])."'"; $result = api_sql_query($sql, __FILE__, __LINE__); while ($row = mysql_fetch_assoc($result)) { $answers[$row['question_id']][] = $row['option_id']; + $all_answers[$row['question_id']][] = $row; } // displaying all the questions foreach ($questions as $key=>$question) { + // if the question type is a scoring then we have to format the answers differently + if ($question['type'] == 'score') + { + foreach($all_answers[$question['question_id']] as $key=>$answer_array) + { + $second_parameter[$answer_array['option_id']] = $answer_array['value']; + } + } + else + { + $second_parameter = $answers[$question['question_id']]; + } + $display = new $question['type']; - $display->render_question($question, $answers[$question['question_id']]); + $display->render_question($question, $second_parameter); +// echo '
';
+	//		print_r($answers[$question['question_id']]);
+		//	echo '
'; } } } @@ -325,6 +367,7 @@ function display_user_report() * @todo allow switching between horizontal and vertical. * @todo multiple response: percentage are probably not OK * @todo the question and option text have to be shortened and should expand when the user clicks on it. + * @todo the pagebreak and comment question types should not be shown => removed from $survey_data before * * @author Patrick Cool , Ghent University * @version February 2007 @@ -346,11 +389,30 @@ function display_question_report($survey_data) $offset = $_GET['question']; } + echo '
'; + for($i=1; $i<=($survey_data['number_of_questions']); $i++ ) + { + if ($offset <> $i-1) + { + echo ''.$i.''; + } + else + { + echo $i; + } + if ($i < $survey_data['number_of_questions']) + { + echo ' | '; + } + } + echo '
'; + // getting the question information - $sql = "SELECT * FROM $table_survey_question WHERE survey_id='".mysql_real_escape_string($_GET['survey_id'])."' LIMIT ".$offset.",1"; + $sql = "SELECT * FROM $table_survey_question WHERE survey_id='".Database::escape_string($_GET['survey_id'])."' AND type<>'pagebreak' AND type<>'comment' ORDER BY sort ASC LIMIT ".$offset.",1"; $result = api_sql_query($sql, __FILE__, __LINE__); $question = mysql_fetch_assoc($result); + // navigate through the questions (next and previous) if ($_GET['question'] <> 0) { echo ' << '.get_lang('PreviousQuestion').' '; @@ -372,10 +434,113 @@ function display_question_report($survey_data) echo $question['survey_question']; + echo '
'; + + if ($question['type'] == 'score') + { + /** @todo this function should return the options as this is needed further in the code */ + $options = display_question_report_score($survey_data, $question, $offset); + } + elseif ($question['type'] == 'open') + { + /** @todo also get the user who has answered this */ + $sql = "SELECT * FROM $table_survey_answer WHERE survey_id='".Database::escape_string($_GET['survey_id'])."' + AND question_id = '".Database::escape_string($question['question_id'])."'"; + $result = api_sql_query($sql, __FILE__, __LINE__); + while ($row = mysql_fetch_assoc($result)) + { + echo $row['option_id'].'
'; + } + + } + else + { + // getting the options + $sql = "SELECT * FROM $table_survey_question_option + WHERE survey_id='".Database::escape_string($_GET['survey_id'])."' + AND question_id = '".Database::escape_string($question['question_id'])."' + ORDER BY sort ASC"; + $result = api_sql_query($sql, __FILE__, __LINE__); + while ($row = mysql_fetch_assoc($result)) + { + $options[$row['question_option_id']] = $row; + } + + // getting the answers + $sql = "SELECT *, count(answer_id) as total FROM $table_survey_answer + WHERE survey_id='".Database::escape_string($_GET['survey_id'])."' + AND question_id = '".Database::escape_string($question['question_id'])."' + GROUP BY option_id, value"; + $result = api_sql_query($sql, __FILE__, __LINE__); + while ($row = mysql_fetch_assoc($result)) + { + $number_of_answers += $row['total']; + $data[$row['option_id']] = $row; + } + + // displaying the table: headers + echo ''; + echo ' '; + echo ' '; + echo ' '; + echo ' '; + echo ' '; + echo ' '; + + + // displaying the table: the content + foreach ($options as $key=>$value) + { + $absolute_number = $data[$value['question_option_id']]['total']; + + echo ' '; + echo ' '; + echo ' '; + echo ' '; + echo ' '; + echo ' '; + } + + // displaying the table: footer (totals) + echo ' '; + echo ' '; + echo ' '; + echo ' '; + echo ' '; + echo ' '; + + echo '
 '.get_lang('AbsoluteTotal').''.get_lang('Percentage').''.get_lang('VisualRepresentation').'
'.$value['option_text'].''.$absolute_number.''.round($absolute_number/$number_of_answers*100, 2).' %
 
'.get_lang('Total').''.$number_of_answers.'  
'; + } + + if (isset($_GET['viewoption'])) + { + echo get_lang('PeopleWhoAnswered').': '.$options[$_GET['viewoption']]['option_text'].'
'; + + if (is_numeric($_GET['value'])) + { + $sql_restriction = "AND value='".Database::escape_string($_GET['value'])."'"; + } + + $sql = "SELECT user FROM $table_survey_answer WHERE option_id = '".Database::escape_string($_GET['viewoption'])."' $sql_restriction"; + $result = api_sql_query($sql, __FILE__, __LINE__); + while ($row = mysql_fetch_assoc($result)) + { + echo ''.$row['user'].'
'; + } + } +} + +function display_question_report_score($survey_data, $question, $offset) +{ + // Database table definitions + $table_survey_question = Database :: get_course_table(TABLE_SURVEY_QUESTION); + $table_survey_question_option = Database :: get_course_table(TABLE_SURVEY_QUESTION_OPTION); + $table_survey_answer = Database :: get_course_table(TABLE_SURVEY_ANSWER); + // getting the options $sql = "SELECT * FROM $table_survey_question_option - WHERE survey_id='".mysql_real_escape_string($_GET['survey_id'])."' - AND question_id = '".mysql_real_escape_string($question['question_id'])."' + WHERE survey_id='".Database::escape_string($_GET['survey_id'])."' + AND question_id = '".Database::escape_string($question['question_id'])."' ORDER BY sort ASC"; $result = api_sql_query($sql, __FILE__, __LINE__); while ($row = mysql_fetch_assoc($result)) @@ -385,20 +550,27 @@ function display_question_report($survey_data) // getting the answers $sql = "SELECT *, count(answer_id) as total FROM $table_survey_answer - WHERE survey_id='".mysql_real_escape_string($_GET['survey_id'])."' - AND question_id = '".mysql_real_escape_string($question['question_id'])."' - GROUP BY option_id"; + WHERE survey_id='".Database::escape_string($_GET['survey_id'])."' + AND question_id = '".Database::escape_string($question['question_id'])."' + GROUP BY option_id, value"; $result = api_sql_query($sql, __FILE__, __LINE__); while ($row = mysql_fetch_assoc($result)) { $number_of_answers += $row['total']; - $data[$row['option_id']] = $row; + $data[$row['option_id']][$row['value']] = $row; } + /* + echo '
';
+	print_r($data);
+	echo '
'; + */ + // displaying the table: headers echo ''; echo ' '; echo ' '; + echo ' '; echo ' '; echo ' '; echo ' '; @@ -408,37 +580,29 @@ function display_question_report($survey_data) // displaying the table: the content foreach ($options as $key=>$value) { - $absolute_number = $data[$value['question_option_id']]['total']; + for ($i=1; $i<=$question['max_value']; $i++) + { + $absolute_number = $data[$value['question_option_id']][$i]['total']; + echo ' '; + echo ' '; + echo ' '; + echo ' '; + echo ' '; + echo ' '; + echo ' '; + } + } + // displaying the table: footer (totals) echo ' '; - echo ' '; - echo ' '; - echo ' '; - echo ' '; + echo ' '; + echo ' '; + echo ' '; + echo ' '; + echo ' '; echo ' '; - } - - // displaying the table: footer (totals) - echo ' '; - echo ' '; - echo ' '; - echo ' '; - echo ' '; - echo ' '; - - echo '
 '.get_lang('Score').''.get_lang('AbsoluteTotal').''.get_lang('Percentage').''.get_lang('VisualRepresentation').'
'.$value['option_text'].''.$i.''.$absolute_number.''.round($absolute_number/$number_of_answers*100, 2).' %
 
'.$value['option_text'].''.$absolute_number.''.round($absolute_number/$number_of_answers*100, 2).' %
 
'.get_lang('Total').' '.$number_of_answers.'  
'.get_lang('Total').''.$number_of_answers.'  
'; - - if (isset($_GET['viewoption'])) - { - echo get_lang('PeopleWhoAnswered').': '.$options[$_GET['viewoption']]['option_text'].'
'; - $sql = "SELECT user FROM $table_survey_answer WHERE option_id = '".mysql_real_escape_string($_GET['viewoption'])."'"; - $result = api_sql_query($sql, __FILE__, __LINE__); - while ($row = mysql_fetch_assoc($result)) - { - echo ''.$row['user'].'
'; - } - } + echo ''; } /** @@ -480,7 +644,7 @@ function display_complete_report() FROM $table_survey_question questions LEFT JOIN $table_survey_question_option options ON questions.question_id = options.question_id /*WHERE questions.question_id = options.question_id*/ - AND questions.survey_id = '".mysql_real_escape_string($_GET['survey_id'])."' + AND questions.survey_id = '".Database::escape_string($_GET['survey_id'])."' GROUP BY questions.question_id"; $result = api_sql_query($sql, __FILE__, __LINE__); while ($row = mysql_fetch_assoc($result)) @@ -517,7 +681,7 @@ function display_complete_report() FROM $table_survey_question survey_question LEFT JOIN $table_survey_question_option survey_question_option ON survey_question.question_id = survey_question_option.question_id - WHERE survey_question.survey_id = '".mysql_real_escape_string($_GET['survey_id'])."' + WHERE survey_question.survey_id = '".Database::escape_string($_GET['survey_id'])."' ORDER BY survey_question.sort ASC"; $result = api_sql_query($sql, __FILE__, __LINE__); while ($row = mysql_fetch_assoc($result)) @@ -542,7 +706,7 @@ function display_complete_report() // getting all the answers of the users $old_user=''; $answers_of_user = array(); - $sql = "SELECT * FROM $table_survey_answer WHERE survey_id='".mysql_real_escape_string($_GET['survey_id'])."' ORDER BY user ASC"; + $sql = "SELECT * FROM $table_survey_answer WHERE survey_id='".Database::escape_string($_GET['survey_id'])."' ORDER BY user ASC"; $result = api_sql_query($sql, __FILE__, __LINE__); while ($row = mysql_fetch_assoc($result)) { @@ -587,7 +751,14 @@ function display_complete_report_row($possible_answers, $answers_of_user, $user) echo ''; if (!empty($answers_of_user[$question_id][$option_id])) { - echo 'v'; + if ($answers_of_user[$question_id][$option_id]['value']<>0) + { + echo $answers_of_user[$question_id][$option_id]['value']; + } + else + { + echo 'v'; + } } echo ''; } @@ -620,7 +791,7 @@ function export_complete_report() FROM $table_survey_question questions LEFT JOIN $table_survey_question_option options ON questions.question_id = options.question_id /*WHERE questions.question_id = options.question_id*/ - AND questions.survey_id = '".mysql_real_escape_string($_GET['survey_id'])."' + AND questions.survey_id = '".Database::escape_string($_GET['survey_id'])."' GROUP BY questions.question_id"; $result = api_sql_query($sql, __FILE__, __LINE__); while ($row = mysql_fetch_assoc($result)) @@ -649,7 +820,7 @@ function export_complete_report() FROM $table_survey_question survey_question LEFT JOIN $table_survey_question_option survey_question_option ON survey_question.question_id = survey_question_option.question_id - WHERE survey_question.survey_id = '".mysql_real_escape_string($_GET['survey_id'])."' + WHERE survey_question.survey_id = '".Database::escape_string($_GET['survey_id'])."' ORDER BY survey_question.sort ASC"; $result = api_sql_query($sql, __FILE__, __LINE__); while ($row = mysql_fetch_assoc($result)) @@ -672,7 +843,7 @@ function export_complete_report() // getting all the answers of the users $old_user=''; $answers_of_user = array(); - $sql = "SELECT * FROM $table_survey_answer WHERE survey_id='".mysql_real_escape_string($_GET['survey_id'])."' ORDER BY user ASC"; + $sql = "SELECT * FROM $table_survey_answer WHERE survey_id='".Database::escape_string($_GET['survey_id'])."' ORDER BY user ASC"; $result = api_sql_query($sql, __FILE__, __LINE__); while ($row = mysql_fetch_assoc($result)) { @@ -735,6 +906,9 @@ function export_complete_report_row($possible_answers, $answers_of_user, $user) */ function display_comparative_report() { + // allowed question types for comparative report + $allowed_question_types = array('yesno', 'multiplechoice', 'multipleresponse', 'dropdown', 'percentage', 'score'); + // getting all the questions $questions = survey_manager::get_questions($_GET['survey_id']); @@ -752,7 +926,7 @@ function display_comparative_report() echo ''; foreach ($questions as $key=>$question) { - if (in_array($question['type'], array('yesno', 'multiplechoice', 'multipleresponse', 'dropdown'))) + if (in_array($question['type'], $allowed_question_types)) { echo ''; foreach ($questions as $key=>$question) { - if (in_array($question['type'], array('yesno', 'multiplechoice', 'multipleresponse', 'dropdown'))) + if (in_array($question['type'], $allowed_question_types)) { echo '