--- loncom/cgi/metadata_keywords.pl 2003/09/01 03:37:27 1.6 +++ loncom/cgi/metadata_keywords.pl 2008/11/28 20:50:25 1.7 @@ -1,6 +1,6 @@ #!/usr/bin/perl # Gets keywords from metadata database. -# $Id: metadata_keywords.pl,v 1.6 2003/09/01 03:37:27 albertel Exp $ +# $Id: metadata_keywords.pl,v 1.7 2008/11/28 20:50:25 raeburn Exp $ # # Copyright Michigan State University Board of Trustees # @@ -61,49 +61,73 @@ # ------------------------------------------------- Modules used by this script -use lib '/home/httpd/lib/perl/'; -use LONCAPA::Configuration; +$|=1; use strict; use DBI; +use lib '/home/httpd/lib/perl/'; +use Apache::lonlocal; +use LONCAPA::Configuration; +use LONCAPA::loncgi; # ---------------------------- Print MIME Content-type and other initialization -$|=1; print 'Content-type: text/plain'."\n\n"; +&main(); + +sub main { + if (!&LONCAPA::loncgi::check_ipbased_access('metadatakeywords')) { + if (!&LONCAPA::loncgi::check_cookie_and_load_env()) { + &Apache::lonlocal::get_language_handle(); + print(&LONCAPA::loncgi::missing_cookie_msg()); + return; + } + + if (!&LONCAPA::loncgi::can_view('metadata_keywords')) { + &Apache::lonlocal::get_language_handle(); + print(&LONCAPA::loncgi::unauthorized_msg('metadata_keywords')); + return; + } + } + + &Apache::lonlocal::get_language_handle(); + # --- Make sure that database can be accessed and that this is a library server # library server test # By default, loncapa_apache.conf is also read by the read_conf subroutine. -my $perlvarref=LONCAPA::Configuration::read_conf('loncapa.conf'); -my %perlvar=%{$perlvarref}; -undef($perlvarref); - -unless ($perlvar{'lonRole'} eq 'library') { - print "This can only be run on a library server!\n"; - exit; -} + my $perlvarref=LONCAPA::Configuration::read_conf('loncapa.conf'); + my %perlvar=%{$perlvarref}; + undef($perlvarref); + + unless ($perlvar{'lonRole'} eq 'library') { + print(&Apache::lonlocal::mt('This can only be run on a library server!)."\n"); + return; + } + # database test -my $dbh; -{ - unless ( - $dbh = DBI->connect("DBI:mysql:loncapa","www", - $perlvar{'lonSqlAccess'}, - { RaiseError =>0,PrintError=>0}) - ) { - print "Cannot connect to database!\n"; - exit; + my $dbh; + { + unless ( + $dbh = DBI->connect("DBI:mysql:loncapa","www", + $perlvar{'lonSqlAccess'}, + { RaiseError =>0,PrintError=>0}) + ) { + print "Cannot connect to database!\n"; + return; + } } -} -%perlvar=(); # undefine it + %perlvar=(); # undefine it # ------------------------ Loop through database records and print out keywords -my $sth=$dbh->prepare("select * from metadata"); -$sth->execute(); -my @row; -while (@row=$sth->fetchrow_array) { - print $row[4]."\n"; -} + my $sth=$dbh->prepare("select * from metadata"); + $sth->execute(); + my @row; + while (@row=$sth->fetchrow_array) { + print $row[4]."\n"; + } # --------------------------------------------------- Close database connection -$dbh->disconnect(); + $dbh->disconnect(); + return; +}