169 lines
No EOL
9.8 KiB
PHP
169 lines
No EOL
9.8 KiB
PHP
<?php
|
|
/**
|
|
* Template Name: Manage Jobs
|
|
*
|
|
* This template is used for the page where Quiz Managers can manage Job postings.
|
|
*
|
|
* @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_jobs' 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">
|
|
<h2><?php esc_html_e( 'Your Job Postings', 'quiztech' ); ?></h2>
|
|
<?php
|
|
// Query args to get jobs for the current user
|
|
$current_user_id = get_current_user_id();
|
|
$args = array(
|
|
'post_type' => 'job',
|
|
'posts_per_page' => -1, // Get all jobs
|
|
'author' => $current_user_id,
|
|
'post_status' => 'any', // Include drafts, pending, etc.
|
|
'orderby' => 'date',
|
|
'order' => 'DESC',
|
|
);
|
|
|
|
$user_jobs_query = new WP_Query( $args );
|
|
|
|
if ( $user_jobs_query->have_posts() ) :
|
|
?>
|
|
<table class="quiztech-manage-table wp-list-table widefat fixed striped">
|
|
<thead>
|
|
<tr>
|
|
<th scope="col"><?php esc_html_e( 'Title', 'quiztech' ); ?></th>
|
|
<th scope="col"><?php esc_html_e( 'Status', 'quiztech' ); ?></th>
|
|
<th scope="col"><?php esc_html_e( 'Actions', 'quiztech' ); ?></th>
|
|
</tr>
|
|
</thead>
|
|
<tbody>
|
|
<?php while ( $user_jobs_query->have_posts() ) : $user_jobs_query->the_post(); ?>
|
|
<tr>
|
|
<td>
|
|
<strong><a href="<?php echo esc_url( get_edit_post_link( get_the_ID() ) ); ?>" title="<?php esc_attr_e( 'Edit this job in WP Admin', 'quiztech' ); ?>"><?php the_title(); ?></a></strong>
|
|
<?php // Add quick edit later if needed ?>
|
|
</td>
|
|
<td><?php echo esc_html( get_post_status( get_the_ID() ) ); ?></td>
|
|
<td>
|
|
<?php $results_url = '#view-results-' . get_the_ID(); // Placeholder ?>
|
|
<button class="button button-small quiztech-edit-job-btn" data-job-id="<?php echo esc_attr( get_the_ID() ); ?>"><?php esc_html_e( 'Edit', 'quiztech' ); ?></button> |
|
|
<a href="<?php echo esc_url( $results_url ); ?>"><?php esc_html_e( 'View Results', 'quiztech' ); ?></a> |
|
|
<a href="#send-invite" class="send-job-invite" data-job-id="<?php echo esc_attr( get_the_ID() ); ?>"><?php esc_html_e( 'Send Invite', 'quiztech' ); ?></a>
|
|
</td>
|
|
</tr>
|
|
<tr class="send-invite-form-row" id="send-invite-row-<?php echo esc_attr( get_the_ID() ); ?>" style="display: none;">
|
|
<td colspan="3">
|
|
<div class="send-invite-form-wrapper" style="padding: 10px; background-color: #f9f9f9;">
|
|
<label for="applicant_email_<?php echo esc_attr( get_the_ID() ); ?>"><?php esc_html_e( 'Applicant Email:', 'quiztech' ); ?></label>
|
|
<input type="email" id="applicant_email_<?php echo esc_attr( get_the_ID() ); ?>" name="applicant_email" size="40" />
|
|
<button class="button button-primary send-invite-submit" data-job-id="<?php echo esc_attr( get_the_ID() ); ?>"><?php esc_html_e( 'Send', 'quiztech' ); ?></button>
|
|
<button class="button cancel-invite"><?php esc_html_e( 'Cancel', 'quiztech' ); ?></button>
|
|
<span class="spinner" style="float: none; vertical-align: middle;"></span>
|
|
<div class="invite-status" style="display: inline-block; margin-left: 10px;"></div>
|
|
</div>
|
|
</td>
|
|
</tr>
|
|
<?php endwhile; ?>
|
|
</tbody>
|
|
</table>
|
|
<?php
|
|
else :
|
|
echo '<p>' . esc_html__( 'You have not created any jobs yet.', 'quiztech' ) . '</p>';
|
|
endif;
|
|
|
|
// Restore original Post Data
|
|
wp_reset_postdata();
|
|
?>
|
|
|
|
<p style="margin-top: 20px;"><a href="#add-new-job-form" class="button add-new-job-button"><?php esc_html_e( 'Add New Job', 'quiztech' ); ?></a></p>
|
|
|
|
<div id="add-new-job-form" style="margin-top: 20px; padding-top: 20px; border-top: 1px solid #ccc; display: none;"> <!-- Initially hidden -->
|
|
<h2><?php esc_html_e( 'Add New Job Details', 'quiztech' ); ?></h2>
|
|
<form id="new-job-form" method="post" action="">
|
|
<?php wp_nonce_field( 'quiztech_add_new_job_action', 'quiztech_add_new_job_nonce' ); ?>
|
|
|
|
<p>
|
|
<label for="job_title"><?php esc_html_e( 'Job Title:', 'quiztech' ); ?></label><br />
|
|
<input type="text" id="job_title" name="job_title" value="" required style="width: 100%;" />
|
|
<input type="hidden" id="quiztech-job-id" name="job_id" value="">
|
|
</p>
|
|
|
|
<p>
|
|
<label for="job_description"><?php esc_html_e( 'Job Description:', 'quiztech' ); ?></label><br />
|
|
<?php
|
|
// Basic textarea for now. Replace with wp_editor in a later refinement step if needed.
|
|
// wp_editor( '', 'job_description', array('textarea_rows' => 10) );
|
|
?>
|
|
<textarea id="job_description" name="job_description" rows="10" style="width: 100%;"></textarea>
|
|
</p>
|
|
|
|
<p>
|
|
<label for="quiztech_associated_assessment_id"><?php esc_html_e( 'Linked Assessment:', 'quiztech' ); ?></label><br />
|
|
<?php
|
|
// Query published assessments
|
|
$assessments_query = new WP_Query( [
|
|
'post_type' => 'assessment',
|
|
'posts_per_page' => -1,
|
|
'post_status' => 'publish',
|
|
'orderby' => 'title',
|
|
'order' => 'ASC',
|
|
] );
|
|
|
|
echo '<select name="quiztech_associated_assessment_id" id="quiztech_associated_assessment_id" style="width: 100%;">';
|
|
echo '<option value="">' . esc_html__( '-- None --', 'quiztech' ) . '</option>';
|
|
|
|
if ( $assessments_query->have_posts() ) {
|
|
while ( $assessments_query->have_posts() ) {
|
|
$assessments_query->the_post();
|
|
$assessment_id = get_the_ID();
|
|
$assessment_title = get_the_title();
|
|
// Note: The 'selected' attribute will be handled by JavaScript when editing
|
|
echo '<option value="' . esc_attr( $assessment_id ) . '">' . esc_html( $assessment_title ) . '</option>';
|
|
}
|
|
wp_reset_postdata(); // Restore original post data
|
|
}
|
|
echo '</select>';
|
|
|
|
if ( ! $assessments_query->have_posts() ) {
|
|
echo '<br><small>' . esc_html__( 'No assessments found. Please create an assessment first.', 'quiztech' ) . '</small>';
|
|
}
|
|
?>
|
|
</p>
|
|
|
|
|
|
<p>
|
|
<input type="submit" name="submit_new_job" class="button button-primary" value="<?php esc_attr_e( 'Save Job', 'quiztech' ); ?>" />
|
|
<button type="button" class="button cancel-add-job"><?php esc_html_e( 'Cancel', 'quiztech' ); ?></button>
|
|
<span class="spinner" style="float: none; vertical-align: middle;"></span>
|
|
<div class="add-job-status" style="display: inline-block; margin-left: 10px;"></div>
|
|
</p>
|
|
</form>
|
|
</div>
|
|
|
|
</div><!-- .entry-content -->
|
|
|
|
</article><!-- #post-<?php the_ID(); ?> -->
|
|
|
|
</main><!-- #main -->
|
|
</div><!-- #primary -->
|
|
|
|
<?php
|
|
get_footer();
|