create_draw.php 5.5 KB

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