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 displaying status tables/overviews
|
|
|
19 |
*
|
|
|
20 |
* File statuslist.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 |
|
|
|
32 |
require_once($CFG->libdir . '/adminlib.php');
|
|
|
33 |
require_once($CFG->dirroot . '/user/filters/lib.php');
|
|
|
34 |
ini_set('display_errors', 1);
|
|
|
35 |
error_reporting(E_ALL);
|
|
|
36 |
|
|
|
37 |
admin_externalpage_setup('toolusersuspension');
|
|
|
38 |
$context = \context_system::instance();
|
|
|
39 |
|
|
|
40 |
$viewtype = optional_param('type', \tool_usersuspension\statustable::STATUS, PARAM_ALPHA);
|
|
|
41 |
$thispageurl = new moodle_url('/' . $CFG->admin . '/tool/usersuspension/view/statuslist.php', array('type' => $viewtype));
|
|
|
42 |
require_capability('tool/usersuspension:viewstatus', $context);
|
|
|
43 |
|
|
|
44 |
// Process action?
|
|
|
45 |
$action = optional_param('action', null, PARAM_ALPHA);
|
|
|
46 |
if ($action === 'exclude') {
|
|
|
47 |
require_sesskey();
|
|
|
48 |
$id = required_param('id', PARAM_INT);
|
|
|
49 |
$obj = array('type' => 'user', 'refid' => $id);
|
|
|
50 |
if (!$DB->record_exists('tool_usersuspension_excl', $obj)) {
|
|
|
51 |
$obj['timecreated'] = time();
|
|
|
52 |
$DB->insert_record('tool_usersuspension_excl', (object)$obj);
|
|
|
53 |
$message = get_string('msg:exclusion:record:inserted', 'tool_usersuspension');
|
|
|
54 |
} else {
|
|
|
55 |
$message = get_string('msg:exclusion:record:exists', 'tool_usersuspension');
|
|
|
56 |
}
|
|
|
57 |
redirect($thispageurl, $message, 5);
|
|
|
58 |
} else if ($action === 'suspend') {
|
|
|
59 |
require_sesskey();
|
|
|
60 |
require_capability('moodle/user:update', context_system::instance());
|
|
|
61 |
$id = required_param('id', PARAM_INT);
|
|
|
62 |
$user = $DB->get_record('user', array('id' => $id));
|
|
|
63 |
$result = \tool_usersuspension\util::do_suspend_user($user, false);
|
|
|
64 |
if ($result === true) {
|
|
|
65 |
$message = get_string('msg:user:suspend:success', 'tool_usersuspension', $user);
|
|
|
66 |
} else {
|
|
|
67 |
$message = get_string('msg:user:suspend:failed', 'tool_usersuspension', $user);
|
|
|
68 |
}
|
|
|
69 |
redirect($thispageurl, $message, 5);
|
|
|
70 |
} else if ($action === 'unsuspend') {
|
|
|
71 |
require_sesskey();
|
|
|
72 |
require_capability('moodle/user:update', context_system::instance());
|
|
|
73 |
$id = required_param('id', PARAM_INT);
|
|
|
74 |
$user = $DB->get_record('user', array('id' => $id));
|
|
|
75 |
$result = \tool_usersuspension\util::do_unsuspend_user($user);
|
|
|
76 |
if ($result === true) {
|
|
|
77 |
$message = get_string('msg:user:unsuspend:success', 'tool_usersuspension', $user);
|
|
|
78 |
} else {
|
|
|
79 |
$message = get_string('msg:user:unsuspend:failed', 'tool_usersuspension', $user);
|
|
|
80 |
}
|
|
|
81 |
redirect($thispageurl, $message, 5);
|
|
|
82 |
} else {
|
|
|
83 |
// Prepare specific filter fields and detect whether or not the current view is applicable.
|
|
|
84 |
$viewtypeenabled = true;
|
|
|
85 |
$viewtypenotification = '';
|
|
|
86 |
$fields = ['realname' => 0, 'username' => 0];
|
|
|
87 |
switch ($viewtype) {
|
|
|
88 |
case \tool_usersuspension\statustable::DELETE:
|
|
|
89 |
$fields['deleteon'] = 0;
|
|
|
90 |
$viewtypeenabled = (bool) \tool_usersuspension\config::get('enablecleanup');
|
|
|
91 |
if (!$viewtypeenabled) {
|
|
|
92 |
$viewtypenotification = get_string('config:cleanup:disabled', 'tool_usersuspension');
|
|
|
93 |
$viewtypenotification .= '<br/>'. get_string('configoption:notactive', 'tool_usersuspension');
|
|
|
94 |
}
|
|
|
95 |
break;
|
|
|
96 |
case \tool_usersuspension\statustable::TOSUSPEND:
|
|
|
97 |
$fields['suspendon'] = 0;
|
|
|
98 |
$viewtypeenabled = (bool) \tool_usersuspension\config::get('enablesmartdetect');
|
|
|
99 |
if (!$viewtypeenabled) {
|
|
|
100 |
$viewtypenotification = get_string('config:smartdetect:disabled', 'tool_usersuspension');
|
|
|
101 |
$viewtypenotification .= '<br/>'. get_string('configoption:notactive', 'tool_usersuspension');
|
|
|
102 |
}
|
|
|
103 |
break;
|
|
|
104 |
}
|
|
|
105 |
|
|
|
106 |
$table = new \tool_usersuspension\statustable($viewtype);
|
|
|
107 |
$table->baseurl = $thispageurl;
|
|
|
108 |
$table->is_downloadable(true);
|
|
|
109 |
|
|
|
110 |
$userfiltering = new \tool_usersuspension\statustable_filtering($viewtype, $fields, $table->baseurl);
|
|
|
111 |
$table->set_filtering($userfiltering);
|
|
|
112 |
|
|
|
113 |
$download = optional_param('download', null, PARAM_ALPHA);
|
|
|
114 |
if ($table->is_downloading($download, 'usersuspension-statustable-' . $viewtype, $viewtype)) {
|
|
|
115 |
$table->render(0);
|
|
|
116 |
exit;
|
|
|
117 |
}
|
|
|
118 |
|
|
|
119 |
echo $OUTPUT->header();
|
|
|
120 |
echo '<div class="tool-usersuspension-container">';
|
|
|
121 |
echo '<div>';
|
|
|
122 |
\tool_usersuspension\util::print_view_tabs(array(), $viewtype);
|
|
|
123 |
echo '</div>';
|
|
|
124 |
echo '<div>' . get_string('page:view:statuslist.php:introduction:' . $viewtype, 'tool_usersuspension') . '</div>';
|
|
|
125 |
echo '<div>';
|
|
|
126 |
if (!empty($viewtypenotification)) {
|
|
|
127 |
echo '<div class="alert alert-info">';
|
|
|
128 |
echo $viewtypenotification;
|
|
|
129 |
echo '</div>';
|
|
|
130 |
}
|
|
|
131 |
$userfiltering->display_add();
|
|
|
132 |
$userfiltering->display_active();
|
|
|
133 |
$table->render(25);
|
|
|
134 |
echo '</div>';
|
|
|
135 |
echo '</div>';
|
|
|
136 |
|
|
|
137 |
echo $OUTPUT->footer();
|
|
|
138 |
}
|