--- loncom/interface/londocs.pm 2015/03/24 10:05:45 1.484.2.60 +++ loncom/interface/londocs.pm 2020/04/10 12:52:34 1.484.2.72.4.2 @@ -1,7 +1,7 @@ # The LearningOnline Network # Documents # -# $Id: londocs.pm,v 1.484.2.60 2015/03/24 10:05:45 raeburn Exp $ +# $Id: londocs.pm,v 1.484.2.72.4.2 2020/04/10 12:52:34 raeburn Exp $ # # Copyright Michigan State University Board of Trustees # @@ -139,7 +139,43 @@ sub clean { return $title; } - +sub default_folderpath { + my ($coursenum,$coursedom,$navmapref) = @_; + return unless ($coursenum && $coursedom && ref($navmapref)); +# Check if entire course is hidden and/or encrypted + my ($hiddenmap,$encryptmap,$folderpath,$hiddentop); + my $toplevel = "uploaded/$coursedom/$coursenum/default.sequence"; + unless (ref($$navmapref)) { + $$navmapref = Apache::lonnavmaps::navmap->new(); + } + if (ref($$navmapref)) { + if (lc($$navmapref->get_mapparam(undef,$toplevel,"0.hiddenresource")) eq 'yes') { + my $filterFunc = sub { my $res = shift; return (!$res->randomout() && !$res->is_map()) }; + my @resources = $$navmapref->retrieveResources($toplevel,$filterFunc,1,1); + unless (@resources) { + $hiddenmap = 1; + unless ($env{'request.role.adv'}) { + $hiddentop = 1; + if ($env{'form.folder'}) { + undef($env{'form.folder'}); + } + } + } + } + if (lc($$navmapref->get_mapparam(undef,$toplevel,"0.encrypturl")) eq 'yes') { + $encryptmap = 1; + } + } + unless ($hiddentop) { + $folderpath='default&'.&escape(&mt('Main Content')). + '::'.$hiddenmap.':'.$encryptmap.'::'; + } + if (wantarray) { + return ($folderpath,$hiddentop); + } else { + return $folderpath; + } +} sub dumpcourse { my ($r) = @_; @@ -586,7 +622,7 @@ sub recurse_html { } sub group_import { - my ($coursenum, $coursedom, $folder, $container, $caller, @files) = @_; + my ($coursenum, $coursedom, $folder, $container, $caller, $ltitoolsref, @files) = @_; my ($donechk,$allmaps,%hierarchy,%titles,%addedmaps,%removefrommap, %removeparam,$importuploaded,$fixuperrors); $allmaps = {}; @@ -615,6 +651,112 @@ sub group_import { } } if ($url) { + if ($url =~ m{^(/adm/$coursedom/$coursenum/(\d+)/ext\.tool)\:?(.*)$}) { + $url = $1; + my $marker = $2; + my $info = $3; + my ($toolid,%toolhash,%toolsettings); + my @extras = ('linktext','explanation','crslabel','crstitle','crsappend'); + my @toolinfo = split(/:/,$info); + if ($residx) { + %toolsettings=&Apache::lonnet::dump('exttool_'.$marker,$coursedom,$coursenum); + $toolid = $toolsettings{'id'}; + } else { + $toolid = shift(@toolinfo); + } + $toolid =~ s/\D//g; + ($toolhash{'target'},$toolhash{'width'},$toolhash{'height'}, + $toolhash{'linktext'},$toolhash{'explanation'}, + $toolhash{'crslabel'},$toolhash{'crstitle'},$toolhash{'crsappend'}) = @toolinfo; + foreach my $item (@extras) { + $toolhash{$item} = &unescape($toolhash{$item}); + } + if (ref($ltitoolsref) eq 'HASH') { + my @deleted; + if (ref($ltitoolsref->{$toolid}) eq 'HASH') { + $toolhash{'id'} = $toolid; + if (($toolhash{'target'} eq 'iframe') || ($toolhash{'target'} eq 'tab') || + ($toolhash{'target'} eq 'window')) { + if ($toolhash{'target'} eq 'window') { + foreach my $item ('width','height') { + $toolhash{$item} =~ s/^\s+//; + $toolhash{$item} =~ s/\s+$//; + if ($toolhash{$item} =~ /\D/) { + delete($toolhash{$item}); + if ($residx) { + if ($toolsettings{$item}) { + push(@deleted,$item); + } + } + } + } + } + } elsif ($residx) { + $toolhash{'target'} = $toolsettings{'target'}; + if ($toolhash{'target'} eq 'window') { + foreach my $item ('width','height') { + $toolhash{$item} = $toolsettings{$item}; + } + } + } elsif (ref($ltitoolsref->{$toolid}->{'display'}) eq 'HASH') { + $toolhash{'target'} = $ltitoolsref->{$toolid}->{'display'}->{'target'}; + if ($toolhash{'target'} eq 'window') { + $toolhash{'width'} = $ltitoolsref->{$toolid}->{'display'}->{'width'}; + $toolhash{'height'} = $ltitoolsref->{$toolid}->{'display'}->{'height'}; + } + } + if ($toolhash{'target'} eq 'iframe') { + foreach my $item ('width','height','linktext','explanation') { + delete($toolhash{$item}); + if ($residx) { + if ($toolsettings{$item}) { + push(@deleted,$item); + } + } + } + } elsif ($toolhash{'target'} eq 'tab') { + foreach my $item ('width','height') { + delete($toolhash{$item}); + if ($residx) { + if ($toolsettings{$item}) { + push(@deleted,$item); + } + } + } + } + if (ref($ltitoolsref->{$toolid}->{'crsconf'}) eq 'HASH') { + foreach my $item ('label','title','linktext','explanation') { + my $crsitem; + if (($item eq 'label') || ($item eq 'title')) { + $crsitem = 'crs'.$item; + } else { + $crsitem = $item; + } + if ($ltitoolsref->{$toolid}->{'crsconf'}->{$item}) { + $toolhash{$crsitem} =~ s/^\s+//; + $toolhash{$crsitem} =~ s/\s+$//; + if ($toolhash{$crsitem} eq '') { + delete($toolhash{$crsitem}); + } + } else { + delete($toolhash{$crsitem}); + } + if (($residx) && (exists($toolsettings{$crsitem}))) { + unless (exists($toolhash{$crsitem})) { + push(@deleted,$crsitem); + } + } + } + } + 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 (($caller eq 'londocs') && ($folder =~ /^default/)) { if (($url =~ /\.(page|sequence)$/) && (!$donechk)) { @@ -626,8 +768,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}); @@ -652,7 +794,7 @@ sub group_import { } else { $fname =~ s/\W/_/g; } - if (length($fname > 15)) { + if (length($fname) > 15) { $fname = substr($fname,0,14); } my $initialtext = &mt('Replace with your own content.'); @@ -791,12 +933,14 @@ sub log_docs { } sub docs_change_log { - my ($r,$coursenum,$coursedom,$folder,$allowed,$crstype,$iconpath)=@_; + my ($r,$coursenum,$coursedom,$folder,$allowed,$crstype,$iconpath,$canedit)=@_; my $supplementalflag=($env{'form.folderpath'}=~/^supplemental/); + my $navmap; my $js = '