@ -33,10 +33,8 @@
*
* CREATE TABLE items (
* item_id INT GENERATED ALWAYS AS IDENTITY PRIMARY KEY,
* priority INT,
* count INT,
* dec_amount INT,
* inc_amount INT,
* priority INT DEFAULT 0,
* done BOOL DEFAULT FALSE,
* description VARCHAR(2048),
* key VARCHAR(64)
* );
@ -55,34 +53,19 @@
< meta charset = "utf-8" >
< meta name = "viewport" content = "width=device-width, initial-scale=1" >
< title > アイテム数トラッカー < / title >
< title > To-Doリスト < / 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 >
< link rel = "stylesheet" href = "/assets/css/style.css" >
< meta name = "theme-color" content = "#facade" >
< / 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'];
$itemDone = $_POST['item-done'];
$itemRemove = $_POST['item-remove'];
$keyMenu = isset($_GET['key-menu']);
$keySet = $_PO ST['key-set'];
$keySet = $_REQUEST['key-set'];
$setDescription = $_POST['set-description'];
// cookieの変数
@ -104,20 +87,15 @@
}
?>
< 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 class = "center container" >
< h1 > To-Doリスト< / h1 >
[< a href = " <?php echo $_SERVER [ 'PHP_SELF' ]; ?> " > home</ a > ]
[< a href = "?key-menu" > key< / a > ]
[< a href = "?source" > source< / a > ]
[< a href = "//xn--rck9c.xn--tckwe" > back< / a > ]
< / header >
< main class = " mt-3 container-fluid ">
< main class = "center container block" >
<?php
date_default_timezone_set('America/Chicago');
@ -126,57 +104,37 @@
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);
}
if(isset($itemEdit)) { // アイテムの編集
$query = 'SELECT item_id, 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 '< h2 > アイテムの編集< small > /edit item< / small > < / 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 = "f orm-contro l" value = "' . $row['description'] . '" required > ';
echo '< div class = " mb-3 d-flex "> ';
echo '< label for = "set-description" > < ruby > 説明< rp > (< / rp > < rt > description< / rt > < rp > )< / rp > < / ruby > < / label > ';
echo '< input id = "set-description" name = "set-description" class = "f lex-fil l" 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 class = "mb-3 d-flex" > ';
echo '< label for = "set-priority" > < ruby > 優先< rp > (< / rp > < rt > priority< / rt > < rp > )< / rp > < / ruby > < / label > ';
echo '< input type = "number" id = "set-priority" name = "set-priority" class = "flex-fill" 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 '< input type = "submit" class = "bg-green" value = "設定" > ';
echo '< button type = "submit" class = "bg-red" name = "item-remove" value = "' . $itemEdit . '" > 削除< / button > ';
echo '< / form > ';
} else if($keyMenu) { //キーを設定
echo '< h2 > キーの設定< / h2 > ';
echo '< h2 > キーの設定< small > /set key< / small > < / 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 '< label for = "key-set" > < ruby > キー< rp > (< / rp > < rt > key< / rt > < rp > )< / rp > < / ruby > < / label > ';
echo '< input id = "key-set" name = "key-set" value = "' . $_COOKIE['key'] . '" > ';
echo '< input type = "submit" value = "設定" class = "bg-green" > ';
echo '< / form > ';
echo '< p > アプリを使用するには、キーを設定する必要があります。キーを持つ誰でもあなたのアイテム を見ることができますので、秘密にしておきましょう。< / p > ';
echo '< p > アプリを使用するには、キーを設定する必要がありま一覧を見ることができますので、秘密にしておきましょう。< / p > ';
} else { // HPを表示
if(!empty($key)) {
if(isset($itemRemove)) { // アイテムを削除
@ -187,47 +145,30 @@
$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 > ";
echo "< div class = \"alert bg-red \ " > {$desc}は削除しました。< / div > ";
} else {
echo "< div class = \"alert alert-warning \ " > アイテムはありません。< / div > ";
echo "< div class = \"alert bg-blue \ " > アイテムはありません。< / 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());
} else if(isset($itemDone)) { // アイテム完了
$query = 'SELECT description, done FROM items WHERE items.key=$1 AND item_id=$2';
$res = pg_query_params($query, [$key, $itemDone]) 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 > ";
$query = 'UPDATE items SET done = NOT done WHERE item_id=$1';
pg_query_params($query, [$itemDone]) or die('Query failed: ' . pg_last_error());
$doneText = $row['done'] == 'f' ? '完了しました' : '完了にしませんでした';
echo "< div class = \"alert bg-green \ " > {$desc}が{$doneText}。< / div > ";
} else {
echo "< div class = \"alert alert-warning \ " > アイテムはありません。< / div > ";
echo "< div class = \"alert bg-red \ " > アイテムはありません。< / 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 > ";
echo "< div class = \"alert bg-blue \ " > リスト{$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) {
@ -235,24 +176,24 @@
$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, $set Description, $key]);
echo "< div class = \"alert alert-success \ " > {$setDescription}は追加しました。< / div > ";
if(!$res || pg_num_rows($res) == 0) {
$query = 'INSERT INTO items (description, key) VALUES ($1, $2)';
pg_query_params($query, [$setDescription, $key]);
echo "< div class = \"alert bg-green \ " > {$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, $set Description, $key, $itemId]);
echo "< div class = \"alert alert-success \ " > {$setDescription}は更新しました。< / div > ";
$query = 'UPDATE items SET priority=$1, description=$2 WHERE items.key=$3 AND item_id=$4 ';
pg_query_params($query, [$setPriority, $setDescription, $key, $itemId]);
echo "< div class = \"alert bg-green \ " > {$setDescription}は更新しました。< / div > ";
}
}
// アイテム一覧
$query = 'SELECT item_id, count, description, priority FROM items WHERE items.key=$1 ORDER BY items.priority DESC, items.description ASC';
$query = 'SELECT item_id, description, priority FROM items WHERE items.key=$1 AND done=FALSE ORDER BY items.priority DESC, items.description ASC';
$res = pg_query_params($query, [$key]) or die('Query failed: ' . pg_last_error());
echo '< h2 > アイテム一覧< / h2 > ';
echo '< h2 > アイテム一覧< small > /item list< / small > < / h2 > ';
if(pg_num_rows($res) > 0) {
echo '< form action= "' . $_SERVER['PHP_SELF'] . '" > ';
echo '< form method= "post" action= "' . $_SERVER['PHP_SELF'] . '" > ';
echo '< ul class = "list-unstyled" > ';
$priority = -1;
while($row = pg_fetch_array($res)) {
@ -261,16 +202,50 @@
$priority = $row['priority'];
echo '< li class = "mb-1 d-flex" > ';
echo '< button type = "submit" formmethod= "post" name = "item-edit " value = "' . $row['item_id'] . '" class = "b tn 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 '< button type = "submit" name= "item-done " value = "' . $row['item_id'] . '" class = "b g-green"> ✓ < / button > ';
echo '< button type = "submit" name= "item-edit" value = "' . $row['item_id'] . '" class = "text-left flex-fill" > ' . $row['description'] . ' < / button > ';
echo '< button type = "submit" name= "item-remove" value = "' . $row['item_id'] . '" class = "bg-red" > × < / button > ';
echo '< / li > ';
}
echo '< / ul > ';
echo '< / form > ';
}
// 追加ボタン
echo '< form method = "post" action = "' . $_SERVER['PHP_SELF'] . '" class = "d-flex" > ';
echo '< button type = "submit" name = "item-done" class = "bg-green" disabled > ✓< / button > ';
echo '< input name = "set-description" class = "flex-fill" placeholder = "新しい" required > ';
echo '< input type = "submit" value = "+" class = "bg-green" > ';
echo '< / form > ';
// 完了一覧
$query = 'SELECT item_id, description FROM items WHERE items.key=$1 AND done=TRUE ORDER BY items.description ASC';
$res = pg_query_params($query, [$key]) or die('Query failed: ' . pg_last_error());
echo '< h3 > 完了されたアイテム< small > /completed items< / small > < / h3 > ';
if(pg_num_rows($res) > 0) {
echo '< form method = "post" 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" name = "item-done" value = "' . $row['item_id'] . '" > ↑< / button > ';
echo '< button type = "submit" name = "item-edit" value = "' . $row['item_id'] . '" class = "text-left flex-fill" > ' . $row['description'] . '< / button > ';
echo '< button type = "submit" name = "item-remove" value = "' . $row['item_id'] . '" class = "bg-red" > × < / button > ';
echo '< / li > ';
}
echo '< / ul > ';
echo '< / form > ';
}
} else {
echo '< div class = "alert alert-info" > < a href = "?key-menu" > キーを設定してください。< / a > < / div > ';
echo '< div class = "alert bg-blue "> < a href = "?key-menu" > キーを設定してください。< / a > < / div > ';
}
}