edit_odf.php 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. /**
  4. * ODF document editor script
  5. * @package chamilo.document
  6. */
  7. require_once __DIR__.'/../inc/global.inc.php';
  8. $documentId = isset($_GET['id']) ? intval($_GET['id']) : 0;
  9. $courseCode = api_get_course_id();
  10. if (!$documentId) {
  11. api_not_allowed();
  12. }
  13. $documentInfo = DocumentManager::get_document_data_by_id(
  14. $documentId,
  15. $courseCode,
  16. true
  17. );
  18. if (empty($documentInfo)) {
  19. api_not_allowed();
  20. }
  21. //Check user visibility
  22. $is_visible = DocumentManager::check_visibility_tree(
  23. $documentId,
  24. api_get_course_id(),
  25. api_get_session_id(),
  26. api_get_user_id(),
  27. api_get_group_id()
  28. );
  29. if (!api_is_allowed_to_edit() && !$is_visible) {
  30. api_not_allowed(true);
  31. }
  32. $headerFile = $documentInfo['path'];
  33. $pathinfo = pathinfo($headerFile);
  34. $showOdfEditor = false;
  35. $webOdfSupportedFiles = DocumentManager::get_web_odf_extension_list();
  36. if (
  37. 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 type="text/javascript" charset="utf-8">
  66. $(document).on(\'ready\', 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('BackTo').' '.get_lang('DocumentsOverview'),
  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();