trackdirect-hmk/htdocs/public/views/search.php

133 lines
7.0 KiB
PHP
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<?php require dirname(__DIR__) . "../../includes/bootstrap.php"; ?>
<?php
$stations = [];
$seconds = $_GET['seconds'] ?? 0;
$page = $_GET['page'] ?? 1;
$rows = $_GET['rows'] ?? 50;
$offset = ($page - 1) * $rows;
$count = 0;
if (isset($_GET['q'])) {
$stations = StationRepository::getInstance()->getObjectListByQueryString($_GET['q'], $seconds, $rows, $offset);
$count = StationRepository::getInstance()->getNumberOfStationsByQueryString($_GET['q'], $seconds);
}
$pages = ceil($count / $rows);
?>
<title>Поиск объектов</title>
<div class="modal-inner-content" style="padding-bottom: 30px;">
<p>
Введите начало позывного/идентификатора станции (или просто нажмите «Ок», чтобы просмотреть все).
</p>
<form id="station-search-form" method="get" action="">
<div style="margin-bottom: 5px;">
<select name ="seconds" style="width: 280px;" id="station-search-form-seconds">
<option <?php echo ($seconds == 0 ? 'selected' : ''); ?> value="0">Включить в поиск все известные станции</option>
<option <?php echo ($seconds == 60 ? 'selected' : ''); ?> value="60">Только станции, активные в последний час</option>
<option <?php echo ($seconds == 360 ? 'selected' : ''); ?> value="360">Только станции, активные в последние 6 часов</option>
<option <?php echo ($seconds == 720 ? 'selected' : ''); ?> value="720">Только станции, активные в последние 12 часов</option>
</select>
</div>
<div>
<input type="text" style="width: 280px; margin-bottom: 5px;" id="station-search-form-q" name="q" placeholder="Поиск" title="Search for a station/vehicle here!" value="<?php echo ($_GET['q'] ?? '') ?>">
<input type="submit" value="Ок">
</div>
</form>
<div style="clear: both;"></div>
<?php if (count($stations) > 0) : ?>
<p>
<?php echo $count; ?> найдено:
</p>
<?php if ($pages > 1): ?>
<div class="pagination">
<a class="tdlink" href="/search.php?q=<?php echo ($_GET['q'] ?? "") ?>&seconds=<?php echo $seconds ?>&page=1"><<</a>
<?php for($i = max(1, $page - 3); $i <= min($pages, $page + 3); $i++) : ?>
<a href="/search.php?q=<?php echo ($_GET['q'] ?? "") ?>&seconds=<?php echo $seconds ?>&page=<?php echo $i; ?>" <?php echo ($i == $page ? 'class="tdlink active"': 'class="tdlink"')?>><?php echo $i ?></a>
<?php endfor; ?>
<a class="tdlink" href="/search.php?q=<?php echo ($_GET['q'] ?? "") ?>&seconds=<?php echo $seconds ?>&page=<?php echo $pages; ?>">>></a>
</div>
<?php endif; ?>
<div class="datagrid datagrid-search" style="max-width:1000px;">
<table>
<thead>
<tr>
<th>&nbsp;</th>
<th>Позывной</th>
<th>Последний пакет</th>
<th>Комментарий/инфо</th>
<th>На карте</th>
</tr>
</thead>
<tbody>
<?php foreach ($stations as $foundStation) : ?>
<tr>
<td>
<img src="<?php echo $foundStation->getIconFilePath(22, 22); ?>" alt="Symbol"/>
</td>
<td>
<a class="tdlink" href="/views/overview.php?id=<?php echo $foundStation->id; ?>&imperialUnits=<?php echo $_GET['imperialUnits'] ?? 0; ?>"><?php echo htmlentities($foundStation->name) ?></a>
</td>
<td class="station-latest-heard-timestamp" style="white-space: nowrap;">
<?php echo $foundStation->latestConfirmedPacketTimestamp; ?>
</td>
<td>
<?php if ($foundStation->sourceId == 5 && $foundStation->getOgnDevice() !== null) : ?>
<div style="width: 100px; display: inline-block;">Регистрация:</div><?php echo htmlspecialchars($foundStation->getOgnDevice()->registration); ?> <?php echo $foundStation->getOgnDevice()->cn ? '[' .htmlspecialchars($foundStation->getOgnDevice()->cn) . ']' : ''; ?><br/>
<div style="width: 100px; display: inline-block;">Модель самолёта:</div><?php echo htmlspecialchars($foundStation->getOgnDevice()->aircraftModel); ?>
<?php else : ?>
<?php $latestPacket = PacketRepository::getInstance()->getObjectById($foundStation->latestPacketId, $foundStation->latestPacketTimestamp); ?>
<?php echo htmlspecialchars($latestPacket->comment); ?>
<?php endif; ?>
</td>
<td>
<?php if ($foundStation->latestConfirmedPacketTimestamp > (time() - 60*60*17568)) : ?>
<a href="?sid=<?php echo $foundStation->id; ?>" onclick="
if (window.parent && window.parent.trackdirect) {
$('.modal', parent.document).hide();
window.parent.trackdirect.filterOnStationId([]);
window.parent.trackdirect.filterOnStationId([<?php echo $foundStation->id; ?>]);
return false;
}">Показать</a>
<?php else : ?>
&nbsp;
<?php endif; ?>
</td>
</tr>
<?php endforeach; ?>
</tbody>
</table>
</div>
<?php endif; ?>
<?php if (isset($_GET['q']) && count($stations) == 0) : ?>
<p>
<b><i>Пакеты не найдены</i></b>
</p>
<?php endif; ?>
</div>
<script>
$(document).ready(function() {
var locale = window.navigator.userLanguage || window.navigator.language;
moment.locale(locale);
$('.station-latest-heard-timestamp').each(function() {
if ($(this).html().trim() != '' && !isNaN($(this).html().trim())) {
$(this).html(moment(new Date(1000 * $(this).html())).format('L LTSZ'));
}
});
$('#station-search-form').bind('submit',function(e) {
var q = $('#station-search-form-q').val();
var seconds = $('#station-search-form-seconds').val();
loadView('/views/search.php?q=' + q + '&seconds=' + seconds);
e.preventDefault();
});
});
</script>