lp_add_item.php 9.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309
  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. * @package chamilo.learnpath
  14. */
  15. $this_section = SECTION_COURSES;
  16. api_protect_course_script();
  17. $isStudentView = isset($_REQUEST['isStudentView']) ? $_REQUEST['isStudentView'] : null;
  18. $learnpath_id = isset($_REQUEST['lp_id']) ? intval($_REQUEST['lp_id']) : null;
  19. $submit = isset($_POST['submit_button']) ? $_POST['submit_button'] : null;
  20. $type = isset($_GET['type']) ? $_GET['type'] : null;
  21. $action = isset($_GET['action']) ? $_GET['action'] : null;
  22. $is_allowed_to_edit = api_is_allowed_to_edit(null, false);
  23. $listUrl = api_get_path(WEB_CODE_PATH).'lp/lp_controller.php?action=view&lp_id='.$learnpath_id.'&'.api_get_cidreq().'&isStudentView=true';
  24. if (!$is_allowed_to_edit) {
  25. header("Location: $listUrl");
  26. exit;
  27. }
  28. /** @var learnpath $learnPath */
  29. $learnPath = Session::read('oLP');
  30. if (empty($learnPath)) {
  31. api_not_allowed();
  32. }
  33. if ($learnPath->get_lp_session_id() != api_get_session_id()) {
  34. // You cannot edit an LP from a base course.
  35. header("Location: $listUrl");
  36. exit;
  37. }
  38. $htmlHeadXtra[] = '<script>'.
  39. $learnPath->get_js_dropdown_array()."
  40. function load_cbo(id) {
  41. if (!id) {
  42. return false;
  43. }
  44. var cbo = document.getElementById('previous');
  45. for(var i = cbo.length - 1; i > 0; i--) {
  46. cbo.options[i] = null;
  47. }
  48. var k=0;
  49. for(var i = 1; i <= child_name[id].length; i++){
  50. var option = new Option(child_name[id][i - 1], child_value[id][i - 1]);
  51. option.style.paddingLeft = '40px';
  52. cbo.options[i] = option;
  53. k = i;
  54. }
  55. cbo.options[k].selected = true;
  56. $('#previous').selectpicker('refresh');
  57. }
  58. $(function() {
  59. if ($('#previous')) {
  60. if('parent is'+$('#idParent').val()) {
  61. load_cbo($('#idParent').val());
  62. }
  63. }
  64. $('.lp_resource_element').click(function() {
  65. window.location.href = $('a', this).attr('href');
  66. });
  67. CKEDITOR.on('instanceReady', function (e) {
  68. showTemplates('content_lp');
  69. });
  70. });
  71. </script>";
  72. /* SHOWING THE ADMIN TOOLS */
  73. if (isset($_SESSION['gradebook'])) {
  74. $gradebook = $_SESSION['gradebook'];
  75. }
  76. if (!empty($gradebook) && $gradebook == 'view') {
  77. $interbreadcrumb[] = array(
  78. 'url' => '../gradebook/'.$_SESSION['gradebook_dest'],
  79. 'name' => get_lang('ToolGradebook')
  80. );
  81. }
  82. $htmlHeadXtra[] = api_get_jquery_libraries_js(array('jquery-ui', 'jquery-upload'));
  83. $interbreadcrumb[] = array(
  84. 'url' => 'lp_controller.php?action=list&'.api_get_cidreq(),
  85. 'name' => get_lang('LearningPaths'),
  86. );
  87. $interbreadcrumb[] = array(
  88. 'url' => api_get_self()."?action=build&lp_id=$learnpath_id&".api_get_cidreq(),
  89. 'name' => $learnPath->get_name(),
  90. );
  91. switch ($type) {
  92. case 'dir':
  93. $interbreadcrumb[] = array(
  94. 'url' => 'lp_controller.php?action=add_item&type=step&lp_id='.$learnPath->get_id().'&'.api_get_cidreq(),
  95. 'name' => get_lang('NewStep'),
  96. );
  97. $interbreadcrumb[] = array('url' => '#', 'name' => get_lang('NewChapter'));
  98. break;
  99. case 'document':
  100. $interbreadcrumb[] = array(
  101. 'url' => 'lp_controller.php?action=add_item&type=step&lp_id='.$learnPath->get_id().'&'.api_get_cidreq(),
  102. 'name' => get_lang('NewStep'),
  103. );
  104. break;
  105. default:
  106. $interbreadcrumb[] = array('url' => '#', 'name' => get_lang('NewStep'));
  107. break;
  108. }
  109. if ($action == 'add_item' && $type == 'document') {
  110. $interbreadcrumb[] = array('url' => '#', 'name' => get_lang('NewDocumentCreated'));
  111. }
  112. // Theme calls.
  113. $show_learn_path = true;
  114. $lp_theme_css = $learnPath->get_theme();
  115. Display::display_header(null, 'Path');
  116. $suredel = trim(get_lang('AreYouSureToDeleteJS'));
  117. //@todo move this somewhere else css/fix.css
  118. ?>
  119. <style>
  120. #feedback { font-size: 1.4em; }
  121. #resExercise .ui-selecting { background: #FECA40; }
  122. #resExercise .ui-selected { background: #F39814; color: white; }
  123. #resExercise { list-style-type: none; margin: 0; padding: 0; width: 60%; }
  124. #resExercise li { margin: 3px; padding: 0.4em; font-size: 1.4em; height: 18px; }
  125. </style>
  126. <script>
  127. function stripslashes(str) {
  128. str=str.replace(/\\'/g,'\'');
  129. str=str.replace(/\\"/g,'"');
  130. str=str.replace(/\\\\/g,'\\');
  131. str=str.replace(/\\0/g,'\0');
  132. return str;
  133. }
  134. function confirmation(name) {
  135. name=stripslashes(name);
  136. if (confirm("<?php echo $suredel; ?> " + name + " ?")) {
  137. return true;
  138. } else {
  139. return false;
  140. }
  141. }
  142. jQuery(document).ready(function(){
  143. jQuery('.scrollbar-inner').scrollbar();
  144. $('#subtab ').on('click', 'a:first', function() {
  145. window.location.reload();
  146. });
  147. });
  148. $(document).ready(function() {
  149. expandColumnToogle('#hide_bar_template', {
  150. selector: '#lp_sidebar'
  151. }, {
  152. selector: '#doc_form'
  153. });
  154. $('.lp-btn-associate-forum').on('click', function (e) {
  155. var associate = confirm('<?php echo get_lang('ConfirmAssociateForumToLPItem') ?>');
  156. if (!associate) {
  157. e.preventDefault();
  158. }
  159. });
  160. $('.lp-btn-dissociate-forum').on('click', function (e) {
  161. var dissociate = confirm('<?php echo get_lang('ConfirmDissociateForumToLPItem') ?>');
  162. if (!dissociate) {
  163. e.preventDefault();
  164. }
  165. });
  166. // hide the current template list for new documment until it tab clicked
  167. $('#frmModel').hide();
  168. });
  169. // document template for new document tab handler
  170. $(document).on( 'shown.bs.tab', 'a[data-toggle="tab"]', function (e) {
  171. var id = e.target.id;
  172. if (id == 'subtab2') {
  173. $('#frmModel').show();
  174. } else {
  175. $('#frmModel').hide();
  176. }
  177. })
  178. </script>
  179. <?php
  180. /* DISPLAY SECTION */
  181. echo $learnPath->build_action_menu();
  182. echo '<div class="row">';
  183. echo '<div id="lp_sidebar" class="col-md-4">';
  184. echo $learnPath->return_new_tree(null, true);
  185. $message = isset($_REQUEST['message']) ? $_REQUEST['message'] : null;
  186. // Show the template list.
  187. if (($type == 'document' || $type == 'step') && !isset($_GET['file'])) {
  188. // Show the template list.
  189. echo '<div id="frmModel" class="scrollbar-inner lp-add-item">';
  190. echo '</div>';
  191. }
  192. echo '</div>';
  193. echo '<div id="doc_form" class="col-md-8">';
  194. //@todo use session flash messages
  195. if (in_array($message, array('ItemUpdated'))) {
  196. echo Display::return_message(get_lang($message));
  197. }
  198. if (isset($new_item_id) && is_numeric($new_item_id)) {
  199. switch ($type) {
  200. case 'dir':
  201. echo $learnPath->display_manipulate($new_item_id, $_POST['type']);
  202. echo Display::return_message(get_lang('NewChapterCreated'), 'confirmation');
  203. break;
  204. case TOOL_LINK:
  205. echo $learnPath->display_manipulate($new_item_id, $type);
  206. echo Display::return_message(get_lang('NewLinksCreated'), 'confirmation');
  207. break;
  208. case TOOL_STUDENTPUBLICATION:
  209. echo $learnPath->display_manipulate($new_item_id, $type);
  210. echo Display::return_message(get_lang('NewStudentPublicationCreated'), 'confirmation');
  211. break;
  212. case TOOL_QUIZ:
  213. echo $learnPath->display_manipulate($new_item_id, $type);
  214. echo Display::return_message(get_lang('NewExerciseCreated'), 'confirmation');
  215. break;
  216. case TOOL_DOCUMENT:
  217. echo Display::return_message(get_lang('NewDocumentCreated'), 'confirmation');
  218. echo $learnPath->display_item($new_item_id);
  219. break;
  220. case TOOL_FORUM:
  221. echo $learnPath->display_manipulate($new_item_id, $type);
  222. echo Display::return_message(get_lang('NewForumCreated'), 'confirmation');
  223. break;
  224. case 'thread':
  225. echo $learnPath->display_manipulate($new_item_id, $type);
  226. echo Display::return_message(get_lang('NewThreadCreated'), 'confirmation');
  227. break;
  228. }
  229. } else {
  230. switch ($type) {
  231. case 'dir':
  232. echo $learnPath->display_item_form($type, get_lang('EnterDataNewChapter'));
  233. break;
  234. case TOOL_DOCUMENT:
  235. if (isset($_GET['file']) && is_numeric($_GET['file'])) {
  236. echo $learnPath->display_document_form('add', 0, $_GET['file']);
  237. } else {
  238. echo $learnPath->display_document_form('add', 0);
  239. }
  240. break;
  241. case 'hotpotatoes':
  242. echo $learnPath->display_hotpotatoes_form('add', 0, $_GET['file']);
  243. break;
  244. case TOOL_QUIZ:
  245. echo Display::return_message(get_lang('ExerciseCantBeEditedAfterAddingToTheLP'), 'warning');
  246. echo $learnPath->display_quiz_form('add', 0, $_GET['file']);
  247. break;
  248. case TOOL_FORUM:
  249. echo $learnPath->display_forum_form('add', 0, $_GET['forum_id']);
  250. break;
  251. case 'thread':
  252. echo $learnPath->display_thread_form('add', 0, $_GET['thread_id']);
  253. break;
  254. case TOOL_LINK:
  255. echo $learnPath->display_link_form('add', 0, $_GET['file']);
  256. break;
  257. case TOOL_STUDENTPUBLICATION:
  258. $extra = isset($_GET['file']) ? $_GET['file'] : null;
  259. echo $learnPath->display_student_publication_form('add', 0, $extra);
  260. break;
  261. case 'step':
  262. $learnPath->display_resources();
  263. break;
  264. }
  265. }
  266. echo '</div>';
  267. echo '</div>';
  268. Display::display_footer();