lp_add_item.php 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346
  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. $is_allowed_to_edit = api_is_allowed_to_edit(null, true);
  111. $isStudentView = (int) $_REQUEST['isStudentView'];
  112. $learnpath_id = (int) $_REQUEST['lp_id'];
  113. $submit = $_POST['submit_button'];
  114. $type = isset($_GET['type']) ? $_GET['type'] : null;
  115. $action = isset($_GET['action']) ? $_GET['action'] : null;
  116. // Using the resource linker as a tool for adding resources to the learning path.
  117. if ($action == 'add' && $type == 'learnpathitem') {
  118. $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>";
  119. }
  120. if ((!$is_allowed_to_edit) || ($isStudentView)) {
  121. error_log('New LP - User not authorized in lp_add_item.php');
  122. header('location:lp_controller.php?action=view&lp_id='.$learnpath_id);
  123. exit;
  124. }
  125. /* SHOWING THE ADMIN TOOLS */
  126. if (isset($_SESSION['gradebook'])) {
  127. $gradebook = $_SESSION['gradebook'];
  128. }
  129. if (!empty($gradebook) && $gradebook == 'view') {
  130. $interbreadcrumb[] = array (
  131. 'url' => '../gradebook/'.$_SESSION['gradebook_dest'],
  132. 'name' => get_lang('ToolGradebook')
  133. );
  134. }
  135. $interbreadcrumb[] = array('url' => 'lp_controller.php?action=list', 'name' => get_lang('LearningPaths'));
  136. $interbreadcrumb[] = array('url' => api_get_self()."?action=build&lp_id=$learnpath_id", 'name' => $_SESSION['oLP']->get_name());
  137. switch ($type) {
  138. case 'chapter':
  139. $interbreadcrumb[]= array ('url' => 'lp_controller.php?action=add_item&type=step&lp_id='.$_SESSION['oLP']->get_id(), 'name' => get_lang('NewStep'));
  140. $interbreadcrumb[]= array ('url' => '#', 'name' => get_lang('NewChapter'));
  141. break;
  142. case 'document':
  143. $interbreadcrumb[]= array ('url' => 'lp_controller.php?action=add_item&type=step&lp_id='.$_SESSION['oLP']->get_id(), 'name' => get_lang('NewStep'));
  144. break;
  145. default:
  146. $interbreadcrumb[]= array ('url' => '#', 'name' => get_lang('NewStep'));
  147. break;
  148. }
  149. if ($action == 'add_item' && $type == 'document' ) {
  150. $interbreadcrumb[]= array ('url' => '#', 'name' => get_lang('NewDocumentCreated'));
  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. /* Fixes LP toolbar */
  166. #resource_tab li a {
  167. padding: 5px 4px;
  168. }
  169. </style>
  170. <script>
  171. function stripslashes(str) {
  172. str=str.replace(/\\'/g,'\'');
  173. str=str.replace(/\\"/g,'"');
  174. str=str.replace(/\\\\/g,'\\');
  175. str=str.replace(/\\0/g,'\0');
  176. return str;
  177. }
  178. function confirmation(name) {
  179. name=stripslashes(name);
  180. if (confirm("<?php echo $suredel; ?> " + name + " ?")) {
  181. return true;
  182. } else {
  183. return false;
  184. }
  185. }
  186. $(document).ready(function() {
  187. $("#hide_bar_template").toggle(
  188. function() {
  189. $("#lp_sidebar").hide();
  190. $(this).css({'background-image' : 'url("../img/hide2.png")'})
  191. $("#doc_form").removeClass("span8");
  192. $("#doc_form").addClass("span11");
  193. },
  194. function() {
  195. $("#lp_sidebar").show();
  196. $("#doc_form").removeClass("span11");
  197. $("#doc_form").addClass("span8");
  198. $(this).css('background-image', 'url("../img/hide0.png")');
  199. }
  200. );
  201. });
  202. </script>
  203. <?php
  204. /* DISPLAY SECTION */
  205. echo $_SESSION['oLP']->build_action_menu();
  206. echo '<div class="row-fluid" style="overflow:hidden">';
  207. echo '<div id="lp_sidebar" class="span4">';
  208. echo $_SESSION['oLP']->return_new_tree(null, true);
  209. // Show the template list.
  210. if ($type == 'document' && !isset($_GET['file'])) {
  211. // Show the template list.
  212. echo '<div id="frmModel" style="display:block; height:890px;width:100px; position:relative;"></div>';}
  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. if (isset($new_item_id) && is_numeric($new_item_id)) {
  220. switch ($type) {
  221. case 'chapter':
  222. echo $_SESSION['oLP']->display_manipulate($new_item_id, $_POST['type']);
  223. Display::display_confirmation_message(get_lang('NewChapterCreated'));
  224. break;
  225. case TOOL_LINK:
  226. echo $_SESSION['oLP']->display_manipulate($new_item_id, $type);
  227. Display::display_confirmation_message(get_lang('NewLinksCreated'));
  228. break;
  229. case TOOL_STUDENTPUBLICATION:
  230. echo $_SESSION['oLP']->display_manipulate($new_item_id, $type);
  231. Display::display_confirmation_message(get_lang('NewStudentPublicationCreated'));
  232. break;
  233. case 'module':
  234. echo $_SESSION['oLP']->display_manipulate($new_item_id, $type);
  235. Display::display_confirmation_message(get_lang('NewModuleCreated'));
  236. break;
  237. case TOOL_QUIZ:
  238. echo $_SESSION['oLP']->display_manipulate($new_item_id, $type);
  239. Display::display_confirmation_message(get_lang('NewExerciseCreated'));
  240. break;
  241. case TOOL_DOCUMENT:
  242. Display::display_confirmation_message(get_lang('NewDocumentCreated'));
  243. echo $_SESSION['oLP']->display_item($new_item_id, true);
  244. break;
  245. case TOOL_FORUM:
  246. echo $_SESSION['oLP']->display_manipulate($new_item_id, $type);
  247. Display::display_confirmation_message(get_lang('NewForumCreated'));
  248. break;
  249. case 'thread':
  250. echo $_SESSION['oLP']->display_manipulate($new_item_id, $type);
  251. Display::display_confirmation_message(get_lang('NewThreadCreated'));
  252. break;
  253. }
  254. } else {
  255. switch ($type) {
  256. case 'chapter':
  257. echo $_SESSION['oLP']->display_item_form($type, get_lang('EnterDataNewChapter'));
  258. break;
  259. case 'module':
  260. echo $_SESSION['oLP']->display_item_form($type, get_lang('EnterDataNewModule'));
  261. break;
  262. case 'document':
  263. if (isset($_GET['file']) && is_numeric($_GET['file'])) {
  264. echo $_SESSION['oLP']->display_document_form('add', 0, $_GET['file']);
  265. } else {
  266. echo $_SESSION['oLP']->display_document_form('add', 0);
  267. }
  268. break;
  269. case 'hotpotatoes':
  270. echo $_SESSION['oLP']->display_hotpotatoes_form('add', 0, $_GET['file']);
  271. break;
  272. case 'quiz':
  273. echo Display::display_warning_message(get_lang('ExerciseCantBeEditedAfterAddingToTheLP'));
  274. echo $_SESSION['oLP']->display_quiz_form('add', 0, $_GET['file']);
  275. break;
  276. case 'forum':
  277. echo $_SESSION['oLP']->display_forum_form('add', 0, $_GET['forum_id']);
  278. break;
  279. case 'thread':
  280. echo $_SESSION['oLP']->display_thread_form('add', 0, $_GET['thread_id']);
  281. break;
  282. case 'link':
  283. echo $_SESSION['oLP']->display_link_form('add', 0, $_GET['file']);
  284. break;
  285. case 'student_publication':
  286. echo $_SESSION['oLP']->display_student_publication_form('add', 0, $_GET['file']);
  287. break;
  288. case 'step':
  289. $_SESSION['oLP']->display_resources();
  290. break;
  291. }
  292. }
  293. echo '</div>';
  294. echo '</div>';
  295. /* FOOTER */
  296. Display::display_footer();