lp_edit_item.php 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  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. $(document).on("ready", function() {
  23. CKEDITOR.on("instanceReady", function (e) {
  24. showTemplates("content_lp");
  25. });
  26. });
  27. </script>';
  28. /* Constants and variables */
  29. $is_allowed_to_edit = api_is_allowed_to_edit(null, true);
  30. $tbl_lp = Database::get_course_table(TABLE_LP_MAIN);
  31. $isStudentView = isset($_REQUEST['isStudentView']) ? intval($_REQUEST['isStudentView']) : null;
  32. $learnpath_id = (int) $_REQUEST['lp_id'];
  33. $submit = isset($_POST['submit_button']) ? $_POST['submit_button'] : null;
  34. /* MAIN CODE */
  35. // Using the resource linker as a tool for adding resources to the learning path.
  36. if ($action == 'add' && $type == 'learnpathitem') {
  37. $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>";
  38. }
  39. if ((!$is_allowed_to_edit) || ($isStudentView)) {
  40. error_log('New LP - User not authorized in lp_add_item.php');
  41. header('location:lp_controller.php?action=view&lp_id='.$learnpath_id);
  42. }
  43. // From here on, we are admin because of the previous condition, so don't check anymore.
  44. $course_id = api_get_course_int_id();
  45. $sql_query = "SELECT * FROM $tbl_lp WHERE c_id = $course_id AND id = $learnpath_id";
  46. $result = Database::query($sql_query);
  47. $therow = Database::fetch_array($result);
  48. /*
  49. Course admin section
  50. - all the functions not available for students - always available in this case (page only shown to admin)
  51. */
  52. /* SHOWING THE ADMIN TOOLS */
  53. if (isset($_SESSION['gradebook'])) {
  54. $gradebook = $_SESSION['gradebook'];
  55. }
  56. if (!empty($gradebook) && $gradebook == 'view') {
  57. $interbreadcrumb[] = array (
  58. 'url' => '../gradebook/'.$_SESSION['gradebook_dest'],
  59. 'name' => get_lang('ToolGradebook')
  60. );
  61. }
  62. $interbreadcrumb[] = array('url' => 'lp_controller.php?action=list', 'name' => get_lang('LearningPaths'));
  63. $interbreadcrumb[] = array('url' => api_get_self()."?action=build&lp_id=$learnpath_id", 'name' => stripslashes("{$therow['name']}"));
  64. $interbreadcrumb[] = array('url' => api_get_self()."?action=add_item&type=step&lp_id=$learnpath_id", 'name' => get_lang('NewStep'));
  65. // Theme calls.
  66. $show_learn_path = true;
  67. $lp_theme_css = $_SESSION['oLP']->get_theme();
  68. Display::display_header(get_lang('Edit'),'Path');
  69. $suredel = trim(get_lang('AreYouSureToDelete'));
  70. ?>
  71. <script>
  72. /* <![CDATA[ */
  73. function stripslashes(str) {
  74. str=str.replace(/\\'/g,'\'');
  75. str=str.replace(/\\"/g,'"');
  76. str=str.replace(/\\\\/g,'\\');
  77. str=str.replace(/\\0/g,'\0');
  78. return str;
  79. }
  80. function confirmation(name) {
  81. name=stripslashes(name);
  82. if (confirm("<?php echo $suredel; ?> " + name + " ?")) {
  83. return true;
  84. } else {
  85. return false;
  86. }
  87. }
  88. </script>
  89. <?php
  90. /* DISPLAY SECTION */
  91. echo $_SESSION['oLP']->build_action_menu();
  92. echo '<div class="row">';
  93. echo '<div class="col-md-3">';
  94. $path_item = isset($_GET['path_item']) ? $_GET['path_item'] : 0;
  95. $path_item = Database::escape_string($path_item);
  96. $tbl_doc = Database :: get_course_table(TABLE_DOCUMENT);
  97. $sql_doc = "SELECT path FROM " . $tbl_doc . " WHERE c_id = $course_id AND id = '". $path_item."' ";
  98. $res_doc = Database::query($sql_doc);
  99. $path_file = Database::result($res_doc, 0, 0);
  100. $path_parts = pathinfo($path_file);
  101. if (Database::num_rows($res_doc) > 0 && $path_parts['extension'] == 'html') {
  102. echo $_SESSION['oLP']->return_new_tree();
  103. // Show the template list
  104. echo '<div id="frmModel" class="lp-add-item"></div>';
  105. } else {
  106. echo $_SESSION['oLP']->return_new_tree();
  107. }
  108. echo '</div>';
  109. echo '<div class="col-md-9">';
  110. if (isset($is_success) && $is_success === true) {
  111. $msg = '<div class="lp_message" style="margin-bottom:10px;">';
  112. $msg .= 'The item has been edited.';
  113. $msg .= '</div>';
  114. echo $_SESSION['oLP']->display_item($_GET['id'], $msg);
  115. } else {
  116. echo $_SESSION['oLP']->display_edit_item($_GET['id']);
  117. }
  118. echo '</div>';
  119. echo '</div>';
  120. /* FOOTER */
  121. Display::display_footer();