Annotation of loncom/cgi/metadata_keywords.pl, revision 1.4

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

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>