83 lines
2.4 KiB
PHP
83 lines
2.4 KiB
PHP
<?php
|
|
|
|
go_form_admin_action('export_macmahon');
|
|
if (!isset($_POST['value_one'])) {
|
|
wp_redirect(admin_url('admin.php?page=go-form-settings'));
|
|
exit;
|
|
}
|
|
|
|
$form_id = intval($_POST['value_one']);
|
|
$form = go_form_get_form_by_id($form_id);
|
|
$form_name = $form ? $form->name : 'Unknown Form';
|
|
$entries = go_form_get_entries($form_id);
|
|
|
|
header('Content-Type: text/xml; charset=utf-8');
|
|
header('Content-Disposition: attachment; filename="go-form-' . sanitize_title($form_name) . '-export-macmahon.xml"');
|
|
|
|
$output = fopen('php://output', 'w');
|
|
include_once 'macmahon-help.php';
|
|
|
|
fwrite($output, $macmahonfirst);
|
|
|
|
// Gather the distinct clubs used per country among the actual participants
|
|
$clubs_by_country = [];
|
|
foreach ($entries as $e) {
|
|
$country_code = strtoupper(trim($e->country));
|
|
$club = trim($e->club);
|
|
if ($country_code === '' || $club === '') {
|
|
continue;
|
|
}
|
|
if (!isset($clubs_by_country[$country_code])) {
|
|
$clubs_by_country[$country_code] = [];
|
|
}
|
|
if (!in_array($club, $clubs_by_country[$country_code], true)) {
|
|
$clubs_by_country[$country_code][] = $club;
|
|
}
|
|
}
|
|
|
|
foreach ($countries as $code => $name) {
|
|
$out = ' <Country typeversion="1">
|
|
<InternetCode>' . esc_html(strtolower($code)) . '</InternetCode>
|
|
<Name>' . esc_html($name) . '</Name>';
|
|
if (!empty($clubs_by_country[$code])) {
|
|
foreach ($clubs_by_country[$code] as $club) {
|
|
$out .= '
|
|
<Club typeversion="1">
|
|
<Name>' . esc_html($club) . '</Name>
|
|
<EGDName>' . esc_html($club) . '</EGDName>
|
|
</Club>';
|
|
}
|
|
}
|
|
$out .= '
|
|
</Country>';
|
|
fwrite($output, $out);
|
|
}
|
|
|
|
foreach ($entries as $i => $e) {
|
|
$rank = $ranks[$e->rank];
|
|
$id = $i + 1;
|
|
$egd = (strlen($e->egd_number) == 0) ? '0' : $e->egd_number;
|
|
$out = " <IndividualParticipant typeversion=\"1\">
|
|
<Id>$id</Id>
|
|
<Joker>false</Joker>
|
|
<PreliminaryRegistration>false</PreliminaryRegistration>
|
|
<ScoreAdjustment>false</ScoreAdjustment>
|
|
<ScoreAdjustmentValue>0</ScoreAdjustmentValue>
|
|
<SuperBarMember>false</SuperBarMember>
|
|
<GoPlayer typeversion=\"1\">
|
|
<AsianName>false</AsianName>
|
|
<FirstName><![CDATA[$e->first_name]]></FirstName>
|
|
<Surname><![CDATA[$e->last_name]]></Surname>
|
|
<GoLevel>$rank</GoLevel>
|
|
<Rating>$e->rating</Rating>
|
|
<EgdPin>$egd</EgdPin>
|
|
<Country>$e->country</Country>
|
|
<Club>$e->club</Club>
|
|
</GoPlayer>
|
|
</IndividualParticipant>";
|
|
fwrite($output, $out);
|
|
}
|
|
|
|
fwrite($output, $macmahonlast);
|
|
|
|
fclose($output); |