|
Server : LiteSpeed System : Linux terra.hostitbro.com 5.14.0-611.54.3.el9_7.x86_64 #1 SMP PREEMPT_DYNAMIC Thu May 7 16:31:24 EDT 2026 x86_64 User : outerorb ( 1091) PHP Version : 8.1.34 Disable Function : mail Directory : /home2/outerorb/emp.outerorbittech.in/employee/ | |
|
Path: /home2/outerorb/emp.outerorbittech.in/employee/document_upload.php
Size: 16.65 KB
Permissions: 0666
<?php
require_once '../config/config.php';
require_once '../includes/helpers.php';
// Check if user is logged in and is an employee
session_start();
if (!isset($_SESSION['employee_id']) || $_SESSION['role'] !== 'employee') {
header('Location: ../index.php');
exit;
}
$employee_id = $_SESSION['employee_id'];
$profile = get_employee_profile($employee_id);
if (!$profile) {
header('Location: ../index.php');
exit;
}
$message = '';
$error = '';
// Handle document upload
if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_FILES['document'])) {
$file = $_FILES['document'];
$document_type = $_POST['document_type'] ?? 'Other';
// Validate file
$allowed_extensions = ['pdf', 'jpg', 'jpeg', 'png', 'doc', 'docx'];
$file_ext = strtolower(pathinfo($file['name'], PATHINFO_EXTENSION));
$max_size = 5 * 1024 * 1024; // 5MB
if ($file['error'] !== UPLOAD_ERR_OK) {
$error = "File upload error. Please try again.";
} elseif (!in_array($file_ext, $allowed_extensions)) {
$error = "Invalid file type. Allowed types: " . implode(', ', $allowed_extensions);
} elseif ($file['size'] > $max_size) {
$error = "File size exceeds 5MB limit.";
} else {
// Generate unique filename
$unique_name = bin2hex(random_bytes(16)) . '.' . $file_ext;
$upload_path = '../uploads/' . $unique_name;
// Create uploads directory if doesn't exist
if (!is_dir('../uploads')) {
mkdir('../uploads', 0755, true);
}
if (move_uploaded_file($file['tmp_name'], $upload_path)) {
// Store in database
$pdo = db();
$sql = "
INSERT INTO employee_documents
(employee_id, document_type, file_name, original_name, file_size, uploaded_at)
VALUES (?, ?, ?, ?, ?, NOW())
";
try {
$stmt = $pdo->prepare($sql);
$stmt->execute([
$employee_id,
$document_type,
$unique_name,
$file['name'],
$file['size']
]);
$message = "Document uploaded successfully!";
} catch (Exception $e) {
unlink($upload_path);
$error = "Failed to save document. Please try again.";
}
} else {
$error = "Failed to upload file. Please try again.";
}
}
}
// Fetch uploaded documents
$pdo = db();
$sql = "
SELECT id, document_type, original_name, file_size, uploaded_at, updated_at
FROM employee_documents
WHERE employee_id = ? AND deleted_at IS NULL
ORDER BY uploaded_at DESC
";
$stmt = $pdo->prepare($sql);
$stmt->execute([$employee_id]);
$documents = $stmt->fetchAll();
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document Upload - HR Portal</title>
<link rel="stylesheet" href="../assets/css/style.css">
<link rel="stylesheet" href="../assets/css/polish.css">
<style>
.upload-zone {
background: rgba(255, 255, 255, 0.05);
backdrop-filter: blur(10px);
border: 2px dashed rgba(255, 255, 255, 0.2);
border-radius: 12px;
padding: 2rem;
text-align: center;
margin-bottom: 2rem;
transition: all 0.3s ease;
cursor: pointer;
}
.upload-zone:hover {
border-color: rgba(37, 99, 235, 0.5);
background: rgba(37, 99, 235, 0.05);
}
.upload-zone.dragover {
border-color: #2563eb;
background: rgba(37, 99, 235, 0.1);
}
.upload-icon {
font-size: 3rem;
margin-bottom: 1rem;
}
.upload-text {
color: #cbd5e1;
margin-bottom: 0.5rem;
}
.upload-hint {
color: #a0aec0;
font-size: 0.875rem;
}
.document-form {
background: rgba(255, 255, 255, 0.05);
backdrop-filter: blur(10px);
padding: 1.5rem;
border-radius: 12px;
border: 1px solid rgba(255, 255, 255, 0.1);
margin-bottom: 2rem;
}
.form-row {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 1rem;
}
@media (max-width: 768px) {
.form-row {
grid-template-columns: 1fr;
}
}
.document-list {
background: rgba(255, 255, 255, 0.05);
backdrop-filter: blur(10px);
border-radius: 12px;
border: 1px solid rgba(255, 255, 255, 0.1);
overflow: hidden;
}
.document-item {
padding: 1rem;
border-bottom: 1px solid rgba(255, 255, 255, 0.05);
display: flex;
justify-content: space-between;
align-items: center;
}
.document-item:last-child {
border-bottom: none;
}
.document-info {
flex: 1;
}
.document-name {
color: #e2e8f0;
font-weight: 500;
margin-bottom: 0.25rem;
}
.document-meta {
color: #a0aec0;
font-size: 0.875rem;
}
.document-type {
display: inline-block;
padding: 0.25rem 0.75rem;
background: rgba(37, 99, 235, 0.2);
color: #2563eb;
border-radius: 6px;
font-size: 0.75rem;
font-weight: 600;
margin-right: 0.5rem;
}
.document-actions {
display: flex;
gap: 0.5rem;
}
.btn-icon {
padding: 0.5rem;
font-size: 1rem;
cursor: pointer;
background: none;
border: none;
color: #cbd5e1;
transition: all 0.3s ease;
}
.btn-icon:hover {
color: #2563eb;
}
#fileInput {
display: none;
}
.empty-state {
text-align: center;
padding: 2rem;
color: #a0aec0;
}
</style>
</head>
<body>
<div class="main-container">
<!-- Sidebar -->
<aside class="sidebar">
<div class="sidebar-header">
<h2>HR Portal</h2>
</div>
<nav class="sidebar-nav">
<a href="dashboard.php" class="nav-link">
<span><i class="fas fa-chart-line"></i> Dashboard</span>
</a>
<a href="profile.php" class="nav-link">
<span><i class="fas fa-user"></i> My Profile</span>
</a>
<a href="attendance.php" class="nav-link">
<span><i class="fas fa-list"></i> Attendance</span>
</a>
<a href="leave.php" class="nav-link">
<span><i class="fas fa-pen"></i> Leave Request</span>
</a>
<a href="payslips.php" class="nav-link">
<span><i class="fas fa-wallet"></i> Payslips</span>
</a>
<a href="document_upload.php" class="nav-link active">
<span><i class="fas fa-file"></i> Documents</span>
</a>
<a href="#" class="nav-link" onclick="logout()">
<span><i class="fas fa-sign-out-alt"></i> Logout</span>
</a>
</nav>
</aside>
<!-- Main Content -->
<div class="main-content">
<!-- Top Bar -->
<div class="top-bar">
<div class="top-bar-left">
<h1>Document Management</h1>
</div>
<div class="top-bar-right">
<div class="notification-bell">
<button id="notificationBell" class="bell-button">
<i class="fas fa-bell"></i>
<span class="badge" id="unreadCount">0</span>
</button>
<div id="notificationDropdown" class="notification-dropdown" style="display: none;">
<div class="dropdown-header">Notifications</div>
<div id="notificationList" class="notification-list">
<div class="notification-item">Loading...</div>
</div>
</div>
</div>
<span class="user-greeting">Welcome, <?php echo htmlspecialchars($profile['first_name']); ?></span>
</div>
</div>
<!-- Content Area -->
<div class="content">
<!-- Messages -->
<?php if ($message): ?>
<div class="alert alert-success" role="alert">
โ <?php echo htmlspecialchars($message); ?>
</div>
<?php endif; ?>
<?php if ($error): ?>
<div class="alert alert-danger" role="alert">
โ <?php echo htmlspecialchars($error); ?>
</div>
<?php endif; ?>
<!-- Upload Zone -->
<div class="upload-zone" id="uploadZone" onclick="document.getElementById('fileInput').click()">
<div class="upload-icon">๐ค</div>
<div class="upload-text">Click to upload or drag and drop</div>
<div class="upload-hint">PDF, JPG, PNG, DOC, DOCX (up to 5MB)</div>
</div>
<!-- Document Form -->
<form method="POST" enctype="multipart/form-data" class="document-form" id="documentForm">
<input type="file" id="fileInput" name="document" accept=".pdf,.jpg,.jpeg,.png,.doc,.docx" onchange="handleFileSelect(event)">
<div class="form-row">
<div class="form-group">
<label for="document_type">Document Type:</label>
<select id="document_type" name="document_type" class="form-control" required>
<option value="">Select a type...</option>
<option value="Resume">Resume</option>
<option value="Certification">Certification</option>
<option value="License">License</option>
<option value="Education">Education Certificate</option>
<option value="Medical">Medical Report</option>
<option value="Other">Other</option>
</select>
</div>
<div class="form-group">
<label for="file_name">File Selected:</label>
<input type="text" id="file_name" class="form-control" readonly placeholder="No file selected">
</div>
</div>
<div class="form-actions">
<button type="submit" class="btn btn-primary" id="uploadBtn" disabled>Upload Document</button>
<button type="button" class="btn btn-secondary" onclick="clearForm()">Clear</button>
</div>
</form>
<!-- Documents List -->
<h2>My Documents</h2>
<div class="document-list">
<?php if (count($documents) > 0): ?>
<?php foreach ($documents as $doc): ?>
<div class="document-item">
<div class="document-info">
<div class="document-name">
<i class="fas fa-file"></i> <?php echo htmlspecialchars($doc['original_name']); ?>
</div>
<div class="document-meta">
<span class="document-type"><?php echo htmlspecialchars($doc['document_type']); ?></span>
<?php echo round($doc['file_size'] / 1024, 2); ?> KB รขโฌยข
Uploaded <?php echo date('d M Y', strtotime($doc['uploaded_at'])); ?>
</div>
</div>
<div class="document-actions">
<button type="button" class="btn-icon" title="Download" onclick="downloadDocument('<?php echo htmlspecialchars($doc['original_name']); ?>')">
<i class="fas fa-download"></i>
</button>
<button type="button" class="btn-icon" title="Delete" onclick="deleteDocument(<?php echo $doc['id']; ?>)">
<i class="fas fa-trash"></i>
</button>
</div>
</div>
<?php endforeach; ?>
<?php else: ?>
<div class="empty-state">
<p>No documents uploaded yet.</p>
</div>
<?php endif; ?>
</div>
</div>
</div>
</div>
<script src="../assets/js/app.js"></script>
<script>
function logout() {
if (confirm('Are you sure you want to logout?')) {
fetch('../admin/logout.php').then(() => {
window.location.href = '../index.php';
});
}
}
const uploadZone = document.getElementById('uploadZone');
const fileInput = document.getElementById('fileInput');
const fileNameInput = document.getElementById('file_name');
const uploadBtn = document.getElementById('uploadBtn');
// Drag and drop
uploadZone.addEventListener('dragover', (e) => {
e.preventDefault();
uploadZone.classList.add('dragover');
});
uploadZone.addEventListener('dragleave', () => {
uploadZone.classList.remove('dragover');
});
uploadZone.addEventListener('drop', (e) => {
e.preventDefault();
uploadZone.classList.remove('dragover');
const files = e.dataTransfer.files;
if (files.length > 0) {
fileInput.files = files;
handleFileSelect({ target: { files: files } });
}
});
function handleFileSelect(event) {
const files = event.target.files;
if (files.length > 0) {
fileNameInput.value = files[0].name;
uploadBtn.disabled = false;
} else {
fileNameInput.value = '';
uploadBtn.disabled = true;
}
}
function clearForm() {
fileInput.value = '';
fileNameInput.value = '';
uploadBtn.disabled = true;
document.getElementById('document_type').value = '';
}
function downloadDocument(filename) {
alert('Download feature coming soon for: ' + filename);
}
function deleteDocument(id) {
if (confirm('Are you sure you want to delete this document?')) {
// Implement delete functionality
alert('Delete feature coming soon for document ID: ' + id);
}
}
// Load notifications
const notificationBell = document.getElementById('notificationBell');
const notificationDropdown = document.getElementById('notificationDropdown');
notificationBell.addEventListener('click', function(e) {
e.stopPropagation();
notificationDropdown.style.display = notificationDropdown.style.display === 'none' ? 'block' : 'none';
});
document.addEventListener('click', function() {
notificationDropdown.style.display = 'none';
});
</script>
</body>
</html>