]> gitweb.morketsmerke.org Git - libmm.git/commitdiff
Zakończono rozwój głównych funkcji. Dodano obsługę sortowania oraz możliwość dodawani... main
authorxf0r3m <jakubstasinski@protonmail.com>
Mon, 6 Nov 2023 08:42:58 +0000 (09:42 +0100)
committerxf0r3m <jakubstasinski@protonmail.com>
Mon, 6 Nov 2023 08:42:58 +0000 (09:42 +0100)
dbdrop.sql [new file with mode: 0644]
index.php
install.sql
library.php
modules/addmagazine.php [new file with mode: 0644]
modules/books.php
modules/delete.php
modules/editmagazine.php [new file with mode: 0644]
modules/magazine.php [new file with mode: 0644]
modules/magazines.php [new file with mode: 0644]

diff --git a/dbdrop.sql b/dbdrop.sql
new file mode 100644 (file)
index 0000000..2d0443a
--- /dev/null
@@ -0,0 +1,3 @@
+DROP USER 'library'@'localhost';
+DROP DATABASE library;
+FLUSH PRIVILEGES;
index 420057599dc3896bfcd194a382df57e72f2c89c5..7e442919f404e2bdd207312019ab2af089315799 100644 (file)
--- a/index.php
+++ b/index.php
           </ul>
           <br />
           <?php 
           </ul>
           <br />
           <?php 
-            if ( ( isset($_GET['p'])) && ( $_GET['p'] == "books" ) ) {
+            if ( ( isset($_GET['p'])) && ( ( $_GET['p'] == "books" ) || ( $_GET['p'] == "magazines" ) ) ) {
+              $url = "?p=" . $_GET['p'];
+              if ( isset($_GET['t']) ) { $url = $url . "&t=" . $_GET['t']; }
+              /*
+              foreach ( $_GET as $key => $value ) {
+                if ( empty($url) ) {
+                  $url = $url . "?" . $key . "=" . $value;
+                } else {
+                  $url = $url . "&" . $key . "=" . $value;
+                }
+              }
+              */
           ?>
             <label for="order-by"><strong>Uporządkuj: </strong></label>
             <ul id="order-by" class="ul-menu">
           ?>
             <label for="order-by"><strong>Uporządkuj: </strong></label>
             <ul id="order-by" class="ul-menu">
-              <li><a href="?p=books&o=title">Tytułami</a></li>
-              <li><a href="?p=books&o=author">Autorami</a></li>
-              <li><a href="?p=books&o=category">Kategoriami</a></li>
-              <li><a href="?p=books&o=pubdate">Rokiem wydania</a></li>
+              <li><a href="<?php echo $url; ?>&o=title">Tytułami</a></li>
+              <?php
+                if ( $_GET['p'] == "books" ) {
+              ?>
+              <li><a href="<?php echo $url; ?>&o=author">Autorami</a></li>
+              <li><a href="<?php echo $url; ?>&o=pubdate">Rokiem wydania</a></li>
+              <?php
+                } else if ( $_GET['p'] == "magazines" ) {
+              ?>
+              <li><a href="<?php echo $url; ?>&o=pubnumber">Numerem wydania</a></li>
+              <?php
+                }
+              ?> 
             </ul>
             <br />
             <label for="sort"><strong>Sortuj: </strong></label>
             <ul id="sort" class="ul-menu">
               <?php
                 if ( isset($_GET['o']) ) {
             </ul>
             <br />
             <label for="sort"><strong>Sortuj: </strong></label>
             <ul id="sort" class="ul-menu">
               <?php
                 if ( isset($_GET['o']) ) {
+                  $url = $url . "&o=" . $_GET['o'];
               ?>
               ?>
-                <li><a href="?p=books&o=<?php echo $_GET['o']; ?>&s=asc">Rosnąco</a>
-                <li><a href="?p=books&o=<?php echo $_GET['o']; ?>&s=desc">Malejąco</a>
+                <li><a href="<?php echo $url; ?>&s=asc">Rosnąco</a></li>
+                <li><a href="<?php echo $url; ?>&s=desc">Malejąco</a></li>
               <?php
                 } else {
               ?>
               <?php
                 } else {
               ?>
-               <li><a href="?p=books&o=title&s=asc">Rosnąco</a>
-               <li><a href="?p=books&o=title&s=desc">Malejąco</a>
+               <li><a href="<?php echo $url; ?>&o=title&s=asc">Rosnąco</a></li>
+               <li><a href="<?php echo $url; ?>&o=title&s=desc">Malejąco</a></li>
             </ul>
             </ul>
+            <br />
           <?php
               }
             }
           <?php
               }
             }
         <div id="content-container">
           <!--content-->
           <?php
         <div id="content-container">
           <!--content-->
           <?php
+            #var_dump($_SERVER);
             switch ($_GET['p']) {
               case 'login':
                 include('modules/login.php'); break;
             switch ($_GET['p']) {
               case 'login':
                 include('modules/login.php'); break;
                 include('modules/delete.php'); break;
               case 'book':
                 include('modules/book.php'); break;
                 include('modules/delete.php'); break;
               case 'book':
                 include('modules/book.php'); break;
+              case 'addmagazine':
+                include('modules/addmagazine.php'); break;
+              case 'magazines':
+                include('modules/magazines.php'); break;
+              case 'editmagazine':
+                include('modules/editmagazine.php'); break;
+              case 'magazine':
+                include('modules/magazine.php'); break;
               default:
                 include('modules/frontpage.php');
             }
               default:
                 include('modules/frontpage.php');
             }
index 231f4998eebdf3a5024ae905f62f3a68608ccb4e..22e606a20a4f8f0cd931a4dff130b266f5144f46 100644 (file)
@@ -27,9 +27,11 @@ CREATE TABLE books (
 
 CREATE TABLE magazines (
   id int AUTO_INCREMENT PRIMARY KEY,
 
 CREATE TABLE magazines (
   id int AUTO_INCREMENT PRIMARY KEY,
+  cover text,
   title text,
   pubnumber text,
   source text,
   title text,
   pubnumber text,
   source text,
+  category int,
   adnotes text,
   description text
 );
   adnotes text,
   description text
 );
index 11e49698a8e6626a16d7c2c44d6272345738b294..cb117871370f42948f8d1fa37348282ee1b2e0f4 100644 (file)
@@ -33,6 +33,7 @@ function getFieldValue($result) {
 
 function dbUpdate($connection, $tableName, $setValue, $whereValue) {
   $query = "UPDATE " . $tableName . " SET " . $setValue . " WHERE " . $whereValue;
 
 function dbUpdate($connection, $tableName, $setValue, $whereValue) {
   $query = "UPDATE " . $tableName . " SET " . $setValue . " WHERE " . $whereValue;
+  #var_dump($query);
   $result = mysqli_query($connection, $query);
  
   if ( mysqliResult($connection, $result) ) {
   $result = mysqli_query($connection, $query);
  
   if ( mysqliResult($connection, $result) ) {
diff --git a/modules/addmagazine.php b/modules/addmagazine.php
new file mode 100644 (file)
index 0000000..0098955
--- /dev/null
@@ -0,0 +1,53 @@
+<!-- PHP CODE -->
+<?php
+  if ( isset($_POST['addmagazine-cover']) ) {
+    $tableName = 'magazines';
+    $columnScheme = 'cover,title,pubnumber,source,category,adnotes,description';
+    $setValues = "'" . mysqli_real_escape_string($connection, $_POST['addmagazine-cover'])
+    . "','" . mysqli_real_escape_string($connection, $_POST['addmagazine-title']) . "','"
+    . mysqli_real_escape_string($connection, $_POST['addmagazine-publishing']) . "','"
+    . mysqli_real_escape_string($connection, $_POST['addmagazine-source']) . "',"
+    . $_POST['addmagazine-category'] . ",'"
+    . mysqli_real_escape_string($connection, $_POST['addmagazine-adnotes']) . "','"
+    . mysqli_real_escape_string($connection, $_POST['addmagazine-description']) . "'";
+    $addMagazineResult = dbAdd($connection, $tableName, $columnScheme, $setValues);
+    if ( mysqliResult($connection, $addMagazineResult) ) {
+      echo "<h3>Czasopismo: " . $_POST['addmagazine-title'] . " "
+      . $_POST['addmagazine-publishing'] . " zostało dodane</h3>";
+    } else {
+      echo "<h3>Nie dodano czasopisma.</h3>";
+    }
+  }
+?>
+<!-- HTML FORM -->
+<form action="?p=addmagazine" method="post">
+  <label for="cover">Link do okładki:</label><br />
+  <input id="cover" class="addbook-input" type="text" name="addmagazine-cover" /><br />
+  <label for="title">Tytuł:</label><br />
+  <input id="title" class="addbook-input" type="text" name="addmagazine-title" /><br />
+  <label for="publishing">Numer:</label><br />
+  <input id="publishing" class="addbook-input" type="text" name="addmagazine-publishing" /><br />
+  <label for="source">Link:</label><br />
+  <input id="source" class="addbook-input" type="text" name="addmagazine-source" /><br />
+  <label for="category">Kategoria:</label><br />
+  <select id="category" class="addbook-input" name="addmagazine-category">
+    <option></option>
+    <?php
+      $tableName = "categories";
+      $columnScheme = "id,name";
+      $whereValue = "1=1";
+      $addMagazineResult = dbQuery($connection, $tableName, $columnScheme, $whereValue);
+      if ( mysqliResult($connection, $addMagazineResult) ) {
+        while ( $row = mysqli_fetch_row($addMagazineResult) ) {
+          echo "<option value=\"" . $row[0] . "\">" . $row[1] . "</option>";
+        }
+      }
+    ?>
+  </select><br />
+  <label for="adnotes">Adnotacje</label><br />
+  <textarea id="adnotes" name="addmagazine-adnotes" rows="15" cols="50"></textarea><br />
+  <label for="description">Opis:</label><br />
+  <textarea id="description" name="addmagazine-description" rows="15" cols="50"></textarea><br />
+  <br />
+  <button type="submit">Dodaj czasopismo</button>
+</form>
index d946b5960154076ef1f5ea925750d009dba5ffde..c411df85778f956f75234498a94ed4ef87e93c20 100644 (file)
   } else if ( isset($_GET['a']) ) {
     $whereValue = "author = '" . urldecode($_GET['a']) . "'";
   }
   } else if ( isset($_GET['a']) ) {
     $whereValue = "author = '" . urldecode($_GET['a']) . "'";
   }
+  switch ($_GET['o']) {
+    case 'author':
+      $whereValue = $whereValue . " ORDER BY author"; break;
+    case 'pubdate':
+      $whereValue = $whereValue . " ORDER BY pubdate"; break;
+    default:
+      $whereValue = $whereValue . " ORDER BY title"; break; 
+  }
+  switch ($_GET['s']) {
+    case 'asc':
+      $whereValue = $whereValue . " ASC"; break;
+    case 'desc':
+      $whereValue = $whereValue . " DESC"; break;
+    default:
+      $whereValue = $whereValue . " ASC"; break;
+  }
   $booksQueryResult = dbQuery($connection, $tableName, $columnScheme, $whereValue)
 ?>
 <!-- HTML FORM -->
   $booksQueryResult = dbQuery($connection, $tableName, $columnScheme, $whereValue)
 ?>
 <!-- HTML FORM -->
index c8935d57a6da78486650ba950d262730b29e68fd..1088ca4ed6c1244981c6c4046beb5c8c32672152 100644 (file)
@@ -18,7 +18,7 @@
     if ( $tableName == "books" ) {
       $columnScheme = "title,type";
     } else if ( $tableName == "magazines" ) {
     if ( $tableName == "books" ) {
       $columnScheme = "title,type";
     } else if ( $tableName == "magazines" ) {
-      $columnScheme = 'title';
+      $columnScheme = 'title,pubnumber';
     } else {
       $columnScheme = 'name';
     }
     } else {
       $columnScheme = 'name';
     }
       echo "<h3>Nie można pobrać informacji o obiekcie.</h3>";
     }
 ?>
       echo "<h3>Nie można pobrać informacji o obiekcie.</h3>";
     }
 ?>
-<h3>Czy jesteś pewien, że chcesz usunąć:<br /> <?php echo $row[0]; ?> ?</h3>
+<?php
+  if ( $tableName == "magazines" ) {
+    echo "<h3>Czy jesteś pewien, że chcesz usunąć:<br />" . $row[0] . " " . $row[1] . "?</h3>";
+  } else {
+    echo "<h3>Czy jesteś pewien, że chcesz usunąć:<br />" . $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; ?>" />
 <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; ?>" />
diff --git a/modules/editmagazine.php b/modules/editmagazine.php
new file mode 100644 (file)
index 0000000..4a68981
--- /dev/null
@@ -0,0 +1,74 @@
+<!-- PHP CODE -->
+<?php
+  if ( isset($_POST['editmag-id']) ) {
+    $tableName = 'magazines';
+    #$columnScheme = "type,coverlink,title,author,publisher,publishing,pubdate,category,ISBN,adnotes,description";
+    $setValues = "cover = '" 
+    . mysqli_real_escape_string($connection, $_POST['editmag-cover']) . "', title = '"
+    . mysqli_real_escape_string($connection, $_POST['editmag-title']) . "', pubnumber = '"
+    . mysqli_real_escape_string($connection, $_POST['editmag-pubnumber']) . "', source = '"
+    . mysqli_real_escape_string($connection, $_POST['editmag-source'])  . "', category = "
+    . intval($_POST['editmag-category']) . ", adnotes = '"
+    . mysqli_real_escape_string($connection, $_POST['editmag-adnotes']) . "', description = '"
+    . mysqli_real_escape_string($connection, $_POST['editmag-desc']) . "'";
+    $whereValue = 'id = ' . intval($_POST['editmag-id']);
+    $editMagResult = dbUpdate($connection, $tableName, $setValues, $whereValue);
+    if ( mysqliResult($connection, $editMagResult) ) {
+      echo "<h3>Zamiany zostały zapisane.</h3>";
+    } else {
+      echo "<h3 style=\"color: red;\">Zmiany nie zostały zapisne.</h3>";
+    }
+  } 
+  $tableName = 'magazines';
+  $columnScheme = '*';
+  if ( ! isset($_GET['id'] ) ) {
+    $whereValue = 'id = ' . intval($_POST['editmag-id']);
+  } else {
+    $whereValue = 'id = ' . intval($_GET['id']);
+  }
+  $editMagResult = dbQuery($connection, $tableName, $columnScheme, $whereValue)
+?>
+<!-- HTML FORM -->
+<?php
+  if ( mysqliResult($connection, $editMagResult) ) {
+    $row = mysqli_fetch_row($editMagResult);
+?>
+    <form action="?p=editmagazine" method="post">
+      <input type="hidden" name="editmag-id" value="<?php echo $row[0]; ?>" />
+      <label for="mag-cover">Adres do okładki:</label><br />
+      <input class="addbook-input" id="mag-cover" type="text" name="editmag-cover" value="<?php echo $row[1]; ?>" /><br />
+      <label for="mag-title">Tytuł:</label><br />
+      <input class="addbook-input" id="mag-title" type="text" name="editmag-title" value="<?php echo $row[2]; ?>" /><br />
+      <label for="mag-pubnumber">Numer:</label><br />
+      <input class="addbook-input" id="mag-pubnumber" type="text" name="editmag-pubnumber" value="<?php echo $row[3]; ?>" /><br />
+      <label for="mag-source">Link:</label><br />
+      <input class="addbook-input" id="mag-source" type="text" name="editmag-source" value="<?php echo $row[4]; ?>" /><br />
+      <label for="mag-category">Kategoria:</label><br />
+      <select class="addbook-input" id="mag-category" name="editmag-category" />
+      <?php
+        $tableName = 'categories';
+        $columnScheme = 'id,name';
+        $whereValue = '1=1';
+        $editMagCategoryResult = dbQuery($connection, $tableName, $columnScheme, $whereValue);
+        if ( mysqli_num_rows($editMagCategoryResult) > 0 ) {
+          while ( $row2 = mysqli_fetch_row($editMagCategoryResult) ) {
+            if ( $row2[0] == $row[5] ) {
+              echo "<option value=\"" . $row[5] . "\" selected>" . $row2[1] . "</option>";
+            } else {
+              echo "<option value=\"" . $row2[0] . "\">" . $row2[1] . "</option>";
+            }
+          } 
+        }
+      ?>
+      </select><br />
+      <label for="mag-adnotes">Adnotacje (informacje dodatkowe):</label><br />
+      <textarea id="mag-adnotes" name="editmag-adnotes" rows="15" cols="50"><?php echo $row[6]; ?></textarea><br />
+      <label for="mag-desc">Opis:</label><br />
+      <textarea id="mag-desc" name="editmag-desc" rows="15" cols="50"><?php echo $row[7]; ?></textarea><br /><br />
+      <button type="submit">Zapisz zmiany</button>
+</form>
+<?php
+  } else {
+    echo "<h3>Nie odnaleziono takiego czasopisma.</h3>";
+  }
+?>
diff --git a/modules/magazine.php b/modules/magazine.php
new file mode 100644 (file)
index 0000000..9313daf
--- /dev/null
@@ -0,0 +1,48 @@
+<!-- PHP CODE -->
+<?php
+  if ( session_status() != 2 ) { session_start();}
+  $tableName = 'magazines';
+  $columnScheme = "*";
+  $whereValue = 'id = ' . intval($_GET['id']);
+  $bookQueryResult = dbQuery($connection, $tableName, $columnScheme, $whereValue);
+  if ( mysqliResult($connection, $bookQueryResult) ) {
+    $row = mysqli_fetch_row($bookQueryResult);
+  } else {
+    echo "<h3>Nie można pobrać informacji o obiekcie</h3>";
+  }
+?>
+<!-- HTML FORM -->
+<h3><?php echo $row[2]; ?></h3>
+<h4 style="color: gray;"><em><?php echo $row[3]; ?></em></h4>
+<div style="width: 340px; height:250px; float: left">
+<?php
+  
+  $tableName = 'categories';
+  $columnScheme = 'name';
+  $whereValue = 'id = ' . intval($row[5]);
+  $catQueryResult = dbQuery($connection, $tableName, $columnScheme, $whereValue);
+  if ( mysqliResult($connection, $catQueryResult) ) {
+    $category = getFieldValue($catQueryResult);
+  }
+?>
+<p><strong>Kategoria:</strong>
+<a href="?p=magazines&c=<?php echo urlencode($row[5]) ?>">
+<?php echo $category; ?>
+</a>
+</p>
+<p><strong>Adnotacje:</strong><br />
+<?php
+         echo nl2br($row[6]);
+?>
+</p>
+<p><strong>Opis:</strong><br /> <?php echo nl2br($row[7]); ?>
+</p>
+<?php
+if ( isset($_SESSION['username']) ) {
+  echo "<p><strong>Link:</strong><a href=\"" . $row[4] . "\">" . $row[4] . "</a></p>";
+}
+?>
+</div>
+<div style="width: 340px; float: left;">
+<img class="book-cover" src="<?php echo $row[1]; ?>" hspace=10 vspace=10 alt="<?php echo basename($row[1]); ?>"/>
+</div>
diff --git a/modules/magazines.php b/modules/magazines.php
new file mode 100644 (file)
index 0000000..5b8720f
--- /dev/null
@@ -0,0 +1,55 @@
+<!-- PHP CODE -->
+<?php
+  if ( session_status() != 2 ) { session_start(); }
+  $tableName = "magazines";
+  $columnScheme = "id,title,pubnumber";
+  $whereValue = "1=1";
+  switch ($_GET['o']) {
+    case 'pubnumber':
+      $whereValue = $whereValue . " ORDER BY pubnumber"; break;
+    default:
+      $whereValue = $whereValue . " ORDER BY title"; break; 
+  }
+  switch ($_GET['s']) {
+    case 'asc':
+      $whereValue = $whereValue . " ASC"; break;
+    case 'desc':
+      $whereValue = $whereValue . " DESC"; break;
+    default:
+      $whereValue = $whereValue . " ASC"; break;
+  }
+  $magsQueryResult = dbQuery($connection, $tableName, $columnScheme, $whereValue)
+?>
+<!-- HTML FORM -->
+<h3>Czasopisma:</h3>
+<?php
+  if ( isset($_GET['c']) ) {
+    $tableName = 'categories';
+    $columnScheme = 'name';
+    $whereValue = "id = " . intval($_GET['c']);
+    $magsCatResult = dbQuery($connection, $tableName, $columnScheme, $whereValue);
+    $category = getFieldValue($magsCatResult);
+    echo "<h3>Kategoria: " . $category . "</h3>";
+  }
+  if ( mysqliResult($connection, $magsQueryResult) ) {
+  echo "<table>";
+  echo "<tr><th>Czasopisma</th>";
+  if ( isset($_SESSION['username']) ) { 
+    echo "<th>Edytuj</th><th>Usuń</th>";
+  }
+  echo "</tr>";
+    while ( $row = mysqli_fetch_row($magsQueryResult) ) {
+      echo "<tr>";
+      echo "<td><a href=\"?p=magazine&id=" . $row[0] . "\">" . $row[2] . "</a><br />";
+      echo "<small style=\"color: gray;\"><em>" . $row[1] . "</em></small></td>";
+      if ( isset($_SESSION['username']) ) {
+        echo "<td style=\"text-align: center;\"><a href=\"?p=editmagazine&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=magazines&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>";
+  }
+?>