--- loncom/interface/londocs.pm 2018/01/12 01:54:56 1.650 +++ loncom/interface/londocs.pm 2018/01/12 13:33:37 1.651 @@ -1,7 +1,7 @@ # The LearningOnline Network # Documents # -# $Id: londocs.pm,v 1.650 2018/01/12 01:54:56 raeburn Exp $ +# $Id: londocs.pm,v 1.651 2018/01/12 13:33:37 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; @@ -4812,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:').'

'); + } + } 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(); @@ -5347,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'}; @@ -6936,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", ); @@ -6986,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) {