MDL-73532 navigation: Secondary navigation for single activity course
[moodle.git] / badges / endorsement.php
blobba9b7396c21d0d2bb7b575fd3efe75fdfbacf5c7
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 $course = get_course($badge->courseid);
48 $heading = format_string($course->fullname, true, ['context' => $context]);
49 $navurl = new moodle_url('/badges/index.php', array('type' => $badge->type, 'id' => $badge->courseid));
50 $PAGE->set_pagelayout('standard');
51 navigation_node::override_active_url($navurl);
52 } else {
53 $PAGE->set_pagelayout('admin');
54 $heading = get_string('administrationsite');
55 navigation_node::override_active_url($navurl, true);
58 $currenturl = new moodle_url('/badges/endorsement.php', array('id' => $badgeid));
59 $PAGE->set_context($context);
60 $PAGE->set_url($currenturl);
61 $PAGE->set_heading($heading);
62 $PAGE->set_title($badge->name);
63 $PAGE->navbar->add($badge->name);
65 $output = $PAGE->get_renderer('core', 'badges');
66 $msg = optional_param('msg', '', PARAM_TEXT);
67 $emsg = optional_param('emsg', '', PARAM_TEXT);
69 if ($msg !== '') {
70 $msg = get_string($msg, 'badges');
73 echo $OUTPUT->header();
75 $actionbar = new \core_badges\output\manage_badge_action_bar($badge, $PAGE);
76 echo $output->render_tertiary_navigation($actionbar);
78 echo $OUTPUT->heading(print_badge_image($badge, $context, 'small') . ' ' . $badge->name);
79 echo $output->print_badge_status_box($badge);
81 $form = new endorsement_form($currenturl, array('badge' => $badge));
82 if ($form->is_cancelled()) {
83 redirect(new moodle_url('/badges/overview.php', array('id' => $badgeid)));
84 } else if ($form->is_submitted() && $form->is_validated() && ($data = $form->get_data())) {
85 $endorsement = new stdClass();
86 $endorsement->badgeid = $badgeid;
87 $endorsement->issuername = $data->issuername;
88 $endorsement->issueremail = $data->issueremail;
89 $endorsement->issuerurl = $data->issuerurl;
90 $endorsement->claimid = $data->claimid;
91 $endorsement->claimcomment = strip_tags($data->claimcomment);
92 $endorsement->dateissued = $data->dateissued;
94 if ($badge->save_endorsement($endorsement)) {
95 $msg = get_string('changessaved');
96 } else {
97 $emsg = get_string('error:save', 'badges');
101 if ($emsg !== '') {
102 echo $OUTPUT->notification($emsg);
104 } else if ($msg !== '') {
105 echo $OUTPUT->notification($msg, 'notifysuccess');
107 echo $output->notification(get_string('noteendorsement', 'badges'), 'info');
108 $form->display();
109 echo $OUTPUT->footer();