lp_edit_item.php 5.0 KB

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