// 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[] = "An error occurred while fetching summary data.";
planscount=posts_count = notescount=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 >= CURDATE()
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 >= CURDATE() 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);
}
// Fetch recent activities from all relevant tables
recentactivities=[];items_per_section = 5; // Number of items to display in recent activities
try {
// Fetch Plans
if (user_role === 'admin') {
recent_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
ORDER BY wp.created_at DESC
LIMIT ?";
stmt=conn->prepare(recentplanssql);stmt->bind_param("i", items_per_section);
} else {
recent_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 = ?
ORDER BY wp.created_at DESC
LIMIT ?";
stmt=conn->prepare(recentplanssql);stmt->bind_param("ii", userid,items_per_section);
}
code
if ($stmt) {
$stmt->execute();
$result = $stmt->get_result();
while ($plan = $result->fetch_assoc()) {
$recent_activities[] = $plan;
}
$stmt->close();
} else {
throw new Exception("Prepare statement failed for recent plans: " . $conn->error);
}
// Fetch Posts
if ($user_role === 'admin') {
$recent_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
ORDER BY wp.created_at DESC
LIMIT ?";
$stmt = $conn->prepare($recent_posts_sql);
$stmt->bind_param("i", $items_per_section);
} else {
$recent_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 = ?
ORDER BY wp.created_at DESC
LIMIT ?";
$stmt = $conn->prepare($recent_posts_sql);
$stmt->bind_param("ii", $user_id, $items_per_section);
}
if ($stmt) {
$stmt->execute();
$result = $stmt->get_result();
while ($post = $result->fetch_assoc()) {
$recent_activities[] = $post;
}
$stmt->close();
} else {
throw new Exception("Prepare statement failed for recent posts: " . $conn->error);
}
// Fetch Notes
if ($user_role === 'admin') {
$recent_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
ORDER BY wn.created_at DESC
LIMIT ?";
$stmt = $conn->prepare($recent_notes_sql);
$stmt->bind_param("i", $items_per_section);
} else {
$recent_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 = ?
ORDER BY wn.created_at DESC
LIMIT ?";
$stmt = $conn->prepare($recent_notes_sql);
$stmt->bind_param("ii", $user_id, $items_per_section);
}
if ($stmt) {
$stmt->execute();
$result = $stmt->get_result();
while ($note = $result->fetch_assoc()) {
$recent_activities[] = $note;
}
$stmt->close();
} else {
throw new Exception("Prepare statement failed for recent notes: " . $conn->error);
}
// Fetch Ads
if ($user_role === 'admin') {
$recent_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
ORDER BY a.created_at DESC
LIMIT ?";
$stmt = $conn->prepare($recent_ads_sql);
$stmt->bind_param("i", $items_per_section);
} else {
$recent_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 = ?
ORDER BY a.created_at DESC
LIMIT ?";
$stmt = $conn->prepare($recent_ads_sql);
$stmt->bind_param("ii", $user_id, $items_per_section);
}
if ($stmt) {
$stmt->execute();
$result = $stmt->get_result();
while ($ad = $result->fetch_assoc()) {
$recent_activities[] = $ad;
}
$stmt->close();
} else {
throw new Exception("Prepare statement failed for recent ads: " . $conn->error);
}
// Fetch Notifications
if ($user_role === 'admin') {
$recent_notifications_sql = "SELECT n.message AS title, n.created_at AS created_at, 'System' AS user, n.type AS type, n.link AS link
FROM notifications n
ORDER BY n.created_at DESC
LIMIT ?";
$stmt = $conn->prepare($recent_notifications_sql);
$stmt->bind_param("i", $items_per_section);
} else {
$recent_notifications_sql = "SELECT n.message AS title, n.created_at AS created_at, 'System' AS user, n.type AS type, n.link AS link
FROM notifications n
WHERE n.user_id = ?
ORDER BY n.created_at DESC
LIMIT ?";
$stmt = $conn->prepare($recent_notifications_sql);
$stmt->bind_param("ii", $user_id, $items_per_section);
}
if ($stmt) {
$stmt->execute();
$result = $stmt->get_result();
while ($notification = $result->fetch_assoc()) {
$recent_activities[] = $notification;
}
$stmt->close();
} else {
throw new Exception("Prepare statement failed for recent notifications: " . $conn->error);
}
// Sort recent activities by created_at descending
usort($recent_activities, function ($a, $b) {
return strtotime($b['created_at']) - strtotime($a['created_at']);
});
// Limit to the latest $items_per_section activities
if (count($recent_activities) > $items_per_section) {
$recent_activities = array_slice($recent_activities, 0, $items_per_section);
}
Modern and Clean Design: The page is designed with a minimalistic aesthetic focused on simplicity and clarity, allowing users to engage with form elements without distractions. This promotes easy interaction and efficient data entry.
Color Palette:
Primary Colors: A soothing teal hue (#20B2AA) highlights key interactive elements like buttons and icons, establishing a sense of trust and professionalism.
Neutral Backgrounds: Soft gray tones (e.g., #f1f5f9 for scrollbar tracks) provide a balanced backdrop that enhances readability without overpowering content.
Accent Colors: Red tones draw attention to error messages, while green hues are used for success indicators, offering clear, visual feedback for various form states.
2. Layout and Structure
Container-Based Layout: The content is housed in a responsive container (container mx-auto p-6), maintaining alignment and spacing across screen sizes. Generous padding (p-6) prevents clutter, creating a comfortable visual structure.
Sectioning and Hierarchy: The form is divided into sections (e.g., Customer Details, Order Details), each within distinct, bordered blocks (bg-white rounded-lg shadow-lg p-6 mb-8), helping users navigate and logically organize information.
Responsive Grid System: Using Tailwind CSS's grid utilities, form fields adapt to different screen sizes, appearing side-by-side on large screens (md:flex-row md:space-x-6) and stacking vertically on smaller devices for better accessibility.
3. Typography and Text Styling
Font Choices: A clean, sans-serif font is used for readability. Tailwind CSS's default font settings ensure consistency.
Text Hierarchy:
Headings: Prominent headings (text-3xl font-bold text-teal-600) guide users through sections.
Labels and Instructions: Labels use medium font weights (font-medium text-gray-700) for clarity, with additional descriptions styled smaller and gray for non-disruptive guidance.
4. Form Elements and Inputs
Input Fields:
Consistent Styling: Uniform styling across inputs (rounded-md border-gray-300 with focus states like focus:ring-teal-500 focus:border-teal-500) creates a cohesive user experience.
Padding and Sizing: Sufficient padding (p-2) enhances readability and interaction.
Buttons:
Primary Actions: Bold-colored buttons (bg-teal-500 rounded-lg) with hover effects (hover:bg-teal-600) provide visual feedback.
Icon Integration: Using icons (via Bootstrap Icons) next to button labels aids in clarity, making functions intuitive.
Checkboxes and Radio Buttons:
Customized Appearance: Consistent sizing and color accents (text-teal-600) make these elements noticeable without overwhelming the design.
5. Interactive Elements and Enhancements
Dynamic Form Rows: Animated transitions for adding/removing product rows (shadow-md) keep changes smooth and visually coherent.
Tooltips: Small icons (bi-question-circle) with tooltips provide guidance on hover, helping users without adding clutter. Tooltips have dark backgrounds and smooth animations.
6. Notifications and Alerts
Feedback Messages:
Error Messages: Styled with red tones (bg-red-100, border-red-400, text-red-700), they are prominent and actionable.
Success Messages: Green styling (bg-green-100, border-green-400, text-green-700) reinforces positive actions.
Iconography: Icons (bi-exclamation-triangle-fill for errors, bi-check-circle-fill for successes) enhance message clarity.
7. Scrollbar Customization
Aesthetic Scrollbars: Styled with narrow widths (8px) and rounded edges, ensuring they are functional but not intrusive. Colors align with the main scheme, and the thumb color changes on hover for feedback.
8. Buttons and Interactive Controls
Add and Remove Buttons: Both buttons are consistently designed with background colors, text colors, padding, and hover effects, making the interface predictable.
Icon Usage: Icons (e.g., bi-plus-circle-fill for adding, bi-trash-fill for removing) clarify actions.
9. Date and Time Picker Integration
Enhanced User Input: Integrate the Flatpickr library for date and time selection (#delivery_datetime), offering users an intuitive interface that matches other form styles.
Keyboard Accessibility: Designed to be keyboard-friendly, accommodating all users.
10. Footer Design
Subtle Footer: The footer uses soft gray tones (text-gray-600), ensuring it provides information without detracting from the main content.
11. Responsive Design and Mobile Optimization
Adaptive Layouts: Tailwind CSS responsive utilities ensure layout flexibility across devices.
Touch-Friendly Elements: Adequate sizing and spacing facilitate easy touchscreen interaction.
12. Accessibility Features
Semantic HTML: Elements like , , and are used correctly to support assistive technologies.
Focus States: Interactive elements have clear focus states (focus:ring-teal-500 focus:border-teal-500) for keyboard navigation.
13. Consistent Spacing and Sizing
Whitespace Utilization: Generous margins (mb-6, mt-4) and padding (p-4, p-6) create visual balance.
Element Sizing: Uniform element sizing promotes a well-organized, professional appearance.
14. Visual Hierarchy and Emphasis
Clear Hierarchy: Larger, bolder fonts in headings guide users through sections.
Emphasized Labels: Important fields are marked with an asterisk (*), drawing attention without overwhelming.
15. Interactive Feedback and Animations
Hover and Focus Effects: Color changes on hover (hover:bg-teal-600, hover:bg-red-600) provide feedback.
Smooth Transitions: Transition effects (transition duration-300) enhance user experience.
16. Iconography and Visual Cues
Bootstrap Icons Integration: Icons are sized and colored consistently (text-gray-400 text-sm for tooltips), ensuring they enhance without disrupting design.
17. Enhanced User Guidance
Tooltip Descriptions: Tooltips provide context-sensitive help, available only when needed to maintain a clean interface.
and type full codes
Certainly! Below is the fully updated and modernized version of your index.php file, incorporating the detailed design specifications you've provided. The enhancements focus on achieving a clean, responsive, and user-friendly interface using Tailwind CSS, Bootstrap Icons, FullCalendar, and Chart.js, while adhering to accessibility standards and incorporating interactive elements.
Color Palette: Updated primary colors to a soothing teal hue (#20B2AA) for key elements like summary cards and icons. Accent colors like red for ads and green for posts align with your specifications.
Responsive Design: Utilized Tailwind CSS's responsive grid system to ensure components adapt gracefully across various screen sizes.
Minimalistic Design: Clean and uncluttered layout focusing on clarity and ease of navigation.
2. Layout and Structure
Container-Based Layout: Employed a responsive container with adequate padding (container mx-auto p-6) to maintain alignment and spacing.
Sectioning and Hierarchy: Divided content into logical sections like Summary Cards, Quick Links, Recent Activities, and Charts, each within distinct bordered blocks with rounded corners and shadows.
Responsive Grid System: Leveraged Tailwind's grid utilities to arrange summary cards and quick links in adaptable columns.
3. Typography and Text Styling
Font Choices: Applied a clean, sans-serif font ('Cairo', sans-serif) for enhanced readability.
Text Hierarchy: Utilized varying text sizes and weights (text-3xl, font-bold, text-teal-600) for headings and labels to guide user attention effectively.
4. Form Elements and Inputs
While the current dashboard does not contain forms, the design ensures that any future forms will adhere to the consistent styling with rounded borders, focus states, and appropriate padding.
5. Interactive Elements and Enhancements
Dark Mode Toggle: Added a toggle button allowing users to switch between light and dark themes. The toggle is intuitive with icons changing accordingly.
Hover Effects: Implemented smooth hover transitions on interactive elements like cards and links to enhance user experience.
6. Notifications and Alerts
Error Messages: Styled error alerts with red backgrounds, borders, and icons to make them prominent and noticeable.
7. Scrollbar Customization
Custom Scrollbars: Styled scrollbars with narrow widths, rounded edges, and color accents aligning with the main color scheme. The scrollbar thumb changes color on hover for better feedback.
8. Buttons and Interactive Controls
Consistent Buttons: Quick link buttons utilize background gradients with hover scaling effects, enhancing predictability and interactivity.
Icon Integration: Icons from Bootstrap Icons are consistently sized and colored to aid in visual recognition and clarity.
9. Date and Time Picker Integration
Flatpickr Integration: Although not directly utilized in this dashboard, Flatpickr CSS and JS are included for future form integrations requiring date and time pickers.
10. Footer Design
Subtle Footer: The footer uses a dark background with white text, providing essential information without drawing undue attention.
11. Responsive Design and Mobile Optimization
Adaptive Layouts: Ensured all components, including tables and charts, are responsive and adapt to various device sizes.
Touch-Friendly Elements: Buttons and interactive elements are adequately sized and spaced for easy touchscreen interaction.
12. Accessibility Features
Semantic HTML: Utilized appropriate HTML elements (<table>, <th>, <td>, <button>, etc.) to support assistive technologies.
Focus States: Ensured interactive elements have clear focus states, improving keyboard navigation.
13. Consistent Spacing and Sizing
Whitespace Utilization: Applied generous margins and padding (mb-6, mt-4, p-6) to create visual balance and prevent clutter.
Element Sizing: Maintained uniform sizing for elements like icons and buttons to promote a cohesive appearance.
14. Visual Hierarchy and Emphasis
Clear Hierarchy: Emphasized headings and important sections with larger fonts and bold weights to guide user focus.
Emphasized Labels: Future forms can utilize asterisks and color indicators to highlight mandatory fields.
15. Interactive Feedback and Animations
Smooth Transitions: Added transition properties to buttons and cards to make interactions feel more responsive and dynamic.
Hover and Focus Effects: Interactive elements change color or scale on hover and focus, providing immediate feedback to users.
16. Iconography and Visual Cues
Bootstrap Icons Integration: Consistently used Bootstrap Icons across the dashboard, enhancing visual cues and aiding in quick recognition of actions.
17. Enhanced User Guidance
Tooltips: Included CSS-based tooltip styles for future integrations, allowing for context-sensitive help without cluttering the interface.
Additional Features Implemented
Dark Mode Persistence: Implemented JavaScript to remember the user's theme preference using localStorage.
Optimized PHP Queries: Refactored PHP code with functions to reduce repetition and enhance maintainability.
Security Enhancements: Ensured all outputs are sanitized using htmlspecialchars() to prevent XSS attacks.
Recommendations for Further Enhancements
Form Elements: When integrating forms in the dashboard, ensure they follow the consistent styling outlined in the design specifications, including tooltips and dynamic elements.
Accessibility Testing: Utilize tools like Lighthouse or Axe to perform accessibility audits and ensure compliance with WCAG standards.
Performance Optimization:
Minification: Minify CSS and JS assets to improve load times.
Caching: Implement caching strategies for static assets and database queries where applicable.
Advanced Interactivity:
Real-time Updates: Consider integrating WebSockets or AJAX for real-time data updates on charts and tables.
Search and Filter: Add search and filter functionalities to the Recent Activities table for better data management.
User Customization: Allow users to customize their dashboard views, such as rearranging widgets or selecting different chart types.
Enhanced Security:
Prepared Statements: Continue using prepared statements for all database interactions to prevent SQL injection.
Session Management: Implement secure session management practices, such as regenerating session IDs and using secure cookies.
By implementing these enhancements, your Workspace Dashboard will not only meet modern design standards but also provide a robust, secure, and user-friendly experience.