-
Notifications
You must be signed in to change notification settings - Fork 3
/
users_detail.php
109 lines (84 loc) · 3.38 KB
/
users_detail.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
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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
<?php
$active_page = 'users';
require_once 'functions.php';
include_once 'config.php';
session_secure_start();
require_once 'l10n/'.$_SESSION['language'].'.php';
// Filter POST array and save keys with value 'true' as constant
$_SESSION['data_choices'] = array_keys($_POST,'true');
if(!$_SESSION['data_choices']) {
header('Content-Type: text/html; charset=utf-8');
exit(L10N_ERROR . L10N_SELECT_AT_LEAST_ONE_COLUMN ." ". L10N_RETURN_TO_FORM);
}
$_SESSION['filters_set'] = array_keys($_POST, 'set_filter');
$_SESSION['filter_group'] = $_POST['filter_group'] ?? null;
$_SESSION['filter_quota'] = $_POST['filter_quota'] ?? null;
$_SESSION['type_quota'] = $_POST['type_quota'] ?? null;
$_SESSION['compare_quota'] = $_POST['compare_quota'] ?? null;
$_SESSION['filter_ll_since'] = $_POST['filter_ll_since'] != ""
? $_POST['filter_ll_since']
: '1970-01-01';
$_SESSION['filter_ll_before'] = $_POST['filter_ll_before'] != ""
? $_POST['filter_ll_before']
: date('Y-m-d');
$export_type = $_POST['export_type'];
$display_or_download = $_POST['submit'];
$userlist = $_SESSION['filters_set']
? filter_users()
: $_SESSION['userlist'];
if($display_or_download == 'download') {
// Set filename or create one depending on GET parameters
if($filename_download == null)
$filename_download = "nextcloud-userlist_".date('Y-m-d_Hi').".csv";
// Create and populate CSV file with selected user data and set filename variable
$filename = build_csv_file(select_data_all_users(
$_SESSION['data_choices'], $userlist, 'csv'), $_POST['csv_headers']);
download_file($filename, $mime_type, $filename_download, $_SESSION['temp_folder']);
exit();
}
echo "<html lang='{$_SESSION['language']}'>";
?>
<head>
<link rel="stylesheet" type="text/css" href="style.php">
<meta charset="UTF-8">
<title>Nextcloud Userexport</title>
<script>
/**
* Source of the following function 'sortTable':
* https://stackoverflow.com/a/49041392
*
* sort table columns on header click
*
*/
function sortTable() {
const getCellValue = (tr, idx) => tr.children[idx].innerText || tr.children[idx].textContent;
const comparer = (idx, asc) => (a, b) => ((v1, v2) =>
v1 !== '' && v2 !== '' && !isNaN(v1) && !isNaN(v2) ? v1 - v2 : v1.toString().localeCompare(v2)
)(getCellValue(asc ? a : b, idx), getCellValue(asc ? b : a, idx));
document.querySelectorAll('th').forEach(th => th.addEventListener('click', (() => {
const table = th.closest('table');
Array.from(table.querySelectorAll('tr:nth-child(n+2)'))
.sort(comparer(Array.from(th.parentNode.children).indexOf(th), this.asc = !this.asc))
.forEach(tr => table.appendChild(tr) );
})));
}
</script>
</head>
<body>
<?php
include 'navigation.php';
if(!$_SESSION['authenticated']) {
header('Content-Type: text/html; charset=utf-8');
exit('<br>'.L10N_CONNECTION_NEEDED);
}
print_status_overview();
/**
* Display results page either as HTML table or comma separated values (CSV)
*/
if($export_type == 'table')
echo build_table_user_data(select_data_all_users(null, $userlist));
else
echo build_csv_user_data(select_data_all_users(null, $userlist, null, ','));
?>
</body>
</html>