forked from Public/pics
Replace generic alert, form and table templates with new Bootstrap equivalents
This commit is contained in:
@@ -26,7 +26,7 @@ class AlbumIndex extends SubTemplate
|
||||
protected function html_content()
|
||||
{
|
||||
echo '
|
||||
<div class="tiled_grid">';
|
||||
<div class="tiled_grid clearfix">';
|
||||
|
||||
foreach (array_chunk($this->albums, 3) as $photos)
|
||||
{
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
* Kabuki CMS (C) 2013-2015, Aaron van Geffen
|
||||
*****************************************************************************/
|
||||
|
||||
class Alert extends SubTemplate
|
||||
class Alert extends Template
|
||||
{
|
||||
private $_type;
|
||||
private $_message;
|
||||
@@ -16,20 +16,20 @@ class Alert extends SubTemplate
|
||||
{
|
||||
$this->_title = $title;
|
||||
$this->_message = $message;
|
||||
$this->_type = in_array($type, ['alert', 'error', 'success', 'info']) ? $type : 'alert';
|
||||
$this->_type = in_array($type, ['success', 'info', 'warning', 'danger']) ? $type : 'info';
|
||||
}
|
||||
|
||||
protected function html_content()
|
||||
public function html_main()
|
||||
{
|
||||
echo '
|
||||
<div class="alert', $this->_type != 'alert' ? ' alert-' . $this->_type : '', '">', (!empty($this->_title) ? '
|
||||
<strong>' . $this->_title . '</strong><br>' : ''), '<p>', $this->_message, '</p>';
|
||||
|
||||
$this->additional_alert_content();
|
||||
|
||||
echo '</div>';
|
||||
<div class="alert', $this->_type !== 'alert' ? ' alert-' . $this->_type : '', '">'
|
||||
, !empty($this->_title) ? '<strong>' . $this->_title . '</strong><br>' : '', '
|
||||
', $this->_message,
|
||||
$this->additional_alert_content(), '
|
||||
</div>';
|
||||
}
|
||||
|
||||
protected function additional_alert_content()
|
||||
{}
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,52 +3,42 @@
|
||||
* FormView.php
|
||||
* Contains the form template.
|
||||
*
|
||||
* Kabuki CMS (C) 2013-2015, Aaron van Geffen
|
||||
* Global Data Lab code (C) Radboud University Nijmegen
|
||||
* Programming (C) Aaron van Geffen, 2015-2022
|
||||
*****************************************************************************/
|
||||
|
||||
class FormView extends SubTemplate
|
||||
{
|
||||
private $content_below;
|
||||
private $content_above;
|
||||
private $data;
|
||||
private $missing;
|
||||
private $fields;
|
||||
private $request_method;
|
||||
private $request_url;
|
||||
private $form;
|
||||
private array $data;
|
||||
private array $missing;
|
||||
private $title;
|
||||
|
||||
public function __construct(Form $form, $title = '')
|
||||
{
|
||||
$this->form = $form;
|
||||
$this->title = $title;
|
||||
$this->request_url = $form->request_url;
|
||||
$this->request_method = $form->request_method;
|
||||
$this->fields = $form->getFields();
|
||||
$this->missing = $form->getMissing();
|
||||
$this->data = $form->getData();
|
||||
$this->content_above = $form->content_above;
|
||||
$this->content_below = $form->content_below;
|
||||
}
|
||||
|
||||
protected function html_content($exclude = [], $include = [])
|
||||
{
|
||||
if (!empty($this->title))
|
||||
echo '
|
||||
<div class="admin_box">
|
||||
<h2>', htmlspecialchars($this->title), '</h2>';
|
||||
<h1>', $this->title, '</h1>';
|
||||
|
||||
foreach ($this->_subtemplates as $template)
|
||||
$template->html_main();
|
||||
|
||||
echo '
|
||||
<form action="', $this->request_url, '" method="', $this->request_method, '" enctype="multipart/form-data">';
|
||||
<form action="', $this->form->request_url, '" method="', $this->form->request_method, '" enctype="multipart/form-data">';
|
||||
|
||||
if (isset($this->content_above))
|
||||
echo $this->content_above;
|
||||
if (isset($this->form->content_above))
|
||||
echo $this->form->content_above;
|
||||
|
||||
echo '
|
||||
<dl>';
|
||||
$this->missing = $this->form->getMissing();
|
||||
$this->data = $this->form->getData();
|
||||
|
||||
foreach ($this->fields as $field_id => $field)
|
||||
foreach ($this->form->getFields() as $field_id => $field)
|
||||
{
|
||||
// Either we have a blacklist
|
||||
if (!empty($exclude) && in_array($field_id, $exclude))
|
||||
@@ -62,107 +52,230 @@ class FormView extends SubTemplate
|
||||
}
|
||||
|
||||
echo '
|
||||
</dl>
|
||||
<input type="hidden" name="', Session::getSessionTokenKey(), '" value="', Session::getSessionToken(), '">
|
||||
<div style="clear: both">
|
||||
<button type="submit" class="btn btn-primary">Save information</button>';
|
||||
<div class="form-group">
|
||||
<div class="offset-sm-2 col-sm-10">
|
||||
<button type="submit" name="submit" class="btn btn-primary">', $this->form->getSubmitButtonCaption(), '</button>';
|
||||
|
||||
if (isset($this->content_below))
|
||||
if (isset($this->form->content_below))
|
||||
echo '
|
||||
', $this->content_below;
|
||||
', $this->form->content_below;
|
||||
|
||||
echo '
|
||||
</div>
|
||||
</div>
|
||||
</form>';
|
||||
|
||||
if (!empty($this->title))
|
||||
echo '
|
||||
</div>';
|
||||
}
|
||||
|
||||
protected function renderField($field_id, $field)
|
||||
protected function renderField($field_id, array $field)
|
||||
{
|
||||
if (isset($field['before_html']))
|
||||
echo '</dl>
|
||||
', $field['before_html'], '
|
||||
<dl>';
|
||||
|
||||
if ($field['type'] != 'checkbox' && isset($field['label']))
|
||||
echo '
|
||||
<dt class="cont_', $field_id, isset($field['tab_class']) ? ' target target-' . $field['tab_class'] : '', '"', in_array($field_id, $this->missing) ? ' style="color: red"' : '', '>', $field['label'], '</dt>';
|
||||
elseif ($field['type'] === 'checkbox' && isset($field['header']))
|
||||
echo '
|
||||
<dt class="cont_', $field_id, isset($field['tab_class']) ? ' target target-' . $field['tab_class'] : '', '"', in_array($field_id, $this->missing) ? ' style="color: red"' : '', '>', $field['header'], '</dt>';
|
||||
', $field['before_html'];
|
||||
|
||||
echo '
|
||||
<dd class="cont_', $field_id, isset($field['dd_class']) ? ' ' . $field['dd_class'] : '', isset($field['tab_class']) ? ' target target-' . $field['tab_class'] : '', '">';
|
||||
<div class="row mb-2">';
|
||||
|
||||
if (isset($field['before']))
|
||||
echo $field['before'];
|
||||
|
||||
if ($field['type'] !== 'checkbox')
|
||||
if (isset($field['label']))
|
||||
echo '
|
||||
<label class="col-sm-2 col-form-label" for="', $field_id, '"', in_array($field_id, $this->missing) ? ' style="color: red"' : '', '>', $field['label'], ':</label>
|
||||
<div class="', isset($field['class']) ? $field['class'] : 'col-sm-6', '">';
|
||||
else
|
||||
echo '
|
||||
<div class="offset-sm-2 ', isset($field['class']) ? $field['class'] : 'col-sm-6', '">';
|
||||
|
||||
switch ($field['type'])
|
||||
{
|
||||
case 'select':
|
||||
echo '
|
||||
<select name="', $field_id, '" id="', $field_id, '"', !empty($field['disabled']) ? ' disabled' : '', '>';
|
||||
|
||||
if (isset($field['placeholder']))
|
||||
echo '
|
||||
<option value="">', $field['placeholder'], '</option>';
|
||||
|
||||
foreach ($field['options'] as $value => $option)
|
||||
echo '
|
||||
<option value="', $value, '"', $this->data[$field_id] == $value ? ' selected' : '', '>', htmlentities($option), '</option>';
|
||||
|
||||
echo '
|
||||
</select>';
|
||||
$this->renderSelect($field_id, $field);
|
||||
break;
|
||||
|
||||
case 'radio':
|
||||
foreach ($field['options'] as $value => $option)
|
||||
echo '
|
||||
<input type="radio" name="', $field_id, '" value="', $value, '"', $this->data[$field_id] == $value ? ' checked' : '', !empty($field['disabled']) ? ' disabled' : '', '> ', htmlentities($option);
|
||||
$this->renderRadio($field_id, $field);
|
||||
break;
|
||||
|
||||
case 'checkbox':
|
||||
echo '
|
||||
<label><input type="checkbox"', $this->data[$field_id] ? ' checked' : '', !empty($field['disabled']) ? ' disabled' : '', ' name="', $field_id, '"> ', htmlentities($field['label']), '</label>';
|
||||
$this->renderCheckbox($field_id, $field);
|
||||
break;
|
||||
|
||||
case 'textarea':
|
||||
echo '
|
||||
<textarea name="', $field_id, '" id="', $field_id, '" cols="', isset($field['columns']) ? $field['columns'] : 40, '" rows="', isset($field['rows']) ? $field['rows'] : 4, '"', !empty($field['disabled']) ? ' disabled' : '', '>', $this->data[$field_id], '</textarea>';
|
||||
$this->renderTextArea($field_id, $field);
|
||||
break;
|
||||
|
||||
case 'color':
|
||||
echo '
|
||||
<input type="color" name="', $field_id, '" id="', $field_id, '" value="', htmlentities($this->data[$field_id]), '"', !empty($field['disabled']) ? ' disabled' : '', '>';
|
||||
$this->renderColor($field_id, $field);
|
||||
break;
|
||||
|
||||
case 'numeric':
|
||||
echo '
|
||||
<input type="number"', isset($field['step']) ? ' step="' . $field['step'] . '"' : '', ' min="', isset($field['min_value']) ? $field['min_value'] : '0', '" max="', isset($field['max_value']) ? $field['max_value'] : '9999', '" name="', $field_id, '" id="', $field_id, '"', isset($field['size']) ? ' size="' . $field['size'] . '"' : '', isset($field['maxlength']) ? ' maxlength="' . $field['maxlength'] . '"' : '', ' value="', htmlentities($this->data[$field_id]), '"', !empty($field['disabled']) ? ' disabled' : '', '>';
|
||||
$this->renderNumeric($field_id, $field);
|
||||
break;
|
||||
|
||||
case 'file':
|
||||
if (!empty($this->data[$field_id]))
|
||||
echo '<img src="', $this->data[$field_id], '" alt=""><br>';
|
||||
$this->renderFile($field_id, $field);
|
||||
break;
|
||||
|
||||
echo '
|
||||
<input type="file" name="', $field_id, '" id="', $field_id, '"', !empty($field['disabled']) ? ' disabled' : '', '>';
|
||||
case 'captcha':
|
||||
$this->renderCaptcha($field_id, $field);
|
||||
break;
|
||||
|
||||
case 'text':
|
||||
case 'password':
|
||||
default:
|
||||
echo '
|
||||
<input type="', $field['type'], '" name="', $field_id, '" id="', $field_id, '"', isset($field['size']) ? ' size="' . $field['size'] . '"' : '', isset($field['maxlength']) ? ' maxlength="' . $field['maxlength'] . '"' : '', ' value="', htmlentities($this->data[$field_id]), '"', !empty($field['disabled']) ? ' disabled' : '', isset($field['trigger']) ? ' class="trigger-' . $field['trigger'] . '"' : '', '>';
|
||||
$this->renderText($field_id, $field);
|
||||
}
|
||||
|
||||
if (isset($field['after']))
|
||||
echo ' ', $field['after'];
|
||||
|
||||
if ($field['type'] !== 'checkbox')
|
||||
echo '
|
||||
</div>';
|
||||
|
||||
echo '
|
||||
</dd>';
|
||||
</div>';
|
||||
}
|
||||
|
||||
private function renderCaptcha($field_id, array $field)
|
||||
{
|
||||
echo '
|
||||
<div class="g-recaptcha" data-sitekey="', RECAPTCHA_API_KEY, '"></div>
|
||||
<script src="https://www.google.com/recaptcha/api.js"></script>';
|
||||
}
|
||||
|
||||
private function renderCheckbox($field_id, array $field)
|
||||
{
|
||||
echo '
|
||||
<div class="offset-sm-2 col-sm-10">
|
||||
<div class="form-check">
|
||||
<input class="form-check-input" type="checkbox"', $this->data[$field_id] ? ' checked' : '', !empty($field['disabled']) ? ' disabled' : '', ' name="', $field_id, '" id="check-', $field_id, '">
|
||||
<label class="form-check-label" for="check-', $field_id, '">
|
||||
', $field['label'], '
|
||||
</label>
|
||||
</div>
|
||||
</div>';
|
||||
}
|
||||
|
||||
private function renderColor($field_id, array $field)
|
||||
{
|
||||
echo '
|
||||
<input class="form-control" type="color" name="', $field_id, '" id="', $field_id, '" value="', htmlspecialchars($this->data[$field_id]), '"', !empty($field['disabled']) ? ' disabled' : '', '>';
|
||||
}
|
||||
|
||||
private function renderFile($field_id, array $field)
|
||||
{
|
||||
if (!empty($this->data[$field_id]))
|
||||
echo 'Currently using asset <tt>', $this->data[$field_id], '</tt>. Upload to overwrite.<br>';
|
||||
|
||||
echo '
|
||||
<input class="form-control" type="file" name="', $field_id, '" id="', $field_id, '"', !empty($field['disabled']) ? ' disabled' : '', '>';
|
||||
}
|
||||
|
||||
private function renderNumeric($field_id, array $field)
|
||||
{
|
||||
echo '
|
||||
<input class="form-control" type="number"',
|
||||
isset($field['step']) ? ' step="' . $field['step'] . '"' : '',
|
||||
' min="', isset($field['min_value']) ? $field['min_value'] : '0', '"',
|
||||
' max="', isset($field['max_value']) ? $field['max_value'] : '9999', '"',
|
||||
' name="', $field_id, '" id="', $field_id, '"',
|
||||
isset($field['size']) ? ' size="' . $field['size'] . '"' : '',
|
||||
isset($field['maxlength']) ? ' maxlength="' . $field['maxlength'] . '"' : '',
|
||||
' value="', htmlspecialchars($this->data[$field_id]), '"',
|
||||
!empty($field['disabled']) ? ' disabled' : '', '>';
|
||||
}
|
||||
|
||||
private function renderRadio($field_id, array $field)
|
||||
{
|
||||
foreach ($field['options'] as $value => $option)
|
||||
echo '
|
||||
<div class="form-check">
|
||||
<input class="form-check-input" type="radio" name="', $field_id, '" id="radio-', $field_id, '-', $value, '" value="', $value, '"', $this->data[$field_id] == $value ? ' checked' : '', !empty($field['disabled']) ? ' disabled' : '', '>
|
||||
<label class="form-check-label" for="radio-', $field_id, '-', $value, '">
|
||||
', htmlspecialchars($option), '
|
||||
</label>
|
||||
</div>';
|
||||
}
|
||||
|
||||
private function renderSelect($field_id, array $field)
|
||||
{
|
||||
echo '
|
||||
<select class="form-select" name="', $field_id, !empty($field['multiple']) ? '[]' : '',
|
||||
'" id="', $field_id, '"',
|
||||
!empty($field['disabled']) ? ' disabled' : '',
|
||||
!empty($field['multiple']) ? ' multiple' : '',
|
||||
!empty($field['size']) ? ' size="' . $field['size'] . '"' : '',
|
||||
'>';
|
||||
|
||||
if (isset($field['placeholder']))
|
||||
echo '
|
||||
<option value="">', $field['placeholder'], '</option>';
|
||||
|
||||
foreach ($field['options'] as $key => $value)
|
||||
{
|
||||
if (is_array($value))
|
||||
{
|
||||
assert(empty($field['multiple']));
|
||||
$this->renderSelectOptionGroup($field_id, $key, $value);
|
||||
}
|
||||
else
|
||||
$this->renderSelectOption($field_id, $value, $key, !empty($field['multiple']));
|
||||
}
|
||||
|
||||
echo '
|
||||
</select>';
|
||||
}
|
||||
|
||||
private function renderSelectOption($field_id, $label, $value, $multiple = false)
|
||||
{
|
||||
echo '
|
||||
<option value="', $value, '"',
|
||||
!$multiple && $this->data[$field_id] == $value ? ' selected' : '',
|
||||
$multiple && in_array($value, $this->data[$field_id]) ? ' selected' : '',
|
||||
'>', htmlspecialchars($label), '</option>';
|
||||
}
|
||||
|
||||
private function renderSelectOptionGroup($field_id, $label, $options)
|
||||
{
|
||||
echo '
|
||||
<optgroup label="', $label, '">';
|
||||
|
||||
foreach ($options as $value => $option)
|
||||
$this->renderSelectOption($field_id, $option, $value);
|
||||
|
||||
echo '
|
||||
</optgroup>';
|
||||
}
|
||||
|
||||
private function renderText($field_id, array $field)
|
||||
{
|
||||
echo '
|
||||
<input class="form-control" ',
|
||||
'type="', $field['type'], '" ',
|
||||
'name="', $field_id, '" ',
|
||||
'id="', $field_id, '"',
|
||||
isset($field['size']) ? ' size="' . $field['size'] . '"' : '',
|
||||
isset($field['maxlength']) ? ' maxlength="' . $field['maxlength'] . '"' : '',
|
||||
isset($this->data[$field_id]) ? ' value="' . htmlspecialchars($this->data[$field_id]) . '"' : '',
|
||||
isset($field['placeholder']) ? ' placeholder="' . $field['placeholder'] . '"' : '',
|
||||
!empty($field['disabled']) ? ' disabled' : '',
|
||||
isset($field['trigger']) ? ' class="trigger-' . $field['trigger'] . '"' : '',
|
||||
'>';
|
||||
}
|
||||
|
||||
private function renderTextArea($field_id, array $field)
|
||||
{
|
||||
echo '
|
||||
<textarea class="form-control' .
|
||||
'" name="', $field_id,
|
||||
'" id="', $field_id,
|
||||
'" cols="', isset($field['columns']) ? $field['columns'] : 40,
|
||||
'" rows="', isset($field['rows']) ? $field['rows'] : 4, '"',
|
||||
isset($field['placeholder']) ? ' placeholder="' . $field['placeholder'] . '"' : '',
|
||||
'"', !empty($field['disabled']) ? ' disabled' : '',
|
||||
'>', $this->data[$field_id], '</textarea>';
|
||||
}
|
||||
}
|
||||
|
||||
61
templates/PageIndexWidget.php
Normal file
61
templates/PageIndexWidget.php
Normal file
@@ -0,0 +1,61 @@
|
||||
<?php
|
||||
/*****************************************************************************
|
||||
* PageIndexWidget.php
|
||||
* Contains the template that displays a page index.
|
||||
*
|
||||
* Global Data Lab code (C) Radboud University Nijmegen
|
||||
* Programming (C) Aaron van Geffen, 2015-2022
|
||||
*****************************************************************************/
|
||||
|
||||
class PageIndexWidget extends Template
|
||||
{
|
||||
private $index;
|
||||
private string $class;
|
||||
|
||||
public function __construct(PageIndex $index)
|
||||
{
|
||||
$this->index = $index;
|
||||
$this->class = $index->getPageIndexClass();
|
||||
}
|
||||
|
||||
public function html_main()
|
||||
{
|
||||
self::paginate($this->index, $this->class);
|
||||
}
|
||||
|
||||
public static function paginate(PageIndex $index, $class = null)
|
||||
{
|
||||
$page_index = $index->getPageIndex();
|
||||
if (empty($page_index) || count($page_index) == 1)
|
||||
return;
|
||||
|
||||
if (!isset($class))
|
||||
$class = $index->getPageIndexClass();
|
||||
|
||||
echo '
|
||||
<ul class="pagination', $class ? ' ' . $class : '', '">
|
||||
<li class="page-item', empty($page_index['previous']) ? ' disabled' : '', '">',
|
||||
'<a class="page-link"', !empty($page_index['previous']) ? ' href="' . $page_index['previous']['href'] . '"' : '', '>',
|
||||
'« previous</a></li>';
|
||||
|
||||
foreach ($page_index as $key => $page)
|
||||
{
|
||||
if (!is_numeric($key))
|
||||
continue;
|
||||
|
||||
if (!is_array($page))
|
||||
echo '
|
||||
<li class="page-item disabled"><a class="page-link">...</a></li>';
|
||||
else
|
||||
echo '
|
||||
<li class="page-item', $page['is_selected'] ? ' active" aria-current="page' : '', '">',
|
||||
'<a class="page-link" href="', $page['href'], '">', $page['index'], '</a></li>';
|
||||
}
|
||||
|
||||
echo '
|
||||
<li class="page-item', empty($page_index['next']) ? ' disabled' : '', '">',
|
||||
'<a class="page-link"', !empty($page_index['next']) ? ' href="' . $page_index['next']['href'] . '"' : '', '>',
|
||||
'next »</a></li>
|
||||
</ul>';
|
||||
}
|
||||
}
|
||||
@@ -1,64 +0,0 @@
|
||||
<?php
|
||||
/*****************************************************************************
|
||||
* Pagination.php
|
||||
* Contains the pagination template.
|
||||
*
|
||||
* Kabuki CMS (C) 2013-2016, Aaron van Geffen
|
||||
*****************************************************************************/
|
||||
|
||||
class Pagination extends SubTemplate
|
||||
{
|
||||
private $index;
|
||||
private static $unique_index_count = 0;
|
||||
private string $class;
|
||||
|
||||
public function __construct(PageIndex $index)
|
||||
{
|
||||
$this->index = $index;
|
||||
$this->class = $index->getPageIndexClass();
|
||||
}
|
||||
|
||||
protected function html_content()
|
||||
{
|
||||
$index = $this->index->getPageIndex();
|
||||
|
||||
echo '
|
||||
<div class="table_pagination', !empty($this->class) ? ' ' . $this->class : '', '">
|
||||
<ul>
|
||||
<li class="first"><', !empty($index['previous']) ? 'a href="' . $index['previous']['href'] . '"' : 'span', '>« previous</', !empty($index['previous']) ? 'a' : 'span', '></li>';
|
||||
|
||||
$num_wildcards = 0;
|
||||
foreach ($index as $key => $page)
|
||||
{
|
||||
if (!is_numeric($key))
|
||||
continue;
|
||||
|
||||
if (!is_array($page))
|
||||
{
|
||||
$num_wildcards++;
|
||||
echo '
|
||||
<li class="page-padding" onclick="javascript:promptGoToPage(', self::$unique_index_count, ')"><span>...</span></li>';
|
||||
}
|
||||
else
|
||||
echo '
|
||||
<li class="page-number', $page['is_selected'] ? ' active' : '', '"><a href="', $page['href'], '">', $page['index'], '</a></li>';
|
||||
}
|
||||
|
||||
echo '
|
||||
<li class="last"><', !empty($index['next']) ? 'a href="' . $index['next']['href'] . '"' : 'span', '>next »</', !empty($index['next']) ? 'a' : 'span', '></li>
|
||||
</ul>
|
||||
</div>';
|
||||
|
||||
if ($num_wildcards)
|
||||
{
|
||||
echo '
|
||||
<script type="text/javascript">
|
||||
var page_index_', self::$unique_index_count++, ' = {
|
||||
wildcard_url: "', $this->index->getLink("%d"), '",
|
||||
num_pages: ', $this->index->getNumberOfPages(), ',
|
||||
per_page: ', $this->index->getItemsPerPage(), '
|
||||
};
|
||||
</script>';
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -45,7 +45,7 @@ class PhotosIndex extends SubTemplate
|
||||
protected function html_content()
|
||||
{
|
||||
echo '
|
||||
<div class="tiled_grid">';
|
||||
<div class="tiled_grid clearfix">';
|
||||
|
||||
for ($i = $this->row_limit; $i > 0 && $row = $this->mosaic->getRow(); $i--)
|
||||
{
|
||||
|
||||
@@ -3,56 +3,73 @@
|
||||
* TabularData.php
|
||||
* Contains the template that displays tabular data.
|
||||
*
|
||||
* Kabuki CMS (C) 2013-2015, Aaron van Geffen
|
||||
* Global Data Lab code (C) Radboud University Nijmegen
|
||||
* Programming (C) Aaron van Geffen, 2015-2022
|
||||
*****************************************************************************/
|
||||
|
||||
class TabularData extends SubTemplate
|
||||
{
|
||||
private Pagination $pager;
|
||||
private GenericTable $_t;
|
||||
|
||||
public function __construct(GenericTable $table)
|
||||
{
|
||||
$this->_t = $table;
|
||||
|
||||
$pageIndex = $table->getPageIndex();
|
||||
if ($pageIndex)
|
||||
$this->pager = new Pagination($pageIndex);
|
||||
}
|
||||
|
||||
protected function html_content()
|
||||
{
|
||||
echo '
|
||||
<div class="admin_box">';
|
||||
|
||||
$title = $this->_t->getTitle();
|
||||
if (!empty($title))
|
||||
{
|
||||
$titleclass = $this->_t->getTitleClass();
|
||||
echo '
|
||||
<h2>', $title, '</h2>';
|
||||
<div class="generic-table', !empty($titleclass) ? ' ' . $titleclass : '', '">
|
||||
<h1>', htmlspecialchars($title), '</h1>';
|
||||
}
|
||||
|
||||
// Showing a page index?
|
||||
if (isset($this->pager))
|
||||
$this->pager->html_content();
|
||||
foreach ($this->_subtemplates as $template)
|
||||
$template->html_main();
|
||||
|
||||
// Maybe even a small form?
|
||||
if (isset($this->_t->form_above))
|
||||
$this->showForm($this->_t->form_above);
|
||||
// Showing an inline form?
|
||||
$pager = $this->_t->getPageIndex();
|
||||
if (!empty($pager) || isset($this->_t->form_above))
|
||||
{
|
||||
echo '
|
||||
<div class="row clearfix justify-content-end">';
|
||||
|
||||
// Page index?
|
||||
if (!empty($pager))
|
||||
PageIndexWidget::paginate($pager);
|
||||
|
||||
// Form controls?
|
||||
if (isset($this->_t->form_above))
|
||||
$this->showForm($this->_t->form_above);
|
||||
|
||||
echo '
|
||||
</div>';
|
||||
}
|
||||
|
||||
$tableClass = $this->_t->getTableClass();
|
||||
if ($tableClass)
|
||||
echo '
|
||||
<div class="', $tableClass, '">';
|
||||
|
||||
// Build the table!
|
||||
echo '
|
||||
<table class="table table-striped">
|
||||
<table class="table table-striped table-condensed">
|
||||
<thead>
|
||||
<tr>';
|
||||
|
||||
// Show the table's headers.
|
||||
foreach ($this->_t->getHeader() as $th)
|
||||
// Show all headers in their full glory!
|
||||
$header = $this->_t->getHeader();
|
||||
foreach ($header as $th)
|
||||
{
|
||||
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'];
|
||||
|
||||
if ($th['sort_mode'] )
|
||||
echo ' ', $th['sort_mode'] === 'up' ? '↑' : '↓';
|
||||
if ($th['sort_mode'])
|
||||
echo ' <i class="bi bi-caret-' . ($th['sort_mode'] === 'down' ? 'down' : 'up') . '-fill"></i>';
|
||||
|
||||
echo '</th>';
|
||||
}
|
||||
@@ -62,7 +79,7 @@ class TabularData extends SubTemplate
|
||||
</thead>
|
||||
<tbody>';
|
||||
|
||||
// Show the table's body.
|
||||
// The body is what we came to see!
|
||||
$body = $this->_t->getBody();
|
||||
if (is_array($body))
|
||||
{
|
||||
@@ -72,51 +89,134 @@ class TabularData extends SubTemplate
|
||||
<tr', (!empty($tr['class']) ? ' class="' . $tr['class'] . '"' : ''), '>';
|
||||
|
||||
foreach ($tr['cells'] as $td)
|
||||
{
|
||||
echo '
|
||||
<td', (!empty($td['width']) ? ' width="' . $td['width'] . '"' : ''), '>', $td['value'], '</td>';
|
||||
<td', (!empty($td['width']) ? ' width="' . $td['width'] . '"' : ''), '>';
|
||||
|
||||
if (!empty($td['class']))
|
||||
echo '<span class="', $td['class'], '">', $td['value'], '</span>';
|
||||
else
|
||||
echo $td['value'];
|
||||
|
||||
echo '</td>';
|
||||
}
|
||||
|
||||
echo '
|
||||
</tr>';
|
||||
}
|
||||
}
|
||||
// !!! Sum colspan!
|
||||
else
|
||||
echo '
|
||||
<tr>
|
||||
<td colspan="', count($this->_t->getHeader()), '">', $body, '</td>
|
||||
<td colspan="', count($header), '" class="fullwidth">', $body, '</td>
|
||||
</tr>';
|
||||
|
||||
echo '
|
||||
</tbody>
|
||||
</table>';
|
||||
|
||||
// Maybe another small form?
|
||||
if (isset($this->_t->form_below))
|
||||
$this->showForm($this->_t->form_below);
|
||||
if ($tableClass)
|
||||
echo '
|
||||
</div>';
|
||||
|
||||
// Showing a page index?
|
||||
if (isset($this->pager))
|
||||
$this->pager->html_content();
|
||||
// Showing an inline form?
|
||||
if (!empty($pager) || isset($this->_t->form_below))
|
||||
{
|
||||
echo '
|
||||
<div class="row clearfix justify-content-end">';
|
||||
|
||||
echo '
|
||||
// Page index?
|
||||
if (!empty($pager))
|
||||
PageIndexWidget::paginate($pager);
|
||||
|
||||
// Form controls?
|
||||
if (isset($this->_t->form_below))
|
||||
$this->showForm($this->_t->form_below);
|
||||
|
||||
echo '
|
||||
</div>';
|
||||
}
|
||||
|
||||
if (!empty($title))
|
||||
echo '
|
||||
</div>';
|
||||
}
|
||||
|
||||
protected function showForm($form)
|
||||
{
|
||||
echo '
|
||||
<form action="', $form['action'], '" method="', $form['method'], '" class="table_form ', $form['class'], '">';
|
||||
<form action="', $form['action'], '" method="', $form['method'], '" class="', $form['class'], '">';
|
||||
|
||||
if (!empty($form['is_group']))
|
||||
echo '
|
||||
<div class="input-group">';
|
||||
|
||||
if (!empty($form['fields']))
|
||||
{
|
||||
foreach ($form['fields'] as $name => $field)
|
||||
echo '
|
||||
<input name="', $name, '" type="', $field['type'], '" placeholder="', $field['placeholder'], '"', isset($field['class']) ? ' class="' . $field['class'] . '"' : '', isset($field['value']) ? ' value="' . $field['value'] . '"' : '', '>';
|
||||
{
|
||||
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(), '">';
|
||||
|
||||
if (!empty($form['buttons']))
|
||||
foreach ($form['buttons'] as $name => $button)
|
||||
{
|
||||
echo '
|
||||
<input name="', $name, '" type="', $button['type'], '" value="', $button['caption'], '" class="btn', isset($button['class']) ? ' ' . $button['class'] . '' : '', '">';
|
||||
<button class="btn ', isset($button['class']) ? $button['class'] : 'btn-primary', '" type="', $button['type'], '" name="', $name, '">', $button['caption'], '</button>';
|
||||
|
||||
if (isset($button['html_after']))
|
||||
echo $button['html_after'];
|
||||
}
|
||||
|
||||
if (!empty($form['is_group']))
|
||||
echo '
|
||||
</div>';
|
||||
|
||||
echo '
|
||||
</form>';
|
||||
</form>';
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user