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 = ' ' . esc_html(strtolower($code)) . ' ' . esc_html($name) . ''; if (!empty($clubs_by_country[$code])) { foreach ($clubs_by_country[$code] as $club) { $out .= ' ' . esc_html($club) . ' ' . esc_html($club) . ' '; } } $out .= ' '; 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 = " $id false false false 0 false false first_name]]> last_name]]> $rank $e->rating $egd $e->country $e->club "; fwrite($output, $out); } fwrite($output, $macmahonlast); fclose($output);