Skip to content

Commit

Permalink
Filter the code shown in course category form
Browse files Browse the repository at this point in the history
  • Loading branch information
AngelFQC committed Apr 10, 2023
1 parent de47f0e commit b3f92b0
Showing 1 changed file with 16 additions and 12 deletions.
28 changes: 16 additions & 12 deletions main/admin/course_category.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@

$myCourseListAsCategory = api_get_configuration_value('my_courses_list_as_category');

$baseUrl = api_get_path(WEB_CODE_PATH).'admin/course_category.php?'
.http_build_query(['category' => $parentInfo['code'] ?? '']);

if (!empty($action)) {
if ('export' === $action) {
$categoryInfo = CourseCategory::getCategoryById($categoryId);
Expand All @@ -48,10 +51,10 @@ function ($value) {
if ($action === 'delete') {
CourseCategory::deleteNode($categoryId);
Display::addFlash(Display::return_message(get_lang('Deleted')));
header('Location: '.api_get_self().'?category='.Security::remove_XSS($category));
header('Location: '.$baseUrl);
exit();
} elseif (($action === 'add' || $action === 'edit') && isset($_POST['formSent']) && $_POST['formSent']) {
$newParentCategoryCode = $_POST['parent_id'] ?? $category;
$newParentCategoryCode = $_POST['parent_id'] ?? $parentInfo['code'] ?? '';

if ($action === 'add') {
$ret = CourseCategory::addNode(
Expand All @@ -69,7 +72,7 @@ function ($value) {
$_POST['auth_course_child'],
$categoryId,
$newParentCategoryCode,
$category
$parentInfo['code'] ?? ''
);
$categoryInfo = CourseCategory::getCategory($_POST['code']);
$ret = $categoryInfo['id'];
Expand All @@ -90,8 +93,8 @@ function ($value) {
header('Location: '.api_get_path(WEB_CODE_PATH).'admin/course_category.php');
exit;
} elseif ($action === 'moveUp') {
CourseCategory::moveNodeUp($categoryId, $_GET['tree_pos'], $category);
header('Location: '.api_get_self().'?category='.Security::remove_XSS($category));
CourseCategory::moveNodeUp($categoryId, $_GET['tree_pos'], $parentInfo['code'] ?? '');
header('Location: '.$baseUrl);
Display::addFlash(Display::return_message(get_lang('Updated')));
exit();
}
Expand Down Expand Up @@ -137,15 +140,16 @@ function showCourses(button, categoryId) {
echo '<div class="actions">';
echo Display::url(
Display::return_icon('folder_up.png', get_lang('Back'), '', ICON_SIZE_MEDIUM),
api_get_path(WEB_CODE_PATH).'admin/course_category.php?category='.Security::remove_XSS($category)
$baseUrl
);
echo '</div>';

$form_title = $action === 'add' ? get_lang('AddACategory') : get_lang('EditNode');
if (!empty($category)) {
$form_title .= ' '.get_lang('Into').' '.Security::remove_XSS($category);
if (!empty($categoryInfo['parent_id'])) {
$form_title .= ' '.get_lang('Into').' '.$categoryInfo['parent_id'];
}
$url = api_get_self().'?action='.Security::remove_XSS($action).'&category='.Security::remove_XSS($category).'&id='.Security::remove_XSS($categoryId);
$url = $baseUrl.'&'
.http_build_query(['action' => Security::remove_XSS($action), 'id' => Security::remove_XSS($categoryId)]);
$form = new FormValidator('course_category', 'post', $url);
$form->addElement('header', '', $form_title);
$form->addElement('hidden', 'formSent', 1);
Expand Down Expand Up @@ -230,7 +234,7 @@ function showCourses(button, categoryId) {
$form->setDefaults(
[
'auth_course_child' => 'TRUE',
'parent_id' => $category,
'parent_id' => $parentInfo['code'] ?? '',
]
);
$form->addButtonCreate($text);
Expand All @@ -254,7 +258,7 @@ function showCourses(button, categoryId) {
if (empty($parentInfo) || $parentInfo['auth_cat_child'] === 'TRUE') {
$newCategoryLink = Display::url(
Display::return_icon('new_folder.png', get_lang('AddACategory'), '', ICON_SIZE_MEDIUM),
api_get_path(WEB_CODE_PATH).'admin/course_category.php?action=add&category='.Security::remove_XSS($category)
$baseUrl.'&action=add'
);

if (!empty($parentInfo) && $parentInfo['access_url_id'] != $urlId) {
Expand All @@ -266,7 +270,7 @@ function showCourses(button, categoryId) {
if (!empty($parentInfo)) {
echo Display::page_subheader($parentInfo['name'].' ('.$parentInfo['code'].')');
}
echo CourseCategory::listCategories($category);
echo CourseCategory::listCategories($parentInfo['code'] ?? '');
}

Display::display_footer();

1 comment on commit b3f92b0

@ywarnier
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

Please sign in to comment.