-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
27 changed files
with
812 additions
and
0 deletions.
There are no files selected for viewing
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
<!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"> | ||
</head> | ||
<body> | ||
<h1>Add a New Book</h1> | ||
<form action="add_book.php" method="POST"> | ||
<label for="title">Title:</label> | ||
<input type="text" id="title" name="title" required><br> | ||
|
||
<label for="author">Author:</label> | ||
<input type="text" id="author" name="author" required><br> | ||
|
||
<label for="publication_year">Publication Year:</label> | ||
<input type="number" id="publication_year" name="publication_year" min="2000" required><br> | ||
|
||
<label for="genre">Genre:</label> | ||
<input type="text" id="genre" name="genre" required><br> | ||
|
||
<button type="submit">Add Book</button> | ||
</form> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
<?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"> | ||
</head> | ||
<body> | ||
<?php include 'navbar.php'; ?> | ||
|
||
<main> | ||
<h1>Add a New Book</h1> | ||
<form action="add_book.php" method="POST"> | ||
<label for="title">Title:</label> | ||
<input type="text" id="title" name="title" required><br> | ||
|
||
<label for="author">Author:</label> | ||
<input type="text" id="author" name="author" required><br> | ||
|
||
<label for="publication_year">Publication Year:</label> | ||
<input type="number" id="publication_year" name="publication_year" min="2000" required><br> | ||
|
||
<label for="genre">Genre:</label> | ||
<input type="text" id="genre" name="genre" required><br> | ||
|
||
<button type="submit">Add Book</button> | ||
</form> | ||
</main> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
[ | ||
{ | ||
"id": "1", | ||
"title": "1st", | ||
"author": "Sapiens", | ||
"publication_year": "2001", | ||
"genre": "Life" | ||
}, | ||
{ | ||
"id": "2", | ||
"title": "1stest", | ||
"author": "H Sapiens", | ||
"publication_year": "2001", | ||
"genre": "Life" | ||
}, | ||
{ | ||
"id": "3", | ||
"title": "First", | ||
"author": "Homo S", | ||
"publication_year": "2001", | ||
"genre": "Life" | ||
}, | ||
{ | ||
"id": "7", | ||
"title": "new", | ||
"author": "first", | ||
"publication_year": "2001", | ||
"genre": "Evolution" | ||
} | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
<?xml version='1.0' encoding='utf-8'?> | ||
<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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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: white; | ||
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; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
<?php include 'navbar.php'; ?> | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="UTF-8"> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0"> | ||
<title>Dashboard</title> | ||
<link rel="stylesheet" href="common.css"> | ||
</head> | ||
<body> | ||
<main> | ||
<h2>Welcome to the Dashboard</h2> | ||
<a href="add_book.html">Add Book</a> | ||
<li><a href="search_books.html">Search Books</a></li> | ||
|
||
</main> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
<?php | ||
// Start the session | ||
session_start(); | ||
|
||
// Check if the user is logged in | ||
if (!isset($_SESSION['username'])) { | ||
header("Location: login.html"); | ||
exit; | ||
} | ||
|
||
$username = $_SESSION['username']; | ||
?> | ||
|
||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="UTF-8"> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0"> | ||
<title>Dashboard</title> | ||
<link rel="stylesheet" href="common.css"> | ||
</head> | ||
<body> | ||
<?php include 'navbar.php'; ?> | ||
|
||
<main> | ||
<h1>Welcome to Your Dashboard</h1> | ||
<p>Hello, <?php echo htmlspecialchars($username); ?>! Here are your options:</p> | ||
<div class="actions"> | ||
<a href="add_book.php" class="btn">Add a Book</a> | ||
<a href="search_books.html" class="btn">Search Books</a> | ||
</div> | ||
</main> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
<?php | ||
// Database configuration | ||
$host = "localhost"; | ||
$user = "root"; | ||
$password = ""; | ||
$database = "library_db"; | ||
$port = 3307; // Updated port number for phpMyAdmin | ||
|
||
// Create a database connection | ||
$conn = new mysqli($host, $user, $password, $database, $port); | ||
|
||
// Check the connection | ||
if ($conn->connect_error) { | ||
die("Connection failed: " . $conn->connect_error); | ||
} | ||
?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
<?php | ||
// Define the path to the Python executable and the script | ||
$python = 'C:\\Users\\Lokesh Patra\\AppData\\Local\\Programs\\Python\\Python312\\python.exe'; // Full path to Python executable | ||
$script = 'export_books.py'; // The Python script to be executed | ||
|
||
// Execute the Python script and capture the output | ||
$output = shell_exec("\"$python\" \"$script\" 2>&1"); // Ensure paths with spaces are handled properly | ||
|
||
// Check if the script executed successfully and output the results | ||
if ($output) { | ||
echo "Books exported to books.xml successfully!<br>"; | ||
echo "Python script output: " . nl2br($output); // nl2br to add line breaks for better readability | ||
} else { | ||
echo "Failed to export books to XML. Error: " . nl2br($output); | ||
} | ||
?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import json | ||
import xml.etree.ElementTree as ET | ||
import os | ||
|
||
# Ensure the books.json file exists and is populated | ||
if os.path.exists('books.json'): | ||
with open('books.json', 'r') as file: | ||
books = json.load(file) | ||
|
||
# Create XML root element | ||
root = ET.Element('books') | ||
|
||
# Add book entries to XML | ||
for book in books: | ||
book_element = ET.SubElement(root, 'book') | ||
for key, value in book.items(): | ||
child = ET.SubElement(book_element, key) | ||
child.text = str(value) | ||
|
||
# Write the XML data to a file | ||
tree = ET.ElementTree(root) | ||
tree.write('books.xml', encoding='utf-8', xml_declaration=True) | ||
print("Books exported to books.xml") | ||
|
||
else: | ||
print("Error: books.json not found.") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
main { | ||
text-align: center; | ||
padding: 2em; | ||
background-color: #f9f9f9; | ||
} | ||
|
||
h2 { | ||
color: #333; | ||
} | ||
|
||
p { | ||
font-size: 1.2em; | ||
margin: 1em 0; | ||
} | ||
|
||
.actions { | ||
margin-top: 2em; | ||
} | ||
|
||
.actions .btn { | ||
text-decoration: none; | ||
color: white; | ||
background-color: #333; | ||
padding: 0.8em 1.5em; | ||
border-radius: 5px; | ||
margin: 0 1em; | ||
font-size: 1em; | ||
transition: background-color 0.3s; | ||
} | ||
|
||
.actions .btn:hover { | ||
background-color: #555; | ||
} | ||
|
||
footer { | ||
text-align: center; | ||
padding: 1em 0; | ||
background-color: #333; | ||
color: white; | ||
position: absolute; | ||
bottom: 0; | ||
width: 100%; | ||
} |
Oops, something went wrong.