Proyectos de Subversion Moodle

Rev

| Ultima modificación | Ver Log |

Rev Autor Línea Nro. Línea
1 efrain 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
 
27
require_once(__DIR__ . '/../config.php');
28
require_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
 
36
require_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.
44
if ($badge->is_active() || $badge->is_locked()) {
45
    redirect($return);
46
}
47
 
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));
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
 
63
if ($delete && has_capability('moodle/badges:configurecriteria', $context)) {
64
    if ($type == BADGE_CRITERIA_TYPE_OVERALL) {
65
        redirect($return, get_string('error:cannotdeletecriterion', 'badges'));
66
    }
67
    if (!$confirm) {
68
        $optionsyes = array('confirm' => 1, 'sesskey' => sesskey(), 'badgeid' => $badgeid, 'delete' => true, 'type' => $type);
69
 
70
        $strdeletecheckfull = get_string('delcritconfirm', 'badges');
71
 
72
        echo $OUTPUT->header();
73
        $formcontinue = new single_button(new moodle_url('/badges/criteria_action.php', $optionsyes), get_string('yes'));
74
        $formcancel = new single_button($return, get_string('no'), 'get');
75
        echo $OUTPUT->confirm($strdeletecheckfull, $formcontinue, $formcancel);
76
        echo $OUTPUT->footer();
77
 
78
        die();
79
    }
80
 
81
    require_sesskey();
82
    if (count($badge->criteria) == 2) {
83
        // Remove overall criterion as well.
84
        $badge->criteria[$type]->delete();
85
        $badge->criteria[BADGE_CRITERIA_TYPE_OVERALL]->delete();
86
    } else {
87
        $badge->criteria[$type]->delete();
88
    }
89
    $return->param('msg', 'criteriadeleted');
90
    redirect($return);
91
}
92
 
93
redirect($return);