--- loncom/publisher/lonpublisher.pm 2003/12/26 18:25:29 1.151
+++ loncom/publisher/lonpublisher.pm 2004/04/14 18:29:32 1.166
@@ -1,7 +1,7 @@
# The LearningOnline Network with CAPA
# Publication Handler
#
-# $Id: lonpublisher.pm,v 1.151 2003/12/26 18:25:29 www Exp $
+# $Id: lonpublisher.pm,v 1.166 2004/04/14 18:29:32 matthew Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -126,6 +126,8 @@ use Apache::loncommon();
use Apache::lonmysql;
use Apache::lonlocal;
use Apache::loncfile;
+use LONCAPA::lonmetadata;
+use Apache::lonmsg;
use vars qw(%metadatafields %metadatakeys);
my %addid;
@@ -202,7 +204,11 @@ sub metaeval {
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;
+ }
}
}
}
@@ -316,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:".
"
".
' ';
}
@@ -330,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$uctitle:".
+ my $selout="\n $title:".
'
';
foreach (@idlist) {
$selout.='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);
+ }
if (! defined($status)) {
$error='Error occured storing new values in '.
'metadata table in LON-CAPA database ';
@@ -878,11 +920,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'}.'/'.
@@ -903,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.
{
@@ -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
@@ -995,6 +1029,7 @@ sub publish {
# ------------------------------------------ See if anything new in file itself
$allmeta=&parseformeta($source,$style);
+
}
@@ -1076,7 +1111,7 @@ sub publish {
# --------------------------------------------------- Scan content for keywords
my $keywords_help = Apache::loncommon::help_open_topic("Publishing_Keywords");
- my $KEYWORDS=&mt('KEYWORDS');
+ my $KEYWORDS=&mt('Keywords');
my $CheckAll=&mt('check all');
my $UncheckAll=&mt('uncheck all');
my $keywordout=<<"END";
@@ -1127,7 +1162,7 @@ END
$scrout.=&textfield('Notes','notes',$metadatafields{'notes'});
$scrout.=
- "\n".&mt('ABSTRACT').":".
+ "\n ".&mt('Abstract').":".
"
".
'
';
@@ -1137,11 +1172,11 @@ END
$scrout.=
"\n".
- uc(&mt('Lowest Grade Level:')).
+ &mt('Lowest Grade Level').':'.
"
".
&Apache::loncommon::select_level_form($metadatafields{'lowestgradelevel'},'lowestgradelevel').
"\n".
- uc(&mt('Highest Grade Level:')).
+ &mt('Highest Grade Level').':'.
"
".
&Apache::loncommon::select_level_form($metadatafields{'highestgradelevel'},'highestgradelevel').
&textfield('Standards','standards',$metadatafields{'standards'});
@@ -1166,7 +1201,7 @@ END
$metadatafields{'creationdate'}=time;
}
$scrout.=&hiddenfield('creationdate',
- &Apache::loncommon::unsqltime($metadatafields{'creationdate'}));
+ &Apache::lonmysql::unsqltime($metadatafields{'creationdate'}));
$scrout.=&hiddenfield('lastrevisiondate',time);
@@ -1200,7 +1235,7 @@ END
$scrout.=&textfield('Custom Distribution File','customdistributionfile',
$metadatafields{'customdistributionfile'}).
$copyright_help;
- my $uctitle=uc(&mt('Obsolete'));
+ my $uctitle=&mt('Obsolete');
$scrout.=
"\n$uctitle:".
' '.
- &HTML::Entities::encode($metadatafields{$unikey})
+ &HTML::Entities::encode($metadatafields{$unikey},'<>&"')
.''.$tag.'>';
}
}
@@ -1385,21 +1426,19 @@ sub phasetwo {
$metadatafields{'url'} = $distarget;
$metadatafields{'version'} = 'current';
- unless ($metadatafields{'copyright'} eq 'priv') {
- my ($error,$success) = &store_metadata(\%metadatafields);
- if ($success) {
- $r->print('
'.&mt('Synchronized SQL metadata database').'
');
- print $logfile "\nSynchronized SQL metadata database";
- } else {
- $r->print($error);
- print $logfile "\n".$error;
- }
+
+ my ($error,$success) = &store_metadata(%metadatafields);
+ if ($success) {
+ $r->print(''.&mt('Synchronized SQL metadata database').'
');
+ print $logfile "\nSynchronized SQL metadata database";
} else {
- $r->print(''.
- &mt('Private Publication - did not synchronize database').'
');
- print $logfile "\nPrivate: Did not synchronize data into ".
- "SQL metadata database";
+ $r->print($error);
+ print $logfile "\n".$error;
}
+# --------------------------------------------- Delete author resource messages
+ my $delresult=&Apache::lonmsg::del_url_author_res_msg($target);
+ $r->print(''.&mt('Removing error messages:').' '.$delresult.'
');
+ print $logfile "\nRemoving error messages: $delresult";
# ----------------------------------------------------------- Copy old versions
if (-e $target) {
@@ -1612,8 +1651,8 @@ sub publishdirectory {
my $resdir=
$Apache::lonnet::perlvar{'lonDocRoot'}.'/res/'.$cudom.'/'.$cuname.'/'.
$thisdisfn;
- $r->print('Directory '.$thisdisfn.' '.
- 'Target: '.$resdir.' ');
+ $r->print(''.&mt('Directory').' '.$thisdisfn.' '.
+ &mt('Target').': '.$resdir.' ');
my $dirptr=16384; # Mask indicating a directory in stat.cmode.
@@ -1651,13 +1690,70 @@ sub publishdirectory {
if ($publishthis) {
&batchpublish($r,$fn.'/'.$filename,$resdir.'/'.$filename);
} else {
- $r->print(' Skipping '.$filename.' ');
+ $r->print(' '.&mt('Skipping').' '.$filename.' ');
}
$r->rflush();
}
}
closedir(DIR);
}
+
+#########################################
+# publish a default.meta file
+
+sub defaultmetapublish {
+ my ($r,$fn,$cuname,$cudom)=@_;
+ $fn=~s/^\/\~$cuname\//\/home\/$cuname\/public_html\//;
+ unless (-e $fn) {
+ return HTTP_NOT_FOUND;
+ }
+ my $target=$fn;
+ $target=~s/^\/home\/$cuname\/public_html\//$Apache::lonnet::perlvar{'lonDocRoot'}\/res\/$cudom\/$cuname\//;
+
+
+ &Apache::loncommon::content_type($r,'text/html');
+ $r->send_http_header;
+
+ $r->print('LON-CAPA Publishing ');
+ $r->print(&Apache::loncommon::bodytag('Catalog Information Publication'));
+
+# ---------------------------------------------------------------- Write Source
+ my $copyfile=$target;
+
+ my @parts=split(/\//,$copyfile);
+ my $path="/$parts[1]/$parts[2]/$parts[3]/$parts[4]";
+
+ my $count;
+ for ($count=5;$count<$#parts;$count++) {
+ $path.="/$parts[$count]";
+ if ((-e $path)!=1) {
+ $r->print(''.&mt('Created directory').' '.$parts[$count].'
');
+ mkdir($path,0777);
+ }
+ }
+
+ if (copy($fn,$copyfile)) {
+ $r->print(''.&mt('Copied source file').'
');
+ } else {
+ return "".
+ &mt('Failed to copy source').", $!, ".&mt('FAIL')." ";
+ }
+
+# --------------------------------------------------- Send update notifications
+
+ my @subscribed=&get_subscribed_hosts($target);
+ foreach my $subhost (@subscribed) {
+ $r->print(''.&mt('Notifying host').' '.$subhost.':');$r->rflush;
+ my $reply=&Apache::lonnet::critical('update:'.$target,$subhost);
+ $r->print($reply.'
');$r->rflush;
+ }
+# ------------------------------------------------------------------- Link back
+ my $link=$fn;
+ $link=~s/^\/home\/$cuname\/public_html\//\/priv\/$cuname\//;
+ $r->print("".&mt('Back to Catalog Information').' ');
+ $r->print('