lp_add_item.php 13 KB

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