]> gitweb.morketsmerke.org Git - libmm.git/commitdiff
Dodano możliwość edycji oraz usuwania książek. TODO: Zmienić notatki na czasopisma.
authorxf0r3m <jakubstasinski@protonmail.com>
Thu, 2 Nov 2023 18:00:01 +0000 (19:00 +0100)
committerxf0r3m <jakubstasinski@protonmail.com>
Thu, 2 Nov 2023 18:00:01 +0000 (19:00 +0100)
index.php
modules/books.php
modules/delete.php [new file with mode: 0644]
modules/editbook.php [new file with mode: 0644]

index b7880c876b6e5043108fd46e80f89d60462bf5be..fbc6acda4db88cc9e93c4243101c18e4a461c0b8 100644 (file)
--- a/index.php
+++ b/index.php
                 include('modules/addbook.php'); break;
               case 'books':
                 include('modules/books.php'); break;
+              case 'editbook':
+                include('modules/editbook.php'); break;
+              case 'delete':
+                include('modules/delete.php'); break;
               default:
                 include('modules/frontpage.php');
             }
index b208c8d1063e804663c0593c16a01173c66b0b54..25a20a9138a6c79b1886da0e0ab216ce5633370a 100644 (file)
   echo "</tr>";
     while ( $row = mysqli_fetch_row($booksQueryResult) ) {
       echo "<tr>";
-      echo "<td style=\"background-color: #17a2b8;\"><a href=\"?p=book&id=" . $row[0] . "\">" . $row[1] . "</a><br />";
+      echo "<td><a href=\"?p=book&id=" . $row[0] . "\">" . $row[1] . "</a><br />";
       echo "<a href=\"?p=books&a=" . urlencode($row[2]) . "\" style=\"color: gray;\">";
       echo "<small style=\"color: gray;\"><em>" . $row[2] . "</em></small></a></td>";
       if ( isset($_SESSION['username']) ) {
-        echo "<td style=\"text-align: center;background-color: #17a2b8;\"><a href=\"?p=editbook&id=" . $row[0] . "\" style=\"text-decoration: none;\">";
-        echo "<button><span style=\"color: #ffc107; font-size: 16px;\">&#9998;</span></button></a></td>";
-        echo "<td style=\"text-align: center;background-color: #17a2b8;\"><a href=\"?p=delete&table=books&id=" . $row[0] . "\" style=\"text-decoration: none;\">";
+        echo "<td style=\"text-align: center;\"><a href=\"?p=editbook&id=" . $row[0] . "\" style=\"text-decoration: none;\">";
+        echo "<button><span style=\"color: #000000; font-size: 16px;\">&#9998;</span></button></a></td>";
+        echo "<td style=\"text-align: center;\"><a href=\"?p=delete&table=books&id=" . $row[0] . "\" style=\"text-decoration: none;\">";
         echo "<button><span style=\"color: red; font-size: 16px;\">&#10006;</span></button></a></td>";
       }
       echo "</tr>";
diff --git a/modules/delete.php b/modules/delete.php
new file mode 100644 (file)
index 0000000..41ee9fc
--- /dev/null
@@ -0,0 +1,45 @@
+<!-- PHP CODE -->
+<?php
+  if ( isset($_POST['delete-table']) ) {
+    $tableName = $_POST['delete-table'];
+    $whereValue = 'id = ' . intval($_POST['delete-id']);
+    $deleteResult = dbDel($connection, $tableName, $whereValue);
+    if ( mysqliResult($connection, $deleteResult) ) {
+      echo "<h3>Obiekt usunięty.</h3>";
+    } else {
+      echo "<h3>Nie można usunąć obiektu.</h3>";
+    }
+  }
+?>
+<!-- HTML FORM -->
+<?php
+  if ( isset($_GET['table'] ) ) {
+    $tableName = $_GET['table'];
+    if ( $tableName == "books" ) {
+      $columnScheme = "title,type";
+    } else {
+      $columnScheme = 'title';
+    }
+    $id = intval($_GET['id']);
+    $whereValue = 'id = ' . $id;
+    $objectQueryResult = dbQuery($connection, $tableName, $columnScheme, $whereValue);
+    if ( mysqliResult($connection, $objectQueryResult) ) {
+      $row = mysqli_fetch_row($objectQueryResult);
+    } else {
+      echo "<h3>Nie można pobrać informacji o obiekcie.</h3>";
+    }
+?>
+<h3>Czy jesteś pewien, że chcesz usunąć:<br /> <?php echo $row[0]; ?> ?</h3>
+<form action="?p=delete" method="post" style="float: left;">
+  <input type="hidden" name="delete-table" value="<?php echo $tableName; ?>" />
+  <input type="hidden" name="delete-id" value="<?php echo $id; ?>" />
+  <button type="submit">Tak</button>
+</form>
+<?php
+      if ( $tableName == "books" ) {
+        echo "<a href=\"?p=" . $tableName . "&t=" . $row[1] . "\" style=\"float: left; margin-left: 10px;\"><button>Nie</button></a>";
+      } else {
+        echo "<a href=\"?p=" . $tableName . "\" style=\"float: left; margin-left: 10px;\"><button>Nie</button></a>";
+      }
+    }
+?>
diff --git a/modules/editbook.php b/modules/editbook.php
new file mode 100644 (file)
index 0000000..4bda634
--- /dev/null
@@ -0,0 +1,109 @@
+<!-- PHP CODE -->
+<?php
+  ?>
+<?php
+  if ( isset($_POST['editbook-id']) ) {
+    $tableName = 'books';
+    #$columnScheme = "type,coverlink,title,author,publisher,publishing,pubdate,category,ISBN,adnotes,description";
+    $setValues = 'type = ' . intval($_POST['addbook-type']) . ", coverlink = '" 
+    . mysqli_real_escape_string($connection, $_POST['addbook-coverlink']) . "', title = '"
+    . mysqli_real_escape_string($connection, $_POST['addbook-title']) . "', author = '"
+    . mysqli_real_escape_string($connection, $_POST['addbook-author']) . "', publisher = '"
+    . mysqli_real_escape_string($connection, $_POST['addbook-publisher']) . "', publishing = "
+    . intval($_POST['addbook-publishing']) . ", pubdate = " . intval($_POST['addbook-pubdate']) . ", category = "
+    . intval($_POST['addbook-category']) . ", ISBN = '" . mysqli_real_escape_string($connection, $_POST['addbook-isbn']) . "', adnotes = '"
+    . mysqli_real_escape_string($connection, $_POST['addbook-adnotes']) . "', description = '"
+    . mysqli_real_escape_string($connection, $_POST['addbook-desc']) . "'";
+    $whereValue = 'id = ' . intval($_POST['editbook-id']);
+    $editBookResult = dbUpdate($connection, $tableName, $setValues, $whereValue);
+    if ( mysqliResult($connection, $editBookResult) ) {
+      echo "<h3>Zamiany zostały zapisane.</h3>";
+    } else {
+      echo "<h3 style=\"color: red;\">Zmiany nie zostały zapisne.</h3>";
+    }
+  } 
+  $tableName = 'books';
+  $columnScheme = '*';
+  if ( ! isset($_GET['id'] ) ) {
+    $whereValue = 'id = ' . intval($_POST['editbook-id']);
+  } else {
+    $whereValue = 'id = ' . intval($_GET['id']);
+  }
+  $editBookResult = dbQuery($connection, $tableName, $columnScheme, $whereValue)
+?>
+<!-- HTML FORM -->
+<?php
+  if ( mysqliResult($connection, $editBookResult) ) {
+    $row = mysqli_fetch_row($editBookResult);
+?>
+    <form action="?p=editbook" method="post">
+      <input type="hidden" name="editbook-id" value="<?php echo $row[0]; ?>" />
+      <label for="book-type">Typ książki:</label><br />
+      <div id="book-type">
+        <?php
+          if ( $row[1] == 0 ) {
+        ?>
+          Książka papierowa&nbsp;<input type="radio" name="addbook-type" value="0" checked/>
+        <?php
+          } else {
+        ?>
+          Książka papierowa&nbsp;<input type="radio" name="addbook-type" value="0" />
+        <?php
+          }
+        ?>
+        &nbsp;
+        <?php
+          if ( $row[1] == 1 ) {
+        ?>
+          E-Book&nbsp;<input type="radio" name="addbook-type" value="1" checked/>
+        <?php
+          } else {
+        ?>
+          E-Book&nbsp;<input type="radio" name="addbook-type" value="1" />
+        <?php
+          }
+        ?>
+      </div><br />
+      <label for="book-cover-link">Adres do okładki:</label><br />
+      <input class="addbook-input" id="book-cover-link" type="text" name="addbook-coverlink" value="<?php echo $row[2]; ?>" /><br />
+      <label for="book-title">Tytuł:</label><br />
+      <input class="addbook-input" id="book-title" type="text" name="addbook-title" value="<?php echo $row[3]; ?>" /><br />
+      <label for="book-author">Autor:</label><br />
+      <input class="addbook-input" id="book-author" type="text" name="addbook-author" value="<?php echo $row[4]; ?>" /><br />
+      <label for="book-publisher">Wydawnictwo:</label><br />
+      <input class="addbook-input" id="book-publisher" type="text" name="addbook-publisher" value="<?php echo $row[5]; ?>" /><br />
+      <label for="book-publishing">Wydanie:</label><br />
+      <input class="addbook-input" id="book-publishing" type="number" name="addbook-publishing" value="<?php echo $row[6]; ?>" /><br />
+      <label for="book-pubdate">Rok wydania:</label><br />
+      <input class="addbook-input" id="book-pubdate" type="number" name="addbook-pubdate" value="<?php echo $row[7]; ?>" /><br />
+      <label for="book-categorie">Kategoria:</label><br />
+      <select class="addbook-input" id="book-categorie" name="addbook-category" />
+      <?php
+        $tableName = 'categories';
+        $columnScheme = 'id,name';
+        $whereValue = '1=1';
+        $editbookCategoryResult = dbQuery($connection, $tableName, $columnScheme, $whereValue);
+        if ( mysqli_num_rows($editbookCategoryResult) > 0 ) {
+          while ( $row2 = mysqli_fetch_row($editbookCategoryResult) ) {
+            if ( $row2[0] == $row[8] ) {
+              echo "<option value=\"" . $row[8] . "\" selected>" . $row2[1] . "</option>";
+            } else {
+              echo "<option value=\"" . $row2[0] . "\">" . $row2[1] . "</option>";
+            }
+          } 
+        }
+      ?>
+      </select><br />
+      <label for="book-isbn">Numer ISBN:</label><br />
+      <input class="addbook-input" id="book-isbn" type="text" name="addbook-isbn" value="<?php echo $row[9]; ?>" /><br />
+      <label for="book-adnotes">Adnotacje (informacje dodatkowe):</label><br />
+      <textarea id="boot-adnotes" name="addbook-adnotes" rows="15" cols="50"><?php echo $row[10]; ?></textarea><br />
+      <label for="book-desc">Opis</label><br />
+      <textarea id="book-desc" name="addbook-desc" rows="15" cols="50"><?php echo $row[11]; ?></textarea><br /><br />
+      <button type="submit">Zapisz zmiany</button>
+</form>
+<?php
+  } else {
+    echo "<h3>Nie odnaleziono takiej książki.</h3>";
+  }
+?>