|
|
@ -0,0 +1,281 @@
|
|
|
|
|
|
|
|
<?php
|
|
|
|
|
|
|
|
/* This is free and unencumbered software released into the public domain.
|
|
|
|
|
|
|
|
*
|
|
|
|
|
|
|
|
* Anyone is free to copy, modify, publish, use, compile, sell, or
|
|
|
|
|
|
|
|
* distribute this software, either in source code form or as a compiled
|
|
|
|
|
|
|
|
* binary, for any purpose, commercial or non-commercial, and by any
|
|
|
|
|
|
|
|
* means.
|
|
|
|
|
|
|
|
*
|
|
|
|
|
|
|
|
* In jurisdictions that recognize copyright laws, the author or authors
|
|
|
|
|
|
|
|
* of this software dedicate any and all copyright interest in the
|
|
|
|
|
|
|
|
* software to the public domain. We make this dedication for the benefit
|
|
|
|
|
|
|
|
* of the public at large and to the detriment of our heirs and
|
|
|
|
|
|
|
|
* successors. We intend this dedication to be an overt act of
|
|
|
|
|
|
|
|
* relinquishment in perpetuity of all present and future rights to this
|
|
|
|
|
|
|
|
* software under copyright law.
|
|
|
|
|
|
|
|
*
|
|
|
|
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
|
|
|
|
|
|
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
|
|
|
|
|
|
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
|
|
|
|
|
|
|
* IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
|
|
|
|
|
|
|
|
* OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
|
|
|
|
|
|
|
|
* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
|
|
|
|
|
|
|
* OTHER DEALINGS IN THE SOFTWARE.
|
|
|
|
|
|
|
|
*
|
|
|
|
|
|
|
|
* For more information, please refer to <http://unlicense.org/>
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
|
|
|
* ##### 使用前に読んでね #####
|
|
|
|
|
|
|
|
*
|
|
|
|
|
|
|
|
* 「vars.php.example」を「vars.php」にコピーして、「<……>」を取り替えます。
|
|
|
|
|
|
|
|
* 次に、vars.phpに指定データベースを作成して、以下のテーブルを作成します。
|
|
|
|
|
|
|
|
*
|
|
|
|
|
|
|
|
* CREATE TABLE items (
|
|
|
|
|
|
|
|
* item_id INT GENERATED ALWAYS AS IDENTITY PRIMARY KEY,
|
|
|
|
|
|
|
|
* priority INT,
|
|
|
|
|
|
|
|
* count INT,
|
|
|
|
|
|
|
|
* dec_amount INT,
|
|
|
|
|
|
|
|
* inc_amount INT,
|
|
|
|
|
|
|
|
* description VARCHAR(2048),
|
|
|
|
|
|
|
|
* key VARCHAR(64)
|
|
|
|
|
|
|
|
* );
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
require_once('vars.php');
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// ソースコードを送信
|
|
|
|
|
|
|
|
if(isset($_GET['source'])) {
|
|
|
|
|
|
|
|
header("Content-Type: text/plain");
|
|
|
|
|
|
|
|
die(file_get_contents(basename($_SERVER['PHP_SELF'])));
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
?>
|
|
|
|
|
|
|
|
<!DOCTYPE html>
|
|
|
|
|
|
|
|
<html lang="ja">
|
|
|
|
|
|
|
|
<head>
|
|
|
|
|
|
|
|
<meta charset="utf-8">
|
|
|
|
|
|
|
|
<meta name="viewport" content="width=device-width, initial-scale=1">
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<title>アイテム数トラッカー</title>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<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>
|
|
|
|
|
|
|
|
main {
|
|
|
|
|
|
|
|
max-width: 768px;
|
|
|
|
|
|
|
|
margin-bottom: 5rem;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
h2 {
|
|
|
|
|
|
|
|
border-bottom: 1px solid lightgray;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
.red {
|
|
|
|
|
|
|
|
color: red;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
</style>
|
|
|
|
|
|
|
|
</head>
|
|
|
|
|
|
|
|
<body>
|
|
|
|
|
|
|
|
<?php
|
|
|
|
|
|
|
|
// formの変数
|
|
|
|
|
|
|
|
$itemMenu = isset($_GET['item-add']) || isset($_POST['item-edit']);
|
|
|
|
|
|
|
|
$itemEdit = $_POST['item-edit'];
|
|
|
|
|
|
|
|
$itemInc = $_POST['item-inc'];
|
|
|
|
|
|
|
|
$itemDec = $_POST['item-dec'];
|
|
|
|
|
|
|
|
$itemRemove = $_POST['item-remove'];
|
|
|
|
|
|
|
|
$keyMenu = isset($_GET['key-menu']);
|
|
|
|
|
|
|
|
$keySet = $_POST['key-set'];
|
|
|
|
|
|
|
|
$setDescription = $_POST['set-description'];
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 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>
|
|
|
|
|
|
|
|
<nav class="navbar navbar-expand-sm navbar-light bg-light">
|
|
|
|
|
|
|
|
<div class="container-fluid">
|
|
|
|
|
|
|
|
<a class="navbar-brand" href="<?php echo $_SERVER['PHP_SELF']; ?>">アイテム数トラッカー</a>
|
|
|
|
|
|
|
|
<ul class="navbar-nav">
|
|
|
|
|
|
|
|
<li class="nav-item"><a class="nav-link" href="?item-add">追加</a></li>
|
|
|
|
|
|
|
|
<li class="nav-item"><a class="nav-link" href="?key-menu"><?php echo empty($key) ? 'キー' : ($shortKey . 'さん'); ?></a></li>
|
|
|
|
|
|
|
|
<li class="nav-item"><a class="nav-link" href="?source">ソース</a></li>
|
|
|
|
|
|
|
|
</ul>
|
|
|
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
</nav>
|
|
|
|
|
|
|
|
</header>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<main class="mt-3 container-fluid">
|
|
|
|
|
|
|
|
<?php
|
|
|
|
|
|
|
|
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($itemMenu) { // アイテムを追加
|
|
|
|
|
|
|
|
if($itemEdit) {
|
|
|
|
|
|
|
|
$query = 'SELECT item_id, count, dec_amount, inc_amount, description, priority FROM items WHERE items.key=$1 AND item_id=$2 LIMIT 1';
|
|
|
|
|
|
|
|
$res = pg_query_params($query, [$key, $itemEdit]) or die('Query failed: ' . pg_last_error());
|
|
|
|
|
|
|
|
$row = pg_fetch_array($res);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
echo '<h2>アイテムの' . ($itemEdit ? '編集' : '追加') . '</h2>';
|
|
|
|
|
|
|
|
echo '<form method="post" action="' . $_SERVER['PHP_SELF'] . '">';
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
echo '<div class="input-group mb-3">';
|
|
|
|
|
|
|
|
echo '<label for="set-description" class="input-group-text">説明</label>';
|
|
|
|
|
|
|
|
echo '<input id="set-description" name="set-description" class="form-control" value="' . $row['description'] . '" required>';
|
|
|
|
|
|
|
|
echo '</div>';
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
echo '<div class="input-group mb-3">';
|
|
|
|
|
|
|
|
echo '<label for="set-count" class="input-group-text">アイテム数</label>';
|
|
|
|
|
|
|
|
echo '<input type="number" id="set-count" name="set-count" class="form-control" value="' . ($row['count'] ?? 0) . '">';
|
|
|
|
|
|
|
|
echo '</div>';
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
echo '<div class="input-group mb-3">';
|
|
|
|
|
|
|
|
echo '<label for="set-inc" class="input-group-text">増加量</label>';
|
|
|
|
|
|
|
|
echo '<input type="number" id="set-inc" name="set-inc" class="form-control" value="' . ($row['inc_amount'] ?? 1) . '">';
|
|
|
|
|
|
|
|
echo '</div>';
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
echo '<div class="input-group mb-3">';
|
|
|
|
|
|
|
|
echo '<label for="set-dec" class="input-group-text">減少量</label>';
|
|
|
|
|
|
|
|
echo '<input type="number" id="set-dec" name="set-dec" class="form-control" value="' . ($row['dec_amount'] ?? 1) . '">';
|
|
|
|
|
|
|
|
echo '</div>';
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
echo '<div class="input-group mb-3">';
|
|
|
|
|
|
|
|
echo '<label for="set-priority" class="input-group-text">優先</label>';
|
|
|
|
|
|
|
|
echo '<input type="number" id="set-priority" name="set-priority" class="form-control" value="' . ($row['priority'] ?? 0) . '">';
|
|
|
|
|
|
|
|
echo '</div>';
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
echo '<input type="hidden" name="item-id" value="' . $row['item_id'] . '">';
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
echo '<input type="submit" class="btn btn-outline-secondary me-2" value="' . ($itemEdit ? '設定' : '追加') . '">';
|
|
|
|
|
|
|
|
if($itemEdit)
|
|
|
|
|
|
|
|
echo '<button type="submit" class="btn btn-outline-danger" name="item-remove" value="' . $itemEdit . '">削除</button>';
|
|
|
|
|
|
|
|
echo '</form>';
|
|
|
|
|
|
|
|
} else if($keyMenu) { //キーを設定
|
|
|
|
|
|
|
|
echo '<h2>キーの設定</h2>';
|
|
|
|
|
|
|
|
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を表示
|
|
|
|
|
|
|
|
if(!empty($key)) {
|
|
|
|
|
|
|
|
if(isset($itemRemove)) { // アイテムを削除
|
|
|
|
|
|
|
|
$query = 'SELECT description FROM items WHERE items.key=$1 AND item_id=$2';
|
|
|
|
|
|
|
|
$res = pg_query_params($query, [$key, $itemRemove]) or die('Query failed: ' . pg_last_error());
|
|
|
|
|
|
|
|
$row = pg_fetch_array($res);
|
|
|
|
|
|
|
|
if($row) {
|
|
|
|
|
|
|
|
$desc = $row['description'];
|
|
|
|
|
|
|
|
$query = 'DELETE FROM items WHERE item_id=$1';
|
|
|
|
|
|
|
|
pg_query_params($query, [$itemRemove]);
|
|
|
|
|
|
|
|
echo "<div class=\"alert alert-danger\">{$desc}は削除しました。</div>";
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
echo "<div class=\"alert alert-warning\">アイテムはありません。</div>";
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
} else if(isset($itemInc)) { // アイテムを増加する
|
|
|
|
|
|
|
|
$query = 'SELECT description, inc_amount, count FROM items WHERE items.key=$1 AND item_id=$2';
|
|
|
|
|
|
|
|
$res = pg_query_params($query, [$key, $itemInc]) or die('Query failed: ' . pg_last_error());
|
|
|
|
|
|
|
|
$row = pg_fetch_array($res);
|
|
|
|
|
|
|
|
if($row) {
|
|
|
|
|
|
|
|
$desc = $row['description'];
|
|
|
|
|
|
|
|
$count = $row['count'] + $row['inc_amount'];
|
|
|
|
|
|
|
|
$query = 'UPDATE items SET count=$1 WHERE item_id=$2';
|
|
|
|
|
|
|
|
pg_query_params($query, [$count, $itemInc]) or die('Query failed: ' . pg_last_error());
|
|
|
|
|
|
|
|
echo "<div class=\"alert alert-success\">{$desc}は{$count}に増加しました。</div>";
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
echo "<div class=\"alert alert-warning\">アイテムはありません。</div>";
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
} else if(isset($itemDec)) { // アイテムを減少する
|
|
|
|
|
|
|
|
$query = 'SELECT description, dec_amount, count FROM items WHERE items.key=$1 AND item_id=$2';
|
|
|
|
|
|
|
|
$res = pg_query_params($query, [$key, $itemDec]) or die('Query failed: ' . pg_last_error());
|
|
|
|
|
|
|
|
$row = pg_fetch_array($res);
|
|
|
|
|
|
|
|
if($row) {
|
|
|
|
|
|
|
|
$desc = $row['description'];
|
|
|
|
|
|
|
|
$count = $row['count'] - $row['dec_amount'];
|
|
|
|
|
|
|
|
$query = 'UPDATE items SET count=$1 WHERE item_id=$2';
|
|
|
|
|
|
|
|
pg_query_params($query, [$count, $itemDec]) or die('Query failed: ' . pg_last_error());
|
|
|
|
|
|
|
|
echo "<div class=\"alert alert-success\">{$desc}は{$count}に減少しました。</div>";
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
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>";
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
} else if(isset($setDescription)) { // アイテムを編集・追加する
|
|
|
|
|
|
|
|
$itemId = $_POST['item-id'];
|
|
|
|
|
|
|
|
$setCount = $_POST['set-count'];
|
|
|
|
|
|
|
|
$setInc = $_POST['set-inc'];
|
|
|
|
|
|
|
|
$setDec = $_POST['set-dec'];
|
|
|
|
|
|
|
|
$setPriority = $_POST['set-priority'];
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if($itemId) {
|
|
|
|
|
|
|
|
$query = 'SELECT FROM items WHERE items.key=$1 AND item_id=$2 LIMIT 1';
|
|
|
|
|
|
|
|
$res = pg_query_params($query, [$key, $itemId]) or die('Query failed: ' . pg_last_error());
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if(pg_num_rows($res) == 0) {
|
|
|
|
|
|
|
|
$query = 'INSERT INTO items (priority, count, dec_amount, inc_amount, description, key) VALUES ($1, $2, $3, $4, $5, $6)';
|
|
|
|
|
|
|
|
pg_query_params($query, [$setPriority, $setCount, $setDec, $setInc, $setDescription, $key]);
|
|
|
|
|
|
|
|
echo "<div class=\"alert alert-success\">{$setDescription}は追加しました。</div>";
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
$query = 'UPDATE items SET priority=$1, count=$2, dec_amount=$3, inc_amount=$4, description=$5 WHERE items.key=$6 AND item_id=$7';
|
|
|
|
|
|
|
|
pg_query_params($query, [$setPriority, $setCount, $setDec, $setInc, $setDescription, $key, $itemId]);
|
|
|
|
|
|
|
|
echo "<div class=\"alert alert-success\">{$setDescription}は更新しました。</div>";
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// アイテム一覧
|
|
|
|
|
|
|
|
$query = 'SELECT item_id, count, description, priority FROM items WHERE items.key=$1 ORDER BY items.priority DESC, items.description ASC';
|
|
|
|
|
|
|
|
$res = pg_query_params($query, [$key]) or die('Query failed: ' . pg_last_error());
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
echo '<h2>アイテム一覧</h2>';
|
|
|
|
|
|
|
|
if(pg_num_rows($res) > 0) {
|
|
|
|
|
|
|
|
echo '<form action="' . $_SERVER['PHP_SELF'] . '">';
|
|
|
|
|
|
|
|
echo '<ul class="list-unstyled">';
|
|
|
|
|
|
|
|
$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 '<button type="submit" formmethod="post" name="item-edit" value="' . $row['item_id'] . '" class="btn btn-sm btn-secondary flex-fill me-1 text-start">' . $row['description'] . ' ー ' . $row['count'] . '</button>';
|
|
|
|
|
|
|
|
echo '<button type="submit" formmethod="post" name="item-inc" value="' . $row['item_id'] . '" title="' . $row['description'] . 'の増加する" aria-label="' . $row['description'] . 'の増加する" class="btn btn-sm btn-outline-secondary me-1">↑</button>';
|
|
|
|
|
|
|
|
echo '<button type="submit" formmethod="post" name="item-dec" value="' . $row['item_id'] . '" title="' . $row['description'] . 'の減少する" aria-label="' . $row['description'] . 'の減少する" class="btn btn-sm btn-outline-secondary me-1">↓</button>';
|
|
|
|
|
|
|
|
echo '</li>';
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
echo '</ul>';
|
|
|
|
|
|
|
|
echo '</form>';
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
echo '<div class="alert alert-info"><a href="?key-menu">キーを設定してください。</a></div>';
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
pg_close($dbc);
|
|
|
|
|
|
|
|
?>
|
|
|
|
|
|
|
|
</main>
|
|
|
|
|
|
|
|
</body>
|
|
|
|
|
|
|
|
</html>
|