viewfiles.html.php 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251
  1. <?php if($files):?>
  2. <?php $sessionString = session_name() . '=' . session_id();?>
  3. <?php if($fieldset == 'true'):?>
  4. <div class="detail">
  5. <div class="detail-title"><?php echo $lang->file->common;?> <i class="icon icon-paper-clip icon-sm"></i></div>
  6. <div class="detail-content">
  7. <?php endif;?>
  8. <style>
  9. .file {padding-top: 2px;}
  10. ul.files-list {margin-bottom: unset}
  11. .files-list>li>a {display: inline; word-wrap: break-word;}
  12. .files-list>li>.right-icon {opacity: 1;}
  13. .fileAction {color: #0c64eb !important;}
  14. .renameFile {display: flex;}
  15. .renameFile .input-group {margin-left: 10px;}
  16. .renameFile .icon {margin-top: 8px;}
  17. .renameFile .input-group-addon {width: 60px;}
  18. .backgroundColor {background: #eff5ff; }
  19. .icon.icon-file-text {padding-left: 7px}
  20. .right-icon .btn {padding: 0 6px;}
  21. li.file:hover .right-icon{display: inline !important;}
  22. </style>
  23. <script>
  24. /**
  25. * Delete a file.
  26. *
  27. * @param int $fileID
  28. * @param object $obj
  29. * @access public
  30. * @return void
  31. */
  32. function deleteFile(fileID, obj)
  33. {
  34. if(!fileID) return;
  35. <?php if($showDelete and $method == 'edit'):?>
  36. $('<input />').attr('type', 'hidden').attr('name', 'deleteFiles[' + fileID + ']').attr('value', fileID).appendTo('ul.files-list');
  37. $(obj).closest('li.file').addClass('hidden');
  38. <?php else:?>
  39. hiddenwin.location.href = createLink('file', 'delete', 'fileID=' + fileID);
  40. <?php endif;?>
  41. }
  42. /**
  43. * Download a file, append the mouse to the link. Thus we call decide to open the file in browser no download it.
  44. *
  45. * @param int $fileID
  46. * @param int $extension
  47. * @param int $imageWidth
  48. * @param string $fileTitle
  49. * @access public
  50. * @return void
  51. */
  52. function downloadFile(fileID, extension, imageWidth, fileTitle)
  53. {
  54. if(!fileID) return;
  55. var fileTypes = 'txt,jpg,jpeg,gif,png,bmp';
  56. var windowWidth = $(window).width();
  57. var width = (windowWidth > imageWidth) ? ((imageWidth < windowWidth * 0.5) ? windowWidth * 0.5 : imageWidth) : windowWidth;
  58. var checkExtension = fileTitle.lastIndexOf('.' + extension) == (fileTitle.length - extension.length - 1);
  59. var url = createLink('file', 'download', 'fileID=' + fileID + '&mouse=left');
  60. url += url.indexOf('?') >= 0 ? '&' : '?';
  61. url += '<?php echo $sessionString;?>';
  62. if(fileTypes.indexOf(extension) >= 0 && checkExtension && config.onlybody != 'yes')
  63. {
  64. $('<a>').modalTrigger({url: url, type: 'iframe', width: width}).trigger('click');
  65. }
  66. else
  67. {
  68. url = url.replace('?onlybody=yes&', '?');
  69. url = url.replace('?onlybody=yes', '?');
  70. url = url.replace('&onlybody=yes', '');
  71. window.open(url, '_blank');
  72. }
  73. return false;
  74. }
  75. /* Show edit box for editing file name. */
  76. /**
  77. * Show edit box for editing file name.
  78. *
  79. * @param int $fileID
  80. * @access public
  81. * @return void
  82. */
  83. function showRenameBox(fileID)
  84. {
  85. $('#renameFile' + fileID).closest('li').addClass('hidden');
  86. $('#renameBox' + fileID).closest('li').removeClass('hidden');
  87. }
  88. /**
  89. * Show File.
  90. *
  91. * @param int $fileID
  92. * @access public
  93. * @return void
  94. */
  95. function showFile(fileID)
  96. {
  97. $('#renameBox' + fileID).closest('li').addClass('hidden');
  98. $('#renameFile' + fileID).closest('li').removeClass('hidden');
  99. }
  100. /**
  101. * Smooth refresh file name.
  102. *
  103. * @param int $fileID
  104. * @access public
  105. * @return void
  106. */
  107. function setFileName(fileID)
  108. {
  109. var fileName = $('#fileName' + fileID).val();
  110. var extension = $('#extension' + fileID).val();
  111. var postData = {'fileName' : fileName, 'extension' : extension};
  112. $.ajax(
  113. {
  114. url:createLink('file', 'edit', 'fileID=' + fileID),
  115. dataType: 'json',
  116. method: 'post',
  117. data: postData,
  118. success: function(data)
  119. {
  120. $('#fileTitle' + fileID).html("<i class='icon icon-file-text'></i> &nbsp;" + data['title']);
  121. $('#renameFile' + fileID).closest('li').removeClass('hidden');
  122. $('#renameBox' + fileID).closest('li').addClass('hidden');
  123. }
  124. })
  125. }
  126. </script>
  127. <ul class="files-list">
  128. <?php foreach($files as $file):?>
  129. <?php if(common::hasPriv('file', 'download')):?>
  130. <?php
  131. $uploadDate = $lang->file->uploadDate . substr($file->addedDate, 0, 10);
  132. $fileTitle = "<i class='icon icon-file-text'></i> &nbsp;" . $file->title;
  133. if(strpos($file->title, ".{$file->extension}") === false && $file->extension != 'txt') $fileTitle .= ".{$file->extension}";
  134. $imageWidth = 0;
  135. if(stripos('jpg|jpeg|gif|png|bmp', $file->extension) !== false)
  136. {
  137. $imageSize = $this->file->getImageSize($file);
  138. $imageWidth = $imageSize[0];
  139. }
  140. $fileSize = 0;
  141. /* Show size info. */
  142. if($file->size < 1024)
  143. {
  144. $fileSize = $file->size . 'B';
  145. }
  146. elseif($file->size < 1024 * 1024)
  147. {
  148. $file->size = round($file->size / 1024, 2);
  149. $fileSize = $file->size . 'K';
  150. }
  151. elseif($file->size < 1024 * 1024 * 1024)
  152. {
  153. $file->size = round($file->size / (1024 * 1024), 2);
  154. $fileSize = $file->size . 'M';
  155. }
  156. else
  157. {
  158. $file->size = round($file->size / (1024 * 1024 * 1024), 2);
  159. $fileSize = $file->size . 'G';
  160. }
  161. $downloadLink = $this->createLink('file', 'download', "fileID=$file->id");
  162. $downloadLink .= strpos($downloadLink, '?') === false ? '?' : '&';
  163. $downloadLink .= $sessionString;
  164. echo "<li class='file' title='{$uploadDate}'>" . html::a($downloadLink, $fileTitle . " <span class='text-muted'>({$fileSize})</span>", '_blank', "id='fileTitle$file->id' onclick=\"return downloadFile($file->id, '$file->extension', $imageWidth, '$file->title')\"");
  165. $objectType = zget($this->config->file->objectType, $file->objectType);
  166. if(common::hasPriv($objectType, 'view', $object))
  167. {
  168. echo "<span class='right-icon' style='display: none'>&nbsp; ";
  169. /* Determines whether the file supports preview. */
  170. if($file->extension == 'txt')
  171. {
  172. $extension = 'txt';
  173. if(($position = strrpos($file->title, '.')) !== false) $extension = substr($file->title, $position + 1);
  174. if($extension != 'txt') $mode = 'down';
  175. $file->extension = $extension;
  176. }
  177. /* For the open source version of the file judgment. */
  178. if(stripos('txt|jpg|jpeg|gif|png|bmp', $file->extension) !== false)
  179. {
  180. echo html::a($downloadLink, "<i class='icon icon-eye'></i>", '_blank', "class='fileAction btn btn-link text-primary' title='{$lang->file->preview}' onclick=\"return downloadFile($file->id, '$file->extension', $imageWidth, '$file->title')\"");
  181. }
  182. /* For the max version of the file judgment. */
  183. if(isset($this->config->file->libreOfficeTurnon) and $this->config->file->libreOfficeTurnon == 1)
  184. {
  185. $officeTypes = 'doc|docx|xls|xlsx|ppt|pptx|pdf';
  186. if(stripos($officeTypes, $file->extension) !== false)
  187. {
  188. echo html::a($downloadLink, "<i class='icon icon-eye'></i>", '_blank', "class='fileAction btn btn-link text-primary' title='{$lang->file->preview}' onclick=\"return downloadFile($file->id, '$file->extension', $imageWidth, '$file->title')\"");
  189. }
  190. }
  191. common::printLink('file', 'download', "fileID=$file->id", "<i class='icon icon-download'></i>", '_blank', "class='fileAction btn btn-link text-primary' title='{$lang->file->downloadFile}'");
  192. if(common::hasPriv($objectType, 'edit', $object))
  193. {
  194. if($showEdit and common::hasPriv('file', 'edit')) echo html::a('###', "<i class='icon icon-pencil-alt'></i>", '', "id='renameFile$file->id' class='fileAction btn btn-link edit text-primary' onclick='showRenameBox($file->id)' title='{$lang->file->edit}'");
  195. if($showDelete and common::hasPriv('file', 'delete')) echo html::a('###', "<i class='icon icon-trash'></i>", '', "class='fileAction btn btn-link text-primary' onclick='deleteFile($file->id, this)' title='$lang->delete'");
  196. }
  197. echo '</span>';
  198. }
  199. echo '</li>';?>
  200. <li class='file hidden'>
  201. <div>
  202. <?php
  203. if(strrpos($file->title, '.') !== false)
  204. {
  205. /* Fix the file name exe.exe */
  206. $title = explode('.', $file->title);
  207. $extension = end($title);
  208. if($file->extension == 'txt' && $extension != $file->extension) $file->extension = $extension;
  209. array_pop($title);
  210. $file->title = join('.', $title);
  211. }
  212. ?>
  213. <div class='renameFile w-300px' id='renameBox<?php echo $file->id;?>'>
  214. <i class='icon icon-file-text'></i>
  215. <div class='input-group'>
  216. <input type="text" id="<?php echo 'fileName' . $file->id?>" value="<?php echo $file->title;?>" class='form-control'/>
  217. <input type="hidden" id="extension<?php echo $file->id?>" value="<?php echo $file->extension;?>"/>
  218. <strong class='input-group-addon'>.<?php echo $file->extension;?></strong>
  219. </div>
  220. <div class="input-group-btn">
  221. <button type="button" class="btn btn-success file-name-confirm" onclick="setFileName(<?php echo $file->id;?>)" style="border-radius: 0px 2px 2px 0px; border-left-color: transparent;"><i class="icon icon-check"></i></button>
  222. <button type="button" class="btn btn-gray file-name-cancel" onclick="showFile(<?php echo $file->id;?>)" style="border-radius: 0px 2px 2px 0px; border-left-color: transparent;"><i class="icon icon-close"></i></button>
  223. </div>
  224. </div>
  225. </div>
  226. </li>
  227. <?php endif;?>
  228. <?php endforeach;?>
  229. </ul>
  230. <?php if($fieldset == 'true'):?>
  231. </div>
  232. </div>
  233. <?php endif;?>
  234. <?php endif;?>