From bf7852bccce954aff2d7c94161f4d301a0f29684 Mon Sep 17 00:00:00 2001 From: Maksymilian Jopek Date: Wed, 16 Mar 2022 23:20:59 +0100 Subject: Initial commit w/ v1.0.0 --- api/add.php | 55 ++++++++++++++++++++++++++++++++++++++++++++++++++++ api/change-order.php | 26 +++++++++++++++++++++++++ api/export.php | 43 ++++++++++++++++++++++++++++++++++++++++ api/remove.php | 19 ++++++++++++++++++ 4 files changed, 143 insertions(+) create mode 100644 api/add.php create mode 100644 api/change-order.php create mode 100644 api/export.php create mode 100644 api/remove.php (limited to 'api') diff --git a/api/add.php b/api/add.php new file mode 100644 index 0000000..b2e4c2d --- /dev/null +++ b/api/add.php @@ -0,0 +1,55 @@ +query('//game[@id="' . $id . '"]')->item(0); + var_dump($game); + var_dump($game->getElementsByTagName); + $xpath->query('//game[@id="' . $id . '"]/name')->item(0)->nodeValue = $name; + $xpath->query('//game[@id="' . $id . '"]/author')->item(0)->nodeValue = $author; + $xpath->query('//game[@id="' . $id . '"]/thumbnail')->item(0)->nodeValue = $thumbnail; + $xpath->query('//game[@id="' . $id . '"]/magazine')->item(0)->nodeValue = $magazine; +} else { + $root = $doc->getElementsByTagName("root")->item(0); + $game = $doc->createElement("game", ""); + + $mid = $doc->getElementsByTagName("mid")->item(0); + $game->setAttribute("id", $mid->nodeValue); + $mid->nodeValue = intval($mid->nodeValue) + 1; + + $count = $doc->getElementsByTagName("count")->item(0); + $count->nodeValue = intval($count->nodeValue) + 1; + $game->setAttribute("order", $count->nodeValue); + + $name = $doc->createElement("name", $name); + $author = $doc->createElement("author", $author); + $thumbnail = $doc->createElement("thumbnail", $thumbnail); + $magazine = $doc->createElement("magazine", $magazine); + $game->append($name); + $game->append($author); + $game->append($thumbnail); + $game->append($magazine); + + $root->appendChild($game); +} + +$doc->save($path); diff --git a/api/change-order.php b/api/change-order.php new file mode 100644 index 0000000..b498605 --- /dev/null +++ b/api/change-order.php @@ -0,0 +1,26 @@ +getElementsByTagName("count")->item(0)->nodeValue; +if ($new_order === strval(intval($count) + 1) || $new_order === "0") { + exit(); +} +$doc = get_doc(); +$xpath = new DOMXpath($doc); +$old_game = $xpath->query('//game[@order="' . $old_order . '"]')->item(0); +$new_game = $xpath->query('//game[@order="' . $new_order . '"]')->item(0); +$old_game->setAttribute("order", $new_order); +$new_game->setAttribute("order", $old_order); + +// check for first + +$doc->save($path); +header("Location: " . $_SERVER["HTTP_REFERER"]); diff --git a/api/export.php b/api/export.php new file mode 100644 index 0000000..77e36a2 --- /dev/null +++ b/api/export.php @@ -0,0 +1,43 @@ +getActiveSheet(); + +$active_sheet->setCellValue('A1', "Name"); +$active_sheet->setCellValue('B1', "Author"); +$active_sheet->setCellValue('C1', "Magazine"); +$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(); + + + $active_sheet->setCellValue('B' . $row, $d["author"]); + $active_sheet->setCellValue('C' . $row, $d["magazine"]); + $row++; +} + +$writer = new Xlsx($spreadsheet); +$writer->save('php://output'); + +$spreadsheet->disconnectWorksheets(); diff --git a/api/remove.php b/api/remove.php new file mode 100644 index 0000000..65f1a82 --- /dev/null +++ b/api/remove.php @@ -0,0 +1,19 @@ +query('//game[@id="' . $id . '"]')->item(0); +$game->parentNode->removeChild($game); + +$count = $doc->getElementsByTagName("count")->item(0); +$count->nodeValue = intval($count->nodeValue) - 1; + +$doc->save($path); +header("Location: " . $_SERVER["HTTP_REFERER"]); -- cgit v1.3.1