2013-05-22 11:37:39 +00:00
|
|
|
<?php
|
|
|
|
// This file is part of the customcert module for Moodle - http://moodle.org/
|
|
|
|
//
|
|
|
|
// Moodle is free software: you can redistribute it and/or modify
|
|
|
|
// it under the terms of the GNU General Public License as published by
|
|
|
|
// the Free Software Foundation, either version 3 of the License, or
|
|
|
|
// (at your option) any later version.
|
|
|
|
//
|
|
|
|
// Moodle is distributed in the hope that it will be useful,
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
// GNU General Public License for more details.
|
|
|
|
//
|
|
|
|
// You should have received a copy of the GNU General Public License
|
|
|
|
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
|
|
|
/**
|
2013-06-05 07:37:52 +00:00
|
|
|
* Handles viewing a report that shows who has received a customcert.
|
2013-05-22 11:37:39 +00:00
|
|
|
*
|
|
|
|
* @package mod_customcert
|
2013-07-22 05:06:18 +00:00
|
|
|
* @copyright 2013 Mark Nelson <markn@moodle.com>
|
2013-05-22 11:37:39 +00:00
|
|
|
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
|
|
|
*/
|
|
|
|
|
|
|
|
require_once('../../config.php');
|
2015-03-11 07:24:51 +00:00
|
|
|
require_once($CFG->dirroot . '/mod/customcert/locallib.php');
|
2013-05-22 11:37:39 +00:00
|
|
|
|
|
|
|
$id = required_param('id', PARAM_INT);
|
|
|
|
$download = optional_param('download', '', PARAM_ALPHA);
|
|
|
|
|
|
|
|
$page = optional_param('page', 0, PARAM_INT);
|
|
|
|
$perpage = optional_param('perpage', CUSTOMCERT_PER_PAGE, PARAM_INT);
|
2013-09-10 07:52:20 +00:00
|
|
|
$pageurl = $url = new moodle_url('/mod/customcert/report.php', array('id' => $id, 'page' => $page, 'perpage' => $perpage));
|
2013-05-22 11:37:39 +00:00
|
|
|
|
|
|
|
// Ensure the perpage variable does not exceed the max allowed if
|
|
|
|
// the user has not specified they wish to view all customcerts.
|
|
|
|
if (CUSTOMCERT_PER_PAGE !== 0) {
|
|
|
|
if (($perpage > CUSTOMCERT_MAX_PER_PAGE) || ($perpage === 0)) {
|
|
|
|
$perpage = CUSTOMCERT_PER_PAGE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
$cm = get_coursemodule_from_id('customcert', $id, 0, false, MUST_EXIST);
|
|
|
|
$course = $DB->get_record('course', array('id' => $cm->course), '*', MUST_EXIST);
|
|
|
|
$customcert = $DB->get_record('customcert', array('id' => $cm->instance), '*', MUST_EXIST);
|
|
|
|
|
|
|
|
// Requires a course login.
|
|
|
|
require_course_login($course->id, false, $cm);
|
|
|
|
|
|
|
|
// Check capabilities.
|
2013-05-28 09:00:07 +00:00
|
|
|
$context = context_module::instance($cm->id);
|
2013-05-22 11:37:39 +00:00
|
|
|
require_capability('mod/customcert:manage', $context);
|
|
|
|
|
|
|
|
// Get the users who have been issued.
|
|
|
|
$users = customcert_get_issues($customcert->id, groups_get_activity_groupmode($cm), $cm, $page, $perpage);
|
|
|
|
|
|
|
|
if ($download) {
|
|
|
|
customcert_generate_report_file($customcert, $users, $download);
|
|
|
|
exit;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Create the table for the users.
|
|
|
|
$table = new html_table();
|
2013-06-05 07:37:52 +00:00
|
|
|
$table->attributes['class'] = 'generaltable centre';
|
|
|
|
$table->attributes['style'] = 'width: 95%;';
|
2013-05-22 11:37:39 +00:00
|
|
|
$table->head = array(get_string('awardedto', 'customcert'), get_string('receiveddate', 'customcert'), get_string('code', 'customcert'));
|
2013-06-05 07:37:52 +00:00
|
|
|
$table->align = array('left', 'left', 'center');
|
2013-05-22 11:37:39 +00:00
|
|
|
foreach ($users as $user) {
|
|
|
|
$name = $OUTPUT->user_picture($user) . fullname($user);
|
|
|
|
$date = userdate($user->timecreated);
|
|
|
|
$code = $user->code;
|
|
|
|
$table->data[] = array($name, $date, $code);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Create table to store buttons.
|
|
|
|
$tablebutton = new html_table();
|
2013-06-05 07:37:52 +00:00
|
|
|
$tablebutton->attributes['class'] = 'centre';
|
2013-05-22 11:37:39 +00:00
|
|
|
$btndownloadods = $OUTPUT->single_button(new moodle_url('report.php', array('id' => $cm->id, 'download' => 'ods')), get_string("downloadods"));
|
|
|
|
$btndownloadxls = $OUTPUT->single_button(new moodle_url('report.php', array('id' => $cm->id, 'download' => 'xls')), get_string("downloadexcel"));
|
|
|
|
$tablebutton->data[] = array($btndownloadods, $btndownloadxls);
|
|
|
|
|
|
|
|
$PAGE->set_url($pageurl);
|
|
|
|
$PAGE->navbar->add(get_string('report', 'customcert'));
|
|
|
|
$PAGE->set_title(format_string($customcert->name) . ": " . get_string('report', 'customcert'));
|
|
|
|
$PAGE->set_heading($course->fullname);
|
|
|
|
|
|
|
|
echo $OUTPUT->header();
|
|
|
|
echo $OUTPUT->heading(get_string('modulenameplural', 'customcert'));
|
|
|
|
groups_print_activity_menu($cm, $url);
|
|
|
|
// If perpage is not set to 0 (displaying all issues), we may need a paging bar.
|
|
|
|
if ($perpage !== 0) {
|
2013-09-10 07:52:20 +00:00
|
|
|
echo $OUTPUT->paging_bar(count((array) $users), $page, $perpage, $url);
|
2013-05-22 11:37:39 +00:00
|
|
|
}
|
|
|
|
echo '<br />';
|
|
|
|
echo html_writer::table($table);
|
|
|
|
echo html_writer::tag('div', html_writer::table($tablebutton), array('style' => 'margin:auto; width:50%'));
|
|
|
|
echo $OUTPUT->footer($course);
|