Skip to content

Commit

Permalink
LM '24 [ v4 Featured /Fashioned /Finished ]
Browse files Browse the repository at this point in the history
  • Loading branch information
lightxLK committed Nov 17, 2024
1 parent 18d2d5b commit b8e3ea4
Show file tree
Hide file tree
Showing 28 changed files with 1,476 additions and 0 deletions.
95 changes: 95 additions & 0 deletions add_book.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
/* General Styles */
body {
font-family: 'Cambria', serif;
background-color: #f4f4f4; /* Light grey background */
color: #333; /* Dark text color */
margin: 0;
padding: 0;
}

header {
background-color: #2C3E50; /* Dark blue */
color: white;
text-align: center;
padding: 20px 0;
margin-bottom: 40px;
}

header h1 {
font-size: 2.5rem;
margin: 0;
}

main {
padding: 40px 10px;
text-align: center;
}

main h1 {
color: #2C3E50; /* Dark blue */
font-size: 2.2rem;
margin-bottom: 20px;
}

form {
background-color: #fff;
padding: 30px;
border-radius: 8px;
box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
width: 50%;
margin: 0 auto;
box-sizing: border-box;
display: flex;
flex-direction: column;
align-items: center; /* Center the form elements */
}

.form-group {
width: 100%; /* Ensure form-group takes full width */
margin-bottom: 15px;
display: flex;
flex-direction: column;
align-items: flex-start;
}

form label {
font-size: 1rem;
margin-bottom: 5px;
width: 100%; /* Ensure label takes full width */
}

form input {
width: 100%;
padding: 12px;
font-size: 1rem;
margin-bottom: 15px;
border: 1px solid #ccc;
border-radius: 4px;
box-sizing: border-box;
}

form button {
background-color: #2C3E50; /* Dark blue */
color: white;
padding: 12px 20px;
border: none;
border-radius: 4px;
font-size: 1.2rem;
cursor: pointer;
transition: background-color 0.3s ease;
align-self: flex-start; /* Align button to the start */
}

form button:hover {
background-color: #1A252F; /* Darker blue on hover */
}

footer {
background-color: #2C3E50; /* Dark blue */
color: white;
text-align: center;
padding: 10px;
position: absolute;
bottom: 0;
width: 100%;
}
44 changes: 44 additions & 0 deletions add_book.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Add Book</title>
<link rel="stylesheet" href="common.css">
<link rel="stylesheet" href="add_book.css">
</head>
<body>
<?php include 'navbar.php'; ?>

<main>
<h1>Add a New Book</h1>
<form action="add_book.php" method="POST">
<div class="form-group">
<label for="title">Title:</label>
<input type="text" id="title" name="title" required placeholder="Enter book title">
</div>

<div class="form-group">
<label for="author">Author:</label>
<input type="text" id="author" name="author" required placeholder="Enter author's name">
</div>

<div class="form-group">
<label for="publication_year">Publication Year:</label>
<input type="number" id="publication_year" name="publication_year" min="2000" required placeholder="Enter publication year (after 2000)">
</div>

<div class="form-group">
<label for="genre">Genre:</label>
<input type="text" id="genre" name="genre" required placeholder="Enter genre">
</div>

<button type="submit">Add Book</button>
</form>
</main>

<footer>
<p>&copy; 2024 Library Management System</p>
</footer>
</body>
</html>
101 changes: 101 additions & 0 deletions add_book.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
<?php
// Start the session
session_start();
require 'db_config.php';

// Redirect if the user is not logged in
if (!isset($_SESSION['username'])) {
header("Location: login.html");
exit;
}

// Function to update the books.json file after adding a new book
function updateJsonFile($conn) {
$query = "SELECT * FROM books";
$result = $conn->query($query);
$books = [];

while ($row = $result->fetch_assoc()) {
$books[] = $row;
}

// Save the books array to books.json
file_put_contents('books.json', json_encode($books, JSON_PRETTY_PRINT));
}

// Handle form submission
if ($_SERVER["REQUEST_METHOD"] === "POST") {
// Retrieve form data
$title = $_POST['title'] ?? '';
$author = $_POST['author'] ?? '';
$publication_year = $_POST['publication_year'] ?? 0;
$genre = $_POST['genre'] ?? '';

// Validate form data
if (empty($title) || empty($author) || empty($publication_year) || empty($genre)) {
echo "<script>alert('All fields are required.'); window.location.href='add_book.php';</script>";
exit;
}

// Insert data into the database
$stmt = $conn->prepare("INSERT INTO books (title, author, publication_year, genre) VALUES (?, ?, ?, ?)");
if (!$stmt) {
die("Prepare failed: " . $conn->error);
}

$stmt->bind_param("ssis", $title, $author, $publication_year, $genre);

if ($stmt->execute()) {
updateJsonFile($conn); // Update the JSON file after adding the book
echo "<script>alert('Book added successfully!'); window.location.href='add_book.php';</script>";
exit;
} else {
die("Error adding book: " . $stmt->error);
}
}
?>

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Add Book</title>
<link rel="stylesheet" href="common.css">
<link rel="stylesheet" href="add_book.css">
</head>
<body>
<?php include 'navbar.php'; ?>

<main>
<h1>Add a New Book</h1>
<form action="add_book.php" method="POST">
<div class="form-group">
<label for="title">Title:</label>
<input type="text" id="title" name="title" required placeholder="Enter book title">
</div>

<div class="form-group">
<label for="author">Author:</label>
<input type="text" id="author" name="author" required placeholder="Enter author's name">
</div>

<div class="form-group">
<label for="publication_year">Publication Year:</label>
<input type="number" id="publication_year" name="publication_year" min="2000" required placeholder="Enter publication year (after 2000)">
</div>

<div class="form-group">
<label for="genre">Genre:</label>
<input type="text" id="genre" name="genre" required placeholder="Enter genre">
</div>

<button type="submit">Add Book</button>
</form>
</main>

<footer>
<p>&copy; 2024 Library Management System</p>
</footer>
</body>
</html>
30 changes: 30 additions & 0 deletions books.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
[
{
"id": "4",
"title": "2nd",
"author": "Habilis",
"publication_year": "2002",
"genre": "Evolution"
},
{
"id": "6",
"title": "feature",
"author": "second",
"publication_year": "2002",
"genre": "tested"
},
{
"id": "8",
"title": "sample",
"author": "2nd",
"publication_year": "2002",
"genre": "tested"
},
{
"id": "13",
"title": "BioInformatics: From Genomes to Drugs",
"author": " Ralf Hofest\u00e4dt",
"publication_year": "2002",
"genre": "Life"
}
]
2 changes: 2 additions & 0 deletions books.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
<?xml version='1.0' encoding='utf-8'?>
<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>
48 changes: 48 additions & 0 deletions common.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
body {
font-family: Arial, sans-serif;
margin: 0;
padding: 0;
background-color: #f4f4f9;
}

header {
background-color: #333;
color: rgb(218, 0, 0);
padding: 1em;
text-align: center;
}

form {
width: 50%;
margin: 2em auto;
padding: 2em;
background: white;
border: 1px solid #ccc;
border-radius: 8px;
}

form label {
display: block;
margin: 0.5em 0 0.2em;
}

form input {
width: 100%;
padding: 0.5em;
margin-bottom: 1em;
border: 1px solid #ccc;
border-radius: 4px;
}

form button {
background-color: #333;
color: white;
padding: 0.7em 1.5em;
border: none;
border-radius: 4px;
cursor: pointer;
}

form button:hover {
background-color: #555;
}
62 changes: 62 additions & 0 deletions dashboard.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
/* General Styles */
body {
font-family: 'Cambria', serif;
background-color: #f4f4f4; /* Light grey background */
color: #333333; /* Dark text color */
margin: 0;
padding: 0;
}

header {
background-color: #2C3E50; /* Dark blue */
color: #ffffff; /* White text */
text-align: center;
padding: 20px 0;
margin-bottom: 40px;
}

header h1 {
font-size: 2.5rem;
margin: 0;
}

main {
text-align: center;
padding: 30px 10px;
}

main h2 {
color: #2C3E50; /* Dark blue */
font-size: 2rem;
margin-bottom: 30px;
}

.actions {
display: flex;
justify-content: center;
gap: 20px;
}

.actions a {
background-color: #3498db; /* Blue button */
color: #ffffff; /* White text */
padding: 12px 20px;
text-decoration: none;
border-radius: 4px;
font-size: 1.1rem;
transition: background-color 0.3s;
}

.actions a:hover {
background-color: #2980b9; /* Darker blue on hover */
}

footer {
background-color: #2C3E50; /* Dark blue */
color: #ffffff; /* White text */
text-align: center;
padding: 10px;
position: absolute;
bottom: 0;
width: 100%;
}
Loading

0 comments on commit b8e3ea4

Please sign in to comment.