--- loncom/publisher/lonpublisher.pm 2003/11/01 17:09:52 1.141
+++ loncom/publisher/lonpublisher.pm 2004/03/31 05:24:00 1.165
@@ -1,7 +1,7 @@
# The LearningOnline Network with CAPA
# Publication Handler
#
-# $Id: lonpublisher.pm,v 1.141 2003/11/01 17:09:52 www Exp $
+# $Id: lonpublisher.pm,v 1.165 2004/03/31 05:24:00 albertel Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -25,24 +25,6 @@
#
# http://www.lon-capa.org/
#
-#
-# (TeX Content Handler
-#
-# 05/29/00,05/30,10/11 Gerd Kortemeyer)
-#
-# 11/28,11/29,11/30,12/01,12/02,12/04,12/23 Gerd Kortemeyer
-# 03/23 Guy Albertelli
-# 03/24,03/29,04/03 Gerd Kortemeyer
-# 05/03,05/05,05/07 Gerd Kortemeyer
-# 06/23,08/07,08/11,8/13,8/17,8/18,8/24,9/26,10/16 Gerd Kortemeyer
-# 12/04,12/05 Guy Albertelli
-# 12/05 Gerd Kortemeyer
-# 12/05 Guy Albertelli
-# 12/06,12/07 Gerd Kortemeyer
-# 12/25 Gerd Kortemeyer
-# YEAR=2002
-# 1/17 Gerd Kortemeyer
-#
###
###############################################################################
@@ -143,6 +125,9 @@ use Apache::lonnet();
use Apache::loncommon();
use Apache::lonmysql;
use Apache::lonlocal;
+use Apache::loncfile;
+use Apache::lonmeta;
+use Apache::lonmsg;
use vars qw(%metadatafields %metadatakeys);
my %addid;
@@ -180,6 +165,10 @@ nothing
#########################################
#########################################
+#
+# Modifies global %metadatafields %metadatakeys
+#
+
sub metaeval {
my ($metastring,$prefix)=@_;
@@ -214,11 +203,9 @@ sub metaeval {
$newentry=~s/^\s*//;
if ($newentry !~m|^/res|) { $newentry=$prefix.$newentry; }
}
- if ($metadatafields{$unikey}) {
- unless (($metadatafields{$unikey}=~/\Q$newentry\E/) ||
- ($newentry eq '')) {
- $metadatafields{$unikey}.=', '.$newentry;
- }
+# actually store
+ if ( $entry eq 'rule' && exists($metadatafields{$unikey})) {
+ $metadatafields{$unikey}.=','.$newentry;
} else {
$metadatafields{$unikey}=$newentry;
}
@@ -267,7 +254,8 @@ sub metaread {
my ($logfile,$fn,$prefix)=@_;
unless (-e $fn) {
print($logfile 'No file '.$fn."\n");
- return '
No file: '.$fn.'';
+ return '
'.&mt('No file').': '.
+ &Apache::loncfile::display($fn).'';
}
print($logfile 'Processing '.$fn."\n");
my $metastring;
@@ -276,7 +264,8 @@ sub metaread {
$metastring=join('',<$metafh>);
}
&metaeval($metastring,$prefix);
- return '
Processed file: '.$fn.'';
+ return '
'.&mt('Processed file').': '.
+ &Apache::loncfile::display($fn).'';
}
#########################################
@@ -333,8 +322,7 @@ sub textfield {
$value=~s/\s+$//gs;
$value=~s/\s+/ /gs;
$title=&mt($title);
- my $uctitle=uc($title);
- return "\n
$uctitle:".
+ return "\n $title:".
" $uctitle:".
+ my $selout="\n $title:".
' '.&mt('Obsolete parameters or stored values').': '.
- $chparms.'
".
'';
}
@@ -347,9 +335,8 @@ sub hiddenfield {
sub selectbox {
my ($title,$name,$value,$functionref,@idlist)=@_;
$title=&mt($title);
- my $uctitle=uc($title);
$value=(split(/\s*,\s*/,$value))[-1];
- my $selout="\n
';
+ my $outstring=''.&mt('Unable to publish file, it contains duplicated ID(s), ID(s) need to be unique. The duplicated ID(s) are').': '.join(', ',@duplicatedids).'';
return ($outstring,1);
}
if ($needsfixup) {
@@ -691,8 +678,15 @@ sub fix_ids_and_indices {
}
if ($lctag eq 'applet') {
my $codebase='';
- if (defined($parms{'codebase'})) {
- my $oldcodebase=$parms{'codebase'};
+ my $havecodebase=0;
+ foreach my $key (keys(%parms)) {
+ if (lc($key) eq 'codebase') {
+ $codebase=$parms{$key};
+ $havecodebase=1;
+ }
+ }
+ if ($havecodebase) {
+ my $oldcodebase=$codebase;
unless ($oldcodebase=~/\/$/) {
$oldcodebase.='/';
}
@@ -706,14 +700,13 @@ sub fix_ids_and_indices {
}
$allow{&absoluteurl($codebase,$target).'/*'}=1;
} else {
- foreach ('archive','code','object') {
- if (defined($parms{$_})) {
- my $oldurl=$parms{$_};
+ foreach my $key (keys(%parms)) {
+ if ($key =~ /(archive|code|object)/i) {
+ my $oldurl=$parms{$key};
my $newurl=&urlfixup($oldurl,$target);
$newurl=~s/\/[^\/]+$/\/\*/;
- print $logfile 'Allow: applet '.$_.':'.
- $oldurl.' allows '.
- $newurl."\n";
+ print $logfile 'Allow: applet '.lc($key).':'.
+ $oldurl.' allows '.$newurl."\n";
$allow{&absoluteurl($newurl,$target)}=1;
}
}
@@ -778,7 +771,7 @@ Returns: (error,status). error is undef
#########################################
#########################################
sub store_metadata {
- my %metadata = %{shift()};
+ my %metadata = @_;
my $error;
# Determine if the table exists
my $status = &Apache::lonmysql::check_table('metadata');
@@ -795,17 +788,45 @@ sub store_metadata {
&Apache::lonnet::logthis($error);
return ($error,undef);
}
- # Remove old value from table
- $status = &Apache::lonmysql::remove_from_table
- ('metadata','url',$metadata{'url'});
- if (! defined($status)) {
- $error = 'Error when removing old values from '.
- 'metadata table in LON-CAPA database.';
- &Apache::lonnet::logthis($error);
- return ($error,undef);
+ if (($metadata{'obsolete'}) || ($metadata{'copyright'} eq 'priv') ||
+ ($metadata{'copyright'} eq 'custom')) {
+# remove this entry
+ $status=&Apache::lonmysql::remove_from_table
+ ('metadata','url',$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);
}
- # Store data in table.
- $status = &Apache::lonmysql::store_row('metadata',\%metadata);
if (! defined($status)) {
$error='Error occured storing new values in '.
'metadata table in LON-CAPA database';
@@ -815,6 +836,26 @@ sub store_metadata {
return (undef,$status);
}
+
+# ============================================== Parse file itself for metadata
+#
+# parses a file with target meta, sets global %metadatafields %metadatakeys
+
+sub parseformeta {
+ my ($source,$style)=@_;
+ my $allmeta='';
+ if (($style eq 'ssi') || ($style eq 'prv')) {
+ my $dir=$source;
+ $dir=~s-/[^/]*$--;
+ my $file=$source;
+ $file=(split('/',$file))[-1];
+ $source=&Apache::lonnet::hreflocation($dir,$file);
+ $allmeta=&Apache::lonnet::ssi_body($source,('grade_target' => 'meta'));
+ &metaeval($allmeta);
+ }
+ return $allmeta;
+}
+
#########################################
#########################################
@@ -846,7 +887,7 @@ sub publish {
my %allow=();
unless ($logfile=Apache::File->new('>>'.$source.'.log')) {
- return ('No write permission to user directory, FAIL',1);
+ return (''.&mt('No write permission to user directory, FAIL').'',1);
}
print $logfile
"\n\n================= Publish ".localtime()." Phase One ================\n".$ENV{'user.name'}.'@'.$ENV{'user.domain'}."\n";
@@ -870,7 +911,7 @@ sub publish {
if ($error) { return ($outstring,$error); }
# ------------------------------------------------------------ Construct Allows
- $scrout.='Dependencies
';
+ $scrout.=''.&mt('Dependencies').'
';
my $allowstr='';
foreach (sort(keys(%allow))) {
my $thisdep=$_;
@@ -879,16 +920,16 @@ sub publish {
$allowstr.="\n".'
';
- 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'}.'/'.
$thisdep.'.meta') eq '-1') {
- $scrout.= ' - Currently not available'.
+ $scrout.= ' - '.&mt('Currently not available').
'';
} else {
my %temphash=(&Apache::lonnet::declutter($target).'___'.
@@ -904,11 +945,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.
{
@@ -927,7 +963,8 @@ sub publish {
# -------------------------------------------- Initial step done, now metadata.
# --------------------------------------- Storage for metadata keys and fields.
-
+# these are globals
+#
%metadatafields=();
%metadatakeys=();
@@ -948,9 +985,6 @@ sub publish {
$metadatafields{'author'}=~s/\s+/ /g;
$metadatafields{'author'}=~s/\s+$//;
$metadatafields{'owner'}=$cuname.'@'.$cudom;
- $metadatafields{'modifyinguser'}=$ENV{'user.name'}.'@'.
- $ENV{'user.domain'};
- $metadatafields{'authorspace'}=$cuname.'@'.$cudom;
# ------------------------------------------------ Check out directory hierachy
@@ -968,6 +1002,10 @@ sub publish {
$scrout.=&metaread($logfile,$currentpath.'default.meta',$prefix);
$prefix=~s|^\.\./||;
}
+# ----------------------------------------------------------- Parse file itself
+# read %metadatafields from file itself
+
+ $allmeta=&parseformeta($source,$style);
# ------------------- Clear out parameters and stores (there should not be any)
@@ -988,20 +1026,13 @@ sub publish {
delete $metadatafields{$_};
}
}
-
- }
+# ------------------------------------------ See if anything new in file itself
+
+ $allmeta=&parseformeta($source,$style);
-# -------------------------------------------------- Parse content for metadata
- if (($style eq 'ssi') || ($style eq 'prv')) {
- my $dir=$source;
- $dir=~s-/[^/]*$--;
- my $file=$source;
- $file=(split('/',$file))[-1];
- $source=&Apache::lonnet::hreflocation($dir,$file);
- $allmeta=&Apache::lonnet::ssi_body($source,('grade_target' => 'meta'));
+ }
- &metaeval($allmeta);
- }
+
# ---------------- Find and document discrepancies in the parameters and stores
my $chparms='';
@@ -1032,7 +1063,9 @@ sub publish {
}
if ($chparms) {
$scrout.='
'. + &mt('If this resource is in active use, student performance data from the previous version may become inaccessible.').'