images.php 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228
  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. //$chamiloPath = '/'.$_configuration['url_append'].'/courses/'.api_get_course_path().'/document'.$file['relative'];
  48. ?>
  49. <td><table width="100" cellpadding="0" cellspacing="0"><tr><td class="block">
  50. <!-- change <?php echo $file['relative'];?> with <?php echo $chamiloPath; ?>
  51. <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>
  52. -->
  53. <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>
  54. </td></tr><tr><td class="edit" style="padding-top: 5px;">
  55. <?php if ($IMConfig['allow_delete']) { ?>
  56. <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>
  57. <?php } ?>
  58. <?php if ($IMConfig['allow_edit']) { ?>
  59. <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>
  60. <?php } ?>
  61. <?php if($file['image']){ echo $file['image'][0].'x'.$file['image'][1]; } else echo $entry;?>
  62. </td></tr></table></td>
  63. <?php
  64. }//foreach
  65. }//function drawFiles
  66. /**
  67. * Draw the directory.
  68. */
  69. function drawDirs($list, &$manager) {
  70. global $relative;
  71. foreach($list as $path => $dir) { ?>
  72. <td><table width="100" cellpadding="0" cellspacing="0"><tr><td class="block">
  73. <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>
  74. </td></tr><tr>
  75. <td class="edit" style="padding-top: 5px;">
  76. <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>
  77. <?php echo $dir['entry']; ?>
  78. </td>
  79. </tr></table></td>
  80. <?php
  81. } //foreach
  82. }//function drawDirs
  83. /**
  84. * No directories and no files.
  85. */
  86. function drawNoResults()
  87. {
  88. ?>
  89. <table width="100%">
  90. <tr>
  91. <td class="noResult">No Images Found</td>
  92. </tr>
  93. </table>
  94. <?php
  95. }
  96. /**
  97. * No directories and no files.
  98. */
  99. function drawErrorBase(&$manager)
  100. {
  101. ?>
  102. <table width="100%">
  103. <tr>
  104. <td class="error">Invalid base directory: <?php echo $manager->config['base_dir']; ?></td>
  105. </tr>
  106. </table>
  107. <?php
  108. }
  109. ?>
  110. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  111. <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="<?php echo $IMConfig['language']; ?>" lang="<?php echo $IMConfig['language']; ?>">
  112. <head>
  113. <title>Image List</title>
  114. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  115. <link href="assets/imagelist.css" rel="stylesheet" type="text/css" />
  116. <script type="text/javascript" src="assets/dialog.js"></script>
  117. <script type="text/javascript">
  118. /*<![CDATA[*/
  119. //if(window.top)
  120. // I18N = window.top.I18N;
  121. I18N = window.parent.I18N;
  122. function hideMessage()
  123. {
  124. //var topDoc = window.top.document;
  125. var topDoc = window.parent.document;
  126. var messages = topDoc.getElementById('messages');
  127. if(messages)
  128. messages.style.display = "none";
  129. }
  130. init = function()
  131. {
  132. hideMessage();
  133. //var topDoc = window.top.document;
  134. var topDoc = window.parent.document;
  135. <?php
  136. //we need to refesh the drop directory list
  137. //save the current dir, delete all select options
  138. //add the new list, re-select the saved dir.
  139. if($refreshDir)
  140. {
  141. $dirs = $manager->getDirs();
  142. ?>
  143. var selection = topDoc.getElementById('dirPath');
  144. var currentDir = selection.options[selection.selectedIndex].text;
  145. while(selection.length > 0)
  146. { selection.remove(0); }
  147. selection.options[selection.length] = new Option("/","<?php echo rawurlencode('/'); ?>");
  148. <?php foreach($dirs as $relative=>$fullpath) { ?>
  149. selection.options[selection.length] = new Option("<?php echo $relative; ?>","<?php echo rawurlencode($relative); ?>");
  150. <?php } ?>
  151. for(var i = 0; i < selection.length; i++)
  152. {
  153. var thisDir = selection.options[i].text;
  154. if(thisDir == currentDir)
  155. {
  156. selection.selectedIndex = i;
  157. break;
  158. }
  159. }
  160. <?php } ?>
  161. }
  162. function editImage(image)
  163. {
  164. var url = "<?php echo api_get_path(REL_CODE_PATH).'inc/lib/fckeditor/editor/plugins/ImageManager/'; ?>editor.php?img="+image;
  165. if ( window.parent.opener )
  166. {
  167. Dialog(url, function(param)
  168. {
  169. if (!param) // user must have pressed Cancel
  170. return false;
  171. else
  172. {
  173. return true;
  174. }
  175. }, null);
  176. }
  177. else if ( window.parent.oEditor )
  178. {
  179. window.parent.oEditor.OpenDialog( url, null, null, 'FCKDialog_ImageEditor', 'Edit image', 713, 596 );
  180. }
  181. }
  182. /*]]>*/
  183. </script>
  184. <script type="text/javascript" src="assets/images.js"></script>
  185. </head>
  186. <body dir="<?php echo $IMConfig['text_direction']; ?>">
  187. <?php if (!$manager->isValidBase()) { drawErrorBase($manager); }
  188. elseif(count($list[0]) > 0 || count($list[1]) > 0) { ?>
  189. <table>
  190. <tr>
  191. <?php drawDirs($list[0], $manager); ?>
  192. <?php drawFiles($list[1], $manager); ?>
  193. </tr>
  194. </table>
  195. <?php } else { drawNoResults(); } ?>
  196. </body>
  197. </html>