lp_build.php 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  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. * @package chamilo.learnpath
  11. */
  12. $_SESSION['whereami'] = 'lp/build';
  13. $this_section = SECTION_COURSES;
  14. api_protect_course_script();
  15. /* Constants and variables */
  16. $is_allowed_to_edit = api_is_allowed_to_edit(null, true);
  17. $tbl_lp = Database::get_course_table(TABLE_LP_MAIN);
  18. $tbl_lp_item = Database::get_course_table(TABLE_LP_ITEM);
  19. $tbl_lp_view = Database::get_course_table(TABLE_LP_VIEW);
  20. $isStudentView = (int) $_REQUEST['isStudentView'];
  21. $learnpath_id = (int) $_REQUEST['lp_id'];
  22. $submit = $_POST['submit_button'];
  23. /* MAIN CODE */
  24. if ((!$is_allowed_to_edit) || ($isStudentView)) {
  25. error_log('New LP - User not authorized in lp_build.php');
  26. header('location:lp_controller.php?action=view&lp_id='.$learnpath_id);
  27. }
  28. // From here on, we are admin because of the previous condition, so don't check anymore.
  29. /* The learnpath has been just created, go get the last id. */
  30. $is_new = false;
  31. $course_id = api_get_course_int_id();
  32. if ($learnpath_id == 0) {
  33. $is_new = true;
  34. $sql = "SELECT id FROM $tbl_lp
  35. WHERE c_id = $course_id
  36. ORDER BY id DESC LIMIT 0, 1";
  37. $result = Database::query($sql);
  38. $row = Database::fetch_array($result);
  39. $learnpath_id = $row['id'];
  40. }
  41. $sql_query = "SELECT * FROM $tbl_lp WHERE c_id = $course_id AND id = $learnpath_id";
  42. $result = Database::query($sql_query);
  43. $therow = Database::fetch_array($result);
  44. /* SHOWING THE ADMIN TOOLS */
  45. if (!empty($_GET['gradebook']) && $_GET['gradebook'] == 'view') {
  46. $_SESSION['gradebook'] = Security::remove_XSS($_GET['gradebook']);
  47. $gradebook = $_SESSION['gradebook'];
  48. } elseif (empty($_GET['gradebook'])) {
  49. unset($_SESSION['gradebook']);
  50. $gradebook = '';
  51. }
  52. if (!empty($gradebook) && $gradebook == 'view') {
  53. $interbreadcrumb[] = array(
  54. 'url' => '../gradebook/'.$_SESSION['gradebook_dest'],
  55. 'name' => get_lang('ToolGradebook')
  56. );
  57. }
  58. $interbreadcrumb[] = array('url' => 'lp_controller.php?action=list', 'name' => get_lang('LearningPaths'));
  59. $interbreadcrumb[] = array('url' => '#', "name" => $therow['name']);
  60. // Theme calls.
  61. $lp_theme_css = $_SESSION['oLP']->get_theme();
  62. $show_learn_path = true;
  63. Display::display_header('', 'Path');
  64. $suredel = trim(get_lang('AreYouSureToDeleteJS'));
  65. ?>
  66. <script>
  67. /* <![CDATA[ */
  68. function stripslashes(str) {
  69. str=str.replace(/\\'/g,'\'');
  70. str=str.replace(/\\"/g,'"');
  71. str=str.replace(/\\\\/g,'\\');
  72. str=str.replace(/\\0/g,'\0');
  73. return str;
  74. }
  75. function confirmation(name) {
  76. name=stripslashes(name);
  77. if (confirm("<?php echo $suredel; ?> " + name + " ?")) {
  78. return true;
  79. } else {
  80. return false;
  81. }
  82. }
  83. </script>
  84. <?php
  85. /* DISPLAY SECTION */
  86. echo $_SESSION['oLP']->build_action_menu();
  87. echo '<div class="row">';
  88. echo '<div class="col-md-4">';
  89. // Build the tree with the menu items in it.
  90. echo $_SESSION['oLP']->return_new_tree();
  91. echo '</div>';
  92. echo '<div class="col-md-8">';
  93. if (isset($is_success) && $is_success === true) {
  94. echo Display::return_message(get_lang('ItemRemoved'), 'confirmation');
  95. } else {
  96. if ($is_new) {
  97. echo Display::return_message(get_lang('LearnpathAdded'), 'normal', false);
  98. }
  99. // Display::addFlash(Display::return_message(get_lang('LPCreatedAddChapterStep'), 'normal', false));
  100. $gradebook = isset($_GET['gradebook']) ? Security::remove_XSS($_GET['gradebook']) : null;
  101. echo Display::page_subheader(get_lang('LearnPathAddedTitle'));
  102. echo '<ul id="lp_overview" class="thumbnails">';
  103. echo show_block(
  104. 'lp_controller.php?'.api_get_cidreq().'&gradebook='.$gradebook.'&action=add_item&type=step&lp_id='.$_SESSION['oLP']->lp_id,
  105. get_lang("NewStep"),
  106. get_lang('NewStepComment'),
  107. 'tools.png'
  108. );
  109. echo show_block(
  110. 'lp_controller.php?'.api_get_cidreq().'&gradebook='.$gradebook.'&action=view&lp_id='.$_SESSION['oLP']->lp_id,
  111. get_lang("Display"),
  112. get_lang('DisplayComment'),
  113. 'view.png'
  114. );
  115. echo '</ul>';
  116. }
  117. echo '</div>';
  118. echo '</div>';
  119. function show_block($link, $title, $subtitle, $icon) {
  120. $html = '<li class="col-md-4">';
  121. $html .= '<div class="thumbnail">';
  122. $html .= '<a href="'.$link.'" title="'.$title.'">';
  123. $html .= Display::return_icon($icon, $title, array(), ICON_SIZE_BIG);
  124. $html .= '</a>';
  125. $html .= '<div class="caption">';
  126. $html .= '<strong>'.$title.'</strong></a> '.$subtitle;
  127. $html .= '</div>';
  128. $html .= '</div>';
  129. $html .= '</li>';
  130. return $html;
  131. }
  132. /* FOOTER */
  133. Display::display_footer();