Skip to content

Commit b8e3ea4

Browse files
committed
LM '24 [ v4 Featured /Fashioned /Finished ]
1 parent 18d2d5b commit b8e3ea4

28 files changed

+1476
-0
lines changed

add_book.css

Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
/* General Styles */
2+
body {
3+
font-family: 'Cambria', serif;
4+
background-color: #f4f4f4; /* Light grey background */
5+
color: #333; /* Dark text color */
6+
margin: 0;
7+
padding: 0;
8+
}
9+
10+
header {
11+
background-color: #2C3E50; /* Dark blue */
12+
color: white;
13+
text-align: center;
14+
padding: 20px 0;
15+
margin-bottom: 40px;
16+
}
17+
18+
header h1 {
19+
font-size: 2.5rem;
20+
margin: 0;
21+
}
22+
23+
main {
24+
padding: 40px 10px;
25+
text-align: center;
26+
}
27+
28+
main h1 {
29+
color: #2C3E50; /* Dark blue */
30+
font-size: 2.2rem;
31+
margin-bottom: 20px;
32+
}
33+
34+
form {
35+
background-color: #fff;
36+
padding: 30px;
37+
border-radius: 8px;
38+
box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
39+
width: 50%;
40+
margin: 0 auto;
41+
box-sizing: border-box;
42+
display: flex;
43+
flex-direction: column;
44+
align-items: center; /* Center the form elements */
45+
}
46+
47+
.form-group {
48+
width: 100%; /* Ensure form-group takes full width */
49+
margin-bottom: 15px;
50+
display: flex;
51+
flex-direction: column;
52+
align-items: flex-start;
53+
}
54+
55+
form label {
56+
font-size: 1rem;
57+
margin-bottom: 5px;
58+
width: 100%; /* Ensure label takes full width */
59+
}
60+
61+
form input {
62+
width: 100%;
63+
padding: 12px;
64+
font-size: 1rem;
65+
margin-bottom: 15px;
66+
border: 1px solid #ccc;
67+
border-radius: 4px;
68+
box-sizing: border-box;
69+
}
70+
71+
form button {
72+
background-color: #2C3E50; /* Dark blue */
73+
color: white;
74+
padding: 12px 20px;
75+
border: none;
76+
border-radius: 4px;
77+
font-size: 1.2rem;
78+
cursor: pointer;
79+
transition: background-color 0.3s ease;
80+
align-self: flex-start; /* Align button to the start */
81+
}
82+
83+
form button:hover {
84+
background-color: #1A252F; /* Darker blue on hover */
85+
}
86+
87+
footer {
88+
background-color: #2C3E50; /* Dark blue */
89+
color: white;
90+
text-align: center;
91+
padding: 10px;
92+
position: absolute;
93+
bottom: 0;
94+
width: 100%;
95+
}

add_book.html

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="UTF-8">
5+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
6+
<title>Add Book</title>
7+
<link rel="stylesheet" href="common.css">
8+
<link rel="stylesheet" href="add_book.css">
9+
</head>
10+
<body>
11+
<?php include 'navbar.php'; ?>
12+
13+
<main>
14+
<h1>Add a New Book</h1>
15+
<form action="add_book.php" method="POST">
16+
<div class="form-group">
17+
<label for="title">Title:</label>
18+
<input type="text" id="title" name="title" required placeholder="Enter book title">
19+
</div>
20+
21+
<div class="form-group">
22+
<label for="author">Author:</label>
23+
<input type="text" id="author" name="author" required placeholder="Enter author's name">
24+
</div>
25+
26+
<div class="form-group">
27+
<label for="publication_year">Publication Year:</label>
28+
<input type="number" id="publication_year" name="publication_year" min="2000" required placeholder="Enter publication year (after 2000)">
29+
</div>
30+
31+
<div class="form-group">
32+
<label for="genre">Genre:</label>
33+
<input type="text" id="genre" name="genre" required placeholder="Enter genre">
34+
</div>
35+
36+
<button type="submit">Add Book</button>
37+
</form>
38+
</main>
39+
40+
<footer>
41+
<p>&copy; 2024 Library Management System</p>
42+
</footer>
43+
</body>
44+
</html>

add_book.php

Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
<?php
2+
// Start the session
3+
session_start();
4+
require 'db_config.php';
5+
6+
// Redirect if the user is not logged in
7+
if (!isset($_SESSION['username'])) {
8+
header("Location: login.html");
9+
exit;
10+
}
11+
12+
// Function to update the books.json file after adding a new book
13+
function updateJsonFile($conn) {
14+
$query = "SELECT * FROM books";
15+
$result = $conn->query($query);
16+
$books = [];
17+
18+
while ($row = $result->fetch_assoc()) {
19+
$books[] = $row;
20+
}
21+
22+
// Save the books array to books.json
23+
file_put_contents('books.json', json_encode($books, JSON_PRETTY_PRINT));
24+
}
25+
26+
// Handle form submission
27+
if ($_SERVER["REQUEST_METHOD"] === "POST") {
28+
// Retrieve form data
29+
$title = $_POST['title'] ?? '';
30+
$author = $_POST['author'] ?? '';
31+
$publication_year = $_POST['publication_year'] ?? 0;
32+
$genre = $_POST['genre'] ?? '';
33+
34+
// Validate form data
35+
if (empty($title) || empty($author) || empty($publication_year) || empty($genre)) {
36+
echo "<script>alert('All fields are required.'); window.location.href='add_book.php';</script>";
37+
exit;
38+
}
39+
40+
// Insert data into the database
41+
$stmt = $conn->prepare("INSERT INTO books (title, author, publication_year, genre) VALUES (?, ?, ?, ?)");
42+
if (!$stmt) {
43+
die("Prepare failed: " . $conn->error);
44+
}
45+
46+
$stmt->bind_param("ssis", $title, $author, $publication_year, $genre);
47+
48+
if ($stmt->execute()) {
49+
updateJsonFile($conn); // Update the JSON file after adding the book
50+
echo "<script>alert('Book added successfully!'); window.location.href='add_book.php';</script>";
51+
exit;
52+
} else {
53+
die("Error adding book: " . $stmt->error);
54+
}
55+
}
56+
?>
57+
58+
<!DOCTYPE html>
59+
<html lang="en">
60+
<head>
61+
<meta charset="UTF-8">
62+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
63+
<title>Add Book</title>
64+
<link rel="stylesheet" href="common.css">
65+
<link rel="stylesheet" href="add_book.css">
66+
</head>
67+
<body>
68+
<?php include 'navbar.php'; ?>
69+
70+
<main>
71+
<h1>Add a New Book</h1>
72+
<form action="add_book.php" method="POST">
73+
<div class="form-group">
74+
<label for="title">Title:</label>
75+
<input type="text" id="title" name="title" required placeholder="Enter book title">
76+
</div>
77+
78+
<div class="form-group">
79+
<label for="author">Author:</label>
80+
<input type="text" id="author" name="author" required placeholder="Enter author's name">
81+
</div>
82+
83+
<div class="form-group">
84+
<label for="publication_year">Publication Year:</label>
85+
<input type="number" id="publication_year" name="publication_year" min="2000" required placeholder="Enter publication year (after 2000)">
86+
</div>
87+
88+
<div class="form-group">
89+
<label for="genre">Genre:</label>
90+
<input type="text" id="genre" name="genre" required placeholder="Enter genre">
91+
</div>
92+
93+
<button type="submit">Add Book</button>
94+
</form>
95+
</main>
96+
97+
<footer>
98+
<p>&copy; 2024 Library Management System</p>
99+
</footer>
100+
</body>
101+
</html>

books.json

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
[
2+
{
3+
"id": "4",
4+
"title": "2nd",
5+
"author": "Habilis",
6+
"publication_year": "2002",
7+
"genre": "Evolution"
8+
},
9+
{
10+
"id": "6",
11+
"title": "feature",
12+
"author": "second",
13+
"publication_year": "2002",
14+
"genre": "tested"
15+
},
16+
{
17+
"id": "8",
18+
"title": "sample",
19+
"author": "2nd",
20+
"publication_year": "2002",
21+
"genre": "tested"
22+
},
23+
{
24+
"id": "13",
25+
"title": "BioInformatics: From Genomes to Drugs",
26+
"author": " Ralf Hofest\u00e4dt",
27+
"publication_year": "2002",
28+
"genre": "Life"
29+
}
30+
]

books.xml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
<?xml version='1.0' encoding='utf-8'?>
2+
<Library><Book><id>4</id><title>2nd</title><author>Habilis</author><publication_year>2002</publication_year><genre>Evolution</genre></Book><Book><id>6</id><title>feature</title><author>second</author><publication_year>2002</publication_year><genre>tested</genre></Book><Book><id>8</id><title>sample</title><author>2nd</author><publication_year>2002</publication_year><genre>tested</genre></Book><Book><id>13</id><title>BioInformatics: From Genomes to Drugs</title><author> Ralf Hofestädt</author><publication_year>2002</publication_year><genre>Life</genre></Book><GenreCounts><Genre><Name>Evolution</Name><Count>1</Count></Genre><Genre><Name>tested</Name><Count>2</Count></Genre><Genre><Name>Life</Name><Count>1</Count></Genre></GenreCounts></Library>

common.css

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
body {
2+
font-family: Arial, sans-serif;
3+
margin: 0;
4+
padding: 0;
5+
background-color: #f4f4f9;
6+
}
7+
8+
header {
9+
background-color: #333;
10+
color: rgb(218, 0, 0);
11+
padding: 1em;
12+
text-align: center;
13+
}
14+
15+
form {
16+
width: 50%;
17+
margin: 2em auto;
18+
padding: 2em;
19+
background: white;
20+
border: 1px solid #ccc;
21+
border-radius: 8px;
22+
}
23+
24+
form label {
25+
display: block;
26+
margin: 0.5em 0 0.2em;
27+
}
28+
29+
form input {
30+
width: 100%;
31+
padding: 0.5em;
32+
margin-bottom: 1em;
33+
border: 1px solid #ccc;
34+
border-radius: 4px;
35+
}
36+
37+
form button {
38+
background-color: #333;
39+
color: white;
40+
padding: 0.7em 1.5em;
41+
border: none;
42+
border-radius: 4px;
43+
cursor: pointer;
44+
}
45+
46+
form button:hover {
47+
background-color: #555;
48+
}

dashboard.css

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
/* General Styles */
2+
body {
3+
font-family: 'Cambria', serif;
4+
background-color: #f4f4f4; /* Light grey background */
5+
color: #333333; /* Dark text color */
6+
margin: 0;
7+
padding: 0;
8+
}
9+
10+
header {
11+
background-color: #2C3E50; /* Dark blue */
12+
color: #ffffff; /* White text */
13+
text-align: center;
14+
padding: 20px 0;
15+
margin-bottom: 40px;
16+
}
17+
18+
header h1 {
19+
font-size: 2.5rem;
20+
margin: 0;
21+
}
22+
23+
main {
24+
text-align: center;
25+
padding: 30px 10px;
26+
}
27+
28+
main h2 {
29+
color: #2C3E50; /* Dark blue */
30+
font-size: 2rem;
31+
margin-bottom: 30px;
32+
}
33+
34+
.actions {
35+
display: flex;
36+
justify-content: center;
37+
gap: 20px;
38+
}
39+
40+
.actions a {
41+
background-color: #3498db; /* Blue button */
42+
color: #ffffff; /* White text */
43+
padding: 12px 20px;
44+
text-decoration: none;
45+
border-radius: 4px;
46+
font-size: 1.1rem;
47+
transition: background-color 0.3s;
48+
}
49+
50+
.actions a:hover {
51+
background-color: #2980b9; /* Darker blue on hover */
52+
}
53+
54+
footer {
55+
background-color: #2C3E50; /* Dark blue */
56+
color: #ffffff; /* White text */
57+
text-align: center;
58+
padding: 10px;
59+
position: absolute;
60+
bottom: 0;
61+
width: 100%;
62+
}

0 commit comments

Comments
 (0)