lp_add_category.php 2.2 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. $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[] = array(
  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. $form->addElement('text', 'name', api_ucfirst(get_lang('Name')));
  28. $form->addRule('name', get_lang('ThisFieldIsRequired'), 'required');
  29. $form->addElement('hidden', 'action', 'add_lp_category');
  30. $form->addElement('hidden', 'c_id', api_get_course_int_id());
  31. $form->addElement('hidden', 'id', 0);
  32. $form->addButtonSave(get_lang('Save'));
  33. if ($form->validate()) {
  34. $values = $form->getSubmitValues();
  35. if (!empty($values['id'])) {
  36. learnpath::updateCategory($values);
  37. $url = api_get_self().'?action=list&'.api_get_cidreq();
  38. Display::addFlash(Display::return_message(get_lang('Updated')));
  39. header('Location: '.$url);
  40. exit;
  41. } else {
  42. learnpath::createCategory($values);
  43. Display::addFlash(Display::return_message(get_lang('Added')));
  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();