From 95643db01425b0b3a50188d352ea271f5e28667e Mon Sep 17 00:00:00 2001 From: wangyidong Date: Tue, 25 Jul 2023 10:32:29 +0800 Subject: [PATCH] * Adjust for export2csv export2html export2xml. --- module/file/control.php | 115 ++++++++++--- module/file/model.php | 2 +- module/file/ui/export.html.php | 2 +- module/file/ui/printfiles.html.php | 88 ---------- module/file/ui/viewfiles.html.php | 238 -------------------------- module/file/view/export2csv.html.php | 28 --- module/file/view/export2html.html.php | 68 -------- module/file/view/export2xml.html.php | 36 ---- 8 files changed, 97 insertions(+), 480 deletions(-) delete mode 100644 module/file/ui/printfiles.html.php delete mode 100644 module/file/ui/viewfiles.html.php delete mode 100644 module/file/view/export2csv.html.php delete mode 100644 module/file/view/export2html.html.php delete mode 100644 module/file/view/export2xml.html.php diff --git a/module/file/control.php b/module/file/control.php index 74fb6ec7ea..0ca9af6fc9 100755 --- a/module/file/control.php +++ b/module/file/control.php @@ -186,9 +186,26 @@ class file extends control */ public function export2CSV() { - $this->view->fields = $this->post->fields; - $this->view->rows = $this->post->rows; - $output = $this->parse('file', 'export2csv'); + $fields = $this->post->fields; + $rows = $this->post->rows; + + /* Build csv content. */ + $output = ''; + if($rows) + { + $output .= '"'. implode('","', $fields) . '"' . "\n"; + foreach($rows as $row) + { + $output .= '"'; + foreach($fields as $fieldName => $fieldLabel) + { + $output .= isset($row->$fieldName) ? str_replace(array('"', ' '), array('“', ' '), htmlspecialchars_decode(strip_tags($row->$fieldName, ''))) : ''; + $output .= '","'; + } + $output .= '"' . "\n"; + } + if($this->post->kind == 'task' && $this->config->vision != 'lite') $output .= $this->lang->file->childTaskTips; + } if($this->post->encode != "utf-8") $output = helper::convertEncoding($output, 'utf-8', $this->post->encode . '//TRANSLIT'); $this->sendDownHeader($this->post->fileName, 'csv', $output); @@ -202,10 +219,26 @@ class file extends control */ public function export2XML() { - $this->view->fields = $this->post->fields; - $this->view->rows = $this->post->rows; + $fields = $this->post->fields; + $rows = $this->post->rows; + $output = "\n"; - $output = $this->parse('file', 'export2XML'); + $output .= ""; + foreach($fields as $fieldName => $fieldLabel) $output .= " <$fieldName>$fieldLabel\n"; + $output .= ""; + + $output .= ""; + foreach($rows as $row) + { + $output .= " \n"; + foreach($fields as $fieldName => $fieldLabel) + { + $fieldValue = isset($row->$fieldName) ? htmlSpecialString($row->$fieldName) : ''; + $output .= " <$fieldName>$fieldValue\n"; + } + $output .= " \n"; + } + $output .= ""; $this->sendDownHeader($this->post->fileName, 'xml', $output); } @@ -218,25 +251,67 @@ class file extends control */ public function export2HTML() { - $this->view->fields = $this->post->fields; - $this->view->rows = $this->post->rows; - $this->host = common::getSysURL(); - $kind = $this->post->kind; + $fields = $this->post->fields; + $rows = $this->post->rows; + $rowspans = $this->post->rowspan ? $this->post->rowspan : array(); + $colspans = $this->post->colspan ? $this->post->colspan : array(); + $host = common::getSysURL(); + $kind = $this->post->kind; + $fileName = $this->post->fileName; - foreach($this->view->rows as $row) + $output = ""; + $output .= ""; + $output .= ""; + $output .= ""; + $output .= "{$fileName}"; + $output .= ""; + + $output .= ""; + if($this->post->kind == 'task') $output .= "
" . $this->lang->file->childTaskTips . '
'; + + $output .= ""; + $output .= ""; + $output .= implode("\n", array_map(function($fieldLabel){return "";}, $fields)); + $output .= ""; + + $i = 0; + foreach($rows as $row) { - foreach($row as &$field) + if(in_array($kind, array('story', 'bug', 'testcase'))) $row->title = html::a($host . $this->createLink($kind, 'view', "{$kind}ID=$row->id"), $row->title); + if($kind == 'task') $row->name = html::a($host . $this->createLink('task', 'view', "taskID=$row->id"), $row->name); + + $output .= "\n"; + $col = 0; + $endColspan = 0; + foreach($fields as $fieldName => $fieldLabel) { - if(empty($field)) continue; - $field = preg_replace('/ src="{([0-9]+)(\.(\w+))?}" /', ' src="' . $this->host . helper::createLink('file', 'read', "fileID=$1", "$3") . '" ', $field); + $col ++; + if(!empty($endColspan) && $col < $endColspan) continue; + if(isset($endRowspan[$fieldName]) && $i < $endRowspan[$fieldName]) continue; + + $fieldValue = isset($row->$fieldName) ? $row->$fieldName : ''; + + $rowspan = ''; + if(isset($rowspans[$i]) && isset($rowspans[$i]['rows'][$fieldName])) + { + $rowspan = "rowspan='{$rowspans[$i]['rows'][$fieldName]}'"; + $endRowspan[$fieldName] = $i + $rowspans[$i]['rows'][$fieldName]; + } + + $colspan = ''; + if(isset($colspans[$i]) && isset($colspans[$i]['cols'][$fieldName])) + { + $colspan = "colspan='{$colspans[$i]['cols'][$fieldName]}'"; + $endColspan = $col + $colspans[$i]['cols'][$fieldName]; + } + + if($fieldValue) $fieldValue = preg_replace('/ src="{([0-9]+)(\.(\w+))?}" /', ' src="' . $host . helper::createLink('file', 'read', "fileID=$1", "$3") . '" ', $fieldValue); + $output .= "\n"; } - - if(in_array($kind, array('story', 'bug', 'testcase'))) $row->title = html::a($this->host . $this->createLink($kind, 'view', "{$kind}ID=$row->id"), $row->title); - if($kind == 'task') $row->name = html::a($this->host . $this->createLink('task', 'view', "taskID=$row->id"), $row->name); + $output .= "\n"; + $i++; } - - $this->view->fileName = $this->post->fileName; - $output = $this->parse('file', 'export2Html'); + $output .= "
$fieldLabel
$fieldValue
"; $this->sendDownHeader($this->post->fileName, 'html', $output); } diff --git a/module/file/model.php b/module/file/model.php index a7185bf0f4..1c260cbbae 100755 --- a/module/file/model.php +++ b/module/file/model.php @@ -1230,7 +1230,7 @@ class fileModel extends model $objectType = zget($this->config->file->objectType, $file->objectType); - $html .= "
  • " . html::a($downloadLink, $fileTitle . " ({$fileSize})", '_blank', "id='fileTitle$file->id' onclick=\"return downloadFile($file->id, '$file->extension', $imageWidth, '$file->title')\""); + $html .= "
  • " . html::a($downloadLink, $fileTitle . " ({$fileSize})", '_blank', "id='fileTitle$file->id' onclick=\"return downloadFile($file->id, '$file->extension', $imageWidth, '$file->title')\""); if(strpos('view,edit', $method) !== false) { if(common::hasPriv($objectType, 'view', $object)) $html = $this->buildFileActions($html, $downloadLink, $imageWidth, $showEdit, $showDelete, $file, $object); diff --git a/module/file/ui/export.html.php b/module/file/ui/export.html.php index b96268b755..7e1f8ba3eb 100644 --- a/module/file/ui/export.html.php +++ b/module/file/ui/export.html.php @@ -85,7 +85,7 @@ if($isCustomExport) set::type('picker'), set::name('exportFields[]'), set::items($exportFieldPairs), - set::defaultValue($selectedFields), + set::value($selectedFields), set::multiple(true), set::required(true), ), diff --git a/module/file/ui/printfiles.html.php b/module/file/ui/printfiles.html.php deleted file mode 100644 index 859da31170..0000000000 --- a/module/file/ui/printfiles.html.php +++ /dev/null @@ -1,88 +0,0 @@ - -* @package file -* @link https://www.zentao.net -*/ - -namespace zin; - -$sessionString = session_name() . '=' . session_id(); - -$liItems = array(); -foreach($files as $file) -{ - if(!common::hasPriv('file', 'download')) continue; - - $uploadDate = $lang->file->uploadDate . substr($file->addedDate, 0, 10); - $fileTitle = $file->title; - if(strpos($file->title, ".{$file->extension}") === false && $file->extension != 'txt') $fileTitle .= ".{$file->extension}"; - - $imageWidth = 0; - if(stripos('jpg|jpeg|gif|png|bmp', $file->extension) !== false) - { - $imageSize = $this->file->getImageSize($file); - $imageWidth = $imageSize[0]; - } - - $fileSize = $this->file->convertFileSize($file->size); - - $downloadLink = $this->createLink('file', 'download', "fileID=$file->id"); - $downloadLink .= strpos($downloadLink, '?') === false ? '?' : '&'; - $downloadLink .= $sessionString; - - $objectType = zget($this->config->file->objectType, $file->objectType); - - $liItems[] = h::li - ( - set::title($uploadDate), - a(set::href($downloadLink), set('onclick', "return downloadFile({$file->id}, '{$file->extension}', $imageWidth, '{$file->title}')"), icon('file-text'), $fileTitle, span(setClass('text-gray'), $fileSize)), - common::hasPriv($objectType, 'edit', $object) ? span - ( - setClass('right-icon'), - common::hasPriv('file', 'edit') ? a(set::style(array('color', '#0c64eb')), set::href(helper::createLink('file', 'edit', "fileID={$file->id}")), set::title($lang->file->edit), set('data-toggle', 'modal'), set('data-size', 'sm'), $lang->file->edit) : null, - common::hasPriv('file', 'delete') ? a(set::style(array('color', '#0c64eb')), set::href(helper::createLink('file', 'delete', "fileID={$file->id}")), set::title($lang->delete), setClass('ajax-submit'), $lang->delete) : null, - ) : null, - ); -} - -h::ul -( - setClass('files-list'), - $liItems, -); - -h::js -( -<< imageWidth) ? ((imageWidth < windowWidth * 0.5) ? windowWidth * 0.5 : imageWidth) : windowWidth; - let checkExtension = fileTitle.lastIndexOf('.' + extension) == (fileTitle.length - extension.length - 1); - - let url = $.createLink('file', 'download', 'fileID=' + fileID + '&mouse=left'); - url += url.indexOf('?') >= 0 ? '&' : '?'; - url += '{$sessionString}'; - - if(fileTypes.indexOf(extension) >= 0 && checkExtension && config.onlybody != 'yes') - { - $('').modalTrigger({url: url, type: 'iframe', width: width}).trigger('click'); - } - else - { - window.open(url, '_blank'); - } - return false; -}; -JAVASCRIPT -); - -render(); diff --git a/module/file/ui/viewfiles.html.php b/module/file/ui/viewfiles.html.php deleted file mode 100644 index e4cdd6b39d..0000000000 --- a/module/file/ui/viewfiles.html.php +++ /dev/null @@ -1,238 +0,0 @@ - -* @package file -* @link https://www.zentao.net -*/ -namespace zin; - -$sessionString = session_name() . '=' . session_id(); - -h::css -( -<<li>a {display: inline; word-wrap: break-word;} -.files-list>li>.right-icon {opacity: 1;} -.fileAction {color: #0c64eb !important;} -.renameFile {display: flex;} -.renameFile .input-group {margin-left: 10px;} -.renameFile .icon {margin-top: 8px;} -.renameFile .input-group-addon {width: 60px;} -.backgroundColor {background: #eff5ff; } -.icon.icon-file-text {padding-left: 7px} -.right-icon .btn {padding: 0 6px;} -CSS -); - -$liItems = array(); -foreach($files as $file) -{ - if(!common::hasPriv('file', 'download')) continue; - - $uploadDate = $lang->file->uploadDate . substr($file->addedDate, 0, 10); - $fileTitle = $file->title; - $fileSize = $this->file->convertFileSize($file->size); - if(strpos($file->title, ".{$file->extension}") === false && $file->extension != 'txt') $fileTitle .= ".{$file->extension}"; - - $imageWidth = 0; - if(stripos('jpg|jpeg|gif|png|bmp', $file->extension) !== false) - { - $imageSize = $this->file->getImageSize($file); - $imageWidth = $imageSize[0]; - } - - $downloadLink = $this->createLink('file', 'download', "fileID=$file->id"); - $downloadLink .= strpos($downloadLink, '?') === false ? '?' : '&'; - $downloadLink .= $sessionString; - - $objectType = zget($this->config->file->objectType, $file->objectType); - - /* Determines whether the file supports preview. */ - if($file->extension == 'txt') - { - $extension = 'txt'; - if(($postion = strrpos($file->title, '.')) !== false) $extension = substr($file->title, $postion + 1); - if($extension != 'txt') $mode = 'down'; - $file->extension = $extension; - } - - $canPreview = false; - if(stripos('txt|jpg|jpeg|gif|png|bmp', $file->extension) !== false) $canPreview = true; - if(isset($this->config->file->libreOfficeTurnon) and $this->config->file->libreOfficeTurnon == 1) - { - $officeTypes = 'doc|docx|xls|xlsx|ppt|pptx|pdf'; - if(stripos($officeTypes, $file->extension) !== false) $canPreview = true; - } - - if(strrpos($file->title, '.') !== false) - { - /* Fix the file name exe.exe */ - $title = explode('.', $file->title); - $extension = end($title); - if($file->extension == 'txt' && $extension != $file->extension) $file->extension = $extension; - array_pop($title); - $file->title = implode('.', $title); - } - - $liItems[] = h::li - ( - setClass('file'), - set::title($uploadDate), - span - ( - setID("fileTitle{$file->id}"), - icon('file-text'), - $fileTitle, - span(setClass('text-gray'), $fileSize), - ), - common::hasPriv($objectType, 'view', $object) ? span - ( - setClass('right-icon hidden'), - ($canPreview) ? a(set::style(array('color', '#0c64eb')), set::href($downloadLink), set('onclick', "return downloadFile({$file->id}, '{$file->extension}', $imageWidth, '{$file->title}')"), set::title($lang->file->preview), icon('eye')) : null, - common::hasPriv('file', 'download') ? a(set::style(array('color', '#0c64eb')), set::href(helper::createLink('file', 'download', "fileID={$file->id}")), set::target('_blank'), set::title($lang->file->downloadFile), icon('download')) : null, - common::hasPriv($objectType, 'edit', $object) && $showEdit && common::hasPriv('file', 'edit') ? a(set::style(array('color', '#0c64eb')), set::href('###'), setClass('edit'), setID("renameFile{$file->id}"), set::title($lang->file->edit), set('onclick', "showRenameBox{$file->id}"), icon('pencil-alt')) : null, - common::hasPriv($objectType, 'edit', $object) && $showDelete && common::hasPriv('file', 'delete') ? a(set::style(array('color', '#0c64eb')), set::href('###'), set::title($lang->delete), set('onclick', "deleteFile($file->id, this)"), icon('trash')) : null, - ) : null, - on::mouseover('showFileActions'), - on::mouseout('hideFileActions'), - ); - $liItems[] = h::li - ( - setClass('file hidden'), - div - ( - setClass('renameFile'), - setID("renameBox{$file->id}"), - icon('file-text'), - inputGroup - ( - input(setID("fileName{$file->id}"), setValue($file->title)), - input(set::type('hidden'), setID("extension{$file->id}"), setValue($file->extension)), - h::strong(setClass('input-group-addon'), ".{$file->extension}"), - ), - div - ( - setClass('input-group-btn'), - btn(setClass('success file-name-confirm'), set::style(array('border-radius' => '0px 2px 2px 0px', 'border-left-color' => 'transparent')), set('onclick', "setFileName($file->id)"), icon('check')), - btn(setClass('gray file-name-cancel'), set::style(array('border-radius' => '0px 2px 2px 0px', 'border-left-color' => 'transparent')), set('onclick', "showFile($file->id)"), icon('close')), - ) - - ) - ); -} - -if($fieldset == 'true') -{ - sectionList - ( - set::title($lang->file->common), - set::content - ( - h::ul - ( - setClass('files-list'), - $liItems, - ) - ) - ); -} -else -{ - h::ul - ( - setClass('files-list'), - $liItems, - ); -} - -$deleteUseForm = ($showDelete && $method == 'edit'); -$isInModal = isInModal(); -h::js -( -<<').attr('type', 'hidden').attr('name', 'deleteFiles[' + fileID + ']').attr('value', fileID).appendTo('ul.files-list'); - $(obj).closest('li.file').addClass('hidden'); - } - else - { - $.ajaxSubmit($.createLink('file', 'delete', 'fileID=' + fileID)); - } -}; - -window.downloadFile = function(fileID, extension, imageWidth, fileTitle) -{ - if(!fileID) return; - let fileTypes = 'txt,jpg,jpeg,gif,png,bmp'; - let windowWidth = $(window).width(); - let width = (windowWidth > imageWidth) ? ((imageWidth < windowWidth * 0.5) ? windowWidth * 0.5 : imageWidth) : windowWidth; - let checkExtension = fileTitle.lastIndexOf('.' + extension) == (fileTitle.length - extension.length - 1); - - let url = $.createLink('file', 'download', 'fileID=' + fileID + '&mouse=left'); - url += url.indexOf('?') >= 0 ? '&' : '?'; - url += '{$sessionString}'; - - if(fileTypes.indexOf(extension) >= 0 && checkExtension && {$isInModal}) - { - $('').modalTrigger({url: url, type: 'iframe', width: width}).trigger('click'); - } - else - { - window.open(url, '_blank'); - } - return false; -}; - -window.showRenameBox = function(fileID) -{ - $('#renameFile' + fileID).closest('li').addClass('hidden'); - $('#renameBox' + fileID).closest('li').removeClass('hidden'); -}; - -window.showFile = function(fileID) -{ - $('#renameBox' + fileID).closest('li').addClass('hidden'); - $('#renameFile' + fileID).closest('li').removeClass('hidden'); -} - -window.setFileName = function(fileID) -{ - let fileName = $('#fileName' + fileID).val(); - let extension = $('#extension' + fileID).val(); - let postData = {'fileName' : fileName, 'extension' : extension}; - $.post($.createLink('file', 'edit', 'fileID=' + fileID), postData, function(data) - { - data = JSON.parse(data); - $('#fileTitle' + fileID).html("  " + data['title']); - $('#renameFile' + fileID).closest('li').removeClass('hidden'); - $('#renameBox' + fileID).closest('li').addClass('hidden'); - }) -} -JAVASCRIPT -); - -render(); diff --git a/module/file/view/export2csv.html.php b/module/file/view/export2csv.html.php deleted file mode 100644 index c009269f34..0000000000 --- a/module/file/view/export2csv.html.php +++ /dev/null @@ -1,28 +0,0 @@ - - * @package file - * @version $Id$ - * @link http://www.zentao.net - */ -?> - $fieldLabel) - { - isset($row->$fieldName) ? print(str_replace(array('"', ' '), array('“', ' '), htmlspecialchars_decode(strip_tags($row->$fieldName, '')))) : print(''); - echo '","'; - } - echo '"' . "\n"; - } -} -if($this->post->kind == 'task' && $config->vision != 'lite') echo $this->lang->file->childTaskTips; diff --git a/module/file/view/export2html.html.php b/module/file/view/export2html.html.php deleted file mode 100644 index 19d092665d..0000000000 --- a/module/file/view/export2html.html.php +++ /dev/null @@ -1,68 +0,0 @@ - - * @package file - * @version $Id$ - * @link http://www.zentao.net - */ -?> - - - - -<?php echo $fileName;?> - -post->kind == 'task') echo "" . $this->lang->file->childTaskTips . '';?> - - - $fieldLabel\n"; - } - ?> - -post->rowspan ? $this->post->rowspan : array(); -$colspans = $this->post->colspan ? $this->post->colspan : array(); -$i = 0; -foreach($rows as $row) -{ - echo "\n"; - $col = 0; - $endColspan = 0; - foreach($fields as $fieldName => $fieldLabel) - { - $col ++; - if(!empty($endColspan) and $col < $endColspan) continue; - if(isset($endRowspan[$fieldName]) and $i < $endRowspan[$fieldName]) continue; - $fieldValue = isset($row->$fieldName) ? $row->$fieldName : ''; - $rowspan = ''; - if(isset($rowspans[$i]) and isset($rowspans[$i]['rows'][$fieldName])) - { - $rowspan = "rowspan='{$rowspans[$i]['rows'][$fieldName]}'"; - $endRowspan[$fieldName] = $i + $rowspans[$i]['rows'][$fieldName]; - } - $colspan = ''; - if(isset($colspans[$i]) and isset($colspans[$i]['cols'][$fieldName])) - { - $colspan = "colspan='{$colspans[$i]['cols'][$fieldName]}'"; - $endColspan = $col + $colspans[$i]['cols'][$fieldName]; - } - echo "\n"; - - } - echo "\n"; - $i++; -} -?> -
    $fieldValue
    - - diff --git a/module/file/view/export2xml.html.php b/module/file/view/export2xml.html.php deleted file mode 100644 index f24bc0dfb7..0000000000 --- a/module/file/view/export2xml.html.php +++ /dev/null @@ -1,36 +0,0 @@ - - * @package file - * @version $Id$ - * @link http://www.zentao.net - */ -?> -\n";?> - - $fieldLabel) -{ - echo " <$fieldName>$fieldLabel\n"; -} -?> - - -\n"; - foreach($fields as $fieldName => $fieldLabel) - { - $fieldValue = isset($row->$fieldName) ? htmlSpecialString($row->$fieldName) : ''; - echo " <$fieldName>$fieldValue\n"; - } - echo " \n"; -} -?> - -