File:  [LON-CAPA] / loncom / cgi / metadata_keywords.pl
Revision 1.3: download - view: text, annotated - select for diffs
Sat May 11 21:31:00 2002 UTC (22 years, 1 month ago) by harris41
Branches: MAIN
CVS tags: version_0_5_1, version_0_5, version_0_4, stable_2002_july, STABLE, HEAD
Using LONCAPA::Configuration::read_conf
BUG 129

    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: #
   10: # YEAR=2002
   11: # 5/11 Scott Harrison
   12: #
   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
   32: # Has it been tested? 4
   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
   48: 
   49: use lib '/home/httpd/lib/perl/';
   50: use LONCAPA::Configuration;
   51: 
   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
   61: my $perlvarref=LONCAPA::Configuration::read_conf('access.conf','loncapa.conf');
   62: my %perlvar=%{$perlvarref};
   63: undef($perlvarref);
   64: 
   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) {
   88:     print $row[4]."\n";
   89: }
   90: 
   91: # --------------------------------------------------- Close database connection
   92: $dbh->disconnect();

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