course_category.php 5.7 KB

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