delete($categoryRepo->find($categoryId)); CourseCategory::reorganizeTreePos($parentId); Display::addFlash(Display::return_message(get_lang('Deleted'))); } header('Location: '.api_get_self().'?category='.Security::remove_XSS($category)); exit; case 'export': $courses = CourseCategory::getCoursesInCategory($categoryId); if ($courses && count($courses) > 0) { $name = api_get_local_time().'_'.$categoryInfo['code']; $courseList = []; /* @var \Chamilo\CoreBundle\Entity\Course $course */ foreach ($courses as $course) { $courseList[] = [$course->getTitle()]; } $header = [get_lang('Course Title')]; Export::arrayToCsvSimple($courseList, $name, false, $header); } else { Display::addFlash(Display::return_message(get_lang('No courses found for this category'), 'warning')); header('Location: '.api_get_self().'?category='.Security::remove_XSS($categoryId)); exit; } break; case 'moveUp': if (CourseCategory::moveNodeUp($categoryId, $_GET['tree_pos'], $parentId)) { Display::addFlash(Display::return_message(get_lang('Update successful'))); } else { Display::addFlash(Display::return_message(get_lang('Cannot move category up'), 'error')); } header('Location: '.api_get_self().'?category='.Security::remove_XSS($category)); exit; case 'add': if (isset($_POST['formSent']) && $_POST['formSent']) { $categoryEntity = CourseCategory::add( $_POST['code'], $_POST['title'], $_POST['auth_course_child'], $_POST['description'], $parentId, ); if (isset($_FILES['image']) && $categoryEntity) { $crop = $_POST['picture_crop_result'] ?? ''; CourseCategory::saveImage($categoryEntity, $_FILES['image'], $crop); } Display::addFlash(Display::return_message(get_lang('Item added'))); header('Location: '.api_get_path(WEB_CODE_PATH).'admin/course_category.php?id='.$parentId); exit; } break; case 'edit': if (isset($_POST['formSent']) && $_POST['formSent']) { $categoryEntity = CourseCategory::edit( $categoryId, $_REQUEST['title'], $_REQUEST['auth_course_child'], $_REQUEST['code'], $_REQUEST['description'] ); // Delete Picture Category $deletePicture = $_POST['delete_picture'] ?? ''; if ($deletePicture && $categoryEntity) { $categoryRepo->deleteAsset($categoryEntity); } if (isset($_FILES['image']) && $categoryEntity) { $crop = $_POST['picture_crop_result'] ?? ''; CourseCategory::saveImage($categoryEntity, $_FILES['image'], $crop); } Display::addFlash(Display::return_message(get_lang('Update successful'))); header('Location: '.api_get_path(WEB_CODE_PATH).'admin/course_category.php?id='.$parentId); exit; } break; } $tool_name = get_lang('Courses categories'); $interbreadcrumb[] = [ 'url' => 'index.php', 'name' => get_lang('Administration'), ]; Display::display_header($tool_name); if ('add' === $action || 'edit' === $action) { $actions = Display::url( Display::getMdiIcon(ActionIcon::BACK, 'ch-tool-icon', null, ICON_SIZE_MEDIUM, get_lang('Back')), api_get_path(WEB_CODE_PATH).'admin/course_category.php?id='.$categoryId ); echo Display::toolbarAction('categories', [$actions]); $form_title = 'add' === $action ? get_lang('Add category') : get_lang('Edit this category'); if (!empty($categoryInfo)) { $form_title .= ' '.get_lang('Into').' '.$categoryInfo['title']; } $url = api_get_self().'?action='.Security::remove_XSS($action).'&id='.Security::remove_XSS($categoryId); $form = new FormValidator('course_category', 'post', $url); $form->addHeader($form_title); $form->addHidden('formSent', 1); $form->addElement('text', 'code', get_lang('Category code')); if ('true' === api_get_setting('editor.save_titles_as_html')) { $form->addHtmlEditor( 'title', get_lang('Category name'), true, false, ['ToolbarSet' => 'TitleAsHtml'] ); } else { $form->addElement('text', 'title', get_lang('Category name')); $form->addRule('title', get_lang('Please enter a code and a name for the category'), 'required'); } $form->addRule('code', get_lang('Please enter a code and a name for the category'), 'required'); $group = [ $form->createElement( 'radio', 'auth_course_child', get_lang('Allow adding courses in this category?'), get_lang('Yes'), 'TRUE' ), $form->createElement( 'radio', 'auth_course_child', null, get_lang('No'), 'FALSE' ), ]; $form->addGroup($group, null, get_lang('Allow adding courses in this category?')); $form->addHtmlEditor( 'description', get_lang('Description'), false, false, ['ToolbarSet' => 'Minimal'] ); $form->addFile( 'image', get_lang('Image'), ['id' => 'picture', 'class' => 'picture-form', 'accept' => 'image/*', 'crop_image' => true] ); if ('edit' === $action && !empty($categoryInfo['asset_id'])) { $form->addElement('checkbox', 'delete_picture', null, get_lang('Delete picture')); $asset = $assetRepo->find($categoryInfo['asset_id']); $image = $assetRepo->getAssetUrl($asset); $escapedImageUrl = htmlspecialchars($image, ENT_QUOTES, 'UTF-8'); $form->addLabel(get_lang('Image'), "Image"); } if ('edit' === $action && !empty($categoryInfo)) { $text = get_lang('Save'); $form->setDefaults($categoryInfo); $form->addButtonSave($text); } else { $text = get_lang('Add category'); $form->setDefaults(['auth_course_child' => 'TRUE']); $form->addButtonCreate($text); } $form->display(); } else { $actions = ''; $link = null; if (!empty($parentInfo)) { $realParentInfo = $parentInfo['parent_id'] ? CourseCategory::getCategoryById($parentInfo['parent_id']) : []; $realParentCode = $realParentInfo ? $realParentInfo['id'] : 0; $actions .= Display::url( Display::getMdiIcon(ActionIcon::BACK, 'ch-tool-icon', null, ICON_SIZE_MEDIUM, get_lang('Back')), api_get_path(WEB_CODE_PATH).'admin/course_category.php?id='.$realParentCode ); } if (empty($parentInfo) || 'TRUE' === $parentInfo['auth_cat_child']) { $newCategoryLink = Display::url( Display::getMdiIcon(ActionIcon::CREATE_FOLDER, 'ch-tool-icon', null, ICON_SIZE_MEDIUM, get_lang('Add category')), api_get_path(WEB_CODE_PATH).'admin/course_category.php?action=add&id='.$categoryId ); if (!empty($parentInfo) && $parentInfo['access_url_id'] != $urlId) { $newCategoryLink = ''; } $actions .= $newCategoryLink; } echo Display::toolbarAction('categories', [$actions]); if (!empty($parentInfo)) { echo Display::page_subheader($parentInfo['title'].' ('.$parentInfo['code'].')'); } echo CourseCategory::listCategories($categoryInfo); } Display::display_footer();