lp_edit_item.php 5.7 KB

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