lp_add_item.php 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348
  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. $language_file = 'learnpath';
  21. $htmlHeadXtra[] = '
  22. <script>
  23. var temp = false;
  24. var load_default_template = '. ((isset($_POST['submit']) || empty($_SERVER['QUERY_STRING'])) ? 'false' : 'true' ) .';
  25. function FCKeditor_OnComplete( editorInstance ) {
  26. editorInstance.Events.AttachEvent( \'OnSelectionChange\', check_for_title) ;
  27. document.getElementById(\'frmModel\').innerHTML = "<iframe id=\'frame_template\' name=\'my_frame_template\' height=890px width=220px; frameborder=0 src=\''.api_get_path(WEB_LIBRARY_PATH).'fckeditor/editor/fckdialogframe.html \'>";
  28. loaded = true;
  29. }
  30. function check_for_title() {
  31. if (temp) {
  32. // This functions shows that you can interact directly with the editor area
  33. // DOM. In this way you have the freedom to do anything you want with it.
  34. // Get the editor instance that we want to interact with.
  35. var oEditor = FCKeditorAPI.GetInstance(\'content_lp\') ;
  36. // Get the Editor Area DOM (Document object).
  37. var oDOM = oEditor.EditorDocument ;
  38. var iLength ;
  39. var contentText ;
  40. var contentTextArray;
  41. var bestandsnaamNieuw = "";
  42. var bestandsnaamOud = "";
  43. // The are two diffent ways to get the text (without HTML markups).
  44. // It is browser specific.
  45. if( document.all ) // If Internet Explorer.
  46. {
  47. contentText = oDOM.body.innerText ;
  48. }
  49. else // If Gecko.
  50. {
  51. var r = oDOM.createRange() ;
  52. r.selectNodeContents( oDOM.body ) ;
  53. contentText = r.toString() ;
  54. }
  55. var index=contentText.indexOf("/*<![CDATA");
  56. contentText=contentText.substr(0,index);
  57. // Compose title if there is none
  58. contentTextArray = contentText.split(\' \') ;
  59. var x=0;
  60. for(x=0; (x<5 && x<contentTextArray.length); x++) {
  61. if(x < 4) {
  62. bestandsnaamNieuw += contentTextArray[x] + \' \';
  63. } else {
  64. bestandsnaamNieuw += contentTextArray[x];
  65. }
  66. }
  67. }
  68. temp=true;
  69. }
  70. function InnerDialogLoaded() {
  71. if (document.all) {
  72. // if is iexplorer
  73. var B=new window.frames.content_lp___Frame.FCKToolbarButton(\'Templates\',window.content_lp___Frame.FCKLang.Templates);
  74. } else {
  75. var B=new window.frames[0].FCKToolbarButton(\'Templates\',window.frames[0].FCKLang.Templates);
  76. }
  77. return B.ClickFrame();
  78. };'."\n".
  79. $learnPath->get_js_dropdown_array() .
  80. 'function load_cbo(id){' ."\n" .
  81. 'if (!id) {return false;}'.
  82. 'var cbo = document.getElementById(\'previous\');' .
  83. 'for(var i = cbo.length - 1; i > 0; i--) {' .
  84. 'cbo.options[i] = null;' .
  85. '}' ."\n" .
  86. 'var k=0;' .
  87. 'for(var i = 1; i <= child_name[id].length; i++){' ."\n" .
  88. ' cbo.options[i] = new Option(child_name[id][i-1], child_value[id][i-1]);' ."\n" .
  89. ' k=i;' ."\n" .
  90. '}' ."\n" .
  91. //'if( typeof cbo != "undefined" ) {'."\n" .
  92. 'cbo.options[k].selected = true;'."\n" .
  93. //'}'."\n" .
  94. '}
  95. $(function() {
  96. if ($(\'#previous\')) {
  97. if(\'parent is\'+$(\'#idParent\').val()) {
  98. load_cbo($(\'#idParent\').val());
  99. }
  100. }
  101. //Loads LP item tabs
  102. $("#resource_tab").tabs();
  103. $(\'.lp_resource_element\').click(function() {
  104. window.location.href = $(\'a\', this).attr(\'href\');
  105. });
  106. });
  107. </script>';
  108. /* Constants and variables */
  109. $isStudentView = isset($_REQUEST['isStudentView']) ? $_REQUEST['isStudentView'] : null;
  110. $learnpath_id = isset($_REQUEST['lp_id']) ? intval($_REQUEST['lp_id']) : null;
  111. $submit = isset($_POST['submit_button']) ? $_POST['submit_button'] : null;
  112. $type = isset($_GET['type']) ? $_GET['type'] : null;
  113. $action = isset($_GET['action']) ? $_GET['action'] : null;
  114. // Using the resource linker as a tool for adding resources to the learning path.
  115. if ($action == 'add' && $type == 'learnpathitem') {
  116. $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>";
  117. }
  118. if ((!$is_allowed_to_edit) || ($isStudentView)) {
  119. error_log('New LP - User not authorized in lp_add_item.php');
  120. header('location:lp_controller.php?action=view&lp_id='.$learnpath_id);
  121. exit;
  122. }
  123. /* SHOWING THE ADMIN TOOLS */
  124. if (isset($_SESSION['gradebook'])) {
  125. $gradebook = $_SESSION['gradebook'];
  126. }
  127. if (!empty($gradebook) && $gradebook == 'view') {
  128. $interbreadcrumb[] = array (
  129. 'url' => '../gradebook/'.$_SESSION['gradebook_dest'],
  130. 'name' => get_lang('ToolGradebook')
  131. );
  132. }
  133. $interbreadcrumb[] = array('url' => 'lp_controller.php?action=list', 'name' => get_lang('LearningPaths'));
  134. $interbreadcrumb[] = array('url' => api_get_self()."?action=build&lp_id=$learnpath_id", 'name' => $learnPath->get_name());
  135. switch ($type) {
  136. case 'chapter':
  137. $interbreadcrumb[]= array ('url' => 'lp_controller.php?action=add_item&type=step&lp_id='.$learnPath->get_id(), 'name' => get_lang('NewStep'));
  138. $interbreadcrumb[]= array ('url' => '#', 'name' => get_lang('NewChapter'));
  139. break;
  140. case 'document':
  141. $interbreadcrumb[]= array ('url' => 'lp_controller.php?action=add_item&type=step&lp_id='.$learnPath->get_id(), 'name' => get_lang('NewStep'));
  142. break;
  143. default:
  144. $interbreadcrumb[]= array ('url' => '#', 'name' => get_lang('NewStep'));
  145. break;
  146. }
  147. if ($action == 'add_item' && $type == 'document' ) {
  148. $interbreadcrumb[]= array ('url' => '#', 'name' => get_lang('NewDocumentCreated'));
  149. }
  150. // Theme calls.
  151. $show_learn_path = true;
  152. $lp_theme_css = $learnPath->get_theme();
  153. Display::display_header(null, 'Path');
  154. $suredel = trim(get_lang('AreYouSureToDelete'));
  155. //@todo move this somewhere else css/fix.css
  156. ?>
  157. <style>
  158. #feedback { font-size: 1.4em; }
  159. #resExercise .ui-selecting { background: #FECA40; }
  160. #resExercise .ui-selected { background: #F39814; color: white; }
  161. #resExercise { list-style-type: none; margin: 0; padding: 0; width: 60%; }
  162. #resExercise li { margin: 3px; padding: 0.4em; font-size: 1.4em; height: 18px; }
  163. /* Fixes LP toolbar */
  164. #resource_tab li a {
  165. padding: 5px 4px;
  166. }
  167. </style>
  168. <script>
  169. function stripslashes(str) {
  170. str=str.replace(/\\'/g,'\'');
  171. str=str.replace(/\\"/g,'"');
  172. str=str.replace(/\\\\/g,'\\');
  173. str=str.replace(/\\0/g,'\0');
  174. return str;
  175. }
  176. function confirmation(name) {
  177. name=stripslashes(name);
  178. if (confirm("<?php echo $suredel; ?> " + name + " ?")) {
  179. return true;
  180. } else {
  181. return false;
  182. }
  183. }
  184. $(document).ready(function() {
  185. $("#hide_bar_template").toggle(
  186. function() {
  187. $("#lp_sidebar").hide();
  188. $(this).css({'background-image' : 'url("../img/hide2.png")'})
  189. $("#doc_form").removeClass("span8");
  190. $("#doc_form").addClass("span11");
  191. },
  192. function() {
  193. $("#lp_sidebar").show();
  194. $("#doc_form").removeClass("span11");
  195. $("#doc_form").addClass("span8");
  196. $(this).css('background-image', 'url("../img/hide0.png")');
  197. }
  198. );
  199. });
  200. </script>
  201. <?php
  202. /* DISPLAY SECTION */
  203. echo $learnPath->build_action_menu();
  204. echo '<div class="row-fluid" style="overflow:hidden">';
  205. echo '<div id="lp_sidebar" class="span4">';
  206. echo $learnPath->return_new_tree(null, true);
  207. $message = isset($_REQUEST['message']) ? $_REQUEST['message'] : null;
  208. // Show the template list.
  209. if ($type == 'document' && !isset($_GET['file'])) {
  210. // Show the template list.
  211. echo '<div id="frmModel" style="display:block; height:890px;width:100px; position:relative;"></div>';
  212. }
  213. echo '</div>';
  214. // hide bar div
  215. if ($action == 'add_item' && $type == 'document' && !isset($_GET['file'])) {
  216. echo '<div id="hide_bar_template"></div>';
  217. }
  218. echo '<div id="doc_form" class="span8">';
  219. //@todo use session flash messages
  220. if (in_array($message, array('ItemUpdated'))) {
  221. echo Display::return_message(get_lang($message));
  222. }
  223. if (isset($new_item_id) && is_numeric($new_item_id)) {
  224. switch ($type) {
  225. case 'chapter':
  226. echo $learnPath->display_manipulate($new_item_id, $_POST['type']);
  227. Display::display_confirmation_message(get_lang('NewChapterCreated'));
  228. break;
  229. case TOOL_LINK:
  230. echo $learnPath->display_manipulate($new_item_id, $type);
  231. Display::display_confirmation_message(get_lang('NewLinksCreated'));
  232. break;
  233. case TOOL_STUDENTPUBLICATION:
  234. echo $learnPath->display_manipulate($new_item_id, $type);
  235. Display::display_confirmation_message(get_lang('NewStudentPublicationCreated'));
  236. break;
  237. case 'module':
  238. echo $learnPath->display_manipulate($new_item_id, $type);
  239. Display::display_confirmation_message(get_lang('NewModuleCreated'));
  240. break;
  241. case TOOL_QUIZ:
  242. echo $learnPath->display_manipulate($new_item_id, $type);
  243. Display::display_confirmation_message(get_lang('NewExerciseCreated'));
  244. break;
  245. case TOOL_DOCUMENT:
  246. Display::display_confirmation_message(get_lang('NewDocumentCreated'));
  247. echo $learnPath->display_item($new_item_id);
  248. break;
  249. case TOOL_FORUM:
  250. echo $learnPath->display_manipulate($new_item_id, $type);
  251. Display::display_confirmation_message(get_lang('NewForumCreated'));
  252. break;
  253. case 'thread':
  254. echo $learnPath->display_manipulate($new_item_id, $type);
  255. Display::display_confirmation_message(get_lang('NewThreadCreated'));
  256. break;
  257. }
  258. } else {
  259. switch ($type) {
  260. case 'chapter':
  261. echo $learnPath->display_item_form($type, get_lang('EnterDataNewChapter'));
  262. break;
  263. case 'module':
  264. echo $learnPath->display_item_form($type, get_lang('EnterDataNewModule'));
  265. break;
  266. case 'document':
  267. if (isset($_GET['file']) && is_numeric($_GET['file'])) {
  268. echo $learnPath->display_document_form('add', 0, $_GET['file']);
  269. } else {
  270. echo $learnPath->display_document_form('add', 0);
  271. }
  272. break;
  273. case 'hotpotatoes':
  274. echo $learnPath->display_hotpotatoes_form('add', 0, $_GET['file']);
  275. break;
  276. case 'quiz':
  277. echo Display::display_warning_message(get_lang('ExerciseCantBeEditedAfterAddingToTheLP'));
  278. echo $learnPath->display_quiz_form('add', 0, $_GET['file']);
  279. break;
  280. case 'forum':
  281. echo $learnPath->display_forum_form('add', 0, $_GET['forum_id']);
  282. break;
  283. case 'thread':
  284. echo $learnPath->display_thread_form('add', 0, $_GET['thread_id']);
  285. break;
  286. case 'link':
  287. echo $learnPath->display_link_form('add', 0, $_GET['file']);
  288. break;
  289. case 'student_publication':
  290. echo $learnPath->display_student_publication_form('add', 0, $_GET['file']);
  291. break;
  292. case 'step':
  293. $learnPath->display_resources();
  294. break;
  295. }
  296. }
  297. echo '</div>';
  298. echo '</div>';
  299. Display::display_footer();