diff --git a/public/main/admin/user_edit.php b/public/main/admin/user_edit.php index 3381695069..f0c7742746 100644 --- a/public/main/admin/user_edit.php +++ b/public/main/admin/user_edit.php @@ -459,16 +459,12 @@ if ($form->validate()) { $currentUserId = api_get_user_id(); - $userObj = api_get_user_entity($user_id); - - UserManager::add_user_as_admin($userObj); - if ($user_id != $currentUserId) { - if (1 == $platform_admin) { $userObj = api_get_user_entity($user_id); - UserManager::add_user_as_admin($userObj); + if ($platform_admin == 1) { + UserManager::addUserAsAdmin($userObj); } else { - UserManager::remove_user_admin($user_id); + UserManager::removeUserAdmin($userObj); } } diff --git a/public/main/auth/courses.php b/public/main/auth/courses.php index 305417e067..da50028c62 100644 --- a/public/main/auth/courses.php +++ b/public/main/auth/courses.php @@ -108,7 +108,7 @@ switch ($action) { case 'subscribe_course': if (api_is_anonymous()) { //header('Location: '.api_get_path(WEB_CODE_PATH).'auth/inscription.php?c='.$courseCodeToSubscribe); - header('Location: '.api_get_path(WEB_CODE_PATH).'auth/inscription.php'); + header('Location: '.api_get_path(WEB_CODE_PATH).'auth/inscription.php?c='.$courseCodeToSubscribe); exit; } $courseCodeToSubscribe = isset($_GET['course_code']) ? Security::remove_XSS($_GET['course_code']) : ''; @@ -519,26 +519,26 @@ switch ($action) { $courseUrl.$course['directory'].'/index.php?id_session=0', ['class' => 'btn btn-primary'] ); - if (!$courseClosed) { - if ($course_unsubscribe_allowed) { + if (!$courseClosed && $course_unsubscribe_allowed && + false === $userRegisteredInCourseAsTeacher + ) { $course['unregister_formatted'] = CoursesAndSessionsCatalog::return_unregister_button( $course, $stok, $searchTerm, $categoryCode ); - } } } elseif ($userRegisteredInCourseAsTeacher) { // if user registered as teacher - if ($course_unsubscribe_allowed) { + /*if ($course_unsubscribe_allowed) { $course['unregister_formatted'] = CoursesAndSessionsCatalog::return_unregister_button( $course, $stok, $searchTerm, $categoryCode ); - } + }*/ } else { // if user not registered in the course if (!$courseClosed) { @@ -624,7 +624,8 @@ switch ($action) { $requirementsData = $repository->checkRequirementsForUser( $sequences, SequenceResource::SESSION_TYPE, - $userId + $userId, + $sessionId ); $continueWithSubscription = $repository->checkSequenceAreCompleted($requirementsData); diff --git a/public/main/auth/inscription.php b/public/main/auth/inscription.php index 88f9972bb3..66d9ebf6bd 100644 --- a/public/main/auth/inscription.php +++ b/public/main/auth/inscription.php @@ -121,6 +121,10 @@ if (false === $user_already_registered_show_terms && } } + $LastnameLabel = get_lang('LastName'); + if (api_get_configuration_value('registration_add_helptext_for_2_names') == true) { + $LastnameLabel = [$LastnameLabel, get_lang('InsertTwoNames')]; + } if (api_is_western_name_order()) { // FIRST NAME and LAST NAME $form->addElement('text', 'firstname', get_lang('First name'), ['size' => 40]); @@ -796,52 +800,10 @@ if ($form->validate()) { /* If the account has to be approved then we set the account to inactive, sent a mail to the platform admin and exit the page.*/ - if ('approval' === api_get_setting('allow_registration')) { + if (api_get_setting('allow_registration') === 'approval') { // 1. Send mail to all platform admin - $emailsubject = get_lang('Approval for new account').': '.$values['username']; - $emailbody = get_lang('Approval for new account')."\n"; - $emailbody .= get_lang('Username').': '.$values['username']."\n"; - - if (api_is_western_name_order()) { - $emailbody .= get_lang('First name').': '.$values['firstname']."\n"; - $emailbody .= get_lang('Last name').': '.$values['lastname']."\n"; - } else { - $emailbody .= get_lang('Last name').': '.$values['lastname']."\n"; - $emailbody .= get_lang('First name').': '.$values['firstname']."\n"; - } - $emailbody .= get_lang('e-mail').': '.$values['email']."\n"; - $emailbody .= get_lang('Status').': '.$values['status']."\n\n"; - - $url_edit = Display::url( - api_get_path(WEB_CODE_PATH).'admin/user_edit.php?user_id='.$user_id, - api_get_path(WEB_CODE_PATH).'admin/user_edit.php?user_id='.$user_id - ); - - $emailbody .= get_lang('Manage user').": $url_edit"; - - if (api_get_configuration_value('send_inscription_notification_to_general_admin_only')) { - $email = api_get_setting('emailAdministrator'); - $firtname = api_get_setting('administratorSurname'); - $lastname = api_get_setting('administratorName'); - - api_mail_html("$firtname $lastname", $email, $emailsubject, $emailbody); - } else { - $admins = UserManager::get_all_administrators(); - foreach ($admins as $admin_info) { - MessageManager::send_message( - $admin_info['user_id'], - $emailsubject, - $emailbody, - [], - [], - null, - null, - null, - null, - $user_id - ); - } - } + $chamiloUser = api_get_user_entity($user_id); + MessageManager::sendNotificationOfNewRegisteredUserApproval($chamiloUser); // 2. set account inactive UserManager::disable($user_id); diff --git a/public/main/exercise/TestCategory.php b/public/main/exercise/TestCategory.php index f70cd74cb0..d87d7f09f4 100644 --- a/public/main/exercise/TestCategory.php +++ b/public/main/exercise/TestCategory.php @@ -335,7 +335,7 @@ class TestCategory return []; } - + /** * Return the category name for question with question_id = $questionId * In this version, a question has only 1 category. @@ -647,36 +647,6 @@ class TestCategory return $content; } - /** - * Return the category name for question with question_id = $questionId - * In this version, a question has only 1 category. - * - * @param $questionId - * @param int $courseId - * - * @return string - */ - public static function getCategoryNameForQuestion($questionId, $courseId = 0) - { - if (empty($courseId)) { - $courseId = api_get_course_int_id(); - } - $courseId = (int) $courseId; - $categoryId = self::getCategoryForQuestion($questionId, $courseId); - $table = Database::get_course_table(TABLE_QUIZ_QUESTION_CATEGORY); - $sql = "SELECT title - FROM $table - WHERE iid = $categoryId "; - $res = Database::query($sql); - $data = Database::fetch_array($res); - $result = ''; - if (Database::num_rows($res) > 0) { - $result = $data['title']; - } - - return $result; - } - /** * sortTabByBracketLabel ($tabCategoryQuestions) * key of $tabCategoryQuestions are the category id (0 for not in a category) @@ -937,9 +907,9 @@ class TestCategory return false; } - - + + /** * @param $primaryKeys diff --git a/public/main/inc/lib/CoursesAndSessionsCatalog.class.php b/public/main/inc/lib/CoursesAndSessionsCatalog.class.php index 766eec64c3..3f6addef44 100644 --- a/public/main/inc/lib/CoursesAndSessionsCatalog.class.php +++ b/public/main/inc/lib/CoursesAndSessionsCatalog.class.php @@ -176,17 +176,25 @@ class CoursesAndSessionsCatalog ]; $allCategories = CourseCategory::getAllCategories(); + $categoryToAvoid = ''; + if (api_is_student()) { + $categoryToAvoid = api_get_configuration_value('course_category_code_to_use_as_model'); + } foreach ($allCategories as $category) { + $categoryCode = $category['code']; + if (!empty($categoryToAvoid) && $categoryToAvoid == $categoryCode) { + continue; + } if (empty($category['parent_id'])) { - $list[$category['code']] = $category; - $list[$category['code']]['level'] = 0; - list($subList, $childrenCount) = self::buildCourseCategoryTree($allCategories, $category['code'], 0); + $list[$categoryCode] = $category; + $list[$categoryCode]['level'] = 0; + list($subList, $childrenCount) = self::buildCourseCategoryTree($allCategories, $categoryCode, 0); foreach ($subList as $item) { $list[$item['code']] = $item; } // Real course count - $countCourses = CourseCategory::countCoursesInCategory($category['code']); - $list[$category['code']]['number_courses'] = $childrenCount + $countCourses; + $countCourses = CourseCategory::countCoursesInCategory($categoryCode); + $list[$categoryCode]['number_courses'] = $childrenCount + $countCourses; } } @@ -1155,21 +1163,27 @@ class CoursesAndSessionsCatalog /** * Display the unregister button of a course in the course catalog. * - * @param $course - * @param $stok - * @param $search_term - * @param $categoryCode + * @param array $course + * @param string $stok + * @param string $search_term + * @param string $categoryCode + * @param int $sessionId * * @return string */ - public static function return_unregister_button($course, $stok, $search_term, $categoryCode) + public static function return_unregister_button($course, $stok, $search_term, $categoryCode, $sessionId = 0) { $title = get_lang('Unsubscription'); + $search_term = Security::remove_XSS($search_term); + $categoryCode = Security::remove_XSS($categoryCode); + $sessionId = (int) $sessionId; + + $url = api_get_self().'?action=unsubscribe&sec_token='.$stok.'&sid='.$sessionId.'&course_code='.$course['code']. + '&search_term='.$search_term.'&category_code='.$categoryCode; return Display::url( Display::returnFontAwesomeIcon('sign-in').' '.$title, - api_get_self().'?action=unsubscribe&sec_token='.$stok - .'&course_code='.$course['code'].'&search_term='.$search_term.'&category_code='.$categoryCode, + $url, ['class' => 'btn btn-danger', 'title' => $title, 'aria-label' => $title] ); } @@ -1195,14 +1209,13 @@ class CoursesAndSessionsCatalog ) { $sessionId = (int) $sessionId; + $class = 'btn-sm'; if ($btnBing) { - $btnBing = 'btn-lg btn-block'; - } else { - $btnBing = 'btn-sm'; + $class = 'btn-lg btn-block'; } if ($checkRequirements) { - return self::getRequirements($sessionId, SequenceResource::SESSION_TYPE, $includeText, $btnBing); + return self::getRequirements($sessionId, SequenceResource::SESSION_TYPE, $includeText, $class); } $catalogSessionAutoSubscriptionAllowed = false; @@ -1225,7 +1238,7 @@ class CoursesAndSessionsCatalog 'pencil', 'primary', [ - 'class' => $btnBing.' ajax', + 'class' => $class.' ajax', 'data-title' => get_lang('AreYouSureToSubscribe'), 'data-size' => 'md', 'title' => get_lang('Subscribe'), @@ -1244,7 +1257,7 @@ class CoursesAndSessionsCatalog $url, 'pencil', 'primary', - ['class' => $btnBing], + ['class' => $class], $includeText ); } @@ -1264,18 +1277,18 @@ class CoursesAndSessionsCatalog return $result; } - public static function getRequirements($id, $type, $includeText, $btnBing) + public static function getRequirements($id, $type, $includeText, $class, $sessionId = 0) { $id = (int) $id; $type = (int) $type; - $url = api_get_path(WEB_AJAX_PATH); - $url .= 'sequence.ajax.php?'; + $url = api_get_path(WEB_AJAX_PATH).'sequence.ajax.php?'; $url .= http_build_query( [ 'a' => 'get_requirements', 'id' => $id, 'type' => $type, + 'sid' => $sessionId, ] ); @@ -1285,7 +1298,7 @@ class CoursesAndSessionsCatalog 'shield', 'info', [ - 'class' => $btnBing.' ajax', + 'class' => $class.' ajax', 'data-title' => get_lang('CheckRequirements'), 'data-size' => 'md', 'title' => get_lang('CheckRequirements'), diff --git a/public/main/inc/lib/TicketManager.php b/public/main/inc/lib/TicketManager.php index 721a860e2f..3a825a923e 100644 --- a/public/main/inc/lib/TicketManager.php +++ b/public/main/inc/lib/TicketManager.php @@ -285,6 +285,8 @@ class TicketManager * @param string $priority * @param string $status * @param int $assignedUserId + * @param int $exerciseId + * @param int $lpId * * @return bool */ @@ -301,7 +303,9 @@ class TicketManager $source = '', $priority = '', $status = '', - $assignedUserId = 0 + $assignedUserId = 0, + $exerciseId = null, + $lpId = null ) { $table_support_tickets = Database::get_main_table(TABLE_TICKET_TICKET); $table_support_category = Database::get_main_table(TABLE_TICKET_CATEGORY); @@ -365,6 +369,13 @@ class TicketManager 'total_messages' => 0, ]; + if (!empty($exerciseId)) { + $params['exercise_id'] = $exerciseId; + } + + if (!empty($lpId)) { + $params['lp_id'] = $lpId; + } if (!empty($course_id)) { $params['course_id'] = $course_id; } @@ -1205,6 +1216,34 @@ class TicketManager if ($course) { $row['course_url'] = ''.$course['name'].''; } + $row['exercise_url'] = null; + + if (!empty($row['exercise_id'])) { + $exerciseTitle = ExerciseLib::getExerciseTitleById($row['exercise_id']); + $dataExercise = [ + 'cidReq' => $course['code'], + 'id_session' => $sessionId, + 'exerciseId' => $row['exercise_id'], + ]; + $urlParamsExercise = http_build_query($dataExercise); + + $row['exercise_url'] = ''.$exerciseTitle.''; + } + + $row['lp_url'] = null; + + if (!empty($row['lp_id'])) { + $lpName = learnpath::getLpNameById($row['lp_id']); + $dataLp = [ + 'cidReq' => $course['code'], + 'id_session' => $sessionId, + 'lp_id' => $row['lp_id'], + 'action' => 'view', + ]; + $urlParamsLp = http_build_query($dataLp); + + $row['lp_url'] = ''.$lpName.''; + } } $userInfo = api_get_user_info($row['sys_insert_user_id']); diff --git a/public/main/inc/lib/api.lib.php b/public/main/inc/lib/api.lib.php index e14851ee5e..fb79076d96 100644 --- a/public/main/inc/lib/api.lib.php +++ b/public/main/inc/lib/api.lib.php @@ -165,6 +165,7 @@ define('SECTION_DASHBOARD', 'dashboard'); define('SECTION_REPORTS', 'reports'); define('SECTION_GLOBAL', 'global'); define('SECTION_INCLUDE', 'include'); +define('SECTION_CUSTOMPAGE', 'custompage'); // CONSTANT name for local authentication source define('PLATFORM_AUTH_SOURCE', 'platform'); @@ -1102,7 +1103,7 @@ function api_protect_course_script($print_headers = false, $allow_session_admins } } - apiBlockInactiveUser(); + api_block_inactive_user(); return true; } @@ -1128,10 +1129,68 @@ function api_protect_admin_script($allow_sessions_admins = false, $allow_drh = f return false; } + api_block_inactive_user(); return true; } +/** + * Blocks inactive users with a currently active session from accessing more pages "live". + * + * @return bool Returns true if the feature is disabled or the user account is still enabled. + * Returns false (and shows a message) if the feature is enabled *and* the user is disabled. + */ +function api_block_inactive_user() +{ + $data = true; + if (api_get_configuration_value('security_block_inactive_users_immediately') != 1) { + return $data; + } + + $userId = api_get_user_id(); + $homeUrl = api_get_path(WEB_PATH); + if ($userId == 0) { + return $data; + } + + $sql = "SELECT active FROM ".Database::get_main_table(TABLE_MAIN_USER)." + WHERE id = $userId"; + + $result = Database::query($sql); + if (Database::num_rows($result) > 0) { + $result_array = Database::fetch_array($result); + $data = (bool) $result_array['active']; + } + if ($data == false) { + $tpl = new Template(null, true, true, false, true, false, true, 0); + $tpl->assign('hide_login_link', 1); + + //api_not_allowed(true, get_lang('AccountInactive')); + // we were not in a course, return to home page + $msg = Display::return_message( + get_lang('AccountInactive'), + 'error', + false + ); + + $msg .= '

+ '.get_lang('BackHome').'

'; + + if (api_is_anonymous()) { + $form = api_get_not_allowed_login_form(); + $msg .= '
'; + $msg .= $form->returnForm(); + $msg .= '
'; + } + + $tpl->assign('content', $msg); + $tpl->display_one_col_template(); + exit; + } + + return $data; +} + /** * Function used to protect a teacher script. * The function blocks access when the user has no teacher rights. @@ -1168,6 +1227,7 @@ function api_block_anonymous_users($printHeaders = true) return false; } + api_block_inactive_user(); return true; } @@ -2590,6 +2650,20 @@ function get_status_from_code($status_code) return get_lang('SessionsAdmin', ''); case DRH: return get_lang('Drh', ''); + case ANONYMOUS: + return get_lang('Anonymous', ''); + case PLATFORM_ADMIN: + return get_lang('Administrator', ''); + case SESSION_COURSE_COACH: + return get_lang('SessionCourseCoach', ''); + case SESSION_GENERAL_COACH: + return get_lang('SessionGeneralCoach', ''); + case COURSE_TUTOR: + return get_lang('CourseAssistant', ''); + case STUDENT_BOSS: + return get_lang('StudentBoss', ''); + case INVITEE: + return get_lang('Invitee', ''); } } diff --git a/public/main/inc/lib/auth.lib.php b/public/main/inc/lib/auth.lib.php index 47ab09c773..1fb05d0f03 100644 --- a/public/main/inc/lib/auth.lib.php +++ b/public/main/inc/lib/auth.lib.php @@ -21,9 +21,11 @@ class Auth /** * This function get all the courses in the particular user category. * + * @param bool $hidePrivate + * * @return array */ - public function getCoursesInCategory() + public function getCoursesInCategory($hidePrivate = true) { $user_id = api_get_user_id(); @@ -31,7 +33,7 @@ class Auth $TABLECOURS = Database::get_main_table(TABLE_MAIN_COURSE); $TABLECOURSUSER = Database::get_main_table(TABLE_MAIN_COURSE_USER); $avoidCoursesCondition = CoursesAndSessionsCatalog::getAvoidCourseCondition(); - $visibilityCondition = CourseManager::getCourseVisibilitySQLCondition('course', true); + $visibilityCondition = CourseManager::getCourseVisibilitySQLCondition('course', true, $hidePrivate); $sql = "SELECT course.id as real_id, @@ -301,7 +303,7 @@ class Auth * * @return bool True if it success */ - public function remove_user_from_course($course_code) + public function remove_user_from_course($course_code, $sessionId = 0) { $tbl_course_user = Database::get_main_table(TABLE_MAIN_COURSE_USER); @@ -311,6 +313,9 @@ class Auth $result = true; $courseInfo = api_get_course_info($course_code); + if ('1' !== $courseInfo['unsubscribe']) { + return false; + } $courseId = $courseInfo['real_id']; // we check (once again) if the user is not course administrator @@ -327,7 +332,9 @@ class Auth $result = false; } - CourseManager::unsubscribe_user($current_user_id, $course_code); + if ($result) { + CourseManager::unsubscribe_user($current_user_id, $course_code, $sessionId); + } return $result; } diff --git a/public/main/inc/lib/chat.lib.php b/public/main/inc/lib/chat.lib.php index fdc614ed5c..5307aeb369 100644 --- a/public/main/inc/lib/chat.lib.php +++ b/public/main/inc/lib/chat.lib.php @@ -400,7 +400,7 @@ class Chat extends Model $params = []; $params['from_user'] = (int) $fromUserId; $params['to_user'] = (int) $to_user_id; - $params['message'] = $message; + $params['message'] = $messagesan; $params['sent'] = api_get_utc_datetime(); if (!empty($fromUserId) && !empty($to_user_id)) { diff --git a/public/main/inc/lib/conditional_login.class.php b/public/main/inc/lib/conditional_login.class.php index 2899bfcf30..76c1f7ff9b 100644 --- a/public/main/inc/lib/conditional_login.class.php +++ b/public/main/inc/lib/conditional_login.class.php @@ -11,7 +11,7 @@ class ConditionalLogin /** * Check conditions based in the $login_conditions see conditional_login.php file. * - * @param type $user + * @param array $user */ public static function check_conditions($user) { diff --git a/public/main/inc/lib/course.lib.php b/public/main/inc/lib/course.lib.php index 0895600a57..3744ef68f7 100644 --- a/public/main/inc/lib/course.lib.php +++ b/public/main/inc/lib/course.lib.php @@ -4188,16 +4188,22 @@ class CourseManager $user_id = api_get_user_id(); $course_info = api_get_course_info_by_id($course['real_id']); $course_visibility = (int) $course_info['visibility']; + $allowUnsubscribe = api_get_configuration_value('enable_unsubscribe_button_on_my_course_page'); - if (COURSE_VISIBILITY_HIDDEN === $course_visibility) { + if ($course_visibility === COURSE_VISIBILITY_HIDDEN) { return ''; } + $sessionInfo = []; + if (!empty($session_id)) { + $sessionInfo = api_get_session_info($session_id); + } $userInCourseStatus = self::getUserInCourseStatus($user_id, $course_info['real_id']); $course_info['status'] = empty($session_id) ? $userInCourseStatus : STUDENT; $course_info['id_session'] = $session_id; $is_coach = api_is_coach($session_id, $course_info['real_id']); + $isAdmin = api_is_platform_admin(); // Display course entry. // Show a hyperlink to the course, unless the course is closed and user is not course admin. @@ -4223,15 +4229,15 @@ class CourseManager $notifications .= Display::show_notification($course_info); } + $sessionCourseAvailable = false; if ($session_accessible) { - if (COURSE_VISIBILITY_CLOSED != $course_visibility || - COURSEMANAGER == $userInCourseStatus + if ($course_visibility != COURSE_VISIBILITY_CLOSED || + $userInCourseStatus == COURSEMANAGER ) { if (empty($course_info['id_session'])) { $course_info['id_session'] = 0; } - $sessionCourseAvailable = false; $sessionCourseStatus = api_get_session_visibility($session_id, $course_info['real_id']); if (in_array( @@ -4295,12 +4301,25 @@ class CourseManager $repo = $entityManager->getRepository(SequenceResource::class); $sequences = $repo->getRequirements($course_info['real_id'], SequenceResource::COURSE_TYPE); - $sequenceList = $repo->checkRequirementsForUser($sequences, SequenceResource::COURSE_TYPE, $user_id); + $sequenceList = $repo->checkRequirementsForUser( + $sequences, + SequenceResource::COURSE_TYPE, + $user_id, + $session_id + ); $completed = $repo->checkSequenceAreCompleted($sequenceList); //var_dump($course_info['real_id'], $completed); $params['completed'] = $completed; $params['requirements'] = ''; + if ($isAdmin || + $userInCourseStatus === COURSEMANAGER || + $is_coach || + $user_id == $sessionInfo['session_admin_id'] + ) { + $params['completed'] = true; + $params['requirements'] = ''; + } else { if ($sequences && false === $completed) { $hasRequirements = false; foreach ($sequences as $sequence) { @@ -4314,8 +4333,10 @@ class CourseManager $course_info['real_id'], SequenceResource::COURSE_TYPE, false, - false + false, + $session_id ); + } } } @@ -4324,38 +4345,47 @@ class CourseManager $params['edit_actions'] = ''; $params['document'] = ''; $params['category'] = $course_info['categoryName']; + if ($course_visibility != COURSE_VISIBILITY_CLOSED && + false === $is_coach && $allowUnsubscribe && '1' === $course_info['unsubscribe']) { + $params['unregister_button'] = + CoursesAndSessionsCatalog::return_unregister_button( + ['code' => $course_info['code']], + Security::get_existing_token(), + '', + '', + $session_id + ); + } if (COURSE_VISIBILITY_CLOSED != $course_visibility && COURSE_VISIBILITY_HIDDEN != $course_visibility ) { - if (api_is_platform_admin()) { - $params['edit_actions'] .= api_get_path(WEB_CODE_PATH).'course_info/infocours.php?cid='.$course_info['real_id']; + if ($isAdmin) { + $params['edit_actions'] .= api_get_path(WEB_CODE_PATH).'course_info/infocours.php?cidReq='.$course_info['code']; if ($load_dirs) { $params['document'] .= ''. Display::returnFontAwesomeIcon('folder-open').''; $params['document'] .= Display::div('', [ - 'id' => 'document_result_'.$course_info['real_id'].'_'.$course_info['id_session'], + 'id' => 'document_result_'.$course_info['real_id'].'_'.$session_id, 'class' => 'document_preview_container', ]); } } } if ('true' === api_get_setting('display_teacher_in_courselist')) { - $teacher_list = self::getTeachersFromCourse( + $teacher_list = self::getTeachersFromCourse($course_info['real_id'], true); + $course_coachs = self::get_coachs_from_course( + $session_id, $course_info['real_id'], true ); - $course_coachs = self::get_coachs_from_course( - $course_info['id_session'], - $course_info['real_id'] - ); $params['teachers'] = $teacher_list; - if ((STUDENT == $course_info['status'] && !empty($course_info['id_session'])) || - ($is_coach && COURSEMANAGER != $course_info['status']) + if (($course_info['status'] == STUDENT && !empty($session_id)) || + ($is_coach && $course_info['status'] != COURSEMANAGER) ) { $params['coaches'] = $course_coachs; } @@ -4363,44 +4393,42 @@ class CourseManager $special = isset($course['special_course']) ? true : false; $params['title'] = $session_title; $params['special'] = $special; - if ('true' === api_get_setting('display_coursecode_in_courselist')) { + if (api_get_setting('display_coursecode_in_courselist') === 'true') { $params['visual_code'] = '('.$course_info['visual_code'].')'; } $params['extra'] = ''; $html = $params; $session_category_id = null; - if (1) { - $session = ''; $active = false; - if (!empty($course_info['id_session'])) { - $session = api_get_session_info($course_info['id_session']); + if (!empty($session_id)) { $sessionCoachName = ''; - if (!empty($session['id_coach'])) { - $coachInfo = api_get_user_info($session['id_coach']); + if (!empty($sessionInfo['id_coach'])) { + $coachInfo = api_get_user_info($sessionInfo['id_coach']); $sessionCoachName = $coachInfo['complete_name']; } $session_category_id = self::get_session_category_id_by_session_id($course_info['id_session']); if ( - '0000-00-00 00:00:00' === $session['access_start_date'] || empty($session['access_start_date']) || - '0000-00-00' === $session['access_start_date'] + $sessionInfo['access_start_date'] === '0000-00-00 00:00:00' || + empty($sessionInfo['access_start_date']) || + $sessionInfo['access_start_date'] === '0000-00-00' ) { - $session['dates'] = ''; - if ('true' === api_get_setting('show_session_coach')) { - $session['coach'] = get_lang('General coach').': '.$sessionCoachName; + $sessionInfo['dates'] = ''; + if (api_get_setting('show_session_coach') === 'true') { + $sessionInfo['coach'] = get_lang('GeneralCoach').': '.$sessionCoachName; } $active = true; } else { - $session['dates'] = ' - '. - get_lang('From').' '.$session['access_start_date'].' '. - get_lang('To').' '.$session['access_end_date']; - if ('true' === api_get_setting('show_session_coach')) { - $session['coach'] = get_lang('General coach').': '.$sessionCoachName; + $sessionInfo['dates'] = ' - '. + get_lang('From').' '.$sessionInfo['access_start_date'].' '. + get_lang('To').' '.$sessionInfo['access_end_date']; + if (api_get_setting('show_session_coach') === 'true') { + $sessionInfo['coach'] = get_lang('GeneralCoach').': '.$sessionCoachName; } - $date_start = $session['access_start_date']; - $date_end = $session['access_end_date']; + $date_start = $sessionInfo['access_start_date']; + $date_end = $sessionInfo['access_end_date']; $active = !$date_end ? ($date_start <= $now) : ($date_start <= $now && $date_end >= $now); } } @@ -4412,7 +4440,7 @@ class CourseManager $user_course_category, $html, $course_info['id_session'], - $session, + $sessionInfo, 'active' => $active, 'session_category_id' => $session_category_id, ]; @@ -4430,9 +4458,6 @@ class CourseManager $output['skill']['icon'] = $skill->getIcon(); } } - } else { - $output = [$course_info['user_course_cat'], $html]; - } return $output; } @@ -4457,14 +4482,14 @@ class CourseManager if (!empty($course_info)) { $cb = new CourseBuilder('', $course_info); - $course = $cb->build($source_session_id, $source_course_code, true); - $course_restorer = new CourseRestorer($course); - $course_restorer->skip_content = $params; - $course_restorer->restore( + $course = $cb->build($source_session_id, $source_course_code, $withBaseContent); + $restorer = new CourseRestorer($course); + $restorer->skip_content = $params; + $restorer->restore( $destination_course_code, $destination_session_id, true, - true + $withBaseContent ); return true; @@ -4481,6 +4506,7 @@ class CourseManager * @param int source session id * @param int destination session id * @param array $params + * @param bool $copySessionContent * * @return array */ @@ -4489,7 +4515,8 @@ class CourseManager $source_course_code, $source_session_id = 0, $destination_session_id = 0, - $params = [] + $params = [], + $copySessionContent = false ) { $source_course_info = api_get_course_info($source_course_code); if (!empty($source_course_info)) { @@ -4506,7 +4533,8 @@ class CourseManager $source_session_id, $new_course_info['code'], $destination_session_id, - $params + $params, + true ); if ($result) { return $new_course_info; @@ -5285,18 +5313,19 @@ class CourseManager * * @param string $courseTableAlias Alias of the course table * @param bool $hideClosed Whether to hide closed and hidden courses + * @param bool $checkHidePrivate * * @return string SQL conditions */ - public static function getCourseVisibilitySQLCondition( - $courseTableAlias, - $hideClosed = false - ) { + public static function getCourseVisibilitySQLCondition($courseTableAlias, $hideClosed = false, $checkHidePrivate = true) + { $visibilityCondition = ''; - $hidePrivate = api_get_setting('course_catalog_hide_private'); - if ('true' === $hidePrivate) { + if ($checkHidePrivate) { + $hidePrivateSetting = api_get_setting('course_catalog_hide_private'); + if ('true' === $hidePrivateSetting) { $visibilityCondition .= " AND $courseTableAlias.visibility <> ".COURSE_VISIBILITY_REGISTERED; } + } if ($hideClosed) { $visibilityCondition .= " AND $courseTableAlias.visibility NOT IN (".COURSE_VISIBILITY_CLOSED.','.COURSE_VISIBILITY_HIDDEN.')'; } diff --git a/public/main/inc/lib/course_category.lib.php b/public/main/inc/lib/course_category.lib.php index cd51cdc3d2..dc732908fb 100644 --- a/public/main/inc/lib/course_category.lib.php +++ b/public/main/inc/lib/course_category.lib.php @@ -552,10 +552,11 @@ class CourseCategory ).' '.$category['name'].' ('.$category['code'].')', $url ); + $countCourses = self::countCoursesInCategory($category['code'], null, false); $content = [ $title, $category['children_count'], - $category['nbr_courses'], + $countCourses, implode('', $actions), ]; $column = 0; @@ -567,9 +568,8 @@ class CourseCategory } return $table->toHtml(); - } else { - return Display::return_message(get_lang('There are no categories here'), 'warning'); } + return Display::return_message(get_lang('NoCategories'), 'warning'); } /** @@ -605,8 +605,16 @@ class CourseCategory ORDER BY tree_pos"; $res = Database::query($sql); + $categoryToAvoid = ''; + if (!api_is_platform_admin()) { + $categoryToAvoid = api_get_configuration_value('course_category_code_to_use_as_model'); + } $categories[''] = '-'; while ($cat = Database::fetch_array($res)) { + $categoryCode = $cat['code']; + if (!empty($categoryToAvoid) && $categoryToAvoid == $categoryCode) { + continue; + } $categories[$cat['id']] = '('.$cat['code'].') '.$cat['name']; ksort($categories); } @@ -614,21 +622,18 @@ class CourseCategory return $categories; } - /** - * @param string $category_code - * @param string $searchTerm - * - * @return int - */ - public static function countCoursesInCategory($category_code = '', $searchTerm = '') - { + public static function getCoursesInCategory($category_code = '', $searchTerm = '', $avoidCourses = true, $conditions = [], $getCount = false) +{ $tbl_course = Database::get_main_table(TABLE_MAIN_COURSE); $tblCourseCategory = Database::get_main_table(TABLE_MAIN_CATEGORY); + $avoidCoursesCondition = ''; + if ($avoidCourses) { + $avoidCoursesCondition = CoursesAndSessionsCatalog::getAvoidCourseCondition(); + } $categoryCode = Database::escape_string($category_code); $searchTerm = Database::escape_string($searchTerm); - $avoidCoursesCondition = CoursesAndSessionsCatalog::getAvoidCourseCondition(); $visibilityCondition = CourseManager::getCourseVisibilitySQLCondition('course', true); $categoryJoin = ''; @@ -669,9 +674,13 @@ class CourseCategory "; $result = Database::query($sql); - $row = Database::fetch_array($result); + if ($getCount) { + $row = Database::fetch_array($result); - return (int) $row['count']; + return (int) $row['count']; + } + + return Database::store_result($result, 'ASSOC'); } /** diff --git a/public/main/inc/lib/plugin.lib.php b/public/main/inc/lib/plugin.lib.php index c3eecfa552..637592b780 100644 --- a/public/main/inc/lib/plugin.lib.php +++ b/public/main/inc/lib/plugin.lib.php @@ -715,21 +715,27 @@ class AppPlugin } $form->addHtml('
'); - $form->addHtml(' + $form->addHtml( + ' - '); - $form->addHtml(' + ' + ); + $form->addHtml( + '
- '); + ' + ); $groups = []; foreach ($obj->course_settings as $setting) { @@ -748,30 +754,30 @@ class AppPlugin if (isset($setting['init_value']) && 1 == $setting['init_value']) { $element->setChecked(true); } - } - } - - if (isset($setting['init_value']) && $setting['init_value'] == 1) { - $element->setChecked(true); - } - $form->addElement($element); - - if (isset($setting['group'])) { - $groups[$setting['group']][] = $element; - } } } - foreach ($groups as $k => $v) { - $form->addGroup($groups[$k], $k, [$obj->get_lang($k)]); + + if (isset($setting['init_value']) && $setting['init_value'] == 1) { + $element->setChecked(true); + } + $form->addElement($element); + + if (isset($setting['group'])) { + $groups[$setting['group']][] = $element; } - $form->addButtonSave(get_lang('Save settings')); - $form->addHtml(' -
-
- '); - $form->addHtml('
'); } } + foreach ($groups as $k => $v) { + $form->addGroup($groups[$k], $k, [$obj->get_lang($k)]); + } + $form->addButtonSave(get_lang('Save settings')); + $form->addHtml( + ' + + + ' + ); + $form->addHtml(''); } /**