lp_edit_item.php 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196
  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 - Improving the list of templates
  11. * @package chamilo.learnpath
  12. */
  13. $this_section = SECTION_COURSES;
  14. api_protect_course_script();
  15. /* Libraries */
  16. include 'learnpath_functions.inc.php';
  17. /* Header and action code */
  18. $learnpath = learnpath::getCurrentLpFromSession();
  19. $htmlHeadXtra[] = '
  20. <script>'.$learnpath->get_js_dropdown_array().
  21. "
  22. function load_cbo(id) {
  23. if (!id) {
  24. return false;
  25. }
  26. var cbo = document.getElementById('previous');
  27. for(var i = cbo.length - 1; i > 0; i--) {
  28. cbo.options[i] = null;
  29. }
  30. var k=0;
  31. for(var i = 1; i <= child_name[id].length; i++){
  32. var option = new Option(child_name[id][i - 1], child_value[id][i - 1]);
  33. option.style.paddingLeft = '20px';
  34. cbo.options[i] = option;
  35. k = i;
  36. }
  37. cbo.options[k].selected = true;
  38. $('#previous').selectpicker('refresh');
  39. }
  40. " .
  41. '
  42. $(document).on("ready", function() {
  43. CKEDITOR.on("instanceReady", function (e) {
  44. showTemplates("content_lp");
  45. });
  46. });
  47. </script>';
  48. /* Constants and variables */
  49. $is_allowed_to_edit = api_is_allowed_to_edit(null, true);
  50. $tbl_lp = Database::get_course_table(TABLE_LP_MAIN);
  51. $isStudentView = isset($_REQUEST['isStudentView']) ? intval($_REQUEST['isStudentView']) : null;
  52. $learnpath_id = (int) $_REQUEST['lp_id'];
  53. $submit = isset($_POST['submit_button']) ? $_POST['submit_button'] : null;
  54. /* MAIN CODE */
  55. if ((!$is_allowed_to_edit) || ($isStudentView)) {
  56. error_log('New LP - User not authorized in lp_add_item.php');
  57. header('location:lp_controller.php?action=view&lp_id='.$learnpath_id);
  58. }
  59. // From here on, we are admin because of the previous condition, so don't check anymore.
  60. $course_id = api_get_course_int_id();
  61. $sql = "SELECT * FROM $tbl_lp
  62. WHERE c_id = $course_id AND id = $learnpath_id";
  63. $result = Database::query($sql);
  64. $therow = Database::fetch_array($result);
  65. /*
  66. Course admin section
  67. - all the functions not available for students - always available in this case (page only shown to admin)
  68. */
  69. /* SHOWING THE ADMIN TOOLS */
  70. if (api_is_in_gradebook()) {
  71. $interbreadcrumb[]= array(
  72. 'url' => api_get_path(WEB_CODE_PATH).'gradebook/index.php?'.api_get_cidreq(),
  73. 'name' => get_lang('ToolGradebook')
  74. );
  75. }
  76. $interbreadcrumb[] = array(
  77. 'url' => 'lp_controller.php?action=list&'.api_get_cidreq(),
  78. 'name' => get_lang('LearningPaths'),
  79. );
  80. $interbreadcrumb[] = array(
  81. 'url' => api_get_self()."?action=build&lp_id=$learnpath_id&".api_get_cidreq(),
  82. 'name' => Security::remove_XSS("{$therow['name']}"),
  83. );
  84. $interbreadcrumb[] = array(
  85. 'url' => api_get_self()."?action=add_item&type=step&lp_id=$learnpath_id&".api_get_cidreq(),
  86. 'name' => get_lang('NewStep'),
  87. );
  88. // Theme calls.
  89. $show_learn_path = true;
  90. $lp_theme_css = $learnpath->get_theme();
  91. Display::display_header(get_lang('Edit'),'Path');
  92. $suredel = trim(get_lang('AreYouSureToDeleteJS'));
  93. ?>
  94. <script>
  95. /* <![CDATA[ */
  96. function stripslashes(str) {
  97. str=str.replace(/\\'/g,'\'');
  98. str=str.replace(/\\"/g,'"');
  99. str=str.replace(/\\\\/g,'\\');
  100. str=str.replace(/\\0/g,'\0');
  101. return str;
  102. }
  103. function confirmation(name) {
  104. name=stripslashes(name);
  105. if (confirm("<?php echo $suredel; ?> " + name + " ?")) {
  106. return true;
  107. } else {
  108. return false;
  109. }
  110. }
  111. $(document).ready(function() {
  112. $('.lp-btn-associate-forum').on('click', function (e) {
  113. var associate = confirm('<?php echo get_lang('ConfirmAssociateForumToLPItem') ?>');
  114. if (!associate) {
  115. e.preventDefault();
  116. }
  117. });
  118. $('.lp-btn-dissociate-forum').on('click', function (e) {
  119. var dissociate = confirm('<?php echo get_lang('ConfirmDissociateForumToLPItem') ?>');
  120. if (!dissociate) {
  121. e.preventDefault();
  122. }
  123. });
  124. });
  125. </script>
  126. <?php
  127. /* DISPLAY SECTION */
  128. echo $learnpath->build_action_menu();
  129. echo '<div class="row">';
  130. echo '<div class="col-md-3">';
  131. $path_item = isset($_GET['path_item']) ? $_GET['path_item'] : 0;
  132. $path_item = Database::escape_string($path_item);
  133. $tbl_doc = Database :: get_course_table(TABLE_DOCUMENT);
  134. $sql_doc = "SELECT path FROM " . $tbl_doc . "
  135. WHERE c_id = $course_id AND id = '". $path_item."' ";
  136. $res_doc = Database::query($sql_doc);
  137. $path_file = Database::result($res_doc, 0, 0);
  138. $path_parts = pathinfo($path_file);
  139. if (Database::num_rows($res_doc) > 0 && $path_parts['extension'] == 'html') {
  140. echo $learnpath->return_new_tree();
  141. // Show the template list
  142. echo '<div id="frmModel" class="lp-add-item"></div>';
  143. } else {
  144. echo $learnpath->return_new_tree();
  145. }
  146. echo '</div>';
  147. echo '<div class="col-md-9">';
  148. if (isset($is_success) && $is_success === true) {
  149. $msg = '<div class="lp_message" style="margin-bottom:10px;">';
  150. $msg .= 'The item has been edited.';
  151. $msg .= '</div>';
  152. echo $learnpath->display_item($_GET['id'], $msg);
  153. } else {
  154. echo $learnpath->display_edit_item($_GET['id']);
  155. }
  156. echo '</div>';
  157. echo '</div>';
  158. $learnpath->updateCurrentLpFromSession();