| 1 |
<?php |
| 2 |
// ====== |
| 3 |
// INIT |
| 4 |
// ====== |
| 5 |
if (empty($props) || !empty($props['error']) || !empty($props['danger'])) |
| 6 |
$props = []; |
| 7 |
|
| 8 |
// =============== |
| 9 |
// ORGANIZE LIST |
| 10 |
// =============== |
| 11 |
|
| 12 |
// pre-group by status bucket |
| 13 |
$groups = ['pending' => [], 'completed' => []]; |
| 14 |
foreach ($props as $app) { |
| 15 |
if (!is_array($app) || empty($app['applicant_id'])) continue; |
| 16 |
$bucket = ((int)($app['app_status'] ?? 0)) === 0 ? 'pending' : 'completed'; |
| 17 |
$groups[$bucket][] = $app; |
| 18 |
} |
| 19 |
|
| 20 |
// ==================== |
| 21 |
// APPLICATION BUTTON |
| 22 |
// ==================== |
| 23 |
$networkMap = get_option('powerpress_network_map', []); |
| 24 |
$applicationPageExists = false; |
| 25 |
$applicationPageId = null; |
| 26 |
if (!empty($networkMap['Application'])) { |
| 27 |
$pageId = $networkMap['Application']; |
| 28 |
if (get_post_status($pageId) == 'publish') { |
| 29 |
$applicationPageExists = true; |
| 30 |
$applicationPageId = $pageId; |
| 31 |
} |
| 32 |
} |
| 33 |
|
| 34 |
// ================= |
| 35 |
// TOS URL SETTING |
| 36 |
// ================= |
| 37 |
$ppn_settings = get_option('powerpress_network', []); |
| 38 |
$tos_url = $ppn_settings['tos_url'] ?? ''; |
| 39 |
?> |
| 40 |
|
| 41 |
<!-- ============= |
| 42 |
PAGE HEADER |
| 43 |
============= --> |
| 44 |
<div class="ppn-section-header"> |
| 45 |
<h2 class="ppn-manage__section-title"><?php echo esc_html(get_option('powerpress_network_title'));?></h2> |
| 46 |
<?php if ($applicationPageExists): ?> |
| 47 |
<a class="button" href="<?php echo esc_url(get_edit_post_link($applicationPageId)); ?>" target="_blank"> |
| 48 |
<?php esc_html_e('Edit Application Page', 'powerpress'); ?> |
| 49 |
</a> |
| 50 |
<?php else: ?> |
| 51 |
<button type="button" class="button" |
| 52 |
data-ppn-action="ppnPageAction" |
| 53 |
data-mode="singleton" |
| 54 |
data-target="Application" |
| 55 |
data-title="<?php echo esc_attr(get_option('powerpress_network_title') . ' Application'); ?>" |
| 56 |
data-edit-label="<?php esc_attr_e('Edit Application Page', 'powerpress'); ?>"> |
| 57 |
<?php esc_html_e('Create Application', 'powerpress'); ?> |
| 58 |
</button> |
| 59 |
<?php endif; ?> |
| 60 |
</div> |
| 61 |
<h4 class="ppn-manage__section-desc"><?php esc_html_e('Review and manage applications from shows wanting to join your network.', 'powerpress'); ?></h4> |
| 62 |
|
| 63 |
<!-- ==================== |
| 64 |
TOS COLLAPSIBLE |
| 65 |
==================== --> |
| 66 |
<div class="ppn-tos"> |
| 67 |
<div class="ppn-toggle ppn-toggle--collapsed" data-ppn-section="tos"> |
| 68 |
<label class="ppn-manage__field-label" style="margin: 0; cursor: pointer;"><?php esc_html_e('Terms & Conditions', 'powerpress'); ?></label> |
| 69 |
<i class="material-icons-outlined ppn-toggle__chevron">expand_more</i> |
| 70 |
</div> |
| 71 |
<div class="ppn-toggle__body" data-ppn-section="tos"> |
| 72 |
<div class="ppn-toggle__inner"> |
| 73 |
<form method="post" id="tosUrlForm"> |
| 74 |
<input type="hidden" name="ppn-action" value="save-tos-url" /> |
| 75 |
<?php wp_nonce_field('powerpress', '_ppn_nonce'); ?> |
| 76 |
<p class="ppn-tos__hint"><?php esc_html_e('Applicants are required to agree to your Terms before submitting. Leave blank if you do not have Terms.', 'powerpress'); ?></p> |
| 77 |
<div class="d-flex gap-sm" style="align-items: center;"> |
| 78 |
<input type="text" id="ppn_tos_url" name="ppn_tos_url" class="pp-flex-1 ppn-manage__page-link" value="<?php echo esc_attr($tos_url); ?>" placeholder="Terms of Service URL" /> |
| 79 |
<button type="button" class="button" data-ppn-action="saveTosUrl" data-form-id="tosUrlForm"><?php esc_html_e('Save', 'powerpress'); ?></button> |
| 80 |
</div> |
| 81 |
</form> |
| 82 |
</div> |
| 83 |
</div> |
| 84 |
</div> |
| 85 |
|
| 86 |
<!-- =============== |
| 87 |
SEARCH + LIST |
| 88 |
=============== --> |
| 89 |
<div class="ppn-search"> |
| 90 |
<input type="text" class="ppn-search__input" placeholder="<?php esc_attr_e('Filter requests...', 'powerpress'); ?>" |
| 91 |
data-ppn-action="filterList" data-ppn-target="ppn-requests-list"> |
| 92 |
<i class="material-icons-outlined ppn-search__icon">search</i> |
| 93 |
</div> |
| 94 |
|
| 95 |
<div class="ppn-list" id="ppn-requests-list"> |
| 96 |
<div class="ppn-list__header row"> |
| 97 |
<div class="col-4"><?php esc_html_e('Shows', 'powerpress'); ?></div> |
| 98 |
<div class="col-3"><?php esc_html_e('Application', 'powerpress'); ?></div> |
| 99 |
<div class="col-3"><?php esc_html_e('Status', 'powerpress'); ?></div> |
| 100 |
<div class="col-2"><?php esc_html_e('Manage', 'powerpress'); ?></div> |
| 101 |
</div> |
| 102 |
<?php if (empty($groups['pending']) && empty($groups['completed'])): ?> |
| 103 |
<div class="ppn-list__row ppn-list__empty"> |
| 104 |
<span class="pp-text-muted"><?php esc_html_e('No applications yet.', 'powerpress'); ?></span> |
| 105 |
</div> |
| 106 |
<?php elseif (!isset($props['danger'])): |
| 107 |
// shared row renderer |
| 108 |
$render_app = function($app) { |
| 109 |
$showName = $app['show_name'] ?? $app['program_title'] ?? ''; |
| 110 |
$appId = $app['applicant_id'] ?? 0; |
| 111 |
$status = (int)($app['app_status'] ?? 0); |
| 112 |
$statusMap = [1 => 'approved', -1 => 'rejected']; |
| 113 |
$statusMod = $statusMap[$status] ?? 'pending'; |
| 114 |
?> |
| 115 |
<div class="ppn-list__row row" id="app-row-<?php echo esc_attr($appId); ?>" data-title="<?php echo esc_attr(strtolower($showName)); ?>"> |
| 116 |
<div class="col-4"> |
| 117 |
<?php echo esc_html($showName); ?> |
| 118 |
</div> |
| 119 |
<div class="col-3"> |
| 120 |
<span class="ppn-list__label"><?php esc_html_e('Application', 'powerpress'); ?></span> |
| 121 |
<a href="#" class="ppn-page-status--linked" data-ppn-action="ppnDialog" data-ppn-dialog="ppn-app-<?php echo esc_attr($appId); ?>"><?php esc_html_e('View Application', 'powerpress'); ?></a> |
| 122 |
</div> |
| 123 |
<div id="app-status-<?php echo esc_attr($appId); ?>" class="col-3"> |
| 124 |
<span class="ppn-list__label"><?php esc_html_e('Status', 'powerpress'); ?></span> |
| 125 |
<span class="ppn-app-status-label ppn-app-status-label--<?php echo esc_attr($statusMod); ?>"> |
| 126 |
<?php |
| 127 |
if ($status === 1) esc_html_e('Approved', 'powerpress'); |
| 128 |
elseif ($status === -1) esc_html_e('Rejected', 'powerpress'); |
| 129 |
else esc_html_e('Pending', 'powerpress'); |
| 130 |
?> |
| 131 |
</span> |
| 132 |
</div> |
| 133 |
<div class="col-2"> |
| 134 |
<?php if ($status !== 1): ?> |
| 135 |
<button type="button" class="ppn-icon-btn" data-ppn-action="approveProgram" data-applicant-id="<?php echo esc_attr($appId); ?>" data-delete="true"><i class="material-icons-outlined">delete</i></button> |
| 136 |
<?php endif; ?> |
| 137 |
</div> |
| 138 |
</div> |
| 139 |
<?php |
| 140 |
}; |
| 141 |
|
| 142 |
powerpress_render_list_section('pending', __('Pending', 'powerpress'), $groups['pending'], $render_app, false, __('No pending applications.', 'powerpress')); |
| 143 |
powerpress_render_list_section('completed', __('Completed', 'powerpress'), $groups['completed'], $render_app, true, __('No completed applications yet.', 'powerpress')); |
| 144 |
endif; ?> |
| 145 |
</div> |
| 146 |
|
| 147 |
<!-- ==================== |
| 148 |
APPLICATION DIALOGS |
| 149 |
==================== --> |
| 150 |
<?php |
| 151 |
if (!isset($props['danger'])) { |
| 152 |
$lbl_not_provided = __('(not provided)', 'powerpress'); |
| 153 |
$all_apps = array_merge($groups['pending'], $groups['completed']); |
| 154 |
|
| 155 |
foreach ($all_apps as $app) { |
| 156 |
$showName = $app['show_name'] ?? $app['program_title'] ?? ''; |
| 157 |
$appId = $app['applicant_id'] ?? 0; |
| 158 |
$status = (int)($app['app_status'] ?? 0); |
| 159 |
|
| 160 |
// detail field data |
| 161 |
$detailRows = [ |
| 162 |
['label' => __('Podcaster', 'powerpress'), 'value' => $app['podcaster_name'] ?? ''], |
| 163 |
['label' => __('Feed URL', 'powerpress'), 'value' => $app['feed_url'] ?? $app['program_rssurl'] ?? '', 'link' => true], |
| 164 |
['label' => __('Website', 'powerpress'), 'value' => $app['website_url'] ?? '', 'link' => true], |
| 165 |
['label' => __('Show Listing', 'powerpress'), 'value' => $app['listing_url'] ?? '', 'link' => true, 'hr' => true], |
| 166 |
['label' => __('Note', 'powerpress'), 'value' => stripslashes($app['application_note']) ?? '', 'style' => 'white-space: pre-line;', 'hr' => true], |
| 167 |
]; |
| 168 |
?> |
| 169 |
<dialog id="ppn-app-<?php echo esc_attr($appId); ?>" class="ppn-dialog ppn-dialog--md"> |
| 170 |
<button type="button" class="ppn-dialog__close" data-ppn-action="ppnDialogClose" aria-label="<?php esc_attr_e('Close', 'powerpress'); ?>"><i class="material-icons-outlined">close</i></button> |
| 171 |
<div class="container-fluid p-3"> |
| 172 |
<div class="row"><div class="col-12"><h3><?php echo esc_html($showName); ?></h3></div></div> |
| 173 |
<?php foreach ($detailRows as $row): ?> |
| 174 |
<div class="row"> |
| 175 |
<div class="col-4"><strong><?php echo esc_html($row['label']); ?></strong></div> |
| 176 |
<div class="col-8"<?php if (!empty($row['style']) && !empty($row['value'])) echo " style=\"" . esc_attr($row['style']) . "\""; ?>> |
| 177 |
<?php if (empty($row['value'])): ?> |
| 178 |
<span class="pp-text-muted" style="font-style: italic;"><?php echo esc_html($lbl_not_provided); ?></span> |
| 179 |
<?php elseif (!empty($row['link'])): ?> |
| 180 |
<a href="<?php echo esc_url($row['value']); ?>" target="_blank"><?php echo esc_url($row['value']); ?></a> |
| 181 |
<?php else: ?> |
| 182 |
<?php echo esc_html($row['value']); ?> |
| 183 |
<?php endif; ?> |
| 184 |
</div> |
| 185 |
</div> |
| 186 |
<?php if (!empty($row['hr'])): ?><hr><?php endif; ?> |
| 187 |
<?php endforeach; ?> |
| 188 |
<div class="row"> |
| 189 |
<div class="col-4"><strong><?php esc_html_e('Decision', 'powerpress'); ?></strong></div> |
| 190 |
<div id="app-modal-status-<?php echo esc_attr($appId); ?>" class="col-8"> |
| 191 |
<select data-ppn-action="approveProgram" data-applicant-id="<?php echo esc_attr($appId); ?>" class="application-dropdown"> |
| 192 |
<option value="0"<?php selected($status, 0); ?>><?php esc_html_e('Pending', 'powerpress'); ?></option> |
| 193 |
<option value="1"<?php selected($status, 1); ?>><?php esc_html_e('Approve', 'powerpress'); ?></option> |
| 194 |
<option value="-1"<?php selected($status, -1); ?>><?php esc_html_e('Reject', 'powerpress'); ?></option> |
| 195 |
</select> |
| 196 |
</div> |
| 197 |
</div> |
| 198 |
<?php if ($status !== 1): ?> |
| 199 |
<div class="row mt-2"> |
| 200 |
<div class="col-4"></div> |
| 201 |
<div class="col-8"> |
| 202 |
<button type="button" class="ppn-icon-btn" style="display: inline-flex; align-items: center; gap: 4px;" |
| 203 |
data-ppn-action="approveProgram" |
| 204 |
data-applicant-id="<?php echo esc_attr($appId); ?>" |
| 205 |
data-delete="true"> |
| 206 |
<i class="material-icons-outlined">delete</i> |
| 207 |
<?php esc_html_e('Delete Application', 'powerpress'); ?> |
| 208 |
</button> |
| 209 |
</div> |
| 210 |
</div> |
| 211 |
<?php endif; ?> |
| 212 |
</div> |
| 213 |
</dialog> |
| 214 |
<?php |
| 215 |
} |
| 216 |
} |
| 217 |
?> |
| 218 |
|