From dc8036f2202850e2fee9f302de79c38c59893cf0 Mon Sep 17 00:00:00 2001 From: SJ Date: Wed, 8 Jan 2014 15:22:58 +0100 Subject: [PATCH] download attachments in 1 zip file --- webui/controller/message/attachments.php | 45 +++++++++++++++ webui/model/message/zip.php | 55 +++++++++++++++++++ .../theme/default/templates/message/view.tpl | 2 +- .../theme/mobile/templates/message/view.tpl | 2 +- 4 files changed, 102 insertions(+), 2 deletions(-) create mode 100644 webui/controller/message/attachments.php create mode 100644 webui/model/message/zip.php diff --git a/webui/controller/message/attachments.php b/webui/controller/message/attachments.php new file mode 100644 index 00000000..8cc7670a --- /dev/null +++ b/webui/controller/message/attachments.php @@ -0,0 +1,45 @@ +id = "content"; + $this->template = "message/headers.tpl"; + $this->layout = "common/layout-empty"; + + $request = Registry::get('request'); + $db = Registry::get('db'); + + $this->load->model('search/search'); + $this->load->model('search/message'); + $this->load->model('message/zip'); + + $this->document->title = $this->data['text_message']; + + $this->data['id'] = @$this->request->get['id']; + + if(!verify_piler_id($this->data['id'])) { + AUDIT(ACTION_UNKNOWN, '', '', $this->data['id'], 'unknown id: ' . $this->data['id']); + die("invalid id: " . $this->data['id']); + } + + if(!$this->model_search_search->check_your_permission_by_id($this->data['id'])) { + AUDIT(ACTION_UNAUTHORIZED_VIEW_MESSAGE, '', '', $this->data['id'], ''); + die("no permission for " . $this->data['id']); + } + + $this->data['piler_id'] = $this->model_search_message->get_piler_id_by_id($this->data['id']); + + //AUDIT(ACTION_DOWNLOAD_ATTACHMENT, '', '', $messageid, $this->data['id']); + + $this->model_message_zip->download_attachments_as_zip($this->data['piler_id']); + + exit; + } + + +} + +?> diff --git a/webui/model/message/zip.php b/webui/model/message/zip.php new file mode 100644 index 00000000..d06fbb68 --- /dev/null +++ b/webui/model/message/zip.php @@ -0,0 +1,55 @@ +open($filename, ZIPARCHIVE::CREATE) != true) { exit("cannot open <$filename>\n"); } + + $attachments = $this->model_search_message->get_attachment_list($piler_id); + + foreach($attachments as $a) { + $attachment = $this->model_search_message->get_attachment_by_id($a['id']); + $fp = fopen(DIR_BASE . 'tmp/' . $a['id'], "w+"); + if($fp) { + fwrite($fp, $attachment['attachment']); + fclose($fp); + + $zip->addFile(DIR_BASE . 'tmp/' . $a['id'], $attachment['filename']); + } + } + + $zip->close(); + + + foreach($attachments as $a) { + unlink(DIR_BASE . 'tmp/' . $a['id']); + } + + + + header("Cache-Control: public, must-revalidate"); + header("Pragma: no-cache"); + header("Content-Type: application/zip"); + header("Expires: 0"); + header("Content-Length: " . filesize($filename)); + header("Content-Disposition: attachment; filename=" . $piler_id . ".zip"); + header("Content-Transfer-Encoding: binary\n"); + + readfile($filename); + + unlink($filename); + } + + +} + +?> diff --git a/webui/view/theme/default/templates/message/view.tpl b/webui/view/theme/default/templates/message/view.tpl index f4184e35..67e57dfa 100644 --- a/webui/view/theme/default/templates/message/view.tpl +++ b/webui/view/theme/default/templates/message/view.tpl @@ -48,7 +48,7 @@
  -
+ 1) { ?>|
diff --git a/webui/view/theme/mobile/templates/message/view.tpl b/webui/view/theme/mobile/templates/message/view.tpl index 5a1e5440..180eeae7 100644 --- a/webui/view/theme/mobile/templates/message/view.tpl +++ b/webui/view/theme/mobile/templates/message/view.tpl @@ -48,7 +48,7 @@
-
+ 1) { ?>|