ok, anyone role as admin can delete or edit (post, plan and note) and type full codes please and this old codes (<?php
// /public/workspace/delete_note.php

// Enable error reporting for debugging (disable in production)
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);

// Start output buffering to prevent "headers already sent" errors
ob_start();

// Include authentication and database connection
require_once __DIR__ . '/../../includes/auth.php';
require_once __DIR__ . '/../../includes/db_connect.php';

// Get note ID from GET parameter
$note_id = isset($_GET['id']) ? intval($_GET['id']) : 0;

// Get current user ID
$user_id = $_SESSION['user_id'];

if ($note_id > 0) {
    // Verify that the note belongs to the user
    $sql = "SELECT id FROM workspace_notes WHERE id = ? AND user_id = ?";
    if ($stmt = $conn->prepare($sql)) {
        $stmt->bind_param("ii", $note_id, $user_id);
        $stmt->execute();
        $stmt->store_result();
        if ($stmt->num_rows > 0) {
            // Proceed to delete
            $stmt->close();
            $delete_sql = "DELETE FROM workspace_notes WHERE id = ? AND user_id = ?";
            if ($delete_stmt = $conn->prepare($delete_sql)) {
                $delete_stmt->bind_param("ii", $note_id, $user_id);
                if ($delete_stmt->execute()) {
                    // Success, redirect to notes.php with success message
                    header("Location: notes.php?message=Note+deleted+successfully");
                    exit();
                } else {
                    // Deletion failed
                    header("Location: notes.php?error=Failed+to+delete+note");
                    exit();
                }
            } else {
                // Prepare failed
                header("Location: notes.php?error=Database+error");
                exit();
            }
        } else {
            // Note not found or doesn't belong to user
            header("Location: notes.php?error=Note+not+found");
            exit();
        }
    } else {
        // Prepare failed
        header("Location: notes.php?error=Database+error");
        exit();
    }
} else {
    // Invalid note ID
    header("Location: notes.php?error=Invalid+note+ID");
    exit();
}

// Flush the output buffer
ob_end_flush();
?>) (<?php
// /public/workspace/delete_plan.php

// Enable error reporting for debugging (disable in production)
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);

// Start output buffering to prevent "headers already sent" errors
ob_start();

// Include authentication and database connection
require_once __DIR__ . '/../../includes/auth.php';
require_once __DIR__ . '/../../includes/db_connect.php';

// Get plan ID from GET parameter
$plan_id = isset($_GET['id']) ? intval($_GET['id']) : 0;

// Get current user ID
$user_id = $_SESSION['user_id'];

if ($plan_id > 0) {
    // Verify that the plan belongs to the user
    $sql = "SELECT id FROM workspace_plans WHERE id = ? AND user_id = ?";
    if ($stmt = $conn->prepare($sql)) {
        $stmt->bind_param("ii", $plan_id, $user_id);
        $stmt->execute();
        $stmt->store_result();
        if ($stmt->num_rows > 0) {
            // Proceed to delete
            $stmt->close();
            $delete_sql = "DELETE FROM workspace_plans WHERE id = ? AND user_id = ?";
            if ($delete_stmt = $conn->prepare($delete_sql)) {
                $delete_stmt->bind_param("ii", $plan_id, $user_id);
                if ($delete_stmt->execute()) {
                    // Success, redirect to plans.php with success message
                    header("Location: plans.php?message=Plan+deleted+successfully");
                    exit();
                } else {
                    // Deletion failed
                    header("Location: plans.php?error=Failed+to+delete+plan");
                    exit();
                }
            } else {
                // Prepare failed
                header("Location: plans.php?error=Database+error");
                exit();
            }
        } else {
            // Plan not found or doesn't belong to user
            header("Location: plans.php?error=Plan+not+found");
            exit();
        }
    } else {
        // Prepare failed
        header("Location: plans.php?error=Database+error");
        exit();
    }
} else {
    // Invalid plan ID
    header("Location: plans.php?error=Invalid+plan+ID");
    exit();
}

// Flush the output buffer
ob_end_flush();
?>)(<?php
// /public/workspace/delete_post.php

// Enable error reporting for debugging (disable in production)
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);

// Start output buffering to prevent "headers already sent" errors
ob_start();

// Include authentication and database connection
require_once __DIR__ . '/../../includes/auth.php';
require_once __DIR__ . '/../../includes/db_connect.php';

// Get post ID from GET parameter
$post_id = isset($_GET['id']) ? intval($_GET['id']) : 0;

// Get current user ID
$user_id = $_SESSION['user_id'];

if ($post_id > 0) {
    // Verify that the post belongs to the user
    $sql = "SELECT id, media_url FROM workspace_posts WHERE id = ? AND user_id = ?";
    if ($stmt = $conn->prepare($sql)) {
        $stmt->bind_param("ii", $post_id, $user_id);
        $stmt->execute();
        $stmt->bind_result($id, $media_url);
        if ($stmt->fetch()) {
            // Proceed to delete
            $stmt->close();
            $delete_sql = "DELETE FROM workspace_posts WHERE id = ? AND user_id = ?";
            if ($delete_stmt = $conn->prepare($delete_sql)) {
                $delete_stmt->bind_param("ii", $post_id, $user_id);
                if ($delete_stmt->execute()) {
                    // If media exists, delete the file
                    if ($media_url) {
                        $file_path = __DIR__ . '/../../' . ltrim($media_url, '/');
                        if (file_exists($file_path)) {
                            unlink($file_path);
                        }
                    }
                    // Success, redirect to posts.php with success message
                    header("Location: posts.php?message=Post+deleted+successfully");
                    exit();
                } else {
                    // Deletion failed
                    header("Location: posts.php?error=Failed+to+delete+post");
                    exit();
                }
            } else {
                // Prepare failed
                header("Location: posts.php?error=Database+error");
                exit();
            }
        } else {
            // Post not found or doesn't belong to user
            header("Location: posts.php?error=Post+not+found");
            exit();
        }
    } else {
        // Prepare failed
        header("Location: posts.php?error=Database+error");
        exit();
    }
} else {
    // Invalid post ID
    header("Location: posts.php?error=Invalid+post+ID");
    exit();
}

// Flush the output buffer
ob_end_flush();
?>)(<?php
// /public/workspace/edit_note.php

// Enable error reporting for debugging (disable in production)
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);

// Start output buffering to prevent "headers already sent" errors
ob_start();

// Include authentication, database connection, and utility functions
require_once __DIR__ . '/../../includes/auth.php';
require_once __DIR__ . '/../../includes/db_connect.php';
require_once __DIR__ . '/../../includes/functions.php'; // Contains sanitize_input()

$user_id = $_SESSION['user_id'];
$note_id = isset($_GET['id']) ? intval($_GET['id']) : 0;
$errors = [];
$title = '';
$content = '';

// Handle GET request to fetch existing note data
if ($_SERVER['REQUEST_METHOD'] === 'GET') {
    if ($note_id > 0) {
        $sql = "SELECT title, content FROM workspace_notes WHERE id = ? AND user_id = ?";
        if ($stmt = $conn->prepare($sql)) {
            $stmt->bind_param("ii", $note_id, $user_id);
            $stmt->execute();
            $stmt->bind_result($title, $content);
            if (!$stmt->fetch()) {
                $errors[] = "Note not found.";
            }
            $stmt->close();
        } else {
            $errors[] = "Database error: Unable to prepare statement.";
        }
    } else {
        $errors[] = "Invalid note ID.";
    }
}

// Handle POST request to update the note
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
    $title = sanitize_input($_POST['title'] ?? '');
    $content = sanitize_input($_POST['content'] ?? '');

    // Validation
    if (empty($title)) {
        $errors[] = "Title is required.";
    }
    if (empty($content)) {
        $errors[] = "Content is required.";
    }

    if ($note_id > 0) {
        // Verify that the note belongs to the user
        $sql_check = "SELECT id FROM workspace_notes WHERE id = ? AND user_id = ?";
        if ($stmt_check = $conn->prepare($sql_check)) {
            $stmt_check->bind_param("ii", $note_id, $user_id);
            $stmt_check->execute();
            $stmt_check->store_result();
            if ($stmt_check->num_rows > 0) {
                $stmt_check->close();
                // Update the note
                $update_sql = "UPDATE workspace_notes SET title = ?, content = ?, updated_at = CURRENT_TIMESTAMP() WHERE id = ? AND user_id = ?";
                if ($stmt_update = $conn->prepare($update_sql)) {
                    $stmt_update->bind_param("ssii", $title, $content, $note_id, $user_id);
                    if ($stmt_update->execute()) {
                        // Success, redirect to view_note.php with success message
                        header("Location: view_note.php?id=$note_id&message=Note+updated+successfully");
                        exit();
                    } else {
                        $errors[] = "Failed to update note. Please try again.";
                    }
                    $stmt_update->close();
                } else {
                    $errors[] = "Database error: Unable to prepare update statement.";
                }
            } else {
                $errors[] = "Note not found or you do not have permission to edit this note.";
            }
        } else {
            $errors[] = "Database error: Unable to prepare statement.";
        }
    } else {
        $errors[] = "Invalid note ID.";
    }
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Edit Note - Workspace</title>
    <!-- Tailwind CSS -->
    <link href="https://cdn.jsdelivr.net/npm/tailwindcss@2.2.19/dist/tailwind.min.css" rel="stylesheet">
    <!-- Bootstrap Icons -->
    <link href="https://cdn.jsdelivr.net/npm/bootstrap-icons/font/bootstrap-icons.css" rel="stylesheet">
</head>
<body class="bg-gray-100 min-h-screen flex flex-col">
    <!-- Header -->
    <?php include __DIR__ . '/../../includes/header.php'; ?>

    <!-- Main Content -->
    <main class="container mx-auto p-6 mt-24 flex-grow">
        <h1 class="text-2xl font-bold mb-6">Edit Note</h1>

        <!-- Display Errors -->
        <?php if(!empty($errors)): ?>
            <div class="bg-red-100 border border-red-400 text-red-700 px-4 py-3 rounded mb-4">
                <ul>
                    <?php foreach($errors as $error): ?>
                        <li><?= htmlspecialchars($error) ?></li>
                    <?php endforeach; ?>
                </ul>
            </div>
        <?php endif; ?>

        <!-- Note Edit Form -->
        <?php if(empty($errors) || $_SERVER['REQUEST_METHOD'] === 'POST'): ?>
            <form action="edit_note.php?id=<?= htmlspecialchars($note_id) ?>" method="POST" class="bg-white p-6 rounded shadow-md">
                <div class="mb-4">
                    <label class="block text-gray-700">Title<span class="text-red-500">*</span></label>
                    <input type="text" name="title" class="w-full px-3 py-2 border rounded focus:outline-none focus:ring focus:border-blue-300" required value="<?= htmlspecialchars($title) ?>">
                </div>
                <div class="mb-4">
                    <label class="block text-gray-700">Content<span class="text-red-500">*</span></label>
                    <textarea name="content" class="w-full px-3 py-2 border rounded focus:outline-none focus:ring focus:border-blue-300" rows="8" required><?= htmlspecialchars($content) ?></textarea>
                </div>
                <div class="flex justify-between">
                    <a href="view_note.php?id=<?= htmlspecialchars($note_id) ?>" class="px-4 py-2 bg-gray-500 text-white rounded hover:bg-gray-600">Cancel</a>
                    <button type="submit" class="px-4 py-2 bg-purple-500 text-white rounded hover:bg-purple-600">Update Note</button>
                </div>
            </form>
        <?php endif; ?>
    </main>

    <!-- Footer -->
    <footer class="bg-gray-800 text-white text-center p-4">
        &copy; 2024 Kaak Alia Bakery. All rights reserved.
    </footer>
</body>
</html>
<?php
// Flush the output buffer
ob_end_flush();
?>)(<?php
// /public/workspace/edit_plan.php

// Enable error reporting for debugging (disable in production)
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);

// Start output buffering to prevent "headers already sent" errors
ob_start();

// Include authentication, database connection, and utility functions
require_once __DIR__ . '/../../includes/auth.php';
require_once __DIR__ . '/../../includes/db_connect.php';
require_once __DIR__ . '/../../includes/functions.php'; // Contains sanitize_input()

$user_id = $_SESSION['user_id'];
$plan_id = isset($_GET['id']) ? intval($_GET['id']) : 0;
$errors = [];
$title = '';
$description = '';
$due_date = '';
$status = 'Not Started';

// Handle GET request to fetch existing plan data
if ($_SERVER['REQUEST_METHOD'] === 'GET') {
    if ($plan_id > 0) {
        $sql = "SELECT title, description, due_date, status FROM workspace_plans WHERE id = ? AND user_id = ?";
        if ($stmt = $conn->prepare($sql)) {
            $stmt->bind_param("ii", $plan_id, $user_id);
            $stmt->execute();
            $stmt->bind_result($title, $description, $due_date, $status);
            if (!$stmt->fetch()) {
                $errors[] = "Plan not found.";
            }
            $stmt->close();
        } else {
            $errors[] = "Database error: Unable to prepare statement.";
        }
    } else {
        $errors[] = "Invalid plan ID.";
    }
}

// Handle POST request to update the plan
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
    $title = sanitize_input($_POST['title'] ?? '');
    $description = sanitize_input($_POST['description'] ?? '');
    $due_date = sanitize_input($_POST['due_date'] ?? '');
    $status = sanitize_input($_POST['status'] ?? 'Not Started');

    // Validation
    if (empty($title)) {
        $errors[] = "Title is required.";
    }
    if (empty($due_date)) {
        $errors[] = "Due date is required.";
    }

    // Validate status
    $valid_statuses = ['Not Started', 'In Progress', 'Completed'];
    if (!in_array($status, $valid_statuses)) {
        $errors[] = "Invalid status selected.";
    }

    // Validate due_date format
    if (!strtotime($due_date)) {
        $errors[] = "Invalid due date format.";
    }

    if ($plan_id > 0) {
        // Verify that the plan belongs to the user
        $sql_check = "SELECT id FROM workspace_plans WHERE id = ? AND user_id = ?";
        if ($stmt_check = $conn->prepare($sql_check)) {
            $stmt_check->bind_param("ii", $plan_id, $user_id);
            $stmt_check->execute();
            $stmt_check->store_result();
            if ($stmt_check->num_rows > 0) {
                $stmt_check->close();
                // Update the plan
                $update_sql = "UPDATE workspace_plans SET title = ?, description = ?, due_date = ?, status = ?, updated_at = CURRENT_TIMESTAMP() WHERE id = ? AND user_id = ?";
                if ($stmt_update = $conn->prepare($update_sql)) {
                    $stmt_update->bind_param("ssssis", $title, $description, $due_date, $status, $plan_id, $user_id);
                    if ($stmt_update->execute()) {
                        // Success, redirect to view_plan.php with success message
                        header("Location: view_plan.php?id=$plan_id&message=Plan+updated+successfully");
                        exit();
                    } else {
                        $errors[] = "Failed to update plan. Please try again.";
                    }
                    $stmt_update->close();
                } else {
                    $errors[] = "Database error: Unable to prepare update statement.";
                }
            } else {
                $errors[] = "Plan not found or you do not have permission to edit this plan.";
            }
        } else {
            $errors[] = "Database error: Unable to prepare statement.";
        }
    } else {
        $errors[] = "Invalid plan ID.";
    }
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Edit Plan - Workspace</title>
    <!-- Tailwind CSS -->
    <link href="https://cdn.jsdelivr.net/npm/tailwindcss@2.2.19/dist/tailwind.min.css" rel="stylesheet">
    <!-- Bootstrap Icons -->
    <link href="https://cdn.jsdelivr.net/npm/bootstrap-icons/font/bootstrap-icons.css" rel="stylesheet">
</head>
<body class="bg-gray-100 min-h-screen flex flex-col">
    <!-- Header -->
    <?php include __DIR__ . '/../../includes/header.php'; ?>

    <!-- Main Content -->
    <main class="container mx-auto p-6 mt-24 flex-grow">
        <h1 class="text-2xl font-bold mb-6">Edit Plan</h1>

        <!-- Display Errors -->
        <?php if(!empty($errors)): ?>
            <div class="bg-red-100 border border-red-400 text-red-700 px-4 py-3 rounded mb-4">
                <ul>
                    <?php foreach($errors as $error): ?>
                        <li><?= htmlspecialchars($error) ?></li>
                    <?php endforeach; ?>
                </ul>
            </div>
        <?php endif; ?>

        <!-- Plan Edit Form -->
        <?php if(empty($errors) || $_SERVER['REQUEST_METHOD'] === 'POST'): ?>
            <form action="edit_plan.php?id=<?= htmlspecialchars($plan_id) ?>" method="POST" class="bg-white p-6 rounded shadow-md">
                <div class="mb-4">
                    <label class="block text-gray-700">Title<span class="text-red-500">*</span></label>
                    <input type="text" name="title" class="w-full px-3 py-2 border rounded focus:outline-none focus:ring focus:border-blue-300" required value="<?= htmlspecialchars($title) ?>">
                </div>
                <div class="mb-4">
                    <label class="block text-gray-700">Description</label>
                    <textarea name="description" class="w-full px-3 py-2 border rounded focus:outline-none focus:ring focus:border-blue-300" rows="4"><?= htmlspecialchars($description) ?></textarea>
                </div>
                <div class="mb-4">
                    <label class="block text-gray-700">Due Date<span class="text-red-500">*</span></label>
                    <input type="datetime-local" name="due_date" class="w-full px-3 py-2 border rounded focus:outline-none focus:ring focus:border-blue-300" required value="<?= htmlspecialchars($due_date) ?>">
                </div>
                <div class="mb-4">
                    <label class="block text-gray-700">Status</label>
                    <select name="status" class="w-full px-3 py-2 border rounded focus:outline-none focus:ring focus:border-blue-300">
                        <option value="Not Started" <?= ($status === 'Not Started') ? 'selected' : '' ?>>Not Started</option>
                        <option value="In Progress" <?= ($status === 'In Progress') ? 'selected' : '' ?>>In Progress</option>
                        <option value="Completed" <?= ($status === 'Completed') ? 'selected' : '' ?>>Completed</option>
                    </select>
                </div>
                <div class="flex justify-between">
                    <a href="view_plan.php?id=<?= htmlspecialchars($plan_id) ?>" class="px-4 py-2 bg-gray-500 text-white rounded hover:bg-gray-600">Cancel</a>
                    <button type="submit" class="px-4 py-2 bg-blue-500 text-white rounded hover:bg-blue-600">Update Plan</button>
                </div>
            </form>
        <?php endif; ?>
    </main>

    <!-- Footer -->
    <footer class="bg-gray-800 text-white text-center p-4">
        &copy; 2024 Kaak Alia Bakery. All rights reserved.
    </footer>
</body>
</html>
<?php
// Flush the output buffer
ob_end_flush();
?>)(<?php
// /public/workspace/edit_post.php

// Enable error reporting for debugging (disable in production)
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);

// Start output buffering to prevent "headers already sent" errors
ob_start();

// Include authentication, database connection, and utility functions
require_once __DIR__ . '/../../includes/auth.php';
require_once __DIR__ . '/../../includes/db_connect.php';
require_once __DIR__ . '/../../includes/functions.php'; // Contains sanitize_input()

$user_id = $_SESSION['user_id'];
$post_id = isset($_GET['id']) ? intval($_GET['id']) : 0;
$errors = [];
$platform = '';
$content = '';
$scheduled_datetime = '';
$status = 'Scheduled';
$media_url = '';

// Handle GET request to fetch existing post data
if ($_SERVER['REQUEST_METHOD'] === 'GET') {
    if ($post_id > 0) {
        $sql = "SELECT platform, content, media_url, scheduled_datetime, status FROM workspace_posts WHERE id = ? AND user_id = ?";
        if ($stmt = $conn->prepare($sql)) {
            $stmt->bind_param("ii", $post_id, $user_id);
            $stmt->execute();
            $stmt->bind_result($platform, $content, $media_url, $scheduled_datetime, $status);
            if (!$stmt->fetch()) {
                $errors[] = "Post not found.";
            }
            $stmt->close();
        } else {
            $errors[] = "Database error: Unable to prepare statement.";
        }
    } else {
        $errors[] = "Invalid post ID.";
    }
}

// Handle POST request to update the post
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
    $platform = sanitize_input($_POST['platform'] ?? '');
    $content = sanitize_input($_POST['content'] ?? '');
    $scheduled_datetime = sanitize_input($_POST['scheduled_datetime'] ?? '');
    $status = 'Scheduled'; // This can be modified if needed

    // Handle media upload if any
    $new_media_url = $media_url; // Existing media_url
    if (isset($_FILES['media']) && $_FILES['media']['error'] !== UPLOAD_ERR_NO_FILE) {
        if ($_FILES['media']['error'] === UPLOAD_ERR_OK) {
            $allowed_types = ['image/jpeg', 'image/png', 'video/mp4', 'image/gif'];
            if (in_array($_FILES['media']['type'], $allowed_types)) {
                $upload_dir = __DIR__ . '/../../assets/uploads/workspace_posts/';
                if (!is_dir($upload_dir)) {
                    mkdir($upload_dir, 0755, true);
                }

                // Generate a unique filename
                $file_ext = pathinfo($_FILES['media']['name'], PATHINFO_EXTENSION);
                $filename = time() . '_' . bin2hex(random_bytes(8)) . '.' . $file_ext;
                $filepath = $upload_dir . $filename;

                if (move_uploaded_file($_FILES['media']['tmp_name'], $filepath)) {
                    // Delete old media file if exists
                    if ($media_url) {
                        $old_file_path = __DIR__ . '/../../' . ltrim($media_url, '/');
                        if (file_exists($old_file_path)) {
                            unlink($old_file_path);
                        }
                    }
                    // Store relative path
                    $new_media_url = '/assets/uploads/workspace_posts/' . $filename;
                } else {
                    $errors[] = "Failed to upload media.";
                }
            } else {
                $errors[] = "Unsupported media type. Allowed types: JPEG, PNG, GIF, MP4.";
            }
        } else {
            $errors[] = "Error uploading media.";
        }
    }

    // Validation
    if (empty($platform)) {
        $errors[] = "Platform is required.";
    }
    if (empty($content)) {
        $errors[] = "Content is required.";
    }
    if (empty($scheduled_datetime)) {
        $errors[] = "Scheduled date and time are required.";
    }

    // Validate platform
    $valid_platforms = ['Instagram', 'Facebook', 'Twitter', 'Other'];
    if (!in_array($platform, $valid_platforms)) {
        $errors[] = "Invalid platform selected.";
    }

    // Validate scheduled_datetime
    if (!strtotime($scheduled_datetime)) {
        $errors[] = "Invalid scheduled date and time.";
    }

    if (empty($errors)) {
        if ($post_id > 0) {
            // Verify ownership
            $sql_check = "SELECT id, media_url FROM workspace_posts WHERE id = ? AND user_id = ?";
            if ($stmt_check = $conn->prepare($sql_check)) {
                $stmt_check->bind_param("ii", $post_id, $user_id);
                $stmt_check->execute();
                $stmt_check->bind_result($id, $existing_media_url);
                if ($stmt_check->fetch()) {
                    $stmt_check->close();

                    // Update the post
                    $update_sql = "UPDATE workspace_posts SET platform = ?, content = ?, media_url = ?, scheduled_datetime = ?, status = ?, updated_at = CURRENT_TIMESTAMP() WHERE id = ? AND user_id = ?";
                    if ($stmt_update = $conn->prepare($update_sql)) {
                        $stmt_update->bind_param("ssssiii", $platform, $content, $new_media_url, $scheduled_datetime, $status, $post_id, $user_id);
                        if ($stmt_update->execute()) {
                            // Success, redirect to view_post.php with success message
                            header("Location: view_post.php?id=$post_id&message=Post+updated+successfully");
                            exit();
                        } else {
                            $errors[] = "Failed to update post. Please try again.";
                        }
                        $stmt_update->close();
                    } else {
                        $errors[] = "Database error: Unable to prepare update statement.";
                    }
                } else {
                    $errors[] = "Post not found or you do not have permission to edit this post.";
                }
            } else {
                $errors[] = "Database error: Unable to prepare statement.";
            }
        } else {
            $errors[] = "Invalid post ID.";
        }
    }
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Edit Post - Workspace</title>
    <!-- Tailwind CSS -->
    <link href="https://cdn.jsdelivr.net/npm/tailwindcss@2.2.19/dist/tailwind.min.css" rel="stylesheet">
    <!-- Bootstrap Icons -->
    <link href="https://cdn.jsdelivr.net/npm/bootstrap-icons/font/bootstrap-icons.css" rel="stylesheet">
</head>
<body class="bg-gray-100 min-h-screen flex flex-col">
    <!-- Header -->
    <?php include __DIR__ . '/../../includes/header.php'; ?>

    <!-- Main Content -->
    <main class="container mx-auto p-6 mt-24 flex-grow">
        <h1 class="text-2xl font-bold mb-6">Edit Post</h1>

        <!-- Display Errors -->
        <?php if(!empty($errors)): ?>
            <div class="bg-red-100 border border-red-400 text-red-700 px-4 py-3 rounded mb-4">
                <ul>
                    <?php foreach($errors as $error): ?>
                        <li><?= htmlspecialchars($error) ?></li>
                    <?php endforeach; ?>
                </ul>
            </div>
        <?php endif; ?>

        <!-- Post Edit Form -->
        <?php if(empty($errors) || $_SERVER['REQUEST_METHOD'] === 'POST'): ?>
            <form action="edit_post.php?id=<?= htmlspecialchars($post_id) ?>" method="POST" enctype="multipart/form-data" class="bg-white p-6 rounded shadow-md">
                <div class="mb-4">
                    <label class="block text-gray-700">Platform<span class="text-red-500">*</span></label>
                    <select name="platform" class="w-full px-3 py-2 border rounded focus:outline-none focus:ring focus:border-blue-300" required>
                        <option value="">-- Select Platform --</option>
                        <option value="Instagram" <?= ($platform === 'Instagram') ? 'selected' : '' ?>>Instagram</option>
                        <option value="Facebook" <?= ($platform === 'Facebook') ? 'selected' : '' ?>>Facebook</option>
                        <option value="Twitter" <?= ($platform === 'Twitter') ? 'selected' : '' ?>>Twitter</option>
                        <option value="Other" <?= ($platform === 'Other') ? 'selected' : '' ?>>Other</option>
                    </select>
                </div>
                <div class="mb-4">
                    <label class="block text-gray-700">Content<span class="text-red-500">*</span></label>
                    <textarea name="content" class="w-full px-3 py-2 border rounded focus:outline-none focus:ring focus:border-blue-300" rows="6" required><?= htmlspecialchars($content) ?></textarea>
                </div>
                <div class="mb-4">
                    <label class="block text-gray-700">Media (Optional)</label>
                    <?php if ($media_url): ?>
                        <div class="mb-2">
                            <?php
                            $file_ext = strtolower(pathinfo($media_url, PATHINFO_EXTENSION));
                            if (in_array($file_ext, ['jpg', 'jpeg', 'png', 'gif'])):
                            ?>
                                <img src="<?= htmlspecialchars($media_url) ?>" alt="Media" class="max-w-sm">
                            <?php elseif (in_array($file_ext, ['mp4'])): ?>
                                <video controls class="max-w-sm">
                                    <source src="<?= htmlspecialchars($media_url) ?>" type="video/mp4">
                                    Your browser does not support the video tag.
                                </video>
                            <?php endif; ?>
                        </div>
                    <?php endif; ?>
                    <input type="file" name="media" class="w-full px-3 py-2 border rounded focus:outline-none focus:ring focus:border-blue-300">
                    <p class="text-sm text-gray-500 mt-1">Supported formats: JPEG, PNG, GIF, MP4.</p>
                </div>
                <div class="mb-4">
                    <label class="block text-gray-700">Scheduled Date & Time<span class="text-red-500">*</span></label>
                    <input type="datetime-local" name="scheduled_datetime" class="w-full px-3 py-2 border rounded focus:outline-none focus:ring focus:border-blue-300" required value="<?= htmlspecialchars($scheduled_datetime) ?>">
                </div>
                <div class="flex justify-between">
                    <a href="view_post.php?id=<?= htmlspecialchars($post_id) ?>" class="px-4 py-2 bg-gray-500 text-white rounded hover:bg-gray-600">Cancel</a>
                    <button type="submit" class="px-4 py-2 bg-blue-500 text-white rounded hover:bg-blue-600">Update Post</button>
                </div>
            </form>
        <?php endif; ?>
    </main>

    <!-- Footer -->
    <footer class="bg-gray-800 text-white text-center p-4">
        &copy; 2024 Kaak Alia Bakery. All rights reserved.
    </footer>
</body>
</html>
<?php
// Flush the output buffer
ob_end_flush();
?>), i want any user admin can delete or edit and type full ocdes please and this inof database (-- phpMyAdmin SQL Dump
-- version 5.2.1
-- https://www.phpmyadmin.net/
--
-- Host: 127.0.0.1:3306
-- Generation Time: Nov 10, 2024 at 08:15 AM
-- Server version: 10.11.9-MariaDB
-- PHP Version: 7.2.34

SET SQL_MODE = "NO_AUTO_VALUE_ON_ZERO";
START TRANSACTION;
SET time_zone = "+00:00";


/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;
/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;
/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;
/*!40101 SET NAMES utf8mb4 */;

--
-- Database: `u406552082_kaakalia`
--

-- --------------------------------------------------------

--
-- Table structure for table `customers`
--

CREATE TABLE `customers` (
  `id` int(11) NOT NULL,
  `name` varchar(100) NOT NULL,
  `contact` varchar(50) DEFAULT NULL,
  `delivery_address` text DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

-- --------------------------------------------------------

--
-- Table structure for table `drivers`
--

CREATE TABLE `drivers` (
  `id` int(11) NOT NULL,
  `name` varchar(100) NOT NULL,
  `number` varchar(15) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

-- --------------------------------------------------------

--
-- Table structure for table `orders`
--

CREATE TABLE `orders` (
  `id` int(11) NOT NULL,
  `customer_id` int(11) NOT NULL,
  `status` enum('Pending','In Progress','Completed','Delivered') DEFAULT 'Pending',
  `priority` enum('Normal','Important','Quick') DEFAULT 'Normal',
  `order_date` datetime DEFAULT current_timestamp(),
  `delivery_datetime` datetime DEFAULT NULL,
  `delivery_date` date DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

-- --------------------------------------------------------

--
-- Table structure for table `order_items`
--

CREATE TABLE `order_items` (
  `id` int(11) NOT NULL,
  `order_id` int(11) NOT NULL,
  `product_id` int(11) NOT NULL,
  `quantity` int(11) NOT NULL DEFAULT 1,
  `packaging_preferences` varchar(255) DEFAULT NULL,
  `discount_percentage` decimal(5,2) DEFAULT 0.00,
  `discount_reason` varchar(255) DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

-- --------------------------------------------------------

--
-- Table structure for table `products`
--

CREATE TABLE `products` (
  `id` int(11) NOT NULL,
  `name` varchar(100) NOT NULL,
  `size` varchar(50) DEFAULT NULL,
  `price` decimal(10,2) NOT NULL,
  `category` varchar(50) DEFAULT NULL,
  `thumbnail` varchar(255) DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

-- --------------------------------------------------------

--
-- Table structure for table `users`
--

CREATE TABLE `users` (
  `id` int(11) NOT NULL,
  `username` varchar(50) NOT NULL,
  `password` varchar(255) NOT NULL,
  `role` enum('admin','staff') NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

-- --------------------------------------------------------

--
-- Table structure for table `workspace_notes`
--

CREATE TABLE `workspace_notes` (
  `id` int(11) NOT NULL,
  `user_id` int(11) NOT NULL,
  `title` varchar(255) NOT NULL,
  `content` text NOT NULL,
  `created_at` datetime DEFAULT current_timestamp(),
  `updated_at` datetime DEFAULT current_timestamp() ON UPDATE current_timestamp()
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

-- --------------------------------------------------------

--
-- Table structure for table `workspace_plans`
--

CREATE TABLE `workspace_plans` (
  `id` int(11) NOT NULL,
  `user_id` int(11) NOT NULL,
  `title` varchar(255) NOT NULL,
  `description` text DEFAULT NULL,
  `due_date` datetime DEFAULT NULL,
  `status` enum('Not Started','In Progress','Completed') DEFAULT 'Not Started',
  `created_at` datetime DEFAULT current_timestamp(),
  `updated_at` datetime DEFAULT current_timestamp() ON UPDATE current_timestamp()
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

-- --------------------------------------------------------

--
-- Table structure for table `workspace_posts`
--

CREATE TABLE `workspace_posts` (
  `id` int(11) NOT NULL,
  `user_id` int(11) NOT NULL,
  `platform` enum('Instagram','Facebook','Twitter','Other') NOT NULL,
  `content` text NOT NULL,
  `media_url` varchar(255) DEFAULT NULL,
  `scheduled_datetime` datetime DEFAULT NULL,
  `status` enum('Scheduled','Posted','Failed') DEFAULT 'Scheduled',
  `created_at` datetime DEFAULT current_timestamp(),
  `updated_at` datetime DEFAULT current_timestamp() ON UPDATE current_timestamp()
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

--
-- Indexes for dumped tables
--

--
-- Indexes for table `customers`
--
ALTER TABLE `customers`
  ADD PRIMARY KEY (`id`);

--
-- Indexes for table `drivers`
--
ALTER TABLE `drivers`
  ADD PRIMARY KEY (`id`);

--
-- Indexes for table `orders`
--
ALTER TABLE `orders`
  ADD PRIMARY KEY (`id`),
  ADD KEY `customer_id` (`customer_id`),
  ADD KEY `idx_orders_customer_id` (`customer_id`);

--
-- Indexes for table `order_items`
--
ALTER TABLE `order_items`
  ADD PRIMARY KEY (`id`),
  ADD KEY `order_id` (`order_id`),
  ADD KEY `product_id` (`product_id`),
  ADD KEY `idx_order_items_order_id` (`order_id`),
  ADD KEY `idx_order_items_product_id` (`product_id`);

--
-- Indexes for table `products`
--
ALTER TABLE `products`
  ADD PRIMARY KEY (`id`);

--
-- Indexes for table `users`
--
ALTER TABLE `users`
  ADD PRIMARY KEY (`id`),
  ADD UNIQUE KEY `username` (`username`);

--
-- Indexes for table `workspace_notes`
--
ALTER TABLE `workspace_notes`
  ADD PRIMARY KEY (`id`),
  ADD KEY `user_id` (`user_id`);

--
-- Indexes for table `workspace_plans`
--
ALTER TABLE `workspace_plans`
  ADD PRIMARY KEY (`id`),
  ADD KEY `user_id` (`user_id`);

--
-- Indexes for table `workspace_posts`
--
ALTER TABLE `workspace_posts`
  ADD PRIMARY KEY (`id`),
  ADD KEY `user_id` (`user_id`);

--
-- AUTO_INCREMENT for dumped tables
--

--
-- AUTO_INCREMENT for table `customers`
--
ALTER TABLE `customers`
  MODIFY `id` int(11) NOT NULL AUTO_INCREMENT;

--
-- AUTO_INCREMENT for table `drivers`
--
ALTER TABLE `drivers`
  MODIFY `id` int(11) NOT NULL AUTO_INCREMENT;

--
-- AUTO_INCREMENT for table `orders`
--
ALTER TABLE `orders`
  MODIFY `id` int(11) NOT NULL AUTO_INCREMENT;

--
-- AUTO_INCREMENT for table `order_items`
--
ALTER TABLE `order_items`
  MODIFY `id` int(11) NOT NULL AUTO_INCREMENT;

--
-- AUTO_INCREMENT for table `products`
--
ALTER TABLE `products`
  MODIFY `id` int(11) NOT NULL AUTO_INCREMENT;

--
-- AUTO_INCREMENT for table `users`
--
ALTER TABLE `users`
  MODIFY `id` int(11) NOT NULL AUTO_INCREMENT;

--
-- AUTO_INCREMENT for table `workspace_notes`
--
ALTER TABLE `workspace_notes`
  MODIFY `id` int(11) NOT NULL AUTO_INCREMENT;

--
-- AUTO_INCREMENT for table `workspace_plans`
--
ALTER TABLE `workspace_plans`
  MODIFY `id` int(11) NOT NULL AUTO_INCREMENT;

--
-- AUTO_INCREMENT for table `workspace_posts`
--
ALTER TABLE `workspace_posts`
  MODIFY `id` int(11) NOT NULL AUTO_INCREMENT;

--
-- Constraints for dumped tables
--

--
-- Constraints for table `orders`
--
ALTER TABLE `orders`
  ADD CONSTRAINT `fk_orders_customer_id` FOREIGN KEY (`customer_id`) REFERENCES `customers` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,
  ADD CONSTRAINT `orders_ibfk_1` FOREIGN KEY (`customer_id`) REFERENCES `customers` (`id`) ON DELETE CASCADE;

--
-- Constraints for table `order_items`
--
ALTER TABLE `order_items`
  ADD CONSTRAINT `fk_order_items_order_id` FOREIGN KEY (`order_id`) REFERENCES `orders` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,
  ADD CONSTRAINT `fk_order_items_product_id` FOREIGN KEY (`product_id`) REFERENCES `products` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,
  ADD CONSTRAINT `order_items_ibfk_1` FOREIGN KEY (`order_id`) REFERENCES `orders` (`id`) ON DELETE CASCADE,
  ADD CONSTRAINT `order_items_ibfk_2` FOREIGN KEY (`product_id`) REFERENCES `products` (`id`) ON DELETE CASCADE;

--
-- Constraints for table `workspace_notes`
--
ALTER TABLE `workspace_notes`
  ADD CONSTRAINT `fk_workspace_notes_user_id` FOREIGN KEY (`user_id`) REFERENCES `users` (`id`) ON DELETE CASCADE;

--
-- Constraints for table `workspace_plans`
--
ALTER TABLE `workspace_plans`
  ADD CONSTRAINT `fk_workspace_plans_user_id` FOREIGN KEY (`user_id`) REFERENCES `users` (`id`) ON DELETE CASCADE;

--
-- Constraints for table `workspace_posts`
--
ALTER TABLE `workspace_posts`
  ADD CONSTRAINT `fk_workspace_posts_user_id` FOREIGN KEY (`user_id`) REFERENCES `users` (`id`) ON DELETE CASCADE;
COMMIT;

/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */;
/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */;
/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;) and this index.php (<?php
// /public/workspace/index.php

// Enable error reporting for debugging (disable in production)
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);

// Start output buffering to prevent "headers already sent" errors
ob_start();

// Include authentication, database connection, and utility functions
require_once __DIR__ . '/../../includes/auth.php';
require_once __DIR__ . '/../../includes/db_connect.php';
require_once __DIR__ . '/../../includes/functions.php'; // Contains sanitize_input()

// Ensure the user is authenticated
if (!isset($_SESSION['user_id'])) {
    header("Location: /public/login.php");
    exit();
}

$user_id = $_SESSION['user_id'];
$calendar_events = []; // Initialize calendar events array
$errors = [];

// Fetch summary data: Total Number of Plans, Posts, Notes
try {
    // Total Plans
    $plans_count_sql = "SELECT COUNT(*) AS total FROM workspace_plans";
    $stmt = $conn->prepare($plans_count_sql);
    if (!$stmt) {
        throw new Exception("Prepare statement failed for plans count: " . $conn->error);
    }
    $stmt->execute();
    $result = $stmt->get_result();
    $plans_count = $result->fetch_assoc()['total'] ?? 0;
    $stmt->close();

    // Total Posts
    $posts_count_sql = "SELECT COUNT(*) AS total FROM workspace_posts";
    $stmt = $conn->prepare($posts_count_sql);
    if (!$stmt) {
        throw new Exception("Prepare statement failed for posts count: " . $conn->error);
    }
    $stmt->execute();
    $result = $stmt->get_result();
    $posts_count = $result->fetch_assoc()['total'] ?? 0;
    $stmt->close();

    // Total Notes
    $notes_count_sql = "SELECT COUNT(*) AS total FROM workspace_notes";
    $stmt = $conn->prepare($notes_count_sql);
    if (!$stmt) {
        throw new Exception("Prepare statement failed for notes count: " . $conn->error);
    }
    $stmt->execute();
    $result = $stmt->get_result();
    $notes_count = $result->fetch_assoc()['total'] ?? 0;
    $stmt->close();
} catch (Exception $e) {
    $errors[] = $e->getMessage();
    $plans_count = $posts_count = $notes_count = 0; // Default values in case of error
}

// Fetch upcoming plans and posts for the calendar along with creator's username
try {
    // Fetch Plans
    $calendar_plans_sql = "SELECT wp.id, wp.title, wp.due_date, u.username 
                           FROM workspace_plans wp
                           JOIN users u ON wp.user_id = u.id
                           WHERE wp.due_date >= NOW()
                           ORDER BY wp.due_date ASC";
    $stmt = $conn->prepare($calendar_plans_sql);
    if (!$stmt) {
        throw new Exception("Prepare statement failed for calendar plans: " . $conn->error);
    }
    $stmt->execute();
    $result = $stmt->get_result();

    while ($plan = $result->fetch_assoc()) {
        $calendar_events[] = [
            'id'    => 'plan_' . $plan['id'], // Prefix to distinguish type
            'title' => sanitize_input($plan['title']) . " (by " . sanitize_input($plan['username']) . ")",
            'start' => $plan['due_date'],
            'type'  => 'plan', // Custom property to identify type
            'color' => '#3B82F6' // Tailwind Blue-500
        ];
    }
    $stmt->close();

    // Fetch Posts
    $calendar_posts_sql = "SELECT wp.id, CONCAT(wp.platform, ': ', wp.content) AS content, wp.scheduled_datetime, u.username 
                           FROM workspace_posts wp
                           JOIN users u ON wp.user_id = u.id
                           WHERE wp.scheduled_datetime >= NOW()
                           ORDER BY wp.scheduled_datetime ASC";
    $stmt = $conn->prepare($calendar_posts_sql);
    if (!$stmt) {
        throw new Exception("Prepare statement failed for calendar posts: " . $conn->error);
    }
    $stmt->execute();
    $result = $stmt->get_result();

    while ($post = $result->fetch_assoc()) {
        $calendar_events[] = [
            'id'    => 'post_' . $post['id'], // Prefix to distinguish type
            'title' => sanitize_input($post['content']) . " (by " . sanitize_input($post['username']) . ")",
            'start' => $post['scheduled_datetime'],
            'type'  => 'post', // Custom property to identify type
            'color' => '#10B981' // Tailwind Green-500
        ];
    }
    $stmt->close();
} catch (Exception $e) {
    $errors[] = $e->getMessage();
}

// (Optional) Fetch recent activities: Plans, Posts, Notes
$recent_plans = [];
$recent_posts = [];
$recent_notes = [];
$items_per_section = 5; // Number of items to display in each recent section

try {
    // Recent Plans
    $recent_plans_sql = "SELECT wp.*, u.username 
                         FROM workspace_plans wp
                         JOIN users u ON wp.user_id = u.id
                         ORDER BY wp.created_at DESC
                         LIMIT ?";
    $stmt = $conn->prepare($recent_plans_sql);
    if ($stmt) {
        $stmt->bind_param("i", $items_per_section);
        $stmt->execute();
        $result = $stmt->get_result();
        while ($plan = $result->fetch_assoc()) {
            $recent_plans[] = $plan;
        }
        $stmt->close();
    }

    // Recent Posts
    $recent_posts_sql = "SELECT wp.*, u.username 
                         FROM workspace_posts wp
                         JOIN users u ON wp.user_id = u.id
                         ORDER BY wp.created_at DESC
                         LIMIT ?";
    $stmt = $conn->prepare($recent_posts_sql);
    if ($stmt) {
        $stmt->bind_param("i", $items_per_section);
        $stmt->execute();
        $result = $stmt->get_result();
        while ($post = $result->fetch_assoc()) {
            $recent_posts[] = $post;
        }
        $stmt->close();
    }

    // Recent Notes
    $recent_notes_sql = "SELECT wn.*, u.username 
                         FROM workspace_notes wn
                         JOIN users u ON wn.user_id = u.id
                         ORDER BY wn.created_at DESC
                         LIMIT ?";
    $stmt = $conn->prepare($recent_notes_sql);
    if ($stmt) {
        $stmt->bind_param("i", $items_per_section);
        $stmt->execute();
        $result = $stmt->get_result();
        while ($note = $result->fetch_assoc()) {
            $recent_notes[] = $note;
        }
        $stmt->close();
    }
} catch (Exception $e) {
    $errors[] = $e->getMessage();
}
?>

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Workspace Dashboard - Kaak Alia Management System</title>
    <!-- Tailwind CSS -->
    <link href="https://cdn.jsdelivr.net/npm/tailwindcss@2.2.19/dist/tailwind.min.css" rel="stylesheet">
    <!-- Bootstrap Icons -->
    <link href="https://cdn.jsdelivr.net/npm/bootstrap-icons/font/bootstrap-icons.css" rel="stylesheet">
    <!-- FullCalendar CSS -->
    <link href='https://cdn.jsdelivr.net/npm/fullcalendar@5.11.3/main.min.css' rel='stylesheet' />
    <!-- Custom Styles -->
    <style>
        body {
            font-family: 'Cairo', sans-serif;
        }
        #calendar {
            max-width: 100%;
            margin: 0 auto;
            background-color: #ffffff;
            border-radius: 8px;
            box-shadow: 0 4px 6px rgba(0,0,0,0.1);
            padding: 20px;
        }
    </style>
</head>
<body class="bg-gray-100">
    <!-- Header -->
    <?php include __DIR__ . '/../../includes/header.php'; ?>

    <!-- Main Content -->
    <main class="container mx-auto p-6 mt-24 mb-20">
        <h1 class="text-3xl font-bold mb-6">Workspace Dashboard</h1>

        <!-- Display Errors -->
        <?php if (!empty($errors)): ?>
            <div class="mb-6">
                <?php foreach ($errors as $error): ?>
                    <div class="bg-red-100 border border-red-400 text-red-700 px-4 py-3 rounded mb-2">
                        <?= htmlspecialchars($error) ?>
                    </div>
                <?php endforeach; ?>
            </div>
        <?php endif; ?>

        <!-- Summary Cards -->
        <div class="grid grid-cols-1 md:grid-cols-3 gap-6 mb-6">
            <!-- Plans -->
            <div class="flex items-center p-4 bg-blue-500 text-white rounded-lg shadow hover:bg-blue-600 transition">
                <i class="bi bi-list-task text-4xl mr-4"></i>
                <div>
                    <h2 class="text-xl font-semibold">Total Plans</h2>
                    <p class="text-2xl"><?= htmlspecialchars(number_format($plans_count)) ?></p>
                </div>
            </div>
            <!-- Posts -->
            <div class="flex items-center p-4 bg-green-500 text-white rounded-lg shadow hover:bg-green-600 transition">
                <i class="bi bi-calendar-plus text-4xl mr-4"></i>
                <div>
                    <h2 class="text-xl font-semibold">Total Posts</h2>
                    <p class="text-2xl"><?= htmlspecialchars(number_format($posts_count)) ?></p>
                </div>
            </div>
            <!-- Notes -->
            <div class="flex items-center p-4 bg-purple-500 text-white rounded-lg shadow hover:bg-purple-600 transition">
                <i class="bi bi-stickies text-4xl mr-4"></i>
                <div>
                    <h2 class="text-xl font-semibold">Total Notes</h2>
                    <p class="text-2xl"><?= htmlspecialchars(number_format($notes_count)) ?></p>
                </div>
            </div>
        </div>

        <!-- Quick Links -->
        <div class="grid grid-cols-1 md:grid-cols-3 gap-6 mb-6">
            <a href="plans.php" class="block p-6 bg-blue-400 text-white rounded-lg shadow hover:bg-blue-500 transition">
                <i class="bi bi-list-task text-3xl"></i>
                <h2 class="mt-2 text-xl font-semibold">Manage Plans</h2>
            </a>
            <a href="posts.php" class="block p-6 bg-green-400 text-white rounded-lg shadow hover:bg-green-500 transition">
                <i class="bi bi-calendar-plus text-3xl"></i>
                <h2 class="mt-2 text-xl font-semibold">Manage Posts</h2>
            </a>
            <a href="notes.php" class="block p-6 bg-purple-400 text-white rounded-lg shadow hover:bg-purple-500 transition">
                <i class="bi bi-stickies text-3xl"></i>
                <h2 class="mt-2 text-xl font-semibold">Manage Notes</h2>
            </a>
        </div>

        <!-- Calendar -->
        <div class="mb-6">
            <h2 class="text-2xl font-bold mb-4">Upcoming Plans & Posts</h2>
            <div id='calendar'></div>
        </div>

        <!-- (Optional) Recent Activities -->
        <div class="grid grid-cols-1 md:grid-cols-3 gap-6 mb-6">
            <!-- Recent Plans -->
            <div>
                <h3 class="text-xl font-semibold mb-2">Recent Plans</h3>
                <?php if (!empty($recent_plans)): ?>
                    <ul>
                        <?php foreach ($recent_plans as $plan): ?>
                            <li class="mb-2">
                                <span class="font-semibold"><?= htmlspecialchars($plan['title']) ?></span> 
                                by <span class="text-gray-700"><?= htmlspecialchars($plan['username']) ?></span>
                                <br>
                                <span class="text-sm text-gray-500"><?= htmlspecialchars(date("d M Y, h:i A", strtotime($plan['created_at']))) ?></span>
                            </li>
                        <?php endforeach; ?>
                    </ul>
                <?php else: ?>
                    <p class="text-gray-500">No recent plans found.</p>
                <?php endif; ?>
            </div>
            <!-- Recent Posts -->
            <div>
                <h3 class="text-xl font-semibold mb-2">Recent Posts</h3>
                <?php if (!empty($recent_posts)): ?>
                    <ul>
                        <?php foreach ($recent_posts as $post): ?>
                            <li class="mb-2">
                                <span class="font-semibold"><?= htmlspecialchars($post['platform']) ?></span>: 
                                <?= htmlspecialchars(substr($post['content'], 0, 50)) ?>...
                                by <span class="text-gray-700"><?= htmlspecialchars($post['username']) ?></span>
                                <br>
                                <span class="text-sm text-gray-500"><?= htmlspecialchars(date("d M Y, h:i A", strtotime($post['created_at']))) ?></span>
                            </li>
                        <?php endforeach; ?>
                    </ul>
                <?php else: ?>
                    <p class="text-gray-500">No recent posts found.</p>
                <?php endif; ?>
            </div>
            <!-- Recent Notes -->
            <div>
                <h3 class="text-xl font-semibold mb-2">Recent Notes</h3>
                <?php if (!empty($recent_notes)): ?>
                    <ul>
                        <?php foreach ($recent_notes as $note): ?>
                            <li class="mb-2">
                                <span class="font-semibold"><?= htmlspecialchars($note['title']) ?></span> 
                                by <span class="text-gray-700"><?= htmlspecialchars($note['username']) ?></span>
                                <br>
                                <span class="text-sm text-gray-500"><?= htmlspecialchars(date("d M Y, h:i A", strtotime($note['created_at']))) ?></span>
                            </li>
                        <?php endforeach; ?>
                    </ul>
                <?php else: ?>
                    <p class="text-gray-500">No recent notes found.</p>
                <?php endif; ?>
            </div>
        </div>
    </main>

    <!-- Footer -->
    <footer class="fixed bottom-0 left-0 w-full bg-gray-800 text-white text-center p-4">
        &copy; 2024 Kaak Alia Bakery. All rights reserved.
    </footer>

    <!-- FullCalendar JS -->
    <script src='https://cdn.jsdelivr.net/npm/fullcalendar@5.11.3/main.min.js'></script>
    <script>
        document.addEventListener('DOMContentLoaded', function() {
            var calendarEl = document.getElementById('calendar');
            var calendarData = <?= json_encode($calendar_events) ?>;
            var calendar = new FullCalendar.Calendar(calendarEl, {
                initialView: 'dayGridMonth',
                events: calendarData,
                headerToolbar: {
                    left: 'prev,next today',
                    center: 'title',
                    right: 'dayGridMonth,timeGridWeek,timeGridDay'
                },
                eventClick: function(info) {
                    // Determine the type of the event and redirect accordingly
                    const eventType = info.event.extendedProps.type;
                    const eventId = info.event.id.split('_')[1]; // Extract the numeric ID

                    if(eventType === 'plan'){
                        window.location.href = 'view_plan.php?id=' + eventId;
                    } else if(eventType === 'post'){
                        window.location.href = 'view_post.php?id=' + eventId;
                    } else {
                        // Default action or handle other types if necessary
                        alert('Unknown event type.');
                    }
                },
                eventColor: '#06D6A0', // Default event color (can be overridden by individual event colors)
                navLinks: true, // Can click day/week names to navigate views
                selectable: true,
                selectMirror: true,
                select: function(arg) {
                    // Handle date selection for creating new plans
                    if(confirm('Would you like to add a new plan on ' + arg.startStr + '?')) {
                        window.location.href = 'create_plan.php?due_date=' + encodeURIComponent(arg.startStr);
                    }
                    calendar.unselect()
                },
                // Responsive Design Enhancements
                height: 'auto',
                windowResize: function(view) {
                    calendar.render();
                }
            });
            calendar.render();
        });
    </script>
</body>
</html>

<?php
// Flush the output buffer
ob_end_flush();
// No closing PHP tag to prevent unwanted output
?>) and type full codes