Files
Digital-Dabei-Hamburg-Job-M…/templates/provider-dashboard.php
Viktor Miller fbbd44a07b feat(04-01): add deactivate action to provider dashboard
Add deactivate mode detection alongside existing edit mode checking for action=deactivate_job and job_id parameter. When in deactivate mode, render deactivation form section similar to edit section structure with heading "Stellenangebot deaktivieren", back link to dashboard, and form shortcode with id_param={job_id}. In job listings table, add "Deaktivieren" button in Actions column only for published jobs (status === 'publish'). Deactivate button uses warning/destructive color (red background) to differentiate from edit/view buttons. Follow same conditional rendering pattern as edit mode showing deactivation form OR listings, not both.

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2026-01-14 20:03:09 +09:00

368 lines
8.0 KiB
PHP

<?php
/**
* Provider Dashboard Template
*
* Displays the current provider's job listings in a table format
*
* @package DDHH_Job_Manager
*/
// Exit if accessed directly.
defined( 'ABSPATH' ) || exit;
// Check if user is logged in and has the ddhh_provider role
if ( ! is_user_logged_in() ) {
echo '<div class="ddhh-error-message">';
echo '<p>Sie müssen angemeldet sein, um diese Seite anzuzeigen.</p>';
echo '</div>';
return;
}
$current_user = wp_get_current_user();
if ( ! in_array( 'ddhh_provider', $current_user->roles, true ) ) {
echo '<div class="ddhh-error-message">';
echo '<p>Sie haben keine Berechtigung, diese Seite anzuzeigen.</p>';
echo '</div>';
return;
}
// Check if we're in edit mode
$is_edit_mode = isset( $_GET['action'] ) && $_GET['action'] === 'edit_job' && isset( $_GET['job_id'] );
// Check if we're in deactivate mode
$is_deactivate_mode = isset( $_GET['action'] ) && $_GET['action'] === 'deactivate_job' && isset( $_GET['job_id'] );
if ( $is_edit_mode ) {
$job_id = absint( $_GET['job_id'] );
$form_id = DDHH_JM_Formidable::get_job_edit_form_id();
if ( $form_id ) {
?>
<div class="ddhh-provider-dashboard">
<div class="ddhh-job-edit-section">
<h2>Stellenangebot bearbeiten</h2>
<p><a href="<?php echo esc_url( get_permalink() ); ?>" class="back-to-dashboard">← Zurück zur Übersicht</a></p>
<?php echo do_shortcode( "[formidable id={$form_id} id_param={$job_id}]" ); ?>
</div>
</div>
<?php
return;
}
}
if ( $is_deactivate_mode ) {
$job_id = absint( $_GET['job_id'] );
$form_id = DDHH_JM_Formidable::get_job_deactivation_form_id();
if ( $form_id ) {
?>
<div class="ddhh-provider-dashboard">
<div class="ddhh-job-deactivate-section">
<h2>Stellenangebot deaktivieren</h2>
<p><a href="<?php echo esc_url( get_permalink() ); ?>" class="back-to-dashboard">← Zurück zur Übersicht</a></p>
<?php echo do_shortcode( "[formidable id={$form_id} id_param={$job_id}]" ); ?>
</div>
</div>
<?php
return;
}
}
// Query current user's job_offer posts
$args = array(
'post_type' => 'job_offer',
'author' => get_current_user_id(),
'post_status' => array( 'publish', 'pending', 'draft' ),
'orderby' => 'date',
'order' => 'DESC',
'posts_per_page' => -1,
);
$job_query = new WP_Query( $args );
?>
<div class="ddhh-provider-dashboard">
<div class="ddhh-job-submit-section">
<h2>Neues Stellenangebot erstellen</h2>
<?php
$form_id = DDHH_JM_Formidable::get_job_submission_form_id();
if ( $form_id ) {
echo do_shortcode( "[formidable id={$form_id}]" );
} else {
echo '<p>Formular konnte nicht geladen werden.</p>';
}
?>
</div>
<div class="ddhh-job-listings-section">
<h2>Meine Stellenangebote</h2>
<?php if ( $job_query->have_posts() ) : ?>
<table class="ddhh-jobs-table">
<thead>
<tr>
<th>Titel</th>
<th>Status</th>
<th>Standort</th>
<th>Art</th>
<th>Aktionen</th>
</tr>
</thead>
<tbody>
<?php while ( $job_query->have_posts() ) : $job_query->the_post(); ?>
<?php
$post_id = get_the_ID();
$post_status = get_post_status();
$location = get_field( 'job_location', $post_id );
$job_type = get_field( 'job_type', $post_id );
// Translate status to German
$status_labels = array(
'publish' => 'Veröffentlicht',
'pending' => 'Ausstehend',
'draft' => 'Entwurf',
);
$status_text = isset( $status_labels[ $post_status ] ) ? $status_labels[ $post_status ] : $post_status;
?>
<tr>
<td class="job-title"><?php the_title(); ?></td>
<td class="job-status">
<span class="status-badge status-<?php echo esc_attr( $post_status ); ?>">
<?php echo esc_html( $status_text ); ?>
</span>
</td>
<td class="job-location"><?php echo esc_html( $location ? $location : '-' ); ?></td>
<td class="job-type"><?php echo esc_html( $job_type ? $job_type : '-' ); ?></td>
<td class="job-actions">
<?php
// Edit link - points to edit form on dashboard
if ( current_user_can( 'edit_job_offer', $post_id ) ) {
$edit_url = add_query_arg(
array(
'action' => 'edit_job',
'job_id' => $post_id,
),
get_permalink()
);
echo '<a href="' . esc_url( $edit_url ) . '" class="button edit-link">Bearbeiten</a>';
}
// View link - only for published posts
if ( 'publish' === $post_status ) {
echo ' <a href="' . esc_url( get_permalink( $post_id ) ) . '" class="button view-link" target="_blank">Ansehen</a>';
}
// Deactivate link - only for published posts
if ( 'publish' === $post_status ) {
$deactivate_url = add_query_arg(
array(
'action' => 'deactivate_job',
'job_id' => $post_id,
),
get_permalink()
);
echo ' <a href="' . esc_url( $deactivate_url ) . '" class="button deactivate-link">Deaktivieren</a>';
}
?>
</td>
</tr>
<?php endwhile; ?>
</tbody>
</table>
<?php else : ?>
<div class="ddhh-empty-state">
<p>Sie haben noch keine Stellenangebote erstellt.</p>
</div>
<?php endif; ?>
<?php wp_reset_postdata(); ?>
</div>
</div>
<style>
.ddhh-provider-dashboard {
max-width: 1200px;
margin: 2rem auto;
padding: 0 1rem;
}
.ddhh-job-submit-section {
margin-bottom: 3rem;
padding: 2rem;
background: #f5f5f5;
border-radius: 8px;
}
.ddhh-job-submit-section h2 {
margin-top: 0;
margin-bottom: 1.5rem;
font-size: 1.5rem;
color: #333;
}
.ddhh-job-edit-section,
.ddhh-job-deactivate-section {
padding: 2rem;
background: #fff;
border-radius: 8px;
box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
}
.ddhh-job-edit-section h2,
.ddhh-job-deactivate-section h2 {
margin-top: 0;
margin-bottom: 1rem;
font-size: 1.5rem;
color: #333;
}
.back-to-dashboard {
display: inline-block;
margin-bottom: 1.5rem;
color: #3b82f6;
text-decoration: none;
font-weight: 500;
}
.back-to-dashboard:hover {
color: #2563eb;
text-decoration: underline;
}
.ddhh-job-listings-section {
margin-top: 3rem;
}
.ddhh-provider-dashboard h2 {
margin-bottom: 1.5rem;
font-size: 2rem;
color: #333;
}
.ddhh-jobs-table {
width: 100%;
border-collapse: collapse;
background: #fff;
box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
}
.ddhh-jobs-table th,
.ddhh-jobs-table td {
padding: 1rem;
text-align: left;
border-bottom: 1px solid #e5e7eb;
}
.ddhh-jobs-table thead th {
background-color: #f9fafb;
font-weight: 600;
color: #374151;
text-transform: uppercase;
font-size: 0.875rem;
letter-spacing: 0.05em;
}
.ddhh-jobs-table tbody tr:hover {
background-color: #f9fafb;
}
.status-badge {
display: inline-block;
padding: 0.25rem 0.75rem;
border-radius: 9999px;
font-size: 0.875rem;
font-weight: 500;
}
.status-publish {
background-color: #d1fae5;
color: #065f46;
}
.status-pending {
background-color: #fef3c7;
color: #92400e;
}
.status-draft {
background-color: #e5e7eb;
color: #374151;
}
.job-actions {
white-space: nowrap;
}
.button {
display: inline-block;
padding: 0.5rem 1rem;
background-color: #3b82f6;
color: #fff;
text-decoration: none;
border-radius: 0.375rem;
font-size: 0.875rem;
transition: background-color 0.2s;
}
.button:hover {
background-color: #2563eb;
color: #fff;
}
.edit-link {
background-color: #6366f1;
}
.edit-link:hover {
background-color: #4f46e5;
}
.view-link {
background-color: #10b981;
margin-left: 0.5rem;
}
.view-link:hover {
background-color: #059669;
}
.deactivate-link {
background-color: #ef4444;
margin-left: 0.5rem;
}
.deactivate-link:hover {
background-color: #dc2626;
}
.ddhh-empty-state,
.ddhh-error-message {
padding: 3rem;
text-align: center;
background: #f9fafb;
border-radius: 0.5rem;
color: #6b7280;
}
.ddhh-error-message {
background: #fee2e2;
color: #991b1b;
}
@media (max-width: 768px) {
.ddhh-jobs-table {
font-size: 0.875rem;
}
.ddhh-jobs-table th,
.ddhh-jobs-table td {
padding: 0.75rem 0.5rem;
}
.button {
padding: 0.375rem 0.75rem;
font-size: 0.8125rem;
}
}
</style>