From 7c8c335fa3a7e10ac93267e1f7882ff02cdf089c Mon Sep 17 00:00:00 2001 From: moodler Date: Mon, 16 Feb 2004 16:13:31 +0000 Subject: [PATCH] Complete clean-up of the survey reports. Frames are GONE. :-) Also, a new survey: CIQ = Critical Incident Questionnaire --- mod/survey/db/mysql.php | 11 ++ mod/survey/db/mysql.sql | 6 + mod/survey/db/postgres7.php | 9 ++ mod/survey/db/postgres7.sql | 6 + mod/survey/lib.php | 42 ++--- mod/survey/report.php | 299 +++++++++++++++++++----------------- mod/survey/version.php | 2 +- mod/survey/view.php | 39 ++++- 8 files changed, 249 insertions(+), 165 deletions(-) diff --git a/mod/survey/db/mysql.php b/mod/survey/db/mysql.php index 41c7c0e715..48df9e725d 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 40df0fbc0a..6ae60272ca 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 91c00d0017..eaab3078e1 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 d3865c7e53..5a1a860704 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 64ab2da230..2844f7f59d 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 ""; - echo ""; + $table->head = array ("", get_string("name"), get_string("time"), get_string("answers", "survey")); + $table->align = array ("", "left", "left", "right"); + $table->size = array (35, "", "", ""); foreach ($results as $a) { - - echo ""; - echo ""; - echo ""; - echo ""; - echo ""; + $table->data[] = array(print_user_picture($a->id, $courseid, $a->picture, false, true, false), + "id&id=$cmid\">".fullname($a)."", + userdate($a->time), $a->numanswers); } - echo "
NameTimeAnswered
id&id=$survey\">".fullname($a)."".userdate($a->time, $dateformat)."$a->numanswers
"; + + print_table($table); } diff --git a/mod/survey/report.php b/mod/survey/report.php index 6cd5dc77c3..035e16e959 100644 --- a/mod/survey/report.php +++ b/mod/survey/report.php @@ -5,7 +5,8 @@ // Check that all the parameters have been provided. - require_variable($id); // Course Module ID + require_variable($id); // Course Module ID + optional_variable($action, "students"); // What to look at if (! $cm = get_record("course_modules", "id", $id)) { error("Course Module ID was incorrect"); @@ -25,10 +26,15 @@ error("Survey ID was incorrect"); } + if (! $template = get_record("survey", "id", $survey->template)) { + error("Template ID was incorrect"); + } + + $showscales = ($template->name != 'ciqname'); - $ME = qualified_me()."?id=$id"; $strreport = get_string("report", "survey"); + $strsurvey = get_string("modulename", "survey"); $strsurveys = get_string("modulenameplural", "survey"); $strsummary = get_string("summary", "survey"); $strscales = get_string("scales", "survey"); @@ -41,68 +47,56 @@ $strseemoredetail = get_string("seemoredetail", "survey"); $strnotes = get_string("notes", "survey"); - if (empty($action)) { - $display = "summary"; + add_to_log($course->id, "survey", "view report", "report.php?id=$cm->id", "$survey->id", $cm->id); + + if ($course->category) { + $navigation = "id\">$course->shortname -> + id\">$strsurveys -> + id\">$survey->name -> "; + } else { + $navigation = "id\">$strsurveys -> + id\">$survey->name -> "; } - if (!empty($display)) { // Display the frame containing something. - add_to_log($course->id, "survey", "view report", "report.php?id=$cm->id", "$survey->id"); - echo "$course->shortname: $strreport: $survey->name\n"; - echo " "; - echo " \n"; - echo " "; - echo " \n"; - echo " \n"; - echo " \n"; - echo "\n"; - exit; + print_header("$course->shortname: $survey->name", "$course->fullname", "$navigation $strreport", + "", "", true, + update_module_button($cm->id, $course->id, $strsurvey), navmenu($course, $cm)); + + print_simple_box_start("center"); + if ($showscales) { + echo "$strsummary"; + echo "    $strscales"; + echo "    $strquestions"; + echo "    $course->students"; + echo "    $strdownload"; + } else { + echo "$strquestions"; + echo "    $course->students"; + echo "    $strdownload"; } + print_simple_box_end(); - switch ($action) { - case "top": - if ($course->category) { - $navigation = "framename}\" HREF=\"../../course/view.php?id=$course->id\">$course->shortname -> - framename}\" HREF=\"index.php?id=$course->id\">$strsurveys -> - framename}\" HREF=\"view.php?id=$cm->id\">$survey->name -> "; - } else { - $navigation = "framename}\" HREF=\"index.php?id=$course->id\">$strsurveys -> - framename}\" HREF=\"view.php?id=$cm->id\">$survey->name -> "; - } - print_header("$course->shortname: $survey->name", "$course->fullname", "$navigation $strreport"); - break; + print_spacer(30,30); - case "menu": - print_header(); - echo "

$strsummary

"; - echo "

$strscales

"; - echo "

$strquestions

"; - echo "

$course->student:

"; - if ($users = survey_get_responses($survey->id)) { - foreach ($users as $user) { - echo "
  • "; - echo "id&id=$id\">"; - echo "$user->firstname $user->lastname"; - echo "
  • "; - } - } - echo "

    $strdownload

    "; - break; + +/// Print the menu across the top + + switch ($action) { case "summary": - print_header("$survey->name: $strsummary", "$strsummary - $strallscales"); + print_heading($strsummary); if (survey_count_responses($survey->id)) { - echo "

    "; + echo "

    "; survey_print_graph("id=$id&type=overall.png"); - echo ""; + echo ""; } else { - 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 "


    "; } } - print_footer($course); break; case "questions": @@ -138,16 +131,16 @@ if ($scale = get_records("survey_questions", "multi", "$qid")) { $scale = array_pop($scale); - print_header("$survey->name: $strquestions", "$scale->text - $strselectedquestions"); + print_heading("$scale->text - $strselectedquestions"); } else { - print_header("$survey->name: $strquestions", "$strselectedquestions"); + print_heading($strselectedquestions); } } else { // get all top-level questions $questions = get_records_list("survey_questions", "id", $survey->questions); $questionorder = explode(",", $survey->questions); - print_header("$survey->name: $strquestions", "$strallquestions"); + print_heading($strallquestions); } foreach ($questionorder as $key => $val) { @@ -167,38 +160,49 @@ $question->text = get_string($question->text, "survey"); if ($question->multi) { - echo "

    $question->text:

    "; + echo "

    $question->text:

    "; $subquestions = get_records_list("survey_questions", "id", $question->multi); $subquestionorder = explode(",", $question->multi); foreach ($subquestionorder as $key => $val) { $subquestion = $subquestions[$val]; if ($subquestion->type > 0) { - echo "

    "; - echo "id\">"; + echo "

    "; + echo "id\">"; survey_print_graph("id=$id&qid=$subquestion->id&type=question.png"); - echo "

    "; + echo "

    "; } } } else if ($question->type > 0 ) { - echo "

    "; - echo "id\">"; + echo "

    "; + echo "id\">"; survey_print_graph("id=$id&qid=$question->id&type=question.png"); - echo "

    "; + echo "

    "; } else { - echo "

    $question->text:

    "; - if ($aaa = survey_get_user_answers($survey->id, $question->id)) { - echo "