#!/opt/perl/bin/perl

# Define constants
local(%FORM);
$CRLF="\r\n";
$DATE= &getlocaldate;

# Tell the browser what's comming
print "Content-type: text/html$CRLF$CRLF";
print "<HTML>\n";
print "<HEAD>\n";
print "<TITLE> 2003 Collegiate Aviation Survey </TITLE>\n";
print "</HEAD>\n";
print "<BODY bgcolor=\"#FFFFFF\" text=\"#000000\" link=\"#0000FF\" vlink=\"#000080\" alink=\"#FF0000\">\n";
print "<H1 align=\"CENTER\"> 2003 Collegiate Aviation Survey </H1>\n";

# Get the input from the browser
read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'});

# Split the name-value pairs
@pairs = split(/&/, $buffer);
foreach $pair (@pairs)
{
  ($name, $value) = split(/=/, $pair);
  $value =~  tr/+/ /;
  $value =~  s/%([a-fA-F0-9][a-fA-F0-91])/pack("C", hex($1))/eg;

  # Stop people from using subshells to execute commands
  $value =~ s/~!/ ~!/g;

  # Uncomment for debugging purposes
  # print "Setting $name to $value<BR>\n",

  $FORM{$name} = $value;
}

# Check for valid input data
exit if ! $FORM{'filelist'};

$DBASEFILEDIR=$FORM{'datadir'};

$FILELIST=$DBASEFILEDIR.$FORM{'filelist'};
if ( -e $FILELIST) {
   if ( -z $FILELIST) {
      print "The control file $FILELIST is an empty file!";
      exit;
   }
   if ( -T $FILELIST) {
   } else {
      print "The control file $FILELIST is not a text file!";
      exit;
   }
} else {
  print "The control file $FILELIST does not exist!";
  exit;
}

# Get default values from the database file

open(FILELIST, "$FILELIST") || die "Can't open control file: $!";
while (<FILELIST>) {
   chomp($FILENAME = $_);

   # See if Survey File Exists in Data Directory
   $DBASEFILE=$DBASEFILEDIR.$FILENAME;
   if ( -e $DBASEFILE) {
      if ( -z $DBASEFILE) {
         print "The file $DBASEFILE is an empty file!";
         next FILELIST;
      }
      if ( -T $DBASEFILE) {
      } else {
         print "The file $DBASEFILE is not a text file!";
         next FILELIST;
      }
   } else {
     print "The file $DBASEFILE does not exist!";
     exit;
     next FILELIST;
   }

# Get values from the database file
open(FILE, "$DBASEFILE") || next FILELIST;
while (<FILE>) {
   # split lines at a colon not preceded by a backslash
   if ($_ =~ /[^\\]:/) {
      ($name, $value) = split(/:/, $_, 2);
      # remove backslash from escaped colons
      $value =~ s/\\:/:/g;
      # remove backslash from escaped backslashes
      $value =~ s/\\\\/\\/g;
      chomp($DBASE{$name} = $value);
   } else {
      # remove backslash from escaped colons
      $_ =~ s/\\:/:/g;
      # remove backslash from escaped backslashes
      $_ =~ s/\\\\/\\/g;
      chomp($DBASE{$name} .= $_);
   } 
}
close (FILE);

$OUTFILE=$DBASEFILEDIR.$DBASE{'key'}.".prn";
open(FILE, ">$OUTFILE") || print "Can't open output file $OUTFILE: $! <BR>\n";
print FILE "$DBASE{'key'}\n";
if (substr($DBASE{'address1'},1,1) ne "") {
   print FILE "$DBASE{'address1'}\n";
}
if (substr($DBASE{'address2'},1,1) ne "") {
   print FILE "$DBASE{'address2'}\n";
}
print FILE "$DBASE{'city'}, $DBASE{'state'} $DBASE{'zipcode'}\n";
print FILE "Telephone: $DBASE{'phone'}\n";
print FILE "Fax: $DBASE{'fax'}\n";
print FILE "Web Site: $DBASE{'poc_url'}\n";
print FILE "\n";
print FILE "Point of Contact: ";
if ($DBASE{'salutation'} =~ /Dr./) {
   print FILE "Dr. ";
} else {
   if ($DBASE{'salutation'} =~ /Mr./) {
      print FILE "Mr. ";
   } else {
      if ($DBASE{'salutation'} =~ /Mrs./) {
         print FILE "Mrs. ";
      } else {
         if ($DBASE{'salutation'} =~ /Ms./) {
            print FILE "Ms. ";
         } else {
            if ($DBASE{'salutation'} =~ /Miss/) {
               print FILE "Miss ";
            } else {
               print FILE "$DBASE{'salute_other'} ";
            }
         }
      }
   }
}
print FILE "$DBASE{'poc_name'}, $DBASE{'poc_dept'}, $DBASE{'poc_street'}, $DBASE{'poc_city'}, $DBASE{'poc_state'} $DBASE{'poc_zipcode'}\n";
print FILE "Telephone: $DBASE{'poc_phone'}\n";
print FILE "Fax: $DBASE{'poc_fax'}\n";
print FILE "E-mail: $DBASE{'poc_email'}\n";
print FILE "\n";
print FILE "Institutional Information\n";
print FILE "Type of School: ";
if ($DBASE{'type'} =~ /pub/) {
   print FILE "Public\n";
} else {
   print FILE "Proprietary\n";
}
print FILE "Accreditation: ";
if ($DBASE{'accred'} =~ /accredited/) {
   print FILE "$DBASE{'accred_agency'}\n";
} else {
   if ($DBASE{'accred'} =~ /candidate/) {
      print FILE "Candidate for accreditation\n";
   } else {
      print FILE "Not Accredited\n";
   }
}
print FILE "Highest Degree Offered: $DBASE{'degree'}\n";
print FILE "Student Body: ";
if ($DBASE{'student_body'} =~ /coed/) {
   print FILE "Co-educational\n";
} else {
   if ($DBASE{'student_body'} =~ /male/) {
      print FILE "Male Only\n";
   } else {
      print FILE "Female Only\n";
   }
}
print FILE "Full Time Enrollment: $DBASE{'enroll_under'} undergraduate, $DBASE{'enroll_grad'} graduate\n";
print FILE "Freshman Admission Requirements: ";
if ($DBASE{'admission'} =~ /SAT/) {
   print FILE "SAT ";
}
if ($DBASE{'admission'} =~ /ACT/) {
   print FILE "ACT ";
}
if ($DBASE{'admission'} =~ /GPA/) {
   print FILE "GPA ";
}
print FILE "( $DBASE{'adm_other'} )";
print FILE "\n";
print FILE "Calendar System: ";
if ($DBASE{'calendar'} =~ /semester/) {
   print FILE "Semesters";
} else {
   if ($DBASE{'calendar'} =~ /quarter/) {
      print FILE "Quarters";
   } else {
      if ($DBASE{'calendar'} =~ /trimester/) {
         print FILE "Trimesters";
      } else {
         print FILE "Other";
      }
   }
}
print FILE "\n";
print FILE "Tuition and Fees: Resident \$$DBASE{'fees_resident'}, Non-resident \$$DBASE{'fees_nonres'}\n";
print FILE "\n";
print FILE "Aviation Program\n";
print FILE "Online Aviation Programs:\n";
if ($DBASE{'o_avn_prog1'} ne "") {
   print FILE "yes\n";
} else {
   print FILE "no\n";
}
print FILE "Other Non-traditional Degree Offerings: ";
if ($DBASE{'non_trad_sat'} =~ /yes/) {
   print FILE "Degrees or courses offered at satellite locations. ";
}
if ($DBASE{'non_trad_dist'} =~ /yes/) {
   print FILE "Courses through distance learning. ";
}
if ($DBASE{'non_trad_corr'} =~ /yes/) {
   print FILE "Correspondence courses. ";
}
if ($DBASE{'non_trad_cert'} =~ /yes/) {
   print FILE "Credit is given for FAA certificates and ratings held at the time of admission.";
}
print FILE "\n";
print FILE "FAA Certificate Offerings: ";
if ($DBASE{'flight_cert'} =~ /Recreational/) {
   print FILE "Recreational, ";
}
if ($DBASE{'flight_cert'} =~ /Private/) {
   print FILE "Private, ";
}
if ($DBASE{'flight_cert'} =~ /Commercial/) {
   print FILE "Commercial, ";
}
if ($DBASE{'flight_cert'} =~ /Instrument/) {
   print FILE "Instrument, ";
}
if ($DBASE{'flight_cert'} =~ /Multi-engine/) {
   print FILE "Multi-engine, ";
}
if ($DBASE{'flight_cert'} =~ /CFI_airplane/) {
   print FILE "CFI(airplane), ";
}
if ($DBASE{'flight_cert'} =~ /CFI_instrument/) {
   print FILE "CFI(instrument), ";
}
if ($DBASE{'flight_cert'} =~ /ATP/) {
   print FILE "ATP, ";
}
if ($DBASE{'flight_cert'} =~ /Glider/) {
   print FILE "Glider, ";
}
if ($DBASE{'flight_cert'} =~ /Rotorcraft/) {
   print FILE "Rotorcraft, ";
}
if ($DBASE{'flight_cert'} =~ /Flight Engineer/) {
   print FILE "Flight Engineer, ";
}
if ($DBASE{'nonflight_cert'} =~ /Airframe/) {
   print FILE "Airframe, ";
}
if ($DBASE{'nonflight_cert'} =~ /Powerplant/) {
   print FILE "Powerplant, ";
}
if ($DBASE{'nonflight_cert'} =~ /AP/) {
   print FILE "Airframe & Powerplant, ";
}
if ($DBASE{'nonflight_cert'} =~ /Avionics/) {
   print FILE "Avionics ";
}
print FILE "\n";
print FILE "Instruction offered under FAA part: ";
if ($DBASE{'flight_instr'} =~ /141/) {
   print FILE "141, ";
}
if ($DBASE{'flight_instr'} =~ /147/) {
   print FILE "147, ";
}
if ($DBASE{'flight_instr'} =~ /61/) {
   print FILE "61. ";
}
if ($DBASE{'flight_instr'} =~ /Examining Authority/) {
   print FILE "Examining Authority";
}
print FILE "\n";
print FILE "Instruction Conducted By: ";
if ($DBASE{'instr_cond_by'} =~ /Institution/) {
   print FILE "Institution. ";
}
if ($DBASE{'instr_cond_by'} =~ /Contractor/) {
   print FILE "Contractor. ";
}
print FILE "$DBASE{'instr_describe'}";
print FILE "\n";
print FILE "Cost of Lab Fees: ";
if ($DBASE{'flight_cost_priv'} != 0) {
   print FILE "Private \$$DBASE{'flight_cost_priv'}; ";
}
if ($DBASE{'flight_cost_comm'} != 0) {
   print FILE "Comm and Instr \$$DBASE{'flight_cost_comm'}; ";
}
if ($DBASE{'flight_cost_CFI'} != 0) {
   print FILE "CFI-Airplane \$$DBASE{'flight_cost_CFI'}; ";
}
if ($DBASE{'flight_cost_multi'} != 0) {
   print FILE "Multi-engine \$$DBASE{'flight_cost_multi'}; ";
}
if ($DBASE{'flight_cost_other'} != 0) {
   print FILE "Other flight costs \$$DBASE{'flight_cost_other'}; ";
}
if ($DBASE{'flight_cost_total'} != 0) {
   print FILE "Total cost of cert & ratings in flight major \$$DBASE{'flight_cost_total'}. ";
}
if ($DBASE{'non_flight_cost_airframe'} != 0) {
   print FILE "Airframe \$$DBASE{'non_flight_cost_airframe'}; ";
}
if ($DBASE{'non_flight_cost_powerplant'} != 0) {
   print FILE "Powerplant \$$DBASE{'non_flight_cost_powerplant'}; ";
}
if ($DBASE{'non_flight_cost_a_and_p'} != 0) {
   print FILE "Airframe & Powerplant \$$DBASE{'non_flight_cost_a_and_p'}; ";
}
if ($DBASE{'non_flight_cost_avionics'} != 0) {
   print FILE "Avionics \$$DBASE{'non_flight_cost_avionics'}; ";
}
if ($DBASE{'non_flight_cost_other'} != 0) {
   print FILE "Other non-flight costs \$$DBASE{'non_flight_cost_other'}";
}
print FILE "\n";
print FILE "Flight Hours at Graduation: ";
print FILE "$DBASE{'flight_hrs_min'} min  $DBASE{'flight_hrs_avg'} avg  $DBASE{'flight_hrs_max'} max";
print FILE "\n";
print FILE "Opportunities: ";
if ($DBASE{'opportunities'} =~ /Co-op Education/) {
   print FILE "Co-op Education, ";
}
if ($DBASE{'opportunities'} =~ /Internship while enrolled/) {
   print FILE "Internship while enrolled, ";
}
if ($DBASE{'opportunities'} =~ /Internship post graduate/) {
   print FILE "Internship post graduate, ";
}
print FILE "$DBASE{'other_opps'}";
print FILE "\n";
print FILE "Scholarships: ";
if ($DBASE{'scholarships_val'} != 0) {
  print FILE "$DBASE{'scholarships_num'} for a total value of \$$DBASE{'scholarships_val'}";
}
print FILE "\n";
print FILE "Year Aviation Program Established: $DBASE{'year_established'}\n";
print FILE "Administration: ";
if ($DBASE{'advisory_committee'} =~ /yes/) {
   print FILE "Aviation Advisory Committee, ";
}
if ($DBASE{'placement_service'} =~ /yes/) {
   print FILE "Aviation Graduate Placement Service ";
}
print FILE "\n";
print FILE "Aviation Program Located: $DBASE{'program_location'}\n";
print FILE "Aviation Affiliations: ";
if ($DBASE{'affiliations'} =~ /UAA Institutional Member/) {
   print FILE "UAA, ";
}
if ($DBASE{'affiliations'} =~ /CAA Member/) {
   print FILE "CAA, ";
}
if ($DBASE{'affiliations'} =~ /NIFA Member/) {
   print FILE "NIFA, ";
}
if ($DBASE{'affiliations'} =~ /Alpha Eta Rho Chapter/) {
   print FILE "Alpha Eta Rho Chapter, ";
}
print FILE "$DBASE{'affil_other'}";
print FILE "\n";
print FILE "Articulation Agreements: ";
print FILE "$DBASE{'art_agreements'}";
print FILE "\n";
print FILE "Other: ";
print FILE "$DBASE{'other_info'}";
print FILE "\n";
print FILE "\n";

print FILE "Aviation Degree Programs:\n";
print FILE "\n";
print FILE "                            Type of Degree      Credit\n";
print FILE "                           -----------------    Hours\n";
print FILE "Program                    A   B   M   D   O    Required  Enrolled   Remarks\n";
print FILE "\n";
$f1=$DBASE{'avn_prog1_A'};
$f2=$DBASE{'avn_prog1_B'};
$f3=$DBASE{'avn_prog1_M'};
$f4=$DBASE{'avn_prog1_D'};
$f5=$DBASE{'avn_prog1_O'};
$f6=$DBASE{'avn_prog1_hrs'};
$f7=$DBASE{'avn_prog1_enroll'};
$f8=$DBASE{'avn_prog1_remarks'};
$f1=" " if $f1 eq "";
$f2=" " if $f2 eq "";
$f3=" " if $f3 eq "";
$f4=" " if $f4 eq "";
$f5=" " if $f5 eq "";
$f6=substr("     ".$f6,-5,5);
$f7=substr("     ".$f7,-5,5);
if ($f1+$f2+$f3+$f4+$f5+$f6+$f7 != 0) {
   print FILE "Aviation Maintenance/\n";
   print FILE "Acft. Maint. Mgmt.         $f1   $f2   $f3   $f4   $f5       $f6     $f7   $f8\n";
   print FILE "\n";
}
$f1=$DBASE{'avn_prog2_A'};
$f2=$DBASE{'avn_prog2_B'};
$f3=$DBASE{'avn_prog2_M'};
$f4=$DBASE{'avn_prog2_D'};
$f5=$DBASE{'avn_prog2_O'};
$f6=$DBASE{'avn_prog2_hrs'};
$f7=$DBASE{'avn_prog2_enroll'};
$f8=$DBASE{'avn_prog2_remarks'};
$f1=" " if $f1 eq "";
$f2=" " if $f2 eq "";
$f3=" " if $f3 eq "";
$f4=" " if $f4 eq "";
$f5=" " if $f5 eq "";
$f6=substr("     ".$f6,-5,5);
$f7=substr("     ".$f7,-5,5);
if ($f1+$f2+$f3+$f4+$f5+$f6+$f7 != 0) {
   print FILE "Aviation Management/\n";
   print FILE "Airway Sci. Mgmt.          $f1   $f2   $f3   $f4   $f5       $f6     $f7   $f8\n";
   print FILE "\n";
}
$f1=$DBASE{'avn_prog3_A'};
$f2=$DBASE{'avn_prog3_B'};
$f3=$DBASE{'avn_prog3_M'};
$f4=$DBASE{'avn_prog3_D'};
$f5=$DBASE{'avn_prog3_O'};
$f6=$DBASE{'avn_prog3_hrs'};
$f7=$DBASE{'avn_prog3_enroll'};
$f8=$DBASE{'avn_prog3_remarks'};
$f1=" " if $f1 eq "";
$f2=" " if $f2 eq "";
$f3=" " if $f3 eq "";
$f4=" " if $f4 eq "";
$f5=" " if $f5 eq "";
$f6=substr("     ".$f6,-5,5);
$f7=substr("     ".$f7,-5,5);
if ($f1+$f2+$f3+$f4+$f5+$f6+$f7 != 0) {
   print FILE "Aviation Studies           $f1   $f2   $f3   $f4   $f5       $f6     $f7   $f8\n";
   print FILE "\n";
}
$f1=$DBASE{'avn_prog4_A'};
$f2=$DBASE{'avn_prog4_B'};
$f3=$DBASE{'avn_prog4_M'};
$f4=$DBASE{'avn_prog4_D'};
$f5=$DBASE{'avn_prog4_O'};
$f6=$DBASE{'avn_prog4_hrs'};
$f7=$DBASE{'avn_prog4_enroll'};
$f8=$DBASE{'avn_prog4_remarks'};
$f1=" " if $f1 eq "";
$f2=" " if $f2 eq "";
$f3=" " if $f3 eq "";
$f4=" " if $f4 eq "";
$f5=" " if $f5 eq "";
$f6=substr("     ".$f6,-5,5);
$f7=substr("     ".$f7,-5,5);
if ($f1+$f2+$f3+$f4+$f5+$f6+$f7 != 0) {
   print FILE "Avionics/\n";
   print FILE "Electronics                $f1   $f2   $f3   $f4   $f5       $f6     $f7   $f8\n";
   print FILE "\n";
}
$f1=$DBASE{'avn_prog5_A'};
$f2=$DBASE{'avn_prog5_B'};
$f3=$DBASE{'avn_prog5_M'};
$f4=$DBASE{'avn_prog5_D'};
$f5=$DBASE{'avn_prog5_O'};
$f6=$DBASE{'avn_prog5_hrs'};
$f7=$DBASE{'avn_prog5_enroll'};
$f8=$DBASE{'avn_prog5_remarks'};
$f1=" " if $f1 eq "";
$f2=" " if $f2 eq "";
$f3=" " if $f3 eq "";
$f4=" " if $f4 eq "";
$f5=" " if $f5 eq "";
$f6=substr("     ".$f6,-5,5);
$f7=substr("     ".$f7,-5,5);
if ($f1+$f2+$f3+$f4+$f5+$f6+$f7 != 0) {
   print FILE "Flight Education           $f1   $f2   $f3   $f4   $f5       $f6     $f7   $f8\n";
   print FILE "\n";
}
$f1=$DBASE{'avn_prog6_A'};
$f2=$DBASE{'avn_prog6_B'};
$f3=$DBASE{'avn_prog6_M'};
$f4=$DBASE{'avn_prog6_D'};
$f5=$DBASE{'avn_prog6_O'};
$f6=$DBASE{'avn_prog6_hrs'};
$f7=$DBASE{'avn_prog6_enroll'};
$f8=$DBASE{'avn_prog6_remarks'};
$f1=" " if $f1 eq "";
$f2=" " if $f2 eq "";
$f3=" " if $f3 eq "";
$f4=" " if $f4 eq "";
$f5=" " if $f5 eq "";
$f6=substr("     ".$f6,-5,5);
$f7=substr("     ".$f7,-5,5);
if ($f1+$f2+$f3+$f4+$f5+$f6+$f7 != 0) {
   print FILE "Other                      $f1   $f2   $f3   $f4   $f5       $f6     $f7   $f8\n";
   print FILE "\n";
}
close (FILE);

# Print Institution Entry to Browser   

print "<HR>\n";
print "<b>$DBASE{'key'}</b><br>\n";
if (substr($DBASE{'address1'},1,1) ne "") {
   print "$DBASE{'address1'}<br>\n";
}
if (substr($DBASE{'address2'},1,1) ne "") {
   print "$DBASE{'address2'}<br>\n";
}
print "$DBASE{'city'}, $DBASE{'state'} $DBASE{'zipcode'}<br>\n";
print "Telephone: $DBASE{'phone'}<br>\n";
print "Fax: $DBASE{'fax'}<br>\n";
print "Web Site: $DBASE{'poc_url'}<br>\n";
print "<br>\n";
print "<b>Point of Contact: </b>";
if ($DBASE{'salutation'} =~ /Dr./) {
   print "Dr. ";
} else {
   if ($DBASE{'salutation'} =~ /Mr./) {
      print "Mr. ";
   } else {
      if ($DBASE{'salutation'} =~ /Mrs./) {
         print "Mrs. ";
      } else {
         if ($DBASE{'salutation'} =~ /Ms./) {
            print "Ms. ";
         } else {
            if ($DBASE{'salutation'} =~ /Miss/) {
               print "Miss ";
            } else {
               print "$DBASE{'salute_other'} ";
            }
         }
      }
   }
}
print "$DBASE{'poc_name'}, $DBASE{'poc_dept'}, $DBASE{'poc_street'}, $DBASE{'city'}, $DBASE{'state'} $DBASE{'zipcode'}<br>\n";
print "Telephone: $DBASE{'poc_phone'}<br>\n";
print "Fax: $DBASE{'poc_fax'}<br>\n";
print "E-mail: $DBASE{'poc_email'}<br>\n";
print "<br>\n";
print "<b>Institutional Information</b><br>\n";
print "<b>Type of School: </b>";
if ($DBASE{'type'} =~ /pub/) {
   print "Public<br>\n";
} else {
   print "Proprietary<br>\n";
}
print "<b>Accreditation: </b>";
if ($DBASE{'accred'} =~ /accredited/) {
   print "$DBASE{'accred_agency'}<br>\n";
} else {
   if ($DBASE{'accred'} =~ /candidate/) {
      print "Candidate for accreditation<br>\n";
   } else {
      print "Not Accredited<br>\n";
   }
}
print "<b>Highest Degree Offered: </b>$DBASE{'degree'}<br>\n";
print "<b>Student Body: </b>";
if ($DBASE{'student_body'} =~ /coed/) {
   print "Co-educational<br>\n";
} else {
   if ($DBASE{'student_body'} =~ /male/) {
      print "Male Only<br>\n";
   } else {
      print "Female Only<br>\n";
   }
}
print "<b>Full Time Enrollment: </b>$DBASE{'enroll_under'} undergraduate, $DBASE{'enroll_grad'} graduate<br>\n";
print "<b>Freshman Admission Requirements: </b>";
if ($DBASE{'admission'} =~ /SAT/) {
   print "SAT ";
}
if ($DBASE{'admission'} =~ /ACT/) {
   print "ACT ";
}
if ($DBASE{'admission'} =~ /GPA/) {
   print "GPA ";
}
print "( $DBASE{'adm_other'} )";
print "<br>\n";
print "<b>Calendar System: </b>";
if ($DBASE{'calendar'} =~ /semester/) {
   print "Semesters";
} else {
   if ($DBASE{'calendar'} =~ /quarter/) {
      print "Quarters";
   } else {
      if ($DBASE{'calendar'} =~ /trimester/) {
         print "Trimesters";
      } else {
         print "Other";
      }
   }
}
print "<br>\n";
print "<b>Tuition and Fees: </b>Resident \$$DBASE{'fees_resident'}, Non-resident \$$DBASE{'fees_nonres'}<br>\n";
print "<br>\n";
print "<b>Aviation Program</b><br>\n";
print "<b>Online Aviation Programs:</b>\n";
if ($DBASE{'o_avn_prog1'} ne "") {
   print "yes<br>\n";
} else {
   print "no<br>\n";
}
print "<b>Other Non-traditional Degree Offerings: </b>";
if ($DBASE{'non_trad_dist'} =~ /yes/) {
   print "Courses through distance learning. ";
}
if ($DBASE{'non_trad_corr'} =~ /yes/) {
   print "Correspondence courses. ";
}
if ($DBASE{'non_trad_cert'} =~ /yes/) {
   print "Credit is given for FAA certificates and ratings held at the time of admission.";
}
print "<br>\n";
print "<b>FAA Certificate Offerings: </b>";
if ($DBASE{'flight_cert'} =~ /Recreational/) {
   print "Recreational, ";
}
if ($DBASE{'flight_cert'} =~ /Private/) {
   print "Private, ";
}
if ($DBASE{'flight_cert'} =~ /Commercial/) {
   print "Commercial, ";
}
if ($DBASE{'flight_cert'} =~ /Instrument/) {
   print "Instrument, ";
}
if ($DBASE{'flight_cert'} =~ /Multi-engine/) {
   print "Multi-engine, ";
}
if ($DBASE{'flight_cert'} =~ /CFI_airplane/) {
   print "CFI(airplane), ";
}
if ($DBASE{'flight_cert'} =~ /CFI_instrument/) {
   print "CFI(instrument), ";
}
if ($DBASE{'flight_cert'} =~ /ATP/) {
   print "ATP, ";
}
if ($DBASE{'flight_cert'} =~ /Glider/) {
   print "Glider, ";
}
if ($DBASE{'flight_cert'} =~ /Rotorcraft/) {
   print "Rotorcraft, ";
}
if ($DBASE{'flight_cert'} =~ /Flight Engineer/) {
   print "Flight Engineer, ";
}
if ($DBASE{'nonflight_cert'} =~ /Airframe/) {
   print "Airframe, ";
}
if ($DBASE{'nonflight_cert'} =~ /Powerplant/) {
   print "Powerplant, ";
}
if ($DBASE{'nonflight_cert'} =~ /AP/) {
   print "Airframe & Powerplant, ";
}
if ($DBASE{'nonflight_cert'} =~ /Avionics/) {
   print "Avionics ";
}
print "<br>\n";
print "<b>Instruction offered under FAA part: </b>";
if ($DBASE{'flight_instr'} =~ /141/) {
   print "141, ";
}
if ($DBASE{'flight_instr'} =~ /147/) {
   print "147, ";
}
if ($DBASE{'flight_instr'} =~ /61/) {
   print "61. ";
}
if ($DBASE{'flight_instr'} =~ /Examining Authority/) {
   print "Examining Authority";
}
print "<br>\n";
print "<b>Instruction Conducted By: </b>";
if ($DBASE{'instr_cond_by'} =~ /Institution/) {
   print "Institution. ";
}
if ($DBASE{'instr_cond_by'} =~ /Contractor/) {
   print "Contractor. ";
}
print "$DBASE{'instr_describe'}";
print "<br>\n";
print "<b>Cost of Lab Fees: </b>";
if ($DBASE{'flight_cost_priv'} != 0) {
   print "Private \$$DBASE{'flight_cost_priv'}; ";
}
if ($DBASE{'flight_cost_comm'} != 0) {
   print "Comm and Instr \$$DBASE{'flight_cost_comm'}; ";
}
if ($DBASE{'flight_cost_CFI'} != 0) {
   print "CFI-Airplane \$$DBASE{'flight_cost_CFI'}; ";
}
if ($DBASE{'flight_cost_multi'} != 0) {
   print "Multi-engine \$$DBASE{'flight_cost_multi'}; ";
}
if ($DBASE{'flight_cost_other'} != 0) {
   print "Other flight costs \$$DBASE{'flight_cost_other'}; ";
}
if ($DBASE{'flight_cost_total'} != 0) {
   print "Total cost of cert & ratings in flight major \$$DBASE{'flight_cost_total'}. ";
}
if ($DBASE{'non_flight_cost_airframe'} != 0) {
   print "Airframe \$$DBASE{'non_flight_cost_airframe'}; ";
}
if ($DBASE{'non_flight_cost_powerplant'} != 0) {
   print "Powerplant \$$DBASE{'non_flight_cost_powerplant'}; ";
}
if ($DBASE{'non_flight_cost_a_and_p'} != 0) {
   print "Airframe & Powerplant \$$DBASE{'non_flight_cost_a_and_p'}; ";
}
if ($DBASE{'non_flight_cost_avionics'} != 0) {
   print "Avionics \$$DBASE{'non_flight_cost_avionics'}; ";
}
if ($DBASE{'non_flight_cost_other'} != 0) {
   print "Other non-flight costs \$$DBASE{'non_flight_cost_other'}";
}
print "<br>\n";
print "<b>Flight Hours at Graduation: </b>";
print "$DBASE{'flight_hrs_min'} min  $DBASE{'flight_hrs_avg'} avg  $DBASE{'flight_hrs_max'} max";
print "<br>\n";
print "<b>Opportunities: </b>";
if ($DBASE{'opportunities'} =~ /Co-op Education/) {
   print "Co-op Education, ";
}
if ($DBASE{'opportunities'} =~ /Internship while enrolled/) {
   print "Internship while enrolled, ";
}
if ($DBASE{'opportunities'} =~ /Internship post graduate/) {
   print "Internship post graduate, ";
}
print "$DBASE{'other_opps'}";
print "<br>\n";
print "<b>Scholarships: </b>";
if ($DBASE{'scholarships_val'} != 0) {
  print "$DBASE{'scholarships_num'} for a total value of \$$DBASE{'scholarships_val'}";
}
print "<br>\n";
print "<b>Year Aviation Program Established: </b>$DBASE{'year_established'}<br>\n";
print "<b>Administration: </b>";
if ($DBASE{'advisory_committee'} =~ /yes/) {
   print "Aviation Advisory Committee, ";
}
if ($DBASE{'placement_service'} =~ /yes/) {
   print "Aviation Graduate Placement Service";
}
print "<br>\n";
print "<b>Aviation Program Located: </b>$DBASE{'program_location'}<br>\n";
print "<b>Aviation Affiliations: </b>";
if ($DBASE{'affiliations'} =~ /UAA Institutional Member/) {
   print "UAA, ";
}
if ($DBASE{'affiliations'} =~ /CAA Member/) {
   print "CAA, ";
}
if ($DBASE{'affiliations'} =~ /NIFA Member/) {
   print "NIFA, ";
}
if ($DBASE{'affiliations'} =~ /Alpha Eta Rho Chapter/) {
   print "Alpha Eta Rho Chapter, ";
}
print "$DBASE{'affil_other'}";
print "<br>\n";
print "<b>Articulation Agreements: </b>";
print "$DBASE{'art_agreements'}";
print "<br>\n";
print "<b>Other: </b>";
print "$DBASE{'other_info'}";
print "<br>\n";
print "<br>\n";

print "<b>Aviation Degree Programs:</b><br>\n";
print "<pre>\n";
print "                            Type of Degree      Credit\n";
print "                           -----------------    Hours\n";
print "Program                    A   B   M   D   O    Required  Enrolled   Remarks\n";
print "\n";
$f1=$DBASE{'avn_prog1_A'};
$f2=$DBASE{'avn_prog1_B'};
$f3=$DBASE{'avn_prog1_M'};
$f4=$DBASE{'avn_prog1_D'};
$f5=$DBASE{'avn_prog1_O'};
$f6=$DBASE{'avn_prog1_hrs'};
$f7=$DBASE{'avn_prog1_enroll'};
$f8=$DBASE{'avn_prog1_remarks'};
$f1=" " if $f1 eq "";
$f2=" " if $f2 eq "";
$f3=" " if $f3 eq "";
$f4=" " if $f4 eq "";
$f5=" " if $f5 eq "";
$f6=substr("     ".$f6,-5,5);
$f7=substr("     ".$f7,-5,5);
if ($f1+$f2+$f3+$f4+$f5+$f6+$f7 != 0) {
   print "Aviation Maintenance/\n";
   print "Acft. Maint. Mgmt.         $f1   $f2   $f3   $f4   $f5       $f6     $f7   $f8\n";
   print "\n";
}
$f1=$DBASE{'avn_prog2_A'};
$f2=$DBASE{'avn_prog2_B'};
$f3=$DBASE{'avn_prog2_M'};
$f4=$DBASE{'avn_prog2_D'};
$f5=$DBASE{'avn_prog2_O'};
$f6=$DBASE{'avn_prog2_hrs'};
$f7=$DBASE{'avn_prog2_enroll'};
$f8=$DBASE{'avn_prog2_remarks'};
$f1=" " if $f1 eq "";
$f2=" " if $f2 eq "";
$f3=" " if $f3 eq "";
$f4=" " if $f4 eq "";
$f5=" " if $f5 eq "";
$f6=substr("     ".$f6,-5,5);
$f7=substr("     ".$f7,-5,5);
if ($f1+$f2+$f3+$f4+$f5+$f6+$f7 != 0) {
   print "Aviation Management/\n";
   print "Airway Sci. Mgmt.          $f1   $f2   $f3   $f4   $f5       $f6     $f7   $f8\n";
   print "\n";
}
$f1=$DBASE{'avn_prog3_A'};
$f2=$DBASE{'avn_prog3_B'};
$f3=$DBASE{'avn_prog3_M'};
$f4=$DBASE{'avn_prog3_D'};
$f5=$DBASE{'avn_prog3_O'};
$f6=$DBASE{'avn_prog3_hrs'};
$f7=$DBASE{'avn_prog3_enroll'};
$f8=$DBASE{'avn_prog3_remarks'};
$f1=" " if $f1 eq "";
$f2=" " if $f2 eq "";
$f3=" " if $f3 eq "";
$f4=" " if $f4 eq "";
$f5=" " if $f5 eq "";
$f6=substr("     ".$f6,-5,5);
$f7=substr("     ".$f7,-5,5);
if ($f1+$f2+$f3+$f4+$f5+$f6+$f7 != 0) {
   print "Aviation Studies           $f1   $f2   $f3   $f4   $f5       $f6     $f7   $f8\n";
   print "\n";
}
$f1=$DBASE{'avn_prog4_A'};
$f2=$DBASE{'avn_prog4_B'};
$f3=$DBASE{'avn_prog4_M'};
$f4=$DBASE{'avn_prog4_D'};
$f5=$DBASE{'avn_prog4_O'};
$f6=$DBASE{'avn_prog4_hrs'};
$f7=$DBASE{'avn_prog4_enroll'};
$f8=$DBASE{'avn_prog4_remarks'};
$f1=" " if $f1 eq "";
$f2=" " if $f2 eq "";
$f3=" " if $f3 eq "";
$f4=" " if $f4 eq "";
$f5=" " if $f5 eq "";
$f6=substr("     ".$f6,-5,5);
$f7=substr("     ".$f7,-5,5);
if ($f1+$f2+$f3+$f4+$f5+$f6+$f7 != 0) {
   print "Avionics/\n";
   print "Electronics                $f1   $f2   $f3   $f4   $f5       $f6     $f7   $f8\n";
   print "\n";
}
$f1=$DBASE{'avn_prog5_A'};
$f2=$DBASE{'avn_prog5_B'};
$f3=$DBASE{'avn_prog5_M'};
$f4=$DBASE{'avn_prog5_D'};
$f5=$DBASE{'avn_prog5_O'};
$f6=$DBASE{'avn_prog5_hrs'};
$f7=$DBASE{'avn_prog5_enroll'};
$f8=$DBASE{'avn_prog5_remarks'};
$f1=" " if $f1 eq "";
$f2=" " if $f2 eq "";
$f3=" " if $f3 eq "";
$f4=" " if $f4 eq "";
$f5=" " if $f5 eq "";
$f6=substr("     ".$f6,-5,5);
$f7=substr("     ".$f7,-5,5);
if ($f1+$f2+$f3+$f4+$f5+$f6+$f7 != 0) {
   print "Flight Education           $f1   $f2   $f3   $f4   $f5       $f6     $f7   $f8\n";
   print "\n";
}
$f1=$DBASE{'avn_prog6_A'};
$f2=$DBASE{'avn_prog6_B'};
$f3=$DBASE{'avn_prog6_M'};
$f4=$DBASE{'avn_prog6_D'};
$f5=$DBASE{'avn_prog6_O'};
$f6=$DBASE{'avn_prog6_hrs'};
$f7=$DBASE{'avn_prog6_enroll'};
$f8=$DBASE{'avn_prog6_remarks'};
$f1=" " if $f1 eq "";
$f2=" " if $f2 eq "";
$f3=" " if $f3 eq "";
$f4=" " if $f4 eq "";
$f5=" " if $f5 eq "";
$f6=substr("     ".$f6,-5,5);
$f7=substr("     ".$f7,-5,5);
if ($f1+$f2+$f3+$f4+$f5+$f6+$f7 != 0) {
   print "Other                      $f1   $f2   $f3   $f4   $f5       $f6     $f7   $f8\n";
   print "\n";
}
print "</pre>\n";
print "</BODY>\n";
print "</HTML>\n";

# Next survey until end of control file
}

# End of main program
exit;

# Subroutines

sub getlocaldate {
   local($sec, $min, $hour, $mday, $month, $year, $wday, $yday, $isdst) = localtime(time);
   $month++; # months start with zero
   $min="00" if $min == 0;
   $min="0$min" if ($min < 10);
   $mday=" $mday" if ($mday < 10);
   local($mon)= "MONTH";
   $mon="Jan" if $month== 1;
   $mon="Feb" if $month== 2;
   $mon="Mar" if $month== 3;
   $mon="Apr" if $month== 4;
   $mon="May" if $month== 5;
   $mon="Jun" if $month== 6;
   $mon="Jul" if $month== 7;
   $mon="Aug" if $month== 8;
   $mon="Sep" if $month== 9;
   $mon="Oct" if $month==10;
   $mon="Nov" if $month==11;
   $mon="Dec" if $month==12;
   return "$mday $mon $year $hour:$min";
}

sub lock_excl {
   # File locking constants
   $LOCK_EXCL = 2;
   flock($_[0], $LOCK_EXCL);
   # seek($_[0], 0, 2);  # Seek to end (end=2)
}

sub lock_share {
   # File locking constants
   $LOCK_SHARED = 1;
   flock($_[0], $LOCK_SHARED);
}

sub lock_unlock {
   # File locking constants
    $LOCK_UNLOCK = 8;
    flock($_[0], $LOCK_UNLOCK);
}
