Annotation of loncom/cgi/metadata_keywords.pl, revision 1.5
1.1 harris41 1: #!/usr/bin/perl
2: #
3: # The LearningOnline Network with CAPA
4: #
5: # Gets keywords from metadata database.
6: #
7: # YEAR=2001
8: #
1.3 harris41 9: # YEAR=2002
10: #
1.1 harris41 11:
12: ###############################################################################
13: ## ##
14: ## ORGANIZATION OF THIS PERL CGI SCRIPT ##
15: ## ##
16: ## 1. Status of this code ##
17: ## 2. Purpose and description of program ##
18: ## 3. Modules used by this script ##
19: ## 4. Print MIME Content-type and other initialization ##
20: ## 5. Make sure database can be accessed and that this is a library server ##
21: ## 6. Loop through database records and print out keywords ##
22: ## ##
23: ###############################################################################
24:
25: # --------------------------------------------------------- Status of this code
26: #
27: # 1=horrible 2=poor 3=fair 4=good 5=excellent
28: # Organization 5
29: # Functionality 4
1.3 harris41 30: # Has it been tested? 4
1.1 harris41 31: #
32:
33: # ------------------------------------------ Purpose and description of program
34: #
35: # This program outputs one line per database entry.
36: # The line is to be a list of keywords separated by commas.
37: # The file is to be output as a text file on a browser (text/plain).
38: # This provides initial data by which to study common and uncommon
39: # keywords being used.
40: # Note that the authoritative copy of metadata "keywords" is in the
41: # .meta files that are native to the library server. We rely
42: # on the assumption that it is okay to use the MySQL server (which
43: # should reflect this information) instead. This is a speedier approach.
44:
45: # ------------------------------------------------- Modules used by this script
1.3 harris41 46:
47: use lib '/home/httpd/lib/perl/';
48: use LONCAPA::Configuration;
49:
1.1 harris41 50: use strict;
51: use DBI;
52:
53: # ---------------------------- Print MIME Content-type and other initialization
54: $|=1;
55: print 'Content-type: text/plain'."\n\n";
56:
57: # --- Make sure that database can be accessed and that this is a library server
58: # library server test
1.4 harris41 59:
60: # By default, loncapa_apache.conf is also read by the read_conf subroutine.
61: my $perlvarref=LONCAPA::Configuration::read_conf('loncapa.conf');
1.3 harris41 62: my %perlvar=%{$perlvarref};
63: undef($perlvarref);
64:
1.1 harris41 65: unless ($perlvar{'lonRole'} eq 'library') {
66: print "This can only be run on a library server!\n";
67: exit;
68: }
69: # database test
70: my $dbh;
71: {
72: unless (
73: $dbh = DBI->connect("DBI:mysql:loncapa","www",
74: $perlvar{'lonSqlAccess'},
75: { RaiseError =>0,PrintError=>0})
76: ) {
77: print "Cannot connect to database!\n";
78: exit;
79: }
80: }
81: %perlvar=(); # undefine it
82:
83: # ------------------------ Loop through database records and print out keywords
84: my $sth=$dbh->prepare("select * from metadata");
85: $sth->execute();
86: my @row;
87: while (@row=$sth->fetchrow_array) {
1.2 harris41 88: print $row[4]."\n";
1.1 harris41 89: }
90:
91: # --------------------------------------------------- Close database connection
92: $dbh->disconnect();
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>