lp_add_category.php 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  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. require 'learnpath_functions.inc.php';
  11. require 'resourcelinker.inc.php';
  12. $is_allowed_to_edit = api_is_allowed_to_edit(null, true);
  13. if (!$is_allowed_to_edit) {
  14. header('location:lp_controller.php?action=list&'.api_get_cidreq());
  15. exit;
  16. }
  17. $interbreadcrumb[] = array(
  18. 'url' => 'lp_controller.php?action=list?'.api_get_cidreq(),
  19. 'name' => get_lang('LearningPaths'),
  20. );
  21. $form = new FormValidator(
  22. 'lp_add_category',
  23. 'post',
  24. 'lp_controller.php?'.api_get_cidreq()
  25. );
  26. // Form title
  27. $form->addElement('header', null, get_lang('AddLPCategory'));
  28. // Title
  29. $form->addElement('text', 'name', api_ucfirst(get_lang('Name')));
  30. $form->addRule('name', get_lang('ThisFieldIsRequired'), 'required');
  31. $form->addElement('hidden', 'action', 'add_lp_category');
  32. $form->addElement('hidden', 'c_id', api_get_course_int_id());
  33. $form->addElement('hidden', 'id', 0);
  34. $form->addButtonSave(get_lang('Save'));
  35. if ($form->validate()) {
  36. $values = $form->getSubmitValues();
  37. if (!empty($values['id'])) {
  38. learnpath::updateCategory($values);
  39. $url = api_get_self().'?action=list&'.api_get_cidreq();
  40. header('Location: '.$url);
  41. exit;
  42. } else {
  43. learnpath::createCategory($values);
  44. $url = api_get_self().'?action=list&'.api_get_cidreq();
  45. header('Location: '.$url);
  46. exit;
  47. }
  48. } else {
  49. $id = isset($_REQUEST['id']) ? $_REQUEST['id'] : null;
  50. if ($id) {
  51. $item = learnpath::getCategory($id);
  52. $defaults = array(
  53. 'id' => $item->getId(),
  54. 'name' => $item->getName()
  55. );
  56. $form->setDefaults($defaults);
  57. }
  58. }
  59. Display::display_header(get_lang('LearnpathAddLearnpath'), 'Path');
  60. echo '<div class="actions">';
  61. echo '<a href="lp_controller.php?'.api_get_cidreq().'">'.
  62. Display::return_icon('back.png', get_lang('ReturnToLearningPaths'), '', ICON_SIZE_MEDIUM).'</a>';
  63. echo '</div>';
  64. $form->display();
  65. Display::display_footer();