lp_add.php 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. /**
  4. * This is a learning path creation and player tool in Chamilo
  5. *
  6. * @author Patrick Cool
  7. * @author Denes Nagy
  8. * @author Roan Embrechts, refactoring and code cleaning
  9. * @author Yannick Warnier <ywarnier@beeznest.org> - cleaning and update for new SCORM tool
  10. * @author Julio Montoya <gugli100@gmail.com> Adding formvalidator support
  11. *
  12. * @package chamilo.learnpath
  13. */
  14. $this_section = SECTION_COURSES;
  15. api_protect_course_script();
  16. /* Libraries */
  17. require 'learnpath_functions.inc.php';
  18. $currentstyle = api_get_setting('stylesheets');
  19. $htmlHeadXtra[] = '<script>
  20. function activate_start_date() {
  21. if(document.getElementById(\'start_date_div\').style.display == \'none\') {
  22. document.getElementById(\'start_date_div\').style.display = \'block\';
  23. } else {
  24. document.getElementById(\'start_date_div\').style.display = \'none\';
  25. }
  26. }
  27. function activate_end_date() {
  28. if(document.getElementById(\'end_date_div\').style.display == \'none\') {
  29. document.getElementById(\'end_date_div\').style.display = \'block\';
  30. } else {
  31. document.getElementById(\'end_date_div\').style.display = \'none\';
  32. }
  33. }
  34. </script>';
  35. /* Constants and variables */
  36. $is_allowed_to_edit = api_is_allowed_to_edit(null, true);
  37. $isStudentView = isset($_REQUEST['isStudentView']) ? $_REQUEST['isStudentView'] : null;
  38. $learnpath_id = isset($_REQUEST['lp_id']) ? $_REQUEST['lp_id'] : null;
  39. /* MAIN CODE */
  40. // Using the resource linker as a tool for adding resources to the learning path.
  41. if ($action == 'add' && $type == 'learnpathitem') {
  42. $htmlHeadXtra[] = "<script> window.location=\"../resourcelinker/resourcelinker.php?source_id=5&action=$action&learnpath_id=$learnpath_id&chapter_id=$chapter_id&originalresource=no\"; </script>";
  43. }
  44. if ((!$is_allowed_to_edit) || ($isStudentView)) {
  45. //error_log('New LP - User not authorized in lp_add.php');
  46. header('location:lp_controller.php?action=view&lp_id='.$learnpath_id);
  47. exit;
  48. }
  49. // From here on, we are admin because of the previous condition, so don't check anymore.
  50. /*
  51. Course admin section
  52. - all the functions not available for students - always available in this case (page only shown to admin)
  53. */
  54. if (api_is_in_gradebook()) {
  55. $interbreadcrumb[]= array(
  56. 'url' => api_get_path(WEB_CODE_PATH).'gradebook/index.php?'.api_get_cidreq(),
  57. 'name' => get_lang('ToolGradebook')
  58. );
  59. }
  60. $interbreadcrumb[] = array(
  61. 'url' => 'lp_controller.php?action=list&'.api_get_cidreq(),
  62. 'name' => get_lang('LearningPaths'),
  63. );
  64. Display::display_header(get_lang('LearnpathAddLearnpath'), 'Path');
  65. echo '<div class="actions">';
  66. echo '<a href="lp_controller.php?'.api_get_cidreq().'">'.
  67. Display::return_icon('back.png', get_lang('ReturnToLearningPaths'),'',ICON_SIZE_MEDIUM).'</a>';
  68. echo '</div>';
  69. Display::display_normal_message(get_lang('AddLpIntro'), false);
  70. if ($_POST AND empty($_REQUEST['lp_name'])) {
  71. Display::display_error_message(get_lang('FormHasErrorsPleaseComplete'), false);
  72. }
  73. $form = new FormValidator(
  74. 'lp_add',
  75. 'post',
  76. api_get_path(WEB_CODE_PATH).'newscorm/lp_controller.php?'.api_get_cidreq()
  77. );
  78. // Form title
  79. $form->addElement('header', get_lang('AddLpToStart'));
  80. // Title
  81. $form->addElement('text', 'lp_name', api_ucfirst(get_lang('LPName')), array('autofocus' => 'autofocus'));
  82. $form->applyFilter('lp_name', 'html_filter');
  83. $form->addRule('lp_name', get_lang('ThisFieldIsRequired'), 'required');
  84. $form->addElement('hidden', 'post_time', time());
  85. $form->addElement('hidden', 'action', 'add_lp');
  86. $form->addButtonAdvancedSettings('advanced_params');
  87. $form->addElement('html', '<div id="advanced_params_options" style="display:none">');
  88. $items = learnpath::getCategoryFromCourseIntoSelect(api_get_course_int_id(), true);
  89. $form->addElement('select', 'category_id', get_lang('Category'), $items);
  90. // Start date
  91. $form->addElement('checkbox', 'activate_start_date_check', null, get_lang('EnableStartTime'), array('onclick' => 'activate_start_date()'));
  92. $form->addElement('html','<div id="start_date_div" style="display:block;">');
  93. $form->addDatePicker('publicated_on', get_lang('PublicationDate'));
  94. $form->addElement('html','</div>');
  95. //End date
  96. $form->addElement('checkbox', 'activate_end_date_check', null, get_lang('EnableEndTime'), array('onclick' => 'activate_end_date()'));
  97. $form->addElement('html','<div id="end_date_div" style="display:none;">');
  98. $form->addDatePicker('expired_on', get_lang('ExpirationDate'));
  99. $form->addElement('html','</div>');
  100. $form->addElement('html','</div>');
  101. $defaults['activate_start_date_check'] = 1;
  102. $defaults['publicated_on'] = date('Y-m-d 08:00:00');
  103. $defaults['expired_on'] = date('Y-m-d 08:00:00',time()+86400);
  104. $form->setDefaults($defaults);
  105. $form->addButtonCreate(get_lang('CreateLearningPath'));
  106. $form->display();
  107. // Footer
  108. Display::display_footer();