Skip to content

Commit dcb298b

Browse files
committed
Features Configured! [ v2.0 ]
1 parent 944eebf commit dcb298b

27 files changed

+812
-0
lines changed

v2 Features/add_book.css

Whitespace-only changes.

v2 Features/add_book.html

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
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+
</head>
9+
<body>
10+
<h1>Add a New Book</h1>
11+
<form action="add_book.php" method="POST">
12+
<label for="title">Title:</label>
13+
<input type="text" id="title" name="title" required><br>
14+
15+
<label for="author">Author:</label>
16+
<input type="text" id="author" name="author" required><br>
17+
18+
<label for="publication_year">Publication Year:</label>
19+
<input type="number" id="publication_year" name="publication_year" min="2000" required><br>
20+
21+
<label for="genre">Genre:</label>
22+
<input type="text" id="genre" name="genre" required><br>
23+
24+
<button type="submit">Add Book</button>
25+
</form>
26+
</body>
27+
</html>

v2 Features/add_book.php

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
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+
</head>
66+
<body>
67+
<?php include 'navbar.php'; ?>
68+
69+
<main>
70+
<h1>Add a New Book</h1>
71+
<form action="add_book.php" method="POST">
72+
<label for="title">Title:</label>
73+
<input type="text" id="title" name="title" required><br>
74+
75+
<label for="author">Author:</label>
76+
<input type="text" id="author" name="author" required><br>
77+
78+
<label for="publication_year">Publication Year:</label>
79+
<input type="number" id="publication_year" name="publication_year" min="2000" required><br>
80+
81+
<label for="genre">Genre:</label>
82+
<input type="text" id="genre" name="genre" required><br>
83+
84+
<button type="submit">Add Book</button>
85+
</form>
86+
</main>
87+
</body>
88+
</html>

v2 Features/books.json

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
[
2+
{
3+
"id": "1",
4+
"title": "1st",
5+
"author": "Sapiens",
6+
"publication_year": "2001",
7+
"genre": "Life"
8+
},
9+
{
10+
"id": "2",
11+
"title": "1stest",
12+
"author": "H Sapiens",
13+
"publication_year": "2001",
14+
"genre": "Life"
15+
},
16+
{
17+
"id": "3",
18+
"title": "First",
19+
"author": "Homo S",
20+
"publication_year": "2001",
21+
"genre": "Life"
22+
},
23+
{
24+
"id": "7",
25+
"title": "new",
26+
"author": "first",
27+
"publication_year": "2001",
28+
"genre": "Evolution"
29+
}
30+
]

v2 Features/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+
<books><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></books>

v2 Features/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: white;
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+
}

v2 Features/dashboard.html

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<?php include 'navbar.php'; ?>
2+
<!DOCTYPE html>
3+
<html lang="en">
4+
<head>
5+
<meta charset="UTF-8">
6+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
7+
<title>Dashboard</title>
8+
<link rel="stylesheet" href="common.css">
9+
</head>
10+
<body>
11+
<main>
12+
<h2>Welcome to the Dashboard</h2>
13+
<a href="add_book.html">Add Book</a>
14+
<li><a href="search_books.html">Search Books</a></li>
15+
16+
</main>
17+
</body>
18+
</html>

v2 Features/dashboard.php

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
<?php
2+
// Start the session
3+
session_start();
4+
5+
// Check if the user is logged in
6+
if (!isset($_SESSION['username'])) {
7+
header("Location: login.html");
8+
exit;
9+
}
10+
11+
$username = $_SESSION['username'];
12+
?>
13+
14+
<!DOCTYPE html>
15+
<html lang="en">
16+
<head>
17+
<meta charset="UTF-8">
18+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
19+
<title>Dashboard</title>
20+
<link rel="stylesheet" href="common.css">
21+
</head>
22+
<body>
23+
<?php include 'navbar.php'; ?>
24+
25+
<main>
26+
<h1>Welcome to Your Dashboard</h1>
27+
<p>Hello, <?php echo htmlspecialchars($username); ?>! Here are your options:</p>
28+
<div class="actions">
29+
<a href="add_book.php" class="btn">Add a Book</a>
30+
<a href="search_books.html" class="btn">Search Books</a>
31+
</div>
32+
</main>
33+
</body>
34+
</html>

v2 Features/db_config.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<?php
2+
// Database configuration
3+
$host = "localhost";
4+
$user = "root";
5+
$password = "";
6+
$database = "library_db";
7+
$port = 3307; // Updated port number for phpMyAdmin
8+
9+
// Create a database connection
10+
$conn = new mysqli($host, $user, $password, $database, $port);
11+
12+
// Check the connection
13+
if ($conn->connect_error) {
14+
die("Connection failed: " . $conn->connect_error);
15+
}
16+
?>

v2 Features/export_books.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<?php
2+
// Define the path to the Python executable and the script
3+
$python = 'C:\\Users\\Lokesh Patra\\AppData\\Local\\Programs\\Python\\Python312\\python.exe'; // Full path to Python executable
4+
$script = 'export_books.py'; // The Python script to be executed
5+
6+
// Execute the Python script and capture the output
7+
$output = shell_exec("\"$python\" \"$script\" 2>&1"); // Ensure paths with spaces are handled properly
8+
9+
// Check if the script executed successfully and output the results
10+
if ($output) {
11+
echo "Books exported to books.xml successfully!<br>";
12+
echo "Python script output: " . nl2br($output); // nl2br to add line breaks for better readability
13+
} else {
14+
echo "Failed to export books to XML. Error: " . nl2br($output);
15+
}
16+
?>

v2 Features/export_books.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import json
2+
import xml.etree.ElementTree as ET
3+
import os
4+
5+
# Ensure the books.json file exists and is populated
6+
if os.path.exists('books.json'):
7+
with open('books.json', 'r') as file:
8+
books = json.load(file)
9+
10+
# Create XML root element
11+
root = ET.Element('books')
12+
13+
# Add book entries to XML
14+
for book in books:
15+
book_element = ET.SubElement(root, 'book')
16+
for key, value in book.items():
17+
child = ET.SubElement(book_element, key)
18+
child.text = str(value)
19+
20+
# Write the XML data to a file
21+
tree = ET.ElementTree(root)
22+
tree.write('books.xml', encoding='utf-8', xml_declaration=True)
23+
print("Books exported to books.xml")
24+
25+
else:
26+
print("Error: books.json not found.")

v2 Features/index.css

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
main {
2+
text-align: center;
3+
padding: 2em;
4+
background-color: #f9f9f9;
5+
}
6+
7+
h2 {
8+
color: #333;
9+
}
10+
11+
p {
12+
font-size: 1.2em;
13+
margin: 1em 0;
14+
}
15+
16+
.actions {
17+
margin-top: 2em;
18+
}
19+
20+
.actions .btn {
21+
text-decoration: none;
22+
color: white;
23+
background-color: #333;
24+
padding: 0.8em 1.5em;
25+
border-radius: 5px;
26+
margin: 0 1em;
27+
font-size: 1em;
28+
transition: background-color 0.3s;
29+
}
30+
31+
.actions .btn:hover {
32+
background-color: #555;
33+
}
34+
35+
footer {
36+
text-align: center;
37+
padding: 1em 0;
38+
background-color: #333;
39+
color: white;
40+
position: absolute;
41+
bottom: 0;
42+
width: 100%;
43+
}

0 commit comments

Comments
 (0)