This content was uploaded by our users and we assume good faith they have the permission to share this book. If you own the copyright to this book and it is wrongfully on our website, we offer a simple DMCA procedure to remove your content from our site. Start by pressing the button below!
Submit an Item for the Hotlist
Transfer Submitted Data to the Public portion of the database (password required).
http://docs.rinet.ru:8080/Using_Perl5_in_Web/ch12.htm (11 of 31) [2/17/2007 1:26:46 PM]
Chapter 12 -- Database Application Using CGI
Clicking Search the Hotlist calls up the search form, which I've likewise kept as simple as possible (see fig. 12.5). Listing 12.6 shows the HTML for the search form shown in figure 12.5. Figure 12.5 : The user enters search criteria in this form, which then posts the criteria to the searching script. Listing 12.6 The Search Form
\n"; }
print "Click on a link to go there, or click on details for a more-detailed description of the link\n";
After a search is performed, the output looks something like the sample screen shown in figure 12.6. Figure 12.6 : After searching the hotlist database, the user sees a list of hot links like this one. Each hot link calls a Perl script that shows the details of that record. Listing 12.8 is the HTML generated for the search results shown in figure 12.6. Listing 12.8 Typical Output from Search of Hotlist Database, With URLs to Detailed Views
LIST OF WWW DBMS GATEWAYS Details
Click on a link to go there, or click on details for a more-detailed description of the link
Viewing the Detail Record Notice that the Details links in the search-results screen shown in figure 12.6 (with the HTML given in Listing 12.8) point to a second CGI script and that each URL has ?UID=nn appended. This simple example shows how state is maintained on the client browser side; no history is maintained on the stateless server. Listing 12.9 shows the code for ShowDetails.p, the CGI program that generates the detail record. This program is similar to the preceding example. Listing 12.9 Perl Code to Return the Detail View
#Up to here code is identical with SearchHotlist.p above # #now @in has key=value pairs, and %in{key} = value #Main Program Begins Here # $UID = $in{'UID'};
#connect to database server $user = "healy"; $server = "server.wherever"; $passwd = "dummy";
#not used, for msql goes by Unix UID;
$database = "test"; &dbi_connect( $user, $pswd, $server, $database );
http://docs.rinet.ru:8080/Using_Perl5_in_Web/ch12.htm (16 of 31) [2/17/2007 1:26:46 PM]
Chapter 12 -- Database Application Using CGI
$Query = "select UID,URL,SHORTDESC,DESCRIPTION from HOTLIST where UID = $UID";
&dbi_dosql($Query); #the next line is msql-specific; comment-out for other ver &dbi_fieldnames('UID','URL','SHORTDESC','DESCRIPTION');
print "
\n"; }
Figure 12.7 shows an example of the detail screen, and Listing 12.10 shows the HTML generated for this screen. Figure 12.7 : Clicking an URL in the search-results screen of figure 12.6 generates a detail view such as this one. Listing 12.10 The Detail View of Figure 12.7
http://docs.rinet.ru:8080/Using_Perl5_in_Web/ch12.htm (17 of 31) [2/17/2007 1:26:46 PM]
Chapter 12 -- Database Application Using CGI
This simple example has only one hot link-to the URL that is being described. In a real application, you can (and should) have multiple hot links in your detail screens-hot links that perform lookups on this database or other databases. The HTML snippet in Listing 12.11, taken from a hypothetical Employee Detail screen, shows what I mean. Listing 12.11 A Hypothetical Employee Detail Screen
Location: Podunk
Position: CAD Technician
Mail Stop: POD-43
Clicking any field in the detail record performs a lookup of related records in that category. The list would contain the names of employees, and the URL behind each name would perform a lookup on the employee ID. This use of URLs to generate further searches effectively converts a relational database to a giant hypertext document. Such hyperlinks can just as easily link one database with another. Several large international databases that are widely used in molecular biology, for example, have Web interfaces. A local database used by one research group for its own internal data can include hot links to related information from one or more of the international databases. Some Major Scientific Databases on the WWW If you want to check out some major biological and chemical databases, use the following URLs: ● http://expasy.hcuge.ch/-the molecular-biology server of Geneva University Hospital ● http://dot.imgen.bcm.tmc.edu:9331/seq-annot/home.html-the Sequence Annotation server ● http://www.ncbi.nlm.nih.gov/-the National Center for Biotechnology Information home page ● http://www3.ncbi.nlm.nih.gov/Omim/-the Online Mendelian Inheritance in Man Genetic Database ● http://www.pdb.bnl.gov/-the Brookhaven Protein Data Bank ● http://www.unige.ch/crystal/w3vlc/data.index.html-a list of crystallography databases Most of these URLs have links to other sites that have related information. Consider a hypothetical business-related example. The marketing people in your company have created a Web-accessible database of product information, including which company locations build given parts of each product. Now suppose that you're a programmer in the personnel department and that you've been given the job of putting your company directory on the Web. http://docs.rinet.ru:8080/Using_Perl5_in_Web/ch12.htm (18 of 31) [2/17/2007 1:26:46 PM]
Chapter 12 -- Database Application Using CGI
You could use hyperlinks in your directory database to link product information with directory information. The location field in a directory detail screen could show the list of products made at that location, for example. With the cooperation of the people who maintain the product-information database, you could also work the other way. When you see a record that lists the various locations that make each part of the product, you could click links that locate people who work at each location. The possibilities for using the Web to integrate multiple databases in different locations are limited only by the programmer's imagination-and by the quality of available databases. The task may also require a much higher degree of connection among the parts of your MIS organization than was the case before. After all, Internet and intranet applications are basically about pulling scattered information together.
Submitting Data to the Hotlist A database is scarcely complete without providing a means for entering data. For some databases, the Web front end allows only searching. For this example, however, I also include a simple data-submission form, so that any user can submit proposed records for possible inclusion in the publicly searchable database. Figure 12.8 shows the submission screen. Figure 12.8 : This form is used for the remote submission, via the Web, of records to be added to the database. Listing 12.12 shows the HTML for the submission screen. Listing 12.12 A Simple HTML Form to Submit New Data via the Web
Note:
The data entered will be reviewed by the database administrators before being added to the database; submitted records will usually be available for viewing in one or two working days. Please check back in a few days to confirm that your submission has been added.
Submitted data is posted to the script shown in Listing 12.13. Listing 12.13 Perl Script to Handle Data-Submission Form
#Up to here code is identical with SearchHotlist.p above # #now @in has key=value pairs, and %in{key} = value #Main Program Begins Here #connect to database server $user = "healy"; $server = "server.wherever"; $passwd = "dummy";
#not used, for msql goes by Unix UID;
$database = "test"; &dbi_connect( $user, $pswd, $server, $database );
$UID = $in{'UID'}; $URL = $in{'URL'}; $SHORTDESC = &escape($in{'SHORTDESC'}); $SHORTDESC =÷ tr/a-z/A-Z/;
#convert to uppercase
$DESCRIPTION = &escape($in{'DESCRIPTION'}); http://docs.rinet.ru:8080/Using_Perl5_in_Web/ch12.htm (20 of 31) [2/17/2007 1:26:46 PM]
Chapter 12 -- Database Application Using CGI
$Query = "select MaxUID from UIDs where TableName = 'SUBMISSIONS'"; &dbi_dosql($Query); #the next line is msql-specific; comment-out for other ver &dbi_fieldnames('MaxUID'); %row = &dbi_nextrow; $MaxUID = $row{'MaxUID'} + 1; $Query = "Update UIDs Set MaxUID = $MaxUID where TableName = å'SUBMISSIONS'";
&dbi_dosql($Query); $Query = "Insert into SUBMISSIONS values(";
$Query = $Query . $MaxUID . ",'";
$Query = $Query . $URL . "','"; $Query = $Query . $SHORTDESC . "','"; $Query = $Query . $DESCRIPTION . "')";
&dbi_dosql($Query);
print "