--- loncom/interface/londocs.pm 2017/05/10 23:58:24 1.631
+++ loncom/interface/londocs.pm 2020/08/11 19:02:31 1.672
@@ -1,7 +1,7 @@
# The LearningOnline Network
# Documents
#
-# $Id: londocs.pm,v 1.631 2017/05/10 23:58:24 raeburn Exp $
+# $Id: londocs.pm,v 1.672 2020/08/11 19:02:31 raeburn Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -45,6 +45,8 @@ use Apache::lontemplate();
use Apache::lonsimplepage();
use Apache::lonhomework();
use Apache::lonpublisher();
+use Apache::lonparmset();
+use Apache::loncourserespicker();
use HTML::Entities;
use HTML::TokeParser;
use GDBM_File;
@@ -52,6 +54,7 @@ use File::MMagic;
use File::Copy;
use Apache::lonlocal;
use Cwd;
+use UUID::Tiny ':std';
use LONCAPA qw(:DEFAULT :match);
my $iconpath;
@@ -659,7 +662,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','crsappend');
my @toolinfo = split(/:/,$info);
if ($residx) {
%toolsettings=&Apache::lonnet::dump('exttool_'.$marker,$coursedom,$coursenum);
@@ -669,14 +672,19 @@ sub group_import {
}
$toolid =~ s/\D//g;
($toolhash{'target'},$toolhash{'width'},$toolhash{'height'},
- $toolhash{'linktext'},$toolhash{'explanation'},
- $toolhash{'crslabel'},$toolhash{'crstitle'}) = @toolinfo;
+ $toolhash{'linktext'},$toolhash{'explanation'},$toolhash{'crslabel'},
+ $toolhash{'crstitle'},$toolhash{'crsappend'},$toolhash{'gradable'}) = @toolinfo;
foreach my $item (@extras) {
$toolhash{$item} = &unescape($toolhash{$item});
}
+ if ($folder =~ /^supplemental/) {
+ delete($toolhash{'gradable'});
+ } else {
+ $toolhash{'gradable'} =~ s/\D+//g;
+ }
if (ref($ltitoolsref) eq 'HASH') {
- my @deleted;
if (ref($ltitoolsref->{$toolid}) eq 'HASH') {
+ my @deleted;
$toolhash{'id'} = $toolid;
if (($toolhash{'target'} eq 'iframe') || ($toolhash{'target'} eq 'tab') ||
($toolhash{'target'} eq 'window')) {
@@ -751,11 +759,51 @@ sub group_import {
}
}
}
+ if ($toolhash{'passback'}) {
+ my $gradesecret = UUID::Tiny::create_uuid_as_string(UUID_V4);
+ $toolhash{'gradesecret'} = $gradesecret;
+ $toolhash{'gradesecretdate'} = time;
+ }
+ if ($toolhash{'roster'}) {
+ my $rostersecret = UUID::Tiny::create_uuid_as_string(UUID_V4);
+ $toolhash{'rostersecret'} = $rostersecret;
+ $toolhash{'rostersecretdate'} = time;
+ }
+ my $changegradable;
+ if (($residx) && ($folder =~ /^default/)) {
+ if ($toolsettings{'gradable'}) {
+ unless (($toolhash{'gradable'}) || (defined($LONCAPA::map::zombies[$residx]))) {
+ push(@deleted,'gradable');
+ $changegradable = 1;
+ }
+ } elsif ($toolhash{'gradable'}) {
+ $changegradable = 1;
+ }
+ if (($caller eq 'londocs') && (defined($LONCAPA::map::zombies[$residx]))) {
+ $changegradable = 1;
+ if ($toolsettings{'gradable'}) {
+ $toolhash{'gradable'} = 1;
+ }
+ }
+ }
my $putres = &Apache::lonnet::put('exttool_'.$marker,\%toolhash,$coursedom,$coursenum);
if ($putres eq 'ok') {
if (@deleted) {
&Apache::lonnet::del('exttool_'.$marker,\@deleted,$coursedom,$coursenum);
- }
+ }
+ if (($changegradable) && ($folder =~ /^default/)) {
+ my $val;
+ if ($toolhash{'gradable'}) {
+ $val = 'yes';
+ } else {
+ $val = 'no';
+ }
+ &LONCAPA::map::storeparameter($residx,'parameter_0_gradable',$val,
+ 'string_yesno');
+ &remember_parms($residx,'gradable','set',$val);
+ }
+ } else {
+ return (&mt('Failed to save update to external tool.'),1);
}
}
}
@@ -993,6 +1041,7 @@ sub docs_change_log {
'encrypturl' => 'URL hidden',
'randompick' => 'Randomly pick',
'randomorder' => 'Randomly ordered',
+ 'gradable' => 'Grade can be assigned to External Tool',
'set' => 'set to',
'del' => 'deleted');
my $filter = &Apache::loncommon::display_filter('docslog')."\n".
@@ -1100,7 +1149,7 @@ sub docs_change_log {
$r->print('');
if ($docslog{$id}{'logentry'}{'parameter_res'}) {
$r->print(&LONCAPA::map::qtescape((split(/\:/,$docslog{$id}{'logentry'}{'parameter_res'}))[0]).':
');
- foreach my $parameter ('randompick','hiddenresource','encrypturl','randomorder') {
+ foreach my $parameter ('randompick','hiddenresource','encrypturl','randomorder','gradable') {
if ($docslog{$id}{'logentry'}{'parameter_action_'.$parameter}) {
# FIXME: internationalization seems wrong here
$r->print('- '.
@@ -1168,13 +1217,19 @@ 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};
- my $mapidx = $env{'docs.markedcopy_map_'.$suffix};
- if (($cid =~ /^$match_domain(?:_)$match_courseid$/) &&
- ($url ne '')) {
- $pasteurls{$cid.'_'.$url.'_'.$mapidx} = 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;
+ }
+ }
}
}
@@ -1183,7 +1238,7 @@ sub update_paste_buffer {
my @pathitems = split(/\&/,$env{'form.folderpath'});
my @folderconf = split(/\:/,$pathitems[-1]);
- my $ispage = $folderconf[4];
+ my $ispage = $folderconf[5];
foreach my $item (@possibles) {
my ($orderidx,$cmd) = split(/:/,$item);
@@ -1196,7 +1251,13 @@ sub update_paste_buffer {
$env{'form.folderpath'},\%curr_groups);
next if ($denied{'copy'});
$url=~s{http(:|:)//https(:|:)//}{https$2//};
- next if (exists($pasteurls{$coursedom.'_'.$coursenum.'_'.$mapidx}));
+ 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 '') {
@@ -1672,8 +1733,8 @@ 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|ext\.tool)$})) {
- my $srctype= $1;
+ ($url =~ m{^/adm/$match_domain/$match_username/\d+/(bulletinboard|smppg)$}) ||
+ ($url =~ m{^/adm/$match_domain/$match_courseid/\d+/ext\.tool$})) {
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
@@ -1683,7 +1744,9 @@ sub do_paste_from_buffer {
next;
}
}
- if (($srctype eq 'ext.tool') && ($srcd ne $coursedom)) {
+# When buffer was populated using an active role in a different course
+# disallow pasting of External Tool if course is in a different domain.
+ if (($url =~ m{/ext\.tool$}) && ($srcd ne $coursedom)) {
$notindom{$suffix} = 1;
next;
}
@@ -1739,7 +1802,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 domain.',
duplicate => 'Paste failed: only one instance of a particular published sequence or page is allowed within each course.',
);
@@ -1768,14 +1831,7 @@ 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) {
@@ -1793,6 +1849,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);
@@ -1850,13 +1913,18 @@ sub do_paste_from_buffer {
}
if ($url=~ m{/(bulletinboard|smppg|ext\.tool)$}) {
my $prefix = $1;
- my $fromothercrs;
+ my $fromothercrs;
#need to copy the db contents to a new one, unless this is a move.
my %info = (
src => $url,
cdom => $coursedom,
cnum => $coursenum,
);
+ if ($prefix eq 'ext.tool') {
+ if ($prefixchg{$suffix} eq 'docstosupp') {
+ $info{'delgradable'} = 1;
+ }
+ }
if (($srcdom{$suffix} =~ /^$match_domain$/) && ($srcnum{$suffix} =~ /^$match_courseid$/)) {
unless (($srcdom{$suffix} eq $coursedom) && ($srcnum{$suffix} eq $coursenum)) {
$fromothercrs = 1;
@@ -1948,6 +2016,18 @@ sub do_paste_from_buffer {
©_templated_files($url,$srcdom{$suffix},$srcnum{$suffix},$srcmapidx{$suffix},
$coursedom,$coursenum,$template,$newidx,"$folder.$container");
}
+ } elsif ($url =~ /ext\.tool$/) {
+ if (($newidx) && ($folder=~/^default/)) {
+ my $marker = (split(m{/},$url))[4];
+ my %toolsettings = &Apache::lonnet::dump('exttool_'.$marker,$coursedom,$coursenum);
+ my $val = 'no';
+ if ($toolsettings{'gradable'}) {
+ $val = 'yes';
+ }
+ &LONCAPA::map::storeparameter($newidx,'parameter_0_gradable',$val,
+ 'string_yesno');
+ &remember_parms($newidx,'gradable','set',$val);
+ }
}
$LONCAPA::map::resources[$newidx]=$title.':'.&LONCAPA::map::qtunescape($url).
':'.$ext.':normal:res';
@@ -2196,6 +2276,9 @@ sub dbcopy {
}
}
$db_name =~ s{_\d*$ }{_$suffix}x;
+ if (($prefix eq 'exttool') && ($dbref->{'delgradable'}) && ($contents{'gradable'})) {
+ delete($contents{'gradable'});
+ }
$result=&Apache::lonnet::put($db_name,\%contents,
$coursedom,$coursenum);
if ($result eq 'ok') {
@@ -2258,7 +2341,9 @@ sub copy_templated_files {
my @simpleprobqtypes = qw(radio option string essay numerical);
my $qtype=$srcparms{$srcprefix.'questiontype'};
if (grep(/^\Q$qtype\E$/,@simpleprobqtypes)) {
- my %newdata;
+ my %newdata = (
+ $newprefix.'questiontype' => $qtype,
+ );
foreach my $type (@simpleprobqtypes) {
if ($type eq $qtype) {
$newdata{"$weightprefix.$type.weight"}=1;
@@ -2480,16 +2565,38 @@ sub url_paste_fixups {
$changed = 1;
}
}
- } elsif ($ressrc =~ m{^/adm/($match_domain)/($match_courseid)/.+$}) {
+ } elsif ($ressrc =~ m{^/adm/($match_domain)/($match_courseid)/(.+)$}) {
next if ($skip);
my $srcdom = $1;
my $srcnum = $2;
+ my $rem = $3;
+ my ($is_exttool,$exttoolchg);
+ if ($rem =~ m{\d+/ext\.tool$}) {
+ $is_exttool = 1;
+ }
if (($srcdom ne $cdom) || ($srcnum ne $cnum)) {
$rewrites->{$oldurl}{$id} = $ressrc;
$dbcopies->{$oldurl}{$id}{'src'} = $ressrc;
$dbcopies->{$oldurl}{$id}{'cdom'} = $srcdom;
$dbcopies->{$oldurl}{$id}{'cnum'} = $srcnum;
$changed = 1;
+ if ($is_exttool) {
+ $exttoolchg = 1;
+ }
+ } elsif (($rem =~ m{\d+/ext\.tool$}) &&
+ ($env{'form.docs.markedcopy_options'} ne 'move')) {
+ $dbcopies->{$oldurl}{$id}{'src'} = $ressrc;
+ $dbcopies->{$oldurl}{$id}{'cdom'} = $srcdom;
+ $dbcopies->{$oldurl}{$id}{'cnum'} = $srcnum;
+ $changed = 1;
+ $exttoolchg = 1;
+ }
+ if (($is_exttool) && ($prefixchg)) {
+ if ($oldurl =~ m{^/uploaded/$match_domain/$match_courseid/default}) {
+ if ($exttoolchg) {
+ $dbcopies->{$oldurl}{$id}{'delgradable'} = 1;
+ }
+ }
}
} elsif ($ressrc =~ m{^/adm/$match_domain/$match_username/\d+/(smppg|bulletinboard)$}) {
if (($fromcdom ne $cdom) || ($fromcnum ne $cnum) ||
@@ -2710,9 +2817,7 @@ sub apply_fixups {
}
}
if (ref($resdatacopy{$key}) eq 'HASH') {
- if ($newsubdir{$key}) {
-
- }
+ my ($gotnewmapname,$newmapname,$srcfolder,$srccontainer);
foreach my $idx (keys(%{$resdatacopy{$key}})) {
if (ref($resdatacopy{$key}{$idx}) eq 'HASH') {
my $srcurl = $resdatacopy{$key}{$idx}{'src'};
@@ -2722,15 +2827,18 @@ sub apply_fixups {
($resdatacopy{$key}{$idx}{'cnum'} =~ /^$match_courseid$/)) {
my $srcdom = $resdatacopy{$key}{$idx}{'cdom'};
my $srcnum = $resdatacopy{$key}{$idx}{'cnum'};
- my ($newmapname) = ($key =~ m{/([^/]+)$});
- my ($srcfolder,$srccontainer) = split(/\./,$newmapname);
+ 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';
}
- if ($newsubdir{$key}) {
- $newmapname =~ s/^((?:default|supplemental)_)(\d+)/$1$newsubdir{$key}/;
- }
©_templated_files($srcurl,$srcdom,$srcnum,$srcmapinfo,$cdom,
$cnum,$template,$idx,$newmapname);
}
@@ -2753,7 +2861,8 @@ sub apply_fixups {
}
}
}
- for (my $i=0; $i<@LONCAPA::map::order; $i++) {
+ my $total = scalar(@LONCAPA::map::order) - 1;
+ for (my $i=$total; $i>=0; $i--) {
my $idx = $LONCAPA::map::order[$i];
if (defined($LONCAPA::map::resources[$idx])) {
my $changed;
@@ -2763,7 +2872,7 @@ sub apply_fixups {
splice(@LONCAPA::map::order,$i,1);
if (ref($currparam{$idx}) eq 'ARRAY') {
foreach my $name (@{$currparam{$idx}}) {
- &LONCAPA::map::delparameter($idx,'parameter_'.$name);
+ &LONCAPA::map::delparameter($idx,$name);
}
}
next;
@@ -2805,7 +2914,7 @@ sub apply_fixups {
foreach my $idx (keys(%remparam)) {
if (ref($remparam{$idx}) eq 'ARRAY') {
foreach my $name (@{$remparam{$idx}}) {
- &LONCAPA::map::delparameter($idx,'parameter_'.$name);
+ &LONCAPA::map::delparameter($idx,$name);
}
}
}
@@ -3016,8 +3125,9 @@ sub update_parameter {
sub handle_edit_cmd {
my ($coursenum,$coursedom) =@_;
+ my $haschanges = 0;
if ($env{'form.cmd'} eq '') {
- return 0;
+ return $haschanges;
}
my ($cmd,$idx)=split('_',$env{'form.cmd'});
@@ -3032,19 +3142,19 @@ sub handle_edit_cmd {
&LONCAPA::map::makezombie($LONCAPA::map::order[$idx]);
}
splice(@LONCAPA::map::order, $idx, 1);
-
+ $haschanges = 1;
} elsif ($cmd eq 'cut') {
&LONCAPA::map::makezombie($LONCAPA::map::order[$idx]);
splice(@LONCAPA::map::order, $idx, 1);
-
+ $haschanges = 1;
} elsif ($cmd eq 'up'
&& ($idx) && (defined($LONCAPA::map::order[$idx-1]))) {
@LONCAPA::map::order[$idx-1,$idx] = @LONCAPA::map::order[$idx,$idx-1];
-
+ $haschanges = 1;
} elsif ($cmd eq 'down'
&& defined($LONCAPA::map::order[$idx+1])) {
@LONCAPA::map::order[$idx+1,$idx] = @LONCAPA::map::order[$idx,$idx+1];
-
+ $haschanges = 1;
} elsif ($cmd eq 'rename') {
my $comment = &LONCAPA::map::qtunescape($env{'form.title'});
if ($comment=~/\S/) {
@@ -3054,11 +3164,26 @@ sub handle_edit_cmd {
# Devalidate title cache
my $renamed_url=&LONCAPA::map::qtescape($url);
&Apache::lonnet::devalidate_title_cache($renamed_url);
-
- } else {
- return 0;
+ $haschanges = 1;
+ } elsif ($cmd eq 'setalias') {
+ my $newvalue = $env{'form.alias'};
+ if ($newvalue ne '') {
+ unless (Apache::lonnet::get_symb_from_alias($newvalue)) {
+ &LONCAPA::map::storeparameter($idx,'parameter_0_mapalias',$newvalue,
+ 'string');
+ &remember_parms($idx,'mapalias','set',$newvalue);
+ $haschanges = 1;
+ }
+ }
+ } elsif ($cmd eq 'delalias') {
+ my $current = (&LONCAPA::map::getparameter($idx,'parameter_0_mapalias'))[0];
+ if ($current ne '') {
+ &LONCAPA::map::delparameter($idx,'parameter_0_mapalias');
+ &remember_parms($idx,'mapalias','del');
+ $haschanges = 1;
+ }
}
- return 1;
+ return $haschanges;
}
sub editor {
@@ -3182,7 +3307,7 @@ sub editor {
# Rename, cut, copy or remove a single resource
if (&handle_edit_cmd($coursenum,$coursedom)) {
my $contentchg;
- if ($env{'form.cmd'} =~ m{^(remove|cut)_}) {
+ if ($env{'form.cmd'} =~ m{^(remove|cut|setalias|delalias)_}) {
$contentchg = 1;
}
($errtext,$fatal)=&storemap($coursenum,$coursedom,$folder.'.'.$container,$contentchg);
@@ -3422,10 +3547,10 @@ sub editor {
.&Apache::loncommon::start_data_table(undef,'contentlist')
.&Apache::loncommon::start_data_table_header_row()
.'
'.&mt('Move').' | '
- .''.&mt('Actions').' | '
+ .''.&mt('Actions').' | '
.''.&mt('Document').' | ';
if ($folder !~ /^supplemental/) {
- $to_show .= ''.&mt('Settings').' | ';
+ $to_show .= ''.&mt('Settings').' | ';
}
$to_show .= &Apache::loncommon::end_data_table_header_row();
if ($folder !~ /^supplemental/) {
@@ -3453,9 +3578,8 @@ sub editor {
''.
&multiple_check_form('actions',\%lists,$canedit).
' | '.
- ' | '.
- ' | '.
- ''.
+ ' | | '.
+ ''.
&multiple_check_form('settings',\%lists,$canedit).
' | '.
&Apache::loncommon::end_data_table_row();
@@ -3803,7 +3927,7 @@ sub entryline {
my $line=&Apache::loncommon::start_data_table_row();
my ($form_start,$form_end,$form_common,$form_param);
# Edit commands
- my ($esc_path, $path, $symb);
+ my ($esc_path, $path, $symb, $curralias);
if ($env{'form.folderpath'}) {
$esc_path=&escape($env{'form.folderpath'});
$path = &HTML::Entities::encode($env{'form.folderpath'},'<>&"');
@@ -3872,6 +3996,8 @@ END
'ct' => 'Cut',
'rn' => 'Rename',
'cp' => 'Copy',
+ 'da' => 'Unset alias',
+ 'sa' => 'Set alias',
'ex' => 'External Resource',
'et' => 'External Tool',
'ed' => 'Edit',
@@ -3902,6 +4028,9 @@ END
($url!~/$LONCAPA::assess_page_seq_re/)) {
$confirm_removal = 1;
}
+ if ($url =~ /$LONCAPA::assess_re/) {
+ $curralias = (&LONCAPA::map::getparameter($orderidx,'parameter_0_mapalias'))[0];
+ }
if ($denied{'copy'}) {
$copylink=(<&');
+ $url.=(($url=~/\?/)?'&':'?').'symb='.&escape($shownsymb);
}
} elsif (!$env{'request.role.adv'}) {
my $checkencrypt;
@@ -4103,7 +4239,7 @@ END
my $shownsymb = &Apache::lonenc::encrypted($symb);
my $shownurl = &Apache::lonenc::encrypted($url);
if (&Apache::lonnet::symbverify($shownsymb,$shownurl)) {
- $url = $shownurl.(($shownurl=~/\?/)?'&':'?').'symb='.&HTML::Entities::encode($shownsymb,'"<>&');
+ $url = $shownurl.(($shownurl=~/\?/)?'&':'?').'symb='.&escape($shownsymb);
if ($env{'request.enc'} ne '') {
delete($env{'request.enc'});
}
@@ -4123,8 +4259,11 @@ END
$url = $1;
$anchor = $2;
if (($url =~ m{^(|/adm/wrapper)/ext/(?!https:)}) && ($ENV{'SERVER_PORT'} == 443)) {
- if ($hostname ne '') {
- $url = 'http://'.$hostname.$url;
+ unless (&Apache::lonnet::uses_sts()) {
+ if ($hostname ne '') {
+ $url = 'http://'.$hostname.$url;
+ }
+ $url .= (($url =~ /\?/) ? '&':'?').'usehttp=1';
}
$nomodal = 1;
}
@@ -4132,10 +4271,12 @@ END
} elsif ($url =~ m{^\Q/public/$coursedom/$coursenum/syllabus\E}) {
if (($ENV{'SERVER_PORT'} == 443) &&
($env{'course.'.$env{'request.course.id'}.'.externalsyllabus'} =~ m{^http://})) {
- if ($hostname ne '') {
- $url = 'http://'.$hostname.$url;
+ unless (&Apache::lonnet::uses_sts()) {
+ if ($hostname ne '') {
+ $url = 'http://'.$hostname.$url;
+ }
+ $url .= (($url =~ /\?/) ? '&':'?').'usehttp=1';
}
- $url .= (($url =~ /\?/) ? '&':'?').'usehttp=1';
$nomodal = 1;
}
}
@@ -4289,6 +4430,17 @@ $form_end;
$reinit = &mt('(re-initialize course to access)');
}
$line.=''.$editlink.$renamelink;
+ if ($orig_url =~ /$LONCAPA::assess_re/) {
+ $line.= ' ';
+ if ($curralias ne '') {
+ $line.=''.
+ $lt{'da'}.'';
+ } else {
+ $line.=''.
+ $lt{'sa'}.'';
+ }
+ }
+ $line.=' | ';
my $link;
if (($url=~m{/adm/(coursedocs|supplemental)}) || (!$allowed && $url)) {
$line.='';
@@ -4305,8 +4457,7 @@ $form_end;
} else {
$link = $url;
}
- $link = &js_escape($link.(($url=~/\?/)?'&':'?').'inhibitmenu=yes'.
- (($anchor ne '')?$anchor:''));
+ $link = &js_escape($link.(($url=~/\?/)?'&':'?').'inhibitmenu=yes'.$anchor);
if ($nomodal) {
$line.=''.
'';
@@ -4328,11 +4479,16 @@ $form_end;
$line.=&Apache::loncommon::modal_link($link,$title,600,500);
}
} elsif (($hiddenfolder) || ($hiddenres)) {
- $line.=$title.' '.&mt('(Hidden)').'';
+ $line.=$title.' ('.&mt('Hidden').')';
} else {
$line.=$title.' '.$reinit.'';
}
- $line.="$extresform | ";
+ if (($allowed) && ($curralias ne '')) {
+ $line .= '
('.$curralias.')';
+ } else {
+ $line .= $extresform;
+ }
+ $line .= '';
$rand_pick_text = ' ' if ($rand_pick_text eq '');
$rand_order_text = ' ' if ($rand_order_text eq '');
if (($allowed) && ($folder!~/^supplemental/)) {
@@ -4550,7 +4706,7 @@ sub untiehash {
sub checkonthis {
- my ($r,$url,$level,$title)=@_;
+ my ($r,$url,$level,$title,$checkstale)=@_;
$url=&unescape($url);
$alreadyseen{$url}=1;
$r->rflush();
@@ -4565,10 +4721,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+)$/;
@@ -4602,7 +4770,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') {
@@ -4616,6 +4784,9 @@ sub checkonthis {
} else {
$r->print(''.&mt('access denied').'');
}
+ if (($updated) && ($result ne 'ok')) {
+ $r->print('
'.&mt('Outdated copy removed'));
+ }
}
}
}
@@ -4668,13 +4839,75 @@ 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('Tiny URLs for deep-linking into course').'
'."\n");
+ $r->rflush();
+ my $readonly;
+ if ($canedit) {
+ my ($numnew,$errors) = &Apache::loncommon::get_requested_shorturls($cdom,$cnum,$navmap);
+ if ($numnew) {
+ $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:').'
');
+ foreach my $error (@{$errors}) {
+ $r->print('- '.$error.'
');
+ }
+ $r->print('
');
+ }
+ } else {
+ $readonly = 1;
+ }
+ my %currtiny = &Apache::lonnet::dump('tiny',$cdom,$cnum);
+ $r->print(&Apache::loncourserespicker::create_picker($navmap,'shorturls',$formname,$crstype,undef,
+ undef,undef,undef,undef,undef,\%currtiny,$readonly));
+ }
+ $r->print(&endContentScreen());
+}
-sub verifycontent {
+sub contentverifyform {
my ($r) = @_;
my $crstype = &Apache::loncommon::course_type();
$r->print(&Apache::loncommon::start_page('Verify '.$crstype.' Content'));
$r->print(&Apache::lonhtmlcommon::breadcrumbs('Verify '.$crstype.' Content'));
$r->print(&startContentScreen('tools'));
+ $r->print(''.&mt($crstype.' content verification').'
');
+ $r->print('');
+ $r->print(&endContentScreen());
+ return;
+}
+
+sub verifycontent {
+ my ($r,$checkstale) = @_;
+ my $crstype = &Apache::loncommon::course_type();
+ $r->print(&Apache::loncommon::start_page('Verify '.$crstype.' Content'));
+ $r->print(&Apache::lonhtmlcommon::breadcrumbs('Verify '.$crstype.' Content'));
+ $r->print(&startContentScreen('tools'));
$r->print(''.&mt($crstype.' content verification').'
');
$hashtied=0;
undef %alreadyseen;
@@ -4691,7 +4924,7 @@ sub verifycontent {
}
}
if (($key=~/^src\_(.+)$/) && (!$alreadyseen{&unescape($hash{$key})})) {
- &checkonthis($r,$hash{$key},0,$hash{'title_'.$1});
+ &checkonthis($r,$hash{$key},0,$hash{'title_'.$1},$checkstale);
}
}
&untiehash();
@@ -4699,7 +4932,6 @@ sub verifycontent {
$r->print(&endContentScreen());
}
-
sub devalidateversioncache {
my $src=shift;
&Apache::lonnet::devalidate_cache_new('courseresversion',$env{'request.course.id'}.'_'.
@@ -5019,13 +5251,17 @@ sub changewarning {
if (!defined($message)) {
$message='Changes will become active for your current session after [_1], or the next time you log in.';
}
+ my $windowname = 'loncapaclient';
+ if ($env{'request.lti.login'}) {
+ $windowname .= 'lti';
+ }
$r->print("\n\n".
''."\n".
-'
+
HIDDENFORM
$r->print(&makesimpleeditform($pathitem)."\n".
@@ -5870,9 +6185,13 @@ HIDDENFORM
}
my $postexec='';
if ($folder eq 'default') {
+ my $windowname = 'loncapaclient';
+ if ($env{'request.lti.login'}) {
+ $windowname .= 'lti';
+ }
$r->print(''."\n"
);
@@ -5885,7 +6204,7 @@ HIDDENFORM
my $newnavform=(<
-
+
$pathitem
@@ -5895,7 +6214,7 @@ HIDDENFORM
NNFORM
my $newsmppageform=(<
-
+
$pathitem
@@ -5905,7 +6224,7 @@ NSPFORM
my $newsmpproblemform=(<
-
+
$pathitem
@@ -5916,7 +6235,7 @@ NSPROBFORM
my $newdropboxform=(<
-
+
$pathitem
@@ -5926,7 +6245,7 @@ NDBFORM
my $newexuploadform=(<
-
+
$pathitem
@@ -5936,7 +6255,7 @@ NEXUFORM
my $newbulform=(<
-
+
$pathitem
@@ -5946,7 +6265,7 @@ NBFORM
my $newaboutmeform=(<
-
+
$pathitem
@@ -5957,7 +6276,7 @@ NAMFORM
my $newaboutsomeoneform=(<
-
+
$pathitem
@@ -5966,7 +6285,7 @@ NASOFORM
my $newrosterform=(<
-
+
$pathitem
@@ -5987,7 +6306,7 @@ NROSTFORM
}
my $newwebpageform =(<
-
+
$pathitem
@@ -6170,7 +6489,7 @@ NWEBFORM
NGFFORM
- @specialdocumentsforma=(
+ if ($container eq 'page') {
+ @specialdocumentsforma=(
+ {''=>$newwebpageform},
+ );
+ } else {
+ @specialdocumentsforma=(
{''=>$newpageform},
{''=>$newsylform},
{''=>$newnavform},
{''=>$newsmppageform},
{''=>$newwebpageform},
- );
+ );
+ }
$specialdocumentsform = &create_form_ul(&create_list_elements(@specialdocumentsforma));
-
- my @importdoc = (
- {''=>$extresourcesform}
+ my @external = (
+ {''=>$extresourcesform}
);
if (keys(%ltitools)) {
- push(@importdoc,
- {''=>$exttoolform},
- );
+ push(@external,
+ {''=>$exttoolform},
+ );
}
+ my $externalform = &create_form_ul(&create_list_elements(@external));
+
+ my @importdoc = ();
unless ($container eq 'page') {
push(@importdoc,
{''=>$imspform}
@@ -6314,12 +6641,13 @@ NGFFORM
my %orderhash = (
'aa' => ['Upload',$fileuploadform],
'bb' => ['Import',$importpubform],
- 'cc' => ['Grading',$gradingform],
+ 'cc' => ['External',$externalform],
+ 'dd' => ['Grading',$gradingform],
+ 'ff' => ['Other',$specialdocumentsform];
);
unless ($container eq 'page') {
$orderhash{'00'} = ['Newfolder',$newfolderform];
- $orderhash{'dd'} = ['Collaboration',$communityform];
- $orderhash{'ee'} = ['Other',$specialdocumentsform];
+ $orderhash{'ee'} = ['Collaboration',$communityform];
}
$hadchanges=0;
@@ -6332,8 +6660,10 @@ unless ($container eq 'page') {
$r->print(''.$error.'
');
}
if ($hadchanges) {
- &mark_hash_old();
- }
+ unless (&is_hash_old()) {
+ &mark_hash_old();
+ }
+ }
&changewarning($r,'');
}
@@ -6453,15 +6783,15 @@ my @specialdocs = (
{''=>$supwebpageform},
);
-my @supimportdoc = (
- {''
- =>$supextform});
+ my @supexternal = (
+ {''
+ =>$supextform});
if (keys(%ltitools)) {
- push(@supimportdoc,
- {''
+ push(@supexternal,
+ {''
=>$supexttoolform});
}
- push(@supimportdoc,
+ my @supimportdoc = (
{''
=>$supupdocform},
);
@@ -6469,7 +6799,8 @@ my @supimportdoc = (
$supupdocform = &create_form_ul(&create_list_elements(@supimportdoc));
my %suporderhash = (
'00' => ['Supnewfolder', $supnewfolderform],
- 'ee' => ['Upload',$supupdocform],
+ 'dd' => ['Upload',$supupdocform],
+ 'ee' => ['External',&create_form_ul(&create_list_elements(@supexternal))],
'ff' => ['Other',&create_form_ul(&create_list_elements(@specialdocs))]
);
if ($supplementalflag) {
@@ -6531,6 +6862,7 @@ my %suporderhash = (
sub embedded_form_elems {
my ($phase,$primaryurl,$newidx) = @_;
my $folderpath = &HTML::Entities::encode($env{'form.folderpath'},'<>&"');
+ $newidx =~s /\D+//g;
return <
@@ -6551,7 +6883,11 @@ sub embedded_destination {
} elsif ($folder =~ /^(default|supplemental)_(\d+)$/) {
$destination .= $2.'/';
}
- $destination .= $env{'form.newidx'};
+ my $newidx = $env{'form.newidx'};
+ $newidx =~s /\D+//g;
+ if ($newidx) {
+ $destination .= $newidx;
+ }
my $dir_root = '/userfiles';
return ($destination,$dir_root);
}
@@ -6577,6 +6913,9 @@ sub decompression_info {
}
unshift(@hiddens,$pathitem);
foreach my $item (@hiddens) {
+ if ($item eq 'newidx') {
+ next if ($env{'form.'.$item} =~ /\D/);
+ }
if ($env{'form.'.$item}) {
$hiddenelem .= ''."\n";
@@ -6689,6 +7028,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",
);
@@ -6739,6 +7079,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) {
@@ -6901,6 +7248,8 @@ sub editing_js {
p_ctr2b => '?',
p_ctr3a => 'Cut those',
p_ctr3b => 'items?',
+ setal => 'Enter a (unique) alias',
+ delal => 'Are you sure you want to eliminate the alias?',
rpck => 'Enter number to pick (e.g., 3)',
imsfile => 'You must choose an IMS package for import',
imscms => 'You must select which Course Management System was the source of the IMS package',
@@ -6945,19 +7294,31 @@ sub editing_js {
} else {
$url = $res;
}
- $backtourl = &HTML::Entities::encode(&Apache::lonnet::clutter($url),'<>&"').'?symb='.
- &HTML::Entities::encode($caller,'<>&"');
+ $backtourl = &HTML::Entities::encode(&Apache::lonnet::clutter($url),'<>&"');
+ if ($backtourl =~ m{^\Q/uploaded/$coursedom/$coursenum/\Edefault_\d+\.sequence$}) {
+ $backtourl .= '?navmap=1';
+ } else {
+ $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://})) {
- if ($hostname ne '') {
- $backtourl = 'http://'.$hostname.$backtourl;
+ unless (&Apache::lonnet::uses_sts()) {
+ if ($hostname ne '') {
+ $backtourl = 'http://'.$hostname.$backtourl;
+ }
+ $backtourl .= (($backtourl =~ /\?/) ? '&':'?').'usehttp=1';
}
- $backtourl .= (($backtourl =~ /\?/) ? '&':'?').'usehttp=1';
}
} elsif ($backtourl =~ m{^/adm/wrapper/ext/(?!https:)}) {
if (($ENV{'SERVER_PORT'} == 443) && ($hostname ne '')) {
- $backtourl = 'http://'.$hostname.$backtourl;
+ unless (&Apache::lonnet::uses_sts()) {
+ if ($hostname ne '') {
+ $backtourl = 'http://'.$hostname.$backtourl;
+ }
+ $backtourl .= (($backtourl =~ /\?/) ? '&':'?').'usehttp=1';
+ }
}
}
if ($anchor ne '') {
@@ -6976,20 +7337,22 @@ sub editing_js {
$backtourl = '/adm/navmaps';
}
- my $fieldsets = "'ext','doc'";
- if ($posslti) {
- $fieldsets .= ",'tool'";
- }
+ my $fieldsets = "'doc'";
unless ($main_container_page) {
$fieldsets .=",'ims'";
}
+ my $extfieldsets = "'ext'";
+ if ($posslti) {
+ $extfieldsets .= ",'tool'";
+ }
if ($supplementalflag) {
- $fieldsets = "'suppext','suppdoc'";
+ $fieldsets = "'suppdoc'";
+ $extfieldsets = "'suppext'";
if ($posslti) {
- $fieldsets .= ",'supptool'";
+ $extfieldsets .= ",'supptool'";
}
}
-
+
my $jsmakefunctions;
if ($canedit) {
$jsmakefunctions = <
END
- close($fh);
- }
- if ((-e $sourcerights) && (-e "$sourcerights.meta")) {
- if (!-e "$docroot/res/$coursedom") {
- mkdir("$docroot/res/$coursedom",0755);
- }
- if (!-e "$docroot/res/$coursedom/$coursenum") {
- mkdir("$docroot/res/$coursedom/$coursenum",0755);
- }
- if ((-e "$docroot/res/$coursedom/$coursenum") && (!-e $targetrights)) {
- my $nokeyref = &Apache::lonpublisher::getnokey($r->dir_config('lonIncludes'));
- my $output = &Apache::lonpublisher::batchpublish($r,$sourcerights,$targetrights,$nokeyref,1);
- }
+ close($fh);
}
}
- if ($env{'form.newresourceadd'}) {
- my $template = $env{'form.template'};
- my $source = $docroot.$redirect;
- my $target = $redirect;
- $target =~ s{^/priv/}{/res/};
- $target = $docroot.$target;
- if (!-e $source) {
- my $copyfrom;
- if ($template) {
- my %templates;
- my @files = &Apache::lonhomework::get_template_list('problem');
- foreach my $poss (@files) {
- if (ref($poss) eq 'ARRAY') {
- if ($template eq $poss->[0]) {
- $templates{$template} = 1;
- last;
- }
- }
- }
- if ($templates{$template}) {
- $copyfrom = $template;
- }
- }
- unless ($copyfrom) {
- $copyfrom = $r->dir_config('lonIncludes').'/templates/blank.problem';
- }
- &File::Copy::copy($copyfrom,$source);
+ if ((-e $sourcerights) && (-e "$sourcerights.meta")) {
+ if (!-e "$docroot/res/$coursedom") {
+ mkdir("$docroot/res/$coursedom",0755);
}
- if (!-e "$source.meta") {
- my $cid = $coursedom.'_'.$coursenum;
- my $now = time;
- if (open(my $fh,">$source.meta")) {
- my $author=$env{'environment.firstname'}.' '.
- $env{'environment.middlename'}.' '.
- $env{'environment.lastname'}.' '.
- $env{'environment.generation'};
- $author =~ s/\s+$//;
- my $title = $env{'form.newresourcetitle'};
- $title =~ s/^\s+|\s+$//g;
- print $fh <dir_config('lonIncludes'));
+ my $output = &Apache::lonpublisher::batchpublish($r,$sourcerights,$targetrights,$nokeyref,1);
+ }
+ }
+ my $source = $docroot.$redirect;
+ if (!-e "$source.meta") {
+ my $cid = $coursedom.'_'.$coursenum;
+ my $now = time;
+ if (open(my $fh,">$source.meta")) {
+ my $author=$env{'environment.firstname'}.' '.
+ $env{'environment.middlename'}.' '.
+ $env{'environment.lastname'}.' '.
+ $env{'environment.generation'};
+ $author =~ s/\s+$//;
+ my $title = $env{'form.newresourcetitle'};
+ $title =~ s/^\s+|\s+$//g;
+ print $fh <
$author
@@ -8458,8 +8838,7 @@ END
$title
END
- close($fh);
- }
+ close($fh);
}
}
}
@@ -8487,7 +8866,7 @@ END
}
sub finishnewprob {
- my ($url,$path,$subdir,$newsubdir,$filename) = @_;
+ my ($url,$path,$subdir,$newsubdir,$filename,$context) = @_;
unless (-d $path) {
unless (mkdir($path,02770)) {
return;
@@ -8530,6 +8909,31 @@ sub finishnewprob {
$redirect = "$url/$filename";
}
}
+ if ((!-e $dest) && ($context ne 'upload')) {
+ my $template = $env{'form.template'};
+ my $copyfrom;
+ if ($template ne '') {
+ my %templates;
+ my @files = &Apache::lonhomework::get_template_list('problem');
+ foreach my $poss (@files) {
+ if (ref($poss) eq 'ARRAY') {
+ if ($template eq $poss->[0]) {
+ $templates{$template} = 1;
+ last;
+ }
+ }
+ }
+ if ($templates{$template}) {
+ $copyfrom = $template;
+ }
+ }
+ if ($filename =~ /\.problem$/) {
+ unless ($copyfrom) {
+ $copyfrom = $Apache::lonnet::perlvar{'lonIncludes'}.'/templates/blank.problem';
+ }
+ &File::Copy::copy($copyfrom,$dest);
+ }
+ }
return $redirect;
}
@@ -8641,7 +9045,9 @@ check on this
Verify Content
-=item devalidateversioncache() & checkversions()
+=item devalidateversioncache()
+
+=item checkversions()
Check Versions