|
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/admin/ | |
|
Path: /home2/outerorb/emp.outerorbittech.in/admin/backups.php
Size: 15.79 KB
Permissions: 0666
<?php
require_once '../config/config.php';
require_once '../includes/helpers.php';
// Check if user is logged in and is admin
session_start();
if (!isset($_SESSION['employee_id']) || $_SESSION['role'] !== 'admin') {
header('Location: ../index.php');
exit;
}
$admin_profile = get_employee_profile($_SESSION['employee_id']);
$message = '';
$error = '';
// Handle backup actions
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
$action = $_POST['action'] ?? '';
if ($action === 'create_backup') {
$backup_file = create_database_backup();
if ($backup_file) {
$message = "Backup created successfully: $backup_file";
log_activity($_SESSION['employee_id'], 'create_backup', 'system_backups', null, "Backup: $backup_file");
} else {
$error = "Failed to create backup. Please check permissions.";
}
} elseif ($action === 'delete_backup') {
$backup_id = (int)($_POST['backup_id'] ?? 0);
if (delete_backup($backup_id)) {
$message = "Backup deleted successfully!";
log_activity($_SESSION['employee_id'], 'delete_backup', 'system_backups', $backup_id, "Backup deleted");
} else {
$error = "Failed to delete backup.";
}
}
}
$backups = get_backups(20);
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Backups - Admin Panel</title>
<link rel="stylesheet" href="../assets/css/style.css">
<link rel="stylesheet" href="../assets/css/polish.css">
<style>
.backup-info {
background: rgba(37, 99, 235, 0.1);
border: 1px solid rgba(37, 99, 235, 0.3);
border-radius: 12px;
padding: 1.5rem;
margin-bottom: 2rem;
border-left: 4px solid #2563eb;
}
.backup-info-title {
font-weight: 600;
margin-bottom: 0.5rem;
color: #e2e8f0;
}
.backup-info-text {
color: #cbd5e1;
font-size: 0.875rem;
line-height: 1.5;
}
.backup-button {
margin-top: 1rem;
}
.backups-table {
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;
}
.backups-table table {
width: 100%;
border-collapse: collapse;
}
.backups-table thead {
background: rgba(255, 255, 255, 0.08);
}
.backups-table th {
padding: 1rem;
text-align: left;
color: #cbd5e1;
font-size: 0.875rem;
font-weight: 600;
border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}
.backups-table td {
padding: 1rem;
border-bottom: 1px solid rgba(255, 255, 255, 0.05);
color: #e2e8f0;
}
.backups-table tbody tr:hover {
background: rgba(255, 255, 255, 0.03);
}
.backup-filename {
font-family: monospace;
color: #2563eb;
word-break: break-word;
}
.backup-size {
color: #cbd5e1;
}
.backup-date {
color: #a0aec0;
font-size: 0.875rem;
}
.backup-actions {
display: flex;
gap: 0.5rem;
}
.btn-download {
padding: 0.4rem 0.8rem;
font-size: 0.75rem;
border: none;
border-radius: 4px;
cursor: pointer;
transition: all 0.3s ease;
background: rgba(16, 185, 129, 0.2);
color: #10b981;
}
.btn-download:hover {
background: #10b981;
color: white;
}
.btn-delete {
padding: 0.4rem 0.8rem;
font-size: 0.75rem;
border: none;
border-radius: 4px;
cursor: pointer;
transition: all 0.3s ease;
background: rgba(239, 68, 68, 0.2);
color: #ef4444;
}
.btn-delete:hover {
background: #ef4444;
color: white;
}
.empty-state {
text-align: center;
padding: 2rem;
color: #a0aec0;
}
.stats-grid {
display: grid;
grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
gap: 1rem;
margin-bottom: 2rem;
}
.stat-card {
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);
text-align: center;
}
.stat-label {
color: #a0aec0;
font-size: 0.875rem;
text-transform: uppercase;
letter-spacing: 0.05em;
}
.stat-value {
font-size: 1.75rem;
font-weight: bold;
color: #2563eb;
margin-top: 0.5rem;
}
@media (max-width: 768px) {
.backups-table table {
font-size: 0.875rem;
}
.backups-table th,
.backups-table td {
padding: 0.75rem;
}
.backup-actions {
flex-direction: column;
}
.btn-download,
.btn-delete {
width: 100%;
}
}
</style>
</head>
<body>
<div class="main-container">
<!-- Sidebar -->
<aside class="sidebar">
<div class="sidebar-header">
<h2>HR Admin</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="users.php" class="nav-link">
<span><i class="fas fa-users"></i> User Management</span>
</a>
<a href="settings.php" class="nav-link">
<span>⚙️ Settings</span>
</a>
<a href="backups.php" class="nav-link active">
<span><i class="fas fa-database"></i> Backups</span>
</a>
<a href="activity-logs.php" class="nav-link">
<span><i class="fas fa-book"></i> Activity Logs</span>
</a>
<a href="logout.php" class="nav-link">
<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>Database Backups</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($admin_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">
<i class="fas fa-times"></i> <?php echo htmlspecialchars($error); ?>
</div>
<?php endif; ?>
<!-- Backup Statistics -->
<div class="stats-grid">
<div class="stat-card">
<div class="stat-label">Total Backups</div>
<div class="stat-value"><?php echo count($backups); ?></div>
</div>
<div class="stat-card">
<div class="stat-label">Last Backup</div>
<div class="stat-value">
<?php
if (count($backups) > 0) {
echo date('d M Y', strtotime($backups[0]['created_at']));
} else {
echo 'Never';
}
?>
</div>
</div>
<div class="stat-card">
<div class="stat-label">Total Size</div>
<div class="stat-value">
<?php
$total_size = 0;
foreach ($backups as $b) {
$total_size += $b['file_size'];
}
echo round($total_size / (1024 * 1024), 2) . ' MB';
?>
</div>
</div>
</div>
<!-- Backup Information -->
<div class="backup-info">
<div class="backup-info-title"><i class="fas fa-database"></i> Create a New Backup</div>
<div class="backup-info-text">
Creating a backup will export all database tables and data to a SQL file.
This file can be used to restore the database in case of data loss or corruption.
</div>
<form method="POST" class="backup-button">
<input type="hidden" name="action" value="create_backup">
<button type="submit" class="btn btn-primary" onclick="return confirm('This may take a few moments. Continue?')">
<i class="fas fa-file"></i> Create Backup Now
</button>
</form>
</div>
<!-- Backups List -->
<h2>Backup History</h2>
<div class="backups-table">
<?php if (count($backups) > 0): ?>
<table>
<thead>
<tr>
<th>Filename</th>
<th>Size</th>
<th>Created By</th>
<th>Date</th>
<th>Actions</th>
</tr>
</thead>
<tbody>
<?php foreach ($backups as $backup): ?>
<tr>
<td>
<div class="backup-filename">
<i class="fas fa-database"></i> <?php echo htmlspecialchars($backup['backup_file']); ?>
</div>
</td>
<td>
<div class="backup-size">
<?php echo round($backup['file_size'] / 1024, 2); ?> KB
</div>
</td>
<td>
<?php
$creator = get_user_by_id($backup['created_by']);
echo $creator ? htmlspecialchars($creator['first_name'] . ' ' . $creator['last_name']) : 'System';
?>
</td>
<td>
<div class="backup-date">
<?php echo date('d M Y H:i:s', strtotime($backup['created_at'])); ?>
</div>
</td>
<td>
<div class="backup-actions">
<button type="button" class="btn-download" onclick="downloadBackup('<?php echo htmlspecialchars($backup['backup_file']); ?>')">
<i class="fas fa-download"></i> Download
</button>
<form method="POST" style="display: inline;">
<input type="hidden" name="action" value="delete_backup">
<input type="hidden" name="backup_id" value="<?php echo $backup['id']; ?>">
<button type="submit" class="btn-delete" onclick="return confirm('Delete this backup?')">
<i class="fas fa-trash"></i> Delete
</button>
</form>
</div>
</td>
</tr>
<?php endforeach; ?>
</tbody>
</table>
<?php else: ?>
<div class="empty-state">
<p>No backups yet. Create your first backup to get started.</p>
</div>
<?php endif; ?>
</div>
</div>
</div>
</div>
<script src="../assets/js/app.js"></script>
<script>
function downloadBackup(filename) {
alert('Download feature for: ' + filename + ' coming soon!');
// In production, implement secure backup download
}
// 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>