#!/usr/athena/bin/perl
 
$rhost = $ENV{'HOST'};
$log = "/afs/athena.mit.edu/dept/libdata/lso/a/survey/surveyTF.log";
require "ctime.pl";
$now =(&ctime(time));
 
print "\nThe MIT Libraries is tracking the use of its electronic resources
this week. We appreciate your cooperation in answering the following
question. All responses are strictly confidential.
 
Please indicate your MIT status by typing a letter:
 
      f    Faculty at MIT

      r    Research staff at MIT
      p    Post-doc at MIT

      g    Grad student at MIT
      u    Undergrad at MIT

      s    Staff at MIT
 
      o    Other MIT affiliation
      n    Not affiliated with MIT\n ";

while(1) {
GOROUND:{

$in = &get_menu_selection;

if ($in =~ /^[fpgurson]{1,1}$/) {
 
	open(LOG, ">>$log") || &start_tfirst(error); #die "Can't open file: $!";
	select LOG;
	print "$in $rhost $now";
	close LOG;
	&start_tfirst;
 
	}
elsif ($in =~ /x/) { exit(0);}

else {
	print "Please choose one of the letters from the menu (or x to exit): ";
	redo GOROUND;
	}
}
}

sub get_menu_selection {
    while(<>) {
        local($input_line) = $_;
        $input_line =~ s/^\s*//;  #get rid of whitespace
        $input_line =~ s/\s*$//;
        return($input_line);
        }
}


sub start_tfirst {
    local($error)=@_;
    if ($error) {print "Error. Couldn't open survey log file. Please report to bug_library@mit.edu\n";}
    print STDOUT "Thanks. Connecting to FirstSearch..\n";
    exec '/mit/library/bin/tfirst.real';
    exit(0);
}



