lp_add_item.php 12 KB

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