lp_add_item.php 9.6 KB

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