Файл: Разработка WEB-ресурса по обмену книгами «BookTrade.org».pdf
Добавлен: 25.04.2023
Просмотров: 320
Скачиваний: 2
<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
$query = ("SELECT title, small_text, text, username FROM lit_news WHERE new_id='$id'");
$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);
$title = $row[0];
$stext = $row[1];
$text = $row[2];
$author = $row[3];
}
}
if ($_SESSION['username'] == $author || $_SESSION['rights'] == 2) {
echo "<form action='editnews.php?id=$id' id='editnews' method='POST' name='editnews'>
<p>Add literature news:</p>
<p><input class='input' id='title' name='title' size='110' type='text' value='$title'></p>
<p><input class='input' id='stext' name='stext' size='110' type='text' value='$stext'></p>
<p><textarea class='input' id='text' name='text' cols='120' rows='20'>$text</textarea></p><br>
<p class='submit'><input class='button' id='admit' name='admit' type='submit' value='Edit'></p></form>";
$title = $_POST['title'];
$stext = $_POST['stext'];
$text = $_POST['text'];
if ($title != NULL && $stext != NULL && $text != NULL) {
$query_active = "UPDATE lit_news SET title='$title', small_text='$stext', text='$text' WHERE new_id='$id'";
$update_active = mysqli_query($connection, $query_active) or die(mysqli_error($connection));
echo "<p>Text was updated. <a href='litnews.php?id=$id'>Go back?</a></p>";
}
}
?>
</div>
<?php include('includes/footer.php'); ?>
</div>
</body>
</html>
editreview.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>
<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
$query = ("SELECT bookname, review, rating, username FROM reviews WHERE review_id='$id'");
$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);
$bookname = $row[0];
$review = $row[1];
$rating = $row[2];
$author = $row[3];
}
}
if ($_SESSION['username'] == $author || $_SESSION['rights'] == 2) {
echo "<form action='editreview.php?id=$id' id='editnews' method='POST' name='editreview'>
<p>Edit review:</p>
<p>$bookname</p>
<p><textarea class='input' id='review' name='review' cols='110' rows='20'>$review</textarea></p>
<p><input class='input' id='rating' name='rating' size='10' type='value' min='1' max='10' value='$rating'></p><br>
<p class='submit'><input class='button' id='admit' name='admit' type='submit' value='Edit'></p></form>";
$review = $_POST['review'];
$rating = $_POST['rating'];
if ($review != NULL && $rating != NULL) {
$query_active = "UPDATE reviews SET review='$review', rating='$rating' WHERE review_id='$id'";
$update_active = mysqli_query($connection, $query_active) or die(mysqli_error($connection));
echo "<p>Text was updated. <a href='reviews.php'>Go back?</a></p>";
}
}
?>
</div>
<?php include('includes/footer.php'); ?>
</div>
</body>
</html>
goread.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 | Go read!</title>
<link rel="stylesheet" href="style/goread.css">
<link rel="SHORTCUT ICON" href="favicon.ico" type="image/x-icon">
<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>
<p><a href="index.php"><- Back to home page</a></p>
<div class="wrapper">
<?php
$query = "SELECT * FROM `books` ORDER BY RAND()";
$result = mysqli_query($connection, $query) or die(mysqli_error($connection));
do {
$bookname = $myrow['bookname'];
$author = $myrow['author'];
$genre = $myrow['genre'];
} while ($myrow = mysqli_fetch_array($result));
?>
<h2>I think you should read...</h2>
<h1>«<?php echo "$bookname"; ?>»</h1>
<h3>by <?php echo "$author"; ?></h3>
<h3>Genres: <?php echo "$genre"; ?></h3>
<br>
<h3><a href="goread.php">Get another book!</a></h3>
</div>
</body>
</html>
library.php
<?php
session_start();
require('includes/connect.php');
?>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" content="text/html">
<title>library</title>
<link rel="SHORTCUT ICON" href="favicon.ico" type="image/x-icon">
</head>
<body>
<p><a href="adminpanel.php"><- Back to admin panel</a></p>
<?php
if ($_SESSION['rights'] == 2) {
$query = "SELECT * FROM books";
$result = mysqli_query($connection, $query) or die("Ошибка " . mysqli_error($connection));
if($result) {
$rows = mysqli_num_rows($result);
echo "<table border=1><tr><th> id </th><th> Book name </th><th> Author </th><th> Genres </th></tr>";
for ($i = 0 ; $i < $rows ; ++$i) {
$row = mysqli_fetch_row($result);
echo "<tr>";
for ($j = 0 ; $j < 4 ; ++$j) echo "<td>$row[$j]</td>";
echo "</tr>";
}
echo "</table>";
}
} else {
echo "You haven't rights to use this page.";
}
?>
</body>
</html>
litnews.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>
<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
$query = ("SELECT title, text, username, date FROM lit_news WHERE new_id='$id'");
$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 "<h2>$row[0]</h2>";
echo "<h5>$row[3]</h5>";
echo "<br>";
echo "<p>$row[1]</p><br>";
$author = $row[2];
}
}
if ($_SESSION['username'] == $author || $_SESSION['rights'] == 2) {
echo "<p><a href='editnews.php?id=$id'>Edit text</a></p>";
}
?>
</div>
<?php include('includes/footer.php'); ?>
</div>
</body>
</html>
login.php
<?php
session_start();
require('includes/connect.php');
if (isset($_SESSION['username'])) {
header('Location: index.php');
exit;
}
if (isset($_POST['username']) && isset($_POST['password'])) {
$username = $_POST['username'];
$password = $_POST['password'];
$query = "SELECT * FROM users WHERE username='$username' and password='$password'";
$result = mysqli_query($connection, $query) or die(mysqli_error($connection));
$count = mysqli_num_rows($result);
if ($count == 1) {
$_SESSION['username'] = $username;
$query_active = "UPDATE user_info SET active=1 WHERE username='$username'";
$update_active = mysqli_query($connection, $query_active);
$query = "SELECT * FROM `users` WHERE username='$username'";
$result = mysqli_query($connection, $query, $select_db) or die(mysqli_error($connection));
do{
$_SESSION['id'] = $myrow['id'];
$_SESSION['rights'] = $myrow['rights'];
}while ($myrow = mysqli_fetch_array($result));
header('Location: index.php');
exit;
} else {
$fmsg = "Incorrect login or password. Try again.";
}
}
?>
<!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 | Log in!</title>
<link rel="SHORTCUT ICON" href="favicon.ico" type="image/x-icon">
<link rel="stylesheet" href="style/loginform.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="container mlogin">
<div id="login">
<h1>Log in</h1>
<?php
echo $fmsg;
?>
<form action="" id="loginform" method="post" name="loginform">
<p><label for="user_login">Login:<br>
<input class="input" id="username" name="username" size="20" type="text" value=""></label></p>
<p><label for="user_pass">Password:<br>
<input class="input" id="password" name="password" size="20" type="password" value=""></label></p>
<p class="submit"><input class="button" name="login" type= "submit" value="Log in"></p>
<p class="regtext">Haven't an account yet? <a href= "register.php">Create an account</a>!</p>
</form>
</div>
</div>
<?php include('includes/footer.php'); ?>
</body>
</html>
messages.php
<?php
session_start();
require('includes/connect.php');
$u_name = $_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 | <?php echo $_SESSION['username']; ?></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>
<div class="wrapper">
<div class="plott">
<p><a href="index.php"><- Back to home page</a></p>
<?php
$db_user = 'root';
$db_name = 'booktrade.org';
$db_pass = '';
$db = new PDO('mysql:dbname='.$db_name.'; host=localhost',$db_user,$db_pass);
$db->exec("SET CHARACTER SET utf8");
$sql="select * from messages where u_to=? order by m_id desc";
$sth=$db->prepare($sql);
$sth->bindParam(1,$u_name,PDO::PARAM_INT);
$sth->execute();
$res=$sth->fetchAll(PDO::FETCH_ASSOC);
foreach ($res as $row){
echo '<p>Message No '.$row['m_id'].' From: '.$row['u_from'].' To: '.$row['u_to'].' <a href="read_mes.php?id='.$row['m_id'].'">Open</a>';
if ($row['flag'] != 0) {
echo ' Readed</p>';
} else {
echo " Unread</p>";
}
}
?>
</div>
<?php include('includes/footer.php'); ?>
</div>
</body>
</html>
news.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
echo "<table align=center border=0px><tr><td><img src='graphics/news.png' width=300px></tr></td></table>";
$query = ('SELECT new_id, title, small_text, date FROM (SELECT * FROM lit_news ORDER BY new_id DESC LIMIT 20) AS T ORDER BY new_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 "<a href='litnews.php?id=$row[0]'><h3>$row[1]</h3></a>";
echo "<h5>$row[3]</h5>";
echo "<p>$row[2]</p>";
echo "<hr><br>";
}
}
?>
</div>
<?php include('includes/footer.php'); ?>
</div>
</body>
</html>
pm.php
<?php
session_start();
require('includes/connect.php');
$to_usr = $_GET['name'];
$from_usr = $_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 | <?php echo $username; ?></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>
<div class="wrapper">
<div class="plott">
<a href="index.php"><- Back to home page</a>
<?php
if ($_SESSION['username'] != NULL && $_SESSION['rights'] > 0) {
echo "<form action='pm.php' method='post' enctype='multipart/form-data'>
<p>Send to:</p>
<p><input name='to_usr' id='to_usr' value='$to_usr' size='90'></p>
<p>Message text:</p>
<p><textarea name='message' rows='10' cols='91'></textarea></p>
<p><input type='submit' value='Send'></p>
</form>";
$message = htmlspecialchars($_POST['message']);
$to = $_POST['to_usr'];
$db_user='root';
$db_name='booktrade.org';
$db_pass='';
$db = new PDO('mysql:dbname='.$db_name.'; host=localhost',$db_user,$db_pass);
$db->exec("SET CHARACTER SET utf8");
$sql="insert into messages (u_from,u_to,message,flag) values
(:u_from,:u_to,:message,:flag)";
$sth=$db->prepare($sql);
$sth->bindValue(':u_from', $from_usr);
$sth->bindValue(':u_to', $to);
$sth->bindValue(':message', $message);
$sth->bindValue(':flag', 0);
$sth->execute();
$error=$sth->errorInfo();
if($error[0]==0){
echo '<p>Message succesfully sent. Go to <a href="messages.php">your messages</a>.</p>';
}
}
?>
</div>
<?php include('includes/footer.php'); ?>
</div>
</body>
quotes.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 | Quote!</title>
<link rel="stylesheet" href="style/goread.css">
<link rel="SHORTCUT ICON" href="favicon.ico" type="image/x-icon">
<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>
<p><a href="index.php"><- Back to home page</a></p>
<div class="wrapper">
<?php
$query = "SELECT * FROM `quotes` ORDER BY RAND()";
$result = mysqli_query($connection, $query) or die(mysqli_error($connection));
do {
$bookname = $myrow['bookname'];
$text = $myrow['quote_text'];
} while ($myrow = mysqli_fetch_array($result));