Skip to content

Commit

Permalink
Merge pull request #48 from bpcurse/feature_development
Browse files Browse the repository at this point in the history
Feature development
  • Loading branch information
bpcurse authored Apr 14, 2021
2 parents 9abe9e0 + 98a27b7 commit 5de2ead
Show file tree
Hide file tree
Showing 7 changed files with 139 additions and 56 deletions.
46 changes: 31 additions & 15 deletions email.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,20 @@
}

if($_POST['submit']) {

$_SESSION['message_mode'] = $_POST['message_mode'] ?? $_SESSION['message_mode'];
filter_email();
$_SESSION['filters_set'] = array_keys($_POST, 'set_filter');
$_SESSION['filter_group'] = $_POST['filter_group'];
$_SESSION['filter_ll_since'] = $_POST['filter_ll_since'];
$_SESSION['filter_ll_before'] = $_POST['filter_ll_before'];
$_SESSION['filter_quota'] = $_POST['filter_quota'];

$user_ids = $_SESSION['filters_set']
? filter_users()
: $_SESSION['userlist'];

header("Location: ".build_mailto_list($_SESSION['message_mode'], $user_ids));

}

?>
Expand Down Expand Up @@ -52,31 +64,35 @@

echo "</td></tr>
<tr><td style='padding-bottom: 1em;'><u>".L10N_SEND_TO."</u></td>
<td style='padding: 0.3em; padding-bottom: 1em;'><input type='radio' name='recipients' value='all_users' checked>
<label for='recipients'>".L10N_ALL_USERS."</label>
<input type='radio' name='recipients' value='group'>
<label for='group'>".L10N_GROUP."</label>
<select name='group_selected' id=group_selected>
<td style='padding: 0.3em; padding-bottom: 1em;'>
<input type='radio' name='filter_group_choice' value='all_users' checked>
<label for='filter_group_choice'>".L10N_ALL_USERS."</label>
<input type='radio' name='filter_group_choice' value='set_filter'>
<label for='filter_group_choice'>".L10N_GROUP."</label>
<select name='filter_group'>
<option value='' selected>-- ".L10N_SELECT_GROUP." --</option>";
foreach($_SESSION['grouplist'] as $item)
echo "<option value='$item'>$item</option>";
echo "</select></td></tr>
<tr><td><u>".L10N_LIMIT_TO."<u></td>
<td style='padding: 0.3em;'><input type='checkbox' name='select_limit_login' value='true'>
<label for='login'>".L10N_LAST_LOGIN_BETWEEN." </label>
<input type=date name='lastlogin_since'>
".L10N_AND."
<input type=date name='lastlogin_before' value='".date('Y-m-d')."'></td>
<td style='padding: 0.3em;'>
<input type='checkbox' name='filter_lastLogin_choice' value='set_filter'>
<label for='filter_lastLogin_choice'>".L10N_LAST_LOGIN_BETWEEN." </label>
<input type=date name='filter_ll_since'>
".L10N_AND."
<input type=date name='filter_ll_before' value='".date('Y-m-d')."'>
</td>
</tr>
<tr><td></td>
<td style='padding: 0.3em;'><input type='checkbox' name='select_limit_quota' value='true'>
<label for='quota_used'>".L10N_QUOTA_USAGE_OVER." </label>
<input style='width: 6em;' type=number min=0.5 step=0.5 name='quota_used' value=25> GB
<td style='padding: 0.3em;'>
<input type='checkbox' name='filter_quota_choice' value='set_filter'>
<label for='filter_quota_choice'>".L10N_QUOTA_USAGE_OVER." </label>
<input style='width: 6em;' type=number min=0.5 step=0.5 name='filter_quota' value=25> GB
</tr>
</table>";

echo "<br><input id='button-email' type='submit' name='submit'
value='Create list'>
value='".L10N_CREATE_LIST."'>
</form>";

?>
Expand Down
91 changes: 60 additions & 31 deletions functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -369,15 +369,18 @@ function fetch_server_capabilities() {
* @return $selected_user_data
* ARRAY
*/
function select_data_all_users($data_choices = null, $format = null,
function select_data_all_users($data_choices = null, $userlist = null, $format = null,
$csv_delimiter = ', ') {

$data_choices = $data_choices ?? $_SESSION['data_choices'];
foreach ($_SESSION['userlist'] as $key => $user_id)
$userlist = $userlist ?? $_SESSION['userlist'];

foreach($userlist as $key => $user_id) {
// Call select_data function to filter/format request data
$selected_user_data[] = select_data_single_user(
$_SESSION['raw_user_data'][$key], $user_id, $data_choices, $format,
$csv_delimiter);
}

return $selected_user_data;
}
Expand Down Expand Up @@ -478,14 +481,14 @@ function select_data_single_user(
*/
function select_data_all_users_filter($filter_by, $condition1, $condition2 = null) {

foreach ($_SESSION['userlist'] as $key => $user_id) {
foreach($_SESSION['userlist'] as $key => $user_id) {

if($filter_by == 'quota' || $filter_by == 'used' || $filter_by == 'free')
$item_data = $_SESSION['raw_user_data'][$key]['ocs']['data']['quota'][$filter_by];
else
$item_data = $_SESSION['raw_user_data'][$key]['ocs']['data'][$filter_by];

switch ($filter_by) {
switch($filter_by) {

case 'quota':
case 'used':
Expand Down Expand Up @@ -520,9 +523,38 @@ function select_data_all_users_filter($filter_by, $condition1, $condition2 = nul

if(!$selected_user_ids)
$selected_user_ids = [''];

return $selected_user_ids;
}

function filter_users() {

if($_SESSION['filters_set']) {

$uids_g = in_array('filter_group_choice', $_SESSION['filters_set'])
? select_data_all_users_filter('groups', $_SESSION['filter_group'])
: $_SESSION['userlist'];

$uids_l = in_array('filter_lastLogin_choice', $_SESSION['filters_set'])
? select_data_all_users_filter('lastLogin', $_SESSION['filter_ll_since'],
$_SESSION['filter_ll_before'])
: $_SESSION['userlist'];

$uids_q = in_array('filter_quota_choice', $_SESSION['filters_set'])
? select_data_all_users_filter('used', $_SESSION['filter_quota'])
: $_SESSION['userlist'];

$user_ids = array_intersect($_SESSION['userlist'], $uids_g, $uids_l, $uids_q);

}

if(!$user_ids)
exit('No users found matching filter settings');

return $user_ids;

}

/**
* Find all users belonging to a given group an return an array containing userID and displayname
*
Expand Down Expand Up @@ -652,33 +684,6 @@ function print_status_overview($scope = 'quick') {
}
}

/**
* Show control button to send emails
*
* Provides a button for basic mass mailing via 'mailto:' string
*
* @param $user_data User data array in raw format ([key][ocs][data][email])
* OPTIONAL DEFAULT: null (full user list will be used)
* @param $button_text Text to display on the button
* OPTIONAL DEFAULT: 'send email to all users'
* @param $message_mode How to send emails (to, cc, bcc)
* OPTIONAL DEFAULT: 'bcc'
*/
function show_button_mailto($message_mode = 'bcc', $user_ids = null,
$button_text = L10N_SEND_EMAIL_TO_ALL_USERS) {

// Build and store email list formatted as 'mailto:'
$mailto_list = build_mailto_list($message_mode, $user_ids);

// Show mass mail button (only if email addresses were provided)
if($mailto_list != false)
echo "
<form>
<button id='button-email'
onclick=\"window.location.href='$mailto_list'\">$button_text</button>
</form>";
}

/**
* Build CSV file
*
Expand Down Expand Up @@ -792,6 +797,30 @@ function delete_folder_content($folder) {
function build_table_user_data($user_data) {
$data_choices = $_SESSION['data_choices'];

if($_SESSION['filters_set']) {
echo "<br><span style='color: red;'>Display filtered by ";

foreach($_SESSION['filters_set'] as $filter)
switch($filter) {
case 'filter_group_choice':
echo "group {$_SESSION['filter_group']}";
$preceding = true;
break;
case 'filter_lastLogin_choice':
if($preceding)
echo " <b>and</b> ";
echo "last login between {$_SESSION['filter_ll_since']} and {$_SESSION['filter_ll_before']} (incl. last day)";
$preceding = true;
break;
case 'filter_quota_choice':
if($preceding)
echo " <b>and</b> ";
echo "quota usage over {$_SESSION['filter_quota']} GB";
break;
}
echo "<br><br></span>";
}

// Define HTML table and set header cell content
$table_user_data_headers = '<table class="list"><tr>';

Expand Down
8 changes: 8 additions & 0 deletions index.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,21 @@
header('Location: index.php');
}

$target_url = filter_input(INPUT_GET, 'url', FILTER_SANITIZE_URL)
?? $target_url;
$user_name = $_GET['user']
?? $user_name;
$user_pass = $_GET['pass']
?? $user_pass;

// Set UI language to config value or to english, if it is not configured
$_SESSION['language'] = $language ?? 'en';
require_once 'l10n/'.$_SESSION['language'].'.php';
$target_url = $_GET['url']
?? filter_input(INPUT_GET, 'url', FILTER_SANITIZE_URL);
$user_name = $_GET['user'];
$user_pass = $_GET['pass'];

$_SESSION['data_choices'] = isset($_GET["select"])
? explode(",", $_GET["select"])
: ['id', 'displayname', 'email', 'lastLogin'];
Expand Down
1 change: 1 addition & 0 deletions l10n/de.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,3 +77,4 @@
define('L10N_YES','Ja');
define('L10N_NO','Nein');
define('L10N_COLUMN_HEADERS','Spaltenüberschriften');
define('L10N_CREATE_LIST','Liste erstellen');
3 changes: 1 addition & 2 deletions l10n/en.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,5 +78,4 @@
define('L10N_YES','Yes');
define('L10N_NO','No');
define('L10N_COLUMN_HEADERS','Column headers');

// EOF
define('L10N_CREATE_LIST','Create list');
30 changes: 25 additions & 5 deletions users.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,12 +66,32 @@ function toggle(source) {
}
}

echo '<tr><td colspan=3 style="height: 10px;"></td></tr>
<tr><td style="border: 1px solid #ddd;">
<input type="checkbox" onClick="toggle(this)" /> '
.L10N_TOGGLE_ALL. '
echo "<tr><td colspan=3 style='height: 10px;'></td></tr>
<tr><td style='border: 1px solid #ddd;'>
<input type='checkbox' onClick='toggle(this)' /> "
.L10N_TOGGLE_ALL. "
</td></tr>
</table>';
</table><br><br>
<u>".L10N_LIMIT_TO."</u><br><br>
<table>
<tr><td style='padding-bottom: 0.3em;'><input type='checkbox' name='filter_group_choice' value='set_filter'>
<label for='filter_group_choice'>".L10N_GROUP."</label>
<select name='filter_group'>
<option value='' selected>-- ".L10N_SELECT_GROUP." --</option>";
foreach($_SESSION['grouplist'] as $item)
echo "<option value='$item'>$item</option>";
echo "</select></td></tr>
<tr><td><input type='checkbox' name='filter_lastLogin_choice' value='set_filter'>
<label for='filter_lastLogin_choice'>".L10N_LAST_LOGIN_BETWEEN." </label>
<input type=date name='filter_ll_since'>
".L10N_AND."
<input type=date name='filter_ll_before' value='".date('Y-m-d')."'></td>
</tr>
<tr><td><input type='checkbox' name='filter_quota_choice' value='set_filter'>
<label for='filter_quota_choice'>".L10N_QUOTA_USAGE_OVER." </label>
<input style='width: 6em;' type=number min=0.5 step=0.5 name='filter_quota' value=25> GB
</tr>
</table>";

?>
<br><br>
Expand Down
16 changes: 13 additions & 3 deletions users_detail.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,20 @@
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_ll_since'] = $_POST['filter_ll_since'] ?? null;
$_SESSION['filter_ll_before'] = $_POST['filter_ll_before'] ?? null;
$_SESSION['filter_quota'] = $_POST['filter_quota'] ?? null;

$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
Expand All @@ -25,7 +35,7 @@

// Create and populate CSV file with selected user data and set filename variable
$filename = build_csv_file(select_data_all_users(
$_SESSION['data_choices'], 'utf8'), $_POST['csv_headers']);
$_SESSION['data_choices'], $userlist, 'utf8'), $_POST['csv_headers']);

download_file($filename, $mime_type, $filename_download, TEMP_FOLDER);
exit();
Expand Down Expand Up @@ -80,9 +90,9 @@ function sortTable() {
* 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());
echo build_table_user_data(select_data_all_users(null, $userlist));
else
echo build_csv_user_data(select_data_all_users(null, null, ','));
echo build_csv_user_data(select_data_all_users(null, $userlist, null, ','));

?>
</body>
Expand Down

0 comments on commit 5de2ead

Please sign in to comment.