|
20 | 20 | use Admidio\Infrastructure\Exception; |
21 | 21 | use Admidio\Infrastructure\Utils\FileSystemUtils; |
22 | 22 | use Admidio\Infrastructure\Utils\SecurityUtils; |
| 23 | +use Admidio\UI\Component\DataTables; |
23 | 24 | use Admidio\UI\Presenter\FormPresenter; |
24 | 25 | use Admidio\UI\Presenter\PagePresenter; |
25 | 26 | use Admidio\Users\Entity\User; |
|
79 | 80 | $getMode = 'pdf'; |
80 | 81 | break; |
81 | 82 | case 'html': |
82 | | - $classTable = 'table table-condensed'; |
| 83 | + $classTable = 'table table-condensed table-hover'; |
83 | 84 | break; |
84 | 85 | case 'print': |
85 | 86 | $classTable = 'table table-condensed table-striped'; |
|
91 | 92 | // CSV file as string |
92 | 93 | $csvStr = ''; |
93 | 94 |
|
| 95 | + // data array |
| 96 | + $data = array('headers' => array(), 'rows' => array(), 'column_align' => array()); |
| 97 | + |
94 | 98 | // generate the display list |
95 | 99 | $report->setConfiguration($getCrtId); |
96 | 100 | $report->generate_listData(); |
|
116 | 120 | } |
117 | 121 |
|
118 | 122 | if ($getMode !== 'csv') { |
119 | | - $datatable = false; |
120 | | - $hoverRows = false; |
121 | | - |
| 123 | + $page = PagePresenter::withHtmlIDAndHeadline('adm_category_report'); |
| 124 | + $smarty = $page->createSmartyObject(); |
| 125 | + $smarty->assign('l10n', $gL10n); |
122 | 126 | if ($getMode === 'print') { |
123 | | - $page = PagePresenter::withHtmlIDAndHeadline('plg-category-report-main-print'); |
124 | 127 | $page->setContentFullWidth(); |
125 | 128 | $page->setPrintMode(); |
126 | 129 | $page->setTitle($title); |
127 | 130 | $page->setHeadline($headline); |
128 | 131 | $page->addHtml('<h5 class="admidio-content-subheader">' . $subHeadline . '</h5>'); |
129 | | - $table = new HtmlTable('adm_lists_table', $page, $hoverRows, $datatable, $classTable); |
| 132 | + $smarty->assign('classTable', $classTable); |
130 | 133 | } elseif ($getMode === 'pdf') { |
131 | 134 | if (ini_get('max_execution_time') < 600) { |
132 | 135 | ini_set('max_execution_time', 600); //600 seconds = 10 minutes |
|
161 | 164 | // add a page |
162 | 165 | $pdf->AddPage(); |
163 | 166 |
|
164 | | - // Create table object for display |
165 | | - $table = new HtmlTable('adm_lists_table', null, $hoverRows, $datatable, $classTable); |
166 | | - $table->addAttribute('border', '1'); |
167 | | - |
168 | | - $table->addTableHeader(); |
169 | | - $table->addRow(); |
170 | | - $table->addAttribute('align', 'center'); |
171 | | - $table->addColumn($subHeadline, array('colspan' => $columnCount + 1)); |
172 | | - $table->addRow(); |
| 167 | + // set subHeadline and class for table |
| 168 | + $smarty->assign('subHeadline', $subHeadline); |
| 169 | + $smarty->assign('classTable', $classTable); |
173 | 170 | } elseif ($getMode === 'html') { |
174 | | - if ($getExportAndFilter) { |
175 | | - $datatable = false; |
176 | | - } else { |
177 | | - $datatable = true; |
178 | | - } |
179 | | - |
180 | | - $hoverRows = true; |
181 | | - |
182 | 171 | // create html page object |
183 | | - $page = PagePresenter::withHtmlIDAndHeadline('plg-category-report-main-html'); |
184 | 172 | $page->setContentFullWidth(); |
185 | 173 | $page->setTitle($title); |
186 | 174 | $page->setHeadline($headline); |
|
303 | 291 |
|
304 | 292 | $page->addHtml('<h5 class="admidio-content-subheader">' . $subHeadline . '</h5>'); |
305 | 293 |
|
306 | | - $table = new HtmlTable('adm_lists_table', $page, $hoverRows, $datatable, $classTable); |
307 | | - $table->setDatatablesRowsPerPage($gSettingsManager->getInt('groups_roles_members_per_page')); |
308 | | - } else { |
309 | | - $table = new HtmlTable('adm_lists_table', null, $hoverRows, $datatable, $classTable); |
| 294 | + $smarty->assign('classTable', $classTable); |
| 295 | + if (!$getExportAndFilter) { |
| 296 | + $categoryReportTable = new DataTables($page, 'adm_lists_table'); |
| 297 | + $categoryReportTable->setRowsPerPage($gSettingsManager->getInt('groups_roles_members_per_page')); |
| 298 | + } |
310 | 299 | } |
311 | 300 | } |
312 | 301 |
|
313 | | - $columnAlign = array('center'); |
| 302 | + $columnAlign = array('right'); |
314 | 303 | $columnValues = array($gL10n->get('SYS_ABR_NO')); |
315 | 304 | $columnNumber = 1; |
316 | 305 |
|
|
321 | 310 | if ($gProfileFields->getPropertyById($usf_id, 'usf_type') == 'NUMBER' |
322 | 311 | || $gProfileFields->getPropertyById($usf_id, 'usf_type') == 'DECIMAL_NUMBER') { |
323 | 312 | $columnAlign[] = 'right'; |
324 | | - } else { |
| 313 | + } elseif ($gProfileFields->getPropertyById($usf_id, 'usf_type') == 'CHECKBOX' || $usf_id === 0) { |
| 314 | + // bei allen Feldern, die kein Profilfeld sind (usf_id = 0) und Checkboxen wird zentriert |
325 | 315 | $columnAlign[] = 'center'; |
| 316 | + } else { |
| 317 | + $columnAlign[] = 'left'; |
326 | 318 | } |
327 | 319 |
|
328 | 320 | if ($getMode == 'csv') { |
|
331 | 323 | $csvStr .= $valueQuotes . $gL10n->get('SYS_ABR_NO') . $valueQuotes; |
332 | 324 | } |
333 | 325 | $csvStr .= $separator . $valueQuotes . $columnHeader['data'] . $valueQuotes; |
334 | | - } elseif ($getMode == 'pdf') { |
335 | | - if ($columnNumber === 1) { |
336 | | - $table->addColumn($gL10n->get('SYS_ABR_NO'), array('style' => 'text-align: center;font-size:14;background-color:#C7C7C7;'), 'th'); |
337 | | - } |
338 | | - $table->addColumn($columnHeader['data'], array('style' => 'text-align: center;font-size:14;background-color:#C7C7C7;'), 'th'); |
339 | 326 | } elseif ($getMode === "xlsx") { |
340 | 327 | // convert html characters to plain text |
341 | 328 | $columnValues[] = html_entity_decode($columnHeader['data'], ENT_QUOTES | ENT_HTML5, 'UTF-8'); |
342 | | - } elseif ($getMode == 'html' || $getMode == 'print') { |
| 329 | + } elseif ($getMode == 'html' || $getMode == 'print' || $getMode == 'pdf') { |
343 | 330 | $columnValues[] = $columnHeader['data']; |
344 | 331 | } |
345 | 332 | $columnNumber++; |
|
351 | 338 | $spreadsheet = new Spreadsheet(); |
352 | 339 | $activeSheet = $spreadsheet->getActiveSheet(); |
353 | 340 | $activeSheet->fromArray(array_values($columnValues)); |
354 | | - } elseif ($getMode === 'html' || $getMode === 'print') { |
355 | | - $table->setColumnAlignByArray($columnAlign); |
356 | | - $table->addRowHeadingByArray($columnValues); |
357 | 341 | } else { |
358 | | - $table->addTableBody(); |
359 | | - $table->setColumnAlignByArray($columnAlign); |
| 342 | + $data['headers'] = $columnValues; |
| 343 | + $data['column_align'] = $columnAlign; |
360 | 344 | } |
361 | 345 |
|
362 | 346 | $listRowNumber = 1; |
|
472 | 456 | $activeSheet->setCellValue($colLetter . $currentRow, $cell); |
473 | 457 | } |
474 | 458 | } else { |
475 | | - $table->addRowByArray($columnValues, 'row-' . $listRowNumber, array('nobr' => 'true')); |
| 459 | + $data['rows'][] = array('id' => 'row-' . $listRowNumber, 'data' => $columnValues); |
476 | 460 | } |
477 | 461 | $listRowNumber++; |
478 | 462 | } |
|
493 | 477 | // download CSV file |
494 | 478 | header('Content-Type: text/comma-separated-values; charset=' . $charset); |
495 | 479 | echo $csvStr; |
496 | | - }elseif ($getMode === 'xlsx') { |
| 480 | + } elseif ($getMode === 'xlsx') { |
497 | 481 | $filename = FileSystemUtils::getSanitizedPathEntry($filename) . '.' . $getMode; |
498 | 482 |
|
499 | 483 | header('Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet; charset=' . $charset); |
|
503 | 487 | formatSpreadsheet($spreadsheet, $columnCount + 1, true); |
504 | 488 | $writer = new Xlsx($spreadsheet); |
505 | 489 | $writer->save('php://output'); |
506 | | - } // send the new PDF to the User |
507 | | - elseif ($getMode === 'pdf') { |
| 490 | + } elseif ($getMode === 'pdf') { |
| 491 | + // send the new PDF to the User |
| 492 | + // Using Smarty templating engine for exporting table in PDF |
| 493 | + $smarty->assign('attributes', array('border' => '1', 'cellpadding' => '1')); |
| 494 | + $smarty->assign('columnAlign', $data['column_align']); |
| 495 | + $smarty->assign('headers', $data['headers']); |
| 496 | + $smarty->assign('headersStyle', 'font-size:14;background-color:#C7C7C7;'); |
| 497 | + $smarty->assign('rows', $data['rows']); |
| 498 | + $smarty->assign('rowsStyle', 'font-size:10;'); |
| 499 | + |
| 500 | + // Fetch the HTML table from our Smarty template |
| 501 | + $smarty->assign('exportMode', true); |
| 502 | + $htmlTable = $smarty->fetch('modules/category-report.list.tpl'); |
| 503 | + |
508 | 504 | // output the HTML content |
509 | | - $pdf->writeHTML($table->getHtmlTable(), true, false, true); |
| 505 | + $pdf->writeHTML($htmlTable, true, false, true); |
510 | 506 |
|
511 | 507 | $file = ADMIDIO_PATH . FOLDER_TEMP_DATA . '/' . $filename; |
512 | 508 |
|
|
527 | 523 | } |
528 | 524 | } elseif ($getMode == 'html' && $getExportAndFilter) { |
529 | 525 | $page->addHtml('<div style="width:100%; height: 500px; overflow:auto; border:20px;">'); |
530 | | - $page->addHtml($table->show(false)); |
531 | | - $page->addHtml('</div><br/>'); |
| 526 | + $smarty->assign('columnAlign', $data['column_align']); |
| 527 | + $smarty->assign('headers', $data['headers']); |
| 528 | + $smarty->assign('rows', $data['rows']); |
532 | 529 |
|
| 530 | + // Fetch the HTML table from our Smarty template |
| 531 | + $htmlTable = $smarty->fetch('modules/category-report.list.tpl'); |
| 532 | + $page->addHtml($htmlTable); |
| 533 | + $page->addHtml('</div><br/>'); |
533 | 534 | $page->show(); |
534 | 535 | } elseif (($getMode == 'html' && !$getExportAndFilter) || $getMode == 'print') { |
535 | | - $page->addHtml($table->show(false)); |
| 536 | + if (isset($categoryReportTable)) { |
| 537 | + // we are in datatable mode |
| 538 | + $categoryReportTable->createJavascript(count($data['rows']), count($data['headers'])); |
| 539 | + $categoryReportTable->setColumnAlignByArray($data['column_align']); |
| 540 | + $page->addHtml('<div class="table-responsive">'); |
| 541 | + } |
536 | 542 |
|
| 543 | + $smarty->assign('columnAlign', $data['column_align']); |
| 544 | + $smarty->assign('headers', $data['headers']); |
| 545 | + $smarty->assign('rows', $data['rows']); |
| 546 | + |
| 547 | + // Fetch the HTML table from our Smarty template |
| 548 | + $htmlTable = $smarty->fetch('modules/category-report.list.tpl'); |
| 549 | + $page->addHtml($htmlTable); |
| 550 | + if (isset($categoryReportTable)) { |
| 551 | + $page->addHtml('</div>'); |
| 552 | + } |
537 | 553 | $page->show(); |
538 | 554 | } |
539 | 555 | } catch (Exception $e) { |
|
0 commit comments