|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* (c) Kitodo. Key to digital objects e.V. <[email protected]> |
|
5
|
|
|
* |
|
6
|
|
|
* This file is part of the Kitodo and TYPO3 projects. |
|
7
|
|
|
* |
|
8
|
|
|
* @license GNU General Public License version 3 or later. |
|
9
|
|
|
* For the full copyright and license information, please read the |
|
10
|
|
|
* LICENSE.txt file that was distributed with this source code. |
|
11
|
|
|
*/ |
|
12
|
|
|
|
|
13
|
|
|
namespace Kitodo\Dlf\Controller; |
|
14
|
|
|
|
|
15
|
|
|
use Kitodo\Dlf\Common\Document; |
|
16
|
|
|
use Kitodo\Dlf\Common\Helper; |
|
17
|
|
|
use TYPO3\CMS\Core\Database\Connection; |
|
18
|
|
|
use TYPO3\CMS\Core\Database\ConnectionPool; |
|
19
|
|
|
use TYPO3\CMS\Core\Utility\GeneralUtility; |
|
20
|
|
|
use TYPO3\CMS\Extbase\Utility\LocalizationUtility; |
|
21
|
|
|
|
|
22
|
|
|
class BasketController extends AbstractController |
|
23
|
|
|
{ |
|
24
|
|
|
/** |
|
25
|
|
|
* Different actions which depends on the choosen action (form) |
|
26
|
|
|
* |
|
27
|
|
|
* @return void |
|
28
|
|
|
*/ |
|
29
|
|
|
public function basketAction() |
|
30
|
|
|
{ |
|
31
|
|
|
$requestData = GeneralUtility::_GPmerged('tx_dlf'); |
|
32
|
|
|
unset($requestData['__referrer'], $requestData['__trustedProperties']); |
|
33
|
|
|
|
|
34
|
|
|
$basketData = $this->getBasketData(); |
|
35
|
|
|
|
|
36
|
|
|
// action remove from basket |
|
37
|
|
|
if ($requestData['basket_action'] === 'remove') { |
|
38
|
|
|
// remove entry from list |
|
39
|
|
|
if (isset($requestData['selected'])) { |
|
40
|
|
|
$basketData = $this->removeFromBasket($requestData, $basketData); |
|
41
|
|
|
} |
|
42
|
|
|
} |
|
43
|
|
|
// action remove from basket |
|
44
|
|
|
if ($requestData['basket_action'] == 'download') { |
|
45
|
|
|
// open selected documents |
|
46
|
|
|
if (isset($requestData['selected'])) { |
|
47
|
|
|
$pdfUrl = $this->settings['pdfgenerate']; |
|
48
|
|
|
foreach ($requestData['selected'] as $docValue) { |
|
49
|
|
|
if ($docValue['id']) { |
|
50
|
|
|
$docData = $this->getDocumentData($docValue['id'], $docValue); |
|
51
|
|
|
$pdfUrl .= $docData['urlParams'] . $this->settings['pdfparamseparator']; |
|
52
|
|
|
$this->redirectToUri($pdfUrl); |
|
53
|
|
|
} |
|
54
|
|
|
} |
|
55
|
|
|
} |
|
56
|
|
|
} |
|
57
|
|
|
// action print from basket |
|
58
|
|
|
if ($requestData['print_action']) { |
|
59
|
|
|
// open selected documents |
|
60
|
|
|
if (isset($requestData['selected'])) { |
|
61
|
|
|
$this->printDocument($requestData, $basketData); |
|
62
|
|
|
} |
|
63
|
|
|
} |
|
64
|
|
|
// action send mail |
|
65
|
|
|
if ($requestData['mail_action']) { |
|
66
|
|
|
if (isset($requestData['selected'])) { |
|
67
|
|
|
$this->sendMail($requestData); |
|
68
|
|
|
} |
|
69
|
|
|
} |
|
70
|
|
|
|
|
71
|
|
|
$this->redirect('main'); |
|
72
|
|
|
} |
|
73
|
|
|
|
|
74
|
|
|
/** |
|
75
|
|
|
* Add documents to the basket |
|
76
|
|
|
* |
|
77
|
|
|
* @return void |
|
78
|
|
|
*/ |
|
79
|
|
|
public function addAction() |
|
80
|
|
|
{ |
|
81
|
|
|
$requestData = GeneralUtility::_GPmerged('tx_dlf'); |
|
82
|
|
|
unset($requestData['__referrer'], $requestData['__trustedProperties']); |
|
83
|
|
|
|
|
84
|
|
|
$basketData = $this->getBasketData(); |
|
85
|
|
|
|
|
86
|
|
|
if ( |
|
87
|
|
|
!empty($requestData['id']) |
|
88
|
|
|
&& $requestData['addToBasket'] |
|
89
|
|
|
) { |
|
90
|
|
|
$returnData = $this->addToBasket($requestData, $basketData); |
|
91
|
|
|
$this->view->assign('pregenerateJs', $returnData['jsOutput']); |
|
92
|
|
|
} |
|
93
|
|
|
|
|
94
|
|
|
$this->redirect('main'); |
|
95
|
|
|
} |
|
96
|
|
|
|
|
97
|
|
|
/** |
|
98
|
|
|
* The main method of the plugin |
|
99
|
|
|
* |
|
100
|
|
|
* @return void |
|
101
|
|
|
*/ |
|
102
|
|
|
public function mainAction() |
|
103
|
|
|
{ |
|
104
|
|
|
$requestData = GeneralUtility::_GPmerged('tx_dlf'); |
|
105
|
|
|
unset($requestData['__referrer'], $requestData['__trustedProperties']); |
|
106
|
|
|
|
|
107
|
|
|
$basketData = $this->getBasketData(); |
|
108
|
|
|
|
|
109
|
|
|
if ($basketData['doc_ids']) { |
|
110
|
|
|
if (is_object($basketData['doc_ids'])) { |
|
111
|
|
|
$basketData['doc_ids'] = get_object_vars($basketData['doc_ids']); |
|
112
|
|
|
} |
|
113
|
|
|
$count = sprintf(LocalizationUtility::translate('basket.count', 'dlf'), count($basketData['doc_ids'])); |
|
|
|
|
|
|
114
|
|
|
} else { |
|
115
|
|
|
$count = sprintf(LocalizationUtility::translate('basket.count', 'dlf'), 0); |
|
116
|
|
|
} |
|
117
|
|
|
$this->view->assign('count', $count); |
|
118
|
|
|
|
|
119
|
|
|
$queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class) |
|
120
|
|
|
->getQueryBuilderForTable('tx_dlf_mail'); |
|
121
|
|
|
|
|
122
|
|
|
// get mail addresses |
|
123
|
|
|
$resultMail = $queryBuilder |
|
124
|
|
|
->select('*') |
|
125
|
|
|
->from('tx_dlf_mail') |
|
126
|
|
|
->where( |
|
127
|
|
|
'1=1', |
|
128
|
|
|
Helper::whereExpression('tx_dlf_mail') |
|
129
|
|
|
) |
|
130
|
|
|
->orderBy('tx_dlf_mail.sorting') |
|
131
|
|
|
->execute(); |
|
132
|
|
|
|
|
133
|
|
|
$mailSelect = []; |
|
134
|
|
|
if ($resultMail->rowCount() > 0) { |
|
135
|
|
|
$mailSelect[0] = htmlspecialchars(LocalizationUtility::translate('basket.chooseMail', 'dlf')); |
|
|
|
|
|
|
136
|
|
|
while ($row = $resultMail->fetch()) { |
|
137
|
|
|
$mailSelect[$row['uid']] = htmlspecialchars($row['name']) . ' (' . htmlspecialchars($row['mail']) . ')'; |
|
138
|
|
|
} |
|
139
|
|
|
$this->view->assign('mailSelect', $mailSelect); |
|
140
|
|
|
} |
|
141
|
|
|
|
|
142
|
|
|
$queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class) |
|
143
|
|
|
->getQueryBuilderForTable('tx_dlf_printer'); |
|
144
|
|
|
|
|
145
|
|
|
// get mail addresses |
|
146
|
|
|
$resultPrinter = $queryBuilder |
|
147
|
|
|
->select('*') |
|
148
|
|
|
->from('tx_dlf_printer') |
|
149
|
|
|
->where( |
|
150
|
|
|
'1=1', |
|
151
|
|
|
Helper::whereExpression('tx_dlf_printer') |
|
152
|
|
|
) |
|
153
|
|
|
->execute(); |
|
154
|
|
|
|
|
155
|
|
|
$printSelect = []; |
|
156
|
|
|
if ($resultPrinter->rowCount() > 0) { |
|
157
|
|
|
$printSelect[0] = htmlspecialchars(LocalizationUtility::translate('basket.choosePrinter', 'dlf')); |
|
158
|
|
|
while ($row = $resultPrinter->fetch()) { |
|
159
|
|
|
$printSelect[$row['uid']] = htmlspecialchars($row['label']); |
|
160
|
|
|
} |
|
161
|
|
|
$this->view->assign('printSelect', $printSelect); |
|
162
|
|
|
} |
|
163
|
|
|
|
|
164
|
|
|
$entries = []; |
|
165
|
|
|
if (isset($basketData['doc_ids'])) { |
|
166
|
|
|
// get each entry |
|
167
|
|
|
foreach ($basketData['doc_ids'] as $value) { |
|
168
|
|
|
$entries[] = $this->getEntry($value); |
|
169
|
|
|
} |
|
170
|
|
|
$this->view->assign('entries', $entries); |
|
171
|
|
|
} |
|
172
|
|
|
} |
|
173
|
|
|
|
|
174
|
|
|
/** |
|
175
|
|
|
* The basket data from user session. |
|
176
|
|
|
* |
|
177
|
|
|
* @return array The found data from user session. |
|
178
|
|
|
*/ |
|
179
|
|
|
protected function getBasketData() |
|
180
|
|
|
{ |
|
181
|
|
|
// get user session |
|
182
|
|
|
$sessionId = $GLOBALS['TSFE']->fe_user->id; |
|
183
|
|
|
$queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class) |
|
184
|
|
|
->getQueryBuilderForTable('tx_dlf_basket'); |
|
185
|
|
|
|
|
186
|
|
|
if ($GLOBALS['TSFE']->loginUser) { |
|
187
|
|
|
$result = $queryBuilder |
|
188
|
|
|
->select('*') |
|
189
|
|
|
->from('tx_dlf_basket') |
|
190
|
|
|
->where( |
|
191
|
|
|
$queryBuilder->expr()->eq('tx_dlf_basket.fe_user_id', (int) $GLOBALS['TSFE']->fe_user->user['uid']), |
|
192
|
|
|
Helper::whereExpression('tx_dlf_basket') |
|
193
|
|
|
) |
|
194
|
|
|
->setMaxResults(1) |
|
195
|
|
|
->execute(); |
|
196
|
|
|
} else { |
|
197
|
|
|
$GLOBALS['TSFE']->fe_user->setKey('ses', 'tx_dlf_basket', ''); |
|
198
|
|
|
$GLOBALS['TSFE']->fe_user->sesData_change = true; |
|
199
|
|
|
$GLOBALS['TSFE']->fe_user->storeSessionData(); |
|
200
|
|
|
$result = $queryBuilder |
|
201
|
|
|
->select('*') |
|
202
|
|
|
->from('tx_dlf_basket') |
|
203
|
|
|
->where( |
|
204
|
|
|
$queryBuilder->expr()->eq('tx_dlf_basket.session_id', $queryBuilder->createNamedParameter($sessionId)), |
|
205
|
|
|
Helper::whereExpression('tx_dlf_basket') |
|
206
|
|
|
) |
|
207
|
|
|
->setMaxResults(1) |
|
208
|
|
|
->execute(); |
|
209
|
|
|
} |
|
210
|
|
|
// session already exists |
|
211
|
|
|
if ($result->rowCount() === 0) { |
|
212
|
|
|
// create new basket in db |
|
213
|
|
|
$insertArray['fe_user_id'] = $GLOBALS['TSFE']->loginUser ? $GLOBALS['TSFE']->fe_user->user['uid'] : 0; |
|
214
|
|
|
$insertArray['session_id'] = $sessionId; |
|
215
|
|
|
$insertArray['doc_ids'] = ''; |
|
216
|
|
|
$insertArray['label'] = ''; |
|
217
|
|
|
$insertArray['l18n_diffsource'] = ''; |
|
218
|
|
|
GeneralUtility::makeInstance(ConnectionPool::class) |
|
219
|
|
|
->getConnectionForTable('tx_dlf_basket') |
|
220
|
|
|
->insert( |
|
221
|
|
|
'tx_dlf_basket', |
|
222
|
|
|
$insertArray |
|
223
|
|
|
); |
|
224
|
|
|
} |
|
225
|
|
|
$basketData = $result->fetchAll()[0]; |
|
226
|
|
|
$basketData['doc_ids'] = json_decode($basketData['doc_ids']); |
|
227
|
|
|
return $basketData; |
|
228
|
|
|
} |
|
229
|
|
|
|
|
230
|
|
|
/** |
|
231
|
|
|
* Return one basket entry |
|
232
|
|
|
* |
|
233
|
|
|
* @access protected |
|
234
|
|
|
* |
|
235
|
|
|
* @param array $data: DocumentData |
|
236
|
|
|
* @param array $template: Template information |
|
237
|
|
|
* |
|
238
|
|
|
* @return string One basket entry |
|
239
|
|
|
*/ |
|
240
|
|
|
protected function getEntry($data) |
|
241
|
|
|
{ |
|
242
|
|
|
if (is_object($data)) { |
|
243
|
|
|
$data = get_object_vars($data); |
|
244
|
|
|
} |
|
245
|
|
|
$id = $data['id']; |
|
246
|
|
|
$startpage = $data['startpage']; |
|
247
|
|
|
$endpage = $data['endpage']; |
|
248
|
|
|
$startX = $data['startX']; |
|
249
|
|
|
$startY = $data['startY']; |
|
250
|
|
|
$endX = $data['endX']; |
|
251
|
|
|
$endY = $data['endY']; |
|
252
|
|
|
$rotation = $data['rotation']; |
|
253
|
|
|
|
|
254
|
|
|
$docData = $this->getDocumentData($id, $data); |
|
255
|
|
|
|
|
256
|
|
|
$entryArray['BASKETDATA'] = $docData; |
|
257
|
|
|
|
|
258
|
|
|
$entryKey = $id . '_' . $startpage; |
|
259
|
|
|
if (!empty($startX)) { |
|
260
|
|
|
$entryKey .= '_' . $startX; |
|
261
|
|
|
} |
|
262
|
|
|
if (!empty($endX)) { |
|
263
|
|
|
$entryKey .= '_' . $endX; |
|
264
|
|
|
} |
|
265
|
|
|
|
|
266
|
|
|
$entryArray['id'] = $id; |
|
267
|
|
|
$entryArray['CONTROLS'] = [ |
|
268
|
|
|
'startpage' => $startpage, |
|
269
|
|
|
'endpage' => $endpage, |
|
270
|
|
|
'startX' => $startX, |
|
271
|
|
|
'startY' => $startY, |
|
272
|
|
|
'endX' => $endX, |
|
273
|
|
|
'endY' => $endY, |
|
274
|
|
|
'rotation' => $rotation, |
|
275
|
|
|
]; |
|
276
|
|
|
|
|
277
|
|
|
$entryArray['NUMBER'] = $docData['record_id']; |
|
278
|
|
|
$entryArray['key'] = $entryKey; |
|
279
|
|
|
|
|
280
|
|
|
// return one entry |
|
281
|
|
|
return $entryArray; |
|
282
|
|
|
} |
|
283
|
|
|
|
|
284
|
|
|
/** |
|
285
|
|
|
* Returns the downloadurl configured in the basket |
|
286
|
|
|
* |
|
287
|
|
|
* @access protected |
|
288
|
|
|
* |
|
289
|
|
|
* @param int $id: Document id |
|
290
|
|
|
* |
|
291
|
|
|
* @return mixed download url or false |
|
292
|
|
|
*/ |
|
293
|
|
|
protected function getDocumentData($id, $data) |
|
294
|
|
|
{ |
|
295
|
|
|
// get document instance to load further information |
|
296
|
|
|
$document = Document::getInstance($id, 0); |
|
297
|
|
|
if ($document) { |
|
|
|
|
|
|
298
|
|
|
// replace url param placeholder |
|
299
|
|
|
$urlParams = str_replace("##page##", (int) $data['page'], $this->settings['pdfparams']); |
|
300
|
|
|
$urlParams = str_replace("##docId##", $document->recordId, $urlParams); |
|
301
|
|
|
$urlParams = str_replace("##startpage##", (int) $data['startpage'], $urlParams); |
|
302
|
|
|
if ($data['startpage'] != $data['endpage']) { |
|
303
|
|
|
$urlParams = str_replace("##endpage##", $data['endpage'] === "" ? "" : (int) $data['endpage'], $urlParams); |
|
304
|
|
|
} else { |
|
305
|
|
|
// remove parameter endpage |
|
306
|
|
|
$urlParams = str_replace(",##endpage##", '', $urlParams); |
|
307
|
|
|
} |
|
308
|
|
|
$urlParams = str_replace("##startx##", $data['startX'] === "" ? "" : (int) $data['startX'], $urlParams); |
|
309
|
|
|
$urlParams = str_replace("##starty##", $data['startY'] === "" ? "" : (int) $data['startY'], $urlParams); |
|
310
|
|
|
$urlParams = str_replace("##endx##", $data['endX'] === "" ? "" : (int) $data['endX'], $urlParams); |
|
311
|
|
|
$urlParams = str_replace("##endy##", $data['endY'] === "" ? "" : (int) $data['endY'], $urlParams); |
|
312
|
|
|
$urlParams = str_replace("##rotation##", $data['rotation'] === "" ? "" : (int) $data['rotation'], $urlParams); |
|
313
|
|
|
|
|
314
|
|
|
$downloadUrl = $this->settings['pdfgenerate'] . $urlParams; |
|
315
|
|
|
|
|
316
|
|
|
$title = $document->getTitle($id, true); |
|
317
|
|
|
if (empty($title)) { |
|
318
|
|
|
$title = LocalizationUtility::translate('basket.noTitle', 'dlf'); |
|
319
|
|
|
} |
|
320
|
|
|
|
|
321
|
|
|
// Set page and cutout information |
|
322
|
|
|
$info = ''; |
|
323
|
|
|
if ($data['startX'] != '' && $data['endX'] != '') { |
|
324
|
|
|
// cutout |
|
325
|
|
|
$info .= htmlspecialchars(LocalizationUtility::translate('basket.cutout', 'dlf')) . ' '; |
|
|
|
|
|
|
326
|
|
|
} |
|
327
|
|
|
if ($data['startpage'] == $data['endpage']) { |
|
328
|
|
|
// One page |
|
329
|
|
|
$info .= htmlspecialchars(LocalizationUtility::translate('page', 'dlf')) . ' ' . $data['startpage']; |
|
330
|
|
|
} else { |
|
331
|
|
|
$info .= htmlspecialchars(LocalizationUtility::translate('page', 'dlf')) . ' ' . $data['startpage'] . '-' . $data['endpage']; |
|
332
|
|
|
} |
|
333
|
|
|
$downloadLink = '<a href="' . $downloadUrl . '" target="_blank">' . htmlspecialchars($title) . '</a> (' . $info . ')'; |
|
334
|
|
|
if ($data['startpage'] == $data['endpage']) { |
|
335
|
|
|
$pageNums = 1; |
|
336
|
|
|
} else { |
|
337
|
|
|
$pageNums = $data['endpage'] - $data['startpage']; |
|
338
|
|
|
} |
|
339
|
|
|
return [ |
|
340
|
|
|
'downloadUrl' => $downloadUrl, |
|
341
|
|
|
'title' => $title, |
|
342
|
|
|
'info' => $info, |
|
343
|
|
|
'downloadLink' => $downloadLink, |
|
344
|
|
|
'pageNums' => $pageNums, |
|
345
|
|
|
'urlParams' => $urlParams, |
|
346
|
|
|
'record_id' => $document->recordId, |
|
347
|
|
|
]; |
|
348
|
|
|
} |
|
349
|
|
|
return false; |
|
350
|
|
|
} |
|
351
|
|
|
|
|
352
|
|
|
/** |
|
353
|
|
|
* Adds documents to the basket |
|
354
|
|
|
* |
|
355
|
|
|
* @access protected |
|
356
|
|
|
* |
|
357
|
|
|
* @param array $_piVars: piVars |
|
358
|
|
|
* @param array $basketData: basket data |
|
359
|
|
|
* |
|
360
|
|
|
* @return array Basket data and Javascript output |
|
361
|
|
|
*/ |
|
362
|
|
|
protected function addToBasket($_piVars, $basketData) |
|
363
|
|
|
{ |
|
364
|
|
|
$output = ''; |
|
365
|
|
|
if (!$_piVars['startpage']) { |
|
366
|
|
|
$page = 0; |
|
367
|
|
|
} else { |
|
368
|
|
|
$page = (int) $_piVars['startpage']; |
|
369
|
|
|
} |
|
370
|
|
|
if ($page != null || $_piVars['addToBasket'] == 'list') { |
|
371
|
|
|
$documentItem = [ |
|
372
|
|
|
'id' => (int) $_piVars['id'], |
|
373
|
|
|
'startpage' => (int) $_piVars['startpage'], |
|
374
|
|
|
'endpage' => !isset($_piVars['endpage']) || $_piVars['endpage'] === "" ? "" : (int) $_piVars['endpage'], |
|
375
|
|
|
'startX' => !isset($_piVars['startX']) || $_piVars['startX'] === "" ? "" : (int) $_piVars['startX'], |
|
376
|
|
|
'startY' => !isset($_piVars['startY']) || $_piVars['startY'] === "" ? "" : (int) $_piVars['startY'], |
|
377
|
|
|
'endX' => !isset($_piVars['endX']) || $_piVars['endX'] === "" ? "" : (int) $_piVars['endX'], |
|
378
|
|
|
'endY' => !isset($_piVars['endY']) || $_piVars['endY'] === "" ? "" : (int) $_piVars['endY'], |
|
379
|
|
|
'rotation' => !isset($_piVars['rotation']) || $_piVars['rotation'] === "" ? "" : (int) $_piVars['rotation'] |
|
380
|
|
|
]; |
|
381
|
|
|
// update basket |
|
382
|
|
|
if (!empty($basketData['doc_ids'])) { |
|
383
|
|
|
$items = $basketData['doc_ids']; |
|
384
|
|
|
$items = get_object_vars($items); |
|
385
|
|
|
} else { |
|
386
|
|
|
$items = []; |
|
387
|
|
|
} |
|
388
|
|
|
// get document instance to load further information |
|
389
|
|
|
$document = Document::getInstance($documentItem['id'], 0); |
|
390
|
|
|
// set endpage for toc and subentry based on logid |
|
391
|
|
|
if (($_piVars['addToBasket'] == 'subentry') or ($_piVars['addToBasket'] == 'toc')) { |
|
392
|
|
|
$smLinks = $document->smLinks; |
|
393
|
|
|
$pageCounter = sizeof($smLinks['l2p'][$_piVars['logId']]); |
|
394
|
|
|
$documentItem['endpage'] = ($documentItem['startpage'] + $pageCounter) - 1; |
|
395
|
|
|
} |
|
396
|
|
|
// add whole document |
|
397
|
|
|
if ($_piVars['addToBasket'] == 'list') { |
|
398
|
|
|
$documentItem['endpage'] = $document->numPages; |
|
399
|
|
|
} |
|
400
|
|
|
$arrayKey = $documentItem['id'] . '_' . $page; |
|
401
|
|
|
if (!empty($documentItem['startX'])) { |
|
402
|
|
|
$arrayKey .= '_' . $documentItem['startX']; |
|
403
|
|
|
} |
|
404
|
|
|
if (!empty($documentItem['endX'])) { |
|
405
|
|
|
$arrayKey .= '_' . $documentItem['endX']; |
|
406
|
|
|
} |
|
407
|
|
|
// do not add more than one identical object |
|
408
|
|
|
if (!in_array($arrayKey, $items)) { |
|
409
|
|
|
$items[$arrayKey] = $documentItem; |
|
410
|
|
|
// replace url param placeholder |
|
411
|
|
|
$pdfParams = str_replace("##startpage##", $documentItem['startpage'], $this->settings['pdfparams']); |
|
412
|
|
|
$pdfParams = str_replace("##docId##", $document->recordId, $pdfParams); |
|
413
|
|
|
$pdfParams = str_replace("##startx##", $documentItem['startX'], $pdfParams); |
|
414
|
|
|
$pdfParams = str_replace("##starty##", $documentItem['startY'], $pdfParams); |
|
415
|
|
|
$pdfParams = str_replace("##endx##", $documentItem['endX'], $pdfParams); |
|
416
|
|
|
$pdfParams = str_replace("##endy##", $documentItem['endY'], $pdfParams); |
|
417
|
|
|
$pdfParams = str_replace("##rotation##", $documentItem['rotation'], $pdfParams); |
|
418
|
|
|
if ($documentItem['startpage'] != $documentItem['endpage']) { |
|
419
|
|
|
$pdfParams = str_replace("##endpage##", $documentItem['endpage'], $pdfParams); |
|
420
|
|
|
} else { |
|
421
|
|
|
// remove parameter endpage |
|
422
|
|
|
$pdfParams = str_replace(",##endpage##", '', $pdfParams); |
|
423
|
|
|
} |
|
424
|
|
|
$pdfGenerateUrl = $this->settings['pdfgenerate'] . $pdfParams; |
|
425
|
|
|
if ($this->settings['pregeneration']) { |
|
426
|
|
|
// send ajax request to webapp |
|
427
|
|
|
$output .= ' |
|
428
|
|
|
<script> |
|
429
|
|
|
$(document).ready(function(){ |
|
430
|
|
|
$.ajax({ |
|
431
|
|
|
url: "' . $pdfGenerateUrl . '", |
|
432
|
|
|
}).done(function() { |
|
433
|
|
|
}); |
|
434
|
|
|
}); |
|
435
|
|
|
</script>'; |
|
436
|
|
|
} |
|
437
|
|
|
} |
|
438
|
|
|
$update = ['doc_ids' => json_encode($items)]; |
|
439
|
|
|
GeneralUtility::makeInstance(ConnectionPool::class) |
|
440
|
|
|
->getConnectionForTable('tx_dlf_basket') |
|
441
|
|
|
->update( |
|
442
|
|
|
'tx_dlf_basket', |
|
443
|
|
|
$update, |
|
444
|
|
|
['uid' => (int) $basketData['uid']] |
|
445
|
|
|
); |
|
446
|
|
|
$basketData['doc_ids'] = $items; |
|
447
|
|
|
} |
|
448
|
|
|
return ['basketData' => $basketData, 'jsOutput' => $output]; |
|
449
|
|
|
} |
|
450
|
|
|
|
|
451
|
|
|
/** |
|
452
|
|
|
* Removes selected documents from basket |
|
453
|
|
|
* |
|
454
|
|
|
* @access protected |
|
455
|
|
|
* |
|
456
|
|
|
* @param array $_piVars: plugin variables |
|
457
|
|
|
* @param array $basketData: array with document information |
|
458
|
|
|
* |
|
459
|
|
|
* @return array basket data |
|
460
|
|
|
*/ |
|
461
|
|
|
protected function removeFromBasket($_piVars, $basketData) |
|
462
|
|
|
{ |
|
463
|
|
|
if (!empty($basketData['doc_ids'])) { |
|
464
|
|
|
$items = $basketData['doc_ids']; |
|
465
|
|
|
$items = get_object_vars($items); |
|
466
|
|
|
} |
|
467
|
|
|
foreach ($_piVars['selected'] as $value) { |
|
468
|
|
|
if (isset($value['id'])) { |
|
469
|
|
|
$arrayKey = $value['id'] . '_' . $value['startpage']; |
|
470
|
|
|
if (!empty($value['startX'])) { |
|
471
|
|
|
$arrayKey .= '_' . $value['startX']; |
|
472
|
|
|
} |
|
473
|
|
|
if (!empty($value['endX'])) { |
|
474
|
|
|
$arrayKey .= '_' . $value['endX']; |
|
475
|
|
|
} |
|
476
|
|
|
if (isset($items[$arrayKey])) { |
|
477
|
|
|
unset($items[$arrayKey]); |
|
478
|
|
|
} |
|
479
|
|
|
} |
|
480
|
|
|
} |
|
481
|
|
|
if (empty($items)) { |
|
482
|
|
|
$update = ['doc_ids' => '']; |
|
483
|
|
|
} else { |
|
484
|
|
|
$update = ['doc_ids' => json_encode($items)]; |
|
485
|
|
|
} |
|
486
|
|
|
|
|
487
|
|
|
GeneralUtility::makeInstance(ConnectionPool::class) |
|
488
|
|
|
->getConnectionForTable('tx_dlf_basket') |
|
489
|
|
|
->update( |
|
490
|
|
|
'tx_dlf_basket', |
|
491
|
|
|
$update, |
|
492
|
|
|
['uid' => (int) $basketData['uid']] |
|
493
|
|
|
); |
|
494
|
|
|
$basketData['doc_ids'] = $items; |
|
|
|
|
|
|
495
|
|
|
return $basketData; |
|
496
|
|
|
} |
|
497
|
|
|
|
|
498
|
|
|
/** |
|
499
|
|
|
* Send mail with pdf download url |
|
500
|
|
|
* |
|
501
|
|
|
* @access protected |
|
502
|
|
|
* |
|
503
|
|
|
* @return void |
|
504
|
|
|
*/ |
|
505
|
|
|
protected function sendMail($requestData) |
|
506
|
|
|
{ |
|
507
|
|
|
// send mail |
|
508
|
|
|
$mailId = $requestData['mail_action']; |
|
509
|
|
|
|
|
510
|
|
|
$queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class) |
|
511
|
|
|
->getQueryBuilderForTable('tx_dlf_mail'); |
|
512
|
|
|
|
|
513
|
|
|
// get id from db and send selected doc download link |
|
514
|
|
|
$resultMail = $queryBuilder |
|
515
|
|
|
->select('*') |
|
516
|
|
|
->from('tx_dlf_mail') |
|
517
|
|
|
->where( |
|
518
|
|
|
$queryBuilder->expr()->eq('tx_dlf_mail.uid', intval($mailId)), |
|
519
|
|
|
Helper::whereExpression('tx_dlf_mail') |
|
520
|
|
|
) |
|
521
|
|
|
->setMaxResults(1) |
|
522
|
|
|
->execute(); |
|
523
|
|
|
|
|
524
|
|
|
$allResults = $resultMail->fetchAll(); |
|
525
|
|
|
$mailData = $allResults[0]; |
|
526
|
|
|
$mailText = htmlspecialchars(LocalizationUtility::translate('basket.mailBody', 'dlf')) . "\n"; |
|
|
|
|
|
|
527
|
|
|
$numberOfPages = 0; |
|
528
|
|
|
$pdfUrl = $this->settings['pdfdownload']; |
|
529
|
|
|
// prepare links |
|
530
|
|
|
foreach ($requestData['selected'] as $docValue) { |
|
531
|
|
|
if ($docValue['id']) { |
|
532
|
|
|
$explodeId = explode("_", $docValue['id']); |
|
533
|
|
|
$docData = $this->getDocumentData($explodeId[0], $docValue); |
|
534
|
|
|
$pdfUrl .= $docData['urlParams'] . $this->settings['pdfparamseparator']; |
|
535
|
|
|
$pages = (abs(intval($docValue['startpage']) - intval($docValue['endpage']))); |
|
536
|
|
|
if ($pages === 0) { |
|
537
|
|
|
$numberOfPages = $numberOfPages + 1; |
|
538
|
|
|
} else { |
|
539
|
|
|
$numberOfPages = $numberOfPages + $pages; |
|
540
|
|
|
} |
|
541
|
|
|
} |
|
542
|
|
|
} |
|
543
|
|
|
// Remove leading/tailing pdfparamseperator |
|
544
|
|
|
$pdfUrl = trim($pdfUrl, $this->settings['pdfparamseparator']); |
|
545
|
|
|
$mailBody = $mailText . $pdfUrl; |
|
546
|
|
|
// Get hook objects. |
|
547
|
|
|
$hookObjects = Helper::getHookObjects($this->scriptRelPath); |
|
|
|
|
|
|
548
|
|
|
// Hook for getting a customized mail body. |
|
549
|
|
|
foreach ($hookObjects as $hookObj) { |
|
550
|
|
|
if (method_exists($hookObj, 'customizeMailBody')) { |
|
551
|
|
|
$mailBody = $hookObj->customizeMailBody($mailText, $pdfUrl); |
|
552
|
|
|
} |
|
553
|
|
|
} |
|
554
|
|
|
$from = \TYPO3\CMS\Core\Utility\MailUtility::getSystemFrom(); |
|
555
|
|
|
// send mail |
|
556
|
|
|
$mail = GeneralUtility::makeInstance(\TYPO3\CMS\Core\Mail\MailMessage::class); |
|
557
|
|
|
// Prepare and send the message |
|
558
|
|
|
$mail |
|
559
|
|
|
// subject |
|
560
|
|
|
->setSubject(LocalizationUtility::translate('basket.mailSubject', 'dlf')) |
|
561
|
|
|
// Set the From address with an associative array |
|
562
|
|
|
->setFrom($from) |
|
563
|
|
|
// Set the To addresses with an associative array |
|
564
|
|
|
->setTo([$mailData['mail'] => $mailData['name']]) |
|
565
|
|
|
->setBody($mailBody, 'text/html') |
|
566
|
|
|
->send(); |
|
567
|
|
|
// protocol |
|
568
|
|
|
$insertArray = [ |
|
569
|
|
|
'pid' => $this->settings['pages'], |
|
570
|
|
|
'file_name' => $pdfUrl, |
|
571
|
|
|
'count_pages' => $numberOfPages, |
|
572
|
|
|
'crdate' => time(), |
|
573
|
|
|
]; |
|
574
|
|
|
if ($GLOBALS["TSFE"]->loginUser) { |
|
575
|
|
|
// internal user |
|
576
|
|
|
$insertArray['user_id'] = $GLOBALS["TSFE"]->fe_user->user['uid']; |
|
577
|
|
|
$insertArray['name'] = $GLOBALS["TSFE"]->fe_user->user['username']; |
|
578
|
|
|
$insertArray['label'] = 'Mail: ' . $mailData['mail']; |
|
579
|
|
|
} else { |
|
580
|
|
|
// external user |
|
581
|
|
|
$insertArray['user_id'] = 0; |
|
582
|
|
|
$insertArray['name'] = 'n/a'; |
|
583
|
|
|
$insertArray['label'] = 'Mail: ' . $mailData['mail']; |
|
584
|
|
|
} |
|
585
|
|
|
// add action to protocol |
|
586
|
|
|
GeneralUtility::makeInstance(ConnectionPool::class) |
|
587
|
|
|
->getConnectionForTable('tx_dlf_actionlog') |
|
588
|
|
|
->insert( |
|
589
|
|
|
'tx_dlf_actionlog', |
|
590
|
|
|
$insertArray |
|
591
|
|
|
); |
|
592
|
|
|
$this->redirect('main'); |
|
593
|
|
|
} |
|
594
|
|
|
|
|
595
|
|
|
/** |
|
596
|
|
|
* Sends document information to an external printer (url) |
|
597
|
|
|
* |
|
598
|
|
|
* @access protected |
|
599
|
|
|
* |
|
600
|
|
|
* @return void |
|
601
|
|
|
*/ |
|
602
|
|
|
protected function printDocument($requestData, $basketData) |
|
|
|
|
|
|
603
|
|
|
{ |
|
604
|
|
|
$pdfUrl = $this->settings['pdfprint']; |
|
605
|
|
|
$numberOfPages = 0; |
|
606
|
|
|
foreach ($requestData['selected'] as $docId => $docValue) { |
|
607
|
|
|
if ($docValue['id']) { |
|
608
|
|
|
$docData = $this->getDocumentData($docValue['id'], $docValue); |
|
609
|
|
|
$pdfUrl .= $docData['urlParams'] . $this->settings['pdfparamseparator']; |
|
610
|
|
|
$numberOfPages += $docData['pageNums']; |
|
611
|
|
|
} |
|
612
|
|
|
} |
|
613
|
|
|
// get printer data |
|
614
|
|
|
$printerId = $requestData['print_action']; |
|
615
|
|
|
|
|
616
|
|
|
$queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class) |
|
617
|
|
|
->getQueryBuilderForTable('tx_dlf_printer'); |
|
618
|
|
|
|
|
619
|
|
|
// get id from db and send selected doc download link |
|
620
|
|
|
$resultPrinter = $queryBuilder |
|
621
|
|
|
->select('*') |
|
622
|
|
|
->from('tx_dlf_printer') |
|
623
|
|
|
->where( |
|
624
|
|
|
$queryBuilder->expr()->eq('tx_dlf_printer.uid', intval($printerId)), |
|
625
|
|
|
Helper::whereExpression('tx_dlf_printer') |
|
626
|
|
|
) |
|
627
|
|
|
->setMaxResults(1) |
|
628
|
|
|
->execute(); |
|
629
|
|
|
|
|
630
|
|
|
$allResults = $resultPrinter->fetchAll(); |
|
631
|
|
|
$printerData = $allResults[0]; |
|
632
|
|
|
// printer is selected |
|
633
|
|
|
if ($printerData) { |
|
634
|
|
|
$pdfUrl = $printerData['print']; |
|
635
|
|
|
$numberOfPages = 0; |
|
636
|
|
|
foreach ($requestData['selected'] as $docId => $docValue) { |
|
637
|
|
|
if ($docValue['id']) { |
|
638
|
|
|
$explodeId = explode("_", $docId); |
|
639
|
|
|
$docData = $this->getDocumentData($explodeId[0], $docValue); |
|
640
|
|
|
$pdfUrl .= $docData['urlParams'] . $this->settings['pdfparamseparator']; |
|
641
|
|
|
$numberOfPages += $docData['pageNums']; |
|
642
|
|
|
} |
|
643
|
|
|
} |
|
644
|
|
|
$pdfUrl = trim($pdfUrl, $this->settings['pdfparamseparator']); |
|
645
|
|
|
} |
|
646
|
|
|
// protocol |
|
647
|
|
|
$insertArray = [ |
|
648
|
|
|
'pid' => $this->settings['pages'], |
|
649
|
|
|
'file_name' => $pdfUrl, |
|
650
|
|
|
'count_pages' => $numberOfPages, |
|
651
|
|
|
'crdate' => time(), |
|
652
|
|
|
]; |
|
653
|
|
|
if ($GLOBALS["TSFE"]->loginUser) { |
|
654
|
|
|
// internal user |
|
655
|
|
|
$insertArray['user_id'] = $GLOBALS["TSFE"]->fe_user->user['uid']; |
|
656
|
|
|
$insertArray['name'] = $GLOBALS["TSFE"]->fe_user->user['username']; |
|
657
|
|
|
$insertArray['label'] = 'Print: ' . $printerData['label']; |
|
658
|
|
|
} else { |
|
659
|
|
|
// external user |
|
660
|
|
|
$insertArray['user_id'] = 0; |
|
661
|
|
|
$insertArray['name'] = 'n/a'; |
|
662
|
|
|
$insertArray['label'] = 'Print: ' . $printerData['label']; |
|
663
|
|
|
} |
|
664
|
|
|
// add action to protocol |
|
665
|
|
|
GeneralUtility::makeInstance(ConnectionPool::class) |
|
666
|
|
|
->getConnectionForTable('tx_dlf_actionlog') |
|
667
|
|
|
->insert( |
|
668
|
|
|
'tx_dlf_actionlog', |
|
669
|
|
|
$insertArray |
|
670
|
|
|
); |
|
671
|
|
|
|
|
672
|
|
|
$this->redirectToUri($pdfUrl); |
|
673
|
|
|
} |
|
674
|
|
|
|
|
675
|
|
|
} |
|
676
|
|
|
|