lp_add_item.php 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. /**
  4. * This is a learning path creation and player tool in Chamilo - previously
  5. * learnpath_handler.php
  6. *
  7. * @author Patrick Cool
  8. * @author Denes Nagy
  9. * @author Roan Embrechts, refactoring and code cleaning
  10. * @author Yannick Warnier <ywarnier@beeznest.org> - cleaning and update
  11. * @author Julio Montoya - Improving the list of templates
  12. * @package chamilo.learnpath
  13. */
  14. $this_section = SECTION_COURSES;
  15. api_protect_course_script();
  16. include 'learnpath_functions.inc.php';
  17. include 'resourcelinker.inc.php';
  18. /** @var learnpath $learnPath */
  19. $learnPath = $_SESSION['oLP'];
  20. $htmlHeadXtra[] = '<script>'.
  21. $learnPath->get_js_dropdown_array() .
  22. "
  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. " .
  42. '
  43. $(function() {
  44. if ($(\'#previous\')) {
  45. if(\'parent is\'+$(\'#idParent\').val()) {
  46. load_cbo($(\'#idParent\').val());
  47. }
  48. }
  49. $(\'.lp_resource_element\').click(function() {
  50. window.location.href = $(\'a\', this).attr(\'href\');
  51. });
  52. });
  53. $(document).on("ready", function() {
  54. CKEDITOR.on("instanceReady", function (e) {
  55. showTemplates("content_lp");
  56. });
  57. });
  58. </script>';
  59. /* Constants and variables */
  60. $isStudentView = isset($_REQUEST['isStudentView']) ? $_REQUEST['isStudentView'] : null;
  61. $learnpath_id = isset($_REQUEST['lp_id']) ? intval($_REQUEST['lp_id']) : null;
  62. $submit = isset($_POST['submit_button']) ? $_POST['submit_button'] : null;
  63. $type = isset($_GET['type']) ? $_GET['type'] : null;
  64. $action = isset($_GET['action']) ? $_GET['action'] : null;
  65. // Using the resource linker as a tool for adding resources to the learning path.
  66. if ($action == 'add' && $type == 'learnpathitem') {
  67. $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>";
  68. }
  69. if ((!$is_allowed_to_edit)) {
  70. error_log('New LP - User not authorized in lp_add_item.php');
  71. header('location:lp_controller.php?action=view&lp_id='.$learnpath_id);
  72. exit;
  73. }
  74. /* SHOWING THE ADMIN TOOLS */
  75. if (isset($_SESSION['gradebook'])) {
  76. $gradebook = $_SESSION['gradebook'];
  77. }
  78. if (!empty($gradebook) && $gradebook == 'view') {
  79. $interbreadcrumb[] = array (
  80. 'url' => '../gradebook/'.$_SESSION['gradebook_dest'],
  81. 'name' => get_lang('ToolGradebook')
  82. );
  83. }
  84. $interbreadcrumb[] = array('url' => 'lp_controller.php?action=list', 'name' => get_lang('LearningPaths'));
  85. $interbreadcrumb[] = array('url' => api_get_self()."?action=build&lp_id=$learnpath_id", 'name' => $learnPath->get_name());
  86. switch ($type) {
  87. case 'chapter':
  88. $interbreadcrumb[]= array('url' => 'lp_controller.php?action=add_item&type=step&lp_id='.$learnPath->get_id(), 'name' => get_lang('NewStep'));
  89. $interbreadcrumb[]= array('url' => '#', 'name' => get_lang('NewChapter'));
  90. break;
  91. case 'document':
  92. $interbreadcrumb[]= array('url' => 'lp_controller.php?action=add_item&type=step&lp_id='.$learnPath->get_id(), 'name' => get_lang('NewStep'));
  93. break;
  94. default:
  95. $interbreadcrumb[]= array('url' => '#', 'name' => get_lang('NewStep'));
  96. break;
  97. }
  98. if ($action == 'add_item' && $type == 'document' ) {
  99. $interbreadcrumb[]= array ('url' => '#', 'name' => get_lang('NewDocumentCreated'));
  100. }
  101. // Theme calls.
  102. $show_learn_path = true;
  103. $lp_theme_css = $learnPath->get_theme();
  104. Display::display_header(null, 'Path');
  105. $suredel = trim(get_lang('AreYouSureToDeleteJS'));
  106. //@todo move this somewhere else css/fix.css
  107. ?>
  108. <style>
  109. #feedback { font-size: 1.4em; }
  110. #resExercise .ui-selecting { background: #FECA40; }
  111. #resExercise .ui-selected { background: #F39814; color: white; }
  112. #resExercise { list-style-type: none; margin: 0; padding: 0; width: 60%; }
  113. #resExercise li { margin: 3px; padding: 0.4em; font-size: 1.4em; height: 18px; }
  114. /* Fixes LP toolbar */
  115. #resource_tab li a {
  116. padding: 5px 4px;
  117. }
  118. </style>
  119. <script>
  120. function stripslashes(str) {
  121. str=str.replace(/\\'/g,'\'');
  122. str=str.replace(/\\"/g,'"');
  123. str=str.replace(/\\\\/g,'\\');
  124. str=str.replace(/\\0/g,'\0');
  125. return str;
  126. }
  127. function confirmation(name) {
  128. name=stripslashes(name);
  129. if (confirm("<?php echo $suredel; ?> " + name + " ?")) {
  130. return true;
  131. } else {
  132. return false;
  133. }
  134. }
  135. jQuery(document).ready(function(){
  136. jQuery('.scrollbar-inner').scrollbar();
  137. });
  138. $(document).ready(function() {
  139. $("#doc_form").removeClass( "col-md-8" ).addClass( "col-md-7" );
  140. $("#hide_bar_template").click(function() {
  141. $("#lp_sidebar").toggleClass("hide");
  142. if ($('#doc_form').is('.col-md-7')) {
  143. $('#doc_form').removeClass('col-md-7');
  144. $('#doc_form').addClass('col-md-11');
  145. } else {
  146. $('#doc_form').removeClass('col-md-11');
  147. $('#doc_form').addClass('col-md-7');
  148. }
  149. $("#hide_bar_template").toggleClass("hide_bar_template_not_hide");
  150. });
  151. $('.lp-btn-associate-forum').on('click', function (e) {
  152. var associate = confirm('<?php echo get_lang('ConfirmAssociateForumToLPItem') ?>');
  153. if (!associate) {
  154. e.preventDefault();
  155. }
  156. });
  157. $('.lp-btn-dissociate-forum').on('click', function (e) {
  158. var dissociate = confirm('<?php echo get_lang('ConfirmDissociateForumToLPItem') ?>');
  159. if (!dissociate) {
  160. e.preventDefault();
  161. }
  162. });
  163. });
  164. </script>
  165. <?php
  166. /* DISPLAY SECTION */
  167. echo $learnPath->build_action_menu();
  168. echo '<div class="row" style="overflow:hidden">';
  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' && !isset($_GET['file'])) {
  174. // Show the template list.
  175. echo '<div id="frmModel" class="scrollbar-inner lp-add-item"></div>';
  176. }
  177. echo '</div>';
  178. // hide bar div
  179. if ($action == 'add_item' && $type == 'document' && !isset($_GET['file'])) {
  180. echo '<div class="col-md-1"><div id="hide_bar_template"></div></div> ';
  181. }
  182. echo '<div id="doc_form" class="col-md-8">';
  183. //@todo use session flash messages
  184. if (in_array($message, array('ItemUpdated'))) {
  185. echo Display::return_message(get_lang($message));
  186. }
  187. if (isset($new_item_id) && is_numeric($new_item_id)) {
  188. switch ($type) {
  189. case 'chapter':
  190. echo $learnPath->display_manipulate($new_item_id, $_POST['type']);
  191. Display::display_confirmation_message(get_lang('NewChapterCreated'));
  192. break;
  193. case TOOL_LINK:
  194. echo $learnPath->display_manipulate($new_item_id, $type);
  195. Display::display_confirmation_message(get_lang('NewLinksCreated'));
  196. break;
  197. case TOOL_STUDENTPUBLICATION:
  198. echo $learnPath->display_manipulate($new_item_id, $type);
  199. Display::display_confirmation_message(get_lang('NewStudentPublicationCreated'));
  200. break;
  201. case 'module':
  202. echo $learnPath->display_manipulate($new_item_id, $type);
  203. Display::display_confirmation_message(get_lang('NewModuleCreated'));
  204. break;
  205. case TOOL_QUIZ:
  206. echo $learnPath->display_manipulate($new_item_id, $type);
  207. Display::display_confirmation_message(get_lang('NewExerciseCreated'));
  208. break;
  209. case TOOL_DOCUMENT:
  210. Display::display_confirmation_message(get_lang('NewDocumentCreated'));
  211. echo $learnPath->display_item($new_item_id);
  212. break;
  213. case TOOL_FORUM:
  214. echo $learnPath->display_manipulate($new_item_id, $type);
  215. Display::display_confirmation_message(get_lang('NewForumCreated'));
  216. break;
  217. case 'thread':
  218. echo $learnPath->display_manipulate($new_item_id, $type);
  219. Display::display_confirmation_message(get_lang('NewThreadCreated'));
  220. break;
  221. }
  222. } else {
  223. switch ($type) {
  224. case 'chapter':
  225. echo $learnPath->display_item_form($type, get_lang('EnterDataNewChapter'));
  226. break;
  227. case 'module':
  228. echo $learnPath->display_item_form($type, get_lang('EnterDataNewModule'));
  229. break;
  230. case TOOL_DOCUMENT:
  231. if (isset($_GET['file']) && is_numeric($_GET['file'])) {
  232. echo $learnPath->display_document_form('add', 0, $_GET['file']);
  233. } else {
  234. echo $learnPath->display_document_form('add', 0);
  235. }
  236. break;
  237. case 'hotpotatoes':
  238. echo $learnPath->display_hotpotatoes_form('add', 0, $_GET['file']);
  239. break;
  240. case TOOL_QUIZ:
  241. echo Display::display_warning_message(get_lang('ExerciseCantBeEditedAfterAddingToTheLP'));
  242. echo $learnPath->display_quiz_form('add', 0, $_GET['file']);
  243. break;
  244. case TOOL_FORUM:
  245. echo $learnPath->display_forum_form('add', 0, $_GET['forum_id']);
  246. break;
  247. case 'thread':
  248. echo $learnPath->display_thread_form('add', 0, $_GET['thread_id']);
  249. break;
  250. case TOOL_LINK:
  251. echo $learnPath->display_link_form('add', 0, $_GET['file']);
  252. break;
  253. case TOOL_STUDENTPUBLICATION:
  254. $extra = isset($_GET['file']) ? $_GET['file'] : null;
  255. echo $learnPath->display_student_publication_form('add', 0, $extra);
  256. break;
  257. case 'step':
  258. $learnPath->display_resources();
  259. break;
  260. }
  261. }
  262. echo '</div>';
  263. echo '</div>';
  264. Display::display_footer();