|
|
@@ -504,51 +504,48 @@ class Route_ViewTableAjax extends RouteBase {
|
|
|
$items = $acl->getItems($params);
|
|
|
|
|
|
$format = V::get('format', 'html', $_GET);
|
|
|
- if ('html' == $format) {
|
|
|
- UI::gora();
|
|
|
- UI::startTag('table', ['class'=>'table table-bordered table-hover']);
|
|
|
- UI::startTag('thead');
|
|
|
- UI::startTag('tr');
|
|
|
- foreach ($labels as $fldName => $label) {
|
|
|
- UI::tag('th', [], $label);
|
|
|
- }
|
|
|
- UI::endTag('tr');
|
|
|
- UI::endTag('thead');
|
|
|
- UI::startTag('tbody');
|
|
|
- foreach ($items as $item) :
|
|
|
- UI::startTag('tr');
|
|
|
- foreach ($labels as $fldName => $label) :
|
|
|
- UI::tag('td', [], V::get($fldName, '', $item));
|
|
|
- endforeach;
|
|
|
- UI::endTag('tr');
|
|
|
- endforeach;
|
|
|
- UI::endTag('tbody');
|
|
|
- UI::endTag('table');
|
|
|
- UI::dol();
|
|
|
- }
|
|
|
- else if ('csv' == $format) {
|
|
|
- $csvFileName = "Tabela-" . $acl->getName() . "-" . date("Y-m-d_H_s");
|
|
|
- header('Content-Type: text/csv; charset=utf-8');
|
|
|
- header("Content-Disposition: attachment; filename={$csvFileName}.csv");
|
|
|
- $csvSeparator = ';';
|
|
|
-
|
|
|
- $labelsLine = array();
|
|
|
- foreach ($labels as $fldName => $label) {
|
|
|
- $labelsLine[] = '"' . addslashes($label) . '"';
|
|
|
+ switch ($format) {
|
|
|
+ case 'html': {
|
|
|
+ UI::gora();
|
|
|
+ echo UI::h('table', ['class'=>'table table-bordered table-hover'], [
|
|
|
+ UI::h('thead', [], [
|
|
|
+ UI::h('tr', [], array_map(function ($label) {
|
|
|
+ return UI::h('th', [], $label);
|
|
|
+ }, $labels))
|
|
|
+ ]),
|
|
|
+ UI::h('tbody', [], array_map(function ($item) use($labels) {
|
|
|
+ return UI::h('tr', [], array_map(function ($fieldName) use ($item) {
|
|
|
+ return UI::h('td', [], V::get($fieldName, '', $item));
|
|
|
+ }, array_keys($labels)));
|
|
|
+ }, $items)),
|
|
|
+ ]);
|
|
|
+ UI::dol();
|
|
|
+ exit;
|
|
|
}
|
|
|
- echo implode($csvSeparator, $labelsLine) . "\n";
|
|
|
-
|
|
|
- foreach ($items as $item) {
|
|
|
- $itemLine = array();
|
|
|
- foreach ($labels as $fldName => $label) {
|
|
|
- $itemLine[] = '"' . addslashes(V::get($fldName, '', $item)) . '"';
|
|
|
+ case 'csv_cp1250':
|
|
|
+ case 'csv': {
|
|
|
+ $csvFileName = "Tabela-" . $acl->getName() . "-" . date("Y-m-d_H_s");
|
|
|
+ header('Content-Type: text/csv; charset=utf-8');
|
|
|
+ header("Content-Disposition: attachment; filename={$csvFileName}.csv");
|
|
|
+ $csvSeparator = ';';
|
|
|
+
|
|
|
+ $csvHeader = implode($csvSeparator, array_map(function ($label) use ($item) {
|
|
|
+ return '"' . addslashes($label) . '"';
|
|
|
+ }, array_values($labels)));
|
|
|
+ $csvRows = implode("\r\n", array_map(function ($item) use ($labels, $csvSeparator) {
|
|
|
+ return implode($csvSeparator, array_map(function ($fieldName) use ($item) {
|
|
|
+ return '"' . addslashes(V::get($fieldName, '', $item)) . '"';
|
|
|
+ }, array_keys($labels)));
|
|
|
+ }, $items));
|
|
|
+ switch ($format) {
|
|
|
+ case 'csv': echo $csvHeader . "\n" . $csvRows; exit;
|
|
|
+ case 'csv_cp1250': echo iconv('utf-8', 'Windows-1250//IGNORE', $csvHeader) . "\r\n" . iconv('utf-8', 'Windows-1250//IGNORE', $csvRows); exit;
|
|
|
+ die("Nieobsługiwane kodowanie danych csv.");
|
|
|
}
|
|
|
- echo implode($csvSeparator, $itemLine) . "\n";
|
|
|
+ exit;
|
|
|
}
|
|
|
}
|
|
|
- else {
|
|
|
- die("Nieobsługiwany format danych.");
|
|
|
- }
|
|
|
+ die("Nieobsługiwany format danych.");
|
|
|
}
|
|
|
|
|
|
public function loadDataAjaxAction() {
|