Creating a dedicated Workspace within your existing Kaak Alia Management System is a fantastic way to manage team activities, plans, and content scheduling without interfering with your existing dashboard functionalities. Below is a comprehensive guide to help you build a Workspace that seamlessly integrates with your current system while maintaining separation from other database tables.
1. Overview
We'll follow these key steps to create the Workspace:
- Design and Update the Database: Create new tables specific to the Workspace.
- Set Up Folder Structure: Organize Workspace-related files.
- Develop Backend Functionality: PHP scripts to handle data operations.
- Create Frontend Interfaces: User-friendly UI for Workspace management.
- Integrate Workspace with Existing System: Link Workspace to your dashboard and ensure secure access.
- Enhance User Experience: Add interactive features like calendars and notifications.
2. Database Design
To keep the Workspace separate yet connected to users, we'll create new tables related to planning, posts, and notes. Below are the SQL scripts to create these tables.
2.1. New Tables Overview
- workspace_plans: Manage plans and tasks.
- workspace_posts: Schedule posts and stories for platforms like Instagram.
- workspace_notes: Store notes and collaborative information.
2.2. SQL Scripts
-- --------------------------------------------------------
-- Table structure for table `workspace_plans`
-- --------------------------------------------------------
CREATE TABLE `workspace_plans` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`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(),
PRIMARY KEY (`id`),
KEY `user_id` (`user_id`),
CONSTRAINT `fk_workspace_plans_user_id` FOREIGN KEY (`user_id`) REFERENCES `users` (`id`) ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
-- --------------------------------------------------------
-- Table structure for table `workspace_posts`
-- --------------------------------------------------------
CREATE TABLE `workspace_posts` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`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(),
PRIMARY KEY (`id`),
KEY `user_id` (`user_id`),
CONSTRAINT `fk_workspace_posts_user_id` FOREIGN KEY (`user_id`) REFERENCES `users` (`id`) ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
-- --------------------------------------------------------
-- Table structure for table `workspace_notes`
-- --------------------------------------------------------
CREATE TABLE `workspace_notes` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`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(),
PRIMARY KEY (`id`),
KEY `user_id` (`user_id`),
CONSTRAINT `fk_workspace_notes_user_id` FOREIGN KEY (`user_id`) REFERENCES `users` (`id`) ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
2.3. Applying the SQL Scripts
- Access phpMyAdmin: Log into your phpMyAdmin interface.
- Select Your Database: Choose
u406552082_kaakalia.
- Run SQL Queries: Navigate to the SQL tab and execute the above scripts.
3. Folder Structure
Organize your project files to keep Workspace components distinct yet accessible.
project_root/
├── includes/
│ ├── header.php
│ ├── auth.php
│ ├── db_connect.php
│ └── ... (other includes)
├── public/
│ ├── dashboard.php
│ ├── workspace/
│ │ ├── index.php
│ │ ├── plans.php
│ │ ├── posts.php
│ │ ├── notes.php
│ │ ├── create_plan.php
│ │ ├── create_post.php
│ │ ├── create_note.php
│ │ └── ... (other workspace files)
│ ├── assets/
│ └── ... (other public files)
└── ... (other directories)
4. Backend Implementation
We'll develop PHP scripts to handle CRUD operations for plans, posts, and notes within the Workspace.
4.1. Database Connection
Ensure that all Workspace files include the necessary database and authentication scripts.
<?php
// /public/workspace/config.php
require_once '../../includes/auth.php';
require_once '../../includes/db_connect.php';
?>
4.2. Workspace Main Page
Create a main Workspace page that serves as a dashboard for Workspace functionalities.
<?php
// /public/workspace/index.php
require_once 'config.php';
// Fetch user-specific data if needed
$user_id = $_SESSION['user_id'];
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Workspace - Kaak Alia Management System</title>
<!-- Include Tailwind CSS or Bootstrap as per your preference -->
<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">
<!-- Custom Styles -->
<style>
/* Add any custom styles here */
</style>
</head>
<body>
<?php include '../includes/header.php'; ?>
<main class="container mx-auto p-6 mt-20">
<h1 class="text-3xl font-bold mb-6">Workspace Dashboard</h1>
<div class="grid grid-cols-1 md:grid-cols-3 gap-6">
<a href="plans.php" class="block p-6 bg-blue-500 text-white rounded-lg shadow hover:bg-blue-600 transition">
<i class="bi bi-list-task text-2xl"></i>
<h2 class="mt-2 text-xl font-semibold">Plans & Tasks</h2>
</a>
<a href="posts.php" class="block p-6 bg-green-500 text-white rounded-lg shadow hover:bg-green-600 transition">
<i class="bi bi-calendar-plus text-2xl"></i>
<h2 class="mt-2 text-xl font-semibold">Scheduled Posts</h2>
</a>
<a href="notes.php" class="block p-6 bg-purple-500 text-white rounded-lg shadow hover:bg-purple-600 transition">
<i class="bi bi-stickies text-2xl"></i>
<h2 class="mt-2 text-xl font-semibold">Notes</h2>
</a>
</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>
</body>
</html>
4.3. Plans & Tasks Management
4.3.1. Display Plans
<?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">
© 2024 Kaak Alia Bakery. All rights reserved.
</footer>
</body>
</html>
4.3.2. Create a New Plan
<?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">
© 2024 Kaak Alia Bakery. All rights reserved.
</footer>
</body>
</html>
4.3.3. Edit and Delete Plans
Similarly, create edit_plan.php and delete_plan.php to handle updating and deleting plans. Ensure these scripts verify that the plan belongs to the logged-in user to prevent unauthorized access.
4.4. Posts & Stories Scheduling
4.4.1. Display Scheduled Posts
<?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">
© 2024 Kaak Alia Bakery. All rights reserved.
</footer>
</body>
</html>
4.4.2. Schedule a New Post
<?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">
© 2024 Kaak Alia Bakery. All rights reserved.
</footer>
</body>
</html>
4.4.3. Automated Posting (Optional)
To automate the posting process, you can set up a CRON job that periodically checks for scheduled posts and triggers the appropriate API calls to social media platforms. However, as you mentioned, you don't want to add APIs. Therefore, this section is optional and depends on your future requirements.
4.5. Notes Management
4.5.1. Display Notes
<?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">
© 2024 Kaak Alia Bakery. All rights reserved.
</footer>
</body>
</html>
4.5.2. Create a New Note
<?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">
© 2024 Kaak Alia Bakery. All rights reserved.
</footer>
</body>
</html>
4.5.3. Edit and Delete Notes
Similarly, create edit_note.php and delete_note.php to handle updating and deleting notes. Ensure access control by verifying that the note belongs to the logged-in user.
5. Frontend Implementation
To maintain a consistent look and feel across your system, utilize Tailwind CSS and Bootstrap Icons as in your existing dashboard. You can enhance the Workspace UI by integrating components like calendars, modals, and responsive layouts.
5.1. Integrate a Calendar
For the Plans & Tasks section, integrating a JavaScript calendar can enhance user experience. Here's how to add a simple calendar using FullCalendar.
5.1.1. Include FullCalendar Libraries
Add these in your plans.php within the <head> section:
<!-- FullCalendar CSS -->
<link href='https://cdn.jsdelivr.net/npm/fullcalendar@5.11.3/main.min.css' rel='stylesheet' />
<!-- FullCalendar JS -->
<script src='https://cdn.jsdelivr.net/npm/fullcalendar@5.11.3/main.min.js'></script>
5.1.2. Add Calendar HTML Element
Within the <main> section of plans.php, add:
<div id='calendar' class="mt-6"></div>
5.1.3. Initialize FullCalendar with PHP Data
Add the following script before the closing </body> tag in plans.php:
<?php
// Fetch plans for calendar
$calendar_plans = [];
$calendar_sql = "SELECT id, title, due_date FROM workspace_plans WHERE user_id = ?";
$calendar_stmt = $conn->prepare($calendar_sql);
$calendar_stmt->bind_param("i", $user_id);
$calendar_stmt->execute();
$calendar_result = $calendar_stmt->get_result();
while($plan = $calendar_result->fetch_assoc()){
$calendar_plans[] = [
'title' => $plan['title'],
'start' => $plan['due_date']
];
}
$calendar_json = json_encode($calendar_plans);
?>
<script>
document.addEventListener('DOMContentLoaded', function() {
var calendarEl = document.getElementById('calendar');
var calendarData = <?= $calendar_json ?>;
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
window.location.href = 'edit_plan.php?id=' + info.event.id;
}
});
calendar.render();
});
</script>
6. Integration with Existing System
To ensure the Workspace is accessible from your existing dashboard without affecting other functionalities:
6.1. Add Workspace Link in Header Navigation
Edit your existing header.php to include a link to the Workspace. Place it appropriately within the navigation menu.
<!-- Inside your existing navigation menu in header.php -->
<nav class="hidden md:flex space-x-4">
<!-- Existing links -->
<a href="/public/workspace/index.php" class="flex items-center bg-indigo-500 text-white px-4 py-2 rounded-lg hover:bg-indigo-400 shadow transition-all duration-300">
<i class="bi bi-gear-fill mr-2"></i> Workspace
</a>
</nav>
6.2. Ensure Secure Access
All Workspace pages should be protected by authentication. Ensure that config.php includes auth.php, which checks for authenticated users. This prevents unauthorized access.
<?php
// /public/workspace/config.php
require_once '../../includes/auth.php';
require_once '../../includes/db_connect.php';
// Optional: Additional Workspace-specific configurations
?>
7. Enhancing User Experience
7.1. Real-Time Collaboration (Optional)
For a more collaborative Workspace, consider implementing features like real-time updates using WebSockets or long-polling. However, this requires more advanced backend setup and is optional based on your requirements.
7.2. Notifications
Utilize the existing notification system to alert users about upcoming tasks or scheduled posts. You can integrate notification badges and audio alerts similar to your main dashboard.
7.3. Responsive Design
Ensure all Workspace pages are fully responsive. Tailwind CSS provides utility classes that make it straightforward to create responsive layouts.
8. Final Touches and Testing
-
Review Security: Ensure all inputs are sanitized to prevent SQL injection and XSS attacks. Use htmlspecialchars() and prepared statements as shown.
-
Test Functionality: Verify all CRUD operations for plans, posts, and notes work seamlessly.
-
Optimize UI: Ensure the Workspace UI is intuitive and matches the aesthetics of your main dashboard.
-
Backup Database: Before making significant changes, always back up your database.
-
Documentation: Document your code and functionalities for future reference and maintenance.
Complete Example: Workspace Main Page (index.php)
To solidify the implementation, here's a complete example of the Workspace main page integrating the header and styling similar to your existing dashboard.
<?php
// /public/workspace/index.php
require_once 'config.php';
$user_id = $_SESSION['user_id'];
// Fetch summary data if needed
// Example: Number of plans, posts, notes
$plans_count_sql = "SELECT COUNT(*) AS total FROM workspace_plans WHERE user_id = ?";
$posts_count_sql = "SELECT COUNT(*) AS total FROM workspace_posts WHERE user_id = ?";
$notes_count_sql = "SELECT COUNT(*) AS total FROM workspace_notes WHERE user_id = ?";
$stmt = $conn->prepare($plans_count_sql);
$stmt->bind_param("i", $user_id);
$stmt->execute();
$plans_count = $stmt->get_result()->fetch_assoc()['total'];
$stmt = $conn->prepare($posts_count_sql);
$stmt->bind_param("i", $user_id);
$stmt->execute();
$posts_count = $stmt->get_result()->fetch_assoc()['total'];
$stmt = $conn->prepare($notes_count_sql);
$stmt->bind_param("i", $user_id);
$stmt->execute();
$notes_count = $stmt->get_result()->fetch_assoc()['total'];
?>
<!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 */
</style>
</head>
<body>
<?php include '../includes/header.php'; ?>
<main class="container mx-auto p-6 mt-20">
<h1 class="text-3xl font-bold mb-6">Workspace Dashboard</h1>
<!-- 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"><?= $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"><?= $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"><?= $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) {
// Fetch the specific plan's ID if needed for detailed view
// Redirect to edit plan page
const planId = info.event.id;
if(planId){
window.location.href = 'edit_plan.php?id=' + planId;
}
}
});
calendar.render();
});
</script>
</body>
</html>
9. Conclusion
By following this guide, you can successfully implement a comprehensive Workspace within your existing Kaak Alia Management System. This Workspace will empower your team to collaborate effectively, manage content schedules, and maintain organized notes and plans. Remember to continuously test each component, ensure security best practices, and gather user feedback for further enhancements.
Additional Recommendations
-
Backup Regularly: Always back up your database before introducing new tables or significant changes.
-
Version Control: Use version control systems like Git to track changes and collaborate with team members.
-
User Permissions: Enhance the users table by adding permissions or roles specific to Workspace functionalities if required.
-
Responsive Testing: Test all Workspace pages across different devices to ensure a seamless user experience.
-
Performance Optimization: Optimize database queries and frontend scripts to maintain system performance as Workspace features expand.
If you encounter any challenges or need further assistance with specific functionalities, feel free to ask!