1 | <?php |
---|
2 | |
---|
3 | /** |
---|
4 | * |
---|
5 | * @author Marcin Król |
---|
6 | * @copyright Copyright (c) eDokumenty Sp. z o.o. |
---|
7 | */ |
---|
8 | class MyExcelFile extends DAVBasicFile { |
---|
9 | |
---|
10 | private $fsize = 1; |
---|
11 | |
---|
12 | |
---|
13 | /** |
---|
14 | * |
---|
15 | * @param string $myPath |
---|
16 | */ |
---|
17 | public function __construct($myPath) { |
---|
18 | parent::__construct($myPath); |
---|
19 | |
---|
20 | $data = []; |
---|
21 | $cregid = isset($this->params['cregid']) ? $this->params['cregid'] : NULL; |
---|
22 | $rep_id = isset($this->params['rep_id']) ? $this->params['rep_id'] : NULL; |
---|
23 | if ($cregid) { |
---|
24 | require_once('./classes/Access/services/CRegisterAccessService.inc'); |
---|
25 | |
---|
26 | $accsrv = new CRegisterAccessService($cregid); |
---|
27 | |
---|
28 | $this->isReadable = $accsrv->canReadRegister($cregid, TRUE); |
---|
29 | |
---|
30 | $keyval = isset($this->params['keyval']) ? $this->params['keyval'] : NULL; |
---|
31 | $clsnam = isset($this->params['clsnam']) ? $this->params['clsnam'] : NULL; |
---|
32 | if ($clsnam && $keyval) { |
---|
33 | |
---|
34 | } |
---|
35 | } |
---|
36 | } |
---|
37 | |
---|
38 | /** |
---|
39 | * Updates the data |
---|
40 | * |
---|
41 | * @param resource $data |
---|
42 | * @return void |
---|
43 | */ |
---|
44 | public function put($data) { |
---|
45 | parent::put($data); |
---|
46 | |
---|
47 | $cregid = isset($this->params['cregid']) ? $this->params['cregid'] : NULL; |
---|
48 | if (!$this->params || !$cregid || !ctype_digit((string)$cregid) || !$this->isReadable) throw new Sabre\DAV\Exception\Forbidden(''); |
---|
49 | |
---|
50 | $fileName = time().'.xlsx'; |
---|
51 | $filePath = VarPathService::getTmpPath().$fileName; |
---|
52 | |
---|
53 | file_put_contents($filePath, $data); |
---|
54 | |
---|
55 | require_once('./classes/Access/services/CRegisterAccessService.inc'); |
---|
56 | require_once(MOD_PATH.'CRegisters/beans/CRegisterEntry.inc'); |
---|
57 | include_once(LIB_PATH.'util/excel/ExcelEditor.inc'); |
---|
58 | |
---|
59 | $accsrv = new CRegisterAccessService($cregid); |
---|
60 | |
---|
61 | $excel = new ExcelEditor(); |
---|
62 | $excel->loadFile($filePath); |
---|
63 | $result = $excel->getAllData(); |
---|
64 | |
---|
65 | foreach ($result as $item) { |
---|
66 | $clsnam = isset($item['clsnam']) ? $item['clsnam'] : NULL; |
---|
67 | $keyval = (isset($item['keyval']) && $item['keyval'] && ctype_digit((string)$item['keyval'])) ? $item['keyval'] : NULL; |
---|
68 | $id____ = (isset($item['id____']) && $item['id____'] && ctype_digit((string)$item['id____'])) ? $item['id____'] : $keyval; |
---|
69 | |
---|
70 | if (($id____ && !$accsrv->canChangeEntry($id____, $cregid)) || ($clsnam && ($clsnam != 'CREGISTER_ENTRY'))) { |
---|
71 | continue; |
---|
72 | } |
---|
73 | if (isset($item['clsnam'])) unset($item['clsnam']); |
---|
74 | if (isset($item['keyval'])) unset($item['keyval']); |
---|
75 | |
---|
76 | $bean = new CRegisterEntry($id____, $cregid); |
---|
77 | $bean->data = array_merge($bean->data, $item); |
---|
78 | |
---|
79 | $bean->save(); |
---|
80 | } |
---|
81 | } |
---|
82 | |
---|
83 | public function get() { |
---|
84 | if (!$this->params || !$this->isReadable) throw new Sabre\DAV\Exception\Forbidden(''); |
---|
85 | |
---|
86 | $data = []; |
---|
87 | $cregid = isset($this->params['cregid']) ? $this->params['cregid'] : NULL; |
---|
88 | $rep_id = isset($this->params['rep_id']) ? $this->params['rep_id'] : NULL; |
---|
89 | if ($cregid) { |
---|
90 | $fs = 'cregid = '.$cregid; |
---|
91 | |
---|
92 | $keyval = isset($this->params['keyval']) ? $this->params['keyval'] : NULL; |
---|
93 | $clsnam = isset($this->params['clsnam']) ? $this->params['clsnam'] : NULL; |
---|
94 | if ($clsnam && $keyval) { |
---|
95 | |
---|
96 | } |
---|
97 | require_once(MOD_PATH.'CRegisters/beans/CRegister.inc'); |
---|
98 | require_once('classes/eDokumentyApi/EDokApi.inc'); |
---|
99 | |
---|
100 | $register = new CRegister($cregid); |
---|
101 | |
---|
102 | $api = new EDokApi(); |
---|
103 | if ((count($this->params) == 1) && isset($this->params['cregid'])) { |
---|
104 | $params = ['filter_string' => 'cregid = '.$cregid.'']; |
---|
105 | |
---|
106 | } else { |
---|
107 | $params = $this->params; |
---|
108 | } |
---|
109 | $data = $api->searchRegisterEntries($cregid, '', 0, 0, $params); |
---|
110 | |
---|
111 | include_once(LIB_PATH.'util/excel/ExcelEditor.inc'); |
---|
112 | |
---|
113 | $excel = new ExcelEditor(); |
---|
114 | if ($excel->setData($data)) { |
---|
115 | $fileName = time().'.xlsx'; |
---|
116 | $filePath = VarPathService::getTmpPath().$fileName; |
---|
117 | |
---|
118 | $excel->objPHPExcel->setActiveSheetIndex(0); |
---|
119 | |
---|
120 | $excel->objPHPExcel->getProperties()->setCreator('eDokumenty'); |
---|
121 | $excel->objPHPExcel->getProperties()->setLastModifiedBy(SysContext::$usr_info['fullnm']); |
---|
122 | $excel->objPHPExcel->getProperties()->setTitle($register->get('name__')); |
---|
123 | $excel->objPHPExcel->getProperties()->setSubject($register->get('name__')); |
---|
124 | $excel->objPHPExcel->getProperties()->setDescription($register->get('dscrpt')); |
---|
125 | |
---|
126 | $excel->objPHPExcel->getProperties()->setCustomProperty('eDokumenty_RegisterID', $cregid); |
---|
127 | |
---|
128 | $excel->save($filePath); |
---|
129 | |
---|
130 | $f = fopen($filePath, 'rb'); |
---|
131 | |
---|
132 | fseek($f, 0, SEEK_END); |
---|
133 | $this->fsize = ftell($f); |
---|
134 | |
---|
135 | fseek($f, 0, SEEK_SET); |
---|
136 | |
---|
137 | return $f; |
---|
138 | } |
---|
139 | } else { |
---|
140 | |
---|
141 | } |
---|
142 | if (empty($data)) throw new Sabre\DAV\Exception\Forbidden('Zero file size!'); |
---|
143 | } |
---|
144 | |
---|
145 | public function getSize() { |
---|
146 | return $this->fsize; |
---|
147 | } |
---|
148 | |
---|
149 | /** |
---|
150 | * |
---|
151 | */ |
---|
152 | public function getContentType() { |
---|
153 | $type = 'application/xlsx'; |
---|
154 | return $type; |
---|
155 | } |
---|
156 | |
---|
157 | } |
---|
158 | |
---|
159 | DAVBasicDirectory::setFileClass('MyExcelFile'); |
---|