#!c:\perl\bin\perl #be sure this above line points to your perl interpreter ## ## A script that, given a SDNumber, provides a view of the corresponding ## order in the SnarkDreams database. ## Author: Zach Tomaszewski ## Date: 30 April 2003 ## use Win32::ODBC; use CGI ":cgi"; $cgi = new CGI; $sdno = $cgi->param('sdno'); #the user-requested order number ############################################# start CUT $DSN="SnarkDreams"; $username=""; $password=""; #Provide the three needed sql statements below. $SQLforCustomer =""; $SQLforOrder_Prod = ""; $SQLforOrder = ""; ############################################# end CUT ##main program printHeader(); if ($cgi->param('sdno')) { #then a specific order number has been requested printOrderView(); printSystemInfo(); } printFooter(); ###END main program ## # Prints the beginning of the html page ## sub printHeader(){ print "Content-Type: text/html\n\n"; #html header print qq^ SnarkDreams Order View

SnarkDreams Order View

Enter SD Order Number:

^; } ## # Prints the order view information # after querying the database for the needed info ## sub printOrderView(){ %customerData = (); %orderData = (); %itemData = (); #open connect to DB and catch errors if (!($db = new Win32::ODBC("DSN=$DSN;UID=$username;PWD=$password;"))){ print "

Error connecting to database.
\n"; print "Error: " . Win32::ODBC::Error() . "

\n"; return; } checkOrderExistance($sdno); #for a friendly message when the order doesn't exist loadSQLResults($SQLforCustomer); #$db now contains the table resulting #from the customer sql query $db->FetchRow(); #Point cursor to the first (and only) row %customerData = $db->DataHash(); #And then store that row in the %customerData hash #where the key is the column name #and the value is value in that column #repeat the process for %orderData loadSQLResults($SQLforOrder); $db->FetchRow(); %orderData = $db->DataHash(); #prep $db for %itemData loadSQLResults($SQLforOrder_Prod); #start printing print qq^

SD No: $sdno
Date: $orderData{ORDERDATE}

Kagi: $orderData{KAGI_NO}

\n

$customerData{FIRSTNAME} $customerData{LASTNAME}
$customerData{ADDRESS}
$customerData{COUNTRY} -- $customerData{STATE}
Tel: $customerData{TELEPHONE}
Email: $customerData{EMAIL}


^; #cycle through all ordered items while ($db->FetchRow()){ %itemData = $db->DataHash(); print "$itemData{QUANTITY} x $itemData{DESCRIPTION}
\n"; undef %itemData; } $costtotal = $orderData{COST} + $orderData{KAGI_PERCENT}; #continue printing print qq^


Comments: $orderData{COMMENTS}


Total Price: $orderData{TOTAL_PRICE}

Kagi Percent: $orderData{KAGI_PERCENT}
Cost: $orderData{COST}
Cost Total: $costtotal

Profit: $orderData{PROFIT}


^; } ## # Prints the end of the html page ## sub printFooter(){ print "\n\n"; } ## # Prints a little bit of system info ## sub printSystemInfo(){ print "


"; my @keys = (); foreach $key (HTTP_HOST, REMOTE_ADDR, HTTP_USER_AGENT, SERVER_SIGNATURE){ print "$key: $ENV{$key}
\n"; } print "

"; } ## # Given an SQL statement, runs it on the global $db ODBC # $db then contains the results # Exits if there is an error, printing the error on the way out. ## sub loadSQLResults { #($SQL) ($SQL) = @_; if ($db->Sql($SQL)){ print "

SQL failed.
\n Error: " . $db->Error() . "

\n"; print "
Statement:
$SQL

\n"; $db->Close(); printFooter(); exit(); } } ## # Given an sdno, checks to see if that order exists in the database. # Upsets the current contents of $db to do this. # If order doesn't exist, warns and exits. ## sub checkOrderExistance{ #($sdno) ($sdno) = @_; loadSQLResults("select sdnumber from sdorder where sdnumber = $sdno"); $db->FetchRow(); %data = $db->DataHash(); if ($data{SDNUMBER} eq "") { print "

There is no order with SDNumber \"$sdno\" in database.

"; printFooter(); exit(); } }