lp_edit_item.php 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173
  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. $(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. header('location:lp_controller.php?action=view&lp_id='.$learnpath_id.'&'.api_get_cidreq());
  35. exit;
  36. }
  37. // From here on, we are admin because of the previous condition, so don't check anymore.
  38. $course_id = api_get_course_int_id();
  39. $sql = "SELECT * FROM $tbl_lp
  40. WHERE c_id = $course_id AND id = $learnpath_id";
  41. $result = Database::query($sql);
  42. $therow = Database::fetch_array($result);
  43. /*
  44. Course admin section
  45. - all the functions not available for students - always available in this case (page only shown to admin)
  46. */
  47. if (api_is_in_gradebook()) {
  48. $interbreadcrumb[] = [
  49. 'url' => Category::getUrl(),
  50. 'name' => get_lang('ToolGradebook'),
  51. ];
  52. }
  53. $interbreadcrumb[] = [
  54. 'url' => 'lp_controller.php?action=list&'.api_get_cidreq(),
  55. 'name' => get_lang('LearningPaths'),
  56. ];
  57. $interbreadcrumb[] = [
  58. 'url' => api_get_self()."?action=build&lp_id=$learnpath_id&".api_get_cidreq(),
  59. 'name' => Security::remove_XSS($therow['name']),
  60. ];
  61. $interbreadcrumb[] = [
  62. 'url' => api_get_self()."?action=add_item&type=step&lp_id=$learnpath_id&".api_get_cidreq(),
  63. 'name' => get_lang('NewStep'),
  64. ];
  65. // Theme calls.
  66. $show_learn_path = true;
  67. $lp_theme_css = $learnPath->get_theme();
  68. Display::display_header(get_lang('Edit'), 'Path');
  69. $suredel = trim(get_lang('AreYouSureToDeleteJS'));
  70. ?>
  71. <script>
  72. function stripslashes(str) {
  73. str=str.replace(/\\'/g,'\'');
  74. str=str.replace(/\\"/g,'"');
  75. str=str.replace(/\\\\/g,'\\');
  76. str=str.replace(/\\0/g,'\0');
  77. return str;
  78. }
  79. function confirmation(name) {
  80. name=stripslashes(name);
  81. if (confirm("<?php echo $suredel; ?> " + name + " ?")) {
  82. return true;
  83. } else {
  84. return false;
  85. }
  86. }
  87. $(function() {
  88. jQuery('.scrollbar-inner').scrollbar();
  89. expandColumnToogle('#hide_bar_template', {
  90. selector: '#lp_sidebar'
  91. }, {
  92. selector: '#doc_form'
  93. });
  94. $('.lp-btn-associate-forum').on('click', function (e) {
  95. var associate = confirm('<?php echo get_lang('ConfirmAssociateForumToLPItem'); ?>');
  96. if (!associate) {
  97. e.preventDefault();
  98. }
  99. });
  100. $('.lp-btn-dissociate-forum').on('click', function (e) {
  101. var dissociate = confirm('<?php echo get_lang('ConfirmDissociateForumToLPItem'); ?>');
  102. if (!dissociate) {
  103. e.preventDefault();
  104. }
  105. });
  106. });
  107. </script>
  108. <?php
  109. echo $learnPath->build_action_menu();
  110. echo '<div class="row">';
  111. echo '<div id="lp_sidebar" class="col-md-4">';
  112. $documentId = isset($_GET['path_item']) ? (int) $_GET['path_item'] : 0;
  113. $documentInfo = DocumentManager::get_document_data_by_id($documentId, api_get_course_id(), false, null, true);
  114. if (empty($documentInfo)) {
  115. // Try with iid
  116. $table = Database::get_course_table(TABLE_DOCUMENT);
  117. $sql = "SELECT path FROM $table
  118. WHERE c_id = $course_id AND iid = $documentId AND path NOT LIKE '%_DELETED_%'";
  119. $res_doc = Database::query($sql);
  120. $path_file = Database::result($res_doc, 0, 0);
  121. } else {
  122. $path_file = $documentInfo['path'];
  123. }
  124. $path_parts = pathinfo($path_file);
  125. if (!empty($path_file) && isset($path_parts['extension']) && $path_parts['extension'] == 'html') {
  126. echo $learnPath->return_new_tree();
  127. // Show the template list
  128. echo '<div id="frmModel" class="scrollbar-inner lp-add-item"></div>';
  129. } else {
  130. echo $learnPath->return_new_tree();
  131. }
  132. echo '</div>';
  133. echo '<div id="doc_form" class="col-md-8">';
  134. if (isset($is_success) && $is_success === true) {
  135. $msg = '<div class="lp_message" style="margin-bottom:10px;">';
  136. $msg .= 'The item has been edited.';
  137. $msg .= '</div>';
  138. echo $learnPath->display_item($_GET['id'], $msg);
  139. } else {
  140. $item = $learnPath->getItem($_GET['id']);
  141. echo $learnPath->display_edit_item($item->getIid());
  142. $finalItem = Session::read('finalItem');
  143. if ($finalItem) {
  144. echo '<script>$("#frmModel").remove()</script>';
  145. }
  146. Session::erase('finalItem');
  147. }
  148. echo '</div>';
  149. echo '</div>';
  150. Display::display_footer();