--- loncom/interface/londocs.pm 2021/02/09 22:12:33 1.675 +++ 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.675 2021/02/09 22:12:33 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,6 +183,64 @@ sub default_folderpath { } } +sub validate_supppath { + my ($coursenum,$coursedom) = @_; + my $backto; + if ($env{'form.supppath'} ne '') { + my @items = split(/\&/,$env{'form.supppath'}); + 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]; + } + } + if ($badpath) { + delete($env{'form.supppath'}); + } else { + $supppath =~ s/^\&//; + $backto =~ s/^\&//; + $env{'form.supppath'} = $supppath; + } + } + return $backto; +} + sub dumpcourse { my ($r) = @_; my $crstype = &Apache::loncommon::course_type(); @@ -916,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); } @@ -1456,7 +1513,7 @@ sub print_paste_buffer { } $pasteitems .= ''; if ($nopaste) { - $pasteitems .= $nopaste; + $pasteitems .= ' '.$nopaste.''; } else { if ($othercrs) { $pasteitems .= $othercrs; @@ -2761,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; @@ -3495,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 => [], @@ -3518,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++; } @@ -3531,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 ($allowed && !$env{'request.role.adv'} && !$isfolder && !$ispage) { + if ((&LONCAPA::map::getparameter($orderidx,'parameter_hiddenresource'))[0]=~/^yes$/i) { + $nolink = 1; + } + } + if ($nolink) { + $line .= ''; + } else { + $line.=''; + } } elsif ($url) { if ($anchor ne '') { if ($supplementalflag) { @@ -4460,7 +4577,14 @@ $form_end; $link = $url; } $link = &js_escape($link.(($url=~/\?/)?'&':'?').'inhibitmenu=yes'.$anchor); - if ($nomodal) { + if ($allowed && !$env{'request.role.adv'} && !$isfolder && !$ispage && !$uploaded) { + if ((&LONCAPA::map::getparameter($orderidx,'parameter_hiddenresource'))[0]=~/^yes$/i) { + $nolink = 1; + } + } + if ($nolink) { + $line.=''; + } elsif ($nomodal) { $line.=''. ''; } else { @@ -4472,9 +4596,26 @@ $form_end; } $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 .= ' '.''. + ''. + ''; + } + if ((($hiddenfolder) || ($hiddenres)) && (!$allowed) && ($supplementalflag)) { + $line.= ' ('.&mt('hidden').') '; + } } elsif ($url) { - if ($nomodal) { + if ($nolink) { + $line.=$title; + } elsif ($nomodal) { $line.=''. $title.''; } else { @@ -4493,32 +4634,42 @@ $form_end; $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.=(<