#!/usr/bin/perl

$bio_file = "misnorcal.txt";

open(FILE, "< $bio_file");
@lines = <FILE>;
close(FILE);

foreach $line (@lines) {
   chomp $line;
   if (($line eq "")) { next; }

   $line =~ s/'/&#39;/g;
   ($key, $lname, $fname, $dob, $birthplace, $entered_army, $discharged_army, $c1, $c2, $c3, $c4, $c5, $c6, $c7, $c8, $notes1, $notes2, $honor1, $honor2, $honor3, $oral_history, $auto, $ques, $bio, $photo, $article, $narrative) = split(/\t/, $line);

   $res = &get_njahs_resources($oral_history, $auto, $ques, $bio, $photo, $article);

   print "UPDATE veterans SET resources = '$res' WHERE veteran_id = $key;\\g\n";
}

sub get_njahs_resources {
   my ($or, $au, $qu, $bi, $ph, $ar) = @_;
   my $res = '';

   if ($or eq '1') { $res = "Oral History, "; }
   if ($au eq '1') { $res .= "Autobiography, "; }
   if ($qu eq '1') { $res .= "Questionnaire, "; } 
   if ($bi eq '1') { $res .= "Biography, "; }
   if ($ph eq '1') { $res .= "Photos, "; }
   if ($ar eq '1') { $res .= "Articles, "; }

   $res =~ s/, $//;
   return $res;
}


