create_draw.php 5.0 KB

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