lp_add_category.php 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. /**
  4. * @author Julio Montoya <gugli100@gmail.com> Adding formvalidator support
  5. *
  6. * @package chamilo.learnpath
  7. */
  8. $this_section = SECTION_COURSES;
  9. api_protect_course_script();
  10. $is_allowed_to_edit = api_is_allowed_to_edit(null, true);
  11. if (!$is_allowed_to_edit) {
  12. header('location:lp_controller.php?action=list&'.api_get_cidreq());
  13. exit;
  14. }
  15. $interbreadcrumb[] = [
  16. 'url' => 'lp_controller.php?action=list&'.api_get_cidreq(),
  17. 'name' => get_lang('LearningPaths'),
  18. ];
  19. $form = new FormValidator(
  20. 'lp_add_category',
  21. 'post',
  22. 'lp_controller.php?'.api_get_cidreq()
  23. );
  24. // Form title
  25. $form->addElement('header', null, get_lang('AddLPCategory'));
  26. // Title
  27. if (api_get_configuration_value('save_titles_as_html')) {
  28. $form->addHtmlEditor(
  29. 'name',
  30. get_lang('Name'),
  31. true,
  32. false,
  33. ['ToolbarSet' => 'TitleAsHtml']
  34. );
  35. } else {
  36. $form->addText('name', get_lang('Name'), true);
  37. }
  38. $form->addElement('hidden', 'action', 'add_lp_category');
  39. $form->addElement('hidden', 'c_id', api_get_course_int_id());
  40. $form->addElement('hidden', 'id', 0);
  41. $form->addButtonSave(get_lang('Save'));
  42. if ($form->validate()) {
  43. $values = $form->getSubmitValues();
  44. if (!empty($values['id'])) {
  45. learnpath::updateCategory($values);
  46. $url = api_get_self().'?action=list&'.api_get_cidreq();
  47. Display::addFlash(Display::return_message(get_lang('Updated')));
  48. header('Location: '.$url);
  49. exit;
  50. } else {
  51. learnpath::createCategory($values);
  52. Display::addFlash(Display::return_message(get_lang('Added')));
  53. $url = api_get_self().'?action=list&'.api_get_cidreq();
  54. header('Location: '.$url);
  55. exit;
  56. }
  57. } else {
  58. $id = isset($_REQUEST['id']) ? $_REQUEST['id'] : null;
  59. if ($id) {
  60. $item = learnpath::getCategory($id);
  61. $defaults = [
  62. 'id' => $item->getId(),
  63. 'name' => $item->getName(),
  64. ];
  65. $form->setDefaults($defaults);
  66. }
  67. }
  68. Display::display_header(get_lang('LearnpathAddLearnpath'), 'Path');
  69. echo '<div class="actions">';
  70. echo '<a href="lp_controller.php?'.api_get_cidreq().'">'.
  71. Display::return_icon(
  72. 'back.png',
  73. get_lang('ReturnToLearningPaths'),
  74. '',
  75. ICON_SIZE_MEDIUM
  76. ).
  77. '</a>';
  78. echo '</div>';
  79. $form->display();
  80. Display::display_footer();