summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--api/add.php4
-rw-r--r--api/change-order.php4
-rw-r--r--api/export.php22
-rw-r--r--api/remove.php20
-rw-r--r--index.php17
-rwxr-xr-xset-pwd.sh9
-rw-r--r--src/data.php2
-rw-r--r--src/db.xml22
-rwxr-xr-xstart4
9 files changed, 68 insertions, 36 deletions
diff --git a/api/add.php b/api/add.php
index 780a3b4..7edeb3b 100644
--- a/api/add.php
+++ b/api/add.php
@@ -8,8 +8,8 @@ foreach ($req_keys as $key) {
exit(0);
}
}
-$path = "/home/maks/school/clientApps/mlos/src/db.xml";
-require_once "/home/maks/school/clientApps/mlos/src/data.php";
+$path = "%PWD%src/db.xml";
+require_once "%PWD%src/data.php";
$name = $_POST["name"];
$author = $_POST["author"];
diff --git a/api/change-order.php b/api/change-order.php
index b498605..8901187 100644
--- a/api/change-order.php
+++ b/api/change-order.php
@@ -4,8 +4,8 @@ if (empty($_POST["old-order"]) || empty($_POST["new-order"])) {
error_log("not enough post");
exit(0);
}
-$path = "/home/maks/school/clientApps/mlos/src/db.xml";
-require_once "/home/maks/school/clientApps/mlos/src/data.php";
+$path = "%PWD%src/db.xml";
+require_once "%PWD%src/data.php";
$old_order = $_POST["old-order"];
$new_order = $_POST["new-order"];
diff --git a/api/export.php b/api/export.php
index 77e36a2..625283e 100644
--- a/api/export.php
+++ b/api/export.php
@@ -1,6 +1,6 @@
<?php
-require_once '../vendor/autoload.php';
-require_once '../src/data.php';
+require_once '%PWD%vendor/autoload.php';
+require_once '%PWD%src/data.php';
[$data, $count] = get_data();
@@ -22,15 +22,17 @@ $row = 2;
foreach ($data as $d) {
$active_sheet->setCellValue('A' . $row, $d["name"]);
- $drawing = new Drawing();
- $drawing->setName($d["name"]);
- $drawing->setPath("../imgs/" . $d["thumbnail"]);
- $drawing->setHeight(200);
-
- $comment = $active_sheet->getComment('A' . $row);
- $comment->setBackgroundImage($drawing);
- $comment->setSizeAsBackgroundImage();
+ $path = "%PWD%imgs/" . $d["thumbnail"];
+ if(file_exists($path)) {
+ $drawing = new Drawing();
+ $drawing->setName($d["name"]);
+ $drawing->setPath($path);
+ $drawing->setHeight(200);
+ $comment = $active_sheet->getComment('A' . $row);
+ $comment->setBackgroundImage($drawing);
+ $comment->setSizeAsBackgroundImage();
+ }
$active_sheet->setCellValue('B' . $row, $d["author"]);
$active_sheet->setCellValue('C' . $row, $d["magazine"]);
diff --git a/api/remove.php b/api/remove.php
index 65f1a82..0ef23e5 100644
--- a/api/remove.php
+++ b/api/remove.php
@@ -1,10 +1,11 @@
<?php
+
if (empty($_POST["id"])) {
http_response_code(400);
exit(0);
}
-$path = "/home/maks/school/clientApps/mlos/src/db.xml";
-require_once "/home/maks/school/clientApps/mlos/src/data.php";
+$path = "%PWD%src/db.xml";
+require_once "%PWD%src/data.php";
$id = $_POST["id"];
$doc = get_doc();
@@ -13,7 +14,20 @@ $game = $xpath->query('//game[@id="' . $id . '"]')->item(0);
$game->parentNode->removeChild($game);
$count = $doc->getElementsByTagName("count")->item(0);
-$count->nodeValue = intval($count->nodeValue) - 1;
+$icount = intval($count->nodeValue) - 1;
+$count->nodeValue = $icount;
+
+
+[$data, $_] = get_data();
+$i = 1;
+foreach($data as $d) {
+ if($d["id"] === $id) continue;
+ $g = $xpath->query('//game[@id="' . $d["id"] . '"]')->item(0);
+ var_dump('//game[@id="' . $d["id"] . '"]');
+ $g->setAttribute("order", $i);
+ $i++;
+}
$doc->save($path);
header("Location: " . $_SERVER["HTTP_REFERER"]);
+
diff --git a/index.php b/index.php
index 77f2825..aacae31 100644
--- a/index.php
+++ b/index.php
@@ -45,7 +45,7 @@ function is_pos(): bool
<tr>
<form action="api/change-order.php" method="post">
<td>
- <?php if ($d["order"] !== $count && $eid === null) { ?>
+ <?php if ($d["order"] !== "$count" && $eid === null) { ?>
<input type="hidden" name="old-order" value="<?= $d["order"] ?>">
<input type="hidden" name="new-order" value="<?= intval($d["order"]) + 1 ?>">
<input type="submit" value="pos -" />
@@ -64,7 +64,7 @@ function is_pos(): bool
</form>
<?php } else { ?>
<td>
- <form action="/api/set-session.php?eid=<?= $id ?>" method="post"><input type="submit" value="E"></form>
+ <form action="api/set-session.php?eid=<?= $id ?>" method="post"><input type="submit" value="E"></form>
</td>
<form action="api/remove.php" method="post">
<td><?= htmlspecialchars($d["name"]) ?></td>
@@ -93,10 +93,10 @@ function is_pos(): bool
<form action="api/remove.php" method="post">
<td></td>
<td></td>
- <td data-id="<?= $d['id'] ?>"><?= htmlspecialchars($d["name"]) ?></td>
- <td data-id="<?= $d['id'] ?>"><img src="/imgs/<?= htmlspecialchars($d["thumbnail"]) ?>" width="200" /></td>
- <td data-id="<?= $d['id'] ?>"><?= htmlspecialchars($d["author"]) ?></td>
- <td data-id="<?= $d['id'] ?>"><?= $d["magazine"] ?></td>
+ <td><?= htmlspecialchars($d["name"]) ?></td>
+ <td><img src="imgs/<?= htmlspecialchars($d["thumbnail"]) ?>" width="200" /></td>
+ <td><?= htmlspecialchars($d["author"]) ?></td>
+ <td><?= $d["magazine"] ?></td>
<td></td>
<td></td>
</form>
@@ -118,7 +118,10 @@ function is_pos(): bool
<?php } ?>
</tbody>
</table>
- <a href="/api/export.php">Export to xlsx</a>
+ <?php if (is_pos()) { ?>
+ <a href="api/export.php">Export to xlsx</a><br>
+ <a href="../mlos.zip">Sources</a>
+ <?php } ?>
<!-- <script src="/src/main.js"></script> -->
</body>
diff --git a/set-pwd.sh b/set-pwd.sh
new file mode 100755
index 0000000..c6963f5
--- /dev/null
+++ b/set-pwd.sh
@@ -0,0 +1,9 @@
+#!/bin/sh
+files="api/change-order.php api/export.php api/add.php api/remove.php src/data.php"
+
+[ -z "$1" ] && echo "\$1 has to be directory where project lives" && exit 1
+path="$(readlink -e "$1")"
+
+for file in $files; do
+ sed -i "s;%PWD%;$1/;" "$file"
+done
diff --git a/src/data.php b/src/data.php
index aaf9d88..1028a8f 100644
--- a/src/data.php
+++ b/src/data.php
@@ -6,7 +6,7 @@ function get_node_value($from, string $name): string
function get_doc(): DOMDocument
{
$doc = new DOMDocument();
- $path = "/home/maks/school/clientApps/mlos/src/db.xml";
+ $path = "%PWD%src/db.xml";
$doc->load($path);
return $doc;
}
diff --git a/src/db.xml b/src/db.xml
index 6cdcf11..3185c7c 100644
--- a/src/db.xml
+++ b/src/db.xml
@@ -1,16 +1,16 @@
<?xml version="1.0"?>
<root>
- <mid>18</mid>
- <count>5</count>
- <game id="1" order="5">
- <name>Wiedzmi&#x144;</name>
+ <mid>28</mid>
+ <count>7</count>
+ <game id="1" order="2">
+ <name>Wiedzmi&#x144;nnn</name>
<thumbnail>wiedzmin.png</thumbnail>
<author>&#x104;ndrzej S&#x119;pkiewicz</author>
<magazine>Fantastyka</magazine>
</game>
- <game id="2" order="3">
+ <game id="2" order="4">
<name>W&#x142;adca pier&#x15B;cieni</name>
- <thumbnail>ring.png222</thumbnail>
+ <thumbnail>ring.png</thumbnail>
<author>Tolkien Sapkowski</author>
<magazine>CDAction 1999</magazine>
</game>
@@ -20,10 +20,16 @@
<author>NotSoArchDev</author>
<magazine>Torvalds 1987</magazine>
</game>
- <game id="4" order="2">
+ <game id="4" order="3">
<name>&#x1F976;</name>
<author>&#x1F911;</author>
<thumbnail>&#x1F64A;.png</thumbnail>
<magazine>&#x1F64A;</magazine>
</game>
-<game id="12" order="4"><name>&lt;h1&gt;Thinkpad&lt;/h1&gt;</name><author>&lt;br&gt;Lenovo</author><thumbnail>&lt;br&gt;thinkpad.png</thumbnail><magazine>&lt;br&gt;&lt;b&gt;Thinkpad Magazine&lt;/b&gt;&lt;br&gt;&lt;br&gt;</magazine></game></root>
+ <game id="12" order="5">
+ <name>&lt;h1&gt;Thinkpad&lt;/h1&gt;</name>
+ <author>&lt;br&gt;Lenovo</author>
+ <thumbnail>&lt;br&gt;thinkpad.png</thumbnail>
+ <magazine>&lt;br&gt;&lt;b&gt;Thinkpad Magazine&lt;/b&gt;&lt;br&gt;&lt;br&gt;</magazine>
+ </game>
+</root>
diff --git a/start b/start
index 5176169..c3a84e0 100755
--- a/start
+++ b/start
@@ -1,4 +1,2 @@
#!/bin/sh
-#st -e pnpm dev &
-st -e php -S 0.0.0.0:8000 &
-lvim .
+php -S 0.0.0.0:8000