From aeedbaeb6c3b15fd79c9f607c9418c4cbd21e06e Mon Sep 17 00:00:00 2001 From: higinovieira Date: Wed, 3 Aug 2016 17:14:30 -0300 Subject: [PATCH] Hack review.php to reprint certificates without course access --- index.php | 5 ++- review.php | 104 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 106 insertions(+), 3 deletions(-) create mode 100644 review.php diff --git a/index.php b/index.php index 3e01fe1..8e9acde 100644 --- a/index.php +++ b/index.php @@ -4,7 +4,7 @@ require_once("../../config.php"); global $DB; // Prepare page -$context = get_context_instance(CONTEXT_SYSTEM); +$context = context_system::instance(); // get_context_instance(CONTEXT_SYSTEM); $PAGE->set_pagelayout('standard'); $PAGE->set_url('/blocks/get_certificate/index.php'); $PAGE->set_context($context); @@ -27,8 +27,7 @@ foreach ($issues as $issue) { $certificate = $DB->get_record('certificate', array('id' => $issue->certificateid)); $course = $DB->get_record('course', array('id' => $certificate->course)); $cm = get_coursemodule_from_instance('certificate', $certificate->id); -// $link = html_writer::link(new moodle_url('/mod/certificate/review.php', array('id'=>$cm->id, 'action'=>'get')), $icon); - $url = new moodle_url('/mod/certificate/review.php', array('id'=>$cm->id, 'action'=>'get')); + $url = new moodle_url('/blocks/get_certificate/review.php', array('id'=>$cm->id, 'action'=>'get')); $action = new popup_action('click', $url, 'view'.$cm->id, array('height' => 600, 'width' => 800)); $link = new action_link($url, $icon, $action); $line = array($issue->code, userdate($issue->timecreated), $course->fullname, $OUTPUT->render($link)); diff --git a/review.php b/review.php new file mode 100644 index 0000000..9792cc2 --- /dev/null +++ b/review.php @@ -0,0 +1,104 @@ +. + +/** + * This page reviews a certificate + * + * @package mod_certificate + * @copyright Mark Nelson + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ + +require_once('../../config.php'); +require_once("$CFG->dirroot/mod/certificate/locallib.php"); +require_once("$CFG->libdir/pdflib.php"); + +// Retrieve any variables that are passed +$id = required_param('id', PARAM_INT); // Course Module ID +$action = optional_param('action', '', PARAM_ALPHA); + +if (!$cm = get_coursemodule_from_id('certificate', $id)) { + print_error('Course Module ID was incorrect'); +} + +if (!$course = $DB->get_record('course', array('id'=> $cm->course))) { + print_error('course is misconfigured'); +} + +if (!$certificate = $DB->get_record('certificate', array('id'=> $cm->instance))) { + print_error('course module is incorrect'); +} + +// Requires just system login +require_login(); + +// Check the capabilities +$context = context_module::instance($cm->id); +require_capability('mod/certificate:view', $context); + +// Initialize $PAGE, compute blocks +$PAGE->set_url('/blocks/get_certificate/review.php', array('id' => $cm->id)); +$PAGE->set_context($context); +$PAGE->set_cm($cm); +$PAGE->set_title(format_string($certificate->name)); +$PAGE->set_heading(format_string($course->fullname)); + +// Get previous cert record +if (!$certrecord = $DB->get_record('certificate_issues', array('userid' => $USER->id, 'certificateid' => $certificate->id))) { + notice(get_string('nocertificatesissued', 'certificate'), "$CFG->wwwroot/course/view.php?id=$course->id"); + die; +} + +// Load the specific certificatetype +require ("$CFG->dirroot/mod/certificate/type/$certificate->certificatetype/certificate.php"); + +if ($action) { + $filename = certificate_get_certificate_filename($certificate, $cm, $course) . '.pdf'; + $filecontents = $pdf->Output('', 'S'); + // Open in browser. + send_file($filecontents, $filename, 0, 0, true, false, 'application/pdf'); + exit(); +} + +echo $OUTPUT->header(); + +$reviewurl = new moodle_url('/blocks/get_certificate/review.php', array('id' => $cm->id)); +groups_print_activity_menu($cm, $reviewurl); +$currentgroup = groups_get_activity_group($cm); +$groupmode = groups_get_activity_groupmode($cm); + +if (has_capability('mod/certificate:manage', $context)) { + $numusers = count(certificate_get_issues($certificate->id, 'ci.timecreated ASC', $groupmode, $cm)); + $url = html_writer::tag('a', get_string('viewcertificateviews', 'certificate', $numusers), + array('href' => $CFG->wwwroot . '/mod/certificate/report.php?id=' . $cm->id)); + echo html_writer::tag('div', $url, array('class' => 'reportlink')); +} + +if (!empty($certificate->intro)) { + echo $OUTPUT->box(format_module_intro('certificate', $certificate, $cm->id), 'generalbox', 'intro'); +} + +echo html_writer::tag('p', get_string('viewed', 'certificate'). '
' . userdate($certrecord->timecreated), array('style' => 'text-align:center')); + +$link = new moodle_url('/blocks/get_certificate/review.php?id='.$cm->id.'&action=get'); +$linkname = get_string('reviewcertificate', 'certificate'); +$button = new single_button($link, $linkname); +$button->add_action(new popup_action('click', $link, array('height' => 600, 'width' => 800))); + +echo html_writer::tag('div', $OUTPUT->render($button), array('style' => 'text-align:center')); + +echo $OUTPUT->footer($course);