printfiles.html.php 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. <?php if($files):?>
  2. <?php $sessionString = session_name() . '=' . session_id();?>
  3. <?php if($fieldset == 'true'):?>
  4. <div class="detail">
  5. <div class="detail-content">
  6. <?php endif;?>
  7. <style>
  8. .files-list>li>a {display: inline; word-wrap: break-word;}
  9. .files-list>li>.right-icon {opacity: 1;}
  10. .fileAction {color: #0c64eb !important;}
  11. </style>
  12. <script>
  13. /* Delete a file. */
  14. function deleteFile(fileID)
  15. {
  16. if(!fileID) return;
  17. hiddenwin.location.href = createLink('file', 'delete', 'fileID=' + fileID);
  18. }
  19. /* Download a file, append the mouse to the link. Thus we call decide to open the file in browser no download it. */
  20. function downloadFile(fileID, extension, imageWidth, fileTitle)
  21. {
  22. if(!fileID) return;
  23. var fileTypes = 'txt,jpg,jpeg,gif,png,bmp';
  24. var windowWidth = $(window).width();
  25. var width = (windowWidth > imageWidth) ? ((imageWidth < windowWidth * 0.5) ? windowWidth * 0.5 : imageWidth) : windowWidth;
  26. var checkExtension = fileTitle.lastIndexOf('.' + extension) == (fileTitle.length - extension.length - 1);
  27. var url = createLink('file', 'download', 'fileID=' + fileID + '&mouse=left');
  28. url += url.indexOf('?') >= 0 ? '&' : '?';
  29. url += '<?php echo $sessionString;?>';
  30. if(fileTypes.indexOf(extension) >= 0 && checkExtension && config.onlybody != 'yes')
  31. {
  32. $('<a>').modalTrigger({url: url, type: 'iframe', width: width}).trigger('click');
  33. }
  34. else
  35. {
  36. url = url.replace('?onlybody=yes&', '?');
  37. url = url.replace('?onlybody=yes', '?');
  38. url = url.replace('&onlybody=yes', '');
  39. window.open(url, '_blank');
  40. }
  41. return false;
  42. }
  43. </script>
  44. <ul class="files-list">
  45. <?php
  46. foreach($files as $file)
  47. {
  48. if(common::hasPriv('file', 'download'))
  49. {
  50. $uploadDate = $lang->file->uploadDate . substr($file->addedDate, 0, 10);
  51. $fileTitle = "<i class='icon icon-file-text'></i> &nbsp;" . $file->title;
  52. if(strpos($file->title, ".{$file->extension}") === false && $file->extension != 'txt') $fileTitle .= ".{$file->extension}";
  53. $imageSize = $this->file->getImageSize($file);
  54. $imageWidth = $imageSize[0];
  55. $fileSize = 0;
  56. /* Show size info. */
  57. if($file->size < 1024)
  58. {
  59. $fileSize = $file->size . 'B';
  60. }
  61. elseif($file->size < 1024 * 1024)
  62. {
  63. $file->size = round($file->size / 1024, 2);
  64. $fileSize = $file->size . 'K';
  65. }
  66. elseif($file->size < 1024 * 1024 * 1024)
  67. {
  68. $file->size = round($file->size / (1024 * 1024), 2);
  69. $fileSize = $file->size . 'M';
  70. }
  71. else
  72. {
  73. $file->size = round($file->size / (1024 * 1024 * 1024), 2);
  74. $fileSize = $file->size . 'G';
  75. }
  76. $downloadLink = $this->createLink('file', 'download', "fileID=$file->id");
  77. $downloadLink .= strpos($downloadLink, '?') === false ? '?' : '&';
  78. $downloadLink .= $sessionString;
  79. echo "<li title='{$uploadDate}'>" . html::a($downloadLink, $fileTitle . " <span class='text-muted'>({$fileSize})</span>", '_blank', "onclick=\"return downloadFile($file->id, '$file->extension', $imageWidth, '$file->title')\"");
  80. $objectType = zget($this->config->file->objectType, $file->objectType);
  81. if(common::hasPriv($objectType, 'edit', $object))
  82. {
  83. echo "<span class='right-icon'>&nbsp; ";
  84. common::printLink('file', 'edit', "fileID=$file->id", $lang->file->edit, '', "data-width='400' class='fileAction btn btn-link edit iframe text-primary' title='{$lang->file->edit}'");
  85. if(common::hasPriv('file', 'delete')) echo html::a('###', $lang->delete, '', "class='fileAction btn btn-link text-primary' onclick='deleteFile($file->id)' title='$lang->delete'");
  86. echo '</span>';
  87. }
  88. echo '</li>';
  89. }
  90. }
  91. ?>
  92. </ul>
  93. <?php if($fieldset == 'true'):?>
  94. </div>
  95. </div>
  96. <?php endif;?>
  97. <?php endif;?>