--- /dev/null
+DROP USER 'library'@'localhost';
+DROP DATABASE library;
+FLUSH PRIVILEGES;
</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">
- <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']) ) {
+ $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 {
?>
- <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>
+ <br />
<?php
}
}
<div id="content-container">
<!--content-->
<?php
+ #var_dump($_SERVER);
switch ($_GET['p']) {
case 'login':
include('modules/login.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');
}
CREATE TABLE magazines (
id int AUTO_INCREMENT PRIMARY KEY,
+ cover text,
title text,
pubnumber text,
source text,
+ category int,
adnotes text,
description text
);
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) ) {
--- /dev/null
+<!-- 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>
} 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 -->
if ( $tableName == "books" ) {
$columnScheme = "title,type";
} else if ( $tableName == "magazines" ) {
- $columnScheme = 'title';
+ $columnScheme = 'title,pubnumber';
} else {
$columnScheme = 'name';
}
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; ?>" />
--- /dev/null
+<!-- 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>";
+ }
+?>
--- /dev/null
+<!-- 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>
--- /dev/null
+<!-- 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;\">✎</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;\">✖</span></button></a></td>";
+ }
+ echo "</tr>";
+ }
+ echo "</table>";
+ }
+?>