|
|
@ -25,7 +25,23 @@
|
|
|
|
* For more information, please refer to <http://unlicense.org/>
|
|
|
|
* For more information, please refer to <http://unlicense.org/>
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
// Return source code
|
|
|
|
/*
|
|
|
|
|
|
|
|
* ##### 使用前に読んでね #####
|
|
|
|
|
|
|
|
*
|
|
|
|
|
|
|
|
* 「vars.php.example」を「vars.php」にコピーして、「<……>」を取り替えます。
|
|
|
|
|
|
|
|
* 次に、vars.phpに指定データベースを作成して、以下のテーブルを作成します。
|
|
|
|
|
|
|
|
*
|
|
|
|
|
|
|
|
* CREATE TABLE favorites (
|
|
|
|
|
|
|
|
* fav_id INT GENERATED ALWAYS AS IDENTITY PRIMARY KEY,
|
|
|
|
|
|
|
|
* stop INT,
|
|
|
|
|
|
|
|
* priority INT,
|
|
|
|
|
|
|
|
* description VARCHAR(2048),
|
|
|
|
|
|
|
|
* key VARCHAR(64)
|
|
|
|
|
|
|
|
* );
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
require_once('vars.php');
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// ソースコードを送信
|
|
|
|
if(isset($_GET['source'])) {
|
|
|
|
if(isset($_GET['source'])) {
|
|
|
|
header("Content-Type: text/plain");
|
|
|
|
header("Content-Type: text/plain");
|
|
|
|
die(file_get_contents(basename($_SERVER['PHP_SELF'])));
|
|
|
|
die(file_get_contents(basename($_SERVER['PHP_SELF'])));
|
|
|
@ -39,10 +55,11 @@
|
|
|
|
|
|
|
|
|
|
|
|
<title>停留所のNexTrip情報</title>
|
|
|
|
<title>停留所のNexTrip情報</title>
|
|
|
|
|
|
|
|
|
|
|
|
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-1BmE4kWBq78iYhFldvKuhfTAU6auU8tT94WrHftjDbrCEXSU1oBoqyl2QvZ6jIW3" crossorigin="anonymous">
|
|
|
|
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.2.0/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-gH2yIJqKdNHPEq0n4Mqa/HGKIhSkIHeL5AyhkYV8i59U5AR6csBvApHHNl/vI1Bx" crossorigin="anonymous">
|
|
|
|
<style>
|
|
|
|
<style>
|
|
|
|
main {
|
|
|
|
main {
|
|
|
|
max-width: 768px;
|
|
|
|
max-width: 768px;
|
|
|
|
|
|
|
|
margin-bottom: 5rem;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
h2 {
|
|
|
|
h2 {
|
|
|
@ -56,16 +73,37 @@
|
|
|
|
$stop = $_GET['stop'];
|
|
|
|
$stop = $_GET['stop'];
|
|
|
|
$favSet = $_POST['fav-set'];
|
|
|
|
$favSet = $_POST['fav-set'];
|
|
|
|
$favRemove = $_POST['fav-remove'];
|
|
|
|
$favRemove = $_POST['fav-remove'];
|
|
|
|
|
|
|
|
$favUp = $_POST['fav-up'];
|
|
|
|
|
|
|
|
$favDown = $_POST['fav-down'];
|
|
|
|
|
|
|
|
$keyMenu = isset($_GET['key-menu']);
|
|
|
|
|
|
|
|
$keySet = $_POST['key-set'];
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// cookieの変数
|
|
|
|
|
|
|
|
if(isset($_COOKIE['key'])) {
|
|
|
|
|
|
|
|
$key = hash('sha256', $_COOKIE['key']);
|
|
|
|
|
|
|
|
$shortKey = substr($key, 0, 7);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// キーを更新
|
|
|
|
|
|
|
|
if(isset($keySet)) {
|
|
|
|
|
|
|
|
if(!empty($keySet)) {
|
|
|
|
|
|
|
|
setcookie("key", $keySet, 2147483647);
|
|
|
|
|
|
|
|
$key = hash('sha256', $keySet);
|
|
|
|
|
|
|
|
$shortKey = substr($key, 0, 7);
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
setcookie("key", "", 1);
|
|
|
|
|
|
|
|
unset($key);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
?>
|
|
|
|
?>
|
|
|
|
|
|
|
|
|
|
|
|
<header>
|
|
|
|
<header>
|
|
|
|
<nav class="navbar navbar-light bg-light">
|
|
|
|
<nav class="navbar navbar-expand-sm navbar-light bg-light">
|
|
|
|
<div class="container-fluid">
|
|
|
|
<div class="container-fluid">
|
|
|
|
<a class="navbar-brand" href="<?php echo $_SERVER['PHP_SELF']; ?>">停留所のNexTrip情報</a>
|
|
|
|
<a class="navbar-brand" href="<?php echo $_SERVER['PHP_SELF']; ?>">停留所のNexTrip情報</a>
|
|
|
|
<ul class="navbar-nav">
|
|
|
|
<ul class="navbar-nav">
|
|
|
|
<li class="nav-item">
|
|
|
|
<li class="nav-item"><a class="nav-link" href="?key-menu"><?php echo empty($key) ? 'キー' : ($shortKey . 'さん'); ?></a></li>
|
|
|
|
<a class="nav-link" href="?source">ソース</a>
|
|
|
|
<li class="nav-item"><a class="nav-link" href="?source">ソース</a></li>
|
|
|
|
</li>
|
|
|
|
|
|
|
|
</ul>
|
|
|
|
</ul>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</nav>
|
|
|
|
</nav>
|
|
|
@ -75,6 +113,10 @@
|
|
|
|
<?php
|
|
|
|
<?php
|
|
|
|
date_default_timezone_set('America/Chicago');
|
|
|
|
date_default_timezone_set('America/Chicago');
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// DBに接続
|
|
|
|
|
|
|
|
$dbc = pg_connect("host=$DB_HOST dbname=$DB_NAME user=$DB_USER password=$DB_PASSWORD")
|
|
|
|
|
|
|
|
or die('Could not connect: ' . pg_last_error());
|
|
|
|
|
|
|
|
|
|
|
|
if(isset($stop)) { // 停留所情報を表示
|
|
|
|
if(isset($stop)) { // 停留所情報を表示
|
|
|
|
$directions = [
|
|
|
|
$directions = [
|
|
|
|
"NB" => "北行",
|
|
|
|
"NB" => "北行",
|
|
|
@ -106,20 +148,33 @@
|
|
|
|
}
|
|
|
|
}
|
|
|
|
echo '</div>';
|
|
|
|
echo '</div>';
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if(!empty($key)) {
|
|
|
|
// お気に入りフォームをプリント
|
|
|
|
// お気に入りフォームをプリント
|
|
|
|
$favDesc = json_decode($_COOKIE['favorites'], true)[$stop];
|
|
|
|
$query = 'SELECT description FROM favorites WHERE favorites.key=$1 AND favorites.stop=$2 LIMIT 1';
|
|
|
|
|
|
|
|
$res = pg_query_params($query, [$key, $stop]) or die('Query failed: ' . pg_last_error());
|
|
|
|
|
|
|
|
$row = pg_fetch_array($res);
|
|
|
|
|
|
|
|
|
|
|
|
echo '<form method="post" action="' . $_SERVER['PHP_SELF'] . '">';
|
|
|
|
echo '<form method="post" action="' . $_SERVER['PHP_SELF'] . '">';
|
|
|
|
echo "<input type=\"hidden\" name=\"fav-set\" value=\"$stop\">";
|
|
|
|
echo '<input type="hidden" name="fav-set" value="' . $stop . '">';
|
|
|
|
echo '<div class="input-group">';
|
|
|
|
echo '<div class="input-group">';
|
|
|
|
echo '<label for="desc" class="input-group-text">お気に入り</label>';
|
|
|
|
echo '<label for="desc" class="input-group-text">お気に入り</label>';
|
|
|
|
echo "<input type=\"text\" id=\"desc\" name=\"desc\" class=\"form-control\" placeholder=\"説明\" value=\"$favDesc\" required>";
|
|
|
|
echo '<input type="text" id="desc" name="desc" class="form-control" placeholder="説明" value="' . $row['description'] . '" required>';
|
|
|
|
echo '<input type="submit" class="btn btn-outline-secondary" value="' . (isset($favDesc) ? '更新' : '追加') . '">';
|
|
|
|
echo '<input type="submit" class="btn btn-outline-secondary" value="' . ($row ? '更新' : '追加') . '">';
|
|
|
|
echo '</div>';
|
|
|
|
echo '</div>';
|
|
|
|
echo '</form>';
|
|
|
|
echo '</form>';
|
|
|
|
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
echo "<div class=\"alert alert-danger\">{$stop}は無効な停留所です。</div>";
|
|
|
|
echo "<div class=\"alert alert-danger\">{$stop}は無効な停留所です。</div>";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
} else if($keyMenu) { //キーを設定
|
|
|
|
|
|
|
|
echo '<form method="post" action="' . $_SERVER['PHP_SELF'] . '">';
|
|
|
|
|
|
|
|
echo '<div class="input-group mb-3">';
|
|
|
|
|
|
|
|
echo '<label for="key-set" class="input-group-text">キー</label>';
|
|
|
|
|
|
|
|
echo '<input type="password" id="key-set" name="key-set" class="form-control" value="' . $_COOKIE['key'] . '">';
|
|
|
|
|
|
|
|
echo '<input type="submit" class="btn btn-outline-secondary" value="設定">';
|
|
|
|
|
|
|
|
echo '</div>';
|
|
|
|
|
|
|
|
echo '</form>';
|
|
|
|
|
|
|
|
echo '<p>キーを設定して、お気に入りを使用できます。キーを持つ誰でもはあなたのお気に入りを見ることができますので、秘密にしておきましょう。</p>';
|
|
|
|
} else { // HPを表示
|
|
|
|
} else { // HPを表示
|
|
|
|
// 停留所フォームをプリント
|
|
|
|
// 停留所フォームをプリント
|
|
|
|
echo '<form method="get" action="' . $_SERVER['PHP_SELF'] . '">';
|
|
|
|
echo '<form method="get" action="' . $_SERVER['PHP_SELF'] . '">';
|
|
|
@ -130,42 +185,105 @@
|
|
|
|
echo '</div>';
|
|
|
|
echo '</div>';
|
|
|
|
echo '</form>';
|
|
|
|
echo '</form>';
|
|
|
|
|
|
|
|
|
|
|
|
// お気に入り一覧
|
|
|
|
if(!empty($key)) {
|
|
|
|
$favorites = isset($_COOKIE['favorites']) ? json_decode($_COOKIE['favorites'], true) : Array();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if(isset($favSet)) { // お気に入りに追加
|
|
|
|
if(isset($favSet)) { // お気に入りに追加
|
|
|
|
$desc = $_POST['desc'];
|
|
|
|
$query = 'SELECT fav_id, stop, description FROM favorites WHERE favorites.key=$1 AND favorites.stop=$2 LIMIT 1';
|
|
|
|
|
|
|
|
$res = pg_query_params($query, [$key, $favSet]) or die('Query failed: ' . pg_last_error());
|
|
|
|
|
|
|
|
$row = pg_fetch_array($res);
|
|
|
|
|
|
|
|
|
|
|
|
$favorites[$favSet] = $desc;
|
|
|
|
$desc = $_POST['desc'];
|
|
|
|
ksort($favorites);
|
|
|
|
if(!$row) {
|
|
|
|
setcookie("favorites", json_encode($favorites), 2147483647);
|
|
|
|
$query = 'INSERT INTO favorites (stop, priority, description, key) VALUES ($1, 0, $2, $3)';
|
|
|
|
echo "<div class=\"alert alert-info\">{$favSet}({$desc})は設定しました。</div>";
|
|
|
|
pg_query_params($query, [$favSet, $desc, $key]);
|
|
|
|
|
|
|
|
echo "<div class=\"alert alert-success\">$favSet – {$desc}は設定しました。</div>";
|
|
|
|
|
|
|
|
} else if($desc != $row['description']) {
|
|
|
|
|
|
|
|
$query = 'UPDATE favorites SET description=$1 WHERE favorites.key=$2 AND favorites.fav_id=$3';
|
|
|
|
|
|
|
|
pg_query_params($query, [$desc, $key, $row['fav_id']]);
|
|
|
|
|
|
|
|
echo "<div class=\"alert alert-success\">$favSet – {$desc}は更新しました。</div>";
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
echo "<div class=\"alert alert-info\">{$favSet}はすでに設定しました。</div>";
|
|
|
|
|
|
|
|
}
|
|
|
|
} else if(isset($favRemove)) { // お気に入りから削除
|
|
|
|
} else if(isset($favRemove)) { // お気に入りから削除
|
|
|
|
if(array_key_exists($favRemove, $favorites)) {
|
|
|
|
$query = 'SELECT stop, description FROM favorites WHERE favorites.key=$1 AND favorites.fav_id=$2';
|
|
|
|
$desc = $favorites[$favRemove];
|
|
|
|
$res = pg_query_params($query, [$key, $favRemove]) or die('Query failed: ' . pg_last_error());
|
|
|
|
unset($favorites[$favRemove]);
|
|
|
|
$row = pg_fetch_array($res);
|
|
|
|
setcookie("favorites", json_encode($favorites), 2147483647);
|
|
|
|
if($row) {
|
|
|
|
echo "<div class=\"alert alert-info\">{$favRemove}({$desc})は削除しました。</div>";
|
|
|
|
$stop = $row['stop'];
|
|
|
|
|
|
|
|
$desc = $row['description'];
|
|
|
|
|
|
|
|
$query = 'DELETE FROM favorites WHERE favorites.fav_id=$1';
|
|
|
|
|
|
|
|
pg_query_params($query, [$favRemove]);
|
|
|
|
|
|
|
|
echo "<div class=\"alert alert-danger\">$stop – {$desc}は削除しました。</div>";
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
echo "<div class=\"alert alert-warning\">亭はお気に入りにありません。</div>";
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
} else if(isset($favUp)) { // お気に入りを上げる
|
|
|
|
|
|
|
|
$query = 'SELECT stop, description, priority FROM favorites WHERE favorites.key=$1 AND favorites.fav_id=$2';
|
|
|
|
|
|
|
|
$res = pg_query_params($query, [$key, $favUp]) or die('Query failed: ' . pg_last_error());
|
|
|
|
|
|
|
|
$row = pg_fetch_array($res);
|
|
|
|
|
|
|
|
if($row) {
|
|
|
|
|
|
|
|
$stop = $row['stop'];
|
|
|
|
|
|
|
|
$desc = $row['description'];
|
|
|
|
|
|
|
|
$priority = $row['priority'] + 1;
|
|
|
|
|
|
|
|
$query = 'UPDATE favorites SET priority=priority+1 WHERE favorites.fav_id=$1';
|
|
|
|
|
|
|
|
pg_query_params($query, [$favUp]) or die('Query failed: ' . pg_last_error());
|
|
|
|
|
|
|
|
echo "<div class=\"alert alert-success\">$stop – {$desc}は{$priority}に上げました。</div>";
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
echo "<div class=\"alert alert-warning\">亭はお気に入りにありません。</div>";
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
} else if(isset($favDown)) { // お気に入りを下げる
|
|
|
|
|
|
|
|
$query = 'SELECT stop, description, priority FROM favorites WHERE favorites.key=$1 AND favorites.fav_id=$2';
|
|
|
|
|
|
|
|
$res = pg_query_params($query, [$key, $favDown]) or die('Query failed: ' . pg_last_error());
|
|
|
|
|
|
|
|
$row = pg_fetch_array($res);
|
|
|
|
|
|
|
|
if($row) {
|
|
|
|
|
|
|
|
$stop = $row['stop'];
|
|
|
|
|
|
|
|
$desc = $row['description'];
|
|
|
|
|
|
|
|
$priority = $row['priority'] - 1;
|
|
|
|
|
|
|
|
$query = 'UPDATE favorites SET priority=priority-1 WHERE favorites.fav_id=$1';
|
|
|
|
|
|
|
|
pg_query_params($query, [$favDown]) or die('Query failed: ' . pg_last_error());
|
|
|
|
|
|
|
|
echo "<div class=\"alert alert-success\">$stop – {$desc}は{$priority}に下げました。</div>";
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
echo "<div class=\"alert alert-warning\">{$favRemove}はお気に入りにありません。</div>";
|
|
|
|
echo "<div class=\"alert alert-warning\">亭はお気に入りにありません。</div>";
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
} else if(isset($keySet)) {
|
|
|
|
|
|
|
|
if(!empty($keySet)) {
|
|
|
|
|
|
|
|
echo "<div class=\"alert alert-info\">ようこそ、{$shortKey}さん。</div>";
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
echo "<div class=\"alert alert-info\">さようなら、{$shortKey}さん。</div>";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// お気に入り一覧
|
|
|
|
|
|
|
|
$query = 'SELECT fav_id, stop, description, priority FROM favorites WHERE favorites.key=$1 ORDER BY favorites.priority DESC, favorites.stop ASC';
|
|
|
|
|
|
|
|
$res = pg_query_params($query, [$key]) or die('Query failed: ' . pg_last_error());
|
|
|
|
|
|
|
|
|
|
|
|
// お気に入りがある場合、プリント
|
|
|
|
// お気に入りがある場合、プリント
|
|
|
|
if(count($favorites) > 0) {
|
|
|
|
if(pg_num_rows($res) > 0) {
|
|
|
|
echo '<h2>お気に入り</h2>';
|
|
|
|
echo '<h2>お気に入り</h2>';
|
|
|
|
echo '<form action="' . $_SERVER['PHP_SELF'] . '">';
|
|
|
|
echo '<form action="' . $_SERVER['PHP_SELF'] . '">';
|
|
|
|
echo '<ul class="list-unstyled">';
|
|
|
|
echo '<ul class="list-unstyled">';
|
|
|
|
foreach($favorites as $favStop => $favDesc) {
|
|
|
|
$priority = -1;
|
|
|
|
|
|
|
|
while($row = pg_fetch_array($res)) {
|
|
|
|
|
|
|
|
if($priority != $row['priority'] && $priority != -1)
|
|
|
|
|
|
|
|
echo '<hr>';
|
|
|
|
|
|
|
|
$priority = $row['priority'];
|
|
|
|
|
|
|
|
|
|
|
|
echo '<li class="mb-1 d-flex">';
|
|
|
|
echo '<li class="mb-1 d-flex">';
|
|
|
|
echo "<button type=\"submit\" formmethod=\"get\" name=\"stop\" value=\"$favStop\" class=\"btn btn-sm btn-secondary flex-fill me-1 text-start\">$favStop ($favDesc)</button>";
|
|
|
|
echo '<button type="submit" formmethod="get" name="stop" value="' . $row['stop'] . '" class="btn btn-sm btn-secondary flex-fill me-1 text-start">' . $row['stop'] . ' – ' . $row['description'] . '</button>';
|
|
|
|
echo "<button type=\"submit\" formmethod=\"post\" name=\"fav-remove\" value=\"$favStop\" aria-label=\"{$favStop}を削除\" class=\"btn btn-sm btn-danger\">×</button>";
|
|
|
|
echo '<button type="submit" formmethod="post" name="fav-up" value="' . $row['fav_id'] . '" title="' . $row['stop'] . 'の優先を上げる" aria-label="' . $row['stop'] . 'の優先を上げる" class="btn btn-sm btn-outline-secondary me-1">↑</button>';
|
|
|
|
|
|
|
|
echo '<button type="submit" formmethod="post" name="fav-down" value="' . $row['fav_id'] . '" title="' . $row['stop'] . 'の優先を下げる" aria-label="' . $row['stop'] . 'の優先を下げる" class="btn btn-sm btn-outline-secondary me-1">↓</button>';
|
|
|
|
|
|
|
|
echo '<button type="submit" formmethod="post" name="fav-remove" value="' . $row['fav_id'] . '" title="' . $row['stop'] . 'を削除" aria-label="' . $row['stop'] . 'を削除" class="btn btn-sm btn-danger">×</button>';
|
|
|
|
echo '</li>';
|
|
|
|
echo '</li>';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
echo '</ul>';
|
|
|
|
echo '</ul>';
|
|
|
|
echo '</form>';
|
|
|
|
echo '</form>';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
echo '<div class="alert alert-info"><a href="?key-menu">キーを設定する</a>と、お気に入りの停留所を保存できます。</div>';
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
pg_close($dbc);
|
|
|
|
?>
|
|
|
|
?>
|
|
|
|
</main>
|
|
|
|
</main>
|
|
|
|
</body>
|
|
|
|
</body>
|
|
|
|