version 1.175, 2004/07/03 03:32:30
|
version 1.191, 2005/04/04 23:55:17
|
Line 138 my $docroot;
|
Line 138 my $docroot;
|
my $cuname; |
my $cuname; |
my $cudom; |
my $cudom; |
|
|
|
my $registered_cleanup; |
|
my $modified_urls; |
|
|
=pod |
=pod |
|
|
=item B<metaeval> |
=item B<metaeval> |
Line 329 sub textfield {
|
Line 332 sub textfield {
|
'<input type="text" name="'.$name.'" size=80 value="'.$value.'" />'; |
'<input type="text" name="'.$name.'" size=80 value="'.$value.'" />'; |
} |
} |
|
|
|
sub text_with_browse_field { |
|
my ($title,$name,$value,$restriction)=@_; |
|
$value=~s/^\s+//gs; |
|
$value=~s/\s+$//gs; |
|
$value=~s/\s+/ /gs; |
|
$title=&mt($title); |
|
$ENV{'form.'.$name}=$value; |
|
return "\n<p><font color=\"#800000\" face=\"helvetica\"><b>$title:". |
|
"</b></font></p><br />". |
|
'<input type="text" name="'.$name.'" size=80 value="'.$value.'" />'. |
|
'<a href="javascript:openbrowser(\'pubform\',\''.$name.'\',\''.$restriction.'\');">Select</a> '. |
|
'<a href="javascript:opensearcher(\'pubform\',\''.$name.'\');">Search</a>'; |
|
|
|
} |
|
|
sub hiddenfield { |
sub hiddenfield { |
my ($name,$value)=@_; |
my ($name,$value)=@_; |
$ENV{'form.'.$name}=$value; |
$ENV{'form.'.$name}=$value; |
Line 472 sub get_subscribed_hosts {
|
Line 490 sub get_subscribed_hosts {
|
while ($filename=readdir(DIR)) { |
while ($filename=readdir(DIR)) { |
if ($filename=~/\Q$srcf\E\.(\w+)$/) { |
if ($filename=~/\Q$srcf\E\.(\w+)$/) { |
my $subhost=$1; |
my $subhost=$1; |
if (($subhost ne 'meta' && $subhost ne 'subscription') && |
if (($subhost ne 'meta' && $subhost ne 'subscription' && |
|
$subhost ne 'tmp') && |
($subhost ne $Apache::lonnet::perlvar{'lonHostID'})) { |
($subhost ne $Apache::lonnet::perlvar{'lonHostID'})) { |
push(@subscribed,$subhost); |
push(@subscribed,$subhost); |
} |
} |
Line 529 sub get_max_ids_indices {
|
Line 548 sub get_max_ids_indices {
|
my $counter; |
my $counter; |
if ($counter=$addid{$token->[1]}) { |
if ($counter=$addid{$token->[1]}) { |
if ($counter eq 'id') { |
if ($counter eq 'id') { |
if (defined($token->[2]->{'id'})) { |
if (defined($token->[2]->{'id'}) && |
|
$token->[2]->{'id'} !~ /^\s*$/) { |
$maxid=($token->[2]->{'id'}>$maxid)?$token->[2]->{'id'}:$maxid; |
$maxid=($token->[2]->{'id'}>$maxid)?$token->[2]->{'id'}:$maxid; |
if (exists($allids{$token->[2]->{'id'}})) { |
if (exists($allids{$token->[2]->{'id'}})) { |
$duplicateids=1; |
$duplicateids=1; |
Line 541 sub get_max_ids_indices {
|
Line 561 sub get_max_ids_indices {
|
$needsfixup=1; |
$needsfixup=1; |
} |
} |
} else { |
} else { |
if (defined($token->[2]->{'index'})) { |
if (defined($token->[2]->{'index'}) && |
|
$token->[2]->{'index'} !~ /^\s*$/) { |
$maxindex=($token->[2]->{'index'}>$maxindex)?$token->[2]->{'index'}:$maxindex; |
$maxindex=($token->[2]->{'index'}>$maxindex)?$token->[2]->{'index'}:$maxindex; |
} else { |
} else { |
$needsfixup=1; |
$needsfixup=1; |
Line 583 sub get_all_text_unbalanced {
|
Line 604 sub get_all_text_unbalanced {
|
} elsif ($token->[0] eq 'E') { |
} elsif ($token->[0] eq 'E') { |
$result.=$token->[2]; |
$result.=$token->[2]; |
} |
} |
if ($result =~ /(.*)\Q$tag\E(.*)/s) { |
if ($result =~ /\Q$tag\E/s) { |
|
($result,my $redo)=$result =~ /(.*)\Q$tag\E(.*)/is; |
#&Apache::lonnet::logthis('Got a winner with leftovers ::'.$2); |
#&Apache::lonnet::logthis('Got a winner with leftovers ::'.$2); |
#&Apache::lonnet::logthis('Result is :'.$1); |
#&Apache::lonnet::logthis('Result is :'.$1); |
$result=$1; |
$redo=$tag.$redo; |
my $redo=$tag.$2; |
|
push (@$pars,HTML::LCParser->new(\$redo)); |
push (@$pars,HTML::LCParser->new(\$redo)); |
$$pars[-1]->xml_mode('1'); |
$$pars[-1]->xml_mode('1'); |
last; |
last; |
Line 655 sub fix_ids_and_indices {
|
Line 676 sub fix_ids_and_indices {
|
if (!$counter) { $counter=$addid{$lctag}; } |
if (!$counter) { $counter=$addid{$lctag}; } |
if ($counter) { |
if ($counter) { |
if ($counter eq 'id') { |
if ($counter eq 'id') { |
unless (defined($parms{'id'})) { |
unless (defined($parms{'id'}) && |
|
$parms{'id'}!~/^\s*$/) { |
$maxid++; |
$maxid++; |
$parms{'id'}=$maxid; |
$parms{'id'}=$maxid; |
print $logfile 'ID: '.$tag.':'.$maxid."\n"; |
print $logfile 'ID: '.$tag.':'.$maxid."\n"; |
} |
} |
} elsif ($counter eq 'index') { |
} elsif ($counter eq 'index') { |
unless (defined($parms{'index'})) { |
unless (defined($parms{'index'}) && |
|
$parms{'index'}!~/^\s*$/) { |
$maxindex++; |
$maxindex++; |
$parms{'index'}=$maxindex; |
$parms{'index'}=$maxindex; |
print $logfile 'Index: '.$tag.':'.$maxindex."\n"; |
print $logfile 'Index: '.$tag.':'.$maxindex."\n"; |
Line 823 sub store_metadata {
|
Line 846 sub store_metadata {
|
} |
} |
|
|
|
|
|
# ========================================== Parse file for errors and warnings |
|
|
|
sub checkonthis { |
|
my ($r,$source)=@_; |
|
my $uri=&Apache::lonnet::hreflocation($source); |
|
$uri=~s/\/$//; |
|
my $result=&Apache::lonnet::ssi_body($uri, |
|
('grade_target'=>'web', |
|
'return_only_error_and_warning_counts' => 1)); |
|
my ($errorcount,$warningcount)=split(':',$result); |
|
if (($errorcount) || ($warningcount)) { |
|
$r->print('<br /><tt>'.$uri.'</tt>: '); |
|
if ($errorcount) { |
|
$r->print('<img src="/adm/lonMisc/bomb.gif" /><font color="red"><b>'. |
|
$errorcount.' '. |
|
&mt('error(s)').'</b></font> '); |
|
} |
|
if ($warningcount) { |
|
$r->print('<font color="blue">'. |
|
$warningcount.' '. |
|
&mt('warning(s)').'</font>'); |
|
} |
|
} else { |
|
#$r->print('<font color="green">'.&mt('ok').'</font>'); |
|
} |
|
$r->rflush(); |
|
return ($warningcount,$errorcount); |
|
} |
|
|
# ============================================== Parse file itself for metadata |
# ============================================== Parse file itself for metadata |
# |
# |
# parses a file with target meta, sets global %metadatafields %metadatakeys |
# parses a file with target meta, sets global %metadatafields %metadatakeys |
Line 988 sub publish {
|
Line 1040 sub publish {
|
$scrout.=&metaread($logfile,$currentpath.'default.meta',$prefix); |
$scrout.=&metaread($logfile,$currentpath.'default.meta',$prefix); |
$prefix=~s|^\.\./||; |
$prefix=~s|^\.\./||; |
} |
} |
|
|
# ----------------------------------------------------------- Parse file itself |
# ----------------------------------------------------------- Parse file itself |
# read %metadatafields from file itself |
# read %metadatafields from file itself |
|
|
Line 1131 END
|
Line 1184 END
|
my $colcount=0; |
my $colcount=0; |
|
|
foreach (sort keys %keywords) { |
foreach (sort keys %keywords) { |
$keywordout.='<td><input type="checkbox" name="keywords" value="'.$_.'"'; |
$keywordout.='<td><label><input type="checkbox" name="keywords" value="'.$_.'"'; |
if ($metadatafields{'keywords'}) { |
if ($metadatafields{'keywords'}) { |
if ($metadatafields{'keywords'}=~/\Q$_\E/) { |
if ($metadatafields{'keywords'}=~/\Q$_\E/) { |
$keywordout.=' checked="on"'; |
$keywordout.=' checked="on"'; |
Line 1141 END
|
Line 1194 END
|
$keywordout.=' checked="on"'; |
$keywordout.=' checked="on"'; |
$ENV{'form.keywords'}.=$_.','; |
$ENV{'form.keywords'}.=$_.','; |
} |
} |
$keywordout.=' />'.$_.'</td>'; |
$keywordout.=' />'.$_.'</label></td>'; |
if ($colcount>10) { |
if ($colcount>10) { |
$keywordout.="</tr><tr>\n"; |
$keywordout.="</tr><tr>\n"; |
$colcount=0; |
$colcount=0; |
Line 1236 END
|
Line 1289 END
|
} |
} |
my $copyright_help = |
my $copyright_help = |
Apache::loncommon::help_open_topic('Publishing_Copyright'); |
Apache::loncommon::help_open_topic('Publishing_Copyright'); |
$intr_scrout =~ s/DISTRIBUTION:/'DISTRIBUTION: ' . $copyright_help/ge; |
$intr_scrout =~ s/Distribution:/'Distribution: ' . $copyright_help/ge; |
$intr_scrout.=&textfield('Custom Distribution File','customdistributionfile', |
$intr_scrout.=&text_with_browse_field('Custom Distribution File','customdistributionfile',$metadatafields{'customdistributionfile'},'rights').$copyright_help; |
$metadatafields{'customdistributionfile'}). |
|
$copyright_help; |
|
$intr_scrout.=&selectbox('Source Distribution','sourceavail', |
$intr_scrout.=&selectbox('Source Distribution','sourceavail', |
$defaultsourceoption, |
$defaultsourceoption, |
\&Apache::loncommon::source_copyrightdescription, |
\&Apache::loncommon::source_copyrightdescription, |
(&Apache::loncommon::source_copyrightids)); |
(&Apache::loncommon::source_copyrightids)); |
$intr_scrout.=&textfield('Source Custom Distribution File','sourcerights', |
$intr_scrout.=&text_with_browse_field('Source Custom Distribution File','sourcerights',$metadatafields{'sourcerights'},'rights'); |
$metadatafields{'sourcerights'}); |
|
my $uctitle=&mt('Obsolete'); |
my $uctitle=&mt('Obsolete'); |
$intr_scrout.= |
$intr_scrout.= |
"\n<p><font color=\"#800000\" face=\"helvetica\"><b>$uctitle:". |
"\n<p><font color=\"#800000\" face=\"helvetica\"><b>$uctitle:". |
Line 1254 END
|
Line 1304 END
|
$intr_scrout.=' checked="1" '; |
$intr_scrout.=' checked="1" '; |
} |
} |
$intr_scrout.='/ ></p>'. |
$intr_scrout.='/ ></p>'. |
&textfield('Suggested Replacement for Obsolete File', |
&text_with_browse_field('Suggested Replacement for Obsolete File', |
'obsoletereplacement', |
'obsoletereplacement', |
$metadatafields{'obsoletereplacement'}); |
$metadatafields{'obsoletereplacement'}); |
} else { |
} else { |
$intr_scrout.=&hiddenfield('copyright','private'); |
$intr_scrout.=&hiddenfield('copyright','private'); |
} |
} |
Line 1528 sub phasetwo {
|
Line 1578 sub phasetwo {
|
"<font color=\"red\">".&mt('Failed to write metadata copy').", $!, ".&mt('FAIL')."</font>"; |
"<font color=\"red\">".&mt('Failed to write metadata copy').", $!, ".&mt('FAIL')."</font>"; |
} |
} |
$r->rflush; |
$r->rflush; |
# --------------------------------------------------- Send update notifications |
|
|
|
my @subscribed=&get_subscribed_hosts($target); |
# ------------------------------------------------------------- Trigger updates |
foreach my $subhost (@subscribed) { |
push(@{$modified_urls},[$target,$source]); |
$r->print('<p>'.&mt('Notifying host').' '.$subhost.':');$r->rflush; |
unless ($registered_cleanup) { |
print $logfile "\nNotifying host ".$subhost.':'; |
$r->register_cleanup(\¬ify); |
my $reply=&Apache::lonnet::critical('update:'.$target,$subhost); |
$registered_cleanup=1; |
$r->print($reply.'</p><br />');$r->rflush; |
|
print $logfile $reply; |
|
} |
|
|
|
# ---------------------------------------- Send update notifications, meta only |
|
|
|
my @subscribedmeta=&get_subscribed_hosts("$target.meta"); |
|
foreach my $subhost (@subscribedmeta) { |
|
$r->print('<p>'. |
|
&mt('Notifying host for metadata only').' '.$subhost.':');$r->rflush; |
|
print $logfile "\nNotifying host for metadata only ".$subhost.':'; |
|
my $reply=&Apache::lonnet::critical('update:'.$target.'.meta', |
|
$subhost); |
|
$r->print($reply.'</p><br />');$r->rflush; |
|
print $logfile $reply; |
|
} |
|
|
|
# --------------------------------------------------- Notify subscribed courses |
|
my %courses=&coursedependencies($target); |
|
my $now=time; |
|
foreach (keys %courses) { |
|
$r->print('<p>'.&mt('Notifying course').' '.$_.':');$r->rflush; |
|
print $logfile "\nNotifying host ".$_.':'; |
|
my ($cdom,$cname)=split(/\_/,$_); |
|
my $reply=&Apache::lonnet::cput |
|
('versionupdate',{$target => $now},$cdom,$cname); |
|
$r->print($reply.'</p><br />');$r->rflush; |
|
print $logfile $reply; |
|
} |
} |
# ------------------------------------------------ Provide link to new resource |
# ------------------------------------------------ Provide link to new resource |
unless ($batch) { |
unless ($batch) { |
Line 1585 sub phasetwo {
|
Line 1606 sub phasetwo {
|
'"><font size="+2">'. |
'"><font size="+2">'. |
&mt('Back to Source Directory').'</font></a></p>'); |
&mt('Back to Source Directory').'</font></a></p>'); |
} |
} |
|
$logfile->close(); |
return '<p><font color="green">'.&mt('Done').'</font></p>'; |
return '<p><font color="green">'.&mt('Done').'</font></p>'; |
} |
} |
|
|
|
# =============================================================== Notifications |
|
sub notify { |
|
# --------------------------------------------------- Send update notifications |
|
foreach my $targetsource (@{$modified_urls}){ |
|
my ($target,$source)=@{$targetsource}; |
|
my $logfile=Apache::File->new('>>'.$source.'.log'); |
|
print $logfile "\nCleanup phase: Notifications\n"; |
|
my @subscribed=&get_subscribed_hosts($target); |
|
foreach my $subhost (@subscribed) { |
|
print $logfile "\nNotifying host ".$subhost.':'; |
|
my $reply=&Apache::lonnet::critical('update:'.$target,$subhost); |
|
print $logfile $reply; |
|
} |
|
# ---------------------------------------- Send update notifications, meta only |
|
my @subscribedmeta=&get_subscribed_hosts("$target.meta"); |
|
foreach my $subhost (@subscribedmeta) { |
|
print $logfile "\nNotifying host for metadata only ".$subhost.':'; |
|
my $reply=&Apache::lonnet::critical('update:'.$target.'.meta', |
|
$subhost); |
|
print $logfile $reply; |
|
} |
|
# --------------------------------------------------- Notify subscribed courses |
|
my %courses=&coursedependencies($target); |
|
my $now=time; |
|
foreach (keys %courses) { |
|
print $logfile "\nNotifying course ".$_.':'; |
|
my ($cdom,$cname)=split(/\_/,$_); |
|
my $reply=&Apache::lonnet::cput |
|
('versionupdate',{$target => $now},$cdom,$cname); |
|
print $logfile $reply; |
|
} |
|
print $logfile "\n============ Done ============\n"; |
|
$logfile->close(); |
|
} |
|
return OK; |
|
} |
|
|
######################################### |
######################################### |
|
|
sub batchpublish { |
sub batchpublish { |
Line 1668 sub publishdirectory {
|
Line 1727 sub publishdirectory {
|
$ruid,$rgid,$rrdev,$rsize, |
$ruid,$rgid,$rrdev,$rsize, |
$ratime,$rmtime,$rctime, |
$ratime,$rmtime,$rctime, |
$rblksize,$rblocks)=stat($resdir.'/'.$filename); |
$rblksize,$rblocks)=stat($resdir.'/'.$filename); |
if (($rmtime<$cmtime) || ($ENV{'form.forcerepub'})) { |
if (($rmtime<$cmtime) || ($ENV{'form.forcerepub'} eq 'ON')) { |
# previously published, modified now |
# previously published, modified now |
$publishthis=1; |
$publishthis=1; |
} |
} |
Line 1797 sub handler {
|
Line 1856 sub handler {
|
&Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'}, |
&Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'}, |
['filename']); |
['filename']); |
|
|
|
# -------------------------------------- Flag and buffer for registered cleanup |
|
$registered_cleanup=0; |
|
@{$modified_urls}=(); |
# -------------------------------------------------------------- Check filename |
# -------------------------------------------------------------- Check filename |
|
|
my $fn=&Apache::lonnet::unescape($ENV{'form.filename'}); |
my $fn=&Apache::lonnet::unescape($ENV{'form.filename'}); |
Line 1890 sub handler {
|
Line 1952 sub handler {
|
|
|
&Apache::loncommon::content_type($r,'text/html'); |
&Apache::loncommon::content_type($r,'text/html'); |
$r->send_http_header; |
$r->send_http_header; |
|
|
$r->print('<html><head><title>LON-CAPA Publishing</title></head>'); |
my $js=&Apache::loncommon::browser_and_searcher_javascript(); |
|
$r->print('<html><head><title>LON-CAPA Publishing</title> |
|
<script type="text/javascript">'.$js.' |
|
</script></head>'); |
$r->print(&Apache::loncommon::bodytag('Resource Publication')); |
$r->print(&Apache::loncommon::bodytag('Resource Publication')); |
|
|
|
|
Line 1947 ENDDIFF
|
Line 2012 ENDDIFF
|
# ------------------ Publishing from $thisfn to $thistarget with $thisembstyle. |
# ------------------ Publishing from $thisfn to $thistarget with $thisembstyle. |
|
|
unless ($ENV{'form.phase'} eq 'two') { |
unless ($ENV{'form.phase'} eq 'two') { |
my ($outstring,$error)=&publish($thisfn,$thistarget,$thisembstyle); |
# ---------------------------------------------------------- Parse for problems |
$r->print('<hr />'.$outstring); |
my ($warningcount,$errorcount); |
|
if ($thisembstyle eq 'ssi') { |
|
($warningcount,$errorcount)=&checkonthis($r,$thisfn); |
|
} |
|
unless ($errorcount) { |
|
my ($outstring,$error)= |
|
&publish($thisfn,$thistarget,$thisembstyle); |
|
$r->print('<hr />'.$outstring); |
|
} else { |
|
$r->print('<h3>'. |
|
&mt('The document contains errors and cannot be published.'). |
|
'</h3>'); |
|
} |
} else { |
} else { |
$r->print('<hr />'. |
$r->print('<hr />'. |
&phasetwo($r,$thisfn,$thistarget,$thisembstyle,$thisdistarget)); |
&phasetwo($r,$thisfn,$thistarget,$thisembstyle,$thisdistarget)); |