course_category.php 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. /**
  4. * @package chamilo.admin
  5. */
  6. $cidReset = true;
  7. require_once __DIR__.'/../inc/global.inc.php';
  8. $this_section = SECTION_PLATFORM_ADMIN;
  9. api_protect_admin_script();
  10. $category = isset($_GET['category']) ? $_GET['category'] : null;
  11. $parentInfo = [];
  12. if (!empty($category)) {
  13. $parentInfo = CourseCategory::getCategory($category);
  14. }
  15. $categoryId = isset($_GET['id']) ? Security::remove_XSS($_GET['id']) : null;
  16. if (!empty($categoryId)) {
  17. $categoryInfo = CourseCategory::getCategory($categoryId);
  18. }
  19. $action = isset($_GET['action']) ? $_GET['action'] : null;
  20. $errorMsg = '';
  21. if (!empty($action)) {
  22. if ($action == 'delete') {
  23. CourseCategory::deleteNode($categoryId);
  24. Display::addFlash(Display::return_message(get_lang('Deleted')));
  25. header('Location: '.api_get_self().'?category='.Security::remove_XSS($category));
  26. exit();
  27. } elseif (($action == 'add' || $action == 'edit') && isset($_POST['formSent']) && $_POST['formSent']) {
  28. if ($action == 'add') {
  29. $ret = CourseCategory::addNode(
  30. $_POST['code'],
  31. $_POST['name'],
  32. $_POST['auth_course_child'],
  33. $category
  34. );
  35. Display::addFlash(Display::return_message(get_lang('Created')));
  36. } else {
  37. $ret = CourseCategory::editNode(
  38. $_POST['code'],
  39. $_POST['name'],
  40. $_POST['auth_course_child'],
  41. $categoryId
  42. );
  43. Display::addFlash(Display::return_message(get_lang('Updated')));
  44. }
  45. if ($ret) {
  46. $action = '';
  47. } else {
  48. $errorMsg = get_lang('CatCodeAlreadyUsed');
  49. }
  50. } elseif ($action == 'moveUp') {
  51. CourseCategory::moveNodeUp($categoryId, $_GET['tree_pos'], $category);
  52. header('Location: '.api_get_self().'?category='.Security::remove_XSS($category));
  53. Display::addFlash(Display::return_message(get_lang('Updated')));
  54. exit();
  55. }
  56. }
  57. $tool_name = get_lang('AdminCategories');
  58. $interbreadcrumb[] = array(
  59. 'url' => 'index.php',
  60. "name" => get_lang('PlatformAdmin'),
  61. );
  62. Display::display_header($tool_name);
  63. if ($action == 'add' || $action == 'edit') {
  64. echo '<div class="actions">';
  65. echo Display::url(
  66. Display::return_icon('folder_up.png', get_lang("Back"), '', ICON_SIZE_MEDIUM),
  67. api_get_path(WEB_CODE_PATH).'admin/course_category.php?category='.Security::remove_XSS($category)
  68. );
  69. echo '</div>';
  70. $form_title = ($action == 'add') ? get_lang('AddACategory') : get_lang('EditNode');
  71. if (!empty($category)) {
  72. $form_title .= ' '.get_lang('Into').' '.Security::remove_XSS($category);
  73. }
  74. $url = api_get_self().'?action='.Security::remove_XSS($action).'&category='.Security::remove_XSS($category).'&id='.Security::remove_XSS($categoryId);
  75. $form = new FormValidator('course_category', 'post', $url);
  76. $form->addElement('header', '', $form_title);
  77. $form->addElement('hidden', 'formSent', 1);
  78. $form->addElement('text', 'code', get_lang("CategoryCode"));
  79. if (api_get_configuration_value('save_titles_as_html')) {
  80. $form->addHtmlEditor(
  81. 'name',
  82. get_lang('CategoryName'),
  83. true,
  84. false,
  85. ['ToolbarSet' => 'Minimal']
  86. );
  87. } else {
  88. $form->addElement('text', 'name', get_lang("CategoryName"));
  89. $form->addRule('name', get_lang('PleaseEnterCategoryInfo'), 'required');
  90. }
  91. $form->addRule('code', get_lang('PleaseEnterCategoryInfo'), 'required');
  92. $group = array(
  93. $form->createElement(
  94. 'radio',
  95. 'auth_course_child',
  96. get_lang("AllowCoursesInCategory"),
  97. get_lang('Yes'),
  98. 'TRUE'
  99. ),
  100. $form->createElement(
  101. 'radio',
  102. 'auth_course_child',
  103. null,
  104. get_lang('No'),
  105. 'FALSE'
  106. ),
  107. );
  108. $form->addGroup($group, null, get_lang("AllowCoursesInCategory"));
  109. if (!empty($categoryInfo)) {
  110. $class = "save";
  111. $text = get_lang('Save');
  112. $form->setDefaults($categoryInfo);
  113. $form->addButtonSave($text);
  114. } else {
  115. $class = "add";
  116. $text = get_lang('AddCategory');
  117. $form->setDefaults(array('auth_course_child' => 'TRUE'));
  118. $form->addButtonCreate($text);
  119. }
  120. $form->display();
  121. } else {
  122. // If multiple URLs and not main URL, prevent deletion and inform user
  123. if ($action == 'delete' && api_get_multiple_access_url() && api_get_current_access_url_id() != 1) {
  124. echo Display::return_message(get_lang('CourseCategoriesAreGlobal'), 'warning');
  125. }
  126. echo '<div class="actions">';
  127. $link = null;
  128. if (!empty($parentInfo)) {
  129. $parentCode = $parentInfo['parent_id'];
  130. echo Display::url(
  131. Display::return_icon('back.png', get_lang("Back"), '', ICON_SIZE_MEDIUM),
  132. api_get_path(WEB_CODE_PATH).'admin/course_category.php?category='.$parentCode
  133. );
  134. }
  135. if (empty($parentInfo) || $parentInfo['auth_cat_child'] == 'TRUE') {
  136. echo Display::url(
  137. Display::return_icon('new_folder.png', get_lang("AddACategory"), '', ICON_SIZE_MEDIUM),
  138. api_get_path(WEB_CODE_PATH).'admin/course_category.php?action=add&category='.Security::remove_XSS($category)
  139. );
  140. }
  141. echo '</div>';
  142. if (!empty($parentInfo)) {
  143. echo Display::page_subheader($parentInfo['name'].' ('.$parentInfo['code'].')');
  144. }
  145. echo CourseCategory::listCategories($category);
  146. }
  147. Display::display_footer();