create_draw.php 5.2 KB

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