lp_add_category.php 2.1 KB

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