edit_paint.php 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185
  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. * @todo used the document_id instead of the curdirpath
  8. *
  9. * @author Juan Carlos Ra�a Trabado
  10. * @since 30/january/2011
  11. */
  12. /* INIT SECTION */
  13. $language_file = array('document');
  14. require_once '../inc/global.inc.php';
  15. $_SESSION['whereami'] = 'document/editpaint';
  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. api_protect_course_script();
  20. api_block_anonymous_users();
  21. $document_data = DocumentManager::get_document_data_by_id($_GET['id'], api_get_course_id());
  22. if (empty($document_data)) {
  23. api_not_allowed();
  24. } else {
  25. $document_id = $document_data['id'];
  26. $file_path = $document_data['path'];
  27. $dir = dirname($document_data['path']);
  28. $parent_id = DocumentManager::get_document_id(api_get_course_info(), $dir);
  29. }
  30. $dir= str_replace('\\', '/',$dir);//and urlencode each url $curdirpath (hack clean $curdirpath under Windows - Bug #3261)
  31. /* Constants & Variables */
  32. $current_session_id=api_get_session_id();
  33. //path for pixlr save
  34. $_SESSION['paint_dir']=Security::remove_XSS($dir);
  35. if($_SESSION['paint_dir']=='/'){
  36. $_SESSION['paint_dir']='';
  37. }
  38. $_SESSION['paint_file']=basename(Security::remove_XSS($file_path));
  39. $get_file = Security::remove_XSS($file_path);
  40. $file = basename($get_file);
  41. $temp_file = explode(".",$file);
  42. $filename=$temp_file[0];
  43. $nameTools = get_lang('EditDocument') . ': '.$filename;
  44. $courseDir = $_course['path'].'/document';
  45. $is_allowed_to_edit = api_is_allowed_to_edit(null, true);
  46. /* Other initialization code */
  47. /* Please, do not modify this dirname formatting */
  48. if (strstr($dir, '..')) {
  49. $dir = '/';
  50. }
  51. if ($dir[0] == '.') {
  52. $dir = substr($dir, 1);
  53. }
  54. if ($dir[0] != '/') {
  55. $dir = '/'.$dir;
  56. }
  57. if ($dir[strlen($dir) - 1] != '/') {
  58. $dir .= '/';
  59. }
  60. $filepath = api_get_path(SYS_COURSE_PATH).$_course['path'].'/document'.$dir;
  61. if (!is_dir($filepath)) {
  62. $filepath = api_get_path(SYS_COURSE_PATH).$_course['path'].'/document/';
  63. $dir = '/';
  64. }
  65. //groups //TODO:clean
  66. if (isset ($_SESSION['_gid']) && $_SESSION['_gid'] != 0) {
  67. $req_gid = '&amp;gidReq='.$_SESSION['_gid'];
  68. $interbreadcrumb[] = array ('url' => '../group/group_space.php?gidReq='.$_SESSION['_gid'], 'name' => get_lang('GroupSpace'));
  69. $group_document = true;
  70. $noPHP_SELF = true;
  71. }
  72. if (!$is_certificate_mode)
  73. $interbreadcrumb[]=array("url"=>"./document.php?id=".$document_id.$req_gid, "name"=> get_lang('Documents'));
  74. else
  75. $interbreadcrumb[]= array ( 'url' => '../gradebook/'.$_SESSION['gradebook_dest'], 'name' => get_lang('Gradebook'));
  76. $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);
  77. if (!$is_allowedToEdit) {
  78. api_not_allowed(true);
  79. }
  80. event_access_tool(TOOL_DOCUMENT);
  81. Display :: display_header($nameTools, 'Doc');
  82. echo '<div class="actions">';
  83. echo '<a href="document.php?id='.$parent_id.'">'.Display::return_icon('back.png',get_lang('BackTo').' '.get_lang('DocumentsOverview'),'','32').'</a>';
  84. echo '<a href="edit_document.php?'.api_get_cidreq().'&id='.$document_id.$req_gid.'&origin=editpaint">'.Display::return_icon('edit.png', get_lang('Rename').'/'.get_lang('Comment' ),'','32').'</a>';
  85. echo '</div>';
  86. ///pixlr
  87. $title=$file;//disk name. No sql name because pixlr return this when save
  88. //$image=urlencode(api_get_path(WEB_COURSE_PATH).$courseDir.$dir.$file);//TODO: only work with public courses. Doesn't remove please
  89. //
  90. $pixlr_code_translation_table = array('' => 'en', 'pt' => 'pt-Pt', 'sr' => 'sr_latn');
  91. $langpixlr = api_get_language_isocode();
  92. $langpixlr = isset($pixlr_code_translation_table[$langpixlr]) ? $pixlredit_code_translation_table[$langpixlr] : $langpixlr;
  93. $loc=$langpixlr;// deprecated ?? TODO:check pixlr read user browser
  94. $exit_path=api_get_path(WEB_CODE_PATH).'document/exit_pixlr.php';
  95. $_SESSION['exit_pixlr']= Security::remove_XSS($parent_id);
  96. $referrer="Chamilo";
  97. $target_path=api_get_path(WEB_CODE_PATH).'document/save_pixlr.php';
  98. $target=$target_path;
  99. $locktarget="true";
  100. $locktitle="false";
  101. //make temp images
  102. $temp_folder=api_get_path(SYS_ARCHIVE_PATH).'temp/images';
  103. if (!file_exists($temp_folder)) {
  104. @mkdir($temp_folder, api_get_permissions_for_new_directories(), true);//TODO:check $permissions value, now empty;
  105. }
  106. //make htaccess with allow from all, and file index.html into temp/images
  107. $htaccess=api_get_path(SYS_ARCHIVE_PATH).'temp/images/.htacess';
  108. if (!file_exists($htaccess)) {
  109. $htaccess_content="order deny,allow\r\nallow from all";
  110. $fp = @ fopen(api_get_path(SYS_ARCHIVE_PATH).'temp/images/.htaccess', 'w');
  111. if ($fp) {
  112. fwrite($fp, $htaccess_content);
  113. fclose($fp);
  114. }
  115. }
  116. $html_index=api_get_path(SYS_ARCHIVE_PATH).'temp/images/index.html';
  117. if (!file_exists($html_index)) {
  118. $html_index_content="<html><head></head><body></body></html>";
  119. $fp = @ fopen(api_get_path(SYS_ARCHIVE_PATH).'temp/images/index.html', 'w');
  120. if ($fp) {
  121. fwrite($fp, $html_index_content);
  122. fclose($fp);
  123. }
  124. }
  125. //encript temp name file
  126. $name_crip=sha1(uniqid());//encript
  127. $findext= explode(".", $file);
  128. $extension= $findext[count($findext)-1];
  129. $file_crip=$name_crip.'.'.$extension;
  130. //copy file to temp/images directory
  131. $from=$filepath.$file;
  132. $to=api_get_path(SYS_ARCHIVE_PATH).'temp/images/'.$file_crip;
  133. copy($from, $to);
  134. $_SESSION['temp_realpath_image']=$to;
  135. //load image to url
  136. $to_url=api_get_path(WEB_ARCHIVE_PATH).'temp/images/'.$file_crip;
  137. $image=urlencode($to_url);
  138. $pixlr_url = 'http://pixlr.com/editor/?title='.$title.'&amp;image='.$image.'&amp;loc='.$loc.'&amp;referrer='.$referrer.'&amp;target='.$target.'&amp;exit='.$exit_path.'&amp;locktarget='.$locktarget.'&amp;locktitle='.$locktitle;
  139. //make frame an send image
  140. echo '<iframe style="height: 600px; width: 100%;" scrolling="no" frameborder="0" src="'.$pixlr_url.'">';
  141. echo '</iframe>';
  142. Display::display_footer();