edit_draw.php 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  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. api_protect_course_script(true);
  17. api_block_anonymous_users();
  18. $document_data = DocumentManager::get_document_data_by_id(
  19. $_GET['id'],
  20. api_get_course_id(),
  21. true
  22. );
  23. $file_path = '';
  24. if (empty($document_data)) {
  25. api_not_allowed();
  26. } else {
  27. $document_id = $document_data['id'];
  28. $file_path = $document_data['path'];
  29. $dir = dirname($document_data['path']);
  30. $parent_id = DocumentManager::get_document_id(api_get_course_info(), $dir);
  31. $my_cur_dir_path = isset($_GET['curdirpath']) ? Security::remove_XSS($_GET['curdirpath']) : '';
  32. }
  33. //and urlencode each url $curdirpath (hack clean $curdirpath under Windows - Bug #3261)
  34. $dir = str_replace('\\', '/', $dir);
  35. /* Constants & Variables */
  36. $current_session_id = api_get_session_id();
  37. $group_id = api_get_group_id();
  38. //path for svg-edit save
  39. Session::write('draw_dir', Security::remove_XSS($dir));
  40. if ($dir == '/') {
  41. Session::write('draw_dir', '');
  42. }
  43. Session::write('draw_file', basename(Security::remove_XSS($file_path)));
  44. $get_file = Security::remove_XSS($file_path);
  45. $file = basename($get_file);
  46. $temp_file = explode(".", $file);
  47. $filename = $temp_file[0];
  48. $nameTools = get_lang('Edit').': '.$filename;
  49. $courseDir = $_course['path'].'/document';
  50. $is_allowed_to_edit = api_is_allowed_to_edit(null, true);
  51. /* Other initialization code */
  52. /* Please, do not modify this dirname formatting */
  53. if (strstr($dir, '..')) {
  54. $dir = '/';
  55. }
  56. if ($dir[0] == '.') {
  57. $dir = substr($dir, 1);
  58. }
  59. if ($dir[0] != '/') {
  60. $dir = '/'.$dir;
  61. }
  62. if ($dir[strlen($dir) - 1] != '/') {
  63. $dir .= '/';
  64. }
  65. $filepath = api_get_path(SYS_COURSE_PATH).$_course['path'].'/document'.$dir;
  66. if (!is_dir($filepath)) {
  67. $filepath = api_get_path(SYS_COURSE_PATH).$_course['path'].'/document/';
  68. $dir = '/';
  69. }
  70. //groups //TODO:clean
  71. if (!empty($group_id)) {
  72. $interbreadcrumb[] = [
  73. 'url' => api_get_path(WEB_CODE_PATH).'group/group_space.php?'.api_get_cidreq(),
  74. 'name' => get_lang('Group area'),
  75. ];
  76. $group_document = true;
  77. }
  78. $is_certificate_mode = DocumentManager::is_certificate_mode($dir);
  79. if (!$is_certificate_mode) {
  80. $interbreadcrumb[] = [
  81. "url" => "./document.php?curdirpath=".urlencode($my_cur_dir_path).'&'.api_get_cidreq(),
  82. "name" => get_lang('Documents'),
  83. ];
  84. } else {
  85. $interbreadcrumb[] = [
  86. 'url' => Category::getUrl(),
  87. 'name' => get_lang('Assessments'),
  88. ];
  89. }
  90. // Interbreadcrumb for the current directory root path
  91. if (empty($document_data['parents'])) {
  92. $interbreadcrumb[] = ['url' => '#', 'name' => $document_data['title']];
  93. } else {
  94. foreach ($document_data['parents'] as $document_sub_data) {
  95. if ($document_data['title'] == $document_sub_data['title']) {
  96. continue;
  97. }
  98. $interbreadcrumb[] = [
  99. 'url' => $document_sub_data['document_url'],
  100. 'name' => $document_sub_data['title'],
  101. ];
  102. }
  103. }
  104. $is_allowedToEdit = api_is_allowed_to_edit(null, true) || $groupRights || DocumentManager::is_my_shared_folder(api_get_user_id(), $dir, $current_session_id);
  105. if (!$is_allowedToEdit) {
  106. api_not_allowed(true);
  107. }
  108. Event::event_access_tool(TOOL_DOCUMENT);
  109. Display :: display_header($nameTools, 'Doc');
  110. echo '<div class="actions">';
  111. echo '<a href="document.php?id='.$parent_id.'">'.
  112. Display::return_icon('back.png', get_lang('Back to').' '.get_lang('Documents overview'), '', ICON_SIZE_MEDIUM).'</a>';
  113. echo '<a href="edit_document.php?'.api_get_cidreq().'&id='.$document_id.'&origin=editdraw">'.
  114. Display::return_icon('edit.png', get_lang('Rename').'/'.get_lang('Comments'), '', ICON_SIZE_MEDIUM).'</a>';
  115. echo '</div>';
  116. if (api_browser_support('svg')) {
  117. //automatic loading the course language
  118. $svgedit_code_translation_table = [
  119. '' => 'en',
  120. 'pt' => 'pt-Pt',
  121. 'sr' => 'sr_latn',
  122. ];
  123. $langsvgedit = api_get_language_isocode();
  124. $langsvgedit = isset($svgedit_code_translation_table[$langsvgedit]) ? $svgedit_code_translation_table[$langsvgedit] : $langsvgedit;
  125. $langsvgedit = file_exists(api_get_path(LIBRARY_PATH).'javascript/svgedit/locale/lang.'.$langsvgedit.'.js') ? $langsvgedit : 'en';
  126. $svg_url = api_get_path(WEB_LIBRARY_PATH).'javascript/svgedit/svg-editor.php?url=../../../../../courses/'.$courseDir.$dir.$file.'&lang='.$langsvgedit; ?>
  127. <script>
  128. 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>');
  129. function resizeIframe() {
  130. var height = window.innerHeight -50;
  131. //max lower size
  132. if (height<550) {
  133. height=550;
  134. }
  135. document.getElementById('frame').style.height = height +"px";
  136. };
  137. document.getElementById('frame').onload = resizeIframe;
  138. window.onresize = resizeIframe;
  139. </script>
  140. <?php
  141. echo '<noscript>';
  142. 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>';
  143. echo '</noscript>';
  144. } else {
  145. echo Display::return_message(get_lang('Your browser does not support SVG files. To use the drawing tool you must have an advanced browser such as Firefox or Chrome'), 'error');
  146. }
  147. Display::display_footer();