source: moodle/trunk/fuentes/badges/criteria_action.php @ 136

Last change on this file since 136 was 136, checked in by mabarracus, 3 years ago

Ported code to xenial

File size: 3.3 KB
Line 
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.
13//
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/**
18 * Processing actions with badge criteria.
19 *
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>
25 */
26
27require_once(dirname(dirname(__FILE__)) . '/config.php');
28require_once($CFG->libdir . '/badgeslib.php');
29
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);
35
36require_login();
37
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));
42
43// Make sure that no actions available for locked or active badges.
44if ($badge->is_active() || $badge->is_locked()) {
45    redirect($return);
46}
47
48if ($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));
51    $PAGE->set_pagelayout('standard');
52    navigation_node::override_active_url($navurl);
53} else {
54    $PAGE->set_pagelayout('admin');
55    navigation_node::override_active_url($navurl, true);
56}
57
58$PAGE->set_context($context);
59$PAGE->set_url('/badges/criteria_action.php');
60$PAGE->set_heading($badge->name);
61$PAGE->set_title($badge->name);
62
63if ($delete && has_capability('moodle/badges:configurecriteria', $context)) {
64    if (!$confirm) {
65        $optionsyes = array('confirm' => 1, 'sesskey' => sesskey(), 'badgeid' => $badgeid, 'delete' => true, 'type' => $type);
66
67        $strdeletecheckfull = get_string('delcritconfirm', 'badges');
68
69        echo $OUTPUT->header();
70        $formcontinue = new single_button(new moodle_url('/badges/criteria_action.php', $optionsyes), get_string('yes'));
71        $formcancel = new single_button($return, get_string('no'), 'get');
72        echo $OUTPUT->confirm($strdeletecheckfull, $formcontinue, $formcancel);
73        echo $OUTPUT->footer();
74
75        die();
76    }
77
78    require_sesskey();
79    if (count($badge->criteria) == 2) {
80        // Remove overall criterion as well.
81        $badge->criteria[$type]->delete();
82        $badge->criteria[BADGE_CRITERIA_TYPE_OVERALL]->delete();
83    } else {
84        $badge->criteria[$type]->delete();
85    }
86    $return->param('msg', 'criteriadeleted');
87    redirect($return);
88}
89
90redirect($return);
Note: See TracBrowser for help on using the repository browser.