--- loncom/interface/londocs.pm 2021/04/23 01:37:14 1.677 +++ loncom/interface/londocs.pm 2022/10/29 14:47:00 1.687 @@ -1,7 +1,7 @@ # The LearningOnline Network # Documents # -# $Id: londocs.pm,v 1.677 2021/04/23 01:37:14 raeburn Exp $ +# $Id: londocs.pm,v 1.687 2022/10/29 14:47:00 raeburn Exp $ # # Copyright Michigan State University Board of Trustees # @@ -91,7 +91,7 @@ sub storemap { if ($map =~ /^default/) { $hadchanges=1; - } else { + } elsif ($contentchg) { $suppchanges=1; } return ($errtext,0); @@ -183,43 +183,62 @@ sub default_folderpath { } } -sub validate_folderpath { - my ($supplementalflag) = @_; - if ($env{'form.folderpath'} ne '') { - my @items = split(/\&/,$env{'form.folderpath'}); - my $badpath; - for (my $i=0; $i<@items; $i++) { - my $odd = $i%2; - if (($odd) && (!$supplementalflag) && ($items[$i] !~ /^[^:]*:(|\d+):(|1):(|1):(|1):(|1)$/)) { - $badpath = 1; - } elsif ((!$odd) && ($items[$i] !~ /^(default|supplemental)(|_\d+)$/)) { - $badpath = 1; - } - last if ($badpath); - } - if ($badpath) { - delete($env{'form.folderpath'}); - } - } - return; -} - -sub validate_suppath { +sub validate_supppath { + my ($coursenum,$coursedom) = @_; + my $backto; if ($env{'form.supppath'} ne '') { my @items = split(/\&/,$env{'form.supppath'}); - my $badpath; + my ($badpath,$got_supp,$supppath,%supphidden,%suppids); for (my $i=0; $i<@items; $i++) { my $odd = $i%2; if ((!$odd) && ($items[$i] !~ /^supplemental(|_\d+)$/)) { $badpath = 1; + last; + } elsif ($odd) { + my $suffix; + my $idx = $i-1; + if ($items[$i] =~ /^([^:]*)::(|1):::$/) { + $backto .= '&'.$1; + } elsif ($items[$idx] eq 'supplemental') { + $backto .= '&'.$items[$i]; + } else { + $backto .= '&'.$items[$i]; + my $is_hidden; + unless ($got_supp) { + my ($supplemental) = &Apache::lonnet::get_supplemental($coursenum,$coursedom); + if (ref($supplemental) eq 'HASH') { + if (ref($supplemental->{'hidden'}) eq 'HASH') { + %supphidden = %{$supplemental->{'hidden'}}; + } + if (ref($supplemental->{'ids'}) eq 'HASH') { + %suppids = %{$supplemental->{'ids'}}; + } + } + $got_supp = 1; + } + if (ref($suppids{"/uploaded/$coursedom/$coursenum/$items[$idx].sequence"}) eq 'ARRAY') { + my $mapid = $suppids{"/uploaded/$coursedom/$coursenum/$items[$idx].sequence"}->[0]; + if ($supphidden{$mapid}) { + $is_hidden = 1; + } + } + $suffix = '::'.$is_hidden.':::'; + } + $supppath .= '&'.$items[$i].$suffix; + } else { + $supppath .= '&'.$items[$i]; + $backto .= '&'.$items[$i]; } - last if ($badpath); } if ($badpath) { delete($env{'form.supppath'}); + } else { + $supppath =~ s/^\&//; + $backto =~ s/^\&//; + $env{'form.supppath'} = $supppath; } } - return; + return $backto; } sub dumpcourse { @@ -955,7 +974,6 @@ END &storemap($coursenum, $coursedom, $folder.'.'.$container,1); unless ($fatal) { if ($folder =~ /^supplemental/) { - &Apache::lonnet::get_numsuppfiles($coursenum,$coursedom,1); my ($errtext,$fatal) = &mapread($coursenum,$coursedom, $folder.'.'.$container); } @@ -1495,7 +1513,7 @@ sub print_paste_buffer { } $pasteitems .= ''; if ($nopaste) { - $pasteitems .= $nopaste; + $pasteitems .= ' '.$nopaste.''; } else { if ($othercrs) { $pasteitems .= $othercrs; @@ -2800,6 +2818,15 @@ sub apply_fixups { $storefn =~ s/^((?:default|supplemental)_)(\d+)/$1$newsubdir{$key}/; } my $mapcontent = &Apache::lonnet::getfile($key); + if (($mapcontent eq '-1') && ($before{'map'} eq 'supplemental') && + ($after{'map'} eq 'default') && + ($key =~ m{^/uploaded/$match_domain/$match_courseid/supplemental_\d+\.sequence$})) { + $mapcontent = ''; + } if ($mapcontent eq '-1') { if (ref($errors) eq 'HASH') { $errors->{$key} = 1; @@ -3534,6 +3561,21 @@ sub editor { $r->print(''); } + if ((!$allowed) && ($folder =~ /^supplemental_\d+$/)) { + my ($supplemental) = &Apache::lonnet::get_supplemental($coursenum,$coursedom); + if (ref($supplemental) eq 'HASH') { + if ((ref($supplemental->{'hidden'}) eq 'HASH') && + (ref($supplemental->{'ids'}) eq 'HASH')) { + if (ref($supplemental->{'ids'}->{"/uploaded/$coursedom/$coursenum/$folder.$container"}) eq 'ARRAY') { + my $mapnum = $supplemental->{'ids'}->{"/uploaded/$coursedom/$coursenum/$folder.$container"}->[0]; + if ($supplemental->{'hidden'}->{$mapnum}) { + $ishidden = 1; + } + } + } + } + } + my ($to_show,$output,@allidx,@allmapidx,%filters,%lists,%curr_groups); %filters = ( canremove => [], @@ -3557,11 +3599,17 @@ sub editor { push(@allmapidx,$res); } + if (($supplementalflag) && (!$allowed) && (!$env{'request.role.adv'})) { + if (($ishidden) || ((&LONCAPA::map::getparameter($res,'parameter_hiddenresource'))[0]=~/^yes$/i)) { + $idx++; + next; + } + } $output .= &entryline($idx,$name,$url,$folder,$allowed,$res, $coursenum,$coursedom,$crstype, $pathitem,$supplementalflag,$container, \%filters,\%curr_groups,$ltitoolsref,$canedit, - $isencrypted,$navmapref,$hostname); + $isencrypted,$ishidden,$navmapref,$hostname); $idx++; $shown++; } @@ -3570,10 +3618,14 @@ sub editor { my $need_save; if ($allowed || ($supplementalflag && $folder eq 'supplemental')) { my $toolslink; - if ($allowed) { + if ($allowed || $canedit) { + my $helpitem = 'Navigation_Screen'; + if (!$allowed) { + $helpitem = 'Supplemental_Navigation'; + } $toolslink = '
' .&Apache::loncommon::help_open_menu('Navigation Screen', - 'Navigation_Screen',undef,'RAT') + $helpitem,undef,'RAT') .' | '.&mt('Tools:').' | ' .'
| ';
- my $link;
+ my ($link,$nolink);
if (($url=~m{/adm/(coursedocs|supplemental)}) || (!$allowed && $url)) {
- $line.=' | ';
if (($url=~m{/adm/(coursedocs|supplemental)}) || (!$allowed && $url)) {
- $line.=''.$title.'';
+ if ($nolink) {
+ $line.=$title;
+ } else {
+ $line.=''.$title.'';
+ }
+ if (!$allowed && $supplementalflag && $canedit && $isfolder) {
+ my $editicon = &Apache::loncommon::lonhttpdurl('/res/adm/pages').'/editmap.png';
+ my $editurl = $url;
+ $editurl =~ s{^\Q/adm/supplemental?\E}{/adm/coursedocs?command=direct&forcesupplement=1&};
+ $line .= ' '.''.
+ ' | ';
$rand_pick_text = ' ' if ($rand_pick_text eq '');
$rand_order_text = ' ' if ($rand_order_text eq '');
- if (($allowed) && ($folder!~/^supplemental/)) {
- my %lt=&Apache::lonlocal::texthash(
- 'hd' => 'Hidden',
- 'ec' => 'URL hidden');
- my ($enctext,$hidtext);
- if ((&LONCAPA::map::getparameter($orderidx,'parameter_encrypturl'))[0]=~/^yes$/i) {
- $enctext = ' checked="checked"';
- if (($ishash) && (ref($filtersref->{'encrypturl'}) eq 'ARRAY')) {
- push(@{$filtersref->{'encrypturl'}},$orderidx);
- }
+ if ($uploaded && $url && !$isfolder && !$ispage) {
+ if (($plainurl ne '') && ($env{'request.role.adv'} || $allowed || !$hiddenres)) {
+ &Apache::lonnet::allowuploaded('/adm/coursedoc',$plainurl);
}
+ }
+ if ($allowed) {
+ my %lt=&Apache::lonlocal::texthash(
+ 'hd' => 'Hidden',
+ 'ec' => 'URL hidden');
+ my ($enctext,$hidtext,$formhidden,$formurlhidden);
if ((&LONCAPA::map::getparameter($orderidx,'parameter_hiddenresource'))[0]=~/^yes$/i) {
$hidtext = ' checked="checked"';
if (($ishash) && (ref($filtersref->{'randomorder'}) eq 'ARRAY')) {
push(@{$filtersref->{'hiddenresource'}},$orderidx);
}
}
- my $formhidden = 'edit_hiddenresource_'.$orderidx;
- my $formurlhidden = 'edit_encrypturl_'.$orderidx;
- $line.=(<