lp_add_item.php 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444
  1. <?php // $Id: index.php 16620 2008-10-25 20:03:54Z yannoo $
  2. /*
  3. ==============================================================================
  4. Dokeos - elearning and course management software
  5. Copyright (c) 2004-2008 Dokeos SPRL
  6. Copyright (c) 2003 Ghent University (UGent)
  7. For a full list of contributors, see "credits.txt".
  8. The full license can be read in "license.txt".
  9. This program is free software; you can redistribute it and/or
  10. modify it under the terms of the GNU General Public License
  11. as published by the Free Software Foundation; either version 2
  12. of the License, or (at your option) any later version.
  13. See the GNU General Public License for more details.
  14. Contact: Dokeos, rue Notre Dame, 152, B-1140 Evere, Belgium, info@dokeos.com
  15. ==============================================================================
  16. */
  17. /**
  18. ==============================================================================
  19. * This is a learning path creation and player tool in Dokeos - previously
  20. * learnpath_handler.php
  21. *
  22. * @author Patrick Cool
  23. * @author Denes Nagy
  24. * @author Roan Embrechts, refactoring and code cleaning
  25. * @author Yannick Warnier <ywarnier@beeznest.org> - cleaning and update
  26. * @author Julio Montoya - Improving the list of templates
  27. * @package dokeos.learnpath
  28. ==============================================================================
  29. */
  30. /*
  31. ==============================================================================
  32. INIT SECTION
  33. ==============================================================================
  34. */
  35. $this_section=SECTION_COURSES;
  36. api_protect_course_script();
  37. /*
  38. -----------------------------------------------------------
  39. Libraries
  40. -----------------------------------------------------------
  41. */
  42. //the main_api.lib.php, database.lib.php and display.lib.php
  43. //libraries are included by default
  44. include('learnpath_functions.inc.php');
  45. //include('../resourcelinker/resourcelinker.inc.php');
  46. include('resourcelinker.inc.php');
  47. //rewrite the language file, sadly overwritten by resourcelinker.inc.php
  48. // name of the language file that needs to be included
  49. $language_file = "learnpath";
  50. /*
  51. -----------------------------------------------------------
  52. Header and action code
  53. -----------------------------------------------------------
  54. */
  55. $htmlHeadXtra[] = '
  56. <script type="text/javascript">
  57. var temp=false;
  58. var temp2=false;
  59. var use_document_title='.api_get_setting('use_document_title').';
  60. var load_default_template = '. ((isset($_POST['submit']) || empty($_SERVER['QUERY_STRING'])) ? 'false' : 'true' ) .';
  61. function FCKeditor_OnComplete( editorInstance )
  62. {
  63. editorInstance.Events.AttachEvent( \'OnSelectionChange\', check_for_title ) ;
  64. document.getElementById(\'frmModel\').innerHTML = "<iframe height=890px width=230px; frameborder=0 src=\''.api_get_path(WEB_LIBRARY_PATH).'fckeditor/editor/fckdialogframe.html \'>";
  65. }
  66. function check_for_title()
  67. {
  68. if(temp==true){
  69. // This functions shows that you can interact directly with the editor area
  70. // DOM. In this way you have the freedom to do anything you want with it.
  71. // Get the editor instance that we want to interact with.
  72. var oEditor = FCKeditorAPI.GetInstance(\'content_lp\') ;
  73. // Get the Editor Area DOM (Document object).
  74. var oDOM = oEditor.EditorDocument ;
  75. var iLength ;
  76. var contentText ;
  77. var contentTextArray;
  78. var bestandsnaamNieuw = "";
  79. var bestandsnaamOud = "";
  80. // The are two diffent ways to get the text (without HTML markups).
  81. // It is browser specific.
  82. if( document.all ) // If Internet Explorer.
  83. {
  84. contentText = oDOM.body.innerText ;
  85. }
  86. else // If Gecko.
  87. {
  88. var r = oDOM.createRange() ;
  89. r.selectNodeContents( oDOM.body ) ;
  90. contentText = r.toString() ;
  91. }
  92. var index=contentText.indexOf("/*<![CDATA");
  93. contentText=contentText.substr(0,index);
  94. // Compose title if there is none
  95. contentTextArray = contentText.split(\' \') ;
  96. var x=0;
  97. for(x=0; (x<5 && x<contentTextArray.length); x++)
  98. {
  99. if(x < 4)
  100. {
  101. bestandsnaamNieuw += contentTextArray[x] + \' \';
  102. }
  103. else
  104. {
  105. bestandsnaamNieuw += contentTextArray[x];
  106. }
  107. }
  108. }
  109. temp=true;
  110. }
  111. function InnerDialogLoaded()
  112. {
  113. if (document.all)
  114. {
  115. // if is iexplorer
  116. var B=new window.frames.content_lp___Frame.FCKToolbarButton(\'Templates\',window.content_lp___Frame.FCKLang.Templates);
  117. }
  118. else
  119. {
  120. var B=new window.frames[0].FCKToolbarButton(\'Templates\',window.frames[0].FCKLang.Templates);
  121. }
  122. return B.ClickFrame();
  123. };
  124. </script>';
  125. $htmlHeadXtra[] = $_SESSION['oLP']->create_js();
  126. /*
  127. -----------------------------------------------------------
  128. Constants and variables
  129. -----------------------------------------------------------
  130. */
  131. $is_allowed_to_edit = api_is_allowed_to_edit();
  132. $tbl_lp = Database::get_course_table(TABLE_LP_MAIN);
  133. $tbl_lp_item = Database::get_course_table(TABLE_LP_ITEM);
  134. $tbl_lp_view = Database::get_course_table(TABLE_LP_VIEW);
  135. $isStudentView = (int) $_REQUEST['isStudentView'];
  136. $learnpath_id = (int) $_REQUEST['lp_id'];
  137. $submit = $_POST['submit_button'];
  138. /*
  139. $chapter_id = $_GET['chapter_id'];
  140. $title = $_POST['title'];
  141. $description = $_POST['description'];
  142. $Submititem = $_POST['Submititem'];
  143. $action = $_REQUEST['action'];
  144. $id = (int) $_REQUEST['id'];
  145. $type = $_REQUEST['type'];
  146. $direction = $_REQUEST['direction'];
  147. $moduleid = $_REQUEST['moduleid'];
  148. $prereq = $_REQUEST['prereq'];
  149. $type = $_REQUEST['type'];
  150. */
  151. /*
  152. ==============================================================================
  153. MAIN CODE
  154. ==============================================================================
  155. */
  156. // using the resource linker as a tool for adding resources to the learning path
  157. if ($action=="add" and $type=="learnpathitem")
  158. {
  159. $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>";
  160. }
  161. if ( (! $is_allowed_to_edit) or ($isStudentView) )
  162. {
  163. error_log('New LP - User not authorized in lp_add_item.php');
  164. header('location:lp_controller.php?action=view&lp_id='.$learnpath_id);
  165. }
  166. //from here on, we are admin because of the previous condition, so don't check anymore
  167. $sql_query = "SELECT * FROM $tbl_lp WHERE id = $learnpath_id";
  168. $result=api_sql_query($sql_query);
  169. $therow=Database::fetch_array($result);
  170. //$admin_output = '';
  171. /*
  172. -----------------------------------------------------------
  173. Course admin section
  174. - all the functions not available for students - always available in this case (page only shown to admin)
  175. -----------------------------------------------------------
  176. */
  177. /*==================================================
  178. SHOWING THE ADMIN TOOLS
  179. ==================================================*/
  180. if (isset($_SESSION['gradebook'])){
  181. $gradebook= $_SESSION['gradebook'];
  182. }
  183. if (!empty($gradebook) && $gradebook=='view') {
  184. $interbreadcrumb[]= array (
  185. 'url' => '../gradebook/'.$_SESSION['gradebook_dest'],
  186. 'name' => get_lang('Gradebook')
  187. );
  188. }
  189. $interbreadcrumb[]= array ("url"=>"lp_controller.php?action=list", "name"=> get_lang("_learning_path"));
  190. $interbreadcrumb[]= array ("url"=>api_get_self()."?action=build&lp_id=$learnpath_id", "name" => stripslashes("{$therow['name']}"));
  191. switch($_GET['type']){
  192. case 'chapter':
  193. $interbreadcrumb[]= array ("url"=>"#", "name" => get_lang("NewChapter"));
  194. break;
  195. default:
  196. $interbreadcrumb[]= array ("url"=>"#", "name" => get_lang("NewStep"));
  197. break;
  198. }
  199. //Theme calls
  200. $show_learn_path=true;
  201. $lp_theme_css=$_SESSION['oLP']->get_theme();
  202. Display::display_header(null,'Path');
  203. //api_display_tool_title($therow['name']);
  204. $suredel = trim(get_lang('AreYouSureToDelete'));
  205. //$suredelstep = trim(get_lang('AreYouSureToDeleteSteps'));
  206. ?>
  207. <script type='text/javascript'>
  208. /* <![CDATA[ */
  209. function stripslashes(str) {
  210. str=str.replace(/\\'/g,'\'');
  211. str=str.replace(/\\"/g,'"');
  212. str=str.replace(/\\\\/g,'\\');
  213. str=str.replace(/\\0/g,'\0');
  214. return str;
  215. }
  216. function confirmation(name)
  217. {
  218. name=stripslashes(name);
  219. if (confirm("<?php echo $suredel; ?> " + name + " ?"))
  220. {
  221. return true;
  222. }
  223. else
  224. {
  225. return false;
  226. }
  227. }
  228. </script>
  229. <?php
  230. //echo $admin_output;
  231. /*
  232. -----------------------------------------------------------
  233. DISPLAY SECTION
  234. -----------------------------------------------------------
  235. */
  236. echo $_SESSION['oLP']->build_action_menu();
  237. echo '<table cellpadding="0" cellspacing="0" class="lp_build">';
  238. echo '<tr>';
  239. echo '<td class="tree">';
  240. // show the template list
  241. if (isset($_GET['type']) && $_GET['type']=='document' && !isset($_GET['file']))
  242. {
  243. $count_items = count($_SESSION['oLP']->ordered_items);
  244. $style = ($count_items > 12)?' style="height:250px;width:230px;overflow-x : auto; overflow-y : scroll;" ':' class="lp_tree" ';
  245. echo '<div '.$style.'>';
  246. //build the tree with the menu items in it
  247. echo $_SESSION['oLP']->build_tree();
  248. echo '</div>';
  249. // show the template list
  250. echo '<p style="border-bottom:1px solid #999999; margin:0; padding:2px;"></p>'; //line
  251. echo '<br />';
  252. echo '<div id="frmModel" style="display:block; height:890px;width:100px; position:relative;"></div>';
  253. } else {
  254. echo '<div class="lp_tree">';
  255. //build the tree with the menu items in it
  256. echo $_SESSION['oLP']->build_tree();
  257. echo '</div>';
  258. }
  259. echo '</td>';
  260. echo '<td class="workspace">';
  261. if(isset($new_item_id) && is_numeric($new_item_id))
  262. {
  263. switch($_GET['type'])
  264. {
  265. case 'chapter':
  266. echo $_SESSION['oLP']->display_manipulate($new_item_id, $_GET['type']);
  267. Display::display_confirmation_message(get_lang('NewChapterCreated'));
  268. break;
  269. case TOOL_LINK:
  270. echo $_SESSION['oLP']->display_manipulate($new_item_id, $_GET['type']);
  271. Display::display_confirmation_message(get_lang('NewLinksCreated'));
  272. break;
  273. case TOOL_STUDENTPUBLICATION:
  274. echo $_SESSION['oLP']->display_manipulate($new_item_id, $_GET['type']);
  275. Display::display_confirmation_message(get_lang('NewStudentPublicationCreated'));
  276. break;
  277. case 'module':
  278. echo $_SESSION['oLP']->display_manipulate($new_item_id, $_GET['type']);
  279. Display::display_confirmation_message(get_lang('NewModuleCreated'));
  280. break;
  281. case TOOL_QUIZ:
  282. echo $_SESSION['oLP']->display_manipulate($new_item_id, $_GET['type']);
  283. Display::display_confirmation_message(get_lang('NewExerciseCreated'));
  284. break;
  285. case TOOL_DOCUMENT:
  286. Display::display_confirmation_message(get_lang('NewDocumentCreated'));
  287. echo $_SESSION['oLP']->display_item($new_item_id, true, $msg);
  288. break;
  289. case TOOL_FORUM:
  290. echo $_SESSION['oLP']->display_manipulate($new_item_id, $_GET['type']);
  291. Display::display_confirmation_message(get_lang('NewForumCreated'));
  292. break;
  293. case 'thread':
  294. echo $_SESSION['oLP']->display_manipulate($new_item_id, $_GET['type']);
  295. Display::display_confirmation_message(get_lang('NewThreadCreated'));
  296. break;
  297. }
  298. }
  299. else
  300. {
  301. switch($_GET['type'])
  302. {
  303. case 'chapter':
  304. echo $_SESSION['oLP']->display_item_form($_GET['type'], get_lang("EnterDataNewChapter"));
  305. break;
  306. case 'module':
  307. echo $_SESSION['oLP']->display_item_form($_GET['type'], get_lang("EnterDataNewModule"));
  308. break;
  309. case 'document':
  310. if(isset($_GET['file']) && is_numeric($_GET['file']))
  311. {
  312. echo $_SESSION['oLP']->display_document_form('add', 0, $_GET['file']);
  313. }
  314. else
  315. {
  316. echo $_SESSION['oLP']->display_document_form('add', 0);
  317. }
  318. break;
  319. case 'hotpotatoes':
  320. echo $_SESSION['oLP']->display_hotpotatoes_form('add', 0, $_GET['file']);
  321. break;
  322. case 'quiz':
  323. echo $_SESSION['oLP']->display_quiz_form('add', 0, $_GET['file']);
  324. break;
  325. case 'forum':
  326. echo $_SESSION['oLP']->display_forum_form('add', 0, $_GET['forum_id']);
  327. break;
  328. case 'thread':
  329. echo $_SESSION['oLP']->display_thread_form('add', 0, $_GET['thread_id']);
  330. break;
  331. case 'link':
  332. echo $_SESSION['oLP']->display_link_form('add', 0, $_GET['file']);
  333. break;
  334. case 'student_publication':
  335. echo $_SESSION['oLP']->display_student_publication_form('add', 0, $_GET['file']);
  336. break;
  337. case 'step':
  338. echo $_SESSION['oLP']->display_resources();
  339. break;
  340. }
  341. }
  342. echo '</td>';
  343. echo '</tr>';
  344. echo '</table>';
  345. /*
  346. ==============================================================================
  347. FOOTER
  348. ==============================================================================
  349. */
  350. Display::display_footer();
  351. ?>