-- Host: 127.0.0.1:3306
-- Generation Time: Nov 11, 2024 at 06:48 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 ads
CREATE TABLE ads (
id int(11) NOT NULL,
user_id int(11) NOT NULL,
name varchar(255) NOT NULL,
ad_type enum('Post','Story') NOT NULL,
related_id int(11) NOT NULL,
budget decimal(10,2) NOT NULL,
total_spent decimal(10,2) DEFAULT 0.00,
start_date date NOT NULL,
end_date date NOT NULL,
status enum('Active','Paused','Completed') DEFAULT 'Active',
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 ad_spend_logs
CREATE TABLE ad_spend_logs (
id int(11) NOT NULL,
ad_id int(11) NOT NULL,
amount decimal(10,2) NOT NULL,
spend_date datetime DEFAULT current_timestamp(),
description varchar(255) DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
--
-- 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,
is_star tinyint(1) DEFAULT 0
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
Assistant
--
-- Table structure for table notifications
CREATE TABLE notifications (
id int(11) NOT NULL,
user_id int(11) NOT NULL,
type enum('order','post','plan','note') NOT NULL,
message varchar(255) NOT NULL,
link varchar(255) NOT NULL,
created_at datetime DEFAULT current_timestamp()
) 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,
email varchar(100) DEFAULT NULL,
password varchar(255) NOT NULL,
role enum('admin','staff') NOT NULL,
profile_image varchar(255) DEFAULT 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,
audio_path varchar(255) 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(),
type enum('Post','Story') DEFAULT 'Post'
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
ALTER TABLE ads
MODIFY id int(11) NOT NULL AUTO_INCREMENT;
--
-- AUTO_INCREMENT for table ad_spend_logs
ALTER TABLE ad_spend_logs
MODIFY id int(11) NOT NULL AUTO_INCREMENT;
--
-- 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 notifications
ALTER TABLE notifications
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 ads
ALTER TABLE ads
ADD CONSTRAINT fk_ads_related_id FOREIGN KEY (related_id) REFERENCES workspace_posts (id) ON DELETE CASCADE,
ADD CONSTRAINT fk_ads_user_id FOREIGN KEY (user_id) REFERENCES users (id) ON DELETE CASCADE;
--
-- Constraints for table ad_spend_logs
ALTER TABLE ad_spend_logs
ADD CONSTRAINT fk_ad_spend_logs_ad_id FOREIGN KEY (ad_id) REFERENCES ads (id) ON DELETE CASCADE;
--
-- Constraints for table notifications
ALTER TABLE notifications
ADD CONSTRAINT notifications_ibfk_1 FOREIGN KEY (user_id) REFERENCES users (id) ON DELETE CASCADE;
--
-- 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 thie activity recent 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);
// Include authentication, database connection, and utility functions
require_once DIR . '/../../includes/auth.php';
require_once DIR . '/../../includes/db_connect.php';
require_once DIR . '/../../includes/functions.php'; // Contains sanitize_input()
// Ensure the user is authenticated
if (!isset($_SESSION['user_id'])) {
header("Location: /public/login.php");
exit();
}
userid=_SESSION['user_id'];
userrole=_SESSION['role']; // 'admin' or 'staff'
calendarevents=[errors = [];
// Fetch summary data: Total Number of Plans, Posts, Notes, Ads
try {
// Total Plans
if (user_role === 'admin') {
plans_count_sql = "SELECT COUNT(*) AS total FROM workspace_plans";
} else {
plans_count_sql = "SELECT COUNT(*) AS total FROM workspace_plans WHERE user_id = ?";
}
if (stmt = conn−>prepare(plans_count_sql)) {
if (user_role !== 'admin') {
stmt->bind_param("i", user_id);
}
stmt->execute();
result=stmt->get_result();
planscount=result->fetch_assoc()['total'] ?? 0;
stmt->close();
} else {
throw new Exception("Prepare statement failed for plans count: " . conn->error);
}
// Total Posts
if ($user_role === 'admin') {
$posts_count_sql = "SELECT COUNT(*) AS total FROM workspace_posts";
} else {
$posts_count_sql = "SELECT COUNT(*) AS total FROM workspace_posts WHERE user_id = ?";
}
if ($stmt = $conn->prepare($posts_count_sql)) {
if ($user_role !== 'admin') {
$stmt->bind_param("i", $user_id);
}
$stmt->execute();
$result = $stmt->get_result();
$posts_count = $result->fetch_assoc()['total'] ?? 0;
$stmt->close();
} else {
throw new Exception("Prepare statement failed for posts count: " . $conn->error);
}
// Total Notes
if ($user_role === 'admin') {
$notes_count_sql = "SELECT COUNT(*) AS total FROM workspace_notes";
} else {
$notes_count_sql = "SELECT COUNT(*) AS total FROM workspace_notes WHERE user_id = ?";
}
if ($stmt = $conn->prepare($notes_count_sql)) {
if ($user_role !== 'admin') {
$stmt->bind_param("i", $user_id);
}
$stmt->execute();
$result = $stmt->get_result();
$notes_count = $result->fetch_assoc()['total'] ?? 0;
$stmt->close();
} else {
throw new Exception("Prepare statement failed for notes count: " . $conn->error);
}
// Total Ads
if ($user_role === 'admin') {
$ads_count_sql = "SELECT COUNT(*) AS total FROM ads";
} else {
$ads_count_sql = "SELECT COUNT(*) AS total FROM ads WHERE user_id = ?";
}
if ($stmt = $conn->prepare($ads_count_sql)) {
if ($user_role !== 'admin') {
$stmt->bind_param("i", $user_id);
}
$stmt->execute();
$result = $stmt->get_result();
$ads_count = $result->fetch_assoc()['total'] ?? 0;
$stmt->close();
} else {
throw new Exception("Prepare statement failed for ads count: " . $conn->error);
}
} catch (Exception e) {
errors[] = e−>getMessage();plans_count = postscount=notes_count = $ads_count = 0; // Default values in case of error
}
// Fetch upcoming plans and posts for the calendar along with creator's username
try {
// Fetch Plans
if (user_role === 'admin') {
calendar_plans_sql = "SELECT wp.id, wp.title, wp.due_date, u.username
FROM workspace_plans wp
JOIN users u ON wp.user_id = u.id
WHERE wp.due_date >= NOW()
ORDER BY wp.due_date ASC";
} else {
calendar_plans_sql = "SELECT wp.id, wp.title, wp.due_date, u.username
FROM workspace_plans wp
JOIN users u ON wp.user_id = u.id
WHERE wp.due_date >= NOW() AND wp.user_id = ?
ORDER BY wp.due_date ASC";
}
stmt = conn−>prepare(calendar_plans_sql);
if (stmt) {
if (user_role !== 'admin') {
stmt−>bindparam("i",user_id);
}
stmt−>execute();result = $stmt->get_result();
while ($plan = $result->fetch_assoc()) {
$calendar_events[] = [
'id' => 'plan_' . $plan['id'], // Prefix to distinguish type
'title' => sanitize_input($plan['title']) . " (by " . sanitize_input($plan['username']) . ")",
'start' => $plan['due_date'],
'type' => 'plan', // Custom property to identify type
'color' => '#3B82F6' // Tailwind Blue-500
];
}
$stmt->close();
} else {
throw new Exception("Prepare statement failed for calendar plans: " . $conn->error);
}
// Fetch Posts
if ($user_role === 'admin') {
$calendar_posts_sql = "SELECT wp.id, CONCAT(wp.platform, ': ', wp.content) AS content, wp.scheduled_datetime, u.username
FROM workspace_posts wp
JOIN users u ON wp.user_id = u.id
WHERE wp.scheduled_datetime >= NOW()
ORDER BY wp.scheduled_datetime ASC";
} else {
$calendar_posts_sql = "SELECT wp.id, CONCAT(wp.platform, ': ', wp.content) AS content, wp.scheduled_datetime, u.username
FROM workspace_posts wp
JOIN users u ON wp.user_id = u.id
WHERE wp.scheduled_datetime >= NOW() AND wp.user_id = ?
ORDER BY wp.scheduled_datetime ASC";
}
$stmt = $conn->prepare($calendar_posts_sql);
if ($stmt) {
if ($user_role !== 'admin') {
$stmt->bind_param("i", $user_id);
}
$stmt->execute();
$result = $stmt->get_result();
while ($post = $result->fetch_assoc()) {
$calendar_events[] = [
'id' => 'post_' . $post['id'], // Prefix to distinguish type
'title' => sanitize_input($post['content']) . " (by " . sanitize_input($post['username']) . ")",
'start' => $post['scheduled_datetime'],
'type' => 'post', // Custom property to identify type
'color' => '#10B981' // Tailwind Green-500
];
}
$stmt->close();
} else {
throw new Exception("Prepare statement failed for calendar posts: " . $conn->error);
}
// Include authentication, database connection, and utility functions
require_once DIR . '/../../includes/auth.php';
require_once DIR . '/../../includes/db_connect.php';
require_once DIR . '/../../includes/functions.php'; // Contains sanitize_input()
// Ensure the user is authenticated
if (!isset($_SESSION['user_id'])) {
header("Location: /public/login.php");
exit();
}
userid=_SESSION['user_id'];
userrole=_SESSION['role']; // 'admin' or 'staff'
$errors = [];
try {
// Fetch Plans
if (user_role === 'admin') {
plans_sql = "SELECT wp.title AS title, wp.created_at AS created_at, u.username AS user, 'plan' AS type, CONCAT('view_plan.php?id=', wp.id) AS link
FROM workspace_plans wp
JOIN users u ON wp.user_id = u.id";
stmt=conn->prepare(plans_sql);
} else {
plans_sql = "SELECT wp.title AS title, wp.created_at AS created_at, u.username AS user, 'plan' AS type, CONCAT('view_plan.php?id=', wp.id) AS link
FROM workspace_plans wp
JOIN users u ON wp.user_id = u.id
WHERE wp.user_id = ?";
stmt=conn->prepare(planssql);stmt->bind_param("i", $user_id);
}
if ($stmt) {
$stmt->execute();
$result = $stmt->get_result();
while ($plan = $result->fetch_assoc()) {
$activities[] = $plan;
}
$stmt->close();
} else {
throw new Exception("Prepare statement failed for plans: " . $conn->error);
}
// Fetch Posts
if ($user_role === 'admin') {
$posts_sql = "SELECT CONCAT(wp.platform, ': ', wp.content) AS title, wp.created_at AS created_at, u.username AS user, 'post' AS type, CONCAT('view_post.php?id=', wp.id) AS link
FROM workspace_posts wp
JOIN users u ON wp.user_id = u.id";
$stmt = $conn->prepare($posts_sql);
} else {
$posts_sql = "SELECT CONCAT(wp.platform, ': ', wp.content) AS title, wp.created_at AS created_at, u.username AS user, 'post' AS type, CONCAT('view_post.php?id=', wp.id) AS link
FROM workspace_posts wp
JOIN users u ON wp.user_id = u.id
WHERE wp.user_id = ?";
$stmt = $conn->prepare($posts_sql);
$stmt->bind_param("i", $user_id);
}
if ($stmt) {
$stmt->execute();
$result = $stmt->get_result();
while ($post = $result->fetch_assoc()) {
$activities[] = $post;
}
$stmt->close();
} else {
throw new Exception("Prepare statement failed for posts: " . $conn->error);
}
// Fetch Notes
if ($user_role === 'admin') {
$notes_sql = "SELECT wn.title AS title, wn.created_at AS created_at, u.username AS user, 'note' AS type, CONCAT('view_note.php?id=', wn.id) AS link
FROM workspace_notes wn
JOIN users u ON wn.user_id = u.id";
$stmt = $conn->prepare($notes_sql);
} else {
$notes_sql = "SELECT wn.title AS title, wn.created_at AS created_at, u.username AS user, 'note' AS type, CONCAT('view_note.php?id=', wn.id) AS link
FROM workspace_notes wn
JOIN users u ON wn.user_id = u.id
WHERE wn.user_id = ?";
$stmt = $conn->prepare($notes_sql);
$stmt->bind_param("i", $user_id);
}
if ($stmt) {
$stmt->execute();
$result = $stmt->get_result();
while ($note = $result->fetch_assoc()) {
$activities[] = $note;
}
$stmt->close();
} else {
throw new Exception("Prepare statement failed for notes: " . $conn->error);
}
// Fetch Ads
if ($user_role === 'admin') {
$ads_sql = "SELECT a.name AS title, a.created_at AS created_at, u.username AS user, 'ad' AS type, CONCAT('view_ad.php?id=', a.id) AS link
FROM ads a
JOIN users u ON a.user_id = u.id";
$stmt = $conn->prepare($ads_sql);
} else {
$ads_sql = "SELECT a.name AS title, a.created_at AS created_at, u.username AS user, 'ad' AS type, CONCAT('view_ad.php?id=', a.id) AS link
FROM ads a
JOIN users u ON a.user_id = u.id
WHERE a.user_id = ?";
$stmt = $conn->prepare($ads_sql);
$stmt->bind_param("i", $user_id);
}
if ($stmt) {
$stmt->execute();
$result = $stmt->get_result();
while ($ad = $result->fetch_assoc()) {
$activities[] = $ad;
}
$stmt->close();
} else {
throw new Exception("Prepare statement failed for ads: " . $conn->error);
}
// Fetch Notifications
if ($user_role === 'admin') {
$notifications_sql = "SELECT message AS title, created_at AS created_at, 'System' AS user, type AS type, link AS link
FROM notifications";
$stmt = $conn->prepare($notifications_sql);
} else {
$notifications_sql = "SELECT message AS title, created_at AS created_at, 'System' AS user, type AS type, link AS link
FROM notifications
WHERE user_id = ?";
$stmt = $conn->prepare($notifications_sql);
$stmt->bind_param("i", $user_id);
}
if ($stmt) {
$stmt->execute();
$result = $stmt->get_result();
while ($notification = $result->fetch_assoc()) {
$activities[] = $notification;
}
$stmt->close();
} else {
throw new Exception("Prepare statement failed for notifications: " . $conn->error);
}
// Sort activities by created_at descending
usort($activities, function ($a, $b) {
return strtotime($b['created_at']) - strtotime($a['created_at']);
});
To enhance your Workspace Dashboard and Activities page, we'll address the following key areas:
Fixing Recent Activities on the Dashboard (index.php): We'll modify the code to fetch recent activities from multiple tables (Plans, Posts, Notes, Ads, Notifications) to ensure comprehensive activity tracking.
Enhancing the Design for Responsiveness and Aesthetics: We'll leverage Tailwind CSS to create a modern, responsive design that looks great on all devices.
Ensuring the Activities Page (activities.php) Works Seamlessly: We'll refine the activities page to display all activities correctly with improved styling and responsiveness.
Below are the updated versions of both index.php and activities.php with detailed explanations of the changes made.
1. Updated Dashboard (index.php)
Key Changes:
Comprehensive Recent Activities: Instead of fetching activities only from the notifications table, we'll aggregate recent activities from workspace_plans, workspace_posts, workspace_notes, ads, and notifications.
Responsive Design Enhancements: Improved styling using Tailwind CSS to ensure the dashboard is aesthetically pleasing and responsive across all devices.
Optimized Queries: Efficiently fetching and merging activities to minimize database load.
Aggregation from Multiple Tables: The code now fetches recent activities from workspace_plans, workspace_posts, workspace_notes, ads, and notifications. Each fetch is limited to the number of items per section (e.g., 5) to maintain performance.
Merging and Sorting: After fetching activities from each table, they are merged into the $recent_activities array and sorted by created_at in descending order to show the most recent activities first.
Responsive Design Enhancements:
Tailwind CSS Grid System: The layout uses Tailwind's grid system (grid-cols-1 sm:grid-cols-2 lg:grid-cols-4) to ensure that the summary cards and quick links adjust seamlessly across different screen sizes.
Hover Effects and Transitions: Added hover effects (hover:scale-105) and smooth transitions (transition duration-300) to make the UI interactive and visually appealing.
Optimized Calendar Styling: Adjusted calendar padding for smaller screens to enhance usability on mobile devices.
Improved Recent Activities Table:
Dynamic Icons and Colors: Each activity type is associated with a specific icon and color for instant visual recognition.
Sanitized Output: Ensured that all dynamic content is sanitized using sanitize_input() and htmlspecialchars() to prevent XSS attacks.
Date Formatting: Activities are displayed with a human-readable date format (d M Y, h:i A).
Performance Optimizations:
Prepared Statements with Limits: Each query fetching recent activities uses LIMIT to restrict the number of records, reducing load times.
Database Connection Closure: Closed the database connection after fetching all necessary data to free up resources.
2. Updated Activities Page (activities.php)
Key Changes:
Comprehensive Activity Listing: Ensured that all activity types (Plans, Posts, Notes, Ads, Notifications) are fetched and displayed in a unified table.
Enhanced Responsiveness and Styling: Utilized Tailwind CSS for a clean and responsive layout, ensuring usability across all devices.
Dark Mode Support (Optional): Included a dark mode toggle for improved user experience, though it can be omitted if not needed.
Unified Fetching: Activities are fetched from workspace_plans, workspace_posts, workspace_notes, ads, and notifications, ensuring a complete overview of all user actions.
Type Identification: Each activity record includes a type field to identify its origin (e.g., 'plan', 'post', etc.) and a link for easy navigation.
Responsive and Modern Design:
Tailwind CSS Enhancements: Utilized Tailwind's utility classes to create a clean and responsive table that adjusts gracefully on different screen sizes.
Activity Icons and Colors: Each activity type is associated with a distinct icon and color, enhancing visual differentiation.
Hover Effects: Rows change background color on hover (hover:bg-gray-100) to improve interactivity and user experience.
Sanitized and Safe Output:
Data Sanitization: All dynamic data is sanitized using sanitize_input() and htmlspecialchars() to prevent potential security vulnerabilities such as XSS attacks.
User-Friendly Navigation:
Direct Links: Each activity's title and the arrow icon are clickable, directing users to the relevant detailed view (e.g., view_plan.php?id=...).
Optional Enhancements:
Pagination Placeholder: A comment block is included to indicate where pagination can be implemented if the activities list grows large.
Dark Mode (Optional): Basic dark mode styles are included, but the toggle functionality is commented out. You can implement it as needed.
3. Database Dump Correction
Issue Identified:
At the end of your provided SQL dump, there's an unexpected ); which is likely a typo that could cause errors during import.
Correction:
Remove the trailing ); after the last /*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;.
Corrected Section:
/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;
4. Additional Recommendations
Centralized Activity Logging (Optional but Recommended):
Single Activity Table: Consider creating a centralized activities table that logs all user actions. This approach simplifies fetching recent activities and ensures all actions are consistently tracked.
Triggers or Backend Logging: Implement database triggers or backend logic to automatically log activities whenever actions occur in various tables.
Pagination for Activities Page:
Improve Performance: If the number of activities becomes large, implementing pagination will enhance performance and usability.
Implementation: Modify SQL queries to include LIMIT and OFFSET, and add pagination controls (e.g., Previous, Next buttons) below the activities table.
Enhance Security:
Session Management: Ensure session handling is secure, implementing measures such as session regeneration and proper session termination.
Input Validation: Beyond sanitization, validate all inputs both on client and server sides.
Optimize Database Queries:
Indexes: Ensure appropriate indexing on frequently queried columns to improve query performance.
Caching: Implement caching strategies for data that doesn't change frequently to reduce database load.
User Experience Enhancements:
Search Functionality: Add search capabilities to the activities page to allow users to find specific activities quickly.
Filter Options: Provide filtering options based on activity type, date range, or user to refine the activities list.
By implementing these changes and recommendations, your Workspace Dashboard and Activities page will not only function correctly but also provide a modern and responsive user experience across all devices.