lp_edit_item.php 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. use ChamiloSession as Session;
  4. /**
  5. * This is a learning path creation and player tool in Chamilo - previously learnpath_handler.php.
  6. *
  7. * @author Patrick Cool
  8. * @author Denes Nagy
  9. * @author Roan Embrechts, refactoring and code cleaning
  10. * @author Yannick Warnier <ywarnier@beeznest.org> - cleaning and update for new SCORM tool
  11. * @author Julio Montoya - Improving the list of templates
  12. *
  13. * @package chamilo.learnpath
  14. */
  15. $this_section = SECTION_COURSES;
  16. api_protect_course_script();
  17. /** @var learnpath $learnPath */
  18. $learnPath = Session::read('oLP');
  19. /* Header and action code */
  20. $htmlHeadXtra[] = '<script>'.$learnPath->get_js_dropdown_array().'
  21. $(document).on("ready", function() {
  22. CKEDITOR.on("instanceReady", function (e) {
  23. showTemplates("content_lp");
  24. });
  25. });
  26. </script>';
  27. /* Constants and variables */
  28. $is_allowed_to_edit = api_is_allowed_to_edit(null, true);
  29. $tbl_lp = Database::get_course_table(TABLE_LP_MAIN);
  30. $isStudentView = isset($_REQUEST['isStudentView']) ? intval($_REQUEST['isStudentView']) : null;
  31. $learnpath_id = (int) $_REQUEST['lp_id'];
  32. $submit = isset($_POST['submit_button']) ? $_POST['submit_button'] : null;
  33. if (!$is_allowed_to_edit || $isStudentView) {
  34. error_log('New LP - User not authorized in lp_edit_item.php');
  35. header('location:lp_controller.php?action=view&lp_id='.$learnpath_id.'&'.api_get_cidreq());
  36. exit;
  37. }
  38. // From here on, we are admin because of the previous condition, so don't check anymore.
  39. $course_id = api_get_course_int_id();
  40. $sql = "SELECT * FROM $tbl_lp
  41. WHERE c_id = $course_id AND id = $learnpath_id";
  42. $result = Database::query($sql);
  43. $therow = Database::fetch_array($result);
  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 (api_is_in_gradebook()) {
  49. $interbreadcrumb[] = [
  50. 'url' => Category::getUrl(),
  51. 'name' => get_lang('ToolGradebook'),
  52. ];
  53. }
  54. $interbreadcrumb[] = [
  55. 'url' => 'lp_controller.php?action=list&'.api_get_cidreq(),
  56. 'name' => get_lang('LearningPaths'),
  57. ];
  58. $interbreadcrumb[] = [
  59. 'url' => api_get_self()."?action=build&lp_id=$learnpath_id&".api_get_cidreq(),
  60. 'name' => Security::remove_XSS($therow['name']),
  61. ];
  62. $interbreadcrumb[] = [
  63. 'url' => api_get_self()."?action=add_item&type=step&lp_id=$learnpath_id&".api_get_cidreq(),
  64. 'name' => get_lang('NewStep'),
  65. ];
  66. // Theme calls.
  67. $show_learn_path = true;
  68. $lp_theme_css = $learnPath->get_theme();
  69. Display::display_header(get_lang('Edit'), 'Path');
  70. $suredel = trim(get_lang('AreYouSureToDeleteJS'));
  71. ?>
  72. <script>
  73. function stripslashes(str) {
  74. str=str.replace(/\\'/g,'\'');
  75. str=str.replace(/\\"/g,'"');
  76. str=str.replace(/\\\\/g,'\\');
  77. str=str.replace(/\\0/g,'\0');
  78. return str;
  79. }
  80. function confirmation(name) {
  81. name=stripslashes(name);
  82. if (confirm("<?php echo $suredel; ?> " + name + " ?")) {
  83. return true;
  84. } else {
  85. return false;
  86. }
  87. }
  88. $(document).ready(function() {
  89. jQuery('.scrollbar-inner').scrollbar();
  90. expandColumnToogle('#hide_bar_template', {
  91. selector: '#lp_sidebar'
  92. }, {
  93. selector: '#doc_form'
  94. });
  95. $('.lp-btn-associate-forum').on('click', function (e) {
  96. var associate = confirm('<?php echo get_lang('ConfirmAssociateForumToLPItem'); ?>');
  97. if (!associate) {
  98. e.preventDefault();
  99. }
  100. });
  101. $('.lp-btn-dissociate-forum').on('click', function (e) {
  102. var dissociate = confirm('<?php echo get_lang('ConfirmDissociateForumToLPItem'); ?>');
  103. if (!dissociate) {
  104. e.preventDefault();
  105. }
  106. });
  107. });
  108. </script>
  109. <?php
  110. echo $learnPath->build_action_menu();
  111. echo '<div class="row">';
  112. echo '<div id="lp_sidebar" class="col-md-4">';
  113. $documentId = isset($_GET['path_item']) ? (int) $_GET['path_item'] : 0;
  114. $documentInfo = DocumentManager::get_document_data_by_id($documentId, api_get_course_id(), false, null, true);
  115. if (empty($documentInfo)) {
  116. // Try with iid
  117. $table = Database::get_course_table(TABLE_DOCUMENT);
  118. $sql = "SELECT path FROM $table
  119. WHERE c_id = $course_id AND iid = $documentId AND path NOT LIKE '%_DELETED_%'";
  120. $res_doc = Database::query($sql);
  121. $path_file = Database::result($res_doc, 0, 0);
  122. } else {
  123. $path_file = $documentInfo['path'];
  124. }
  125. $path_parts = pathinfo($path_file);
  126. if (!empty($path_file) && isset($path_parts['extension']) && $path_parts['extension'] == 'html') {
  127. echo $learnPath->return_new_tree();
  128. // Show the template list
  129. echo '<div id="frmModel" class="scrollbar-inner lp-add-item"></div>';
  130. } else {
  131. echo $learnPath->return_new_tree();
  132. }
  133. echo '</div>';
  134. echo '<div id="doc_form" class="col-md-8">';
  135. if (isset($is_success) && $is_success === true) {
  136. $msg = '<div class="lp_message" style="margin-bottom:10px;">';
  137. $msg .= 'The item has been edited.';
  138. $msg .= '</div>';
  139. echo $learnPath->display_item($_GET['id'], $msg);
  140. } else {
  141. $item = $learnPath->getItem($_GET['id']);
  142. echo $learnPath->display_edit_item($item->getIid());
  143. $finalItem = Session::read('finalItem');
  144. if ($finalItem) {
  145. echo '<script>$("#frmModel").remove()</script>';
  146. }
  147. Session::erase('finalItem');
  148. }
  149. echo '</div>';
  150. echo '</div>';
  151. Display::display_footer();