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