#!/usr/bin/perl -w # # File: Project3B.pl # A program to display all the outstanding Digital Donut orders # # D. Hildebrandt # A340 - Fall, 2002 # Use the GGI.pm Perl module to simplify this program use CGI qw(:standard); $theLocation = "localhost"; # Open the order file for reading open( INDAT, "; print "Content-type: text/html\n\n"; print ""; print ""; print "Digital Donuts<sup>®</sup> Outstanding Orders"; print ""; print ""; print ""; print "  "; print "

"; print ""; print ""; print ""; print ""; print ""; print ""; print ""; print ""; print ""; print ""; print ""; print ""; print ""; print ""; print ""; print ""; print ""; print ""; print ""; print ""; print ""; # Check the length of the list if( ($#records+1) == 0 ) { print ""; } else { # Report the file contents, one record at a time foreach $record (@records) { # Remove any terminating newline chomp( $record ); # 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 Orders
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
"; # Close the input file close(INDAT); # Terminate this program exit(0); sub error() { print header(); print start_html("Open File Error"); print "Unable to open the file data/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; } sub testPage() { print "Content-type: Text/html\n\n"; print ""; print ""; print "Test Page"; print ""; print ""; print "

Perl is working

"; print ""; print ""; }