edit_odf.php 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. require_once '../inc/global.inc.php';
  4. exit;
  5. $document_id = $_GET['id'];
  6. if ($document_id) {
  7. $document_data = DocumentManager::get_document_data_by_id($document_id);
  8. if (empty($document_data)) {
  9. api_not_allowed();
  10. }
  11. } else {
  12. api_not_allowed();
  13. }
  14. //Check user visibility
  15. //$is_visible = DocumentManager::is_visible_by_id($document_id, $course_info, api_get_session_id(), api_get_user_id());
  16. $is_visible = DocumentManager::check_visibility_tree($document_id, api_get_course_id(), api_get_session_id(), api_get_user_id());
  17. if (!api_is_allowed_to_edit() && !$is_visible) {
  18. api_not_allowed(true);
  19. }
  20. $header_file = $document_data['path'];
  21. $pathinfo = pathinfo($header_file);
  22. $show_web_odf = false;
  23. $web_odf_supported_files = DocumentManager::get_web_odf_extension_list();
  24. if (in_array(strtolower($pathinfo['extension']), $web_odf_supported_files)) {
  25. $show_web_odf = true;
  26. }
  27. $file_url_web = api_get_path(WEB_COURSE_PATH).$_course['path'].'/document'.$header_file.'?'.api_get_cidreq();
  28. if ($show_web_odf) {
  29. $htmlHeadXtra[] = api_get_js('webodf/webodf.js');
  30. $htmlHeadXtra[] = api_get_css(api_get_path(WEB_LIBRARY_PATH).'javascript/webodf/webodf.css');
  31. $htmlHeadXtra[] = '
  32. <script type="text/javascript" charset="utf-8">
  33. function init() {
  34. var odfelement = document.getElementById("odf"),
  35. odfcanvas = new odf.OdfCanvas(odfelement);
  36. odfcanvas.load("'.$file_url_web.'");
  37. }
  38. $(document).ready(function() {
  39. window.setTimeout(init, 0);
  40. });
  41. </script>';
  42. }
  43. $interbreadcrumb[]=array("url"=>"./document.php?curdirpath=".urlencode($my_cur_dir_path).$req_gid, "name"=> get_lang('Documents'));
  44. // Interbreadcrumb for the current directory root path
  45. if (empty($document_data['parents'])) {
  46. $interbreadcrumb[] = array('url' => '#', 'name' => $document_data['title']);
  47. } else {
  48. foreach($document_data['parents'] as $document_sub_data) {
  49. if ($document_data['title'] == $document_sub_data['title']) {
  50. continue;
  51. }
  52. $interbreadcrumb[] = array('url' => $document_sub_data['document_url'], 'name' => $document_sub_data['title']);
  53. }
  54. }
  55. Display::display_header('');
  56. echo '<div id="odf"></div>';
  57. Display::display_footer();