document_slideshow.inc.php 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. <?php // $Id: document_slideshow.inc.php 16755 2008-11-15 19:50:44Z yannoo $
  2. /*
  3. ==============================================================================
  4. Dokeos - elearning and course management software
  5. Copyright (c) 2004-2008 Dokeos SPRL
  6. Copyright (c) 2003 Ghent University (UGent)
  7. Copyright (c) 2001 Universite catholique de Louvain (UCL)
  8. For a full list of contributors, see "credits.txt".
  9. The full license can be read in "license.txt".
  10. This program is free software; you can redistribute it and/or
  11. modify it under the terms of the GNU General Public License
  12. as published by the Free Software Foundation; either version 2
  13. of the License, or (at your option) any later version.
  14. See the GNU General Public License for more details.
  15. Contact: Dokeos, rue du Corbeau, 108, B-1030 Brussels, Belgium, info@dokeos.com
  16. ==============================================================================
  17. */
  18. /**
  19. * This is a plugin for the documents tool. It looks for .jpg, .jpeg, .gif, .png
  20. * files (since these are the files that can be viewed in a browser) and creates
  21. * a slideshow with it by allowing to go to the next/previous image.
  22. * You can also have a quick overview (thumbnail view) of all the images in
  23. * that particular folder.
  24. *
  25. * Each slideshow is folder based. Only
  26. * the images of the chosen folder are shown.
  27. *
  28. * This file has two large sections.
  29. * 1. code that belongs in document.php, but to avoid clutter I put the code here
  30. * (not present) 2. the function resize_image that handles the image resizing
  31. *
  32. * @author Patrick Cool, responsible author
  33. * @author Roan Embrechts, minor cleanup
  34. * @package dokeos.document
  35. ==============================================================================
  36. */
  37. /*
  38. ==============================================================================
  39. general code that belongs in document.php
  40. this code should indeed go in documents.php but since document.php is already a really ugly file with
  41. too much things in one file , I decided to put the code for document.php here and to include this
  42. file into document.php
  43. ==============================================================================
  44. */
  45. $accepted_extensions = array('.jpg','.jpeg','.gif','.png');
  46. // resetting the images of the slideshow = destroying the slideshow
  47. if (isset($_GET['action']) && $_GET['action']=="exit_slideshow")
  48. {
  49. $_SESSION["image_files_only"]=null;
  50. unset($image_files_only);
  51. }
  52. // We check if there are images in this folder by searching the extensions for .jpg, .gif, .png
  53. // grabbing the list of all the documents of this folder
  54. //$all_files=$fileList['name'];
  55. $array_to_search = (is_array($docs_and_folders))?$docs_and_folders:array();
  56. if(count($array_to_search) > 0) {
  57. while(list ($key) = each ($array_to_search))
  58. {
  59. $all_files[] = basename($array_to_search[$key]['path']);
  60. //echo basename($array_to_search[$key]['path']).'<br>';
  61. }
  62. }
  63. $image_present=0;
  64. if ( count($all_files) > 0 )
  65. {
  66. foreach ($all_files as $file)
  67. {
  68. $slideshow_extension=strrchr($file,".");
  69. $slideshow_extension=strtolower($slideshow_extension);
  70. if (in_array($slideshow_extension,$accepted_extensions))
  71. {
  72. $image_present=1;
  73. $image_files_only[]=$file;
  74. }
  75. }
  76. }
  77. $tablename_column = (isset($_GET['tablename_column'])?$_GET['tablename_column']:0);
  78. if($tablename_column==0){
  79. $tablename_column=1;
  80. }
  81. else{
  82. $tablename_column= intval($tablename_column)-1;
  83. }
  84. $tablename_direction = (isset($_GET['tablename_direction'])?$_GET['tablename_direction']:'ASC');
  85. $image_files_only = sort_files($array_to_search);
  86. $_SESSION["image_files_only"] = $image_files_only;
  87. function sort_files($table){
  88. global $tablename_direction,$accepted_extensions;
  89. $temp=array();
  90. foreach($table as $file_array){
  91. if($file_array['filetype']=='file'){
  92. $slideshow_extension=strrchr($file_array['path'],".");
  93. $slideshow_extension=strtolower($slideshow_extension);
  94. if (in_array($slideshow_extension,$accepted_extensions))
  95. {
  96. $temp[] = array('file', basename($file_array['path']), $file_array['size'], $file_array['insert_date']);
  97. }
  98. }
  99. }
  100. usort($temp, 'sort_table');
  101. if($tablename_direction == 'DESC'){
  102. rsort($temp);
  103. }
  104. $final_array=array();
  105. foreach($temp as $file_array){
  106. $final_array[] = $file_array[1];
  107. }
  108. return $final_array;
  109. }
  110. function sort_table($a, $b)
  111. {
  112. global $tablename_column;
  113. if($a[$tablename_column] > $b[$tablename_column]){
  114. return 1;
  115. }
  116. else{
  117. return -1;
  118. }
  119. }
  120. ?>