2009-09-23 06:34:39 +00:00
|
|
|
<?php
|
2001-11-22 06:23:56 +00:00
|
|
|
|
2003-01-05 14:19:20 +00:00
|
|
|
require_once("../../config.php");
|
|
|
|
require_once("lib.php");
|
2001-11-22 06:23:56 +00:00
|
|
|
|
2008-10-31 00:53:28 +00:00
|
|
|
$id = required_param('id', PARAM_INT); //moduleid
|
|
|
|
$format = optional_param('format', CHOICE_PUBLISH_NAMES, PARAM_INT);
|
|
|
|
$download = optional_param('download', '', PARAM_ALPHA);
|
|
|
|
$action = optional_param('action', '', PARAM_ALPHA);
|
2011-08-17 16:27:15 +02:00
|
|
|
$attemptids = optional_param_array('attemptid', array(), PARAM_INT); //get array of responses to delete.
|
2005-03-30 18:17:58 +00:00
|
|
|
|
2010-01-16 15:39:56 +00:00
|
|
|
$url = new moodle_url('/mod/choice/report.php', array('id'=>$id));
|
2009-09-23 06:34:39 +00:00
|
|
|
if ($format !== CHOICE_PUBLISH_NAMES) {
|
|
|
|
$url->param('format', $format);
|
|
|
|
}
|
|
|
|
if ($download !== '') {
|
|
|
|
$url->param('download', $download);
|
|
|
|
}
|
|
|
|
if ($action !== '') {
|
|
|
|
$url->param('action', $action);
|
|
|
|
}
|
|
|
|
$PAGE->set_url($url);
|
|
|
|
|
2006-08-08 22:09:55 +00:00
|
|
|
if (! $cm = get_coursemodule_from_id('choice', $id)) {
|
2008-05-23 07:03:17 +00:00
|
|
|
print_error("invalidcoursemodule");
|
2001-11-22 06:23:56 +00:00
|
|
|
}
|
|
|
|
|
2008-06-04 06:42:54 +00:00
|
|
|
if (! $course = $DB->get_record("course", array("id" => $cm->course))) {
|
2008-05-23 07:03:17 +00:00
|
|
|
print_error("coursemisconf");
|
2001-11-22 06:23:56 +00:00
|
|
|
}
|
|
|
|
|
2012-04-22 17:41:47 +02:00
|
|
|
require_login($course, false, $cm);
|
2008-06-04 06:42:54 +00:00
|
|
|
|
2012-07-26 14:57:34 +08:00
|
|
|
$context = context_module::instance($cm->id);
|
2008-06-04 06:42:54 +00:00
|
|
|
|
2006-08-14 05:55:40 +00:00
|
|
|
require_capability('mod/choice:readresponses', $context);
|
2008-06-04 06:42:54 +00:00
|
|
|
|
2002-09-08 09:42:07 +00:00
|
|
|
if (!$choice = choice_get_choice($cm->instance)) {
|
2008-05-23 07:03:17 +00:00
|
|
|
print_error('invalidcoursemodule');
|
2001-11-22 06:23:56 +00:00
|
|
|
}
|
|
|
|
|
2002-08-12 08:28:04 +00:00
|
|
|
$strchoice = get_string("modulename", "choice");
|
|
|
|
$strchoices = get_string("modulenameplural", "choice");
|
|
|
|
$strresponses = get_string("responses", "choice");
|
|
|
|
|
2005-04-10 16:55:32 +00:00
|
|
|
add_to_log($course->id, "choice", "report", "report.php?id=$cm->id", "$choice->id",$cm->id);
|
2008-06-04 06:42:54 +00:00
|
|
|
|
2009-11-22 11:09:11 +00:00
|
|
|
if (data_submitted() && $action == 'delete' && has_capability('mod/choice:deleteresponses',$context) && confirm_sesskey()) {
|
2010-10-14 14:58:43 +00:00
|
|
|
choice_delete_responses($attemptids, $choice, $cm, $course); //delete responses.
|
2008-03-03 04:42:01 +00:00
|
|
|
redirect("report.php?id=$cm->id");
|
2006-02-23 01:20:24 +00:00
|
|
|
}
|
2008-06-04 06:42:54 +00:00
|
|
|
|
2007-07-05 04:40:48 +00:00
|
|
|
if (!$download) {
|
2009-09-08 02:05:11 +00:00
|
|
|
$PAGE->navbar->add($strresponses);
|
|
|
|
$PAGE->set_title(format_string($choice->name).": $strresponses");
|
2010-07-05 22:42:46 +00:00
|
|
|
$PAGE->set_heading($course->fullname);
|
2009-09-08 02:05:11 +00:00
|
|
|
echo $OUTPUT->header();
|
2007-07-05 04:40:48 +00:00
|
|
|
/// Check to see if groups are being used in this choice
|
2007-08-27 21:52:35 +00:00
|
|
|
$groupmode = groups_get_activity_groupmode($cm);
|
2008-10-31 00:53:28 +00:00
|
|
|
if ($groupmode) {
|
|
|
|
groups_get_activity_group($cm, true);
|
2009-11-30 17:12:48 +00:00
|
|
|
groups_print_activity_menu($cm, $CFG->wwwroot . '/mod/choice/report.php?id='.$id);
|
2008-10-31 00:53:28 +00:00
|
|
|
}
|
2007-07-05 04:40:48 +00:00
|
|
|
} else {
|
2007-08-27 21:52:35 +00:00
|
|
|
$groupmode = groups_get_activity_groupmode($cm);
|
2001-11-22 06:23:56 +00:00
|
|
|
}
|
2008-03-03 04:42:01 +00:00
|
|
|
$users = choice_get_response_data($choice, $cm, $groupmode);
|
2006-12-21 19:46:29 +00:00
|
|
|
|
|
|
|
if ($download == "ods" && has_capability('mod/choice:downloadresponses', $context)) {
|
|
|
|
require_once("$CFG->libdir/odslib.class.php");
|
2008-06-04 06:42:54 +00:00
|
|
|
|
|
|
|
/// Calculate file name
|
2006-12-21 19:46:29 +00:00
|
|
|
$filename = clean_filename("$course->shortname ".strip_tags(format_string($choice->name,true))).'.ods';
|
|
|
|
/// Creating a workbook
|
|
|
|
$workbook = new MoodleODSWorkbook("-");
|
|
|
|
/// Send HTTP headers
|
|
|
|
$workbook->send($filename);
|
|
|
|
/// Creating the first worksheet
|
2012-12-15 12:36:40 +01:00
|
|
|
$myxls = $workbook->add_worksheet($strresponses);
|
2006-12-21 19:46:29 +00:00
|
|
|
|
|
|
|
/// Print names of all the fields
|
|
|
|
$myxls->write_string(0,0,get_string("lastname"));
|
|
|
|
$myxls->write_string(0,1,get_string("firstname"));
|
|
|
|
$myxls->write_string(0,2,get_string("idnumber"));
|
|
|
|
$myxls->write_string(0,3,get_string("group"));
|
|
|
|
$myxls->write_string(0,4,get_string("choice","choice"));
|
2008-03-03 04:42:01 +00:00
|
|
|
|
2006-12-21 19:46:29 +00:00
|
|
|
/// generate the data for the body of the spreadsheet
|
2008-06-04 06:42:54 +00:00
|
|
|
$i=0;
|
2006-12-21 19:46:29 +00:00
|
|
|
$row=1;
|
|
|
|
if ($users) {
|
2008-03-03 04:42:01 +00:00
|
|
|
foreach ($users as $option => $userid) {
|
|
|
|
$option_text = choice_get_option_text($choice, $option);
|
|
|
|
foreach($userid as $user) {
|
|
|
|
$myxls->write_string($row,0,$user->lastname);
|
|
|
|
$myxls->write_string($row,1,$user->firstname);
|
|
|
|
$studentid=(!empty($user->idnumber) ? $user->idnumber : " ");
|
|
|
|
$myxls->write_string($row,2,$studentid);
|
|
|
|
$ug2 = '';
|
|
|
|
if ($usergrps = groups_get_all_groups($course->id, $user->id)) {
|
|
|
|
foreach ($usergrps as $ug) {
|
|
|
|
$ug2 = $ug2. $ug->name;
|
2006-12-21 19:46:29 +00:00
|
|
|
}
|
|
|
|
}
|
2008-03-03 04:42:01 +00:00
|
|
|
$myxls->write_string($row,3,$ug2);
|
|
|
|
|
|
|
|
if (isset($option_text)) {
|
2008-06-04 06:42:54 +00:00
|
|
|
$myxls->write_string($row,4,format_string($option_text,true));
|
2008-03-03 04:42:01 +00:00
|
|
|
}
|
|
|
|
$row++;
|
2006-12-21 19:46:29 +00:00
|
|
|
$pos=4;
|
|
|
|
}
|
|
|
|
}
|
2008-03-03 04:42:01 +00:00
|
|
|
}
|
|
|
|
/// Close the workbook
|
|
|
|
$workbook->close();
|
2006-12-21 19:46:29 +00:00
|
|
|
|
2008-03-03 04:42:01 +00:00
|
|
|
exit;
|
2006-12-21 19:46:29 +00:00
|
|
|
}
|
|
|
|
|
2005-04-11 22:59:32 +00:00
|
|
|
//print spreadsheet if one is asked for:
|
2006-08-14 05:55:40 +00:00
|
|
|
if ($download == "xls" && has_capability('mod/choice:downloadresponses', $context)) {
|
2006-01-05 16:33:29 +00:00
|
|
|
require_once("$CFG->libdir/excellib.class.php");
|
2008-06-04 06:42:54 +00:00
|
|
|
|
|
|
|
/// Calculate file name
|
2006-01-05 16:33:29 +00:00
|
|
|
$filename = clean_filename("$course->shortname ".strip_tags(format_string($choice->name,true))).'.xls';
|
|
|
|
/// Creating a workbook
|
|
|
|
$workbook = new MoodleExcelWorkbook("-");
|
|
|
|
/// Send HTTP headers
|
|
|
|
$workbook->send($filename);
|
|
|
|
/// Creating the first worksheet
|
2012-12-15 12:36:40 +01:00
|
|
|
$myxls = $workbook->add_worksheet($strresponses);
|
2005-04-11 22:59:32 +00:00
|
|
|
|
2006-01-05 16:33:29 +00:00
|
|
|
/// Print names of all the fields
|
2005-04-11 22:59:32 +00:00
|
|
|
$myxls->write_string(0,0,get_string("lastname"));
|
|
|
|
$myxls->write_string(0,1,get_string("firstname"));
|
|
|
|
$myxls->write_string(0,2,get_string("idnumber"));
|
2006-02-23 01:20:24 +00:00
|
|
|
$myxls->write_string(0,3,get_string("group"));
|
|
|
|
$myxls->write_string(0,4,get_string("choice","choice"));
|
2008-06-04 06:42:54 +00:00
|
|
|
|
|
|
|
|
2005-04-11 22:59:32 +00:00
|
|
|
/// generate the data for the body of the spreadsheet
|
2008-06-04 06:42:54 +00:00
|
|
|
$i=0;
|
2006-01-05 16:33:29 +00:00
|
|
|
$row=1;
|
|
|
|
if ($users) {
|
2008-03-03 04:42:01 +00:00
|
|
|
foreach ($users as $option => $userid) {
|
|
|
|
$option_text = choice_get_option_text($choice, $option);
|
|
|
|
foreach($userid as $user) {
|
|
|
|
$myxls->write_string($row,0,$user->lastname);
|
|
|
|
$myxls->write_string($row,1,$user->firstname);
|
|
|
|
$studentid=(!empty($user->idnumber) ? $user->idnumber : " ");
|
|
|
|
$myxls->write_string($row,2,$studentid);
|
|
|
|
$ug2 = '';
|
|
|
|
if ($usergrps = groups_get_all_groups($course->id, $user->id)) {
|
|
|
|
foreach ($usergrps as $ug) {
|
|
|
|
$ug2 = $ug2. $ug->name;
|
2006-08-09 13:45:49 +00:00
|
|
|
}
|
2006-09-11 07:17:10 +00:00
|
|
|
}
|
2008-03-03 04:42:01 +00:00
|
|
|
$myxls->write_string($row,3,$ug2);
|
|
|
|
if (isset($option_text)) {
|
|
|
|
$myxls->write_string($row,4,format_string($option_text,true));
|
|
|
|
}
|
|
|
|
$row++;
|
2006-01-05 16:33:29 +00:00
|
|
|
}
|
|
|
|
}
|
2008-03-03 04:42:01 +00:00
|
|
|
$pos=4;
|
|
|
|
}
|
|
|
|
/// Close the workbook
|
|
|
|
$workbook->close();
|
|
|
|
exit;
|
2006-09-11 07:17:10 +00:00
|
|
|
}
|
2008-03-03 04:42:01 +00:00
|
|
|
|
2008-06-04 06:42:54 +00:00
|
|
|
// print text file
|
2006-08-14 05:55:40 +00:00
|
|
|
if ($download == "txt" && has_capability('mod/choice:downloadresponses', $context)) {
|
2005-04-14 19:00:23 +00:00
|
|
|
$filename = clean_filename("$course->shortname ".strip_tags(format_string($choice->name,true))).'.txt';
|
2006-08-14 05:55:40 +00:00
|
|
|
|
|
|
|
header("Content-Type: application/download\n");
|
|
|
|
header("Content-Disposition: attachment; filename=\"$filename\"");
|
|
|
|
header("Expires: 0");
|
|
|
|
header("Cache-Control: must-revalidate,post-check=0,pre-check=0");
|
|
|
|
header("Pragma: public");
|
|
|
|
|
|
|
|
/// Print names of all the fields
|
2005-04-11 22:59:32 +00:00
|
|
|
|
|
|
|
echo get_string("firstname")."\t".get_string("lastname") . "\t". get_string("idnumber") . "\t";
|
2006-02-23 01:20:24 +00:00
|
|
|
echo get_string("group"). "\t";
|
2008-06-04 06:42:54 +00:00
|
|
|
echo get_string("choice","choice"). "\n";
|
2006-08-14 05:55:40 +00:00
|
|
|
|
|
|
|
/// generate the data for the body of the spreadsheet
|
2008-06-04 06:42:54 +00:00
|
|
|
$i=0;
|
2008-03-03 04:42:01 +00:00
|
|
|
if ($users) {
|
|
|
|
foreach ($users as $option => $userid) {
|
|
|
|
$option_text = choice_get_option_text($choice, $option);
|
|
|
|
foreach($userid as $user) {
|
|
|
|
echo $user->lastname;
|
|
|
|
echo "\t".$user->firstname;
|
|
|
|
$studentid = " ";
|
|
|
|
if (!empty($user->idnumber)) {
|
|
|
|
$studentid = $user->idnumber;
|
|
|
|
}
|
|
|
|
echo "\t". $studentid."\t";
|
|
|
|
$ug2 = '';
|
|
|
|
if ($usergrps = groups_get_all_groups($course->id, $user->id)) {
|
|
|
|
foreach ($usergrps as $ug) {
|
|
|
|
$ug2 = $ug2. $ug->name;
|
|
|
|
}
|
2006-08-14 05:55:40 +00:00
|
|
|
}
|
2008-03-03 04:42:01 +00:00
|
|
|
echo $ug2. "\t";
|
|
|
|
if (isset($option_text)) {
|
|
|
|
echo format_string($option_text,true);
|
|
|
|
}
|
|
|
|
echo "\n";
|
2006-08-14 05:55:40 +00:00
|
|
|
}
|
|
|
|
}
|
2008-03-03 04:42:01 +00:00
|
|
|
}
|
2006-08-14 05:55:40 +00:00
|
|
|
exit;
|
|
|
|
}
|
2012-01-25 20:03:11 +13:00
|
|
|
// Show those who haven't answered the question.
|
|
|
|
if (!empty($choice->showunanswered)) {
|
|
|
|
$choice->option[0] = get_string('notanswered', 'choice');
|
|
|
|
$choice->maxanswers[0] = 0;
|
|
|
|
}
|
2006-08-14 05:55:40 +00:00
|
|
|
|
2010-07-23 03:55:06 +00:00
|
|
|
$results = prepare_choice_show_results($choice, $course, $cm, $users);
|
|
|
|
$renderer = $PAGE->get_renderer('mod_choice');
|
|
|
|
echo $renderer->display_result($results, has_capability('mod/choice:readresponses', $context));
|
2011-08-17 16:27:15 +02:00
|
|
|
|
2008-06-04 06:42:54 +00:00
|
|
|
//now give links for downloading spreadsheets.
|
2009-02-09 09:19:47 +00:00
|
|
|
if (!empty($users) && has_capability('mod/choice:downloadresponses',$context)) {
|
2010-07-23 03:55:06 +00:00
|
|
|
$downloadoptions = array();
|
2008-05-22 10:13:55 +00:00
|
|
|
$options = array();
|
2008-06-04 06:42:54 +00:00
|
|
|
$options["id"] = "$cm->id";
|
2008-05-22 10:13:55 +00:00
|
|
|
$options["download"] = "ods";
|
2010-07-23 03:55:06 +00:00
|
|
|
$button = $OUTPUT->single_button(new moodle_url("report.php", $options), get_string("downloadods"));
|
|
|
|
$downloadoptions[] = html_writer::tag('li', $button, array('class'=>'reportoption'));
|
|
|
|
|
2008-05-22 10:13:55 +00:00
|
|
|
$options["download"] = "xls";
|
2010-10-13 09:00:31 +00:00
|
|
|
$button = $OUTPUT->single_button(new moodle_url("report.php", $options), get_string("downloadexcel"));
|
2010-07-23 03:55:06 +00:00
|
|
|
$downloadoptions[] = html_writer::tag('li', $button, array('class'=>'reportoption'));
|
|
|
|
|
2008-06-04 06:42:54 +00:00
|
|
|
$options["download"] = "txt";
|
2010-07-23 03:55:06 +00:00
|
|
|
$button = $OUTPUT->single_button(new moodle_url("report.php", $options), get_string("downloadtext"));
|
|
|
|
$downloadoptions[] = html_writer::tag('li', $button, array('class'=>'reportoption'));
|
2008-05-22 10:13:55 +00:00
|
|
|
|
2010-07-23 03:55:06 +00:00
|
|
|
$downloadlist = html_writer::tag('ul', implode('', $downloadoptions));
|
|
|
|
$downloadlist .= html_writer::tag('div', '', array('class'=>'clearfloat'));
|
|
|
|
echo html_writer::tag('div',$downloadlist, array('class'=>'downloadreport'));
|
2008-05-22 10:13:55 +00:00
|
|
|
}
|
2009-08-06 14:20:08 +00:00
|
|
|
echo $OUTPUT->footer();
|
2005-02-16 10:40:48 +00:00
|
|
|
|