lp_add_item.php 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. use ChamiloSession as Session;
  4. /**
  5. * This is a learning path creation and player tool in Chamilo - previously
  6. * learnpath_handler.php.
  7. *
  8. * @author Patrick Cool
  9. * @author Denes Nagy
  10. * @author Roan Embrechts, refactoring and code cleaning
  11. * @author Yannick Warnier <ywarnier@beeznest.org> - cleaning and update
  12. * @author Julio Montoya - Improving the list of templates
  13. *
  14. * @package chamilo.learnpath
  15. */
  16. $this_section = SECTION_COURSES;
  17. api_protect_course_script();
  18. $isStudentView = isset($_REQUEST['isStudentView']) ? $_REQUEST['isStudentView'] : null;
  19. $lpId = isset($_REQUEST['lp_id']) ? (int) $_REQUEST['lp_id'] : 0;
  20. $submit = isset($_POST['submit_button']) ? $_POST['submit_button'] : null;
  21. $type = isset($_GET['type']) ? $_GET['type'] : null;
  22. $action = isset($_GET['action']) ? $_GET['action'] : null;
  23. $is_allowed_to_edit = api_is_allowed_to_edit(null, false);
  24. $listUrl = api_get_path(WEB_CODE_PATH).'lp/lp_controller.php?action=view&lp_id='.$lpId.'&'.api_get_cidreq().'&isStudentView=true';
  25. if (!$is_allowed_to_edit) {
  26. header("Location: $listUrl");
  27. exit;
  28. }
  29. /** @var learnpath $learnPath */
  30. $learnPath = Session::read('oLP');
  31. if (empty($learnPath)) {
  32. api_not_allowed();
  33. }
  34. if ($learnPath->get_lp_session_id() != api_get_session_id()) {
  35. // You cannot edit an LP from a base course.
  36. header("Location: $listUrl");
  37. exit;
  38. }
  39. $htmlHeadXtra[] = '<script>'.$learnPath->get_js_dropdown_array()."
  40. function load_cbo(id, previousId) {
  41. if (!id) {
  42. return false;
  43. }
  44. previousId = previousId || 'previous';
  45. var cbo = document.getElementById(previousId);
  46. for (var i = cbo.length - 1; i > 0; i--) {
  47. cbo.options[i] = null;
  48. }
  49. var k=0;
  50. for (var i = 1; i <= child_name[id].length; i++){
  51. var option = new Option(child_name[id][i - 1], child_value[id][i - 1]);
  52. option.style.paddingLeft = '40px';
  53. cbo.options[i] = option;
  54. k = i;
  55. }
  56. cbo.options[k].selected = true;
  57. $('#' + previousId).selectpicker('refresh');
  58. }
  59. $(function() {
  60. if ($('#previous')) {
  61. if('parent is'+$('#idParent').val()) {
  62. load_cbo($('#idParent').val());
  63. }
  64. }
  65. $('.lp_resource_element').click(function() {
  66. window.location.href = $('a', this).attr('href');
  67. });
  68. CKEDITOR.on('instanceReady', function (e) {
  69. showTemplates('content_lp');
  70. });
  71. });
  72. </script>";
  73. if (api_is_in_gradebook()) {
  74. $interbreadcrumb[] = [
  75. 'url' => Category::getUrl(),
  76. 'name' => get_lang('ToolGradebook'),
  77. ];
  78. }
  79. $htmlHeadXtra[] = api_get_jquery_libraries_js(['jquery-ui', 'jquery-upload']);
  80. $interbreadcrumb[] = [
  81. 'url' => 'lp_controller.php?action=list&'.api_get_cidreq(),
  82. 'name' => get_lang('LearningPaths'),
  83. ];
  84. $interbreadcrumb[] = [
  85. 'url' => api_get_self()."?action=build&lp_id=$lpId&".api_get_cidreq(),
  86. 'name' => $learnPath->getNameNoTags(),
  87. ];
  88. switch ($type) {
  89. case 'dir':
  90. $interbreadcrumb[] = [
  91. 'url' => 'lp_controller.php?action=add_item&type=step&lp_id='.$learnPath->get_id().'&'.api_get_cidreq(),
  92. 'name' => get_lang('NewStep'),
  93. ];
  94. $interbreadcrumb[] = ['url' => '#', 'name' => get_lang('NewChapter')];
  95. break;
  96. case 'document':
  97. $interbreadcrumb[] = [
  98. 'url' => 'lp_controller.php?action=add_item&type=step&lp_id='.$learnPath->get_id().'&'.api_get_cidreq(),
  99. 'name' => get_lang('NewStep'),
  100. ];
  101. break;
  102. default:
  103. $interbreadcrumb[] = ['url' => '#', 'name' => get_lang('NewStep')];
  104. break;
  105. }
  106. if ($action === 'add_item' && $type === 'document') {
  107. $interbreadcrumb[] = ['url' => '#', 'name' => get_lang('NewDocumentCreated')];
  108. }
  109. // Theme calls.
  110. $show_learn_path = true;
  111. $lp_theme_css = $learnPath->get_theme();
  112. Display::display_header(null, 'Path');
  113. $suredel = trim(get_lang('AreYouSureToDeleteJS'));
  114. ?>
  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. $(function() {
  132. jQuery('.scrollbar-inner').scrollbar();
  133. $('#subtab ').on('click', 'a:first', function() {
  134. window.location.reload();
  135. });
  136. expandColumnToogle('#hide_bar_template', {
  137. selector: '#lp_sidebar'
  138. }, {
  139. selector: '#doc_form'
  140. });
  141. $('.lp-btn-associate-forum').on('click', function (e) {
  142. var associate = confirm('<?php echo get_lang('ConfirmAssociateForumToLPItem'); ?>');
  143. if (!associate) {
  144. e.preventDefault();
  145. }
  146. });
  147. $('.lp-btn-dissociate-forum').on('click', function (e) {
  148. var dissociate = confirm('<?php echo get_lang('ConfirmDissociateForumToLPItem'); ?>');
  149. if (!dissociate) {
  150. e.preventDefault();
  151. }
  152. });
  153. // hide the current template list for new documment until it tab clicked
  154. $('#frmModel').hide();
  155. });
  156. // document template for new document tab handler
  157. $(document).on('shown.bs.tab', 'a[data-toggle="tab"]', function (e) {
  158. var id = e.target.id;
  159. if (id == 'subtab2') {
  160. $('#frmModel').show();
  161. } else {
  162. $('#frmModel').hide();
  163. }
  164. })
  165. </script>
  166. <?php
  167. echo $learnPath->build_action_menu();
  168. echo '<div class="row">';
  169. echo '<div id="lp_sidebar" class="col-md-4">';
  170. echo $learnPath->return_new_tree(null, true);
  171. $message = isset($_REQUEST['message']) ? $_REQUEST['message'] : null;
  172. // Show the template list.
  173. if (($type == 'document' || $type == 'step') && !isset($_GET['file'])) {
  174. // Show the template list.
  175. echo '<div id="frmModel" class="scrollbar-inner lp-add-item">';
  176. echo '</div>';
  177. }
  178. echo '</div>';
  179. echo '<div id="doc_form" class="col-md-8">';
  180. //@todo use session flash messages
  181. if (in_array($message, ['ItemUpdated'])) {
  182. echo Display::return_message(get_lang($message));
  183. }
  184. if (isset($new_item_id) && is_numeric($new_item_id)) {
  185. switch ($type) {
  186. case 'dir':
  187. echo $learnPath->display_manipulate($new_item_id, $_POST['type']);
  188. echo Display::return_message(
  189. get_lang('NewChapterCreated'),
  190. 'confirmation'
  191. );
  192. break;
  193. case TOOL_LINK:
  194. echo $learnPath->display_manipulate($new_item_id, $type);
  195. echo Display::return_message(
  196. get_lang('NewLinksCreated'),
  197. 'confirmation'
  198. );
  199. break;
  200. case TOOL_STUDENTPUBLICATION:
  201. echo $learnPath->display_manipulate($new_item_id, $type);
  202. echo Display::return_message(
  203. get_lang('NewStudentPublicationCreated'),
  204. 'confirmation'
  205. );
  206. break;
  207. case TOOL_QUIZ:
  208. echo $learnPath->display_manipulate($new_item_id, $type);
  209. echo Display::return_message(
  210. get_lang('NewExerciseCreated'),
  211. 'confirmation'
  212. );
  213. break;
  214. case TOOL_DOCUMENT:
  215. echo Display::return_message(
  216. get_lang('NewDocumentCreated'),
  217. 'confirmation'
  218. );
  219. echo $learnPath->display_item($new_item_id);
  220. break;
  221. case TOOL_FORUM:
  222. echo $learnPath->display_manipulate($new_item_id, $type);
  223. echo Display::return_message(
  224. get_lang('NewForumCreated'),
  225. 'confirmation'
  226. );
  227. break;
  228. case 'thread':
  229. echo $learnPath->display_manipulate($new_item_id, $type);
  230. echo Display::return_message(
  231. get_lang('NewThreadCreated'),
  232. 'confirmation'
  233. );
  234. break;
  235. }
  236. } else {
  237. switch ($type) {
  238. case 'dir':
  239. echo $learnPath->display_item_form(
  240. $type,
  241. get_lang('EnterDataNewChapter')
  242. );
  243. break;
  244. case TOOL_DOCUMENT:
  245. if (isset($_GET['file']) && is_numeric($_GET['file'])) {
  246. echo $learnPath->display_document_form('add', 0, $_GET['file']);
  247. } else {
  248. echo $learnPath->display_document_form('add', 0);
  249. }
  250. break;
  251. case 'hotpotatoes':
  252. echo $learnPath->display_hotpotatoes_form('add', 0, $_GET['file']);
  253. break;
  254. case TOOL_QUIZ:
  255. echo Display::return_message(
  256. get_lang('ExerciseCantBeEditedAfterAddingToTheLP'),
  257. 'warning'
  258. );
  259. echo $learnPath->display_quiz_form('add', 0, $_GET['file']);
  260. break;
  261. case TOOL_FORUM:
  262. echo $learnPath->display_forum_form('add', 0, $_GET['forum_id']);
  263. break;
  264. case 'thread':
  265. echo $learnPath->display_thread_form('add', 0, $_GET['thread_id']);
  266. break;
  267. case TOOL_LINK:
  268. echo $learnPath->display_link_form('add', 0, $_GET['file']);
  269. break;
  270. case TOOL_STUDENTPUBLICATION:
  271. $extra = isset($_GET['file']) ? $_GET['file'] : null;
  272. echo $learnPath->display_student_publication_form('add', 0, $extra);
  273. break;
  274. case 'step':
  275. $learnPath->display_resources();
  276. break;
  277. }
  278. }
  279. echo '</div>';
  280. echo '</div>';
  281. Display::display_footer();