--- loncom/interface/londocs.pm 2017/05/08 14:20:20 1.626 +++ loncom/interface/londocs.pm 2017/05/10 00:03:08 1.627 @@ -1,7 +1,7 @@ # The LearningOnline Network # Documents # -# $Id: londocs.pm,v 1.626 2017/05/08 14:20:20 raeburn Exp $ +# $Id: londocs.pm,v 1.627 2017/05/10 00:03:08 raeburn Exp $ # # Copyright Michigan State University Board of Trustees # @@ -761,8 +761,8 @@ sub group_import { $donechk = 1; } if ($url =~ m{^/uploaded/\Q$coursedom\E/\Q$coursenum\E/(default_\d+\.)(page|sequence)$}) { - &contained_map_check($url,$folder,\%removefrommap,\%removeparam, - \%addedmaps,\%hierarchy,\%titles,$allmaps); + &contained_map_check($url,$folder,$coursenum,$coursedom,\%removefrommap, + \%removeparam,\%addedmaps,\%hierarchy,\%titles,$allmaps); $importuploaded = 1; } elsif ($url =~ m{^/res/.+\.(page|sequence)$}) { next if ($allmaps->{$url}); @@ -1213,8 +1213,8 @@ sub update_paste_buffer { $subdir = $prefix; } my (%addedmaps,%removefrommap,%removeparam,%hierarchy,%titles,%allmaps); - &contained_map_check($url,$folder,\%removefrommap,\%removeparam,\%addedmaps, - \%hierarchy,\%titles,\%allmaps); + &contained_map_check($url,$folder,$coursenum,$coursedom,\%removefrommap, + \%removeparam,\%addedmaps,\%hierarchy,\%titles,\%allmaps); if (ref($hierarchy{$url}) eq 'HASH') { my ($nested,$nestednames); &recurse_uploaded_maps($url,$subdir,\%hierarchy,\%titles,\$nested,\$nestednames); @@ -1326,11 +1326,16 @@ sub print_paste_buffer { $is_uploaded_map = 1; } } elsif (($url =~ m{^/res/lib/templates/\w+\.problem$}) || - ($url =~ m{^/adm/($match_domain)/($match_username)/\d+/(bulletinboard|smppg)$})) { + ($url =~ m{^/adm/($match_domain)/($match_username)/\d+/(bulletinboard|smppg|ext\.tool)$})) { if ($cid ne $env{'request.course.id'}) { my ($srcdom,$srcnum) = split(/_/,$cid); if ($env{"user.priv.cm./$srcdom/$srcnum"} =~ /\Q:mdc&F\E/) { - $othercrs = '
'.&mt('(from another course)'); + if (($is_exttool) && ($srcdom ne $coursedom)) { + $canpaste = 0; + $nopaste = &mt('Paste from another domain unavailable.'); + } else { + $othercrs = '
'.&mt('(from another course)'); + } } else { $canpaste = 0; $nopaste = &mt('Paste from another course unavailable.'); @@ -1342,10 +1347,13 @@ sub print_paste_buffer { } } my $buffer; - if (($is_external) || ($is_exttool)) { + if ($is_external) { $buffer = &mt('External Resource').': '. &LONCAPA::map::qtescape($env{'docs.markedcopy_title_'.$suffix}).' ('. &LONCAPA::map::qtescape($url).')'; + } elsif ($is_exttool) { + $buffer = &mt('External Tool').': '. + &LONCAPA::map::qtescape($env{'docs.markedcopy_title_'.$suffix}); } else { my $icon = &Apache::loncommon::icon($extension); if ($extension eq 'sequence' && @@ -1625,7 +1633,7 @@ sub do_paste_from_buffer { return(); } - my (%msgs,%before,%after,@dopaste,%is_map,%notinsupp,%notincrs,%duplicate, + my (%msgs,%before,%after,@dopaste,%is_map,%notinsupp,%notincrs,%notindom,%duplicate, %prefixchg,%srcdom,%srcnum,%srcmapidx,%marktomove,$save_err,$lockerrors,$allresult); foreach my $suffix (@topaste) { @@ -1654,7 +1662,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)$})) { + ($url =~ m{^/adm/$match_domain/$match_username/\d+/(bulletinboard|smppg|ext\.tool)$})) { + my $srctype= $1; 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 @@ -1664,6 +1673,10 @@ sub do_paste_from_buffer { next; } } + if (($srctype eq 'ext.tool') && ($srcd ne $coursedom)) { + $notindom{$suffix} = 1; + next; + } $srcdom{$suffix} = $srcd; $srcnum{$suffix} = $srcn; } @@ -1672,7 +1685,6 @@ sub do_paste_from_buffer { if ($url=~/\.(page|sequence)$/) { $is_map{$suffix} = 1; } - if ($url =~ m{^/uploaded/$match_domain/$match_courseid/([^/]+)}) { my $oldprefix = $1; # When pasting content from Main Content to Supplemental Content and vice versa @@ -1717,6 +1729,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.', duplicate => 'Paste failed: only one instance of a particular published sequence or page is allowed within each course.', ); @@ -1770,8 +1783,9 @@ sub do_paste_from_buffer { if ($is_map{$suffix}) { # If pasting a map, check if map contains other maps my (%hierarchy,%titles); - &contained_map_check($url,$folder,\%removefrommap,\%removeparam, - \%addedmaps,\%hierarchy,\%titles,$allmaps); + &contained_map_check($url,$folder,$coursenum,$coursedom, + \%removefrommap,\%removeparam,\%addedmaps, + \%hierarchy,\%titles,$allmaps); if ($url=~ m{^/uploaded/}) { my $newurl; unless ($env{'form.docs.markedcopy_options_'.$suffix} eq 'move') { @@ -1824,7 +1838,7 @@ sub do_paste_from_buffer { } } } - if ($url=~ m{/(bulletinboard|smppg)$}) { + 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. @@ -1852,6 +1866,8 @@ sub do_paste_from_buffer { $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; $msgerrs{$suffix} = $msg; @@ -2111,8 +2127,11 @@ sub dbcopy { my ($url,$result,$errtext); if (ref($dbref) eq 'HASH') { $url = $dbref->{'src'}; - if ($url =~ m{/(smppg|bulletinboard)$}) { + if ($url =~ m{/(smppg|bulletinboard|ext\.tool)$}) { my $prefix = $1; + if ($prefix eq 'ext.tool') { + $prefix = 'exttool'; + } if (($dbref->{'cdom'} =~ /^$match_domain$/) && ($dbref->{'cnum'} =~ /^$match_courseid$/)) { my $db_name; @@ -2123,6 +2142,8 @@ sub dbcopy { &Apache::lonsimplepage::get_db_name($url,$marker, $dbref->{'cdom'}, $dbref->{'cnum'}); + } elsif ($dbref->{'src'} =~ m{/ext\.tool$}) { + $db_name = 'exttool_'.$marker; } else { $db_name = 'bulletinpage_'.$marker; } @@ -2166,7 +2187,7 @@ sub dbcopy { $result=&Apache::lonnet::put($db_name,\%contents, $coursedom,$coursenum); if ($result eq 'ok') { - $url =~ s{/(\d*)/(smppg|bulletinboard)$}{/$suffix/$2}x; + $url =~ s{/(\d*)/(smppg|bulletinboard|ext\.tool)$}{/$suffix/$2}x; } } if (($freedlock ne 'ok') && (ref($lockerrorsref) eq 'HASH')) { @@ -2176,6 +2197,9 @@ sub dbcopy { if ($prefix eq 'smppg') { $lockerrorsref->{$prefix} .= ' '.&mt('This will prevent creation of additional simple pages in this course.'); + } elsif ($prefix eq 'exttool') { + $lockerrorsref->{$prefix} .= + ' '.&mt('This will prevent addition of more external tools to this course.'); } else { $lockerrorsref->{$prefix} .= ' '.&mt('This will prevent creation of additional discussion boards in this course.'); } @@ -2305,8 +2329,8 @@ sub uniqueness_check { } sub contained_map_check { - my ($url,$folder,$removefrommap,$removeparam,$addedmaps,$hierarchy,$titles, - $allmaps) = @_; + my ($url,$folder,$coursenum,$coursedom,$removefrommap,$removeparam,$addedmaps, + $hierarchy,$titles,$allmaps) = @_; my $content = &Apache::lonnet::getfile($url); unless ($content eq '-1') { my $parser = HTML::TokeParser->new(\$content); @@ -2316,7 +2340,13 @@ sub contained_map_check { if ($token->[1] eq 'resource') { next if ($token->[2]->{'type'} eq 'zombie'); my $ressrc = $token->[2]->{'src'}; - if ($folder =~ /^supplemental/) { + if ($ressrc =~ m{^/adm/($match_domain)/$match_courseid/\d+/ext\.tool$}) { + my $srcdom = $1; + unless ($srcdom eq $coursedom) { + $removefrommap->{$url}{$token->[2]->{'id'}} = $ressrc; + next; + } + } elsif ($folder =~ /^supplemental/) { unless (&supp_pasteable($ressrc)) { $removefrommap->{$url}{$token->[2]->{'id'}} = $ressrc; next; @@ -2335,8 +2365,8 @@ sub contained_map_check { $addedmaps->{$ressrc} = [$url]; } } - &contained_map_check($ressrc,$folder,$removefrommap,$removeparam, - $addedmaps,$hierarchy,$titles,$allmaps); + &contained_map_check($ressrc,$folder,$coursenum,$coursedom,$removefrommap, + $removeparam,$addedmaps,$hierarchy,$titles,$allmaps); } } elsif ($token->[1] eq 'param') { if ($folder =~ /^supplemental/) { @@ -5083,12 +5113,12 @@ sub handler { # # --------------------------------------------- Initialize help topics for this foreach my $topic ('Adding_Course_Doc','Main_Course_Documents', - 'Adding_External_Resource','Navigate_Content', - 'Adding_Folders','Docs_Overview', 'Load_Map', - 'Supplemental','Score_Upload_Form','Adding_Pages', - 'Importing_LON-CAPA_Resource','Importing_IMS_Course', - 'Uploading_From_Harddrive','Course_Roster','Web_Page', - 'Dropbox','Simple_Problem') { + 'Adding_External_Resource','Adding_External_Tool', + 'Navigate_Content','Adding_Folders','Docs_Overview', + 'Load_Map','Supplemental','Score_Upload_Form', + 'Adding_Pages','Importing_LON-CAPA_Resource', + 'Importing_IMS_Course','Uploading_From_Harddrive', + 'Course_Roster','Web_Page','Dropbox','Simple_Problem') { $help{$topic}=&Apache::loncommon::help_open_topic('Docs_'.$topic); } # Composite help files @@ -6239,7 +6269,7 @@ NGFFORM ); if (keys(%ltitools)) { push(@importdoc, - {''.$lt{extt}.''=>$exttoolform}, + {''.$lt{extt}.''=>$exttoolform}, ); } unless ($container eq 'page') { @@ -6416,7 +6446,7 @@ my @supimportdoc = ( =>$supextform}); if (keys(%ltitools)) { push(@supimportdoc, - {''.$lt{extt}.'' + {''.$lt{extt}.'' =>$supexttoolform}); } push(@supimportdoc, @@ -6911,7 +6941,7 @@ sub editing_js { 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 '')) {