lp_add_item.php 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. /**
  4. * This is a learning path creation and player tool in Chamilo - previously
  5. * learnpath_handler.php
  6. *
  7. * @author Patrick Cool
  8. * @author Denes Nagy
  9. * @author Roan Embrechts, refactoring and code cleaning
  10. * @author Yannick Warnier <ywarnier@beeznest.org> - cleaning and update
  11. * @author Julio Montoya - Improving the list of templates
  12. * @package chamilo.learnpath
  13. */
  14. $this_section = SECTION_COURSES;
  15. api_protect_course_script();
  16. include 'learnpath_functions.inc.php';
  17. include 'resourcelinker.inc.php';
  18. /** @var learnpath $learnPath */
  19. $learnPath = $_SESSION['oLP'];
  20. $htmlHeadXtra[] = '<script>'.
  21. $learnPath->get_js_dropdown_array() .
  22. 'function load_cbo(id){' ."\n" .
  23. 'if (!id) {return false;}'.
  24. 'var cbo = document.getElementById(\'previous\');' .
  25. 'for(var i = cbo.length - 1; i > 0; i--) {' .
  26. 'cbo.options[i] = null;' .
  27. '}' ."\n" .
  28. 'var k=0;' .
  29. 'for(var i = 1; i <= child_name[id].length; i++){' ."\n" .
  30. ' cbo.options[i] = new Option(child_name[id][i-1], child_value[id][i-1]);' ."\n" .
  31. ' k=i;' ."\n" .
  32. '}' ."\n" .
  33. //'if( typeof cbo != "undefined" ) {'."\n" .
  34. 'cbo.options[k].selected = true;'."\n" .
  35. //'}'."\n" .
  36. '}
  37. $(function() {
  38. if ($(\'#previous\')) {
  39. if(\'parent is\'+$(\'#idParent\').val()) {
  40. load_cbo($(\'#idParent\').val());
  41. }
  42. }
  43. $(\'.lp_resource_element\').click(function() {
  44. window.location.href = $(\'a\', this).attr(\'href\');
  45. });
  46. });
  47. $(document).on("ready", function() {
  48. CKEDITOR.on("instanceReady", function (e) {
  49. showTemplates("content_lp");
  50. });
  51. });
  52. </script>';
  53. /* Constants and variables */
  54. $isStudentView = isset($_REQUEST['isStudentView']) ? $_REQUEST['isStudentView'] : null;
  55. $learnpath_id = isset($_REQUEST['lp_id']) ? intval($_REQUEST['lp_id']) : null;
  56. $submit = isset($_POST['submit_button']) ? $_POST['submit_button'] : null;
  57. $type = isset($_GET['type']) ? $_GET['type'] : null;
  58. $action = isset($_GET['action']) ? $_GET['action'] : null;
  59. // Using the resource linker as a tool for adding resources to the learning path.
  60. if ($action == 'add' && $type == 'learnpathitem') {
  61. $htmlHeadXtra[] = "<script type='text/javascript'> window.location=\"../resourcelinker/resourcelinker.php?source_id=5&action=$action&learnpath_id=$learnpath_id&chapter_id=$chapter_id&originalresource=no\"; </script>";
  62. }
  63. if ((!$is_allowed_to_edit)) {
  64. error_log('New LP - User not authorized in lp_add_item.php');
  65. header('location:lp_controller.php?action=view&lp_id='.$learnpath_id);
  66. exit;
  67. }
  68. /* SHOWING THE ADMIN TOOLS */
  69. if (isset($_SESSION['gradebook'])) {
  70. $gradebook = $_SESSION['gradebook'];
  71. }
  72. if (!empty($gradebook) && $gradebook == 'view') {
  73. $interbreadcrumb[] = array (
  74. 'url' => '../gradebook/'.$_SESSION['gradebook_dest'],
  75. 'name' => get_lang('ToolGradebook')
  76. );
  77. }
  78. $interbreadcrumb[] = array('url' => 'lp_controller.php?action=list', 'name' => get_lang('LearningPaths'));
  79. $interbreadcrumb[] = array('url' => api_get_self()."?action=build&lp_id=$learnpath_id", 'name' => $learnPath->get_name());
  80. switch ($type) {
  81. case 'chapter':
  82. $interbreadcrumb[]= array('url' => 'lp_controller.php?action=add_item&type=step&lp_id='.$learnPath->get_id(), 'name' => get_lang('NewStep'));
  83. $interbreadcrumb[]= array('url' => '#', 'name' => get_lang('NewChapter'));
  84. break;
  85. case 'document':
  86. $interbreadcrumb[]= array('url' => 'lp_controller.php?action=add_item&type=step&lp_id='.$learnPath->get_id(), 'name' => get_lang('NewStep'));
  87. break;
  88. default:
  89. $interbreadcrumb[]= array('url' => '#', 'name' => get_lang('NewStep'));
  90. break;
  91. }
  92. if ($action == 'add_item' && $type == 'document' ) {
  93. $interbreadcrumb[]= array ('url' => '#', 'name' => get_lang('NewDocumentCreated'));
  94. }
  95. // Theme calls.
  96. $show_learn_path = true;
  97. $lp_theme_css = $learnPath->get_theme();
  98. Display::display_header(null, 'Path');
  99. $suredel = trim(get_lang('AreYouSureToDelete'));
  100. //@todo move this somewhere else css/fix.css
  101. ?>
  102. <style>
  103. #feedback { font-size: 1.4em; }
  104. #resExercise .ui-selecting { background: #FECA40; }
  105. #resExercise .ui-selected { background: #F39814; color: white; }
  106. #resExercise { list-style-type: none; margin: 0; padding: 0; width: 60%; }
  107. #resExercise li { margin: 3px; padding: 0.4em; font-size: 1.4em; height: 18px; }
  108. /* Fixes LP toolbar */
  109. #resource_tab li a {
  110. padding: 5px 4px;
  111. }
  112. </style>
  113. <script>
  114. function stripslashes(str) {
  115. str=str.replace(/\\'/g,'\'');
  116. str=str.replace(/\\"/g,'"');
  117. str=str.replace(/\\\\/g,'\\');
  118. str=str.replace(/\\0/g,'\0');
  119. return str;
  120. }
  121. function confirmation(name) {
  122. name=stripslashes(name);
  123. if (confirm("<?php echo $suredel; ?> " + name + " ?")) {
  124. return true;
  125. } else {
  126. return false;
  127. }
  128. }
  129. $(document).ready(function() {
  130. $("#hide_bar_template").click(function() {
  131. $("#lp_sidebar").toggleClass("hide");
  132. $("#hide_bar_template").toggleClass("hide_bar_template_not_hide");
  133. });
  134. });
  135. </script>
  136. <?php
  137. /* DISPLAY SECTION */
  138. echo $learnPath->build_action_menu();
  139. echo '<div class="row" style="overflow:hidden">';
  140. echo '<div id="lp_sidebar" class="col-md-3">';
  141. echo $learnPath->return_new_tree(null, true);
  142. $message = isset($_REQUEST['message']) ? $_REQUEST['message'] : null;
  143. // Show the template list.
  144. if ($type == 'document' && !isset($_GET['file'])) {
  145. // Show the template list.
  146. echo '<div id="frmModel" class="lp-add-item"></div>';
  147. }
  148. echo '</div>';
  149. // hide bar div
  150. if ($action == 'add_item' && $type == 'document' && !isset($_GET['file'])) {
  151. echo '<div class="col-md-1"><div id="hide_bar_template"></div></div> ';
  152. }
  153. echo '<div id="doc_form" class="col-md-8">';
  154. //@todo use session flash messages
  155. if (in_array($message, array('ItemUpdated'))) {
  156. echo Display::return_message(get_lang($message));
  157. }
  158. if (isset($new_item_id) && is_numeric($new_item_id)) {
  159. switch ($type) {
  160. case 'chapter':
  161. echo $learnPath->display_manipulate($new_item_id, $_POST['type']);
  162. Display::display_confirmation_message(get_lang('NewChapterCreated'));
  163. break;
  164. case TOOL_LINK:
  165. echo $learnPath->display_manipulate($new_item_id, $type);
  166. Display::display_confirmation_message(get_lang('NewLinksCreated'));
  167. break;
  168. case TOOL_STUDENTPUBLICATION:
  169. echo $learnPath->display_manipulate($new_item_id, $type);
  170. Display::display_confirmation_message(get_lang('NewStudentPublicationCreated'));
  171. break;
  172. case 'module':
  173. echo $learnPath->display_manipulate($new_item_id, $type);
  174. Display::display_confirmation_message(get_lang('NewModuleCreated'));
  175. break;
  176. case TOOL_QUIZ:
  177. echo $learnPath->display_manipulate($new_item_id, $type);
  178. Display::display_confirmation_message(get_lang('NewExerciseCreated'));
  179. break;
  180. case TOOL_DOCUMENT:
  181. Display::display_confirmation_message(get_lang('NewDocumentCreated'));
  182. echo $learnPath->display_item($new_item_id);
  183. break;
  184. case TOOL_FORUM:
  185. echo $learnPath->display_manipulate($new_item_id, $type);
  186. Display::display_confirmation_message(get_lang('NewForumCreated'));
  187. break;
  188. case 'thread':
  189. echo $learnPath->display_manipulate($new_item_id, $type);
  190. Display::display_confirmation_message(get_lang('NewThreadCreated'));
  191. break;
  192. }
  193. } else {
  194. switch ($type) {
  195. case 'chapter':
  196. echo $learnPath->display_item_form($type, get_lang('EnterDataNewChapter'));
  197. break;
  198. case 'module':
  199. echo $learnPath->display_item_form($type, get_lang('EnterDataNewModule'));
  200. break;
  201. case 'document':
  202. if (isset($_GET['file']) && is_numeric($_GET['file'])) {
  203. echo $learnPath->display_document_form('add', 0, $_GET['file']);
  204. } else {
  205. echo $learnPath->display_document_form('add', 0);
  206. }
  207. break;
  208. case 'hotpotatoes':
  209. echo $learnPath->display_hotpotatoes_form('add', 0, $_GET['file']);
  210. break;
  211. case 'quiz':
  212. echo Display::display_warning_message(get_lang('ExerciseCantBeEditedAfterAddingToTheLP'));
  213. echo $learnPath->display_quiz_form('add', 0, $_GET['file']);
  214. break;
  215. case 'forum':
  216. echo $learnPath->display_forum_form('add', 0, $_GET['forum_id']);
  217. break;
  218. case 'thread':
  219. echo $learnPath->display_thread_form('add', 0, $_GET['thread_id']);
  220. break;
  221. case 'link':
  222. echo $learnPath->display_link_form('add', 0, $_GET['file']);
  223. break;
  224. case 'student_publication':
  225. echo $learnPath->display_student_publication_form('add', 0, $_GET['file']);
  226. break;
  227. case 'step':
  228. $learnPath->display_resources();
  229. break;
  230. }
  231. }
  232. echo '</div>';
  233. echo '</div>';
  234. Display::display_footer();