#!/usr/bin/perl

$name_line1 = "NoName";
$name_line2 = "NoSurname";
$guest_relation = "Guest";
$host_name = "";
@badge_puzzle = (0,0,0,0,0,0,0,0,0,0,0,0);
$temporary = 0;
$country = "NoCountry";
$state = "";
@events = (0,0,0,0,0,0,0,0,0);
# 0 = empty
# 1 = present
# (for 2: 1 = Exchange, 2 = Assistant, 3 = City Tour)
# (for 5: 0 = Party, 1 = Filoli)

while ($line = <STDIN>) {
  chomp $line;
  $line =~ s/\#.*//g;
  $line =~ s/^\s+//g;
  $line =~ s/\s+$//g;
  if ($line =~ /^NAMELINE1 (.*)/) {
    $name_line1 = $1;
  }
  if ($line =~ /^NAMELINE2 (.*)/) {
    $name_line2 = $1;
  }
  if ($line =~ /^HOSTNAME (.*)/) {
    $host_name = $1;
  }
  if ($line =~ /^RELATION (.*)/) {
    $guest_relation = $1;
  }
  if ($line =~ /^TEMPORARY/) {
    $temporary = 1;
  }
  if ($line =~ /^COUNTRY (.*)/) {
    $country = $1;
  }
  if ($line =~ /^STATE (.*)/) {
    $state = $1;
  }
  if ($line =~ /^PUZZLE (.*)/) {
    @badge_puzzle = split(' ',$1);
  }
  if ($line =~ /^EVENTS (.*)/) {
    @events = split(' ',$1);
  }
}
$is_guest = ($host_name ne "");

####################### XML header
sub xmlheader {
print <<HEADER;
<?xml version="1.0" encoding="utf-8"?>
<!-- Generator: Adobe Illustrator 13.0.2, SVG Export Plug-In . SVG Version: 6.00 Build 14948)  -->
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
<svg version="1.1" id="Layer_1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px"
   width="288.5px" height="216.5px" viewBox="0 0 288.5 216.5" enable-background="new 0 0 288.5 216.5" xml:space="preserve">
HEADER
}

####################### Outer Frame
sub outerframe {
print <<OUTFRAME;
<rect x="0.25" y="0.25" fill="none" stroke="#939598" stroke-width="0.5" width="288" height="216"/>
OUTFRAME
}

####################### IPP Logo
sub ipplogo {
open IPLOG, "<ipp-logo.svg";
print <IPLOG>;
}

####################### Name section
sub namesection {
if ($is_guest) {
  $row1_height = 92.5;
  $row2_height = 125;
} else {
  $row1_height = 101.5;
  $row2_height = 139.75;
}
print <<NAMES;
<g>
  <text style="text-anchor: middle" 
        transform="matrix(1 0 0 1 136 $row1_height)" fill="#231F20" font-family="'FranklinGothic-DemiCond'" font-size="48">
    $name_line1
  </text>
  <text style="text-anchor: middle"
        transform="matrix(1 0 0 1 136 $row2_height)" fill="#231F20" font-family="'FranklinGothic-DemiCond'" font-size="36">
    $name_line2
  </text>
</g>
NAMES

if ($is_guest) {
print <<GUEST_CONNECTION;
  <text style="text-anchor: middle"
        transform="matrix(1 0 0 1 144 146.5)" fill="#231F20" font-family="'FranklinGothic-MediumCond'" font-size="16">
    $guest_relation of <tspan fill="#231F20" font-family="'FranklinGothic-DemiCond'" font-size="16">$host_name</tspan>
  </text>
GUEST_CONNECTION
}
}

####################### Badge Puzzle
sub badgepuzzle {
$badge_svg = <<BADGEPUZ;
  <circle fill="#00AEEF" cx="242.125" cy="12.625" r="5.625"/>
  <polygon fill="#EC008C" points="257.875,7 252.25,11.5 254.5,18.25 261.25,18.25 263.5,11.5 "/>
  <polygon fill="#00A651" points="279.25,7 279.25,12.625 273.625,12.625 273.625,18.25 268,18.25 268,7 "/>
  <rect x="238.149" y="24.398" transform="matrix(0.7071 0.7071 -0.7071 0.7071 90.9815 -162.8988)" fill="#2E3192" width="7.955" height="7.955"/>
  <polygon fill="#D8C800" points="252.25,22.75 255.625,22.75 257.875,25 260.125,22.75 263.5,22.75 263.5,26.125 261.25,28.375 263.5,30.625 263.5,34 260.125,34 257.875,31.75 255.625,34 252.25,34 252.25,30.625 254.5,28.375 252.25,26.125 "/>
  <path fill="#ED1C24" d="M268,28.375c0,3.106,2.52,5.625,5.625,5.625s5.625-2.519,5.625-5.625V22.75H268V28.375z"/>
  <polygon fill="#90278F" points="247.75,49.75 244.375,49.75 242.125,45.25 239.875,49.75 236.5,49.75 242.125,38.5 "/>
  <path fill="#F7931E" d="M263.5,49.75c0-6.213-5.037-11.25-11.25-11.25C252.25,44.713,257.287,49.75,263.5,49.75z"/>
  <polygon fill="#8F5501" points="268,46.375 271.375,49.75 275.875,49.75 279.25,46.375 279.25,41.875 275.875,38.5 271.375,38.5 268,41.875 "/>
  <polygon fill="#636467" points="236.5,54.25 247.75,54.25 247.75,65.5 "/>
  <polygon fill="#8CC63F" points="256.75,54.25 252.25,57.625 252.25,63.25 259,65.5 263.5,62.125 263.5,56.5 "/>
  <rect x="268" y="54.25" fill="#00A99D" width="11.25" height="11.25"/>
BADGEPUZ
@badge_svg = split("\n", $badge_svg);

print <<BADGEPUZ;
<g>
  <g>
    <line fill="none" stroke="#000000" stroke-width="0.5" x1="265.75" y1="7" x2="265.75" y2="65.5"/>
    <line fill="none" stroke="#000000" stroke-width="0.5" x1="250" y1="7" x2="250" y2="65.5"/>
    <line fill="none" stroke="#000000" stroke-width="0.5" x1="279.25" y1="36.25" x2="236.5" y2="36.25"/>
    <line fill="none" stroke="#000000" stroke-width="0.5" x1="279.25" y1="52" x2="236.5" y2="52"/>
    <line fill="none" stroke="#000000" stroke-width="0.5" x1="279.499" y1="20.667" x2="236.5" y2="20.667"/>
  </g>
BADGEPUZ

for (0..$#badge_svg) {
  if ($badge_puzzle[$_]) {
    print $badge_svg[$_];
  }
}

print <<BADGEPUZ;
</g>
BADGEPUZ
}

####################### Country / State
sub countrystate{
  $ccountry = $country;
  $ccountry =~ tr/A-Z/a-z/;
  $ccountry =~ s/[^a-z]//g;
  $country = "USA" if ($country eq "U.S.A.";

if ($ccountry ne "") {
  open FHAND, "<flag-$ccountry.svg";
  @country_svg = <FHAND>;
  chop(@country_svg);
  chop(@country_svg);
  close FHAND;
  shift(@country_svg);
  shift(@country_svg);
  shift(@country_svg);
  shift(@country_svg);
  shift(@country_svg);
  pop(@country_svg);
  $country_svg = join("\n", @country_svg);
} else {
  $country_svg = "";
}

print <<GEOGRAPHY;
<g>
  <text style="text-anchor: middle" transform="matrix(1 0 0 1 30.85 50.875)" font-family="'FranklinGothic-DemiCond'" font-size="8">$country</text>
  <text style="text-anchor: middle" transform="matrix(1 0 0 1 30.85 59.875)" font-family="'FranklinGothic-DemiCond'" font-size="8">$state</text>
  <g transform="translate(9.25, 13.75) scale(0.2)">
    $country_svg
  </g>
  <rect x="9.25" y="13.75" fill="none" stroke-width="0.25" stroke="#000000" width="43.2" height="28.8"/>
</g>
GEOGRAPHY
}

####################### events
sub events {

if ($events[0] == 0) { # GG Park
print <<EV;
<g>
  <path fill="none" stroke="#2E3192" d="M13.75,207.25v-18c2.25,0,4.5-4.5,9-4.5s6.75,4.5,9,4.5s4.5-2.25,6.75-2.25s4.5,2.25,6.75,2.25
    s4.5-4.5,9-4.5s6.75,4.5,9,4.5v18H13.75z"/>
</g>
EV
} else {
print <<EV;
<g>
  <path fill="#2E3192" d="M13.75,207.25v-18c2.25,0,4.5-4.5,9-4.5s6.75,4.5,9,4.5s4.5-2.25,6.75-2.25s4.5,2.25,6.75,2.25
    s4.5-4.5,9-4.5s6.75,4.5,9,4.5v18H13.75z"/>
  <text transform="matrix(1 0 0 1 20.7168 200.5)" 
        fill="none" stroke="#2E3192" stroke-width="3" font-family="'FranklinGothic-MediumCond'" font-size="12">GG Park</text>
  <text transform="matrix(1 0 0 1 20.7168 200.5)" fill="#FFFFFF" font-family="'FranklinGothic-MediumCond'" font-size="12">GG Park</text>
</g>
EV
}

if ($events[1] == 0) { # Reception
print <<EV;
<g>
  <path fill="none" stroke="#2E3192" stroke-linecap="round" stroke-linejoin="round" d="M40.75,157.75H43v5.625
        c0-3.105,1.511-5.625,3.375-5.625s3.375,2.52,3.375,5.625c0-3.105,1.511-5.625,3.375-5.625s3.375,2.52,3.375,5.625v-5.625h2.25
        v5.625c0-3.105,1.511-5.625,3.375-5.625s3.375,2.52,3.375,5.625v-5.625h2.25v5.625c0-3.105,1.511-5.625,3.375-5.625
        s3.375,2.52,3.375,5.625v-5.625h2.25v5.625c0-3.105,1.511-5.625,3.375-5.625s3.375,2.52,3.375,5.625
        c0-3.105,1.511-5.625,3.375-5.625s3.375,2.52,3.375,5.625c0,1.267-0.251,2.436-0.675,3.376l-0.002-0.001h0.678V178H88v-5.625
        c0,3.105-1.511,5.625-3.375,5.625s-3.375-2.52-3.375-5.625V178H79v-5.625c0,3.105-1.511,5.625-3.375,5.625
        s-3.375-2.52-3.375-5.625c0,3.105-1.511,5.625-3.375,5.625s-3.375-2.52-3.375-5.625c0,3.105-1.511,5.625-3.375,5.625
        s-3.375-2.52-3.375-5.625c0,3.105-1.511,5.625-3.375,5.625S52,175.48,52,172.375V178h-2.25v-5.625
        c0,3.105-1.511,5.625-3.375,5.625S43,175.48,43,172.375V178h-2.25V157.75z"/>
</g>
EV
} else {
print <<EV;
<g>
  <g>
    <path fill="#2E3192" d="M49.75,163.375c0,3.105-1.511,5.625-3.375,5.625S43,166.48,43,163.375s1.511-5.625,3.375-5.625
      S49.75,160.27,49.75,163.375z"/>
    <path fill="#2E3192" d="M49.75,172.375c0,3.105-1.511,5.625-3.375,5.625S43,175.48,43,172.375s1.511-5.625,3.375-5.625
      S49.75,169.27,49.75,172.375z"/>
    <path fill="#2E3192" d="M56.5,163.375c0,3.105-1.511,5.625-3.375,5.625s-3.375-2.52-3.375-5.625s1.511-5.625,3.375-5.625
      S56.5,160.27,56.5,163.375z"/>
    <path fill="#2E3192" d="M65.5,163.375c0,3.105-1.511,5.625-3.375,5.625s-3.375-2.52-3.375-5.625s1.511-5.625,3.375-5.625
      S65.5,160.27,65.5,163.375z"/>
    <path fill="#2E3192" d="M58.75,172.375c0,3.105-1.511,5.625-3.375,5.625S52,175.48,52,172.375s1.511-5.625,3.375-5.625
      S58.75,169.27,58.75,172.375z"/>
    <path fill="#2E3192" d="M90.25,163.375c0,3.105-1.511,5.625-3.375,5.625s-3.375-2.52-3.375-5.625s1.511-5.625,3.375-5.625
      S90.25,160.27,90.25,163.375z"/>
    <path fill="#2E3192" d="M88,172.375c0,3.105-1.511,5.625-3.375,5.625s-3.375-2.52-3.375-5.625s1.511-5.625,3.375-5.625
      S88,169.27,88,172.375z"/>
    <path fill="#2E3192" d="M83.5,163.375c0,3.105-1.511,5.625-3.375,5.625s-3.375-2.52-3.375-5.625s1.511-5.625,3.375-5.625
      S83.5,160.27,83.5,163.375z"/>
    <path fill="#2E3192" d="M72.25,172.375c0,3.105-1.511,5.625-3.375,5.625s-3.375-2.52-3.375-5.625s1.511-5.625,3.375-5.625
      S72.25,169.27,72.25,172.375z"/>
    <path fill="#2E3192" d="M79,172.375c0,3.105-1.511,5.625-3.375,5.625s-3.375-2.52-3.375-5.625s1.511-5.625,3.375-5.625
      S79,169.27,79,172.375z"/>
    <path fill="#2E3192" d="M74.5,163.375c0,3.105-1.511,5.625-3.375,5.625s-3.375-2.52-3.375-5.625s1.511-5.625,3.375-5.625
      S74.5,160.27,74.5,163.375z"/>
    <path fill="#2E3192" d="M65.5,172.375c0,3.105-1.511,5.625-3.375,5.625s-3.375-2.52-3.375-5.625s1.511-5.625,3.375-5.625
      S65.5,169.27,65.5,172.375z"/>
    <rect x="40.75" y="157.75" fill="#2E3192" width="2.25" height="11.25"/>
    <rect x="40.75" y="166.75" fill="#2E3192" width="2.25" height="11.25"/>
    <rect x="56.5" y="157.75" fill="#2E3192" width="2.25" height="11.25"/>
    <rect x="49.75" y="166.75" fill="#2E3192" width="2.25" height="11.25"/>
    <rect x="65.5" y="157.75" fill="#2E3192" width="2.25" height="11.25"/>
    <rect x="74.5" y="157.75" fill="#2E3192" width="2.25" height="11.25"/>
    <rect x="79" y="166.75" fill="#2E3192" width="2.25" height="11.25"/>
    <rect x="88" y="166.75" fill="#2E3192" width="2.25" height="11.25"/>
  </g>
  
  <text transform="matrix(1 0 0 1 43.2197 171.25)" fill="none" stroke="#2E3192" stroke-width="3" 
    font-family="'FranklinGothic-MediumCond'" font-size="12">Reception</text>
  <text transform="matrix(1 0 0 1 43.2197 171.25)" fill="#FFFFFF" font-family="'FranklinGothic-MediumCond'" font-size="12">Reception</text>
</g>
EV
}

if ($events[2] == 0) { # no exchange
print <<EV;
<g>
  <path fill="none" stroke="#2E3192" stroke-linecap="round" stroke-linejoin="round" d="M68.906,201.893
          c2.882-0.793,9.454-0.527,9.972-0.222c1.868,1.111,1.961,1.5,3.344,2.47c1.384,0.971,3.803,2.92,6.255,3.284
          c2.604,0.39,5.012,0.915,7.608,1.589c1.787,0.463,5.07,1.319,6.917,0.881c3.344-0.793,1.821-1.9,1.269-2.293
          c-1.498-1.059-3.718-0.418-4.727-0.97c-0.799-0.437-6.442-1.885-3.849-1.532c2.593,0.354,4.353,0.407,6.658,0.496
          c2.306,0.088,9.468-0.033,12.538-1.158c1.361-0.498,4.277-1.27,4.323-2.609c0.044-1.258-4.539-1.201-4.539-1.201
          s4.755-0.641,4.583-1.874c-0.174-1.233-4.107-1.067-4.107-1.067s3.176-1.051,2.939-1.938c-0.375-1.411-4.684-1.08-4.684-1.08
          s3.6-0.507,3.214-1.444c-0.338-0.822-0.778-1.322-4.323-1.488l-0.563,2.053l0.087-6.063l-7.897,2.733l7.724-3.31l-9.166-3.518
          l-10.203,3.297l7.033,3.482l-7.302-2.91l-0.12,6.316c0,0-0.383-2.599-0.648-2.91c-0.476-0.563-1.658,0.904-4.193,1.785
          c-1.585,0.552-4.252-0.672-6.27-1.465c-2.017-0.797-6.686-1.304-9.165-1.437C69.137,189.656,66.024,202.686,68.906,201.893z"/>
</g>
EV
} elsif ($events[2] == 1) { # exchange
print <<EV;
<g>
  <path fill="#2E3192" stroke-linecap="round" stroke-linejoin="round" d="M68.906,201.893
          c2.882-0.793,9.454-0.527,9.972-0.222c1.868,1.111,1.961,1.5,3.344,2.47c1.384,0.971,3.803,2.92,6.255,3.284
          c2.604,0.39,5.012,0.915,7.608,1.589c1.787,0.463,5.07,1.319,6.917,0.881c3.344-0.793,1.821-1.9,1.269-2.293
          c-1.498-1.059-3.718-0.418-4.727-0.97c-0.799-0.437-6.442-1.885-3.849-1.532c2.593,0.354,4.353,0.407,6.658,0.496
          c2.306,0.088,9.468-0.033,12.538-1.158c1.361-0.498,4.277-1.27,4.323-2.609c0.044-1.258-4.539-1.201-4.539-1.201
          s4.755-0.641,4.583-1.874c-0.174-1.233-4.107-1.067-4.107-1.067s3.176-1.051,2.939-1.938c-0.375-1.411-4.684-1.08-4.684-1.08
          s3.6-0.507,3.214-1.444c-0.338-0.822-0.778-1.322-4.323-1.488l-0.563,2.053l0.087-6.063l-7.897,2.733l7.724-3.31l-9.166-3.518
          l-10.203,3.297l7.033,3.482l-7.302-2.91l-0.12,6.316c0,0-0.383-2.599-0.648-2.91c-0.476-0.563-1.658,0.904-4.193,1.785
          c-1.585,0.552-4.252-0.672-6.27-1.465c-2.017-0.797-6.686-1.304-9.165-1.437C69.137,189.656,66.024,202.686,68.906,201.893z"/>
  <text transform="matrix(1 0 0 1 71.5464 199.3759)" fill="none" 
     stroke="#2E3191" stroke-width="3" font-family="'FranklinGothic-MediumCond'" font-size="12">Exchange</text>
  <text transform="matrix(1 0 0 1 71.5464 199.3759)" fill="#FFFFFF" font-family="'FranklinGothic-MediumCond'" font-size="12">Exchange</text>
</g>
EV
} elsif ($events[2] == 2) { # assistant
print <<EV;
<g>
  <path fill="#2E3192" stroke-linecap="round" stroke-linejoin="round" d="M68.906,201.893
          c2.882-0.793,9.454-0.527,9.972-0.222c1.868,1.111,1.961,1.5,3.344,2.47c1.384,0.971,3.803,2.92,6.255,3.284
          c2.604,0.39,5.012,0.915,7.608,1.589c1.787,0.463,5.07,1.319,6.917,0.881c3.344-0.793,1.821-1.9,1.269-2.293
          c-1.498-1.059-3.718-0.418-4.727-0.97c-0.799-0.437-6.442-1.885-3.849-1.532c2.593,0.354,4.353,0.407,6.658,0.496
          c2.306,0.088,9.468-0.033,12.538-1.158c1.361-0.498,4.277-1.27,4.323-2.609c0.044-1.258-4.539-1.201-4.539-1.201
          s4.755-0.641,4.583-1.874c-0.174-1.233-4.107-1.067-4.107-1.067s3.176-1.051,2.939-1.938c-0.375-1.411-4.684-1.08-4.684-1.08
          s3.6-0.507,3.214-1.444c-0.338-0.822-0.778-1.322-4.323-1.488l-0.563,2.053l0.087-6.063l-7.897,2.733l7.724-3.31l-9.166-3.518
          l-10.203,3.297l7.033,3.482l-7.302-2.91l-0.12,6.316c0,0-0.383-2.599-0.648-2.91c-0.476-0.563-1.658,0.904-4.193,1.785
          c-1.585,0.552-4.252-0.672-6.27-1.465c-2.017-0.797-6.686-1.304-9.165-1.437C69.137,189.656,66.024,202.686,68.906,201.893z"/>
  <text transform="matrix(1 0 0 1 72.3579 199.3759)" fill="none" 
     stroke="#2E3191" stroke-width="3" font-family="'FranklinGothic-MediumCond'" font-size="12">Assistant</text>
  <text transform="matrix(1 0 0 1 72.3579 199.3759)" fill="#FFFFFF" font-family="'FranklinGothic-MediumCond'" font-size="12">Assistant</text>
</g>
EV
} elsif ($events[2] == 3) { # city tour
print <<EV;
<g>
  <g>
    <polygon fill="#2E3192" points="67.75,189.25 74.5,187 74.5,184.75 112.75,184.75 112.75,187 119.5,189.25 117.25,189.25 
            117.25,202.75 70,202.75 70,189.25               "/>
    <circle fill="#2E3192" cx="79" cy="202.75" r="4.5"/>
    <circle fill="#2E3192" cx="108.25" cy="202.75" r="4.5"/>
  </g>
  <text transform="matrix(1 0 0 1 73.6944 198.25)" fill="#FFFFFF" font-family="'FranklinGothic-MediumCond'" font-size="12">City Tour</text>
</g>
EV
}

if ($events[3] == 0) { # workshop
print <<EV;
<g>
  <polygon fill="none" stroke="#2E3192" points="101.5,157.75 101.5,164.5 94.75,169 101.5,173.5 101.5,180.25 108.25,175.75 115,180.25 
    119.5,173.5 124,180.25 130.75,175.75 137.5,180.25 137.5,173.5 144.25,169 137.5,164.5 137.5,157.75 130.75,162.25 124,157.75 
    119.5,164.5 115,157.75 108.25,162.25   "/>
</g>
EV
} else {
print <<EV;
<g>
  <polygon fill="#2E3192" points="101.5,157.75 101.5,164.5 94.75,169 101.5,173.5 101.5,180.25 108.25,175.75 115,180.25 
    119.5,173.5 124,180.25 130.75,175.75 137.5,180.25 137.5,173.5 144.25,169 137.5,164.5 137.5,157.75 130.75,162.25 124,157.75 
    119.5,164.5 115,157.75 108.25,162.25   "/>
  <text transform="matrix(1 0 0 1 97.627 173.5)" 
    fill="none" stroke="#2E3192" stroke-width="3" font-family="'FranklinGothic-MediumCond'" font-size="12">Workshop</text>
  <text transform="matrix(1 0 0 1 97.627 173.5)" fill="#FFFFFF" font-family="'FranklinGothic-MediumCond'" font-size="12">Workshop</text>
</g>
EV
}

if ($events[4] == 0) { # banquet
print <<EV;
<g>
  <g>
    <g>
      <path fill="none" stroke="#2E3192" d="M145.826,192.402c-0.585-4.59-0.799-6.527-2.366-6.527c-0.101,0-0.134,3.199-0.137,7.064
        c-1.336-4.102-5.184-7.064-9.73-7.064c-3.699,0-6.929,1.968-8.729,4.907c0.002-1.132-0.146-2.599-0.564-4.517
        c-0.507-2.328-0.34,6.498-0.886,6.498c-0.511,0-0.229-6.81-0.626-6.81c-0.398,0-0.185,6.81-0.621,6.81
        c-0.423,0-0.126-8.896-0.864-6.422c-1.902,6.389,0.802,8.242,0.802,8.242v11.766l1.501-0.023v-7.982
        c1.019,4.58,5.1,8.006,9.987,8.006c4.561,0,8.42-2.979,9.744-7.103c0.018,3.884,0.046,7.103,0.046,7.103l1.477-0.021v-8.638
        C144.857,197.691,146.387,196.785,145.826,192.402z"/>
    </g>
  </g>
  <g>
    <g>
      <path fill="none" stroke="#2E3192" d="M171.42,192.402c-0.585-4.59-0.798-6.527-2.365-6.527c-0.102,0-0.135,3.199-0.138,7.064
        c-1.337-4.102-5.185-7.064-9.729-7.064c-3.696,0-6.93,1.968-8.729,4.906c0.003-1.133-0.146-2.598-0.563-4.516
        c-0.506-2.328-0.34,6.498-0.889,6.498c-0.511,0-0.229-6.81-0.627-6.81c-0.396,0-0.186,6.81-0.617,6.81
        c-0.426,0-0.13-8.896-0.865-6.422c-1.901,6.389,0.804,8.242,0.804,8.242v11.766l1.5-0.023v-7.982
        c1.019,4.58,5.1,8.006,9.987,8.006c4.561,0,8.42-2.979,9.744-7.103c0.019,3.884,0.045,7.103,0.045,7.103l1.477-0.021v-8.638
        C170.452,197.691,171.979,196.785,171.42,192.402z"/>
    </g>
  </g>
</g>
EV
} else {
print <<EV;
<g>
  <g>
    <g>
      <path fill="#2E3192" d="M145.826,192.402c-0.585-4.59-0.799-6.527-2.366-6.527c-0.101,0-0.134,3.199-0.137,7.064
        c-1.336-4.102-5.184-7.064-9.73-7.064c-3.699,0-6.929,1.968-8.729,4.907c0.002-1.132-0.146-2.599-0.564-4.517
        c-0.507-2.328-0.34,6.498-0.886,6.498c-0.511,0-0.229-6.81-0.626-6.81c-0.398,0-0.185,6.81-0.621,6.81
        c-0.423,0-0.126-8.896-0.864-6.422c-1.902,6.389,0.802,8.242,0.802,8.242v11.766l1.501-0.023v-7.982
        c1.019,4.58,5.1,8.006,9.987,8.006c4.561,0,8.42-2.979,9.744-7.103c0.018,3.884,0.046,7.103,0.046,7.103l1.477-0.021v-8.638
        C144.857,197.691,146.387,196.785,145.826,192.402z"/>
    </g>
  </g>
  <g>
    <g>
      <path fill="#2E3192" d="M171.42,192.402c-0.585-4.59-0.798-6.527-2.365-6.527c-0.102,0-0.135,3.199-0.138,7.064
        c-1.337-4.102-5.185-7.064-9.729-7.064c-3.696,0-6.93,1.968-8.729,4.906c0.003-1.133-0.146-2.598-0.563-4.516
        c-0.506-2.328-0.34,6.498-0.889,6.498c-0.511,0-0.229-6.81-0.627-6.81c-0.396,0-0.186,6.81-0.617,6.81
        c-0.426,0-0.13-8.896-0.865-6.422c-1.901,6.389,0.804,8.242,0.804,8.242v11.766l1.5-0.023v-7.982
        c1.019,4.58,5.1,8.006,9.987,8.006c4.561,0,8.42-2.979,9.744-7.103c0.019,3.884,0.045,7.103,0.045,7.103l1.477-0.021v-8.638
        C170.452,197.691,171.979,196.785,171.42,192.402z"/>
    </g>
  </g>
  
    <text transform="matrix(1 0 0 1 127.7939 200.5)" fill="none" stroke="#2E3192" stroke-width="3" font-family="'FranklinGothic-MediumCond'" font-size="12">Banquet</text>
  <text transform="matrix(1 0 0 1 127.7939 200.5)" fill="#FFFFFF" font-family="'FranklinGothic-MediumCond'" font-size="12">Banquet</text>
</g>
EV
}

if ($events[5] == 1) { # Filoli, not party
print <<EV;
<g>
  <polygon fill="#2E3191" points="173.5,162.25 166.75,162.25 166.75,157.75 164.5,157.75 164.5,162.25 162.25,162.25 160,164.5 
    155.5,162.25 155.5,160 153.25,160 153.25,162.25 148.75,164.5 148.75,180.25 198.25,180.25 198.25,164.5 193.75,162.25 
    193.75,160 191.5,160 191.5,162.25 187,164.5 184.75,162.25 182.5,162.25 182.5,157.75 180.25,157.75 180.25,162.25   "/>
  <text transform="matrix(1 0 0 1 162.8652 175.75)" fill="#FFFFFF" font-family="'FranklinGothic-MediumCond'" font-size="12">Filoli</text>
</g>
EV
} else { # party
print <<EV;
<g>
  <path fill="#2E3191" d="M196,160l2.25-2.25l-7.207,2.703c-1.32-1.646-3.345-2.703-5.618-2.703h-23.85
     c-2.274,0-4.298,1.057-5.618,2.703l-7.207-2.703L151,160l-2.25,2.25l2.25,2.25l-2.25,2.25L151,169l-2.25,2.25l2.25,2.25
     l-2.25,2.25L151,178l-2.25,2.25l7.207-2.703c1.32,1.646,3.344,2.703,5.618,2.703h23.85c2.273,0,4.298-1.057,5.618-2.703
     l7.207,2.703L196,178l2.25-2.25L196,173.5l2.25-2.25L196,169l2.25-2.25L196,164.5l2.25-2.25L196,160z"/>
  <text transform="matrix(1 0 0 1 162.3584 173.5)" fill="#FFFFFF" font-family="'FranklinGothic-MediumCond'" font-size="12">Party</text>
</g>
EV
}

if ($events[6] == 0) { # Sonoma
print <<EV;
<g>
  <path fill="none" stroke="#2E3192" d="M221.82,191.5v-6.75h-2.303v6.75c0,0-1.222,1.211-1.885,3.605c-0.66-2.396-1.883-3.605-1.883-3.605v-6.75
     h-2.303v6.75c0,0-1.031,1.041-1.717,3.074c-0.682-2.033-1.713-3.074-1.713-3.074v-6.75h-2.304v6.75c0,0-1.22,1.211-1.883,3.605
     c-0.663-2.396-1.883-3.605-1.883-3.605v-6.75h-2.304v6.75c0,0-1.03,1.041-1.713,3.074c-0.686-2.033-1.716-3.074-1.716-3.074
     v-6.75h-2.304v6.75c0,0-1.221,1.211-1.883,3.605c-0.663-2.396-1.885-3.605-1.885-3.605v-6.75h-2.303v6.75
     c0,0-1.031,1.041-1.715,3.074c-0.684-2.033-1.714-3.074-1.714-3.074v-6.75h-2.304v6.75c0,0-1.219,1.211-1.883,3.605
     c-0.662-2.396-1.883-3.605-1.883-3.605v-6.75h-2.305v6.75c0,0-2.305,2.25-2.305,6.75s0,9,0,9h6.066h0.844h4.89h1.182h4.89h0.842
     h4.889h1.18h4.892h0.842h4.892h1.18h4.889h0.842h6.068c0,0,0-4.5,0-9S221.82,191.5,221.82,191.5z"/>
</g>
EV
} else {
print <<EV;
<g>
  <path fill="#2E3192" d="M221.82,191.5v-6.75h-2.303v6.75c0,0-1.222,1.211-1.885,3.605c-0.66-2.396-1.883-3.605-1.883-3.605v-6.75
     h-2.303v6.75c0,0-1.031,1.041-1.717,3.074c-0.682-2.033-1.713-3.074-1.713-3.074v-6.75h-2.304v6.75c0,0-1.22,1.211-1.883,3.605
     c-0.663-2.396-1.883-3.605-1.883-3.605v-6.75h-2.304v6.75c0,0-1.03,1.041-1.713,3.074c-0.686-2.033-1.716-3.074-1.716-3.074
     v-6.75h-2.304v6.75c0,0-1.221,1.211-1.883,3.605c-0.663-2.396-1.885-3.605-1.885-3.605v-6.75h-2.303v6.75
     c0,0-1.031,1.041-1.715,3.074c-0.684-2.033-1.714-3.074-1.714-3.074v-6.75h-2.304v6.75c0,0-1.219,1.211-1.883,3.605
     c-0.662-2.396-1.883-3.605-1.883-3.605v-6.75h-2.305v6.75c0,0-2.305,2.25-2.305,6.75s0,9,0,9h6.066h0.844h4.89h1.182h4.89h0.842
     h4.889h1.18h4.892h0.842h4.892h1.18h4.889h0.842h6.068c0,0,0-4.5,0-9S221.82,191.5,221.82,191.5z"/>
  <text transform="matrix(1 0 0 1 182.2041 200.5)" 
    fill="none" stroke="#2E3192" stroke-width="3" font-family="'FranklinGothic-MediumCond'" font-size="12">Sonoma</text>
  <text transform="matrix(1 0 0 1 182.2041 200.5)" fill="#FFFFFF" font-family="'FranklinGothic-MediumCond'" font-size="12">Sonoma</text>
</g>
EV
}

if ($events[7] == 0) { # Awards
print <<EV;
<g>
  <polygon fill="none" stroke="#2E3192" points="235.375,169 252.25,164.95 247.75,162.25 251.125,157.75 223.825,163.541 223.887,163.262 
    220.74,162.26 219.736,159.118 216.514,159.82 214.075,157.6 211.637,159.82 208.412,159.118 207.41,162.26 204.264,163.262 
    204.973,166.486 202.75,168.925 204.973,171.363 204.264,174.588 207.41,175.59 208.412,178.73 211.637,178.027 214.075,180.25 
    216.514,178.027 219.736,178.73 220.74,175.59 223.887,174.588 223.875,174.535 250,180.25 247.75,175.75 252.25,173.05       "/>
</g>
EV
} else {
print <<EV;
<g>
  <polygon fill="#2E3192" points="235.375,169 252.25,164.95 247.75,162.25 251.125,157.75 223.825,163.541 223.887,163.262 
    220.74,162.26 219.736,159.118 216.514,159.82 214.075,157.6 211.637,159.82 208.412,159.118 207.41,162.26 204.264,163.262 
    204.973,166.486 202.75,168.925 204.973,171.363 204.264,174.588 207.41,175.59 208.412,178.73 211.637,178.027 214.075,180.25 
    216.514,178.027 219.736,178.73 220.74,175.59 223.887,174.588 223.875,174.535 250,180.25 247.75,175.75 252.25,173.05       "/>
  <text transform="matrix(1 0 0 1 211.5537 173.5)" 
     fill="none" stroke="#2E3192" stroke-width="3" font-family="'FranklinGothic-MediumCond'" font-size="12">Awards</text>
  <text transform="matrix(1 0 0 1 211.5537 173.5)" fill="#FFFFFF" font-family="'FranklinGothic-MediumCond'" font-size="12">Awards</text>
</g>
EV
}

if ($events[8] == 0) { # South bay
print <<EV;
<g>
  <circle fill="none" stroke="#2E3192" cx="274.746" cy="205.504" r="2.875"/>
  <circle fill="none" stroke="#2E3192" cx="267.855" cy="205.504" r="2.903"/>
  <path fill="none" stroke="#2E3192" d="M275.752,197.921v-9.854h-2.835l-0.021-1.748l0.804-0.875l-0.005-0.663h-2.813h-2.852
          l-0.007,0.597l0.779,0.848l0.045,1.842h-12.496l-0.021-1.377c0.018-0.719-0.67-1.934-1.387-1.898l-1.442-0.007l-1.386-0.021
          c-0.727-0.003-1.459,0.903-1.445,1.877l-0.021,1.432h-9.146l-0.004-3.297l-9.614-0.021l-0.005,3.314h2.372
          c0.494,0.011,0.938,0.572,0.93,1.061l-0.023,4.313c-0.01,0.508-0.418,0.99-0.906,0.969l-4.502-0.003v7.651h1.983
          c-0.204,0.527-0.327,1.096-0.327,1.695c0,2.598,2.105,4.703,4.703,4.703s4.703-2.105,4.703-4.703c0-0.6-0.123-1.168-0.327-1.695
          h2.697c-0.204,0.527-0.327,1.096-0.327,1.695c0,2.598,2.105,4.703,4.703,4.703s4.703-2.105,4.703-4.703
          c0-0.6-0.123-1.168-0.327-1.695h2.695c-0.204,0.527-0.327,1.096-0.327,1.695c0,2.598,2.105,4.703,4.703,4.703
          s4.703-2.105,4.703-4.703c0-0.6-0.123-1.168-0.327-1.695h14.597v-4.142L275.752,197.921z"/>
</g>
EV
} else {
print <<EV;
<g>
  <circle fill="#2E3192" cx="247.559" cy="203.754" r="4.703"/>
  <circle fill="#2E3192" cx="236.109" cy="203.754" r="4.703"/>
  <circle fill="#2E3192" cx="274.746" cy="205.504" r="2.875"/>
  <circle fill="#2E3192" cx="267.855" cy="205.504" r="2.903"/>
  <circle fill="#2E3192" cx="259.006" cy="203.754" r="4.703"/>
  <path id="path650" fill="#2E3192" d="M234.252,194.41l-4.502-0.003v7.651h48.229v-4.141l-2.227,0.004v-9.855h-2.835l-0.021-1.748
    l0.804-0.875l-0.005-0.663h-2.813h-2.852l-0.007,0.597l0.779,0.848l0.045,1.842h-12.496l-0.021-1.377
    c0.018-0.719-0.67-1.934-1.387-1.899l-1.442-0.007l-1.386-0.021c-0.727-0.002-1.459,0.904-1.445,1.877l-0.021,1.432h-9.146
    l-0.004-3.297l-9.614-0.021l-0.005,3.314h2.372c0.494,0.011,0.938,0.572,0.93,1.061l-0.024,4.313
    C235.148,193.949,234.74,194.432,234.252,194.41z"/>
  <text transform="matrix(1 0 0 1 232.0566 198.25)" 
     fill="none" stroke="#2E3192" stroke-width="3" font-family="'FranklinGothic-MediumCond'" font-size="12">South Bay</text>
  <text transform="matrix(1 0 0 1 232.0566 198.25)" fill="#FFFFFF" font-family="'FranklinGothic-MediumCond'" font-size="12">South Bay</text>
</g>
EV
}

}

####################### remaining stuff
sub temporary {
if ($temporary) {
print <<EOFF;
 <text transform="translate(0, 100) matrix(0.9606 -0.278 0.278 0.9606 111.1167 70.8833)">
   <tspan x="0" y="0" fill="#FF0000" stroke="#000000" stroke-width="0.7177" font-family="'FranklinGothic-DemiCond'" font-size="25.8356">Temporary Badge</tspan>
   <tspan x="8.708" y="26.554" fill="#FF0000" stroke="#000000" stroke-width="0.7177" font-family="'FranklinGothic-DemiCond'" font-size="34.4475">Photograph</tspan>
   <tspan x="34.83" y="53.106" fill="#FF0000" stroke="#000000" stroke-width="0.7177" font-family="'FranklinGothic-DemiCond'" font-size="34.4475">Needed</tspan>
 </text>
EOFF
}
}

xmlheader();
outerframe();
ipplogo();
namesection();
badgepuzzle();
countrystate();
events();
temporary();
print "</svg>\n";
