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

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

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

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

Добавлен: 25.04.2023

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

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

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

$query = "SELECT author FROM `books` WHERE bookname='$bookname'";

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

do {

$author = $myrow['author'];

} while ($myrow = mysqli_fetch_array($result));

?>

<h1>«<?php echo "$text"; ?>»</h1>

<h3>«<?php echo "$bookname"; ?>» by <?php echo "$author"; ?></h3>

<br>

<h3><a href="quotes.php">Get another quote!</a></h3>

</div>

</body>

</html>

read_mes.php

<?php

session_start();

require('includes/connect.php');

$u_name = $_SESSION['username'];

$id_mess=(int)$_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 | <?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">

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

<p><a href="messages.php"><- Back to messages list</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 = :u_to and m_id = :id_mess";

$sth=$db->prepare($sql);

$sth->bindParam(':u_to',$u_name,PDO::PARAM_STR);

$sth->bindParam(':id_mess',$id_mess,PDO::PARAM_INT);

$sth->execute();

$res=$sth->fetch(PDO::FETCH_ASSOC);

$sql="update messages set flag = 1 where u_to = :u_to and m_id = :id_mess";

$sth=$db->prepare($sql);

$sth->bindParam(':u_to',$u_name,PDO::PARAM_STR);

$sth->bindParam(':id_mess',$id_mess,PDO::PARAM_INT);

$sth->execute();

if($res['m_id']<>''){

echo '<p>Sent by: '.$res['u_from'].'</p>';

echo '<div>'.$res['message'].'</div>Date: '.$res['data'];

echo '<p><a href="pm.php?name='.$res['u_from'].'">Answer</a></p>';

}else{

echo "Message doesn't exist or was sent to another user.";

}

?>

</div>

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

</div>

</body>

</html>

register.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 | Registration</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 mregister">

<div id="login">

<h1>Registration</h1>

<?php

require('includes/connect.php');

if (isset($_POST['username']) && isset($_POST['password'])) {

$username = $_POST['username'];

$email = $_POST['email'];

$password = $_POST['password'];

$query = "INSERT INTO users (username, email, password, rights) VALUES ('$username', '$email', '$password', 1)";

$result = mysqli_query($connection, $query);

if ($result) {

$fullname = $_POST['fullname'];

$age = $_POST['age'];

$location = $_POST['location'];

$userinfo = $_POST['userinfo'];


$active_date = time();

$query_all = "INSERT INTO user_info (username, fullname, age, location, userinfo, active_date) VALUES ('$username', '$fullname', '$age', '$location', '$userinfo', '$active_date')";

$result_all = mysqli_query($connection, $query_all);

$smsg = "Account successfully created";

echo "<a href='login.php' align=center>Log in</a><br><a href='index.php' align=center>Home page</a>";

} else {

$fsmsg = "Account with that name already created.";

}

}

if(isset($smsg)) { ?><div class="alert" role="alert"> <?php echo $smsg; ?> </div> <?php }

if(isset($fsmsg)) { ?><div class="alert" role="alert"> <?php echo $fsmsg; ?> </div> <?php }

?>

<form action="register.php" id="registerform" method="POST" name="registerform">

<p><label for="user_login">Login*:<br>

<input class="input" id="username" name="username" size="32" type="text" placeholder="username" required></label></p>

<p><label for="user_email">E-mail*:<br>

<input class="input" id="email" name="email" size="32" type="email" placeholder="e-mail" required></label></p>

<p><label for="user_pass">Password*:<br>

<input class="input" id="password" name="password" size="32" type="password" placeholder="password" required></label></p>

<p><label for="user_name">Full name:<br>

<input class="input" id="fullname" name="fullname" size="32" type="text" placeholder="full name"></label></p>

<p><label for="user_age">Age:<br>

<input class="input" id="age" name="age" size="32" type="number" min="1" max="130" step="1" placeholder="age"></label></p>

<p><label for="user_location">Location:<br>

<input class="input" id="location" name="location" size="32" type="text" placeholder="location"></label></p>

<p><label for="user_info">Personal info:<br>

<textarea class="input" id="userinfo" name="userinfo" cols="32" rows="5" placeholder="about"></textarea></label></p>

<p class="submit"><input class="button" id="register" name="register" type="submit" value="Register"></p>

<p class="regtext">Have an account? <a href="login.php">Log in</a>!</p>

</form>

</div>

</div>

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

</body>

</html>

reviews.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 | Reviews</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) {

echo "<p align='center'><a href='addreview.php'>Add your review!</a></p><br>";


}

echo "<table align=center border=0px><tr><td><img src='graphics/reviews.png' width=400px></tr></td></table>";

$query = "SELECT * FROM `reviews` ORDER BY RAND() LIMIT 10";

$result = mysqli_query($connection, $query) or die;

if($result) {

$rows = mysqli_num_rows($result);

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

$row = mysqli_fetch_row($result);

$id = $row[0];

echo "<h4>«$row[1]» by $row[2]</h4>";

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

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

echo "<p align=right>$row[5]/10</p>";

echo "<h5 align='right'>$row[6]</h5>";

$author = $row[3];

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

echo "<p align=center><a href='editreview.php?id=$id'>Edit review</a></p>";

}

echo "<hr>";

}

}

?>

</div>

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

</div>

</body>

</html>

toffers.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 | Trade offers</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) {

echo "<p align='center'><a href='addbook.php'>Add your trade offer!</a></p><br>";

}

echo "<table align=center border=0px><tr><td><img src='graphics/trade.png' width=300px></tr></td></table>";

$query = ('SELECT username, bookname, author, trade_info, date FROM (SELECT * FROM w_trade ORDER BY item_id DESC LIMIT 100) AS T ORDER BY item_id ASC');

$result = mysqli_query($connection, $query) or die;

if($result) {

$rows = mysqli_num_rows($result);

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

$row = mysqli_fetch_row($result);

$id = $row[0];

echo "<h4>«$row[1]» by $row[2]</h4>";

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

echo "<h5 align='right'>$row[4]</h5>";

echo "<h5 align='center'><a href='pm.php?name=$row[0]'>Send mail to $row[0]</a></h5><hr>";

}

}

?>

</div>

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

</div>

</body>

</html>

user.php

<?php

session_start();

require('includes/connect.php');

$username = $_GET['name'];

if ($username == NULL) {

$username = $_SESSION['username'];

}

$id = $_SESSION['id'];

$query = "SELECT * FROM `user_info` WHERE username='$username'";

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


do {

$fullname = $myrow['fullname'];

$age = $myrow['age'];

$location = $myrow['location'];

$userinfo = $myrow['userinfo'];

$active = $myrow['active'];

} while ($myrow = mysqli_fetch_array($result));

?>

<!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

echo "<p>ID: $id</p>

<p>Username: $username</p>

<p>Full name: $fullname</p>

<p>Age: $age</p>

<p>From $location</p>

<p>$userinfo</p>";

if ($active == 1) {

echo "<p>User is online</p>";

} else {

echo "<p>User is offline</p>";

}

if ($_GET['name'] != $_SESSION['username']) {

echo "<p><a href='pm.php?name=$username'>Private mail</a></p>";

}

if ($_GET['name'] == $_SESSION['username'] && $_SESSION['rights'] != 0) {

echo "<p><a href='addbook.php'>Add book to readed, wanted or trade offers</a></p>";

}

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

echo "<p><a href='useredit.php'>Edit profile</a></p>";

}

echo "<h3 align='center'>$username's trade offers:</h3>";

$query_trade = "SELECT * FROM `w_trade` WHERE username='$username'";

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

if(isset($result_trade)) {

$rows = mysqli_num_rows($result_trade);

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

$row = mysqli_fetch_row($result_trade);

echo "<h4>«$row[2]» by $row[3]</h4><p>$row[4]</p>";

echo "<h5 align='right'>$row[5]</h5>";

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

echo "<h5 align=center><a href='includes/delete.php?id=$row[0]'>Remove an offer</a></h5>";

}

}

}

echo "<hr><h3 align='center'>$username's wanted books:</h3>";

$query_wanted = "SELECT * FROM `w_read` WHERE username='$username'";

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

if(isset($result_wanted)) {

$rows = mysqli_num_rows($result_wanted);

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

$row = mysqli_fetch_row($result_wanted);

if ($row[0] != NULL) {

echo "<h4>«$row[2]» by $row[3]</h4>";

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

echo "<h5 align=center><a href='includes/deletew.php?id=$row[0]'>Remove a wanted book</a></h5>";

}

}

}

}

echo "<hr><h3 align='center'>$username's readed books:</h3>";

$query_readed = "SELECT * FROM `readed` WHERE username='$username'";

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

if(isset($result_readed)) {

$rows = mysqli_num_rows($result_readed);

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

$row = mysqli_fetch_row($result_readed);

if ($row[0] != NULL) {

echo "<h4>«$row[2]» by $row[3]</h4>";

}

}

}

echo "<hr><h3 align='center'>$username's reviews:</h3>";

$query_reviews = "SELECT * FROM `reviews`";

$result_reviews = mysqli_query($connection, $query_reviews) or die(mysqli_error($connection));

if(isset($result_reviews)) {

$rows = mysqli_num_rows($result);

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


$row = mysqli_fetch_row($result_reviews);

if ($row[0] != NULL) {

echo "<h4>«$row[1]» by $row[2]</h4>";

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

echo "<p align='right'>$row[5]/10</p>";

echo "<h5 align='right'>$row[6]</h5>";

$author = $row[3];

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

echo "<p align=center><a href='editreview.php?id=$id'>Edit review</a></p>";

}

} else {

echo "<p>$username didn't add anything to this section yet.</p>";

break;

}

}

}

?>

</div>

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

</div>

</body>

</html>

useredit.php

<?php

session_start();

require('includes/connect.php');

$username = $_SESSION['username'];

$id = $_SESSION['id'];

$query = "SELECT * FROM `user_info` WHERE username='$username'";

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

do {

$fullname = $myrow['fullname'];

$age = $myrow['age'];

$location = $myrow['location'];

$userinfo = $myrow['userinfo'];

} while ($myrow = mysqli_fetch_array($result));

$cfullname = $_POST['fullname'];

$cage = $_POST['age'];

$clocation = $_POST['location'];

$cuserinfo = $_POST['userinfo'];

if ($cfullname != NULL) {

$query_active = "UPDATE user_info SET fullname='$cfullname' WHERE username='$username'";

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

}

if ($cage != NULL) {

$query_active = "UPDATE user_info SET age='$cage' WHERE username='$username'";

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

}

if ($clocation != NULL) {

$query_active = "UPDATE user_info SET location='$clocation' WHERE username='$username'";

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

}

if ($cuserinfo != NULL) {

$query_active = "UPDATE user_info SET userinfo='$cuserinfo' WHERE username='$username'";

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

}

?>

<!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/uedit.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">

<?php

echo "<p>ID: $id</p>

<p>$username</p>

<form action='useredit.php' id='editform' method='POST' name='editform'>

<p>Изменить отображаемое имя:</p>

<p><input class='input' id='fullname' name='fullname' size='32' type='text' placeholder='$fullname'></p>

<p>Возраст:</p>

<p><input class='input' id='age' name='age' size='32' type='number' min='1' max='130' step='1' placeholder='$age'></p>

<p>Место жительства:</p>

<p><input class='input' id='location' name='location' size='32' type='text' placeholder='$location'></p>

<p>Информация о Вас:</p>

<p><textarea class='input' id='userinfo' name='userinfo' cols='50' rows='5' placeholder='$userinfo'></textarea></p>";

?>

<p class="submit"><input class="button" id="admit" name="admit" type="submit" value="OK"></p>

</form>

<p><a href="index.php"><- Back to user page</a></p>