edit_odf.php 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. /**
  4. * ODF document editor script.
  5. *
  6. * @package chamilo.document
  7. */
  8. require_once __DIR__.'/../inc/global.inc.php';
  9. $documentId = isset($_GET['id']) ? intval($_GET['id']) : 0;
  10. $courseCode = api_get_course_id();
  11. if (!$documentId) {
  12. api_not_allowed();
  13. }
  14. $documentInfo = DocumentManager::get_document_data_by_id(
  15. $documentId,
  16. $courseCode,
  17. true
  18. );
  19. if (empty($documentInfo)) {
  20. api_not_allowed();
  21. }
  22. //Check user visibility
  23. $is_visible = DocumentManager::check_visibility_tree(
  24. $documentId,
  25. api_get_course_info(),
  26. api_get_session_id(),
  27. api_get_user_id(),
  28. api_get_group_id()
  29. );
  30. if (!api_is_allowed_to_edit() && !$is_visible) {
  31. api_not_allowed(true);
  32. }
  33. $headerFile = $documentInfo['path'];
  34. $pathinfo = pathinfo($headerFile);
  35. $showOdfEditor = false;
  36. $webOdfSupportedFiles = DocumentManager::get_web_odf_extension_list();
  37. if (in_array(strtolower($pathinfo['extension']), $webOdfSupportedFiles) &&
  38. api_get_configuration_value('enabled_support_odf') === true
  39. ) {
  40. $showOdfEditor = true;
  41. }
  42. $fileUrl = api_get_path(WEB_COURSE_PATH)
  43. .$_course['path'].'/document'.$headerFile;
  44. if (!$showOdfEditor) {
  45. api_not_allowed(true);
  46. }
  47. $parentId = $documentInfo['parent_id'];
  48. if (!$parentId) {
  49. $testParentId = 0;
  50. // Get parent id from current path
  51. if (!empty($documentInfo['path'])) {
  52. $testParentId = DocumentManager::get_document_id(
  53. api_get_course_info(),
  54. dirname($documentInfo['path']),
  55. 0
  56. );
  57. }
  58. $parentId = !empty($testParentId) ? $testParentId : 0;
  59. }
  60. //$htmlHeadXtra[] = api_get_js('webodf/webodf.js');
  61. $htmlHeadXtra[] = api_get_js('wodotexteditor/wodotexteditor.js');
  62. $htmlHeadXtra[] = api_get_js('wodotexteditor/localfileeditor.js');
  63. $htmlHeadXtra[] = api_get_js('wodotexteditor/FileSaver.js');
  64. $htmlHeadXtra[] = '
  65. <script>
  66. $(function() {
  67. createEditor(\''.$fileUrl.'\');
  68. });
  69. </script>
  70. ';
  71. $htmlHeadXtra[] = '
  72. <style>
  73. #editorContainer {
  74. width: 100%;
  75. height: 600px;
  76. margin: 0px;
  77. padding: 0px;
  78. }
  79. </style>
  80. ';
  81. // Interbreadcrumb for the current directory root path
  82. $interbreadcrumb[] = [
  83. 'url' => api_get_path(WEB_CODE_PATH).'document/document.php',
  84. 'name' => get_lang('Documents'),
  85. ];
  86. if (!empty($documentInfo['parents'])) {
  87. foreach ($documentInfo['parents'] as $documentParent) {
  88. if ($documentInfo['title'] == $documentParent['title']) {
  89. continue;
  90. }
  91. $interbreadcrumb[] = [
  92. 'url' => $documentParent['document_url'],
  93. 'name' => $documentParent['title'],
  94. ];
  95. }
  96. }
  97. $actionBack = Display::url(
  98. Display::return_icon(
  99. 'back.png',
  100. get_lang('Back to').' '.get_lang('Documents overview'),
  101. [],
  102. ICON_SIZE_MEDIUM
  103. ),
  104. 'document.php?'.api_get_cidreq(true, true, 'editodf').'&id='.$parentId
  105. );
  106. $actionEdit = Display::url(
  107. Display::return_icon(
  108. 'edit.png',
  109. get_lang('Rename').'/'.get_lang('Comments'),
  110. [],
  111. ICON_SIZE_MEDIUM
  112. ),
  113. 'edit_document.php?'.api_get_cidreq(true, true, 'editodf')
  114. .'&id='.$documentId
  115. );
  116. $content = '<div id="editorContainer"></div>';
  117. $view = new Template($documentInfo['title']);
  118. $view->assign(
  119. 'actions',
  120. Display::toolbarAction('actions', [$actionBack.$actionEdit])
  121. );
  122. $view->assign('header', $documentInfo['title']);
  123. $view->assign('content', $content);
  124. $view->display_one_col_template();