'index.php',
'name' => get_lang('Administration'),
];
Display::display_header($tool_name);
$urlId = api_get_current_access_url_id();
if ($action == 'add' || $action == 'edit') {
echo '
';
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)
);
echo '
';
$form_title = ($action == 'add') ? get_lang('Add category') : get_lang('Edit this category');
if (!empty($category)) {
$form_title .= ' '.get_lang('Into').' '.Security::remove_XSS($category);
}
$url = api_get_self().'?action='.Security::remove_XSS($action).'&category='.Security::remove_XSS($category).'&id='.Security::remove_XSS($categoryId);
$form = new FormValidator('course_category', 'post', $url);
$form->addElement('header', '', $form_title);
$form->addElement('hidden', 'formSent', 1);
$form->addElement('text', 'code', get_lang("Category code"));
if (api_get_configuration_value('save_titles_as_html')) {
$form->addHtmlEditor(
'name',
get_lang('Category name'),
true,
false,
['ToolbarSet' => 'TitleAsHtml']
);
} else {
$form->addElement('text', 'name', get_lang("Category name"));
$form->addRule('name', 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?'));
if ($myCourseListAsCategory) {
$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 ($action == 'edit' && !empty($categoryInfo['image'])) {
$form->addElement('checkbox', 'delete_picture', null, get_lang('Delete picture'));
$form->addHtml('
');
}
}
if (!empty($categoryInfo)) {
$class = 'save';
$text = get_lang('Save');
$form->setDefaults($categoryInfo);
$form->addButtonSave($text);
} else {
$class = 'add';
$text = get_lang('Add category');
$form->setDefaults(['auth_course_child' => 'TRUE']);
$form->addButtonCreate($text);
}
$form->display();
} else {
// If multiple URLs and not main URL, prevent deletion and inform user
if ($action == 'delete' && api_get_multiple_access_url() && $urlId != 1) {
echo Display::return_message(get_lang('Course categories are global over multiple portals configurations. Changes are only allowed in the main administrative portal.'), 'warning');
}
echo '';
$link = null;
if (!empty($parentInfo)) {
$parentCode = $parentInfo['parent_id'];
echo Display::url(
Display::return_icon('back.png', get_lang('Back'), '', ICON_SIZE_MEDIUM),
api_get_path(WEB_CODE_PATH).'admin/course_category.php?category='.$parentCode
);
}
if (empty($parentInfo) || $parentInfo['auth_cat_child'] == 'TRUE') {
$newCategoryLink = Display::url(
Display::return_icon('new_folder.png', get_lang('Add category'), '', ICON_SIZE_MEDIUM),
api_get_path(WEB_CODE_PATH).'admin/course_category.php?action=add&category='.Security::remove_XSS($category)
);
if (!empty($parentInfo) && $parentInfo['access_url_id'] != $urlId) {
$newCategoryLink = '';
}
echo $newCategoryLink;
}
echo '
';
if (!empty($parentInfo)) {
echo Display::page_subheader($parentInfo['name'].' ('.$parentInfo['code'].')');
}
echo CourseCategory::listCategories($category);
}
Display::display_footer();