lp_add.php 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. /**
  4. * This is a learning path creation and player tool in Chamilo - previously learnpath_handler.php.
  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. /* Header and action code */
  17. $currentstyle = api_get_setting('stylesheets');
  18. $htmlHeadXtra[] = '<script>
  19. function activate_start_date() {
  20. if(document.getElementById(\'start_date_div\').style.display == \'none\') {
  21. document.getElementById(\'start_date_div\').style.display = \'block\';
  22. } else {
  23. document.getElementById(\'start_date_div\').style.display = \'none\';
  24. }
  25. }
  26. function activate_end_date() {
  27. if(document.getElementById(\'end_date_div\').style.display == \'none\') {
  28. document.getElementById(\'end_date_div\').style.display = \'block\';
  29. } else {
  30. document.getElementById(\'end_date_div\').style.display = \'none\';
  31. }
  32. }
  33. </script>';
  34. /* Constants and variables */
  35. $is_allowed_to_edit = api_is_allowed_to_edit(null, true);
  36. $isStudentView = isset($_REQUEST['isStudentView']) ? $_REQUEST['isStudentView'] : null;
  37. $learnpath_id = isset($_REQUEST['lp_id']) ? $_REQUEST['lp_id'] : null;
  38. /* MAIN CODE */
  39. if ((!$is_allowed_to_edit) || $isStudentView) {
  40. header('location:lp_controller.php?action=view&lp_id='.$learnpath_id.'&'.api_get_cidreq());
  41. exit;
  42. }
  43. if (api_is_in_gradebook()) {
  44. $interbreadcrumb[] = [
  45. 'url' => Category::getUrl(),
  46. 'name' => get_lang('Assessments'),
  47. ];
  48. }
  49. $interbreadcrumb[] = [
  50. 'url' => 'lp_controller.php?action=list&'.api_get_cidreq(),
  51. 'name' => get_lang('Learning paths'),
  52. ];
  53. Display::display_header(get_lang('Create new learning path'), 'Path');
  54. echo '<div class="actions">';
  55. echo '<a href="lp_controller.php?'.api_get_cidreq().'">'.
  56. Display::return_icon(
  57. 'back.png',
  58. get_lang('ReturnToLearning paths'),
  59. '',
  60. ICON_SIZE_MEDIUM
  61. ).'</a>';
  62. echo '</div>';
  63. echo Display::return_message(get_lang('<strong>Welcome</strong> to the Chamilo Course authoring tool.<br />Create your courses step-by-step. The table of contents will appear to the left.'), 'normal', false);
  64. if ($_POST && empty($_REQUEST['lp_name'])) {
  65. echo Display::return_message(
  66. get_lang('The form contains incorrect or incomplete data. Please check your input.'),
  67. 'error',
  68. false
  69. );
  70. }
  71. $form = new FormValidator(
  72. 'lp_add',
  73. 'post',
  74. api_get_path(WEB_CODE_PATH).'lp/lp_controller.php?'.api_get_cidreq()
  75. );
  76. // Form title
  77. $form->addHeader(get_lang('To start, give a title to your course'));
  78. // Title
  79. if (api_get_configuration_value('save_titles_as_html')) {
  80. $form->addHtmlEditor(
  81. 'lp_name',
  82. get_lang('Learning path name'),
  83. true,
  84. false,
  85. ['ToolbarSet' => 'TitleAsHtml']
  86. );
  87. } else {
  88. $form->addElement(
  89. 'text',
  90. 'lp_name',
  91. api_ucfirst(get_lang('Learning path name')),
  92. ['autofocus' => 'autofocus']
  93. );
  94. }
  95. $form->applyFilter('lp_name', 'html_filter');
  96. $form->addRule('lp_name', get_lang('Required field'), 'required');
  97. $form->addElement('hidden', 'post_time', time());
  98. $form->addElement('hidden', 'action', 'add_lp');
  99. $form->addButtonAdvancedSettings('advanced_params');
  100. $form->addHtml('<div id="advanced_params_options" style="display:none">');
  101. $items = learnpath::getCategoryFromCourseIntoSelect(
  102. api_get_course_int_id(),
  103. true
  104. );
  105. $form->addElement('select', 'category_id', get_lang('Category'), $items);
  106. // accumulate_scorm_time
  107. $form->addElement(
  108. 'checkbox',
  109. 'accumulate_scorm_time',
  110. [null, get_lang('When enabled, the session time for SCORM Learning Paths will be cumulative, otherwise, it will only be counted from the last update time.')],
  111. get_lang('Accumulate SCORM session time')
  112. );
  113. // Start date
  114. $form->addElement(
  115. 'checkbox',
  116. 'activate_start_date_check',
  117. null,
  118. get_lang('Enable start time'),
  119. ['onclick' => 'activate_start_date()']
  120. );
  121. $form->addElement('html', '<div id="start_date_div" style="display:block;">');
  122. $form->addDatePicker('publicated_on', get_lang('Publication date'));
  123. $form->addElement('html', '</div>');
  124. //End date
  125. $form->addElement(
  126. 'checkbox',
  127. 'activate_end_date_check',
  128. null,
  129. get_lang('Enable end time'),
  130. ['onclick' => 'activate_end_date()']
  131. );
  132. $form->addElement('html', '<div id="end_date_div" style="display:none;">');
  133. $form->addDatePicker('expired_on', get_lang('Expiration date'));
  134. $form->addElement('html', '</div>');
  135. $extraField = new ExtraField('lp');
  136. $extra = $extraField->addElements($form, 0, ['lp_icon']);
  137. Skill::addSkillsToForm($form, ITEM_TYPE_LEARNPATH, 0);
  138. $form->addElement('html', '</div>');
  139. $defaults['activate_start_date_check'] = 1;
  140. $defaults['accumulate_scorm_time'] = 0;
  141. if (api_get_setting('scorm_cumulative_session_time') == 'true') {
  142. $defaults['accumulate_scorm_time'] = 1;
  143. }
  144. $defaults['publicated_on'] = date('Y-m-d 08:00:00');
  145. $defaults['expired_on'] = date('Y-m-d 08:00:00', time() + 86400);
  146. $form->setDefaults($defaults);
  147. $form->addButtonCreate(get_lang('Continue'));
  148. $form->display();
  149. Display::display_footer();