From 562606f6180575aeaf70ff6aaead987e669a6751 Mon Sep 17 00:00:00 2001 From: Julio Date: Thu, 3 Oct 2019 12:25:48 +0200 Subject: [PATCH] Minor - merge from 1.11.x --- main/admin/course_category.php | 2 +- main/admin/course_edit.php | 8 - main/admin/user_import.php | 15 +- main/admin/user_list.php | 4 +- main/admin/usergroup_users.php | 101 +++-- main/announcements/announcements.php | 2 +- main/attendance/attendance_list.php | 1 - main/auth/courses.php | 111 +---- main/auth/courses_categories.php | 354 +++++++++++---- main/auth/courses_controller.php | 298 +------------ main/auth/courses_list.php | 323 -------------- main/auth/hrm_courses.php | 34 +- main/auth/inscription.php | 5 +- main/calendar/agenda_js.php | 4 + main/calendar/download.php | 8 +- main/course_home/course_home.php | 3 +- main/document/recycle.php | 6 +- main/document/showinframes.php | 20 +- main/exercise/TestCategory.php | 78 ---- main/exercise/exercise.class.php | 25 +- main/exercise/exercise_show.php | 87 +++- main/exercise/exercise_submit.php | 4 +- main/exercise/fill_blanks.class.php | 62 --- main/forum/forumfunction.inc.php | 2 +- main/forum/viewforum.php | 2 +- main/gradebook/certificate_report.php | 2 - .../gradebook_display_certificate.php | 14 +- main/gradebook/gradebook_display_summary.php | 5 - main/gradebook/gradebook_flatview.php | 2 +- main/gradebook/lib/GradebookUtils.php | 30 +- main/gradebook/lib/be/category.class.php | 132 ++++-- main/gradebook/lib/be/exerciselink.class.php | 4 - main/gradebook/lib/fe/displaygradebook.php | 2 +- .../gradebook/lib/fe/gradebooktable.class.php | 13 +- .../lib/flatview_data_generator.class.php | 22 - main/inc/ajax/course_home.ajax.php | 11 +- main/inc/ajax/install.ajax.php | 60 ++- main/inc/ajax/message.ajax.php | 2 - main/inc/ajax/model.ajax.php | 26 +- main/inc/lib/AnnouncementManager.php | 20 +- main/inc/lib/Compilatio.php | 2 +- .../lib/CoursesAndSessionsCatalog.class.php | 3 +- main/inc/lib/agenda.lib.php | 14 +- main/inc/lib/attendance.lib.php | 20 +- main/inc/lib/auth.lib.php | 30 +- main/inc/lib/banner.lib.php | 5 +- main/inc/lib/certificate.lib.php | 7 +- main/inc/lib/course.lib.php | 18 +- main/inc/lib/course_category.lib.php | 100 ++--- main/inc/lib/course_home.lib.php | 17 +- main/inc/lib/display.lib.php | 27 ++ main/inc/lib/extra_field.lib.php | 1 + main/inc/lib/extra_field_value.lib.php | 35 -- .../lib/formvalidator/FormValidator.class.php | 5 + main/inc/lib/link.lib.php | 121 ----- main/inc/lib/plugin.lib.php | 101 +++-- main/inc/lib/sessionmanager.lib.php | 92 ++-- main/inc/lib/social.lib.php | 261 ++++------- main/inc/lib/sortable_table.class.php | 76 +++- main/inc/lib/thematic.lib.php | 5 +- main/inc/lib/tracking.lib.php | 373 ++-------------- main/inc/lib/usergroup.lib.php | 57 ++- main/inc/lib/usermanager.lib.php | 220 +-------- main/inc/lib/userportal.lib.php | 34 +- main/inc/lib/webservices/Rest.php | 21 +- main/inc/lib/webservices/WebService.class.php | 8 + main/lp/learnpath.class.php | 103 +++-- main/lp/lp_add.php | 10 +- main/lp/lp_controller.php | 35 +- main/lp/lp_subscribe_users.php | 13 +- main/session/resume_session.php | 13 +- main/survey/ch_comment.php | 6 - main/survey/preview.php | 421 ++++++++---------- main/survey/question.php | 4 +- main/survey/surveyUtil.class.php | 64 --- main/ticket/new_ticket.php | 10 - main/webservices/access_url.php | 2 - main/webservices/api/v2.php | 26 ++ main/work/work.lib.php | 4 +- main/work/work_list.php | 53 ++- plugin/bbb/lib/bbb.lib.php | 2 +- plugin/bbb/listing.php | 2 +- plugin/bbb/view/listing.tpl | 2 +- .../src/CustomCertificatePlugin.php | 2 +- plugin/customcertificate/src/index.php | 4 +- .../src/print_certificate.php | 4 +- plugin/redirection/RedirectionPlugin.php | 2 +- .../studentfollowup/StudentFollowUpPlugin.php | 25 +- 88 files changed, 1472 insertions(+), 2892 deletions(-) delete mode 100755 main/auth/courses_list.php diff --git a/main/admin/course_category.php b/main/admin/course_category.php index 992a6352a2..3960aa9985 100755 --- a/main/admin/course_category.php +++ b/main/admin/course_category.php @@ -113,7 +113,7 @@ if ($action == 'add' || $action == 'edit') { get_lang('CategoryName'), true, false, - ['ToolbarSet' => 'Minimal'] + ['ToolbarSet' => 'TitleAsHtml'] ); } else { $form->addElement('text', 'name', get_lang("CategoryName")); diff --git a/main/admin/course_edit.php b/main/admin/course_edit.php index 70fe530db8..f195a63de5 100755 --- a/main/admin/course_edit.php +++ b/main/admin/course_edit.php @@ -16,7 +16,6 @@ $this_section = SECTION_PLATFORM_ADMIN; api_protect_admin_script(); $course_table = Database::get_main_table(TABLE_MAIN_COURSE); -$course_user_table = Database::get_main_table(TABLE_MAIN_COURSE_USER); $em = Database::getManager(); /** @var CourseCategoryRepository $courseCategoriesRepo */ $courseCategoriesRepo = $em->getRepository('ChamiloCoreBundle:CourseCategory'); @@ -221,7 +220,6 @@ if (!empty($coursesInSession) && $allowEditSessionCoaches) { $sessionTeachers = []; foreach ($coaches as $coachId) { - $userInfo = api_get_user_info($coachId); $sessionTeachers[] = $coachId; if (isset($teachers[$coachId])) { @@ -230,10 +228,6 @@ if (!empty($coursesInSession) && $allowEditSessionCoaches) { } $groupName = 'session_coaches_'.$sessionId; - $platformTeacherId = 'platform_teachers_by_session_'.$sessionId; - $coachId = 'coaches_by_session_'.$sessionId; - $platformTeacherName = 'platform_teachers_by_session'; - $coachName = 'coaches_by_session'; $sessionUrl = api_get_path(WEB_CODE_PATH).'session/resume_session.php?id_session='.$sessionId; $form->addElement( 'advmultiselect', @@ -508,7 +502,6 @@ function mysort(a, b) { function valide() { // Checking all multiple - $('select').filter(function() { if ($(this).attr('multiple')) { $(this).find('option').each(function() { @@ -516,7 +509,6 @@ function valide() { }); } }); - //document.update_course.submit(); } "; diff --git a/main/admin/user_import.php b/main/admin/user_import.php index 2c1731c98d..df742e3000 100644 --- a/main/admin/user_import.php +++ b/main/admin/user_import.php @@ -752,10 +752,10 @@ if (api_get_configuration_value('plugin_redirection_enabled')) {

:

-LastName;FirstName;Email;UserName;Password;AuthSource;OfficialCode;PhoneNumber;Status;ExpiryDate; 0) {
+LastName;FirstName;Email;UserName;Password;AuthSource;OfficialCode;language;PhoneNumber;Status;ExpiryDate; 0) {
     echo implode(';', $list).';';
 } ?>Courses;Sessions;ClassId;
-xxx;xxx;xxx;xxx;xxx;;xxx;xxx;user/teacher/drh;0000-00-00 00:00:00; 0) {
+xxx;xxx;xxx;xxx;xxx;;xxx;english/spanish/(other);xxx;user/teacher/drh;0000-00-00 00:00:00; 0) {
     echo implode(';', $list_reponse).';';
 } ?>xxx1|xxx2|xxx3;sessionId|sessionId|sessionId;1;
@@ -773,17 +773,18 @@ if (api_get_configuration_value('plugin_redirection_enabled')) { <AuthSource></AuthSource> <Email>xxx</Email> <OfficialCode>xxx</OfficialCode> + <language>english/spanish/(other)</language> <PhoneNumber>xxx</PhoneNumber> - <Status>user/teacher/drh', $result_xml; - echo ''; -} ?></Status> + echo '
'; +} ?> <Courses>xxx1|xxx2|xxx3</Courses> <Sessions>sessionId|sessionId|sessionId</Sessions> <ClassId>1</ClassId> - </Contact> + </Contact> </Contacts> -
+ '.$name.''; } diff --git a/main/admin/usergroup_users.php b/main/admin/usergroup_users.php index 16af867dcf..0cef6a5c27 100644 --- a/main/admin/usergroup_users.php +++ b/main/admin/usergroup_users.php @@ -4,7 +4,7 @@ /** * @package chamilo.admin */ -$cidReset = true; + require_once __DIR__.'/../inc/global.inc.php'; $this_section = SECTION_PLATFORM_ADMIN; @@ -13,15 +13,15 @@ $id = isset($_GET['id']) ? (int) $_GET['id'] : 0; $usergroup = new UserGroup(); $userGroupInfo = $usergroup->get($id); - if (empty($userGroupInfo)) { api_not_allowed(true); } -$usergroup->protectScript($userGroupInfo); +$usergroup->protectScript($userGroupInfo, true, true); +$allowEdit = api_is_platform_admin() || isset($userGroupInfo['author_id']) && $userGroupInfo['author_id'] == api_get_user_id(); $calendarPlugin = null; -if (api_get_plugin_setting('learning_calendar', 'enabled') === 'true') { +if ($allowEdit && api_get_plugin_setting('learning_calendar', 'enabled') === 'true') { $calendarPlugin = LearningCalendarPlugin::create(); } @@ -31,10 +31,18 @@ $action = isset($_GET['action']) ? Security::remove_XSS($_GET['action']) : null; $userId = isset($_GET['user_id']) ? (int) $_GET['user_id'] : 0; $calendarId = isset($_REQUEST['calendar_id']) ? (int) $_REQUEST['calendar_id'] : 0; -// setting breadcrumbs -$interbreadcrumb[] = ['url' => 'usergroups.php', 'name' => get_lang('Classes')]; +$courseInfo = api_get_course_info(); +if (empty($courseInfo)) { + $interbreadcrumb[] = ['url' => 'usergroups.php', 'name' => get_lang('Classes')]; +} else { + $interbreadcrumb[] = ['url' => api_get_path(WEB_CODE_PATH).'user/class.php?'.api_get_cidreq(), 'name' => get_lang('Classes')]; +} $interbreadcrumb[] = ['url' => '#', 'name' => $userGroupInfo['name']]; +if (!empty($action)) { + $usergroup->protectScript($userGroupInfo); +} + switch ($action) { case 'add_calendar': $form = new FormValidator( @@ -140,7 +148,7 @@ $column_model = [ ], ]; -if (api_get_plugin_setting('learning_calendar', 'enabled') === 'true') { +if ($calendarPlugin) { $columns = [ get_lang('Name'), get_lang('Calendar'), @@ -195,25 +203,33 @@ $extraParams['autowidth'] = 'true'; $extraParams['height'] = 'auto'; $extraParams['sortname'] = 'name'; $extraParams['sortorder'] = 'desc'; -$extraParams['multiselect'] = true; +$extraParams['multiselect'] = $allowEdit; $deleteIcon = Display::return_icon('delete.png', get_lang('Delete'), null, ICON_SIZE_SMALL); $urlStats = api_get_path(WEB_CODE_PATH); -//$addCalendar = ''.Display::return_icon('agenda.png', get_lang('Agenda'), '', ICON_SIZE_SMALL).''; - $reportingIcon = Display::return_icon('statistics.png', get_lang('Reporting'), '', ICON_SIZE_SMALL); $controlPoint = Display::return_icon('add.png', get_lang('ControlPoint'), '', ICON_SIZE_SMALL); +$link = ''; + +if ($calendarPlugin) { + $link = ''.$controlPoint.''; +} + +$deleteButton = ''; +if ($allowEdit) { + $deleteButton = ''.$deleteIcon.''; +} //return \''.Display::return_icon('edit.png', get_lang('Edit'), '', ICON_SIZE_SMALL).''. // With this function we can add actions to the jgrid $action_links = ' function action_formatter(cellvalue, options, rowObject) { var value = rowObject[5]; return \''. - ' '.$controlPoint.''. + ' '.$link. ' '.$reportingIcon.''. - ' '.$deleteIcon.'\'; + ' '.$deleteButton.' \'; } function extra_formatter(cellvalue, options, rowObject) { @@ -237,40 +253,43 @@ function extra_formatter(cellvalue, options, rowObject) { $deleteUrl = api_get_path(WEB_AJAX_PATH).'usergroup.ajax.php?a=delete_user_in_usergroup&group_id='.$id; -$form = new FormValidator( - 'add_multiple_calendar', - 'post', - api_get_self().'?id='.$id.'&action=add_multiple_users_to_calendar' -); -$calendarPlugin->getAddUserToCalendarForm($form); -$form->addHidden('user_list', ''); -$form->addButtonSave(get_lang('Add')); +if ($calendarPlugin) { + $form = new FormValidator( + 'add_multiple_calendar', + 'post', + api_get_self().'?id='.$id.'&action=add_multiple_users_to_calendar' + ); + $calendarPlugin->getAddUserToCalendarForm($form); + $form->addHidden('user_list', ''); + $form->addButtonSave(get_lang('Add')); +} ?> - + - + showGroupTypeSetting = true; // Action handling: Adding a note -if ($action === 'delete' && is_numeric($_GET['id'])) { +if ($allowEdit && $action === 'delete' && is_numeric($_GET['id'])) { $res = $usergroup->delete_user_rel_group($_GET['user_id'], $_GET['id']); Display::addFlash(Display::return_message(get_lang('Deleted'), 'confirmation')); header('Location: '.api_get_self().'?id='.$id); exit; -} else { - $usergroup->displayToolBarUserGroupUsers(); } +$usergroup->displayToolBarUserGroupUsers(); + Display::display_footer(); diff --git a/main/announcements/announcements.php b/main/announcements/announcements.php index 6a1f0be601..52aaac66c7 100755 --- a/main/announcements/announcements.php +++ b/main/announcements/announcements.php @@ -43,7 +43,7 @@ if (!empty($sessionId) && $drhHasAccessToSessionContent) { $allowToEdit = $allowToEdit || api_is_drh(); } -// Configuration settings +// Database Table Definitions $tbl_announcement = Database::get_course_table(TABLE_ANNOUNCEMENT); $tbl_item_property = Database::get_course_table(TABLE_ITEM_PROPERTY); diff --git a/main/attendance/attendance_list.php b/main/attendance/attendance_list.php index 16cf03bd99..5516a6f27e 100755 --- a/main/attendance/attendance_list.php +++ b/main/attendance/attendance_list.php @@ -51,7 +51,6 @@ if (api_is_allowed_to_edit(null, true)) { } $table->set_form_actions($actions); } - if ($table->get_total_number_of_items() > 0) { $table->display(); } diff --git a/main/auth/courses.php b/main/auth/courses.php index 00a7760b1a..5a5ca36e2b 100755 --- a/main/auth/courses.php +++ b/main/auth/courses.php @@ -42,10 +42,7 @@ if (api_is_platform_admin() || api_is_course_admin() || api_is_allowed_to_create // filter actions $actions = [ - 'sortmycourses', - 'createcoursecategory', 'subscribe', - 'deletecoursecategory', 'display_courses', 'display_random_courses', 'subscribe_user_with_password', @@ -53,7 +50,6 @@ $actions = [ 'subscribe_to_session', 'search_tag', 'search_session', - 'set_collapsable', 'subscribe_course_validation', 'subscribe_course', ]; @@ -72,73 +68,19 @@ if (empty($nameTools)) { } else { if (!in_array( $action, - ['sortmycourses', 'createcoursecategory', 'display_random_courses', 'display_courses', 'subscribe'] + ['display_random_courses', 'display_courses', 'subscribe'] )) { $interbreadcrumb[] = [ 'url' => api_get_path(WEB_CODE_PATH).'auth/courses.php', 'name' => get_lang('CourseManagement'), ]; } - - if ($action === 'createcoursecategory') { - $interbreadcrumb[] = [ - 'url' => api_get_path(WEB_CODE_PATH).'auth/courses.php?action=sortmycourses', - 'name' => get_lang('SortMyCourses'), - ]; - } $interbreadcrumb[] = ['url' => '#', 'name' => $nameTools]; } // course description controller object $courseController = new CoursesController(); -// We are moving a course or category of the user up/down the list (=Sort My Courses). -if (isset($_GET['move'])) { - if (isset($_GET['course'])) { - $courseController->move_course( - $_GET['move'], - $_GET['course'], - $_GET['category'] - ); - } - if (isset($_GET['category']) && !isset($_GET['course'])) { - $courseController->move_category($_GET['move'], $_GET['category']); - } -} - -// We are moving the course of the user to a different user defined course category (=Sort My Courses). -if (isset($_POST['submit_change_course_category'])) { - if (!empty($_POST['sec_token']) && $ctok == $_POST['sec_token']) { - $courseController->change_course_category( - $_POST['course_2_edit_category'], - $_POST['course_categories'] - ); - } -} - -// We edit course category -if (isset($_POST['submit_edit_course_category']) && - isset($_POST['title_course_category']) && - strlen(trim($_POST['title_course_category'])) > 0 -) { - if (!empty($_POST['sec_token']) && $ctok == $_POST['sec_token']) { - $courseController->edit_course_category( - $_POST['title_course_category'], - $_POST['edit_course_category'] - ); - } -} - -// We are creating a new user defined course category (= Create Course Category). -if (isset($_POST['create_course_category']) && - isset($_POST['title_course_category']) && - strlen(trim($_POST['title_course_category'])) > 0 -) { - if (!empty($_POST['sec_token']) && $ctok == $_POST['sec_token']) { - $courseController->addCourseCategory($_POST['title_course_category']); - } -} - // search courses if (isset($_REQUEST['search_course'])) { if (!empty($_REQUEST['sec_token']) && $ctok == $_REQUEST['sec_token']) { @@ -173,18 +115,6 @@ if (isset($_POST['unsubscribe'])) { } switch ($action) { - case 'deletecoursecategory': - // we are deleting a course category - if (isset($_GET['id'])) { - if (Security::check_token('get')) { - $courseController->delete_course_category($_GET['id']); - header('Location: '.api_get_self()); - exit; - } - } - - $courseController->courseList($action); - break; case 'subscribe_course': if (api_is_anonymous()) { header('Location: '.api_get_path(WEB_CODE_PATH).'auth/inscription.php?c='.$courseCodeToSubscribe); @@ -237,12 +167,6 @@ switch ($action) { $template->assign('content', $content); $template->display_one_col_template(); break; - case 'createcoursecategory': - $courseController->categoryList(); - break; - case 'sortmycourses': - $courseController->courseList($action); - break; case 'subscribe': if (!$user_can_view_page) { api_not_allowed(true); @@ -366,37 +290,4 @@ switch ($action) { $courseController->sessionListBySearch($limit); break; - case 'set_collapsable': - api_block_anonymous_users(); - - if (!api_get_configuration_value('allow_user_course_category_collapsable')) { - api_not_allowed(true); - } - - $userId = api_get_user_id(); - $categoryId = isset($_REQUEST['categoryid']) ? (int) $_REQUEST['categoryid'] : 0; - $option = isset($_REQUEST['option']) ? (int) $_REQUEST['option'] : 0; - $redirect = isset($_REQUEST['redirect']) ? $_REQUEST['redirect'] : 0; - - if (empty($userId) || empty($categoryId)) { - api_not_allowed(true); - } - - $table = Database::get_main_table(TABLE_USER_COURSE_CATEGORY); - $sql = "UPDATE $table - SET collapsed = $option - WHERE user_id = $userId AND id = $categoryId"; - Database::query($sql); - Display::addFlash(Display::return_message(get_lang('Updated'))); - - if ($redirect === 'home') { - $url = api_get_path(WEB_PATH).'user_portal.php'; - header('Location: '.$url); - exit; - } - - $url = api_get_path(WEB_CODE_PATH).'auth/courses.php?action=sortmycourses'; - header('Location: '.$url); - exit; - break; } diff --git a/main/auth/courses_categories.php b/main/auth/courses_categories.php index 1958153055..d370fea3dd 100755 --- a/main/auth/courses_categories.php +++ b/main/auth/courses_categories.php @@ -33,9 +33,7 @@ if ($showSessions && isset($_POST['date'])) { } $userInfo = api_get_user_info(); $code = isset($code) ? $code : null; -$search = null; -$select = null; -$message = null; + ?> - +
+

'.get_lang('CourseManagement').'

+
+
'; + +if ($showCourses) { + echo '
'; if (!isset($_GET['hidden_links']) || intval($_GET['hidden_links']) != 1) { - $term = empty($_POST['search_term']) ? '' : api_htmlentities($searchTerm); - $urlAction = CourseCategory::getCourseCategoryUrl(1, $pageLength, 'ALL', 0, 'subscribe'); - $formSearch = new FormValidator('search_catalog', 'post', $urlAction, null, [], FormValidator::LAYOUT_BOX_SEARCH); - $formSearch->addHidden('sec_token', $stok); - $formSearch->addHidden('search_course', 1); - $formSearch->addText('search_term', get_lang('Search'), false, ['value' => $term, 'icon' => 'search'])->setButton(true); - //$formSearch->defaultRenderer()->setElementTemplate($formSearch->getDefaultElementTemplate(),'search_term'); - $search = $formSearch->returnForm(); - - $webAction = api_get_path(WEB_CODE_PATH).'auth/courses.php'; - $formSelect = new FormValidator('select_category', 'get', $webAction, null, []); - $formSelect->addHidden('action', $action); - $formSelect->addHidden('pageCurrent', $pageCurrent); - $formSelect->addHidden('pageLength', $pageLength); - $options = []; - - foreach ($browse_course_categories[0] as $category) { - $categoryCode = $category['code']; - $countCourse = $category['count_courses']; - if (empty($countCourse)) { - continue; - } + ?> +
+ + + +
+ +
+ +
+
+
+ '; + echo '
'; + $listCategories = CoursesAndSessionsCatalog::getCourseCategoriesTree(); + $categoriesSelect = getOptionSelect($listCategories, $codeType); + + $webAction = api_get_path(WEB_CODE_PATH).'auth/courses.php'; + $form = '
'; + $form .= ''; + $form .= ''; + $form .= ''; + $form .= '
'; + $form .= ''; + $form .= $categoriesSelect; + $form .= '
'; + $form .= '
'; + echo $form; + echo '
'; +} - $options[$categoryCode] = $category['name'].' ('.$countCourse.')'; - } +if ($showSessions) { + $url = CourseCategory::getCourseCategoryUrl(1, $pageLength, null, 0, 'display_sessions'); + echo ' + '; +} - if (empty($codeType)) { - $codeType = 'ALL'; - } - $formSelect->addSelect('category_code', get_lang('Categories'), $options, ['onchange' => 'submit();'])->setSelected($codeType); - $select = $formSelect->returnForm(); - } +echo '
'; if ($showCourses && $action != 'display_sessions') { if (!empty($message)) { - $message = Display::return_message($message, 'confirmation', false); + echo Display::return_message($message, 'confirmation', false); } if (!empty($error)) { - $message = Display::return_message($error, 'error', false); + echo Display::return_message($error, 'error', false); } if (!empty($content)) { - $message = $content; + echo $content; } if (!empty($searchTerm)) { - $message = "

".get_lang('SearchResultsFor')." ".$searchTerm."
"; + echo "

".get_lang('SearchResultsFor')." ".$searchTerm."
"; } $showTeacher = api_get_setting('display_teacher_in_courselist') === 'true'; @@ -127,7 +151,6 @@ if ($showCourses && $action != 'display_sessions') { $user_id = api_get_user_id(); $categoryListFromDatabase = CourseCategory::getCategories(); - $courseList = []; $categoryList = []; if (!empty($categoryListFromDatabase)) { foreach ($categoryListFromDatabase as $categoryItem) { @@ -136,6 +159,7 @@ if ($showCourses && $action != 'display_sessions') { } if (!empty($browse_courses_in_category)) { + echo '

'; foreach ($browse_courses_in_category as $course) { $course_hidden = $course['visibility'] == COURSE_VISIBILITY_HIDDEN; @@ -158,47 +182,19 @@ if ($showCourses && $action != 'display_sessions') { $creation_date = substr($course['creation_date'], 0, 10); // display the course bloc + $html = '
'; $course['category_title'] = ''; if (isset($course['category'])) { $course['category_title'] = isset($categoryList[$course['category']]) ? $categoryList[$course['category']] : ''; } - if (api_get_configuration_value('hide_course_rating') === false) { - $ajax_url = api_get_path(WEB_AJAX_PATH).'course.ajax.php?a=add_course_vote'; - $rating = Display::return_rating_system( - 'star_'.$course['real_id'], - $ajax_url.'&course_id='.$course['real_id'], - $course['point_info'] - ); - } - - //course return image - - $course_path = api_get_path(SYS_COURSE_PATH).$course['directory']; - - if (file_exists($course_path.'/course-pic.png')) { - $courseMediumImage = api_get_path(WEB_COURSE_PATH).$course['directory'].'/course-pic.png'; - } else { - // without picture - $courseMediumImage = Display::return_icon( - 'session_default.png', - null, - null, - null, - null, - true - ); - } - - if ($showTeacher) { - $teachers = CourseManager::getTeachersFromCourse($course['real_id']); - } + // Display thumbnail + $html .= returnThumbnail($course, $userRegistered); $separator = null; - $subscribeBuy = return_register_button($course, $stok, $code, $searchTerm); + $subscribeButton = return_register_button($course, $stok, $code, $searchTerm); // Start buy course validation - // display the course price and buy button if the buycourses plugin is enabled and this course is configured $plugin = BuyCoursesPlugin::create(); $isThisCourseInSale = $plugin->buyCoursesForGridCatalogValidator( @@ -211,7 +207,7 @@ if ($showCourses && $action != 'display_sessions') { $separator = $isThisCourseInSale['html']; // set the Buy button instead register. if ($isThisCourseInSale['verificator']) { - $subscribeBuy = $plugin->returnBuyCourseButton( + $subscribeButton = $plugin->returnBuyCourseButton( $course['real_id'], BuyCoursesPlugin::PRODUCT_TYPE_COURSE ); @@ -219,47 +215,54 @@ if ($showCourses && $action != 'display_sessions') { } // end buy course validation + // display course title and button bloc + $html .= '
'; + $html .= return_title($course, $userRegisteredInCourse); + + if ($showTeacher) { + $html .= return_teacher($course); + } + + // display button line + $html .= '
'; + $html .= $separator ? '
'.$separator.'
' : ''; + $html .= '
'; // if user registered as student if ($userRegisteredInCourse) { - $subscribeButton = return_already_registered_label('student'); + $html .= return_already_registered_label('student'); if (!$course_closed) { if ($course_unsubscribe_allowed) { - $subscribeButton = return_unregister_button($course, $stok, $searchTerm, $code); + $html .= return_unregister_button($course, $stok, $searchTerm, $code); } } } elseif ($userRegisteredInCourseAsTeacher) { // if user registered as teacher if ($course_unsubscribe_allowed) { - $subscribeButton = return_unregister_button($course, $stok, $searchTerm, $code); + $html .= return_unregister_button($course, $stok, $searchTerm, $code); } } else { // if user not registered in the course if (!$course_closed) { if (!$course_private) { if ($course_subscribe_allowed) { - $subscribeButton = $subscribeBuy; + $html .= $subscribeButton; } } } } - - $courseList[] = [ - 'id' => $course['real_id'], - 'title' => $course['title'], - 'category' => $course['category_title'], - 'image' => $courseMediumImage, - 'url' => $linkCourse = api_get_path(WEB_PATH).'course/'.$course['real_id'].'/about', - 'teachers' => $teachers, - 'ranking' => $rating, - 'description_ajax' => CourseManager::returnDescriptionButton($course), - 'subscribe' => $subscribeButton, - ]; + $html .= '
'; + $html .= '
'; + $html .= '
'; + $html .= '
'; + $html .= '
'; + echo $html; } + echo '
'; } else { if (!isset($_REQUEST['subscribe_user_with_password']) && !isset($_REQUEST['subscribe_course']) ) { - $message = Display::return_message( + echo Display::return_message( get_lang('ThereAreNoCoursesInThisCategory'), 'warning' ); @@ -267,16 +270,171 @@ if ($showCourses && $action != 'display_sessions') { } } -$template = new Template(get_lang('Course Catalog')); -$template->assign('search', $search); -$template->assign('select', $select); -$template->assign('pagination', $cataloguePagination); -$template->assign('courses', $courseList); -$template->assign('message', $message); -$layout = $template->get_template('auth/course_catalog.html.twig'); -$content = $template->fetch($layout); +echo '
'; +echo $cataloguePagination; +echo '
'; + +function getOptionSelect($categories, $codeType) +{ + $html = ''; + $html .= ''; + + return $html; +} +/** + * Display the course catalog image of a course. + * + * @param array $course + * @param bool $registeredUser + * + * @return string HTML string + */ +function returnThumbnail($course, $registeredUser) +{ + $html = ''; + $title = cut($course['title'], 70); + //$linkCourse = api_get_course_url($course['code']); + $linkCourse = api_get_path(WEB_PATH).'course/'.$course['real_id'].'/about'; + // course path + $course_path = api_get_path(SYS_COURSE_PATH).$course['directory']; + + if (file_exists($course_path.'/course-pic.png')) { + // redimensioned image 85x85 + $courseMediumImage = api_get_path(WEB_COURSE_PATH).$course['directory'].'/course-pic.png'; + } else { + // without picture + $courseMediumImage = Display::return_icon( + 'session_default.png', + null, + null, + null, + null, + true + ); + } + + $html .= '
'; + $html .= '' + .''; + + $categoryTitle = isset($course['category_title']) ? $course['category_title'] : ''; + if (!empty($categoryTitle)) { + $html .= ''.$categoryTitle.''; + $html .= '
'; + } + + $html .= '
'; + + return $html; +} + +/** + * @param array $courseInfo + * + * @return string + */ +function return_teacher($courseInfo) +{ + $teachers = CourseManager::getTeachersFromCourse($courseInfo['real_id']); + $length = count($teachers); + + if (!$length) { + return ''; + } + + $html = '
'; + if ($length > 6) { + $html .= ' + + '; + $html .= '
'; + foreach ($teachers as $value) { + $name = $value['firstname'].' '.$value['lastname']; + $html .= '
'; + $html .= ' + '.get_lang('UserPicture').''; + $html .= ''; + $html .= '
'; + } + $html .= '
'; + } else { + foreach ($teachers as $value) { + $name = $value['firstname'].' '.$value['lastname']; + if ($length > 2) { + $html .= ' + '.get_lang('UserPicture').''; + } else { + $html .= ' + '.get_lang('UserPicture').''; + $html .= '
+ ' + .$name.'

'.get_lang('Teacher').'

'; + } + } + } + $html .= '
'; + + return $html; +} + +/** + * Display the title of a course in course catalog. + * + * @param array $course + * @param bool $registeredUser + * + * @return string HTML string + */ +function return_title($course, $registeredUser) +{ + //$linkCourse = api_get_course_url($course['code']); + $linkCourse = api_get_path(WEB_PATH).'course/'.$course['real_id'].'/about'; + $html = '

'; + $html .= ''.$course['title'].''; + $html .= '

'; + + if (api_get_configuration_value('hide_course_rating') === false) { + $ajax_url = api_get_path(WEB_AJAX_PATH).'course.ajax.php?a=add_course_vote'; + $rating = Display::return_rating_system( + 'star_'.$course['real_id'], + $ajax_url.'&course_id='.$course['real_id'], + $course['point_info'] + ); + $html .= '
'.$rating.'
'; + } -echo $content; + return $html; +} /** * Display the goto course button of a course in the course catalog. diff --git a/main/auth/courses_controller.php b/main/auth/courses_controller.php index ade8959e59..4bb90aed03 100755 --- a/main/auth/courses_controller.php +++ b/main/auth/courses_controller.php @@ -33,57 +33,6 @@ class CoursesController $this->model = new Auth(); } - /** - * It's used for listing courses, - * render to courses_list view. - * - * @param string $action - * @param string $message confirmation message(optional) - */ - public function courseList($action, $message = '') - { - $data = []; - $data['user_courses'] = $this->model->get_courses_of_user(api_get_user_id()); - $data['user_course_categories'] = CourseManager::get_user_course_categories(api_get_user_id()); - $data['courses_in_category'] = $this->model->get_courses_in_category(); - $data['action'] = $action; - $data['message'] = $message; - - // render to the view - $this->view->set_data($data); - $this->view->set_layout('catalog_layout'); - $this->view->set_template('courses_list'); - $this->view->render(); - } - - /** - * It's used for listing categories, render to categories_list view. - */ - public function categoryList() - { - api_block_anonymous_users(); - $stok = Security::get_token(); - $actions = Display::url( - Display::return_icon('back.png', get_lang('Back'), '', '32'), - api_get_path(WEB_CODE_PATH).'auth/courses.php?action=sortmycourses' - ); - $actions = Display::toolbarAction('toolbar-forum', [$actions]); - - $form = new FormValidator( - 'create_course_category', - 'post', - api_get_path(WEB_CODE_PATH).'auth/courses.php?action=createcoursecategory' - ); - $form->addHidden('sec_token', $stok); - $form->addText('title_course_category', get_lang('Name')); - $form->addButtonSave(get_lang('AddCategory'), 'create_course_category'); - - $tpl = new Template(); - $tpl->assign('content', $form->returnForm()); - $tpl->assign('actions', $actions); - $tpl->display_one_col_template(); - } - /** * It's used for listing courses with categories, * render to courses_categories view. @@ -218,129 +167,6 @@ class CoursesController $this->view->render(); } - /** - * Create a category - * render to listing view. - * - * @param string $title - */ - public function addCourseCategory($title) - { - $result = $this->model->store_course_category($title); - if ($result) { - Display::addFlash( - Display::return_message(get_lang('CourseCategoryStored')) - ); - } else { - Display::addFlash( - Display::return_message( - get_lang('ACourseCategoryWithThisNameAlreadyExists'), - 'error' - ) - ); - } - header('Location: '.api_get_path(WEB_CODE_PATH).'auth/courses.php?action=sortmycourses'); - exit; - } - - /** - * Change course category - * render to listing view. - * - * @param string $course_code - * @param int $category_id - */ - public function change_course_category($course_code, $category_id) - { - $courseInfo = api_get_course_info($course_code); - $courseId = $courseInfo['real_id']; - - $result = $this->model->updateCourseCategory($courseId, $category_id); - if ($result) { - Display::addFlash( - Display::return_message(get_lang('EditCourseCategorySucces')) - ); - } - $action = 'sortmycourses'; - $this->courseList($action); - } - - /** - * Move up/down courses inside a category - * render to listing view. - * - * @param string $move move to up or down - * @param string $course_code - * @param int $category_id Category id - */ - public function move_course($move, $course_code, $category_id) - { - $result = $this->model->move_course($move, $course_code, $category_id); - if ($result) { - Display::addFlash( - Display::return_message(get_lang('CourseSortingDone')) - ); - } - $action = 'sortmycourses'; - $this->courseList($action); - } - - /** - * Move up/down categories - * render to listing view. - * - * @param string $move move to up or down - * @param int $category_id Category id - */ - public function move_category($move, $category_id) - { - $result = $this->model->move_category($move, $category_id); - if ($result) { - Display::addFlash( - Display::return_message(get_lang('CategorySortingDone')) - ); - } - $action = 'sortmycourses'; - $this->courseList($action); - } - - /** - * Edit course category - * render to listing view. - * - * @param string $title Category title - * @param int $category Category id - */ - public function edit_course_category($title, $category) - { - $result = $this->model->store_edit_course_category($title, $category); - if ($result) { - Display::addFlash( - Display::return_message(get_lang('CourseCategoryEditStored')) - ); - } - $action = 'sortmycourses'; - $this->courseList($action); - } - - /** - * Delete a course category - * render to listing view. - * - * @param int Category id - */ - public function delete_course_category($category_id) - { - $result = $this->model->delete_course_category($category_id); - if ($result) { - Display::addFlash( - Display::return_message(get_lang('CourseCategoryDeleted')) - ); - } - $action = 'sortmycourses'; - $this->courseList($action); - } - /** * Unsubscribe user from a course * render to listing view. @@ -376,123 +202,6 @@ class CoursesController } } - /** - * Get the html block for courses categories. - * - * @param string $code Current category code - * @param bool $hiddenLinks Whether hidden links - * @param array $limit - * - * @return string The HTML block - */ - public function getCoursesCategoriesBlock( - $code = null, - $hiddenLinks = false, - $limit = null - ) { - $categories = CoursesAndSessionsCatalog::getCourseCategories(); - $html = ''; - if (!empty($categories)) { - $action = 'display_courses'; - foreach ($categories[0] as $category) { - $categoryName = $category['name']; - $categoryCode = $category['code']; - $categoryCourses = $category['count_courses']; - - $html .= '
  • '; - - $categoryLink = CourseCategory::getCourseCategoryUrl( - 1, - $limit['length'], - $categoryCode, - $hiddenLinks, - $action - ); - - if ($code == $categoryCode) { - $html .= ''; - $html .= "$categoryName ($categoryCourses)"; - $html .= ''; - } else { - if (!empty($categoryCourses)) { - $html .= ''; - $html .= "$categoryName ($categoryCourses)"; - $html .= ''; - } else { - $html .= "$categoryName ($categoryCourses)"; - } - } - - if (!empty($categories[$categoryCode])) { - $html .= ''; - } - $html .= '
  • '; - } - } - - return $html; - } - /** * Get a HTML button for subscribe to session. * @@ -512,6 +221,7 @@ class CoursesController $includeText = false, $btnBing = false ) { + $sessionId = (int) $sessionId; if ($btnBing) { $btnBing = 'btn-lg btn-block'; } else { @@ -522,7 +232,7 @@ class CoursesController $url .= 'sequence.ajax.php?'; $url .= http_build_query([ 'a' => 'get_requirements', - 'id' => intval($sessionId), + 'id' => $sessionId, 'type' => SequenceResource::SESSION_TYPE, ]); @@ -552,7 +262,7 @@ class CoursesController $url .= 'auth/courses.php?'; $url .= http_build_query([ 'action' => 'subscribe_to_session', - 'session_id' => intval($sessionId), + 'session_id' => $sessionId, ]); $result = Display::toolbarButton( @@ -588,7 +298,7 @@ class CoursesController $hook = HookResubscribe::create(); if (!empty($hook)) { $hook->setEventData([ - 'session_id' => intval($sessionId), + 'session_id' => $sessionId, ]); try { $hook->notifyResubscribe(HOOK_EVENT_TYPE_PRE); diff --git a/main/auth/courses_list.php b/main/auth/courses_list.php deleted file mode 100755 index 7d73af0f36..0000000000 --- a/main/auth/courses_list.php +++ /dev/null @@ -1,323 +0,0 @@ - - Beeznest - * - * @package chamilo.auth - */ - -// Access rights: anonymous users can't do anything usefull here. -api_block_anonymous_users(); -$stok = Security::get_token(); -$courses_without_category = isset($courses_in_category[0]) ? $courses_in_category[0] : null; -echo '
    '; -if ($action != 'createcoursecategory') { - echo ''; - echo Display::return_icon('new_folder.png', get_lang('CreateCourseCategory'), '', '32'); - echo ''; -} -echo '
    '; - -if (!empty($message)) { - echo Display::return_message($message, 'confirm', false); -} - -$allowCollapsable = api_get_configuration_value('allow_user_course_category_collapsable'); -$teachersIcon = Display::return_icon('teacher.png', get_lang('Teachers'), null, ICON_SIZE_TINY); - -// COURSES WITH CATEGORIES -if (!empty($user_course_categories)) { - $counter = 0; - $last = end($user_course_categories); - foreach ($user_course_categories as $row) { - echo Display::page_subheader($row['title']); - echo ''; - $url = api_get_path(WEB_CODE_PATH).'auth/courses.php?categoryid='.$row['id'].'&sec_token='.$stok; - if (isset($_GET['categoryid']) && $_GET['categoryid'] == $row['id']) { - ?> - -
    - - - - -
    - ', - $url.'&action=set_collapsable&option=1' - ); - } else { - echo Display::url( - '', - $url.'&action=set_collapsable&option=0' - ); - } - } ?> - - - - - - - - - - - - - - - - - "javascript: if (!confirm('".addslashes( - api_htmlentities( - get_lang('CourseCategoryAbout2bedeleted'), - ENT_QUOTES, - api_get_system_encoding() - ) - )."')) return false;", - ], - 22 - ); ?> - -
    '; - // Show the courses inside this category - echo ''; - $number_of_courses = isset($courses_in_category[$row['id']]) ? count($courses_in_category[$row['id']]) : 0; - $key = 0; - if (!empty($courses_in_category[$row['id']])) { - foreach ($courses_in_category[$row['id']] as $course) { - echo ' {% endif %} diff --git a/plugin/customcertificate/src/CustomCertificatePlugin.php b/plugin/customcertificate/src/CustomCertificatePlugin.php index 63d5050306..9d83056d49 100644 --- a/plugin/customcertificate/src/CustomCertificatePlugin.php +++ b/plugin/customcertificate/src/CustomCertificatePlugin.php @@ -233,7 +233,7 @@ class CustomCertificatePlugin extends Plugin $courseCode = $row['course_code']; $sessionId = $row['session_id']; $userId = $row['user_id']; - if (api_get_course_setting('customcertificate_course_enable', $courseCode) == 1) { + if (api_get_course_setting('customcertificate_course_enable', api_get_course_info($courseCode)) == 1) { return [ 'course_code' => $courseCode, 'session_id' => $sessionId, diff --git a/plugin/customcertificate/src/index.php b/plugin/customcertificate/src/index.php index 4d16dd1cd2..7eb9cb989c 100644 --- a/plugin/customcertificate/src/index.php +++ b/plugin/customcertificate/src/index.php @@ -32,8 +32,8 @@ if ($isDefault === 1) { $courseId = api_get_course_int_id(); $courseCode = api_get_course_id(); $sessionId = api_get_session_id(); - $enableCourse = api_get_course_setting('customcertificate_course_enable', $courseCode) == 1 ? true : false; - $useDefault = api_get_course_setting('use_certificate_default', $courseCode) == 1 ? true : false; + $enableCourse = api_get_course_setting('customcertificate_course_enable', $course_info) == 1 ? true : false; + $useDefault = api_get_course_setting('use_certificate_default', $course_info) == 1 ? true : false; $defaultCertificate = 0; $urlParams = '?'.api_get_cidreq(); } diff --git a/plugin/customcertificate/src/print_certificate.php b/plugin/customcertificate/src/print_certificate.php index ace1411a3a..b0e47260fe 100644 --- a/plugin/customcertificate/src/print_certificate.php +++ b/plugin/customcertificate/src/print_certificate.php @@ -31,8 +31,8 @@ if ($default == 1) { $courseId = api_get_course_int_id(); $courseCode = api_get_course_id(); $sessionId = api_get_session_id(); - $enableCourse = api_get_course_setting('customcertificate_course_enable', $courseCode) == 1 ? true : false; - $useDefault = api_get_course_setting('use_certificate_default', $courseCode) == 1 ? true : false; + $enableCourse = api_get_course_setting('customcertificate_course_enable') == 1 ? true : false; + $useDefault = api_get_course_setting('use_certificate_default') == 1 ? true : false; } if (empty($courseCode)) { diff --git a/plugin/redirection/RedirectionPlugin.php b/plugin/redirection/RedirectionPlugin.php index cc2768cec3..4f0f6f0be7 100644 --- a/plugin/redirection/RedirectionPlugin.php +++ b/plugin/redirection/RedirectionPlugin.php @@ -162,7 +162,7 @@ class RedirectionPlugin extends Plugin { // Check redirection plugin $plugin = new AppPlugin(); - $pluginList = $plugin->get_installed_plugins(); + $pluginList = $plugin->getInstalledPlugins(); $redirectionInstalled = in_array('redirection', $pluginList); if ($redirectionInstalled) { $pluginInfo = $plugin->getPluginInfo('redirection'); diff --git a/plugin/studentfollowup/StudentFollowUpPlugin.php b/plugin/studentfollowup/StudentFollowUpPlugin.php index ff09ebf1ad..e9def01c1c 100644 --- a/plugin/studentfollowup/StudentFollowUpPlugin.php +++ b/plugin/studentfollowup/StudentFollowUpPlugin.php @@ -92,14 +92,8 @@ class StudentFollowUpPlugin extends Plugin */ public static function getPermissions($studentId, $currentUserId) { - $params = ['variable = ? AND subkey = ?' => ['status', 'studentfollowup']]; - $result = api_get_settings_params_simple($params); - $installed = false; - if (!empty($result) && $result['selected_value'] === 'installed') { - $installed = true; - } - - if ($installed == false) { + $installed = AppPlugin::getInstance()->isInstalled('studentfollowup'); + if ($installed === false) { return [ 'is_allow' => false, 'show_private' => false, @@ -187,8 +181,6 @@ class StudentFollowUpPlugin extends Plugin switch ($status) { case COURSEMANAGER: - /*$sessions = SessionManager::get_sessions_by_user($currentUserId); - $sessions = array_column($sessions, 'session_id');*/ $sessionsFull = SessionManager::getSessionsCoachedByUser($currentUserId); $sessions = array_column($sessionsFull, 'id'); if (!empty($sessionId)) { @@ -229,19 +221,6 @@ class StudentFollowUpPlugin extends Plugin $limit ); - /*$userList = []; - foreach ($sessions as $sessionId) { - foreach ($courses as $courseId) { - $courseInfo = ['real_id' => $courseId]; - $userFromSessionList = SessionManager::getUsersByCourseSession( - $sessionId, - $courseInfo - ); - $userList = array_merge($userList, $userFromSessionList); - } - $userList = array_unique($userList); - }*/ - return [ 'users' => $userList, 'sessions' => $sessionsFull,
    '; - echo ''; - echo ''.$course['title'].''; - echo ' ('.$course['visual_code'].')'; - echo '
    '; - echo $teachersIcon; - echo ' '; - echo CourseManager::getTeacherListFromCourseCodeToString($course['code']); - echo '
    '; - - if (api_get_setting('display_teacher_in_courselist') === 'true') { - echo $course['tutor']; - } - echo '
    '; - if (isset($_GET['edit']) && $course['code'] == $_GET['edit']) { - $edit_course = Security::remove_XSS($_GET['edit']); ?> - -
    - - - - -
    - -
    - - - - - - - - - - - - - - - 0) { - ?> - - - - - - - - - - - - - - - -
    -
    - - -
    ')) return false"> - - - -
    -
    - '; - } - } -} - -echo Display::page_subheader(get_lang('NoCourseCategory')); -echo ''; -// COURSES WITHOUT CATEGORY -if (!empty($courses_without_category)) { - $number_of_courses = count($courses_without_category); - $key = 0; - foreach ($courses_without_category as $course) { - echo ' - - -
    '; - echo ''; - echo ''.$course['title'].''; - echo ' ('.$course['visual_code'].')'; - echo '
    '; - echo $teachersIcon; - echo ' '; - echo CourseManager::getTeacherListFromCourseCodeToString($course['code']); - echo '
    '; - - if (api_get_setting('display_teacher_in_courselist') === 'true') { - echo $course['tutor']; - } - echo '
    '; - // the edit icon OR the edit dropdown list - if (isset($_GET['edit']) && $course['code'] == $_GET['edit']) { - $edit_course = Security::remove_XSS($_GET['edit']); ?> -
    -
    - - - - -

    -
    - -
    - - - - - - - - - 0) { - ?> - - - - - - - - -
    -
    - - - -
    ')) return false;"> - - - -
    -
    - -
    diff --git a/main/auth/hrm_courses.php b/main/auth/hrm_courses.php index bebc3d4a12..e51c1ae27f 100644 --- a/main/auth/hrm_courses.php +++ b/main/auth/hrm_courses.php @@ -1,11 +1,9 @@ getDirectory(); - $webCoursePath = api_get_path(WEB_COURSE_PATH).$course->getDirectory(); - - return [ - 'visibility' => $course->getVisibility(), - 'link' => api_get_course_url($course->getCode(), $sessionId), - 'category' => $course->getCategoryCode(), - 'title' => $course->getTitle(), - 'title_cut' => $course->getTitle(), - 'code_course' => $showCourseCode ? $course->getCode() : null, - 'image' => file_exists($sysCoursePath.'/course-pic.png') - ? $webCoursePath.'/course-pic.png' - : Display::return_icon( - 'session_default.png', - null, - null, - null, - null, - true - ), - 'teachers' => api_get_setting('display_teacher_in_courselist') === 'true' - ? $teachers = CourseManager::getTeachersFromCourse($course->getId(), true) - : [], - ]; -} - -$showCourseCode = api_get_configuration_value('display_coursecode_in_courselist') === 'true'; - $hrm = api_get_user_entity(api_get_user_id()); $assignedUsers = UserManager::get_users_followed_by_drh($hrm->getId()); $users = []; diff --git a/main/auth/inscription.php b/main/auth/inscription.php index 81a2cae1e0..7be987dcd5 100755 --- a/main/auth/inscription.php +++ b/main/auth/inscription.php @@ -636,8 +636,9 @@ if ($extraConditions && $extraFieldsLoaded) { $element->setLabel( [ '', - //'', - '
    '.get_lang($condition['text_area']).'
    ', + '
    '. + get_lang(nl2br($condition['text_area'])). + '
    ', ] ); } diff --git a/main/calendar/agenda_js.php b/main/calendar/agenda_js.php index 4c58f8dd23..cb6d054c5b 100755 --- a/main/calendar/agenda_js.php +++ b/main/calendar/agenda_js.php @@ -278,6 +278,10 @@ if ($agenda->type === 'course') { $form->addElement('textarea', 'comment', get_lang('Comment'), ['id' => 'comment']); } +$form->addHtml(''); + $tpl->assign('form_add', $form->returnForm()); $tpl->assign('legend_list', api_get_configuration_value('agenda_legend')); diff --git a/main/calendar/download.php b/main/calendar/download.php index 0ef649c8b3..3dfe8fdc35 100755 --- a/main/calendar/download.php +++ b/main/calendar/download.php @@ -19,18 +19,14 @@ header('Expires: Wed, 01 Jan 1990 00:00:00 GMT'); header('Cache-Control: public'); header('Pragma: no-cache'); -$course_id = isset($_REQUEST['course_id']) ? $_REQUEST['course_id'] : 0; +$course_id = isset($_REQUEST['course_id']) ? (int) $_REQUEST['course_id'] : api_get_course_int_id(); $user_id = api_get_user_id(); $course_info = api_get_course_info_by_id($course_id); +$doc_url = $_REQUEST['file']; -if (empty($course_id)) { - $course_id = api_get_course_int_id(); -} if (empty($course_id) || empty($doc_url)) { api_not_allowed(); } - -$doc_url = $_REQUEST['file']; $session_id = api_get_session_id(); $is_user_is_subscribed = CourseManager::is_user_subscribed_in_course( diff --git a/main/course_home/course_home.php b/main/course_home/course_home.php index ccd6a714d8..90e0ac4ce4 100755 --- a/main/course_home/course_home.php +++ b/main/course_home/course_home.php @@ -227,7 +227,7 @@ if (!empty($lpAutoLaunch)) { } else { $session_key = 'lp_autolaunch_'.$session_id.'_'.api_get_course_int_id().'_'.api_get_user_id(); if (!isset($_SESSION[$session_key])) { - //redirecting to the LP + // Redirecting to the LP $url = api_get_path(WEB_CODE_PATH).'lp/lp_controller.php?'.api_get_cidreq().'&action=view&lp_id='.$lp_data['id']; $_SESSION[$session_key] = true; @@ -325,6 +325,7 @@ if ($documentAutoLaunch == 1) { } } +// Used in different pages $tool_table = Database::get_course_table(TABLE_TOOL_LIST); /* Introduction section (editable by course admins) */ diff --git a/main/document/recycle.php b/main/document/recycle.php index fc2c93614f..49da00fe67 100644 --- a/main/document/recycle.php +++ b/main/document/recycle.php @@ -26,7 +26,7 @@ $actions .= Display::url( ); $action = isset($_GET['action']) ? $_GET['action'] : ''; -$id = isset($_GET['id']) ? intval($_GET['id']) : ''; +$id = isset($_GET['id']) ? (int) $_GET['id'] : ''; $currentUrl = api_get_self().'?'.api_get_cidreq(); switch ($action) { @@ -51,8 +51,8 @@ switch ($action) { } $interbreadcrumb[] = [ - "url" => api_get_path(WEB_CODE_PATH).'document/document.php?'.api_get_cidreq(), - "name" => get_lang('Documents'), + 'url' => api_get_path(WEB_CODE_PATH).'document/document.php?'.api_get_cidreq(), + 'name' => get_lang('Documents'), ]; $template = new Template(get_lang('DeletedDocuments')); $template->assign('files', $files); diff --git a/main/document/showinframes.php b/main/document/showinframes.php index 75c2b3f734..d53ae552ec 100755 --- a/main/document/showinframes.php +++ b/main/document/showinframes.php @@ -166,7 +166,7 @@ if (api_is_course_admin()) { $frameheight = 165; } -$frameReady = Display::getFrameReadyBlock('top.mainFrame'); +$frameReady = Display::getFrameReadyBlock('#mainFrame'); $web_odf_supported_files = DocumentManager::get_web_odf_extension_list(); // PDF should be displayed with viewerJS @@ -226,20 +226,14 @@ if (!$playerSupported && $execute_iframe) { '; $htmlHeadXtra[] = ''; $htmlHeadXtra[] = ''; } diff --git a/main/exercise/TestCategory.php b/main/exercise/TestCategory.php index 3b3a7ec3fb..be596675a3 100644 --- a/main/exercise/TestCategory.php +++ b/main/exercise/TestCategory.php @@ -283,22 +283,6 @@ class TestCategory return $result; } - /** - * true if question id has a category. - * - * @param int $questionId - * - * @return bool - */ - public static function isQuestionHasCategory($questionId) - { - if (self::getCategoryForQuestion($questionId) > 0) { - return true; - } - - return false; - } - /** * Return the category name for question with question_id = $questionId * In this version, a question has only 1 category. @@ -437,17 +421,6 @@ class TestCategory return $result; } - /** - * return the number of differents categories for a test - * input : test_id - * return : integer - * hubert.borderiou 07-04-2011. - */ - public static function getNumberOfCategoriesForTest($id) - { - return count(self::getListOfCategoriesIDForTest($id)); - } - /** * return the number of question of a category id in a test. * @@ -672,22 +645,6 @@ class TestCategory return $content; } - /** - * Display signs [+] and/or (>0) after question title if question has options - * scoreAlwaysPositive and/or uncheckedMayScore. - * - * @param $objQuestion - */ - public function displayQuestionOption($objQuestion) - { - if ($objQuestion->type == MULTIPLE_ANSWER && $objQuestion->scoreAlwaysPositive) { - echo " (>0)"; - } - if ($objQuestion->type == MULTIPLE_ANSWER && $objQuestion->uncheckedMayScore) { - echo " [+]"; - } - } - /** * sortTabByBracketLabel ($tabCategoryQuestions) * key of $tabCategoryQuestions are the category id (0 for not in a category) @@ -863,22 +820,6 @@ class TestCategory return ''; } - /** - * @return array - */ - public static function get_all_categories() - { - $table = Database::get_course_table(TABLE_QUIZ_CATEGORY); - $sql = "SELECT * FROM $table ORDER BY title ASC"; - $res = Database::query($sql); - $array = []; - while ($row = Database::fetch_array($res, 'ASSOC')) { - $array[] = $row; - } - - return $array; - } - /** * @param Exercise $exercise * @param int $courseId @@ -1073,25 +1014,6 @@ class TestCategory return $return; } - /** - * Sorts an array. - * - * @param array $array - * - * @return array - */ - public function sort_tree_array($array) - { - foreach ($array as $key => $row) { - $parent[$key] = $row['parent_id']; - } - if (count($array) > 0) { - array_multisort($parent, SORT_ASC, $array); - } - - return $array; - } - /** * Return true if a category already exists with the same name. * diff --git a/main/exercise/exercise.class.php b/main/exercise/exercise.class.php index bffd2eecb5..0d8b21b0f7 100755 --- a/main/exercise/exercise.class.php +++ b/main/exercise/exercise.class.php @@ -22,7 +22,7 @@ use Doctrine\DBAL\Types\Type; */ class Exercise { - const PAGINATION_ITEMS_PER_PAGE = 5; + const PAGINATION_ITEMS_PER_PAGE = 20; public $iId; public $id; public $name; @@ -1721,9 +1721,6 @@ class Exercise $this->save_categories_in_exercise($this->categories); - // Updates the question position - $this->update_question_positions(); - return $this->iId; } @@ -8292,7 +8289,6 @@ class Exercise $studentCount = 0; $sum = 0; $bestResult = 0; - $weight = 0; $sumResult = 0; $result = Database::query($sql); while ($data = Database::fetch_array($result, 'ASSOC')) { @@ -8306,13 +8302,10 @@ class Exercise if (!isset($students[$data['exe_user_id']])) { if ($data['exe_weighting'] != 0) { $students[$data['exe_user_id']] = $data['exe_result']; - $studentCount++; if ($data['exe_result'] > $bestResult) { $bestResult = $data['exe_result']; } - $sum += $data['exe_result'] / $data['exe_weighting']; $sumResult += $data['exe_result']; - $weight = $data['exe_weighting']; } } } @@ -8407,15 +8400,19 @@ class Exercise // Condition for the session $condition_session = api_get_session_condition($sessionId, true, true); $content = ''; + $column = 0; + if ($is_allowedToEdit) { + $column = 1; + } $table = new SortableTableFromArrayConfig( [], - 1, + $column, self::PAGINATION_ITEMS_PER_PAGE, 'exercises_cat_'.$categoryId ); - $limit = self::PAGINATION_ITEMS_PER_PAGE; + $limit = $table->per_page; $page = $table->page_nr; $from = $limit * ($page - 1); @@ -8469,7 +8466,7 @@ class Exercise active = 1 $condition_session $categoryCondition - $keywordCondition + $keywordCondition ORDER BY title LIMIT $from , $limit"; } @@ -9132,7 +9129,7 @@ class Exercise } $currentRow = [ - $row['iid'], + $row['id'], $currentRow['title'], $currentRow['count_questions'], $actions, @@ -9176,7 +9173,7 @@ class Exercise $result = Database::query($sql); $attributes = []; - while ($row = Database :: fetch_array($result, 'ASSOC')) { + while ($row = Database::fetch_array($result, 'ASSOC')) { $attributes[$row['iid']] = $row; } @@ -9336,9 +9333,7 @@ class Exercise if (empty($tableRows)) { return ''; } - $table->setTableData($tableRows); - $table->setTotalNumberOfItems($total); $table->set_additional_parameters([ 'cidReq' => api_get_course_id(), diff --git a/main/exercise/exercise_show.php b/main/exercise/exercise_show.php index 320be98ba2..bc24988aa1 100755 --- a/main/exercise/exercise_show.php +++ b/main/exercise/exercise_show.php @@ -210,8 +210,16 @@ if ($action != 'export') { var oHidn = document.createElement("input"); oHidn.type = "hidden"; var selname = oHidn.name = "marks_" + m_id[i]; - var selid = document.forms['marksform_' + m_id[i]].marks.selectedIndex; - oHidn.value = document.forms['marksform_' + m_id[i]].marks.options[selid].value; + + var elMarks = document.forms['marksform_' + m_id[i]].marks; + + if (elMarks.tagName.toLowerCase() === 'select') { + var selid = elMarks.selectedIndex; + oHidn.value = elMarks.options[selid].value; + } else if (elMarks.tagName.toLowerCase() === 'input') { + oHidn.value = elMarks.value; + } + f.appendChild(oHidn); } @@ -620,14 +628,16 @@ foreach ($questionList as $questionId) { $renderer->setFormTemplate('
    {content}
    '); $renderer->setCustomElementTemplate('
    {element}
    '); $comnt = Event::get_comments($id, $questionId); - $default = ['comments_'.$questionId => $comnt]; + + $textareaId = 'comments_'.$questionId; + $default = [$textareaId => $comnt]; if ($useAdvancedEditor) { $feedback_form->addElement( 'html_editor', - 'comments_'.$questionId, - null, + $textareaId, null, + ['id' => $textareaId], [ 'ToolbarSet' => 'TestAnswerFeedback', 'Width' => '100%', @@ -635,7 +645,7 @@ foreach ($questionList as $questionId) { ] ); } else { - $feedback_form->addElement('textarea', 'comments_'.$questionId); + $feedback_form->addElement('textarea', $textareaId, ['id' => $textareaId]); } $feedback_form->setDefaults($default); $feedback_form->display(); @@ -665,29 +675,60 @@ foreach ($questionList as $questionId) { echo ''; } -Display :: display_footer(); +Display::display_footer(); diff --git a/main/gradebook/lib/GradebookUtils.php b/main/gradebook/lib/GradebookUtils.php index b5927b7ac6..caed9ed412 100644 --- a/main/gradebook/lib/GradebookUtils.php +++ b/main/gradebook/lib/GradebookUtils.php @@ -448,7 +448,6 @@ class GradebookUtils $is_locked = $link->is_locked(); $modify_icons = null; - if (!api_is_allowed_to_edit(null, true)) { return null; } @@ -566,30 +565,6 @@ class GradebookUtils return $row; } - /** - * Remove a resource from the unique gradebook of a given course. - * - * @param int Link/Resource ID - * - * @return bool false on error, true on success - */ - public static function get_resource_from_course_gradebook($link_id) - { - if (empty($link_id)) { - return false; - } - // TODO find the corresponding category (the first one for this course, ordered by ID) - $l = Database::get_main_table(TABLE_MAIN_GRADEBOOK_LINK); - $sql = "SELECT * FROM $l WHERE id = ".(int) $link_id; - $res = Database::query($sql); - $row = []; - if (Database::num_rows($res) > 0) { - $row = Database::fetch_array($res, 'ASSOC'); - } - - return $row; - } - /** * Return the course id. * @@ -1440,7 +1415,7 @@ class GradebookUtils foreach ($courses as $course) { if (!$includeNonPublicCertificates) { - $allowPublicCertificates = api_get_course_setting('allow_public_certificates', $course['code']); + $allowPublicCertificates = api_get_course_setting('allow_public_certificates', $course); if (empty($allowPublicCertificates)) { continue; @@ -1512,7 +1487,7 @@ class GradebookUtils foreach ($sessionCourses as $course) { if (!$includeNonPublicCertificates) { - $allowPublicCertificates = api_get_course_setting('allow_public_certificates', $course['code']); + $allowPublicCertificates = api_get_course_setting('allow_public_certificates'); if (empty($allowPublicCertificates)) { continue; @@ -1665,7 +1640,6 @@ class GradebookUtils $graph. '
    '.get_lang('Feedback').'
    '; - $result = $pdf->html_to_pdf_with_template( $content, $saveToFile, diff --git a/main/gradebook/lib/be/category.class.php b/main/gradebook/lib/be/category.class.php index 025b058c17..519e715706 100755 --- a/main/gradebook/lib/be/category.class.php +++ b/main/gradebook/lib/be/category.class.php @@ -978,10 +978,8 @@ class Category implements GradebookItem $linkres = $link->calc_score($stud_id, null); if (!empty($linkres) && $link->get_weight() != 0) { - $students[$stud_id] = $linkres[0]; $linkweight = $link->get_weight(); $link_res_denom = $linkres[1] == 0 ? 1 : $linkres[1]; - $count++; $weightsum += $linkweight; $ressum += $linkres[0] / $link_res_denom * $linkweight; } else { @@ -1009,10 +1007,10 @@ class Category implements GradebookItem } // Calculate score - $count = 0; $ressum = 0; $weightsum = 0; $bestResult = 0; + $totalScorePerStudent = []; if (!empty($cats)) { /** @var Category $cat */ @@ -1042,57 +1040,91 @@ class Category implements GradebookItem } if (!empty($evals)) { - /** @var Evaluation $eval */ - foreach ($evals as $eval) { - $evalres = $eval->calc_score(null, $type); - $eval->setStudentList($this->getStudentList()); - - if (isset($evalres) && $eval->get_weight() != 0) { - $evalweight = $eval->get_weight(); - $weightsum += $evalweight; - $count++; - if (!empty($evalres[1])) { - $ressum += $evalres[0] / $evalres[1] * $evalweight; + if ($type === 'best') { + $studentList = $this->getStudentList(); + foreach ($studentList as $student) { + $studentId = $student['user_id']; + foreach ($evals as $eval) { + $linkres = $eval->calc_score($studentId, null); + $linkweight = $eval->get_weight(); + $link_res_denom = $linkres[1] == 0 ? 1 : $linkres[1]; + $ressum = $linkres[0] / $link_res_denom * $linkweight; + + if (!isset($totalScorePerStudent[$studentId])) { + $totalScorePerStudent[$studentId] = 0; + } + $totalScorePerStudent[$studentId] += $ressum; } + } + } else { + /** @var Evaluation $eval */ + foreach ($evals as $eval) { + $evalres = $eval->calc_score(null, $type); + $eval->setStudentList($this->getStudentList()); - if ($ressum > $bestResult) { - $bestResult = $ressum; - } - } else { - if ($eval->get_weight() != 0) { + if (isset($evalres) && $eval->get_weight() != 0) { $evalweight = $eval->get_weight(); $weightsum += $evalweight; + if (!empty($evalres[1])) { + $ressum += $evalres[0] / $evalres[1] * $evalweight; + } + + if ($ressum > $bestResult) { + $bestResult = $ressum; + } + } else { + if ($eval->get_weight() != 0) { + $evalweight = $eval->get_weight(); + $weightsum += $evalweight; + } } } } } + if (!empty($links)) { - /** @var EvalLink|ExerciseLink $link */ - foreach ($links as $link) { - $link->setStudentList($this->getStudentList()); + $studentList = $this->getStudentList(); + if ($type === 'best') { + foreach ($studentList as $student) { + $studentId = $student['user_id']; + foreach ($links as $link) { + $linkres = $link->calc_score($studentId, null); + $linkweight = $link->get_weight(); + $link_res_denom = $linkres[1] == 0 ? 1 : $linkres[1]; + $ressum = $linkres[0] / $link_res_denom * $linkweight; - if ($session_id) { - $link->set_session_id($session_id); + if (!isset($totalScorePerStudent[$studentId])) { + $totalScorePerStudent[$studentId] = 0; + } + $totalScorePerStudent[$studentId] += $ressum; + } } + } else { + /** @var EvalLink|ExerciseLink $link */ + foreach ($links as $link) { + $link->setStudentList($this->getStudentList()); - $linkres = $link->calc_score($stud_id, $type); - if (!empty($linkres) && $link->get_weight() != 0) { - $students[$stud_id] = $linkres[0]; - $linkweight = $link->get_weight(); - $link_res_denom = $linkres[1] == 0 ? 1 : $linkres[1]; + if ($session_id) { + $link->set_session_id($session_id); + } - $count++; - $weightsum += $linkweight; - $ressum += $linkres[0] / $link_res_denom * $linkweight; + $linkres = $link->calc_score($stud_id, $type); - if ($ressum > $bestResult) { - $bestResult = $ressum; - } - } else { - // Adding if result does not exists - if ($link->get_weight() != 0) { + if (!empty($linkres) && $link->get_weight() != 0) { $linkweight = $link->get_weight(); + $link_res_denom = $linkres[1] == 0 ? 1 : $linkres[1]; + $weightsum += $linkweight; + $ressum += $linkres[0] / $link_res_denom * $linkweight; + if ($ressum > $bestResult) { + $bestResult = $ressum; + } + } else { + // Adding if result does not exists + if ($link->get_weight() != 0) { + $linkweight = $link->get_weight(); + $weightsum += $linkweight; + } } } } @@ -1101,6 +1133,10 @@ class Category implements GradebookItem switch ($type) { case 'best': + arsort($totalScorePerStudent); + $maxScore = current($totalScorePerStudent); + + return [$maxScore, $this->get_weight()]; if (empty($bestResult)) { if ($cacheAvailable) { $cacheDriver->save($key, null); @@ -2123,7 +2159,10 @@ class Category implements GradebookItem $sessionId ); $userHasSkills = !empty($userSkills); + } + // Block certification links depending gradebook configuration (generate certifications) + if (empty($category->getGenerateCertificates())) { if ($userHasSkills) { return [ 'badge_link' => Display::toolbarButton( @@ -2133,10 +2172,7 @@ class Category implements GradebookItem ), ]; } - } - // Block certification links depending gradebook configuration (generate certifications) - if (empty($category->getGenerateCertificates())) { return false; } @@ -2217,14 +2253,14 @@ class Category implements GradebookItem 'pdf_link' => $exportToPDF, 'pdf_url' => "$url&action=export", ]; + } - if ($skillToolEnabled && $userHasSkills) { - $html['badge_link'] = Display::toolbarButton( - get_lang('ExportBadges'), - api_get_path(WEB_CODE_PATH)."gradebook/get_badges.php?user=$user_id", - 'external-link' - ); - } + if ($skillToolEnabled && $userHasSkills) { + $html['badge_link'] = Display::toolbarButton( + get_lang('ExportBadges'), + api_get_path(WEB_CODE_PATH)."gradebook/get_badges.php?user=$user_id", + 'external-link' + ); } return $html; diff --git a/main/gradebook/lib/be/exerciselink.class.php b/main/gradebook/lib/be/exerciselink.class.php index 75a33da555..5698733237 100755 --- a/main/gradebook/lib/be/exerciselink.class.php +++ b/main/gradebook/lib/be/exerciselink.class.php @@ -204,10 +204,6 @@ class ExerciseLink extends AbstractLink break; case 'ranking': return [null, null]; - /* - $newList = []; - $ranking = AbstractLink::getCurrentUserRanking($stud_id, $link->getUserScoreList()); - return $ranking;*/ break; default: if (!empty($stud_id)) { diff --git a/main/gradebook/lib/fe/displaygradebook.php b/main/gradebook/lib/fe/displaygradebook.php index 9a5515cfe9..3a51dc051a 100755 --- a/main/gradebook/lib/fe/displaygradebook.php +++ b/main/gradebook/lib/fe/displaygradebook.php @@ -487,7 +487,7 @@ class DisplayGradebook Display::return_icon('edit.png', get_lang('Edit'), '', ICON_SIZE_MEDIUM).''; if (api_get_plugin_setting('customcertificate', 'enable_plugin_customcertificate') == 'true' && - api_get_course_setting('customcertificate_course_enable', $courseCode) == 1 + api_get_course_setting('customcertificate_course_enable') == 1 ) { $actionsRight .= '__soapCall( - 'ws_add_contact_information', - ['contact_params' => $contact_params] - ); - echo $result; + $data = [ + 'person_name' => $person_name, + 'person_email' => $person_email, + 'person_role' => $person_role, + 'financial_decision' => $financial_decision, + 'contact_language' => $contact_language, + 'company_name' => $company_name, + 'company_activity' => $company_activity, + 'company_country' => $company_country, + 'company_city' => $company_city, + ]; + + $client = new GuzzleHttp\Client(); + $options['query'] = $data; + $res = $client->request('GET', $url, $options); + if ($res->getStatusCode() == '200') { + echo '1'; + } } } break; diff --git a/main/inc/ajax/message.ajax.php b/main/inc/ajax/message.ajax.php index c2f7ec38a8..785d0eb937 100755 --- a/main/inc/ajax/message.ajax.php +++ b/main/inc/ajax/message.ajax.php @@ -62,8 +62,6 @@ switch ($action) { case 'get_count_message': $userId = api_get_user_id(); $invitations = []; - $group_pending_invitations = 0; - // Setting notifications $count_unread_message = 0; if (api_get_setting('allow_message_tool') === 'true') { diff --git a/main/inc/ajax/model.ajax.php b/main/inc/ajax/model.ajax.php index a53de6409c..14bf4ba300 100755 --- a/main/inc/ajax/model.ajax.php +++ b/main/inc/ajax/model.ajax.php @@ -275,7 +275,7 @@ switch ($action) { break; case 'get_usergroups_users': $usergroup = new UserGroup(); - $usergroup->protectScript(); + $usergroup->protectScript(null, true, true); $id = isset($_REQUEST['id']) ? $_REQUEST['id'] : 0; $count = $usergroup->getUserGroupUsers($id, true); break; @@ -798,7 +798,7 @@ switch ($action) { break; case 'get_usergroups_teacher': $obj = new UserGroup(); - $obj->protectScript(); + $obj->protectScript(null, false, true); $type = isset($_REQUEST['type']) ? $_REQUEST['type'] : 'registered'; $groupFilter = isset($_REQUEST['group_filter']) ? (int) $_REQUEST['group_filter'] : 0; $keyword = isset($_REQUEST['keyword']) ? $_REQUEST['keyword'] : ''; @@ -829,7 +829,7 @@ switch ($action) { exit; } -//3. Calculating first, end, etc +// 3. Calculating first, end, etc $total_pages = 0; if ($count > 0) { if (!empty($limit)) { @@ -2205,12 +2205,20 @@ switch ($action) { foreach ($result as $group) { $countUsers = count($obj->get_users_by_usergroup($group['id'])); $group['users'] = $countUsers; - - if ($obj->allowTeachers()) { - $group['users'] = Display::url( - $countUsers, - $urlUserGroup.'&id='.$group['id'] - ); + if (!empty($countUsers)) { + if ($obj->allowTeachers()) { + if (isset($group['author_id']) && $group['author_id'] == $currentUserId) { + $group['users'] = Display::url( + $countUsers, + $urlUserGroup.'&id='.$group['id'] + ); + } + } else { + $group['users'] = Display::url( + $countUsers, + $urlUserGroup.'&id='.$group['id'] + ); + } } if ($obj->usergroup_was_added_in_course($group['id'], $course_id)) { diff --git a/main/inc/lib/AnnouncementManager.php b/main/inc/lib/AnnouncementManager.php index 819ab06307..0c58c82a5c 100755 --- a/main/inc/lib/AnnouncementManager.php +++ b/main/inc/lib/AnnouncementManager.php @@ -1034,17 +1034,17 @@ class AnnouncementManager $sql = "SELECT DISTINCT announcement.c_id, count(announcement.id) count - FROM $tbl_announcement announcement - INNER JOIN $tbl_item_property ip - ON (announcement.id = ip.ref AND announcement.c_id = ip.c_id) - WHERE - ip.tool='announcement' AND - ( + FROM $tbl_announcement announcement + INNER JOIN $tbl_item_property ip + ON (announcement.id = ip.ref AND announcement.c_id = ip.c_id) + WHERE + ip.tool='announcement' AND + ( ip.to_user_id = '$user_id' AND - (ip.to_group_id='0' OR ip.to_group_id IS NULL) - ) - AND ip.visibility='1' - AND announcement.session_id = 0 + (ip.to_group_id='0' OR ip.to_group_id IS NULL) + ) + AND ip.visibility='1' + AND announcement.session_id = 0 GROUP BY announcement.c_id"; $rs = Database::query($sql); $num_rows = Database::num_rows($rs); diff --git a/main/inc/lib/Compilatio.php b/main/inc/lib/Compilatio.php index ceac327bff..5d3904df27 100644 --- a/main/inc/lib/Compilatio.php +++ b/main/inc/lib/Compilatio.php @@ -482,7 +482,7 @@ class Compilatio */ public static function plagiarismDeleteDoc($courseId, $itemId) { - if (api_get_configuration_value('allow_compilatio_tool')) { + if (api_get_configuration_value('allow_compilatio_tool') === false) { return false; } diff --git a/main/inc/lib/CoursesAndSessionsCatalog.class.php b/main/inc/lib/CoursesAndSessionsCatalog.class.php index 74944fae4e..484c81b015 100644 --- a/main/inc/lib/CoursesAndSessionsCatalog.class.php +++ b/main/inc/lib/CoursesAndSessionsCatalog.class.php @@ -580,13 +580,14 @@ class CoursesAndSessionsCatalog s.nbrCourses > 0 "; + //('$date' BETWEEN s.accessStartDate AND s.accessEndDate) if (!is_null($date)) { $date = Database::escape_string($date); $dql .= " AND ( (s.accessEndDate IS NULL) OR - ( + ( s.accessStartDate IS NOT NULL AND s.accessEndDate IS NOT NULL AND s.accessStartDate >= '$date' AND s.accessEndDate <= '$date') diff --git a/main/inc/lib/agenda.lib.php b/main/inc/lib/agenda.lib.php index d977829862..2e71e0eae6 100644 --- a/main/inc/lib/agenda.lib.php +++ b/main/inc/lib/agenda.lib.php @@ -2490,12 +2490,16 @@ class Agenda $form->addElement('textarea', 'comment', get_lang('Comment')); $form->addLabel( get_lang('FilesAttachment'), - ' + '
    +
    -
    - '.get_lang('Description').'  

    + + + +
    - ' + +
    ' ); $form->addLabel( @@ -3041,7 +3045,7 @@ class Agenda } $form->addHidden('type', 'personal'); - $sessions = ['0' => get_lang('Select An Option')] + $sessions; + $sessions = ['0' => get_lang('SelectAnOption')] + $sessions; $form->addSelect( 'session_id', diff --git a/main/inc/lib/attendance.lib.php b/main/inc/lib/attendance.lib.php index ff515a3827..3721ca6b87 100755 --- a/main/inc/lib/attendance.lib.php +++ b/main/inc/lib/attendance.lib.php @@ -43,20 +43,30 @@ class Attendance * * @see SortableTable#get_total_number_of_items() */ - public static function getNumberOfAttendances($active = -1) + public static function getNumberOfAttendances() { $tbl_attendance = Database::get_course_table(TABLE_ATTENDANCE); $session_id = api_get_session_id(); $condition_session = api_get_session_condition($session_id); $course_id = api_get_course_int_id(); + + $active_plus = ''; + + if ((isset($_GET['isStudentView']) && $_GET['isStudentView'] == 'true') || + !api_is_allowed_to_edit(null, true) + ) { + $active_plus = ' AND att.active = 1'; + } + $sql = "SELECT COUNT(att.id) AS total_number_of_items FROM $tbl_attendance att - WHERE c_id = $course_id $condition_session "; - - $active = (int) $active; + WHERE + c_id = $course_id AND + active <> 2 $active_plus $condition_session "; + /*$active = (int) $active; if ($active === 1 || $active === 0) { $sql .= "AND att.active = $active"; - } + }*/ $res = Database::query($sql); $obj = Database::fetch_object($res); diff --git a/main/inc/lib/auth.lib.php b/main/inc/lib/auth.lib.php index f4214d6957..26e41a2aa5 100755 --- a/main/inc/lib/auth.lib.php +++ b/main/inc/lib/auth.lib.php @@ -96,6 +96,7 @@ class Auth $visibilityCondition = CourseManager::getCourseVisibilitySQLCondition('course', true); $sql = "SELECT + course.id as real_id, course.code, course.visual_code, course.subscribe subscr, course.unsubscribe unsubscr, course.title title, course.tutor_name tutor, course.directory, course_rel_user.status status, course_rel_user.sort sort, course_rel_user.user_course_cat user_course_cat @@ -128,8 +129,8 @@ class Auth */ public function updateCourseCategory($courseId, $newcategory) { - $courseId = intval($courseId); - $newcategory = intval($newcategory); + $courseId = (int) $courseId; + $newcategory = (int) $newcategory; $current_user = api_get_user_id(); $table = Database::get_main_table(TABLE_MAIN_COURSE_USER); @@ -289,7 +290,7 @@ class Auth { // protect data $title = Database::escape_string($title); - $category_id = intval($category_id); + $category_id = (int) $category_id; $result = false; $table = Database::get_main_table(TABLE_USER_COURSE_CATEGORY); $sql = "UPDATE $table @@ -315,7 +316,7 @@ class Auth $current_user_id = api_get_user_id(); $tucc = Database::get_main_table(TABLE_USER_COURSE_CATEGORY); $TABLECOURSUSER = Database::get_main_table(TABLE_MAIN_COURSE_USER); - $category_id = intval($category_id); + $category_id = (int) $category_id; $result = false; $sql = "DELETE FROM $tucc WHERE @@ -336,6 +337,27 @@ class Auth return $result; } + /** + * @param int $categoryId + * + * @return array|mixed + */ + public function getUserCourseCategory($categoryId) + { + $userId = api_get_user_id(); + $tucc = Database::get_main_table(TABLE_USER_COURSE_CATEGORY); + $categoryId = (int) $categoryId; + + $sql = "SELECT * FROM $tucc + WHERE + id= $categoryId AND + user_id= $userId"; + $resultQuery = Database::query($sql); + $result = Database::fetch_array($resultQuery, 'ASSOC'); + + return $result; + } + /** * unsubscribe the user from a given course. * diff --git a/main/inc/lib/banner.lib.php b/main/inc/lib/banner.lib.php index 49809e174a..82428fadc6 100755 --- a/main/inc/lib/banner.lib.php +++ b/main/inc/lib/banner.lib.php @@ -534,7 +534,6 @@ function return_breadcrumb($interbreadcrumb, $language_file, $nameTools) $i = 0; $final_navigation_count = count($final_navigation); if (!empty($final_navigation)) { - // $home_link.= '/'; if (!empty($home_link)) { $lis .= Display::tag('li', $home_link); } @@ -557,7 +556,7 @@ function return_breadcrumb($interbreadcrumb, $language_file, $nameTools) // View as student/teacher link if (!empty($view_as_student_link)) { - $html .= Display::tag('div', $view_as_student_link, ['id' => 'view_as_link', 'class' => 'float-right']); + $html .= Display::tag('div', $view_as_student_link, ['id' => 'view_as_link', 'class' => 'pull-right']); } if (!empty($navigation_right)) { @@ -566,7 +565,7 @@ function return_breadcrumb($interbreadcrumb, $language_file, $nameTools) $lis .= Display::tag( 'li', $item['title'], - ['class' => $extra_class.' float-right'] + ['class' => $extra_class.' pull-right'] ); } } diff --git a/main/inc/lib/certificate.lib.php b/main/inc/lib/certificate.lib.php index bcecb1db05..b297189b99 100755 --- a/main/inc/lib/certificate.lib.php +++ b/main/inc/lib/certificate.lib.php @@ -612,7 +612,12 @@ class Certificate extends Model return false; } - if (api_get_course_setting('allow_public_certificates', $gradeBookInfo['course_code']) == 0) { + $setting = api_get_course_setting( + 'allow_public_certificates', + api_get_course_info($gradeBookInfo['course_code']) + ); + + if ($setting == 0) { // Printing not allowed return false; } diff --git a/main/inc/lib/course.lib.php b/main/inc/lib/course.lib.php index cbc542edd1..dcc38d7d71 100755 --- a/main/inc/lib/course.lib.php +++ b/main/inc/lib/course.lib.php @@ -769,7 +769,7 @@ class CourseManager ) ); - $send = api_get_course_setting('email_alert_to_teacher_on_new_user_in_course', $courseCode); + $send = api_get_course_setting('email_alert_to_teacher_on_new_user_in_course', $courseInfo); if ($send == 1) { self::email_to_tutor( @@ -785,7 +785,7 @@ class CourseManager ); } - $subscribe = (int) api_get_course_setting('subscribe_users_to_forum_notifications', $courseCode); + $subscribe = (int) api_get_course_setting('subscribe_users_to_forum_notifications', $courseInfo); if ($subscribe === 1) { require_once api_get_path(SYS_CODE_PATH).'forum/forumfunction.inc.php'; $forums = get_forums(0, $courseCode, true, $sessionId); @@ -3698,7 +3698,7 @@ class CourseManager $collapsableLink = ''; if ($collapsable) { $url = api_get_path(WEB_CODE_PATH). - 'auth/courses.php?categoryid='.$row['id'].'&sec_token='.$stok.'&redirect=home'; + 'auth/sort_my_courses.php?categoryid='.$row['id'].'&sec_token='.$stok.'&redirect=home'; $collapsed = isset($row['collapsed']) && $row['collapsed'] ? 1 : 0; if ($collapsed === 0) { $collapsableLink = Display::url( @@ -3926,8 +3926,6 @@ class CourseManager $params['title_cut'] = $params['title']; $params['category'] = $course_info['categoryName']; $params['category_code'] = $course_info['categoryCode']; - //$params['category_id'] = $course_info['categoryId']; - //$params['color'] = Display::randomColor($params['category_id']); $params['teachers'] = $teachers; $params['real_id'] = $course_info['real_id']; @@ -4081,7 +4079,7 @@ class CourseManager $session_url = ''; $params = []; $params['icon'] = Display::return_icon( - 'blackboard_blue.png', + 'session.png', null, [], ICON_SIZE_LARGE, @@ -4153,6 +4151,12 @@ class CourseManager } $params['thumbnails'] = $thumbnails; $params['image'] = $image; + $params['html_image'] = ''; + if (!empty($thumbnails)) { + $params['html_image'] = Display::img($thumbnails, $course_info['name'], ['class' => 'img-responsive']); + } else { + $params['html_image'] = Display::return_icon('session.png', $course_info['name'], ['class' => 'img-responsive'], ICON_SIZE_LARGE, $course_info['name']); + } $params['link'] = $session_url; $params['title'] = $session_title; $params['name'] = $course_info['name']; @@ -4168,7 +4172,7 @@ class CourseManager if ($load_dirs) { $params['document'] .= '
    '. Display::returnFontAwesomeIcon('folder-open').''; $params['document'] .= Display::div('', [ diff --git a/main/inc/lib/course_category.lib.php b/main/inc/lib/course_category.lib.php index 04333c56b5..2622b006cc 100755 --- a/main/inc/lib/course_category.lib.php +++ b/main/inc/lib/course_category.lib.php @@ -16,7 +16,7 @@ class CourseCategory public static function getCategoryById($categoryId) { $table = Database::get_main_table(TABLE_MAIN_CATEGORY); - $categoryId = intval($categoryId); + $categoryId = (int) $categoryId; $sql = "SELECT * FROM $table WHERE id = $categoryId"; $result = Database::query($sql); if (Database::num_rows($result)) { @@ -29,7 +29,7 @@ class CourseCategory /** * Get category details from a simple category code. * - * @param string $category The literal category code + * @param string $categoryCode The literal category code * * @return array */ @@ -41,16 +41,18 @@ class CourseCategory $result = Database::query($sql); if (Database::num_rows($result)) { $category = Database::fetch_array($result, 'ASSOC'); - // Get access url id - $table = Database::get_main_table(TABLE_MAIN_ACCESS_URL_REL_COURSE_CATEGORY); - $sql = "SELECT * FROM $table WHERE course_category_id = ".$category['id']; - $result = Database::query($sql); - $result = Database::fetch_array($result); - if ($result) { - $category['access_url_id'] = $result['access_url_id']; - } + if ($category) { + // Get access url id + $table = Database::get_main_table(TABLE_MAIN_ACCESS_URL_REL_COURSE_CATEGORY); + $sql = "SELECT * FROM $table WHERE course_category_id = ".$category['id']; + $result = Database::query($sql); + $result = Database::fetch_array($result); + if ($result) { + $category['access_url_id'] = $result['access_url_id']; + } - return $category; + return $category; + } } return []; @@ -197,11 +199,17 @@ class CourseCategory ]; $categoryId = Database::insert($table, $params); + if ($categoryId) { + self::updateParentCategoryChildrenCount($parent_id, 1); + UrlManager::addCourseCategoryListToUrl( + [$categoryId], + [api_get_current_access_url_id()] + ); - self::updateParentCategoryChildrenCount($parent_id, 1); - self::addToUrl($categoryId); + return $categoryId; + } - return $categoryId; + return false; } /** @@ -214,7 +222,7 @@ class CourseCategory { $table = Database::get_main_table(TABLE_MAIN_CATEGORY); $categoryId = Database::escape_string($categoryId); - $delta = intval($delta); + $delta = (int) $delta; // First get to the highest level possible in the tree $result = Database::query("SELECT parent_id FROM $table WHERE code = '$categoryId'"); $row = Database::fetch_array($result); @@ -223,7 +231,6 @@ class CourseCategory self::updateParentCategoryChildrenCount($row['parent_id'], $delta); } // Now we're at the top, get back down to update each child - //$children_count = courseCategoryChildrenCount($categoryId); $sql = "UPDATE $table SET children_count = (children_count - ".abs($delta).") WHERE code = '$categoryId'"; if ($delta >= 0) { $sql = "UPDATE $table SET children_count = (children_count + $delta) WHERE code = '$categoryId'"; @@ -328,7 +335,7 @@ class CourseCategory { $table = Database::get_main_table(TABLE_MAIN_CATEGORY); $code = Database::escape_string($code); - $tree_pos = intval($tree_pos); + $tree_pos = (int) $tree_pos; $parent_id = Database::escape_string($parent_id); $parentIdCondition = " AND (parent_id IS NULL OR parent_id = '' )"; @@ -382,7 +389,7 @@ class CourseCategory public static function courseCategoryChildrenCount($categoryId) { $table = Database::get_main_table(TABLE_MAIN_CATEGORY); - $categoryId = intval($categoryId); + $categoryId = (int) $categoryId; $count = 0; if (empty($categoryId)) { return 0; @@ -486,7 +493,7 @@ class CourseCategory $categorySource = Security::remove_XSS($categorySource); if (count($categories) > 0) { - $table = new HTML_Table(['class' => 'table data_table']); + $table = new HTML_Table(['class' => 'data_table']); $column = 0; $row = 0; $headers = [ @@ -578,19 +585,6 @@ class CourseCategory return Database::store_result(Database::query($sql)); } - /** - * @param int $id - * - * @return bool - */ - public static function addToUrl($id) - { - UrlManager::addCourseCategoryListToUrl( - [$id], - [api_get_current_access_url_id()] - ); - } - /** * @param string $categoryCode * @@ -902,21 +896,14 @@ class CourseCategory */ public static function getCourseCatalogNameTools($action) { - $nameTools = get_lang('SortMyCourses'); + $nameTools = get_lang('MyCourses'); if (empty($action)) { return $nameTools; //should never happen } switch ($action) { - case 'createcoursecategory': - $nameTools = get_lang('CreateCourseCategory'); - break; case 'subscribe': - $nameTools = get_lang('CourseManagement'); - break; case 'subscribe_user_with_password': - $nameTools = get_lang('CourseManagement'); - break; case 'display_random_courses': case 'display_courses': $nameTools = get_lang('CourseManagement'); @@ -990,37 +977,4 @@ class CourseCategory return true; } - - /** - * Deletes the image on disk and in the database. - * - * @param $categoryId - * - * @return bool Always returns true - */ - public static function deletePictureCategory($categoryId) - { - $dirName = 'course_category/'; - $fileImage = $dirName.'cc_'.$categoryId.'.jpg'; - $fileDir = api_get_path(SYS_UPLOAD_PATH).$fileImage; - if (file_exists($fileDir)) { - try { - unlink($fileDir); - } catch (Exception $e) { - error_log($e->getMessage()); - } - } - $table = Database::get_main_table(TABLE_MAIN_CATEGORY); - $result = Database::update( - $table, - ['image' => ''], - ['id = ?' => $categoryId] - ); - - if ($result) { - return true; - } - - return false; - } } diff --git a/main/inc/lib/course_home.lib.php b/main/inc/lib/course_home.lib.php index fc332c12a3..2e5f7a91b1 100755 --- a/main/inc/lib/course_home.lib.php +++ b/main/inc/lib/course_home.lib.php @@ -861,7 +861,7 @@ class CourseHome $item = []; $studentview = false; $tool['original_link'] = $tool['link']; - if ($tool['image'] == 'scormbuilder.gif') { + if ($tool['image'] === 'scormbuilder.gif') { // Check if the published learnpath is visible for student $lpId = self::getPublishedLpIdFromLink($tool['link']); if (api_is_allowed_to_edit(null, true)) { @@ -929,9 +929,8 @@ class CourseHome switch ($visibility) { case '0': $info = pathinfo($tool['image']); - $basename = basename($tool['image'], '.'.$info['extension']); // $file is set to "index" + $basename = basename($tool['image'], '.'.$info['extension']); $tool['image'] = $basename.'_na.'.$info['extension']; - $link['name'] = Display::return_icon( 'invisible.png', get_lang('Activate'), @@ -980,7 +979,7 @@ class CourseHome } } - $item['visibility'] = null; + $item['visibility'] = ''; if (isset($lnk) && is_array($lnk)) { foreach ($lnk as $this_link) { if (empty($tool['adminlink'])) { @@ -989,8 +988,6 @@ class CourseHome $this_link['name'].''; } } - } else { - $item['visibility'] .= ''; } // NOTE : Table contains only the image file name, not full path @@ -1005,14 +1002,14 @@ class CourseHome if ($tool['visibility'] == '0' && $toolAdmin != '1') { $class = 'text-muted'; $info = pathinfo($tool['image']); - $basename = basename($tool['image'], '.'.$info['extension']); // $file is set to "index" + $basename = basename($tool['image'], '.'.$info['extension']); $tool['image'] = $basename.'_na.'.$info['extension']; } $qm_or_amp = strpos($tool['link'], '?') === false ? '?' : '&'; // If it's a link, we don't add the cidReq - if ($tool['image'] == 'file_html.png' || $tool['image'] == 'file_html_na.png') { + if ($tool['image'] === 'file_html.png' || $tool['image'] === 'file_html_na.png') { $tool['link'] = $tool['link']; } else { $tool['link'] = $tool['link'].$qm_or_amp.api_get_cidreq(); @@ -1219,7 +1216,7 @@ class CourseHome 'external_na.gif', ]; - $toolName = Security::remove_XSS(stripslashes($tool['name'])); + $toolName = Security::remove_XSS(stripslashes(strip_tags($tool['name']))); if (isset($tool['image']) && in_array($tool['image'], $already_translated_icons)) { return $toolName; @@ -1819,7 +1816,7 @@ class CourseHome } return Display::return_icon( - 'tool_'.$image, + $image, $item['name'], ['id' => $id], $iconSize, diff --git a/main/inc/lib/display.lib.php b/main/inc/lib/display.lib.php index 33ee24cb07..44a88a44d3 100755 --- a/main/inc/lib/display.lib.php +++ b/main/inc/lib/display.lib.php @@ -2388,6 +2388,33 @@ class Display return $html; } + /** + * @param $url + * @param $currentPage + * @param $pagesCount + * @param $totalItems + * + * @return string + */ + public static function getPagination($url, $currentPage, $pagesCount, $totalItems) + { + $pagination = ''; + if ($totalItems > 1 && $pagesCount > 1) { + $pagination .= '
      '; + for ($i = 0; $i < $pagesCount; $i++) { + $newPage = $i + 1; + if ($currentPage == $newPage) { + $pagination .= '
    • '.$newPage.'
    • '; + } else { + $pagination .= '
    • '.$newPage.'
    • '; + } + } + $pagination .= '
    '; + } + + return $pagination; + } + /** * Adds a message in the queue. * diff --git a/main/inc/lib/extra_field.lib.php b/main/inc/lib/extra_field.lib.php index 5ae2e9abdb..3bae143e1a 100755 --- a/main/inc/lib/extra_field.lib.php +++ b/main/inc/lib/extra_field.lib.php @@ -2661,6 +2661,7 @@ JAVASCRIPT; [ 'title' => $field['display_text'], 'target' => '_blank', + 'class' => 'download_extra_field', ] ); break; diff --git a/main/inc/lib/extra_field_value.lib.php b/main/inc/lib/extra_field_value.lib.php index 5f1785d082..2659383cd4 100755 --- a/main/inc/lib/extra_field_value.lib.php +++ b/main/inc/lib/extra_field_value.lib.php @@ -1030,27 +1030,6 @@ class ExtraFieldValue extends Model Database::query($sql); } - /** - * Deletes values of a specific field for a specific item. - * - * @param int $item_id (session id, course id, etc) - * @param int $field_id - * @assert (-1,-1) == null - */ - public function delete_values_by_handler_and_field_id($item_id, $field_id) - { - $field_id = (int) $field_id; - $item_id = (int) $item_id; - $extraFieldType = $this->getExtraField()->getExtraFieldType(); - - $sql = "DELETE FROM {$this->table} - WHERE - item_id = '$item_id' AND - field_id = '$field_id' - "; - Database::query($sql); - } - /** * Deletes all values from an item. * @@ -1108,20 +1087,6 @@ class ExtraFieldValue extends Model return false; } - /** - * Not yet implemented - Compares the field values of two items. - * - * @param int $item_id Item 1 - * @param int $item_to_compare Item 2 - * - * @todo - * - * @return mixed Differential array generated from the comparison - */ - public function compareItemValues($item_id, $item_to_compare) - { - } - /** * Get all values for an item. * diff --git a/main/inc/lib/formvalidator/FormValidator.class.php b/main/inc/lib/formvalidator/FormValidator.class.php index 6ba7be585b..d1cdc86002 100755 --- a/main/inc/lib/formvalidator/FormValidator.class.php +++ b/main/inc/lib/formvalidator/FormValidator.class.php @@ -1038,6 +1038,11 @@ EOT; $attributes['cols'] = isset($config['cols']) ? $config['cols'] : 80; $attributes['cols-size'] = isset($config['cols-size']) ? $config['cols-size'] : []; $attributes['class'] = isset($config['class']) ? $config['class'] : []; + $attributes['id'] = isset($config['id']) ? $config['id'] : ''; + + if (empty($attributes['id'])) { + $attributes['id'] = $name; + } $this->addElement('html_editor', $name, $label, $attributes, $config); $this->applyFilter($name, 'trim'); diff --git a/main/inc/lib/link.lib.php b/main/inc/lib/link.lib.php index 02dd3679e7..b8d44c71d2 100755 --- a/main/inc/lib/link.lib.php +++ b/main/inc/lib/link.lib.php @@ -1314,127 +1314,6 @@ class Link extends Model Display::addFlash(Display::return_message(get_lang('LinkMoved'))); } - /** - * CSV file import functions. - * - * @author René Haentjens , Ghent University - * - * @param string $catname - * - * @return int - */ - public static function get_cat($catname) - { - // Get category id (existing or make new). - $tbl_categories = Database::get_course_table(TABLE_LINK_CATEGORY); - $course_id = api_get_course_int_id(); - - $result = Database:: query( - "SELECT id FROM ".$tbl_categories." - WHERE c_id = $course_id AND category_title='".Database::escape_string($catname)."'" - ); - if (Database:: num_rows($result) >= 1 && ($row = Database:: fetch_array($result))) { - return $row['id']; // Several categories with same name: take the first. - } - - $result = Database:: query( - "SELECT MAX(display_order) FROM ".$tbl_categories." WHERE c_id = $course_id " - ); - list($max_order) = Database:: fetch_row($result); - - $params = [ - 'c_id' => $course_id, - 'category_title' => $catname, - 'description' => '', - 'display_order' => $max_order + 1, - ]; - $id = Database::insert($tbl_categories, $params); - - return $id; - } - - /** - * CSV file import functions. - * - * @author René Haentjens , Ghent University - * - * @param string $url - * @param string $title - * @param string $description - * @param string $on_homepage - * @param string $hidden - */ - public static function put_link($url, $cat, $title, $description, $on_homepage, $hidden) - { - $_course = api_get_course_info(); - $_user = api_get_user_info(); - - $tbl_link = Database::get_course_table(TABLE_LINK); - $course_id = api_get_course_int_id(); - - $urleq = "url='".Database:: escape_string($url)."'"; - $cateq = "category_id=".intval($cat); - - $result = Database:: query( - " - SELECT id FROM $tbl_link - WHERE c_id = $course_id AND ".$urleq.' AND '.$cateq - ); - - if (Database:: num_rows($result) >= 1 && ($row = Database:: fetch_array($result))) { - $sql = "UPDATE $tbl_link SET - title = '".Database:: escape_string($title)."', - description = '".Database:: escape_string($description)."' - WHERE c_id = $course_id AND id='".Database:: escape_string($row['id'])."'"; - Database:: query($sql); - - $ipu = 'LinkUpdated'; - $rv = 1; // 1 = upd - } else { - // Add new link - $result = Database:: query( - "SELECT MAX(display_order) FROM $tbl_link - WHERE c_id = $course_id AND category_id='".intval($cat)."'" - ); - list($max_order) = Database:: fetch_row($result); - - Database:: query( - "INSERT INTO $tbl_link (c_id, url, title, description, category_id, display_order, on_homepage) - VALUES (".api_get_course_int_id().", - '".Database:: escape_string($url)."', - '".Database:: escape_string($title)."', - '".Database:: escape_string($description)."', - '".intval($cat)."','".(intval($max_order) + 1)."', - '".intval($on_homepage). - "')" - ); - - $id = Database:: insert_id(); - $ipu = 'LinkAdded'; - $rv = 2; // 2 = new - } - - api_item_property_update( - $_course, - TOOL_LINK, - $id, - $ipu, - $_user['user_id'] - ); - - if ($hidden && $ipu == 'LinkAdded') { - api_item_property_update( - $_course, - TOOL_LINK, - $id, - 'invisible', - $_user['user_id'] - ); - } - - return $rv; - } - /** * This function checks if the url is a vimeo link. * diff --git a/main/inc/lib/plugin.lib.php b/main/inc/lib/plugin.lib.php index 3c79d01d4b..f559897eec 100755 --- a/main/inc/lib/plugin.lib.php +++ b/main/inc/lib/plugin.lib.php @@ -31,6 +31,7 @@ class AppPlugin public $installedPluginListName = []; public $installedPluginListObject = []; + private static $instance; /** * Constructor. @@ -39,6 +40,18 @@ class AppPlugin { } + /** + * @return AppPlugin + */ + public static function getInstance() + { + if (!isset(self::$instance)) { + self::$instance = new self(); + } + + return self::$instance; + } + /** * Read plugin from path. * @@ -61,30 +74,13 @@ class AppPlugin return $plugins; } - /** - * @return array - */ - public function get_installed_plugins_by_region() - { - $plugins = []; - /* We retrieve all the active plugins. */ - $result = api_get_settings('Plugins'); - if (!empty($result)) { - foreach ($result as $row) { - $plugins[$row['variable']][] = $row['selected_value']; - } - } - - return $plugins; - } - /** * @return array */ public function getInstalledPluginListName() { if (empty($this->installedPluginListName)) { - $this->installedPluginListName = $this->get_installed_plugins(); + $this->installedPluginListName = $this->getInstalledPlugins(); } return $this->installedPluginListName; @@ -118,22 +114,46 @@ class AppPlugin } /** + * @param string $plugin + * + * @return bool + */ + public function isInstalled($plugin) + { + $list = self::getInstalledPlugins(false); + + return in_array($plugin, $list); + } + + /** + * @param bool $fromDatabase + * * @return array */ - public function get_installed_plugins() + public function getInstalledPlugins($fromDatabase = true) { - $installedPlugins = []; - $plugins = api_get_settings_params( - [ - "variable = ? AND selected_value = ? AND category = ? " => ['status', 'installed', 'Plugins'], - ] - ); + static $installedPlugins = null; - if (!empty($plugins)) { - foreach ($plugins as $row) { - $installedPlugins[$row['subkey']] = true; + if ($fromDatabase === false) { + if (is_array($installedPlugins)) { + return $installedPlugins; + } + } + + if ($fromDatabase || $installedPlugins === null) { + $installedPlugins = []; + $plugins = api_get_settings_params( + [ + 'variable = ? AND selected_value = ? AND category = ? ' => ['status', 'installed', 'Plugins'], + ] + ); + + if (!empty($plugins)) { + foreach ($plugins as $row) { + $installedPlugins[$row['subkey']] = true; + } + $installedPlugins = array_keys($installedPlugins); } - $installedPlugins = array_keys($installedPlugins); } return $installedPlugins; @@ -145,10 +165,9 @@ class AppPlugin */ public function install($pluginName, $urlId = null) { + $urlId = (int) $urlId; if (empty($urlId)) { $urlId = api_get_current_access_url_id(); - } else { - $urlId = intval($urlId); } api_add_setting( @@ -180,10 +199,9 @@ class AppPlugin */ public function uninstall($pluginName, $urlId = null) { + $urlId = (int) $urlId; if (empty($urlId)) { $urlId = api_get_current_access_url_id(); - } else { - $urlId = intval($urlId); } // First call the custom uninstall to allow full access to global settings @@ -193,6 +211,7 @@ class AppPlugin require $pluginPath; } + // Second remove all remaining global settings api_delete_settings_params( ['category = ? AND access_url = ? AND subkey = ? ' => ['Plugins', $urlId, $pluginName]] @@ -217,16 +236,6 @@ class AppPlugin return $areas; } - /** - * @param string $location - * - * @return bool - */ - public function is_valid_plugin_location($location) - { - return in_array($location, $this->plugin_list); - } - /** * @param string $pluginName * @@ -246,7 +255,7 @@ class AppPlugin /** * @return array */ - public function getPluginRegions() + public function get_plugin_regions() { sort($this->plugin_regions); @@ -459,9 +468,9 @@ class AppPlugin $plugin_info = $this->getPluginInfo($pluginName); if (isset($plugin_info) && isset($plugin_info['templates'])) { return $plugin_info['templates']; - } else { - return false; } + + return false; } /** diff --git a/main/inc/lib/sessionmanager.lib.php b/main/inc/lib/sessionmanager.lib.php index c1cf7355de..a58cdee746 100755 --- a/main/inc/lib/sessionmanager.lib.php +++ b/main/inc/lib/sessionmanager.lib.php @@ -488,7 +488,7 @@ class SessionManager if (!api_is_platform_admin()) { if (api_is_session_admin() && - api_get_setting('allow_session_admins_to_manage_all_sessions') == 'false' + api_get_setting('allow_session_admins_to_manage_all_sessions') === 'false' ) { $where .= " AND s.session_admin_id = $userId "; } @@ -496,7 +496,7 @@ class SessionManager if (!api_is_platform_admin() && api_is_teacher() && - api_get_setting('allow_teachers_to_create_sessions') == 'true' + api_get_setting('allow_teachers_to_create_sessions') === 'true' ) { $where .= " AND s.id_coach = $userId "; } @@ -2299,7 +2299,7 @@ class SessionManager $course_code = Database::escape_string($course_code); $courseInfo = api_get_course_info($course_code); $courseId = $courseInfo['real_id']; - $subscribe = (int) api_get_course_setting('subscribe_users_to_forum_notifications', $course_code); + $subscribe = (int) api_get_course_setting('subscribe_users_to_forum_notifications', $courseInfo); $forums = []; if ($subscribe === 1) { require_once api_get_path(SYS_CODE_PATH).'forum/forumfunction.inc.php'; @@ -3299,33 +3299,6 @@ class SessionManager } } - /** - * Get the session image. - * - * @param int $id - * - * @return image path - */ - public static function getSessionImage($id) - { - $id = (int) $id; - $extraFieldValuesTable = Database::get_main_table(TABLE_EXTRA_FIELD_VALUES); - $sql = "SELECT value FROM $extraFieldValuesTable WHERE field_id = 16 AND item_id = ".$id; - $result = Database::query($sql); - if (Database::num_rows($result) > 0) { - while ($row = Database::fetch_array($result, 'ASSOC')) { - $sessionImage = $row['value']; - $sessionImage = api_get_path(WEB_UPLOAD_PATH).$sessionImage; - } - - return $sessionImage; - } else { - $sessionImage = api_get_path(WEB_PUBLIC_PATH)."img/session_default.png"; - - return $sessionImage; - } - } - /** * Get Hot Sessions (limit 8). * @@ -3956,7 +3929,7 @@ class SessionManager $tbl_course = Database::get_main_table(TABLE_MAIN_COURSE); $tbl_session_rel_course = Database::get_main_table(TABLE_MAIN_SESSION_COURSE); $session_id = (int) $session_id; - $sqlSelect = '*, c.id, c.id as real_id'; + $sqlSelect = '*, c.id, c.id as real_id, c.code as course_code'; if ($getCount) { $sqlSelect = 'COUNT(1) as count'; @@ -4433,22 +4406,25 @@ class SessionManager /** * Copies a session with the same data to a new session. - * The new copy is not assigned to the same promotion. @see subscribe_sessions_to_promotions() for that. + * The new copy is not assigned to the same promotion. + * * - * @param int Session ID - * @param bool Whether to copy the relationship with courses - * @param bool Whether to copy the relationship with users - * @param bool New courses will be created - * @param bool Whether to set exercises and learning paths in the new session to invisible by default + * @param int $id Session ID + * @param bool $copy_courses Whether to copy the relationship with courses + * @param bool $copyTeachersAndDrh + * @param bool $create_new_courses New courses will be created + * @param bool $set_exercises_lp_invisible Set exercises and LPs in the new session to invisible by default * * @return int The new session ID on success, 0 otherwise * + * @see subscribe_sessions_to_promotions() for that. + * * @todo make sure the extra session fields are copied too */ public static function copy( $id, $copy_courses = true, - $copy_users = true, + $copyTeachersAndDrh = true, $create_new_courses = false, $set_exercises_lp_invisible = false ) { @@ -4483,7 +4459,7 @@ class SessionManager if (api_strtotime($s['coach_access_end_date']) < $now) { $s['coach_access_end_date'] = $inOneMonth; } - // Now try to create the session + $extraFieldValue = new ExtraFieldValue('session'); $extraFieldsValues = $extraFieldValue->getAllValuesByItem($id); $extraFieldsValuesToCopy = []; @@ -4520,7 +4496,6 @@ class SessionManager if ($copy_courses) { // Register courses from the original session to the new session $courses = self::get_course_list_by_session_id($id); - $short_courses = $new_short_courses = []; if (is_array($courses) && count($courses) > 0) { foreach ($courses as $course) { @@ -4528,7 +4503,6 @@ class SessionManager } } - $courses = null; // We will copy the current courses of the session to new courses if (!empty($short_courses)) { if ($create_new_courses) { @@ -4586,11 +4560,19 @@ class SessionManager $short_courses = $new_short_courses; self::add_courses_to_session($sid, $short_courses, true); - $short_courses = null; + + if ($create_new_courses === false && $copyTeachersAndDrh) { + foreach ($short_courses as $course) { + $coachList = self::getCoachesByCourseSession($id, $course['id']); + foreach ($coachList as $userId) { + self::set_coach_to_course_session($userId, $sid, $course['id']); + } + } + } } } - if ($copy_users) { + if ($copyTeachersAndDrh) { // Register users from the original session to the new session $users = self::get_users_by_session($id); if (!empty($users)) { @@ -4599,23 +4581,24 @@ class SessionManager $userData['relation_type'] = (int) $userData['relation_type']; $userListByStatus[$userData['relation_type']][] = $userData; } - //Subscribing in read only mode + foreach ($userListByStatus as $status => $userList) { $userList = array_column($userList, 'user_id'); switch ($status) { case 0: - self::subscribeUsersToSession( - $sid, + /*self::subscribeUsersToSession( + $sid, $userList, - SESSION_VISIBLE_READ_ONLY, + SESSION_VISIBLE_READ_ONLY, false, - true - ); + true + );*/ break; case 1: + // drh users foreach ($userList as $drhId) { - $drhId = api_get_user_info($drhId); - self::subscribeSessionsToDrh($drhId, [$sid], false); + $userInfo = api_get_user_info($drhId); + self::subscribeSessionsToDrh($userInfo, [$sid], false, false); } break; } @@ -6857,9 +6840,9 @@ SQL; */ public static function editUserSessionDuration($duration, $userId, $sessionId) { - $duration = intval($duration); - $userId = intval($userId); - $sessionId = intval($sessionId); + $duration = (int) $duration; + $userId = (int) $userId; + $sessionId = (int) $sessionId; if (empty($userId) || empty($sessionId)) { return false; @@ -9085,6 +9068,7 @@ SQL; } $userRelSession = self::getUserSession($userId, $sessionId); + if ($userRelSession) { if (isset($userRelSession['collapsed']) && $userRelSession['collapsed'] != '') { $collapsed = $userRelSession['collapsed']; diff --git a/main/inc/lib/social.lib.php b/main/inc/lib/social.lib.php index efa6d5c256..782bc36da9 100755 --- a/main/inc/lib/social.lib.php +++ b/main/inc/lib/social.lib.php @@ -53,25 +53,6 @@ class SocialManager extends UserManager } } - /** - * Get relation type contact by name. - * - * @param string names of the kind of relation - * - * @return int - * - * @author isaac flores paz - */ - public static function get_relation_type_by_name($relation_type_name) - { - $list_type_friend = self::show_list_type_friends(); - foreach ($list_type_friend as $value_type_friend) { - if (strtolower($value_type_friend['title']) == $relation_type_name) { - return $value_type_friend['id']; - } - } - } - /** * Get the kind of relation between contacts. * @@ -301,7 +282,7 @@ class SocialManager extends UserManager $row_if_exist = Database::fetch_array($res_if_exist, 'ASSOC'); if ($row_if_exist['count'] == 1) { $sql = 'UPDATE '.$tbl_message.' SET - msg_status=5, content = "'.$clean_message_content.'" + msg_status = 5, content = "'.$clean_message_content.'" WHERE user_sender_id='.$user_id.' AND user_receiver_id='.$friend_id.' AND @@ -331,7 +312,7 @@ class SocialManager extends UserManager $sql = 'SELECT COUNT(*) as count_message_in_box FROM '.$table.' WHERE user_receiver_id='.$userId.' AND - msg_status='.MESSAGE_STATUS_INVITATION_PENDING; + msg_status = '.MESSAGE_STATUS_INVITATION_PENDING; $res = Database::query($sql); $row = Database::fetch_array($res, 'ASSOC'); if ($row) { @@ -1242,8 +1223,8 @@ class SocialManager extends UserManager Display::return_icon( 'announcement.png', get_lang('Announcements') - ).$announcement['course']['name'].' ('.$announcement['count'].')', - api_get_path(WEB_CODE_PATH).'announcements/announcements.php?cidReq='.$announcement['course']['code'] + ).$announcement['course']['name'].' ('.$announcement['count'].')', + api_get_path(WEB_CODE_PATH).'announcements/announcements.php?cidReq='.$announcement['course']['code'] ); $announcements[] = Display::tag('li', $url); } @@ -1643,10 +1624,9 @@ class SocialManager extends UserManager $select = ' SELECT count(id) as count_items '; } - $sql = "$select - FROM $tblMessage m - WHERE - msg_status <> ".MESSAGE_STATUS_WALL_DELETE.' AND '; + $sqlBase = "$select FROM $tblMessage m WHERE "; + $sql = []; + $sql[1] = $sqlBase."msg_status <> ".MESSAGE_STATUS_WALL_DELETE.' AND '; // Get my own posts $userReceiverCondition = ' ( @@ -1655,24 +1635,25 @@ class SocialManager extends UserManager parent_id = '.$parentId.' )'; - $sql .= $userReceiverCondition; + $sql[1] .= $userReceiverCondition; - $sql .= ' OR ( - msg_status IN ('.MESSAGE_STATUS_PROMOTED.') - ) '; + $sql[2] = $sqlBase.' msg_status = '.MESSAGE_STATUS_PROMOTED.' '; // Get my group posts $groupCondition = ''; if (!empty($groupId)) { if (is_array($groupId)) { $groupId = array_map('intval', $groupId); - $groupId = implode("','", $groupId); - $groupCondition = " OR ( group_id IN ('$groupId') "; + $groupId = implode(",", $groupId); + $groupCondition = " ( group_id IN ($groupId) "; } else { $groupId = (int) $groupId; - $groupCondition = " OR ( group_id = '$groupId' "; + $groupCondition = " ( group_id = $groupId "; } - $groupCondition .= ' AND msg_status IN ('.MESSAGE_STATUS_NEW.', '.MESSAGE_STATUS_UNREAD.')) '; + $groupCondition .= ' AND (msg_status = '.MESSAGE_STATUS_NEW.' OR msg_status = '.MESSAGE_STATUS_UNREAD.')) '; + } + if (!empty($groupCondition)) { + $sql[3] = $sqlBase.$groupCondition; } // Get my friend posts @@ -1680,31 +1661,30 @@ class SocialManager extends UserManager if (!empty($friendId)) { if (is_array($friendId)) { $friendId = array_map('intval', $friendId); - $friendId = implode("','", $friendId); - $friendCondition = " OR ( user_receiver_id IN ('$friendId') "; + $friendId = implode(",", $friendId); + $friendCondition = " ( user_receiver_id IN ($friendId) "; } else { $friendId = (int) $friendId; - $friendCondition = " OR ( user_receiver_id = '$friendId' "; + $friendCondition = " ( user_receiver_id = $friendId "; } - $friendCondition .= ' AND msg_status IN ('.MESSAGE_STATUS_WALL_POST.') AND parent_id = 0) '; + $friendCondition .= ' AND msg_status = '.MESSAGE_STATUS_WALL_POST.' AND parent_id = 0) '; } - - if (!empty($groupCondition) || !empty($friendCondition)) { - $sql .= " $groupCondition $friendCondition "; + if (!empty($friendCondition)) { + $sql[4] = $sqlBase.$friendCondition; } if (!empty($threadList)) { if ($getCount) { - $select = ' SELECT count(iid) count '; + $select = ' SELECT count(iid) count_items '; } else { $select = " SELECT - iid, - poster_id, + iid as id, + poster_id as user_sender_id, '' as user_receiver_id, - post_date, - post_text, + post_date as send_date, + post_text as content, '' as parent_id, - ".MESSAGE_STATUS_FORUM.", + ".MESSAGE_STATUS_FORUM." as msg_status, '' as group_id, forum_id, thread_id, @@ -1715,72 +1695,86 @@ class SocialManager extends UserManager $threadList = array_map('intval', $threadList); $threadList = implode("','", $threadList); $condition = " thread_id IN ('$threadList') "; - $sql .= " - UNION ( - $select + $sql[5] = "$select FROM c_forum_post WHERE $condition - ) "; } if ($getCount) { - $res = Database::query($sql); - $row = Database::fetch_array($res); + $count = 0; + foreach ($sql as $oneQuery) { + if (!empty($oneQuery)) { + $res = Database::query($oneQuery); + $row = Database::fetch_array($res); + $count += (int) $row['count_items']; + } + } - return (int) $row['count']; + return $count; } - $sql .= ' ORDER BY send_date DESC '; - $sql .= " LIMIT $start, $length "; - + $sqlOrder = ' ORDER BY send_date DESC '; + $sqlLimit = " LIMIT $start, $length "; $messages = []; - $res = Database::query($sql); - $em = Database::getManager(); - if (Database::num_rows($res) > 0) { - $repo = $em->getRepository('ChamiloCourseBundle:CForumPost'); - $repoThread = $em->getRepository('ChamiloCourseBundle:CForumThread'); - $groups = []; - $userGroup = new UserGroup(); - $urlGroup = api_get_path(WEB_CODE_PATH).'social/group_view.php?id='; - while ($row = Database::fetch_array($res, 'ASSOC')) { - $row['group_info'] = []; - if (!empty($row['group_id'])) { - if (!in_array($row['group_id'], $groups)) { - $group = $userGroup->get($row['group_id']); - $group['url'] = $urlGroup.$group['id']; - $groups[$row['group_id']] = $group; - $row['group_info'] = $group; - } else { - $row['group_info'] = $groups[$row['group_id']]; + foreach ($sql as $index => $oneQuery) { + if ($index === 5) { + // Exception only for the forum query above (field name change) + $oneQuery .= ' ORDER BY post_date DESC '.$sqlLimit; + } else { + $oneQuery .= $sqlOrder.$sqlLimit; + } + $res = Database::query($oneQuery); + $em = Database::getManager(); + if (Database::num_rows($res) > 0) { + $repo = $em->getRepository('ChamiloCourseBundle:CForumPost'); + $repoThread = $em->getRepository('ChamiloCourseBundle:CForumThread'); + $groups = []; + $userGroup = new UserGroup(); + $urlGroup = api_get_path(WEB_CODE_PATH).'social/group_view.php?id='; + while ($row = Database::fetch_array($res, 'ASSOC')) { + $row['group_info'] = []; + if (!empty($row['group_id'])) { + if (!in_array($row['group_id'], $groups)) { + $group = $userGroup->get($row['group_id']); + $group['url'] = $urlGroup.$group['id']; + $groups[$row['group_id']] = $group; + $row['group_info'] = $group; + } else { + $row['group_info'] = $groups[$row['group_id']]; + } } - } - // Forums - $row['post_title'] = ''; - $row['forum_title'] = ''; - $row['thread_url'] = ''; - if ($row['msg_status'] == MESSAGE_STATUS_FORUM) { - /** @var CForumPost $post */ - $post = $repo->find($row['id']); - /** @var CForumThread $thread */ - $thread = $repoThread->find($row['thread_id']); - if ($post && $thread) { - $courseInfo = api_get_course_info_by_id($post->getCId()); - $row['post_title'] = $post->getForumId(); - $row['forum_title'] = $thread->getThreadTitle(); - $row['thread_url'] = api_get_path(WEB_CODE_PATH).'forum/viewthread.php?'.http_build_query([ - 'cidReq' => $courseInfo['code'], - 'forum' => $post->getForumId(), - 'thread' => $post->getThreadId(), - 'post_id' => $post->getIid(), - ]).'#post_id_'.$post->getIid(); + // Forums + $row['post_title'] = ''; + $row['forum_title'] = ''; + $row['thread_url'] = ''; + if ($row['msg_status'] == MESSAGE_STATUS_FORUM) { + /** @var CForumPost $post */ + $post = $repo->find($row['id']); + /** @var CForumThread $thread */ + $thread = $repoThread->find($row['thread_id']); + if ($post && $thread) { + $courseInfo = api_get_course_info_by_id($post->getCId()); + $row['post_title'] = $post->getForumId(); + $row['forum_title'] = $thread->getThreadTitle(); + $row['thread_url'] = api_get_path(WEB_CODE_PATH).'forum/viewthread.php?'.http_build_query([ + 'cidReq' => $courseInfo['code'], + 'forum' => $post->getForumId(), + 'thread' => $post->getThreadId(), + 'post_id' => $post->getIid(), + ]).'#post_id_'.$post->getIid(); + } } - } - $messages[] = $row; + $messages[$row['id']] = $row; + } } } + // Reordering messages by ID (reverse order) is enough to have the + // latest first, as there is currently no option to edit messages + // afterwards + krsort($messages); return $messages; } @@ -2219,77 +2213,6 @@ class SocialManager extends UserManager $template->assign('social_avatar_block', $template->fetch($templateName)); } - /** - * @param int $user_id - * @param $link_shared - * @param $show_full_profile - * - * @return string - */ - public static function listMyFriends($user_id, $link_shared, $show_full_profile) - { - // SOCIALGOODFRIEND , USER_RELATION_TYPE_FRIEND, USER_RELATION_TYPE_PARENT - $friends = self::get_friends($user_id, USER_RELATION_TYPE_FRIEND); - $number_of_images = 30; - $number_friends = count($friends); - $friendHtml = ''; - if ($number_friends != 0) { - if ($number_friends > $number_of_images) { - if (api_get_user_id() == $user_id) { - $friendHtml .= ' '.get_lang('SeeAll').''; - } else { - $friendHtml .= ' ' - .''.get_lang('SeeAll').''; - } - } - - $friendHtml .= ''; - } else { - $friendHtml .= '
    '.get_lang('NoFriendsInYourContactList').'
    - - '.get_lang('TryAndFindSomeFriends').'
    '; - } - - $friendHtml = Display::panel($friendHtml, get_lang('SocialFriend').' ('.$number_friends.')'); - - return $friendHtml; - } - /** * @param int $user_id * @param $link_shared diff --git a/main/inc/lib/sortable_table.class.php b/main/inc/lib/sortable_table.class.php index 4d3bb5bc7d..bd710c1708 100755 --- a/main/inc/lib/sortable_table.class.php +++ b/main/inc/lib/sortable_table.class.php @@ -100,11 +100,15 @@ class SortableTable extends HTML_Table * The array containing all data for this table. */ public $table_data; + public $hideItemSelector; + /** * @var array Columns to hide */ private $columnsToHide = []; private $dataFunctionParams; + private $defaultColumn; + private $defaultItemsPerPage; /** * Create a new SortableTable. @@ -137,7 +141,7 @@ class SortableTable extends HTML_Table $table_id = $table_name.uniqid('table', true); } if (isset($parameters) && empty($parameters)) { - $parameters = ['class' => 'table table-bordered table-striped', 'id' => $table_id]; + $parameters = ['class' => 'table table-bordered data_table', 'id' => $table_id]; } $this->table_id = $table_id; @@ -145,17 +149,42 @@ class SortableTable extends HTML_Table $this->table_name = $table_name; $this->additional_parameters = []; $this->param_prefix = $table_name.'_'; + $this->defaultColumn = (int) $default_column; + $this->defaultItemsPerPage = $default_items_per_page; + $this->hideItemSelector = false; + + $defaultRow = api_get_configuration_value('table_default_row'); + if (!empty($defaultRow)) { + $this->defaultItemsPerPage = $default_items_per_page = $defaultRow; + } + + $cleanSessionData = Session::read('clean_sortable_table'); + if ($cleanSessionData === true) { + $this->cleanUrlSessionParams(); + } + + // Allow to change paginate in multiples tabs + //Session::erase($this->param_prefix.'per_page'); + $this->per_page = Session::read($this->param_prefix.'per_page', $default_items_per_page); + + // If per page changed, then reset the page to 1 + if (!empty($this->per_page) && isset($_GET[$this->param_prefix.'per_page']) && $this->per_page != $_GET[$this->param_prefix.'per_page']) { + Session::erase($this->param_prefix.'page_nr'); + $_GET[$this->param_prefix.'page_nr'] = 1; + } + + $this->per_page = isset($_GET[$this->param_prefix.'per_page']) ? (int) $_GET[$this->param_prefix.'per_page'] : $this->per_page; + + if (isset($_GET[$this->param_prefix.'per_page'])) { + Session::erase($this->param_prefix.'page_nr'); + } $this->page_nr = Session::read($this->param_prefix.'page_nr', 1); $this->page_nr = isset($_GET[$this->param_prefix.'page_nr']) ? (int) $_GET[$this->param_prefix.'page_nr'] : $this->page_nr; + $this->column = Session::read($this->param_prefix.'column', $default_column); $this->column = isset($_GET[$this->param_prefix.'column']) ? (int) $_GET[$this->param_prefix.'column'] : $this->column; - $defaultRow = api_get_configuration_value('table_default_row'); - if (!empty($defaultRow)) { - $default_items_per_page = $defaultRow; - } - // Default direction. if (in_array(strtoupper($default_order_direction), ['ASC', 'DESC'])) { $this->direction = $default_order_direction; @@ -187,12 +216,6 @@ class SortableTable extends HTML_Table } } - // Allow to change paginate in multiples tabs - Session::erase($this->param_prefix.'per_page'); - - $this->per_page = Session::read($this->param_prefix.'per_page', $default_items_per_page); - $this->per_page = isset($_GET[$this->param_prefix.'per_page']) ? (int) $_GET[$this->param_prefix.'per_page'] : $this->per_page; - Session::write($this->param_prefix.'per_page', $this->per_page); Session::write($this->param_prefix.'direction', $this->direction); Session::write($this->param_prefix.'page_nr', $this->page_nr); @@ -212,6 +235,26 @@ class SortableTable extends HTML_Table $this->dataFunctionParams = []; } + /** + * Clean URL params when changing student view. + */ + public function cleanUrlSessionParams() + { + Session::erase('clean_sortable_table'); + + $prefix = $this->param_prefix; + + Session::erase($prefix.'page_nr'); + Session::erase($prefix.'column'); + Session::erase($prefix.'direction'); + Session::erase($prefix.'per_page'); + + $_GET[$this->param_prefix.'per_page'] = $this->default_items_per_page; + $_GET[$this->param_prefix.'page_nr'] = 1; + $_GET[$this->param_prefix.'column'] = $this->defaultColumn; + $_GET[$this->param_prefix.'direction'] = $this->direction; + } + /** * @return array */ @@ -710,6 +753,10 @@ class SortableTable extends HTML_Table if ($total_number_of_items <= $this->default_items_per_page) { return ''; } + + if ($this->hideItemSelector === true) { + return ''; + } $result[] = '
    '; $param[$this->param_prefix.'direction'] = $this->direction; $param[$this->param_prefix.'page_nr'] = $this->page_nr; @@ -736,8 +783,7 @@ class SortableTable extends HTML_Table } $result[] = ''; } - // @todo no limits - //if ($total_number_of_items < 500) { + $result[] = ''; //} $result[] = ''; @@ -913,7 +959,7 @@ class SortableTable extends HTML_Table } /** - * Add a filter to a column. If another filter was allready defined for the + * Add a filter to a column. If another filter was already defined for the * given column, it will be overwritten. * * @param int $column The number of the column diff --git a/main/inc/lib/thematic.lib.php b/main/inc/lib/thematic.lib.php index e1e4eef8aa..67e95db7fd 100755 --- a/main/inc/lib/thematic.lib.php +++ b/main/inc/lib/thematic.lib.php @@ -716,8 +716,9 @@ class Thematic $tbl_thematic_advance = Database::get_course_table(TABLE_THEMATIC_ADVANCE); $data = []; $condition = ''; - if (isset($thematic_advance_id)) { - $thematic_advance_id = intval($thematic_advance_id); + $thematic_advance_id = (int) $thematic_advance_id; + + if (!empty($thematic_advance_id)) { $condition = " AND a.id = $thematic_advance_id "; } diff --git a/main/inc/lib/tracking.lib.php b/main/inc/lib/tracking.lib.php index cc4b085583..b54df65740 100755 --- a/main/inc/lib/tracking.lib.php +++ b/main/inc/lib/tracking.lib.php @@ -1839,49 +1839,6 @@ class Tracking return false; } - /** - * Get las connection date for a student. - * - * @param array $studentList Student id array - * @param int $days - * @param bool $getCount - * - * @return int - */ - public static function getInactiveUsers($studentList, $days, $getCount = true) - { - if (empty($studentList)) { - return 0; - } - $days = (int) $days; - $date = api_get_utc_datetime(strtotime($days.' days ago')); - $studentList = array_map('intval', $studentList); - - $tbl_track_login = Database::get_main_table(TABLE_STATISTIC_TRACK_E_LOGIN); - $select = " SELECT login_user_id "; - if ($getCount) { - $select = " SELECT count(DISTINCT login_user_id) as count"; - } - $sql = "$select - FROM $tbl_track_login - WHERE - login_user_id IN (' ".implode("','", $studentList)."' ) AND - login_date < '$date' - "; - $rs = Database::query($sql); - if (Database::num_rows($rs) > 0) { - if ($getCount) { - $count = Database::fetch_array($rs); - - return $count['count']; - } - - return Database::store_result($rs, 'ASSOC'); - } - - return false; - } - /** * Get first user's connection date on the course. * @@ -1902,51 +1859,30 @@ class Tracking $courseId = (int) $courseId; $session_id = (int) $session_id; - if (self::minimumTimeAvailable($session_id, $courseId)) { - $tbl_track_e_access = Database::get_main_table(TABLE_STATISTIC_TRACK_E_ACCESS); - $sql = 'SELECT access_date - FROM '.$tbl_track_e_access.' - WHERE access_user_id = '.$student_id.' AND - c_id = "'.$courseId.'" AND - access_session_id = '.$session_id.' - ORDER BY access_date ASC - LIMIT 0,1'; - - $rs = Database::query($sql); - if (Database::num_rows($rs) > 0) { - if ($last_login_date = Database::result($rs, 0, 0)) { - if (empty($last_login_date)) { - return false; - } - if ($convert_date) { - return api_convert_and_format_date($last_login_date, DATE_FORMAT_SHORT); - } else { - return $last_login_date; - } + $table = Database::get_main_table(TABLE_STATISTIC_TRACK_E_COURSE_ACCESS); + $sql = 'SELECT login_course_date + FROM '.$table.' + WHERE + user_id = '.$student_id.' AND + c_id = '.$courseId.' AND + session_id = '.$session_id.' + ORDER BY login_course_date ASC + LIMIT 0,1'; + $rs = Database::query($sql); + if (Database::num_rows($rs) > 0) { + if ($first_login_date = Database::result($rs, 0, 0)) { + if (empty($first_login_date)) { + return false; } - } - } else { - $tbl_track_login = Database::get_main_table(TABLE_STATISTIC_TRACK_E_COURSE_ACCESS); - $sql = 'SELECT login_course_date - FROM '.$tbl_track_login.' - WHERE - user_id = '.$student_id.' AND - c_id = '.$courseId.' AND - session_id = '.$session_id.' - ORDER BY login_course_date ASC - LIMIT 0,1'; - $rs = Database::query($sql); - if (Database::num_rows($rs) > 0) { - if ($first_login_date = Database::result($rs, 0, 0)) { - if ($convert_date) { - return api_convert_and_format_date( - $first_login_date, - DATE_FORMAT_SHORT - ); - } else { - return $first_login_date; - } + + if ($convert_date) { + return api_convert_and_format_date( + $first_login_date, + DATE_FORMAT_SHORT + ); } + + return $first_login_date; } } @@ -2467,182 +2403,6 @@ class Tracking return $result.'%'; } - /** - * get teacher progress by course and session. - * - * @param int course id - * @param int session id - * - * @return array - */ - public static function get_teachers_progress_by_course($courseId, $sessionId) - { - $course = api_get_course_info_by_id($courseId); - $sessionId = intval($sessionId); - $courseId = intval($courseId); - - $sessionCourseUserTable = Database::get_main_table(TABLE_MAIN_SESSION_COURSE_USER); - $sessionTable = Database::get_main_table(TABLE_MAIN_SESSION); - - //get teachers - $sql = "SELECT scu.session_id, scu.user_id, s.name - FROM $sessionCourseUserTable scu, $sessionTable s - WHERE - scu.session_id = s.id - AND scu.status = 2 - AND scu.visibility = 1 - AND scu.c_id = '%s' - AND scu.session_id = %s"; - $query = sprintf($sql, intval($courseId), $sessionId); - $rs = Database::query($query); - $teachers = []; - while ($teacher = Database::fetch_array($rs, 'ASSOC')) { - $teachers[] = $teacher; - } - $data = []; - foreach ($teachers as $teacher) { - //total documents added - $sql = "SELECT count(*) as total - FROM c_item_property - WHERE lastedit_type = 'DocumentAdded' - AND c_id = %s - AND insert_user_id = %s - AND session_id = %s"; - $query = sprintf( - $sql, - $courseId, - $teacher['user_id'], - $teacher['session_id'] - ); - - $rs = Database::query($query); - $totalDocuments = 0; - if ($rs) { - $row = Database::fetch_row($rs); - $totalDocuments = $row[0]; - } - // Total links added - $sql = "SELECT count(*) as total - FROM c_item_property - WHERE lastedit_type = 'LinkAdded' - AND c_id = %s - AND insert_user_id = %s - AND session_id = %s"; - $query = sprintf( - $sql, - $courseId, - $teacher['user_id'], - $teacher['session_id'] - ); - $rs = Database::query($query); - - $totalLinks = 0; - if ($rs) { - $row = Database::fetch_row($rs); - $totalLinks = $row[0]; - } - //total forums added - $sql = "SELECT count(*) as total - FROM c_item_property - WHERE lastedit_type = 'ForumthreadVisible' - AND c_id = %s - AND insert_user_id = %s - AND session_id = %s"; - $query = sprintf( - $sql, - $courseId, - $teacher['user_id'], - $teacher['session_id'] - ); - $rs = Database::query($query); - - $totalForums = 0; - if ($rs) { - $row = Database::fetch_row($rs); - $totalForums = $row[0]; - } - - //total wikis added - $sql = "SELECT COUNT(DISTINCT(ref)) as total - FROM c_item_property - WHERE lastedit_type = 'WikiAdded' - AND c_id = %s - AND insert_user_id = %s - AND session_id = %s"; - - $query = sprintf( - $sql, - $courseId, - $teacher['user_id'], - $teacher['session_id'] - ); - - $rs = Database::query($query); - - $totalWikis = 0; - if ($rs) { - $row = Database::fetch_row($rs); - $totalWikis = $row[0]; - } - - // Total works added - $sql = "SELECT COUNT(*) as total - FROM c_item_property - WHERE lastedit_type = 'DirectoryCreated' - AND tool = 'work' - AND c_id = %s - AND insert_user_id = %s - AND session_id = %s"; - $query = sprintf( - $sql, - $courseId, - $teacher['user_id'], - $teacher['session_id'] - ); - $rs = Database::query($query); - - $totalWorks = 0; - if ($rs) { - $row = Database::fetch_row($rs); - $totalWorks = $row[0]; - } - //total announcements added - $sql = "SELECT COUNT(*) as total - FROM c_item_property - WHERE lastedit_type = 'AnnouncementAdded' - AND c_id = %s - AND insert_user_id = %s - AND session_id = %s"; - $query = sprintf( - $sql, - $courseId, - $teacher['user_id'], - $teacher['session_id'] - ); - $rs = Database::query($query); - - $totalAnnouncements = 0; - if ($rs) { - $row = Database::fetch_row($rs); - $totalAnnouncements = $row[0]; - } - $tutor = api_get_user_info($teacher['user_id']); - $data[] = [ - 'course' => $course['title'], - 'session' => $teacher['name'], - 'tutor' => $tutor['username'].' - '.$tutor['lastname'].' '.$tutor['firstname'], - 'documents' => $totalDocuments, - 'links' => $totalLinks, - 'forums' => $totalForums, - 'works' => $totalWorks, - 'wikis' => $totalWikis, - 'announcements' => $totalAnnouncements, - ]; - } - - return $data; - } - /** * Returns the average student progress in the learning paths of the given * course, it will take into account the progress that were not started. @@ -3587,60 +3347,6 @@ class Tracking return $students; } - /** - * Get student followed by a coach inside a session. - * - * @param int Session id - * @param int Coach id - * - * @return array students list - */ - public static function get_student_followed_by_coach_in_a_session( - $id_session, - $coach_id - ) { - $coach_id = intval($coach_id); - $tbl_session_course_user = Database::get_main_table(TABLE_MAIN_SESSION_COURSE_USER); - $tbl_session = Database::get_main_table(TABLE_MAIN_SESSION); - - $students = []; - // At first, courses where $coach_id is coach of the course - $sql = 'SELECT c_id FROM '.$tbl_session_course_user.' - WHERE session_id="'.$id_session.'" AND user_id='.$coach_id.' AND status=2'; - $result = Database::query($sql); - - while ($a_courses = Database::fetch_array($result)) { - $courseId = $a_courses['c_id']; - $sql = "SELECT DISTINCT srcru.user_id - FROM $tbl_session_course_user AS srcru - WHERE - c_id = '$courseId' AND - session_id = '".$id_session."'"; - $rs = Database::query($sql); - while ($row = Database::fetch_array($rs)) { - $students[$row['user_id']] = $row['user_id']; - } - } - - // Then, courses where $coach_id is coach of the session - $sql = 'SELECT id_coach FROM '.$tbl_session.' - WHERE id="'.$id_session.'" AND id_coach="'.$coach_id.'"'; - $result = Database::query($sql); - - //He is the session_coach so we select all the users in the session - if (Database::num_rows($result) > 0) { - $sql = 'SELECT DISTINCT srcru.user_id - FROM '.$tbl_session_course_user.' AS srcru - WHERE session_id="'.$id_session.'"'; - $result = Database::query($sql); - while ($row = Database::fetch_array($result)) { - $students[$row['user_id']] = $row['user_id']; - } - } - - return $students; - } - /** * Check if a coach is allowed to follow a student. * @@ -7016,32 +6722,6 @@ class Tracking return $allow; } - - public function getCoursesAndSessions($userId) - { - $userId = (int) $userId; - - // Get the list of sessions where the user is subscribed as student - $sql = 'SELECT session_id, c_id - FROM '.Database::get_main_table(TABLE_MAIN_SESSION_COURSE_USER).' - WHERE user_id='.$userId; - $rs = Database::query($sql); - $tmp_sessions = []; - while ($row = Database::fetch_array($rs, 'ASSOC')) { - $tmp_sessions[] = $row['session_id']; - if ($drh_can_access_all_courses) { - if (in_array($row['session_id'], $tmp_sessions)) { - $courses_in_session[$row['session_id']][] = $row['c_id']; - } - } else { - if (isset($courses_in_session_by_coach[$row['session_id']])) { - if (in_array($row['session_id'], $tmp_sessions)) { - $courses_in_session[$row['session_id']][] = $row['c_id']; - } - } - } - } - } } /** @@ -7797,8 +7477,10 @@ class TrackingCourseLog $user['first_connection'] = Tracking::get_first_connection_date_on_the_course( $user['user_id'], $courseId, - $session_id + $session_id, + $export_csv === false ); + $user['last_connection'] = Tracking::get_last_connection_date_on_the_course( $user['user_id'], $courseInfo, @@ -7806,6 +7488,11 @@ class TrackingCourseLog $export_csv === false ); + if ($export_csv) { + $user['first_connection'] = api_get_local_time($user['first_connection']); + $user['last_connection'] = api_get_local_time($user['last_connection']); + } + if (empty($session_id)) { $user['survey'] = (isset($survey_user_list[$user['user_id']]) ? $survey_user_list[$user['user_id']] : 0).' / '.$total_surveys; } diff --git a/main/inc/lib/usergroup.lib.php b/main/inc/lib/usergroup.lib.php index 6bb8de5282..4204add976 100755 --- a/main/inc/lib/usergroup.lib.php +++ b/main/inc/lib/usergroup.lib.php @@ -220,7 +220,7 @@ class UserGroup extends Model } else { $sql = "SELECT count(a.id) as count FROM {$this->table} a - WHERE 1 =1 + WHERE 1 = 1 $authorCondition "; $result = Database::query($sql); @@ -293,9 +293,18 @@ class UserGroup extends Model { // action links echo '
    '; - echo ''. - Display::return_icon('back.png', get_lang('BackTo').' '.get_lang('PlatformAdmin'), '', '32'). - ''; + $courseInfo = api_get_course_info(); + if (empty($courseInfo)) { + echo ''. + Display::return_icon('back.png', get_lang('BackTo').' '.get_lang('PlatformAdmin'), '', '32'). + ''; + } else { + echo Display::url( + Display::return_icon('back.png', get_lang('BackTo').' '.get_lang('PlatformAdmin'), '', '32'), + api_get_path(WEB_CODE_PATH).'user/class.php?'.api_get_cidreq() + ); + } + echo '
    '; echo Display::grid_html('usergroups'); } @@ -388,7 +397,7 @@ class UserGroup extends Model } else { $sql = "SELECT $select FROM {$this->usergroup_rel_course_table} usergroup - INNER JOIN {$this->table} u + INNER JOIN {$this->table} u ON (u.id = usergroup.usergroup_id) INNER JOIN {$this->table_course} c ON (usergroup.course_id = c.id) @@ -1470,10 +1479,6 @@ class UserGroup extends Model WHERE usergroup_id = $id"; Database::query($sql); - /*$sql = "DELETE FROM $this->usergroup_rel_ - WHERE usergroup_id = $id"; - Database::query($sql);*/ - parent::delete($id); } @@ -1651,7 +1656,7 @@ class UserGroup extends Model * @param string $id group id * @param string picture group name * @param string height - * @param string picture size it can be small_, medium_ or big_ + * @param string $size_picture picture size it can be small_, medium_ or big_ * @param string style css * * @return array with the file and the style of an image i.e $array['file'] $array['style'] @@ -2835,22 +2840,34 @@ class UserGroup extends Model * Check permissions and blocks the page. * * @param array $userGroupInfo + * @param bool $checkAuthor + * @param bool $checkCourseIsAllow */ - public function protectScript($userGroupInfo = []) + public function protectScript($userGroupInfo = [], $checkAuthor = true, $checkCourseIsAllow = false) { api_block_anonymous_users(); - if (!api_is_platform_admin()) { - if (api_is_teacher()) { - if (!empty($userGroupInfo)) { - if ($userGroupInfo['author_id'] != api_get_user_id()) { - api_not_allowed(true); - } + if (api_is_platform_admin()) { + return true; + } + + if ($checkCourseIsAllow) { + if (api_is_allowed_to_edit()) { + return true; + } + } + + if ($this->allowTeachers() && api_is_teacher()) { + if ($checkAuthor && !empty($userGroupInfo)) { + if (isset($userGroupInfo['author_id']) && $userGroupInfo['author_id'] != api_get_user_id()) { + api_not_allowed(true); } - } else { - api_protect_admin_script(true); - api_protect_limit_for_session_admin(); } + + return true; + } else { + api_protect_admin_script(true); + api_protect_limit_for_session_admin(); } } } diff --git a/main/inc/lib/usermanager.lib.php b/main/inc/lib/usermanager.lib.php index 0ed834b6ab..59041a7654 100755 --- a/main/inc/lib/usermanager.lib.php +++ b/main/inc/lib/usermanager.lib.php @@ -2456,62 +2456,6 @@ class UserManager return $fields; } - /** - * Build a list of extra file already uploaded in $user_folder/{$extra_field}/. - * - * @param $user_id - * @param $extra_field - * @param bool $force - * @param bool $showDelete - * - * @return bool|string - */ - public static function build_user_extra_file_list( - $user_id, - $extra_field, - $force = false, - $showDelete = false - ) { - if (!$force && !empty($_POST['remove_'.$extra_field])) { - return true; // postpone reading from the filesystem - } - - $extra_files = self::get_user_extra_files($user_id, $extra_field); - if (empty($extra_files)) { - return false; - } - - $path_info = self::get_user_picture_path_by_id($user_id, 'web'); - $path = $path_info['dir']; - $del_image = Display::returnIconPath('delete.png'); - - $del_text = get_lang('Delete'); - $extra_file_list = ''; - if (count($extra_files) > 0) { - $extra_file_list = '
      '; - foreach ($extra_files as $file) { - $filename = substr($file, strlen($extra_field) + 1); - $extra_file_list .= '
    • '.Display::return_icon('archive.png'). - ' - '.htmlentities($filename). - ' '; - if ($showDelete) { - $extra_file_list .= '
    • '; - } - } - $extra_file_list .= '
    '; - } - - return $extra_file_list; - } - /** * Get valid filenames in $user_folder/{$extra_field}/. * @@ -2554,33 +2498,6 @@ class UserManager return $files; // can be an empty array } - /** - * Remove an {$extra_file} from the user folder $user_folder/{$extra_field}/. - * - * @param int $user_id - * @param string $extra_field - * @param string $extra_file - * - * @return bool - */ - public static function remove_user_extra_file($user_id, $extra_field, $extra_file) - { - $extra_file = Security::filter_filename($extra_file); - $path_info = self::get_user_picture_path_by_id($user_id, 'system'); - if (strpos($extra_file, $extra_field) !== false) { - $path_extra_file = $path_info['dir'].$extra_file; - } else { - $path_extra_file = $path_info['dir'].$extra_field.'/'.$extra_file; - } - if (is_file($path_extra_file)) { - unlink($path_extra_file); - - return true; - } - - return false; - } - /** * Creates a new extra field. * @@ -2824,18 +2741,6 @@ class UserManager return $extraField->get_handler_field_info_by_tags($variable); } - /** - * @param string $type - * - * @return array - */ - public static function get_all_extra_field_by_type($type) - { - $extraField = new ExtraField('user'); - - return $extraField->get_all_extra_field_by_type($type); - } - /** * Get all the extra field information of a certain field (also the options). * @@ -3611,6 +3516,13 @@ class UserManager if (!empty($myCourseList)) { ksort($myCourseList); + $checkPosition = array_filter(array_column($myCourseList, 'position')); + if (empty($checkPosition)) { + // The session course list doesn't have any position, + // then order the course list by course code + $list = array_column($myCourseList, 'course_code'); + array_multisort($myCourseList, SORT_ASC, $list); + } } return $myCourseList; @@ -5355,42 +5267,6 @@ class UserManager return false; } - /** - * Gets the user path of user certificated. - * - * @param int The user id - * - * @return array containing path_certificate and cat_id - */ - public static function get_user_path_certificate($user_id) - { - $my_certificate = []; - $table_certificate = Database::get_main_table(TABLE_MAIN_GRADEBOOK_CERTIFICATE); - $table_gradebook_category = Database::get_main_table(TABLE_MAIN_GRADEBOOK_CATEGORY); - - $session_id = api_get_session_id(); - $user_id = (int) $user_id; - if ($session_id == 0 || is_null($session_id)) { - $sql_session = 'AND (session_id='.intval($session_id).' OR isnull(session_id)) '; - } elseif ($session_id > 0) { - $sql_session = 'AND session_id='.intval($session_id); - } else { - $sql_session = ''; - } - $sql = "SELECT tc.path_certificate,tc.cat_id,tgc.course_code,tgc.name - FROM $table_certificate tc, $table_gradebook_category tgc - WHERE tgc.id = tc.cat_id AND tc.user_id = $user_id - ORDER BY tc.date_certificate DESC - LIMIT 5"; - - $rs = Database::query($sql); - while ($row = Database::fetch_array($rs)) { - $my_certificate[] = $row; - } - - return $my_certificate; - } - /** * This function check if the user is a coach inside session course. * @@ -5452,32 +5328,6 @@ class UserManager return $icon_link; } - /** - * Returns an array of the different types of user extra fields [id => title translation]. - * - * @return array - */ - public static function get_user_field_types() - { - $types = []; - $types[self::USER_FIELD_TYPE_TEXT] = get_lang('FieldTypeText'); - $types[self::USER_FIELD_TYPE_TEXTAREA] = get_lang('FieldTypeTextarea'); - $types[self::USER_FIELD_TYPE_RADIO] = get_lang('FieldTypeRadio'); - $types[self::USER_FIELD_TYPE_SELECT] = get_lang('FieldTypeSelect'); - $types[self::USER_FIELD_TYPE_SELECT_MULTIPLE] = get_lang('FieldTypeSelectMultiple'); - $types[self::USER_FIELD_TYPE_DATE] = get_lang('FieldTypeDate'); - $types[self::USER_FIELD_TYPE_DATETIME] = get_lang('FieldTypeDatetime'); - $types[self::USER_FIELD_TYPE_DOUBLE_SELECT] = get_lang('FieldTypeDoubleSelect'); - $types[self::USER_FIELD_TYPE_DIVIDER] = get_lang('FieldTypeDivider'); - $types[self::USER_FIELD_TYPE_TAG] = get_lang('FieldTypeTag'); - $types[self::USER_FIELD_TYPE_TIMEZONE] = get_lang('FieldTypeTimezone'); - $types[self::USER_FIELD_TYPE_SOCIAL_PROFILE] = get_lang('FieldTypeSocialProfile'); - $types[self::USER_FIELD_TYPE_FILE] = get_lang('FieldTypeFile'); - $types[self::USER_FIELD_TYPE_MOBILE_PHONE_NUMBER] = get_lang('FieldTypeMobilePhoneNumber'); - - return $types; - } - /** * @param User $user */ @@ -5679,34 +5529,6 @@ class UserManager ); } - /** - * Get the teacher (users with COURSEMANGER status) list. - * - * @return array The list - */ - public static function getTeachersList() - { - $userTable = Database::get_main_table(TABLE_MAIN_USER); - $resultData = Database::select( - 'user_id, lastname, firstname, username', - $userTable, - [ - 'where' => [ - 'status = ?' => COURSEMANAGER, - ], - ] - ); - - foreach ($resultData as &$teacherData) { - $teacherData['completeName'] = api_get_person_name( - $teacherData['firstname'], - $teacherData['lastname'] - ); - } - - return $resultData; - } - /** * @return array */ @@ -5902,21 +5724,6 @@ class UserManager return get_lang('Anonymous'); } - /** - * Displays the name of the user and makes the link to the user profile. - * - * @param $userInfo - * - * @return string - */ - public static function getUserProfileLinkWithPicture($userInfo) - { - return Display::url( - Display::img($userInfo['avatar']), - $userInfo['profile_url'] - ); - } - /** * Get users whose name matches $firstname and $lastname. * @@ -6472,19 +6279,6 @@ SQL; } } - /** - * @return int - */ - public static function getCountActiveUsers() - { - $table = Database::get_main_table(TABLE_MAIN_USER); - $sql = "SELECT count(id) count FROM $table WHERE active = 1 AND status <> ".ANONYMOUS; - $result = Database::query($sql); - $row = Database::fetch_array($result); - - return (int) $row['count']; - } - /** * @param array $userInfo * @param int $searchYear diff --git a/main/inc/lib/userportal.lib.php b/main/inc/lib/userportal.lib.php index 3a44c1adb1..02615cbbcd 100755 --- a/main/inc/lib/userportal.lib.php +++ b/main/inc/lib/userportal.lib.php @@ -956,14 +956,14 @@ class IndexManager $items[] = [ 'class' => 'add-course', 'icon' => Display::return_icon('new-course.png', get_lang('CreateCourseRequest')), - 'link' => 'main/create_course/add_course.php', + 'link' => api_get_path(WEB_CODE_PATH).'create_course/add_course.php', 'title' => get_lang('CreateCourseRequest'), ]; } else { $items[] = [ 'class' => 'add-course', 'icon' => Display::return_icon('new-course.png', get_lang('CourseCreate')), - 'link' => 'main/create_course/add_course.php', + 'link' => api_get_path(WEB_CODE_PATH).'create_course/add_course.php', 'title' => get_lang('CourseCreate'), ]; } @@ -972,7 +972,7 @@ class IndexManager $items[] = [ 'class' => 'add-session', 'icon' => Display::return_icon('session.png', get_lang('AddSession')), - 'link' => 'main/session/session_add.php', + 'link' => api_get_path(WEB_CODE_PATH).'session/session_add.php', 'title' => get_lang('AddSession'), ]; } @@ -983,7 +983,7 @@ class IndexManager $items[] = [ 'class' => 'order-course', 'icon' => Display::return_icon('order-course.png', get_lang('SortMyCourses')), - 'link' => api_get_path(WEB_CODE_PATH).'auth/courses.php?action=sortmycourses', + 'link' => api_get_path(WEB_CODE_PATH).'auth/sort_my_courses.php', 'title' => get_lang('SortMyCourses'), ]; } @@ -993,14 +993,14 @@ class IndexManager $items[] = [ 'class' => 'history-course', 'icon' => Display::return_icon('history-course.png', get_lang('DisplayTrainingList')), - 'link' => 'user_portal.php', + 'link' => api_get_path(WEB_PATH).'user_portal.php', 'title' => get_lang('DisplayTrainingList'), ]; } else { $items[] = [ 'class' => 'history-course', 'icon' => Display::return_icon('history-course.png', get_lang('HistoryTrainingSessions')), - 'link' => 'user_portal.php?history=1', + 'link' => api_get_path(WEB_PATH).'user_portal.php?history=1', 'title' => get_lang('HistoryTrainingSessions'), ]; } @@ -1018,12 +1018,12 @@ class IndexManager $items[] = [ 'class' => 'list-course', 'icon' => Display::return_icon('catalog-course.png', get_lang('CourseCatalog')), - 'link' => 'main/auth/courses.php', + 'link' => api_get_path(WEB_CODE_PATH).'auth/courses.php', 'title' => get_lang('CourseCatalog'), ]; } else { $items[] = [ - 'link' => 'main/dashboard/index.php', + 'link' => api_get_path(WEB_CODE_PATH).'dashboard/index.php', 'title' => get_lang('Dashboard'), ]; } @@ -1338,7 +1338,7 @@ class IndexManager if (is_array($session_categories)) { foreach ($session_categories as $session_category) { $session_category_id = $session_category['session_category']['id']; - + // Sessions and courses that are not in a session category if (empty($session_category_id) && isset($session_category['sessions']) ) { @@ -1517,11 +1517,11 @@ class IndexManager if ($collapsable) { $collapsableData = SessionManager::getCollapsableData( - $user_id, - $session_id, - $extraFieldValue, - $collapsableLink - ); + $user_id, + $session_id, + $extraFieldValue, + $collapsableLink + ); $params['collapsed'] = $collapsableData['collapsed']; $params['collapsable_link'] = $collapsableData['collapsable_link']; } @@ -1767,11 +1767,11 @@ class IndexManager $this->tpl->assign('show_tutor', (api_get_setting('show_session_coach') === 'true' ? true : false)); $this->tpl->assign('gamification_mode', $gameModeIsActive); $this->tpl->assign('remove_session_url', api_get_configuration_value('remove_session_url')); - //$this->tpl->assign('remove_session_url', api_get_setting('session.remove_session_url')); + if ($viewGridCourses) { $sessions_with_no_category = $this->tpl->fetch( $this->tpl->get_template('/user_portal/grid_session.tpl') - ); + ); } else { $sessions_with_no_category = $this->tpl->fetch( $this->tpl->get_template('user_portal/classic_session.tpl') @@ -2366,7 +2366,7 @@ class IndexManager } $icon = Display::return_icon( - 'blackboard_blue.png', + 'session.png', $title, ['class' => 'sessionView'], ICON_SIZE_LARGE diff --git a/main/inc/lib/webservices/Rest.php b/main/inc/lib/webservices/Rest.php index 6afcbab47d..f53b0fa503 100644 --- a/main/inc/lib/webservices/Rest.php +++ b/main/inc/lib/webservices/Rest.php @@ -19,6 +19,8 @@ class Rest extends WebService const GET_AUTH = 'authenticate'; const GET_USER_MESSAGES = 'user_messages'; + const POST_USER_MESSAGE_READ = 'user_message_read'; + const POST_USER_MESSAGE_UNREAD = 'user_message_unread'; const SAVE_GCM_ID = 'gcm_id'; const GET_USER_COURSES = 'user_courses'; const GET_PROFILE = 'user_profile'; @@ -133,7 +135,7 @@ class Rest extends WebService */ public static function validate($username, $apiKeyToValidate) { - $apiKey = self::findUserApiKey($username, self::SERVIVE_NAME); + $apiKey = self::findUserApiKey($username, self::SERVICE_NAME); if ($apiKey != $apiKeyToValidate) { throw new Exception(get_lang('InvalidApiKey')); @@ -201,7 +203,8 @@ class Rest extends WebService 'sendDate' => $message['send_date'], 'content' => $message['content'], 'hasAttachments' => $hasAttachments, - 'url' => '', + 'url' => api_get_path(WEB_CODE_PATH).'messages/view_message.php?' + .http_build_query(['type' => 1, 'id' => $message['id']]), ]; } @@ -211,6 +214,10 @@ class Rest extends WebService /** * Get the user courses. * + * @throws \Doctrine\ORM\OptimisticLockException + * @throws \Doctrine\ORM\TransactionRequiredException + * @throws \Doctrine\ORM\ORMException + * * @return array */ public function getUserCourses() @@ -218,18 +225,21 @@ class Rest extends WebService $courses = CourseManager::get_courses_list_by_user_id($this->user->getId()); $data = []; - foreach ($courses as $courseId) { + foreach ($courses as $courseInfo) { /** @var Course $course */ - $course = Database::getManager()->find('ChamiloCoreBundle:Course', $courseId['real_id']); + $course = Database::getManager()->find('ChamiloCoreBundle:Course', $courseInfo['real_id']); $teachers = CourseManager::getTeacherListFromCourseCodeToString($course->getCode()); + $picturePath = CourseManager::getPicturePath($course, true) + ?: Display::return_icon('session_default.png', null, null, null, null, true); $data[] = [ 'id' => $course->getId(), 'title' => $course->getTitle(), 'code' => $course->getCode(), 'directory' => $course->getDirectory(), - 'urlPicture' => CourseManager::getPicturePath($course, true), + 'urlPicture' => $picturePath, 'teachers' => $teachers, + 'isSpecial' => !empty($courseInfo['special_course']), ]; } @@ -915,6 +925,7 @@ class Rest extends WebService 'code' => $courseInfo['code'], 'directory' => $courseInfo['directory'], 'pictureUrl' => $courseInfo['course_image_large'], + 'urlPicture' => $courseInfo['course_image_large'], 'teachers' => $teachers, ]; } diff --git a/main/inc/lib/webservices/WebService.class.php b/main/inc/lib/webservices/WebService.class.php index 3e817842a1..46727e2e3d 100644 --- a/main/inc/lib/webservices/WebService.class.php +++ b/main/inc/lib/webservices/WebService.class.php @@ -99,4 +99,12 @@ class WebService $user->getSalt() ); } + + /** + * @return User + */ + public function getUser() + { + return $this->user; + } } diff --git a/main/lp/learnpath.class.php b/main/lp/learnpath.class.php index 90fe04f736..8bb6a4aef7 100755 --- a/main/lp/learnpath.class.php +++ b/main/lp/learnpath.class.php @@ -731,16 +731,10 @@ class learnpath // Check course code exists. // Check lp_name doesn't exist, otherwise append something. $i = 0; - $name = Database::escape_string($name); $categoryId = (int) $categoryId; - // Session id. $session_id = api_get_session_id(); $userId = empty($userId) ? api_get_user_id() : $userId; - $check_name = "SELECT * FROM $tbl_lp - WHERE c_id = $course_id AND name = '$name'"; - - $res_name = Database::query($check_name); if (empty($publicated_on)) { $publicated_on = null; @@ -754,12 +748,16 @@ class learnpath $expired_on = Database::escape_string(api_get_utc_datetime($expired_on)); } + $check_name = "SELECT * FROM $tbl_lp + WHERE c_id = $course_id AND name = '".Database::escape_string($name)."'"; + $res_name = Database::query($check_name); + while (Database::num_rows($res_name)) { // There is already one such name, update the current one a bit. $i++; $name = $name.' - '.$i; $check_name = "SELECT * FROM $tbl_lp - WHERE c_id = $course_id AND name = '$name'"; + WHERE c_id = $course_id AND name = '".Database::escape_string($name)."' "; $res_name = Database::query($check_name); } // New name does not exist yet; keep it. @@ -2249,13 +2247,22 @@ class learnpath // @todo remove this query and load the row info as a parameter $table = Database::get_course_table(TABLE_LP_MAIN); // Get current prerequisite - $sql = "SELECT id, prerequisite, subscribe_users, publicated_on, expired_on + $sql = "SELECT id, prerequisite, subscribe_users, publicated_on, expired_on, category_id FROM $table WHERE iid = $lp_id"; $rs = Database::query($sql); $now = time(); if (Database::num_rows($rs) > 0) { $row = Database::fetch_array($rs, 'ASSOC'); + + if (!empty($row['category_id'])) { + $em = Database::getManager(); + $category = $em->getRepository('ChamiloCourseBundle:CLpCategory')->find($row['category_id']); + if (self::categoryIsVisibleForStudent($category, api_get_user_entity($student_id)) === false) { + return false; + } + } + $prerequisite = $row['prerequisite']; $is_visible = true; @@ -2733,6 +2740,23 @@ class learnpath return false; } + /** + * Gets the status list for all LP's items. + * + * @return array Array of [index] => [item ID => current status] + */ + public function get_items_status_list() + { + $list = []; + foreach ($this->ordered_items as $item_id) { + $list[] = [ + $item_id => $this->items[$item_id]->get_status(), + ]; + } + + return $list; + } + /** * Return the number of interactions for the given learnpath Item View ID. * This method can be used as static. @@ -4224,24 +4248,9 @@ class learnpath public static function toggleCategoryVisibility($id, $visibility = 1) { $action = 'visible'; - if ($visibility != 1) { - $action = 'invisible'; - $list = new LearnpathList( - api_get_user_id(), - null, - null, - null, - false, - $id - ); - - $lpList = $list->get_flat_list(); - foreach ($lpList as $lp) { - self::toggle_visibility($lp['iid'], 0); - } - self::toggleCategoryPublish($id, 0); + $action = 'invisible'; } return api_item_property_update( @@ -4466,10 +4475,8 @@ class learnpath $courseId = 0, $sessionId = 0 ) { - $subscriptionSettings = self::getSubscriptionSettings(); - - if ($subscriptionSettings['allow_add_users_to_lp_category'] == false) { - return true; + if (empty($category)) { + return false; } $isAllowedToEdit = api_is_allowed_to_edit(null, true); @@ -4478,19 +4485,34 @@ class learnpath return true; } - if (empty($category)) { + $courseId = empty($courseId) ? api_get_course_int_id() : (int) $courseId; + $sessionId = empty($sessionId) ? api_get_session_id() : (int) $sessionId; + + $courseInfo = api_get_course_info_by_id($courseId); + + $categoryVisibility = api_get_item_visibility( + $courseInfo, + TOOL_LEARNPATH_CATEGORY, + $category->getId(), + $sessionId + ); + + if ($categoryVisibility !== 1 && $categoryVisibility != -1) { return false; } + $subscriptionSettings = self::getSubscriptionSettings(); + + if ($subscriptionSettings['allow_add_users_to_lp_category'] == false) { + return true; + } + $users = $category->getUsers(); if (empty($users) || !$users->count()) { return true; } - $courseId = empty($courseId) ? api_get_course_int_id() : (int) $courseId; - $sessionId = empty($sessionId) ? api_get_session_id() : (int) $sessionId; - if ($category->hasUserAdded($user)) { return true; } @@ -4901,12 +4923,15 @@ class learnpath if (empty($name)) { return false; } - $this->name = Database::escape_string($name); $lp_table = Database::get_course_table(TABLE_LP_MAIN); + $name = Database::escape_string($name); + + $this->name = $name; + $lp_id = $this->get_id(); $course_id = $this->course_info['real_id']; $sql = "UPDATE $lp_table SET - name = '".Database::escape_string($this->name)."' + name = '$name' WHERE iid = $lp_id"; $result = Database::query($sql); // If the lp is visible on the homepage, change his name there. @@ -4915,7 +4940,7 @@ class learnpath $session_condition = api_get_session_condition($session_id); $tbl_tool = Database::get_course_table(TABLE_TOOL_LIST); $link = 'lp/lp_controller.php?action=view&lp_id='.$lp_id.'&id_session='.$session_id; - $sql = "UPDATE $tbl_tool SET name = '$this->name' + $sql = "UPDATE $tbl_tool SET name = '$name' WHERE c_id = $course_id AND (link='$link' AND image='scormbuilder.gif' $session_condition)"; @@ -6223,7 +6248,7 @@ class learnpath } else { $parent_arrays = []; if ($arrLP[$i]['depth'] > 1) { - //Getting list of parents + // Getting list of parents for ($j = 0; $j < $arrLP[$i]['depth']; $j++) { foreach ($arrLP as $item) { if ($item['id'] == $parent_id) { @@ -7416,7 +7441,7 @@ class learnpath public function display_hotpotatoes_form($action = 'add', $id = 0, $extra_info = '') { $course_id = api_get_course_int_id(); - $uploadPath = DIR_HOTPOTATOES; //defined in main_api + $uploadPath = DIR_HOTPOTATOES; if ($id != 0 && is_array($extra_info)) { $item_title = stripslashes($extra_info['title']); @@ -9981,7 +10006,7 @@ class learnpath ORDER BY title ASC"; $sql_hot = "SELECT * FROM $tbl_doc - WHERE + WHERE c_id = $course_id AND path LIKE '".$uploadPath."/%/%htm%' $condition_session @@ -11526,7 +11551,7 @@ EOD; if (filter_extension($new_file_name)) { $file_extension = explode('.', $image_array['name']); - $file_extension = strtolower($file_extension[sizeof($file_extension) - 1]); + $file_extension = strtolower($file_extension[count($file_extension) - 1]); $filename = uniqid(''); $new_file_name = $filename.'.'.$file_extension; $new_path = $updir.'/'.$new_file_name; diff --git a/main/lp/lp_add.php b/main/lp/lp_add.php index b0ee211120..ef2f08cfce 100755 --- a/main/lp/lp_add.php +++ b/main/lp/lp_add.php @@ -101,11 +101,11 @@ if (api_get_configuration_value('save_titles_as_html')) { ); } else { $form->addElement( - 'text', - 'lp_name', - api_ucfirst(get_lang('LPName')), - ['autofocus' => 'autofocus'] -); + 'text', + 'lp_name', + api_ucfirst(get_lang('LPName')), + ['autofocus' => 'autofocus'] + ); } $form->applyFilter('lp_name', 'html_filter'); $form->addRule('lp_name', get_lang('ThisFieldIsRequired'), 'required'); diff --git a/main/lp/lp_controller.php b/main/lp/lp_controller.php index 576d31760d..17de4f5afc 100755 --- a/main/lp/lp_controller.php +++ b/main/lp/lp_controller.php @@ -102,7 +102,7 @@ $htmlHeadXtra[] = ' var jItems = $("#lp_item_list li.li_container"); var jItem = $("#"+ itemId); var index = jItems.index(jItem); - var total = jItems.length; + var total = jItems.length; switch (dir) { case "up": @@ -130,7 +130,7 @@ $htmlHeadXtra[] = ' } else { //console.log("classic"); jItem.detach().insertBefore(jItems[index - 1]); - } + } break; } @@ -142,8 +142,8 @@ $htmlHeadXtra[] = ' //console.log(parentIndex); jItem.detach().insertAfter(jItems[parentIndex]); } else { - jItem.detach().insertBefore(jItems[index - 1]); - } + jItem.detach().insertBefore(jItems[index - 1]); + } } break; case "down": @@ -155,10 +155,10 @@ $htmlHeadXtra[] = ' index = subItems.length + index; //console.log("element is a chapter with items"); //console.log("new index = " + index); - } + } var subItems = $(jItems[index + 1]).find("li.sub_item"); - // is a chapter? + //console.log("next subItems.length: "+subItems.length); // This is an element entering in a chapter if (subItems.length > 0) { // Check if im a child @@ -172,7 +172,7 @@ $htmlHeadXtra[] = ' jItem.detach().insertAfter(jItems[parentIndex]); } else { jItem.detach().insertAfter(subItems); - } + } break; } @@ -185,13 +185,13 @@ $htmlHeadXtra[] = ' // We are brothers! if (parentId == myParentId) { - if ((index + 1) < total) { + if ((index + 1) < total) { //console.log(index + 1); //console.log("We are brothers"); - jItem.detach().insertAfter(jItems[index + 1]); - } + jItem.detach().insertAfter(jItems[index + 1]); + } break; - } + } if (currentSubItems.length > 0) { var parentIndex = jItems.index(jItem.parent().parent()); @@ -200,9 +200,9 @@ $htmlHeadXtra[] = ' //console.log("parentIndex: " + parentIndex); if (parentIndex >= 0) { jItem.detach().insertAfter(jItems[parentIndex]); - break; - } - + break; + } + //jItem.detach().insertAfter($(jItems[index]).parent().parent()); } //var lastItem = $(jItems[index + 1]).parent().parent().find("li.li_container").last(); @@ -769,7 +769,7 @@ switch ($action) { $new_lp_id = learnpath::add_lp( api_get_course_id(), - Security::remove_XSS($_REQUEST['lp_name']), + $_REQUEST['lp_name'], '', 'chamilo', 'manual', @@ -1160,8 +1160,7 @@ switch ($action) { require 'lp_list.php'; } else { Session::write('refresh', 1); - $lp_name = Security::remove_XSS($_REQUEST['lp_name']); - $_SESSION['oLP']->set_name($lp_name); + $_SESSION['oLP']->set_name($_REQUEST['lp_name']); $author = $_REQUEST['lp_author']; // Fixing the author name (no body or html tags). $auth_init = stripos($author, '

    '); @@ -1190,8 +1189,6 @@ switch ($action) { $hide_toc_frame = null; if (isset($_REQUEST['hide_toc_frame']) && $_REQUEST['hide_toc_frame'] == 1) { $hide_toc_frame = $_REQUEST['hide_toc_frame']; - } else { - $hide_toc_frame = null; } $_SESSION['oLP']->set_hide_toc_frame($hide_toc_frame); $_SESSION['oLP']->set_prerequisite(isset($_POST['prerequisites']) ? (int) $_POST['prerequisites'] : 0); diff --git a/main/lp/lp_subscribe_users.php b/main/lp/lp_subscribe_users.php index 5c3b56b8bd..dd2053fa6c 100644 --- a/main/lp/lp_subscribe_users.php +++ b/main/lp/lp_subscribe_users.php @@ -68,12 +68,13 @@ if (!$session) { ->getQuery() ->getResult(); } else { - $session->getUserCourseSubscriptionsByStatus($course, Session::STUDENT) - ->forAll( - function ($i, SessionRelCourseRelUser $sessionCourseUser) use (&$subscribedUsers) { - $subscribedUsers[$i] = $sessionCourseUser->getUser(); - } - ); + $list = $session->getUserCourseSubscriptionsByStatus($course, Session::STUDENT); + if ($list) { + /** @var SessionRelCourseRelUser $sessionCourseUser */ + foreach ($list as $sessionCourseUser) { + $subscribedUsers[$sessionCourseUser->getUser()->getUserId()] = $sessionCourseUser->getUser(); + } + } } // Getting all users in a nice format. diff --git a/main/session/resume_session.php b/main/session/resume_session.php index 35f665f5b7..2805003174 100644 --- a/main/session/resume_session.php +++ b/main/session/resume_session.php @@ -179,14 +179,17 @@ if ($session->getNbrCourses() === 0) { $course, $session ); + // Get coachs of the courses in session $namesOfCoaches = []; - $coachSubscriptions = $session->getUserCourseSubscriptionsByStatus($course, Session::COACH) - ->forAll(function ($index, SessionRelCourseRelUser $subscription) use (&$namesOfCoaches) { - $namesOfCoaches[] = UserManager::formatUserFullName($subscription->getUser(), true); + $coachSubscriptions = $session->getUserCourseSubscriptionsByStatus($course, Session::COACH); - return true; - }); + if ($coachSubscriptions) { + /** @var SessionRelCourseRelUser $subscription */ + foreach ($coachSubscriptions as $subscription) { + $namesOfCoaches[] = $subscription->getUser()->getCompleteNameWithUserName(); + } + } $orderButtons = ''; if (SessionManager::orderCourseIsEnabled()) { diff --git a/main/survey/ch_comment.php b/main/survey/ch_comment.php index 93fbafcb01..656314f39c 100644 --- a/main/survey/ch_comment.php +++ b/main/survey/ch_comment.php @@ -13,12 +13,6 @@ class ch_comment extends survey_question */ public function render(FormValidator $form, $questionData = [], $answers = '') { - if (is_array($answers)) { - $content = implode('', $answers); - } else { - $content = $answers; - } - $name = 'question'.$questionData['question_id']; $form->addTextarea($name, null); $form->setDefaults([$name => $answers]); diff --git a/main/survey/preview.php b/main/survey/preview.php index 659883f723..49d929c6ab 100755 --- a/main/survey/preview.php +++ b/main/survey/preview.php @@ -4,273 +4,223 @@ /** * @package chamilo.survey * - * @author unknown, the initial survey that did not make it in 1.8 because of bad code - * @author Patrick Cool , Ghent University: cleanup, refactoring and rewriting code - * @author Julio Montoya , Chamilo: Personality Test modifications - * - * @version $Id: survey_list.php 10680 2007-01-11 21:26:23Z pcool $ + * @author Patrick Cool , Ghent University + * @author Julio Montoya */ require_once __DIR__.'/../inc/global.inc.php'; -$this_section = SECTION_COURSES; +api_protect_course_script(true); -// Database table definitions -$table_survey = Database::get_course_table(TABLE_SURVEY); -$table_survey_question = Database::get_course_table(TABLE_SURVEY_QUESTION); -$table_survey_question_option = Database::get_course_table(TABLE_SURVEY_QUESTION_OPTION); -$table_course = Database::get_main_table(TABLE_MAIN_COURSE); -$table_user = Database::get_main_table(TABLE_MAIN_USER); -$table_survey_invitation = Database::get_course_table(TABLE_SURVEY_INVITATION); +if (!api_is_allowed_to_edit()) { + api_not_allowed(true); +} -$course_id = api_get_course_int_id(); -$courseInfo = $course_id ? api_get_course_info_by_id($course_id) : []; -$userId = api_get_user_id(); $surveyId = (int) $_GET['survey_id']; -$userInvited = 0; -$userAnonymous = 0; - -$allowRequiredSurveyQuestions = api_get_configuration_value('allow_required_survey_questions'); -//query to ask if logged user is allowed to see the preview (if he is invited of he is a teacher) -$sql = "SELECT survey_invitation.user - FROM $table_survey_invitation survey_invitation - LEFT JOIN $table_survey survey - ON survey_invitation.survey_code = survey.code - WHERE - survey_invitation.c_id = $course_id AND - survey.survey_id = $surveyId AND - survey_invitation.user = $userId"; -$result = Database::query($sql); -if (Database::num_rows($result) > 0) { - $userInvited = 1; -} - -// We exit here if there is no valid $_GET parameter -if (!isset($_GET['survey_id']) || !is_numeric($_GET['survey_id'])) { - api_not_allowed( - true, - Display::return_message(get_lang('InvallidSurvey'), 'error', false) - ); +if (empty($surveyId)) { + api_not_allowed(true); } // Getting the survey information $survey_data = SurveyManager::get_survey($surveyId); if (empty($survey_data)) { - api_not_allowed( - true, - Display::return_message(get_lang('InvallidSurvey'), 'error', false) - ); -} - -$urlname = strip_tags($survey_data['title']); -if (api_is_allowed_to_edit()) { - // Breadcrumbs - $interbreadcrumb[] = [ - 'url' => api_get_path(WEB_CODE_PATH).'survey/survey_list.php?'.api_get_cidreq(), - 'name' => get_lang('SurveyList'), - ]; - $interbreadcrumb[] = [ - 'url' => api_get_path(WEB_CODE_PATH).'survey/survey.php?survey_id='.$surveyId.'&'.api_get_cidreq(), - 'name' => $urlname, - ]; -} -$courseCode = isset($_GET['cidReq']) ? $_GET['cidReq'] : null; -$surveyAnonymous = SurveyManager::get_survey($surveyId, 0, $courseCode); -$surveyAnonymous = $surveyAnonymous['anonymous']; -if ($surveyAnonymous == 0 && api_is_anonymous()) { api_not_allowed(true); -} elseif ($surveyAnonymous == 0 && $userInvited == 0) { - if (!api_is_allowed_to_edit()) { - api_not_allowed(true); - } } -$show = 0; +$this_section = SECTION_COURSES; + +$table_survey_question = Database::get_course_table(TABLE_SURVEY_QUESTION); +$table_survey_question_option = Database::get_course_table(TABLE_SURVEY_QUESTION_OPTION); + +$course_id = api_get_course_int_id(); +$courseInfo = api_get_course_info(); +$allowRequiredSurveyQuestions = api_get_configuration_value('allow_required_survey_questions'); + +// Breadcrumbs +$interbreadcrumb[] = [ + 'url' => api_get_path(WEB_CODE_PATH).'survey/survey_list.php?'.api_get_cidreq(), + 'name' => get_lang('SurveyList'), +]; +$interbreadcrumb[] = [ + 'url' => api_get_path(WEB_CODE_PATH).'survey/survey.php?survey_id='.$surveyId.'&'.api_get_cidreq(), + 'name' => strip_tags($survey_data['title']), +]; + +$show = 0; Display::display_header(get_lang('SurveyPreview')); // We exit here is the first or last question is a pagebreak (which causes errors) SurveyUtil::check_first_last_question($surveyId, false); -$counter_question = 0; -// Only a course admin is allowed to preview a survey: you are a course admin -if (api_is_course_admin() || - (api_is_course_admin() && $_GET['isStudentView'] == 'true') || - api_is_allowed_to_session_edit(false, true) -) { - // Survey information - echo '

    '; - if (!empty($survey_data['survey_subtitle'])) { - echo '
    '.$survey_data['survey_subtitle'].'
    '; - } - // Displaying the survey introduction - if (!isset($_GET['show'])) { - if (!empty($survey_data['survey_introduction'])) { - echo '
    '.$survey_data['survey_introduction'].'
    '; - } - } +// Survey information +echo ''; +if (!empty($survey_data['survey_subtitle'])) { + echo '
    '.$survey_data['survey_subtitle'].'
    '; +} - // Displaying the survey thanks message - if (isset($_POST['finish_survey'])) { - echo Display::return_message(get_lang('SurveyFinished'), 'confirm'); - echo $survey_data['survey_thanks']; - Display::display_footer(); - exit; +// Displaying the survey introduction +if (!isset($_GET['show'])) { + if (!empty($survey_data['survey_introduction'])) { + echo '
    '.$survey_data['survey_introduction'].'
    '; } +} - $questions = []; - if (isset($_GET['show'])) { - // Getting all the questions for this page and add them to a - // multidimensional array where the first index is the page. - // as long as there is no pagebreak fount we keep adding questions to the page - $questions_displayed = []; - $paged_questions = []; - $counter = 0; - $sql = "SELECT * FROM $table_survey_question - WHERE - survey_question NOT LIKE '%{{%' AND - c_id = $course_id AND - survey_id = '".$surveyId."' - ORDER BY sort ASC"; - $result = Database::query($sql); - $questions_exists = true; - if (Database::num_rows($result)) { - while ($row = Database::fetch_array($result)) { - if ($survey_data['one_question_per_page'] == 1) { - if ($row['type'] != 'pagebreak') { - $paged_questions[$counter][] = $row['question_id']; - $counter++; - continue; - } - } else { - if ($row['type'] == 'pagebreak') { - $counter++; - } else { - $paged_questions[$counter][] = $row['question_id']; - } - } - } - } else { - $questions_exists = false; - } - - if (array_key_exists($_GET['show'], $paged_questions)) { - $sql = "SELECT - survey_question.question_id, - survey_question.survey_id, - survey_question.survey_question, - survey_question.display, - survey_question.sort, - survey_question.type, - survey_question.max_value, - survey_question_option.question_option_id, - survey_question_option.option_text, - survey_question_option.sort as option_sort - ".($allowRequiredSurveyQuestions ? ', survey_question.is_required' : '')." - FROM $table_survey_question survey_question - LEFT JOIN $table_survey_question_option survey_question_option - ON - survey_question.question_id = survey_question_option.question_id AND - survey_question_option.c_id = $course_id - WHERE - survey_question.survey_id = '".$surveyId."' AND - survey_question.question_id IN (".Database::escape_string(implode(',', $paged_questions[$_GET['show']]), null, false).") AND - survey_question.c_id = $course_id AND - survey_question NOT LIKE '%{{%' - ORDER BY survey_question.sort, survey_question_option.sort ASC"; +// Displaying the survey thanks message +if (isset($_POST['finish_survey'])) { + echo Display::return_message(get_lang('SurveyFinished'), 'confirm'); + echo $survey_data['survey_thanks']; + Display::display_footer(); + exit; +} - $result = Database::query($sql); - while ($row = Database::fetch_array($result)) { - // If the type is not a pagebreak we store it in the $questions array +$questions = []; +if (isset($_GET['show'])) { + // Getting all the questions for this page and add them to a + // multidimensional array where the first index is the page. + // as long as there is no pagebreak fount we keep adding questions to the page + $questions_displayed = []; + $paged_questions = []; + $counter = 0; + $sql = "SELECT * FROM $table_survey_question + WHERE + survey_question NOT LIKE '%{{%' AND + c_id = $course_id AND + survey_id = '".$surveyId."' + ORDER BY sort ASC"; + $result = Database::query($sql); + $questions_exists = true; + if (Database::num_rows($result)) { + while ($row = Database::fetch_array($result)) { + if ($survey_data['one_question_per_page'] == 1) { if ($row['type'] != 'pagebreak') { - $sort = $row['sort']; - $questions[$sort]['question_id'] = $row['question_id']; - $questions[$sort]['survey_id'] = $row['survey_id']; - $questions[$sort]['survey_question'] = $row['survey_question']; - $questions[$sort]['display'] = $row['display']; - $questions[$sort]['type'] = $row['type']; - //$questions[$sort]['options'][intval($row['option_sort'])] = $row['option_text']; - $questions[$sort]['options'][$row['question_option_id']] = $row['option_text']; - $questions[$sort]['maximum_score'] = $row['max_value']; - $questions[$row['sort']]['is_required'] = $allowRequiredSurveyQuestions && $row['is_required']; + $paged_questions[$counter][] = $row['question_id']; + $counter++; + continue; + } + } else { + if ($row['type'] == 'pagebreak') { + $counter++; } else { - // If the type is a pagebreak we are finished loading the questions for this page - //break; + $paged_questions[$counter][] = $row['question_id']; } - $counter_question++; } } + } else { + $questions_exists = false; } - $before = 0; - if (isset($_GET['show']) && isset($paged_questions[$_GET['show'] - 1])) { - $before = count($paged_questions[$_GET['show'] - 1]); - } - - $numberOfPages = SurveyManager::getCountPages($survey_data); + if (array_key_exists($_GET['show'], $paged_questions)) { + $sql = "SELECT + survey_question.question_id, + survey_question.survey_id, + survey_question.survey_question, + survey_question.display, + survey_question.sort, + survey_question.type, + survey_question.max_value, + survey_question_option.question_option_id, + survey_question_option.option_text, + survey_question_option.sort as option_sort + ".($allowRequiredSurveyQuestions ? ', survey_question.is_required' : '')." + FROM $table_survey_question survey_question + LEFT JOIN $table_survey_question_option survey_question_option + ON + survey_question.question_id = survey_question_option.question_id AND + survey_question_option.c_id = survey_question.c_id + WHERE + survey_question.survey_id = '".$surveyId."' AND + survey_question.question_id IN (".Database::escape_string(implode(',', $paged_questions[$_GET['show']]), null, false).") AND + survey_question.c_id = $course_id AND + survey_question NOT LIKE '%{{%' + ORDER BY survey_question.sort, survey_question_option.sort ASC"; - // Displaying the form with the questions - if (isset($_GET['show'])) { - $show = (int) $_GET['show'] + 1; + $result = Database::query($sql); + while ($row = Database::fetch_array($result)) { + // If the type is not a pagebreak we store it in the $questions array + if ($row['type'] != 'pagebreak') { + $sort = $row['sort']; + $questions[$sort]['question_id'] = $row['question_id']; + $questions[$sort]['survey_id'] = $row['survey_id']; + $questions[$sort]['survey_question'] = $row['survey_question']; + $questions[$sort]['display'] = $row['display']; + $questions[$sort]['type'] = $row['type']; + $questions[$sort]['options'][$row['question_option_id']] = $row['option_text']; + $questions[$sort]['maximum_score'] = $row['max_value']; + $questions[$row['sort']]['is_required'] = $allowRequiredSurveyQuestions && $row['is_required']; + } + } } - $originalShow = isset($_GET['show']) ? (int) $_GET['show'] : 0; +} - $url = api_get_self().'?survey_id='.$surveyId.'&show='.$show.'&'.api_get_cidreq(); - $form = new FormValidator( - 'question-survey', - 'post', - $url, - null, - null, - FormValidator::LAYOUT_INLINE - ); +$before = 0; +if (isset($_GET['show']) && isset($paged_questions[$_GET['show'] - 1])) { + $before = count($paged_questions[$_GET['show'] - 1]); +} - if (is_array($questions) && count($questions) > 0) { - $counter = 1; - if (!empty($originalShow)) { - $before = 0; - foreach ($paged_questions as $keyQuestion => $list) { - if ($originalShow > $keyQuestion) { - $before += count($list); - } +$numberOfPages = SurveyManager::getCountPages($survey_data); + +// Displaying the form with the questions +if (isset($_GET['show'])) { + $show = (int) $_GET['show'] + 1; +} +$originalShow = isset($_GET['show']) ? (int) $_GET['show'] : 0; + +$url = api_get_self().'?survey_id='.$surveyId.'&show='.$show.'&'.api_get_cidreq(); +$form = new FormValidator( + 'question-survey', + 'post', + $url, + null, + null, + FormValidator::LAYOUT_INLINE +); + +if (is_array($questions) && count($questions) > 0) { + $counter = 1; + if (!empty($originalShow)) { + $before = 0; + foreach ($paged_questions as $keyQuestion => $list) { + if ($originalShow > $keyQuestion) { + $before += count($list); } - $counter = $before + 1; - } - foreach ($questions as $key => &$question) { - $ch_type = 'ch_'.$question['type']; - /** @var survey_question $display */ - $display = new $ch_type(); - $form->addHtml('
    '); - $form->addHtml('
    '.$counter.'.
    '); - $form->addHtml('
    '.Security::remove_XSS($question['survey_question']).'
    '); - $display->render($form, $question); - $form->addHtml('
    '); - $counter++; } + $counter = $before + 1; } - $form->addHtml('
    '); + foreach ($questions as $key => &$question) { + $ch_type = 'ch_'.$question['type']; + /** @var survey_question $display */ + $display = new $ch_type(); + $form->addHtml('
    '); + $form->addHtml('
    '.$counter.'.
    '); + $form->addHtml('
    '.Security::remove_XSS($question['survey_question']).'
    '); + $display->render($form, $question); + $form->addHtml('
    '); + $counter++; + } +} +$form->addHtml('
    '); - if ($show < $numberOfPages) { - if ($show == 0) { - $form->addButton( - 'next_survey_page', - get_lang('StartSurvey'), - 'arrow-right', - 'success' - ); - } else { - $form->addButton( - 'next_survey_page', - get_lang('NextQuestion'), - 'arrow-right', - 'success' - ); - } +if ($show < $numberOfPages) { + if ($show == 0) { + $form->addButton( + 'next_survey_page', + get_lang('StartSurvey'), + 'arrow-right', + 'success' + ); + } else { + $form->addButton( + 'next_survey_page', + get_lang('NextQuestion'), + 'arrow-right', + 'success' + ); } +} - if ($show >= $numberOfPages && isset($_GET['show']) || - (isset($_GET['show']) && count($questions) == 0) - ) { +if (isset($_GET['show'])) { + if ($show >= $numberOfPages || count($questions) == 0) { if ($questions_exists == false) { echo '

    '.get_lang('ThereAreNotQuestionsForthisSurvey').'

    '; } @@ -281,18 +231,15 @@ if (api_is_course_admin() || 'success' ); } - $form->addHtml('
    '); - $form->display(); - - if ($courseInfo) { - echo Display::toolbarButton( - get_lang('ReturnToCourseHomepage'), - api_get_course_url($courseInfo['code']), - 'home' - ); - } -} else { - echo Display::return_message(get_lang('NotAllowed'), 'error', false); } +$form->addHtml('
    '); +$form->display(); + +echo Display::toolbarButton( + get_lang('ReturnToCourseHomepage'), + api_get_course_url($courseInfo['code']), + 'home' +); + Display::display_footer(); diff --git a/main/survey/question.php b/main/survey/question.php index 6cfda9fafc..2ce521f5fe 100755 --- a/main/survey/question.php +++ b/main/survey/question.php @@ -103,13 +103,11 @@ if (!in_array($_GET['type'], $possible_types)) { Display::display_footer(); } -$error_message = ''; - // Displaying the form for adding or editing the question - $ch_type = 'ch_'.$_GET['type']; /** @var survey_question $surveyQuestion */ $surveyQuestion = new $ch_type(); +//$surveyQuestion = survey_question::createQuestion($_GET['type']) // The defaults values for the form $formData = []; diff --git a/main/survey/surveyUtil.class.php b/main/survey/surveyUtil.class.php index fd816ee1a9..e7e89c6855 100755 --- a/main/survey/surveyUtil.class.php +++ b/main/survey/surveyUtil.class.php @@ -3732,70 +3732,6 @@ class SurveyUtil return $field_list_array; } - /** - * @author Isaac Flores Paz - * - * @param int $user_id User ID - * @param string $survey_code - * @param int $user_answer User in survey answer table (user id or anonymous) - * - * @return bool - */ - public static function show_link_available($user_id, $survey_code, $user_answer) - { - $table_survey = Database::get_course_table(TABLE_SURVEY); - $table_survey_invitation = Database::get_course_table(TABLE_SURVEY_INVITATION); - $table_survey_answer = Database::get_course_table(TABLE_SURVEY_ANSWER); - $table_survey_question = Database::get_course_table(TABLE_SURVEY_QUESTION); - - $survey_code = Database::escape_string($survey_code); - $user_id = (int) $user_id; - $user_answer = Database::escape_string($user_answer); - $course_id = api_get_course_int_id(); - - $sql = 'SELECT COUNT(*) as count - FROM '.$table_survey_invitation.' - WHERE - user='.$user_id.' AND - survey_code="'.$survey_code.'" AND - answered="1" AND - c_id = '.$course_id; - - $sql2 = 'SELECT COUNT(*) as count - FROM '.$table_survey.' s - INNER JOIN '.$table_survey_question.' q - ON s.survey_id=q.survey_id AND s.c_id = q.c_id - WHERE - s.code="'.$survey_code.'" AND - q.type NOT IN("pagebreak","comment") AND - s.c_id = '.$course_id.' AND q.c_id = '.$course_id.' '; - - $sql3 = 'SELECT COUNT(DISTINCT question_id) as count - FROM '.$table_survey_answer.' - WHERE survey_id=( - SELECT survey_id FROM '.$table_survey.' - WHERE - code = "'.$survey_code.'" AND - c_id = '.$course_id.' - ) AND - user="'.$user_answer.'" AND - c_id = '.$course_id; - - $result = Database::query($sql); - $result2 = Database::query($sql2); - $result3 = Database::query($sql3); - - $row = Database::fetch_array($result, 'ASSOC'); - $row2 = Database::fetch_array($result2, 'ASSOC'); - $row3 = Database::fetch_array($result3, 'ASSOC'); - - if ($row['count'] == 1 && $row3['count'] != $row2['count']) { - return true; - } else { - return false; - } - } - /** * Display survey question chart. * diff --git a/main/ticket/new_ticket.php b/main/ticket/new_ticket.php index 3b5ef0ad9b..3812f47c88 100644 --- a/main/ticket/new_ticket.php +++ b/main/ticket/new_ticket.php @@ -113,16 +113,6 @@ $htmlHeadXtra[] = ''; -/** - * @param $s - * - * @return string - */ -function js_str($s) -{ - return '"'.addcslashes($s, "\0..\37\"\\").'"'; -} - /** * @param $array * @param $name diff --git a/main/webservices/access_url.php b/main/webservices/access_url.php index 445f3607a7..75c7260f4f 100644 --- a/main/webservices/access_url.php +++ b/main/webservices/access_url.php @@ -1,8 +1,6 @@ getUserMessages($lastMessageId); $restResponse->setData($messages); break; + case Rest::POST_USER_MESSAGE_READ: + case Rest::POST_USER_MESSAGE_UNREAD: + $messagesId = isset($_POST['messages']) && is_array($_POST['messages']) + ? array_map('intval', $_POST['messages']) + : []; + + $messagesId = array_filter($messagesId); + + if (empty($messagesId)) { + throw new Exception(get_lang('NoData')); + } + + $messageStatus = $action === Rest::POST_USER_MESSAGE_READ ? MESSAGE_STATUS_NEW : MESSAGE_STATUS_UNREAD; + + $data = array_flip($messagesId); + + foreach ($messagesId as $messageId) { + $data[$messageId] = MessageManager::update_message_status( + $restApi->getUser()->getId(), + $messageId, + $messageStatus + ); + } + + $restResponse->setData($data); + break; case Rest::GET_USER_COURSES: $courses = $restApi->getUserCourses(); $restResponse->setData($courses); diff --git a/main/work/work.lib.php b/main/work/work.lib.php index a8ecdff81f..1a2a2de3cb 100755 --- a/main/work/work.lib.php +++ b/main/work/work.lib.php @@ -2994,7 +2994,7 @@ function getAllDocumentsFromWorkToString($workId, $courseInfo) foreach ($documents as $doc) { $docData = DocumentManager::get_document_data_by_id($doc['document_id'], $courseInfo['code']); if ($docData) { - $content .= '
  • '.$docData['title'].'
  • '; + $content .= '
  • '.$docData['title'].'
  • '; } } $content .= '
    '; @@ -3457,7 +3457,7 @@ function addWorkComment($courseInfo, $userId, $parentWork, $work, $data) } } - $sendNotification = api_get_course_setting('email_to_teachers_on_new_work_feedback', api_get_course_id()); + $sendNotification = api_get_course_setting('email_to_teachers_on_new_work_feedback'); if ($sendNotification != 1) { $userIdListToSend = []; } diff --git a/main/work/work_list.php b/main/work/work_list.php index c40b36de9e..d7a74cf1a9 100755 --- a/main/work/work_list.php +++ b/main/work/work_list.php @@ -11,7 +11,7 @@ api_protect_course_script(true); require_once 'work.lib.php'; $this_section = SECTION_COURSES; -$workId = isset($_GET['id']) ? intval($_GET['id']) : null; +$workId = isset($_GET['id']) ? (int) $_GET['id'] : null; $courseInfo = api_get_course_info(); if (empty($workId) || empty($courseInfo)) { @@ -20,7 +20,7 @@ if (empty($workId) || empty($courseInfo)) { // Student publications are saved with the iid in a LP $origin = api_get_origin(); -if ($origin == 'learnpath') { +if ($origin === 'learnpath') { $em = Database::getManager(); /** @var CStudentPublication $work */ $work = $em->getRepository('ChamiloCourseBundle:CStudentPublication')->findOneBy( @@ -73,14 +73,12 @@ $onlyOnePublication = api_get_configuration_value('allow_only_one_student_public if (api_is_allowed_to_session_edit(false, true) && !empty($workId) && !api_is_invitee()) { $url = api_get_path(WEB_CODE_PATH).'work/upload.php?'.api_get_cidreq().'&id='.$workId; $actionsRight = Display::url( - Display::return_icon( - 'upload_file.png', - get_lang('UploadMyAssignment'), - null, - ICON_SIZE_MEDIUM - ).get_lang('UploadMyAssignment'), + Display::returnFontAwesomeIcon( + ' fa-upload' + ). + get_lang('UploadMyAssignment'), $url, - ['class' => 'btn-toolbar'] + ['class' => 'btn btn-primary', 'id' => 'upload_button'] ); } @@ -107,10 +105,35 @@ if (!empty($my_folder_data['description'])) { $content .= Display::panel($contentWork, get_lang('Description')); } -$content .= workGetExtraFieldData($workId); +$extraFieldWorkData = workGetExtraFieldData($workId); + +if (!empty($extraFieldWorkData)) { + $forceDownload = api_get_configuration_value('force_download_doc_before_upload_work'); + if ($forceDownload) { + // Force to download documents first. + $downloadDocumentsFirst = addslashes(get_lang('DownloadDocumentsFirst')); + $content .= ""; + } +} + +$content .= $extraFieldWorkData; $action = isset($_REQUEST['action']) ? $_REQUEST['action'] : null; -$item_id = isset($_REQUEST['item_id']) ? intval($_REQUEST['item_id']) : null; +$item_id = isset($_REQUEST['item_id']) ? (int) $_REQUEST['item_id'] : null; switch ($action) { case 'delete': @@ -126,7 +149,7 @@ switch ($action) { $result = getWorkDateValidationStatus($work_data); $content .= $result['message']; -$check_qualification = intval($my_folder_data['qualification']); +$check_qualification = (int) $my_folder_data['qualification']; if (!api_is_invitee()) { if (!empty($work_data['enable_qualification']) && !empty($check_qualification)) { @@ -215,7 +238,7 @@ if (!api_is_invitee()) { 'width' => '60', 'align' => 'left', 'search' => 'false', - 'wrap_cell' => "true", + 'wrap_cell' => 'true', ], [ 'name' => 'qualification', @@ -260,7 +283,9 @@ if (!api_is_invitee()) { '; - $content .= getAllDocumentsFromWorkToString($workId, $courseInfo); + $documents = getAllDocumentsFromWorkToString($workId, $courseInfo); + $content .= $documents; + $tableWork = Display::grid_html('results'); $content .= Display::panel($tableWork); } diff --git a/plugin/bbb/lib/bbb.lib.php b/plugin/bbb/lib/bbb.lib.php index 4055cb0a50..9ac876e84f 100755 --- a/plugin/bbb/lib/bbb.lib.php +++ b/plugin/bbb/lib/bbb.lib.php @@ -92,7 +92,7 @@ class bbb // Course check $courseInfo = api_get_course_info(); if ($courseInfo) { - $this->groupSupport = api_get_course_setting('bbb_enable_conference_in_groups', $courseInfo['code']) === '1'; + $this->groupSupport = api_get_course_setting('bbb_enable_conference_in_groups', $courseInfo) === '1'; } } } diff --git a/plugin/bbb/listing.php b/plugin/bbb/listing.php index 98609d4de2..28b1a9212b 100755 --- a/plugin/bbb/listing.php +++ b/plugin/bbb/listing.php @@ -133,7 +133,7 @@ if ($conferenceManager) { if ($plugin->get('allow_regenerate_recording') !== 'true') { api_not_allowed(true); } - $allow = api_get_course_setting('bbb_force_record_generation', $courseCode) == 1 ? true : false; + $allow = api_get_course_setting('bbb_force_record_generation', $courseInfo) == 1 ? true : false; if ($allow) { $result = $bbb->getMeetingByRemoteId($_GET['remote_id']); if (!empty($result)) { diff --git a/plugin/bbb/view/listing.tpl b/plugin/bbb/view/listing.tpl index c375fa0e42..c8f44308a0 100644 --- a/plugin/bbb/view/listing.tpl +++ b/plugin/bbb/view/listing.tpl @@ -154,7 +154,7 @@ {{ 'CloseMeeting'|get_plugin_lang('BBBPlugin') }} {% endif %} - {{ meeting.action_links }} + {{ meeting.action_links }}