Clarkson Computer Sales & Service Center
Freshman Sales




The following code, order.cgi, is the program that processes the order when a student submits the form and writes the information to the database file, order.txt. #!/usr/local/bin/perl # # bring_buy.cgi # This Program Copyright (c) Gregory J. Borrelli 2000 # You may not use any part of this program without permission # greg@borrellinet.net &read_form_results; open (OUT, ">>admin/order.txt"); print (OUT "$entry{last_name}:$entry{first_name}:$entry{middle_initial}: $entry{student_number}:$entry{email_address}:$entry{address}: $entry{city}:$entry{state}:$entry{zip_code}:$entry{zip_code_ext}: $entry{area_code}:$entry{local_code}:$entry{local_number}: $entry{Buy_Dell_Computer}:$entry{Buy_HP_Printer}\n"); &success; sub success{ print ("Location:thanks.html\n\n"); } sub read_form_results { local ($buffer, $name, $value); read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'}); foreach (split(/&/, $buffer)) { ($name, $value) = split(/=/); # Un-Webify plus signs and %-encoding $value =~ tr/+/ /; $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg; $entry{$name} = $value; } 1; }

The following code, view_order.cgi, is the program that processes the information when a user makes a request to view the orders that have been submited. Then, depending on the options that the user has selected, it dynamically generates a page that shows the information to the user that it gets from the database file, order.txt

#!/usr/local/bin/perl open (FH, "order.txt"); $line_count = 0; while (<FH>) { @lines = (@lines, $_); $line_count ++; } close (FH); &read_form_results; $op1 = 0; $op2 = 0; $op3 = 0; $lt1 = 0; $dj1 = 0; $lj1 = 0; print ("content-type: text/html\n\n"); print <<EOT <html> <head> <title>Freshman Sales</title> <link rel=stylesheet type="text/css" href="../style_order.css"> </head> <body bgcolor="#FFFFFF" text="#000000"> <center> <h2> Clarkson Computer Sales &amp; Service Center<br> <i>Freshman Computer Orders</i> </h2> <hr> <p> EOT ; print_list(); print <<EOT <p><br><br> <table border="0" cellPadding="6" cellSpacing="0" width="620" bgcolor="#fffff0"> <tr><td> <b>TOTALS:</b> </td></tr> <tr><td> Dell Optiplex #1: <b>$op1</b><br> Dell Optiplex #2: <b>$op2</b><br> Dell Optiplex #3: <b>$op3</b><br> Dell Latitude #1: <b>$lt1</b><br> <br> HP DeskJet 930C: <b>$dj1</b><br> HP LaserJet 1100xi: <b>$lj1</b><br> </td></tr> </table> <p><br><br> <table border="0" cellPadding="6" cellSpacing="0" width="620" bgcolor="#fffff0"> <tr><td align=center> <a href="view_order.html">Back to Main Menu</a> </td></tr> <tr><td> Copyright&nbsp;© 2000 - Gregory J. Borrelli </td></tr> </table> </body> </html> EOT ; sub print_list{ if ($entry{view} == 1){ print "<table border='1' bordercolor='#000080' cellspacing='0' cellpadding='2' bgcolor='#fffff0'>\n<tr>\n<th>Name</th>\n"; if ($entry{student_number}){print "<th>Student Number</th>\n";} if ($entry{email_address}){print "<th>E-Mail Address</th>\n";} if ($entry{street_address}){print "<th>Street Address</th>\n";} if ($entry{phone_number}){print "<th>Phone Number</th>\n";} if ($entry{computer_purchase}){print "<th>Computer Purchase</th>\n";} if ($entry{printer_purchase}){print "<th>Printer Purchase</th>\n";} print "</tr>\n"; foreach (sort(@lines)){ @person = split(/:/,$_); if ($person[13] =~ m/Optiplex 1/){$op1 ++;} if ($person[13] =~ m/Optiplex 2/){$op2 ++;} if ($person[13] =~ m/Optiplex 3/){$op3 ++;} if ($person[13] =~ m/Latitude 1/){$lt1 ++;} if ($person[14] =~ m/DeskJet 930C/){$dj1 ++;} if ($person[14] =~ m/LaserJet 1100xi/){$lj1 ++;} print "<tr>\n<td>&nbsp;$person[0], $person[1] $person[2]</td>\n"; if ($entry{student_number}){print "<td>&nbsp;$person[3]</td>\n";} if ($entry{email_address}){print "<td>&nbsp;<a href='mailto: $person[4]'>$person[4]</a></td>\n";} if ($entry{street_address}){print "<td>&nbsp;$person[5], $person[6], $person[7], $person[8]-$person[9]</td>\n";} if ($entry{phone_number}){print "<td>&nbsp; $person[10]-$person[11]-$person[12]</td>\n";} if ($entry{computer_purchase}){print "<td>&nbsp;$person[13]</td>\n";} if ($entry{printer_purchase}){print "<td>&nbsp;$person[14]</td>\n";} print "</tr>\n"; } print "</table>\n"; } if ($entry{view} == 2){ foreach (sort(@lines)){ @person = split(/:/,$_); if ($person[13] =~ m/Optiplex 1/){$op1 ++;} if ($person[13] =~ m/Optiplex 2/){$op2 ++;} if ($person[13] =~ m/Optiplex 3/){$op3 ++;} if ($person[13] =~ m/Latitude 1/){$lt1 ++;} if ($person[14] =~ m/DeskJet 930C/){$dj1 ++;} if ($person[14] =~ m/LaserJet 1100xi/){$lj1 ++;} print "<p><br><br><table border='0' cellspacing='0' cellpadding='2' width='620' bgcolor='#fffff0'>\n"; print "<tr><td><b>$person[0], $person[1] $person[2]</b>"; if ($entry{student_number}){ print "&nbsp;&nbsp;&nbsp;&nbsp;Student Number: <b>$person[3]</b></td></tr>\n";} else {print "</td></tr>\n";} if ($entry{street_address}) {print "<tr><td><b>$person[5]<br>\n$person[6], $person[7]<br>\n$person[8]-$person[9]</b></td></tr>\n";} if ($entry{phone_number} && $entry{email_address}) {print "<tr><td>Phone Number: <b>$person[10]-$person[11]-$person[12]</b> &nbsp;&nbsp; E-mail Address: <b><a href='mailto:$person[4]'>$person[4]</a></b></td></tr>\n";} elsif ($entry{phone_number}){print "<tr><td>Phone Number: <b>$person[10]-$person[11]-$person[12]</b></td></tr>\n";} elsif ($entry{email_address}){print "<tr><td>E-mail Address: <b><a href='mailto:$person[4]'>$person[4]</a></b></td></tr>\n";} if ($entry{computer_purchase} && $entry{printer_purchase}) {print "<tr><td>Computer Purchase: <b>$person[13]</b> &nbsp;&nbsp; Printer Purchase: <b>$person[14]</b></td></tr>\n";} elsif ($entry{computer_purchase}) {print "<tr><td>Computer Purchase: <b>$person[13]</b></td></tr>\n";} elsif ($entry{printer_purchase}) {print "<tr><td>Printer Purchase: <b>$person[14]</b></td></tr>\n";} print "</table>\n"; } } } sub read_form_results { local ($buffer, $name, $value); read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'}); foreach (split(/&/, $buffer)) { ($name, $value) = split(/=/); # Un-Webify plus signs and %-encoding $value =~ tr/+/ /; $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg; $entry{$name} = $value; } 1; }

Back to Main Menu




Copyright © 2000 - Gregory J. Borrelli