based on this codes (<?php // /public/workspace/index.php… · The Chat Archive
Explore / Programming based on this codes (<?php // /public/workspace/index.php // Enable error reporting for… Save Share Download ▾ Reportbased 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();
}
u s e r i d = user_id = u se r i d = _SESSION['user_id'];
c a l e n d a r p l a n s = [ ] ; / / I n errors = [];
Show full message · 1,059 lines Assistant2024-11-10 08:18 UTC Copy response
Copy first prompt
Details
Provider OpenAI
Model provenance As recorded by source dataset
Turns 1 (2 messages)
Language en
Conversation date Nov 10, 2024
Added to archive Nov 16, 2026
ID 01m7h427a8zch1jykf89q7taxcSource & license Imported from WildChat-4.8M (AI2) (source ). Imported records earn no Research Points.
Upstream record: 9a0542e364983ec75e0470d6c36b956a
Zhao et al., WildChat: 1M ChatGPT Interaction Logs in the Wild (ICLR 2024). Contains information from WildChat-4.8M, made available under the ODC Attribution License.
License: ODC-BY-1.0
i t i a l i z e c a l e n d a r p l a n s a r r a y calendar_plans = []; // Initialize calendar plans array
c a l e n d a r p l an s = [ ] ; // I ni t ia l i z ec a l e n d a r pl an s a r r a y
// Fetch summary data: Number of plans, posts, notes
try {
// Prepare and execute plans count
p l a n s c o u n t s q l = " S E L E C T C O U N T ( ∗ ) A S t o t a l F R O M w o r k s p a c e p l a n s W H E R E u s e r i d = ? " ; plans_count_sql = "SELECT COUNT(*) AS total FROM workspace_plans WHERE user_id = ?";
pl an s c o u n t s q l = " S E L E C T C O U N T ( ∗ ) A S t o t a l F R O M w or k s p a c e p l an s W H E R ? " ; stmt = c o n n − > p r e p a r e ( conn->prepare( co nn − > p r e p a r e ( plans_count_sql);
if (!stmt) {
throw new Exception("Prepare statement failed for plans count: " . conn->error);
}
s t m t − > b i n d p a r a m ( " i " , stmt->bind_param("i", s t m t − > bin d p a r am ( " i " , user_id);
s t m t − > e x e c u t e ( ) ; stmt->execute();
s t m t − > e x ec u t e ( ) ; result = s t m t − > g e t r e s u l t ( ) ; stmt->get_result();
s t m t − > g e t r es u l t ( ) ; plans_count = r e s u l t − > f e t c h a s s o c ( ) [ ′ t o t a l ′ ] ; result->fetch_assoc()['total'];
r es u l t − > f e t c h a ssoc ( ) [ stmt->close();
code Copy code
// 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 − > g e t M e s s a g e ( ) ; e->getMessage();
e − > g e tM ess a g e ( ) ; plans_count = p o s t s c o u n t = posts_count = p os t s c o u n t = notes_count = 0; // Default values in case of error
}
// Fetch upcoming plans for the calendar
try {
c a l e n d a r s q l = " S E L E C T i d , t i t l e , d u e d a t e F R O M w o r k s p a c e p l a n s W H E R E u s e r i d = ? A N D d u e d a t e > = N O W ( ) O R D E R B Y d u e d a t e A S C " ; calendar_sql = "SELECT id, title, due_date FROM workspace_plans WHERE user_id = ? AND due_date >= NOW() ORDER BY due_date ASC";
c a l e n d a r s q l = " S E L E C T i d , t i tl e , d u e d a t e F R O M w or k s p a c e p ? A N D d u e d a t e >= N O W ( ) O R D E R B Y d u e d a t e A S C " ; stmt = c o n n − > p r e p a r e ( conn->prepare( co nn − > p r e p a r e ( calendar_sql);
if (!stmt) {
throw new Exception("Prepare statement failed for calendar data: " . conn->error);
}
s t m t − > b i n d p a r a m ( " i " , stmt->bind_param("i", s t m t − > bin d p a r am ( " i " , user_id);
s t m t − > e x e c u t e ( ) ; stmt->execute();
s t m t − > e x ec u t e ( ) ; result = $stmt->get_result();
code Copy code
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();
}
code Copy code
<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">
© 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>
-- 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';
u s e r i d = user_id = u se r i d = _SESSION['user_id'];
$errors = [];
if (_SERVER['REQUEST_METHOD'] == 'POST') {
title = trim(P O S T [ ′ t i t l e ′ ] ) ; _POST['title']);
P O S T [ ′ t i tl e ′ ]) ; content = trim($_POST['content']);
code Copy code
// 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.";
}
}
code Copy code
<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">
© 2024 Kaak Alia Bakery. All rights reserved.
</footer>
require_once 'config.php';
u s e r i d = user_id = u se r i d = _SESSION['user_id'];
$errors = [];
if (_SERVER['REQUEST_METHOD'] == 'POST') {
title = trim(P O S T [ ′ t i t l e ′ ] ) ; _POST['title']);
P O S T [ ′ t i tl e ′ ]) ; description = trim(P O S T [ ′ d e s c r i p t i o n ′ ] ) ; _POST['description']);
P O S T [ ′ d escr i pt i o n ′ due_date = trim(P O S T [ ′ d u e d a t e ′ ] ) ; _POST['due_date']);
P O S T [ ′ d u e d a t status = $_POST['status'];
code Copy code
// 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.";
}
}
code Copy code
<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">
© 2024 Kaak Alia Bakery. All rights reserved.
</footer>
require_once 'config.php';
u s e r i d = user_id = u se r i d = _SESSION['user_id'];
$errors = [];
if (_SERVER['REQUEST_METHOD'] == 'POST') {
platform = P O S T [ ′ p l a t f o r m ′ ] ; _POST['platform'];
P O S T [ ′ pl a t f or m ′ ] ; content = trim(P O S T [ ′ c o n t e n t ′ ] ) ; _POST['content']);
P O S T [ ′ co n t e n t ′ ]) ; scheduled_datetime = trim(P O S T [ ′ s c h e d u l e d d a t e t i m e ′ ] ) ; _POST['scheduled_datetime']);
P O S T [ ′ sc h e d u l e d status = 'Scheduled'; // Default status
code Copy code
// 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.";
}
}
code Copy code
<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">
© 2024 Kaak Alia Bakery. All rights reserved.
</footer>
require_once 'config.php';
u s e r i d = user_id = u se r i d = _SESSION['user_id'];
// Fetch user's notes
s q l = " S E L E C T ∗ F R O M w o r k s p a c e n o t e s W H E R E u s e r i d = ? O R D E R B Y u p d a t e d a t D E S C " ; sql = "SELECT * FROM workspace_notes WHERE user_id = ? ORDER BY updated_at DESC";
s q l = " S E L E C T ∗ F R O M w or k s p a c e n o t es W H E R E u se r i d = ? O R D E R B Y u p d a t e d a t D E S C " ; stmt = c o n n − > p r e p a r e ( conn->prepare( co nn − > p r e p a r e ( sql);
s t m t − > b i n d p a r a m ( " i " , stmt->bind_param("i", s t m t − > bin d p a r am ( " i " , user_id);
s t m t − > e x e c u t e ( ) ; stmt->execute();
s t m t − > e x ec u t e ( ) ; result = $stmt->get_result();
?>
code Copy code
<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">
© 2024 Kaak Alia Bakery. All rights reserved.
</footer>
require_once 'config.php';
u s e r i d = user_id = u se r i d = _SESSION['user_id'];
// Fetch user's plans
s q l = " S E L E C T ∗ F R O M w o r k s p a c e p l a n s W H E R E u s e r i d = ? O R D E R B Y d u e d a t e A S C " ; sql = "SELECT * FROM workspace_plans WHERE user_id = ? ORDER BY due_date ASC";
s q l = " S E L E C T ∗ F R O M w or k s p a c e p l an s W H E R E u se r i d = ? O R D E R B Y d u e d a t e A S C " ; stmt = c o n n − > p r e p a r e ( conn->prepare( co nn − > p r e p a r e ( sql);
s t m t − > b i n d p a r a m ( " i " , stmt->bind_param("i", s t m t − > bin d p a r am ( " i " , user_id);
s t m t − > e x e c u t e ( ) ; stmt->execute();
s t m t − > e x ec u t e ( ) ; result = $stmt->get_result();
?>
code Copy code
<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">
© 2024 Kaak Alia Bakery. All rights reserved.
</footer>
require_once 'config.php';
u s e r i d = user_id = u se r i d = _SESSION['user_id'];
// Fetch user's posts
s q l = " S E L E C T ∗ F R O M w o r k s p a c e p o s t s W H E R E u s e r i d = ? O R D E R B Y s c h e d u l e d d a t e t i m e A S C " ; sql = "SELECT * FROM workspace_posts WHERE user_id = ? ORDER BY scheduled_datetime ASC";
s q l = " S E L E C T ∗ F R O M w or k s p a c e p os t s W H E R E u se r i d = ? O R D E R B Y sc h e d u l e d d a t e t im e A S C " ; stmt = c o n n − > p r e p a r e ( conn->prepare( co nn − > p r e p a r e ( sql);
s t m t − > b i n d p a r a m ( " i " , stmt->bind_param("i", s t m t − > bin d p a r am ( " i " , user_id);
s t m t − > e x e c u t e ( ) ; stmt->execute();
s t m t − > e x ec u t e ( ) ; result = $stmt->get_result();
?>
code Copy code
<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">
© 2024 Kaak Alia Bakery. All rights reserved.
</footer>
Certainly! I'll provide you with fully integrated and improved versions of your PHP files, ensuring they are secure, maintainable, and styled consistently using Tailwind CSS. I'll also address common issues such as session management, input sanitization, error handling, and security enhancements.
Prerequisites:
Session Management : Ensure that session_start() is called at the beginning of each script that requires session access.
Configuration File (config.php) : This file should handle database connections and include necessary utilities.
Utility Functions (functions.php) : Include functions like sanitize_input() to sanitize user inputs.
Directory Structure:
Assuming the following directory structure for clarity:
code Copy code
/public
/workspace
index.php
create_note.php
create_plan.php
create_post.php
notes.php
plans.php
posts.php
/includes
config.php
auth.php
functions.php
header.php
/assets
/uploads
/workspace_posts
1. Configuration File (config.php)
Ensure that you have a central configuration file that initializes the session and establishes the database connection.
php Copy code
<?php
// /includes/config.php
session_start();
// Database configuration
define('DB_SERVER', 'localhost');
define('DB_USERNAME', 'your_db_username');
define('DB_PASSWORD', 'your_db_password');
define('DB_NAME', 'u406552082_kaakalia');
// Attempt to connect to MySQL database
$conn = new mysqli(DB_SERVER, DB_USERNAME, DB_PASSWORD, DB_NAME);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
// Set character set to UTF-8
$conn->set_charset("utf8mb4");
?>
2. Authentication Check (auth.php)
Ensure that this file checks if the user is authenticated. Redirect to the login page if not.
php Copy code
<?php
// /includes/auth.php
if (!isset($_SESSION['user_id'])) {
header("Location: /public/login.php");
exit();
}
?>
3. Utility Functions (functions.php)
Include any utility functions you might need, such as input sanitization.
php Copy code
<?php
// /includes/functions.php
/**
* Sanitize input data to prevent XSS
*
* @param string $data
* @return string
*/
function sanitize_input($data) {
return htmlspecialchars(trim($data), ENT_QUOTES, 'UTF-8');
}
?>
4. Header (header.php)
A common header file to include in all workspace pages.
php Copy code
<?php
// /includes/header.php
?>
<header class="fixed top-0 left-0 w-full bg-gray-800 text-white shadow-md z-50">
<div class="container mx-auto flex justify-between items-center p-4">
<a href="/public/workspace/index.php" class="text-xl font-bold">Kaak Alia Workspace</a>
<nav>
<a href="/public/workspace/index.php" class="mx-2 hover:underline">Dashboard</a>
<a href="/public/workspace/notes.php" class="mx-2 hover:underline">Notes</a>
<a href="/public/workspace/plans.php" class="mx-2 hover:underline">Plans & Tasks</a>
<a href="/public/workspace/posts.php" class="mx-2 hover:underline">Scheduled Posts</a>
<a href="/public/logout.php" class="mx-2 hover:underline">Logout</a>
</nav>
</div>
</header>
5. Workspace Dashboard (index.php)
Improved version with better error handling and security.
6. Create Note (create_note.php)
Improved version with enhanced security and styling.
7. Create Plan (create_plan.php)
Improved version with better validation and styling.
8. Create Post (create_post.php)
Improved version with secure file upload handling and better validation.
9. Notes Listing (notes.php)
Improved version with better security and styling.
php Copy code
<?php
// /public/workspace/notes.php
// Include necessary files
require_once __DIR__ . '/../../includes/config.php';
require_once __DIR__ . '/../../includes/auth.php';
require_once __DIR__ . '/../../includes/functions.php';
$user_id = $_SESSION['user_id'];
// Fetch user's notes
$sql = "SELECT * FROM workspace_notes WHERE user_id = ? ORDER BY updated_at DESC";
if ($stmt = $conn->prepare($sql)) {
$stmt->bind_param("i", $user_id);
$stmt->execute();
$result = $stmt->get_result();
$stmt->close();
} else {
$result = false; // Handle error accordingly
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Notes - 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">
<?php include __DIR__ . '/../../includes/header.php'; ?>
<main class="container mx-auto p-6 mt-24 mb-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 && $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 hover:shadow-lg transition">
<h2 class="text-xl font-semibold mb-2"><?= sanitize_input($note['title']) ?></h2>
<p class="text-gray-700 mb-4"><?= nl2br(sanitize_input($note['content'])) ?></p>
<div class="flex justify-between items-center">
<span class="text-sm text-gray-500"><?= 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="bg-gray-800 text-white text-center p-4 fixed bottom-0 left-0 w-full">
© 2024 Kaak Alia Bakery. All rights reserved.
</footer>
</body>
</html>
10. Plans Listing (plans.php)
Improved version with better security and styling.
11. Scheduled Posts Listing (posts.php)
Improved version with better security and styling.
12. Additional Enhancements
To further secure your application and improve user experience, consider the following:
CSRF Protection : Implement CSRF tokens in your forms to prevent Cross-Site Request Forgery attacks.
Input Validation : Use server-side validation to ensure that all inputs meet expected formats and constraints.
Error Logging : Instead of displaying errors to users, log them to a file for debugging purposes.
Responsive Design : Ensure that all pages are mobile-friendly and render well on different devices.
Pagination : For listing pages like notes.php, plans.php, and posts.php, implement pagination if the number of records grows large.
User Roles : Implement user roles and permissions if different levels of access are required (e.g., admin vs. staff).
13. Security Best Practices
Prepared Statements : Continue using prepared statements to prevent SQL injection.
File Upload Security :
Validate file types and sizes before uploading.
Store uploaded files outside the web root or use .htaccess to prevent direct access.
XSS Protection : Always sanitize user inputs and outputs using htmlspecialchars() or equivalent functions.
Session Security :
Use secure cookies (secure and httponly flags).
Regenerate session IDs upon login to prevent session fixation.
14. Testing
After implementing the above code:
Test All Functionalities : Ensure that creating, editing, deleting notes, plans, and posts work as expected.
Check Responsiveness : Verify that the UI looks good on various devices and screen sizes.
Validate Security : Attempt common attacks like SQL injection and XSS to ensure protections are in place.
Error Handling : Intentionally cause errors to see if they are handled gracefully without exposing sensitive information.
15. Database Considerations
Ensure that your database tables match the structure provided in your SQL dump. Here's a quick checklist:
Primary Keys : Each table should have a primary key (id).
Foreign Keys : Ensure foreign key constraints are correctly set up to maintain data integrity.
Indexes : Proper indexing can significantly improve query performance.
Data Types : Use appropriate data types for each column to optimize storage and performance.
16. Final Notes
Code Organization : Consider using an MVC framework or organizing your code into classes and functions for better maintainability.
Version Control : Use a version control system like Git to track changes and collaborate with others.
Backup : Regularly back up your database and important files to prevent data loss.
By following the above guidelines and utilizing the improved code samples, your Kaak Alia Management System's workspace should be more secure, maintainable, and user-friendly. If you encounter specific issues or need further assistance with particular functionalities, feel free to ask!
Show full message · 1,021 lines Copy first response
Not yet included in a published release.
E
u
se
r i
d
=
′
t
o
t
a
l ′
]
;
l
an
s
W
H
E
R
E
u
se
r i
d
=
])
;
e
′
])
;
d
a
t
e
t
im
e ′
])
;
<?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 necessary files
require_once __DIR__ . '/../../includes/config.php';
require_once __DIR__ . '/../../includes/auth.php';
require_once __DIR__ . '/../../includes/functions.php';
// Initialize variables
$user_id = $_SESSION['user_id'];
$calendar_plans = [];
$errors = [];
// Fetch summary data: Number of plans, posts, notes
try {
// Plans Count
$stmt = $conn->prepare("SELECT COUNT(*) AS total FROM workspace_plans WHERE user_id = ?");
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'] ?? 0;
$stmt->close();
// Posts Count
$stmt = $conn->prepare("SELECT COUNT(*) AS total FROM workspace_posts WHERE user_id = ?");
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'] ?? 0;
$stmt->close();
// Notes Count
$stmt = $conn->prepare("SELECT COUNT(*) AS total FROM workspace_notes WHERE user_id = ?");
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'] ?? 0;
$stmt->close();
} catch (Exception $e) {
$errors[] = $e->getMessage();
$plans_count = $posts_count = $notes_count = 0;
}
// Fetch upcoming plans for the calendar
try {
$stmt = $conn->prepare("SELECT id, title, due_date FROM workspace_plans WHERE user_id = ? AND due_date >= NOW() ORDER BY due_date ASC");
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' => sanitize_input($plan['title']),
'start' => $plan['due_date'],
];
}
$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">
<?php include __DIR__ . '/../../includes/header.php'; ?>
<main class="container mx-auto p-6 mt-24 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">
<?= sanitize_input($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">Plans</h2>
<p class="text-2xl"><?= sanitize_input(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">Scheduled Posts</h2>
<p class="text-2xl"><?= sanitize_input(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">Notes</h2>
<p class="text-2xl"><?= sanitize_input(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="bg-gray-800 text-white text-center p-4 fixed bottom-0 left-0 w-full">
© 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) {
const planId = info.event.id;
if(planId){
window.location.href = 'edit_plan.php?id=' + planId;
}
},
eventColor: '#06D6A0',
navLinks: true,
selectable: true,
selectMirror: true,
select: function(arg) {
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();
?>
<?php
// /public/workspace/create_note.php
// Include necessary files
require_once __DIR__ . '/../../includes/config.php';
require_once __DIR__ . '/../../includes/auth.php';
require_once __DIR__ . '/../../includes/functions.php';
$user_id = $_SESSION['user_id'];
$errors = [];
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 (empty($errors)) {
$sql = "INSERT INTO workspace_notes (user_id, title, content) VALUES (?, ?, ?)";
if ($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.";
}
$stmt->close();
} else {
$errors[] = "Database error: Unable to prepare statement.";
}
}
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Create 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">
<?php include __DIR__ . '/../../includes/header.php'; ?>
<main class="container mx-auto p-6 mt-24">
<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><?= $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']) ? $_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']) ? $_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="bg-gray-800 text-white text-center p-4 fixed bottom-0 left-0 w-full">
© 2024 Kaak Alia Bakery. All rights reserved.
</footer>
</body>
</html>
<?php
// /public/workspace/create_plan.php
// Include necessary files
require_once __DIR__ . '/../../includes/config.php';
require_once __DIR__ . '/../../includes/auth.php';
require_once __DIR__ . '/../../includes/functions.php';
$user_id = $_SESSION['user_id'];
$errors = [];
// Pre-fill due_date if passed via GET
$pre_fill_due_date = sanitize_input($_GET['due_date'] ?? '');
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.";
}
if (empty($errors)) {
$sql = "INSERT INTO workspace_plans (user_id, title, description, due_date, status) VALUES (?, ?, ?, ?, ?)";
if ($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.";
}
$stmt->close();
} else {
$errors[] = "Database error: Unable to prepare statement.";
}
}
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Create 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">
<?php include __DIR__ . '/../../includes/header.php'; ?>
<main class="container mx-auto p-6 mt-24">
<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><?= $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']) ? $_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']) ? $_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']) ? $_POST['due_date'] : $pre_fill_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="bg-gray-800 text-white text-center p-4 fixed bottom-0 left-0 w-full">
© 2024 Kaak Alia Bakery. All rights reserved.
</footer>
</body>
</html>
<?php
// /public/workspace/create_post.php
// Include necessary files
require_once __DIR__ . '/../../includes/config.php';
require_once __DIR__ . '/../../includes/auth.php';
require_once __DIR__ . '/../../includes/functions.php';
$user_id = $_SESSION['user_id'];
$errors = [];
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
$platform = sanitize_input($_POST['platform'] ?? '');
$content = sanitize_input($_POST['content'] ?? '');
$scheduled_datetime = sanitize_input($_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 = __DIR__ . '/../../assets/uploads/workspace_posts/';
if(!is_dir($upload_dir)){
mkdir($upload_dir, 0755, true);
}
// Generate a unique filename to prevent overwriting
$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)){
// Store relative path
$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.";
}
// 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)) {
$sql = "INSERT INTO workspace_posts (user_id, platform, content, media_url, scheduled_datetime, status) VALUES (?, ?, ?, ?, ?, ?)";
if ($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.";
}
$stmt->close();
} else {
$errors[] = "Database error: Unable to prepare statement.";
}
}
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Schedule 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">
<?php include __DIR__ . '/../../includes/header.php'; ?>
<main class="container mx-auto p-6 mt-24">
<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><?= $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']) ? $_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']) ? $_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="bg-gray-800 text-white text-center p-4 fixed bottom-0 left-0 w-full">
© 2024 Kaak Alia Bakery. All rights reserved.
</footer>
</body>
</html>
<?php
// /public/workspace/plans.php
// Include necessary files
require_once __DIR__ . '/../../includes/config.php';
require_once __DIR__ . '/../../includes/auth.php';
require_once __DIR__ . '/../../includes/functions.php';
$user_id = $_SESSION['user_id'];
// Fetch user's plans
$sql = "SELECT * FROM workspace_plans WHERE user_id = ? ORDER BY due_date ASC";
if ($stmt = $conn->prepare($sql)) {
$stmt->bind_param("i", $user_id);
$stmt->execute();
$result = $stmt->get_result();
$stmt->close();
} else {
$result = false; // Handle error accordingly
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Plans & Tasks - 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">
<?php include __DIR__ . '/../../includes/header.php'; ?>
<main class="container mx-auto p-6 mt-24 mb-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 && $result->num_rows > 0): ?>
<div class="overflow-x-auto">
<table class="min-w-full bg-white rounded shadow-md">
<thead>
<tr class="bg-gray-200">
<th class="px-4 py-2 text-left">Title</th>
<th class="px-4 py-2 text-left">Description</th>
<th class="px-4 py-2 text-left">Due Date</th>
<th class="px-4 py-2 text-left">Status</th>
<th class="px-4 py-2 text-left">Actions</th>
</tr>
</thead>
<tbody>
<?php while($plan = $result->fetch_assoc()): ?>
<tr class="border-b hover:bg-gray-100">
<td class="px-4 py-2"><?= sanitize_input($plan['title']) ?></td>
<td class="px-4 py-2"><?= nl2br(sanitize_input($plan['description'])) ?></td>
<td class="px-4 py-2"><?= 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') ?>">
<?= sanitize_input($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>
</div>
<?php else: ?>
<p class="text-center text-gray-500">No plans found. Start by adding a new plan.</p>
<?php endif; ?>
</main>
<footer class="bg-gray-800 text-white text-center p-4 fixed bottom-0 left-0 w-full">
© 2024 Kaak Alia Bakery. All rights reserved.
</footer>
</body>
</html>
<?php
// /public/workspace/posts.php
// Include necessary files
require_once __DIR__ . '/../../includes/config.php';
require_once __DIR__ . '/../../includes/auth.php';
require_once __DIR__ . '/../../includes/functions.php';
$user_id = $_SESSION['user_id'];
// Fetch user's posts
$sql = "SELECT * FROM workspace_posts WHERE user_id = ? ORDER BY scheduled_datetime ASC";
if ($stmt = $conn->prepare($sql)) {
$stmt->bind_param("i", $user_id);
$stmt->execute();
$result = $stmt->get_result();
$stmt->close();
} else {
$result = false; // Handle error accordingly
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Scheduled Posts - 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">
<?php include __DIR__ . '/../../includes/header.php'; ?>
<main class="container mx-auto p-6 mt-24 mb-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 && $result->num_rows > 0): ?>
<div class="overflow-x-auto">
<table class="min-w-full bg-white rounded shadow-md">
<thead>
<tr class="bg-gray-200">
<th class="px-4 py-2 text-left">Platform</th>
<th class="px-4 py-2 text-left">Content</th>
<th class="px-4 py-2 text-left">Media</th>
<th class="px-4 py-2 text-left">Scheduled DateTime</th>
<th class="px-4 py-2 text-left">Status</th>
<th class="px-4 py-2 text-left">Actions</th>
</tr>
</thead>
<tbody>
<?php while($post = $result->fetch_assoc()): ?>
<tr class="border-b hover:bg-gray-100">
<td class="px-4 py-2"><?= sanitize_input($post['platform']) ?></td>
<td class="px-4 py-2"><?= nl2br(sanitize_input($post['content'])) ?></td>
<td class="px-4 py-2">
<?php if($post['media_url']): ?>
<a href="<?= sanitize_input($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"><?= 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') ?>">
<?= sanitize_input($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>
</div>
<?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="bg-gray-800 text-white text-center p-4 fixed bottom-0 left-0 w-full">
© 2024 Kaak Alia Bakery. All rights reserved.
</footer>
</body>
</html>