#!/usr/local/bin/perl ############################################################################# # nileList: List and sort all orders for customer # ARGV: sort_by: N (name), A (addr), D (date) # asc_desc: a (ascending), d (descending) # all: any character (will force display of all recs) ############################################################################# use CGI "cookie"; # import CGI cookie function use DBI; $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/sql/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 { print "Content-type: text/html \n"; print "\n"; ($sort_by, $asc_desc, $all) = @ARGV; # extract sort arguments $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 / $dateOpt = ($sort_by eq "D" && $asc_desc eq "a") ? "D+d" : "D+a"; # desc print < Nile.com - Order History
Nile.com  (SQL)
List Current Orders

EOF1 $dbh = DBI->connect("DBI:mysql:nile","nile","nile"); if (!defined($dbh)) { $msg = "Cannot open database connection - $DBI::errstr"; return; } $sql = "select order_num, last_name, first_name, address, date_format(order_date, 'a. m/d/y h:m:s') from orders "; $sql .= " where cust_id = \'$custid\' " if (! $all); $sql .= " order by "; $sql .= " last_name, first_name " if ($sort_by eq 'N'); $sql .= " address " if ($sort_by eq 'A'); $sql .= " order_date " if ($sort_by eq 'D'); $sql .= " DESC" if ($asc_desc eq 'd'); $cursor = $dbh->prepare($sql); $rc = $cursor->execute(); while( @columns = $cursor->fetchrow_array() ) { ($order,$lname,$fname,$address,$date) = @columns; print "
Name Address Order Date  
$lname $fname $address $date Detail "; } print <
EOF2 } ###########################################################################