lp_add_item.php 12 KB

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