, Ghent University, Belgium
*/
function status_filter($status)
{
$name = api_get_status_langvars();
return $name[$status];
}
if (isset($_GET['keyword']) || isset($_GET['keyword_firstname'])) {
$interbreadcrumb[] = ['url' => 'index.php', 'name' => get_lang('PlatformAdmin')];
$interbreadcrumb[] = ['url' => 'user_list.php', 'name' => get_lang('UserList')];
$tool_name = get_lang('SearchUsers');
} else {
$interbreadcrumb[] = ['url' => 'index.php', 'name' => get_lang('PlatformAdmin')];
$tool_name = get_lang('UserList');
}
$message = '';
if (!empty($action)) {
$check = Security::check_token('get');
if ($check) {
switch ($action) {
case 'add_user_to_my_url':
$user_id = $_REQUEST['user_id'];
$result = UrlManager::add_user_to_url($user_id, $urlId);
if ($result) {
$user_info = api_get_user_info($user_id);
$message = get_lang('UserAdded').' '.$user_info['complete_name_with_username'];
$message = Display::return_message($message, 'confirmation');
}
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() && !empty($_POST['id'])) {
$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 != $_user['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('SelectedUsersDeleted'),
'confirmation'
);
} else {
$message = Display::return_message(
get_lang('SomeUsersNotDeleted'),
'error'
);
}
}
break;
case 'disable':
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 != $_user['user_id']) {
if (UserManager::disable($user_id)) {
$number_of_affected_users++;
}
}
}
}
if ($number_of_selected_users == $number_of_affected_users) {
$message = Display::return_message(
get_lang('SelectedUsersDisabled'),
'confirmation'
);
} else {
$message = Display::return_message(
get_lang('SomeUsersNotDisabled'),
'error'
);
}
}
break;
case 'enable':
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 != $_user['user_id']) {
if (UserManager::enable($user_id)) {
$number_of_affected_users++;
}
}
}
}
if ($number_of_selected_users == $number_of_affected_users) {
$message = Display::return_message(
get_lang('SelectedUsersEnabled'),
'confirmation'
);
} else {
$message = Display::return_message(
get_lang('SomeUsersNotEnabled'),
'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('SearchUsers'),
]
);
$form->addButtonSearch(get_lang('Search'));
$searchAdvanced = '
'.Display::returnFontAwesomeIcon('arrow-right').' '.get_lang('AdvancedSearch').'
';
$actionsLeft = '';
$actionsCenter = '';
$actionsRight = '';
if (api_is_platform_admin()) {
$actionsRight .= ''.
Display::return_icon('new_user.png', get_lang('AddUsers'), '', ICON_SIZE_MEDIUM).'';
}
$actionsLeft .= $form->returnForm();
$actionsCenter .= $searchAdvanced;
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('AdvancedSearch'));
$form->addText('keyword_firstname', get_lang('FirstName'), false);
$form->addText('keyword_lastname', get_lang('LastName'), false);
$form->addText('keyword_username', get_lang('LoginName'), false);
$form->addText('keyword_email', get_lang('Email'), false);
$form->addText('keyword_officialcode', get_lang('OfficialCode'), false);
$status_options = [];
$status_options['%'] = get_lang('All');
$status_options[STUDENT] = get_lang('Student');
$status_options[COURSEMANAGER] = get_lang('Teacher');
$status_options[DRH] = get_lang('Drh');
$status_options[SESSIONADMIN] = get_lang('SessionsAdmin');
$status_options[PLATFORM_ADMIN] = get_lang('Administrator');
$form->addElement(
'select',
'keyword_status',
get_lang('Profile'),
$status_options
);
$active_group = [];
$active_group[] = $form->createElement('checkbox', 'keyword_active', '', get_lang('Active'));
$active_group[] = $form->createElement('checkbox', 'keyword_inactive', '', get_lang('Inactive'));
$form->addGroup($active_group, '', get_lang('ActiveAccount'), null, false);
$form->addElement('checkbox', 'check_easy_passwords', null, get_lang('CheckEasyPasswords'));
$data = $extraField->addElements($form, 0, [], true, false, $variablesToShow);
$htmlHeadXtra[] = '
';
$form->addButtonSearch(get_lang('SearchUsers'));
$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('OfficialCode'));
if (api_is_western_name_order()) {
$table->set_header(3, get_lang('FirstName'));
$table->set_header(4, get_lang('LastName'));
} else {
$table->set_header(3, get_lang('LastName'));
$table->set_header(4, get_lang('FirstName'));
}
$table->set_header(5, get_lang('LoginName'));
$table->set_header(6, get_lang('Email'));
$table->set_header(7, get_lang('Profile'));
$table->set_header(8, get_lang('Active'), true, 'width="15px"');
$table->set_header(9, get_lang('RegistrationDate'), true, 'width="90px"');
$table->set_header(10, get_lang('LatestLogin'), true, 'width="90px"');
$table->set_header(11, get_lang('Action'), false, 'width="220px"');
$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(11, 'modify_filter');
// Hide email column if login is email, to avoid column with same data
if (api_get_setting('login_is_email') === 'true') {
$table->setHideColumn(6);
}
// Only show empty actions bar if delete users has been blocked
$actionsList = [];
if (api_is_platform_admin() &&
!api_get_configuration_value('deny_delete_users')
) {
$actionsList['delete'] = get_lang('DeleteFromPlatform');
}
$actionsList['disable'] = get_lang('Disable');
$actionsList['enable'] = get_lang('Enable');
$table->set_form_actions($actionsList);
$table_result = $table->return_table();
$extra_search_options = '';
// Try to search the user everywhere
if ($table->get_total_number_of_items() == 0) {
if (api_get_multiple_access_url() && isset($_REQUEST['keyword'])) {
$keyword = Database::escape_string($_REQUEST['keyword']);
$conditions = ['username' => $keyword];
$user_list = UserManager::get_user_list(
$conditions,
[],
false,
' OR '
);
if (!empty($user_list)) {
$extra_search_options = Display::page_subheader(get_lang('UsersFoundInOtherPortals'));
$table = new HTML_Table(['class' => 'data_table']);
$column = 0;
$row = 0;
$headers = [get_lang('User'), 'URL', get_lang('Actions')];
foreach ($headers as $header) {
$table->setHeaderContents($row, $column, $header);
$column++;
}
$row++;
foreach ($user_list as $user) {
$column = 0;
$access_info = UrlManager::get_access_url_from_user($user['id']);
$access_info_to_string = '';
$add_user = true;
if (!empty($access_info)) {
foreach ($access_info as $url_info) {
if ($urlId == $url_info['access_url_id']) {
$add_user = false;
}
$access_info_to_string .= $url_info['url'].'
';
}
}
if ($add_user) {
$row_table = [];
$row_table[] = api_get_person_name($user['firstname'], $user['lastname']).' ('.$user['username'].') ';
$row_table[] = $access_info_to_string;
$url = api_get_self().'?action=add_user_to_my_url&user_id='.$user['id'].'&sec_token='.Security::getTokenFromSession();
$row_table[] = Display::url(
get_lang('AddUserToMyURL'),
$url,
['class' => 'btn']
);
foreach ($row_table as $cell) {
$table->setCellContents($row, $column, $cell);
$table->updateCellAttributes(
$row,
$column,
'align="center"'
);
$column++;
}
$table->updateRowAttributes(
$row,
$row % 2 ? 'class="row_even"' : 'class="row_odd"',
true
);
$row++;
}
}
$extra_search_options .= $table->toHtml();
$table_result = '';
}
}
}
$toolbarActions = Display::toolbarAction(
'toolbarUser',
[$actionsLeft, $actionsCenter, $actionsRight],
[4, 4, 4]
);
$tpl = new Template($tool_name);
$tpl->assign('actions', $toolbarActions);
$tpl->assign('message', $message);
$tpl->assign('content', $form.$table_result.$extra_search_options);
$tpl->display_one_col_template();