- Implement OAuth 2.0 authentication for Zoho CRM - Add sync functionality for Events → Campaigns, Users → Contacts, Orders → Invoices - Create staging mode that prevents production syncs from non-production domains - Build admin interface for sync management - Add comprehensive field mapping between WordPress and Zoho - Include test scripts and documentation - Ensure production sync only on upskillhvac.com domain
394 lines
No EOL
14 KiB
PHP
394 lines
No EOL
14 KiB
PHP
<?php
|
|
/**
|
|
* HVAC Dashboard Handler
|
|
*
|
|
* Handles dashboard page rendering and functionality
|
|
*
|
|
* @package HVAC_Community_Events
|
|
* @since 1.0.0
|
|
*/
|
|
|
|
if (!defined('ABSPATH')) {
|
|
exit;
|
|
}
|
|
|
|
class HVAC_Dashboard {
|
|
|
|
/**
|
|
* Constructor
|
|
*/
|
|
public function __construct() {
|
|
add_action('init', array($this, 'register_shortcode'));
|
|
// Use higher priority to run after shortcode processing
|
|
add_filter('the_content', array($this, 'render_dashboard_content'), 99);
|
|
add_action('wp_enqueue_scripts', array($this, 'enqueue_dashboard_styles'));
|
|
}
|
|
|
|
/**
|
|
* Register dashboard shortcode
|
|
*/
|
|
public function register_shortcode() {
|
|
add_shortcode('hvac_trainer_dashboard', array($this, 'render_dashboard_shortcode'));
|
|
}
|
|
|
|
/**
|
|
* Render dashboard via shortcode
|
|
*/
|
|
public function render_dashboard_shortcode($atts) {
|
|
// Check if user is logged in and has proper permissions
|
|
if (!is_user_logged_in()) {
|
|
return '<div class="hvac-login-notice">
|
|
<p>Please log in to view the dashboard.</p>
|
|
<p><a href="' . esc_url(home_url('/community-login/')) . '" class="button">Login</a></p>
|
|
</div>';
|
|
}
|
|
|
|
if (!current_user_can('view_hvac_dashboard')) {
|
|
return '<div class="hvac-access-denied">
|
|
<p>You do not have permission to view this dashboard.</p>
|
|
</div>';
|
|
}
|
|
|
|
return $this->get_dashboard_content();
|
|
}
|
|
|
|
/**
|
|
* Render dashboard content for the page
|
|
*/
|
|
public function render_dashboard_content($content) {
|
|
// Only process if content contains our shortcode
|
|
if (has_shortcode($content, 'hvac_trainer_dashboard')) {
|
|
return do_shortcode($content);
|
|
}
|
|
|
|
return $content;
|
|
}
|
|
|
|
/**
|
|
* Get dashboard content
|
|
*/
|
|
private function get_dashboard_content() {
|
|
$user_id = get_current_user_id();
|
|
|
|
// Include dashboard data class
|
|
require_once HVAC_CE_PLUGIN_DIR . 'includes/class-hvac-dashboard-data.php';
|
|
$dashboard_data = new HVAC_Dashboard_Data($user_id);
|
|
|
|
// Get data
|
|
$data = array(
|
|
'total_events' => $dashboard_data->get_total_events_count(),
|
|
'upcoming_events' => $dashboard_data->get_upcoming_events_count(),
|
|
'past_events' => $dashboard_data->get_past_events_count(),
|
|
'total_sold' => $dashboard_data->get_total_tickets_sold(),
|
|
'total_revenue' => $dashboard_data->get_total_revenue(),
|
|
'revenue_target' => $dashboard_data->get_annual_revenue_target(),
|
|
'events_table' => $dashboard_data->get_events_table_data(isset($_GET['event_status']) ? sanitize_key($_GET['event_status']) : 'all'),
|
|
'current_filter' => isset($_GET['event_status']) ? sanitize_key($_GET['event_status']) : 'all'
|
|
);
|
|
|
|
// Get dashboard HTML
|
|
ob_start();
|
|
?>
|
|
<div class="hvac-dashboard-wrapper">
|
|
<!-- Dashboard Header & Navigation -->
|
|
<div class="hvac-dashboard-header">
|
|
<h1>Trainer Dashboard</h1>
|
|
<div class="hvac-dashboard-nav">
|
|
<a href="<?php echo esc_url(home_url('/manage-event/')); ?>" class="button hvac-button hvac-button-primary">Create Event</a>
|
|
<a href="<?php echo esc_url(home_url('/my-events/')); ?>" class="button hvac-button hvac-button-primary">My Events</a>
|
|
<a href="<?php echo esc_url(home_url('/trainer-profile/')); ?>" class="button hvac-button hvac-button-secondary">View Profile</a>
|
|
<a href="<?php echo esc_url(wp_logout_url(home_url('/community-login/'))); ?>" class="button hvac-button hvac-button-secondary">Logout</a>
|
|
</div>
|
|
</div>
|
|
|
|
<!-- Statistics Section -->
|
|
<section class="hvac-dashboard-stats">
|
|
<h2>Your Stats</h2>
|
|
<div class="hvac-stats-grid">
|
|
<!-- Total Events -->
|
|
<div class="hvac-stat-card">
|
|
<h3>Total Events</h3>
|
|
<p class="metric-value"><?php echo esc_html($data['total_events']); ?></p>
|
|
</div>
|
|
|
|
<!-- Upcoming Events -->
|
|
<div class="hvac-stat-card">
|
|
<h3>Upcoming Events</h3>
|
|
<p class="metric-value"><?php echo esc_html($data['upcoming_events']); ?></p>
|
|
</div>
|
|
|
|
<!-- Past Events -->
|
|
<div class="hvac-stat-card">
|
|
<h3>Past Events</h3>
|
|
<p class="metric-value"><?php echo esc_html($data['past_events']); ?></p>
|
|
</div>
|
|
|
|
<!-- Total Tickets Sold -->
|
|
<div class="hvac-stat-card">
|
|
<h3>Tickets Sold</h3>
|
|
<p class="metric-value"><?php echo esc_html($data['total_sold']); ?></p>
|
|
</div>
|
|
|
|
<!-- Total Revenue -->
|
|
<div class="hvac-stat-card">
|
|
<h3>Total Revenue</h3>
|
|
<p class="metric-value">$<?php echo esc_html(number_format($data['total_revenue'], 2)); ?></p>
|
|
<?php if ($data['revenue_target']) : ?>
|
|
<small>Target: $<?php echo esc_html(number_format($data['revenue_target'], 2)); ?></small>
|
|
<?php endif; ?>
|
|
</div>
|
|
</div>
|
|
</section>
|
|
|
|
<!-- Events Table Section -->
|
|
<section class="hvac-dashboard-events">
|
|
<h2>Your Events</h2>
|
|
|
|
<!-- Tab Filters -->
|
|
<div class="hvac-event-filters">
|
|
<span>Filter: </span>
|
|
<?php
|
|
$dashboard_url = get_permalink();
|
|
$filter_statuses = array('all', 'publish', 'draft', 'pending', 'private');
|
|
foreach ($filter_statuses as $status) :
|
|
$url = ($status === 'all') ? remove_query_arg('event_status', $dashboard_url) : add_query_arg('event_status', $status, $dashboard_url);
|
|
$class = ($status === $data['current_filter']) ? 'hvac-filter-active' : '';
|
|
?>
|
|
<a href="<?php echo esc_url($url); ?>" class="hvac-filter <?php echo esc_attr($class); ?>"><?php echo esc_html(ucfirst($status)); ?></a>
|
|
<?php endforeach; ?>
|
|
</div>
|
|
|
|
<!-- Events Table -->
|
|
<div class="hvac-events-table-wrapper">
|
|
<?php if (!empty($data['events_table'])) : ?>
|
|
<table class="hvac-events-table">
|
|
<thead>
|
|
<tr>
|
|
<th>Status</th>
|
|
<th>Event Name</th>
|
|
<th>Date</th>
|
|
<th>Organizer</th>
|
|
<th>Capacity</th>
|
|
<th>Sold</th>
|
|
<th>Revenue</th>
|
|
<th>Actions</th>
|
|
</tr>
|
|
</thead>
|
|
<tbody>
|
|
<?php foreach ($data['events_table'] as $event) : ?>
|
|
<tr>
|
|
<td><?php echo esc_html(ucfirst($event['status'])); ?></td>
|
|
<td>
|
|
<strong><a href="<?php echo esc_url($event['link']); ?>" target="_blank"><?php echo esc_html($event['name']); ?></a></strong>
|
|
</td>
|
|
<td><?php echo esc_html(date('Y-m-d H:i', $event['start_date_ts'])); ?></td>
|
|
<td><?php
|
|
if (function_exists('tribe_get_organizer')) {
|
|
echo esc_html(tribe_get_organizer($event['organizer_id']));
|
|
} else {
|
|
echo 'Organizer ID: ' . esc_html($event['organizer_id']);
|
|
}
|
|
?></td>
|
|
<td><?php echo esc_html($event['capacity']); ?></td>
|
|
<td><?php echo esc_html($event['sold']); ?></td>
|
|
<td>$<?php echo esc_html(number_format($event['revenue'], 2)); ?></td>
|
|
<td>
|
|
<?php
|
|
$edit_url = add_query_arg('event_id', $event['id'], home_url('/manage-event/'));
|
|
$summary_url = get_permalink($event['id']);
|
|
?>
|
|
<a href="<?php echo esc_url($edit_url); ?>">Edit</a> |
|
|
<a href="<?php echo esc_url($summary_url); ?>">Summary</a>
|
|
</td>
|
|
</tr>
|
|
<?php endforeach; ?>
|
|
</tbody>
|
|
</table>
|
|
<?php else : ?>
|
|
<p>No events found.</p>
|
|
<?php endif; ?>
|
|
</div>
|
|
</section>
|
|
</div>
|
|
<?php
|
|
return ob_get_clean();
|
|
}
|
|
|
|
/**
|
|
* Enqueue dashboard styles
|
|
*/
|
|
public function enqueue_dashboard_styles() {
|
|
if (!is_page('hvac-dashboard')) {
|
|
return;
|
|
}
|
|
|
|
// Inline CSS for now - can be moved to external file later
|
|
$css = '
|
|
.hvac-dashboard-wrapper {
|
|
max-width: 1200px;
|
|
margin: 0 auto;
|
|
padding: 20px;
|
|
}
|
|
|
|
.hvac-dashboard-header {
|
|
margin-bottom: 30px;
|
|
}
|
|
|
|
.hvac-dashboard-header h1 {
|
|
margin-bottom: 20px;
|
|
}
|
|
|
|
.hvac-dashboard-nav {
|
|
display: flex;
|
|
gap: 10px;
|
|
flex-wrap: wrap;
|
|
}
|
|
|
|
.hvac-button {
|
|
display: inline-block;
|
|
padding: 10px 20px;
|
|
text-decoration: none;
|
|
border-radius: 4px;
|
|
transition: all 0.3s ease;
|
|
}
|
|
|
|
.hvac-button-primary {
|
|
background-color: #E9AF28;
|
|
color: #000;
|
|
}
|
|
|
|
.hvac-button-primary:hover {
|
|
background-color: #d49b20;
|
|
}
|
|
|
|
.hvac-button-secondary {
|
|
background-color: #0B5C7D;
|
|
color: #fff;
|
|
}
|
|
|
|
.hvac-button-secondary:hover {
|
|
background-color: #084562;
|
|
}
|
|
|
|
.hvac-dashboard-stats {
|
|
margin-bottom: 40px;
|
|
}
|
|
|
|
.hvac-stats-grid {
|
|
display: grid;
|
|
grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
|
|
gap: 20px;
|
|
margin-top: 20px;
|
|
}
|
|
|
|
.hvac-stat-card {
|
|
background: #f8f9fa;
|
|
border: 1px solid #e9ecef;
|
|
border-radius: 8px;
|
|
padding: 20px;
|
|
text-align: center;
|
|
}
|
|
|
|
.hvac-stat-card h3 {
|
|
margin: 0 0 10px;
|
|
font-size: 16px;
|
|
color: #666;
|
|
}
|
|
|
|
.hvac-stat-card .metric-value {
|
|
font-size: 32px;
|
|
font-weight: bold;
|
|
color: #E9AF28;
|
|
margin: 0;
|
|
}
|
|
|
|
.hvac-stat-card small {
|
|
display: block;
|
|
margin-top: 5px;
|
|
color: #666;
|
|
}
|
|
|
|
.hvac-dashboard-events {
|
|
margin-top: 40px;
|
|
}
|
|
|
|
.hvac-event-filters {
|
|
margin: 20px 0;
|
|
display: flex;
|
|
gap: 10px;
|
|
align-items: center;
|
|
}
|
|
|
|
.hvac-filter {
|
|
padding: 5px 15px;
|
|
border: 1px solid #ddd;
|
|
border-radius: 4px;
|
|
text-decoration: none;
|
|
color: #333;
|
|
transition: all 0.3s ease;
|
|
}
|
|
|
|
.hvac-filter:hover,
|
|
.hvac-filter-active {
|
|
background-color: #E9AF28;
|
|
color: #000;
|
|
border-color: #E9AF28;
|
|
}
|
|
|
|
.hvac-events-table-wrapper {
|
|
overflow-x: auto;
|
|
}
|
|
|
|
.hvac-events-table {
|
|
width: 100%;
|
|
border-collapse: collapse;
|
|
margin-top: 20px;
|
|
}
|
|
|
|
.hvac-events-table th,
|
|
.hvac-events-table td {
|
|
padding: 12px;
|
|
text-align: left;
|
|
border-bottom: 1px solid #ddd;
|
|
}
|
|
|
|
.hvac-events-table th {
|
|
background-color: #f8f9fa;
|
|
font-weight: bold;
|
|
}
|
|
|
|
.hvac-events-table tr:hover {
|
|
background-color: #f8f9fa;
|
|
}
|
|
|
|
.hvac-events-table a {
|
|
color: #0B5C7D;
|
|
text-decoration: none;
|
|
}
|
|
|
|
.hvac-events-table a:hover {
|
|
text-decoration: underline;
|
|
}
|
|
|
|
@media (max-width: 768px) {
|
|
.hvac-stats-grid {
|
|
grid-template-columns: 1fr;
|
|
}
|
|
|
|
.hvac-events-table {
|
|
font-size: 14px;
|
|
}
|
|
|
|
.hvac-events-table th,
|
|
.hvac-events-table td {
|
|
padding: 8px;
|
|
}
|
|
}
|
|
';
|
|
|
|
wp_add_inline_style('astra-theme-css', $css);
|
|
}
|
|
}
|
|
|
|
// Initialize the dashboard
|
|
new HVAC_Dashboard();
|