1434 |
ariadna |
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 |
* Manage module notifications.
|
|
|
19 |
*
|
|
|
20 |
* @package local_moofactory_notification
|
|
|
21 |
* @copyright 2020 Patrick ROCHET <patrick.r@lmsfactory.com>
|
|
|
22 |
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
|
|
23 |
*/
|
|
|
24 |
|
|
|
25 |
require_once("../../config.php");
|
|
|
26 |
require_once('module_form.php');
|
|
|
27 |
|
|
|
28 |
$courseid = optional_param('courseid', 2, PARAM_INT); // Id du cours.
|
|
|
29 |
$id = optional_param('id', 0, PARAM_INT); // Id de l'activité.
|
|
|
30 |
|
|
|
31 |
// Empêcher l'accès pour les utilisateurs invités ou non connectés.
|
|
|
32 |
if (isguestuser() || !isloggedin()) {
|
|
|
33 |
redirect(new moodle_url('/login/index.php'));
|
|
|
34 |
}
|
|
|
35 |
|
|
|
36 |
$returnurl = new moodle_url($CFG->wwwroot . '/course/view.php', array('id' => $courseid));
|
|
|
37 |
$nexturl = new moodle_url($CFG->wwwroot . '/course/view.php', array('id' => $courseid));
|
|
|
38 |
|
|
|
39 |
$mform = new module_form( null, array('courseid' => $courseid, 'id' => $id));
|
|
|
40 |
|
|
|
41 |
if ($mform->is_cancelled()) {
|
|
|
42 |
redirect($returnurl);
|
|
|
43 |
} else if ($fromform = $mform->get_data()) {
|
|
|
44 |
// This branch is where you process validated data.
|
|
|
45 |
// Do stuff ...
|
|
|
46 |
$courseid = $fromform->courseid;
|
|
|
47 |
$id = $fromform->id;
|
|
|
48 |
|
|
|
49 |
$name = 'moduleevents_'.$courseid.'_'.$id;
|
|
|
50 |
if(empty($fromform->$name)){
|
|
|
51 |
$value = "";
|
|
|
52 |
}
|
|
|
53 |
else{
|
|
|
54 |
$value = $fromform->$name;
|
|
|
55 |
}
|
|
|
56 |
set_config($name, $value, 'local_moofactory_notification');
|
|
|
57 |
|
|
|
58 |
$name = 'modulecheckavailability_'.$courseid.'_'.$id;
|
|
|
59 |
if(empty($fromform->$name)){
|
|
|
60 |
$value = "";
|
|
|
61 |
}
|
|
|
62 |
else{
|
|
|
63 |
$value = $fromform->$name;
|
|
|
64 |
}
|
|
|
65 |
set_config($name, $value, 'local_moofactory_notification');
|
|
|
66 |
|
|
|
67 |
$name = 'modulecheckdateavailability_'.$courseid.'_'.$id;
|
|
|
68 |
if(empty($fromform->$name)){
|
|
|
69 |
$value = "";
|
|
|
70 |
}
|
|
|
71 |
else{
|
|
|
72 |
$value = $fromform->$name;
|
|
|
73 |
}
|
|
|
74 |
set_config($name, $value, 'local_moofactory_notification');
|
|
|
75 |
|
|
|
76 |
$name = 'modulecheckgroupavailability_'.$courseid.'_'.$id;
|
|
|
77 |
if(empty($fromform->$name)){
|
|
|
78 |
$value = "";
|
|
|
79 |
}
|
|
|
80 |
else{
|
|
|
81 |
$value = $fromform->$name;
|
|
|
82 |
}
|
|
|
83 |
set_config($name, $value, 'local_moofactory_notification');
|
|
|
84 |
|
|
|
85 |
$name = 'modulenotification_'.$courseid.'_'.$id;
|
|
|
86 |
$value = $fromform->$name;
|
|
|
87 |
set_config($name, $value, 'local_moofactory_notification');
|
|
|
88 |
|
|
|
89 |
$configvars = ['moduledaysbeforeevents1', 'modulehoursbeforeevents1', 'moduledaysbeforeevents2', 'modulehoursbeforeevents2', 'moduledaysbeforeevents3', 'modulehoursbeforeevents3'];
|
|
|
90 |
foreach($configvars as $configvar){
|
|
|
91 |
$name = $configvar.'_'.$courseid.'_'.$id;
|
|
|
92 |
// Si la valeur = '999', on reset avec les valeurs définies dans le cours
|
|
|
93 |
if($fromform->$name != '999'){
|
|
|
94 |
if($fromform->$name == ""){
|
|
|
95 |
$value = "";
|
|
|
96 |
}
|
|
|
97 |
else{
|
|
|
98 |
$value = $fromform->$name;
|
|
|
99 |
}
|
|
|
100 |
set_config($name, $value, 'local_moofactory_notification');
|
|
|
101 |
}
|
|
|
102 |
else{
|
|
|
103 |
unset_config($name, 'local_moofactory_notification');
|
|
|
104 |
}
|
|
|
105 |
}
|
|
|
106 |
|
|
|
107 |
/*********** form notification après levée des restrictions d’accès ************/
|
|
|
108 |
$name = 'modulelevee_'.$courseid.'_'.$id;
|
|
|
109 |
if(empty($fromform->$name)){
|
|
|
110 |
$value = "";
|
|
|
111 |
}
|
|
|
112 |
else{
|
|
|
113 |
$value = $fromform->$name;
|
|
|
114 |
if($value){
|
|
|
115 |
set_config($name . '_date', time(), 'local_moofactory_notification');
|
|
|
116 |
} else {
|
|
|
117 |
unset_config($name . '_date', 'local_moofactory_notification');
|
|
|
118 |
}
|
|
|
119 |
|
|
|
120 |
}
|
|
|
121 |
set_config($name, $value, 'local_moofactory_notification');
|
|
|
122 |
|
|
|
123 |
$name = 'moduleleveenotification_'.$courseid.'_'.$id;
|
|
|
124 |
$value = $fromform->$name;
|
|
|
125 |
set_config($name, $value, 'local_moofactory_notification');
|
|
|
126 |
|
|
|
127 |
$name = 'moduleleveedelai_'.$courseid.'_'.$id;
|
|
|
128 |
if(empty($fromform->$name)){
|
|
|
129 |
$value = "";
|
|
|
130 |
}
|
|
|
131 |
else{
|
|
|
132 |
$value = $fromform->$name;
|
|
|
133 |
}
|
|
|
134 |
set_config($name, $value, 'local_moofactory_notification');
|
|
|
135 |
|
|
|
136 |
$name = 'copiemaillevee_'.$courseid.'_'.$id;
|
|
|
137 |
if(empty($fromform->$name)){
|
|
|
138 |
$value = "";
|
|
|
139 |
}
|
|
|
140 |
else{
|
|
|
141 |
$value = $fromform->$name;
|
|
|
142 |
}
|
|
|
143 |
set_config($name, $value, 'local_moofactory_notification');
|
|
|
144 |
|
|
|
145 |
$configvars = ['moduledaysbeforelevee1', 'modulehoursbeforelevee1', 'moduledaysbeforelevee2', 'modulehoursbeforelevee2', 'moduledaysbeforelevee3', 'modulehoursbeforelevee3'];
|
|
|
146 |
foreach($configvars as $configvar){
|
|
|
147 |
$name = $configvar.'_'.$courseid.'_'.$id;
|
|
|
148 |
|
|
|
149 |
if(empty($fromform->$name)){
|
|
|
150 |
$value = "";
|
|
|
151 |
}
|
|
|
152 |
else{
|
|
|
153 |
$value = $fromform->$name;
|
|
|
154 |
}
|
|
|
155 |
set_config($name, $value, 'local_moofactory_notification');
|
|
|
156 |
}
|
|
|
157 |
// Typically you finish up by redirecting to somewhere where the user
|
|
|
158 |
// can see what they did.
|
|
|
159 |
redirect($nexturl);
|
|
|
160 |
}
|
|
|
161 |
|
|
|
162 |
echo $OUTPUT->header();
|
|
|
163 |
$cm = get_coursemodule_from_id('', $id);
|
|
|
164 |
echo $OUTPUT->heading(get_string('module', 'local_moofactory_notification') . '"' . $cm->name . '"', 2);
|
|
|
165 |
$mform->display();
|
|
|
166 |
|
|
|
167 |
echo $OUTPUT->footer();
|