lp_add.php 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  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('ToolGradebook'),
  47. ];
  48. }
  49. $interbreadcrumb[] = [
  50. 'url' => 'lp_controller.php?action=list&'.api_get_cidreq(),
  51. 'name' => get_lang('LearningPaths'),
  52. ];
  53. Display::display_header(get_lang('LearnpathAddLearnpath'), '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('ReturnToLearningPaths'),
  59. '',
  60. ICON_SIZE_MEDIUM
  61. ).'</a>';
  62. echo '</div>';
  63. echo Display::return_message(get_lang('AddLpIntro'), 'normal', false);
  64. if ($_POST && empty($_REQUEST['lp_name'])) {
  65. echo Display::return_message(
  66. get_lang('FormHasErrorsPleaseComplete'),
  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('AddLpToStart'));
  78. // Title
  79. $form->addElement(
  80. 'text',
  81. 'lp_name',
  82. api_ucfirst(get_lang('LPName')),
  83. ['autofocus' => 'autofocus']
  84. );
  85. $form->applyFilter('lp_name', 'html_filter');
  86. $form->addRule('lp_name', get_lang('ThisFieldIsRequired'), 'required');
  87. $form->addElement('hidden', 'post_time', time());
  88. $form->addElement('hidden', 'action', 'add_lp');
  89. $form->addButtonAdvancedSettings('advanced_params');
  90. $form->addHtml('<div id="advanced_params_options" style="display:none">');
  91. $items = learnpath::getCategoryFromCourseIntoSelect(
  92. api_get_course_int_id(),
  93. true
  94. );
  95. $form->addElement('select', 'category_id', get_lang('Category'), $items);
  96. // accumulate_scorm_time
  97. $form->addElement(
  98. 'checkbox',
  99. 'accumulate_scorm_time',
  100. [null, get_lang('AccumulateScormTimeInfo')],
  101. get_lang('AccumulateScormTime')
  102. );
  103. // Start date
  104. $form->addElement(
  105. 'checkbox',
  106. 'activate_start_date_check',
  107. null,
  108. get_lang('EnableStartTime'),
  109. ['onclick' => 'activate_start_date()']
  110. );
  111. $form->addElement('html', '<div id="start_date_div" style="display:block;">');
  112. $form->addDatePicker('publicated_on', get_lang('PublicationDate'));
  113. $form->addElement('html', '</div>');
  114. //End date
  115. $form->addElement(
  116. 'checkbox',
  117. 'activate_end_date_check',
  118. null,
  119. get_lang('EnableEndTime'),
  120. ['onclick' => 'activate_end_date()']
  121. );
  122. $form->addElement('html', '<div id="end_date_div" style="display:none;">');
  123. $form->addDatePicker('expired_on', get_lang('ExpirationDate'));
  124. $form->addElement('html', '</div>');
  125. $extraField = new ExtraField('lp');
  126. $extra = $extraField->addElements($form, 0, ['lp_icon']);
  127. Skill::addSkillsToForm($form, ITEM_TYPE_LEARNPATH, 0);
  128. $form->addElement('html', '</div>');
  129. $defaults['activate_start_date_check'] = 1;
  130. $defaults['accumulate_scorm_time'] = 0;
  131. if (api_get_setting('scorm_cumulative_session_time') == 'true') {
  132. $defaults['accumulate_scorm_time'] = 1;
  133. }
  134. $defaults['publicated_on'] = date('Y-m-d 08:00:00');
  135. $defaults['expired_on'] = date('Y-m-d 08:00:00', time() + 86400);
  136. $form->setDefaults($defaults);
  137. $form->addButtonCreate(get_lang('CreateLearningPath'));
  138. $form->display();
  139. Display::display_footer();