export.html.php 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346
  1. <?php
  2. /**
  3. * The export view file of file module of ZenTaoPMS.
  4. *
  5. * @copyright Copyright 2009-2023 禅道软件(青岛)有限公司(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 Congzhi Chen <congzhi@cnezsoft.com>
  8. * @package file
  9. * @version $Id$
  10. * @link https://www.zentao.net
  11. */
  12. ?>
  13. <?php include $app->getModuleRoot() . 'common/view/header.lite.html.php';?>
  14. <?php include $app->getModuleRoot() . 'common/view/chosen.html.php';?>
  15. <?php $this->app->loadLang('file');?>
  16. <style>
  17. #customFields .panel {border: 1px solid #ddd; background: #fafafa; margin: 0;}
  18. #customFields .panel-actions {padding: 0;}
  19. #customFields .panel {position: relative;}
  20. #customFields .panel:before, #customFields .panel:after {content: ' '; display: block; width: 0; height: 0; border-style: solid; border-width: 0 10px 10px 10px; border-color: transparent transparent #f1f1f1 transparent; position: absolute; left: 315px; top: -9px;}
  21. #customFields .panel:before {border-color: transparent transparent #ddd transparent; top: -10px;}
  22. #mainContent .c-name {width:120px;}
  23. #mainContent .c-fileName {width:300px;}
  24. </style>
  25. <script>
  26. function setDownloading()
  27. {
  28. if(navigator.userAgent.toLowerCase().indexOf("opera") > -1) return true; // Opera don't support, omit it.
  29. var $fileName = $('#fileName');
  30. if($fileName.val() === '') $fileName.val('<?php echo $lang->file->untitled;?>');
  31. $.cookie('downloading', 0);
  32. time = setInterval("closeWindow()", 300);
  33. $('#mainContent').addClass('loading');
  34. return true;
  35. }
  36. function closeWindow()
  37. {
  38. if($.cookie('downloading') == 1)
  39. {
  40. $('#mainContent').removeClass('loading');
  41. parent.$.closeModal();
  42. $.cookie('downloading', null);
  43. clearInterval(time);
  44. }
  45. }
  46. function switchEncode(fileType)
  47. {
  48. var $encode = $('#encode');
  49. if(fileType != 'csv') $encode.val('utf-8').attr('disabled', 'disabled');
  50. else $encode.removeAttr('disabled');
  51. $encode.trigger('chosen:updated');
  52. if(fileType == 'word')
  53. {
  54. $('#tplBox').closest('tr').addClass('hidden');
  55. $('#customFields').addClass('hidden');
  56. }
  57. else
  58. {
  59. $('#tplBox').closest('tr').removeClass('hidden');
  60. }
  61. }
  62. function saveTemplate()
  63. {
  64. var $inputGroup = $('#customFields div.input-group');
  65. var $publicBox = $inputGroup.find('input[id^="public"]');
  66. var title = $inputGroup.find('#title').val();
  67. var content = $('#customFields #exportFields').val();
  68. var isPublic = ($publicBox.size() > 0 && $publicBox.prop('checked')) ? $publicBox.val() : 0;
  69. if(!title || !content) return;
  70. saveTemplateLink = '<?php echo $this->createLink('file', 'ajaxSaveTemplate', 'module=' . $this->moduleName);?>';
  71. $.post(saveTemplateLink, {title:title, content:content, public:isPublic}, function(data)
  72. {
  73. var defaultValue = $('#tplBox #template').val();
  74. $('#tplBox').html(data);
  75. if(data.indexOf('alert') >= 0) $('#tplBox #template').val(defaultValue);
  76. $("#tplBox #template").chosen().on('chosen:showing_dropdown', function()
  77. {
  78. var $this = $(this);
  79. var $chosen = $this.next('.chosen-container').removeClass('chosen-up');
  80. var $drop = $chosen.find('.chosen-drop');
  81. $chosen.toggleClass('chosen-up', $drop.height() + $drop.offset().top - $(document).scrollTop() > $(window).height());
  82. });
  83. $inputGroup.find('#title').val(title);
  84. });
  85. }
  86. /* Set template. */
  87. function setTemplate(templateID)
  88. {
  89. var $template= $('#tplBox #template' + templateID);
  90. var exportFields = $template.size() > 0 ? $template.html() : defaultExportFields;
  91. exportFields = exportFields.split(',');
  92. $('#exportFields').val('');
  93. var optionHtml = '';
  94. for(i in exportFields)
  95. {
  96. $selectedOption = $('#exportFields').find('option[value="' + exportFields[i] + '"]');
  97. optionHtml += $selectedOption.attr('selected', 'selected').prop('outerHTML');
  98. $selectedOption.remove();
  99. }
  100. $('#exportFields option').each(function(){optionHtml += $(this).removeAttr('selected').prop('outerHTML')});
  101. $('#exportFields').html(optionHtml).trigger("chosen:updated");
  102. }
  103. /* Delete template. */
  104. function deleteTemplate()
  105. {
  106. var templateID = $('#tplBox #template').val();
  107. if(templateID == 0) return;
  108. hiddenwin.location.href = createLink('file', 'ajaxDeleteTemplate', 'templateID=' + templateID);
  109. $('#tplBox #template').find('option[value="'+ templateID +'"]').remove();
  110. $('#tplBox #template').trigger("chosen:updated");
  111. $('#tplBox #template').change();
  112. }
  113. /**
  114. * Toggle export template box.
  115. *
  116. * @access public
  117. * @return void
  118. */
  119. function setExportTPL()
  120. {
  121. $('#customFields').toggleClass('hidden');
  122. }
  123. /**
  124. * Set whether part download.
  125. *
  126. * @param input target
  127. * @access public
  128. * @return void
  129. */
  130. function setPart(target)
  131. {
  132. if($(target).prop("checked"))
  133. {
  134. $("#submit").attr("onclick", 'setPartDownloading();');
  135. }
  136. else
  137. {
  138. $("#submit").attr("onclick", 'setDownloading();');
  139. }
  140. }
  141. var partQueue = new Array();
  142. /**
  143. * Set part down and begin the first part down.
  144. *
  145. * @access public
  146. * @return void
  147. */
  148. function setPartDownloading()
  149. {
  150. var partNum = 10000;
  151. var total = $('.pager', window.parent.document).data('rec-total');
  152. for(var i = 0; i < total; i = i + partNum)
  153. {
  154. partQueue.push(i + ',' + partNum);
  155. }
  156. $.cookie('downloading', 0);
  157. $('#mainContent').addClass('loading');
  158. $("#limit").val(partQueue.shift());
  159. $("#submit").attr("onclick", 'startPartDownloading();');
  160. time = setInterval(function()
  161. {
  162. startPartDownloading();
  163. }, 1000);
  164. }
  165. /**
  166. * Start follow-up part down.
  167. *
  168. * @access public
  169. * @return void
  170. */
  171. function startPartDownloading()
  172. {
  173. if($.cookie('downloading') == 1)
  174. {
  175. var limit = partQueue.shift();
  176. if(limit)
  177. {
  178. $.cookie('downloading', 0);
  179. $("#limit").val(limit);
  180. $("#submit").attr("disabled", false).click();
  181. }
  182. else
  183. {
  184. $('#mainContent').removeClass('loading');
  185. parent.$.closeModal();
  186. $.cookie('downloading', null);
  187. clearInterval(time);
  188. }
  189. }
  190. }
  191. $(document).ready(function()
  192. {
  193. $(document).on('change', '#template', function()
  194. {
  195. $('#title').val($(this).find('option:selected').text());
  196. });
  197. $('#fileType').change();
  198. setTimeout(function()
  199. {
  200. if($.cookie('checkedItem') !== '') $('#exportType').val('selected').trigger('chosen:updated');
  201. }, 150);
  202. if($('#customFields #exportFields').length > 0)
  203. {
  204. $('#customFields #exportFields').change(function()
  205. {
  206. setTimeout(function()
  207. {
  208. var optionHtml = '';
  209. var selected = ',';
  210. $('#customFields #exportFields_chosen .chosen-choices li.search-choice').each(function(i)
  211. {
  212. index = $(this).find('.search-choice-close').data('option-array-index');
  213. optionHtml += $('#exportFields option').eq(index).attr('selected', 'selected').prop("outerHTML");
  214. $(this).find('.search-choice-close').attr('data-option-array-index', i);
  215. selected += index + ',';
  216. })
  217. $('#exportFields option').each(function(i)
  218. {
  219. if(selected.indexOf(',' + i + ',') < 0) optionHtml += $(this).removeAttr('selected').prop("outerHTML");
  220. })
  221. $('#exportFields').html(optionHtml).trigger('chosen:updated');
  222. }, 100);
  223. })
  224. }
  225. });
  226. </script>
  227. <?php
  228. $isCustomExport = (!empty($customExport) and !empty($allExportFields));
  229. if($isCustomExport)
  230. {
  231. $allExportFields = explode(',', $allExportFields);
  232. $hasDefaultField = isset($selectedFields);
  233. $selectedFields = $hasDefaultField ? explode(',', $selectedFields) : array();
  234. $exportFieldPairs = array();
  235. $moduleName = $this->moduleName;
  236. $moduleLang = $lang->$moduleName;
  237. foreach($allExportFields as $key => $field)
  238. {
  239. $field = trim($field);
  240. $exportFieldPairs[$field] = isset($moduleLang->$field) ? $moduleLang->$field : (isset($lang->$field) ? $lang->$field : $field);
  241. if(!is_string($exportFieldPairs[$field])) $exportFieldPairs[$field] = $field;
  242. if(!$hasDefaultField)$selectedFields[] = $field;
  243. }
  244. js::set('defaultExportFields', join(',', $selectedFields));
  245. }
  246. ?>
  247. <main id="main">
  248. <div class="container">
  249. <div id="mainContent" class='main-content load-indicator'>
  250. <div class='main-header'>
  251. <h2><?php echo $lang->export;?></h2>
  252. </div>
  253. <form class='main-form' method='post' target='hiddenwin'>
  254. <table class="table table-form">
  255. <tbody>
  256. <tr>
  257. <th class='c-name'><?php echo $lang->file->fileName;?></th>
  258. <td class="c-fileName"><?php echo html::input('fileName', isset($fileName) ? $fileName : '', "class='form-control' autofocus placeholder='{$lang->file->untitled}'");?></td>
  259. <td></td>
  260. </tr>
  261. <tr>
  262. <th><?php echo $lang->file->extension;?></th>
  263. <td><?php echo html::select('fileType', $lang->exportFileTypeList, '', 'onchange=switchEncode(this.value) class="form-control chosen" data-drop_direction="down"');?></td>
  264. </tr>
  265. <tr>
  266. <th><?php echo $lang->file->encoding;?></th>
  267. <td><?php echo html::select('encode', $config->charsets[$this->cookie->lang], 'utf-8', "class='form-control chosen'");?></td>
  268. </tr>
  269. <?php $hide = isset($_SERVER['HTTP_REFERER']) && strpos($_SERVER['HTTP_REFERER'], 'kanban') !== false ? 'style="display:none"' : '';?>
  270. <tr <?php echo $hide;?>>
  271. <th><?php echo $lang->file->exportRange;?></th>
  272. <td>
  273. <?php if(isset($_SERVER['HTTP_REFERER']) && strpos($_SERVER['HTTP_REFERER'], 'calendar') !== false) unset($lang->exportTypeList['selected']);?>
  274. <?php echo html::select('exportType', $lang->exportTypeList, 'all', "class='form-control chosen'");?>
  275. </td>
  276. <td class='checkbox part hidden'>
  277. <?php echo html::checkbox('part', array( 1 => $lang->file->batchExport), '', "onclick='setPart(this);'");?>
  278. <?php echo html::hidden('limit', '');?>
  279. </td>
  280. </tr>
  281. <?php if($isCustomExport):?>
  282. <tr>
  283. <th><?php echo $lang->file->tplTitleAB;?></th>
  284. <td id="tplBox"><?php echo $this->fetch('file', 'buildExportTPL', 'module=' . $this->moduleName);?></td>
  285. <td>
  286. <button type='button' onclick='setExportTPL()' class='btn'><?php echo $lang->file->setExportTPL?></button>
  287. </td>
  288. </tr>
  289. <tr id='customFields' class="hidden">
  290. <th></th>
  291. <td colspan="2">
  292. <div class='panel'>
  293. <div class='panel-heading'>
  294. <strong><?php echo $lang->file->exportFields?></strong>
  295. <div class="panel-actions btn-toolbar">
  296. <button type="button" class="btn btn-link" onclick="setExportTPL()"><i class="icon icon-close icon-sm muted"></i></button>
  297. </div>
  298. </div>
  299. <div class='panel-body'>
  300. <p><?php echo html::select('exportFields[]', $exportFieldPairs, $selectedFields, "class='form-control chosen' multiple")?></p>
  301. <div>
  302. <div class='input-group'>
  303. <span class='input-group-addon'><?php echo $lang->file->tplTitle;?></span>
  304. <?php echo html::input('title', $lang->file->defaultTPL, "class='form-control'")?>
  305. <?php if(common::hasPriv('file', 'setPublic')):?>
  306. <span class='input-group-addon'><?php echo html::checkbox('public', array(1 => $lang->public));?></span>
  307. <?php endif?>
  308. <span class='input-group-btn'><button id='saveTpl' type='button' onclick='saveTemplate()' class='btn btn-primary'><?php echo $lang->save?></button></span>
  309. <span class='input-group-btn'><button type='button' onclick='deleteTemplate()' class='btn'><?php echo $lang->delete?></button></span>
  310. </div>
  311. </div>
  312. </div>
  313. </div>
  314. </td>
  315. </tr>
  316. <?php endif?>
  317. <tr>
  318. <th></th>
  319. <td class='text-center'>
  320. <?php echo html::submitButton($lang->export, "onclick='setDownloading();'", 'btn btn-primary');?>
  321. </td>
  322. </tr>
  323. </tbody>
  324. </table>
  325. </form>
  326. </div>
  327. </div>
  328. </main>
  329. <?php include $app->getModuleRoot() . 'common/view/footer.lite.html.php';?>