lp_add_item.php 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274
  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. //Loads LP item tabs
  44. $("#resource_tab").tabs();
  45. $(\'.lp_resource_element\').click(function() {
  46. window.location.href = $(\'a\', this).attr(\'href\');
  47. });
  48. });
  49. $(document).on("ready", function() {
  50. CKEDITOR.on("instanceReady", function (e) {
  51. showTemplates("content_lp");
  52. });
  53. });
  54. </script>';
  55. /* Constants and variables */
  56. $isStudentView = isset($_REQUEST['isStudentView']) ? $_REQUEST['isStudentView'] : null;
  57. $learnpath_id = isset($_REQUEST['lp_id']) ? intval($_REQUEST['lp_id']) : null;
  58. $submit = isset($_POST['submit_button']) ? $_POST['submit_button'] : null;
  59. $type = isset($_GET['type']) ? $_GET['type'] : null;
  60. $action = isset($_GET['action']) ? $_GET['action'] : null;
  61. // Using the resource linker as a tool for adding resources to the learning path.
  62. if ($action == 'add' && $type == 'learnpathitem') {
  63. $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>";
  64. }
  65. if ((!$is_allowed_to_edit)) {
  66. error_log('New LP - User not authorized in lp_add_item.php');
  67. header('location:lp_controller.php?action=view&lp_id='.$learnpath_id);
  68. exit;
  69. }
  70. /* SHOWING THE ADMIN TOOLS */
  71. if (isset($_SESSION['gradebook'])) {
  72. $gradebook = $_SESSION['gradebook'];
  73. }
  74. if (!empty($gradebook) && $gradebook == 'view') {
  75. $interbreadcrumb[] = array (
  76. 'url' => '../gradebook/'.$_SESSION['gradebook_dest'],
  77. 'name' => get_lang('ToolGradebook')
  78. );
  79. }
  80. $interbreadcrumb[] = array('url' => 'lp_controller.php?action=list', 'name' => get_lang('LearningPaths'));
  81. $interbreadcrumb[] = array('url' => api_get_self()."?action=build&lp_id=$learnpath_id", 'name' => $learnPath->get_name());
  82. switch ($type) {
  83. case 'chapter':
  84. $interbreadcrumb[]= array ('url' => 'lp_controller.php?action=add_item&type=step&lp_id='.$learnPath->get_id(), 'name' => get_lang('NewStep'));
  85. $interbreadcrumb[]= array ('url' => '#', 'name' => get_lang('NewChapter'));
  86. break;
  87. case 'document':
  88. $interbreadcrumb[]= array ('url' => 'lp_controller.php?action=add_item&type=step&lp_id='.$learnPath->get_id(), 'name' => get_lang('NewStep'));
  89. break;
  90. default:
  91. $interbreadcrumb[]= array ('url' => '#', 'name' => get_lang('NewStep'));
  92. break;
  93. }
  94. if ($action == 'add_item' && $type == 'document' ) {
  95. $interbreadcrumb[]= array ('url' => '#', 'name' => get_lang('NewDocumentCreated'));
  96. }
  97. // Theme calls.
  98. $show_learn_path = true;
  99. $lp_theme_css = $learnPath->get_theme();
  100. Display::display_header(null, 'Path');
  101. $suredel = trim(get_lang('AreYouSureToDelete'));
  102. //@todo move this somewhere else css/fix.css
  103. ?>
  104. <style>
  105. #feedback { font-size: 1.4em; }
  106. #resExercise .ui-selecting { background: #FECA40; }
  107. #resExercise .ui-selected { background: #F39814; color: white; }
  108. #resExercise { list-style-type: none; margin: 0; padding: 0; width: 60%; }
  109. #resExercise li { margin: 3px; padding: 0.4em; font-size: 1.4em; height: 18px; }
  110. /* Fixes LP toolbar */
  111. #resource_tab li a {
  112. padding: 5px 4px;
  113. }
  114. </style>
  115. <script>
  116. function stripslashes(str) {
  117. str=str.replace(/\\'/g,'\'');
  118. str=str.replace(/\\"/g,'"');
  119. str=str.replace(/\\\\/g,'\\');
  120. str=str.replace(/\\0/g,'\0');
  121. return str;
  122. }
  123. function confirmation(name) {
  124. name=stripslashes(name);
  125. if (confirm("<?php echo $suredel; ?> " + name + " ?")) {
  126. return true;
  127. } else {
  128. return false;
  129. }
  130. }
  131. $(document).ready(function() {
  132. $("#hide_bar_template").click(function() {
  133. $("#lp_sidebar").toggleClass("hide");
  134. $("#hide_bar_template").toggleClass("hide_bar_template_not_hide");
  135. });
  136. });
  137. </script>
  138. <?php
  139. /* DISPLAY SECTION */
  140. echo $learnPath->build_action_menu();
  141. echo '<div class="row" style="overflow:hidden">';
  142. echo '<div id="lp_sidebar" class="col-md-3">';
  143. echo $learnPath->return_new_tree(null, true);
  144. $message = isset($_REQUEST['message']) ? $_REQUEST['message'] : null;
  145. // Show the template list.
  146. if ($type == 'document' && !isset($_GET['file'])) {
  147. // Show the template list.
  148. echo '<div id="frmModel" class="lp-add-item"></div>';
  149. }
  150. echo '</div>';
  151. // hide bar div
  152. if ($action == 'add_item' && $type == 'document' && !isset($_GET['file'])) {
  153. echo '<div class="col-md-1"><div id="hide_bar_template"></div></div> ';
  154. }
  155. echo '<div id="doc_form" class="col-md-8">';
  156. //@todo use session flash messages
  157. if (in_array($message, array('ItemUpdated'))) {
  158. echo Display::return_message(get_lang($message));
  159. }
  160. if (isset($new_item_id) && is_numeric($new_item_id)) {
  161. switch ($type) {
  162. case 'chapter':
  163. echo $learnPath->display_manipulate($new_item_id, $_POST['type']);
  164. Display::display_confirmation_message(get_lang('NewChapterCreated'));
  165. break;
  166. case TOOL_LINK:
  167. echo $learnPath->display_manipulate($new_item_id, $type);
  168. Display::display_confirmation_message(get_lang('NewLinksCreated'));
  169. break;
  170. case TOOL_STUDENTPUBLICATION:
  171. echo $learnPath->display_manipulate($new_item_id, $type);
  172. Display::display_confirmation_message(get_lang('NewStudentPublicationCreated'));
  173. break;
  174. case 'module':
  175. echo $learnPath->display_manipulate($new_item_id, $type);
  176. Display::display_confirmation_message(get_lang('NewModuleCreated'));
  177. break;
  178. case TOOL_QUIZ:
  179. echo $learnPath->display_manipulate($new_item_id, $type);
  180. Display::display_confirmation_message(get_lang('NewExerciseCreated'));
  181. break;
  182. case TOOL_DOCUMENT:
  183. Display::display_confirmation_message(get_lang('NewDocumentCreated'));
  184. echo $learnPath->display_item($new_item_id);
  185. break;
  186. case TOOL_FORUM:
  187. echo $learnPath->display_manipulate($new_item_id, $type);
  188. Display::display_confirmation_message(get_lang('NewForumCreated'));
  189. break;
  190. case 'thread':
  191. echo $learnPath->display_manipulate($new_item_id, $type);
  192. Display::display_confirmation_message(get_lang('NewThreadCreated'));
  193. break;
  194. }
  195. } else {
  196. switch ($type) {
  197. case 'chapter':
  198. echo $learnPath->display_item_form($type, get_lang('EnterDataNewChapter'));
  199. break;
  200. case 'module':
  201. echo $learnPath->display_item_form($type, get_lang('EnterDataNewModule'));
  202. break;
  203. case 'document':
  204. if (isset($_GET['file']) && is_numeric($_GET['file'])) {
  205. echo $learnPath->display_document_form('add', 0, $_GET['file']);
  206. } else {
  207. echo $learnPath->display_document_form('add', 0);
  208. }
  209. break;
  210. case 'hotpotatoes':
  211. echo $learnPath->display_hotpotatoes_form('add', 0, $_GET['file']);
  212. break;
  213. case 'quiz':
  214. echo Display::display_warning_message(get_lang('ExerciseCantBeEditedAfterAddingToTheLP'));
  215. echo $learnPath->display_quiz_form('add', 0, $_GET['file']);
  216. break;
  217. case 'forum':
  218. echo $learnPath->display_forum_form('add', 0, $_GET['forum_id']);
  219. break;
  220. case 'thread':
  221. echo $learnPath->display_thread_form('add', 0, $_GET['thread_id']);
  222. break;
  223. case 'link':
  224. echo $learnPath->display_link_form('add', 0, $_GET['file']);
  225. break;
  226. case 'student_publication':
  227. echo $learnPath->display_student_publication_form('add', 0, $_GET['file']);
  228. break;
  229. case 'step':
  230. $learnPath->display_resources();
  231. break;
  232. }
  233. }
  234. echo '</div>';
  235. echo '</div>';
  236. Display::display_footer();