lp_admin_view.php 9.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292
  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 learnpath_handler.php
  20. *
  21. * @author Patrick Cool
  22. * @author Denes Nagy
  23. * @author Roan Embrechts, refactoring and code cleaning
  24. * @author Yannick Warnier <ywarnier@beeznest.org> - cleaning and update for new SCORM tool
  25. * @package dokeos.learnpath
  26. ==============================================================================
  27. */
  28. /*
  29. ==============================================================================
  30. INIT SECTION
  31. ==============================================================================
  32. */
  33. $this_section=SECTION_COURSES;
  34. api_protect_course_script();
  35. /*
  36. -----------------------------------------------------------
  37. Libraries
  38. -----------------------------------------------------------
  39. */
  40. //the main_api.lib.php, database.lib.php and display.lib.php
  41. //libraries are included by default
  42. include('learnpath_functions.inc.php');
  43. //include('../resourcelinker/resourcelinker.inc.php');
  44. include('resourcelinker.inc.php');
  45. //rewrite the language file, sadly overwritten by resourcelinker.inc.php
  46. $language_file = "learnpath";
  47. /*
  48. -----------------------------------------------------------
  49. Constants and variables
  50. -----------------------------------------------------------
  51. */
  52. $is_allowed_to_edit = api_is_allowed_to_edit(null,true);
  53. $tbl_lp = Database::get_course_table(TABLE_LP_MAIN);
  54. $tbl_lp_item = Database::get_course_table(TABLE_LP_ITEM);
  55. $tbl_lp_view = Database::get_course_table(TABLE_LP_VIEW);
  56. $isStudentView = (int) $_REQUEST['isStudentView'];
  57. $learnpath_id = (int) $_REQUEST['lp_id'];
  58. $submit = $_POST['submit_button'];
  59. /*
  60. $chapter_id = $_GET['chapter_id'];
  61. $title = $_POST['title'];
  62. $description = $_POST['description'];
  63. $Submititem = $_POST['Submititem'];
  64. $action = $_REQUEST['action'];
  65. $id = (int) $_REQUEST['id'];
  66. $type = $_REQUEST['type'];
  67. $direction = $_REQUEST['direction'];
  68. $moduleid = $_REQUEST['moduleid'];
  69. $prereq = $_REQUEST['prereq'];
  70. $type = $_REQUEST['type'];
  71. */
  72. /*
  73. ==============================================================================
  74. MAIN CODE
  75. ==============================================================================
  76. */
  77. // using the resource linker as a tool for adding resources to the learning path
  78. if ($action=="add" and $type=="learnpathitem")
  79. {
  80. $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>";
  81. }
  82. if ( (! $is_allowed_to_edit) or ($isStudentView) )
  83. {
  84. error_log('New LP - User not authorized in lp_admin_view.php');
  85. header('location:lp_controller.php?action=view&lp_id='.$learnpath_id);
  86. }
  87. //from here on, we are admin because of the previous condition, so don't check anymore
  88. $sql_query = "SELECT * FROM $tbl_lp WHERE id = $learnpath_id";
  89. $result=Database::query($sql_query);
  90. $therow=Database::fetch_array($result);
  91. //$admin_output = '';
  92. /*
  93. -----------------------------------------------------------
  94. Course admin section
  95. - all the functions not available for students - always available in this case (page only shown to admin)
  96. -----------------------------------------------------------
  97. */
  98. /*==================================================
  99. SHOWING THE ADMIN TOOLS
  100. ==================================================*/
  101. /*==================================================
  102. prerequisites setting end
  103. ==================================================*/
  104. if (isset($_SESSION['gradebook'])){
  105. $gradebook= $_SESSION['gradebook'];
  106. }
  107. if (!empty($gradebook) && $gradebook=='view') {
  108. $interbreadcrumb[]= array (
  109. 'url' => '../gradebook/'.$_SESSION['gradebook_dest'],
  110. 'name' => get_lang('Gradebook')
  111. );
  112. }
  113. $interbreadcrumb[]= array ("url"=>"lp_controller.php?action=list", "name"=> get_lang("_learning_path"));
  114. $interbreadcrumb[]= array ("url"=>api_get_self()."?action=admin_view&lp_id=$learnpath_id", "name" => stripslashes("{$therow['name']}"));
  115. //Theme calls
  116. $show_learn_path=true;
  117. $lp_theme_css=$_SESSION['oLP']->get_theme();
  118. Display::display_header(null,'Path');
  119. //api_display_tool_title($therow['name']);
  120. $suredel = trim(get_lang('AreYouSureToDelete'));
  121. //$suredelstep = trim(get_lang('AreYouSureToDeleteSteps'));
  122. ?>
  123. <script type='text/javascript'>
  124. /* <![CDATA[ */
  125. function stripslashes(str) {
  126. str=str.replace(/\\'/g,'\'');
  127. str=str.replace(/\\"/g,'"');
  128. str=str.replace(/\\\\/g,'\\');
  129. str=str.replace(/\\0/g,'\0');
  130. return str;
  131. }
  132. function confirmation(name)
  133. {
  134. name=stripslashes(name);
  135. if (confirm("<?php echo $suredel; ?> " + name + " ?"))
  136. {
  137. return true;
  138. }
  139. else
  140. {
  141. return false;
  142. }
  143. }
  144. </script>
  145. <?php
  146. /*
  147. -----------------------------------------------------------
  148. DISPLAY SECTION
  149. -----------------------------------------------------------
  150. */
  151. switch($_GET['action'])
  152. {
  153. case 'edit_item':
  154. if(isset($is_success) && $is_success === true)
  155. {
  156. Display::display_confirmation_message(get_lang("_learnpath_item_edited"));
  157. }
  158. else
  159. {
  160. echo $_SESSION['oLP']->display_edit_item($_GET['id']);
  161. }
  162. break;
  163. case 'delete_item':
  164. if(isset($is_success) && $is_success === true)
  165. {
  166. Display::display_confirmation_message(get_lang("_learnpath_item_deleted"));
  167. }
  168. break;
  169. }
  170. // POST action handling (uploading mp3, deleting mp3)
  171. if (isset($_POST['save_audio']))
  172. {
  173. // deleting the audio fragments
  174. foreach ($_POST as $key=>$value) {
  175. if (substr($key,0,9) == 'removemp3') {
  176. $lp_items_to_remove_audio[] = str_ireplace('removemp3','',$key);
  177. // removing the audio from the learning path item
  178. $tbl_lp_item = Database::get_course_table(TABLE_LP_ITEM);
  179. $in = implode(',',$lp_items_to_remove_audio);
  180. }
  181. }
  182. if (count($lp_items_to_remove_audio)>0) {
  183. $sql = "UPDATE $tbl_lp_item SET audio = '' WHERE id IN (".$in.")";
  184. $result = Database::query($sql, __FILE__, __LINE__);
  185. }
  186. // uploading the audio files
  187. foreach ($_FILES as $key=>$value)
  188. {
  189. if (substr($key,0,7) == 'mp3file' AND !empty($_FILES[$key]['tmp_name']))
  190. {
  191. // the id of the learning path item
  192. $lp_item_id = str_ireplace('mp3file','',$key);
  193. // create the audio folder if it does not exist yet
  194. global $_course;
  195. $filepath = api_get_path('SYS_COURSE_PATH').$_course['path'].'/document/';
  196. if(!is_dir($filepath.'audio'))
  197. {
  198. $perm = api_get_setting('permissions_for_new_directories');
  199. $perm = octdec(!empty($perm)?$perm:'0770');
  200. mkdir($filepath.'audio',$perm);
  201. $audio_id=add_document($_course,'/audio','folder',0,'audio');
  202. api_item_property_update($_course, TOOL_DOCUMENT, $audio_id, 'FolderCreated', api_get_user_id(),null,null,null,null,api_get_session_id());
  203. }
  204. // check if file already exits into document/audio/
  205. $file_name = $_FILES[$key]['name'];
  206. $file_name=stripslashes($file_name);
  207. //add extension to files without one (if possible)
  208. $file_name = add_ext_on_mime($file_name,$_FILES[$key]['type']);
  209. $clean_name = replace_dangerous_char($file_name);
  210. //no "dangerous" files
  211. $clean_name = disable_dangerous_file($clean_name);
  212. $check_file_path = api_get_path('SYS_COURSE_PATH').$_course['path'].'/document/audio/'.$clean_name;
  213. // if the file exists we generate a new name
  214. if (file_exists($check_file_path)) {
  215. $filename_components = explode('.',$clean_name);
  216. // gettting the extension of the file
  217. $file_extension = $filename_components[count($filename_components)-1];
  218. // adding something random to prevent overwriting
  219. $filename_components[count($filename_components)-1] = time();
  220. // reconstructing the new filename
  221. $clean_name = implode($filename_components) .'.'.$file_extension;
  222. // using the new name in the $_FILES superglobal
  223. $_FILES[$key]['name'] = $clean_name;
  224. }
  225. // upload the file in the documents tool
  226. include_once(api_get_path(LIBRARY_PATH) . 'fileUpload.lib.php');
  227. $file_path = handle_uploaded_document($_course, $_FILES[$key],api_get_path('SYS_COURSE_PATH').$_course['path'].'/document','/audio',api_get_user_id(),'','','','','',false);
  228. // getting the filename only
  229. $file_components = explode('/',$file_path);
  230. $file = $file_components[count($file_components)-1];
  231. // store the mp3 file in the lp_item table
  232. $tbl_lp_item = Database::get_course_table(TABLE_LP_ITEM);
  233. $sql_insert_audio = "UPDATE $tbl_lp_item SET audio = '".Database::escape_string($file)."' WHERE id = '".Database::escape_string($lp_item_id)."'";
  234. Database::query($sql_insert_audio, __FILE__, __LINE__);
  235. }
  236. }
  237. Display::display_confirmation_message(get_lang('ChangesStored'));
  238. }
  239. echo $_SESSION['oLP']->overview();
  240. /*
  241. ==============================================================================
  242. FOOTER
  243. ==============================================================================
  244. */
  245. Display::display_footer();
  246. ?>