images.php 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227
  1. <?php
  2. /**
  3. * Show a list of images in a long horizontal table.
  4. * @author Wei Zhuo
  5. * @version $Id: images.php,v 1.2 2006/12/16 21:38:13 thierrybo Exp $
  6. * @package ImageManager
  7. */
  8. require_once 'config.inc.php';
  9. require_once 'Classes/ImageManager.php';
  10. //default path is /
  11. $relative = '/images/gallery/';
  12. $manager = new ImageManager($IMConfig);
  13. //process any file uploads
  14. $manager->processUploads();
  15. $manager->deleteFiles();
  16. $refreshDir = false;
  17. //process any directory functions
  18. if ($manager->deleteDirs() || $manager->processNewDir())
  19. $refreshDir = true;
  20. //check for any sub-directory request
  21. //check that the requested sub-directory exists
  22. //and valid
  23. if (isset($_REQUEST['dir'])) {
  24. $path = rawurldecode($_REQUEST['dir']);
  25. if ($manager->validRelativePath($path)) {
  26. $relative = $path;
  27. }
  28. }
  29. $manager = new ImageManager($IMConfig);
  30. //get the list of files and directories
  31. $list = $manager->getFiles($relative);
  32. /* ================= OUTPUT/DRAW FUNCTIONS ======================= */
  33. /**
  34. * Draw the files in an table.
  35. */
  36. function drawFiles($list, &$manager) {
  37. global $relative;
  38. global $IMConfig;
  39. // add filename with course code in it
  40. // here filename is images/gallery/COMES.jpg
  41. // it should be /chamilo1884url/courses/COURSTESTSIMSUURLAPP/document/
  42. global $_configuration;
  43. //var topDoc = window.top.document;
  44. $course_id = api_get_course_id();
  45. $in_course = $course_id != -1 ? true : false;
  46. foreach ($list as $entry => $file) {
  47. ?>
  48. <td><table width="100" cellpadding="0" cellspacing="0"><tr><td class="block">
  49. <!-- change <?php echo $file['relative'];?> with <?php echo $chamiloPath; ?>
  50. <a href="javascript: void(0);" onclick="selectImage('<?php echo $file['relative'];?>', '<?php echo $entry; ?>', <?php echo $file['image'][0];?>, <?php echo $file['image'][1]; ?>);"title="<?php echo $entry; ?> - <?php echo Files::formatSize($file['stat']['size']); ?>"><img src="<?php echo $manager->getThumbnail($file['relative']); ?>" alt="<?php echo $entry; ?> - <?php echo Files::formatSize($file['stat']['size']); ?>"/></a>
  51. -->
  52. <a href="javascript: void(0);" onclick="selectImage('<?php echo $file['relative']; ?>', '<?php echo $entry; ?>', <?php echo $file['image'][0];?>, <?php echo $file['image'][1]; ?>);"title="<?php echo $entry; ?> - <?php echo Files::formatSize($file['stat']['size']); ?>"><img src="<?php echo $manager->getThumbnail($file['relative']); ?>" alt="<?php echo $entry; ?> - <?php echo Files::formatSize($file['stat']['size']); ?>"/></a>
  53. </td></tr><tr><td class="edit" style="padding-top: 5px;">
  54. <?php if ($IMConfig['allow_delete']) { ?>
  55. <a href="images.php?dir=<?php echo $relative; ?>&amp;delf=<?php echo rawurlencode($file['relative']);?>" title="Trash" onclick="return confirmDeleteFile('<?php echo $entry; ?>');"><img src="img/edit_trash.gif" height="15" width="15" alt="Trash"/></a>
  56. <?php } ?>
  57. <?php if ($IMConfig['allow_edit']) { ?>
  58. <a href="javascript: void(0);" title="Edit" onclick="editImage('<?php echo rawurlencode($file['relative']);?>');"><img src="img/edit_pencil.gif" height="15" width="15" alt="Edit"/></a>
  59. <?php } ?>
  60. <?php if($file['image']){ echo $file['image'][0].'x'.$file['image'][1]; } else echo $entry;?>
  61. </td></tr></table></td>
  62. <?php
  63. }//foreach
  64. }//function drawFiles
  65. /**
  66. * Draw the directory.
  67. */
  68. function drawDirs($list, &$manager) {
  69. global $relative;
  70. foreach($list as $path => $dir) { ?>
  71. <td><table width="100" cellpadding="0" cellspacing="0"><tr><td class="block">
  72. <a href="images.php?dir=<?php echo rawurlencode($path); ?>" onclick="updateDir('<?php echo $path; ?>')" title="<?php echo $dir['entry']; ?>"><img src="img/folder.gif" height="80" width="80" alt="<?php echo $dir['entry']; ?>" /></a>
  73. </td></tr><tr>
  74. <td class="edit" style="padding-top: 5px;">
  75. <a href="images.php?dir=<?php echo $relative; ?>&amp;deld=<?php echo rawurlencode($path); ?>" title="Trash" onclick="return confirmDeleteDir('<?php echo $dir['entry']; ?>', <?php echo $dir['count']; ?>);"><img src="img/edit_trash.gif" style="width: 15px; height: 15px;" alt="Trash"/></a>
  76. <?php echo $dir['entry']; ?>
  77. </td>
  78. </tr></table></td>
  79. <?php
  80. } //foreach
  81. }//function drawDirs
  82. /**
  83. * No directories and no files.
  84. */
  85. function drawNoResults()
  86. {
  87. ?>
  88. <table width="100%">
  89. <tr>
  90. <td class="noResult">No Images Found</td>
  91. </tr>
  92. </table>
  93. <?php
  94. }
  95. /**
  96. * No directories and no files.
  97. */
  98. function drawErrorBase(&$manager)
  99. {
  100. ?>
  101. <table width="100%">
  102. <tr>
  103. <td class="error">Invalid base directory: <?php echo $manager->config['base_dir']; ?></td>
  104. </tr>
  105. </table>
  106. <?php
  107. }
  108. ?>
  109. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  110. <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="<?php echo $IMConfig['language']; ?>" lang="<?php echo $IMConfig['language']; ?>">
  111. <head>
  112. <title>Image List</title>
  113. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  114. <link href="assets/imagelist.css" rel="stylesheet" type="text/css" />
  115. <script type="text/javascript" src="assets/dialog.js"></script>
  116. <script type="text/javascript">
  117. /*<![CDATA[*/
  118. //if(window.top)
  119. // I18N = window.top.I18N;
  120. I18N = window.parent.I18N;
  121. function hideMessage()
  122. {
  123. //var topDoc = window.top.document;
  124. var topDoc = window.parent.document;
  125. var messages = topDoc.getElementById('messages');
  126. if(messages)
  127. messages.style.display = "none";
  128. }
  129. init = function()
  130. {
  131. hideMessage();
  132. //var topDoc = window.top.document;
  133. var topDoc = window.parent.document;
  134. <?php
  135. //we need to refesh the drop directory list
  136. //save the current dir, delete all select options
  137. //add the new list, re-select the saved dir.
  138. if($refreshDir)
  139. {
  140. $dirs = $manager->getDirs();
  141. ?>
  142. var selection = topDoc.getElementById('dirPath');
  143. var currentDir = selection.options[selection.selectedIndex].text;
  144. while(selection.length > 0)
  145. { selection.remove(0); }
  146. selection.options[selection.length] = new Option("/","<?php echo rawurlencode('/'); ?>");
  147. <?php foreach($dirs as $relative=>$fullpath) { ?>
  148. selection.options[selection.length] = new Option("<?php echo $relative; ?>","<?php echo rawurlencode($relative); ?>");
  149. <?php } ?>
  150. for(var i = 0; i < selection.length; i++)
  151. {
  152. var thisDir = selection.options[i].text;
  153. if(thisDir == currentDir)
  154. {
  155. selection.selectedIndex = i;
  156. break;
  157. }
  158. }
  159. <?php } ?>
  160. }
  161. function editImage(image)
  162. {
  163. var url = "<?php echo api_get_path(REL_CODE_PATH).'inc/lib/fckeditor/editor/plugins/ImageManager/'; ?>editor.php?img="+image;
  164. if ( window.parent.opener )
  165. {
  166. Dialog(url, function(param)
  167. {
  168. if (!param) // user must have pressed Cancel
  169. return false;
  170. else
  171. {
  172. return true;
  173. }
  174. }, null);
  175. }
  176. else if ( window.parent.oEditor )
  177. {
  178. window.parent.oEditor.OpenDialog( url, null, null, 'FCKDialog_ImageEditor', 'Edit image', 713, 596 );
  179. }
  180. }
  181. /*]]>*/
  182. </script>
  183. <script type="text/javascript" src="assets/images.js"></script>
  184. </head>
  185. <body dir="<?php echo $IMConfig['text_direction']; ?>">
  186. <?php if (!$manager->isValidBase()) { drawErrorBase($manager); }
  187. elseif(count($list[0]) > 0 || count($list[1]) > 0) { ?>
  188. <table>
  189. <tr>
  190. <?php drawDirs($list[0], $manager); ?>
  191. <?php drawFiles($list[1], $manager); ?>
  192. </tr>
  193. </table>
  194. <?php } else { drawNoResults(); } ?>
  195. </body>
  196. </html>