create_draw.php 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  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. /* INIT SECTION */
  12. // Name of the language file that needs to be included
  13. $language_file = array('document');
  14. require_once '../inc/global.inc.php';
  15. $_SESSION['whereami'] = 'document/createdraw';
  16. $this_section = SECTION_COURSES;
  17. require_once api_get_path(SYS_CODE_PATH).'document/document.inc.php';
  18. require_once api_get_path(LIBRARY_PATH).'groupmanager.lib.php';
  19. $nameTools = get_lang('Draw');
  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());
  23. if (empty($document_data)) {
  24. if (api_is_in_group()) {
  25. $group_properties = GroupManager::get_group_properties(api_get_group_id());
  26. $document_id = DocumentManager::get_document_id(api_get_course_info(), $group_properties['directory']);
  27. $document_data = DocumentManager::get_document_data_by_id($document_id, api_get_course_id());
  28. }
  29. }
  30. $document_id = $document_data['id'];
  31. $dir = $document_data['path'];
  32. /* Constants and variables */
  33. //path for svg-edit save
  34. $_SESSION['draw_dir'] = Security::remove_XSS($dir);
  35. if ($_SESSION['draw_dir']=='/'){
  36. $_SESSION['draw_dir']='';
  37. }
  38. $dir = isset($dir) ? Security::remove_XSS($dir) : Security::remove_XSS($_POST['dir']);
  39. $is_allowed_to_edit = api_is_allowed_to_edit(null, true);
  40. // Please, do not modify this dirname formatting
  41. if (strstr($dir, '..')) {
  42. $dir = '/';
  43. }
  44. if ($dir[0] == '.') {
  45. $dir = substr($dir, 1);
  46. }
  47. if ($dir[0] != '/') {
  48. $dir = '/'.$dir;
  49. }
  50. if ($dir[strlen($dir) - 1] != '/') {
  51. $dir .= '/';
  52. }
  53. $filepath = api_get_path(SYS_COURSE_PATH).$_course['path'].'/document'.$dir;
  54. if (!is_dir($filepath)) {
  55. $filepath = api_get_path(SYS_COURSE_PATH).$_course['path'].'/document/';
  56. $dir = '/';
  57. }
  58. //groups //TODO: clean
  59. if (isset ($_SESSION['_gid']) && $_SESSION['_gid'] != 0) {
  60. $req_gid = '&amp;gidReq='.$_SESSION['_gid'];
  61. $interbreadcrumb[] = array ("url" => "../group/group_space.php?gidReq=".$_SESSION['_gid'], "name" => get_lang('GroupSpace'));
  62. $noPHP_SELF = true;
  63. $to_group_id = $_SESSION['_gid'];
  64. $group = GroupManager :: get_group_properties($to_group_id);
  65. $path = explode('/', $dir);
  66. if ('/'.$path[1] != $group['directory']) {
  67. api_not_allowed(true);
  68. }
  69. }
  70. $interbreadcrumb[] = array ("url" => "./document.php?id=".$parent_id.$req_gid, "name" => get_lang('Documents'));
  71. if (!$is_allowed_in_course) {
  72. api_not_allowed(true);
  73. }
  74. 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()))) {
  75. api_not_allowed(true);
  76. }
  77. /* Header */
  78. event_access_tool(TOOL_DOCUMENT);
  79. $display_dir = $dir;
  80. if (isset ($group)) {
  81. $display_dir = explode('/', $dir);
  82. unset ($display_dir[0]);
  83. unset ($display_dir[1]);
  84. $display_dir = implode('/', $display_dir);
  85. }
  86. // Interbreadcrumb for the current directory root path
  87. // Copied from document.php
  88. $dir_array = explode('/', $dir);
  89. $array_len = count($dir_array);
  90. /*
  91. TODO:check and delete this code
  92. if (!$is_certificate_mode) {
  93. if ($array_len > 1) {
  94. if (empty($_SESSION['_gid'])) {
  95. $url_dir = 'document.php?&curdirpath=/';
  96. $interbreadcrumb[] = array('url' => $url_dir, 'name' => get_lang('HomeDirectory'));
  97. }
  98. }
  99. }
  100. */
  101. $dir_acum = '';
  102. for ($i = 0; $i < $array_len; $i++) {
  103. $url_dir = 'document.php?&curdirpath='.$dir_acum.$dir_array[$i];
  104. //Max char 80
  105. $url_to_who = cut($dir_array[$i],80);
  106. if ($is_certificate_mode) {
  107. $interbreadcrumb[] = array('url' => $url_dir.'&selectcat='.Security::remove_XSS($_GET['selectcat']), 'name' => $url_to_who);
  108. } else {
  109. $interbreadcrumb[] = array('url' => $url_dir, 'name' => $url_to_who);
  110. }
  111. $dir_acum .= $dir_array[$i].'/';
  112. }
  113. Display :: display_header($nameTools, 'Doc');
  114. echo '<div class="actions">';
  115. echo '<a href="document.php?id='.$document_id.'">'.Display::return_icon('back.png',get_lang('BackTo').' '.get_lang('DocumentsOverview'),'','32').'</a>';
  116. echo '</div>';
  117. if (api_browser_support('svg')){
  118. //automatic loading the course language
  119. $svgedit_code_translation_table = array('' => 'en', 'pt' => 'pt-Pt', 'sr' => 'sr_latn');
  120. $langsvgedit = api_get_language_isocode();
  121. $langsvgedit = isset($svgedit_code_translation_table[$langsvgedit]) ? $svgedit_code_translation_table[$langsvgedit] : $langsvgedit;
  122. $langsvgedit = file_exists(api_get_path(LIBRARY_PATH).'svg-edit/locale/lang.'.$langsvgedit.'.js') ? $langsvgedit : 'en';
  123. //editor
  124. echo '<iframe style=\'height: 550px; width: 100%;\' scrolling=\'no\' frameborder=\'0\' src=\''.api_get_path(WEB_LIBRARY_PATH).'svg-edit/svg-editor.php?lang='.$langsvgedit.'\'>';
  125. echo '</iframe>';
  126. } else {
  127. Display::display_error_message(get_lang('BrowserDontSupportsSVG'));
  128. }
  129. Display :: display_footer();