Display egd in edit files

This commit is contained in:
2026-08-01 21:24:41 +02:00
parent 2139a31e7c
commit c36f409484
2 changed files with 62 additions and 33 deletions
+49 -26
View File
@@ -464,6 +464,30 @@ function go_form_delete_custom_field()
add_action('admin_post_go_form_delete_custom_field', 'go_form_delete_custom_field');
// ========== Entry Edit Admin Action ==========
function go_form_fetch_egd_data($pin)
{
$pin = trim($pin);
if (empty($pin)) {
return null;
}
$url = 'https://europeangodatabase.eu/EGD/GetPlayerDataByPIN.php?pin=' . urlencode($pin);
$response = wp_remote_get($url, ['timeout' => 10]);
if (is_wp_error($response)) {
return null;
}
$body = wp_remote_retrieve_body($response);
$data = json_decode($body, true);
if ($data && isset($data['retcode']) && $data['retcode'] === 'Ok') {
return $data;
}
return null;
}
function go_form_update_egd_data()
{
go_form_admin_action('update_egd_data');
@@ -473,7 +497,7 @@ function go_form_update_egd_data()
exit;
}
global $wpdb, $ranks;
global $wpdb;
$form_id = intval($_POST['value_one']);
$entries = go_form_get_entries($form_id);
$updated_count = 0;
@@ -483,35 +507,26 @@ function go_form_update_egd_data()
continue;
}
$pin = trim($entry->egd_number);
$url = 'https://europeangodatabase.eu/EGD/GetPlayerDataByPIN.php?pin=' . urlencode($pin);
$response = wp_remote_get($url, ['timeout' => 10]);
if (is_wp_error($response)) {
$data = go_form_fetch_egd_data($entry->egd_number);
if (!$data) {
continue;
}
$body = wp_remote_retrieve_body($response);
$data = json_decode($body, true);
// Map EGD Grade_n to our rank system
// EGD Grade_n: 0=30k, 1=29k, ... 25=5k, 30=1d, ... 39=9d, 40=1p, ... 47=9p
// Our ranks array: 0=30k, 1=29k, ... 25=5k, 30=1d, ... 39=9d, 40=1p, ... 47=9p
// So we can use Grade_n directly as our rank value
$new_rank = isset($data['Grade_n']) ? intval($data['Grade_n']) : $entry->rank;
$new_rating = isset($data['Gor']) ? intval($data['Gor']) : $entry->rating;
if ($data && isset($data['retcode']) && $data['retcode'] === 'Ok') {
// Map EGD Grade_n to our rank system
// EGD Grade_n: 0=30k, 1=29k, ... 25=5k, 30=1d, ... 39=9d, 40=1p, ... 47=9p
// Our ranks array: 0=30k, 1=29k, ... 25=5k, 30=1d, ... 39=9d, 40=1p, ... 47=9p
// So we can use Grade_n directly as our rank value
$new_rank = isset($data['Grade_n']) ? intval($data['Grade_n']) : $entry->rank;
$new_rating = isset($data['Gor']) ? intval($data['Gor']) : $entry->rating;
// Only update if values changed
if ($new_rank !== $entry->rank || $new_rating !== $entry->rating) {
$wpdb->update(
"{$wpdb->prefix}go_form_entries",
['rank' => $new_rank, 'rating' => $new_rating],
['id' => $entry->id]
);
$updated_count++;
}
// Only update if values changed
if ($new_rank !== $entry->rank || $new_rating !== $entry->rating) {
$wpdb->update(
"{$wpdb->prefix}go_form_entries",
['rank' => $new_rank, 'rating' => $new_rating],
['id' => $entry->id]
);
$updated_count++;
}
}
@@ -627,3 +642,11 @@ function go_form_settings_page()
{
include_once 'templates/settings-page.php';
}
function go_form_egd_hint($value)
{
if ($value === null || $value === '') {
return '';
}
return ' <span style="color:#2271b1; font-style:italic;">(EGD: ' . esc_html($value) . ')</span>';
}
+12 -6
View File
@@ -162,29 +162,35 @@ if (isset($_GET['error']) && $_GET['error'] == 'egd_update_failed')
$entry = go_form_get_entry_by_id($edit_entry_id);
if ($entry && $entry->form_id == $selected_form_id) {
$custom_fields = go_form_get_custom_fields($selected_form_id);
global $ranks;
$egd_data = !empty($entry->egd_number) ? go_form_fetch_egd_data($entry->egd_number) : null;
echo '<div style="margin-bottom:20px; padding:15px; background:#fff; border:1px solid #ddd; border-radius:4px;">';
echo '<h3>Edit Entry</h3>';
if (!empty($entry->egd_number) && !$egd_data) {
echo '<div class="notice notice-warning inline"><p>Could not fetch EGD data for PIN ' . esc_html($entry->egd_number) . '.</p></div>';
}
echo '<form method="post" action="' . admin_url('admin-post.php') . '">';
echo wp_nonce_field('go_form_update_entry_action', 'go_form_update_entry_nonce', true, false);
echo '<input type="hidden" name="action" value="go_form_update_entry">';
echo '<input type="hidden" name="entry_id" value="' . esc_attr($entry->id) . '">';
echo '<input type="hidden" name="form_id" value="' . esc_attr($selected_form_id) . '">';
echo '<table class="form-table">';
echo '<tr><th><label for="first_name">First Name*:</label></th><td><input type="text" name="first_name" id="first_name" value="' . esc_attr($entry->first_name) . '" required></td></tr>';
echo '<tr><th><label for="last_name">Last Name*:</label></th><td><input type="text" name="last_name" id="last_name" value="' . esc_attr($entry->last_name) . '" required></td></tr>';
echo '<tr><th><label for="country">Country:</label></th><td><input type="text" name="country" id="country" value="' . esc_attr($entry->country) . '"></td></tr>';
echo '<tr><th><label for="club">Club:</label></th><td><input type="text" name="club" id="club" value="' . esc_attr($entry->club) . '"></td></tr>';
echo '<tr><th><label for="first_name">First Name*:</label></th><td><input type="text" name="first_name" id="first_name" value="' . esc_attr($entry->first_name) . '" required>' . go_form_egd_hint($egd_data['Name'] ?? $egd_data['Real_Name'] ?? null) . '</td></tr>';
echo '<tr><th><label for="last_name">Last Name*:</label></th><td><input type="text" name="last_name" id="last_name" value="' . esc_attr($entry->last_name) . '" required>' . go_form_egd_hint($egd_data['Last_Name'] ?? $egd_data['Real_Last_Name'] ?? null) . '</td></tr>';
echo '<tr><th><label for="country">Country:</label></th><td><input type="text" name="country" id="country" value="' . esc_attr($entry->country) . '">' . go_form_egd_hint($egd_data['Country_Code'] ?? null) . '</td></tr>';
echo '<tr><th><label for="club">Club:</label></th><td><input type="text" name="club" id="club" value="' . esc_attr($entry->club) . '">' . go_form_egd_hint($egd_data['Club'] ?? null) . '</td></tr>';
echo '<tr><th><label for="display_country">Display Country:</label></th><td><input type="text" name="display_country" id="display_country" value="' . esc_attr($entry->display_country) . '"></td></tr>';
echo '<tr><th><label for="display_club">Display Club:</label></th><td><input type="text" name="display_club" id="display_club" value="' . esc_attr($entry->display_club) . '"></td></tr>';
echo '<tr><th><label for="rank">Rank:</label></th><td>';
echo '<select name="rank" id="rank">';
global $ranks;
foreach ($ranks as $value => $label) {
echo '<option value="' . esc_attr($value) . '" ' . selected($entry->rank, $value, false) . '>' . esc_html($label) . '</option>';
}
echo '</select>';
echo go_form_egd_hint(isset($egd_data['Grade_n']) ? ($ranks[intval($egd_data['Grade_n'])] ?? null) : null);
echo '</td></tr>';
echo '<tr><th><label for="rating">Rating:</label></th><td><input type="number" name="rating" id="rating" value="' . esc_attr($entry->rating) . '"></td></tr>';
echo '<tr><th><label for="rating">Rating:</label></th><td><input type="number" name="rating" id="rating" value="' . esc_attr($entry->rating) . '">' . go_form_egd_hint($egd_data['Gor'] ?? null) . '</td></tr>';
echo '<tr><th><label for="egd_number">EGD Number:</label></th><td><input type="text" name="egd_number" id="egd_number" value="' . esc_attr($entry->egd_number) . '"></td></tr>';
// Custom fields