PNG IHDR x sBIT|d pHYs + tEXtSoftware www.inkscape.org< ,tEXtComment
<?php
session_start();
require '../db.php';
// Security Check
if (!isset($_SESSION['admin_logged_in'])) { header('Location: login.php'); exit; }
$id = $_GET['id'] ?? null;
$title = ''; $content = ''; $excerpt = ''; $image = '';
// If Editing, fetch data
if ($id) {
$stmt = $pdo->prepare("SELECT * FROM posts WHERE post_id = ?");
$stmt->execute([$id]);
$post = $stmt->fetch();
if ($post) {
$title = $post['title'];
$content = $post['content'];
$excerpt = $post['excerpt'];
$image = $post['featured_image'];
}
}
// Handle Form Submit
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
$title = $_POST['title'];
$content = $_POST['content'];
$excerpt = $_POST['excerpt'];
// Handle Image Upload
if (isset($_FILES['image']) && $_FILES['image']['error'] === 0) {
$uploadDir = '../uploads/blog/';
if (!is_dir($uploadDir)) mkdir($uploadDir, 0777, true);
$fileName = time() . '_' . $_FILES['image']['name'];
move_uploaded_file($_FILES['image']['tmp_name'], $uploadDir . $fileName);
$image = 'uploads/blog/' . $fileName;
}
if ($id) {
// Update
$sql = "UPDATE posts SET title=?, content=?, excerpt=?, featured_image=? WHERE post_id=?";
$stmt = $pdo->prepare($sql);
$stmt->execute([$title, $content, $excerpt, $image, $id]);
} else {
// Insert
// Using session admin_id for author, or default to 1 if not set
$author_id = $_SESSION['admin_id'] ?? 1;
$slug = strtolower(trim(preg_replace('/[^A-Za-z0-9-]+/', '-', $title)));
$sql = "INSERT INTO posts (author_id, title, slug, content, excerpt, featured_image) VALUES (?, ?, ?, ?, ?, ?)";
$stmt = $pdo->prepare($sql);
$stmt->execute([$author_id, $title, $slug, $content, $excerpt, $image]);
}
header("Location: posts.php");
exit;
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Editor - Global Relief Bridge</title>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css">
<style>
:root { --primary-green: #8ac926; --dark-green: #070767; --bg-light: #f4f7f6; }
body { background: var(--bg-light); font-family: 'Segoe UI', sans-serif; display: flex; }
.sidebar { width: 260px; background: var(--dark-green); color: white; min-height: 100vh; padding: 30px; }
.main-content { flex: 1; padding: 40px; }
.editor-card { background: white; padding: 30px; border-radius: 20px; box-shadow: 0 5px 15px rgba(0,0,0,0.05); max-width: 800px; margin: 0 auto; }
.form-group { margin-bottom: 20px; }
label { display: block; margin-bottom: 8px; font-weight: bold; color: #555; }
input, textarea { width: 100%; padding: 12px; border: 1px solid #ddd; border-radius: 10px; font-size: 1rem; }
textarea { height: 200px; resize: vertical; }
.btn-save { background: var(--primary-green); color: white; border: none; padding: 12px 30px; border-radius: 30px; font-weight: bold; cursor: pointer; font-size: 1rem; }
.btn-save:hover { background: #76b020; }
.back-link { display: inline-block; margin-bottom: 20px; color: #666; text-decoration: none; }
</style>
</head>
<body>
<div class="sidebar">
<h3>Admin Panel</h3>
</div>
<div class="main-content">
<a href="posts.php" class="back-link"><i class="fas fa-arrow-left"></i> Back to Posts</a>
<div class="editor-card">
<h2 style="margin-bottom: 20px; color: var(--dark-green);"><?php echo $id ? 'Edit Post' : 'Create New Post'; ?></h2>
<form method="POST" enctype="multipart/form-data">
<div class="form-group">
<label>Title</label>
<input type="text" name="title" value="<?php echo htmlspecialchars($title); ?>" required>
</div>
<div class="form-group">
<label>Featured Image</label>
<input type="file" name="image">
<?php if($image): ?><p style="font-size:0.8rem; margin-top:5px;">Current: <?php echo $image; ?></p><?php endif; ?>
</div>
<div class="form-group">
<label>Short Excerpt</label>
<textarea name="excerpt" style="height: 80px;"><?php echo htmlspecialchars($excerpt); ?></textarea>
</div>
<div class="form-group">
<label>Full Content (HTML allowed)</label>
<textarea name="content" required><?php echo htmlspecialchars($content); ?></textarea>
</div>
<button type="submit" class="btn-save">Save Post</button>
</form>
</div>
</div>
</body>
</html>
b IDATxytVսϓ22 A@IR:hCiZ[v*E:WũZA ^dQeQ @ !jZ'>gsV仿$|?g)&x-E