lp_add.php 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  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. /**
  15. * Code
  16. */
  17. $this_section = SECTION_COURSES;
  18. api_protect_course_script();
  19. /* Libraries */
  20. require 'learnpath_functions.inc.php';
  21. //include '../resourcelinker/resourcelinker.inc.php';
  22. require 'resourcelinker.inc.php';
  23. // Rewrite the language file, sadly overwritten by resourcelinker.inc.php.
  24. // Name of the language file that needs to be included.
  25. $language_file = 'learnpath';
  26. /* Header and action code */
  27. $currentstyle = api_get_setting('stylesheets');
  28. $showImg = Display::return_icon('div_show.gif');
  29. $hideImg = Display::return_icon('div_hide.gif');
  30. $htmlHeadXtra[] = '<script>
  31. function setFocus(){
  32. $("#learnpath_title").focus();
  33. }
  34. $(document).ready(function () {
  35. setFocus();
  36. });
  37. function advanced_parameters() {
  38. if(document.getElementById(\'options\').style.display == \'none\') {
  39. document.getElementById(\'options\').style.display = \'block\';
  40. document.getElementById(\'img_plus_and_minus\').innerHTML=\'&nbsp;'.$hideImg.'&nbsp;'.get_lang('AdvancedParameters').'\';
  41. } else {
  42. document.getElementById(\'options\').style.display = \'none\';
  43. document.getElementById(\'img_plus_and_minus\').innerHTML=\'&nbsp;'.$showImg.'&nbsp;'.get_lang('AdvancedParameters').'\';
  44. }
  45. }
  46. function activate_start_date() {
  47. if(document.getElementById(\'start_date_div\').style.display == \'none\') {
  48. document.getElementById(\'start_date_div\').style.display = \'block\';
  49. } else {
  50. document.getElementById(\'start_date_div\').style.display = \'none\';
  51. }
  52. }
  53. function activate_end_date() {
  54. if(document.getElementById(\'end_date_div\').style.display == \'none\') {
  55. document.getElementById(\'end_date_div\').style.display = \'block\';
  56. } else {
  57. document.getElementById(\'end_date_div\').style.display = \'none\';
  58. }
  59. }
  60. </script>';
  61. /* Constants and variables */
  62. $is_allowed_to_edit = api_is_allowed_to_edit(null, true);
  63. $isStudentView = isset($_REQUEST['isStudentView']) ? $_REQUEST['isStudentView'] : null;
  64. $learnpath_id = isset($_REQUEST['lp_id']) ? $_REQUEST['lp_id'] : null;
  65. /* MAIN CODE */
  66. // Using the resource linker as a tool for adding resources to the learning path.
  67. if ($action == 'add' && $type == 'learnpathitem') {
  68. $htmlHeadXtra[] = "<script type='text/javascript'> window.location=\"../resourcelinker/resourcelinker.php?source_id=5&action=$action&learnpath_id=$learnpath_id&chapter_id=$chapter_id&originalresource=no\"; </script>";
  69. }
  70. if ((!$is_allowed_to_edit) || ($isStudentView)) {
  71. //error_log('New LP - User not authorized in lp_add.php');
  72. header('location:lp_controller.php?action=view&lp_id='.$learnpath_id);
  73. }
  74. // From here on, we are admin because of the previous condition, so don't check anymore.
  75. /*
  76. Course admin section
  77. - all the functions not available for students - always available in this case (page only shown to admin)
  78. */
  79. if (isset($_SESSION['gradebook'])){
  80. $gradebook = $_SESSION['gradebook'];
  81. }
  82. if (!empty($gradebook) && $gradebook=='view') {
  83. $interbreadcrumb[]= array (
  84. 'url' => '../gradebook/'.$_SESSION['gradebook_dest'],
  85. 'name' => get_lang('ToolGradebook')
  86. );
  87. }
  88. $interbreadcrumb[] = array('url' => 'lp_controller.php?action=list', 'name' => get_lang('LearningPaths'));
  89. Display::display_header(get_lang('LearnpathAddLearnpath'), 'Path');
  90. echo '<div class="actions">';
  91. echo '<a href="lp_controller.php?cidReq='.$_course['sysCode'].'">'.Display::return_icon('back.png', get_lang('ReturnToLearningPaths'),'',ICON_SIZE_MEDIUM).'</a>';
  92. echo '</div>';
  93. Display::display_normal_message(get_lang('AddLpIntro'), false);
  94. if ($_POST AND empty($_REQUEST['lp_name'])) {
  95. Display::display_error_message(get_lang('FormHasErrorsPleaseComplete'), false);
  96. }
  97. $form = new FormValidator('lp_add', 'post', 'lp_controller.php');
  98. // Form title
  99. $form->addElement('header', null, get_lang('AddLpToStart'));
  100. // Title
  101. $form->addElement('text', 'lp_name', api_ucfirst(get_lang('LPName')), array('class' => 'span6'));
  102. $form->applyFilter('lp_name', 'html_filter');
  103. $form->addRule('lp_name', get_lang('ThisFieldIsRequired'), 'required');
  104. $form->addElement('hidden', 'post_time', time());
  105. $form->addElement('hidden', 'action', 'add_lp');
  106. $advanced = '<a href="javascript://" onclick=" return advanced_parameters()"><span id="img_plus_and_minus"><div style="vertical-align:top;" >&nbsp;'.$showImg.'&nbsp;'.get_lang('AdvancedParameters').'</div></span></a>';
  107. $form -> addElement('advanced_settings',$advanced);
  108. $form -> addElement('html','<div id="options" style="display:none">');
  109. $items = learnpath::get_category_from_course_into_select(api_get_course_int_id());
  110. if (!empty($items)) {
  111. $items = array_merge(array(get_lang('SelectACategory')), $items);
  112. }
  113. $form->addElement('select', 'category_id', get_lang('Category'), $items);
  114. //Start date
  115. $form->addElement('checkbox', 'activate_start_date_check', null, get_lang('EnableStartTime'), array('onclick' => 'activate_start_date()'));
  116. $form->addElement('html','<div id="start_date_div" style="display:block;">');
  117. $form->addElement('datepicker', 'publicated_on', get_lang('PublicationDate'), array('form_name'=>'lp_add'), 5);
  118. $form->addElement('html','</div>');
  119. //End date
  120. $form->addElement('checkbox', 'activate_end_date_check', null, get_lang('EnableEndTime'), array('onclick' => 'activate_end_date()'));
  121. $form->addElement('html','<div id="end_date_div" style="display:none;">');
  122. $form->addElement('datepicker', 'expired_on', get_lang('ExpirationDate'), array('form_name'=>'lp_add'), 5);
  123. $form->addElement('html','</div>');
  124. $form->addElement('html','</div>');
  125. $defaults['activate_start_date_check'] = 1;
  126. $defaults['publicated_on'] = date('Y-m-d 08:00:00');
  127. $defaults['expired_on'] = date('Y-m-d 08:00:00',time()+84600);
  128. $form->setDefaults($defaults);
  129. $form->addElement('style_submit_button', 'Submit',get_lang('CreateLearningPath'),'class="save"');
  130. $form->display();
  131. // Footer
  132. Display::display_footer();