course_category.php 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. use Chamilo\CoreBundle\Framework\Container;
  4. /**
  5. * @package chamilo.admin
  6. */
  7. $cidReset = true;
  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' => Container::getRouter()->generate('administration'),
  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. $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('Save');
  90. $form->setDefaults($categoryInfo);
  91. $form->addButtonSave($text);
  92. } else {
  93. $class = "add";
  94. $text = get_lang('AddCategory');
  95. $form->setDefaults(array('auth_course_child' => 'TRUE'));
  96. $form->addButtonCreate($text);
  97. }
  98. $form->display();
  99. } else {
  100. // If multiple URLs and not main URL, prevent deletion and inform user
  101. if ($action == 'delete' && api_get_multiple_access_url() && api_get_current_access_url_id() != 1) {
  102. Display::display_warning_message(get_lang('CourseCategoriesAreGlobal'));
  103. }
  104. echo '<div class="actions">';
  105. $link = null;
  106. if (!empty($parentInfo)) {
  107. $parentCode = $parentInfo['parent_id'];
  108. echo Display::url(
  109. Display::return_icon('back.png', get_lang("Back"), '', ICON_SIZE_MEDIUM),
  110. api_get_path(WEB_CODE_PATH).'admin/course_category.php?category='.$parentCode
  111. );
  112. }
  113. if (empty($parentInfo) || $parentInfo['auth_cat_child'] == 'TRUE') {
  114. echo Display::url(
  115. Display::return_icon('new_folder.png', get_lang("AddACategory"), '', ICON_SIZE_MEDIUM),
  116. api_get_path(WEB_CODE_PATH).'admin/course_category.php?action=add&category='.Security::remove_XSS($category)
  117. );
  118. }
  119. echo '</div>';
  120. if (!empty($parentInfo)) {
  121. echo Display::page_subheader($parentInfo['name'].' ('.$parentInfo['code'].')');
  122. }
  123. echo CourseCategory::listCategories($category);
  124. }
  125. Display::display_footer();