Файл: Разработка WEB-ресурса по обмену книгами «BookTrade.org».pdf

ВУЗ: Не указан

Категория: Курсовая работа

Дисциплина: Не указана

Добавлен: 25.04.2023

Просмотров: 328

Скачиваний: 2

ВНИМАНИЕ! Если данный файл нарушает Ваши авторские права, то обязательно сообщите нам.

} while ($res = mysqli_fetch_array($wrg));

if ($_SESSION['username'] == $username) {

$sql = "DELETE FROM w_read WHERE wr_id = '$wr_id'";

if (mysqli_query($connection, $sql)) {

mysqli_close($connection);

header('Location: /booktrade.org/user.php');

exit;

}

else {

echo "Error deleting record";

}

}

?>

index.php

<?php

session_start();

require('includes/connect.php');

?>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">

<html>

<head>

<meta charset="utf-8" content="text/html">

<title>BookTrade</title>

<link rel="SHORTCUT ICON" href="favicon.ico" type="image/x-icon">

<link rel="stylesheet" href="style/main.css">

<link rel="stylesheet" href="style/navigation.css">

<link href='http://fonts.googleapis.com/css?family=Open+Sans:300italic,400italic,600italic,700italic,800italic,400,300,600,700,800' rel='stylesheet' type='text/css'>

</head>

<body>

<div class="wrapper">

<?php

if (isset($_SESSION['username'])) {

include('includes/aheader.php');

} else {

include('includes/header.php');

}

?>

<div class="plot">

<ul>

<a href="index.php"><li class="li_first">Home page</li></a>

<a href="goread.php"><li class="li_reg">What to read?</li></a>

<a href="quotes.php"><li class="li_reg">Quotes</li></a>

<a href="reviews.php"><li class="li_reg">Users' reviews</li></a>

<a href="toffers.php"><li class="li_reg">Trade offers</li></a>

<a href="news.php"><li class="li_last">Literature news</li></a>

</ul>

<br>

<?php

if ($_SESSION['username'] == NULL) {

echo "<h3 align='center'>This site was made by book lovers for book lovers. Here you can find the latest literature news, exchange books with other users or even find new friends.<br>Our resource is not aimed at providing information, but in the search for something new. You can find something new for yourself by looking at a section with a random book, random quotes, or even a selection of random reviews!</h3>";

}

?>

<img src='graphics/sharing.png' align='center' width = 880px>

<hr>

<h5>Users online now:</h5>

<p>

<?php

$query_online = "SELECT * FROM user_info WHERE active=1";

$result_online = mysqli_query($connection, $query_online) or die("Ошибка " . mysqli_error($connection));

if($result_online) {

$rows = mysqli_num_rows($result_online);

for ($i = 0 ; $i < $rows ; ++$i) {

$row = mysqli_fetch_row($result_online);

echo "<a href='user.php?name=$row[0]'>$row[0]</a> ";

}

}

?>

</p>

<hr>

<?php

$query = ('SELECT title, text FROM (SELECT * FROM site_news ORDER BY n_id DESC LIMIT 5) AS T ORDER BY n_id ASC');

$result = mysqli_query($connection, $query) or die("Ошибка " . mysqli_error($connection));

if($result) {

$rows = mysqli_num_rows($result);

for ($i = 0 ; $i < $rows ; ++$i) {

$row = mysqli_fetch_row($result);

echo "<h3>$row[0]</h3>";

echo "<p>$row[1]</p>";

echo "<h5>$row[3]</h5>";

echo "<br>";

}

}

?>

</div>

<?php include('includes/footer.php'); ?>

</div>

</body>

</html>

addbook.php

<?php

session_start();

require('includes/connect.php');

$username = $_SESSION['username'];

?>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">

<html>

<head>

<meta charset="utf-8" content="text/html">

<title>BookTrade | Add book</title>

<link rel="SHORTCUT ICON" href="favicon.ico" type="image/x-icon">

<link rel="stylesheet" href="style/main.css">


<link rel="stylesheet" href="style/ubody.css">

<link href='http://fonts.googleapis.com/css?family=Open+Sans:300italic,400italic,600italic,700italic,800italic,400,300,600,700,800' rel='stylesheet' type='text/css'>

</head>

<body>

</body>

<div class="wrapper">

<div class="plott">

<?php

echo "<a href='index.php'><- Back to home page</a><br><a href='user.php?name=$username'><- Back to userpage</a>";

if ($_SESSION['rights'] > 0) {

$tbookname = $_POST['tbookname'];

$tradeinfo = $_POST['tradeinfo'];

$tauthor = $_POST['tauthor'];

if ($tbookname != NULL && $tradeinfo != NULL && $tauthor != NULL) {

$query_trade = "INSERT INTO w_trade (username, bookname, author, trade_info) VALUES ('$username', '$tbookname', '$tauthor', '$tradeinfo')";

$add_trade = mysqli_query($connection, $query_trade) or die(mysqli_error($connection));

echo "<p>You added trade offer.</p>";

}

$wbookname = $_POST['wbookname'];

$wauthor = $_POST['wauthor'];

if ($wbookname != NULL && $wauthor != NULL) {

$query_wanted = "INSERT INTO w_read (username, bookname, author) VALUES ('$username', '$wbookname', '$wauthor')";

$add_wanted = mysqli_query($connection, $query_wanted) or die(mysqli_error($connection));

echo "<p>You added $wbookname to wanted books.</p>";

}

$rbookname = $_POST['rbookname'];

if ($rbookname != NULL && $rauthor != NULL) {

$query_readed = "INSERT INTO readed (username, bookname, author) VALUES ('$username', '$rbookname', '$rauthor')";

$add_readed = mysqli_query($connection, $query_readed) or die(mysqli_error($connection));

echo "<p>You added $rbookname to readed books.</p>";

}

echo "<form action='addbook.php' id='addtrade' method='POST' name='addtrade'>

<h4>Add trade offer:</h4>

<p>Book name:</p>

<p><input class='input' id='tbookname' name='tbookname' size='32' type='text' placeholder='book name'></p>

<p>Author:</p>

<p><input class='input' id='tauthor' name='tauthor' size='32' type='text' placeholder='author'></p>

<p>Trade info:</p>

<p><textarea class='input' id='tradeinfo' name='tradeinfo' cols='50' rows='5' placeholder='trade info'></textarea></p>

<p class='submit'><input class='button' id='admit' name='admit' type='submit' value='Add trade offer'></p></form><hr>";

echo "<form action='addbook.php' id='addwanted' method='POST' name='addwanted'>

<h4>Add wanted book:</h4>

<p>Book name:</p>

<p><input class='input' id='wbookname' name='wbookname' size='32' type='text' placeholder='book name'></p>

<p>Author:</p>

<p><input class='input' id='wauthor' name='wauthor' size='32' type='text' placeholder='author'></p>

<p class='submit'><input class='button' id='admit' name='admit' type='submit' value='Add wanted book'></p></form><hr>";

echo "<form action='addbook.php' id='addreaded' method='POST' name='addeaded'>

<h4>Add readed book:</h4>

<p>Book name:</p>

<p><input class='input' id='rbookname' name='rbookname' size='32' type='text' placeholder='book name'></p>

<p>Author:</p>

<p><input class='input' id='rauthor' name='rauthor' size='32' type='text' placeholder='author'></p>

<p class='submit'><input class='button' id='admit' name='admit' type='submit' value='Add readed book'></p></form><hr>";

}

?>

</div>

</div>

</body>

addreview.php

<?php

session_start();

require('includes/connect.php');

?>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">

<html>

<head>

<meta charset="utf-8" content="text/html">

<title>BookTrade | Literature news</title>

<link rel="SHORTCUT ICON" href="favicon.ico" type="image/x-icon">


<link rel="stylesheet" href="style/main.css">

<link rel="stylesheet" href="style/navigation.css">

<link href='http://fonts.googleapis.com/css?family=Open+Sans:300italic,400italic,600italic,700italic,800italic,400,300,600,700,800' rel='stylesheet' type='text/css'>

</head>

<body>

<div class="wrapper">

<?php

if (isset($_SESSION['username'])) {

include('includes/aheader.php');

} else {

include('includes/header.php');

}

?>

<div class="plot">

<ul>

<a href="index.php"><li class="li_first">Home page</li></a>

<a href="goread.php"><li class="li_reg">What to read?</li></a>

<a href="quotes.php"><li class="li_reg">Quotes</li></a>

<a href="reviews.php"><li class="li_reg">Users' reviews</li></a>

<a href="toffers.php"><li class="li_reg">Trade offers</li></a>

<a href="news.php"><li class="li_last">Literature news</li></a>

</ul>

<br>

<?php

if ($_SESSION['rights'] > 0) {

$bookname = $_POST['bookname'];

$review = $_POST['review'];

$rating = $_POST['rating'];

$author = $_POST['author'];

if ($bookname != NULL && $review != NULL && $rating != NULL) {

$query = "INSERT INTO reviews (bookname, username, review, rating, author) VALUES ('$bookname', '$username', '$review', '$rating', '$author')";

$update_active = mysqli_query($connection, $query) or die(mysqli_error($connection));

echo "<p>You added review.</p>";

}

echo "<h2>Add your review!</h2>

<form action='addreview.php' id='litnews' method='POST' name='litnews'>

<p>Book name:</p>

<p><input class='input' id='bookname' name='bookname' size='110' type='text' placeholder='book name'></p>

<p>Author:</p>

<p><input class='input' id='author' name='author' size='110' type='text' placeholder='author'></p>

<p>Your review:</p>

<p><textarea class='input' id='review' name='review' cols='110' rows='20' placeholder='review'></textarea></p>

<p>Your mark:</p>

<p><input class='input' id='rating' name='rating' size='10' type='value' min='1' max='10'></p>

<p class='submit'><input class='button' id='admit' name='admit' type='submit' value='Add review!'></p></form>";

} else {

echo "<p>You haven't rights to use this page.</p>";

if ($_SESSION['username'] == NULL) {

echo "<p>You should register or log in to add your review.</p>";

}

}

?>

</div>

<?php include('includes/footer.php'); ?>

</div>

</body>

</html>

adminpanel.php

<?php

session_start();

require("includes/connect.php");

?>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">

<html>

<head>

<meta charset="utf-8" content="text/html">

<title>BookTrade | Adminpanel</title>

<link rel="SHORTCUT ICON" href="favicon.ico" type="image/x-icon">

<link rel="stylesheet" href="style/main.css">

<link rel="stylesheet" href="style/ubody.css">

<style type="text/css">

.button {

border: solid 1px #094b9c;

background: #3986c9;

color: #fff;

height: 30px;

width: 150px;

padding: 7px 12px;

cursor: pointer;

}

.button:hover {

background: #094b9c;

}

input {

background: #fbfbfb;

font-size: 12pt;

line-height: 1;

width: 300px;

padding: 3px;

padding-left: 10px;

margin: 0 6px 5px 0;

outline: none;

border-bottom: 1px solid #d9d9d9;

border-top: 0px;

border-left: 0px;

border-right: 0px;

}

</style>

<link href='http://fonts.googleapis.com/css?family=Open+Sans:300italic,400italic,600italic,700italic,800italic,400,300,600,700,800' rel='stylesheet' type='text/css'>


</head>

<body>

<div class='wrapper'>

<div class='plott'>

<?php

if ($_SESSION['rights'] == 2) {

$busername = $_POST['busername'];

if ($busername != NULL) {

$query = "UPDATE users SET rights='0' WHERE username='$busername'";

$update_active = mysqli_query($connection, $query) or die(mysqli_error($connection));

echo "<p>You banned $busername.</p>";

}

$unbusername = $_POST['unbusername'];

if ($unbusername != NULL) {

$query = "UPDATE users SET rights='1' WHERE username='$unbusername'";

$update_active = mysqli_query($connection, $query) or die(mysqli_error($connection));

echo "<p>You unbanned $unbusername.</p>";

}

$bookname = $_POST['bookname'];

$author = $_POST['author'];

$genre = $_POST['genre'];

if ($bookname != NULL && $author != NULL && $genre != NULL) {

$query = "INSERT INTO books (bookname, author, genre) VALUES ('$bookname', '$author', '$genre')";

$update_active = mysqli_query($connection, $query) or die(mysqli_error($connection));

echo "<p>You added book: $bookname by $author ($genre).</p>";

}

$bookid = $_POST['bookid'];

$ebookname = $_POST['ebookname'];

$eauthor = $_POST['eauthor'];

$egenre = $_POST['egenre'];

if ($bookid != NULL && $ebookname != NULL) {

$query_active = "UPDATE books SET bookname='$ebookname' WHERE book_id='$bookid'";

$update_active = mysqli_query($connection, $query_active) or die(mysqli_error($connection));

}

if ($bookid != NULL && $eauthor != NULL) {

$query_active = "UPDATE books SET author='$eauthor' WHERE book_id='$bookid'";

$update_active = mysqli_query($connection, $query_active) or die(mysqli_error($connection));

}

if ($bookid != NULL && $egenre != NULL) {

$query_active = "UPDATE books SET genre='$egenre' WHERE book_id='$bookid'";

$update_active = mysqli_query($connection, $query_active) or die(mysqli_error($connection));

}

$stitle = $_POST['stitle'];

$stext = $_POST['stext'];

$usr = $_SESSION['username'];

if ($stitle != NULL && $stext != NULL) {

$query = "INSERT INTO site_news (title, text, username) VALUES ('$stitle', '$stext', '$usr')";

$update_active = mysqli_query($connection, $query) or die(mysqli_error($connection));

echo "<p>You added site news: $stitle.</p>";

}

$ltitle = $_POST['ltitle'];

$lstext = $_POST['lstext'];

$ltext = $_POST['ltext'];

if ($ltitle != NULL && $lstext != NULL && $ltext != NULL) {

$query = "INSERT INTO lit_news (title, small_text, text, username) VALUES ('$ltitle', '$lstext', '$ltext', '$usr')";

$update_active = mysqli_query($connection, $query) or die(mysqli_error($connection));

echo "<p>You added site news: $ltitle.</p>";

}

$qtext = $_POST['qtext'];

$qbookname = $_POST['qbookname'];

if ($qtext != NULL && $qbookname != NULL) {

$query = "INSERT INTO quotes (bookname, quote_text) VALUES ('$qbookname', '$qtext')";

$update_active = mysqli_query($connection, $query) or die(mysqli_error($connection));

echo "<p>You added quote: $qtext.</p>";

}

echo "<p><a href='index.php'><- Back to home page</a></p>

<br>

<form action='adminpanel.php' id='ban_user' method='POST' name='ban_user'>

<p>Ban user:</p>

<p><input class='input' id='busername' name='busername' size='32' type='text' placeholder='username'></p>

<p class='submit'><input class='button' id='admit' name='admit' type='submit' value='Ban'></p></form>

<br>

<form action='adminpanel.php' id='unban_user' method='POST' name='unban_user'>

<p>Unban user:</p>

<p><input class='input' id='unbusername' name='unbusername' size='32' type='text' placeholder='username'></p>

<p class='submit'><input class='button' id='admit' name='admit' type='submit' value='Unban'></p></form>

<br>

<form action='adminpanel.php' id='addbook' method='POST' name='addbook'>

<p><a href='library.php'>Library (all added books)</a>.</p>


<p>Add book to library:</p>

<p><input class='input' id='bookname' name='bookname' size='50' type='text' placeholder='book'></p>

<p><input class='input' id='author' name='author' size='50' type='text' placeholder='author'></p>

<p><input class='input' id='genre' name='genre' size='50' type='text' placeholder='genres'></p>

<p class='submit'><input class='button' id='admit' name='admit' type='submit' value='Add book'></p></form>

<br>

<form action='adminpanel.php' id='editbook' method='POST' name='editbook'>

<p>Edit book from library:</p>

<p><input class='input' id='bookid' name='bookid' size='5' type='value' placeholder='book id'></p>

<p><input class='input' id='ebookname' name='ebookname' size='50' type='text' placeholder='book'></p>

<p><input class='input' id='eauthor' name='eauthor' size='50' type='text' placeholder='author'></p>

<p><input class='input' id='egenre' name='egenre' size='50' type='text' placeholder='genres'></p>

<p class='submit'><input class='button' id='admit' name='admit' type='submit' value='Edit book'></p></form>

<br>

<form action='adminpanel.php' id='sitenews' method='POST' name='sitenews'>

<p>Add site news:</p>

<p><input class='input' id='stitle' name='stitle' size='50' type='text' placeholder='title'></p>

<p><textarea class='input' id='stext' name='stext' cols='50' rows='5' placeholder='text'></textarea></p>

<p class='submit'><input class='button' id='admit' name='admit' type='submit' value='Add site news'></p></form>

<br>

<form action='adminpanel.php' id='litnews' method='POST' name='litnews'>

<p>Add literature news:</p>

<p><input class='input' id='ltitle' name='ltitle' size='50' type='text' placeholder='title'></p>

<p><input class='input' id='lstext' name='lstext' size='50' type='text' placeholder='small text'></p>

<p><textarea class='input' id='ltext' name='ltext' cols='50' rows='5' placeholder='main text'></textarea></p>

<p class='submit'><input class='button' id='admit' name='admit' type='submit' value='Add lit news'></p></form>

<br>

<form action='adminpanel.php' id='quotes' method='POST' name='quotes'>

<p>Add quote (don't forget add book to the library!):</p>

<p><input class='input' id='qbookname' name='qbookname' size='50' type='text' placeholder='bookname'></p>

<p><textarea class='input' id='qtext' name='qtext' cols='50' rows='5' placeholder='quote'></textarea></p>

<p class='submit'><input class='button' id='admit' name='admit' type='submit' value='Add quote'></p></form>

";

} else {

echo "You haven't rights to use this page.";

}

?>

</div>

</div>

</body>

</html>

editnews.php

<?php

session_start();

require('includes/connect.php');

$id = $_GET['id'];

?>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">

<html>

<head>

<meta charset="utf-8" content="text/html">

<title>BookTrade | Literature news</title>

<link rel="SHORTCUT ICON" href="favicon.ico" type="image/x-icon">

<link rel="stylesheet" href="style/main.css">

<link rel="stylesheet" href="style/navigation.css">

<link href='http://fonts.googleapis.com/css?family=Open+Sans:300italic,400italic,600italic,700italic,800italic,400,300,600,700,800' rel='stylesheet' type='text/css'>

</head>

<body>

<div class="wrapper">

<?php

if (isset($_SESSION['username'])) {

include('includes/aheader.php');

} else {

include('includes/header.php');

}

?>

<div class="plot">

<ul>

<a href="index.php"><li class="li_first">Home page</li></a>