slideshow.php 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. /**
  4. * @author Patrick Cool
  5. * @author Julio Montoya Lots of improvements, cleaning, adding security
  6. * @package dokeos.document
  7. */
  8. /*
  9. Developped by Patrick Cool
  10. patrick.cool@UGent.be
  11. Ghent University
  12. Mai 2004
  13. http://icto.UGent.be
  14. Improved by Juan Carlos Raña Trabado
  15. herodoto@telefonica.net
  16. January 2008
  17. */
  18. // Language files that need to be included
  19. $language_file = array('slideshow', 'document');
  20. require_once '../inc/global.inc.php';
  21. $noPHP_SELF = true;
  22. $path = Security::remove_XSS($_GET['curdirpath']);
  23. $pathurl = urlencode($path);
  24. $slide_id = Security::remove_XSS($_GET['slide_id']);
  25. if ($path != '/') {
  26. $folder = $path.'/';
  27. } else {
  28. $folder = '/';
  29. }
  30. $sys_course_path = api_get_path(SYS_COURSE_PATH);
  31. // Including the functions for the slideshow
  32. require_once 'slideshow.inc.php';
  33. // Breadcrumb navigation
  34. $url = 'document.php?curdirpath='.$pathurl;
  35. $originaltoolname = get_lang('Documents');
  36. $interbreadcrumb[] = array('url' => Security::remove_XSS($url), 'name' => $originaltoolname);
  37. // Because $nametools uses $_SERVER['PHP_SELF'] for the breadcrumbs instead of $_SERVER['REQUEST_URI'], I had to
  38. // bypass the $nametools thing and use <b></b> tags in the $interbreadcrump array
  39. //$url = 'slideshow.php?curdirpath='.$pathurl;
  40. $originaltoolname = get_lang('SlideShow');
  41. //$interbreadcrumb[] = array('url'=>$url, 'name' => $originaltoolname);
  42. Display :: display_header($originaltoolname, 'Doc');
  43. // Loading the slides from the session
  44. if (isset($_SESSION['image_files_only'])) {
  45. $image_files_only = $_SESSION['image_files_only'];
  46. }
  47. // Calculating the current slide, next slide, previous slide and the number of slides
  48. if ($slide_id != 'all') {
  49. $slide = $slide_id ? $slide_id : 0;
  50. $previous_slide = $slide - 1;
  51. $next_slide = $slide + 1;
  52. }
  53. $total_slides = count($image_files_only);
  54. ?>
  55. <script language="JavaScript" type="text/javascript">
  56. <!--
  57. function MM_openBrWindow(theURL,winName,features) { //v2.0
  58. window.open(theURL,winName,features);
  59. }
  60. //-->
  61. </script>
  62. <div class="actions">
  63. <?php
  64. // Exit the slideshow
  65. echo '<a href="document.php?action=exit_slideshow&curdirpath='.$pathurl.'">'.Display::return_icon('back.png').get_lang('BackTo').' '.get_lang('DocumentsOverview').'</a>&nbsp;';
  66. // Show thumbnails
  67. if ($slide_id != 'all') {
  68. echo '<a href="slideshow.php?slide_id=all&curdirpath='.$pathurl.'"><img src="'.api_get_path(WEB_IMG_PATH).'thumbnails.png" alt="">'.get_lang('_show_thumbnails').'</a>&nbsp;';
  69. } else {
  70. echo '<img src="'.api_get_path(WEB_IMG_PATH).'thumbnails_na.png" alt="">'.get_lang('_show_thumbnails').'&nbsp;';
  71. }
  72. // Slideshow options
  73. echo '<a href="slideshowoptions.php?curdirpath='.$pathurl.'"><img src="'.api_get_path(WEB_IMG_PATH).'acces_tool.gif" alt="">'.get_lang('_set_slideshow_options').'</a> &nbsp;';
  74. ?>
  75. </div>
  76. <?php
  77. echo '<br />';
  78. /* TREATING THE POST DATA FROM SLIDESHOW OPTIONS */
  79. // If we come from slideshowoptions.php we sessionize (new word !!! ;-) the options
  80. if (isset($_POST['Submit'])) {
  81. // We come from slideshowoptions.php
  82. $_SESSION["image_resizing"] = Security::remove_XSS($_POST['radio_resizing']);
  83. if ($_POST['radio_resizing'] == "resizing" && $_POST['width'] != '' && $_POST['height'] != '') {
  84. //echo "resizing";
  85. $_SESSION["image_resizing_width"] = Security::remove_XSS($_POST['width']);
  86. $_SESSION["image_resizing_height"] = Security::remove_XSS($_POST['height']);
  87. } else {
  88. //echo "unsetting the session heighte and width";
  89. $_SESSION["image_resizing_width"] = null;
  90. $_SESSION["image_resizing_height"] = null;
  91. }
  92. }
  93. // The target height and width depends if we choose resizing or no resizing
  94. if ($_SESSION["image_resizing"] == "resizing") {
  95. $target_width = $_SESSION["image_resizing_width"];
  96. $target_height = $_SESSION["image_resizing_height"];
  97. } else {
  98. $image_width = $source_width;
  99. $image_height = $source_height;
  100. }
  101. /* THUMBNAIL VIEW */
  102. // This is for viewing all the images in the slideshow as thumbnails.
  103. $image_tag = array ();
  104. if ($slide_id == 'all') {
  105. $thumbnail_width = 100;
  106. $thumbnail_height = 100;
  107. $row_items = 4;
  108. if (is_array($image_files_only)) {
  109. foreach ($image_files_only as $one_image_file) {
  110. $image = $sys_course_path.$_course['path'].'/document'.$folder.$one_image_file;
  111. if (file_exists($image)) {
  112. $image_height_width = resize_image($image, $thumbnail_width, $thumbnail_height, 1);
  113. $image_height = $image_height_width[0];
  114. $image_width = $image_height_width[1];
  115. $doc_url = ($path && $path !== '/') ? $path.'/'.$one_image_file : $path.$one_image_file;
  116. $image_tag[] = '<img src="download.php?doc_url='.$doc_url.'" border="0" width="'.$image_width.'" height="'.$image_height.'" title="'.$one_image_file.'">';
  117. }
  118. }
  119. }
  120. }
  121. // Creating the table
  122. $html_table = '';
  123. echo '<table align="center" width="760px" border="0" cellspacing="10">';
  124. $i = 0;
  125. $count_image = count($image_tag);
  126. $number_image = 6;
  127. $number_iteration = ceil($count_image/$number_image);
  128. $p = 0;
  129. for ($k = 0; $k < $number_iteration; $k++) {
  130. echo '<tr height="'.$thumbnail_height.'">';
  131. for ($i = 0; $i < $number_image; $i++) {
  132. if (!is_null($image_tag[$p])) {
  133. echo '<td style="border:1px solid; border-color: #CCCCCC #666666 #666666 #CCCCCC;">';
  134. echo '<div align="center"><a href="slideshow.php?slide_id='.$p.'&curdirpath='.$pathurl.' ">'.$image_tag[$p].'</a>';
  135. echo '</div></td>';
  136. }
  137. $p++;
  138. }
  139. echo '</tr>';
  140. }
  141. echo '</table>';
  142. /* ONE AT A TIME VIEW */
  143. // This is for viewing all the images in the slideshow one at a time.
  144. if ($slide_id != 'all') {
  145. $image = $sys_course_path.$_course['path'].'/document'.$folder.$image_files_only[$slide];
  146. if (file_exists($image)) {
  147. $image_height_width = resize_image($image, $target_width, $target_height);
  148. $image_height = $image_height_width[0];
  149. $image_width = $image_height_width[1];
  150. if ($_SESSION['image_resizing'] == 'resizing') {
  151. $height_width_tags = 'width="'.$image_width.'" height="'.$image_height.'"';
  152. }
  153. // Showing the comment of the image, Patrick Cool, 8 april 2005
  154. // This is done really quickly and should be cleaned up a little bit using the API functions
  155. $tbl_documents = Database::get_course_table(TABLE_DOCUMENT);
  156. if ($path == '/') {
  157. $pathpart = '/';
  158. } else {
  159. $pathpart = $path.'/';
  160. }
  161. $sql = "SELECT * FROM $tbl_documents WHERE path='".Database::escape_string($pathpart.$image_files_only[$slide])."'";
  162. $result = Database::query($sql);
  163. $row = Database::fetch_array($result);
  164. echo '<table align="center" border="0" cellspacing="10">';
  165. echo '<tr>';
  166. echo '<td align="center" style="font-size: xx-large; font-weight: bold;">';
  167. echo $row['title'];
  168. echo '</td>';
  169. echo '</tr>';
  170. echo '<tr>';
  171. echo '<td align="center">';
  172. if ($slide < $total_slides - 1 && $slide_id != 'all') {
  173. echo "<a href='slideshow.php?slide_id=".$next_slide."&curdirpath=$pathurl'>";
  174. } else {
  175. echo "<a href='slideshow.php?slide_id=0&curdirpath=$pathurl'>";
  176. }
  177. echo "<img src='download.php?doc_url=$path/".$image_files_only[$slide]."' alt='".$image_files_only[$slide]."' border='0'".$height_width_tags.">";
  178. echo '</a>';
  179. echo '</td>';
  180. echo '</tr>';
  181. echo '<tr>';
  182. echo '<td style="border:1px solid; border-color: #CCCCCC">';
  183. echo $row['comment'];
  184. echo '</td>';
  185. echo '</tr>';
  186. echo '</table>';
  187. echo '<table align="center" border="0">';
  188. if (api_is_allowed_to_edit(null, true)) {
  189. echo '<tr>';
  190. echo '<td align="center">';
  191. echo '<a href="edit_document.php?'.api_get_cidreq().'&curdirpath='.$pathurl.'&amp;origin=slideshow&amp;origin_opt='.$slide_id.'&amp;file='.urlencode($path).'/'.$image_files_only[$slide].'"><img src="../img/edit.gif" border="0" title="'.get_lang('Modify').'" alt="'.get_lang('Modify').'" /></a><br />';
  192. $aux = explode('.', htmlspecialchars($image_files_only[$slide]));
  193. $ext = $aux[count($aux) - 1];
  194. echo $image_files_only[$slide].' <br />';
  195. list($width, $high) = getimagesize($image);
  196. echo $width.' x '.$high.' <br />';
  197. echo round((filesize($image)/1024), 2).' KB';
  198. echo ' - '.$ext;
  199. echo '</td>';
  200. echo '</tr>';
  201. echo '<tr>';
  202. echo '<td align="center">';
  203. if ($_SESSION['image_resizing'] == 'resizing') {
  204. $resize_info = get_lang('_resizing').'<br />';
  205. $resize_widht = $_SESSION["image_resizing_width"].' x ';
  206. $resize_height = $_SESSION['image_resizing_height'];
  207. } else {
  208. $resize_info = get_lang('_no_resizing').'<br />';
  209. }
  210. echo $resize_info;
  211. echo $resize_widht;
  212. echo $resize_height;
  213. echo '</td>';
  214. echo '</tr>';
  215. }
  216. echo '</table>';
  217. echo '<br />';
  218. // Back forward buttons
  219. echo '<table align="center" border="0">';
  220. echo '<tr>';
  221. echo '<td align="center" >';
  222. if ($slide == 0) {
  223. $imgp = 'slide_previous_na.png';
  224. $first = '<img src="'.api_get_path(WEB_IMG_PATH).'slide_first_na.png">';
  225. } else {
  226. $imgp = 'slide_previous.png';
  227. $first = '<a href="slideshow.php?slide_id=0&curdirpath='.$pathurl.'"><img src="'.api_get_path(WEB_IMG_PATH).'slide_first.png" title="'.get_lang('FirstSlide').'" alt="'.get_lang('FirstSlide').'">&nbsp;&nbsp;</a>';
  228. }
  229. // First slide
  230. echo $first;
  231. // Previous slide
  232. if ($slide > 0) {
  233. echo '<a href="slideshow.php?slide_id='.$previous_slide.'&amp;curdirpath='.$pathurl.'">';
  234. }
  235. echo '<img src="'.api_get_path(WEB_IMG_PATH).$imgp.'" title="'.get_lang('Previous').'" alt="'.get_lang('Previous').'">';
  236. if ($slide > 0) {
  237. echo '</a> ';
  238. }
  239. // Divider
  240. if ($slide_id != 'all') {
  241. echo '</td><td valign="middle"> [ '.$next_slide.'/'.$total_slides.' ] </td><td>';
  242. }
  243. // Next slide
  244. if ($slide < $total_slides -1 and $slide_id <> "all") {
  245. echo "<a href='slideshow.php?slide_id=".$next_slide."&curdirpath=$pathurl'>";
  246. }
  247. if ($slide == $total_slides - 1) {
  248. $imgn = 'slide_next_na.png';
  249. $last = '<img src="'.api_get_path(WEB_IMG_PATH).'slide_last_na.png" title="'.get_lang('LastSlide').'" alt="'.get_lang('LastSlide').'">';
  250. } else {
  251. $imgn = 'slide_next.png';
  252. $last = '<a href="slideshow.php?slide_id='.($total_slides-1).'&curdirpath='.$pathurl.'"><img src="'.api_get_path(WEB_IMG_PATH).'slide_last.png" title="'.get_lang('LastSlide').'" alt="'.get_lang('LastSlide').'"></a>';
  253. }
  254. echo '<img src="'.api_get_path(WEB_IMG_PATH).$imgn.'" title="'.get_lang('Next').'" alt="'.get_lang('Next').'">';
  255. if ($slide > 0) {
  256. echo '</a>';
  257. }
  258. // Last slide
  259. echo '&nbsp;&nbsp;'.$last;
  260. echo '</td>';
  261. echo '</tr>';
  262. echo '</table>';
  263. } else {
  264. Display::display_warning_message(get_lang('FileNotFound'));
  265. }
  266. }
  267. Display :: display_footer();