#!/usr/bin/perl -w use strict; use CGI qw(:standard); use lib "./pm/"; use Mail::Sendmail; use Text::Template; use vars qw($MAILTO $MAILFROM); use CGI::Carp qw(fatalsToBrowser); =head1 URL http://leadbelly.lanl.gov/lanl_ep_data/ep_request.html =head1 NAME ep_request.cgi =head1 DESCRIPTION Created to be used as the new EP-Request web-page form and cgi script. This file contains both the script and calls the html from library files. The HTML portion contained in the library files contains the EP_Request form. The script then takes the data entered into that form and produces a textfile with the request information. =head1 AUTHOR Written by Sarah Braun =head1 DATE September 24, 2003 =cut require "./top_html.lib"; require "./body_html.lib"; require "./end_html.lib"; print "Content-type:text/html\n\n"; html_top(); ### FORM DATA ### if (param) { print" \n\n \n\n 
"; #################### Send Mail To ######################################### $MAILTO = 'ddelapp@lanl.gov'; # (comma or semicolon seperated list) Who the notification of the data request will be sent to $MAILFROM = 'EP Request Form '; # When notification emails are sent, this is who it will say they are from ### End Send Mail To ### #################### User Information ##################################### my ($name, $address, $phone, $email, $time, $sec, $min, $hours, $mday, $mon, $year); $name = param('name'); $address = param('address'); $phone = param('phone'); $email = param('email'); ($sec, $min, $hours, $mday, $mon, $year) = (localtime)[0..5]; $year = $year + 1900; $mon = $mon + 1; ##################### Create OUT FILE ##################################### my ($filename); $filename .= "$year\-$mon\-$mday\-$hours$min"; open(OUTPUT_FILE,(">./REQUEST_LOG/$filename.txt")) or die("Could not create ./REQUEST_LOG/$filename.txt: $!"); ### End Create OUT FILE ### print OUTPUT_FILE "FILE: $filename.txt\n"; print OUTPUT_FILE "TIME_OF_REQUEST: $mon/$mday/$year $hours:$min:$sec\n\n"; if ($name) { print OUTPUT_FILE "REQUESTOR: $name\n\n"; } else { print "ERROR: Please go back and enter your name\n\n

"; } if ($address){ print OUTPUT_FILE "ADDRESS: $address\n"; } else { print "ERROR: Please go back and enter your address\n\n

"; } if ($phone){ print OUTPUT_FILE "PHONE: $phone\n"; } else { print "ERROR: Please go back and enter your phone number\n\n

"; } if ($email){ print OUTPUT_FILE "EMAIL: $email\n"; } else { print "ERROR: Please go back and enter your email address\n\n

"; } ### END User Information ### ##################### Requested Data Info ################################# my ($datause, $compression, @energies, $satellites, $timeres, $units, @year, @month, @day, @start, @duration, $i); $datause = param('datause'); #$compression = param('compression'); #@energies = param('energies'); #@satellites = param('satellites'); $satellites = param('satellites'); $timeres = param('timeres'); #$units = param('units'); @year = param('year'); @month = param('month'); @day = param('day'); @start = param('start'); @duration = param('duration'); if ($datause) { print OUTPUT_FILE "DATA_USE: $datause \n\n"; } else { print OUTPUT_FILE "MISSING DATA: Intended Data Use \n\n"; } $compression = "zipped"; if ($compression) { print OUTPUT_FILE "COMPRESSION: $compression \n\n"; } else { print OUTPUT_FILE "MISSING DATA: File Compression \n\n"; } @energies = ("i","j","k","l","m"); if (@energies){ foreach my $energies(@energies){ if ($energies eq 'i'){ print OUTPUT_FILE "ENERGY_CHNL: Low Energy Electrons: 5 channels, 50 to 315 keV\n\n"; } else { } if ($energies eq 'j'){ print OUTPUT_FILE "ENERGY_CHNL: High Energy Electrons: 4 channels, 315 keV to 1.5 MeV\n\n"; } else { } if ($energies eq 'k'){ print OUTPUT_FILE "ENERGY_CHNL: Low Energy Protons: 6 channels, 50 to 670 keV\n\n"; } else { } if ($energies eq 'l'){ print OUTPUT_FILE "ENERGY_CHNL: High Energy Protons: 4 channels, 0.67 to 5 MeV\n\n"; } else { } if ($energies eq 'm'){ print OUTPUT_FILE "ENERGY_CHNL: High Energy Protons: 2 channels, 5 to 50 MeV\n\n"; } else { } } } else { print OUTPUT_FILE "MISSING DATA: Energy Channels \n\n"; } if ($satellites) { print OUTPUT_FILE "SATELLITES: $satellites \n\n"; } #if (@satellites) { # if ($satellites[$_] =~ m/all/){ # print OUTPUT_FILE "SATELLITES: All \n\n"; # } # else{ # $i = 0; # foreach (@satellites){ # print OUTPUT_FILE "SATELLITES: $satellites[$i] \n\n"; # $i++; # } # } #} else { print OUTPUT_FILE "MISSING DATA: satellites \n\n"; } if ($timeres) { print OUTPUT_FILE "TIME_RES: $timeres \n\n"; } else { print OUTPUT_FILE "MISSING DATA: time resolution \n\n"; } $units = "Flux"; if ($units) { print OUTPUT_FILE "UNITS: $units \n\n"; } else { print OUTPUT_FILE "MISSING DATA: units \n\n"; } if (@year and @month and @day and @start and @duration) { $i = 0; foreach (@year){ if ($year[$i] =~ m/\w/){ print OUTPUT_FILE "YEAR: $year[$i]\nMONTH: $month[$i]\nDAY: $day[$i]\nSTART: $start[$i]\nDURATION: $duration[$i]\n\n"; } $i ++; } } else { print OUTPUT_FILE "MISSING DATA: Dates and Times\n\n"; } ### END Requested Data Info ### close (OUTPUT_FILE); open(INPUT_FILE,("<./REQUEST_LOG/$filename.txt")) or die("Could not open ./REQUEST_LOG/$filename.txt: $!"); flock (INPUT_FILE, 2)|| Error ('lock', 'file'); my @log = ; #################### EP Request Notification Email ######################## my (%mail); $mail{Message} .= "There was a new EP data request from:\n\n"; foreach (@log) { $mail{Message} .= "$_"; } $mail{Message} .= "File avalable at /REQUEST_LOG/$filename.txt \n\n"; $mail{To} = $MAILTO; $mail{From} = $MAILFROM; $mail{Subject} = "New EP Request"; $mail{smtp} = 'mailhost.lanl.gov'; sendmail(%mail) or warn $Mail::Sendmail::error; ### END EP Request Notification Email ### close (INPUT_FILE); ### END FORM DATA ### print "

THANK YOU for your request.

"; print "

You should recieve your confirmation e-mail "; print "with a link to your data as soon as your request has been processed.

"; print "

If you have any problems with the processing, please email Data Processing

"; print "

Submit Another Request"; print "

This request generated file: $filename.txt

"; print " \n\n \n\n\ \n\n"; } else { my ($line, @names, %sat, $i, $name, $key, @rows); my $template = Text::Template->new(TYPE => 'FILE', SOURCE => 'main.html', DELIMITERS => ['<%','%>']) or die "Couldn't construct template: $Text::Template::ERROR"; open(SAT_FILE,("<./satellites.txt")) or die("Could not open ./satellites.txt: $!"); # open guide file $i = 0; foreach $line () { $line =~ s/^[ \t]+//; #removes leading spaces and tabs next if $line =~ /^\s*\#/; #skip commented lines $line =~ s//>/g; $names[$i] = $line; $i++; } my $r = 0; foreach (@names){ $rows[$r] = "\t\n\n\t\n\n\t $names[$r]\n\n\t\n\n"; $r++; } my $table = ""; foreach my $vals (@rows){ $table .= $vals; } $sat{tablestart} = "\n\n"; $sat{"tablerows"} = $table; $sat{tableend} = "
"; my $result = $template->fill_in(HASH => \%sat); if (defined $result) { print $result } else { die "Couldn't fill in template: $Text::Template::ERROR" } close SAT_FILE; } html_end(); ### END ep_requestnew.cgi script ###