0) { CourseManager::unsubscribe_user($user_ids, $courseCode); Display::addFlash( Display::return_message(get_lang('UsersUnsubscribed')) ); } } } } } // Getting extra fields that have the filter option "on" $extraField = new ExtraField('user'); $extraFields = $extraField->get_all(['filter = ?' => 1]); $user_image_pdf_size = 80; if (api_is_allowed_to_edit(null, true)) { if (isset($_GET['action'])) { switch ($_GET['action']) { case 'set_tutor': $userId = isset($_GET['user_id']) ? intval($_GET['user_id']) : null; $isTutor = isset($_GET['is_tutor']) ? intval($_GET['is_tutor']) : 0; $userInfo = api_get_user_info($userId); if (!empty($userId)) { if (!$sessionId) { if ($userInfo['status'] != INVITEE) { CourseManager::updateUserCourseTutor( $userId, $courseId, $isTutor ); Display::addFlash( Display::return_message(get_lang('Updated')) ); } else { Display::addFlash( Display::return_message( get_lang('InviteesCantBeTutors'), 'error' ) ); } } } break; case 'export': $table_course_user = Database::get_main_table(TABLE_MAIN_COURSE_USER); $table_users = Database::get_main_table(TABLE_MAIN_USER); $is_western_name_order = api_is_western_name_order(); $data = []; $a_users = []; $current_access_url_id = api_get_current_access_url_id(); $extra_fields = UserManager::get_extra_user_data( api_get_user_id(), false, false, false, true ); $extra_fields = array_keys($extra_fields); $select_email_condition = ''; if (api_get_setting('show_email_addresses') == 'true') { $select_email_condition = ' user.email, '; if ($sort_by_first_name) { $a_users[0] = [ 'id', get_lang('FirstName'), get_lang('LastName'), get_lang('Username'), get_lang('Email'), get_lang('Phone'), get_lang('OfficialCode'), get_lang('Active') ]; } else { $a_users[0] = [ 'id', get_lang('LastName'), get_lang('FirstName'), get_lang('Username'), get_lang('Email'), get_lang('Phone'), get_lang('OfficialCode'), get_lang('Active') ]; } } else { if ($sort_by_first_name) { $a_users[0] = [ 'id', get_lang('FirstName'), get_lang('LastName'), get_lang('Username'), get_lang('Phone'), get_lang('OfficialCode'), get_lang('Active') ]; } else { $a_users[0] = [ 'id', get_lang('LastName'), get_lang('FirstName'), get_lang('Username'), get_lang('Phone'), get_lang('OfficialCode'), get_lang('Active') ]; } } $legal = ''; if (isset($course_info['activate_legal']) && $course_info['activate_legal'] == 1) { $legal = ', legal_agreement'; $a_users[0][] = get_lang('LegalAgreementAccepted'); } if ($_GET['format'] == 'pdf') { $select_email_condition = ' user.email, '; if ($is_western_name_order) { $a_users[0] = [ '#', get_lang('UserPicture'), get_lang('OfficialCode'), get_lang('FirstName').', '.get_lang('LastName'), get_lang('Email'), get_lang('Phone') ]; } else { $a_users[0] = [ '#', get_lang('UserPicture'), get_lang('OfficialCode'), get_lang('LastName').', '.get_lang('FirstName'), get_lang('Email'), get_lang('Phone') ]; } } $a_users[0] = array_merge($a_users[0], $extra_fields); // users subscribed to the course through a session. if (api_get_session_id()) { $table_session_course_user = Database::get_main_table(TABLE_MAIN_SESSION_COURSE_USER); $sql = "SELECT DISTINCT user.user_id, ".($is_western_name_order ? "user.firstname, user.lastname" : "user.lastname, user.firstname").", user.username, $select_email_condition phone, user.official_code, active $legal FROM $table_session_course_user as session_course_user, $table_users as user "; if (api_is_multiple_url_enabled()) { $sql .= ' , '.Database::get_main_table(TABLE_MAIN_ACCESS_URL_REL_USER).' au '; } $sql .= " WHERE c_id = $courseId AND session_course_user.user_id = user.user_id AND session_id = $sessionId "; if (api_is_multiple_url_enabled()) { $sql .= " AND user.user_id = au.user_id AND access_url_id = $current_access_url_id "; } // only users no coaches/teachers if ($type == COURSEMANAGER) { $sql .= " AND session_course_user.status = 2 "; } else { $sql .= " AND session_course_user.status = 0 "; } $sql .= $sort_by_first_name ? ' ORDER BY user.firstname, user.lastname' : ' ORDER BY user.lastname, user.firstname'; $rs = Database::query($sql); $counter = 1; while ($user = Database:: fetch_array($rs, 'ASSOC')) { if (isset($user['legal_agreement'])) { if ($user['legal_agreement'] == 1) { $user['legal_agreement'] = get_lang('Yes'); } else { $user['legal_agreement'] = get_lang('No'); } } $extra_fields = UserManager::get_extra_user_data( $user['user_id'], false, false, false, true ); if (!empty($extra_fields)) { foreach ($extra_fields as $key => $extra_value) { $user[$key] = $extra_value; } } $data[] = $user; if ($_GET['format'] == 'pdf') { $user_info = api_get_user_info($user['user_id']); $user_image = ''; if ($is_western_name_order) { $user_pdf = [ $counter, $user_image, $user['official_code'], $user['firstname'].', '.$user['lastname'], $user['email'], $user['phone'] ]; } else { $user_pdf = [ $counter, $user_image, $user['official_code'], $user['lastname'].', '.$user['firstname'], $user['email'], $user['phone'] ]; } $a_users[] = $user_pdf; } else { $a_users[] = $user; } $counter++; } } if ($sessionId == 0) { // users directly subscribed to the course $table_course_user = Database::get_main_table(TABLE_MAIN_COURSE_USER); $sql = "SELECT DISTINCT user.user_id, ".($is_western_name_order ? "user.firstname, user.lastname" : "user.lastname, user.firstname").", user.username, $select_email_condition phone, user.official_code, active $legal FROM $table_course_user as course_user, $table_users as user "; if (api_is_multiple_url_enabled()) { $sql .= ' , '.Database::get_main_table(TABLE_MAIN_ACCESS_URL_REL_USER).' au '; } $sql .= " WHERE c_id = '$courseId' AND course_user.relation_type <> ".COURSE_RELATION_TYPE_RRHH." AND course_user.user_id = user.user_id "; if (api_is_multiple_url_enabled()) { $sql .= " AND user.user_id = au.user_id AND access_url_id = $current_access_url_id "; } // only users no teachers/coaches if ($type == COURSEMANAGER) { $sql .= " AND course_user.status = 1 "; } else { $sql .= " AND course_user.status = 5 "; } $sql .= ($sort_by_first_name ? " ORDER BY user.firstname, user.lastname" : " ORDER BY user.lastname, user.firstname"); $rs = Database::query($sql); $counter = 1; while ($user = Database::fetch_array($rs, 'ASSOC')) { if (isset($user['legal_agreement'])) { if ($user['legal_agreement'] == 1) { $user['legal_agreement'] = get_lang('Yes'); } else { $user['legal_agreement'] = get_lang('No'); } } $extra_fields = UserManager::get_extra_user_data( $user['user_id'], false, false, false, true ); if (!empty($extra_fields)) { foreach ($extra_fields as $key => $extra_value) { $user[$key] = $extra_value; } } if ($_GET['format'] == 'pdf') { $user_info = api_get_user_info($user['user_id']); $user_image = ''; if ($is_western_name_order) { $user_pdf = [ $counter, $user_image, $user['official_code'], $user['firstname'].', '.$user['lastname'], $user['email'], $user['phone'] ]; } else { $user_pdf = [ $counter, $user_image, $user['official_code'], $user['lastname'].', '.$user['firstname'], $user['email'], $user['phone'] ]; } $a_users[] = $user_pdf; } else { $a_users[] = $user; } $data[] = $user; $counter++; } } $fileName = get_lang('StudentList'); $pdfTitle = get_lang('StudentList'); if ($type == COURSEMANAGER) { $fileName = get_lang('Teachers'); $pdfTitle = get_lang('Teachers'); } switch ($_GET['format']) { case 'csv': Export::arrayToCsv($a_users, $fileName); exit; case 'xls': Export::arrayToXls($a_users, $fileName); exit; case 'pdf': $header_attributes = [ ['style' => 'width:10px'], ['style' => 'width:30px'], ['style' => 'width:50px'], ['style' => 'width:500px'] ]; $params = [ 'filename' => $fileName, 'pdf_title' => $pdfTitle, 'header_attributes' => $header_attributes ]; Export::export_table_pdf($a_users, $params); exit; } } } } // end if allowed to edit if (api_is_allowed_to_edit(null, true)) { // Unregister user from course if (isset($_REQUEST['unregister']) && $_REQUEST['unregister']) { if (isset($_GET['user_id']) && is_numeric($_GET['user_id']) && ($_GET['user_id'] != $_user['user_id'] || api_is_platform_admin()) ) { $user_id = intval($_GET['user_id']); $tbl_user = Database::get_main_table(TABLE_MAIN_USER); $tbl_session_rel_course = Database::get_main_table(TABLE_MAIN_SESSION_COURSE); $tbl_session_rel_user = Database::get_main_table(TABLE_MAIN_SESSION_USER); $sql = 'SELECT user.user_id FROM '.$tbl_user.' user INNER JOIN '.$tbl_session_rel_user.' reluser ON user.user_id = reluser.user_id AND reluser.relation_type<>'.SESSION_RELATION_TYPE_RRHH.' INNER JOIN '.$tbl_session_rel_course.' rel_course ON rel_course.session_id = reluser.session_id WHERE user.user_id = "'.$user_id.'" AND rel_course.c_id = "'.$courseId.'"'; $result = Database::query($sql); $row = Database::fetch_array($result, 'ASSOC'); if ($row['user_id'] == $user_id || $row['user_id'] == "") { CourseManager::unsubscribe_user($_GET['user_id'], $courseCode); Display::addFlash( Display::return_message(get_lang('UserUnsubscribed')) ); } else { Display::addFlash( Display::return_message( get_lang('ThisStudentIsSubscribeThroughASession') ) ); } } } } else { // If student can unsubscribe if (isset($_REQUEST['unregister']) && $_REQUEST['unregister'] == 'yes') { if ($course_info['unsubscribe'] == 1) { $user_id = api_get_user_id(); CourseManager::unsubscribe_user($user_id, $course_info['code']); header('Location: '.api_get_path(WEB_PATH).'user_portal.php'); exit; } } } // $is_allowed_in_course is first defined in local.inc.php if (!api_is_allowed_in_course()) { api_not_allowed(true); } // Statistics Event::event_access_tool(TOOL_USER); $default_column = 3; $tableLabel = $type === STUDENT ? 'student' : 'teacher'; $table = new SortableTable( $tableLabel.'_list', 'get_number_of_users', 'get_user_data', $default_column ); $parameters['keyword'] = isset($_GET['keyword']) ? Security::remove_XSS($_GET['keyword']) : null; $parameters['sec_token'] = Security::get_token(); $parameters['id_session'] = api_get_session_id(); $parameters['type'] = $type; $table->set_additional_parameters($parameters); $header_nr = 0; $indexList = []; $table->set_header($header_nr++, '', false); $indexList['photo'] = $header_nr; $table->set_header($header_nr++, get_lang('Photo'), false); $indexList['official_code'] = $header_nr; $table->set_header($header_nr++, get_lang('OfficialCode')); if ($is_western_name_order) { $indexList['firstname'] = $header_nr; $table->set_header($header_nr++, get_lang('FirstName')); $indexList['lastname'] = $header_nr; $table->set_header($header_nr++, get_lang('LastName')); } else { $indexList['lastname'] = $header_nr; $table->set_header($header_nr++, get_lang('LastName')); $indexList['firstname'] = $header_nr; $table->set_header($header_nr++, get_lang('FirstName')); } $indexList['username'] = $header_nr; $table->set_header($header_nr++, get_lang('LoginName')); $indexList['groups'] = $header_nr; $table->set_header($header_nr++, get_lang('GroupSingle'), false); $hideFields = api_get_configuration_value('hide_user_field_from_list'); if (!empty($hideFields)) { $hideFields = $hideFields['fields']; foreach ($hideFields as $fieldToHide) { if (isset($indexList[$fieldToHide])) { $table->setHideColumn($indexList[$fieldToHide]); } } } $table->setHideColumn('is_tutor'); $table->setHideColumn('user_status_in_course'); if (api_is_allowed_to_edit(null, true)) { $table->set_header($header_nr++, get_lang('Status'), false); $table->set_header($header_nr++, get_lang('Active'), false); if ($canEditUsers) { $table->set_column_filter(8, 'active_filter'); } else { $table->set_column_filter(8, 'active_filter'); } foreach ($extraFields as $extraField) { $table->set_header($header_nr++, $extraField['display_text'], false); } // Actions column $table->set_header($header_nr++, get_lang('Action'), false); $table->set_column_filter($header_nr - 1, 'modify_filter'); if ($canEditUsers) { $table->set_form_actions(['unsubscribe' => get_lang('Unreg')], 'user'); } } else { if ($course_info['unsubscribe'] == 1) { $table->set_header($header_nr++, get_lang('Action'), false); $table->set_column_filter($header_nr - 1, 'modify_filter'); } } /* Header */ if (isset($origin) && $origin == 'learnpath') { Display::display_reduced_header(); } else { if (isset($_GET['keyword']) && !empty($_GET['keyword'])) { $interbreadcrumb[] = [ "url" => "user.php?".api_get_cidreq(), "name" => get_lang("Users"), ]; $tool_name = get_lang('SearchResults'); } else { $tool_name = get_lang('Users'); $origin = 'users'; } Display::display_header($tool_name, "User"); } // Tool introduction Display::display_introduction_section(TOOL_USER, 'left'); $actions = ''; $selectedTab = 1; if (api_is_allowed_to_edit(null, true)) { echo '