Merge branch 'MDL-40255_M25' of git://github.com/lazydaisy/moodle into MOODLE_25_STABLE
[moodle.git] / badges / criteria_action.php
blob74ff62c01c1327a6da07fc373c9c21d6e6751046
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/>.
17 /**
18 * Processing actions with badge criteria.
20 * @package core
21 * @subpackage badges
22 * @copyright 2012 onwards Totara Learning Solutions Ltd {@link http://www.totaralms.com/}
23 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
24 * @author Yuliya Bozhko <yuliya.bozhko@totaralms.com>
27 require_once(dirname(dirname(__FILE__)) . '/config.php');
28 require_once($CFG->libdir . '/badgeslib.php');
30 $badgeid = optional_param('badgeid', 0, PARAM_INT); // Badge ID.
31 $crit = optional_param('crit', 0, PARAM_INT);
32 $type = optional_param('type', 0, PARAM_INT); // Criteria type.
33 $delete = optional_param('delete', 0, PARAM_BOOL);
34 $confirm = optional_param('confirm', 0, PARAM_BOOL);
36 require_login();
38 $return = new moodle_url('/badges/criteria.php', array('id' => $badgeid));
39 $badge = new badge($badgeid);
40 $context = $badge->get_context();
41 $navurl = new moodle_url('/badges/index.php', array('type' => $badge->type));
43 // Make sure that no actions available for locked or active badges.
44 if ($badge->is_active() || $badge->is_locked()) {
45 redirect($return);
48 if ($badge->type == BADGE_TYPE_COURSE) {
49 require_login($badge->courseid);
50 $navurl = new moodle_url('/badges/index.php', array('type' => $badge->type, 'id' => $badge->courseid));
53 $PAGE->set_context($context);
54 $PAGE->set_url('/badges/criteria_action.php');
55 $PAGE->set_pagelayout('standard');
56 $PAGE->set_heading($badge->name);
57 $PAGE->set_title($badge->name);
58 navigation_node::override_active_url($navurl);
60 if ($delete && has_capability('moodle/badges:configurecriteria', $context)) {
61 if (!$confirm) {
62 $optionsyes = array('confirm' => 1, 'sesskey' => sesskey(), 'badgeid' => $badgeid, 'delete' => true, 'type' => $type);
64 $strdeletecheckfull = get_string('delcritconfirm', 'badges');
66 echo $OUTPUT->header();
67 $formcontinue = new single_button(new moodle_url('/badges/criteria_action.php', $optionsyes), get_string('yes'));
68 $formcancel = new single_button($return, get_string('no'), 'get');
69 echo $OUTPUT->confirm($strdeletecheckfull, $formcontinue, $formcancel);
70 echo $OUTPUT->footer();
72 die();
75 require_sesskey();
76 if (count($badge->criteria) == 2) {
77 // Remove overall criterion as well.
78 $badge->criteria[$type]->delete();
79 $badge->criteria[BADGE_CRITERIA_TYPE_OVERALL]->delete();
80 } else {
81 $badge->criteria[$type]->delete();
83 redirect($return);
86 redirect($return);