--- loncom/publisher/lonpublisher.pm 2012/01/29 03:08:32 1.278
+++ loncom/publisher/lonpublisher.pm 2024/12/27 04:01:41 1.306
@@ -1,7 +1,7 @@
# The LearningOnline Network with CAPA
# Publication Handler
#
-# $Id: lonpublisher.pm,v 1.278 2012/01/29 03:08:32 raeburn Exp $
+# $Id: lonpublisher.pm,v 1.306 2024/12/27 04:01:41 raeburn Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -102,8 +102,6 @@ to publication space.
Many of the undocumented subroutines implement various magical
parsing shortcuts.
-=over 4
-
=cut
######################################################################
@@ -121,7 +119,6 @@ use HTML::LCParser;
use HTML::Entities;
use Encode::Encoder;
use Apache::lonxml;
-use Apache::loncacc;
use DBI;
use Apache::lonnet;
use Apache::loncommon();
@@ -131,13 +128,9 @@ use Apache::lonlocal;
use Apache::loncfile;
use LONCAPA::lonmetadata;
use Apache::lonmsg;
-use vars qw(%metadatafields %metadatakeys);
+use vars qw(%metadatafields %metadatakeys %addid $readit);
use LONCAPA qw(:DEFAULT :match);
-
-my %addid;
-my %nokey;
-
my $docroot;
my $cuname;
@@ -150,6 +143,8 @@ my $lock;
=pod
+=over 4
+
=item B
Evaluates a string that contains metadata. This subroutine
@@ -201,12 +196,12 @@ sub metaeval {
if (defined($token->[2]->{'name'})) {
$unikey.="\0".$token->[2]->{'name'};
}
- foreach (@{$token->[3]}) {
- $metadatafields{$unikey.'.'.$_}=$token->[2]->{$_};
+ foreach my $item (@{$token->[3]}) {
+ $metadatafields{$unikey.'.'.$item}=$token->[2]->{$item};
if ($metadatakeys{$unikey}) {
- $metadatakeys{$unikey}.=','.$_;
+ $metadatakeys{$unikey}.=','.$item;
} else {
- $metadatakeys{$unikey}=$_;
+ $metadatakeys{$unikey}=$item;
}
}
my $newentry=$parser->get_text('/'.$entry);
@@ -294,8 +289,8 @@ sub coursedependencies {
my %evaldata=&Apache::lonnet::dump('nohist_resevaldata',$adomain,
$aauthor,$regexp);
my %courses=();
- foreach (keys %evaldata) {
- if ($_=~/^([a-zA-Z0-9]+_[a-zA-Z0-9]+)___.+___course$/) {
+ foreach my $item (keys(%evaldata)) {
+ if ($item=~/^([a-zA-Z0-9]+_[a-zA-Z0-9]+)___.+___course$/) {
$courses{$1}=1;
}
}
@@ -319,8 +314,12 @@ string which presents the form field (fo
=item B
+=item B
+
=item B
+=item B
+
=item B
=back
@@ -330,7 +329,7 @@ string which presents the form field (fo
#########################################
#########################################
sub textfield {
- my ($title,$name,$value,$noline)=@_;
+ my ($title,$name,$value,$noline,$readonly)=@_;
$value=~s/^\s+//gs;
$value=~s/\s+$//gs;
$value=~s/\s+/ /gs;
@@ -342,22 +341,31 @@ sub textfield {
}
sub text_with_browse_field {
- my ($title,$name,$value,$restriction,$noline)=@_;
+ my ($title,$name,$value,$restriction,$noline,$readonly)=@_;
$value=~s/^\s+//gs;
$value=~s/\s+$//gs;
$value=~s/\s+/ /gs;
$title=&mt($title);
$env{'form.'.$name}=$value;
- return "\n".&Apache::lonhtmlcommon::row_title($title)
- .''
- .'
'
+ my $disabled;
+ if ($readonly) {
+ $disabled = ' disabled="disabled"';
+ }
+ my $output =
+ "\n".&Apache::lonhtmlcommon::row_title($title)
+ .'';
+ unless ($readonly) {
+ $output .=
+ '
'
.''
.&mt('Select')
.' '
.''
.&mt('Search')
- .''
- .&Apache::lonhtmlcommon::row_closure($noline);
+ .'';
+ }
+ $output .= &Apache::lonhtmlcommon::row_closure($noline);
+ return $output;
}
sub hiddenfield {
@@ -368,12 +376,12 @@ sub hiddenfield {
sub checkbox {
my ($name,$text)=@_;
- return "\n
');$r->rflush;
}
# ------------------------------------------------------------------- Link back
- $r->print("".&mt('Back to Metadata').'');
+ $r->print("".&mt('Back to Metadata').'');
$r->print(&Apache::loncommon::end_page());
return OK;
}
@@ -2078,7 +2578,7 @@ sub handler {
# -------------------------------------------------------------- Check filename
my $fn=&unescape($env{'form.filename'});
- ($cuname,$cudom)=&Apache::loncacc::constructaccess($fn);
+ ($cuname,$cudom)=&Apache::lonnet::constructaccess($fn);
# ----------------------------------------------------- Do we have permissions?
unless (($cuname) && ($cudom)) {
$r->log_reason($env{'user.name'}.' at '.$env{'user.domain'}.
@@ -2113,38 +2613,27 @@ sub handler {
return HTTP_NOT_FOUND;
}
-# -------------------------------- File is there and owned, init lookup tables.
-
- %addid=();
-
- {
- my $fh=Apache::File->new($r->dir_config('lonTabDir').'/addid.tab');
- while (<$fh>=~/(\w+)\s+(\w+)/) {
- $addid{$1}=$2;
- }
- }
-
- %nokey=();
-
- {
- my $fh=Apache::File->new($r->dir_config('lonIncludes').'/un_keyword.tab');
- while (<$fh>) {
- my $word=$_;
- chomp($word);
- $nokey{$word}=1;
- }
- }
-
-# ---------------------------------------------------------- Start page output.
+# --------------------------------- File is there and owned, start page output
&Apache::loncommon::content_type($r,'text/html');
$r->send_http_header;
-
+
# Breadcrumbs
&Apache::lonhtmlcommon::clear_breadcrumbs();
+ my $crumbtext = 'Authoring Space';
+ my $crumbhref = &Apache::loncommon::authorspace($fn);
+ my $crsauthor;
+ if ($env{'request.course.id'}) {
+ my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
+ my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
+ if ($crumbhref eq "/priv/$cdom/$cnum/") {
+ $crumbtext = 'Course Authoring Space';
+ $crsauthor = 1;
+ }
+ }
&Apache::lonhtmlcommon::add_breadcrumb({
- 'text' => 'Construction Space',
- 'href' => &Apache::loncommon::authorspace($fn),
+ 'text' => $crumbtext,
+ 'href' => $crumbhref,
});
&Apache::lonhtmlcommon::add_breadcrumb({
'text' => 'Resource Publication',
@@ -2154,7 +2643,53 @@ sub handler {
my $js='';
- $r->print(&Apache::loncommon::start_page('Resource Publication',$js)
+ my $startargs = {};
+ if ($fn=~/\/$/) {
+ unless ($env{'form.phase'} eq 'two') {
+ $startargs->{'add_entries'} = { onload => 'javascript:setDefaultAccess();' };
+ $js .= <<"END";
+
+
+END
+ }
+ }
+ $r->print(&Apache::loncommon::start_page('Resource Publication',$js,$startargs)
.&Apache::lonhtmlcommon::breadcrumbs()
.&Apache::loncommon::head_subbox(
&Apache::loncommon::CSTR_pageheader($docroot.$fn))
@@ -2164,11 +2699,15 @@ sub handler {
my $thistarget=$fn;
$thistarget=~s/^\/priv\//\/res\//;
my $thisdistarget=&HTML::Entities::encode($thistarget,'<>&"');
+ my $nokeyref = &getnokey($r->dir_config('lonIncludes'));
if ($fn=~/\/$/) {
# -------------------------------------------------------- This is a directory
- &publishdirectory($r,$docroot.$fn,$thisdisfn);
- $r->print('
'.&mt('Return to Directory').'');
+ &publishdirectory($r,$docroot.$fn,$thisdisfn,$nokeyref,$crsauthor);
+ $r->print(
+ '
'.
+ &Apache::lonhtmlcommon::actionbox([
+ ''.&mt('Return to Directory').'']));
} else {
# ---------------------- Evaluate individual file, and then output information.
$fn=~/\.(\w+)$/;
@@ -2218,7 +2757,7 @@ ENDCAPTION
$r->print(&Apache::lonhtmlcommon::row_closure()
.&Apache::lonhtmlcommon::row_title(&mt('Diffs')));
$r->print(<
+
ENDDIFF
$r->print(&mt('Diffs with Current Version').'');
}
@@ -2237,7 +2776,7 @@ ENDDIFF
}
unless ($errorcount) {
my ($outstring,$error)=
- &publish($docroot.$fn,$docroot.$thistarget,$thisembstyle);
+ &publish($docroot.$fn,$docroot.$thistarget,$thisembstyle,undef,$nokeyref);
$r->print($outstring);
} else {
$r->print(''.
@@ -2245,7 +2784,9 @@ ENDDIFF
'
');
}
} else {
- &phasetwo($r,$docroot.$fn,$docroot.$thistarget,$thisembstyle,$thisdistarget);
+ my ($output,$error) = &phasetwo($r,$docroot.$fn,$docroot.$thistarget,
+ $thisembstyle,$thisdistarget);
+ $r->print($output);
}
}
$r->print(&Apache::loncommon::end_page());
@@ -2253,6 +2794,24 @@ ENDDIFF
return OK;
}
+BEGIN {
+
+# ----------------------------------- Read addid.tab
+ unless ($readit) {
+ %addid=();
+
+ {
+ my $tabdir = $Apache::lonnet::perlvar{'lonTabDir'};
+ my $fh=Apache::File->new($tabdir.'/addid.tab');
+ while (<$fh>=~/(\w+)\s+(\w+)/) {
+ $addid{$1}=$2;
+ }
+ }
+ }
+ $readit=1;
+}
+
+
1;
__END__
@@ -2260,7 +2819,5 @@ __END__
=back
-=back
-
=cut