#!/usr/bin/perl # fill in amount with needed # really need the fully/partially deal? # make database-ready and invoice ready output use Mysql; unshift(@INC,"/usr/local/etc/httpd/sites/virtualfoundation.org/admin"); require('cgisettings.pl'); $email_donation_msg_to = ("webmaster\@ecologia.ssquest.net", "ecologia\@igc.apc.org" ); # connect to the DB -- we'll need this no matter what $dbh = Mysql->connect(undef, "foundation", "vf", "virtualfoundation"); $process_delay = "1"; #debug # check for id to process, and process it (spooled at job) if ($ARGV[0] =~ /^\d{10}$/) { &process_donation($ARGV[0]); exit; } &parse_input; &tweak_input(%stdin); if (!$stdin{'step'}) { if ($argv{'project_id'} =~ /^.{10}$/) { &get_project_info($argv{'project_id'}); } elsif ($ENV{'HTTP_REFERER'} =~ m#/(.{10})\.(html|cgi)#) { &get_project_info($1); } unless ($stdin{'project_name'}) { $stdin{'project_name'} = "Project Name"; } &first_page; } elsif ($stdin{'step'} eq "2") { &assign_id; &record_info; if ( ($stdin{'how'} eq "fully" || $stdin{'how'} eq "partially") && ( !$stdin{'project_name'} || $stdin{'project_name'} eq "Project Name" ) ) { &error_page("need_project_name"); exit; } if ( !$stdin{'amount'} || $stdin{'amount'} !~ /^\d+$/ ) { &error_page("need_amount"); exit; } &second_page; } elsif ($stdin{'step'} eq "3") { #$time = `date +%y%m%d%H%M`; chop($time); #if ( $time > ( $stdin{'id'} + $process_delay ) ) { # &assign_id; # &fork_processor; #} &fork_processor; &record_info; &fix_amount; if ( !$stdin{'name'} ) { &error_page("need_name"); exit; } unless ($stdin{'phone'} || $stdin{'email'} || $stdin{'address'}) { &error_page("need_contact"); exit; } if ( $stdin{'email'} && $stdin{'email'} !~ /.+\@.+/ ) { &error_page("invalid_email"); exit; } if ( $stdin{'phone'} ) { if ( $stdin{'phone'} =~ /(\d{3}).*(\d{3}).*(\d{4})/ ) { $stdin{'phone'} = "($1) $2-$3"; } else { &error_page("invalid_phone"); exit; } } &third_page; } exit; sub assign_id { $stdin{'id'} = `date +%y%m%d%H%M`; chop($stdin{'id'}); } sub get_project_info { local($project_id = $_[0],%hash); #so we don't drag that around # if ( $project_id =~ /^.{10}$/ ) { # connect to the DB $dbh = Mysql->connect(undef, $database_name, "vf", "virtualfoundation"); unless ($sth_select = $dbh->query("SELECT * FROM main WHERE id = '$project_id'") ) { print "Select query failed."; die "Select query failed.

"; } %hash = $sth_select->fetchhash; $stdin{'project_name'} = $hash{'title'}; #added for CAFF 6-9-9 AFC if ($project_id = euschina01) { $stdin{'amount'} = 0; } else { $stdin{'amount'} = $hash{'budget'} - $hash{'collected'}; } } ###################### ### Page Functions ### ###################### # # sub first_page { print < Virtual Foundation Donation

The Virtual Foundation - your donation makes it happen


Donating to the Virtual Foundation

Please complete the form and then click "Proceed to Personal Info".

Would you like to:
Fully fund this project:
Partially fund this project:
Give to the Projects Fund: we direct your contribution to the projects with the greatest need
Give to the Development Fund: this supports operational needs of the Virtual Foundation

Amount: \$.00
Method: I would like to make an encrypted credit card donation through a secure server
Please bill me
I will send a check


If you have any trouble with this form or would feel more comfortable speaking to someone, please don't hesitate to call us at (888)801-7101.
EOF } sub second_page { print < Virtual Foundation Donation

The Virtual Foundation - your donation makes it happen


EOF # customize if this is not the first donation, i.e. pass information and # remind to check listed_name if ( $stdin{'name'} ) { print <Thank you again.

Your contact information from your last donation was saved, but you may make any necessary changes. Please be sure to specify the name this donation is to be listed under below.

Click "Complete Your Donation" when finished. EOF } else { print <Thank you.

Now, please tell us about yourself.

Click "Complete Your Donation" when finished. EOF } print <
Full Name:
Organization:
U.S. Phone:
Email:
Address:

Under what name shall we list the donation on our List of Donors?
Same as above Anonymous Other:


The Virtual Foundation will not give this information to any third party without your express permission.
If you have any trouble with this form or would feel more comfortable speaking to someone, please call us at (888)801-7101.

EOF } sub third_page { # see allocation routine in parse_input if ($stdin{'method'} eq "sending_check") { $billing_message = "You prefer to send a check. Please make the check payable to ECOLOGIA, and send it to ECOLOGIA, P.O. Box 142, Harford, PA 18823 within 14 days."; } elsif ($stdin{'method'} eq "credit_card") { $billing_message = "Please click here to complete your encrypted credit card donation on a secure server."; } elsif ($stdin{'method'} eq "bill_me") { $billing_message = "You prefer for us to bill you. We will send you an invoice within 14 days."; if ( !$stdin{'address'} ) { $billing_message .= " We will need to contact you by phone or e-mail to obtain your address, so that we can send you an invoice."; } } print < Virtual Foundation Donation

The Virtual Foundation - your donation makes it happen


We appreciate your donation!

Your tracking number is $stdin{'id'}.

Please confirm your information:
Name: $stdin{'name'}
Organization: $stdin{'organization'}
Address: $stdin{'address'}
Phone: $stdin{'phone'}
E-mail: $stdin{'email'}

You have given \$$stdin{'amount'}, which you would like to go toward $allocation, and be listed under the name "$listed_name".

EOF if ( ($stdin{'project_name'} eq "The Chinese American Friendship Forest") && $listed_name && ($listed_name ne "Anonymous") && ($listed_name ne $stdin{'name'}) ) { $cert_donor = $stdin{'name'}; $cert_donor =~ s/[^\w ]//g; $cert_donor =~ s/ /%20/g; $cert_recip = $listed_name; $cert_recip =~ s/[^\w ]//g; $cert_recip =~ s/ /%20/g; print <printable certificate (opens in new window) that you may present to your recipient. Or, you may give $listed_name this address to view it on the web:

http://www.virtualfoundation.org/donate/treecert.cgi?donor=$cert_donor&recip=$cert_recip&amount=$stdin{'amount'}
EOF } print <
If there are any mistakes in this information, you may back up using or your browser's Back button and correct them.


EOF } sub error_page { $error = $_[0]; # arg passed if ($error eq "need_name") { $error_text = "

Sorry, but we need your name in order to process your donation.

"; } elsif ($error eq "need_contact") { $error_text = "

Sorry, but we need at least one method of contacting you in order to process your donation.

"; } elsif ($error eq "invalid_email") { $error_text = "

Sorry, but I don't recognize that type of e-mail address. You may leave it blank if you enter a phone number or street address.

"; } elsif ($error eq "invalid_phone") { $error_text = "

Sorry, but I don't recognize that type of phone number. Please make sure you include your area code. You may leave it blank if you enter an e-mail address or street address.

"; } elsif ($error eq "need_project_name") { $error_text = "

Sorry, but we need to know which project you would like to fund.

"; } elsif ($error eq "need_amount") { $error_text = "

Sorry, but we need the amount of your donation. Please use only numbers, and not dollar signs (\$), commas (,), or decimal points (.). ($stdin{'amount'})

"; } elsif ($error eq "cant_open_datafile") { $error_text = "

Sorry, there was an error with the CGI. It can't open a datafile for your donation. Please call or e-mail us. ($donations_dir/$stdin{'id'})

"; } print < Virtual Foundation Donation

The Virtual Foundation - your donation makes it happen


$error_text

Please back up using or your browser's Back button and try again.

You can also e-mail us, or call us at (888) 801-7101.

EOF } ########################### ### Global Functions ### ########################### sub record_info { unless ( open(DATAFILE,"+>>$donations_dir/$stdin{'id'}") ) { &error_page("cant_open_datafile"); exit; } # print DATAFILE "I am running as $ENV{'USER'}/$ENV{'LOGNAME'}.\n"; # print DATAFILE "real user id: $<, effective user id: $>\n"; print DATAFILE $stdin; print DATAFILE "\n"; close(DATAFILE); } sub fix_amount { $stdin{'amount'} =~ s/^\s*//; # space at beginning $stdin{'amount'} =~ s/\s*$//; # space at end $stdin{'amount'} =~ s/\$//; # dollar sign $stdin{'amount'} =~ s/\.00$//; # no cents $stdin{'amount'} =~ s/\,//; # comma } sub tweak_input { local(%input = @_); if ($input{'how'} eq "fully" || $input{'how'} eq "partially") { $allocation = "\"$input{'project_name'}\""; } elsif ($input{'how'} eq "projfund") { $allocation = "the Projects Fund"; } elsif ($input{'how'} eq "devfund") { $allocation = "the Development Fund"; } if ( $input{'listed_name'} ) { # ignore options if they typed something here $listed_name = $input{'listed_name'}; } elsif ( $input{'listed_name_type'} eq "same_as_above" ) { $listed_name = $input{'name'}; } elsif ( $input{'listed_name_type'} eq "anonymous" ) { $listed_name = "Anonymous"; } else { $listed_name = "[error--please call]"; } } ############################ ### Processing functions ### ############################ sub fork_processor { open(PROCESSOR,"| at now + $process_delay minutes"); print PROCESSOR "$0 $stdin{'id'}"; close(PROCESSOR); } sub process_donation { local($file = "$donations_dir/$_[0]"); open(MAIL,"| mail -s \"VF Donation$_[0]\" $email_donation_msg_to"); unless ( open(DATAFILE,"+<$file") ) { print MAIL "Couldn't open donation datafile $file.\n"; if (!-e "$file") { print MAIL "It doesn't exist.\n"; } if (!-r "$file") { print MAIL "It isn't readable.\n"; } if (!-w "$file") { print MAIL "It isn't writable.\n"; } print MAIL "I am user $ENV{'USER'}.\n"; close(MAIL); exit; } @datafile = ; if ( -z "$file" ) { print MAIL "The donation datafile is empty.\n"; $process = 0; } elsif ( grep(/^Processed/,@datafile) ) { print MAIL "### This donation has already been processed ###\n"; if ( $datafile[$#datafile] =~ /^Processed/ ) { print MAIL "It is up to date.\n"; $process = 0; } else { print MAIL "But there are entries since the last processing.\n"; $process = 1; } } else { $process = 1; } if ($process) { if ( $datafile[$#datafile] =~ /step=3/) { $argv = $datafile[$#datafile]; } elsif ( @step3s = grep(/step=3/,@datafile) ) { print MAIL "Odd, the last entry is not a step 3, but there is a step 3 in the file.\n"; if ( $step3s[$#step3s] =~ /^$datafile[$#datafile]/ ) { print MAIL "That's OK, the info in the last step 3 is the same as in the very entry (a step 2).\n"; } $argv = $step3s[$#step3s]; } else { print MAIL "We have only donation info for this person.\n"; $argv = $datafile[$#datafile]; } # pretty kludgey: to get parse_input to process our info, # we need to put our info in $argv and clear @ARGV @ARGV = (); # parse_input doesn't chop $argv (only $stdin), so we need to chop($argv); &parse_input; &tweak_input(%argv); print MAIL <