lp_edit_item.php 6.2 KB

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