// 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'];
user_SESSION['role']; // 'admin' or 'staff'
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);
}
code
// 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();
code
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);
}
Redesign Dashboard Cards:
Colors: Use a more consistent color scheme that aligns with the brand colors or introduces a gradient for each card to make them more vibrant.
Icons: Add more recognizable icons on each card to represent the sections (plans, posts, notes, ads) more visually.
Animation: Add a hover effect to the cards (e.g., slight scaling or shadow effect) to give a sense of interactivity.
Enhance Overview Sections:
Plans Overview: Replace the empty space with a bar or line graph showing the number of plans created per month. Add labels, tooltips, and a legend for better data understanding.
Posts Overview: Currently, there's a single pie chart for Instagram. Consider expanding this to include different social media platforms (Instagram, Facebook, TikTok) to provide a better overview.
Notes Overview: Include a stacked bar chart or line chart that shows notes by categories (e.g., feedback, tasks, reminders) to give more context.
Ads Budget vs Spent: Improve the visualization with a dual-line graph (one line for the budget and one for the actual spend). Add percentage indicators for the spent amount relative to the budget.
Add More Detailed Widgets:
Recent Activities Section:
Expand this section with a table format showing recent actions (e.g., created post, updated plan, added note) with clickable links to view the related item.
Include filters for different types of activities (e.g., 'All', 'Posts', 'Plans') to make it easier to find specific actions.
Summary Widgets:
Add small summary boxes at the top with key statistics (e.g., "Total Plans This Month," "Total Posts Today," "Budget Utilization").
Use dynamic badges or counters to indicate trends (e.g., green for growth, red for decline).
Improve Calendar Section:
Interactive Calendar: Enhance the calendar with hover details for each event. When the user hovers over a date with an upcoming plan or post, show a tooltip with a brief summary.
Add Filters: Allow users to filter the calendar by type (plans, posts, notes).
Integrate Actions: Add a "Quick Add" button on each date for users to easily create a new plan or post directly from the calendar.
Include a Notifications Widget:
Notifications Panel: Add a notifications section or a pop-up panel that shows pending tasks, upcoming posts, or reminders for ads.
UI Enhancements:
Spacing and Alignment: Increase the padding around cards and charts for a cleaner look. Align the charts and graphs for consistency.
Detailed Insights Section:
Add a Performance Insight Widget: Provide a small section with insights like "Top Performing Post of the Week," "Most Active Plan," or "Best Note Category."
Loading Animations:
Add subtle loading animations or placeholders while data is being fetched, especially for charts and recent activities.
Better Typography:
Use a modern, clean font style with different weights to make headings stand out. Consider using a mix of bold for titles and regular for content.
Customizable Dashboard:
Allow users to customize their dashboard layout by dragging and dropping widgets or rearranging sections based on their preferences.
By implementing these suggestions, the page will not only look more visually appealing but also become more functional and user-friendly. Let me know if you want detailed code or design mockups for any of these ideas!
) don't add toggle dark mode, and add recent activites (activities.php), and this info of database (-- phpMyAdmin SQL Dump
-- version 5.2.1
-- https://www.phpmyadmin.net/
-- 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;
--
-- 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 */;) and type full codes
To enhance your "Workspace Dashboard" page based on the detailed suggestions you've provided, we'll implement several improvements to make the dashboard more organized, visually appealing, and user-friendly. Below is the comprehensive updated code for your index.php along with a new activities.php to handle recent activities. Additionally, we'll integrate various charts using Chart.js for better data visualization.
Overview of Changes:
Redesigned Dashboard Cards: Improved color schemes, added recognisable icons, and hover animations for interactivity.
Enhanced Overview Sections: Integrated various charts to provide insights into Plans, Posts, Notes, and Ads.
Added Recent Activities Widget: Created activities.php to display recent user activities with filtering options.
Improved Calendar Section: Enhanced interactivity with tooltips and quick add functionalities.
Added Notifications Widget: Included a notifications panel to inform users about pending tasks and reminders.
UI Enhancements: Improved spacing, alignment, and typography for a cleaner look.
Detailed Insights Section: Added widgets to display performance insights.
Loading Animations: Implemented loading spinners for data-fetching sections.
Customizable Dashboard: Provided a foundation for future customization (e.g., drag-and-drop widgets).
Note: Ensure that you have included the necessary libraries like Chart.js in your project. You can include them via CDN as shown below.
This file will handle the "Recent Activities" section. It fetches activities from the notifications table and displays them with filtering options.
php
Additional Enhancements and Considerations
Categories for Notes:
The initial code assumes that workspace_notes table has a category field. If it doesn't, consider adding it to categorize notes (e.g., feedback, tasks, reminders).
Modify the CREATE TABLE workspace_notes SQL accordingly:
sql
ALTER TABLE `workspace_notes` ADD COLUMN `category` varchar(50) DEFAULT NULL AFTER `title`;
Engagement and Progress Fields:
The workspace_posts and workspace_plans tables in the database dump do not have engagement or progress fields. Add them to track performance metrics.
Modify the CREATE TABLE workspace_posts and CREATE TABLE workspace_plans SQL accordingly:
sql
ALTER TABLE `workspace_posts` ADD COLUMN `engagement` int(11) DEFAULT 0 AFTER `status`;
ALTER TABLE `workspace_plans` ADD COLUMN `progress` int(11) DEFAULT 0 AFTER `status`;
Handling Missing Fields:
If adding new fields is not feasible, adjust the PHP code to reflect existing data structures or skip certain features.
Security Enhancements:
Ensure that all user inputs are properly sanitized to prevent SQL Injection and XSS attacks.
Consider implementing CSRF tokens for form submissions.
Responsive Design:
The updated dashboard is built with Tailwind CSS's responsive grid system. Test it across various devices to ensure optimal display.
Performance Optimization:
Limit the number of records fetched for activities and other lists to enhance performance.
Implement caching strategies if necessary for frequently accessed data.
Error Handling:
Centralize error messages for better user experience.
Log errors to a file for debugging without exposing sensitive information to end-users.
By implementing these changes, your "Workspace Dashboard" will be more dynamic, informative, and aligned with the user experience best practices. Ensure to test each feature thoroughly and adjust based on user feedback.
The foundation is set for adding drag-and-drop functionalities or allowing users to customize their dashboard layout using JavaScript libraries like SortableJS.