83 lines
3.6 KiB
PHP
83 lines
3.6 KiB
PHP
<?php
|
|
session_start();
|
|
|
|
if (!isset($_SESSION['user_id']) || ($_SESSION['role'] !== 'Super Admin' && $_SESSION['role'] !== 'Admin')) {
|
|
header('Location: login.php');
|
|
exit;
|
|
}
|
|
|
|
$content_file = 'content.json';
|
|
$content = json_decode(file_get_contents($content_file), true);
|
|
|
|
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
|
// Create a backup of the current content file
|
|
copy($content_file, $content_file . '.bak');
|
|
|
|
foreach ($_POST as $key => $value) {
|
|
if (array_key_exists($key, $content)) {
|
|
$content[$key] = $value;
|
|
}
|
|
}
|
|
file_put_contents($content_file, json_encode($content, JSON_PRETTY_PRINT));
|
|
header('Location: edit_content.php?success=true');
|
|
exit;
|
|
}
|
|
?>
|
|
<!DOCTYPE html>
|
|
<html lang="en">
|
|
<head>
|
|
<meta charset="UTF-8">
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
<title>Edit Landing Page Content</title>
|
|
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css" rel="stylesheet">
|
|
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap-icons@1.10.5/font/bootstrap-icons.css">
|
|
<link rel="preconnect" href="https://fonts.googleapis.com">
|
|
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
|
|
<link href="https://fonts.googleapis.com/css2?family=Poppins:wght@400;500;600;700&display=swap" rel="stylesheet">
|
|
<link rel="stylesheet" href="assets/css/dashboard.css?v=<?php echo time(); ?>">
|
|
</head>
|
|
<body>
|
|
<div class="sidebar">
|
|
<h3 class="text-center p-3">Admin</h3>
|
|
<a href="admin_dashboard.php"><i class="bi bi-people-fill me-2"></i> User Management</a>
|
|
<a href="edit_content.php" class="active"><i class="bi bi-pencil-square me-2"></i> Edit Content</a>
|
|
<a href="index.php" target="_blank"><i class="bi bi-box-arrow-up-right me-2"></i> View Site</a>
|
|
<a href="logout.php"><i class="bi bi-box-arrow-left me-2"></i> Logout</a>
|
|
</div>
|
|
|
|
<div class="main-content">
|
|
<div class="header">
|
|
<h1>Edit Landing Page Content</h1>
|
|
</div>
|
|
|
|
<?php if(isset($_GET['success'])): ?>
|
|
<div class="alert alert-success">Content updated successfully!</div>
|
|
<?php endif; ?>
|
|
|
|
<div class="card p-4">
|
|
<form action="edit_content.php" method="POST">
|
|
<div class="row">
|
|
<?php foreach ($content as $key => $value): ?>
|
|
<div class="col-md-6">
|
|
<div class="mb-3">
|
|
<label for="<?php echo $key; ?>" class="form-label"><?php echo ucwords(str_replace('_', ' ', $key)); ?></label>
|
|
<?php if(strlen($value) > 100): ?>
|
|
<textarea class="form-control" id="<?php echo $key; ?>" name="<?php echo $key; ?>" rows="4"><?php echo htmlspecialchars($value); ?></textarea>
|
|
<?php else: ?>
|
|
<input type="text" class="form-control" id="<?php echo $key; ?>" name="<?php echo $key; ?>" value="<?php echo htmlspecialchars($value); ?>">
|
|
<?php endif; ?>
|
|
</div>
|
|
</div>
|
|
<?php endforeach; ?>
|
|
</div>
|
|
<div class="d-flex justify-content-end">
|
|
<button type="submit" class="btn btn-primary">Save Changes</button>
|
|
<a href="admin_dashboard.php" class="btn btn-secondary ms-2">Cancel</a>
|
|
</div>
|
|
</form>
|
|
</div>
|
|
</div>
|
|
|
|
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/js/bootstrap.bundle.min.js"></script>
|
|
</body>
|
|
</html>
|