#!/usr/local/bin/perl ############################################################################# # nileList: List and sort all orders for customer # ARGV: sort_by: N (name), A (addr), F (flavor), D (date) # asc_desc: a (ascending), d (descending) # all: any character (will force display of all recs) ############################################################################# use CGI "cookie"; # import CGI cookie function require "date.pl"; # import "date.pl" $custid = cookie('custid'); # customer id = cookie (new way) if ($custid eq '') { # if cookie is not present &print_menu(); # reprint menu with error # exec "./nileSignin"; # (or) execute Signin pgm } &display_data(); exit; ########################################################################### sub print_menu { print "Content-type: text/html \n"; print "\n"; open(HTML, "<../../web/demo/perl/nileMenu.html") || print ("Cannot open file - $!"); while ($line = ) { #print menu html print $line; } close(HTML); print "
"; print "You Must First Sign In!"; exit(-1); } ########################################################################### sub display_data { ($sort_by, $asc_desc, $all) = @ARGV; # extract sort arguments $downImage = ""; $upImage = ""; print "Content-type: text/html \n"; print "\n"; $nameOpt = ($sort_by eq "N" && $asc_desc eq "a") ? "N+d" : "N+a"; #toggle $addrOpt = ($sort_by eq "A" && $asc_desc eq "a") ? "A+d" : "A+a"; # asc $flavOpt = ($sort_by eq "F" && $asc_desc eq "a") ? "F+d" : "F+a"; # & $dateOpt = ($sort_by eq "D" && $asc_desc eq "a") ? "D+d" : "D+a"; # desc if ($sort_by eq "N") { $nameIcon = ($asc_desc eq "a") ? $downImage : $upImage; } if ($sort_by eq "A") { $addrIcon = ($asc_desc eq "a") ? $downImage : $upImage; } if ($sort_by eq "F") { $flavIcon = ($asc_desc eq "a") ? $downImage : $upImage; } if ($sort_by eq "D") { $dateIcon = ($asc_desc eq "a") ? $downImage : $upImage; } print < Nile.com - Order History
Nile.com
List Current Orders

EOF1 open (ORDERFILE, "< ../../data/nile.order.file") || print "Cannot open file - $!"; while($rec = ) { chomp($rec); ($userid,$fname,$address,$flavor,$top,$sec) = split(/:/,$rec); next if ($userid ne $custid && !$all); # next rec if not custid if ($sort_by eq 'N') { @array[$i++] = join('~',($fname,$address,$flavor,$sec)); } if ($sort_by eq 'A') { @array[$i++] = join('~',($address,$fname,$flavor,$sec)); } if ($sort_by eq 'F') { @array[$i++] = join('~',($flavor,$fname,$address,$sec)); } if ($sort_by eq 'D') { @array[$i++] = join('~',($sec,$fname,$address,$flavor)); } } if ($asc_desc eq "a") { @array = sort @array; } # sort ascending if ($asc_desc eq "d") { @array = reverse sort @array; } # sort descending for ($i=0; $i<@array; $i++) { if ($sort_by eq 'N') { ($fname,$address,$flavor,$sec) = split(/~/, @array[$i]); } if ($sort_by eq 'A') { ($address,$fname,$flavor,$sec) = split(/~/, @array[$i]); } if ($sort_by eq 'F') { ($flavor,$fname,$address,$sec) = split(/~/, @array[$i]); } if ($sort_by eq 'D') { ($sec,$fname,$address,$flavor) = split(/~/, @array[$i]); } $address =~ s/__/
/g; ($day,$date,$time) = &dateTime($sec); print "
\n"; } print <
Name $nameIcon Address $addrIcon Flavor $flavIcon Date $dateIcon
$fname $address $flavor $day $date $time

EOF2 } ###########################################################################