1 | <?php |
---|
2 | |
---|
3 | /** |
---|
4 | * ReportDocumentsExport |
---|
5 | * |
---|
6 | * @uses AbsReportExport |
---|
7 | * @final |
---|
8 | * @author Tomasz Świenty |
---|
9 | * @version 0.1 |
---|
10 | * @copyright Copyright (c) BetaSoft |
---|
11 | */ |
---|
12 | final class ReportDocumentsExport extends AbsReportExport implements IReportExporterPlugin { |
---|
13 | |
---|
14 | |
---|
15 | |
---|
16 | |
---|
17 | public function getName() { |
---|
18 | |
---|
19 | return Translator::translate('Eksport listy dokumentów wraz z załącznikami do pliku ZIP (jako paczka do podglądu offline)'); |
---|
20 | |
---|
21 | } |
---|
22 | |
---|
23 | |
---|
24 | |
---|
25 | public function export($params) { |
---|
26 | |
---|
27 | $rep_id = $params['rep_id']; |
---|
28 | $dctpid = isset($params['dctpid']) ? $params['dctpid'] : FALSE; |
---|
29 | $users = isset($params['recipients']) ? $params['recipients'] : FALSE; |
---|
30 | |
---|
31 | if (!$rep_id) { |
---|
32 | return FALSE; |
---|
33 | } |
---|
34 | |
---|
35 | $reportOut = new HTMLReportOutput($rep_id, FALSE); |
---|
36 | |
---|
37 | $reportParams = JSON::toArray($reportOut->report->data['params']); |
---|
38 | $reportParams['compact_mode'] = TRUE; |
---|
39 | $reportOut->report->data['params'] = $reportParams; |
---|
40 | |
---|
41 | $reportHTML = '<style>'.file_get_contents(LIB_PATH.'../css/printOut.css').'</style>'.$reportOut->toHtml(); |
---|
42 | |
---|
43 | $report = $reportOut->report; |
---|
44 | |
---|
45 | $tmpPath = VarPathService::getTmpPath(); |
---|
46 | |
---|
47 | $zipFilePath = $tmpPath.sprintf('eksport_%s.zip', time()); |
---|
48 | $zip = new ZipArchive(); |
---|
49 | if (($res = $zip->open($zipFilePath, ZIPARCHIVE::OVERWRITE)) !== TRUE) { |
---|
50 | trigger_error('creating zip file failed with code: '.$res, E_USER_ERROR); |
---|
51 | } |
---|
52 | |
---|
53 | // trzeba dodać właściwy nagłówek strony |
---|
54 | $zip->addFromString('index.html', '<html><meta http-equiv="Content-type" content="text/html; charset=UTF-8" />'.$reportHTML.'</html>'); |
---|
55 | $zip->addEmptyDir('dokumenty'); |
---|
56 | |
---|
57 | require_once(MOD_PATH.'ADocuments/beans/Document.inc'); |
---|
58 | |
---|
59 | foreach ($report->resultQueries[0] as $data) { |
---|
60 | if (!isset($data['clsnam']) OR ($data['clsnam'] != 'DOCUMENT') OR !isset($data['keyval'])) { |
---|
61 | continue; |
---|
62 | } |
---|
63 | $document = Document::getInstance($data['keyval']); |
---|
64 | $attachments = $document->getAttachmentsID(); |
---|
65 | if ($attachments) { |
---|
66 | foreach ($attachments as $attachment) { |
---|
67 | $file = new File($attachment); |
---|
68 | $location = FileLocation::createByURI($file->URI); |
---|
69 | $path = $location->get($file->URI); |
---|
70 | if (file_exists($path)) { |
---|
71 | $zip->addFromString('dokumenty/fileid_'.$attachment.'.'.end(explode('.', $file->name)), file_get_contents($path)); |
---|
72 | } |
---|
73 | } |
---|
74 | } |
---|
75 | } |
---|
76 | |
---|
77 | $zip->close(); |
---|
78 | |
---|
79 | $js = ''; |
---|
80 | if (($fuid = FileManager::getJSForFileDownloadByContent(file_get_contents($zipFilePath), $js, basename($zipFilePath))) !== FALSE) { |
---|
81 | JScript::registerOnLoad($js); |
---|
82 | } |
---|
83 | |
---|
84 | return $zipFilePath; |
---|
85 | |
---|
86 | } |
---|
87 | |
---|
88 | } // class ReportDocumentsExport |
---|
89 | |
---|
90 | ?> |
---|