groups.php 4.3 KB

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