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 |
* Processor file for user exclusion overview and configuration
|
|
|
19 |
*
|
|
|
20 |
* File exclude.php
|
|
|
21 |
* Encoding UTF-8
|
|
|
22 |
*
|
|
|
23 |
* @package tool_usersuspension
|
|
|
24 |
*
|
|
|
25 |
* @copyright Sebsoft.nl
|
|
|
26 |
* @author R.J. van Dongen <rogier@sebsoft.nl>
|
|
|
27 |
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
|
|
28 |
*/
|
|
|
29 |
|
|
|
30 |
require_once(dirname(__FILE__) . '/../../../../config.php');
|
|
|
31 |
require_once($CFG->libdir.'/adminlib.php');
|
|
|
32 |
|
|
|
33 |
use tool_usersuspension\config;
|
|
|
34 |
use tool_usersuspension\processor\csv as csvprocessor;
|
|
|
35 |
|
|
|
36 |
/**
|
|
|
37 |
* Test script message output callback.
|
|
|
38 |
*
|
|
|
39 |
* @param string $msg
|
|
|
40 |
*/
|
|
|
41 |
function trtrace($msg) {
|
|
|
42 |
echo html_writer::div($msg, 'alert alert-info');
|
|
|
43 |
}
|
|
|
44 |
/**
|
|
|
45 |
* Write action links for this script.
|
|
|
46 |
* @param moodle_url|string $pageurl
|
|
|
47 |
*/
|
|
|
48 |
function write_actiontype_links($pageurl) {
|
|
|
49 |
$actiontypes = ['suspend', 'unsuspend'];
|
|
|
50 |
foreach ($actiontypes as $type) {
|
|
|
51 |
echo html_writer::link(new moodle_url($pageurl, ['actiontype' => $type]),
|
|
|
52 |
get_string('testfromfolder:' . $type, 'tool_usersuspension'), []);
|
|
|
53 |
echo '<br/>';
|
|
|
54 |
}
|
|
|
55 |
}
|
|
|
56 |
|
|
|
57 |
admin_externalpage_setup('toolusersuspension');
|
|
|
58 |
$context = \context_system::instance();
|
|
|
59 |
|
|
|
60 |
$thispageurl = new moodle_url('/' . $CFG->admin . '/tool/usersuspension/view/testfromfolder.php', array());
|
|
|
61 |
|
|
|
62 |
require_capability('tool/usersuspension:administration', $context);
|
|
|
63 |
|
|
|
64 |
// Process exclusion?
|
|
|
65 |
$actiontype = optional_param('actiontype', null, PARAM_ALPHA);
|
|
|
66 |
$actiontypes = ['suspend', 'unsuspend'];
|
|
|
67 |
if (!in_array($actiontype, $actiontypes)) {
|
|
|
68 |
echo $OUTPUT->header();
|
|
|
69 |
echo '<div class="tool-usersuspension-container">';
|
|
|
70 |
echo '<div>';
|
|
|
71 |
\tool_usersuspension\util::print_view_tabs(array(), 'testfromfolder');
|
|
|
72 |
echo '</div>';
|
|
|
73 |
write_actiontype_links($thispageurl);
|
|
|
74 |
echo '</div>';
|
|
|
75 |
echo $OUTPUT->footer();
|
|
|
76 |
} else if ($actiontype === 'suspend') {
|
|
|
77 |
echo $OUTPUT->header();
|
|
|
78 |
echo '<div class="tool-usersuspension-container">';
|
|
|
79 |
echo '<div>';
|
|
|
80 |
\tool_usersuspension\util::print_view_tabs(array(), 'testfromfolder');
|
|
|
81 |
echo '</div>';
|
|
|
82 |
write_actiontype_links($thispageurl);
|
|
|
83 |
|
|
|
84 |
echo $OUTPUT->heading(get_string('testing:suspendfromfolder', 'tool_usersuspension'), 4);
|
|
|
85 |
|
|
|
86 |
if (!(bool)config::get('enabled')) {
|
|
|
87 |
echo html_writer::div(get_string('config:tool:disabled', 'tool_usersuspension'), 'alert alert-danger');
|
|
|
88 |
} else {
|
|
|
89 |
echo html_writer::div(get_string('config:tool:enabled', 'tool_usersuspension'), 'alert alert-info');
|
|
|
90 |
}
|
|
|
91 |
|
|
|
92 |
if (!(bool)config::get('enablefromfolder')) {
|
|
|
93 |
echo html_writer::div(get_string('config:fromfolder:disabled', 'tool_usersuspension'), 'alert alert-danger');
|
|
|
94 |
} else {
|
|
|
95 |
echo html_writer::div(get_string('config:fromfolder:enabled', 'tool_usersuspension'), 'alert alert-info');
|
|
|
96 |
}
|
|
|
97 |
|
|
|
98 |
if (is_dir(config::get('uploadfolder'))) {
|
|
|
99 |
echo html_writer::div(get_string('config:uploadfolder:exists', 'tool_usersuspension',
|
|
|
100 |
config::get('uploadfolder')), 'alert alert-info');
|
|
|
101 |
} else {
|
|
|
102 |
echo html_writer::div(get_string('config:uploadfolder:not-exists', 'tool_usersuspension',
|
|
|
103 |
config::get('uploadfolder')), 'alert alert-danger');
|
|
|
104 |
}
|
|
|
105 |
|
|
|
106 |
$uploadedfile = config::get('uploadfolder') . '/' . config::get('uploadfilename');
|
|
|
107 |
if (!file_exists($uploadedfile) || is_dir($uploadedfile)) {
|
|
|
108 |
echo html_writer::div(get_string('config:uploadfile:not-exists', 'tool_usersuspension',
|
|
|
109 |
$uploadedfile), 'alert alert-danger');
|
|
|
110 |
} else {
|
|
|
111 |
echo html_writer::div(get_string('config:uploadfile:exists', 'tool_usersuspension',
|
|
|
112 |
$uploadedfile), 'alert alert-info');
|
|
|
113 |
if (!is_readable($uploadedfile)) {
|
|
|
114 |
echo html_writer::div(get_string('msg:file-not-readable', 'tool_usersuspension',
|
|
|
115 |
$uploadedfile), 'alert alert-danger');
|
|
|
116 |
}
|
|
|
117 |
|
|
|
118 |
$choices = \csv_import_reader::get_delimiter_list();
|
|
|
119 |
// Process uploaded file.
|
|
|
120 |
$proc = new csvprocessor();
|
|
|
121 |
$proc->set_file($uploadedfile);
|
|
|
122 |
$proc->set_delimiter($choices[config::get('csvdelimiter')]);
|
|
|
123 |
$proc->set_enclosure('"');
|
|
|
124 |
$proc->set_notifycallback('trtrace');
|
|
|
125 |
$proc->set_mode(csvprocessor::MODE_SUSPEND);
|
|
|
126 |
$proc->set_testmode();
|
|
|
127 |
$proc->process();
|
|
|
128 |
|
|
|
129 |
if (is_writable($uploadedfile)) {
|
|
|
130 |
echo html_writer::div(get_string('msg:file-would-delete', 'tool_usersuspension',
|
|
|
131 |
$uploadedfile), 'alert alert-success');
|
|
|
132 |
} else {
|
|
|
133 |
echo html_writer::div(get_string('msg:file-not-writeable', 'tool_usersuspension',
|
|
|
134 |
$uploadedfile), 'alert alert-danger');
|
|
|
135 |
}
|
|
|
136 |
}
|
|
|
137 |
echo '</div>';
|
|
|
138 |
echo $OUTPUT->footer();
|
|
|
139 |
} else if ($actiontype === 'unsuspend') {
|
|
|
140 |
echo $OUTPUT->header();
|
|
|
141 |
echo '<div class="tool-usersuspension-container">';
|
|
|
142 |
echo '<div>';
|
|
|
143 |
\tool_usersuspension\util::print_view_tabs(array(), 'testfromfolder');
|
|
|
144 |
echo '</div>';
|
|
|
145 |
write_actiontype_links($thispageurl);
|
|
|
146 |
|
|
|
147 |
echo $OUTPUT->heading(get_string('testing:unsuspendfromfolder', 'tool_usersuspension'), 4);
|
|
|
148 |
|
|
|
149 |
if (!(bool)config::get('enabled')) {
|
|
|
150 |
echo html_writer::div(get_string('config:tool:disabled', 'tool_usersuspension'), 'alert alert-danger');
|
|
|
151 |
} else {
|
|
|
152 |
echo html_writer::div(get_string('config:tool:enabled', 'tool_usersuspension'), 'alert alert-info');
|
|
|
153 |
}
|
|
|
154 |
|
|
|
155 |
if (!(bool)config::get('enableunsuspendfromfolder')) {
|
|
|
156 |
echo html_writer::div(get_string('config:unsuspendfromfolder:disabled', 'tool_usersuspension'), 'alert alert-danger');
|
|
|
157 |
} else {
|
|
|
158 |
echo html_writer::div(get_string('config:unsuspendfromfolder:enabled', 'tool_usersuspension'), 'alert alert-info');
|
|
|
159 |
}
|
|
|
160 |
|
|
|
161 |
if (is_dir(config::get('uploadfolder'))) {
|
|
|
162 |
echo html_writer::div(get_string('config:uploadfolder:exists', 'tool_usersuspension',
|
|
|
163 |
config::get('uploadfolder')), 'alert alert-info');
|
|
|
164 |
} else {
|
|
|
165 |
echo html_writer::div(get_string('config:uploadfolder:not-exists', 'tool_usersuspension',
|
|
|
166 |
config::get('uploadfolder')), 'alert alert-danger');
|
|
|
167 |
}
|
|
|
168 |
|
|
|
169 |
$uploadedfile = config::get('uploadfolder') . '/' . config::get('unsuspenduploadfilename');
|
|
|
170 |
if (!file_exists($uploadedfile) || is_dir($uploadedfile)) {
|
|
|
171 |
echo html_writer::div('CSV File "'.$uploadedfile.'" does not exist', 'alert alert-danger');
|
|
|
172 |
} else {
|
|
|
173 |
echo html_writer::div(get_string('config:uploadfile:exists', 'tool_usersuspension',
|
|
|
174 |
$uploadedfile), 'alert alert-info');
|
|
|
175 |
if (!is_readable($uploadedfile)) {
|
|
|
176 |
echo html_writer::div(get_string('msg:file-not-readable', 'tool_usersuspension',
|
|
|
177 |
$uploadedfile), 'alert alert-danger');
|
|
|
178 |
}
|
|
|
179 |
|
|
|
180 |
$choices = \csv_import_reader::get_delimiter_list();
|
|
|
181 |
// Process uploaded file.
|
|
|
182 |
$proc = new csvprocessor();
|
|
|
183 |
$proc->set_file($uploadedfile);
|
|
|
184 |
$proc->set_delimiter($choices[config::get('csvdelimiter')]);
|
|
|
185 |
$proc->set_enclosure('"');
|
|
|
186 |
$proc->set_notifycallback('trtrace');
|
|
|
187 |
$proc->set_mode(csvprocessor::MODE_UNSUSPEND);
|
|
|
188 |
$proc->set_testmode();
|
|
|
189 |
$proc->process();
|
|
|
190 |
|
|
|
191 |
if (is_writable($uploadedfile)) {
|
|
|
192 |
echo html_writer::div(get_string('msg:file-would-delete', 'tool_usersuspension',
|
|
|
193 |
$uploadedfile), 'alert alert-danger');
|
|
|
194 |
} else {
|
|
|
195 |
echo html_writer::div(get_string('msg:file-not-writeable', 'tool_usersuspension',
|
|
|
196 |
$uploadedfile), 'alert alert-danger');
|
|
|
197 |
}
|
|
|
198 |
}
|
|
|
199 |
echo '</div>';
|
|
|
200 |
echo $OUTPUT->footer();
|
|
|
201 |
}
|