edit_draw.php 5.3 KB

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