Implements front page widgets

main
Yasen Pramatarov 2024-07-27 12:29:28 +03:00
parent 350ba053e8
commit 7d459cf508
2 changed files with 47 additions and 119 deletions

View File

@ -64,63 +64,24 @@ try {
exit(); exit();
} }
// display the result // prepare the widget
echo "<a style=\"text-decoration: none;\" data-toggle=\"collapse\" href=\"#collapseLastDays\" role=\"button\" aria-expanded=\"true\" aria-controls=\"collapseLastDays\">"; $widget['name'] = 'LastDays';
echo "<div class=\"card bg-light card-body\">Conferences for the last 2 days</div></a>"; $widget['title'] = 'Conferences for the last 2 days';
echo "<div class=\"collapse show\" id=\"collapseLastDays\">";
if ($time_range_specified) { if ($time_range_specified) {
echo "<p class=\"m-3\">time period: <strong>$from_time - $until_time</strong></p>"; $widget['time_period'] = "<p class=\"m-3\">time period: <strong>$from_time - $until_time</strong></p>";
} else {
$widget['time_period'] = '';
} }
//// filters - time selection and sorting dropdowns
//include 'templates/results-filter.php';
// results table
echo "<div class=\"mb-5\">\n";
if (!empty($conferences['records'])) { if (!empty($conferences['records'])) {
$widget['full'] = true;
echo "\t<table class=\"table table-striped table-hover table-bordered\">\n"; $widget['table_headers'] = array_keys($conferences['records'][0]);
$widget['table_records'] = $conferences['records'];
echo "\t\t<thead class=\"thead-dark\">\n";
echo "\t\t\t<tr>\n";
// table headers
foreach (array_keys($conferences['records'][0]) as $header) {
echo "\t\t\t\t<th scope=\"col\">" . htmlspecialchars($header) . "</th>\n";
}
echo "\t\t\t</tr>\n";
echo "\t\t</thead>\n";
echo "\t\t<tbody>\n";
//table rows
foreach ($conferences['records'] as $row) {
echo "\t\t\t<tr>\n";
// sometimes $column is empty, we make it '' then
foreach ($row as $key => $column) {
if ($key === 'conference ID' && $column === $conference_id) {
echo "\t\t\t\t<td><strong>" . htmlspecialchars($column ?? '') . "</strong></td>\n";
} elseif ($key === 'conference name') {
echo "\t\t\t\t<td><a href=\"$app_root?page=conferences&name=" . htmlspecialchars($column ?? '') . "\">" . htmlspecialchars($column ?? '') . "</a></td>\n";
} else { } else {
echo "\t\t\t\t<td>" . htmlspecialchars($column ?? '') . "</td>\n"; $widget['full'] = false;
}
}
echo "\t\t\t</tr>\n";
} }
echo "\t\t</tbody>\n"; // display the widget
echo "\t</table>\n"; include('templates/widget.php');
} else {
echo '<p class="m-3">No matching conferences found.</p>';
}
echo "\n</div>\n";
echo "</div>";
echo "<br />"; echo "<br />";
@ -179,63 +140,23 @@ try {
exit(); exit();
} }
// display the result // prepare the widget
echo "<a style=\"text-decoration: none;\" data-toggle=\"collapse\" href=\"#collapseLastConferences\" role=\"button\" aria-expanded=\"true\" aria-controls=\"collapseLastConferences\">"; $widget['name'] = 'LastConferences';
echo "<div class=\"card bg-light card-body\">The last $conference_number conferences</div></a>"; $widget['title'] = "The last $conference_number conferences";
echo "<div class=\"collapse show\" id=\"collapseLastConferences\">";
if ($time_range_specified) { if ($time_range_specified) {
echo "<br />for the time period <strong>$from_time - $until_time</strong>"; $widget['time_period'] = "<p class=\"m-3\">time period: <strong>$from_time - $until_time</strong></p>";
} else {
$widget['time_period'] = '';
} }
//// filters - time selection and sorting dropdowns
//include 'templates/results-filter.php';
// results table
echo "<div class=\"mb-5\">\n";
if (!empty($conferences['records'])) { if (!empty($conferences['records'])) {
$widget['full'] = true;
echo "\t<table class=\"table table-striped table-hover table-bordered\">\n"; $widget['table_headers'] = array_keys($conferences['records'][0]);
$widget['table_records'] = $conferences['records'];
echo "\t\t<thead class=\"table-secondary\">\n";
echo "\t\t\t<tr>\n";
// table headers
foreach (array_keys($conferences['records'][0]) as $header) {
echo "\t\t\t\t<th scope=\"col\">" . htmlspecialchars($header) . "</th>\n";
}
echo "\t\t\t</tr>\n";
echo "\t\t</thead>\n";
echo "\t\t<tbody>\n";
//table rows
foreach ($conferences['records'] as $row) {
echo "\t\t\t<tr>\n";
// sometimes $column is empty, we make it '' then
foreach ($row as $key => $column) {
if ($key === 'conference ID') {
echo "\t\t\t\t<td><a href=\"$app_root?page=conferences&id=" . htmlspecialchars($column ?? '') . "\">" . htmlspecialchars($column ?? '') . "</a></td>\n";
} elseif ($key === 'conference name') {
echo "\t\t\t\t<td><a href=\"$app_root?page=conferences&name=" . htmlspecialchars($column ?? '') . "\">" . htmlspecialchars($column ?? '') . "</a></td>\n";
} else { } else {
echo "\t\t\t\t<td>" . htmlspecialchars($column ?? '') . "</td>\n"; $widget['full'] = false;
}
}
echo "\t\t\t</tr>\n";
} }
echo "\t\t</tbody>\n"; // display the widget
echo "\t</table>\n"; include('templates/widget.php');
} else {
echo '<p class="m-3">No matching conferences found.</p>';
}
echo "\n</div>\n";
echo "</div>";
?> ?>

View File

@ -1,10 +1,11 @@
<a style="text-decoration: none;" data-toggle="collapse" href="#collapseLastDays" role="button" aria-expanded="true" aria-controls="collapseLastDays"> <a style="text-decoration: none;" data-toggle="collapse" href="#collapse<?= $widget['name'] ?>" role="button" aria-expanded="true" aria-controls="collapse<?= $widget['name'] ?>">
<div class="card bg-light card-body"><?= $widget['title'] ?></div></a> <div class="card bg-light card-body"><?= $widget['title'] ?></div></a>
<div class="collapse show" id="collapseLastDays"> <div class="collapse show" id="collapse<?= $widget['name'] ?>">
<?= $widget['time_period'] ?> <?= $widget['time_period'] ?>
<div class="mb-5"> <div class="mb-5">
<?php if ($widget['full'] == true) { ?>
<table class="table table-striped table-hover table-bordered"> <table class="table table-striped table-hover table-bordered">
<thead class="thead-dark"> <thead class="thead-dark">
<tr> <tr>
@ -17,14 +18,20 @@
<?php foreach ($widget['table_records'] as $row) { ?> <?php foreach ($widget['table_records'] as $row) { ?>
<tr> <tr>
<?php foreach ($row as $key => $column) { <?php foreach ($row as $key => $column) {
if ($key === 'conference ID' && $column === $conference_id) { ?> if ($key === 'conference ID') { ?>
<td><strong><?= htmlspecialchars($column ?? '') ?></strong></td> <td><a href="<?= $app_root ?>?page=conferences&id=<?= htmlspecialchars($column ?? '') ?>"><?= htmlspecialchars($column ?? '') ?></a></td>
<?php } elseif ($key === 'conference name') { ?> <?php } elseif ($key === 'conference name') { ?>
<td><a href="<?= $app_root ?>?page=conferences&name="<?= htmlspecialchars($column ?? '') ?>"">"<?= htmlspecialchars($column ?? '') ?>"</a></td> <td><a href="<?= $app_root ?>?page=conferences&name=<?= htmlspecialchars($column ?? '') ?>"><?= htmlspecialchars($column ?? '') ?></a></td>
<?php } ?> <?php } else { ?>
<td><?= htmlspecialchars($column ?? '') ?></td>
<?php }
} ?>
</tr> </tr>
<?php } ?> <?php } ?>
</tbody> </tbody>
</table> </table>
<?php } else { ?>
<p class="m-3">No matching records found.</p>
<?php } ?>
</div> </div>
</div> </div>