create_draw.php 5.3 KB

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