@@ -53,9 +53,11 @@ | |||||
</div> | </div> | ||||
<div class="col input-group"> | <div class="col input-group"> | ||||
<input type="text" class="form-control" placeholder="YYYY/MM/DD" id="filter-date-start" /> | |||||
<input type="text" class="form-control" placeholder="YYYY-MM-DD" id="filter-date-start" | |||||
value="<?= $date_start ?>" /> | |||||
<span class="input-group-text">〜</span> | <span class="input-group-text">〜</span> | ||||
<input type="text" class="form-control" placeholder="YYYY/MM/DD" id="filter-date-end" /> | |||||
<input type="text" class="form-control" placeholder="YYYY-MM-DD" id="filter-date-end" | |||||
value="<?= $date_end ?>" /> | |||||
</div> | </div> | ||||
</div> | </div> | ||||
@@ -12,6 +12,9 @@ $length = (int) ($_GET['max'] ?? 20); | |||||
$asc = ($_GET['asc'] ?? 0) != 0; | $asc = ($_GET['asc'] ?? 0) != 0; | ||||
$keyword = trim ($_GET['q'] ?? ''); | $keyword = trim ($_GET['q'] ?? ''); | ||||
$date_start = $_GET['start'] ?: null; | |||||
$date_end = $_GET['end'] ?: null; | |||||
$f = fopen (LOG_PATH, 'r'); | $f = fopen (LOG_PATH, 'r'); | ||||
if ($f !== false) | if ($f !== false) | ||||
@@ -40,6 +43,18 @@ if ($keyword != '') | |||||
!== false)); | !== false)); | ||||
} | } | ||||
if ($date_start) | |||||
{ | |||||
$log_data = array_filter ($log_data, fn ($row) => ( | |||||
substr ($row['date_time'], 0, 10) >= $date_start)); | |||||
} | |||||
if ($date_end) | |||||
{ | |||||
$log_data = array_filter ($log_data, fn ($row) => ( | |||||
substr ($row['date_time'], 0, 10) <= $date_end)); | |||||
} | |||||
$pages_max = (int) ((count ($log_data) - 1) / $length) + 1; | $pages_max = (int) ((count ($log_data) - 1) / $length) + 1; | ||||
if (!($asc)) | if (!($asc)) | ||||
@@ -4,8 +4,11 @@ Script | |||||
static | static | ||||
main () | main () | ||||
{ | { | ||||
$ ('#filter-date-start').datepicker (); | |||||
$ ('#filter-date-end').datepicker (); | |||||
const dateOptions = {dateFormat: 'yy-mm-dd', | |||||
firstDay: 6}; | |||||
$ ('#filter-date-start').datepicker (dateOptions); | |||||
$ ('#filter-date-end').datepicker (dateOptions); | |||||
const url = new URL (window.location.href); | const url = new URL (window.location.href); | ||||
@@ -17,6 +20,14 @@ Script | |||||
const filter = ( | const filter = ( | ||||
function (e) | function (e) | ||||
{ | { | ||||
let dateStart = $ ('#filter-date-start').val (); | |||||
let dateEnd = $ ('#filter-date-end').val (); | |||||
if ((dateStart !== '') | |||||
&& (dateEnd !== '') | |||||
&& (dateStart > dateEnd)) | |||||
[dateStart, dateEnd] = [dateEnd, dateStart]; | |||||
url.searchParams.delete ('p'); | url.searchParams.delete ('p'); | ||||
url.searchParams.delete ('asc'); | url.searchParams.delete ('asc'); | ||||
@@ -25,6 +36,15 @@ Script | |||||
url.searchParams.delete ('q'); | url.searchParams.delete ('q'); | ||||
url.searchParams.append ('q', filterKeyword.value); | url.searchParams.append ('q', filterKeyword.value); | ||||
url.searchParams.delete ('start'); | |||||
url.searchParams.delete ('end'); | |||||
if (dateStart !== '') | |||||
url.searchParams.append ('start', dateStart); | |||||
if (dateEnd !== '') | |||||
url.searchParams.append ('end', dateEnd); | |||||
window.location.href = url; | window.location.href = url; | ||||
}); | }); | ||||