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
 * Adds new or edit instance of enrol_coursecompleted to specified course
19
 *
20
 * @package   enrol_coursecompleted
21
 * @copyright 2017 eWallah (www.eWallah.net)
22
 * @author    Renaat Debleu <info@eWallah.net>
23
 * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
24
 */
25
 
26
require_once("../../config.php");
27
require_once($CFG->dirroot . '/enrol/coursecompleted/classes/plugin.php');
28
global $DB, $OUTPUT, $PAGE;
29
 
30
$enrolid = required_param('enrolid', PARAM_INT);
31
$action = optional_param('action', '', PARAM_RAW);
32
 
33
if ($instance = $DB->get_record('enrol', ['id' => $enrolid, 'enrol' => 'coursecompleted'], '*', MUST_EXIST)) {
34
    $course = get_course($instance->courseid);
35
    $context = \context_course::instance($course->id, MUST_EXIST);
36
}
37
$canenrol = has_capability('enrol/coursecompleted:enrolpast', $context);
38
$canunenrol = has_capability('enrol/coursecompleted:unenrol', $context);
39
 
40
if (!$canenrol && !$canunenrol) {
41
    // No need to invent new error strings here...
42
    require_capability('enrol/manual:enrol', $context);
43
}
44
require_login($course);
45
 
46
$enrol = enrol_get_plugin('coursecompleted');
47
$instancename = $enrol->get_instance_name($instance);
48
 
49
$PAGE->set_url('/enrol/coursecompleted/manage.php', ['enrolid' => $instance->id]);
50
$PAGE->set_pagelayout('admin');
51
$PAGE->set_title($instancename);
52
$PAGE->set_heading($course->fullname);
53
 
54
$timeformat = get_string('strftimedatetimeshort');
55
 
56
echo $OUTPUT->header();
57
echo $OUTPUT->heading(get_string('enrolusers', 'enrol'));
58
 
59
if ($enrolid > 0) {
60
    $br = '<br>';
61
    $current = get_enrolled_users($context, '', 0, 'u.id', 'id', 0, 0, true);
62
    $candidates = enrol_coursecompleted_plugin::get_candidates($instance->customint1);
63
    if ($action === 'enrol') {
64
        require_sesskey();
65
        foreach ($candidates as $candidate) {
66
            if (!isset($current[$candidate])) {
67
                $user = \core_user::get_user($candidate);
68
                if (!empty($user) && !$user->deleted) {
69
                    $enrol->enrol_user($instance, $candidate);
70
                    echo '.';
71
                }
72
            }
73
        }
74
        echo $br . $br . get_string('usersenrolled', 'enrol_coursecompleted', count($candidates));
75
        $url = new \moodle_url('/enrol/instances.php', ['id' => $course->id]);
76
        echo $br . $br . $OUTPUT->continue_button($url);
77
    } else {
78
        $allusers = [];
79
        $cancelurl = new \moodle_url('/enrol/instances.php', ['id' => $instance->courseid]);
80
        foreach ($candidates as $candidate) {
81
            if (!isset($current[$candidate])) {
82
                $user = \core_user::get_user($candidate);
83
                if (!empty($user) && !$user->deleted) {
84
                    $allusers[$candidate] = fullname($user);
85
                }
86
            }
87
        }
88
        if (count($allusers) > 0) {
89
            $link = new \moodle_url($PAGE->url, ['enrolid' => $enrolid, 'action' => 'enrol', 'sesskey' => sesskey()]);
90
            echo $OUTPUT->confirm(
91
                implode(', ', $allusers),
92
                new \single_button($link, get_string('manual:enrol', 'enrol_manual')),
93
                $cancelurl
94
            );
95
        } else {
96
            echo $OUTPUT->box(get_string('nousersfound')) . $br . $OUTPUT->single_button($cancelurl, get_string('cancel'));
97
        }
98
    }
99
}
100
echo $OUTPUT->footer();