course_category.php 6.3 KB

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