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
 * Notificationeabc enrolment plugin.
19
 *
20
 * This plugin notifies users when an event occurs on their enrolments (enrol, unenrol, update enrolment)
21
 *
22
 * @package    enrol_notificationeabc
23
 * @copyright  2017 e-ABC Learning
24
 * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
25
 * @author     Osvaldo Arriola <osvaldo@e-abclearning.com>
26
 */
27
 
28
 
29
require('../../config.php');
30
require_once('edit_form.php');
31
 
32
$courseid = required_param('courseid', PARAM_INT);
33
$instanceid = optional_param('id', 0, PARAM_INT);
34
 
35
$course = $DB->get_record('course', array('id' => $courseid), '*', MUST_EXIST);
36
$context = context_course::instance($course->id, MUST_EXIST);
37
 
38
require_login($course);
39
require_capability('enrol/notificationeabc:manage', $context);
40
 
41
$PAGE->set_url('/enrol/notificationeabc/edit.php', array('courseid' => $course->id, 'id' => $instanceid));
42
$PAGE->set_pagelayout('admin');
43
 
44
$return = new moodle_url('/enrol/instances.php', array('id' => $course->id));
45
if (!enrol_is_enabled('notificationeabc')) {
46
    redirect($return);
47
}
48
 
49
/** @var enrol_notificationeabc_plugin $plugin */
50
$plugin = enrol_get_plugin('notificationeabc');
51
 
52
if ($instanceid) {
53
    $instance = $DB->get_record('enrol',
54
        array(
55
        'courseid' => $course->id,
56
        'enrol' => 'notificationeabc',
57
        'id' => $instanceid
58
    ), '*', MUST_EXIST);
59
 
60
} else {
61
    require_capability('moodle/course:enrolconfig', $context);
62
    // No instance yet, we have to add new instance.
63
    navigation_node::override_active_url(new moodle_url('/enrol/instances.php', array('id' => $course->id)));
64
 
65
    $instance = (object)$plugin->get_instance_defaults();
66
    $instance->id = null;
67
    $instance->courseid = $course->id;
68
    $instance->status = ENROL_INSTANCE_ENABLED; // Do not use default for automatically created instances here.
69
}
70
 
71
 
72
$mform = new enrol_notificationeabc_edit_form(null, array($instance, $plugin, $context));
73
 
74
if ($mform->is_cancelled()) {
75
    redirect($return);
76
 
77
} else if ($data = $mform->get_data()) {
78
    if ($instance->id) {
79
        $reset = ($instance->status != $data->status);
80
 
81
        $instance->status = $data->status;
82
        $instance->name = $data->name;
83
        $instance->customint1 = $data->customint1;
84
        if (isset($data->customint2)) {
85
            $instance->customint2 = $data->customint2;
86
        } else {
87
            $instance->customint2 = 0;
88
        }
89
 
90
        if (isset($data->customint3)) {
91
            $instance->customint3 = $data->customint3;
92
        } else {
93
            $instance->customint3 = 0;
94
        }
95
 
96
        if (isset($data->customint4)) {
97
            $instance->customint4 = $data->customint4;
98
        } else {
99
            $instance->customint4 = 0;
100
        }
101
 
102
        if (isset($data->customint5)) {
103
            $instance->customint5 = $data->customint5;
104
        } else {
105
            $instance->customint5 = 0;
106
        }
107
 
108
        $instance->customtext1 = $data->customtext1['text'];
109
        $instance->customtext2 = $data->customtext2['text'];
110
        $instance->customtext3 = $data->customtext3['text'];
111
        $instance->customchar1 = $data->customchar1;
112
        $instance->customchar2 = $data->customchar2;
113
        $instance->timemodified = time();
114
        $DB->update_record('enrol', $instance);
115
 
116
        if ($reset) {
117
            $context->mark_dirty();
118
        }
119
 
120
    } else {
121
        $fields = array(
122
            'status' => $data->status,
123
            'name' => $data->name,
124
            'customint1' => $data->customint1,
125
            'customint2' => $data->customint2,
126
            'customint3' => $data->customint3,
127
            'customint4' => $data->customint4,
128
            'customint5' => $data->customint5,
129
            'customtext1' => $data->customtext1['text'],
130
            'customtext2' => $data->customtext2['text'],
131
            'customtext3' => $data->customtext3['text'],
132
            'customchar1' => $data->customchar1,
133
            'customchar2' => $data->customchar2);
134
        $plugin->add_instance($course, $fields);
135
    }
136
 
137
    redirect($return);
138
}
139
 
140
$PAGE->set_heading($course->fullname);
141
$PAGE->set_title(get_string('pluginname', 'enrol_notificationeabc'));
142
 
143
echo $OUTPUT->header();
144
echo $OUTPUT->heading(get_string('pluginname', 'enrol_notificationeabc'));
145
$mform->display();
146
echo $OUTPUT->footer();