MDL-68658 phpunit: Ensure that the configured proxy is applied always
[moodle.git] / badges / endorsement.php
blobd7b2345d62abaaf8fd6be06168314ac50575b78c
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 if ($msg !== '') {
67 $msg = get_string($msg, 'badges');
70 echo $OUTPUT->header();
71 echo $OUTPUT->heading(print_badge_image($badge, $context, 'small') . ' ' . $badge->name);
73 echo $output->print_badge_status_box($badge);
74 $output->print_badge_tabs($badgeid, $context, 'bendorsement');
76 $form = new endorsement_form($currenturl, array('badge' => $badge));
77 if ($form->is_cancelled()) {
78 redirect(new moodle_url('/badges/overview.php', array('id' => $badgeid)));
79 } else if ($form->is_submitted() && $form->is_validated() && ($data = $form->get_data())) {
80 $endorsement = new stdClass();
81 $endorsement->badgeid = $badgeid;
82 $endorsement->issuername = $data->issuername;
83 $endorsement->issueremail = $data->issueremail;
84 $endorsement->issuerurl = $data->issuerurl;
85 $endorsement->claimid = $data->claimid;
86 $endorsement->claimcomment = strip_tags($data->claimcomment);
87 $endorsement->dateissued = $data->dateissued;
89 if ($badge->save_endorsement($endorsement)) {
90 $msg = get_string('changessaved');
91 } else {
92 $emsg = get_string('error:save', 'badges');
96 if ($emsg !== '') {
97 echo $OUTPUT->notification($emsg);
99 } else if ($msg !== '') {
100 echo $OUTPUT->notification($msg, 'notifysuccess');
102 echo $output->notification(get_string('noteendorsement', 'badges'), 'info');
103 $form->display();
104 echo $OUTPUT->footer();