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

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.3     ! harris41   61: my $perlvarref=LONCAPA::Configuration::read_conf('access.conf','loncapa.conf');
        !            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>