diff --git a/mod/survey/db/mysql.php b/mod/survey/db/mysql.php index 41c7c0e7154..48df9e725d8 100644 --- a/mod/survey/db/mysql.php +++ b/mod/survey/db/mysql.php @@ -4,6 +4,8 @@ function survey_upgrade($oldversion) { // This function does anything necessary to upgrade // older versions to match current functionality + global $CFG; + if ($oldversion < 2002081400) { execute_sql(" ALTER TABLE `survey_questions` DROP `owner` "); @@ -156,6 +158,15 @@ function survey_upgrade($oldversion) { execute_sql("ALTER TABLE `survey_answers` CHANGE `user` `userid` INT(10) UNSIGNED DEFAULT '0' NOT NULL "); } + if ($oldversion < 2003051502) { + execute_sql("INSERT INTO `{$CFG->prefix}survey` (`id`, `course`, `template`, `days`, `timecreated`, `timemodified`, `name`, `intro`, `questions`) VALUES (5, 0, 0, 0, 985017600, 985017600, 'ciqname', 'ciqintro', '69,70,71,72,73')"); + execute_sql("INSERT INTO `{$CFG->prefix}survey_questions` (`id`, `text`, `shorttext`, `multi`, `intro`, `type`, `options`) VALUES (69, 'ciq1', 'ciq1short', '', '', 0, '')"); + execute_sql("INSERT INTO `{$CFG->prefix}survey_questions` (`id`, `text`, `shorttext`, `multi`, `intro`, `type`, `options`) VALUES (70, 'ciq2', 'ciq2short', '', '', 0, '')"); + execute_sql("INSERT INTO `{$CFG->prefix}survey_questions` (`id`, `text`, `shorttext`, `multi`, `intro`, `type`, `options`) VALUES (71, 'ciq3', 'ciq3short', '', '', 0, '')"); + execute_sql("INSERT INTO `{$CFG->prefix}survey_questions` (`id`, `text`, `shorttext`, `multi`, `intro`, `type`, `options`) VALUES (72, 'ciq4', 'ciq4short', '', '', 0, '')"); + execute_sql("INSERT INTO `{$CFG->prefix}survey_questions` (`id`, `text`, `shorttext`, `multi`, `intro`, `type`, `options`) VALUES (73, 'ciq5', 'ciq5short', '', '', 0, '')"); + } + return true; } diff --git a/mod/survey/db/mysql.sql b/mod/survey/db/mysql.sql index 40df0fbc0a9..6ae60272ca6 100755 --- a/mod/survey/db/mysql.sql +++ b/mod/survey/db/mysql.sql @@ -35,6 +35,7 @@ INSERT INTO `prefix_survey` (`id`, `course`, `template`, `days`, `timecreated`, INSERT INTO `prefix_survey` (`id`, `course`, `template`, `days`, `timecreated`, `timemodified`, `name`, `intro`, `questions`) VALUES (2, 0, 0, 0, 985017600, 985017600, 'collespname', 'collespintro', '31,32,33,34,35,36,43,44'); INSERT INTO `prefix_survey` (`id`, `course`, `template`, `days`, `timecreated`, `timemodified`, `name`, `intro`, `questions`) VALUES (3, 0, 0, 0, 985017600, 985017600, 'collesapname', 'collesapintro', '37,38,39,40,41,42,43,44'); INSERT INTO `prefix_survey` (`id`, `course`, `template`, `days`, `timecreated`, `timemodified`, `name`, `intro`, `questions`) VALUES (4, 0, 0, 0, 985017600, 985017600, 'attlsname', 'attlsintro', '65,67,68'); +INSERT INTO `prefix_survey` (`id`, `course`, `template`, `days`, `timecreated`, `timemodified`, `name`, `intro`, `questions`) VALUES (5, 0, 0, 0, 985017600, 985017600, 'ciqname', 'ciqintro', '69,70,71,72,73'); @@ -166,6 +167,11 @@ INSERT INTO `prefix_survey_questions` (`id`, `text`, `shorttext`, `multi`, `intr INSERT INTO `prefix_survey_questions` (`id`, `text`, `shorttext`, `multi`, `intro`, `type`, `options`) VALUES (67, 'attlsm2', 'attlsm2', '63,62,59,57,55,49,52,50,48,47', 'attlsmintro', -1, 'scaleagree5'); INSERT INTO `prefix_survey_questions` (`id`, `text`, `shorttext`, `multi`, `intro`, `type`, `options`) VALUES (68, 'attlsm3', 'attlsm3', '46,54,45,51,60,53,56,58,61,64', 'attlsmintro', -1, 'scaleagree5'); +INSERT INTO `prefix_survey_questions` (`id`, `text`, `shorttext`, `multi`, `intro`, `type`, `options`) VALUES (69, 'ciq1', 'ciq1short', '', '', 0, ''); +INSERT INTO `prefix_survey_questions` (`id`, `text`, `shorttext`, `multi`, `intro`, `type`, `options`) VALUES (70, 'ciq2', 'ciq2short', '', '', 0, ''); +INSERT INTO `prefix_survey_questions` (`id`, `text`, `shorttext`, `multi`, `intro`, `type`, `options`) VALUES (71, 'ciq3', 'ciq3short', '', '', 0, ''); +INSERT INTO `prefix_survey_questions` (`id`, `text`, `shorttext`, `multi`, `intro`, `type`, `options`) VALUES (72, 'ciq4', 'ciq4short', '', '', 0, ''); +INSERT INTO `prefix_survey_questions` (`id`, `text`, `shorttext`, `multi`, `intro`, `type`, `options`) VALUES (73, 'ciq5', 'ciq5short', '', '', 0, ''); # diff --git a/mod/survey/db/postgres7.php b/mod/survey/db/postgres7.php index 91c00d00178..eaab3078e12 100644 --- a/mod/survey/db/postgres7.php +++ b/mod/survey/db/postgres7.php @@ -6,6 +6,15 @@ function survey_upgrade($oldversion) { global $CFG; + if ($oldversion < 2003051501) { + modify_database("", "INSERT INTO `prefix_survey` (`id`, `course`, `template`, `days`, `timecreated`, `timemodified`, `name`, `intro`, `questions`) VALUES (5, 0, 0, 0, 985017600, 985017600, 'ciqname', 'ciqintro', '69,70,71,72,73')"); + modify_database("", "INSERT INTO `prefix_survey_questions` (`id`, `text`, `shorttext`, `multi`, `intro`, `type`, `options`) VALUES (69, 'ciq1', 'ciq1short', '', '', 0, '')"); + modify_database("", "INSERT INTO `prefix_survey_questions` (`id`, `text`, `shorttext`, `multi`, `intro`, `type`, `options`) VALUES (70, 'ciq2', 'ciq2short', '', '', 0, '')"); + modify_database("", "INSERT INTO `prefix_survey_questions` (`id`, `text`, `shorttext`, `multi`, `intro`, `type`, `options`) VALUES (71, 'ciq3', 'ciq3short', '', '', 0, '')"); + modify_database("", "INSERT INTO `prefix_survey_questions` (`id`, `text`, `shorttext`, `multi`, `intro`, `type`, `options`) VALUES (72, 'ciq4', 'ciq4short', '', '', 0, '')"); + modify_database("", "INSERT INTO `prefix_survey_questions` (`id`, `text`, `shorttext`, `multi`, `intro`, `type`, `options`) VALUES (73, 'ciq5', 'ciq5short', '', '', 0, '')"); + } + return true; } diff --git a/mod/survey/db/postgres7.sql b/mod/survey/db/postgres7.sql index d3865c7e537..5a1a8607046 100755 --- a/mod/survey/db/postgres7.sql +++ b/mod/survey/db/postgres7.sql @@ -34,6 +34,7 @@ INSERT INTO prefix_survey (id, course, template, days, timecreated, timemodified INSERT INTO prefix_survey (id, course, template, days, timecreated, timemodified, name, intro, questions) VALUES (2, 0, 0, 0, 985017600, 985017600, 'collespname', 'collespintro', '31,32,33,34,35,36,43,44'); INSERT INTO prefix_survey (id, course, template, days, timecreated, timemodified, name, intro, questions) VALUES (3, 0, 0, 0, 985017600, 985017600, 'collesapname', 'collesapintro', '37,38,39,40,41,42,43,44'); INSERT INTO prefix_survey (id, course, template, days, timecreated, timemodified, name, intro, questions) VALUES (4, 0, 0, 0, 985017600, 985017600, 'attlsname', 'attlsintro', '65,67,68'); +INSERT INTO prefix_survey (id, course, template, days, timecreated, timemodified, name, intro, questions) VALUES (5, 0, 0, 0, 985017600, 985017600, 'ciqname', 'ciqintro', '69,70,71,72,73'); @@ -161,6 +162,11 @@ INSERT INTO prefix_survey_questions (id, text, shorttext, multi, intro, type, op INSERT INTO prefix_survey_questions (id, text, shorttext, multi, intro, type, options) VALUES (68, 'attlsm3', 'attlsm3', '46,54,45,51,60,53,56,58,61,64', 'attlsmintro', -1, 'scaleagree5'); +INSERT INTO prefix_survey_questions (id, text, shorttext, multi, intro, type, options) VALUES (69, 'ciq1', 'ciq1short', '', '', 0, ''); +INSERT INTO prefix_survey_questions (id, text, shorttext, multi, intro, type, options) VALUES (70, 'ciq2', 'ciq2short', '', '', 0, ''); +INSERT INTO prefix_survey_questions (id, text, shorttext, multi, intro, type, options) VALUES (71, 'ciq3', 'ciq3short', '', '', 0, ''); +INSERT INTO prefix_survey_questions (id, text, shorttext, multi, intro, type, options) VALUES (72, 'ciq4', 'ciq4short', '', '', 0, ''); +INSERT INTO prefix_survey_questions (id, text, shorttext, multi, intro, type, options) VALUES (73, 'ciq5', 'ciq5short', '', '', 0, ''); # # Dumping data for table log_display diff --git a/mod/survey/lib.php b/mod/survey/lib.php index 64ab2da2306..2844f7f59db 100644 --- a/mod/survey/lib.php +++ b/mod/survey/lib.php @@ -178,7 +178,7 @@ function survey_get_participants($surveyid) { function survey_log_info($log) { global $CFG; - return get_record_sql("SELECT s.name, u.firstname, u.lastname + return get_record_sql("SELECT s.name, u.firstname, u.lastname, u.picture FROM {$CFG->prefix}survey s, {$CFG->prefix}user u WHERE s.id = '$log->info' @@ -189,11 +189,10 @@ function survey_get_responses($survey) { global $CFG; return get_records_sql("SELECT MAX(a.time) as time, count(*) as numanswers, - u.id, u.firstname, u.lastname + u.id, u.firstname, u.lastname, u.picture FROM {$CFG->prefix}survey_answers AS a, {$CFG->prefix}user AS u - WHERE a.answer1 <> '0' AND a.answer2 <> '0' - AND a.survey = $survey + WHERE a.survey = $survey AND a.userid = u.id GROUP BY u.id, u.firstname, u.lastname ORDER BY time ASC"); @@ -218,7 +217,7 @@ function survey_update_analysis($survey, $user, $notes) { } -function survey_get_user_answers($surveyid, $questionid) { +function survey_get_user_answers($surveyid, $questionid, $sort="sa.answer1,sa.answer2 ASC") { global $CFG; return get_records_sql("SELECT sa.*,u.firstname,u.lastname,u.picture @@ -227,7 +226,17 @@ function survey_get_user_answers($surveyid, $questionid) { WHERE sa.survey = '$surveyid' AND sa.question = $questionid AND u.id = sa.userid - ORDER BY sa.answer1,sa.answer2 ASC"); + ORDER BY $sort"); +} + +function survey_get_user_answer($surveyid, $questionid, $userid) { + global $CFG; + + return get_record_sql("SELECT sa.* + FROM {$CFG->prefix}survey_answers sa + WHERE sa.survey = '$surveyid' + AND sa.question = '$questionid' + AND sa.userid = '$userid'"); } // MODULE FUNCTIONS //////////////////////////////////////////////////////// @@ -255,23 +264,20 @@ function survey_count_responses($survey) { } -function survey_print_all_responses($survey, $results) { +function survey_print_all_responses($cmid, $results, $courseid) { global $THEME; - $dateformat = get_string("strftimedatetime"); - - echo "
| Name | Time | Answered |
| id&id=$survey\">".fullname($a)." | "; - echo "".userdate($a->time, $dateformat)." | "; - echo "$a->numanswers | "; - echo "
";
+ echo " ";
survey_print_graph("id=$id&type=overall.png");
- echo "";
+ echo "
".get_string("nobodyyet","survey")."
"; + echo "".get_string("nobodyyet","survey")."
"; } - print_footer($course); break; case "scales": - print_header("$survey->name: $strscales", "$strallscales"); + print_heading($strscales); $questions = get_records_list("survey_questions", "id", $survey->questions); $questionorder = explode(",", $survey->questions); @@ -121,13 +115,12 @@ if ($virtualscales && $question->type > 0) { // Don't show non-virtual scales if virtual continue; } - echo "multi>";
+ echo " multi>";
survey_print_graph("id=$id&qid=$question->id&type=multiquestion.png");
- echo "
";
+ echo "
";
- echo "id\">";
+ echo " ";
+ echo "id\">";
survey_print_graph("id=$id&qid=$subquestion->id&type=question.png");
- echo "
";
- echo "id\">";
+ echo " ";
+ echo "id\">";
survey_print_graph("id=$id&qid=$question->id&type=question.png");
- echo "
| '.fullname($a).' | '; + $contents .= ''.$a->answer1.' | '; + $contents .= "
| $strname | $strtime | $stractual | $strpreferred | |
|---|---|---|---|---|
| "; - print_user_picture($a->userid, $course->id, $a->picture, false); - echo " | "; - echo ""; - echo " | ".userdate($a->time, $strdateformat)." | ";
- echo "cellcontent\"> "; if ($a->answer1) { - echo "$a->answer1 - ".$answers[$a->answer1 - 1]; + $answer1 = "$a->answer1 - ".$answers[$a->answer1 - 1]; } else { - echo " "; + $answer1 = " "; } - echo " | cellcontent\"> "; if ($a->answer2) { - echo "$a->answer2 - ".$answers[$a->answer2 - 1]; + $answer2 = "$a->answer2 - ".$answers[$a->answer2 - 1]; } else { - echo " "; + $answer2 = " "; } - echo " |
"; + echo "
"; print_user_picture($user->id, $course->id, $user->picture, true); - echo "
"; + echo ""; - // Print overall summary - echo ""; - survey_print_graph("id=$id&sid=$student&type=student.png"); - echo "
"; - - // Print scales $questions = get_records_list("survey_questions", "id", $survey->questions); $questionorder = explode(",", $survey->questions); - - foreach ($questionorder as $key => $val) { - $question = $questions[$val]; - if ($question->type < 0) { // We have some virtual scales. Just show them. - $virtualscales = true; - break; - } - } - - foreach ($questionorder as $key => $val) { - $question = $questions[$val]; - if ($question->multi) { - if ($virtualscales && $question->type > 0) { // Don't show non-virtual scales if virtual - continue; + + if ($showscales) { + // Print overall summary + echo ""; + survey_print_graph("id=$id&sid=$student&type=student.png"); + echo "
"; + + // Print scales + + foreach ($questionorder as $key => $val) { + $question = $questions[$val]; + if ($question->type < 0) { // We have some virtual scales. Just show them. + $virtualscales = true; + break; } - echo "'.get_string("downloadinfo", "survey").'
'; - echo "$strdownloadinfo
"; + echo 'id\">".
+ echo " id\">".
get_string("viewsurveyresponses", "survey", $numusers)."