From d1369305f3ed6f852751974d0ebb56358d47046d Mon Sep 17 00:00:00 2001 From: Pk11 Date: Sun, 6 Nov 2022 02:20:12 -0600 Subject: [PATCH] =?UTF-8?q?=E6=9C=80=E5=88=9D=E3=82=B3=E3=83=9F=E3=83=83?= =?UTF-8?q?=E3=83=88?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 1 + LICENSE | 24 ++++ README.md | 23 ++++ index.php | 281 +++++++++++++++++++++++++++++++++++++++++++++++ vars.php.example | 7 ++ 5 files changed, 336 insertions(+) create mode 100644 .gitignore create mode 100644 LICENSE create mode 100644 README.md create mode 100644 index.php create mode 100644 vars.php.example diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..2dc8f9e --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +vars.php diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..68a49da --- /dev/null +++ b/LICENSE @@ -0,0 +1,24 @@ +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 diff --git a/README.md b/README.md new file mode 100644 index 0000000..c53e17b --- /dev/null +++ b/README.md @@ -0,0 +1,23 @@ +# count.ピケ.コム + +シンプルなアイテム数トラッカーページです。 + +## ホスト +1. これをインストール: + - PHP (7.3.31を使う) + - PostgreSQL (11.14を使う) +2. このリポジトリをクローン、`git clone https://git.xn--rck9c.xn--tckwe/pk11/count.git` +3. `vars.php.example`を`vars.php`にコピー +4. `vars.php`を返照 +5. 以下のテーブルを指定のデータベースに作成: + ```sql + 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) + ); + ``` diff --git a/index.php b/index.php new file mode 100644 index 0000000..edd8f87 --- /dev/null +++ b/index.php @@ -0,0 +1,281 @@ + + */ + + /* + * ##### 使用前に読んでね ##### + * + * 「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']))); + } +?> + + + + + + + アイテム数トラッカー + + + + + + + +
+ +
+ +
+ アイテムの' . ($itemEdit ? '編集' : '追加') . ''; + echo '
'; + + echo '
'; + echo ''; + echo ''; + echo '
'; + + echo '
'; + echo ''; + echo ''; + echo '
'; + + echo '
'; + echo ''; + echo ''; + echo '
'; + + echo '
'; + echo ''; + echo ''; + echo '
'; + + echo '
'; + echo ''; + echo ''; + echo '
'; + + echo ''; + + echo ''; + if($itemEdit) + echo ''; + echo '
'; + } else if($keyMenu) { //キーを設定 + echo '

キーの設定

'; + echo '
'; + echo '
'; + echo ''; + echo ''; + echo ''; + echo '
'; + echo '
'; + echo '

アプリを使用するには、キーを設定する必要があります。キーを持つ誰でもあなたのアイテムを見ることができますので、秘密にしておきましょう。

'; + } 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 "
{$desc}は削除しました。
"; + } else { + echo "
アイテムはありません。
"; + } + } 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 "
{$desc}は{$count}に増加しました。
"; + } else { + echo "
アイテムはありません。
"; + } + } 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 "
{$desc}は{$count}に減少しました。
"; + } else { + echo "
アイテムはありません。
"; + } + } else if(isset($keySet)) { + if(!empty($keySet)) { + echo "
ようこそ、{$shortKey}さん。
"; + } else { + echo "
さようなら、{$shortKey}さん。
"; + } + } 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 "
{$setDescription}は追加しました。
"; + } 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 "
{$setDescription}は更新しました。
"; + } + } + + // アイテム一覧 + $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 '

アイテム一覧

'; + if(pg_num_rows($res) > 0) { + echo '
'; + echo '
    '; + $priority = -1; + while($row = pg_fetch_array($res)) { + if($priority != $row['priority'] && $priority != -1) + echo '
    '; + $priority = $row['priority']; + + echo '
  • '; + echo ''; + echo ''; + echo ''; + echo '
  • '; + } + echo '
'; + echo '
'; + } + } else { + echo ''; + } + } + + pg_close($dbc); + ?> +
+ + diff --git a/vars.php.example b/vars.php.example new file mode 100644 index 0000000..a564bf7 --- /dev/null +++ b/vars.php.example @@ -0,0 +1,7 @@ +'; + $DB_USER = ''; + $DB_PASSWORD = ''; +?>