--- loncom/publisher/lonpublisher.pm 2004/01/05 22:29:51 1.161
+++ loncom/publisher/lonpublisher.pm 2004/06/18 16:52:19 1.174
@@ -1,7 +1,7 @@
# The LearningOnline Network with CAPA
# Publication Handler
#
-# $Id: lonpublisher.pm,v 1.161 2004/01/05 22:29:51 albertel Exp $
+# $Id: lonpublisher.pm,v 1.174 2004/06/18 16:52:19 www Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -126,7 +126,7 @@ use Apache::loncommon();
use Apache::lonmysql;
use Apache::lonlocal;
use Apache::loncfile;
-use Apache::lonmeta;
+use LONCAPA::lonmetadata;
use Apache::lonmsg;
use vars qw(%metadatafields %metadatakeys);
@@ -199,12 +199,17 @@ sub metaeval {
}
}
my $newentry=$parser->get_text('/'.$entry);
- if ($entry eq 'customdistributionfile') {
+ if (($entry eq 'customdistributionfile') ||
+ ($entry eq 'sourcerights')) {
$newentry=~s/^\s*//;
if ($newentry !~m|^/res|) { $newentry=$prefix.$newentry; }
}
# actually store
- $metadatafields{$unikey}=$newentry;
+ if ( $entry eq 'rule' && exists($metadatafields{$unikey})) {
+ $metadatafields{$unikey}.=','.$newentry;
+ } else {
+ $metadatafields{$unikey}=$newentry;
+ }
}
}
}
@@ -318,6 +323,7 @@ sub textfield {
$value=~s/\s+$//gs;
$value=~s/\s+/ /gs;
$title=&mt($title);
+ $ENV{'form.'.$name}=$value;
return "\n
$title:".
"
".
'';
@@ -325,6 +331,7 @@ sub textfield {
sub hiddenfield {
my ($name,$value)=@_;
+ $ENV{'form.'.$name}=$value;
return "\n".'';
}
@@ -332,6 +339,11 @@ sub selectbox {
my ($title,$name,$value,$functionref,@idlist)=@_;
$title=&mt($title);
$value=(split(/\s*,\s*/,$value))[-1];
+ if (defined($value)) {
+ $ENV{'form.'.$name}=$value;
+ } else {
+ $ENV{'form.'.$name}=$idlist[0];
+ }
my $selout="\n
$title:".
'
';
}
+sub select_level_form {
+ my ($value,$name)=@_;
+ $ENV{'form.'.$name}=$value;
+ if (!defined($value)) { $ENV{'form.'.$name}=0; }
+ return &Apache::loncommon::select_level_form($value,$name);
+}
#########################################
#########################################
@@ -784,49 +802,21 @@ sub store_metadata {
&Apache::lonnet::logthis($error);
return ($error,undef);
}
+ my $dbh = &Apache::lonmysql::get_dbh();
if (($metadata{'obsolete'}) || ($metadata{'copyright'} eq 'priv') ||
($metadata{'copyright'} eq 'custom')) {
-# remove this entry
- $status=&Apache::lonmysql::remove_from_table
- ('metadata','url',$metadata{'url'});
+ # remove this entry
+ $status=&LONCAPA::lonmetadata::delete_metadata($dbh,undef,
+ $metadata{'url'});
} else {
-# store new data
-# adjust some values to metadatadatabase (e.g., "usage" is a reserved word)
- $metadata{'creationdate'}=
- &Apache::lonmysql::sqltime($metadata{'creationdate'});
- $metadata{'lastrevisiondate'}=
- &Apache::lonmysql::sqltime($metadata{'lastrevisiondate'});
- $metadata{'sequsage'}=$metadata{'usage'};
- $metadata{'sequsage_list'}=$metadata{'usage_list'};
- my %newmetadata=();
-# see if we have old entries
- my @oldmeta=&Apache::lonmysql::get_rows('metadata',
- "url LIKE BINARY '".
- $metadata{'url'}."'");
- if ($#oldmeta==0) {
-# yes, there is one old entry, transfer to newmetadata
- %newmetadata=&Apache::lonmeta::metadata_col_to_hash(@{$oldmeta[0]});
-# remove old entry
- $status=&Apache::lonmysql::remove_from_table
- ('metadata','url',$metadata{'url'});
- } elsif ($#oldmeta>0) {
-# more than one entry fit - how did that happen?
- $error='Error occured retrieving old values in '.
- 'metadata table in LON-CAPA database: '.$#oldmeta.
- ' matches';
- &Apache::lonnet::logthis($error);
- return ($error,undef);
- }
-# store new data on top of it
- foreach (keys %metadata) {
- $newmetadata{$_}=$metadata{$_};
- }
- $status = &Apache::lonmysql::store_row('metadata',\%newmetadata);
+ $status = &LONCAPA::lonmetadata::update_metadata($dbh,undef,
+ \%metadata);
}
- if (! defined($status)) {
+ if (defined($status) && $status ne '') {
$error='Error occured storing new values in '.
'metadata table in LON-CAPA database';
&Apache::lonnet::logthis($error);
+ &Apache::lonnet::logthis($status);
return ($error,undef);
}
return (undef,$status);
@@ -916,11 +906,11 @@ sub publish {
$allowstr.="\n".'';
}
$scrout.=' ';
- unless ($thisdep=~/\*/) {
+ if ($thisdep!~/\*/ && $thisdep!~m|^/adm/|) {
$scrout.='';
}
$scrout.=''.$thisdep.'';
- unless ($thisdep=~/\*/) {
+ if ($thisdep!~/\*/ && $thisdep!~m|^/adm/|) {
$scrout.='';
if (
&Apache::lonnet::getfile($Apache::lonnet::perlvar{'lonDocRoot'}.'/'.
@@ -941,11 +931,6 @@ sub publish {
}
$outstring=~s/\n*(\<\/[^\>]+\>)\s*$/$allowstr\n$1\n/s;
-### FIXME: is this really what we want?
-# I dont' think so, to will corrupt any UTF-8 resources at least,
-# and any encoding other than ISO-8859-1 will probably break
- #Encode any High ASCII characters
- #$outstring=&HTML::Entities::encode($outstring,"\200-\377");
# ------------------------------------------------------------- Write modified.
{
@@ -1090,32 +1075,40 @@ sub publish {
}
- foreach (split(/\W+/,$metadatafields{'keywords'})) {
- $keywords{$_}=1;
+ foreach my $addkey (split(/[\"\'\,\;]/,$metadatafields{'keywords'})) {
+ $addkey=~s/\s+/ /g;
+ $addkey=~s/^\s//;
+ $addkey=~s/\s$//;
+ if ($addkey=~/\w/) {
+ $keywords{$addkey}=1;
+ }
}
# --------------------------------------------------- Now we also have keywords
# =============================================================================
-# INTERACTIVE MODE
-#
- unless ($batch) {
- $scrout.=
- '