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