create_draw.php 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. use ChamiloSession as Session;
  4. /**
  5. * This file allows creating new svg and png documents with an online editor.
  6. *
  7. * @package chamilo.document
  8. *
  9. * @author Juan Carlos Raña Trabado
  10. *
  11. * @since 25/september/2010
  12. */
  13. require_once __DIR__.'/../inc/global.inc.php';
  14. $this_section = SECTION_COURSES;
  15. $groupRights = Session::read('group_member_with_upload_rights');
  16. $nameTools = get_lang('Draw');
  17. api_protect_course_script();
  18. api_block_anonymous_users();
  19. api_protect_course_group(GroupManager::GROUP_TOOL_DOCUMENTS);
  20. $document_data = DocumentManager::get_document_data_by_id(
  21. $_GET['id'],
  22. api_get_course_id(),
  23. true
  24. );
  25. if (empty($document_data)) {
  26. if (api_is_in_group()) {
  27. $group_properties = GroupManager::get_group_properties(
  28. api_get_group_id()
  29. );
  30. $document_id = DocumentManager::get_document_id(
  31. api_get_course_info(),
  32. $group_properties['directory']
  33. );
  34. $document_data = DocumentManager::get_document_data_by_id(
  35. $document_id,
  36. api_get_course_id()
  37. );
  38. }
  39. }
  40. $document_id = $document_data['id'];
  41. $dir = $document_data['path'];
  42. // path for svg-edit save
  43. Session::write('draw_dir', Security::remove_XSS($dir));
  44. if ($dir == '/') {
  45. Session::write('draw_dir', '');
  46. }
  47. $dir = isset($dir) ? Security::remove_XSS($dir) : (isset($_POST['dir']) ? Security::remove_XSS($_POST['dir']) : '/');
  48. $is_allowed_to_edit = api_is_allowed_to_edit(null, true);
  49. // Please, do not modify this dirname formatting
  50. if (strstr($dir, '..')) {
  51. $dir = '/';
  52. }
  53. if ($dir[0] == '.') {
  54. $dir = substr($dir, 1);
  55. }
  56. if ($dir[0] != '/') {
  57. $dir = '/'.$dir;
  58. }
  59. if ($dir[strlen($dir) - 1] != '/') {
  60. $dir .= '/';
  61. }
  62. $filepath = api_get_path(SYS_COURSE_PATH).$_course['path'].'/document'.$dir;
  63. if (!is_dir($filepath)) {
  64. $filepath = api_get_path(SYS_COURSE_PATH).$_course['path'].'/document/';
  65. $dir = '/';
  66. }
  67. $groupId = api_get_group_id();
  68. if (!empty($groupId)) {
  69. $interbreadcrumb[] = [
  70. "url" => "../group/group_space.php?".api_get_cidreq(),
  71. "name" => get_lang('GroupSpace'),
  72. ];
  73. $group = GroupManager :: get_group_properties($groupId);
  74. $path = explode('/', $dir);
  75. if ('/'.$path[1] != $group['directory']) {
  76. api_not_allowed(true);
  77. }
  78. }
  79. $interbreadcrumb[] = [
  80. "url" => "./document.php?".api_get_cidreq(),
  81. "name" => get_lang('Documents'),
  82. ];
  83. if (!api_is_allowed_in_course()) {
  84. api_not_allowed(true);
  85. }
  86. if (!($is_allowed_to_edit || $groupRights ||
  87. DocumentManager::is_my_shared_folder(
  88. api_get_user_id(),
  89. Security::remove_XSS($dir),
  90. api_get_session_id()
  91. ))
  92. ) {
  93. api_not_allowed(true);
  94. }
  95. Event::event_access_tool(TOOL_DOCUMENT);
  96. $display_dir = $dir;
  97. if (isset($group)) {
  98. $display_dir = explode('/', $dir);
  99. unset($display_dir[0]);
  100. unset($display_dir[1]);
  101. $display_dir = implode('/', $display_dir);
  102. }
  103. // Interbreadcrumb for the current directory root path
  104. // Copied from document.php
  105. $dir_array = explode('/', $dir);
  106. $array_len = count($dir_array);
  107. // Interbreadcrumb for the current directory root path
  108. if (empty($document_data['parents'])) {
  109. $interbreadcrumb[] = ['url' => '#', 'name' => $document_data['title']];
  110. } else {
  111. foreach ($document_data['parents'] as $document_sub_data) {
  112. $interbreadcrumb[] = [
  113. 'url' => $document_sub_data['document_url'],
  114. 'name' => $document_sub_data['title'],
  115. ];
  116. }
  117. }
  118. Display :: display_header($nameTools, 'Doc');
  119. echo '<div class="actions">';
  120. echo '<a href="document.php?id='.$document_id.'">'.
  121. Display::return_icon('back.png', get_lang('BackTo').' '.get_lang('DocumentsOverview'), '', ICON_SIZE_MEDIUM).'</a>';
  122. echo '</div>';
  123. if (api_browser_support('svg')) {
  124. // Automatic loading the course language
  125. $translationList = ['' => 'en', 'pt' => 'pt-Pt', 'sr' => 'sr_latn'];
  126. $langsvgedit = api_get_language_isocode();
  127. $langsvgedit = isset($translationList[$langsvgedit]) ? $translationList[$langsvgedit] : $langsvgedit;
  128. $langsvgedit = file_exists(api_get_path(LIBRARY_PATH).'javascript/svgedit/locale/lang.'.$langsvgedit.'.js') ? $langsvgedit : 'en';
  129. $svg_url = api_get_path(WEB_LIBRARY_PATH).'javascript/svgedit/svg-editor.php?'.api_get_cidreq().'&lang='.$langsvgedit; ?>
  130. <script>
  131. document.write('<iframe id="frame" frameborder="0" scrolling="no" src="<?php echo $svg_url; ?>" width="100%" height="100%"><noframes><p>Sorry, your browser does not handle frames</p></noframes></iframe>');
  132. function resizeIframe() {
  133. var height = window.innerHeight -50;
  134. // max lower size
  135. if (height<550) {
  136. height=550;
  137. }
  138. document.getElementById('frame').style.height = height +"px";
  139. }
  140. document.getElementById('frame').onload = resizeIframe;
  141. window.onresize = resizeIframe;
  142. </script>
  143. <?php
  144. echo '<noscript>';
  145. echo '<iframe style="height: 550px; width: 100%;" scrolling="no" frameborder="0" src="'.$svg_url.'"><noframes><p>Sorry, your browser does not handle frames</p></noframes></iframe>';
  146. echo '</noscript>';
  147. } else {
  148. echo Display::return_message(get_lang('BrowserDontSupportsSVG'), 'error');
  149. }
  150. Display :: display_footer();