134 lines
No EOL
7.4 KiB
PHP
134 lines
No EOL
7.4 KiB
PHP
<?php
|
|
/**
|
|
* Template Name: Quiztech Dashboard
|
|
*
|
|
* This template is used for the main dashboard page for Quiz Managers.
|
|
*
|
|
* @package Quiztech
|
|
*/
|
|
|
|
// Ensure the user is logged in and has the appropriate capability.
|
|
// Using 'manage_options' as a placeholder capability for Quiz Managers.
|
|
// Replace with a more specific capability like 'manage_quiztech_options' if defined.
|
|
if ( ! is_user_logged_in() || ! current_user_can( 'manage_options' ) ) {
|
|
// Redirect to login page or show an error message.
|
|
wp_safe_redirect( wp_login_url( get_permalink() ) );
|
|
exit;
|
|
// Alternatively, display an error message:
|
|
// wp_die( esc_html__( 'You do not have sufficient permissions to access this page.', 'quiztech' ), 403 );
|
|
}
|
|
|
|
get_header(); ?>
|
|
|
|
<div id="primary" class="content-area">
|
|
<main id="main" class="site-main">
|
|
|
|
<article id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
|
|
<header class="entry-header">
|
|
<?php the_title( '<h1 class="entry-title">', '</h1>' ); ?>
|
|
</header><!-- .entry-header -->
|
|
|
|
<div class="entry-content">
|
|
<?php
|
|
// Fetch dashboard data using helper functions
|
|
$quick_links = function_exists('quiztech_get_dashboard_quick_links') ? quiztech_get_dashboard_quick_links() : [];
|
|
$recent_invitations = function_exists('quiztech_get_dashboard_recent_invitations') ? quiztech_get_dashboard_recent_invitations() : [];
|
|
$recent_completions = function_exists('quiztech_get_dashboard_recent_completions') ? quiztech_get_dashboard_recent_completions() : [];
|
|
$active_job_count = function_exists('quiztech_get_dashboard_active_job_count') ? quiztech_get_dashboard_active_job_count() : 0;
|
|
$credit_balance = ( function_exists('\Quiztech\AssessmentPlatform\Includes\quiztech_get_user_credit_balance') && is_user_logged_in() ) // Correct function name and namespace check
|
|
? \Quiztech\AssessmentPlatform\Includes\quiztech_get_user_credit_balance( get_current_user_id() ) // Correct function call
|
|
: __('N/A', 'quiztech');
|
|
?>
|
|
|
|
<div class="quiztech-dashboard-widgets">
|
|
|
|
<!-- Quick Links Widget -->
|
|
<div class="dashboard-widget quick-links">
|
|
<h2><?php esc_html_e('Quick Links', 'quiztech'); ?></h2>
|
|
<?php if (!empty($quick_links)) : ?>
|
|
<ul>
|
|
<?php foreach ($quick_links as $label => $url) : ?>
|
|
<?php if (!empty($url)) : ?>
|
|
<li><a href="<?php echo esc_url($url); ?>" class="button"><?php echo esc_html($label); ?></a></li>
|
|
<?php else : ?>
|
|
<li><span class="button disabled"><?php echo esc_html($label); ?> (<?php esc_html_e('Page not found', 'quiztech'); ?>)</span></li>
|
|
<?php endif; ?>
|
|
<?php endforeach; ?>
|
|
</ul>
|
|
<?php else : ?>
|
|
<p><?php esc_html_e('Quick links could not be loaded.', 'quiztech'); ?></p>
|
|
<?php endif; ?>
|
|
</div>
|
|
|
|
<!-- Statistics Widget -->
|
|
<div class="dashboard-widget statistics">
|
|
<h2><?php esc_html_e('Statistics', 'quiztech'); ?></h2>
|
|
<p>
|
|
<strong><?php esc_html_e('Active Jobs:', 'quiztech'); ?></strong>
|
|
<?php echo esc_html($active_job_count); ?>
|
|
</p>
|
|
<p>
|
|
<strong><?php esc_html_e('Credits Remaining:', 'quiztech'); ?></strong>
|
|
<?php echo esc_html($credit_balance); ?>
|
|
</p>
|
|
</div>
|
|
|
|
<!-- Recent Activity Widget -->
|
|
<div class="dashboard-widget recent-activity">
|
|
<h2><?php esc_html_e('Recent Activity', 'quiztech'); ?></h2>
|
|
|
|
<div class="activity-section">
|
|
<h3><?php esc_html_e('Invitations Sent', 'quiztech'); ?></h3>
|
|
<?php if (!empty($recent_invitations)) : ?>
|
|
<ul>
|
|
<?php foreach ($recent_invitations as $invitation) : ?>
|
|
<li>
|
|
<?php echo esc_html(gmdate('Y-m-d', strtotime($invitation->created_timestamp))); ?> -
|
|
<?php printf(
|
|
/* translators: 1: Applicant Email, 2: Job Title */
|
|
esc_html__('Invited %1$s for %2$s', 'quiztech'),
|
|
'<strong>' . esc_html($invitation->applicant_email) . '</strong>',
|
|
'<em>' . esc_html($invitation->job_title ?: __('N/A', 'quiztech')) . '</em>'
|
|
); ?>
|
|
</li>
|
|
<?php endforeach; ?>
|
|
</ul>
|
|
<?php else : ?>
|
|
<p><?php esc_html_e('No recent invitations found.', 'quiztech'); ?></p>
|
|
<?php endif; ?>
|
|
</div>
|
|
|
|
<div class="activity-section">
|
|
<h3><?php esc_html_e('Assessments Completed', 'quiztech'); ?></h3>
|
|
<?php if (!empty($recent_completions)) : ?>
|
|
<ul>
|
|
<?php foreach ($recent_completions as $completion) : ?>
|
|
<li>
|
|
<?php echo esc_html(gmdate('Y-m-d', strtotime($completion['completion_date']))); ?> -
|
|
<?php printf(
|
|
/* translators: 1: Applicant Email, 2: Job Title */
|
|
esc_html__('%1$s completed assessment for %2$s', 'quiztech'),
|
|
'<strong>' . esc_html($completion['applicant_email']) . '</strong>',
|
|
'<em>' . esc_html($completion['job_title'] ?: __('N/A', 'quiztech')) . '</em>'
|
|
); ?>
|
|
<?php /* <a href="<?php echo esc_url(get_edit_post_link($completion['evaluation_id'])); ?>">(View)</a> */ ?>
|
|
</li>
|
|
<?php endforeach; ?>
|
|
</ul>
|
|
<?php else : ?>
|
|
<p><?php esc_html_e('No recent completions found.', 'quiztech'); ?></p>
|
|
<?php endif; ?>
|
|
</div>
|
|
</div>
|
|
|
|
</div> <!-- .quiztech-dashboard-widgets -->
|
|
|
|
</div><!-- .entry-content -->
|
|
|
|
</article><!-- #post-<?php the_ID(); ?> -->
|
|
|
|
</main><!-- #main -->
|
|
</div><!-- #primary -->
|
|
|
|
<?php
|
|
get_footer();
|