Course: Add advanced search in enroll user - refs #3045

pull/4509/head
Yannick Warnier 3 years ago committed by GitHub
parent c0c522f75b
commit 098626eadd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 112
      main/user/subscribe_user.php

@ -130,6 +130,24 @@ if (isset($_POST['action'])) {
$is_western_name_order = api_is_western_name_order();
$sort_by_first_name = api_sort_by_first_name();
$htmlHeadXtra[] = '<script>
function display_advanced_search_form () {
if ($("#advanced_search_form").css("display") == "none") {
$("#advanced_search_form").css("display", "block");
$("#img_plus_and_minus").html(\''.Display::returnFontAwesomeIcon('arrow-down').' '.get_lang('AdvancedSearch').'\');
} else {
$("#advanced_search_form").css("display", "none");
$("#img_plus_and_minus").html(\''.Display::returnFontAwesomeIcon('arrow-right').' '.get_lang('AdvancedSearch').'\');
}
}
</script>';
$searchAdvanced = '<a id="advanced_params" class="btn btn-default advanced_options" onclick="display_advanced_search_form();">'.
'<span id="img_plus_and_minus">'.
Display::returnFontAwesomeIcon('arrow-right').' '.get_lang('AdvancedSearch').
'</span>'.
'</a>';
// Build table
if (api_get_configuration_value('session_course_users_subscription_limited_to_session_users') && !empty($sessionId)) {
$table = new SortableTable(
@ -196,9 +214,15 @@ if (isset($_GET['subscribe_user_filter_value']) && !empty($_GET['subscribe_user_
$actionsLeft .= '<a href="subscribe_user.php?type='.$type.'">'.
Display::return_icon('clean_group.gif').' '.get_lang('ClearFilterResults').'</a>';
}
$extraForm = '';
$extraForm = '<a id="advanced_params" class="btn btn-default advanced_options" onclick="display_advanced_search_form();">'.
'<span id="img_plus_and_minus">'.
Display::returnFontAwesomeIcon('arrow-right').' '.get_lang('AdvancedSearch').
'</span>'.
'</a>';
if (api_get_setting('ProfilingFilterAddingUsers') === 'true') {
$extraForm = display_extra_profile_fields_filter();
$extraForm .= display_extra_profile_fields_filter();
}
// Build search-form
@ -216,6 +240,30 @@ $form->addElement('hidden', 'cidReq', api_get_course_id());
$form->addButtonSearch(get_lang('Search'));
echo Display::toolbarAction('toolbar-subscriber', [$actionsLeft, $extraForm, $form->returnForm()], [4, 4, 4]);
$advancedForm = new FormValidator(
'advanced_search',
'get',
'',
'',
[],
FormValidator::LAYOUT_HORIZONTAL
);
$advancedForm->addElement('html', '<div id="advanced_search_form" style="display:none;">');
$advancedForm->addElement('header', get_lang('AdvancedSearch'));
$advancedForm->addText('keyword_firstname', get_lang('FirstName'), false);
$advancedForm->addText('keyword_lastname', get_lang('LastName'), false);
$advancedForm->addText('keyword_username', get_lang('LoginName'), false);
$advancedForm->addText('keyword_email', get_lang('Email'), false);
$advancedForm->addText('keyword_officialcode', get_lang('OfficialCode'), false);
$advancedForm->addElement('hidden', 'type', $type);
$advancedForm->addElement('hidden', 'cidReq', api_get_course_id());
$advancedForm->addButtonSearch(get_lang('SearchUsers'));
$advancedForm->addElement('html', '</div>');
$advancedForm = $advancedForm->returnForm();
echo $advancedForm;
$option = $type == COURSEMANAGER ? 2 : 1;
echo UserManager::getUserSubscriptionTab($option);
@ -464,7 +512,41 @@ function get_number_of_users()
}
// when there is a keyword then we are searching and we have to change the SQL statement
if (isset($_GET['keyword']) && !empty($_GET['keyword'])) {
if (!empty($_GET['keyword_firstname']) || !empty($_GET['keyword_lastname']) || !empty($_GET['keyword_username']) || !empty($_GET['keyword_email']) || !empty($_GET['keyword_officialcode'])) {
$condition = '';
$keywords = [
'firstname' => Security::remove_XSS(Database::escape_string($_GET['keyword_firstname'])),
'lastname' => Security::remove_XSS(Database::escape_string($_GET['keyword_lastname'])),
'username' => Security::remove_XSS(Database::escape_string($_GET['keyword_username'])),
'email' => Security::remove_XSS(Database::escape_string($_GET['keyword_email'])),
'official_code' => Security::remove_XSS(Database::escape_string($_GET['keyword_officialcode'])),
];
foreach ($keywords as $keyword => $value) {
if (!empty($value)) {
if (!empty($condition)) {
$condition .= ' AND ';
}
$condition .= $keyword." LIKE '%".$value."%'";
}
}
$user_table = Database::get_main_table(TABLE_MAIN_USER);
$course_user_table = Database::get_main_table(TABLE_MAIN_COURSE_USER);
$courseId = api_get_course_int_id();
$sql = "SELECT COUNT(u.id)
FROM $user_table u
LEFT JOIN $course_user_table cu
ON u.user_id = cu.user_id AND c_id = '".$courseId."' WHERE u.status <> ".DRH."";
if (!empty($condition)) {
$sql .= ' AND cu.user_id IS NULL';
$sql .= ' AND ('.$condition.')';
$sql .= " AND u.status != ".ANONYMOUS." ";
}
} elseif (!empty($_GET['keyword'])) {
// when there is a keyword then we are searching and we have to change the SQL statement
$keyword = Database::escape_string(trim($_REQUEST['keyword']));
$sql .= " AND (
firstname LIKE '%".$keyword."%' OR
@ -730,7 +812,29 @@ function get_user_data($from, $number_of_items, $column, $direction)
}
// adding additional WHERE statements to the SQL for the search functionality
if (isset($_REQUEST['keyword'])) {
if (!empty($_GET['keyword_firstname']) || !empty($_GET['keyword_lastname']) || !empty($_GET['keyword_username']) || !empty($_GET['keyword_email']) || !empty($_GET['keyword_officialcode'])) {
$condition = '';
$keywords = [
'firstname' => Security::remove_XSS(Database::escape_string($_GET['keyword_firstname'])),
'lastname' => Security::remove_XSS(Database::escape_string($_GET['keyword_lastname'])),
'username' => Security::remove_XSS(Database::escape_string($_GET['keyword_username'])),
'email' => Security::remove_XSS(Database::escape_string($_GET['keyword_email'])),
'official_code' => Security::remove_XSS(Database::escape_string($_GET['keyword_officialcode'])),
];
foreach ($keywords as $keyword => $value) {
if (!empty($value)) {
if (!empty($condition)) {
$condition .= ' AND ';
}
$condition .= "u.".$keyword." LIKE '%".$value."%'";
}
}
if (!empty($condition)) {
$sql .= ' AND ('.$condition.')';
}
} elseif (!empty($_REQUEST['keyword'])) {
$keyword = Database::escape_string(trim($_REQUEST['keyword']));
$sql .= " AND (
firstname LIKE '%".$keyword."%' OR

Loading…
Cancel
Save