course)) {
error("Course is misconfigured");
}
require_login($course->id, false, $cm);
$context = get_context_instance(CONTEXT_MODULE, $cm->id);
require_capability('mod/survey:readresponses', $context);
if (! $survey = get_record("survey", "id", $cm->instance)) {
error("Survey ID was incorrect");
}
if (! $template = get_record("survey", "id", $survey->template)) {
error("Template ID was incorrect");
}
$showscales = ($template->name != 'ciqname');
$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");
$strquestion = get_string("question", "survey");
$strquestions = get_string("questions", "survey");
$strdownload = get_string("download", "survey");
$strallscales = get_string("allscales", "survey");
$strallquestions = get_string("allquestions", "survey");
$strselectedquestions = get_string("selectedquestions", "survey");
$strseemoredetail = get_string("seemoredetail", "survey");
$strnotes = get_string("notes", "survey");
add_to_log($course->id, "survey", "view report", "report.php?id=$cm->id", "$survey->id", $cm->id);
if ($course->id != SITEID) {
$navigation = "id\">$course->shortname ->
id\">$strsurveys ->
id\">".format_string($survey->name,true)." -> ";
} else {
$navigation = "id\">$strsurveys ->
id\">".format_string($survey->name,true)." -> ";
}
$navigation = build_navigation($strreport, $cm);
print_header("$course->shortname: ".format_string($survey->name), $course->fullname, $navigation,
"", "", true,
update_module_button($cm->id, $course->id, $strsurvey), navmenu($course, $cm));
/// Check to see if groups are being used in this survey
if ($groupmode = groups_get_activity_groupmode($cm)) { // Groups are being used
$menuaction = $action == "student" ? "students" : $action;
$currentgroup = groups_get_activity_group($cm, true);
groups_print_activity_menu($cm, $CFG->wwwroot . "/mod/survey/report.php?id=$cm->id&action=$menuaction&qid=$qid");
} else {
$currentgroup = 0;
}
if ($currentgroup) {
$users = groups_get_members($currentgroup);
} else if (!empty($CFG->enablegroupings) && !empty($cm->groupingid)) {
$users = groups_get_grouping_members($cm->groupingid);
} else {
$users = get_course_users($course->id);
}
$groupingid = $cm->groupingid;
print_simple_box_start("center");
if ($showscales) {
echo "$strsummary";
echo " $strscales";
echo " $strquestions";
echo " $course->students";
if (has_capability('mod/survey:download', $context)) {
echo " $strdownload";
}
if (empty($action)) {
$action = "summary";
}
} else {
echo "$strquestions";
echo " $course->students";
if (has_capability('mod/survey:download', $context)) {
echo " $strdownload";
}
if (empty($action)) {
$action = "questions";
}
}
print_simple_box_end();
print_spacer(30,30);
/// Print the menu across the top
$virtualscales = false;
switch ($action) {
case "summary":
print_heading($strsummary);
if (survey_count_responses($survey->id, $currentgroup, $groupingid)) {
echo "
";
} else {
notify(get_string("nobodyyet","survey"));
}
break;
case "scales":
print_heading($strscales);
if (! $results = survey_get_responses($survey->id, $currentgroup, $groupingid) ) {
notify(get_string("nobodyyet","survey"));
} else {
$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 (!empty($virtualscales) && $question->type > 0) { // Don't show non-virtual scales if virtual
continue;
}
echo "multi\">";
survey_print_graph("id=$id&qid=$question->id&group=$currentgroup&type=multiquestion.png");
echo "
";
}
}
}
break;
case "questions":
if ($qid) { // just get one multi-question
$questions = get_records_list("survey_questions", "id", $qid);
$questionorder = explode(",", $qid);
if ($scale = get_records("survey_questions", "multi", "$qid")) {
$scale = array_pop($scale);
print_heading("$scale->text - $strselectedquestions");
} else {
print_heading($strselectedquestions);
}
} else { // get all top-level questions
$questions = get_records_list("survey_questions", "id", $survey->questions);
$questionorder = explode(",", $survey->questions);
print_heading($strallquestions);
}
if (! $results = survey_get_responses($survey->id, $currentgroup, $groupingid) ) {
notify(get_string("nobodyyet","survey"));
} else {
foreach ($questionorder as $key => $val) {
$question = $questions[$val];
if ($question->type < 0) { // We have some virtual scales. DON'T show them.
$virtualscales = true;
break;
}
}
foreach ($questionorder as $key => $val) {
$question = $questions[$val];
if ($question->type < 0) { // We have some virtual scales. DON'T show them.
continue;
}
$question->text = get_string($question->text, "survey");
if ($question->multi) {
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\">";
survey_print_graph("id=$id&qid=$subquestion->id&group=$currentgroup&type=question.png");
echo "
";
}
}
} else if ($question->type > 0 ) {
echo "";
echo "id\">";
survey_print_graph("id=$id&qid=$question->id&group=$currentgroup&type=question.png");
echo "
";
} else {
$table = NULL;
$table->head = array($question->text);
$table->align = array ("left");
$contents = '';
if ($aaa = survey_get_user_answers($survey->id, $question->id, $currentgroup, "sa.time ASC")) {
foreach ($aaa as $a) {
$contents .= "";
$contents .= ''.fullname($a).' | ';
$contents .= ''.$a->answer1.' | ';
$contents .= "
";
}
}
$contents .= "
";
$table->data[] = array($contents);
print_table($table);
print_spacer(30);
}
}
}
break;
case "question":
if (!$question = get_record("survey_questions", "id", $qid)) {
error("Question doesn't exist");
}
$question->text = get_string($question->text, "survey");
$answers = explode(",", get_string($question->options, "survey"));
print_heading("$strquestion: $question->text");
$strname = get_string("name", "survey");
$strtime = get_string("time", "survey");
$stractual = get_string("actual", "survey");
$strpreferred = get_string("preferred", "survey");
$strdateformat = get_string("strftimedatetime");
$table = NULL;
$table->head = array("", $strname, $strtime, $stractual, $strpreferred);
$table->align = array ("left", "left", "left", "left", "right");
$table->size = array (35, "", "", "", "");
if ($aaa = survey_get_user_answers($survey->id, $question->id, $currentgroup)) {
foreach ($aaa as $a) {
if ($a->answer1) {
$answer1 = "$a->answer1 - ".$answers[$a->answer1 - 1];
} else {
$answer1 = " ";
}
if ($a->answer2) {
$answer2 = "$a->answer2 - ".$answers[$a->answer2 - 1];
} else {
$answer2 = " ";
}
$table->data[] = array(
print_user_picture($a->userid, $course->id, $a->picture, false, true, true),
"userid\">".fullname($a)."",
userdate($a->time),
$answer1, $answer2);
}
}
print_table($table);
break;
case "students":
print_heading(get_string("analysisof", "survey", "$course->students"));
if (! $results = survey_get_responses($survey->id, $currentgroup, $groupingid) ) {
notify(get_string("nobodyyet","survey"));
} else {
survey_print_all_responses($cm->id, $results, $course->id);
}
break;
case "student":
if (!$user = get_record("user", "id", $student)) {
error("Student doesn't exist");
}
print_heading(get_string("analysisof", "survey", fullname($user)));
if ($notes != '' and confirm_sesskey()) {
if (survey_get_analysis($survey->id, $user->id)) {
if (! survey_update_analysis($survey->id, $user->id, $notes)) {
notify("An error occurred while saving your notes. Sorry.");
} else {
notify(get_string("savednotes", "survey"));
}
} else {
if (! survey_add_analysis($survey->id, $user->id, $notes)) {
notify("An error occurred while saving your notes. Sorry.");
} else {
notify(get_string("savednotes", "survey"));
}
}
}
echo "";
print_user_picture($user->id, $course->id, $user->picture, true);
echo "
";
$questions = get_records_list("survey_questions", "id", $survey->questions);
$questionorder = explode(",", $survey->questions);
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;
}
}
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;
}
echo "";
echo "multi\">";
survey_print_graph("id=$id&qid=$question->id&sid=$student&type=studentmultiquestion.png");
echo "
";
}
}
}
// Print non-scale questions
foreach ($questionorder as $key => $val) {
$question = $questions[$val];
if ($question->type == 0 or $question->type == 1) {
if ($answer = survey_get_user_answer($survey->id, $question->id, $user->id)) {
$table = NULL;
$table->head = array(get_string($question->text, "survey"));
$table->align = array ("left");
$table->data[] = array(s($answer->answer1)); // no html here, just plain text
print_table($table);
print_spacer(30);
}
}
}
if ($rs = survey_get_analysis($survey->id, $user->id)) {
$notes = $rs->notes;
} else {
$notes = "";
}
echo "
";
echo "";
break;
case "download":
print_heading($strdownload);
require_capability('mod/survey:download', $context);
echo ''.get_string("downloadinfo", "survey").'
';
echo '';
$optons = array();
$options["id"] = "$cm->id";
$options["group"] = $currentgroup;
$options["type"] = "ods";
print_single_button("download.php", $options, get_string("downloadods"));
$options["type"] = "xls";
print_single_button("download.php", $options, get_string("downloadexcel"));
$options["type"] = "txt";
print_single_button("download.php", $options, get_string("downloadtext"));
echo '
';
break;
}
print_footer($course);
?>