lp_add.php 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  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. /* Libraries */
  17. require 'learnpath_functions.inc.php';
  18. //include '../resourcelinker/resourcelinker.inc.php';
  19. require 'resourcelinker.inc.php';
  20. // Rewrite the language file, sadly overwritten by resourcelinker.inc.php.
  21. // Name of the language file that needs to be included.
  22. /* Header and action code */
  23. $currentstyle = api_get_setting('stylesheets');
  24. $htmlHeadXtra[] = '<script>
  25. function activate_start_date() {
  26. if(document.getElementById(\'start_date_div\').style.display == \'none\') {
  27. document.getElementById(\'start_date_div\').style.display = \'block\';
  28. } else {
  29. document.getElementById(\'start_date_div\').style.display = \'none\';
  30. }
  31. }
  32. function activate_end_date() {
  33. if(document.getElementById(\'end_date_div\').style.display == \'none\') {
  34. document.getElementById(\'end_date_div\').style.display = \'block\';
  35. } else {
  36. document.getElementById(\'end_date_div\').style.display = \'none\';
  37. }
  38. }
  39. </script>';
  40. /* Constants and variables */
  41. $is_allowed_to_edit = api_is_allowed_to_edit(null, true);
  42. $isStudentView = isset($_REQUEST['isStudentView']) ? $_REQUEST['isStudentView'] : null;
  43. $learnpath_id = isset($_REQUEST['lp_id']) ? $_REQUEST['lp_id'] : null;
  44. /* MAIN CODE */
  45. // Using the resource linker as a tool for adding resources to the learning path.
  46. if ($action == 'add' && $type == 'learnpathitem') {
  47. $htmlHeadXtra[] = "<script> window.location=\"../resourcelinker/resourcelinker.php?source_id=5&action=$action&learnpath_id=$learnpath_id&chapter_id=$chapter_id&originalresource=no\"; </script>";
  48. }
  49. if ((!$is_allowed_to_edit) || ($isStudentView)) {
  50. //error_log('New LP - User not authorized in lp_add.php');
  51. header('location:lp_controller.php?action=view&lp_id='.$learnpath_id);
  52. exit;
  53. }
  54. // From here on, we are admin because of the previous condition, so don't check anymore.
  55. /*
  56. Course admin section
  57. - all the functions not available for students - always available in this case (page only shown to admin)
  58. */
  59. if (isset($_SESSION['gradebook'])){
  60. $gradebook = $_SESSION['gradebook'];
  61. }
  62. if (!empty($gradebook) && $gradebook=='view') {
  63. $interbreadcrumb[]= array (
  64. 'url' => '../gradebook/'.$_SESSION['gradebook_dest'],
  65. 'name' => get_lang('ToolGradebook')
  66. );
  67. }
  68. $interbreadcrumb[] = array('url' => 'lp_controller.php?action=list', 'name' => get_lang('LearningPaths'));
  69. Display::display_header(get_lang('LearnpathAddLearnpath'), 'Path');
  70. echo '<div class="actions">';
  71. echo '<a href="lp_controller.php?cidReq='.$_course['sysCode'].'">'.
  72. Display::return_icon('back.png', get_lang('ReturnToLearningPaths'),'',ICON_SIZE_MEDIUM).'</a>';
  73. echo '</div>';
  74. Display::display_normal_message(get_lang('AddLpIntro'), false);
  75. if ($_POST AND empty($_REQUEST['lp_name'])) {
  76. Display::display_error_message(get_lang('FormHasErrorsPleaseComplete'), false);
  77. }
  78. $form = new FormValidator(
  79. 'lp_add',
  80. 'post',
  81. api_get_path(WEB_CODE_PATH).'newscorm/lp_controller.php?'.api_get_cidreq()
  82. );
  83. // Form title
  84. $form->addElement('header', get_lang('AddLpToStart'));
  85. // Title
  86. $form->addElement('text', 'lp_name', api_ucfirst(get_lang('LPName')), array('autofocus' => 'autofocus'));
  87. $form->applyFilter('lp_name', 'html_filter');
  88. $form->addRule('lp_name', get_lang('ThisFieldIsRequired'), 'required');
  89. $form->addElement('hidden', 'post_time', time());
  90. $form->addElement('hidden', 'action', 'add_lp');
  91. $form->addButtonAdvancedSettings('advanced_params');
  92. $form->addElement('html', '<div id="advanced_params_options" style="display:none">');
  93. $items = learnpath::getCategoryFromCourseIntoSelect(api_get_course_int_id(), true);
  94. $form->addElement('select', 'category_id', get_lang('Category'), $items);
  95. // Start date
  96. $form->addElement('checkbox', 'activate_start_date_check', null, get_lang('EnableStartTime'), array('onclick' => 'activate_start_date()'));
  97. $form->addElement('html','<div id="start_date_div" style="display:block;">');
  98. $form->addElement('DatePicker', 'publicated_on', get_lang('PublicationDate'));
  99. $form->addElement('html','</div>');
  100. //End date
  101. $form->addElement('checkbox', 'activate_end_date_check', null, get_lang('EnableEndTime'), array('onclick' => 'activate_end_date()'));
  102. $form->addElement('html','<div id="end_date_div" style="display:none;">');
  103. $form->addElement('DatePicker', 'expired_on', get_lang('ExpirationDate'));
  104. $form->addElement('html','</div>');
  105. $form->addElement('html','</div>');
  106. $defaults['activate_start_date_check'] = 1;
  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();