MDL-63724 messaging: Prefix field with the table alias
[moodle.git] / badges / endorsement.php
blobec3e145a0f4f820c4cc9f845f14a7fdb7a58eedd
1 <?php
2 // This file is part of Moodle - http://moodle.org/
3 //
4 // Moodle is free software: you can redistribute it and/or modify
5 // it under the terms of the GNU General Public License as published by
6 // the Free Software Foundation, either version 3 of the License, or
7 // (at your option) any later version.
8 //
9 // Moodle is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU General Public License for more details.
14 // You should have received a copy of the GNU General Public License
15 // along with Moodle. If not, see <http://www.gnu.org/licenses/>.
16 /**
17 * Endorsement information
19 * @package core
20 * @subpackage badges
21 * @copyright 2018 Tung Thai
22 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
23 * @author Tung Thai <Tung.ThaiDuc@nashtechglobal.com>
25 require_once(__DIR__ . '/../config.php');
26 require_once($CFG->libdir . '/badgeslib.php');
27 require_once($CFG->dirroot . '/badges/endorsement_form.php');
29 $badgeid = required_param('id', PARAM_INT);
31 require_login();
33 if (empty($CFG->enablebadges)) {
34 print_error('badgesdisabled', 'badges');
37 $badge = new badge($badgeid);
38 $context = $badge->get_context();
39 $navurl = new moodle_url('/badges/index.php', array('type' => $badge->type));
40 require_capability('moodle/badges:configuredetails', $context);
42 if ($badge->type == BADGE_TYPE_COURSE) {
43 if (empty($CFG->badges_allowcoursebadges)) {
44 print_error('coursebadgesdisabled', 'badges');
46 require_login($badge->courseid);
47 $navurl = new moodle_url('/badges/index.php', array('type' => $badge->type, 'id' => $badge->courseid));
48 $PAGE->set_pagelayout('standard');
49 navigation_node::override_active_url($navurl);
50 } else {
51 $PAGE->set_pagelayout('admin');
52 navigation_node::override_active_url($navurl, true);
55 $currenturl = new moodle_url('/badges/endorsement.php', array('id' => $badgeid));
56 $PAGE->set_context($context);
57 $PAGE->set_url($currenturl);
58 $PAGE->set_heading($badge->name);
59 $PAGE->set_title($badge->name);
60 $PAGE->navbar->add($badge->name);
62 $output = $PAGE->get_renderer('core', 'badges');
63 $msg = optional_param('msg', '', PARAM_TEXT);
64 $emsg = optional_param('emsg', '', PARAM_TEXT);
66 echo $OUTPUT->header();
67 echo $OUTPUT->heading(print_badge_image($badge, $context, 'small') . ' ' . $badge->name);
69 echo $output->print_badge_status_box($badge);
70 $output->print_badge_tabs($badgeid, $context, 'bendorsement');
72 $form = new endorsement_form($currenturl, array('badge' => $badge));
73 if ($form->is_cancelled()) {
74 redirect(new moodle_url('/badges/overview.php', array('id' => $badgeid)));
75 } else if ($form->is_submitted() && $form->is_validated() && ($data = $form->get_data())) {
76 $endorsement = new stdClass();
77 $endorsement->badgeid = $badgeid;
78 $endorsement->issuername = $data->issuername;
79 $endorsement->issueremail = $data->issueremail;
80 $endorsement->issuerurl = $data->issuerurl;
81 $endorsement->claimid = $data->claimid;
82 $endorsement->claimcomment = strip_tags($data->claimcomment);
83 $endorsement->dateissued = $data->dateissued;
85 if ($badge->save_endorsement($endorsement)) {
86 $msg = get_string('changessaved');
87 } else {
88 $emsg = get_string('error:save', 'badges');
92 if ($emsg !== '') {
93 echo $OUTPUT->notification($emsg);
95 } else if ($msg !== '') {
96 echo $OUTPUT->notification($msg, 'notifysuccess');
98 echo $output->notification(get_string('noteendorsement', 'badges'), 'info');
99 $form->display();
100 echo $OUTPUT->footer();