#!/usr/bin/perl -w -T
use strict ;
use English ;
use CGI qw/:standard -no_xhtml/ ;
use CGI::Carp qw/fatalsToBrowser/ ;
use GDBM_File ;
use URI::Escape ;
use FileHandle ;
#setup Files
my $DATA_DIR = "/srv/www/fpcp07/REGISTRATION"; # must be writable by 'nobody'
#setup DBM
my %ppool = (); #tie at id, only if needed
my $query= new CGI ;
my %fields = $query->Vars;
print $query->header, # create the HTTP header
$query->start_html('Registration Details'), # start the HTML
$query->h1('Registration Details'); # level 1 header
#for my $key (keys %fields) {
# print "$key => $fields{$key}\n",p;
#}
# checking & filling
my $title;
my $first;
my $last;
my $affil;
my $address;
my $badge;
my $email;
my $accomp;
my $reservation;
my $singlenum;
my $doublenum;
my $singlename;
my $doublename;
my $doubleshare;
my $payment;
my $creditcard;
my $transport;
my $transdate;
my $arrival;
my $departure;
my $vat;
my $acclunch;
my $accnum;
my $visa;
my $visa_warn;
my $num_trunc;
my $regisum=0;
my $roomsum=0;
my $accsum=0;
my $transum=0;
my $hotelsum=0;
my $checksum=0;
######### basic data
$title=$fields{'Title'};
if (!$fields{'First_name'}) {
print "
Form Incomplete, first name missing!\n",p,"Please return to the form and complete it!",p;
print "
";
$checksum=1;
} else {
$first=$fields{'First_name'};
}
if (!$fields{'Last_name'}) {
print "Form Incomplete, last name missing!\n",p,"Please return to the form and complete it!",p;
print "
";
$checksum=1;
}
else {
$last=$fields{'Last_name'};
}
if (!$fields{'Afilliation'}) {
print "Form Incomplete, afilliation missing!\n",p,"Please return to the form and complete it!",p;
print "
";
$checksum=1;
}
else {
$affil=$fields{'Afilliation'};
}
if (!$fields{'Address'}) {
print "Form Incomplete, address missing!\n",p,"Please return to the form and complete it!",p;
print "
";
$checksum=1;
} else {
$address=$fields{'Address'};
}
if (!$fields{'E_mail'}) {
print "Form Incomplete, e-mail address missing!\n",p,"Please return to the form and complete it!",p;
print "
";
$checksum=1;
}
else {
$email=$fields{'E_mail'};
}
$visa=$fields{'Visa'};
$badge=$title." ".$first." ".$last."\n".$affil."\n";
############ rooms
if (!$fields{'Visa'}) {
if ($fields{'Reservation'} =~ m/Yes/) {
$reservation="Yes";
if ($fields{'Single_num'} == 0 && $fields{'Double_num'} == 0 ) {
$checksum=1;
print "Form Incomplete, the number of rooms you want to reserve is zero!\n",p,"Please return to the form and complete it!",p;
print "
";
}
if ($fields{'Single_num'} != 0 && $fields{'Single_room'} =~ m/none/ ) {
print "Form Incomplete, You have selected a single room but not chosen the hotel!\n",p,"Please return to the form and complete it!\n",p;
print "
";
$checksum=1;
}
if ($fields{'Double_num'} != 0 && $fields{'Double_room'} =~ m/none/ ) {
print "Form Incomplete, You have selected a double room but not chosen the hotel!\n",p,"Please return to the form and complete it!",p;
print "
";
$checksum=1;
}
$reservation="Yes";
if ($fields{'Single_num'} != 0) {
$singlenum=$fields{'Single_num'};
$singlename=$fields{'Single_room'};
$arrival=$fields{'Arr_date'};
$departure=$fields{'Dep_date'};
}
if ($fields{'Double_num'} != 0) {
$doublenum=$fields{'Double_num'};
$doublename=$fields{'Double_room'};
$doubleshare=$fields{'Double_share'};
$arrival=$fields{'Arr_date'};
$departure=$fields{'Dep_date'};
}
}
else {
$reservation="No";
}
if ($reservation =~ m/No/ && ($fields{'Single_num'} != 0 || $fields{'Double_num'} != 0)) {
print "Form Incomplete, You have indicated required number of rooms but not indicated you wish to make the reservation!\n",p,"Please return to the form and complete it!",p;
$checksum=1;
}
}
###### Visa check
if ($visa =~ m/Yes/ && ($fields{'Single_num'} != 0 || $fields{'Double_num'} != 0)) {
$visa_warn=1;
}
######## Accompanying persons
$accnum=$fields{'Acc_num'};
$accomp=$fields{'accom_names'};
$acclunch= ($fields{'acc_lunch'} =~ m/y/) ? "Yes" : "No";
############ Payment
if (!$fields{'Visa'}) {
if (!$fields{'Payment_transf'} && !$fields{'Payment_card'} && !$fields{'Payment_cash'}) {
print "Form Incomplete, payment method not specified!\n",p,"Please return to the form and complete it!",p;
print "
";
$checksum=1;
}
if ($fields{'Payment_transf'}) {
$payment="Bank transfer";
}
if ($fields{'Payment_cash'}) {
$payment="Cash on arrival";
}
if ($fields{'Payment_transf'} && $fields{'Payment_cash'}) {
print "Form incomplete, multiple payment methods selected!\n",p,"Please return to the form and choose only one!",p;
print "
";
$checksum=1;
}
if ($fields{'Payment_card'}) {
if (!$fields{'Card_name'} || !$fields{'Card_con'} || !$fields{'Card_number'} || $fields{'Card_type'} =~ m/none/) {
print "Form Incomplete, credit card information incomplete!\n",p,"Please return to the form and complete it!",p;
print "
";
$checksum=1;
}
$payment="Credit card";
$creditcard="Card holder = ".$fields{'Card_name'}.", Card type= ".$fields{'Card_type'}.", Card number= ".$fields{'Card_number'}.", back num=".$fields{'Card_con'}.", expiry=".$fields{'Card_exp_1'}." ".$fields{'Card_exp_2'};
}
}
if ($fields{'vat'}) {
$vat=$fields{'vat'};
}
####### Visa check
if ($visa =~ m/Yes/ && ($fields{'Payment_transf'} || $fields{'Payment_cash'} || $fields{'Payment_card'})) {
$visa_warn=1;
}
######### Transportation
if ($fields{'Transport'}) {
if (!$fields{'Flight_num'}) {
print "Form Incomplete, flight number missing!\n",p,"Please return to the form and complete it!",p;
print "
";
$checksum=1;
}
$transport="Yes";
$transdate=$fields{'flight_num'}." ".$fields{'Arrival_time_1'}." ".$fields{'Arrival_time_2'}." ".$fields{Arrival_time_3};
}
############ calculate the price
### registration
if (!$fields{'Visa'}) {
if ($fields{'Payment_cash'}) {
$regisum=350;
} else {
$regisum=300;
}
} else {
$regisum=0;
}
#### accomodation
if (!$fields{'Visa'}) {
if ($reservation =~ m/Yes/) {
if ($singlenum != 0) {
if ($singlename =~ m/Lovec/){
$hotelsum=$singlenum*105;
}
if ($singlename =~ m/Kompas/) {
$hotelsum=$singlenum*95;
}
}
if ($doublenum != 0) {
if ($doublename =~ m/Lovec/){
$hotelsum=$hotelsum+$doublenum*130;
}
if ($doublename =~ m/Kompas/){
$hotelsum=$hotelsum+$doublenum*120;
}
}
}
}
######## accompanying persons
if (!$fields{'Visa'}) {
if ($accnum != 0){
if ($acclunch =~ m/Yes/){
$accsum=$accnum*180;
}
if ($acclunch =~ m/No/){
$accsum=$accnum*125;
}
}
}
######### now store the stuff
if ($checksum == 0 ) {
my $id=prepare_session();
$ppool{LIST} =$ppool{LIST}. ",$id";
$ppool{$id . "_id"} = $id;
$ppool{$id . "_title"} = $title;
$ppool{$id . "_first"} = $first;
$ppool{$id . "_last"} = $last;
$ppool{$id . "_affil"} = $affil;
$ppool{$id . "_address"} = $address;
$ppool{$id . "_badge"} = $badge;
$ppool{$id . "_email"} = $email;
$ppool{$id . "_accomp"} = $accomp;
$ppool{$id . "_accnum"} = $accnum;
$ppool{$id . "_acclunch"} = $acclunch;
$ppool{$id . "_reservation"} = $reservation;
$ppool{$id . "_singlenum"} = $singlenum;
$ppool{$id . "_singlename"} = $singlename;
$ppool{$id . "_doublenum"} = $doublenum;
$ppool{$id . "_doublename"} = $doublename;
$ppool{$id . "_doubleshare"} = $doubleshare;
$ppool{$id . "_arrival"} = $arrival;
$ppool{$id . "_departure"} = $departure;
$ppool{$id . "_payment"} = $payment;
$ppool{$id . "_creditcard"} = $creditcard;
$ppool{$id . "_vat"} = $vat;
$ppool{$id . "_transport"} = $transport;
$ppool{$id . "_transdate"} = $transdate;
$ppool{$id . "_visa"} = $visa;
############# send mail to golob
# $ENV{PATH} = '/usr/sbin';
%ENV = (PATH=>"/usr/sbin/");
my $sendmail = "/usr/sbin/sendmail -t";
# my $sendmail = "/usr/sbin/sendmail";
my $subject = "Subject: Registration of $title $first $last to fpcp07\n";
# my $to = "To: bostjan.golob\@ijs.si\n";
# my $to = "To: borut.kersevan\@ijs.si\n";
my $to = "To: FPCP2007\@ijs.si\n";
# compose content
my $content = "Title: $title\n"."First name: $first\n"."Last name: $last\n"."Affiliation: $affil\n".
"Address: $address\n"."E-mail: $email\n"."Num. accomp. persons:\n $accnum\n".
"Accomp. persons:\n $accomp\n"."Accomp. persons lunch:\n $acclunch\n".
"Room reservation: $reservation\n";
if ($visa =~ m/Yes/) {
$content = $content."Visa required!!!\n";
}
if ($reservation =~ m/Yes/) {
$content = $content."Arrival date: $arrival\n"."Departure date: $departure\n";
if ($singlenum) {
$content = $content . "Number of single rooms: $singlenum\n";
$content = $content . "Hotel: $singlename\n";
}
if ($doublenum) {
$content = $content . "Number of double rooms: $doublenum\n";
$content = $content . "Hotel: $doublename\n";
$content = $content . "Sharing with: $doubleshare\n";
}
}
$content = $content . "Payment method: $payment\n";
if ($vat) {
$content = $content . "VAT: $vat\n";
}
$content = $content . "Transport request: $transport\n";
if ($transport =~ m/Yes/) {
$content = $content . "Transport details: $transdate\n";
}
open(SENDMAIL, "|$sendmail") or die "Cannot open $sendmail: $!";
#print SENDMAIL $reply_to;
print SENDMAIL $to;
print SENDMAIL $subject;
print SENDMAIL "Content-type: text/plain\n\n";
print SENDMAIL $content;
close(SENDMAIL);
############# send notification mail to user
%ENV = (PATH=>"/usr/sbin/");
my $sendmail = "/usr/sbin/sendmail -t";
# my $sendmail = "/usr/sbin/sendmail";
# my $subject = "Subject: Registration of $title $first $last to FPCP07\n";
# # my $to = "To: bostjan.golob\@ijs.si\n";
# # my $to = "To: borut.kersevan\@ijs.si\n";
# # my $to = "To: FPCP2007\@ijs.si\n";
my $to = "To: $email\n";
# # compose content
my $content = "Dear $title $first $last,\n".
"This is an automatic notification of your registration to FPCP07.\n".
"Information you have provided has been registered. In case you have\n".
"also made the accommodation reservation through the registration web page,\n".
"you will receive another confirmation when the reservation is processed.\n".
"If visa is required for your travel we will contact you at the registered\n".
"e-mail address with further details.\n".
" \n".
"In case of any questions please contact the organizers at FPCP07\@ijs.si.\n".
" \n".
"We are looking forward seeing you at Bled,\n".
"FPCP07 Local Organizing Committee.\n";
#
open(SENDMAIL, "|$sendmail") or die "Cannot open $sendmail: $!";
# #print SENDMAIL $reply_to;
print SENDMAIL $to;
print SENDMAIL $subject;
print SENDMAIL "Content-type: text/plain\n\n";
print SENDMAIL $content;
close(SENDMAIL);
#
####### print registration info
print "A formal notice of your registration will be sent to\n",p,"the e-mail address indicated as soon as your request is processed.\n";
print "
";
print "The following information has been received:\n",p;
print "
";
print "Title: $title\n",p;
print "
";
print "First name: $first\n",p;
print "
";
print "Last name: $last\n",p;
print "
";
print "Affiliation: $affil\n",p;
print "
";
print "Address: $address\n",p;
print "
";
print "E-mail: $email\n",p;
print "
";
if ($visa_warn == 1){
print "Note: Invitation letter for visa application has been required.\n",p,"Please
note that the accommodation reservation and payment\n",p," will not be processed until we send the letter and receive your message about visa approval!\n";
print"
";
}
print "Number of Accomp. persons:\n $accnum\n",p;
print "
";
if ($accnum != 0) {
print "Accomp. persons:\n $accomp\n",p;
print "
";
print "Accomp. persons lunch:\n $acclunch\n",p;
print "
";
}
print "Room reservation: $reservation\n",p;
print "
";
if ($reservation =~ m/Yes/) {
print "Arrival date: $arrival\n",p;
print "
";
print "Departure date: $departure\n",p;
print "
";
}
if ($singlenum) {
print "Number of single rooms: $singlenum\n",p;
print "
";
print "Hotel: $singlename\n",p;
print "
";
}
if ($doublenum) {
print "Number of double rooms: $doublenum\n",p;
print "
";
print "Hotel: $doublename\n",p;
print "
";
print "Sharing with: $doubleshare\n",p;
print "
";
}
print "Payment method: $payment\n",p;
print "
";
if ($payment =~ m/Credit card/) {
# print "Credit card details: $creditcard\n",p;
# $num_trunc=`echo $fields{'Card_number'} | /usr/bin/cut -c 12-16`;
$num_trunc=$fields{'Card_number'};
$num_trunc=~/\d\d\d\d\d\d\d\d\d\d\d\d(.+)/;
$num_trunc=$1;
print "Credit card type: $fields{'Card_name'}, Card holder: $fields{'Card_name'}\n",p,"Card number: ************$num_trunc, Expiry: $fields{'Card_exp_1'} $fields{'Card_exp_2'}";
print "
";
}
if ($vat) {
print "VAT: $vat\n",p;
print "
";
}
print "Transport request: $transport\n",p;
print "
";
if ($transport =~ m/Yes/) {
print "Transport details: $transdate\n",p;
print "
";
}
print "Payment details\n",p;
print "Registration fee, participant: $regisum EUR\n",p;
print "Registration fee, accompanying persons(s): $accsum EUR\n",p;
print "Accomodation: $hotelsum EUR per night\n",p;
print "
";
print "Thank you for registration!\n",p;
print "
";
}
print $query->end_html; # end the HTML
sub prepare_session {
my $key;
my $entry=0;
$key="fpcp0701.gdbm";
if (! -e "$DATA_DIR/$key") {
warn "We forged key $key." ;
tie %ppool, 'GDBM_File', "$DATA_DIR/$key", &GDBM_NEWDB, 0640 or
die "Can't open GDBM file for $key." ;
$entry=1;
return $entry;
} else {
untie %ppool;
sleep 1;
tie %ppool, 'GDBM_File', "$DATA_DIR/$key", &GDBM_WRITER, 0640 or
die "Can't resume reading the file $DATA_DIR/$key!" ;
foreach( split(/,/, $ppool{LIST}) ) { $entry++; }
return $entry;
}
}