based on this codes (<?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'; // Assuming you have a functions.php for utilities like sanitize_input()

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

$user_id = $_SESSION['user_id'];
$calendar_plans = []; // Initialize calendar plans array
$errors = [];

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

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

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

// Fetch upcoming plans for the calendar
try {
    $calendar_sql = "SELECT id, title, due_date FROM workspace_plans WHERE user_id = ? AND due_date >= NOW() ORDER BY due_date ASC";
    $stmt = $conn->prepare($calendar_sql);
    if (!$stmt) {
        throw new Exception("Prepare statement failed for calendar data: " . $conn->error);
    }
    $stmt->bind_param("i", $user_id);
    $stmt->execute();
    $result = $stmt->get_result();

    while ($plan = $result->fetch_assoc()) {
        $calendar_plans[] = [
            'id'    => $plan['id'],
            'title' => htmlspecialchars($plan['title'], ENT_QUOTES, 'UTF-8'),
            'start' => $plan['due_date'], // FullCalendar accepts datetime strings
        ];
    }
    $stmt->close();
} catch (Exception $e) {
    $errors[] = $e->getMessage();
}

?>
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Workspace - 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>
        /* Custom styles can be added here */
        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>
    <?php include __DIR__ . '/../../includes/header.php'; ?>

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

        <?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">
                <i class="bi bi-list-task text-4xl mr-4"></i>
                <div>
                    <h2 class="text-xl font-semibold">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">
                <i class="bi bi-calendar-plus text-4xl mr-4"></i>
                <div>
                    <h2 class="text-xl font-semibold">Scheduled 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">
                <i class="bi bi-stickies text-4xl mr-4"></i>
                <div>
                    <h2 class="text-xl font-semibold">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</h2>
            <div id='calendar'></div>
        </div>
    </main>

    <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_plans) ?>;
            var calendar = new FullCalendar.Calendar(calendarEl, {
                initialView: 'dayGridMonth',
                events: calendarData,
                headerToolbar: {
                    left: 'prev,next today',
                    center: 'title',
                    right: 'dayGridMonth,timeGridWeek,timeGridDay'
                },
                eventClick: function(info) {
                    // Redirect to edit plan page with the plan ID
                    const planId = info.event.id;
                    if(planId){
                        window.location.href = 'edit_plan.php?id=' + planId;
                    }
                },
                eventColor: '#06D6A0', // Optional: Customize event color
                navLinks: true, // can click day/week names to navigate views
                selectable: true,
                selectMirror: true,
                select: function(arg) {
                    // Optional: 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()
                }
            });
            calendar.render();
        });
    </script>
</body>
</html>

<?php
// Flush the output buffer
ob_end_flush();
// No closing PHP tag to prevent unwanted output
?>) and thsi info  databse (-- 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 */;)i want to fix (<?php
// /public/workspace/create_note.php

require_once 'config.php';
$user_id = $_SESSION['user_id'];
$errors = [];

if ($_SERVER['REQUEST_METHOD'] == 'POST') {
    $title = trim($_POST['title']);
    $content = trim($_POST['content']);

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

    if (empty($errors)) {
        $sql = "INSERT INTO workspace_notes (user_id, title, content) VALUES (?, ?, ?)";
        $stmt = $conn->prepare($sql);
        $stmt->bind_param("iss", $user_id, $title, $content);
        if ($stmt->execute()) {
            header("Location: notes.php");
            exit();
        } else {
            $errors[] = "Failed to create note. Please try again.";
        }
    }
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Create Note - Workspace</title>
    <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>
    <?php include '../includes/header.php'; ?>

    <main class="container mx-auto p-6 mt-20">
        <h1 class="text-2xl font-bold mb-6">Create New Note</h1>

        <?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; ?>

        <form action="create_note.php" 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" required value="<?= isset($_POST['title']) ? htmlspecialchars($_POST['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" rows="8" required><?= isset($_POST['content']) ? htmlspecialchars($_POST['content']) : '' ?></textarea>
            </div>
            <div class="flex justify-between">
                <a href="notes.php" 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">Create Note</button>
            </div>
        </form>
    </main>

    <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>
</body>
</html>) and (<?php
// /public/workspace/create_plan.php

require_once 'config.php';
$user_id = $_SESSION['user_id'];
$errors = [];

if ($_SERVER['REQUEST_METHOD'] == 'POST') {
    $title = trim($_POST['title']);
    $description = trim($_POST['description']);
    $due_date = trim($_POST['due_date']);
    $status = $_POST['status'];

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

    if (empty($errors)) {
        $sql = "INSERT INTO workspace_plans (user_id, title, description, due_date, status) VALUES (?, ?, ?, ?, ?)";
        $stmt = $conn->prepare($sql);
        $stmt->bind_param("issss", $user_id, $title, $description, $due_date, $status);
        if ($stmt->execute()) {
            header("Location: plans.php");
            exit();
        } else {
            $errors[] = "Failed to create plan. Please try again.";
        }
    }
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Create Plan - Workspace</title>
    <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>
    <?php include '../includes/header.php'; ?>

    <main class="container mx-auto p-6 mt-20">
        <h1 class="text-2xl font-bold mb-6">Create New Plan</h1>

        <?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; ?>

        <form action="create_plan.php" 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" required value="<?= isset($_POST['title']) ? htmlspecialchars($_POST['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" rows="4"><?= isset($_POST['description']) ? htmlspecialchars($_POST['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" required value="<?= isset($_POST['due_date']) ? htmlspecialchars($_POST['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">
                    <option value="Not Started" <?= isset($_POST['status']) && $_POST['status'] == 'Not Started' ? 'selected' : '' ?>>Not Started</option>
                    <option value="In Progress" <?= isset($_POST['status']) && $_POST['status'] == 'In Progress' ? 'selected' : '' ?>>In Progress</option>
                    <option value="Completed" <?= isset($_POST['status']) && $_POST['status'] == 'Completed' ? 'selected' : '' ?>>Completed</option>
                </select>
            </div>
            <div class="flex justify-between">
                <a href="plans.php" 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">Create Plan</button>
            </div>
        </form>
    </main>

    <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>
</body>
</html>) and (<?php
// /public/workspace/create_post.php

require_once 'config.php';
$user_id = $_SESSION['user_id'];
$errors = [];

if ($_SERVER['REQUEST_METHOD'] == 'POST') {
    $platform = $_POST['platform'];
    $content = trim($_POST['content']);
    $scheduled_datetime = trim($_POST['scheduled_datetime']);
    $status = 'Scheduled'; // Default status

    // Handle media upload if any
    $media_url = null;
    if(isset($_FILES['media']) && $_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 = '../../assets/uploads/workspace_posts/';
            if(!is_dir($upload_dir)){
                mkdir($upload_dir, 0755, true);
            }
            $filename = time() . '_' . basename($_FILES['media']['name']);
            $filepath = $upload_dir . $filename;
            if(move_uploaded_file($_FILES['media']['tmp_name'], $filepath)){
                $media_url = '/assets/uploads/workspace_posts/' . $filename;
            } else {
                $errors[] = "Failed to upload media.";
            }
        } else {
            $errors[] = "Unsupported media type. Allowed types: JPEG, PNG, GIF, MP4.";
        }
    }

    // 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.";
    }

    if (empty($errors)) {
        $sql = "INSERT INTO workspace_posts (user_id, platform, content, media_url, scheduled_datetime, status) VALUES (?, ?, ?, ?, ?, ?)";
        $stmt = $conn->prepare($sql);
        $stmt->bind_param("isssss", $user_id, $platform, $content, $media_url, $scheduled_datetime, $status);
        if ($stmt->execute()) {
            header("Location: posts.php");
            exit();
        } else {
            $errors[] = "Failed to schedule post. Please try again.";
        }
    }
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Schedule Post - Workspace</title>
    <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>
    <?php include '../includes/header.php'; ?>

    <main class="container mx-auto p-6 mt-20">
        <h1 class="text-2xl font-bold mb-6">Schedule New Post</h1>

        <?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; ?>

        <form action="create_post.php" 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" required>
                    <option value="">-- Select Platform --</option>
                    <option value="Instagram" <?= isset($_POST['platform']) && $_POST['platform'] == 'Instagram' ? 'selected' : '' ?>>Instagram</option>
                    <option value="Facebook" <?= isset($_POST['platform']) && $_POST['platform'] == 'Facebook' ? 'selected' : '' ?>>Facebook</option>
                    <option value="Twitter" <?= isset($_POST['platform']) && $_POST['platform'] == 'Twitter' ? 'selected' : '' ?>>Twitter</option>
                    <option value="Other" <?= isset($_POST['platform']) && $_POST['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" rows="6" required><?= isset($_POST['content']) ? htmlspecialchars($_POST['content']) : '' ?></textarea>
            </div>
            <div class="mb-4">
                <label class="block text-gray-700">Media (Optional)</label>
                <input type="file" name="media" class="w-full px-3 py-2 border rounded">
                <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" required value="<?= isset($_POST['scheduled_datetime']) ? htmlspecialchars($_POST['scheduled_datetime']) : '' ?>">
            </div>
            <div class="flex justify-between">
                <a href="posts.php" 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-green-500 text-white rounded hover:bg-green-600">Schedule Post</button>
            </div>
        </form>
    </main>

    <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>
</body>
</html>) and (<?php
// /public/workspace/notes.php

require_once 'config.php';
$user_id = $_SESSION['user_id'];

// Fetch user's notes
$sql = "SELECT * FROM workspace_notes WHERE user_id = ? ORDER BY updated_at DESC";
$stmt = $conn->prepare($sql);
$stmt->bind_param("i", $user_id);
$stmt->execute();
$result = $stmt->get_result();
?>
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Notes - Workspace</title>
    <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>
    <?php include '../includes/header.php'; ?>

    <main class="container mx-auto p-6 mt-20">
        <div class="flex justify-between items-center mb-6">
            <h1 class="text-2xl font-bold">Notes</h1>
            <a href="create_note.php" class="px-4 py-2 bg-purple-500 text-white rounded hover:bg-purple-600 flex items-center">
                <i class="bi bi-plus-lg mr-2"></i> Add New Note
            </a>
        </div>

        <?php if($result->num_rows > 0): ?>
            <div class="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-6">
                <?php while($note = $result->fetch_assoc()): ?>
                    <div class="bg-white p-4 rounded shadow">
                        <h2 class="text-xl font-semibold mb-2"><?= htmlspecialchars($note['title']) ?></h2>
                        <p class="text-gray-700 mb-4"><?= nl2br(htmlspecialchars($note['content'])) ?></p>
                        <div class="flex justify-between items-center">
                            <span class="text-sm text-gray-500"><?= htmlspecialchars(date("d M Y, h:i A", strtotime($note['updated_at']))) ?></span>
                            <div class="space-x-2">
                                <a href="edit_note.php?id=<?= $note['id'] ?>" class="text-blue-500 hover:underline">Edit</a>
                                <a href="delete_note.php?id=<?= $note['id'] ?>" class="text-red-500 hover:underline" onclick="return confirm('Are you sure you want to delete this note?');">Delete</a>
                            </div>
                        </div>
                    </div>
                <?php endwhile; ?>
            </div>
        <?php else: ?>
            <p class="text-center text-gray-500">No notes found. Start by adding a new note.</p>
        <?php endif; ?>
    </main>

    <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>
</body>
</html>)(<?php
// /public/workspace/plans.php

require_once 'config.php';
$user_id = $_SESSION['user_id'];

// Fetch user's plans
$sql = "SELECT * FROM workspace_plans WHERE user_id = ? ORDER BY due_date ASC";
$stmt = $conn->prepare($sql);
$stmt->bind_param("i", $user_id);
$stmt->execute();
$result = $stmt->get_result();
?>
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Plans & Tasks - Workspace</title>
    <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>
    <?php include '../includes/header.php'; ?>

    <main class="container mx-auto p-6 mt-20">
        <div class="flex justify-between items-center mb-6">
            <h1 class="text-2xl font-bold">Plans & Tasks</h1>
            <a href="create_plan.php" class="px-4 py-2 bg-blue-500 text-white rounded hover:bg-blue-600 flex items-center">
                <i class="bi bi-plus-lg mr-2"></i> Add New Plan
            </a>
        </div>

        <?php if($result->num_rows > 0): ?>
            <table class="w-full table-auto">
                <thead>
                    <tr class="bg-gray-200">
                        <th class="px-4 py-2">Title</th>
                        <th class="px-4 py-2">Description</th>
                        <th class="px-4 py-2">Due Date</th>
                        <th class="px-4 py-2">Status</th>
                        <th class="px-4 py-2">Actions</th>
                    </tr>
                </thead>
                <tbody>
                    <?php while($plan = $result->fetch_assoc()): ?>
                        <tr class="border-b">
                            <td class="px-4 py-2"><?= htmlspecialchars($plan['title']) ?></td>
                            <td class="px-4 py-2"><?= nl2br(htmlspecialchars($plan['description'])) ?></td>
                            <td class="px-4 py-2"><?= htmlspecialchars(date("d M Y, h:i A", strtotime($plan['due_date']))) ?></td>
                            <td class="px-4 py-2">
                                <span class="px-2 py-1 rounded <?= 
                                    $plan['status'] == 'Completed' ? 'bg-green-500' :
                                    ($plan['status'] == 'In Progress' ? 'bg-yellow-500' : 'bg-red-500') ?>">
                                    <?= htmlspecialchars($plan['status']) ?>
                                </span>
                            </td>
                            <td class="px-4 py-2">
                                <a href="edit_plan.php?id=<?= $plan['id'] ?>" class="text-blue-500 hover:underline">Edit</a> |
                                <a href="delete_plan.php?id=<?= $plan['id'] ?>" class="text-red-500 hover:underline" onclick="return confirm('Are you sure you want to delete this plan?');">Delete</a>
                            </td>
                        </tr>
                    <?php endwhile; ?>
                </tbody>
            </table>
        <?php else: ?>
            <p class="text-center text-gray-500">No plans found. Start by adding a new plan.</p>
        <?php endif; ?>
    </main>

    <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>
</body>
</html>)(<?php
// /public/workspace/posts.php

require_once 'config.php';
$user_id = $_SESSION['user_id'];

// Fetch user's posts
$sql = "SELECT * FROM workspace_posts WHERE user_id = ? ORDER BY scheduled_datetime ASC";
$stmt = $conn->prepare($sql);
$stmt->bind_param("i", $user_id);
$stmt->execute();
$result = $stmt->get_result();
?>
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Scheduled Posts - Workspace</title>
    <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>
    <?php include '../includes/header.php'; ?>

    <main class="container mx-auto p-6 mt-20">
        <div class="flex justify-between items-center mb-6">
            <h1 class="text-2xl font-bold">Scheduled Posts</h1>
            <a href="create_post.php" class="px-4 py-2 bg-green-500 text-white rounded hover:bg-green-600 flex items-center">
                <i class="bi bi-plus-lg mr-2"></i> Schedule Post
            </a>
        </div>

        <?php if($result->num_rows > 0): ?>
            <table class="w-full table-auto">
                <thead>
                    <tr class="bg-gray-200">
                        <th class="px-4 py-2">Platform</th>
                        <th class="px-4 py-2">Content</th>
                        <th class="px-4 py-2">Media</th>
                        <th class="px-4 py-2">Scheduled DateTime</th>
                        <th class="px-4 py-2">Status</th>
                        <th class="px-4 py-2">Actions</th>
                    </tr>
                </thead>
                <tbody>
                    <?php while($post = $result->fetch_assoc()): ?>
                        <tr class="border-b">
                            <td class="px-4 py-2"><?= htmlspecialchars($post['platform']) ?></td>
                            <td class="px-4 py-2"><?= nl2br(htmlspecialchars($post['content'])) ?></td>
                            <td class="px-4 py-2">
                                <?php if($post['media_url']): ?>
                                    <a href="<?= htmlspecialchars($post['media_url']) ?>" target="_blank" class="text-blue-500 hover:underline">View Media</a>
                                <?php else: ?>
                                    N/A
                                <?php endif; ?>
                            </td>
                            <td class="px-4 py-2"><?= htmlspecialchars(date("d M Y, h:i A", strtotime($post['scheduled_datetime']))) ?></td>
                            <td class="px-4 py-2">
                                <span class="px-2 py-1 rounded <?= 
                                    $post['status'] == 'Posted' ? 'bg-green-500' :
                                    ($post['status'] == 'Failed' ? 'bg-red-500' : 'bg-yellow-500') ?>">
                                    <?= htmlspecialchars($post['status']) ?>
                                </span>
                            </td>
                            <td class="px-4 py-2">
                                <a href="edit_post.php?id=<?= $post['id'] ?>" class="text-blue-500 hover:underline">Edit</a> |
                                <a href="delete_post.php?id=<?= $post['id'] ?>" class="text-red-500 hover:underline" onclick="return confirm('Are you sure you want to delete this post?');">Delete</a>
                            </td>
                        </tr>
                    <?php endwhile; ?>
                </tbody>
            </table>
        <?php else: ?>
            <p class="text-center text-gray-500">No scheduled posts found. Start by scheduling a new post.</p>
        <?php endif; ?>
    </main>

    <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>
</body>
</html>) and type full codes with goodstyles