1 |
efrain |
1 |
<?php
|
|
|
2 |
|
|
|
3 |
require_once('../config.php');
|
|
|
4 |
require_once($CFG->libdir.'/adminlib.php');
|
|
|
5 |
require_once($CFG->libdir.'/authlib.php');
|
|
|
6 |
require_once($CFG->dirroot.'/user/lib.php');
|
|
|
7 |
require_once($CFG->dirroot.'/'.$CFG->admin.'/user/user_bulk_forms.php');
|
|
|
8 |
|
|
|
9 |
$delete = optional_param('delete', 0, PARAM_INT);
|
|
|
10 |
$confirm = optional_param('confirm', '', PARAM_ALPHANUM); //md5 confirmation hash
|
|
|
11 |
$confirmuser = optional_param('confirmuser', 0, PARAM_INT);
|
|
|
12 |
$acl = optional_param('acl', '0', PARAM_INT); // id of user to tweak mnet ACL (requires $access)
|
|
|
13 |
$suspend = optional_param('suspend', 0, PARAM_INT);
|
|
|
14 |
$unsuspend = optional_param('unsuspend', 0, PARAM_INT);
|
|
|
15 |
$unlock = optional_param('unlock', 0, PARAM_INT);
|
|
|
16 |
$resendemail = optional_param('resendemail', 0, PARAM_INT);
|
|
|
17 |
|
|
|
18 |
admin_externalpage_setup('editusers');
|
|
|
19 |
|
|
|
20 |
$sitecontext = context_system::instance();
|
|
|
21 |
$site = get_site();
|
|
|
22 |
|
|
|
23 |
$returnurl = new moodle_url('/admin/user.php');
|
|
|
24 |
|
|
|
25 |
$PAGE->set_primary_active_tab('siteadminnode');
|
|
|
26 |
$PAGE->navbar->add(get_string('userlist', 'admin'), $PAGE->url);
|
|
|
27 |
|
|
|
28 |
// The $user variable is also used outside of these if statements.
|
|
|
29 |
$user = null;
|
|
|
30 |
if ($confirmuser and confirm_sesskey()) {
|
|
|
31 |
require_capability('moodle/user:update', $sitecontext);
|
|
|
32 |
if (!$user = $DB->get_record('user', array('id'=>$confirmuser, 'mnethostid'=>$CFG->mnet_localhost_id))) {
|
|
|
33 |
throw new \moodle_exception('nousers');
|
|
|
34 |
}
|
|
|
35 |
|
|
|
36 |
$auth = get_auth_plugin($user->auth);
|
|
|
37 |
|
|
|
38 |
$result = $auth->user_confirm($user->username, $user->secret);
|
|
|
39 |
|
|
|
40 |
if ($result == AUTH_CONFIRM_OK or $result == AUTH_CONFIRM_ALREADY) {
|
|
|
41 |
redirect($returnurl);
|
|
|
42 |
} else {
|
|
|
43 |
echo $OUTPUT->header();
|
|
|
44 |
redirect($returnurl, get_string('usernotconfirmed', '', fullname($user, true)));
|
|
|
45 |
}
|
|
|
46 |
|
|
|
47 |
} else if ($resendemail && confirm_sesskey()) {
|
|
|
48 |
if (!$user = $DB->get_record('user', ['id' => $resendemail, 'mnethostid' => $CFG->mnet_localhost_id, 'deleted' => 0])) {
|
|
|
49 |
throw new \moodle_exception('nousers');
|
|
|
50 |
}
|
|
|
51 |
|
|
|
52 |
// Prevent spamming users who are already confirmed.
|
|
|
53 |
if ($user->confirmed) {
|
|
|
54 |
throw new \moodle_exception('alreadyconfirmed', 'moodle');
|
|
|
55 |
}
|
|
|
56 |
|
|
|
57 |
$returnmsg = get_string('emailconfirmsentsuccess');
|
|
|
58 |
$messagetype = \core\output\notification::NOTIFY_SUCCESS;
|
|
|
59 |
if (!send_confirmation_email($user)) {
|
|
|
60 |
$returnmsg = get_string('emailconfirmsentfailure');
|
|
|
61 |
$messagetype = \core\output\notification::NOTIFY_ERROR;
|
|
|
62 |
}
|
|
|
63 |
|
|
|
64 |
redirect($returnurl, $returnmsg, null, $messagetype);
|
|
|
65 |
} else if ($delete and confirm_sesskey()) { // Delete a selected user, after confirmation
|
|
|
66 |
require_capability('moodle/user:delete', $sitecontext);
|
|
|
67 |
|
|
|
68 |
$user = $DB->get_record('user', array('id'=>$delete, 'mnethostid'=>$CFG->mnet_localhost_id), '*', MUST_EXIST);
|
|
|
69 |
|
|
|
70 |
if ($user->deleted) {
|
|
|
71 |
throw new \moodle_exception('usernotdeleteddeleted', 'error');
|
|
|
72 |
}
|
|
|
73 |
if (is_siteadmin($user->id)) {
|
|
|
74 |
throw new \moodle_exception('useradminodelete', 'error');
|
|
|
75 |
}
|
|
|
76 |
|
|
|
77 |
if ($confirm != md5($delete)) {
|
|
|
78 |
echo $OUTPUT->header();
|
|
|
79 |
$fullname = fullname($user, true);
|
|
|
80 |
echo $OUTPUT->heading(get_string('deleteuser', 'admin'));
|
|
|
81 |
|
|
|
82 |
$optionsyes = array('delete'=>$delete, 'confirm'=>md5($delete), 'sesskey'=>sesskey());
|
|
|
83 |
$deleteurl = new moodle_url($returnurl, $optionsyes);
|
|
|
84 |
$deletebutton = new single_button($deleteurl, get_string('delete'), 'post');
|
|
|
85 |
|
|
|
86 |
echo $OUTPUT->confirm(get_string('deletecheckfull', '', "'$fullname'"), $deletebutton, $returnurl);
|
|
|
87 |
echo $OUTPUT->footer();
|
|
|
88 |
die;
|
|
|
89 |
} else {
|
|
|
90 |
if (delete_user($user)) {
|
|
|
91 |
\core\session\manager::gc(); // Remove stale sessions.
|
|
|
92 |
redirect($returnurl, get_string('deleteduserx', 'admin', fullname($user, true)));
|
|
|
93 |
} else {
|
|
|
94 |
\core\session\manager::gc(); // Remove stale sessions.
|
|
|
95 |
echo $OUTPUT->header();
|
|
|
96 |
echo $OUTPUT->notification($returnurl, get_string('deletednot', '', fullname($user, true)));
|
|
|
97 |
}
|
|
|
98 |
}
|
|
|
99 |
} else if ($acl and confirm_sesskey()) {
|
|
|
100 |
if (!has_capability('moodle/user:update', $sitecontext)) {
|
|
|
101 |
throw new \moodle_exception('nopermissions', 'error', '', 'modify the NMET access control list');
|
|
|
102 |
}
|
|
|
103 |
if (!$user = $DB->get_record('user', array('id'=>$acl))) {
|
|
|
104 |
throw new \moodle_exception('nousers', 'error');
|
|
|
105 |
}
|
|
|
106 |
if (!is_mnet_remote_user($user)) {
|
|
|
107 |
throw new \moodle_exception('usermustbemnet', 'error');
|
|
|
108 |
}
|
|
|
109 |
$accessctrl = strtolower(required_param('accessctrl', PARAM_ALPHA));
|
|
|
110 |
if ($accessctrl != 'allow' and $accessctrl != 'deny') {
|
|
|
111 |
throw new \moodle_exception('invalidaccessparameter', 'error');
|
|
|
112 |
}
|
|
|
113 |
$aclrecord = $DB->get_record('mnet_sso_access_control', array('username'=>$user->username, 'mnet_host_id'=>$user->mnethostid));
|
|
|
114 |
if (empty($aclrecord)) {
|
|
|
115 |
$aclrecord = new stdClass();
|
|
|
116 |
$aclrecord->mnet_host_id = $user->mnethostid;
|
|
|
117 |
$aclrecord->username = $user->username;
|
|
|
118 |
$aclrecord->accessctrl = $accessctrl;
|
|
|
119 |
$DB->insert_record('mnet_sso_access_control', $aclrecord);
|
|
|
120 |
} else {
|
|
|
121 |
$aclrecord->accessctrl = $accessctrl;
|
|
|
122 |
$DB->update_record('mnet_sso_access_control', $aclrecord);
|
|
|
123 |
}
|
|
|
124 |
$mnethosts = $DB->get_records('mnet_host', null, 'id', 'id,wwwroot,name');
|
|
|
125 |
redirect($returnurl);
|
|
|
126 |
|
|
|
127 |
} else if ($suspend and confirm_sesskey()) {
|
|
|
128 |
require_capability('moodle/user:update', $sitecontext);
|
|
|
129 |
|
|
|
130 |
if ($user = $DB->get_record('user', array('id'=>$suspend, 'mnethostid'=>$CFG->mnet_localhost_id, 'deleted'=>0))) {
|
|
|
131 |
if (!is_siteadmin($user) and $USER->id != $user->id and $user->suspended != 1) {
|
|
|
132 |
$user->suspended = 1;
|
|
|
133 |
// Force logout.
|
|
|
134 |
\core\session\manager::kill_user_sessions($user->id);
|
|
|
135 |
user_update_user($user, false);
|
|
|
136 |
}
|
|
|
137 |
}
|
|
|
138 |
redirect($returnurl);
|
|
|
139 |
|
|
|
140 |
} else if ($unsuspend and confirm_sesskey()) {
|
|
|
141 |
require_capability('moodle/user:update', $sitecontext);
|
|
|
142 |
|
|
|
143 |
if ($user = $DB->get_record('user', array('id'=>$unsuspend, 'mnethostid'=>$CFG->mnet_localhost_id, 'deleted'=>0))) {
|
|
|
144 |
if ($user->suspended != 0) {
|
|
|
145 |
$user->suspended = 0;
|
|
|
146 |
user_update_user($user, false);
|
|
|
147 |
}
|
|
|
148 |
}
|
|
|
149 |
redirect($returnurl);
|
|
|
150 |
|
|
|
151 |
} else if ($unlock and confirm_sesskey()) {
|
|
|
152 |
require_capability('moodle/user:update', $sitecontext);
|
|
|
153 |
|
|
|
154 |
if ($user = $DB->get_record('user', array('id'=>$unlock, 'mnethostid'=>$CFG->mnet_localhost_id, 'deleted'=>0))) {
|
|
|
155 |
login_unlock_account($user);
|
|
|
156 |
}
|
|
|
157 |
redirect($returnurl);
|
|
|
158 |
}
|
|
|
159 |
|
|
|
160 |
echo $OUTPUT->header();
|
|
|
161 |
|
|
|
162 |
if (has_capability('moodle/user:create', $sitecontext)) {
|
|
|
163 |
echo html_writer::start_div('d-flex mb-2');
|
|
|
164 |
$url = new moodle_url('/user/editadvanced.php', ['id' => -1]);
|
|
|
165 |
echo html_writer::link($url, get_string('addnewuser', 'moodle'), [
|
|
|
166 |
'class' => 'btn btn-primary ml-auto',
|
|
|
167 |
'data-action' => 'add-user',
|
|
|
168 |
]);
|
|
|
169 |
echo html_writer::end_div();
|
|
|
170 |
}
|
|
|
171 |
|
|
|
172 |
echo html_writer::start_div('', ['data-region' => 'report-user-list-wrapper']);
|
|
|
173 |
|
|
|
174 |
$bulkactions = new user_bulk_action_form(new moodle_url('/admin/user/user_bulk.php'),
|
|
|
175 |
['excludeactions' => ['displayonpage', 'download'], 'passuserids' => true, 'hidesubmit' => true],
|
|
|
176 |
'post', '',
|
|
|
177 |
['id' => 'user-bulk-action-form']);
|
|
|
178 |
$bulkactions->set_data(['returnurl' => $PAGE->url->out_as_local_url(false)]);
|
|
|
179 |
|
|
|
180 |
$report = \core_reportbuilder\system_report_factory::create(\core_admin\reportbuilder\local\systemreports\users::class,
|
|
|
181 |
context_system::instance(), parameters: ['withcheckboxes' => $bulkactions->has_bulk_actions()]);
|
|
|
182 |
echo $report->output();
|
|
|
183 |
|
|
|
184 |
if ($bulkactions->has_bulk_actions()) {
|
|
|
185 |
$PAGE->requires->js_call_amd('core_admin/bulk_user_actions', 'init');
|
|
|
186 |
$bulkactions->display();
|
|
|
187 |
}
|
|
|
188 |
|
|
|
189 |
echo html_writer::end_div();
|
|
|
190 |
|
|
|
191 |
echo $OUTPUT->footer();
|