-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbulkdelete.php
44 lines (35 loc) · 1.32 KB
/
bulkdelete.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
<?php
require_once(__DIR__ . '/../../config.php');
// Ensure this script is accessed within Moodle.
defined('MOODLE_INTERNAL') || die();
// Require the user to be logged in.
require_login();
$PAGE->set_url(new moodle_url('/auth/faceauth/bulkdelete.php'));
$PAGE->set_context(context_system::instance());
$PAGE->set_title(get_string('bulkdelete', 'auth_faceauth'));
// Get the list of user IDs from the request.
$userids = required_param('userids', PARAM_RAW);
$userids = explode(',', $userids);
// Directory to store enrolled face images.
$upload_dir = $CFG->dataroot . '/faceauth/faces/';
// Ensure the upload directory exists.
if (!is_dir($upload_dir)) {
debugging("Upload directory does not exist: {$upload_dir}", DEBUG_DEVELOPER);
echo $OUTPUT->notification(get_string('dirdoesnotexist', 'auth_faceauth'), 'notifyproblem');
exit;
}
// Delete the images for the selected users.
foreach ($userids as $userid) {
$files = glob($upload_dir . $userid . '_*');
foreach ($files as $file) {
if (is_file($file)) {
unlink($file);
}
}
}
// Output the header.
echo $OUTPUT->header();
// Display the success message.
echo $OUTPUT->notification(get_string('bulkdeletesuccess', 'auth_faceauth'), 'notifysuccess');
// Output the footer.
echo $OUTPUT->footer();