course_category.php 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. /**
  4. * @package chamilo.admin
  5. */
  6. // name of the language file that needs to be included
  7. $language_file = 'admin';
  8. $cidReset = true;
  9. require_once '../inc/global.inc.php';
  10. $this_section = SECTION_PLATFORM_ADMIN;
  11. api_protect_admin_script();
  12. $category = isset($_GET['category']) ? $_GET['category'] : null;
  13. if (!empty($category)) {
  14. $parentInfo = getCategory($category);
  15. }
  16. $categoryId = isset($_GET['id']) ? Security::remove_XSS($_GET['id']) : null;
  17. if (!empty($categoryId)) {
  18. $categoryInfo = getCategory($categoryId);
  19. }
  20. $action = isset($_GET['action']) ? $_GET['action'] : null;
  21. $errorMsg = '';
  22. if (!empty($action)) {
  23. if ($action == 'delete') {
  24. if (api_get_multiple_access_url()) {
  25. if (api_get_current_access_url_id() == 1 ||
  26. (isset($_configuration['enable_multiple_url_support_for_course_category']) &&
  27. $_configuration['enable_multiple_url_support_for_course_category'])
  28. ) {
  29. deleteNode($categoryId);
  30. header('Location: ' . api_get_self() . '?category=' . Security::remove_XSS($category));
  31. exit();
  32. }
  33. } else {
  34. deleteNode($categoryId);
  35. header('Location: ' . api_get_self() . '?category=' . Security::remove_XSS($category));
  36. exit();
  37. }
  38. } elseif (($action == 'add' || $action == 'edit') && isset($_POST['formSent']) && $_POST['formSent']) {
  39. if ($action == 'add') {
  40. $ret = addNode($_POST['code'], $_POST['name'], $_POST['auth_course_child'], $category);
  41. } else {
  42. $ret = editNode($_POST['code'], $_POST['name'], $_POST['auth_course_child'], $categoryId);
  43. }
  44. if ($ret) {
  45. $action = '';
  46. } else {
  47. $errorMsg = get_lang('CatCodeAlreadyUsed');
  48. }
  49. } elseif ($action == 'moveUp') {
  50. moveNodeUp($categoryId, $_GET['tree_pos'], $category);
  51. header('Location: ' . api_get_self() . '?category=' . Security::remove_XSS($category));
  52. exit();
  53. }
  54. }
  55. $tool_name = get_lang('AdminCategories');
  56. $interbreadcrumb[] = array('url' => 'index.php', "name" => get_lang('PlatformAdmin'));
  57. Display::display_header($tool_name);
  58. if ($action == 'add' || $action == 'edit') {
  59. if ((api_get_multiple_access_url() && api_get_current_access_url_id() == 1) ||
  60. !api_get_multiple_access_url() ||
  61. (isset($_configuration['enable_multiple_url_support_for_course_category']) &&
  62. $_configuration['enable_multiple_url_support_for_course_category'])
  63. ) {
  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='.$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='.$category;
  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. $form->addElement('text', 'name', get_lang("CategoryName"));
  80. $form->addRule('name', get_lang('PleaseEnterCategoryInfo'), 'required');
  81. $form->addRule('code', get_lang('PleaseEnterCategoryInfo'), 'required');
  82. $group = array(
  83. $form->createElement('radio', 'auth_course_child', get_lang("AllowCoursesInCategory"), get_lang('Yes'), 'TRUE'),
  84. $form->createElement('radio', 'auth_course_child', null, get_lang('No'), 'FALSE')
  85. );
  86. $form->addGroup($group, null, get_lang("AllowCoursesInCategory"));
  87. if (!empty($categoryInfo)) {
  88. $class = "save";
  89. $text = get_lang('CategoryMod');
  90. $form->setDefaults($categoryInfo);
  91. } else {
  92. $class = "add";
  93. $text = get_lang('AddCategory');
  94. $form->setDefaults(array('auth_course_child' => 'TRUE'));
  95. }
  96. $form->addElement('button', 'submit', $text);
  97. $form->display();
  98. } elseif (api_get_multiple_access_url() && api_get_current_access_url_id() != 1) {
  99. // If multiple URLs and not main URL, prevent edition and inform user
  100. Display::display_warning_message(get_lang('CourseCategoriesAreGlobal'));
  101. }
  102. } else {
  103. // If multiple URLs and not main URL, prevent deletion and inform user
  104. if ($action == 'delete' && api_get_multiple_access_url() && api_get_current_access_url_id() != 1) {
  105. Display::display_warning_message(get_lang('CourseCategoriesAreGlobal'));
  106. }
  107. echo '<div class="actions">';
  108. $link = null;
  109. if (!empty($parentInfo)) {
  110. $parentCode = $parentInfo['parent_id'];
  111. echo Display::url(
  112. Display::return_icon('back.png', get_lang("Back"), '', ICON_SIZE_MEDIUM),
  113. api_get_path(WEB_CODE_PATH).'admin/course_category.php?category='.$parentCode
  114. );
  115. }
  116. if (empty($parentInfo) || $parentInfo['auth_cat_child'] == 'TRUE') {
  117. echo Display::url(
  118. Display::return_icon('new_folder.png', get_lang("AddACategory"), '', ICON_SIZE_MEDIUM),
  119. api_get_path(WEB_CODE_PATH).'admin/course_category.php?action=add&category='.$category
  120. );
  121. }
  122. echo '</div>';
  123. if (!empty($parentInfo)) {
  124. echo Display::page_subheader($parentInfo['name'].' ('.$parentInfo['code'].')');
  125. }
  126. echo listCategories($category);
  127. }
  128. Display::display_footer();