groups.php 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  1. <?php
  2. /* Integrate svg-edit libraries with Chamilo default documents
  3. * @author Juan Carlos Raña Trabado
  4. * @since 25/september/2010
  5. */
  6. require_once '../../../../../inc/global.inc.php';
  7. //Add security from Chamilo
  8. api_protect_course_script();
  9. api_block_anonymous_users();
  10. $is_allowed_to_edit = api_is_allowed_to_edit(null, true);
  11. $course_info = api_get_course_info();
  12. $groupId = api_get_group_id();
  13. $group_properties = GroupManager::get_group_properties($groupId);
  14. $groupdirpath = $group_properties['directory'];
  15. $group_disk_path = api_get_path(SYS_COURSE_PATH).$course_info['path'].'/document'.$groupdirpath.'/';
  16. $group_web_path = api_get_path(WEB_COURSE_PATH).$course_info['path'].'/document'.$groupdirpath.'/';
  17. //get all group files and folders
  18. $docs_and_folders = DocumentManager::get_all_document_data(
  19. $course_info,
  20. $groupdirpath,
  21. api_get_group_id(),
  22. null,
  23. $is_allowed_to_edit,
  24. false
  25. );
  26. //get all group filenames
  27. $array_to_search = is_array($docs_and_folders) ? $docs_and_folders : array();
  28. if (count($array_to_search) > 0) {
  29. while (list($key) = each($array_to_search)) {
  30. $all_files[] = basename($array_to_search[$key]['path']);
  31. }
  32. }
  33. //get all svg and png group files
  34. $accepted_extensions = array('.svg', '.png');
  35. if (is_array($all_files) && count($all_files) > 0) {
  36. foreach ($all_files as & $file) {
  37. $slideshow_extension = strrchr($file, '.');
  38. $slideshow_extension = strtolower($slideshow_extension);
  39. if (in_array($slideshow_extension, $accepted_extensions)) {
  40. $png_svg_files[] =$file;
  41. }
  42. }
  43. }
  44. $style = '<style>';
  45. $style .= '@import "'.api_get_path(WEB_CSS_PATH).'base.css";';
  46. $style .= '@import "'.api_get_path(WEB_CSS_PATH).'themes/'.api_get_visual_theme().'/default.css";';
  47. $style .='</style>';
  48. ?>
  49. <!doctype html>
  50. <?php echo api_get_jquery_js(); ?>
  51. <?php echo $style ?>
  52. <body>
  53. <?php
  54. echo '<h2>'.get_lang('GroupSingle').': '.$group_properties['name'].'</h2>';
  55. if ((
  56. $group_properties['doc_state'] == 2 &&
  57. ($is_allowed_to_edit || GroupManager :: is_user_in_group($_user['user_id'], $groupId))) || $group_properties['doc_state'] == 1
  58. ){
  59. if (!empty($png_svg_files)) {
  60. echo '<h3>'.get_lang('SelectSVGEditImage').'</h3>';
  61. echo '<ul>';
  62. foreach($png_svg_files as $filename) {
  63. $image = $group_disk_path.$filename;
  64. if (strpos($filename, "svg")){
  65. $new_sizes['width'] = 60;
  66. $new_sizes['height'] = 60;
  67. } else {
  68. $new_sizes = api_resize_image($image, 60, 60);
  69. }
  70. echo '<li style="display:inline; padding:8px;">';
  71. echo '<a href = "'.$group_web_path.$filename.'" alt="'.$filename.'" title="'.$filename.'">';
  72. echo '<img src = "'.$group_web_path.$filename.'" width = "'.$new_sizes['width'].'" height="'.$new_sizes['height'].'" border="0"></a></li>';
  73. }
  74. echo '</ul>';
  75. }
  76. } else {
  77. echo Display::display_warning_message(get_lang('OnlyAccessFromYourGroup'));
  78. }
  79. ?>
  80. </body>
  81. <script>
  82. $('a').click(function() {
  83. var href = this.href;
  84. // Convert Non-SVG images to data URL first
  85. // (this could also have been done server-side by the library)
  86. if(this.href.indexOf('.svg') === -1) {
  87. var meta_str = JSON.stringify({
  88. name: $(this).text(),
  89. id: href
  90. });
  91. window.top.postMessage(meta_str, "*");
  92. var img = new Image();
  93. img.onload = function() {
  94. var canvas = document.createElement("canvas");
  95. canvas.width = this.width;
  96. canvas.height = this.height;
  97. // load the raster image into the canvas
  98. canvas.getContext("2d").drawImage(this,0,0);
  99. // retrieve the data: URL
  100. try {
  101. var dataurl = canvas.toDataURL();
  102. } catch(err) {
  103. // This fails in Firefox with file:// URLs :(
  104. alert("Data URL conversion failed: " + err);
  105. var dataurl = "";
  106. }
  107. window.top.postMessage('|' + href + '|' + dataurl, "*");
  108. }
  109. img.src = href;
  110. } else {
  111. // Send metadata (also indicates file is about to be sent)
  112. var meta_str = JSON.stringify({
  113. name: $(this).text(),
  114. id: href
  115. });
  116. window.top.postMessage(meta_str, "*");
  117. // Do ajax request for image's href value
  118. $.get(href, function(data) {
  119. data = '|' + href + '|' + data;
  120. // This is where the magic happens!
  121. window.top.postMessage(data, "*");
  122. }, 'html'); // 'html' is necessary to keep returned data as a string
  123. }
  124. return false;
  125. });
  126. </script>