--- loncom/interface/londocs.pm 2017/11/10 15:47:49 1.641
+++ loncom/interface/londocs.pm 2018/04/14 00:10:48 1.652
@@ -1,7 +1,7 @@
# The LearningOnline Network
# Documents
#
-# $Id: londocs.pm,v 1.641 2017/11/10 15:47:49 raeburn Exp $
+# $Id: londocs.pm,v 1.652 2018/04/14 00:10:48 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('- '.
@@ -1852,13 +1901,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;
@@ -1950,6 +2004,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';
@@ -2198,6 +2264,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') {
@@ -2482,16 +2551,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) ||
@@ -2755,7 +2846,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;
@@ -2765,7 +2857,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;
@@ -2807,7 +2899,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);
}
}
}
@@ -4311,7 +4403,7 @@ $form_end;
$reinit = &mt('(re-initialize course to access)');
}
$line.='
'.$editlink.$renamelink;
- if ($url =~ /$LONCAPA::assess_re/) {
+ if ($orig_url =~ /$LONCAPA::assess_re/) {
$line.= ' ';
if ($curralias ne '') {
$line.=''.
@@ -4721,6 +4813,48 @@ 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::make_short_symbs($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 contentverifyform {
my ($r) = @_;
my $crstype = &Apache::loncommon::course_type();
@@ -5256,6 +5390,9 @@ sub handler {
} elsif ($allowed && $env{'form.listsymbs'}) {
&init_breadcrumbs('listsymbs','List Content IDs');
&list_symbs($r);
+ } elsif ($allowed && $env{'form.shorturls'}) {
+ &init_breadcrumbs('shorturls','Set/Display Shortened URLs','Docs_Short_URLs');
+ &short_urls($r,$canedit);
} elsif ($allowed && $env{'form.docslog'}) {
&init_breadcrumbs('docslog','Show Log');
my $folder = $env{'form.folder'};
@@ -5590,7 +5727,7 @@ sub handler {
}
}
my $tabidstr = join("','",@tabids);
- %ltitools = &Apache::lonnet::get_domain_ltitools($coursedom);
+ %ltitools = &Apache::lonnet::get_domain_lti($coursedom,'consumer');
my $posslti = keys(%ltitools);
my $hostname = $r->hostname();
$script .= &editing_js($udom,$uname,$supplementalflag,$coursedom,$coursenum,$posslti,
@@ -6845,6 +6982,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",
);
@@ -6895,6 +7033,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) {
|