239 lines
9.0 KiB
HTML
239 lines
9.0 KiB
HTML
<!DOCTYPE html>
|
|
<html lang="en">
|
|
<head>
|
|
<meta charset="UTF-8">
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
<title>Multi File Upload & Edit</title>
|
|
<link href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css" rel="stylesheet">
|
|
<script src="https://code.jquery.com/jquery-3.5.1.min.js"></script>
|
|
<script src="auth.js"></script>
|
|
<script src="upload.js"></script>
|
|
<script src="displayFileList.js"></script>
|
|
<style>
|
|
.container { margin-top: 10px; }
|
|
#fileListContainer, #uploadForm, #addUserModal { display: none; }
|
|
|
|
.logout-container {
|
|
position: absolute;
|
|
top: 10px;
|
|
right: 10px;
|
|
display: flex;
|
|
flex-direction: column;
|
|
align-items: flex-end;
|
|
gap: 5px;
|
|
}
|
|
|
|
@media (max-width: 768px) {
|
|
.logout-container {
|
|
position: static;
|
|
align-items: flex-end;
|
|
text-align: right;
|
|
margin-top: 10px;
|
|
}
|
|
|
|
.logout-container button {
|
|
width: auto;
|
|
min-width: 120px;
|
|
}
|
|
}
|
|
|
|
.modal {
|
|
display: none;
|
|
position: fixed;
|
|
top: 50%;
|
|
left: 50%;
|
|
transform: translate(-50%, -50%);
|
|
background: white;
|
|
padding: 20px;
|
|
border: 1px solid black;
|
|
box-shadow: 0px 4px 6px rgba(0,0,0,0.1);
|
|
z-index: 1000;
|
|
width: 350px;
|
|
height: auto;
|
|
display: flex;
|
|
flex-direction: column;
|
|
gap: 10px;
|
|
}
|
|
</style>
|
|
</head>
|
|
<body>
|
|
<header class="text-center" style="position: relative;">
|
|
<h1>Multi File Upload & Edit</h1>
|
|
<div class="logout-container">
|
|
<button id="logoutBtn" class="btn btn-danger" style="display: none;">Logout</button>
|
|
<button id="addUserBtn" class="btn btn-success" style="display: none;">Add User</button>
|
|
</div>
|
|
</header>
|
|
|
|
<div class="container">
|
|
<div class="row" id="loginForm">
|
|
<div class="col-md-6">
|
|
<form id="authForm" method="post">
|
|
<div class="form-group">
|
|
<label for="loginUsername">User:</label>
|
|
<input type="text" class="form-control" id="loginUsername" name="username" required>
|
|
</div>
|
|
<div class="form-group">
|
|
<label for="loginPassword">Password:</label>
|
|
<input type="password" class="form-control" id="loginPassword" name="password" required>
|
|
</div>
|
|
<button type="submit" class="btn btn-primary">Login</button>
|
|
</form>
|
|
</div>
|
|
</div>
|
|
|
|
<div class="row" id="uploadForm">
|
|
<div class="col-md-12">
|
|
<form id="uploadFileForm" method="post" enctype="multipart/form-data">
|
|
<div class="form-group">
|
|
<label for="file"></label>
|
|
<input type="file" id="file" name="file[]" class="form-control-file" multiple required style="width: 768px;">
|
|
</div>
|
|
<button type="submit" id="uploadBtn" class="btn btn-primary" disabled>Upload</button>
|
|
<div id="statusMessage"></div>
|
|
</form>
|
|
</div>
|
|
</div>
|
|
|
|
<div id="fileListContainer">
|
|
<h2>Uploaded Files</h2>
|
|
<button id="deleteSelectedBtn" class="btn btn-danger" style="margin-bottom: 10px; display: none;">Delete Selected</button>
|
|
<div id="fileList"></div>
|
|
</div>
|
|
|
|
<!-- Add User Modal -->
|
|
<div id="addUserModal" class="modal">
|
|
<h3>Create New User</h3>
|
|
<label for="newUsername">Username:</label>
|
|
<input type="text" id="newUsername" class="form-control">
|
|
|
|
<label for="newPassword">Password:</label>
|
|
<input type="password" id="newPassword" class="form-control">
|
|
|
|
<div>
|
|
<input type="checkbox" id="isAdmin">
|
|
<label for="isAdmin">Grant Admin Access</label>
|
|
</div>
|
|
|
|
<button id="saveUserBtn" class="btn btn-primary">Save User</button>
|
|
<button id="cancelUserBtn" class="btn btn-secondary">Cancel</button>
|
|
</div>
|
|
</div>
|
|
|
|
<script>
|
|
document.addEventListener("DOMContentLoaded", function () {
|
|
checkAuthentication();
|
|
|
|
function updateUI(data) {
|
|
if (data.authenticated) {
|
|
document.getElementById("loginForm").style.display = "none";
|
|
document.getElementById("uploadForm").style.display = "block";
|
|
document.getElementById("fileListContainer").style.display = "block";
|
|
document.getElementById("logoutBtn").style.display = "block";
|
|
|
|
if (data.isAdmin) {
|
|
document.getElementById("addUserBtn").style.display = "block";
|
|
} else {
|
|
document.getElementById("addUserBtn").style.display = "none";
|
|
}
|
|
|
|
loadFileList();
|
|
} else {
|
|
document.getElementById("loginForm").style.display = "block";
|
|
document.getElementById("uploadForm").style.display = "none";
|
|
document.getElementById("fileListContainer").style.display = "none";
|
|
document.getElementById("logoutBtn").style.display = "none";
|
|
document.getElementById("addUserBtn").style.display = "none";
|
|
}
|
|
}
|
|
|
|
function checkAuthentication() {
|
|
fetch("checkAuth.php")
|
|
.then(response => response.json())
|
|
.then(updateUI)
|
|
.catch(error => console.error("Error checking authentication:", error));
|
|
}
|
|
|
|
document.getElementById("authForm").addEventListener("submit", function (event) {
|
|
event.preventDefault();
|
|
|
|
const formData = {
|
|
username: document.getElementById("loginUsername").value.trim(),
|
|
password: document.getElementById("loginPassword").value.trim()
|
|
};
|
|
|
|
fetch("auth.php", {
|
|
method: "POST",
|
|
headers: { "Content-Type": "application/json" },
|
|
body: JSON.stringify(formData)
|
|
})
|
|
.then(response => response.json())
|
|
.then(data => {
|
|
if (data.success) {
|
|
updateUI({ authenticated: true, isAdmin: data.isAdmin }); // Update UI immediately
|
|
} else {
|
|
alert("Login failed: " + (data.error || "Unknown error"));
|
|
}
|
|
})
|
|
.catch(error => console.error("Error logging in:", error));
|
|
});
|
|
|
|
document.getElementById("logoutBtn").addEventListener("click", function () {
|
|
fetch("logout.php", { method: "POST" })
|
|
.then(() => window.location.reload(true))
|
|
.catch(error => console.error("Logout error:", error));
|
|
});
|
|
|
|
document.getElementById("addUserBtn").addEventListener("click", function () {
|
|
resetUserForm();
|
|
document.getElementById("addUserModal").style.display = "block";
|
|
});
|
|
|
|
document.getElementById("saveUserBtn").addEventListener("click", function () {
|
|
const newUsername = document.getElementById("newUsername").value.trim();
|
|
const newPassword = document.getElementById("newPassword").value.trim();
|
|
const isAdmin = document.getElementById("isAdmin").checked;
|
|
|
|
if (!newUsername || !newPassword) {
|
|
alert("Username and password are required!");
|
|
return;
|
|
}
|
|
|
|
fetch("addUser.php", {
|
|
method: "POST",
|
|
headers: { "Content-Type": "application/json" },
|
|
body: JSON.stringify({ username: newUsername, password: newPassword, isAdmin })
|
|
})
|
|
.then(response => response.json())
|
|
.then(data => {
|
|
if (data.success) {
|
|
alert("User added successfully!");
|
|
closeAddUserModal();
|
|
checkAuthentication(); // Refresh UI after adding user
|
|
} else {
|
|
alert("Error: " + (data.error || "Could not add user"));
|
|
}
|
|
})
|
|
.catch(error => console.error("Error adding user:", error));
|
|
});
|
|
|
|
document.getElementById("cancelUserBtn").addEventListener("click", function () {
|
|
closeAddUserModal();
|
|
});
|
|
|
|
function closeAddUserModal() {
|
|
document.getElementById("addUserModal").style.display = "none";
|
|
resetUserForm();
|
|
}
|
|
|
|
function resetUserForm() {
|
|
document.getElementById("newUsername").value = "";
|
|
document.getElementById("newPassword").value = "";
|
|
document.getElementById("isAdmin").checked = false;
|
|
}
|
|
});
|
|
</script>
|
|
|
|
</body>
|
|
</html>
|