, Ghent University, Belgium
*/
function status_filter($status)
{
$statusname = api_get_status_langvars();
return $statusname[$status];
}
if (isset($_GET['keyword']) || isset($_GET['keyword_firstname'])) {
$interbreadcrumb[] = ['url' => 'index.php', 'name' => get_lang('Administration')];
$interbreadcrumb[] = ['url' => 'user_list_consent.php', 'name' => get_lang('User list')];
$tool_name = get_lang('Search users');
} else {
$interbreadcrumb[] = ['url' => 'index.php', 'name' => get_lang('Administration')];
$tool_name = get_lang('User list');
}
$message = '';
if (!empty($action)) {
$check = Security::check_token('get');
if ($check) {
switch ($action) {
case 'delete_terms':
UserManager::cleanUserRequestsOfRemoval($_GET['user_id']);
Display::addFlash(Display::return_message(get_lang('Deleted')));
header('Location: '.api_get_self());
exit;
break;
case 'delete_user':
$message = UserManager::deleteUserWithVerification($_GET['user_id']);
Display::addFlash($message);
header('Location: '.api_get_self());
exit;
break;
case 'delete':
if (api_is_platform_admin()) {
$number_of_selected_users = count($_POST['id']);
$number_of_affected_users = 0;
if (is_array($_POST['id'])) {
foreach ($_POST['id'] as $index => $user_id) {
if ($user_id != $userInfo['user_id']) {
if (UserManager::delete_user($user_id)) {
$number_of_affected_users++;
}
}
}
}
if ($number_of_selected_users == $number_of_affected_users) {
$message = Display::return_message(
get_lang('Selected users deleted'),
'confirmation'
);
} else {
$message = Display::return_message(
get_lang('Some of the selected users have not been deleted. We recommend you confirm which, by using the advanced search.'),
'error'
);
}
}
break;
case 'anonymize':
$message = UserManager::anonymizeUserWithVerification($_GET['user_id']);
Display::addFlash($message);
header('Location: '.api_get_self());
exit;
break;
}
Security::clear_token();
}
}
// Create a search-box
$form = new FormValidator('search_simple', 'get', null, null, null, 'inline');
$form->addText(
'keyword',
get_lang('Search'),
false,
[
'aria-label' => get_lang('Search users'),
]
);
$form->addButtonSearch(get_lang('Search'));
$actionsLeft = '';
$actionsCenter = '';
$actionsRight = '';
$actionsLeft .= $form->returnForm();
if (isset($_GET['keyword'])) {
$parameters = ['keyword' => Security::remove_XSS($_GET['keyword'])];
} elseif (isset($_GET['keyword_firstname'])) {
$parameters['keyword_firstname'] = Security::remove_XSS($_GET['keyword_firstname']);
$parameters['keyword_lastname'] = Security::remove_XSS($_GET['keyword_lastname']);
$parameters['keyword_username'] = Security::remove_XSS($_GET['keyword_username']);
$parameters['keyword_email'] = Security::remove_XSS($_GET['keyword_email']);
$parameters['keyword_officialcode'] = Security::remove_XSS($_GET['keyword_officialcode']);
$parameters['keyword_status'] = Security::remove_XSS($_GET['keyword_status']);
$parameters['keyword_active'] = Security::remove_XSS($_GET['keyword_active']);
$parameters['keyword_inactive'] = Security::remove_XSS($_GET['keyword_inactive']);
}
// Create a sortable table with user-data
$parameters['sec_token'] = Security::get_token();
$_admins_list = array_keys(UserManager::get_all_administrators());
Session::write('admin_list', $_admins_list);
// Display Advanced search form.
$form = new FormValidator(
'advanced_search',
'get',
'',
'',
[],
FormValidator::LAYOUT_HORIZONTAL
);
$form->addElement('html', '');
$form->addElement('header', get_lang('Advanced search'));
$form->addText('keyword_firstname', get_lang('First name'), false);
$form->addText('keyword_lastname', get_lang('Last name'), false);
$form->addText('keyword_username', get_lang('Login'), false);
$form->addText('keyword_email', get_lang('e-mail'), false);
$form->addText('keyword_officialcode', get_lang('Code'), false);
$status_options = [];
$status_options['%'] = get_lang('All');
$status_options[STUDENT] = get_lang('Learner');
$status_options[COURSEMANAGER] = get_lang('Trainer');
$status_options[DRH] = get_lang('Human Resources Manager');
$status_options[SESSIONADMIN] = get_lang('Sessions administrator');
$status_options[PLATFORM_ADMIN] = get_lang('Administrator');
$form->addSelect(
'keyword_status',
get_lang('Profile'),
$status_options
);
$form->addButtonSearch(get_lang('Search users'));
$defaults = [];
$defaults['keyword_active'] = 1;
$defaults['keyword_inactive'] = 1;
$form->setDefaults($defaults);
$form->addElement('html', '
');
$form = $form->returnForm();
$table = new SortableTable(
'users',
'get_number_of_users',
'get_user_data',
(api_is_western_name_order() xor api_sort_by_first_name()) ? 3 : 2
);
$table->set_additional_parameters($parameters);
$table->set_header(0, '', false, 'width="18px"');
$table->set_header(1, get_lang('Photo'), false);
$table->set_header(2, get_lang('Code'));
if (api_is_western_name_order()) {
$table->set_header(3, get_lang('First name'));
$table->set_header(4, get_lang('Last name'));
} else {
$table->set_header(3, get_lang('Last name'));
$table->set_header(4, get_lang('First name'));
}
$table->set_header(5, get_lang('Login'));
$table->set_header(6, get_lang('e-mail'));
$table->set_header(7, get_lang('Profile'));
$table->set_header(8, get_lang('active'));
$table->set_header(9, get_lang('Registration date'));
$table->set_header(10, get_lang('Request type'));
$table->set_header(11, get_lang('Request date'));
$table->set_header(12, get_lang('Action'), false);
$table->set_column_filter(3, 'user_filter');
$table->set_column_filter(4, 'user_filter');
$table->set_column_filter(6, 'email_filter');
$table->set_column_filter(7, 'status_filter');
$table->set_column_filter(8, 'active_filter');
$table->set_column_filter(12, 'modify_filter');
$table->set_column_filter(10, 'requestTypeFilter');
// Only show empty actions bar if delete users has been blocked
$actionsList = [];
if (api_is_platform_admin() &&
!api_get_env_variable('DENY_DELETE_USERS', false)
) {
$actionsList['delete'] = get_lang('Remove from portal');
}
$table->set_form_actions($actionsList);
$table_result = $table->return_table();
$extra_search_options = '';
$toolbarActions = Display::toolbarAction('toolbarUser', [$actionsLeft, $actionsCenter, $actionsRight]);
$noticeMessage = sprintf(
get_lang("You can find more information about the user's right to be forgotten through the following page: %s"),
'https://gdpr-info.eu/art-17-gdpr/'
);
$notice = Display::return_message($noticeMessage, 'normal', false);
$tpl = new Template($tool_name);
$tpl->assign('actions', $toolbarActions);
$tpl->assign('message', $message);
$tpl->assign('content', $form.$table_result.$extra_search_options.$notice);
$tpl->display_one_col_template();