home *** CD-ROM | disk | FTP | other *** search
- #!C:/perl/bin/perl
-
- # order.pl
- ######################################
- # Order Management System
- #
- # A simple on-line database to demonstrate
- # the capabilities of Perl, Win32 and the Web.
- # Database is a text file; limited insert,
- # update and delete features are implemented.
- #
- # Created: 1/2/98
- # Author: Michael L. Curry
- # http://www.cs.uoregon.edu/~currym
- ######################################
- # Copyright 1998, This script may be
- # distributed and modified as needed.
- # Please credit the author as appropriate.
- ######################################
-
- require("cgi-lib.pl");
- &ReadParse(*form);
- $|=1; # turn on error messages
- print "Content-type: text/html\n\n";
- $error1 = 'You must select an order before you can view details';
- $error2 = 'You must select an order before you can fill it';
-
- ######################################
- # File references
- #
- $applet = "order.pl";
- $base_server_path = 'http://localhost/interactiveinternettech/perl/cgi-bin/';
- $base_file_path = 'c:/webshare/wwwroot/interactiveinternettech/perl/cgi-bin/';
- $db = $base_file_path . "order.db";
-
- #############################
- # Test all valid button selections
- #
- if ($form{'new.x'}) { &new; } # main page, new record button
-
- elsif ($form{'view.x'}) # main page, view an order button
- {
- if ($form{'D1'}) {&view;} # view the order if they selected one
- else {&main($error1);} # complain if they forgot to select one
- }
- elsif ($form{'modify.x'}) { &modify; } # detail page, modify order
- elsif ($form{'save.x'}) { &save; } # detail page, save new order button
- elsif ($form{'fill.x'}) # main page, fill the order button
- {
- if ($form{'D1'}) {&fill;} # delete the order
- else {&main($error2);} # complain if they forgot to select one
- }
- else {&main();} # otherwise, give them the summary
-
- ##################
- # Main: display main menu
- #
- sub main {
- local ($msg) = @_;
- &header('Main Menu', $msg);
- &summary;
- }
- ##################
- # New
- #
- sub new {
- &header('Create a New Order');
- &addFields('Place Order','save');
- }
- ##################
- # View
- #
- sub view {
- &header('View & Modify an Order');
- &addFields('Update Order','modify');
- }
- ##################
- # Save
- #
- sub save {
- &insert;
- &header('Main Menu', 'Previous order inserted');
- &summary;
- }
- ##################
- # Modify
- #
- sub modify {
- &update_modify;
- &header('Main Menu', 'Previous order updated');
- &summary;
- }
- ##################
- # Fill
- #
- sub fill {
- &update_delete;
- &header('Main Menu','Previous order filled');
- &summary;
- }
- ##################
- # Order Summary
- #
- sub summary {
-
- local $action = $base_server_path . $applet;
- open (DAT, "< $db") || die "Can't open $db:$!<br>";
-
- print <<SUMMARY1;
- <form action="$action" method="GET">
- <input type="hidden" name="page" value="main order"><div
- align="center"><center><table border="0">
- <tr>
- <td><input type="image" name="new"
- src="../dkBluBtn.gif" align="bottom" border="0"
- width="32" height="25"></td>
- <td><font size="5">New Order </font></td>
- <td> </td>
- <td><input type="image" name="view"
- src="../dkBluBtn.gif" align="bottom" border="0"
- width="32" height="25"></td>
- <td><font size="5">View Order</font></td>
- <td> </td>
- <td><input type="image" name="fill"
- src="../dkBluBtn.gif" align="bottom" border="0"
- width="32" height="25"></td>
- <td><font size="5">Fill Order</font></td>
- </tr>
- </table>
- </center></div><p align="center"><select name="D1" size="5">
- SUMMARY1
-
- while (<DAT>)
- {
- print "<option>$_</option>";
- }
-
- print <<SUMMARY2;
- </select></p>
- </form>
- <div align="center"><center>
-
- <table border="0">
- <tr>
- <td valign="top"><font size="5"><img src="../Fork_LiftF1D1.gif"
- width="27" height="21"></font></td>
- <td><font size="4">The Order Management System provides
- current order status reflected in the local order
- administration database. For configuration information, </font><a
- href="../configur.htm"><font size="4">consult this document</font></a><font
- size="4">.</font><p><font size="5"><strong>Instructions: </strong></font></p>
- </td>
- </tr>
- <tr>
- <td> </td>
- <td><ol>
- <li>Select New Order to create an order. </li>
- <li>Select View Order and make changes to the order
- and view details.</li>
- <li>Select Fill Order to delete the order.</li>
- </ol>
- </td>
- </tr>
- </table>
- </center></div>
- <p><em>Developed by:</em> <a
- href="http://www.cs.uoregon.edu/~currym">Michael L. Curry</a> <br>
- ⌐ Copyright 1998, <a href="../configur.htm#About the OMS">See
- distribution notice</a></p>
- </body>
- </html>
-
- SUMMARY2
- close (DAT);
- }
- ##################
- # Add Fields
- #
- sub addFields {
- local ($label,$button) = @_;
-
- if ($form{'D1'} && $form{'view.x'})
- {
- ($id, $date, $part, $desc, $price, $qty, $status) = split(/::/, $form{'D1'});
-
- }
- else {$id = &getindex;}
-
- local $action = $base_server_path . $applet;
-
- print <<FIELDS;
- <form action="$action" method="GET">
- <div align="center"><center><table border="0">
- <tr>
- <td><font size="4">Order Id</font></td>
- <td><font size="4"><input type="text" size="10"
- name="T1" value="$id"></font></td>
- <td><font size="4">Date Created</font></td>
- <td><font size="4"><input type="text" size="10"
- name="T2" value="$date"></font></td>
- <td> </td>
- <td> </td>
- </tr>
- <tr>
- <td><font size="4">ISBN </font></td>
- <td><font size="4"><input type="text" size="10"
- name="T3" value="$part"></font></td>
- <td><font size="4">Title</font></td>
- <td colspan="3"><font size="4"><input type="text"
- size="20" name="T4" value="$desc"></font></td>
- <td> </td>
- <td> </td>
- </tr>
- <tr>
- <td><font size="4">Unit Price</font></td>
- <td><font size="4"><input type="text" size="10"
- name="T5" value="$price"></font></td>
- <td><font size="4">Quantity</font></td>
- <td><font size="4"><input type="text" size="5"
- name="T6" value="$qty"></font></td>
- <td> </td>
- <td> </td>
- </tr>
- <tr>
- <td><font size="4">Status</font></td>
- <td colspan="3"><font size="4"><input type="text"
- size="30" name="T7" value="$status"></font></td>
- <td> </td>
- <td> </td>
- <td> </td>
- <td> </td>
- </tr>
- <tr>
- <td><p align="right"><input type="image" name="$button"
- value="save new" src="../dkBluBtn.gif" align="bottom" border="0"
- width="32" height="25"></p>
- </td>
- <td valign="top"><font size="4"><strong>$label</strong></font></td>
- <td> </td>
- <td> </td>
- <td> </td>
- <td> </td>
- <td> </td>
- <td> </td>
- </tr>
- </table>
- </center></div><p><font size="4"> </font></p>
- </form>
- </body>
- </html>
-
- FIELDS
- }
- ##################
- # Header
- #
- sub header {
- local ($msg1, $msg2) = @_;
-
- print <<HEADER;
- <html>
-
- <head>
- <title>New Order</title>
- </head>
-
- <body background="../Lava.gif" bgcolor="#FFFFFF" text="#000000"
- bgproperties="fixed">
-
- <table border="0" width="100%">
- <tr>
- <td rowspan="2"><img src="../library.gif" width="121"
- height="187"></td>
- <td rowspan="2"><p align="center"><font color="#008080"
- size="6"><strong>Electronic Library Document Order Management System</strong></font></p>
- </td>
- </tr>
- </table>
-
- <center><p><font color="#800040" size="4"><strong>$msg2</strong></font></p>
- HEADER
- }
- ##################
- # Insert record into Database
- #
- sub insert {
-
- local ($line);
- $line = $form{'T1'}.'::'.$form{'T2'}.'::'.$form{'T3'}.'::'.$form{'T4'}.'::'.$form{'T5'}.'::'.$form{'T6'}.'::'.$form{'T7'}."\n";
- open (DAT, ">> $db") || die "Can't open $db:$!<br>";
- print DAT $line;
- close(DAT);
- }
-
- ##################
- # Update Database by modifying record
- #
- sub update_modify {
-
- local ($tempDB, $line, $pat); # vars
- $tempDB = $db;
- $tempDB =~ s/\.db/\.tmp/;
- #
- # build the new line
- $pat = $form{'T1'};
- $line = $form{'T1'}.'::'.$form{'T2'}.'::'.$form{'T3'}.'::'.$form{'T4'}.'::'.$form{'T5'}.'::'.$form{'T6'}.'::'.$form{'T7'}."\n";
-
- #print "Pat: $pat <br>";
- #
- # write new line & other lines to temp db
- #
- open (DAT, "< $db") || die "Can't open $db:$!<br>"; #read from
- open (TMP, "> $tempDB") || die "Can't open $tempDB:$!<br>"; #write to
- while (<DAT>)
- {
- if ($_ =~ /^\s*$pat\:\:/)
- { print TMP $line; }
- else { print TMP $_; }
- }
- close (DAT); close (TMP);
- #
- # Now over write the db with the temp db
- #
- open (DAT, "> $db") || die "Can't open $db:$!<br>"; #write to
- open (TMP, "< $tempDB") || die "Can't open $tempDB:$!<br>"; #read from
- while (<TMP>) {print DAT $_;}
- close (DAT); close (TMP);
- }
- ##################
- # Update Database by deleting record
- #
- sub update_delete {
-
- local ($tempDB, $line, $pat);
- $tempDB = $db;
- $tempDB =~ s/\.db/\.tmp/;
- $pat = $form{'D1'};
-
- # print "Pat: $pat <br>";
- #
- # eliminate line from temp db
- #
- open (DAT, "< $db") || die "Can't open $db:$!<br>"; #read from
- open (TMP, "> $tempDB") || die "Can't open $tempDB:$!<br>"; #write to
- while (<DAT>)
- {
- if ($_ =~ /$pat/) {
- #print $_, "matched", $pat, "<br>";
- next; # delete line
- }
- else {print TMP $_;}
- }
- close (DAT); close (TMP);
- #
- # Now overwrite the db with the temp db
- #
- open (DAT, "> $db") || die "Can't open $db:$!<br>"; #write to
- open (TMP, "< $tempDB") || die "Can't open $tempDB:$!<br>"; #read from
- while (<TMP>) {print DAT $_;}
- close (DAT); close (TMP);
- }
- ##################
- # get index: returns new index number
- #
- sub getindex {
- local (%hash, @tmp, $key, $lastID);
- open (DAT, "< $db") || die "Can't open $db:$!<br>";
- while (<DAT>)
- {
- @tmp = split (/::/,$_);
- $hash{$tmp[0]}=$tmp[3];
- }
- close (DAT);
- foreach $key (sort(keys(%hash))) {$lastID = $key}
- $lastID= $lastID + 1;
- return ($lastID);
- }
- #!C:/perl/bin/perl
-
- # strip.pl
- ######################################
- # Strip out un necessary text in
- # periodical file & fake an ISBN #
- #
- $file = "periodicals.txt";
- $tempfile = "CARL-index.txt";
-
- sub isbn
- {
- local ($num) = @_;
-
- while (length($num) < 10) {
- $num += int(rand 9999999999);
- }
- return $num;
- }
-
- open (DAT, "< $file") || die "Can't open $file:$!";
- open (TMP, "> $tempfile") || die "Can't open $tempfile:$!";
-
- $flg = 0;
-
- while (<DAT>) {
-
- if (($_ =~ /^\#/) || ($_ =~ /^--/) || ($_ =~ /^\s\s/))
- {
- print TMP $_;
- next;
- }
- if (($_ =~ /Our Price/) || ($_ =~ /Read more about this title/)) {next;}
- if ($_ =~ s/(\d+)(\.)(\s*)([^\~]*)(\~)(.*)/$4/)
- {
- $num = $1;
- $isbn = &isbn($num);
- $line = $_;
- chomp($line);
- $flg = 1;
- next;
- }
- if ($flg) {
- if ($_ =~ /([^\/]*)(\/)([^\d]*)(\d*)/) {
- $author = $1;
- $year = $4;
- $flg = 0;
- $line .= " Author: " . $author . " Published: " . $year;
- $line .= " ISBN:" . $isbn;
- print TMP "$line\n\n";
- }
-
- }
- }
- close (TMP);
- close (DAT);
- print "done!\n";
- #!c:\perl\bin\perl
-
- ######################
- # File: stuff.pl
- # Accepts a list of files as input arguments
- # Combines them into one big file
-
- $flag = shift(@ARGV);
-
- if ($flag ne '-o') {
-
- print "Usage: stuff.pl -o stuffedfile infile1 [infile2] ... [infileN]\n";
- die;
- }
-
- $outfile = shift(@ARGV);
- open (OUT, ">> $outfile") || die print "can't open $outfile: $!\n";
-
- while (<ARGV>) { print OUT $_; }
-
- close (OUT);
- print "done!\n";
-