--- loncom/interface/londocs.pm 2017/12/29 15:11:18 1.647 +++ loncom/interface/londocs.pm 2018/04/14 02:29:44 1.653 @@ -1,7 +1,7 @@ # The LearningOnline Network # Documents # -# $Id: londocs.pm,v 1.647 2017/12/29 15:11:18 raeburn Exp $ +# $Id: londocs.pm,v 1.653 2018/04/14 02:29:44 raeburn Exp $ # # Copyright Michigan State University Board of Trustees # @@ -46,6 +46,7 @@ use Apache::lonsimplepage(); use Apache::lonhomework(); use Apache::lonpublisher(); use Apache::lonparmset(); +use Apache::loncourserespicker(); use HTML::Entities; use HTML::TokeParser; use GDBM_File; @@ -677,7 +678,9 @@ sub group_import { $toolhash{$item} = &unescape($toolhash{$item}); } if ($folder =~ /^supplemental/) { - delete($toolhash{'gradable'}); + delete($toolhash{'gradable'}); + } else { + $toolhash{'gradable'} =~ s/\D+//g; } if (ref($ltitoolsref) eq 'HASH') { if (ref($ltitoolsref->{$toolid}) eq 'HASH') { @@ -768,14 +771,20 @@ sub group_import { } my $changegradable; if (($residx) && ($folder =~ /^default/)) { - if (exists($toolsettings{'gradable'})) { - if (!exists($toolhash{'gradable'})) { + if ($toolsettings{'gradable'}) { + unless (($toolhash{'gradable'}) || (defined($LONCAPA::map::zombies[$residx]))) { push(@deleted,'gradable'); $changegradable = 1; } - } elsif (exists($toolhash{'gradable'})) { + } 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') { @@ -1892,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; @@ -1990,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'; @@ -2238,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') { @@ -2522,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) || @@ -4352,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.=''. @@ -4762,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(); @@ -5132,13 +5225,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". -'
'. +''. '

'. &mt($message,' '."\n" .'// '."\n" .''."\n" ); @@ -6886,6 +6990,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", ); @@ -6936,6 +7041,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) {