#!/usr/local/bin/perl

require "cgi-lib.pl";

binmode STDIN;
print &PrintHeader, "\n\n";
print '<html><head><title>ANIMAL USAGE REQUEST</title></head><body>';

&ReadParse(*input);

$addrname = $ENV{REMOTE_ADDR};
$tmpdir = "../temp";

####################################################################
# initialize optional fields

    $req{"PIhomePh"}="opt";
    $req{"Oname"}="opt";
    $req{"OoffPh"}="opt";
    $req{"OhomePh"}="opt";
    $req{"startdate"}="opt";
    $req{"enddate"}="opt";

####################################################################

# print normal header as for AUP.html
#print "<h2>Value of all components extracted from the URL</h2>\n";


# process name value pairs

print "<dl>\n";
$i=0;
foreach $key (keys %input)
{
  $output = $input{ "$key" };
  $output =~ s/\n/<br>/g;
  $output =~ tr/\0-\37\177-\377/./;
  $output =~ s/\n/<br>\n/g;
  $output =~ s/\r/&lt;cr&gt;/g; # so that we can see these..

  $form_val{$key} = $output; # save values
  $form_key[$i] =  "$key"; # save keywords
  $i++;
}
$No_form=$i; # save number of key/value pairs
$tempval=$form_val{"datafile"};

if ($form_val{"datafile"} eq "new") {
    #  First time through, create new datafile";
    #  Write keyword value pairs to input file
#    $datafile = "$tmpdir/out_$addrname.$$";   # result of AUP form data
    $datafile = "$tmpdir/temp.out";   # result of AUP form data
 
    if ( !open(OUTFILE,"> $datafile") ) {
    	print "Error opening an output file $datafile: $!\n";
	print "Bailing out..\n";
    	exit(1);
    }

#############################################################################
    $No_emp=0; # all fields initially assumed to be filled in
    # verify all fields have been entered, if not, the AUP form has 
    # to be re-sent to the client.
    # Note which fields (req'd) that still need to be filled
    for ( $i=0; $i<=$No_form; $i++ ) { 
	if (($form_val{$form_key[$i]} eq "")&&($req{$form_key[$i]} ne "opt")) {
	    $form_val{$form_key[$i]}="empty";
	    $No_emp++;
	}
    }
    # write data to temp file
    if ($No_emp==0) {
	print OUTFILE "keyword done\n";
    }
    for ( $i=0; $i<=$No_form; $i++ ) {
	print OUTFILE "keyword $form_key[$i]\n";
	print OUTFILE "$form_val{$form_key[$i]}\n";
    }
#############################################################################

} # end if

else {
    # read data from file
    $datafile=$form_val{"datafile"};
    if ( !(-e $datafile) ) {
   	print "temporary file $datafile doesn't exist!\n";
   	print "Bailing out..\n";
   	exit(1);
    }
    print "using sequence database file: $datafile\n";
    open(INFILE, "<$datafile") || die "Unable to open filename \"$!\".\n";

    $i=0;
    while ($line = <INFILE> ) {
	@fields = split(' ',$line);
	if ($fields[0] eq "keyword") {
	    $key = $fields[1];
	    $keyword[$i] = $key;
	    $i++;
	}
	else {
	    $val{$key}.$line;
	}	
    }
    # now combine current with read data key/value pairs
    # overwrite readin data values with those just submitted by form
    for ( $i=0; $i<=$No_form; $i++ ) { # $No_form is the number of fields passed
            $val{$form_key[$i]}=$form_val{$form_key[$i]};
    }

#############################################################################
    # verify all required fields have been entered, if not, the AUP 
    # form has to be re-sent to the client.

    # Note which fields (req'd) that still need to be filled
    for ( $i=0; $i<=$No_form; $i++ ) {
        if (($form_val{$form_key[$i]} eq "")&&($req{$form_key[$i]} ne "opt")) {
            $form_val{$form_key[$i]}="empty";
            $No_emp++;
        }
    }
    # write data to temp file
    if ($No_emp==0) {
        print OUTFILE "keyword done\n";
    }
    for ( $i=0; $i<=$No_form; $i++ ) {
        print OUTFILE "keyword $form_key[$i]\n";
        print OUTFILE "$form_val{$form_key[$i]}\n";
    }
#############################################################################

} # end else


# begin printing html header
print "Content-type: text/html\n\n";
print "<HTML>\n";
print "<HEAD>\n";

print "<META NAME=\"description\" content=\"information, services, protcols on transgenic and knockout mice\">\n";

print "<META NAME=\"keywords\" content=\"mouse, mice,oocytes, transgenic, dna, cancer,genetics,gene transfer, research, knockout, protein, enzyme, burnham,institute, microinjection\">\n"; 
print "<FONT FACE=\"HELVETICA, ARIAL \">\n";
print "<TITLE>ANIMAL USAGE REQUEST<\/TITLE>\n";
print "<\/HEAD>\n";
print "<BODY BGCOLOR=\"#CCCCFF\">\n";
print "<A NAME=\"LINK 1\"><HR size=4><\/A><P>\n";
print "<H2><CENTER>ANIMAL USAGE REQUEST<\/H2><\/CENTER>\n";


if ($No_emp==0) {
    # output thank you for submitting form.


} # end if

else {
# re-print form elements that haven't been filled

    print "<FORM METHOD=\"POST\" ACTION=\"..\/cgi-bin\/temp.cgi\">\n"; 
    print "<PRE>\n";
    print "<H4>The following entries require input.\n";
    print "Please complete the following requests:<\/H4>\n";
    print "\n";
    print "<input type=\"hidden\" name=\"datafile\" value=\"$datafile\">\n";
    print "<ul>\n";
    if ($form_val{"PIname"} eq "empty") {
	print "<pre> Principal Investigator: \n";
	print "<input name=\"PIname\" maxlength=\"30\" size=\"30\">(Required)\n";
    }
    if ($form_val{"PIoffPh"} eq "empty") {
    	print "<pre><br> Office Phone:\n";
    	print "<input name=\"PIoffPh\" maxlength=\"30\" size=\"30\">(Required)\n";
    }
    print "<br><br> \n";         
    print "\n";
    print "\n";
    if ($form_val{"PIoffPh"} eq "empty") {
	print "Project Title:\n";
	print "<input name=\"ProjTitle\" maxlength=\"30\" size=\"30\">(Required)\n";
	print "\n";
	print "\n";
	print "Check whether this is for a grant application or an actual project using animals.  \n";
	print "<input type=checkbox name=project  value=\"Grant\">Grant  \n";
	print "<input type=checkbox name=project  value=\"Project\">Project\n";
	print "\n";
	print "\n";
	print "<br> Start Date (MM\/DD\/YY):\n";
	print "<input name=\"startdate\" maxlength=\"30\" size=\"30\">(Optional)\n";
	print "\n";
	print "If less than a year,\n";
	print "indicate end date:<input name=\"enddate\" maxlength=\"30\" size=\"30\">(Optional)\n";
    }
    print "<br>\n";
    print "<A NAME=\"LINK 2\"><HR size=4><B>Grant Application:<\/B><\/A>\n";
    print "<br> \n";
    print "\n";
    print "Animal Usage Forms approved for grant applications may not be used to conduct experiments.\n";
    print "      1.  Check off if new or renewal.\n";
    print "                <input type=radio name=newren value=\"new\">New <input type=radio name=newren value=\"renewal\">Renewal\n";
    print "\n";
    print "      2.  If renewal: \n";
    print "                a)  check if competitive or non-competitive, and\n";
    print "               <input type=radio name=competitive value=\"comp\">Competitive <input type=radio name=competitive value=\"noncomp\">Non-Competitive\n";
    print "\n";
    print "\n";
    print "                b)  provide the grant number <input name=\"grantno\" maxlength=\"30\" size=\"30\">(Required)\n";
    print "\n";
    print "\n";
    print "     3.  If new or competitive renewal:\n";
    print "                a)  attach a copy of the abstract from the application, and\n";
    print "                b)  complete \"Section F.  Use of Vertebrate Animals.\"\n";
    print "                \n";
    print "\n";
    print "If Project (Using Animals):  \n";
    print "Provide account number to bill for care\/procedure charges.\n";
    print "\n";
    print "Account #:<input name=\"accountno\" maxlength=\"30\" size=\"30\">(Required)\n";
    print "\n";
    print "<br>\n";
    print "<A NAME=\"LINK 3\"><HR size=4><B>Specific Aims of This Project:<\/B><\/A>\n";
    print "<br> \n";
    print "Briefly describe in lay terms the specific aims of this project's use of animals. \n";
    print "<textarea name=specific_aims cols=50 rows=5>\n";
    print "<\/textarea>\n";
    print "<br>\n";
    print "<br>\n";
    print "Briefly indicate in lay terms your reason for using live experimental animals\n";
    print "vs. in vitro methods.\n";
    print "<textarea name=reason cols=50 rows=5>\n";
    print "<\/textarea>\n";
    print "\n";
    print "\n";
    print "Briefly indicate in lay terms your rationale for the species\/strain selected and a \n";
    print "justification for the number requested (i.e. experimental design).\n";
    print "<textarea name=rationale cols=50 rows=5>\n";
    print "<\/textarea>\n";
    print "\n";
    print "\n";
    print "Number of Animals:\n";
    print "\n";
    print "Mice:   Rats:   Rabbits:        Xenopus:        Other:\n";
    print "Species\/Strain:\n";
    print "Principal Use of Animals:  \n";
    print "Immunization\n";
    print "Source of \n";
    print "Tissue\n";
    print "Monoclonal \n";
    print "Antibody\n";
    print "Antisera\n";
    print "Production\n";
    print "Transgenic\n";
    print "Other (please specify):\n";
    print "\n";
    print "\n";
    print "Benefits to Humans and Animals:  \n";
    print "Describe in lay terms, the potential benefits this work may have for animals and\/or humans.  \n";
    print "Please be specific.\n";
    print "<textarea name=benefits cols=50 rows=5>\n";
    print "<\/textarea>\n";
    print "\n";
    print "<br>\n";
    print "<A NAME=\"LINK 4\"><HR size=4><B>Proposed Use of Animals:<\/B><\/A>\n";
    print "<br>\n";
    print "A.  If you are following an ARC Standard Policy with regard to your project, you do not need \n";
    print "to describe those procedures found in the Policy.  Indicate the procedure being used and include \n";
    print "the Policy date.\n";
    print "<textarea name=reason cols=50 rows=5>\n";
    print "<\/textarea>\n";
    print "\n";
    print "*Polyclonal Antisera\n";
    print "**Transgenic Mice\n";
    print "*Monoclonal Antibodies\n";
    print "Tumor Generation\n";
    print "Policy Date: <input name=\"policy_date\" maxlength=\"50\" size=\"30\">\n";
    print "\n";
    print "* In the Use of Animals section, please describe antigen(s) in detail.\n";
    print "\n";
    print "** In the Use of Animals section, please describe expected results which may \n";
    print "affect the animals you wish to produce .  Also, please describe what you will \n";
    print "use animals for (i.e. tissue collection, breedings, to look at embryos, etc.)\n";
    print "\n";
    print "<textarea name=animal_use cols=50 rows=5>\n";
    print "<\/textarea>\n";
    print "\n";
    print "\n";
    print "B.  If you are not following an ARC Standard Policy, please provide a complete description of the \n";
    print "proposed use of the animals.  Include the following where applicable:\n";
    print "       1.  antigens, including quantity of and any adjuvant to be used,\n";  
    print "       2.  steps taken to insure antigens have been purified and are nontoxic, \n";
    print "            non-irritating and aseptic,\n";
    print "       3.  any anesthesia/analgesia which will be used.  Include dosage, \n";
    print "             route and frequency of administration,  \n";
    print "       4.  volume and frequency of blood collection,\n";
    print "       5.  use, identity and quantity of radioisotopes and precautions for \n";
    print "             animal handlers.\n";
    print "            Note:  Use of radioisotopes must be approved by the radiation safety \n";
    print "             office (ext. 368) prior to submission to the animal facility.\n";
    print "\n";
    print "<textarea name=arc_policy cols=60 rows=5>\n";
    print "<\/textarea>\n";
    print "\n";
    print "<br>\n";
    print "<A NAME=\"LINK 5\"><HR size=4><B>Pain Levels:<\/B><\/A>\n";
    print "<br>\n";
    print "A generally acceptable method of determining whether or not a procedure would be considered painful, \n";
    print "is to consider whether it is considered a painful procedure in man.  If it is, then appropriate use of \n";
    print "anesthesia or analgesia should be made.\n";
    print "\n";
    print "Federal regulations currently define three levels of pain.  Please indicate which best defines the type \n";
    print "experienced with your research.\n";
    print "\n";
    print "<input type=radio name=pain_levels  value=\"catA\">     Category A:  A minor pain incurred by routine procedures such as injections and routine blood \n";
    print "collections.  Anesthetics are not required for these procedures.\n";
    print "\n";
    print "<input type=radio name=pain_levels  value=\"catB\">     Category B:  Pain for which the animal receives an appropriate type and amount of anesthetic, \n";
    print "analgesic and\/or tranquilizer.  Provide a complete description of the anesthetic, quantity, and route \n";
    print "of administration.\n";
    print "\n";
    print "<input type=radio name=pain_levels  value=\"catC\">     Category C:  Pain which, due to requirement of the research protocol, cannot be relieved by \n";
    print "anesthesia, analgesia and\/or tranquilizer.  Provide written justification of your requirements on a \n";
    print "separate sheet.  Projects classified as C require the prior review and approval of the full Animal \n";
    print "Research Committee before they are initiated.\n";
    print "\n";
    print "\n";
    print "\n";        
    print "Euthanasia:\n";
    print "Indicate how the animals will be sacrificed, either during the term of the study or upon \n";
    print "completion.  \n";
    print "<input type=radio name=euthanasia  value=\"co2\">CO2  \n";
    print "<input type=radio name=euthanasia  value=\"cd\">Cervical Dislocation\n";  
    print "<input type=radio name=euthanasia  value=\"od\">O.D.    \n";
    print "<input name=\"euthanasia\" maxlength=\"50\" size=\"30\">Other (please specify):\n";
    print "Other (please specify):\n";
    print "\n";
    print "\n";
    print "In the event that an animal dies during the course of this study, \n";
    print "please indicate whether or not animal facility personel should retain the carcass.\n";
    print "\n";
    print "Retain carcass:\n";
    print "<input type=radio name=carcass value=\"yes\">Yes <input type=radio name=carcass value=\"no\">No\n";
    print "\n";
    print "\n";
    print "<INPUT TYPE=\"submit\" VALUE=\"Send\"> <b>Send the form.<\/b><BR>\n";
    print "<INPUT TYPE=\"reset\" VALUE=\"Clear\"> <b>Clear and start over.<\/b> \n";
    print "\n";
    print "<\/FORM>\n";
    print "<\/PRE>\n";
    print "<\/BODY>\n";
    print "<\/HTML>\n";

} # end else 


exit (0);






