lp_add_item.php 12 KB

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