edit_draw.php 5.3 KB

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