edit_odf.php 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  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 (in_array(strtolower($pathinfo['extension']), $webOdfSupportedFiles) &&
  37. api_get_configuration_value('enabled_support_odf') === true
  38. ) {
  39. $showOdfEditor = true;
  40. }
  41. $fileUrl = api_get_path(WEB_COURSE_PATH)
  42. .$_course['path'].'/document'.$headerFile;
  43. if (!$showOdfEditor) {
  44. api_not_allowed(true);
  45. }
  46. $parentId = $documentInfo['parent_id'];
  47. if (!$parentId) {
  48. $testParentId = 0;
  49. // Get parent id from current path
  50. if (!empty($documentInfo['path'])) {
  51. $testParentId = DocumentManager::get_document_id(
  52. api_get_course_info(),
  53. dirname($documentInfo['path']),
  54. 0
  55. );
  56. }
  57. $parentId = !empty($testParentId) ? $testParentId : 0;
  58. }
  59. //$htmlHeadXtra[] = api_get_js('webodf/webodf.js');
  60. $htmlHeadXtra[] = api_get_js('wodotexteditor/wodotexteditor.js');
  61. $htmlHeadXtra[] = api_get_js('wodotexteditor/localfileeditor.js');
  62. $htmlHeadXtra[] = api_get_js('wodotexteditor/FileSaver.js');
  63. $htmlHeadXtra[] = '
  64. <script type="text/javascript" charset="utf-8">
  65. $(document).on(\'ready\', function() {
  66. createEditor(\''.$fileUrl.'\');
  67. });
  68. </script>
  69. ';
  70. $htmlHeadXtra[] = '
  71. <style>
  72. #editorContainer {
  73. width: 100%;
  74. height: 600px;
  75. margin: 0px;
  76. padding: 0px;
  77. }
  78. </style>
  79. ';
  80. // Interbreadcrumb for the current directory root path
  81. $interbreadcrumb[] = [
  82. 'url' => api_get_path(WEB_CODE_PATH).'document/document.php',
  83. 'name' => get_lang('Documents')
  84. ];
  85. if (!empty($documentInfo['parents'])) {
  86. foreach ($documentInfo['parents'] as $documentParent) {
  87. if ($documentInfo['title'] == $documentParent['title']) {
  88. continue;
  89. }
  90. $interbreadcrumb[] = [
  91. 'url' => $documentParent['document_url'],
  92. 'name' => $documentParent['title']
  93. ];
  94. }
  95. }
  96. $actionBack = Display::url(
  97. Display::return_icon(
  98. 'back.png',
  99. get_lang('BackTo').' '.get_lang('DocumentsOverview'),
  100. [],
  101. ICON_SIZE_MEDIUM
  102. ),
  103. 'document.php?'.api_get_cidreq(true, true, 'editodf').'&id='.$parentId
  104. );
  105. $actionEdit = Display::url(
  106. Display::return_icon(
  107. 'edit.png',
  108. get_lang('Rename').'/'.get_lang('Comments'),
  109. [],
  110. ICON_SIZE_MEDIUM
  111. ),
  112. 'edit_document.php?'.api_get_cidreq(true, true, 'editodf')
  113. .'&id='.$documentId
  114. );
  115. $content = '<div id="editorContainer"></div>';
  116. $view = new Template($documentInfo['title']);
  117. $view->assign(
  118. 'actions',
  119. Display::toolbarAction('actions', [$actionBack.$actionEdit])
  120. );
  121. $view->assign('header', $documentInfo['title']);
  122. $view->assign('content', $content);
  123. $view->display_one_col_template();