showfiles.html.php 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327
  1. <?php
  2. /**
  3. * The showFiles view file of doc module of ZenTaoPMS.
  4. *
  5. * @copyright Copyright 2009-2015 禅道软件(青岛)有限公司(ZenTao Software (Qingdao) Co., Ltd. www.cnezsoft.com)
  6. * @license ZPL(http://zpl.pub/page/zplv12.html) or AGPL(https://www.gnu.org/licenses/agpl-3.0.en.html)
  7. * @author Yidong Wang <yidong@cnezsoft.com>
  8. * @package doc
  9. * @version $Id$
  10. * @link http://www.zentao.net
  11. */
  12. ?>
  13. <?php include $this->app->getModuleRoot() . 'common/view/header.html.php';?>
  14. <?php js::set('treeData', $libTree);?>
  15. <?php js::set('docLang', $lang->doc);?>
  16. <?php js::set('libType', 'annex');?>
  17. <?php js::set('canViewFiles', common::hasPriv('doc', 'showfiles'));?>
  18. <?php js::set('linkParams', "objectID=$objectID&%s");?>
  19. <?php js::set('type', $type);?>
  20. <?php js::set('viewType', $viewType);?>
  21. <?php js::set('tab', $this->app->tab);?>
  22. <?php js::set('searchLink', helper::createLink('doc', 'showFiles', "type=$type&objectID=$objectID&viewType=$viewType&orderBy=id_desc&recTotal=0&recPerPage=20&pageID=1&searchTitle=%s"));?>
  23. <div id="mainMenu" class="clearfix">
  24. <div id="leftBar" class="btn-toolbar pull-left">
  25. <?php echo $objectDropdown;?>
  26. <div class='btn-group searchBox'>
  27. <form class="input-control has-icon-right table-col not-watch" method="post">
  28. <?php echo html::input('title', $searchTitle, "class='form-control' placeholder='{$lang->doc->fileTitle}'");?>
  29. <?php echo html::submitButton("<i class='icon icon-search'></i>", '', "btn btn-icon btn-link input-control-icon-right");?>
  30. </form>
  31. </div>
  32. </div>
  33. <div class="btn-toolbar pull-right">
  34. <?php $class = $viewType == 'card' ? 'iframe' : 'export';?>
  35. <?php if(common::hasPriv('doc', 'exportFiles')) echo html::a($this->createLink('doc', 'exportFiles', "objectID=$objectID&objectType=$type", "html", true), "<i class='icon-export muted'> </i>" . $lang->export, '', "class='btn btn-link $class' id='exportFiles'");?>
  36. <div class='btn-group'>
  37. <?php echo html::a(inlink('showFiles', "type=$type&objectID=$objectID&viewType=list&orderBy=$orderBy&recTotal={$pager->recTotal}&recPerPage={$pager->recPerPage}&pageID={$pager->pageID}&searchTitle=$searchTitle"), "<i class='icon icon-bars'></i>", '', "title={$this->lang->doc->browseTypeList['list']} class='btn btn-icon" . ($viewType == 'list' ? ' text-primary' : '') . "' data-app='{$this->app->tab}'");?>
  38. <?php echo html::a(inlink('showFiles', "type=$type&objectID=$objectID&viewType=card&orderBy=$orderBy&recTotal={$pager->recTotal}&recPerPage={$pager->recPerPage}&pageID={$pager->pageID}&searchTitle=$searchTitle"), "<i class='icon icon-cards-view'></i>", '', "title={$this->lang->doc->browseTypeList['grid']} class='btn btn-icon" . ($viewType != 'list' ? ' text-primary' : '') . "' data-app='{$this->app->tab}'");?>
  39. </div>
  40. <?php
  41. if(common::hasPriv('doc', 'createLib'))
  42. {
  43. echo html::a(helper::createLink('doc', 'createLib', "type=$type&objectID=$objectID"), '<i class="icon icon-plus"></i> ' . $this->lang->doc->createLib, '', 'class="btn btn-secondary iframe" data-width="800px"');
  44. }
  45. ?>
  46. </div>
  47. </div>
  48. <div class="main-row fade <?php if(!empty($libTree)) echo 'flex';?>" id="mainContent">
  49. <div id='sideBar' class="panel side side-col col overflow-auto" data-min-width="150">
  50. <?php include $this->app->getModuleRoot() . 'doc/view/lefttree.html.php';?>
  51. </div>
  52. <div class="sidebar-toggle flex-center"><i class="icon icon-angle-left"></i></div>
  53. <div class="main-col flex-full overflow-visible flex-auto" data-min-width="500">
  54. <?php if($viewType == 'list'):?>
  55. <?php if(!empty($files)):?>
  56. <div class='main-table'>
  57. <table class="table has-sort-head" data-ride="table" id='filesTable'>
  58. <thead>
  59. <tr>
  60. <?php $this->app->rawMethod = 'showfiles';?>
  61. <?php $vars = "type=$type&objectID=$objectID&viewType=$viewType&orderBy=%s&recTotal=$pager->recTotal&recPerPage=$pager->recPerPage&pageID=$pager->pageID&searchTitle=$searchTitle";?>
  62. <th class="c-id">
  63. <?php if(common::hasPriv('doc', 'exportFiles')) echo "<div class='checkbox-primary check-all' title='{$this->lang->selectAll}'><label></label></div>";?>
  64. <?php common::printOrderLink('id', $orderBy, $vars, $lang->doc->id);?>
  65. </th>
  66. <th class="c-name"><?php common::printOrderLink('title', $orderBy, $vars, $lang->doc->fileTitle);?></th>
  67. <th class="c-source"><?php common::printOrderLink('objectID', $orderBy, $vars, $lang->doc->source);?></th>
  68. <th class="c-type"><?php common::printOrderLink('extension', $orderBy, $vars, $lang->doc->extension);?></th>
  69. <th class="c-size"><?php common::printOrderLink('size', $orderBy, $vars, $lang->doc->size);?></th>
  70. <th class="c-size"><?php common::printOrderLink('addedBy', $orderBy, $vars, $lang->doc->addedBy);?></th>
  71. <th class="c-size"><?php common::printOrderLink('addedDate', $orderBy, $vars, $lang->doc->addedDate);?></th>
  72. <th class="c-actions-1"><?php echo $lang->actions;?></th>
  73. </tr>
  74. </thead>
  75. <tbody>
  76. <?php foreach($files as $file):?>
  77. <?php if(empty($file->pathname)) continue;?>
  78. <tr>
  79. <?php
  80. $imageSize = $this->file->getImageSize($file);
  81. $imageWidth = isset($imageSize[0]) ? $imageSize[0] : 0;
  82. ?>
  83. <td><?php echo (common::hasPriv('doc', 'exportFiles') ? html::checkbox('fileIdList', array($file->id => '')) : '') . sprintf('%03d', $file->id);?></td>
  84. <td class='c-name' title='<?php echo str_replace('.' . $file->extension, '', $file->title);?>'>
  85. <?php if(in_array($file->extension, $config->file->imageExtensions)):?>
  86. <div style='display: inline-block'><img onload='setImageSize(this, 19)' src='<?php echo $file->webPath;?>' data-extension="<?php echo $file->extension;?>" data-id="<?php echo $file->id;?>" data-width="<?php echo $imageWidth;?>"/></div>
  87. <?php else:?>
  88. <?php echo $fileIcon[$file->id];?>
  89. <?php endif;?>
  90. <?php echo str_replace('.' . $file->extension, '', $file->title);?>
  91. </td>
  92. <td class='c-name'>
  93. <?php
  94. if($file->objectType == 'requirement')
  95. {
  96. $commonTitle = $lang->URCommon . ' : ';
  97. }
  98. elseif(isset($lang->doc->fileType->{$file->objectType}))
  99. {
  100. $commonTitle = $lang->doc->fileType->{$file->objectType};
  101. }
  102. else
  103. {
  104. if(!isset($lang->{$file->objectType}->common)) $app->loadLang($file->objectType);
  105. $commonTitle = $lang->{$file->objectType}->common . ' : ';
  106. }
  107. echo $commonTitle;
  108. ?>
  109. <?php
  110. $isonlybody = $file->objectType != 'doc';
  111. $fileObjectID = isset($sourcePairs[$file->objectType][$file->objectID]) ? $sourcePairs[$file->objectType][$file->objectID] : $file->objectID;
  112. $moduleName = $file->objectType;
  113. $methodName = 'view';
  114. $params = "objectID={$file->objectID}";
  115. if($file->objectType == 'requirement') $moduleName = 'story';
  116. if($file->objectType == 'stepResult')
  117. {
  118. $moduleName = 'testtask';
  119. $methodName = 'results';
  120. $params = "runID=0&caseID={$file->caseID}";
  121. }
  122. ?>
  123. <a title='<?php echo $fileObjectID;?>' href='<?php echo $this->createLink($moduleName, $methodName, $params, '', $isonlybody);?>' class='<?php if($isonlybody) echo "iframe";?>' data-width='90%'><?php echo $fileObjectID;?></a>
  124. </td>
  125. <td><?php echo $file->extension;?></td>
  126. <td><?php echo number_format($file->size / 1024, 1) . 'K';?></td>
  127. <td><?php echo isset($file->addedBy) ? zget($users, $file->addedBy) : '';?></td>
  128. <td><?php echo isset($file->addedDate) ? substr($file->addedDate, 0, 10) : '';?></td>
  129. <td class="c-actions"><?php common::printLink('file', 'download', "fileID=$file->id", '<i class="icon-import"></i>', "", "class='btn' title={$lang->doc->download}", true, false, $file);?></td>
  130. </tr>
  131. <?php endforeach;?>
  132. </tbody>
  133. </table>
  134. </div>
  135. <div class='table-footer'><?php $pager->show('right', 'pagerjs');?></div>
  136. <?php else:?>
  137. <div class='table-empty-tip text-muted'><?php echo $lang->pager->noRecord;?></div>
  138. <?php endif?>
  139. <?php else:?>
  140. <div class="panel block-files block-sm no-margin">
  141. <div class="panel-body">
  142. <div class="row row-grid files-grid" data-size="300">
  143. <?php foreach($files as $file):?>
  144. <?php if(empty($file->pathname)) continue;?>
  145. <div class='col'>
  146. <div class='lib-file'>
  147. <?php
  148. $imageSize = $this->file->getImageSize($file);
  149. $imageWidth = isset($imageSize[0]) ? $imageSize[0] : 0;
  150. $fileID = $file->id;
  151. $url = helper::createLink('file', 'download', 'fileID=' . $fileID);
  152. $url .= strpos($url, '?') === false ? '?' : '&';
  153. $url .= session_name() . '=' . session_id();
  154. ?>
  155. <div class='file'>
  156. <?php if(common::hasPriv('doc', 'exportFiles')) echo html::checkbox('fileIdList', array($file->id => ''), '', "class='fileCheckbox'");?>
  157. <a href='<?php echo $url;?>' title='<?php echo $file->title;?>' target='_blank' onclick="return downloadFile(<?php echo $file->id?>, '<?php echo $file->extension?>', <?php echo $imageWidth?>)">
  158. <?php
  159. $downloadLink = $this->createLink('file', 'download', "fileID=$file->id&mouse=left");
  160. if(in_array($file->extension, $config->file->imageExtensions))
  161. {
  162. echo "<div class='img-holder' style='background-image: url($file->webPath)'><img src='$file->webPath'/></div>";
  163. }
  164. else
  165. {
  166. echo $fileIcon[$file->id];
  167. }
  168. ?>
  169. </a>
  170. <div class='file-name' title='<?php echo $file->title;?>'><?php echo $file->title;?></a></div>
  171. <div class='file-name text-muted'>
  172. <?php
  173. if($file->objectType == 'requirement')
  174. {
  175. $commonTitle = $lang->URCommon . ' : ';
  176. }
  177. else
  178. {
  179. if(!isset($lang->{$file->objectType}->common)) $app->loadLang($file->objectType);
  180. $commonTitle = $lang->{$file->objectType}->common . ' : ';
  181. }
  182. echo $commonTitle;
  183. ?>
  184. <?php $isonlybody = $file->objectType != 'doc';?>
  185. <a href='<?php echo $this->createLink(($file->objectType == 'requirement' ? 'story' : $file->objectType), 'view', "objectID=$file->objectID", '', $isonlybody);?>' title='<?php if(isset($sourcePairs[$file->objectType][$file->objectID])) echo $sourcePairs[$file->objectType][$file->objectID];?>' class='<?php if($isonlybody) echo "iframe";?>' data-width='90%'>
  186. <?php if(isset($sourcePairs[$file->objectType][$file->objectID])) echo $sourcePairs[$file->objectType][$file->objectID];?>
  187. </a>
  188. </div>
  189. </div>
  190. </div>
  191. </div>
  192. <?php endforeach;?>
  193. </div>
  194. <?php if(!empty($files)):?>
  195. <div class='table-footer'><?php $pager->show('right', 'pagerjs');?></div>
  196. <?php else:?>
  197. <div class='table-empty-tip text-muted'><?php echo $lang->pager->noRecord;?></div>
  198. <?php endif?>
  199. </div>
  200. </div>
  201. </div>
  202. <?php endif?>
  203. </div>
  204. </div>
  205. <div class='hidden' id='dropDownData'>
  206. <ul class='libDorpdown'>
  207. <?php if(common::hasPriv('tree', 'browse')):?>
  208. <li data-method="addCataLib" data-has-children='%hasChildren%' data-libid='%libID%' data-moduleid="%moduleID%" data-type="add"><a><i class="icon icon-controls"></i><?php echo $lang->doc->libDropdown['addModule'];?></a></li>
  209. <?php endif;?>
  210. <?php if(common::hasPriv('doc', 'editLib')):?>
  211. <li data-method="editLib"><a href='<?php echo inlink('editLib', 'libID=%libID%');?>' data-toggle='modal' data-type='iframe'><i class="icon icon-edit"></i><?php echo $lang->doc->libDropdown['editLib'];?></a></li>
  212. <?php endif;?>
  213. <?php if(common::hasPriv('doc', 'deleteLib')):?>
  214. <li data-method="deleteLib"><a href='<?php echo inlink('deleteLib', 'libID=%libID%');?>' target='hiddenwin'><i class="icon icon-trash"></i><?php echo $lang->doc->libDropdown['deleteLib'];?></a></li>
  215. <?php endif;?>
  216. </ul>
  217. <ul class='moduleDorpdown'>
  218. <?php if(common::hasPriv('tree', 'browse')):?>
  219. <li data-method="addCataBro" data-type="add" data-id="%moduleID%"><a><i class="icon icon-controls"></i><?php echo $lang->doc->libDropdown['addSameModule'];?></a></li>
  220. <li data-method="addCataChild" data-type="add" data-id="%moduleID%" data-has-children='%hasChildren%'><a><i class="icon icon-edit"></i><?php echo $lang->doc->libDropdown['addSubModule'];?></a></li>
  221. <li data-method="editCata" class='edit-module'><a data-href='<?php echo helper::createLink('tree', 'edit', 'moduleID=%moduleID%&type=doc');?>'><i class="icon icon-edit"></i><?php echo $lang->doc->libDropdown['editModule'];?></a></li>
  222. <li data-method="deleteCata"><a href='<?php echo helper::createLink('tree', 'delete', 'rootID=%libID%&moduleID=%moduleID%');?>' target='hiddenwin'><i class="icon icon-trash"></i><?php echo $lang->doc->libDropdown['delModule'];?></a></li>
  223. <?php endif;?>
  224. </ul>
  225. </div>
  226. <div class='hidden' data-id="ulTreeModal">
  227. <ul data-id="liTreeModal" class="menu-active-primary menu-hover-primary has-input">
  228. <li data-id="insert" class="has-input">
  229. <input data-target="%target%" class="form-control input-tree"></input>
  230. </li>
  231. </ul>
  232. </div>
  233. <div class="hidden" data-id="aTreeModal">
  234. <a href="###" style="position: relative" data-has-children="false" data-action="true" title="%name%" data-id="%id%">
  235. <div class="text h-full w-full flex-between overflow-hidden" style="position: relative;">
  236. <span style="padding-left: 5px;">%name%</span>
  237. <i class="icon icon-drop icon-ellipsis-v tree-icon hidden" data-iscatalogue="true"></i>
  238. </div>
  239. </a>
  240. </div>
  241. <script>
  242. <?php $sessionString = session_name() . '=' . session_id();?>
  243. function downloadFile(fileID, extension, imageWidth)
  244. {
  245. if(!fileID) return;
  246. var fileTypes = 'jpg,jpeg,gif,png,bmp';
  247. var windowWidth = $(window).width();
  248. var url = createLink('file', 'download', 'fileID=' + fileID + '&mouse=left');
  249. url += url.indexOf('?') >= 0 ? '&' : '?';
  250. url += '<?php echo $sessionString;?>';
  251. width = (windowWidth > imageWidth) ? ((imageWidth < windowWidth * 0.5) ? windowWidth * 0.5 : imageWidth) : windowWidth;
  252. if(fileTypes.indexOf(extension) >= 0)
  253. {
  254. $('<a>').modalTrigger({url: url, type: 'iframe', width: width}).trigger('click');
  255. }
  256. else
  257. {
  258. window.open(url, '_self');
  259. }
  260. return false;
  261. }
  262. /**
  263. * Set the max with of image.
  264. *
  265. * @access public
  266. * @return void
  267. */
  268. function setImageSize(image, maxWidth, maxHeight)
  269. {
  270. var $image = $(image);
  271. if($image.parent().prop('tagName').toLowerCase() == 'a') return;
  272. /* If not set maxWidth, set it auto. */
  273. if(!maxWidth)
  274. {
  275. bodyWidth = $('body').width();
  276. maxWidth = bodyWidth - 470; // The side bar's width is 336, and add some margins.
  277. }
  278. if(!maxHeight) maxHeight = $(top.window).height();
  279. setTimeout(function()
  280. {
  281. maxHeightStyle = $image.height() > 0 ? 'max-height:' + maxHeight + 'px' : '';
  282. if(!document.getElementsByClassName('xxc-embed').length && $image.width() > 0 && $image.width() > maxWidth) $image.attr('width', maxWidth);
  283. $image.wrap('<a href="javascript:;" style="display:inline-block;position:relative;overflow:hidden;' + maxHeightStyle + '" onclick="return downloadFile(' + $image.attr('data-id') + ",'" + $image.attr('data-extension') + "', " + $image.attr('data-width') + ')"></a>');
  284. if($image.height() > 0 && $image.height() > maxHeight) $image.closest('a').append("<a href='###' class='showMoreImage' onclick='showMoreImage(this)'>" + lang.expand + " <i class='icon-angle-down'></i></a>");
  285. }, 50);
  286. }
  287. $(function()
  288. {
  289. if(viewType == 'card')
  290. {
  291. var checkedItem = [];
  292. var $checked = $("input[type='checkbox'][name^='fileIdList']");
  293. $checked.click(function()
  294. {
  295. if($(this).prop('checked'))
  296. {
  297. checkedItem.push($(this).val());
  298. }
  299. else
  300. {
  301. checkedItem.splice($.inArray($(this).val(), checkedItem), 1);
  302. }
  303. $.cookie('checkedItem', checkedItem.join(','), {expires: config.cookieLife, path: config.webRoot});
  304. });
  305. $('.file').hover(function()
  306. {
  307. $(this).find('.checkbox-primary').show();
  308. $(this).find('.checkbox-primary').css('display', 'block');
  309. }, function()
  310. {
  311. if($(this).find('.checkbox-primary').find('input').prop('checked')) return;
  312. $(this).find('.checkbox-primary').hide();
  313. $(this).find('.checkbox-primary').css('display', 'none');
  314. })
  315. }
  316. })
  317. </script>
  318. <?php include $this->app->getModuleRoot() . 'common/view/footer.html.php';?>