lp_admin_view.php 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267
  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();
  53. $tbl_lp = Database::get_course_table('lp');
  54. $tbl_lp_item = Database::get_course_table('lp_item');
  55. $tbl_lp_view = Database::get_course_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=api_sql_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. $interbreadcrumb[]= array ("url"=>"lp_controller.php?action=list", "name"=> get_lang("_learning_path"));
  105. $interbreadcrumb[]= array ("url"=>api_get_self()."?action=admin_view&lp_id=$learnpath_id", "name" => stripslashes("{$therow['name']}"));
  106. //Theme calls
  107. $show_learn_path=true;
  108. $lp_theme_css=$_SESSION['oLP']->get_theme();
  109. Display::display_header(null,'Path');
  110. //api_display_tool_title($therow['name']);
  111. $suredel = trim(get_lang('AreYouSureToDelete'));
  112. //$suredelstep = trim(get_lang('AreYouSureToDeleteSteps'));
  113. ?>
  114. <script type='text/javascript'>
  115. /* <![CDATA[ */
  116. function stripslashes(str) {
  117. str=str.replace(/\\'/g,'\'');
  118. str=str.replace(/\\"/g,'"');
  119. str=str.replace(/\\\\/g,'\\');
  120. str=str.replace(/\\0/g,'\0');
  121. return str;
  122. }
  123. function confirmation(name)
  124. {
  125. name=stripslashes(name);
  126. if (confirm("<?php echo $suredel; ?> " + name + " ?"))
  127. {
  128. return true;
  129. }
  130. else
  131. {
  132. return false;
  133. }
  134. }
  135. </script>
  136. <?php
  137. /*
  138. -----------------------------------------------------------
  139. DISPLAY SECTION
  140. -----------------------------------------------------------
  141. */
  142. switch($_GET['action'])
  143. {
  144. case 'edit_item':
  145. if(isset($is_success) && $is_success === true)
  146. {
  147. echo '<div class="confirmation-message">';
  148. echo get_lang("_learnpath_item_edited");
  149. echo '</div>';
  150. }
  151. else
  152. {
  153. echo $_SESSION['oLP']->display_edit_item($_GET['id']);
  154. }
  155. break;
  156. case 'delete_item':
  157. if(isset($is_success) && $is_success === true)
  158. {
  159. echo '<div class="confirmation-message">';
  160. echo get_lang("_learnpath_item_deleted");
  161. echo '</div>';
  162. }
  163. break;
  164. }
  165. // POST action handling (uploading mp3, deleting mp3)
  166. if (isset($_POST['save_audio']))
  167. {
  168. // deleting the audio fragments
  169. foreach ($_POST as $key=>$value)
  170. {
  171. if (substr($key,0,9) == 'removemp3')
  172. {
  173. $lp_items_to_remove_audio[] = str_ireplace('removemp3','',$key);
  174. // removing the audio from the learning path item
  175. $tbl_lp_item = Database::get_course_table('lp_item');
  176. $in = implode(',',$lp_items_to_remove_audio);
  177. }
  178. }
  179. if (count($lp_items_to_remove_audio)>0)
  180. {
  181. $sql = "UPDATE $tbl_lp_item SET audio = '' WHERE id IN (".$in.")";
  182. $result = api_sql_query($sql, __FILE__, __LINE__);
  183. }
  184. // uploading the audio files
  185. foreach ($_FILES as $key=>$value)
  186. {
  187. if (substr($key,0,7) == 'mp3file' AND !empty($_FILES[$key]['tmp_name']))
  188. {
  189. // the id of the learning path item
  190. $lp_item_id = str_ireplace('mp3file','',$key);
  191. // create the audio folder if it does not exist yet
  192. global $_course;
  193. $filepath = api_get_path('SYS_COURSE_PATH').$_course['path'].'/document/';
  194. if(!is_dir($filepath.'audio'))
  195. {
  196. $perm = api_get_setting('permissions_for_new_directories');
  197. $perm = octdec(!empty($perm)?$perm:'0770');
  198. mkdir($filepath.'audio',$perm);
  199. $audio_id=add_document($_course,'/audio','folder',0,'audio');
  200. api_item_property_update($_course, TOOL_DOCUMENT, $audio_id, 'FolderCreated', api_get_user_id());
  201. }
  202. // upload the file in the documents tool
  203. include_once(api_get_path(LIBRARY_PATH) . 'fileUpload.lib.php');
  204. $file_path = handle_uploaded_document($_course, $_FILES[$key],api_get_path('SYS_COURSE_PATH').$_course['path'].'/document','/audio',api_get_user_id(),'','','','','',false);
  205. // getting the filename only
  206. $file_components = explode('/',$file_path);
  207. $file = $file_components[count($file_components)-1];
  208. // store the mp3 file in the lp_item table
  209. $tbl_lp_item = Database::get_course_table('lp_item');
  210. $sql_insert_audio = "UPDATE $tbl_lp_item SET audio = '".Database::escape_string($file)."' WHERE id = '".Database::escape_string($lp_item_id)."'";
  211. api_sql_query($sql_insert_audio, __FILE__, __LINE__);
  212. }
  213. }
  214. Display::display_confirmation_message(get_lang('ChangesStored'));
  215. }
  216. echo $_SESSION['oLP']->overview();
  217. /*
  218. ==============================================================================
  219. FOOTER
  220. ==============================================================================
  221. */
  222. Display::display_footer();
  223. ?>