From 2f9afe88a21ef1b347cdb028969e488ad53227cd Mon Sep 17 00:00:00 2001 From: Julio Montoya Date: Tue, 21 Jul 2015 20:08:45 +0200 Subject: [PATCH] Improve user UI see BT#6050 (work in progress) --- main/group/group.php | 7 +- main/inc/lib/usermanager.lib.php | 10 +- main/user/subscribe_user.php | 186 ++++++++++++++++++------------- main/user/user.php | 94 +++++++++++----- 4 files changed, 182 insertions(+), 115 deletions(-) diff --git a/main/group/group.php b/main/group/group.php index 3f420277f3..80cf23c123 100755 --- a/main/group/group.php +++ b/main/group/group.php @@ -147,8 +147,11 @@ if (api_is_allowed_to_edit(false, true)) { echo '
'; if (api_is_allowed_to_edit(false, true)) { + echo ''. - Display::return_icon('new_group.png', get_lang('NewGroupCreate'), '', ICON_SIZE_MEDIUM).''; + Display::return_icon('add.png', get_lang('NewGroupCreate'), '', ICON_SIZE_MEDIUM).''; + + echo GroupManager::getSearchForm(); if (api_get_setting('allow_group_categories') == 'true') { echo ''. @@ -172,8 +175,6 @@ if (api_is_allowed_to_edit(false, true)) { echo ''. Display::return_icon('group_summary.png', get_lang('GroupOverview'), '', ICON_SIZE_MEDIUM).''; - - echo GroupManager::getSearchForm(); } $group_cats = GroupManager::get_categories(api_get_course_id()); diff --git a/main/inc/lib/usermanager.lib.php b/main/inc/lib/usermanager.lib.php index 50c2fbe78b..92546bbcca 100755 --- a/main/inc/lib/usermanager.lib.php +++ b/main/inc/lib/usermanager.lib.php @@ -5076,17 +5076,21 @@ SQL; $headers = [ [ - 'url' => $userPath.'user.php?'.api_get_cidreq(), - 'content' => get_lang('Users'), + 'url' => $userPath.'user.php?'.api_get_cidreq().'&type='.STUDENT, + 'content' => get_lang('Students'), ], [ + 'url' => $userPath.'user.php?'.api_get_cidreq().'&type='.COURSEMANAGER, + 'content' => get_lang('Teachers'), + ], + /*[ 'url' => $userPath.'subscribe_user.php?'.api_get_cidreq(), 'content' => get_lang('Students'), ], [ 'url' => $userPath.'subscribe_user.php?type=teacher&'.api_get_cidreq(), 'content' => get_lang('Teachers'), - ], + ],*/ [ 'url' => api_get_path(WEB_CODE_PATH).'group/group.php?'.api_get_cidreq(), 'content' => get_lang('Groups'), diff --git a/main/user/subscribe_user.php b/main/user/subscribe_user.php index d4f755c276..4cd8afc898 100755 --- a/main/user/subscribe_user.php +++ b/main/user/subscribe_user.php @@ -26,76 +26,53 @@ if (!api_is_allowed_to_edit()) { } $tool_name = get_lang("SubscribeUserToCourse"); -$type = isset($_REQUEST['type']) ? Security::remove_XSS($_REQUEST['type']) : null; +$type = isset($_REQUEST['type']) ? intval($_REQUEST['type']) : STUDENT; $keyword = isset($_REQUEST['keyword']) ? Security::remove_XSS($_REQUEST['keyword']) : null; -if ($type == 'teacher') { +$courseInfo = api_get_course_info(); + +if ($type == COURSEMANAGER) { $tool_name = get_lang("SubscribeUserToCourseAsTeacher"); } //extra entries in breadcrumb -$interbreadcrumb[] = array ("url" => "user.php", "name" => get_lang("ToolUser")); +$interbreadcrumb[] = array( + "url" => "user.php?".api_get_cidreq(), + "name" => get_lang("ToolUser"), +); if ($keyword) { - $interbreadcrumb[] = array ("url" => "subscribe_user.php?type=".$type, "name" => $tool_name); + $interbreadcrumb[] = array( + "url" => "subscribe_user.php?type=".$type.'&'.api_get_cidreq(), + "name" => $tool_name, + ); $tool_name = get_lang('SearchResults'); } -Display :: display_header($tool_name, "User"); - -// Build search-form -echo '
'; -$actions = null; -if (isset($keyword)) { - $actions .= ''.Display::return_icon('clean_group.gif').' '.get_lang('ClearSearchResults').''; -} -if (isset($_GET['subscribe_user_filter_value']) AND !empty($_GET['subscribe_user_filter_value'])) { - $actions .= ''.Display::return_icon('clean_group.gif').' '.get_lang('ClearFilterResults').''; -} -if (api_get_setting('ProfilingFilterAddingUsers') == 'true') { - display_extra_profile_fields_filter(); -} - - -// Build search-form -$form = new FormValidator('search_user', 'get', '', '', null, false); -$renderer = $form->defaultRenderer(); -$renderer->setCustomElementTemplate('{element} '); -$form->addText('keyword', '', false); -$form->addElement('hidden', 'type', $type); -$form->addButtonSearch(get_lang('Search')); -$form->addElement('static', 'additionalactions', null, $actions); -$form->display(); -echo '
'; - - -$option = $type == 'teacher' ? 3 : 2; -echo UserManager::getUserSubscriptionTab($option); - -/* - MAIN SECTION -*/ $current_session_id = api_get_session_id(); $list_register_user=''; $list_not_register_user=''; if (isset($_REQUEST['register'])) { - if ($type =='teacher') { + if ($type == COURSEMANAGER) { if (!empty($current_session_id)) { $result_simple_sub = SessionManager::set_coach_to_course_session( $_REQUEST['user_id'], $current_session_id, - $_course['code'] + $courseInfo['code'] ); } else { $result_simple_sub = CourseManager:: subscribe_user( $_REQUEST['user_id'], - $_course['code'], + $courseInfo['code'], COURSEMANAGER ); } } else { - $result_simple_sub = CourseManager :: subscribe_user($_REQUEST['user_id'], $_course['code']); + $result_simple_sub = CourseManager:: subscribe_user( + $_REQUEST['user_id'], + $courseInfo['code'] + ); } $user_id_temp = $_SESSION['session_user_id']; @@ -105,9 +82,9 @@ if (isset($_REQUEST['register'])) { for ($j=0; $j<$counter;$j++) { if ($user_id_temp[$j]==$_GET['user_id']) { if ($result_simple_sub) { - Display::display_confirmation_message($_SESSION['session_user_name'][$j].' '.get_lang('AddedToCourse')); + Display::addFlash(Display::return_message($_SESSION['session_user_name'][$j].' '.get_lang('AddedToCourse'))); } else { - Display::display_error_message($_SESSION['session_user_name'][$j].' '.get_lang('NotAddedToCourse')); + Display::addFlash(Display::return_message($_SESSION['session_user_name'][$j].' '.get_lang('NotAddedToCourse'), 'error')); } } @@ -115,33 +92,44 @@ if (isset($_REQUEST['register'])) { unset($_SESSION['session_user_id']); unset($_SESSION['session_user_name']); } + + + header('Location:'.api_get_path(WEB_CODE_PATH).'user/user.php?'.api_get_cidreq().'&type='.$type); + exit; } -if (isset ($_POST['action'])) { - switch ($_POST['action']) { - case 'subscribe': - if (is_array($_POST['user'])) { - foreach ($_POST['user'] as $index => $user_id) { - $user_id=intval($user_id); - if ($type =='teacher') { - if (!empty($current_session_id)) { - $is_suscribe[] = SessionManager::set_coach_to_course_session( +if (isset($_POST['action'])) { + switch($_POST['action']) { + case 'subscribe': + if (is_array($_POST['user'])) { + foreach ($_POST['user'] as $index => $user_id) { + $user_id=intval($user_id); + if ($type == COURSEMANAGER) { + if (!empty($current_session_id)) { + $is_suscribe[] = SessionManager::set_coach_to_course_session( $user_id, $current_session_id, - $_course['sysCode'] + $courseInfo['code'] ); - } else { - $is_suscribe[] = CourseManager::subscribe_user($user_id, $_course['code'],COURSEMANAGER); - } - } else { - $is_suscribe[] = CourseManager::subscribe_user($user_id, $_course['code']); - } + } else { + $is_suscribe[] = CourseManager::subscribe_user( + $user_id, + $courseInfo['code'], + COURSEMANAGER + ); + } + } else { + $is_suscribe[] = CourseManager::subscribe_user( + $user_id, + $courseInfo['code'] + ); + } $is_suscribe_user_id[] = $user_id; - } - } + } + } - $user_id_temp=$_SESSION['session_user_id']; - $user_name_temp=$_SESSION['session_user_name']; + $user_id_temp = $_SESSION['session_user_id']; + $user_name_temp = $_SESSION['session_user_name']; unset($_SESSION['session_user_id']); unset($_SESSION['session_user_name']); @@ -167,17 +155,20 @@ if (isset ($_POST['action'])) { if (!empty($list_register_user)) { if ($is_suscribe_counter==1) { $register_user_message=$temp_unique_user.' '.get_lang('AddedToCourse'); - Display::display_confirmation_message($register_user_message,false); + Display::addFlash(Display::return_message($register_user_message)); } else { $register_user_message='
'.get_lang('UsersRegistered').'

'.$list_register_user; - Display::display_confirmation_message($register_user_message,false); + Display::addFlash(Display::return_message($register_user_message, false)); } } if (!empty($list_not_register_user)) { $not_register_user_message='
'.get_lang('UsersNotRegistered').'


'.$list_not_register_user; - Display::display_error_message($not_register_user_message,false); + Display::addFlash(Display::return_message($not_register_user_message, 'error')); } + + header('Location:'.api_get_path(WEB_CODE_PATH).'user/user.php?'.api_get_cidreq().'&type='.$type); + exit; break; } } @@ -201,7 +192,7 @@ $table = new SortableTable( ($is_western_name_order xor $sort_by_first_name) ? 3 : 2 ); $parameters['keyword'] = $keyword; -$parameters['type'] = $type; +$parameters['type'] = COURSEMANAGER; $table->set_additional_parameters($parameters); $col = 0; $table->set_header($col ++, '', false); @@ -229,6 +220,50 @@ if (!empty($_POST['keyword'])) { echo '
'.get_lang('SearchResultsFor').' '.$keyword_name.'
'; } + +Display :: display_header($tool_name, "User"); + +// Build search-form +echo '
'; + +switch ($type) { + case STUDENT: + $url = api_get_path(WEB_CODE_PATH).'user/user.php?'.api_get_cidreq().''; + break; + case COURSEMANAGER: + $url = api_get_path(WEB_CODE_PATH).'user/user.php?'.api_get_cidreq().'&type='.COURSEMANAGER; + break; +} + +echo Display::url( + Display::return_icon('back.png', get_lang('Back'), '', ICON_SIZE_MEDIUM), + $url +); +$actions = ''; +if (isset($keyword)) { + $actions .= ''. + Display::return_icon('clean_group.gif').' '.get_lang('ClearSearchResults').''; +} +if (isset($_GET['subscribe_user_filter_value']) AND !empty($_GET['subscribe_user_filter_value'])) { + $actions .= ''. + Display::return_icon('clean_group.gif').' '.get_lang('ClearFilterResults').''; +} +if (api_get_setting('ProfilingFilterAddingUsers') == 'true') { + display_extra_profile_fields_filter(); +} + +// Build search-form +$form = new FormValidator('search_user', 'get', '', '', null, FormValidator::LAYOUT_INLINE); +$form->addText('keyword', '', false); +$form->addElement('hidden', 'type', $type); +$form->addButtonSearch(get_lang('Search')); +$form->addElement('static', 'additionalactions', null, $actions); +$form->display(); +echo '
'; + +$option = $type == COURSEMANAGER ? 2 : 1; +echo UserManager::getUserSubscriptionTab($option); + // Display table $table->display(); @@ -241,8 +276,6 @@ Display::display_footer(); */ function get_number_of_users() { - global $_configuration; - // Database table definition $user_table = Database::get_main_table(TABLE_MAIN_USER); $course_user_table = Database::get_main_table(TABLE_MAIN_COURSE_USER); @@ -419,8 +452,6 @@ function get_number_of_users() */ function get_user_data($from, $number_of_items, $column, $direction) { - global $_configuration; - $url_access_id = api_get_current_access_url_id(); $course_code = api_get_course_id(); $session_id = api_get_session_id(); @@ -459,8 +490,7 @@ function get_user_data($from, $number_of_items, $column, $direction) u.active AS col4, u.user_id AS col5"; } - - if (isset($_REQUEST['type']) && $_REQUEST['type'] == 'teacher') { + if (isset($_REQUEST['type']) && $_REQUEST['type'] == COURSEMANAGER) { // adding a teacher through a session if (!empty($session_id)) { $sql = "SELECT $select_fields @@ -728,10 +758,10 @@ function email_filter($email) { * @return string Some HTML-code */ function reg_filter($user_id) { - if (isset($_REQUEST['type']) && $_REQUEST['type'] == 'teacher') { - $type = 'teacher'; + if (isset($_REQUEST['type']) && $_REQUEST['type'] == COURSEMANAGER) { + $type = COURSEMANAGER; } else { - $type = 'student'; + $type = STUDENT; } $result = ''.get_lang("reg").''; return $result; @@ -787,8 +817,6 @@ function search_additional_profile_fields($keyword) $table_user_field_values = Database::get_main_table(TABLE_EXTRA_FIELD_VALUES); $tableExtraField = Database::get_main_table(TABLE_EXTRA_FIELD); $table_user = Database::get_main_table(TABLE_MAIN_USER); - $table_course_user = Database :: get_main_table(TABLE_MAIN_COURSE_USER); - $table_session_course_user = Database::get_main_table(TABLE_MAIN_SESSION_COURSE_USER); // getting the field option text that match this keyword (for radio buttons and checkboxes) $sql = "SELECT * FROM $table_user_field_options diff --git a/main/user/user.php b/main/user/user.php index a453120f01..ee32a9fb80 100755 --- a/main/user/user.php +++ b/main/user/user.php @@ -19,8 +19,6 @@ $this_section = SECTION_COURSES; // notice for unauthorized people. api_protect_course_script(true); -global $_configuration; - if (!api_is_platform_admin(true)) { if (!api_is_course_admin() && !api_is_coach()) { if (api_get_course_setting('allow_user_view_user_list') == 0) { @@ -534,14 +532,13 @@ function searchUserKeyword($firstname, $lastname, $username, $official_code, $ke */ function get_user_data($from, $number_of_items, $column, $direction) { - global $origin; global $is_western_name_order; global $extraFields; + $type = isset($_REQUEST['type']) ? intval($_REQUEST['type']) : STUDENT; $course_info = api_get_course_info(); $sessionId = api_get_session_id(); $course_code = $course_info['code']; - $a_users = array(); // limit @@ -585,12 +582,22 @@ function get_user_data($from, $number_of_items, $column, $direction) $active = isset($_GET['active']) ? $_GET['active'] : null; + if (empty($sessionId)) { + $status = $type; + } else { + if ($type == COURSEMANAGER) { + $status = 2; + } else { + $status = 0; + } + } + $a_course_users = CourseManager :: get_user_list_from_course_code( $course_code, $sessionId, $limit, $order_by, - null, + $status, null, false, false, @@ -746,17 +753,18 @@ function active_filter($active, $urlParams, $row) */ function modify_filter($user_id, $row, $data) { - global $origin, $is_allowed_to_track, $charset; + global $is_allowed_to_track, $charset; $user_id = $data[0]; $course_info = $_course = api_get_course_info(); $current_user_id = api_get_user_id(); $sessionId = api_get_session_id(); + $type = isset($_REQUEST['type']) ? intval($_REQUEST['type']) : STUDENT; $result = ""; if ($is_allowed_to_track) { - $result .= ' + $result .= ' '.get_lang('Tracking').' '; } @@ -764,7 +772,7 @@ function modify_filter($user_id, $row, $data) // If platform admin, show the login_as icon (this drastically shortens // time taken by support to test things out) if (api_is_platform_admin()) { - $result .= ' '. + $result .= ' '. Display::return_icon('login_as.gif', get_lang('LoginAs')).'  '; } @@ -781,20 +789,22 @@ function modify_filter($user_id, $row, $data) $disabled = ''; - if ($data['user_status_in_course'] == COURSEMANAGER) { - $disabled = 'disabled'; + if ($data['user_status_in_course'] == STUDENT) { + + $result .= Display::url( + $text, + 'user.php?'.api_get_cidreq( + ).'&action=set_tutor&is_tutor='.$isTutor.'&user_id='.$user_id.'&type='.$type, + array('class' => 'btn btn-default '.$disabled) + ).' '; } - $result .= Display::url( - $text, - 'user.php?'.api_get_cidreq().'&action=set_tutor&is_tutor='.$isTutor.'&user_id='.$user_id, - array('class' => 'btn btn-default '.$disabled) - ).' '; } // edit if (api_get_setting('allow_user_course_subscription_by_course_admin') == 'true' or api_is_platform_admin()) { // unregister if ($user_id != $current_user_id || api_is_platform_admin()) { - $result .= ''.get_lang('Unreg').' '; + $result .= ''. + get_lang('Unreg').' '; } else { //$result .= Display::return_icon('unsubscribe_course_na.png', get_lang('Unreg'),'',ICON_SIZE_SMALL).' '; } @@ -803,7 +813,8 @@ function modify_filter($user_id, $row, $data) // Show buttons for unsubscribe if ($course_info['unsubscribe'] == 1) { if ($user_id == $current_user_id) { - $result .= ''.get_lang('Unreg').' '; + $result .= ''. + get_lang('Unreg').' '; } } } @@ -890,14 +901,16 @@ if (api_is_allowed_to_edit(null, true)) { } } - /* Header */ if (isset($origin) && $origin == 'learnpath') { Display::display_reduced_header(); } else { if (isset($_GET['keyword']) && !empty($_GET['keyword'])) { - $interbreadcrumb[] = array ("url" => "user.php", "name" => get_lang("Users")); + $interbreadcrumb[] = array( + "url" => "user.php?".api_get_cidreq(), + "name" => get_lang("Users"), + ); $tool_name = get_lang('SearchResults'); } else { $tool_name = get_lang('Users'); @@ -912,12 +925,38 @@ $is_allowed_to_track = ($is_courseAdmin || $is_courseTutor); // Tool introduction Display::display_introduction_section(TOOL_USER, 'left'); $actions = ''; +$type = isset($_REQUEST['type']) ? intval($_REQUEST['type']) : STUDENT; + +$selectedTab = 1; + if (api_is_allowed_to_edit(null, true)) { echo '
'; - $actions .= ''. + switch ($type) { + case STUDENT: + $selectedTab = 1; + $url = api_get_path(WEB_CODE_PATH).'user/subscribe_user.php?'.api_get_cidreq().''; + break; + case COURSEMANAGER: + $selectedTab = 2; + $url = api_get_path(WEB_CODE_PATH).'user/subscribe_user.php?'.api_get_cidreq().'&type='.COURSEMANAGER; + break; + } + + echo Display::url( + Display::return_icon('add.png', get_lang('Add'), '', ICON_SIZE_MEDIUM), + $url + ); + + // Build search-form + $form = new FormValidator('search_user', 'get', '', '', null, FormValidator::LAYOUT_INLINE); + $form->addText('keyword', '', false); + $form->addButtonSearch(get_lang('SearchButton')); + $form->display(); + + $actions .= ''. Display::return_icon('export_csv.png', get_lang('ExportAsCSV'),'',ICON_SIZE_MEDIUM).' '; - $actions .= ''. + $actions .= ''. Display::return_icon('export_excel.png', get_lang('ExportAsXLS'),'',ICON_SIZE_MEDIUM).' '; if (api_get_setting('allow_user_course_subscription_by_course_admin') == 'true' || @@ -929,24 +968,19 @@ if (api_is_allowed_to_edit(null, true)) { $actions .= ''. Display::return_icon('pdf.png', get_lang('ExportToPDF'),'',ICON_SIZE_MEDIUM).' '; - /*$actions .= "". - Display::return_icon('group.png', get_lang("GroupUserManagement"),'',ICON_SIZE_MEDIUM)."";*/ $allowTutors = api_get_setting('allow_tutors_to_assign_students_to_session'); if (api_is_allowed_to_edit() && $allowTutors == 'true') { - $actions .= ' '.get_lang('Sessions').''; + $actions .= ' '. + get_lang('Sessions').''; } - // Build search-form - $form = new FormValidator('search_user', 'get', '', '', null, FormValidator::LAYOUT_INLINE); - $form->addText('keyword', '', false); - $form->addButtonSearch(get_lang('SearchButton')); - $form->display(); echo $actions; + echo '
'; } -echo UserManager::getUserSubscriptionTab(1); +echo UserManager::getUserSubscriptionTab($selectedTab); if (isset($message)) { Display::display_confirmation_message($message);