edit_draw.php 5.3 KB

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