edit_draw.php 5.4 KB

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