lp_add_item.php 9.2 KB

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