--- loncom/interface/londocs.pm 2018/04/29 17:33:52 1.484.2.72.2.5
+++ loncom/interface/londocs.pm 2020/07/20 10:39:57 1.484.2.85.2.4
@@ -1,7 +1,7 @@
# The LearningOnline Network
# Documents
#
-# $Id: londocs.pm,v 1.484.2.72.2.5 2018/04/29 17:33:52 raeburn Exp $
+# $Id: londocs.pm,v 1.484.2.85.2.4 2020/07/20 10:39:57 raeburn Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -43,6 +43,7 @@ use Apache::lonnavdisplay();
use Apache::lonextresedit();
use Apache::lontemplate();
use Apache::lonsimplepage();
+use Apache::loncourserespicker();
use HTML::Entities;
use HTML::TokeParser;
use GDBM_File;
@@ -656,7 +657,7 @@ sub group_import {
my $marker = $2;
my $info = $3;
my ($toolid,%toolhash,%toolsettings);
- my @extras = ('linktext','explanation','crslabel','crstitle');
+ my @extras = ('linktext','explanation','crslabel','crstitle');
my @toolinfo = split(/:/,$info);
if ($residx) {
%toolsettings=&Apache::lonnet::dump('exttool_'.$marker,$coursedom,$coursenum);
@@ -940,7 +941,7 @@ sub docs_change_log {
'// '."\n".
@@ -1165,29 +1166,47 @@ sub update_paste_buffer {
# Construct identifiers for current contents of user's paste buffer
if (@currpaste) {
foreach my $suffix (@currpaste) {
- my $cid = $env{'docs.markedcopy_crs_'.$suffix};
- my $url = $env{'docs.markedcopy_url_'.$suffix};
- if (($cid =~ /^$match_domain(?:_)$match_courseid$/) &&
- ($url ne '')) {
- $pasteurls{$cid.'_'.$url} = 1;
- }
+ my $cid = $env{'docs.markedcopy_crs_'.$suffix};
+ my $url = $env{'docs.markedcopy_url_'.$suffix};
+ my $mapidx = $env{'docs.markedcopy_map_'.$suffix};
+ if (($cid =~ /^$match_domain(?:_)$match_courseid$/) &&
+ ($url ne '')) {
+ if ($url eq '/res/lib/templates/simpleproblem.problem') {
+ $pasteurls{$cid.'_'.$mapidx} = 1;
+ } elsif ($url =~ m{^/res/$match_domain/$match_username/}) {
+ $pasteurls{$url} = 1;
+ } else {
+ $pasteurls{$cid.'_'.$url} = 1;
+ }
+ }
}
}
# Mark items for copying (skip any items already in user's paste buffer)
my %addtoenv;
-
+
+ my @pathitems = split(/\&/,$env{'form.folderpath'});
+ my @folderconf = split(/\:/,$pathitems[-1]);
+ my $ispage = $folderconf[5];
+
foreach my $item (@possibles) {
my ($orderidx,$cmd) = split(/:/,$item);
next if ($orderidx =~ /\D/);
next unless (($cmd eq 'cut') || ($cmd eq 'copy') || ($cmd eq 'remove'));
+ my $mapidx = $folder.':'.$orderidx.':'.$ispage;
my ($title,$url)=split(':',$LONCAPA::map::resources[$orderidx]);
my %denied = &action_restrictions($coursenum,$coursedom,
&LONCAPA::map::qtescape($url),
$env{'form.folderpath'},\%curr_groups);
next if ($denied{'copy'});
$url=~s{http(:|:)//https(:|:)//}{https$2//};
- next if (exists($pasteurls{$coursedom.'_'.$coursenum.'_'.$url}));
+ if ($url eq '/res/lib/templates/simpleproblem.problem') {
+ next if (exists($pasteurls{$coursedom.'_'.$coursenum.'_'.$mapidx}));
+ } elsif ($url =~ m{^/res/$match_domain/$match_username/}) {
+ next if (exists($pasteurls{$url}));
+ } else {
+ next if (exists($pasteurls{$coursedom.'_'.$coursenum.'_'.$url}));
+ }
my ($suffix,$errortxt,$locknotfreed) =
&new_timebased_suffix($env{'user.domain'},$env{'user.name'},'paste');
if ($suffix ne '') {
@@ -1206,7 +1225,7 @@ sub update_paste_buffer {
$addtoenv{'docs.markedcopy_url_'.$suffix} = $url,
$addtoenv{'docs.markedcopy_cmd_'.$suffix} = $cmd,
$addtoenv{'docs.markedcopy_crs_'.$suffix} = $env{'request.course.id'};
-
+ $addtoenv{'docs.markedcopy_map_'.$suffix} = $mapidx;
if ($url =~ m{^/uploaded/$match_domain/$match_courseid/(default|supplemental)_?(\d*)\.(page|sequence)$}) {
my $prefix = $1;
my $subdir =$2;
@@ -1284,6 +1303,7 @@ sub print_paste_buffer {
next if ($suffix =~ /\D/);
my $cid = $env{'docs.markedcopy_crs_'.$suffix};
my $url = $env{'docs.markedcopy_url_'.$suffix};
+ my $mapidx = $env{'docs.markedcopy_map_'.$suffix};
if (($cid =~ /^$match_domain\_$match_courseid$/) &&
($url ne '')) {
$clipboardcount ++;
@@ -1342,12 +1362,12 @@ sub print_paste_buffer {
}
}
}
- }
- if ($canpaste) {
- push(@pasteable,$suffix);
+ if ($canpaste) {
+ push(@pasteable,$suffix);
+ }
}
my $buffer;
- if ($is_external) {
+ if ($is_external) {
$buffer = &mt('External Resource').': '.
&LONCAPA::map::qtescape($env{'docs.markedcopy_title_'.$suffix}).' ('.
&LONCAPA::map::qtescape($url).')';
@@ -1634,11 +1654,12 @@ sub do_paste_from_buffer {
}
my (%msgs,%before,%after,@dopaste,%is_map,%notinsupp,%notincrs,%notindom,%duplicate,
- %prefixchg,%srcdom,%srcnum,%marktomove,$save_err,$lockerrors,$allresult);
+ %prefixchg,%srcdom,%srcnum,%srcmapidx,%marktomove,$save_err,$lockerrors,$allresult);
foreach my $suffix (@topaste) {
my $url=&LONCAPA::map::qtescape($env{'docs.markedcopy_url_'.$suffix});
my $cid=&LONCAPA::map::qtescape($env{'docs.markedcopy_crs_'.$suffix});
+ my $mapidx=&LONCAPA::map::qtescape($env{'docs.markedcopy_map_'.$suffix});
# Supplemental content may only include certain types of content
# Early out if pasted content is not supported in Supplemental area
if ($folder =~ /^supplemental/) {
@@ -1678,7 +1699,21 @@ sub do_paste_from_buffer {
}
$srcdom{$suffix} = $srcd;
$srcnum{$suffix} = $srcn;
+ } elsif (($url =~ m{^/res/lib/templates/\w+\.problem$}) ||
+ ($url =~ m{^/adm/$match_domain/$match_username/\d+/(bulletinboard|smppg)$})) {
+ my ($srcd,$srcn) = split(/_/,$cid);
+# When paste buffer was populated using an active role in a different course
+# check for mdc privilege in the course from which the resource was pasted
+ if (($srcd ne $coursedom) || ($srcn ne $coursenum)) {
+ unless ($env{"user.priv.cm./$srcd/$srcn"} =~ /\Q:mdc&F\E/) {
+ $notincrs{$suffix} = 1;
+ next;
+ }
+ }
+ $srcdom{$suffix} = $srcd;
+ $srcnum{$suffix} = $srcn;
}
+ $srcmapidx{$suffix} = $mapidx;
push(@dopaste,$suffix);
if ($url=~/\.(page|sequence)$/) {
$is_map{$suffix} = 1;
@@ -1728,7 +1763,7 @@ sub do_paste_from_buffer {
%msgs = &Apache::lonlocal::texthash (
notinsupp => 'Paste failed: content type is not supported within Supplemental Content',
notincrs => 'Paste failed: Item is from a different course which you do not have rights to edit.',
- notindom => 'Paste failed: Item is an external tool from a course in a different donain.',
+ notindom => 'Paste failed: Item is an external tool from a course in a different donain.',
duplicate => 'Paste failed: only one instance of a particular published sequence or page is allowed within each course.',
);
@@ -1757,21 +1792,14 @@ sub do_paste_from_buffer {
# Retrieve information about all course maps in main content area
my $allmaps = {};
- if ($folder =~ /^default/) {
- $allmaps =
- &Apache::loncommon::allmaps_incourse($coursedom,$coursenum,
- $env{"course.$env{'request.course.id'}.home"},
- $env{'request.course.id'});
- }
-
- my (@toclear,%mapurls,%lockerrs,%msgerrs,%results);
+ my (@toclear,%mapurls,%lockerrs,%msgerrs,%results,$donechk);
# Loop over the items to paste
foreach my $suffix (@dopaste) {
# Maps need to be copied first
my (%removefrommap,%removeparam,%addedmaps,%rewrites,%retitles,%copies,
%dbcopies,%zombies,%params,%docmoves,%mapmoves,%mapchanges,%newsubdir,
- %newurls,%tomove);
+ %newurls,%tomove,%resdatacopy);
if (ref($marktomove{$suffix}) eq 'ARRAY') {
map { $tomove{$_} = 1; } @{$marktomove{$suffix}};
}
@@ -1782,6 +1810,13 @@ sub do_paste_from_buffer {
if ($is_map{$suffix}) {
# If pasting a map, check if map contains other maps
my (%hierarchy,%titles);
+ if (($folder =~ /^default/) && (!$donechk)) {
+ $allmaps =
+ &Apache::loncommon::allmaps_incourse($coursedom,$coursenum,
+ $env{"course.$env{'request.course.id'}.home"},
+ $env{'request.course.id'});
+ $donechk = 1;
+ }
&contained_map_check($url,$folder,$coursenum,$coursedom,
\%removefrommap,\%removeparam,\%addedmaps,
\%hierarchy,\%titles,$allmaps);
@@ -1814,7 +1849,7 @@ sub do_paste_from_buffer {
\%retitles,\%copies,\%dbcopies,
\%zombies,\%params,\%mapmoves,
\%mapchanges,\%tomove,\%newsubdir,
- \%newurls)) {
+ \%newurls,\%resdatacopy)) {
$mapmoves{$url} = 1;
}
$url = $newurl;
@@ -1823,7 +1858,7 @@ sub do_paste_from_buffer {
$coursenum,$srcdom{$suffix},$srcnum{$suffix},
$allmaps,\%rewrites,\%retitles,\%copies,\%dbcopies,
\%zombies,\%params,\%mapmoves,\%mapchanges,
- \%tomove,\%newsubdir,\%newurls);
+ \%tomove,\%newsubdir,\%newurls,\%resdatacopy);
}
} elsif ($url=~m {^/res/}) {
# published map can only exist once, so remove from paste buffer when done
@@ -1837,7 +1872,7 @@ sub do_paste_from_buffer {
}
}
}
- if ($url=~ m{/(ext\.tool)$}) {
+ if ($url=~ m{/(bulletinboard|smppg|ext\.tool)$}) {
my $prefix = $1;
my $fromothercrs;
#need to copy the db contents to a new one, unless this is a move.
@@ -1845,7 +1880,7 @@ sub do_paste_from_buffer {
src => $url,
cdom => $coursedom,
cnum => $coursenum,
- );
+ );
if (($srcdom{$suffix} =~ /^$match_domain$/) && ($srcnum{$suffix} =~ /^$match_courseid$/)) {
unless (($srcdom{$suffix} eq $coursedom) && ($srcnum{$suffix} eq $coursenum)) {
$fromothercrs = 1;
@@ -1861,7 +1896,11 @@ sub do_paste_from_buffer {
$url = $newurl;
$title=&mt('Copy of').' '.$title;
} else {
- if ($prefix eq 'ext.tool') {
+ if ($prefix eq 'smppg') {
+ $msg = &mt('Paste failed: An error occurred when copying the simple page.').' '.$errtext;
+ } elsif ($prefix eq 'bulletinboard') {
+ $msg = &mt('Paste failed: An error occurred when copying the discussion board.').' '.$errtext;
+ } elsif ($prefix eq 'ext.tool') {
$msg = &mt('Paste failed: An error occurred when copying the external tool.').' '.$errtext;
}
$results{$suffix} = $result;
@@ -1927,6 +1966,12 @@ sub do_paste_from_buffer {
}
}
}
+ } elsif ($url =~ m{^/res/lib/templates/(\w+)\.problem$}) {
+ my $template = $1;
+ if ($newidx) {
+ ©_templated_files($url,$srcdom{$suffix},$srcnum{$suffix},$srcmapidx{$suffix},
+ $coursedom,$coursenum,$template,$newidx,"$folder.$container");
+ }
}
$LONCAPA::map::resources[$newidx]=$title.':'.&LONCAPA::map::qtunescape($url).
':'.$ext.':normal:res';
@@ -1940,7 +1985,8 @@ sub do_paste_from_buffer {
}
}
-# Apply any changes to maps, or copy dependencies for uploaded HTML pages
+# Apply any changes to maps, or copy dependencies for uploaded HTML pages, or update
+# resourcedata for simpleproblems copied from another course
unless ($allresult eq 'fail') {
my %updated = (
rewrites => \%rewrites,
@@ -1948,6 +1994,7 @@ sub do_paste_from_buffer {
removefrommap => \%removefrommap,
removeparam => \%removeparam,
dbcopies => \%dbcopies,
+ resdatacopy => \%resdatacopy,
retitles => \%retitles,
);
my %info = (
@@ -2214,6 +2261,97 @@ sub dbcopy {
return ($url,$result,$errtext);
}
+sub copy_templated_files {
+ my ($srcurl,$srcdom,$srcnum,$srcmapinfo,$coursedom,$coursenum,$template,$newidx,$newmapname) = @_;
+ my ($srcfolder,$srcid,$srcwaspage) = split(/:/,$srcmapinfo);
+ my $srccontainer = 'sequence';
+ if ($srcwaspage) {
+ $srccontainer = 'page';
+ }
+ my $srcsymb = "uploaded/$srcdom/$srcnum/$srcfolder.$srccontainer".
+ '___'.$srcid.'___'.&Apache::lonnet::declutter($srcurl);
+ my $srcprefix = $srcdom.'_'.$srcnum.'.'.$srcsymb;
+ my %srcparms=&Apache::lonnet::dump('resourcedata',$srcdom,$srcnum,$srcprefix);
+ my $newsymb = "uploaded/$coursedom/$coursenum/$newmapname".'___'.$newidx.'___lib/templates/'.
+ $template.'.problem';
+ my $newprefix = $coursedom.'_'.$coursenum.'.'.$newsymb;
+ if ($template eq 'simpleproblem') {
+ $srcprefix .= '.0.';
+ my $weightprefix = $newprefix;
+ $newprefix .= '.0.';
+ my @simpleprobqtypes = qw(radio option string essay numerical);
+ my $qtype=$srcparms{$srcprefix.'questiontype'};
+ if (grep(/^\Q$qtype\E$/,@simpleprobqtypes)) {
+ my %newdata = (
+ $newprefix.'questiontype' => $qtype,
+ );
+ foreach my $type (@simpleprobqtypes) {
+ if ($type eq $qtype) {
+ $newdata{"$weightprefix.$type.weight"}=1;
+ } else {
+ $newdata{"$weightprefix.$type.weight"}=0;
+ }
+ }
+ $newdata{$newprefix.'hiddenparts'} = '!'.$qtype;
+ $newdata{$newprefix.'questiontext'} = $srcparms{$srcprefix.'questiontext'};
+ $newdata{$newprefix.'hinttext'} = $srcparms{$srcprefix.'hinttext'};
+ if ($qtype eq 'numerical') {
+ $newdata{$newprefix.'numericalscript'} = $srcparms{$srcprefix.'numericalscript'};
+ $newdata{$newprefix.'numericalanswer'} = $srcparms{$srcprefix.'numericalanswer'};
+ $newdata{$newprefix.'numericaltolerance'} = $srcparms{$srcprefix.'numericaltolerance'};
+ $newdata{$newprefix.'numericalsigfigs'} = $srcparms{$srcprefix.'numericalsigfigs'};
+ } elsif (($qtype eq 'option') || ($qtype eq 'radio')) {
+ my $maxfoils=$srcparms{$srcprefix.'maxfoils'};
+ unless (defined($maxfoils)) { $maxfoils=10; }
+ unless ($maxfoils=~/^\d+$/) { $maxfoils=10; }
+ if ($maxfoils<=0) { $maxfoils=10; }
+ my $randomize=$srcparms{$srcprefix.'randomize'};
+ unless (defined($randomize)) { $randomize='yes'; }
+ unless ($randomize eq 'no') { $randomize='yes'; }
+ $newdata{$newprefix.'maxfoils'} = $maxfoils;
+ $newdata{$newprefix.'randomize'} = $randomize;
+ if ($qtype eq 'option') {
+ $newdata{$newprefix.'options'} = $srcparms{$srcprefix.'options'};
+ }
+ for (my $i=1; $i<=10; $i++) {
+ $newdata{$newprefix.'value'.$i} = $srcparms{$srcprefix.'value'.$i};
+ $newdata{$newprefix.'position'.$i} = $srcparms{$srcprefix.'position'.$i};
+ $newdata{$newprefix.'text'.$i} = $srcparms{$srcprefix.'text'.$i};
+ }
+
+ } elsif (($qtype eq 'option') || ($qtype eq 'radio')) {
+ my $maxfoils=$srcparms{$srcprefix.'maxfoils'};
+ unless (defined($maxfoils)) { $maxfoils=10; }
+ unless ($maxfoils=~/^\d+$/) { $maxfoils=10; }
+ if ($maxfoils<=0) { $maxfoils=10; }
+ my $randomize=$srcparms{$srcprefix.'randomize'};
+ unless (defined($randomize)) { $randomize='yes'; }
+ unless ($randomize eq 'no') { $randomize='yes'; }
+ $newdata{$newprefix.'maxfoils'} = $maxfoils;
+ $newdata{$newprefix.'randomize'} = $randomize;
+ if ($qtype eq 'option') {
+ $newdata{$newprefix.'options'} = $srcparms{$srcprefix.'options'};
+ }
+ for (my $i=1; $i<=10; $i++) {
+ $newdata{$newprefix.'value'.$i} = $srcparms{$srcprefix.'value'.$i};
+ $newdata{$newprefix.'position'.$i} = $srcparms{$srcprefix.'position'.$i};
+ $newdata{$newprefix.'text'.$i} = $srcparms{$srcprefix.'text'.$i};
+ }
+ } elsif ($qtype eq 'string') {
+ $newdata{$newprefix.'stringanswer'} = $srcparms{$srcprefix.'stringanswer'};
+ $newdata{$newprefix.'stringtype'} = $srcparms{$srcprefix.'stringtype'};
+ }
+ if (keys(%newdata)) {
+ my $putres = &Apache::lonnet::cput('resourcedata',\%newdata,$coursedom,
+ $coursenum);
+ if ($putres eq 'ok') {
+ &Apache::lonnet::devalidatecourseresdata($coursenum,$coursedom);
+ }
+ }
+ }
+ }
+}
+
sub uniqueness_check {
my ($newurl) = @_;
my $unique = 1;
@@ -2280,7 +2418,7 @@ sub contained_map_check {
sub url_paste_fixups {
my ($oldurl,$folder,$prefixchg,$cdom,$cnum,$fromcdom,$fromcnum,$allmaps,
$rewrites,$retitles,$copies,$dbcopies,$zombies,$params,$mapmoves,
- $mapchanges,$tomove,$newsubdir,$newurls) = @_;
+ $mapchanges,$tomove,$newsubdir,$newurls,$resdatacopy) = @_;
my $checktitle;
if (($prefixchg) &&
($oldurl =~ m{^/uploaded/$match_domain/$match_courseid/supplemental})) {
@@ -2329,7 +2467,7 @@ sub url_paste_fixups {
$srcdom,$srcnum,$allmaps,$rewrites,
$retitles,$copies,$dbcopies,$zombies,
$params,$mapmoves,$mapchanges,$tomove,
- $newsubdir,$newurls);
+ $newsubdir,$newurls,$resdatacopy);
next;
} else {
($newurl,my $error) =
@@ -2353,7 +2491,7 @@ sub url_paste_fixups {
$cnum,$srcdom,$srcnum,$allmaps,
$rewrites,$retitles,$copies,$dbcopies,
$zombies,$params,$mapmoves,$mapchanges,
- $tomove,$newsubdir,$newurls)) {
+ $tomove,$newsubdir,$newurls,$resdatacopy)) {
$mapmoves->{$ressrc} = 1;
}
$changed = 1;
@@ -2382,6 +2520,12 @@ sub url_paste_fixups {
$dbcopies->{$oldurl}{$id}{'cnum'} = $fromcnum;
$changed = 1;
}
+ } elsif ($ressrc eq '/res/lib/templates/simpleproblem.problem') {
+ if (($fromcdom ne $cdom) || ($fromcnum ne $cnum)) {
+ $resdatacopy->{$oldurl}{$id}{'src'} = $ressrc;
+ $resdatacopy->{$oldurl}{$id}{'cdom'} = $fromcdom;
+ $resdatacopy->{$oldurl}{$id}{'cnum'} = $fromcnum;
+ }
} elsif ($ressrc =~ m{^/public/($match_domain)/($match_courseid)/(.+)$}) {
next if ($skip);
my $srcdom = $1;
@@ -2413,7 +2557,7 @@ sub apply_fixups {
$oldurl,$url,$caller) = @_;
my (%rewrites,%zombies,%removefrommap,%removeparam,%dbcopies,%retitles,
%params,%newsubdir,%before,%after,%copies,%docmoves,%mapmoves,@msgs,
- %lockerrors,$lockmsg);
+ %resdatacopy,%lockerrors,$lockmsg);
if (ref($updated) eq 'HASH') {
if (ref($updated->{'rewrites'}) eq 'HASH') {
%rewrites = %{$updated->{'rewrites'}};
@@ -2433,6 +2577,9 @@ sub apply_fixups {
if (ref($updated->{'retitles'}) eq 'HASH') {
%retitles = %{$updated->{'retitles'}};
}
+ if (ref($updated->{'resdatacopy'}) eq 'HASH') {
+ %resdatacopy = %{$updated->{'resdatacopy'}};
+ }
}
if (ref($info) eq 'HASH') {
if (ref($info->{'newsubdir'}) eq 'HASH') {
@@ -2583,6 +2730,36 @@ sub apply_fixups {
}
}
}
+ if (ref($resdatacopy{$key}) eq 'HASH') {
+ my ($gotnewmapname,$newmapname,$srcfolder,$srccontainer);
+ foreach my $idx (keys(%{$resdatacopy{$key}})) {
+ if (ref($resdatacopy{$key}{$idx}) eq 'HASH') {
+ my $srcurl = $resdatacopy{$key}{$idx}{'src'};
+ if ($srcurl =~ m{^/res/lib/templates/(\w+)\.problem$}) {
+ my $template = $1;
+ if (($resdatacopy{$key}{$idx}{'cdom'} =~ /^$match_domain$/) &&
+ ($resdatacopy{$key}{$idx}{'cnum'} =~ /^$match_courseid$/)) {
+ my $srcdom = $resdatacopy{$key}{$idx}{'cdom'};
+ my $srcnum = $resdatacopy{$key}{$idx}{'cnum'};
+ unless ($gotnewmapname) {
+ ($newmapname) = ($key =~ m{/([^/]+)$});
+ ($srcfolder,$srccontainer) = split(/\./,$newmapname);
+ if ($newsubdir{$key}) {
+ $newmapname =~ s/^((?:default|supplemental)_)(\d+)/$1$newsubdir{$key}/;
+ }
+ $gotnewmapname = 1;
+ }
+ my $srcmapinfo = $srcfolder.':'.$idx;
+ if ($srccontainer eq 'page') {
+ $srcmapinfo .= ':1';
+ }
+ ©_templated_files($srcurl,$srcdom,$srcnum,$srcmapinfo,$cdom,
+ $cnum,$template,$idx,$newmapname);
+ }
+ }
+ }
+ }
+ }
if (ref($params{$key}) eq 'HASH') {
%currparam = %{$params{$key}};
}
@@ -2911,7 +3088,7 @@ sub handle_edit_cmd {
sub editor {
my ($r,$coursenum,$coursedom,$folder,$allowed,$upload_output,$crstype,
$supplementalflag,$orderhash,$iconpath,$pathitem,$ltitoolsref,
- $canedit,$navmapref,$hiddentop)=@_;
+ $canedit,$hostname,$navmapref,$hiddentop)=@_;
my ($randompick,$ishidden,$isencrypted,$plain,$is_random_order,$container);
if ($allowed) {
(my $breadcrumbtrail,$randompick,$ishidden,$isencrypted,$plain,
@@ -3242,7 +3419,7 @@ sub editor {
$coursenum,$coursedom,$crstype,
$pathitem,$supplementalflag,$container,
\%filters,\%curr_groups,$ltitoolsref,$canedit,
- $isencrypted,$navmapref);
+ $isencrypted,$navmapref,$hostname);
$idx++;
$shown++;
}
@@ -3621,7 +3798,7 @@ sub is_supplemental_title {
sub entryline {
my ($index,$title,$url,$folder,$allowed,$residx,$coursenum,$coursedom,
$crstype,$pathitem,$supplementalflag,$container,$filtersref,$currgroups,
- $ltitoolsref,$canedit,$isencrypted,$navmapref)=@_;
+ $ltitoolsref,$canedit,$isencrypted,$navmapref,$hostname)=@_;
my ($foldertitle,$renametitle,$oldtitle);
if (&is_supplemental_title($title)) {
($title,$foldertitle,$renametitle) = &Apache::loncommon::parse_supplemental_title($title);
@@ -3873,11 +4050,19 @@ END
my ($editlink,$extresform,$anchor,$hiddenres,$nomodal);
my $orig_url = $url;
$orig_url=~s{http(:|:)//https(:|:)//}{https$2//};
- $url=~s{^http(|s)(:|:)//}{/adm/wrapper/ext/};
+ if ($container eq 'page') {
+ $url=~s{^http(|s)(:|:)//}{/ext/};
+ } else {
+ $url=~s{^http(|s)(:|:)//}{/adm/wrapper/ext/};
+ }
if (!$supplementalflag && $residx && $symb) {
if ((!$isfolder) && (!$ispage)) {
(undef,undef,$url)=&Apache::lonnet::decode_symb($symb);
- $url=&Apache::lonnet::clutter($url);
+ if (($url =~ m{^ext/}) && ($container eq 'page')) {
+ $url=&Apache::lonnet::clutter_with_no_wrapper($url);
+ } else {
+ $url=&Apache::lonnet::clutter($url);
+ }
if ($url=~/^\/*uploaded\//) {
$url=~/\.(\w+)$/;
my $embstyle=&Apache::loncommon::fileembstyle($1);
@@ -3891,7 +4076,7 @@ END
} elsif ($url=~m{^(|/adm/wrapper)/ext/([^#]+)}) {
my $wrapped = $1;
my $exturl = $2;
- if ($wrapped eq '') {
+ if (($wrapped eq '') && ($container ne 'page')) {
$url='/adm/wrapper'.$url;
}
if (($ENV{'SERVER_PORT'} == 443) && ($exturl !~ /^https:/)) {
@@ -3902,18 +4087,18 @@ END
} elsif ($url eq "/public/$coursedom/$coursenum/syllabus") {
if (($ENV{'SERVER_PORT'} == 443) &&
($env{'course.'.$env{'request.course.id'}.'.externalsyllabus'} =~ m{^http://})) {
+ unless (&Apache::lonnet::uses_sts()) {
+ $url .= '?usehttp=1';
+ }
$nomodal = 1;
}
}
if (&Apache::lonnet::symbverify($symb,$url)) {
my $shownsymb = $symb;
if ($isexternal) {
- if ($url =~ /^([^#]+)#([^#]+)$/) {
- $url = $1;
- $anchor = $2;
- if ($symb =~ m{^([^#]+)\Q#$anchor\E$}) {
- $shownsymb = $1.&escape('#').$anchor;
- }
+ $url =~ s/\#[^#]+$//;
+ if ($container eq 'page') {
+ $url = &Apache::lonnet::clutter($url);
}
}
unless ($env{'request.role.adv'}) {
@@ -3967,12 +4152,24 @@ END
$url = $1;
$anchor = $2;
if (($url =~ m{^(|/adm/wrapper)/ext/(?!https:)}) && ($ENV{'SERVER_PORT'} == 443)) {
+ unless (&Apache::lonnet::uses_sts()) {
+ if ($hostname ne '') {
+ $url = 'http://'.$hostname.$url;
+ }
+ $url .= (($url =~ /\?/) ? '&':'?').'usehttp=1';
+ }
$nomodal = 1;
}
}
} elsif ($url =~ m{^\Q/public/$coursedom/$coursenum/syllabus\E}) {
if (($ENV{'SERVER_PORT'} == 443) &&
($env{'course.'.$env{'request.course.id'}.'.externalsyllabus'} =~ m{^http://})) {
+ unless (&Apache::lonnet::uses_sts()) {
+ if ($hostname ne '') {
+ $url = 'http://'.$hostname.$url;
+ }
+ $url .= (($url =~ /\?/) ? '&':'?').'usehttp=1';
+ }
$nomodal = 1;
}
}
@@ -4087,7 +4284,8 @@ $form_end;
if ($isexternal) {
($editlink,$extresform) =
&Apache::lonextresedit::extedit_form(0,$residx,$orig_url,$title,$pathitem,
- undef,undef,undef,$disabled);
+ undef,undef,undef,undef,undef,undef,
+ undef,$disabled);
} elsif ($orig_url =~ m{^/adm/$coursedom/$coursenum/\d+/ext\.tool$}) {
($editlink,$extresform) =
&Apache::lonextresedit::extedit_form(0,$residx,$orig_url,$title,$pathitem,
@@ -4107,7 +4305,8 @@ $form_end;
$forceedit,
undef,$symb,
&escape($env{'form.folderpath'}),
- $renametitle,'','',1,$suppanchor);
+ $renametitle,$hostname,
+ '','',1,$suppanchor);
if ($jscall) {
$editlink = ''.&mt('Edit').' '."\n";
@@ -4135,8 +4334,13 @@ $form_end;
$anchor = '#'.&HTML::Entities::encode($anchor,'"<>&');
}
}
- $link = &js_escape($url.(($url=~/\?/)?'&':'?').'inhibitmenu=yes'.
- (($anchor ne '')?$anchor:''));
+
+ if ((!$supplementalflag) && ($nomodal) && ($hostname ne '')) {
+ $link = 'http://'.$hostname.$url;
+ } else {
+ $link = $url;
+ }
+ $link = &js_escape($link.(($url=~/\?/)?'&':'?').'inhibitmenu=yes'.$anchor);
if ($nomodal) {
$line.=''.
'';
@@ -4216,9 +4420,11 @@ sub action_restrictions {
if ($url=~ m{^/res/.+\.(page|sequence)$}) {
# no copy for published maps
$denied{'copy'} = 1;
- } elsif ($url=~m{^/res/lib/templates/}) {
- $denied{'copy'} = 1;
- $denied{'cut'} = 1;
+ } elsif ($url=~m{^/res/lib/templates/([^/]+)\.problem$}) {
+ unless ($1 eq 'simpleproblem') {
+ $denied{'copy'} = 1;
+ }
+ $denied{'cut'} = 1;
} elsif ($url eq "/uploaded/$cdom/$cnum/group_allfolders.sequence") {
if ($folderpath =~ /^default&[^\&]+$/) {
if ((ref($currgroups) eq 'HASH') && (keys(%{$currgroups}) > 0)) {
@@ -4378,7 +4584,7 @@ sub untiehash {
sub checkonthis {
- my ($r,$url,$level,$title)=@_;
+ my ($r,$url,$level,$title,$checkstale)=@_;
$url=&unescape($url);
$alreadyseen{$url}=1;
$r->rflush();
@@ -4393,10 +4599,22 @@ sub checkonthis {
$r->print(''.
($title?$title:$url).' ');
if ($url=~/^\/res\//) {
+ my $updated;
+ if (($checkstale) && ($url !~ m{^/res/lib/templates/}) &&
+ ($url !~ /\.\d+\.\w+$/)) {
+ $updated = &Apache::lonnet::remove_stale_resfile($url);
+ }
my $result=&Apache::lonnet::repcopy(
&Apache::lonnet::filelocation('',$url));
if ($result eq 'ok') {
$r->print(''.&mt('ok').'');
+ if ($updated) {
+ $r->print('
');
+ for (my $i=0;$i<=$level*5;$i++) {
+ $r->print(' ');
+ }
+ $r->print('- '.&mt('Outdated copy removed'));
+ }
$r->rflush();
&Apache::lonnet::countacc($url);
$url=~/\.(\w+)$/;
@@ -4430,7 +4648,7 @@ sub checkonthis {
&Apache::lonnet::metadata($url,'dependencies');
foreach my $dep (split(/\,/,$dependencies)) {
if (($dep=~/^\/res\//) && (!$alreadyseen{$dep})) {
- &checkonthis($r,$dep,$level+1);
+ &checkonthis($r,$dep,$level+1,'',$checkstale);
}
}
} elsif ($result eq 'unavailable') {
@@ -4444,6 +4662,9 @@ sub checkonthis {
} else {
$r->print(''.&mt('access denied').'');
}
+ if (($updated) && ($result ne 'ok')) {
+ $r->print('
'.&mt('Outdated copy removed'));
+ }
}
}
}
@@ -4496,9 +4717,71 @@ sub list_symbs {
$r->print(&endContentScreen());
}
+sub short_urls {
+ my ($r,$canedit) = @_;
+ my $crstype = &Apache::loncommon::course_type();
+ my $formname = 'shortenurl';
+ $r->print(&Apache::loncommon::start_page('Display/Set Shortened URLs'));
+ $r->print(&Apache::lonhtmlcommon::breadcrumbs('Shortened URLs'));
+ $r->print(&startContentScreen('tools'));
+ my ($navmap,$errormsg) =
+ &Apache::loncourserespicker::get_navmap_object($crstype,'shorturls');
+ my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
+ my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
+ my (%maps,%resources,%titles);
+ if (!ref($navmap)) {
+ $r->print($errormsg.
+ &endContentScreen());
+ return '';
+ } else {
+ $r->print('
'.&mt('Created [quant,_1,URL]',$numnew).'
'); + } + if ((ref($errors) eq 'ARRAY') && (@{$errors} > 0)) { + $r->print(&mt('The following errors occurred when processing your request to create shortened URLs:').''.$error.'
'); @@ -5904,6 +6207,7 @@ unless ($container eq 'page') { &mark_hash_old(); } } + &changewarning($r,''); } } @@ -5963,12 +6267,12 @@ SNFFORM &Apache::lonextresedit::extedit_form(1,0,undef,undef,$pathitem, $help{'Adding_External_Resource'}, undef,undef,$disabled); - my $supexttoolform = &Apache::lonextresedit::extedit_form(1,0,undef,undef,$pathitem, $help{'Adding_External_Tool'}, undef,undef,'tool',$coursedom, $coursenum,\%ltitools,$disabled); + my $supnewsylform=(<'.$error.'
'); } else { @@ -6062,7 +6366,7 @@ my %suporderhash = ( } } elsif ($supplementalflag) { my $error = &editor($r,$coursenum,$coursedom,$folder,$allowed,'',$crstype, - $supplementalflag,'',$iconpath,$pathitem); + $supplementalflag,'',$iconpath,$pathitem,'',$hostname); if ($error) { $r->print(''.$error.'
'); } @@ -6262,6 +6566,7 @@ sub generate_admin_menu { 'vc' => 'Verify Content', 'cv' => 'Check/Set Resource Versions', 'ls' => 'List Resource Identifiers', + 'ct' => 'Display/Set Shortened URLs for Deep-linking', 'imse' => 'Export contents to IMS Archive', 'dcd' => "Copy $crstype Content to Authoring Space", ); @@ -6312,6 +6617,13 @@ sub generate_admin_menu { icon => 'symbs.png', linktitle => "List the unique identifier used for each resource instance in your $lc_crstype" }, + { linktext => $lt{'ct'}, + url => "javascript:injectData(document.courseverify,'dummy','shorturls','$lt{'ct'}')", + permission => 'F', + help => 'Docs_Short_URLs', + icon => 'shorturls.png', + linktitle => "Set shortened URLs for a resource or folder in your $lc_crstype for use in deep-linking" + }, ] }); if ($canedit) { @@ -6442,7 +6754,8 @@ END } sub editing_js { - my ($udom,$uname,$supplementalflag,$coursedom,$coursenum,$posslti,$canedit,$navmapref) = @_; + my ($udom,$uname,$supplementalflag,$coursedom,$coursenum,$posslti, + $canedit,$hostname,$navmapref) = @_; my %js_lt = &Apache::lonlocal::texthash( p_mnf => 'Name of New Folder', t_mnf => 'New Folder', @@ -6521,6 +6834,26 @@ sub editing_js { $backtourl .= '?symb='. &HTML::Entities::encode($caller,'<>&"'); } + if ($backtourl =~ m{^\Q/public/$coursedom/$coursenum/syllabus\E}) { + if (($ENV{'SERVER_PORT'} == 443) && + ($env{'course.'.$env{'request.course.id'}.'.externalsyllabus'} =~ m{^http://})) { + unless (&Apache::lonnet::uses_sts()) { + if ($hostname ne '') { + $backtourl = 'http://'.$hostname.$backtourl; + } + $backtourl .= (($backtourl =~ /\?/) ? '&':'?').'usehttp=1'; + } + } + } elsif ($backtourl =~ m{^/adm/wrapper/ext/(?!https:)}) { + if (($ENV{'SERVER_PORT'} == 443) && ($hostname ne '')) { + unless (&Apache::lonnet::uses_sts()) { + if ($hostname ne '') { + $backtourl = 'http://'.$hostname.$backtourl; + } + $backtourl .= (($backtourl =~ /\?/) ? '&':'?').'usehttp=1'; + } + } + } if ($anchor ne '') { $backtourl .= '#'.&HTML::Entities::encode($anchor,'<>&"'); } @@ -7735,7 +8068,7 @@ check on this Verify Content -=item devalidateversioncache() +=item devalidateversioncache() =item checkversions()