lp_add.php 6.7 KB

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