forked from grinchenkoedu/local_cleanup
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathghost.php
More file actions
95 lines (78 loc) · 2.41 KB
/
ghost.php
File metadata and controls
95 lines (78 loc) · 2.41 KB
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
<?php
/**
* @global moodle_page $PAGE
* @global moodle_database $DB
* @global stdClass $USER
* @global stdClass $CFG
* @global renderer_base $OUTPUT
*/
require_once(__DIR__ . '/../../config.php');
use core\task\manager as task_manager;
use local_cleanup\task\cleanup;
$PAGE->set_context(context_system::instance());
$PAGE->set_url('/local/cleanup/ghost.php');
$PAGE->set_title(get_string('ghostfiles', 'local_cleanup'));
$PAGE->set_heading(get_string('ghostfiles', 'local_cleanup'));
$PAGE->set_pagelayout('admin');
require_login();
if (!is_siteadmin()) {
header('HTTP/1.1 403 Forbidden');
exit('Forbidden!');
}
$task = task_manager::get_scheduled_task(cleanup::class);
$page = optional_param('page', 0, PARAM_INT);
$limit = 250;
$items = $DB->get_recordset('cleanup', [], 'size DESC', '*', $page * $limit, $limit);
$total_items = $DB->count_records('cleanup');
$total_size = $DB->get_field('cleanup', 'SUM(size)', []);
$table = new html_table();
$table->head = [
get_string('file'),
'MIME',
get_string('size'),
'',
];
while ($items->valid()) {
$item = $items->current();
$actions = [
html_writer::link(
new moodle_url('/local/cleanup/download.php', ['path' => $item->path]),
$OUTPUT->pix_icon('i/down', get_string('download'))
),
];
$table->data[] = [
$item->path,
$item->mime,
sprintf(
'%.1f %s',
$item->size / pow(1024, 2),
get_string('sizemb')
),
implode(' ', $actions)
];
$items->next();
}
$pagination = $OUTPUT->paging_bar($total_items, $page, $limit, $PAGE->url);
echo $OUTPUT->header();
echo $OUTPUT->box(
html_writer::tag('p',
html_writer::tag('b',
get_string(
'ghosttotalheader',
'local_cleanup',
[
'files' => $total_items,
'size' => sprintf('%.3f', $total_size / pow(1024, 3)),
'cleanup_date' => date(DATE_ISO8601, $task->get_next_run_time()),
]
)
)
)
);
if (count($table->data) !== 0) {
echo html_writer::table($table);
} else {
echo $OUTPUT->notification(get_string('nothingtoshow', 'local_cleanup'), 'notifysuccess');
}
echo $OUTPUT->box($pagination, 'text-center');
echo $OUTPUT->footer();