lp_add.php 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  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 (isset($_SESSION['gradebook'])) {
  49. $gradebook = $_SESSION['gradebook'];
  50. }
  51. if (!empty($gradebook) && $gradebook == 'view') {
  52. $interbreadcrumb[] = array(
  53. 'url' => '../gradebook/'.$_SESSION['gradebook_dest'],
  54. 'name' => get_lang('ToolGradebook')
  55. );
  56. }
  57. $interbreadcrumb[] = array('url' => 'lp_controller.php?action=list', 'name' => get_lang('LearningPaths'));
  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('back.png', get_lang('ReturnToLearningPaths'), '', ICON_SIZE_MEDIUM).'</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(get_lang('FormHasErrorsPleaseComplete'), 'error', false);
  66. }
  67. $form = new FormValidator(
  68. 'lp_add',
  69. 'post',
  70. api_get_path(WEB_CODE_PATH).'lp/lp_controller.php?'.api_get_cidreq()
  71. );
  72. // Form title
  73. $form->addElement('header', get_lang('AddLpToStart'));
  74. // Title
  75. $form->addElement('text', 'lp_name', api_ucfirst(get_lang('LPName')), array('autofocus' => 'autofocus'));
  76. $form->applyFilter('lp_name', 'html_filter');
  77. $form->addRule('lp_name', get_lang('ThisFieldIsRequired'), 'required');
  78. $form->addElement('hidden', 'post_time', time());
  79. $form->addElement('hidden', 'action', 'add_lp');
  80. $form->addButtonAdvancedSettings('advanced_params');
  81. $form->addElement('html', '<div id="advanced_params_options" style="display:none">');
  82. $items = learnpath::getCategoryFromCourseIntoSelect(api_get_course_int_id(), true);
  83. $form->addElement('select', 'category_id', get_lang('Category'), $items);
  84. // accumulate_scorm_time
  85. $form->addElement(
  86. 'checkbox',
  87. 'accumulate_scorm_time',
  88. [get_lang('AccumulateScormTime'), get_lang('AccumulateScormTimeInfo')]
  89. );
  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. if (api_get_setting('scorm_cumulative_session_time') == 'true') {
  103. $defaults['accumulate_scorm_time'] = 1;
  104. } else {
  105. $defaults['accumulate_scorm_time'] = 0;
  106. }
  107. $defaults['publicated_on'] = date('Y-m-d 08:00:00');
  108. $defaults['expired_on'] = date('Y-m-d 08:00:00', time() + 86400);
  109. $form->setDefaults($defaults);
  110. $form->addButtonCreate(get_lang('CreateLearningPath'));
  111. $form->display();
  112. // Footer
  113. Display::display_footer();