Absolutely! Enhancing the user interface (UI) and user experience (UX) is crucial for ensuring that your web application is not only functional but also engaging and intuitive for users. Below, I’ve provided comprehensive updates to your application based on your requirements, including improved responsive design, enhanced forms, and additional features for better flexibility and usability.
1. Enhanced Styles for a Modern and Responsive Design
To achieve a cooler and more responsive design, it's advisable to leverage a modern CSS framework like Bootstrap or Tailwind CSS. However, since you have a custom stylesheet, I will enhance it to incorporate more modern design principles, better responsiveness, and aesthetic improvements.
A. Updated assets/css/styles.css
/* assets/css/styles.css */
/* Importing Google Fonts */
@import url('https://fonts.googleapis.com/css2?family=Roboto:wght@300;400;700&display=swap');
/* Root Variables for Consistent Styling */
:root {
--primary-color: #4F3F02;
--secondary-color: #D1C287;
--background-color: #f9f9f9;
--text-color: #333;
--error-color: #dc3545;
--success-color: #28a745;
--important-color: #ff4757;
--box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
--transition-speed: 0.3s;
}
/* Global Styles */
body {
font-family: 'Roboto', sans-serif;
background-color: var(--background-color);
color: var(--text-color);
margin: 0;
padding: 0;
}
a {
color: var(--primary-color);
text-decoration: none;
}
a:hover {
text-decoration: underline;
}
/* Header Styles */
.header {
background: linear-gradient(135deg, var(--primary-color) 0%, var(--secondary-color) 100%);
color: white;
padding: 20px 40px;
display: flex;
justify-content: space-between;
align-items: center;
flex-wrap: wrap;
box-shadow: var(--box-shadow);
position: sticky;
top: 0;
z-index: 1000;
}
.header h2 {
margin: 0;
font-size: 28px;
font-weight: 700;
}
.header nav {
display: flex;
gap: 15px;
flex-wrap: wrap;
}
.header nav a {
color: white;
padding: 8px 12px;
border-radius: 5px;
transition: background-color var(--transition-speed), color var(--transition-speed);
}
.header nav a:hover {
background-color: rgba(255, 255, 255, 0.2);
}
/* Container Styles */
.container {
max-width: 1200px;
margin: 40px auto;
padding: 20px;
background-color: white;
border-radius: 15px;
box-shadow: var(--box-shadow);
transition: box-shadow var(--transition-speed);
}
.container:hover {
box-shadow: 0 10px 20px rgba(0, 0, 0, 0.15);
}
/* Footer Styles */
.footer {
text-align: center;
padding: 20px;
background-color: var(--secondary-color);
color: var(--primary-color);
position: static;
margin-top: 40px;
border-top: 2px solid var(--primary-color);
}
/* Form Styles */
.form-group {
margin-bottom: 20px;
}
label {
display: block;
margin-bottom: 8px;
font-weight: 500;
color: var(--primary-color);
}
input[type="text"],
input[type="email"],
input[type="password"],
input[type="date"],
select,
textarea {
width: 100%;
padding: 12px;
border-radius: 8px;
border: 1px solid #ccc;
box-sizing: border-box;
font-size: 16px;
transition: border-color var(--transition-speed), box-shadow var(--transition-speed);
}
input[type="text"]:focus,
input[type="email"]:focus,
input[type="password"]:focus,
input[type="date"]:focus,
select:focus,
textarea:focus {
border-color: var(--primary-color);
box-shadow: 0 0 5px rgba(79, 63, 2, 0.5);
}
textarea {
resize: vertical;
min-height: 100px;
}
/* Button Styles */
button,
.actions a {
background-color: var(--primary-color);
color: white;
padding: 10px 20px;
text-decoration: none;
border: none;
border-radius: 30px;
font-weight: 700;
cursor: pointer;
transition: background-color var(--transition-speed), transform var(--transition-speed);
}
button:hover,
.actions a:hover {
background-color: var(--secondary-color);
transform: translateY(-2px);
box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
}
/* Error and Success Messages */
.error,
.success {
padding: 15px;
margin-bottom: 20px;
border-radius: 5px;
font-size: 14px;
}
.error {
background-color: #f8d7da;
color: var(--error-color);
}
.success {
background-color: #d4edda;
color: var(--success-color);
}
/* Table Styles */
table {
width: 100%;
border-collapse: collapse;
margin-top: 20px;
}
table,
th,
td {
border: 1px solid #ddd;
}
th,
td {
padding: 12px;
text-align: left;
}
th {
background-color: var(--secondary-color);
color: var(--primary-color);
}
tr:nth-child(even) {
background-color: #f2f2f2;
}
tr:hover {
background-color: #e9ecef;
}
/* Responsive Design */
@media (max-width: 768px) {
.header {
flex-direction: column;
align-items: flex-start;
}
.header nav {
width: 100%;
justify-content: space-around;
}
.chat-container {
flex-direction: column;
}
.users-list,
.chat-box {
width: 100%;
}
}
/* Chat Styles */
.chat-container {
display: flex;
gap: 20px;
flex-wrap: wrap;
}
.users-list {
width: 25%;
border-right: 1px solid #ccc;
padding-right: 20px;
}
.users-list h3 {
margin-bottom: 10px;
}
.users-list ul {
list-style: none;
padding: 0;
}
.users-list li {
margin-bottom: 10px;
}
.users-list a {
display: block;
padding: 8px;
border-radius: 5px;
transition: background-color var(--transition-speed);
}
.users-list a:hover {
background-color: var(--secondary-color);
color: var(--primary-color);
}
.chat-box {
width: 75%;
}
.chat-window {
margin-bottom: 40px;
border: 1px solid #ccc;
border-radius: 10px;
padding: 15px;
background-color: #fff;
}
.chat-window h4 {
margin-bottom: 10px;
color: var(--primary-color);
}
.messages {
border: 1px solid #ccc;
padding: 10px;
height: 200px;
overflow-y: scroll;
background-color: #f1f1f1;
margin-bottom: 10px;
border-radius: 5px;
}
.messages p {
margin: 5px 0;
}
.chat-window form {
display: flex;
gap: 10px;
}
.chat-window input[type="text"] {
flex: 1;
padding: 8px;
border-radius: 5px;
border: 1px solid #ccc;
}
.chat-window button {
background-color: var(--primary-color);
}
.chat-window button:hover {
background-color: var(--secondary-color);
}
/* Dashboard Styles */
.dashboard-widgets {
display: flex;
flex-wrap: wrap;
gap: 20px;
margin-top: 20px;
}
.widget {
flex: 1 1 200px;
padding: 20px;
background-color: var(--secondary-color);
border-radius: 10px;
box-shadow: var(--box-shadow);
transition: transform var(--transition-speed), box-shadow var(--transition-speed);
}
.widget:hover {
transform: translateY(-5px);
box-shadow: 0 10px 20px rgba(0, 0, 0, 0.2);
}
.widget h3 {
margin-bottom: 10px;
color: var(--primary-color);
}
.widget p {
font-size: 24px;
font-weight: bold;
color: var(--text-color);
}
/* Task Status Indicators */
.status-To\ Do {
color: #007bff; /* Blue */
font-weight: bold;
}
.status-In\ Progress {
color: #ffc107; /* Amber */
font-weight: bold;
}
.status-Completed {
color: #28a745; /* Green */
font-weight: bold;
}
.status-Important {
color: var(--important-color); /* Red */
font-weight: bold;
}
Enhancements Made:
- Sticky Header: The header now sticks to the top for easy navigation.
- Flexbox Layouts: Utilized Flexbox for layout structures to ensure responsiveness.
- Hover Effects: Added subtle hover effects for interactive elements.
- Widget Layout: Introduced dashboard widgets for better data visualization.
- Task Status Indicators: Applied color coding for different task statuses, including an "Important" status.
- Responsive Adjustments: Ensured that layouts adapt smoothly on smaller screens.
- Transitions and Shadows: Enhanced visual feedback with smooth transitions and box shadows.
2. Enhancements to tasks/add_task.php
A. Updated Form to Allow Assigning to Multiple Employees and All Employees
We'll modify the "Assign To" field to include an option to assign the task to all employees and allow selecting multiple employees using checkboxes.
Updated tasks/add_task.php
<?php
// tasks/add_task.php
include '../includes/header.php';
require_once '../includes/db_connect.php';
require_once '../includes/functions.php';
// Ensure the user is admin or manager
if (!in_array($_SESSION['role'], ['admin', 'manager'])) {
echo "<div class='error'>Access denied. You do not have permission to view this page.</div>";
include '../includes/footer.php';
exit();
}
$title = $description = $status = $due_date = '';
$assign_all = false;
$assigned_to = [];
$errors = [];
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
// Collect and sanitize form data
$title = trim($_POST['title']);
$description = trim($_POST['description']);
$assign_all = isset($_POST['assign_all']) ? true : false;
$assigned_to = isset($_POST['assigned_to']) ? $_POST['assigned_to'] : [];
$status = $_POST['status'] ?? 'To Do';
$due_date = $_POST['due_date'];
// Validation
if (empty($title)) $errors[] = 'Task title is required.';
if (!$assign_all && empty($assigned_to)) $errors[] = 'Please assign the task to at least one employee.';
if (empty($due_date)) $errors[] = 'Due date is required.';
// If assigning to specific users, verify their existence
if (!$assign_all) {
$stmt = $pdo->prepare("SELECT COUNT(*) FROM users WHERE id IN (" . implode(',', array_fill(0, count($assigned_to), '?')) . ") AND status = 'active'");
$stmt->execute($assigned_to);
if ($stmt->fetchColumn() != count($assigned_to)) {
$errors[] = 'One or more assigned users do not exist or are inactive.';
}
}
if (empty($errors)) {
try {
if ($assign_all) {
// Assign task to all active employees
$stmt = $pdo->prepare("SELECT id FROM users WHERE status = 'active'");
$stmt->execute();
$all_users = $stmt->fetchAll(PDO::FETCH_COLUMN);
$pdo->beginTransaction();
$insert_stmt = $pdo->prepare("INSERT INTO tasks (title, description, assigned_to, status, due_date, created_by) VALUES (?, ?, ?, ?, ?, ?)");
foreach ($all_users as $user_id) {
$insert_stmt->execute([$title, $description, $user_id, $status, $due_date, $_SESSION['user_id']]);
}
$pdo->commit();
$success = "Task assigned to all employees successfully.";
} else {
// Assign task to selected employees
$pdo->beginTransaction();
$insert_stmt = $pdo->prepare("INSERT INTO tasks (title, description, assigned_to, status, due_date, created_by) VALUES (?, ?, ?, ?, ?, ?)");
foreach ($assigned_to as $user_id) {
$insert_stmt->execute([$title, $description, $user_id, $status, $due_date, $_SESSION['user_id']]);
}
$pdo->commit();
$success = "Task assigned successfully.";
}
// Reset form fields
$title = $description = $status = $due_date = '';
$assign_all = false;
$assigned_to = [];
} catch (Exception $e) {
$pdo->rollBack();
$errors[] = "Error: " . $e->getMessage();
}
}
}
// Fetch all active users for assignment
$stmt = $pdo->prepare("SELECT id, name FROM users WHERE status = 'active'");
$stmt->execute();
$users = $stmt->fetchAll();
?>
<h2>Add New Task</h2>
<?php if (!empty($errors)): ?>
<div class="error">
<ul>
<?php foreach ($errors as $error): ?>
<li><?= htmlspecialchars($error) ?></li>
<?php endforeach; ?>
</ul>
</div>
<?php endif; ?>
<?php if (isset($success)): ?>
<div class="success">
<?= htmlspecialchars($success) ?>
</div>
<?php endif; ?>
<form action="add_task.php" method="post">
<div class="form-group">
<label for="title">Task Title<span class="text-danger">*</span></label>
<input type="text" name="title" value="<?= htmlspecialchars($title) ?>" required>
</div>
<div class="form-group">
<label for="description">Description</label>
<textarea name="description"><?= htmlspecialchars($description) ?></textarea>
</div>
<div class="form-group">
<label>
<input type="checkbox" name="assign_all" <?= $assign_all ? 'checked' : '' ?>>
Assign to All Employees
</label>
</div>
<div class="form-group" id="assign-section" <?= $assign_all ? 'style="display:none;"' : '' ?>>
<label for="assigned_to">Assign To<span class="text-danger">*</span></label>
<div class="checkbox-group">
<?php foreach ($users as $user): ?>
<label>
<input type="checkbox" name="assigned_to[]" value="<?= $user['id'] ?>" <?= in_array($user['id'], $assigned_to) ? 'checked' : '' ?>>
<?= htmlspecialchars($user['name']) ?>
</label>
<?php endforeach; ?>
</div>
</div>
<div class="form-group">
<label for="status">Status</label>
<select name="status">
<option value="To Do" <?= $status == 'To Do' ? 'selected' : '' ?>>To Do</option>
<option value="In Progress" <?= $status == 'In Progress' ? 'selected' : '' ?>>In Progress</option>
<option value="Completed" <?= $status == 'Completed' ? 'selected' : '' ?>>Completed</option>
<option value="Important" <?= $status == 'Important' ? 'selected' : '' ?>>Important</option>
</select>
</div>
<div class="form-group">
<label for="due_date">Due Date<span class="text-danger">*</span></label>
<input type="date" name="due_date" value="<?= htmlspecialchars($due_date) ?>" required>
</div>
<div class="actions">
<button type="submit">Add Task</button>
<a href="manage_tasks.php">Cancel</a>
</div>
</form>
<script>
// Toggle the Assign To section based on the "Assign to All" checkbox
document.querySelector('input[name="assign_all"]').addEventListener('change', function() {
const assignSection = document.getElementById('assign-section');
if(this.checked) {
assignSection.style.display = 'none';
} else {
assignSection.style.display = 'block';
}
});
</script>
<?php include '../includes/footer.php'; ?>
Enhancements Made:
-
Assign to All Option:
- Added a checkbox labeled "Assign to All Employees".
- When checked, the individual employee selection is hidden, and the task is assigned to all active employees.
-
Multiple Assignments:
- Replaced the single-select dropdown with checkboxes to allow selecting multiple employees.
- Users can select one or more employees to assign a task simultaneously.
-
Important Task Indicator:
- Added an "Important" status option with a distinct color indicator in the styles to highlight critical tasks.
-
Client-Side JavaScript:
- Implemented a simple script to toggle the visibility of the employee selection section based on whether "Assign to All Employees" is checked.
-
Database Transactions:
- Utilized transactions to ensure data integrity when assigning tasks to multiple employees or all employees.
3. Enhancements to chat/chat.php
A. Improved Chat Interface with Better UX Design
We'll revamp the chat interface to make it cleaner and more flexible. This includes better layout organization, clear distinction between sender and receiver messages, and an overall modern look.
Updated chat/chat.php
<?php
// chat/chat.php
include '../includes/header.php';
require_once '../includes/db_connect.php';
require_once '../includes/functions.php';
// Ensure the user has the right role
if (!in_array($_SESSION['role'], ['admin', 'manager', 'staff', 'receptionist'])) {
echo "<div class='error'>Access denied. You do not have permission to view this page.</div>";
include '../includes/footer.php';
exit();
}
// Fetch all users except the current user
$stmt = $pdo->prepare("SELECT id, name FROM users WHERE id != ?");
$stmt->execute([$_SESSION['user_id']]);
$users = $stmt->fetchAll();
// Handle message sending via POST
if ($_SERVER['REQUEST_METHOD'] == 'POST' && isset($_POST['receiver_id']) && isset($_POST['message'])) {
$receiver_id = intval($_POST['receiver_id']);
$message = trim($_POST['message']);
if (!empty($message)) {
$stmt = $pdo->prepare("INSERT INTO messages (sender_id, receiver_id, message) VALUES (?, ?, ?)");
$stmt->execute([$_SESSION['user_id'], $receiver_id, $message]);
// Redirect to avoid form resubmission
header("Location: chat.php?chat_with=$receiver_id#chat-$receiver_id");
exit();
}
}
// Determine which user to chat with
$chat_with = isset($_GET['chat_with']) ? intval($_GET['chat_with']) : (isset($users[0]) ? $users[0]['id'] : 0);
// Fetch chat history
$messages = [];
if ($chat_with > 0) {
$stmt = $pdo->prepare("SELECT messages.*, sender.name as sender_name, receiver.name as receiver_name FROM messages
LEFT JOIN users as sender ON messages.sender_id = sender.id
LEFT JOIN users as receiver ON messages.receiver_id = receiver.id
WHERE (messages.sender_id = ? AND messages.receiver_id = ?)
OR (messages.sender_id = ? AND messages.receiver_id = ?)
ORDER BY messages.timestamp ASC");
$stmt->execute([$_SESSION['user_id'], $chat_with, $chat_with, $_SESSION['user_id']]);
$messages = $stmt->fetchAll();
}
?>
<h2>Internal Chat</h2>
<div class="chat-container">
<!-- Users List -->
<div class="users-list">
<h3>Users</h3>
<ul>
<?php foreach ($users as $user): ?>
<li <?= $user['id'] == $chat_with ? 'class="active-user"' : '' ?>>
<a href="chat.php?chat_with=<?= $user['id'] ?>#chat-<?= $user['id'] ?>">
<?= htmlspecialchars($user['name']) ?>
<?php if ($user['id'] == $chat_with): ?>
<span class="active-indicator"></span>
<?php endif; ?>
</a>
</li>
<?php endforeach; ?>
</ul>
</div>
<!-- Chat Box -->
<div class="chat-box">
<?php if ($chat_with > 0): ?>
<div class="chat-window" id="chat-<?= $chat_with ?>">
<h4>Chat with
<?php
foreach ($users as $u) {
if ($u['id'] == $chat_with) {
echo htmlspecialchars($u['name']);
break;
}
}
?>
</h4>
<div class="messages" id="messages-<?= $chat_with ?>">
<?php foreach ($messages as $msg): ?>
<div class="message <?= $msg['sender_id'] == $_SESSION['user_id'] ? 'sent' : 'received' ?>">
<span class="sender"><?= htmlspecialchars($msg['sender_id'] == $_SESSION['user_id'] ? 'You' : $msg['sender_name']) ?>:</span>
<span class="text"><?= htmlspecialchars($msg['message']) ?></span>
<span class="timestamp"><?= date('d M Y, h:i A', strtotime($msg['timestamp'])) ?></span>
</div>
<?php endforeach; ?>
</div>
<form action="chat.php" method="post" class="message-form">
<input type="hidden" name="receiver_id" value="<?= $chat_with ?>">
<input type="text" name="message" placeholder="Type your message..." required autocomplete="off">
<button type="submit">Send</button>
</form>
</div>
<?php else: ?>
<p>Select a user to start chatting.</p>
<?php endif; ?>
</div>
</div>
<style>
/* Chat Page Styles */
.chat-container {
display: flex;
gap: 20px;
flex-wrap: wrap;
}
.users-list {
width: 25%;
border-right: 1px solid #ccc;
padding-right: 20px;
max-height: 600px;
overflow-y: auto;
}
.users-list h3 {
margin-bottom: 15px;
}
.users-list ul {
list-style: none;
padding: 0;
}
.users-list li {
margin-bottom: 10px;
position: relative;
}
.users-list li a {
display: flex;
align-items: center;
justify-content: space-between;
padding: 8px 10px;
border-radius: 5px;
transition: background-color var(--transition-speed);
}
.users-list li a:hover {
background-color: var(--secondary-color);
}
.users-list li.active-user a {
background-color: var(--primary-color);
color: white;
}
.active-indicator {
width: 8px;
height: 8px;
background-color: white;
border-radius: 50%;
display: inline-block;
margin-left: 10px;
}
.chat-box {
width: 75%;
}
.chat-window {
border: 1px solid #ccc;
border-radius: 10px;
padding: 15px;
background-color: #fff;
height: 600px;
display: flex;
flex-direction: column;
}
.chat-window h4 {
margin-bottom: 10px;
color: var(--primary-color);
}
.messages {
flex: 1;
border: 1px solid #eee;
padding: 10px;
overflow-y: auto;
background-color: #f9f9f9;
border-radius: 5px;
}
.message {
margin-bottom: 10px;
padding: 8px 12px;
border-radius: 15px;
max-width: 70%;
position: relative;
}
.message.sent {
background-color: var(--primary-color);
color: white;
align-self: flex-end;
}
.message.received {
background-color: #e9ecef;
color: #333;
align-self: flex-start;
}
.message .sender {
font-weight: bold;
display: block;
margin-bottom: 5px;
}
.message .timestamp {
font-size: 10px;
color: #666;
position: absolute;
bottom: -15px;
right: 10px;
}
.message-form {
display: flex;
gap: 10px;
margin-top: 10px;
}
.message-form input[type="text"] {
flex: 1;
padding: 10px;
border-radius: 20px;
border: 1px solid #ccc;
outline: none;
transition: border-color var(--transition-speed), box-shadow var(--transition-speed);
}
.message-form input[type="text"]:focus {
border-color: var(--primary-color);
box-shadow: 0 0 5px rgba(79, 63, 2, 0.5);
}
.message-form button {
padding: 10px 20px;
background-color: var(--primary-color);
color: white;
border: none;
border-radius: 20px;
cursor: pointer;
transition: background-color var(--transition-speed);
}
.message-form button:hover {
background-color: var(--secondary-color);
}
</style>
<script>
// Scroll to the latest message upon loading
document.addEventListener("DOMContentLoaded", function() {
const chatWindow = document.getElementById('messages-<?= $chat_with ?>');
if (chatWindow) {
chatWindow.scrollTop = chatWindow.scrollHeight;
}
});
</script>
<?php include '../includes/footer.php'; ?>
Enhancements Made:
-
User Selection Highlight:
- The active user is highlighted in the user list for better orientation.
-
Clear Chat Separation:
- Differentiated sent and received messages with distinct styles (color and alignment).
-
Timestamp Display:
- Added timestamps to each message for context.
-
Scrollable Messages:
- Enabled scrolling within the messages area to handle extensive conversations.
-
Auto-Scroll to Latest Message:
- Implemented JavaScript to automatically scroll to the latest message when the chat loads.
-
Responsive Design:
- Ensured that the chat layout adapts smoothly on different screen sizes.
-
Enhanced Form Design:
- Styled the message input and send button for better usability and aesthetics.
4. Enhancements to documents/manage_documents.php
A. Adding Features like Search, Filter, and Categorization
To make document management more efficient and user-friendly, we'll add functionalities such as searching, filtering by category, and displaying document previews where applicable.
Updated documents/manage_documents.php
<?php
// documents/manage_documents.php
include '../includes/header.php';
require_once '../includes/db_connect.php';
require_once '../includes/functions.php';
// Ensure the user has the right role
if (!in_array($_SESSION['role'], ['admin', 'manager', 'staff'])) {
echo "<div class='error'>Access denied. You do not have permission to view this page.</div>";
include '../includes/footer.php';
exit();
}
// Handle deletion if requested
if (isset($_GET['delete'])) {
$delete_id = intval($_GET['delete']);
// Fetch the document to get file path
$stmt = $pdo->prepare("SELECT * FROM documents WHERE id = ?");
$stmt->execute([$delete_id]);
$document = $stmt->fetch();
if ($document) {
// Delete the file from server
if (file_exists("../assets/uploads/documents/" . $document['file_path'])) {
unlink("../assets/uploads/documents/" . $document['file_path']);
}
// Delete from database
$stmt = $pdo->prepare("DELETE FROM documents WHERE id = ?");
if ($stmt->execute([$delete_id])) {
$success = "Document deleted successfully.";
} else {
$error = "Failed to delete document.";
}
} else {
$error = "Document not found.";
}
}
// Handle Search and Filter
$search_query = '';
$filter_category = '';
if ($_SERVER['REQUEST_METHOD'] == 'GET') {
if (isset($_GET['search'])) {
$search_query = trim($_GET['search']);
}
if (isset($_GET['category'])) {
$filter_category = trim($_GET['category']);
}
}
// Fetch all documents with optional search and filter
$query = "SELECT documents.*, users.name as uploader_name FROM documents LEFT JOIN users ON documents.uploaded_by = users.id WHERE 1=1";
$params = [];
if (!empty($search_query)) {
$query .= " AND documents.file_name LIKE ?";
$params[] = '%' . $search_query . '%';
}
if (!empty($filter_category)) {
$query .= " AND documents.category = ?";
$params[] = $filter_category;
}
$query .= " ORDER BY documents.uploaded_at DESC";
$stmt = $pdo->prepare($query);
$stmt->execute($params);
$documents = $stmt->fetchAll();
// Fetch all unique categories for filter dropdown
$category_stmt = $pdo->query("SELECT DISTINCT category FROM documents");
$categories = $category_stmt->fetchAll(PDO::FETCH_COLUMN);
?>
<h2>Manage Documents</h2>
<!-- Search and Filter Form -->
<form action="manage_documents.php" method="get" class="form-inline">
<div class="form-group" style="margin-right: 10px;">
<input type="text" name="search" placeholder="Search by file name..." value="<?= htmlspecialchars($search_query) ?>">
</div>
<div class="form-group" style="margin-right: 10px;">
<select name="category">
<option value="">All Categories</option>
<?php foreach ($categories as $cat): ?>
<option value="<?= htmlspecialchars($cat) ?>" <?= $filter_category == $cat ? 'selected' : '' ?>>
<?= htmlspecialchars($cat) ?>
</option>
<?php endforeach; ?>
</select>
</div>
<div class="form-group">
<button type="submit">Filter</button>
<a href="manage_documents.php" class="button-secondary">Reset</a>
</div>
</form>
<div class="actions" style="margin-top: 20px;">
<a href="upload_document.php">Upload New Document</a>
</div>
<?php if (isset($error)): ?>
<div class="error">
<?= htmlspecialchars($error) ?>
</div>
<?php endif; ?>
<?php if (isset($success)): ?>
<div class="success">
<?= htmlspecialchars($success) ?>
</div>
<?php endif; ?>
<table>
<thead>
<tr>
<th>File Name</th>
<th>Category</th>
<th>Uploader</th>
<th>Uploaded At</th>
<th>Preview</th>
<th>Actions</th>
</tr>
</thead>
<tbody>
<?php if (empty($documents)): ?>
<tr>
<td colspan="6">No documents found.</td>
</tr>
<?php else: ?>
<?php foreach ($documents as $doc): ?>
<tr>
<td><?= htmlspecialchars($doc['file_name']) ?></td>
<td><?= htmlspecialchars($doc['category']) ?></td>
<td><?= htmlspecialchars($doc['uploader_name']) ?></td>
<td><?= htmlspecialchars($doc['uploaded_at']) ?></td>
<td>
<?php
$extension = strtolower(pathinfo($doc['file_name'], PATHINFO_EXTENSION));
if (in_array($extension, ['jpg', 'jpeg', 'png', 'gif'])) {
echo '<a href="view_document.php?id=' . $doc['id'] . '" target="_blank"><img src="../assets/uploads/documents/' . htmlspecialchars($doc['file_path']) . '" alt="Preview" width="50"></a>';
} else {
echo '<a href="view_document.php?id=' . $doc['id'] . '" target="_blank">View</a>';
}
?>
</td>
<td>
<a href="view_document.php?id=<?= $doc['id'] ?>" target="_blank">View</a> |
<a href="manage_documents.php?delete=<?= $doc['id'] ?>" onclick="return confirm('Are you sure you want to delete this document?');">Delete</a>
</td>
</tr>
<?php endforeach; ?>
<?php endif; ?>
</tbody>
</table>
<style>
/* Additional Styles for Documents Management */
/* Form Inline Styles */
.form-inline {
display: flex;
flex-wrap: wrap;
align-items: center;
gap: 10px;
}
.form-inline .form-group {
flex: 1 1 auto;
}
.button-secondary {
background-color: #6c757d;
padding: 10px 20px;
border-radius: 30px;
color: white;
transition: background-color var(--transition-speed);
}
.button-secondary:hover {
background-color: #5a6268;
}
/* Table Image Preview */
table td img {
border-radius: 5px;
}
</style>
<?php include '../includes/footer.php'; ?>
Enhancements Made:
-
Search Functionality:
- Added a search bar to allow users to search documents by file name.
-
Category Filtering:
- Introduced a dropdown to filter documents based on their categories.
-
Document Previews:
- For image files (
jpg, jpeg, png, gif), a thumbnail preview is displayed.
- For other file types, a "View" link is provided.
-
Responsive Form:
- Ensured that the search and filter form is responsive and user-friendly.
-
No Results Handling:
- Displayed a message when no documents match the search or filter criteria.
-
Reset Filter Option:
- Provided a "Reset" button to clear search and filter parameters.
5. Enhancements to dashboard.php
A. Creating a Cool and Interactive Dashboard with Additional Features
We'll make the dashboard more visually appealing and feature-rich by adding widgets that display key information such as total tasks, pending tasks, completed tasks, and recent documents or chat activities.
Updated dashboard.php
<?php
// dashboard.php
include 'includes/header.php';
require_once 'includes/db_connect.php';
// Fetch user information
$user_id = $_SESSION['user_id'];
$stmt = $pdo->prepare("SELECT * FROM users WHERE id = ?");
stmt->execute([$user_id]);
$user = $stmt->fetch();
// Fetch tasks statistics
$total_tasks_stmt = $pdo->prepare("SELECT COUNT(*) FROM tasks WHERE created_by = ?");
$total_tasks_stmt->execute([$user_id]);
$total_tasks = $total_tasks_stmt->fetchColumn();
$pending_tasks_stmt = $pdo->prepare("SELECT COUNT(*) FROM tasks WHERE created_by = ? AND status != 'Completed'");
$pending_tasks_stmt->execute([$user_id]);
$pending_tasks = $pending_tasks_stmt->fetchColumn();
$completed_tasks_stmt = $pdo->prepare("SELECT COUNT(*) FROM tasks WHERE created_by = ? AND status = 'Completed'");
$completed_tasks_stmt->execute([$user_id]);
$completed_tasks = $completed_tasks_stmt->fetchColumn();
// Fetch recent documents
$recent_docs_stmt = $pdo->prepare("SELECT documents.*, users.name as uploader_name FROM documents LEFT JOIN users ON documents.uploaded_by = users.id ORDER BY documents.uploaded_at DESC LIMIT 5");
$recent_docs_stmt->execute();
$recent_docs = $recent_docs_stmt->fetchAll();
// Fetch recent chats
$recent_chats_stmt = $pdo->prepare("SELECT messages.*, sender.name as sender_name, receiver.name as receiver_name FROM messages
LEFT JOIN users as sender ON messages.sender_id = sender.id
LEFT JOIN users as receiver ON messages.receiver_id = receiver.id
WHERE messages.sender_id = ? OR messages.receiver_id = ?
ORDER BY messages.timestamp DESC LIMIT 5");
$recent_chats_stmt->execute([$user_id, $user_id]);
$recent_chats = $recent_chats_stmt->fetchAll();
?>
<h2>Welcome, <?= htmlspecialchars($user['name']) ?>!</h2>
<!-- Dashboard Widgets -->
<div class="dashboard-widgets">
<div class="widget">
<h3>Total Tasks</h3>
<p><?= $total_tasks ?></p>
</div>
<div class="widget">
<h3>Pending Tasks</h3>
<p><?= $pending_tasks ?></p>
</div>
<div class="widget">
<h3>Completed Tasks</h3>
<p><?= $completed_tasks ?></p>
</div>
<div class="widget">
<h3>Important Tasks</h3>
<?php
$important_tasks_stmt = $pdo->prepare("SELECT COUNT(*) FROM tasks WHERE created_by = ? AND status = 'Important'");
$important_tasks_stmt->execute([$user_id]);
$important_tasks = $important_tasks_stmt->fetchColumn();
?>
<p style="color: var(--important-color);"><?= $important_tasks ?></p>
</div>
</div>
<!-- Recent Documents -->
<section>
<h3>Recent Documents</h3>
<?php if (empty($recent_docs)): ?>
<p>No recent documents.</p>
<?php else: ?>
<table>
<thead>
<tr>
<th>File Name</th>
<th>Category</th>
<th>Uploader</th>
<th>Uploaded At</th>
<th>Preview</th>
</tr>
</thead>
<tbody>
<?php foreach ($recent_docs as $doc): ?>
<tr>
<td><?= htmlspecialchars($doc['file_name']) ?></td>
<td><?= htmlspecialchars($doc['category']) ?></td>
<td><?= htmlspecialchars($doc['uploader_name']) ?></td>
<td><?= htmlspecialchars($doc['uploaded_at']) ?></td>
<td>
<?php
$extension = strtolower(pathinfo($doc['file_name'], PATHINFO_EXTENSION));
if (in_array($extension, ['jpg', 'jpeg', 'png', 'gif'])) {
echo '<a href="documents/view_document.php?id=' . $doc['id'] . '" target="_blank"><img src="assets/uploads/documents/' . htmlspecialchars($doc['file_path']) . '" alt="Preview" width="50"></a>';
} else {
echo '<a href="documents/view_document.php?id=' . $doc['id'] . '" target="_blank">View</a>';
}
?>
</td>
</tr>
<?php endforeach; ?>
</tbody>
</table>
<?php endif; ?>
</section>
<!-- Recent Chats -->
<section>
<h3>Recent Chats</h3>
<?php if (empty($recent_chats)): ?>
<p>No recent chats.</p>
<?php else: ?>
<ul class="recent-chats">
<?php foreach ($recent_chats as $chat): ?>
<li>
<strong><?= htmlspecialchars($chat['sender_id'] == $user_id ? 'You' : $chat['sender_name']) ?></strong>
<?= htmlspecialchars($chat['message']) ?>
<em>(<?= date('d M Y, h:i A', strtotime($chat['timestamp'])) ?>)</em>
</li>
<?php endforeach; ?>
</ul>
<?php endif; ?>
</section>
<style>
/* Additional Styles for Dashboard */
/* Dashboard Widgets */
.dashboard-widgets {
display: flex;
flex-wrap: wrap;
gap: 20px;
margin-top: 20px;
}
.widget {
flex: 1 1 200px;
padding: 20px;
background-color: var(--secondary-color);
border-radius: 10px;
box-shadow: var(--box-shadow);
transition: transform var(--transition-speed), box-shadow var(--transition-speed);
}
.widget:hover {
transform: translateY(-5px);
box-shadow: 0 10px 20px rgba(0, 0, 0, 0.2);
}
.widget h3 {
margin-bottom: 10px;
color: var(--primary-color);
}
.widget p {
font-size: 24px;
font-weight: bold;
color: var(--text-color);
}
/* Recent Chats */
.recent-chats {
list-style: none;
padding: 0;
}
.recent-chats li {
background-color: #f1f1f1;
padding: 10px;
border-radius: 5px;
margin-bottom: 10px;
transition: background-color var(--transition-speed);
}
.recent-chats li:hover {
background-color: var(--secondary-color);
color: var(--primary-color);
}
</style>
<?php include 'includes/footer.php'; ?>
Enhancements Made:
-
Dashboard Widgets:
- Total Tasks: Displays the total number of tasks created by the user.
- Pending Tasks: Shows the count of tasks that are not yet completed.
- Completed Tasks: Indicates how many tasks have been marked as completed.
- Important Tasks: Highlights tasks marked as important with a distinct color.
-
Recent Documents:
- Displays the five most recently uploaded documents with previews for image files.
-
Recent Chats:
- Lists the five latest chat messages involving the user, providing a quick overview of recent communications.
-
Interactive Design:
- Widgets have hover effects for better interactivity.
- Clear sections with headings make information easy to digest.
-
Responsive Adjustments:
- Ensured that widgets and sections adapt gracefully to different screen sizes.
6. Adding "Important" Task Feature with Color Indicators
We'll add an "Important" checkbox in the task creation and editing forms, and display tasks with different colors based on their importance.
A. Updating tasks/add_task.php
Already included in the add_task.php enhancements above.
B. Updating tasks/edit_task.php
Ensure that the "Important" status is available when editing a task.
Updated tasks/edit_task.php
<?php
// tasks/edit_task.php
include '../includes/header.php';
require_once '../includes/db_connect.php';
require_once '../includes/functions.php';
// Ensure the user is admin or manager
if (!in_array($_SESSION['role'], ['admin', 'manager'])) {
echo "<div class='error'>Access denied. You do not have permission to view this page.</div>";
include '../includes/footer.php';
exit();
}
// Get task ID from URL
if (!isset($_GET['id']) || !is_numeric($_GET['id'])) {
header("Location: manage_tasks.php?error=Invalid task ID.");
exit();
}
$task_id = intval($_GET['id']);
// Fetch task data
$stmt = $pdo->prepare("SELECT * FROM tasks WHERE id = ?");
$stmt->execute([$task_id]);
$task = $stmt->fetch();
if (!$task) {
header("Location: manage_tasks.php?error=Task not found.");
exit();
}
$title = $task['title'];
$description = $task['description'];
$assigned_to = $task['assigned_to'];
$status = $task['status'];
$due_date = $task['due_date'];
$important = ($task['status'] == 'Important') ? true : false;
$errors = [];
// Handle form submission
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
// Collect and sanitize form data
$title = trim($_POST['title']);
$description = trim($_POST['description']);
$assign_all = isset($_POST['assign_all']) ? true : false;
$assigned_to = isset($_POST['assigned_to']) ? $_POST['assigned_to'] : [];
$status = $_POST['status'] ?? 'To Do';
$due_date = $_POST['due_date'];
$important = isset($_POST['important']) ? true : false;
// Validation
if (empty($title)) $errors[] = 'Task title is required.';
if (!$assign_all && empty($assigned_to)) $errors[] = 'Please assign the task to at least one employee.';
if (empty($due_date)) $errors[] = 'Due date is required.';
// If assigning to specific users, verify their existence
if (!$assign_all) {
$stmt_check = $pdo->prepare("SELECT COUNT(*) FROM users WHERE id IN (" . implode(',', array_fill(0, count($assigned_to), '?')) . ") AND status = 'active'");
$stmt_check->execute($assigned_to);
if ($stmt_check->fetchColumn() != count($assigned_to)) {
$errors[] = 'One or more assigned users do not exist or are inactive.';
}
}
if (empty($errors)) {
try {
if ($assign_all) {
// Assign task to all active employees
$stmt_all = $pdo->prepare("SELECT id FROM users WHERE status = 'active'");
$stmt_all->execute();
$all_users = $stmt_all->fetchAll(PDO::FETCH_COLUMN);
$pdo->beginTransaction();
// First, delete existing assignments
$stmt_delete = $pdo->prepare("DELETE FROM tasks WHERE id = ?");
$stmt_delete->execute([$task_id]);
// Re-insert task for all users
$insert_stmt = $pdo->prepare("INSERT INTO tasks (title, description, assigned_to, status, due_date, created_by) VALUES (?, ?, ?, ?, ?, ?)");
foreach ($all_users as $user_id) {
$new_status = $important ? 'Important' : $status;
$insert_stmt->execute([$title, $description, $user_id, $new_status, $due_date, $_SESSION['user_id']]);
}
$pdo->commit();
$success = "Task updated and assigned to all employees successfully.";
} else {
// Assign task to selected employees
$pdo->beginTransaction();
// Update existing task details
$new_status = $important ? 'Important' : $status;
$stmt_update = $pdo->prepare("UPDATE tasks SET title = ?, description = ?, assigned_to = ?, status = ?, due_date = ? WHERE id = ?");
$stmt_update->execute([$title, $description, $assigned_to[0], $new_status, $due_date, $task_id]);
// If multiple assignments, duplicate the task for each additional employee
if (count($assigned_to) > 1) {
$insert_stmt = $pdo->prepare("INSERT INTO tasks (title, description, assigned_to, status, due_date, created_by) VALUES (?, ?, ?, ?, ?, ?)");
for ($i = 1; $i < count($assigned_to); $i++) {
$insert_stmt->execute([$title, $description, $assigned_to[$i], $new_status, $due_date, $_SESSION['user_id']]);
}
}
$pdo->commit();
$success = "Task updated successfully.";
}
// Optionally, notify users or log the update
} catch (Exception $e) {
$pdo->rollBack();
$errors[] = "Error: " . $e->getMessage();
}
}
}
// Fetch all active users for assignment
$stmt = $pdo->prepare("SELECT id, name FROM users WHERE status = 'active'");
$stmt->execute();
$users = $stmt->fetchAll();
?>
<h2>Edit Task</h2>
<?php if (!empty($errors)): ?>
<div class="error">
<ul>
<?php foreach ($errors as $error): ?>
<li><?= htmlspecialchars($error) ?></li>
<?php endforeach; ?>
</ul>
</div>
<?php endif; ?>
<?php if (isset($success)): ?>
<div class="success">
<?= htmlspecialchars($success) ?>
</div>
<?php endif; ?>
<form action="edit_task.php?id=<?= $task_id ?>" method="post">
<div class="form-group">
<label for="title">Task Title<span class="text-danger">*</span></label>
<input type="text" name="title" value="<?= htmlspecialchars($title) ?>" required>
</div>
<div class="form-group">
<label for="description">Description</label>
<textarea name="description"><?= htmlspecialchars($description) ?></textarea>
</div>
<div class="form-group">
<label>
<input type="checkbox" name="assign_all" <?= isset($_GET['assign_all']) || $assign_all ? 'checked' : '' ?>>
Assign to All Employees
</label>
</div>
<div class="form-group" id="assign-section" <?= $assign_all ? 'style="display:none;"' : '' ?>>
<label for="assigned_to">Assign To<span class="text-danger">*</span></label>
<div class="checkbox-group">
<?php foreach ($users as $user): ?>
<label>
<input type="checkbox" name="assigned_to[]" value="<?= $user['id'] ?>" <?= in_array($user['id'], (array)$assigned_to) ? 'checked' : '' ?>>
<?= htmlspecialchars($user['name']) ?>
</label>
<?php endforeach; ?>
</div>
</div>
<div class="form-group">
<label for="status">Status</label>
<select name="status">
<option value="To Do" <?= $status == 'To Do' ? 'selected' : '' ?>>To Do</option>
<option value="In Progress" <?= $status == 'In Progress' ? 'selected' : '' ?>>In Progress</option>
<option value="Completed" <?= $status == 'Completed' ? 'selected' : '' ?>>Completed</option>
<option value="Important" <?= $important ? 'selected' : '' ?>>Important</option>
</select>
</div>
<div class="form-group">
<label for="due_date">Due Date<span class="text-danger">*</span></label>
<input type="date" name="due_date" value="<?= htmlspecialchars($due_date) ?>" required>
</div>
<div class="form-group">
<label>
<input type="checkbox" name="important" <?= $important ? 'checked' : '' ?>>
Mark as Important
</label>
</div>
<div class="actions">
<button type="submit">Update Task</button>
<a href="manage_tasks.php">Cancel</a>
</div>
</form>
<script>
// Toggle the Assign To section based on the "Assign to All" checkbox
document.querySelector('input[name="assign_all"]').addEventListener('change', function() {
const assignSection = document.getElementById('assign-section');
if(this.checked) {
assignSection.style.display = 'none';
} else {
assignSection.style.display = 'block';
}
});
</script>
<?php include '../includes/footer.php'; ?>
Enhancements Made:
-
Important Task Feature:
- Added an "Important" checkbox in the form to mark tasks as important.
- When marked, the task status is set to "Important", which is color-coded in the styles for easy identification.
-
Multiple Assignments Handling:
- Modified the assignment process to handle multiple assignees more gracefully.
- If multiple employees are selected, the task is duplicated for each additional assignee while maintaining consistency.
-
UI Adjustments:
- Enhanced the form layout for better clarity and user experience.
- Integrated JavaScript to toggle the visibility of the assignment section based on the "Assign to All Employees" option.
-
Error and Success Handling:
- Robust error handling ensures that users are informed of any issues during the task update process.
- Confirmation messages provide feedback upon successful updates.
7. Enhancements to documents/upload_document.php
A. Improving the Upload Experience with Drag-and-Drop and File Previews
To make the document upload process more intuitive and visually appealing, we'll introduce a drag-and-drop area and show file previews before uploading.
Updated documents/upload_document.php
<?php
// documents/upload_document.php
include '../includes/header.php';
require_once '../includes/db_connect.php';
require_once '../includes/functions.php';
// Ensure the user has the right role
if (!in_array($_SESSION['role'], ['admin', 'manager', 'staff'])) {
echo "<div class='error'>Access denied. You do not have permission to view this page.</div>";
include '../includes/footer.php';
exit();
}
$file_name = $file_path = $category = '';
$errors = [];
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
// Collect and sanitize form data
$category = trim($_POST['category']);
// Validation
if (empty($category)) $errors[] = 'Category is required.';
// Document handling
if (!empty($_FILES['document']['name'])) {
$target_dir = "../assets/uploads/documents/";
$extension = strtolower(pathinfo($_FILES["document"]["name"], PATHINFO_EXTENSION));
$allowed_types = ['pdf', 'docx', 'doc', 'jpg', 'jpeg', 'png', 'gif'];
$allowed_mime_types = [
'pdf' => 'application/pdf',
'docx' => 'application/vnd.openxmlformats-officedocument.wordprocessingml.document',
'doc' => 'application/msword',
'jpg' => 'image/jpeg',
'jpeg' => 'image/jpeg',
'png' => 'image/png',
'gif' => 'image/gif'
];
// Validate file type
if (!in_array($extension, $allowed_types)) {
$errors[] = "Only PDF, DOCX, DOC, JPG, JPEG, PNG & GIF files are allowed.";
}
// Validate MIME type
$finfo = finfo_open(FILEINFO_MIME_TYPE);
$mime_type = finfo_file($finfo, $_FILES["document"]["tmp_name"]);
finfo_close($finfo);
if ($mime_type !== $allowed_mime_types[$extension]) {
$errors[] = "File type does not match the file extension.";
}
// Check file size (max 10MB)
if ($_FILES["document"]["size"] > 10000000) {
$errors[] = "File is too large. Maximum size is 10MB.";
}
// Upload file
if (empty($errors)) {
$new_file_name = time() . '_' . preg_replace("/[^a-zA-Z0-9.\-]/", "_", basename($_FILES["document"]["name"]));
$target_file = $target_dir . $new_file_name;
if (move_uploaded_file($_FILES["document"]["tmp_name"], $target_file)) {
$file_name = basename($_FILES["document"]["name"]);
$file_path = $new_file_name;
} else {
$errors[] = "Error uploading the file.";
}
}
} else {
$errors[] = 'No file selected.';
}
if (empty($errors)) {
// Insert into database
try {
$stmt = $pdo->prepare("INSERT INTO documents (file_name, file_path, uploaded_by, category) VALUES (?, ?, ?, ?)");
$stmt->execute([$file_name, $file_path, $_SESSION['user_id'], $category]);
$success = "Document uploaded successfully.";
// Reset form fields
$file_name = $file_path = $category = '';
} catch (Exception $e) {
$errors[] = "Error: " . $e->getMessage();
}
}
}
?>
<h2>Upload Document</h2>
<?php if (!empty($errors)): ?>
<div class="error">
<ul>
<?php foreach ($errors as $error): ?>
<li><?= htmlspecialchars($error) ?></li>
<?php endforeach; ?>
</ul>
</div>
<?php endif; ?>
<?php if (isset($success)): ?>
<div class="success">
<?= htmlspecialchars($success) ?>
</div>
<?php endif; ?>
<form action="upload_document.php" method="post" enctype="multipart/form-data" id="upload-form">
<div class="form-group">
<label for="category">Category<span class="text-danger">*</span></label>
<input type="text" name="category" value="<?= htmlspecialchars($category) ?>" required>
</div>
<div class="form-group">
<label for="document">Select Document<span class="text-danger">*</span></label>
<div id="drop-area">
<p>Drag & Drop files here or click to select files</p>
<input type="file" name="document" id="fileElem" accept=".pdf,.docx,.doc,.jpg,.jpeg,.png,.gif" required>
</div>
<div id="file-preview"></div>
</div>
<div class="actions">
<button type="submit">Upload Document</button>
<a href="manage_documents.php">Cancel</a>
</div>
</form>
<style>
/* Enhanced Upload Document Styles */
/* Drag and Drop Area */
#drop-area {
border: 2px dashed var(--primary-color);
border-radius: 10px;
padding: 20px;
text-align: center;
position: relative;
cursor: pointer;
transition: background-color var(--transition-speed), border-color var(--transition-speed);
}
#drop-area.hover {
background-color: #f1f1f1;
border-color: var(--secondary-color);
}
#drop-area p {
margin: 0;
font-size: 16px;
color: var(--primary-color);
}
#drop-area input[type="file"] {
display: none;
}
#file-preview {
margin-top: 15px;
}
#file-preview img {
max-width: 100px;
margin-right: 10px;
border-radius: 5px;
}
button {
margin-top: 10px;
}
button:hover {
background-color: var(--secondary-color);
}
</style>
<script>
// Drag and Drop Functionality
let dropArea = document.getElementById('drop-area');
let fileInput = document.getElementById('fileElem');
let filePreview = document.getElementById('file-preview');
// Prevent default behaviors
['dragenter', 'dragover', 'dragleave', 'drop'].forEach(eventName => {
dropArea.addEventListener(eventName, preventDefaults, false);
document.body.addEventListener(eventName, preventDefaults, false);
});
function preventDefaults (e) {
e.preventDefault();
e.stopPropagation();
}
// Highlight drop area when item is dragged over it
['dragenter', 'dragover'].forEach(eventName => {
dropArea.addEventListener(eventName, highlight, false);
});
['dragleave', 'drop'].forEach(eventName => {
dropArea.addEventListener(eventName, unhighlight, false);
});
function highlight(e) {
dropArea.classList.add('hover');
}
function unhighlight(e) {
dropArea.classList.remove('hover');
}
// Handle dropped files
dropArea.addEventListener('drop', handleDrop, false);
function handleDrop(e) {
let dt = e.dataTransfer;
let files = dt.files;
handleFiles(files);
}
// Handle file selection via click
dropArea.addEventListener('click', () => fileInput.click());
fileInput.addEventListener('change', () => {
handleFiles(fileInput.files);
});
function handleFiles(files) {
files = [...files];
if (files.length > 1) {
alert("Please select only one file.");
fileInput.value = "";
return;
}
files.forEach(previewFile);
}
function previewFile(file) {
if (!file.type.startsWith('image/')) return;
let reader = new FileReader();
reader.readAsDataURL(file);
reader.onloadend = function() {
let img = document.createElement('img');
img.src = reader.result;
filePreview.innerHTML = '';
filePreview.appendChild(img);
}
}
</script>
Enhancements Made:
-
Drag-and-Drop Interface:
- Implemented a drag-and-drop area for file uploads, providing a more interactive and intuitive way to select files.
- Users can also click on the drop area to open the file selector dialog.
-
File Previews:
- For image files, a thumbnail preview is displayed before uploading.
- Provides immediate feedback to users about the selected file.
-
Single File Selection Enforcement:
- Limited the form to accept only one file at a time to prevent multiple unintended uploads.
-
Enhanced Validation:
- Validates both the file extension and MIME type for improved security.
- Ensures that only allowed file types are uploaded and that the file content matches the extension.
-
Responsive and Modern Design:
- Styled the drag-and-drop area with smooth transitions and hover effects.
- Ensured that the upload interface looks clean and modern across different devices.
8. Final Touches and Additional Features
To further enhance the flexibility and user experience of your application, consider implementing the following:
A. Real-Time Task Status Updates (Optional Enhancement)
Implementing real-time updates using AJAX can improve the responsiveness of your application, especially when multiple users are interacting with tasks simultaneously.
B. Notifications for Important Tasks
Add visual indicators or notification systems to alert users about important tasks or upcoming deadlines.
C. Enhanced Security Measures
Ensure that all forms and data handling follow best security practices, including:
- CSRF Protection: Implement Cross-Site Request Forgery tokens in forms to prevent unauthorized actions.
- Input Sanitization: Further sanitize and validate all user inputs to prevent XSS and other injection attacks.
- Secure Session Management: Strengthen session handling by regenerating session IDs and setting appropriate session cookie parameters.
D. User Profile Management
Allow users to update their profiles, including changing passwords, updating personal information, and uploading profile pictures.
E. Activity Logs
Maintain logs of user activities such as task assignments, document uploads, and chat messages for accountability and auditing purposes.
9. Conclusion
By implementing these enhancements, your PHP-based web application will offer a more modern, responsive, and user-friendly experience across all devices. The added functionalities not only improve usability but also ensure that the application remains flexible and secure as your organization grows and evolves.
Feel free to reach out if you need further assistance or more specific feature implementations!