lp_edit_item.php 6.8 KB

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