Добавлен: 28.03.2023
Просмотров: 261
Скачиваний: 2
$rows = mysqli_num_rows($resultNext);
for ($i = 0; $i < $rows ; ++$i) {
$row = mysqli_fetch_row($resultNext);
echo '<div class="newsblock"><p><span class="eventDate"><i>'.$row[1].'</i></span></p>';
echo '<h3>'.$row[2].'</h3>';
echo '<p>'.$row[3].'</p>';
if ($row[4] != NULL) {
echo '<p><a href="'.$row[4].'">Подробнее</a></p></div>';
} else {
echo '</div>';
}
}
}
$resultPast = mysqli_query($connection, "SELECT * FROM `events` WHERE `date` < date(now()) ORDER BY `events`.`date` DESC LIMIT 5");
if ($resultPast) {
echo '<h2>Прошедшие события</h2>';
$rows = mysqli_num_rows($resultPast);
for ($i = 0; $i < $rows ; ++$i) {
$row = mysqli_fetch_row($resultPast);
echo '<div class="newsblock"><p class="eventDate"><i>'.$row[1].'</i></p>';
echo '<h3>'.$row[2].'</h3>';
echo '<p>'.$row[3].'</p>';
if ($row[4] != NULL) {
echo '<p><a href="'.$row[4].'">Подробнее</a></p></div>';
} else {
echo '</div>';
}
}
}
?>
</section>
<section id="contacts">
<address>
<h2>Связаться с нами можно по адресу:</h2>
<p>город Москва<br>Нагорный проезд<br>дом 10, корпус 2, строение 3</p>
<h3>Мы работаем всю неделю с 9:00 до 22:00. Приходите!</h3>
<h2>Или по следующим контактам:</h2>
<p><a href="mailto:info@mylibrary.org">info@MyLibrary.org</a><br>
<a href="tel:89999999999">8 (999) 999 99-99</a></p>
<h2><a href="contacts.php">Также Вы можете воспользоваться контактной формой, перейдя по этой ссылке</a></h2>
</address>
<script type="text/javascript" charset="utf-8" async src="https://api-maps.yandex.ru/services/constructor/1.0/js/?um=constructor%3A24a21c1662170c20530fb363ccf8ceae4e07d91f572efd8105c6f4bf2b761f28&width=1000&height=300&lang=ru_RU&scroll=true"></script>
</section>
<?php require('./includes/footer.html'); ?>
</body>
</html>
Login.php
<?php
require('./includes/connection.php');
if (isset($_SESSION['role'])) {
header('Location: ./user.php');
exit;
}
if (isset($_POST['login']) && isset($_POST['password'])) {
$login = $_POST['login'];
$password = $_POST['password'];
$query = "SELECT * FROM users WHERE login='$login' and password='$password'";
$result = mysqli_query($connection, $query) or die(mysqli_error($connection));
$count = mysqli_num_rows($result);
if ($count == 1) {
$query = "SELECT * FROM `users` WHERE login='$login'";
$result = mysqli_query($connection, $query, $select_db) or die(mysqli_error($connection));
do {
$_SESSION['login'] = $myrow['login'];
$_SESSION['id'] = $myrow['id'];
$_SESSION['role'] = $myrow['role'];
if (isset($myrow['name'])) {
$_SESSION['name'] = $myrow['name'];
}
} while ($myrow = mysqli_fetch_array($result));
header('Location: ./index.php');
exit;
} else {
$fmsg = "Некорректный пароль или логин. Попробуйте еще раз.";
}
}
?>
<!DOCTYPE HTML>
<html>
<head>
<?php require('./includes/head.html'); ?>
<title>Войти в личный кабинет</title>
<link rel="stylesheet" href="css/login.css">
</head>
<body>
<section id="loginform">
<div class="loginform">
<h1>Войти</h1>
<?php
if (isset($fmsg)) {
echo $fmsg;
}
?>
<form action="" method="post" name="loginform">
<p><label for="user_login">Логин:<br>
<input class="input" name="login" size="20" type="text" value="" required></label></p>
<p><label for="user_pass">Пароль:<br>
<input class="input" name="password" size="20" type="password" value="" required></label></p>
<p class="submit"><input class="button" name="enter" type= "submit" value="Войти"></p>
</form>
</div>
</section>
<?php require('./includes/footer.html'); ?>
</body>
</html>
Register.php
<?php
require('./includes/connection.php');
if (isset($_SESSION['role'])) {
header('Location: ./user.php');
exit;
}
?>
<!DOCTYPE HTML>
<html>
<head>
<?php require('./includes/head.html'); ?>
<title>Зарегистрироваться</title>
<link rel="stylesheet" href="css/login.css">
</head>
<body>
<section id="loginform">
<div class="loginform">
<h1>Зарегистрироваться</h1>
<?php
if (isset($_POST['addlogin'])) {
$addlogin = $_POST['addlogin'];
$addpassword = $_POST['addpassword'];
$addemail = $_POST['addemail'];
$addnumber = $_POST['addnumber'];
$addname = $_POST['addname'];
$addbirthday = $_POST['addbirthday'];
$checkloginq = mysqli_query($connection, "SELECT `login` FROM users WHERE `login`='$addlogin'");
$checklogin = mysqli_num_rows($checkloginq);
if ($checklogin == 0) {
$adduser = mysqli_query($connection, "INSERT INTO users (`login`,`password`,`email`,`number`,`name`,`birthday`,`edited`,`role`,`registered`)
VALUES ('$addlogin','$addpassword','$addemail','$addnumber','$addname','$addbirthday',0,'user',date(now()))");
header('Location: ./index.php');
} else {
echo '<p><b><i>Невозможно добавить пользователя: такой логин уже существует.</p></b></i>';
}
}
echo '<form action="register.php" method="post">
<p>Логин*: <input name="addlogin" type="text" size="20" required></p>
<p>Пароль*: <input name="addpassword" type="text" size="20" required></p>
<p>Имя: <input name="addname" type="text" size="20"></p>
<p>E-mail*: <input name="addemail" type="text" size="20" required></p>
<p>Номер телефона: <input name="addnumber" type="text" size="20"></p>
<p>Дата рождения в формате месяц/день/год: <input name="addbirthday" type="date"></p>
<p><input type="submit" value="Зарегистрироваться"></p>
</form>';
?>
</div>
</section>
<?php require('./includes/footer.html'); ?>
</body>
</html>
News.php
<?php require('./includes/connection.php'); ?>
<!DOCTYPE HTML>
<html>
<head>
<?php require('./includes/head.html'); ?>
<title>Моя библиотека | Новости</title>
<link rel="stylesheet" href="css/news.css">
</head>
<body>
<?php require('./includes/header.html'); ?>
<div class="news">
<?php
require('./includes/welcome.php');
$result = mysqli_query($connection, "SELECT * FROM `events`ORDER BY `events`.`date`");
if ($result) {
$rows = mysqli_num_rows($result);
for ($i = 0; $i < $rows ; ++$i) {
$row = mysqli_fetch_row($result);
echo '<div class="container"><p class="eventDate"><i>'.$row[1].'</i></p>';
if (isset($_SESSION['role'])) {
if ($_SESSION['role'] == 'librarian') {
echo '<h5>ID: '.$row[0].'</h5>';
}
}
echo '<h2>'.$row[2].'</h2>';
echo '<p>'.$row[3].'</p>';
if ($row[4] != NULL) {
echo '<p><a href="'.$row[4].'">Подробнее</a></p></div>';
} else {
echo '</div>';
}
}
}
echo '</div>';
require('./includes/footer.html');
?>
</body>
</html>
Books.php
<?php
require('./includes/connection.php');
?>
<!DOCTYPE HTML>
<html>
<head>
<?php require('./includes/head.html'); ?>
<title>Моя библиотека | Книги</title>
</head>
<body>
<?php require('./includes/header.html'); ?>
<?php
require('./includes/welcome.php');
?>
<form method="get">
<p><select name="type">
<option value="none" hidden="">Выберите жанр книги</option>
<option value="Художественная литература">Художественная литература</option>
<option value="Документальная проза">Документальная проза</option>
<option value="Мемуары">Мемуары</option>
<option value="Научная литература">Научная литература</option>
<option value="Научно-популярная литература">Научно-популярная литература</option>
<option value="Справочная литература">Справочная литература</option>
<option value="Учебная литература">Учебная литература</option>
<option value="Техническая литература">Техническая литература</option>
<option value="Психология и саморазвитие">Психология и саморазвитие</option>
</select></p>
<p><select name="status">
<option value="none" hidden="">Выберите статус книги</option>
<option value="В наличии">В наличии</option>
<option value="Забронирована">Забронирована</option>
<option value="Выдана">Выдана</option>
<option value="Только для чтения в зале">Только для чтения в зале</option>
</select></p>
<p><input type="submit" value="Отправить"></p>
</form>
<?php
if (isset($_GET['type'])) {
if ($_GET['type'] != 'none' && $_GET['status'] == 'none') {
$type = $_GET['type'];
$result = mysqli_query($connection, "SELECT * FROM `list` WHERE `type` = '$type'");
} else if ($_GET['type'] == 'none' && $_GET['status'] != 'none') {
$status = $_GET['status'];
$result = mysqli_query($connection, "SELECT * FROM `list` WHERE `status` = '$status'");
} else if ($_GET['type'] != 'none' && $_GET['status'] != 'none') {
$type = $_GET['type'];
$status = $_GET['status'];
$result = mysqli_query($connection, "SELECT * FROM `list` WHERE `type` = '$type' AND `status` = '$status'");
} else {
$result = mysqli_query($connection, "SELECT * FROM `list`");
}
} else {
$result = mysqli_query($connection, "SELECT * FROM `list`");
}
if ($result) {
$rows = mysqli_num_rows($result);
echo '<table border=1 width="100%"><tr><thead><th> id </th><th> Жанр </th><th> Название </th><th> Автор </th><th> Язык </th><th> Издание </th><th> Статус </th></thead></tr>';
for ($i = 0 ; $i < $rows ; ++$i) {
$row = mysqli_fetch_row($result);
echo "<tr>";
for ($j = 0 ; $j < 6 ; ++$j) echo "<td>$row[$j]</td>";
echo '<td>'.$row[6];
if (isset($_SESSION['login']) && $row[6] == 'В наличии') {
echo ' (<a href="add.php?id='.$row[0].'">забронировать</a>)</td>';
} else {
echo '</td>';
}
if (isset($_SESSION['role'])) {
if ($_SESSION['role'] == 'librarian') {
echo '<td><a href="bookinfo.php?id='.$row[0].'">Посмотреть информацию о передвижении книги</a></td>';
}
}
echo "</tr>";
}
echo "</table>";
}
require('./includes/footer.html');
?>
</body>
</html>
Bookinfo.php
<?php
require('./includes/connection.php');
if (isset($_SESSION['role'])) {
if ($_SESSION['role'] == 'user') {
header('Location: ./books.php');
exit;
}
} else {
header('Location: ./books.php');
exit;
}
?>
<!DOCTYPE HTML>
<head>
<?php require('./includes/head.html'); ?>
<title>Подробная информация о книге</title>
</head>
<a href="books.php">К списку книг</a>
<form method='get'>
<p><label for='search'>Введите ID книги:
<input type='number' name='id' value=''></label></p>
<p><input type='submit' value='Отправить'></p>
</form>
<?php
if (isset($_GET['id'])) {
$bid = $_GET['id'];
if ($bid == NULL) {
$list = mysqli_query($connection, "SELECT * FROM readlists ORDER BY `status` ASC");
} else {
$list = mysqli_query($connection, "SELECT * FROM readlists WHERE `bid`='$bid' ORDER BY `status` ASC");
}
} else {
$list = mysqli_query($connection, "SELECT * FROM readlists ORDER BY `status` ASC");
}
if ($list) {
$rows = mysqli_num_rows($list);
echo '<table border=1><tr><thead><th> id </th><th> ID читателя </th><th>Логин читателя</th><th>Имя читателя</th><th> ID книги </th><th>Название книги</th><th>Автор книги</th><th> Статус </th><th> Дата </th></thead></tr>';
for ($i = 0 ; $i < $rows ; ++$i) {
$row = mysqli_fetch_row($list);
echo '<tr>';
echo '<td>'.$row[0].'</td>';
echo '<td><a href="user.php?id='.$row[1].'">'.$row[1].'</td>';
$user = mysqli_query($connection, "SELECT `login`,`name` FROM users WHERE `id`='$row[1]'");
$userinfo = mysqli_fetch_array($user);
echo '<td><a href="user.php?id='.$row[1].'">'.$userinfo[0].'</td>';
echo '<td><a href="user.php?id='.$row[1].'">'.$userinfo[1].'</td>';
echo '</a>';
echo '<td>'.$row[2].'</td>';
$book = mysqli_query($connection, "SELECT `title`,`author` FROM list WHERE `id`='$row[2]'");
$bookinfo = mysqli_fetch_array($book);
echo '<td>'.$bookinfo[0].'</td>';
echo '<td>'.$bookinfo[1].'</td>';
echo '<td>'.$row[3].'</td>';
echo '<td>'.$row[4].'</td>';
echo '</tr>';
}
echo '</table>';
}
require('./includes/footer.html');
?>
Contacts.php
<?php
require('./includes/connection.php');
?>
<!DOCTYPE HTML>
<html>
<head>
<?php require('./includes/head.html'); ?>
<title>Моя библиотека | Контакты</title>
<link rel="stylesheet" href="css/contacts.css">
</head>
<body>
<?php require('./includes/header.html'); ?>
<?php
require('./includes/welcome.php');