lp_add_item.php 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351
  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. ?>
  160. <style>
  161. #feedback { font-size: 1.4em; }
  162. #resExercise .ui-selecting { background: #FECA40; }
  163. #resExercise .ui-selected { background: #F39814; color: white; }
  164. #resExercise { list-style-type: none; margin: 0; padding: 0; width: 60%; }
  165. #resExercise li { margin: 3px; padding: 0.4em; font-size: 1.4em; height: 18px; }
  166. /* Fixes LP toolbar */
  167. #resource_tab li a {
  168. padding: 5px 4px;
  169. }
  170. </style>
  171. <script>
  172. function stripslashes(str) {
  173. str=str.replace(/\\'/g,'\'');
  174. str=str.replace(/\\"/g,'"');
  175. str=str.replace(/\\\\/g,'\\');
  176. str=str.replace(/\\0/g,'\0');
  177. return str;
  178. }
  179. function confirmation(name) {
  180. name=stripslashes(name);
  181. if (confirm("<?php echo $suredel; ?> " + name + " ?")) {
  182. return true;
  183. } else {
  184. return false;
  185. }
  186. }
  187. $(document).ready(function() {
  188. $("#hide_bar_template").toggle(
  189. function() {
  190. $("#lp_sidebar").hide();
  191. $(this).css({'background-image' : 'url("../img/hide2.png")'})
  192. $("#doc_form").removeClass("span8");
  193. $("#doc_form").addClass("span11");
  194. },
  195. function() {
  196. $("#lp_sidebar").show();
  197. $("#doc_form").removeClass("span11");
  198. $("#doc_form").addClass("span8");
  199. $(this).css('background-image', 'url("../img/hide0.png")');
  200. }
  201. );
  202. });
  203. </script>
  204. <?php
  205. /* DISPLAY SECTION */
  206. echo $_SESSION['oLP']->build_action_menu();
  207. echo '<div class="row-fluid" style="overflow:hidden">';
  208. echo '<div id="lp_sidebar" class="span4">';
  209. echo $_SESSION['oLP']->return_new_tree(null, true);
  210. $message = isset($_REQUEST['message']) ? $_REQUEST['message'] : null;
  211. // Show the template list.
  212. if ($type == 'document' && !isset($_GET['file'])) {
  213. // Show the template list.
  214. echo '<div id="frmModel" style="display:block; height:890px;width:100px; position:relative;"></div>';
  215. }
  216. echo '</div>';
  217. //hide bar div
  218. if ($action == 'add_item' && $type == 'document' && !isset($_GET['file'])) {
  219. echo '<div id="hide_bar_template"></div>';
  220. }
  221. echo '<div id="doc_form" class="span8">';
  222. //@todo use session flash messages
  223. if (in_array($message, array('ItemUpdated'))) {
  224. echo Display::return_message(get_lang($message));
  225. }
  226. if (isset($new_item_id) && is_numeric($new_item_id)) {
  227. switch ($type) {
  228. case 'chapter':
  229. echo $_SESSION['oLP']->display_manipulate($new_item_id, $_POST['type']);
  230. Display::display_confirmation_message(get_lang('NewChapterCreated'));
  231. break;
  232. case TOOL_LINK:
  233. echo $_SESSION['oLP']->display_manipulate($new_item_id, $type);
  234. Display::display_confirmation_message(get_lang('NewLinksCreated'));
  235. break;
  236. case TOOL_STUDENTPUBLICATION:
  237. echo $_SESSION['oLP']->display_manipulate($new_item_id, $type);
  238. Display::display_confirmation_message(get_lang('NewStudentPublicationCreated'));
  239. break;
  240. case 'module':
  241. echo $_SESSION['oLP']->display_manipulate($new_item_id, $type);
  242. Display::display_confirmation_message(get_lang('NewModuleCreated'));
  243. break;
  244. case TOOL_QUIZ:
  245. echo $_SESSION['oLP']->display_manipulate($new_item_id, $type);
  246. Display::display_confirmation_message(get_lang('NewExerciseCreated'));
  247. break;
  248. case TOOL_DOCUMENT:
  249. Display::display_confirmation_message(get_lang('NewDocumentCreated'));
  250. echo $_SESSION['oLP']->display_item($new_item_id);
  251. break;
  252. case TOOL_FORUM:
  253. echo $_SESSION['oLP']->display_manipulate($new_item_id, $type);
  254. Display::display_confirmation_message(get_lang('NewForumCreated'));
  255. break;
  256. case 'thread':
  257. echo $_SESSION['oLP']->display_manipulate($new_item_id, $type);
  258. Display::display_confirmation_message(get_lang('NewThreadCreated'));
  259. break;
  260. }
  261. } else {
  262. switch ($type) {
  263. case 'chapter':
  264. echo $_SESSION['oLP']->display_item_form($type, get_lang('EnterDataNewChapter'));
  265. break;
  266. case 'module':
  267. echo $_SESSION['oLP']->display_item_form($type, get_lang('EnterDataNewModule'));
  268. break;
  269. case 'document':
  270. if (isset($_GET['file']) && is_numeric($_GET['file'])) {
  271. echo $_SESSION['oLP']->display_document_form('add', 0, $_GET['file']);
  272. } else {
  273. echo $_SESSION['oLP']->display_document_form('add', 0);
  274. }
  275. break;
  276. case 'hotpotatoes':
  277. echo $_SESSION['oLP']->display_hotpotatoes_form('add', 0, $_GET['file']);
  278. break;
  279. case 'quiz':
  280. echo Display::display_warning_message(get_lang('ExerciseCantBeEditedAfterAddingToTheLP'));
  281. echo $_SESSION['oLP']->display_quiz_form('add', 0, $_GET['file']);
  282. break;
  283. case 'forum':
  284. echo $_SESSION['oLP']->display_forum_form('add', 0, $_GET['forum_id']);
  285. break;
  286. case 'thread':
  287. echo $_SESSION['oLP']->display_thread_form('add', 0, $_GET['thread_id']);
  288. break;
  289. case 'link':
  290. echo $_SESSION['oLP']->display_link_form('add', 0, $_GET['file']);
  291. break;
  292. case 'student_publication':
  293. echo $_SESSION['oLP']->display_student_publication_form('add', 0, $_GET['file']);
  294. break;
  295. case 'step':
  296. $_SESSION['oLP']->display_resources();
  297. break;
  298. }
  299. }
  300. echo '</div>';
  301. echo '</div>';
  302. /* FOOTER */
  303. Display::display_footer();