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>";
}
//// filters - time selection and sorting dropdowns
//include 'templates/results-filter.php';
// results table
echo "<div class=\"mb-5\">\n";
if (!empty($conferences['records'])) {
echo "\t<table class=\"table table-striped table-hover table-bordered\">\n";
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 {
echo "\t\t\t\t<td>" . htmlspecialchars($column ?? '') . "</td>\n";
}
}
echo "\t\t\t</tr>\n";
}
echo "\t\t</tbody>\n";
echo "\t</table>\n";
} else { } else {
echo '<p class="m-3">No matching conferences found.</p>'; $widget['time_period'] = '';
}
if (!empty($conferences['records'])) {
$widget['full'] = true;
$widget['table_headers'] = array_keys($conferences['records'][0]);
$widget['table_records'] = $conferences['records'];
} else {
$widget['full'] = false;
} }
echo "\n</div>\n";
echo "</div>"; // display the widget
include('templates/widget.php');
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>";
}
//// filters - time selection and sorting dropdowns
//include 'templates/results-filter.php';
// results table
echo "<div class=\"mb-5\">\n";
if (!empty($conferences['records'])) {
echo "\t<table class=\"table table-striped table-hover table-bordered\">\n";
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 {
echo "\t\t\t\t<td>" . htmlspecialchars($column ?? '') . "</td>\n";
}
}
echo "\t\t\t</tr>\n";
}
echo "\t\t</tbody>\n";
echo "\t</table>\n";
} else { } else {
echo '<p class="m-3">No matching conferences found.</p>'; $widget['time_period'] = '';
}
if (!empty($conferences['records'])) {
$widget['full'] = true;
$widget['table_headers'] = array_keys($conferences['records'][0]);
$widget['table_records'] = $conferences['records'];
} else {
$widget['full'] = false;
} }
echo "\n</div>\n";
echo "</div>";
// display the widget
include('templates/widget.php');
?> ?>

View File

@ -1,30 +1,37 @@
<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>
<?php foreach ($widget['table_headers'] as $header) { ?> <?php foreach ($widget['table_headers'] as $header) { ?>
<th scope="col"><?= htmlspecialchars($header) ?></th> <th scope="col"><?= htmlspecialchars($header) ?></th>
<?php } ?> <?php } ?>
</tr> </tr>
</thead> </thead>
<tbody> <tbody>
<?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>