lp_add_item.php 9.7 KB

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