lp_add.php 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173
  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);
  41. exit;
  42. }
  43. // From here on, we are admin because of the previous condition, so don't check anymore.
  44. /*
  45. Course admin section
  46. - all the functions not available for students - always available in this case (page only shown to admin)
  47. */
  48. if (api_is_in_gradebook()) {
  49. $interbreadcrumb[] = [
  50. 'url' => Category::getUrl(),
  51. 'name' => get_lang('ToolGradebook'),
  52. ];
  53. }
  54. $interbreadcrumb[] = [
  55. 'url' => 'lp_controller.php?action=list',
  56. 'name' => get_lang('LearningPaths'),
  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(
  62. 'back.png',
  63. get_lang('ReturnToLearningPaths'),
  64. '',
  65. ICON_SIZE_MEDIUM
  66. ).'</a>';
  67. echo '</div>';
  68. echo Display::return_message(get_lang('AddLpIntro'), 'normal', false);
  69. if ($_POST && empty($_REQUEST['lp_name'])) {
  70. echo Display::return_message(
  71. get_lang('FormHasErrorsPleaseComplete'),
  72. 'error',
  73. false
  74. );
  75. }
  76. $form = new FormValidator(
  77. 'lp_add',
  78. 'post',
  79. api_get_path(WEB_CODE_PATH).'lp/lp_controller.php?'.api_get_cidreq()
  80. );
  81. // Form title
  82. $form->addHeader(get_lang('AddLpToStart'));
  83. // Title
  84. $form->addElement(
  85. 'text',
  86. 'lp_name',
  87. api_ucfirst(get_lang('LPName')),
  88. ['autofocus' => 'autofocus']
  89. );
  90. $form->applyFilter('lp_name', 'html_filter');
  91. $form->addRule('lp_name', get_lang('ThisFieldIsRequired'), 'required');
  92. $form->addElement('hidden', 'post_time', time());
  93. $form->addElement('hidden', 'action', 'add_lp');
  94. $form->addButtonAdvancedSettings('advanced_params');
  95. $form->addHtml('<div id="advanced_params_options" style="display:none">');
  96. $items = learnpath::getCategoryFromCourseIntoSelect(
  97. api_get_course_int_id(),
  98. true
  99. );
  100. $form->addElement('select', 'category_id', get_lang('Category'), $items);
  101. // accumulate_scorm_time
  102. $form->addElement(
  103. 'checkbox',
  104. 'accumulate_scorm_time',
  105. [null, get_lang('AccumulateScormTimeInfo')],
  106. get_lang('AccumulateScormTime')
  107. );
  108. // Start date
  109. $form->addElement(
  110. 'checkbox',
  111. 'activate_start_date_check',
  112. null,
  113. get_lang('EnableStartTime'),
  114. ['onclick' => 'activate_start_date()']
  115. );
  116. $form->addElement('html', '<div id="start_date_div" style="display:block;">');
  117. $form->addDatePicker('publicated_on', get_lang('PublicationDate'));
  118. $form->addElement('html', '</div>');
  119. //End date
  120. $form->addElement(
  121. 'checkbox',
  122. 'activate_end_date_check',
  123. null,
  124. get_lang('EnableEndTime'),
  125. ['onclick' => 'activate_end_date()']
  126. );
  127. $form->addElement('html', '<div id="end_date_div" style="display:none;">');
  128. $form->addDatePicker('expired_on', get_lang('ExpirationDate'));
  129. $form->addElement('html', '</div>');
  130. Skill::addSkillsToForm($form, ITEM_TYPE_LEARNPATH, 0);
  131. $form->addElement('html', '</div>');
  132. $defaults['activate_start_date_check'] = 1;
  133. if (api_get_setting('scorm_cumulative_session_time') == 'true') {
  134. $defaults['accumulate_scorm_time'] = 1;
  135. } else {
  136. $defaults['accumulate_scorm_time'] = 0;
  137. }
  138. $defaults['publicated_on'] = date('Y-m-d 08:00:00');
  139. $defaults['expired_on'] = date('Y-m-d 08:00:00', time() + 86400);
  140. $form->setDefaults($defaults);
  141. $form->addButtonCreate(get_lang('CreateLearningPath'));
  142. $form->display();
  143. // Footer
  144. Display::display_footer();