2016-09-01 23:13:23 +02:00
|
|
|
<?php
|
|
|
|
/*****************************************************************************
|
|
|
|
* TabularData.php
|
|
|
|
* Contains the template that displays tabular data.
|
|
|
|
*
|
2023-04-08 21:32:38 +02:00
|
|
|
* Kabuki CMS (C) 2013-2023, Aaron van Geffen
|
2016-09-01 23:13:23 +02:00
|
|
|
*****************************************************************************/
|
|
|
|
|
2021-02-17 16:41:58 +01:00
|
|
|
class TabularData extends SubTemplate
|
2016-09-01 23:13:23 +02:00
|
|
|
{
|
2024-08-27 11:55:22 +02:00
|
|
|
protected GenericTable $_t;
|
2022-12-25 13:50:33 +01:00
|
|
|
|
2016-09-01 23:13:23 +02:00
|
|
|
public function __construct(GenericTable $table)
|
|
|
|
{
|
|
|
|
$this->_t = $table;
|
|
|
|
}
|
|
|
|
|
|
|
|
protected function html_content()
|
|
|
|
{
|
2024-08-27 11:55:22 +02:00
|
|
|
$this->renderTitle();
|
2023-03-11 13:20:59 +01:00
|
|
|
|
|
|
|
foreach ($this->_subtemplates as $template)
|
|
|
|
$template->html_main();
|
|
|
|
|
|
|
|
// Showing an inline form?
|
|
|
|
$pager = $this->_t->getPageIndex();
|
|
|
|
if (!empty($pager) || isset($this->_t->form_above))
|
2024-08-27 11:55:22 +02:00
|
|
|
$this->renderPaginationForm($pager, $this->_t->form_above);
|
|
|
|
|
|
|
|
$tableClass = $this->_t->getTableClass();
|
|
|
|
if ($tableClass)
|
2016-09-01 23:13:23 +02:00
|
|
|
echo '
|
2024-08-27 11:55:22 +02:00
|
|
|
<div class="', $tableClass, '">';
|
2016-09-01 23:13:23 +02:00
|
|
|
|
2024-08-27 11:55:22 +02:00
|
|
|
// Build the table!
|
|
|
|
echo '
|
|
|
|
<table class="table table-striped table-condensed">';
|
2023-03-11 13:20:59 +01:00
|
|
|
|
2024-08-27 11:55:22 +02:00
|
|
|
$this->renderTableHead($this->_t->getHeader());
|
|
|
|
$this->renderTableBody($this->_t->getBody());
|
2023-03-11 13:20:59 +01:00
|
|
|
|
2024-08-27 11:55:22 +02:00
|
|
|
echo '
|
|
|
|
</table>';
|
2016-09-01 23:13:23 +02:00
|
|
|
|
2023-03-11 13:20:59 +01:00
|
|
|
if ($tableClass)
|
|
|
|
echo '
|
2024-08-27 11:55:22 +02:00
|
|
|
</div>';
|
2016-09-01 23:13:23 +02:00
|
|
|
|
2024-08-27 11:55:22 +02:00
|
|
|
// Showing an inline form?
|
|
|
|
if (!empty($pager) || isset($this->_t->form_below))
|
|
|
|
$this->renderPaginationForm($pager, $this->_t->form_below);
|
|
|
|
|
|
|
|
$title = $this->_t->getTitle();
|
|
|
|
if (!empty($title))
|
|
|
|
echo '
|
|
|
|
</div>';
|
|
|
|
}
|
|
|
|
|
|
|
|
protected function renderTitle()
|
|
|
|
{
|
|
|
|
$title = $this->_t->getTitle();
|
|
|
|
if (!empty($title))
|
|
|
|
{
|
|
|
|
$titleclass = $this->_t->getTitleClass();
|
|
|
|
echo '
|
|
|
|
<div class="generic-table', !empty($titleclass) ? ' ' . $titleclass : '', '">
|
|
|
|
<h1>', htmlspecialchars($title), '</h1>';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
protected function renderPaginationForm($pager, $form, $class='row')
|
|
|
|
{
|
|
|
|
echo '
|
|
|
|
<div class="', $class, ' clearfix justify-content-end">';
|
|
|
|
|
|
|
|
// Page index?
|
|
|
|
if (!empty($pager))
|
|
|
|
PageIndexWidget::paginate($pager);
|
|
|
|
|
|
|
|
// Form controls?
|
|
|
|
if (isset($form))
|
|
|
|
$this->renderInlineForm($form);
|
|
|
|
|
|
|
|
echo '
|
|
|
|
</div>';
|
|
|
|
}
|
|
|
|
|
|
|
|
protected function renderTableHead(array $headers)
|
|
|
|
{
|
2016-09-01 23:13:23 +02:00
|
|
|
echo '
|
|
|
|
<thead>
|
|
|
|
<tr>';
|
|
|
|
|
2024-08-27 11:55:22 +02:00
|
|
|
foreach ($headers as $th)
|
2016-09-01 23:13:23 +02:00
|
|
|
{
|
|
|
|
echo '
|
|
|
|
<th', (!empty($th['width']) ? ' width="' . $th['width'] . '"' : ''), (!empty($th['class']) ? ' class="' . $th['class'] . '"' : ''), ($th['colspan'] > 1 ? ' colspan="' . $th['colspan'] . '"' : ''), ' scope="', $th['scope'], '">',
|
|
|
|
$th['href'] ? '<a href="' . $th['href'] . '">' . $th['label'] . '</a>' : $th['label'];
|
|
|
|
|
2023-03-11 13:20:59 +01:00
|
|
|
if ($th['sort_mode'])
|
|
|
|
echo ' <i class="bi bi-caret-' . ($th['sort_mode'] === 'down' ? 'down' : 'up') . '-fill"></i>';
|
2016-09-01 23:13:23 +02:00
|
|
|
|
|
|
|
echo '</th>';
|
|
|
|
}
|
|
|
|
|
|
|
|
echo '
|
|
|
|
</tr>
|
2024-08-27 11:55:22 +02:00
|
|
|
</thead>';
|
|
|
|
}
|
|
|
|
|
|
|
|
protected function renderTableBody($body)
|
|
|
|
{
|
|
|
|
echo '
|
2016-09-01 23:13:23 +02:00
|
|
|
<tbody>';
|
|
|
|
|
|
|
|
if (is_array($body))
|
|
|
|
{
|
|
|
|
foreach ($body as $tr)
|
|
|
|
{
|
|
|
|
echo '
|
|
|
|
<tr', (!empty($tr['class']) ? ' class="' . $tr['class'] . '"' : ''), '>';
|
|
|
|
|
|
|
|
foreach ($tr['cells'] as $td)
|
2023-03-11 13:20:59 +01:00
|
|
|
{
|
2016-09-01 23:13:23 +02:00
|
|
|
echo '
|
2024-08-27 11:55:22 +02:00
|
|
|
<td',
|
|
|
|
(!empty($td['class']) ? ' class="' . $td['class'] . '"' : ''),
|
|
|
|
(!empty($td['width']) ? ' width="' . $td['width'] . '"' : ''), '>',
|
|
|
|
$td['value'],
|
|
|
|
'</td>';
|
2023-03-11 13:20:59 +01:00
|
|
|
}
|
2016-09-01 23:13:23 +02:00
|
|
|
|
|
|
|
echo '
|
|
|
|
</tr>';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
2024-08-27 11:55:22 +02:00
|
|
|
{
|
|
|
|
$header = $this->_t->getHeader();
|
2016-09-01 23:13:23 +02:00
|
|
|
echo '
|
|
|
|
<tr>
|
2023-03-11 13:20:59 +01:00
|
|
|
<td colspan="', count($header), '" class="fullwidth">', $body, '</td>
|
2016-09-01 23:13:23 +02:00
|
|
|
</tr>';
|
2023-03-11 13:20:59 +01:00
|
|
|
}
|
|
|
|
|
2024-08-27 11:55:22 +02:00
|
|
|
echo '
|
|
|
|
</tbody>';
|
2016-09-01 23:13:23 +02:00
|
|
|
}
|
|
|
|
|
2024-08-27 11:55:22 +02:00
|
|
|
protected function renderInlineForm($form)
|
2016-09-01 23:13:23 +02:00
|
|
|
{
|
2023-03-11 21:24:55 +01:00
|
|
|
if (!isset($form['is_embed']))
|
|
|
|
echo '
|
2023-03-11 13:20:59 +01:00
|
|
|
<form action="', $form['action'], '" method="', $form['method'], '" class="', $form['class'], '">';
|
2023-03-11 21:24:55 +01:00
|
|
|
else
|
|
|
|
echo '
|
|
|
|
<div class="', $form['class'], '">';
|
2023-03-11 13:20:59 +01:00
|
|
|
|
|
|
|
if (!empty($form['is_group']))
|
|
|
|
echo '
|
|
|
|
<div class="input-group">';
|
2016-09-01 23:13:23 +02:00
|
|
|
|
|
|
|
if (!empty($form['fields']))
|
2023-03-11 13:20:59 +01:00
|
|
|
{
|
2016-09-01 23:13:23 +02:00
|
|
|
foreach ($form['fields'] as $name => $field)
|
2023-03-11 13:20:59 +01:00
|
|
|
{
|
|
|
|
if ($field['type'] === 'select')
|
|
|
|
{
|
|
|
|
echo '
|
|
|
|
<select class="form-select" name="', $name, '"', (isset($field['onchange']) ? ' onchange="' . $field['onchange'] . '"' : ''), '>';
|
|
|
|
|
|
|
|
foreach ($field['values'] as $value => $caption)
|
|
|
|
{
|
|
|
|
if (!is_array($caption))
|
|
|
|
{
|
|
|
|
echo '
|
|
|
|
<option value="', $value, '"', $value === $field['selected'] ? ' selected' : '', '>', $caption, '</option>';
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
$label = $value;
|
|
|
|
$options = $caption;
|
|
|
|
|
|
|
|
echo '
|
|
|
|
<optgroup label="', $label, '">';
|
|
|
|
|
|
|
|
foreach ($options as $value => $caption)
|
|
|
|
{
|
|
|
|
echo '
|
|
|
|
<option value="', $value, '"', $value === $field['selected'] ? ' selected' : '', '>', $caption, '</option>';
|
|
|
|
}
|
|
|
|
|
|
|
|
echo '
|
|
|
|
</optgroup>';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
echo '
|
|
|
|
</select>';
|
|
|
|
}
|
|
|
|
else
|
|
|
|
echo '
|
|
|
|
<input name="', $name, '" id="field_', $name, '" type="', $field['type'], '" placeholder="', $field['placeholder'], '" class="form-control', isset($field['class']) ? ' ' . $field['class'] : '', '"', isset($field['value']) ? ' value="' . htmlspecialchars($field['value']) . '"' : '', '>';
|
|
|
|
|
|
|
|
if (isset($field['html_after']))
|
|
|
|
echo $field['html_after'];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
echo '
|
|
|
|
<input type="hidden" name="', Session::getSessionTokenKey(), '" value="', Session::getSessionToken(), '">';
|
2016-09-01 23:13:23 +02:00
|
|
|
|
|
|
|
if (!empty($form['buttons']))
|
|
|
|
foreach ($form['buttons'] as $name => $button)
|
2023-03-11 13:20:59 +01:00
|
|
|
{
|
2016-09-01 23:13:23 +02:00
|
|
|
echo '
|
2023-03-11 21:24:55 +01:00
|
|
|
<button class="btn ', isset($button['class']) ? $button['class'] : 'btn-primary', '" type="', $button['type'], '" name="', $name, '"';
|
|
|
|
|
|
|
|
if (isset($button['onclick']))
|
|
|
|
echo ' onclick="', $button['onclick'], '"';
|
|
|
|
|
|
|
|
echo '>', $button['caption'], '</button>';
|
2023-03-11 13:20:59 +01:00
|
|
|
|
|
|
|
if (isset($button['html_after']))
|
|
|
|
echo $button['html_after'];
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!empty($form['is_group']))
|
|
|
|
echo '
|
|
|
|
</div>';
|
2016-09-01 23:13:23 +02:00
|
|
|
|
2023-03-11 21:24:55 +01:00
|
|
|
if (!isset($form['is_embed']))
|
|
|
|
echo '
|
2023-03-11 13:20:59 +01:00
|
|
|
</form>';
|
2023-03-11 21:24:55 +01:00
|
|
|
else
|
|
|
|
echo '
|
|
|
|
</div>';
|
2016-09-01 23:13:23 +02:00
|
|
|
}
|
|
|
|
}
|