From 8cbc0dcd4ca4cc5342c8cd1d0c7d15221716d3b0 Mon Sep 17 00:00:00 2001 From: fujia Date: Thu, 19 Aug 2010 09:02:39 +0000 Subject: [PATCH] * complete task #299:use default file name when download. + complete task #297:add file delete function to all files. --- module/bug/control.php | 7 +++++++ module/bug/view/view.html.php | 11 ++++++++++- module/doc/view/view.html.php | 24 +++++++++--------------- module/file/control.php | 30 +++++++++++++++++++++++++++--- module/file/view/download.html.php | 19 +++++++++++++++++++ module/story/control.php | 7 +++++++ module/story/view/view.html.php | 11 ++++++++++- module/task/control.php | 7 +++++++ module/task/view/view.html.php | 11 ++++++++++- module/testcase/control.php | 7 +++++++ module/testcase/view/view.html.php | 11 ++++++++++- 11 files changed, 123 insertions(+), 22 deletions(-) create mode 100644 module/file/view/download.html.php diff --git a/module/bug/control.php b/module/bug/control.php index 627a5e9993..729a18c41f 100644 --- a/module/bug/control.php +++ b/module/bug/control.php @@ -529,6 +529,13 @@ class bug extends control } } + /* 删除一个文件。*/ + public function deleteFile($fileID) + { + $this->dao->delete()->from(TABLE_FILE)->where('id')->eq($fileID)->exec(); + die(js::reload('parent')); + } + /* 保存模板。*/ public function saveTemplate() { diff --git a/module/bug/view/view.html.php b/module/bug/view/view.html.php index 4b3e942305..74b4d7509e 100644 --- a/module/bug/view/view.html.php +++ b/module/bug/view/view.html.php @@ -23,6 +23,7 @@ */ ?> +
@@ -56,7 +57,15 @@
bug->legendAttatch;?> -
files as $file) echo html::a($this->createLink('file', 'download', "fileID=$file->id"), $file->title, '_blank');?>
+
+ files as $file) + { + echo html::a($this->createLink('file', 'download', "fileID=$file->id"), $file->title, '_blank', "onclick='return downloadFile($file->id)'"); + echo html::commonButton('x', "onclick=deleteFile($file->id)"); + } + ?> +
diff --git a/module/doc/view/view.html.php b/module/doc/view/view.html.php index 1879540ccc..97ea146ffa 100644 --- a/module/doc/view/view.html.php +++ b/module/doc/view/view.html.php @@ -23,14 +23,8 @@ */ ?> - + +
@@ -57,13 +51,13 @@ function deleteFile(fileID)
title . $lang->colon . $lang->doc->view;?>
files;?> - files as $file) - { - echo html::a($this->createLink('file', 'download', "fileID=$file->id"), $file->title, '_blank'); - echo html::commonButton('x', "onclick=deleteFile($file->id)"); - } - ?> + files as $file) + { + echo html::a($this->createLink('file', 'download', "fileID=$file->id"), $file->title, '_blank', "onclick='return downloadFile($file->id)'"); + echo html::commonButton('x', "onclick=deleteFile($file->id)"); + } + ?>
diff --git a/module/file/control.php b/module/file/control.php index c00e8437a9..26961c8853 100644 --- a/module/file/control.php +++ b/module/file/control.php @@ -32,11 +32,35 @@ class file extends control } /* 下载一个文件。*/ - public function download($fileID) + public function download($fileID, $mouse = '') { $file = $this->file->getById($fileID); - if(file_exists($file->realPath))$this->locate($file->webPath); - $this->app->error("The file you visit $fileID not found.", __FILE__, __LINE__, true); + $fileTypes = array('txt', 'jpg', 'jpeg', 'gif', 'png', 'bmp', 'xml', 'html'); + foreach($fileTypes as $fileType) + { + if($file->extension == $fileType) + { + $download = 'false'; + break; + } + } + if(isset($download) && $mouse == 'left') + { + if(file_exists($file->realPath))$this->locate($file->webPath); + $this->app->error("The file you visit $fileID not found.", __FILE__, __LINE__, true); + } + else + { + if(file_exists($file->realPath)) + { + $fileName = $file->title . '.' . $file->extension; + header('Content-type: application/octet-stream'); + header("Content-Disposition: attachment; filename=$fileName"); + $fileData = file_get_contents($file->realPath); + echo $fileData; + } + $this->app->error("The file you visit $fileID not found.", __FILE__, __LINE__, true); + } } /* 导出csv格式的文件。*/ diff --git a/module/file/view/download.html.php b/module/file/view/download.html.php new file mode 100644 index 0000000000..af7841f56c --- /dev/null +++ b/module/file/view/download.html.php @@ -0,0 +1,19 @@ + + + diff --git a/module/story/control.php b/module/story/control.php index 44267e6159..8450a75fe9 100644 --- a/module/story/control.php +++ b/module/story/control.php @@ -223,6 +223,13 @@ class story extends control } } + /* 删除一个文件。*/ + public function deleteFile($fileID) + { + $this->dao->delete()->from(TABLE_FILE)->where('id')->eq($fileID)->exec(); + die(js::reload('parent')); + } + /* 评审一条需求。*/ public function review($storyID) { diff --git a/module/story/view/view.html.php b/module/story/view/view.html.php index d26eb1cca8..f379775ee1 100644 --- a/module/story/view/view.html.php +++ b/module/story/view/view.html.php @@ -23,6 +23,7 @@ */ ?> +
@@ -54,7 +55,15 @@
story->legendAttatch;?> -
files as $file) echo html::a($this->createLink('file', 'download', "fileID=$file->id"), $file->title, '_blank');?>
+
+ files as $file) + { + echo html::a($this->createLink('file', 'download', "fileID=$file->id"), $file->title, '_blank', "onclick='return downloadFile($file->id)'"); + echo html::commonButton('x', "onclick=deleteFile($file->id)"); + } + ?> +
diff --git a/module/task/control.php b/module/task/control.php index 2cf964117b..13a224b8e3 100644 --- a/module/task/control.php +++ b/module/task/control.php @@ -303,6 +303,13 @@ class task extends control } } + /* 删除一个文件。*/ + public function deleteFile($fileID) + { + $this->dao->delete()->from(TABLE_FILE)->where('id')->eq($fileID)->exec(); + die(js::reload('parent')); + } + /* 发送邮件。*/ private function sendmail($taskID, $actionID) { diff --git a/module/task/view/view.html.php b/module/task/view/view.html.php index efa2e307a8..c7d1cf3f6f 100644 --- a/module/task/view/view.html.php +++ b/module/task/view/view.html.php @@ -23,6 +23,7 @@ */ ?> +
@@ -57,7 +58,15 @@
files;?> -
files as $file) echo html::a($this->createLink('file', 'download', "fileID=$file->id"), $file->title, '_blank');?>
+
+ files as $file) + { + echo html::a($this->createLink('file', 'download', "fileID=$file->id"), $file->title, '_blank', "onclick='return downloadFile($file->id)'"); + echo html::commonButton('x', "onclick=deleteFile($file->id)"); + } + ?> +
diff --git a/module/testcase/control.php b/module/testcase/control.php index 03018a7bba..7ed0514d00 100644 --- a/module/testcase/control.php +++ b/module/testcase/control.php @@ -255,6 +255,13 @@ class testcase extends control } } + /* 删除一个文件。*/ + public function deleteFile($fileID) + { + $this->dao->delete()->from(TABLE_FILE)->where('id')->eq($fileID)->exec(); + die(js::reload('parent')); + } + /* 确认需求变动。*/ public function confirmStoryChange($caseID) { diff --git a/module/testcase/view/view.html.php b/module/testcase/view/view.html.php index 20b7d3a3ec..dd6e1dfddf 100644 --- a/module/testcase/view/view.html.php +++ b/module/testcase/view/view.html.php @@ -24,6 +24,7 @@ ?> +
deleted) echo "class='deleted'";?>> CASE #id . $lang->colon . $case->title;?> @@ -66,7 +67,15 @@
testcase->legendAttatch;?> -
files as $file) echo html::a($this->createLink('file', 'download', "fileID=$file->id"), $file->title, '_blank');?>
+
+ files as $file) + { + echo html::a($this->createLink('file', 'download', "fileID=$file->id"), $file->title, '_blank', "onclick='return downloadFile($file->id)'"); + echo html::commonButton('x', "onclick=deleteFile($file->id)"); + } + ?> +