slideshow.php 11 KB

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