get_courses_in_category(); $action = isset($_REQUEST['action']) ? $_REQUEST['action'] : ''; $currentUrl = api_get_self(); $interbreadcrumb[] = [ 'url' => api_get_self(), 'name' => get_lang('SortMyCourses'), ]; // 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'])) { $result = $auth->updateCourseCategory($_POST['course_2_edit_category'], $_POST['course_categories']); if ($result) { Display::addFlash( Display::return_message(get_lang('EditCourseCategorySucces')) ); } header('Location: '.api_get_self()); exit; } // We edit course category if (isset($_POST['submit_edit_course_category']) && isset($_POST['title_course_category']) ) { $result = $auth->store_edit_course_category($_POST['title_course_category'], $_POST['category_id']); if ($result) { Display::addFlash( Display::return_message(get_lang('CourseCategoryEditStored')) ); } header('Location: '.api_get_self()); exit; } // 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 ) { $result = $auth->store_course_category($_POST['title_course_category']); if ($result) { Display::addFlash( Display::return_message(get_lang('CourseCategoryStored')) ); } else { Display::addFlash( Display::return_message( get_lang('ACourseCategoryWithThisNameAlreadyExists'), 'error' ) ); } header('Location: '.api_get_self()); exit; } // 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'])) { $result = $auth->move_course($_GET['move'], $_GET['course'], $_GET['category']); if ($result) { Display::addFlash( Display::return_message(get_lang('CourseSortingDone')) ); } } if (isset($_GET['category']) && !isset($_GET['course'])) { $result = $auth->move_category($_GET['move'], $_GET['category']); if ($result) { Display::addFlash( Display::return_message(get_lang('CategorySortingDone')) ); } } header('Location: '.api_get_self()); exit; } switch ($action) { case 'edit_category': $categoryId = isset($_GET['category_id']) ? (int) $_GET['category_id'] : 0; $categoryInfo = $auth->getUserCourseCategory($categoryId); if ($categoryInfo) { $categoryName = $categoryInfo['title']; $form = new FormValidator( 'edit_course_category', 'post', $currentUrl.'?action=edit_category' ); $form->addText('title_course_category', get_lang('Name')); $form->addHidden('category_id', $categoryId); $form->addButtonSave(get_lang('Edit'), 'submit_edit_course_category'); $form->setDefaults(['title_course_category' => $categoryName]); $form->display(); } exit; break; case 'edit_course_category': $edit_course = (int) $_GET['course_id']; $defaultCategoryId = isset($_GET['category_id']) ? (int) $_GET['category_id'] : 0; $courseInfo = api_get_course_info_by_id($edit_course); if (empty($courseInfo)) { exit; } $form = new FormValidator( 'edit_course_category', 'post', $currentUrl.'?action=edit_course_category' ); $form->addHeader($courseInfo['title']); $options = []; foreach ($user_course_categories as $row) { $options[$row['id']] = $row['title']; } asort($options); $form->addSelect( 'course_categories', get_lang('Categories'), $options, ['disable_js' => true, 'placeholder' => get_lang('SelectAnOption')] ); $form->addHidden('course_2_edit_category', $edit_course); if (!empty($defaultCategoryId)) { $form->setDefaults(['course_categories' => $defaultCategoryId]); } $form->addButtonSave(get_lang('Save'), 'submit_change_course_category'); $form->display(); exit; break; case 'deletecoursecategory': // we are deleting a course category if (isset($_GET['id'])) { if (Security::check_token('get')) { $result = $auth->delete_course_category($_GET['id']); if ($result) { Display::addFlash( Display::return_message(get_lang('CourseCategoryDeleted')) ); } } } header('Location: '.api_get_self()); exit; break; case 'createcoursecategory': $form = new FormValidator( 'create_course_category', 'post', $currentUrl.'?action=createcoursecategory' ); $form->addText('title_course_category', get_lang('Name')); $form->addButtonSave(get_lang('AddCategory'), 'create_course_category'); $form->display(); exit; break; case 'set_collapsable': 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_self(); header('Location: '.$url); exit; break; } Display::display_header(); $stok = Security::get_token(); $courses_without_category = isset($courses_in_category[0]) ? $courses_in_category[0] : null; echo '