lp_add_item.php 9.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326
  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. //@todo move this somewhere else css/fix.css
  115. ?>
  116. <style>
  117. #feedback { font-size: 1.4em; }
  118. #resExercise .ui-selecting { background: #FECA40; }
  119. #resExercise .ui-selected { background: #F39814; color: white; }
  120. #resExercise { list-style-type: none; margin: 0; padding: 0; width: 60%; }
  121. #resExercise li { margin: 3px; padding: 0.4em; font-size: 1.4em; height: 18px; }
  122. </style>
  123. <script>
  124. function stripslashes(str) {
  125. str=str.replace(/\\'/g,'\'');
  126. str=str.replace(/\\"/g,'"');
  127. str=str.replace(/\\\\/g,'\\');
  128. str=str.replace(/\\0/g,'\0');
  129. return str;
  130. }
  131. function confirmation(name) {
  132. name=stripslashes(name);
  133. if (confirm("<?php echo $suredel; ?> " + name + " ?")) {
  134. return true;
  135. } else {
  136. return false;
  137. }
  138. }
  139. $(function() {
  140. jQuery('.scrollbar-inner').scrollbar();
  141. $('#subtab ').on('click', 'a:first', function() {
  142. window.location.reload();
  143. });
  144. expandColumnToogle('#hide_bar_template', {
  145. selector: '#lp_sidebar'
  146. }, {
  147. selector: '#doc_form'
  148. });
  149. $('.lp-btn-associate-forum').on('click', function (e) {
  150. var associate = confirm('<?php echo get_lang('ConfirmAssociateForumToLPItem'); ?>');
  151. if (!associate) {
  152. e.preventDefault();
  153. }
  154. });
  155. $('.lp-btn-dissociate-forum').on('click', function (e) {
  156. var dissociate = confirm('<?php echo get_lang('ConfirmDissociateForumToLPItem'); ?>');
  157. if (!dissociate) {
  158. e.preventDefault();
  159. }
  160. });
  161. // hide the current template list for new documment until it tab clicked
  162. $('#frmModel').hide();
  163. });
  164. // document template for new document tab handler
  165. $(document).on('shown.bs.tab', 'a[data-toggle="tab"]', function (e) {
  166. var id = e.target.id;
  167. if (id == 'subtab2') {
  168. $('#frmModel').show();
  169. } else {
  170. $('#frmModel').hide();
  171. }
  172. })
  173. </script>
  174. <?php
  175. /* DISPLAY SECTION */
  176. echo $learnPath->build_action_menu();
  177. echo '<div class="row">';
  178. echo '<div id="lp_sidebar" class="col-md-4">';
  179. echo $learnPath->return_new_tree(null, true);
  180. $message = isset($_REQUEST['message']) ? $_REQUEST['message'] : null;
  181. // Show the template list.
  182. if (($type == 'document' || $type == 'step') && !isset($_GET['file'])) {
  183. // Show the template list.
  184. echo '<div id="frmModel" class="scrollbar-inner lp-add-item">';
  185. echo '</div>';
  186. }
  187. echo '</div>';
  188. echo '<div id="doc_form" class="col-md-8">';
  189. //@todo use session flash messages
  190. if (in_array($message, ['ItemUpdated'])) {
  191. echo Display::return_message(get_lang($message));
  192. }
  193. if (isset($new_item_id) && is_numeric($new_item_id)) {
  194. switch ($type) {
  195. case 'dir':
  196. echo $learnPath->display_manipulate($new_item_id, $_POST['type']);
  197. echo Display::return_message(
  198. get_lang('NewChapterCreated'),
  199. 'confirmation'
  200. );
  201. break;
  202. case TOOL_LINK:
  203. echo $learnPath->display_manipulate($new_item_id, $type);
  204. echo Display::return_message(
  205. get_lang('NewLinksCreated'),
  206. 'confirmation'
  207. );
  208. break;
  209. case TOOL_STUDENTPUBLICATION:
  210. echo $learnPath->display_manipulate($new_item_id, $type);
  211. echo Display::return_message(
  212. get_lang('NewStudentPublicationCreated'),
  213. 'confirmation'
  214. );
  215. break;
  216. case TOOL_QUIZ:
  217. echo $learnPath->display_manipulate($new_item_id, $type);
  218. echo Display::return_message(
  219. get_lang('NewExerciseCreated'),
  220. 'confirmation'
  221. );
  222. break;
  223. case TOOL_DOCUMENT:
  224. echo Display::return_message(
  225. get_lang('NewDocumentCreated'),
  226. 'confirmation'
  227. );
  228. echo $learnPath->display_item($new_item_id);
  229. break;
  230. case TOOL_FORUM:
  231. echo $learnPath->display_manipulate($new_item_id, $type);
  232. echo Display::return_message(
  233. get_lang('NewForumCreated'),
  234. 'confirmation'
  235. );
  236. break;
  237. case 'thread':
  238. echo $learnPath->display_manipulate($new_item_id, $type);
  239. echo Display::return_message(
  240. get_lang('NewThreadCreated'),
  241. 'confirmation'
  242. );
  243. break;
  244. }
  245. } else {
  246. switch ($type) {
  247. case 'dir':
  248. echo $learnPath->display_item_form(
  249. $type,
  250. get_lang('EnterDataNewChapter')
  251. );
  252. break;
  253. case TOOL_DOCUMENT:
  254. if (isset($_GET['file']) && is_numeric($_GET['file'])) {
  255. echo $learnPath->display_document_form('add', 0, $_GET['file']);
  256. } else {
  257. echo $learnPath->display_document_form('add', 0);
  258. }
  259. break;
  260. case 'hotpotatoes':
  261. echo $learnPath->display_hotpotatoes_form('add', 0, $_GET['file']);
  262. break;
  263. case TOOL_QUIZ:
  264. echo Display::return_message(
  265. get_lang('ExerciseCantBeEditedAfterAddingToTheLP'),
  266. 'warning'
  267. );
  268. echo $learnPath->display_quiz_form('add', 0, $_GET['file']);
  269. break;
  270. case TOOL_FORUM:
  271. echo $learnPath->display_forum_form('add', 0, $_GET['forum_id']);
  272. break;
  273. case 'thread':
  274. echo $learnPath->display_thread_form('add', 0, $_GET['thread_id']);
  275. break;
  276. case TOOL_LINK:
  277. echo $learnPath->display_link_form('add', 0, $_GET['file']);
  278. break;
  279. case TOOL_STUDENTPUBLICATION:
  280. $extra = isset($_GET['file']) ? $_GET['file'] : null;
  281. echo $learnPath->display_student_publication_form('add', 0, $extra);
  282. break;
  283. case 'step':
  284. $learnPath->display_resources();
  285. break;
  286. }
  287. }
  288. echo '</div>';
  289. echo '</div>';
  290. Display::display_footer();