]> gitweb.morketsmerke.org Git - libmm.git/commitdiff
Dalszy rozwój. Dodano dodwanie książek oraz ich listę
authorxf0r3m <jakubstasinski@protonmail.com>
Thu, 2 Nov 2023 13:49:08 +0000 (14:49 +0100)
committerxf0r3m <jakubstasinski@protonmail.com>
Thu, 2 Nov 2023 13:49:08 +0000 (14:49 +0100)
index.php
install.sql
library.php
modules/addbook.php
modules/addcategorie.php
modules/books.php [new file with mode: 0644]
style.css

index 9af8f4a60f11aa413cede7b00baec60d02cfd229..b7880c876b6e5043108fd46e80f89d60462bf5be 100644 (file)
--- a/index.php
+++ b/index.php
                 include('modules/login.php'); break;
               case 'addcategorie':
                 include('modules/addcategorie.php'); break;
+              case 'addbook':
+                include('modules/addbook.php'); break;
+              case 'books':
+                include('modules/books.php'); break;
               default:
                 include('modules/frontpage.php');
             }
index 7cb7f1fb2e38bac65104593f31f7ad0a573d85f2..a966355744f4016480a8ec186fb406e7d56a09b1 100644 (file)
@@ -13,6 +13,7 @@ CREATE TABLE users (
 CREATE TABLE books (
   id int AUTO_INCREMENT PRIMARY KEY,
   type int,
+  coverlink text,
   title text,
   author text,
   publisher text,
index 87bc33b8fe5c145a4d9496375c74e4a868f7a56c..11e49698a8e6626a16d7c2c44d6272345738b294 100644 (file)
@@ -21,6 +21,7 @@ function dbQuery($connection, $tableName, $columnScheme, $whereValue, $debug=0)
     return $result;
   } else {
     echo "<script>console.log('Pobranie danych z bazy jest niemożliwe');</script>";
+    return $result;
   }
 
 }
@@ -44,6 +45,7 @@ function dbUpdate($connection, $tableName, $setValue, $whereValue) {
 
 function dbAdd($connection, $tableName, $columnScheme, $setValues) {
   $query = "INSERT INTO " . $tableName . " (" . $columnScheme . ") VALUES (" . $setValues . ");";
+  #var_dump($query);
   $result = mysqli_query($connection, $query);
 
   if ( mysqliResult($connection, $result) ) {
index 43aa982bd5293ca796743c96ff9d57c1e7a97693..969c44971deb2fce3dd863c4a89ac3dc9360444e 100644 (file)
@@ -1,5 +1,66 @@
 <!-- PHP CODE -->
 <?php
+  if ( isset($_POST['addbook-type']) ) {
+    $tableName = 'books';
+    $columnScheme = "type,coverlink,title,author,publisher,publishing,pubdate,category,ISBN,adnotes,description";
+    $setValues = intval($_POST['addbook-type']) . ",'" 
+    . mysqli_real_escape_string($connection, $_POST['addbook-coverlink']) . "','"
+    . mysqli_real_escape_string($connection, $_POST['addbook-title']) . "','"
+    . mysqli_real_escape_string($connection, $_POST['addbook-author']) . "','"
+    . mysqli_real_escape_string($connection, $_POST['addbook-publisher']) . "',"
+    . intval($_POST['addbook-publishing']) . "," . intval($_POST['addbook-pubdate']) . ","
+    . intval($_POST['addbook-category']) . ",'" . mysqli_real_escape_string($connection, $_POST['addbook-isbn']) . "','"
+    . mysqli_real_escape_string($connection, $_POST['addbook-adnotes']) . "','"
+    . mysqli_real_escape_string($connection, $_POST['addbook-desc']) . "'";
+
+    $addBookResult = dbAdd($connection, $tableName, $columnScheme, $setValues);
+    if ( mysqliResult($connection, $addBookResult) ) {
+      echo "<h3>Książka \"" . $_POST['addbook-title'] . "\" została dodana.</h3>";
+    } else {
+      echo "<h3 style=\"color: red;\">Książka nie została dodana</h3>";
+    }
+  }
 ?>
 <!-- HTML FORM -->
-
+<form action="?p=addbook" method="post">
+  <label for="book-type">Typ książki:</label><br />
+  <div id="book-type">
+    Książka papierowa&nbsp;<input type="radio" name="addbook-type" value="0" />
+    &nbsp;
+    E-Book&nbsp;<input type="radio" name="addbook-type" value="1" />
+  </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" /><br />
+  <label for="book-title">Tytuł:</label><br />
+  <input class="addbook-input" id="book-title" type="text" name="addbook-title" /><br />
+  <label for="book-author">Autor:</label><br />
+  <input class="addbook-input" id="book-author" type="text" name="addbook-author" /><br />
+  <label for="book-publisher">Wydawnictwo:</label><br />
+  <input class="addbook-input" id="book-publisher" type="text" name="addbook-publisher" /><br />
+  <label for="book-publishing">Wydanie:</label><br />
+  <input class="addbook-input" id="book-publishing" type="number" name="addbook-publishing" /><br />
+  <label for="book-pubdate">Rok wydania:</label><br />
+  <input class="addbook-input" id="book-pubdate" type="number" name="addbook-pubdate" /><br />
+  <label for="book-categorie">Kategoria:</label><br />
+  <select class="addbook-input" id="book-categorie" name="addbook-category" />
+    <option></option>
+    <?php
+      $tableName = 'categories';
+      $columnScheme = 'id,name';
+      $whereValue = '1=1';
+      $addbookCategoryResult = dbQuery($connection, $tableName, $columnScheme, $whereValue);
+      if ( mysqli_num_rows($addbookCategoryResult) > 0 ) {
+        while ( $row = mysqli_fetch_row($addbookCategoryResult) ) {
+          echo "<option value=\"" . $row[0] . "\">" . $row[1] . "</option>";
+        } 
+      }
+    ?>
+  </select><br />
+  <label for="book-isbn">Numer ISBN:</label><br />
+  <input class="addbook-input" id="book-isbn" type="text" name="addbook-isbn" /><br />
+  <label for="book-adnotes">Adnotacje (informacje dodatkowe):</label><br />
+  <textarea id="boot-adnotes" name="addbook-adnotes" rows="15" cols="50"></textarea><br />
+  <label for="book-desc">Opis</label><br />
+  <textarea id="book-desc" name="addbook-desc" rows="15" cols="50"></textarea><br /><br />
+  <button type="submit">Dodaj książkę</button>
+</form>
index 7add66c15ae0f7cdb67d6790d7c76c82769bbe9d..ede7a182e047aa2a53bbb74bf61cc4cbb7d45d33 100644 (file)
   <input type="text" name="categorie" /><br /><br />
   <button type="submit">Dodaj kategorię</button>
 </form>
+<hr />
+<h3>Kategorie:</h3>
+<?php
+  $tableName = "categories";
+  $columnScheme = "id,name";
+  $whereValue = "1=1";
+  $printCategoriesResult = dbQuery($connection, $tableName, $columnScheme, $whereValue);
+  if ( mysqliResult($connection, $printCategoriesResult) ) {
+    echo "<table>";
+    echo "<tr><th>Kategoria</th><th>Usuń</th></tr>";
+    while ( $row = mysqli_fetch_row($printCategoriesResult) ) {
+      echo "<tr><td><a href=\"?p=books&sortby=category&id=" . $row[0] . "\">" . $row[1] . "</a></td>";
+      echo "<td style=\"text-align: center;\"><a href=\"?p=delete&table=categories&id=" . $row[0] . "\" style=\"text-decoration: none\"><button><span style=\"color: red; font-size: 16px;\">&#10006;</span></button></a></td></tr>";
+    }
+    echo "</table>"; 
+  } else {
+    echo "<h3>Nieznaleziono żadnych kategorii.</h3>";
+  } 
+?>
diff --git a/modules/books.php b/modules/books.php
new file mode 100644 (file)
index 0000000..b208c8d
--- /dev/null
@@ -0,0 +1,38 @@
+<!-- PHP CODE -->
+<?php
+  if ( session_status() != 2 ) { session_start(); }
+  $tableName = "books";
+  $columnScheme = "id,title,author";
+  $whereValue = "type = " . intval($_GET['t']);
+  $booksQueryResult = dbQuery($connection, $tableName, $columnScheme, $whereValue)
+?>
+<!-- HTML FORM -->
+<?php
+  if ( isset($_GET['t']) && ( $_GET['t'] == 1 ) ) {
+    echo "<h3>E-Booki:</h3><br />";
+  } else {
+    echo "<h3>Książki papierowe:</h3><br />";
+  }
+  if ( mysqliResult($connection, $booksQueryResult) ) {
+  echo "<table>";
+  echo "<tr><th>Książka</th>";
+  if ( isset($_SESSION['username']) ) { 
+    echo "<th>Edytuj</th><th>Usuń</th>";
+  }
+  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 "<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 "<button><span style=\"color: red; font-size: 16px;\">&#10006;</span></button></a></td>";
+      }
+      echo "</tr>";
+    }
+    echo "</table>";
+  }
+?>
index 7f01ce0bef17ddf2f4761978dc66a8cba48df540..ffba53b6353d43ed39cb490aba9b66ed0767e91b 100644 (file)
--- a/style.css
+++ b/style.css
@@ -52,3 +52,7 @@ button {
   border-radius: unset;
   border: 1px solid;
 }
+
+.addbook-input {
+  width: 400px;
+}