printcardfiles.html.php 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  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. $imageWidth = 0;
  54. if(stripos('jpg|jpeg|gif|png|bmp', $file->extension) !== false)
  55. {
  56. $imageSize = $this->loadModel('file')->getImageSize($file);
  57. $imageWidth = $imageSize[0];
  58. }
  59. $fileSize = 0;
  60. /* Show size info. */
  61. if($file->size < 1024)
  62. {
  63. $fileSize = $file->size . 'B';
  64. }
  65. elseif($file->size < 1024 * 1024)
  66. {
  67. $file->size = round($file->size / 1024, 2);
  68. $fileSize = $file->size . 'K';
  69. }
  70. elseif($file->size < 1024 * 1024 * 1024)
  71. {
  72. $file->size = round($file->size / (1024 * 1024), 2);
  73. $fileSize = $file->size . 'M';
  74. }
  75. else
  76. {
  77. $file->size = round($file->size / (1024 * 1024 * 1024), 2);
  78. $fileSize = $file->size . 'G';
  79. }
  80. $downloadLink = $this->createLink('file', 'download', "fileID=$file->id");
  81. $downloadLink .= strpos($downloadLink, '?') === false ? '?' : '&';
  82. $downloadLink .= $sessionString;
  83. 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')\"");
  84. $objectType = zget($this->config->file->objectType, $file->objectType);
  85. if(common::hasPriv($objectType, 'edit', $object))
  86. {
  87. echo "<span class='right-icon'>&nbsp; ";
  88. 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}'");
  89. if(common::hasPriv('file', 'delete')) echo html::a('###', $lang->delete, '', "class='fileAction btn btn-link text-primary' onclick='deleteFile($file->id)' title='$lang->delete'");
  90. echo '</span>';
  91. }
  92. echo '</li>';
  93. }
  94. }
  95. ?>
  96. </ul>
  97. <?php if($fieldset == 'true'):?>
  98. </div>
  99. </div>
  100. <?php endif;?>
  101. <?php endif;?>