#!/usr/bin/perl -w # # File: Project3C.pl # # A program that delivers the next Digital Donuts order # # D. Hildebrandt # A340 - Fall, 2002 # Use the GGI.pm Perl module to simplify this program use CGI qw(:standard); $theLocation = "localhost"; # Open the file for reading open( INDAT, "; # Remove the first record from the list $record = shift( @records ); # Close the input file close(INDAT); # Open the file for writing specifying the complete path to the data file open(OUTDAT,">e:\\WebWeaver\\scripts\\data\\Project3A.txt") or error(); # Write the currect array to the file print OUTDAT @records; # Close the output file close(OUTDAT); # Get the current date and time ($second,$minute,$hour,$dayOfMonth,$month,$year,$weekDay,$dayOfYear,$isDst) = localtime(time); # Remember to add 1 to $month later # Send back a page containing the order print "Content-type: text/html\n\n"; print ""; print ""; print "Digital Donuts<sup>®</sup> Delivery"; print ""; print ""; print ""; print "  "; print "

"; # Remove any terminating newline chomp( $record ); print ""; print ""; print ""; print ""; print ""; print ""; print ""; print ""; print ""; print ""; print ""; print ""; print ""; print ""; print ""; print ""; print ""; print ""; print ""; print ""; print ""; if( $record eq "") { print ""; } else { # Split the record into its fields ($name,$email,$phone, $delivery, $plain, $choco, $vanilla, $coconut, $maple, $totalDonuts, $singles,$halfDozens,$dozens,$price,$deliveryFee,$totalPrice, $second,$minute,$hour,$dayOfMonth,$month,$year,$weekDay,$dayOfYear,$isDst) = split( /\|/, $record ); # Display each field print ""; print ""; print ""; print ""; @delivery = ( "Today", "Next Day" ); print ""; print ""; print ""; print ""; print ""; print ""; print ""; print ""; print ""; print ""; print ""; print ""; print ""; $realMonth = $month + 1; $realYear = $year + 1900; print ""; print ""; print ""; } print "
Digital Donuts® Outstanding Delivery
NameE-mailPhone No.Delivery DayPlainChocolate FrostedVanilla FrostedCoconut ToppedMaple FrostedTotal DonutsSinglesHalf DozensDozensPriceDelivery FeeTotal PriceDate"; print "Time
There are no outstanding orders to deliver
$name$email$phone$delivery[$delivery]$plain$choco$vanilla$coconut$maple$totalDonuts$singles$halfDozens$dozens" . toCurrency($price) . "" . toCurrency($deliveryFee) . "" . toCurrency($totalPrice) . "$realMonth/$dayOfMonth/$realYear$hour:$minute:$second
"; print end_html(); # Terminate this program exit(0); sub error() { print header(); print start_html("Open File Error"); print "Unable to open the file Project3A.txt"; print end_html(); exit(0); } sub toCurrency() { ##Converts numbers to currency my $x = $_[0]; ## convert to cents (shift decimal point 2 places to the right) $x = $x * 100; ## truncate any fractional cents $x = int($x / 1); ## get dollars my $dollars = int($x / 100); ## and cents my $cents = $x - ($dollars * 100); ## put the pieces together my $result = "\$" . $dollars; if( $cents < 10 ){ $cents = "0" . $cents;} $result = $result . "." . $cents; return $result; }