--- loncom/interface/londocs.pm 2022/09/29 03:59:29 1.681 +++ loncom/interface/londocs.pm 2022/10/19 00:03:10 1.682 @@ -1,7 +1,7 @@ # The LearningOnline Network # Documents # -# $Id: londocs.pm,v 1.681 2022/09/29 03:59:29 raeburn Exp $ +# $Id: londocs.pm,v 1.682 2022/10/19 00:03:10 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); @@ -955,7 +955,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); } @@ -3278,11 +3277,28 @@ sub editor { return $errtext if ($fatal); } + my (%supphidden,%suppids,$suppmapid); + if ($#LONCAPA::map::order<1) { my $idx=&LONCAPA::map::getresidx(); if ($idx<=0) { $idx=1; } $LONCAPA::map::order[0]=$idx; $LONCAPA::map::resources[$idx]=''; + } elsif ($supplementalflag && !$allowed) { + 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'}}; + } + } + if ($folder eq 'supplemental') { + $suppmapid = 0; + } elsif ($folder =~ /^supplemental_(\d+)$/) { + $suppmapid = $1; + } } # ------------------------------------------------------------ Process commands @@ -3566,11 +3582,15 @@ sub editor { push(@allmapidx,$res); } + if (($supplementalflag) && (!$allowed) && (!$env{'request.role.adv'})) { + next if ($supphidden{$suppmapid.':'.$res}); + } $output .= &entryline($idx,$name,$url,$folder,$allowed,$res, $coursenum,$coursedom,$crstype, $pathitem,$supplementalflag,$container, \%filters,\%curr_groups,$ltitoolsref,$canedit, - $isencrypted,$navmapref,$hostname); + $isencrypted,$navmapref,$hostname, + \%supphidden,\%suppids,$suppmapid); $idx++; $shown++; } @@ -3579,10 +3599,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 = '' .'' - .''; - if ($folder !~ /^supplemental/) { - $to_show .= ''; - } - $to_show .= &Apache::loncommon::end_data_table_header_row(); + .'' + .'' + .&Apache::loncommon::end_data_table_header_row(); if ($folder !~ /^supplemental/) { $lists{'canhide'} = join(',',@allidx); $lists{'canrandomlyorder'} = join(',',@allmapidx); @@ -3950,7 +3972,8 @@ sub is_supplemental_title { sub entryline { my ($index,$title,$url,$folder,$allowed,$residx,$coursenum,$coursedom, $crstype,$pathitem,$supplementalflag,$container,$filtersref,$currgroups, - $ltitoolsref,$canedit,$isencrypted,$navmapref,$hostname)=@_; + $ltitoolsref,$canedit,$isencrypted,$navmapref,$hostname, + $supphidden,$suppids,$suppmapid)=@_; my ($foldertitle,$renametitle,$oldtitle); if (&is_supplemental_title($title)) { ($title,$foldertitle,$renametitle) = &Apache::loncommon::parse_supplemental_title($title); @@ -4337,6 +4360,11 @@ END if (!$allowed && $supplementalflag) { $folderpath.=$containerarg.'&'.$foldername; $url.='folderpath='.&escape($folderpath); + if (ref($supphidden) eq 'HASH') { + if ($supphidden->{$suppmapid.':'.$residx}) { + $hiddenfolder = 1; + } + } } else { my $rpicknum = (&LONCAPA::map::getparameter($orderidx, 'parameter_randompick'))[0]; @@ -4430,6 +4458,11 @@ $form_end; if ($anchor ne '') { $url .= '&anchor='.&HTML::Entities::encode($anchor,'"<>&'); } + if (ref($supphidden) eq 'HASH') { + if ($supphidden->{$suppmapid.':'.$residx}) { + $hiddenres = 1; + } + } } my ($tdalign,$tdwidth); if ($allowed) { @@ -4518,6 +4551,17 @@ $form_end; $line.=''; if (($url=~m{/adm/(coursedocs|supplemental)}) || (!$allowed && $url)) { $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 .= ' '.''. + ''.&mt('Edit Content').''. + ''; + } + if ((($hiddenfolder) || ($hiddenres)) && (!$allowed) && ($supplementalflag)) { + $line.= ' ('.&mt('hidden').') '; + } } elsif ($url) { if ($nomodal) { $line.=''. @@ -4538,32 +4582,37 @@ $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 ($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.=(<
$form_param $form_common $form_end +ENDPARMS + if ($folder =~/^supplemental/) { + $line.= "\n
ENDPARMS + } } $line.=&Apache::loncommon::end_data_table_row(); return $line; @@ -5429,17 +5479,20 @@ sub handler { $help{'Caching'} = &Apache::loncommon::help_open_topic('Caching'); my ($allowed,$canedit,$canview,$noendpage,$disabled); +# does this user have privileges to modify content. + if (&Apache::lonnet::allowed('mdc',$env{'request.course.id'})) { # URI is /adm/supplemental when viewing supplemental docs in non-edit mode. - unless ($r->uri eq '/adm/supplemental') { - # does this user have privileges to modify content. - if (&Apache::lonnet::allowed('mdc',$env{'request.course.id'})) { + unless ($r->uri eq '/adm/supplemental') { $allowed = 1; - $canedit = 1; - $canview = 1; - } elsif (&Apache::lonnet::allowed('cev',$env{'request.course.id'})) { + } + $canedit = 1; + $canview = 1; + } elsif (&Apache::lonnet::allowed('cev',$env{'request.course.id'})) { +# URI is /adm/supplemental when viewing supplemental docs in non-edit mode. + unless ($r->uri eq '/adm/supplemental') { $allowed = 1; - $canview = 1; } + $canview = 1; } unless ($canedit) { $disabled = ' disabled="disabled"'; @@ -5544,7 +5597,7 @@ sub handler { # Get the parameters that may be needed # &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'}, - ['folderpath', + ['folderpath','title', 'forcesupplement','forcestandard', 'tools','symb','command','supppath']); @@ -5817,8 +5870,14 @@ sub handler { &Apache::lonhtmlcommon::clear_breadcrumbs(); if ($showdoc) { - $r->print(&Apache::loncommon::start_page("$crstype documents",undef, - {'force_register' => $showdoc,})); + my $args; + if ($supplementalflag) { + my $brcrum = &Apache::lonhtmlcommon::docs_breadcrumbs(undef,$crstype,undef,$env{'form.title'},1); + $args = {'bread_crumbs' => $brcrum}; + } else { + $args = {'force_register' => $showdoc}; + } + $r->print(&Apache::loncommon::start_page("$crstype documents",undef,$args)); } elsif ($toolsflag) { my ($breadtext,$breadtitle); $breadtext = "$crstype Editor"; @@ -5836,6 +5895,12 @@ sub handler { $breadtitle) ); } elsif ($r->uri eq '/adm/supplemental') { + unless ($env{'request.role.adv'}) { + unless (&Apache::lonnet::has_unhidden_suppfiles($coursenum,$coursedom)) { + $r->internal_redirect('/adm/navmaps'); + return OK; + } + } my $brcrum = &Apache::lonhtmlcommon::docs_breadcrumbs(undef,$crstype); $r->print(&Apache::loncommon::start_page("Supplemental $crstype Content",undef, {'bread_crumbs' => $brcrum,})); @@ -6830,29 +6895,41 @@ my %suporderhash = ( 'ff' => ['Other',&create_form_ul(&create_list_elements(@specialdocs))] ); if ($supplementalflag) { - my $error = &editor($r,$coursenum,$coursedom,$folder,$allowed,'',$crstype, - $supplementalflag,\%suporderhash,$iconpath,$pathitem, - \%ltitools,$canedit,$hostname); - if ($error) { - $r->print('

'.$error.'

'); - } else { - if ($suppchanges) { - my %servers = &Apache::lonnet::internet_dom_servers($coursedom); - my @ids=&Apache::lonnet::current_machine_ids(); - foreach my $server (keys(%servers)) { - next if (grep(/^\Q$server\E$/,@ids)); - my $hashid=$coursenum.':'.$coursedom; - my $cachekey = &escape('suppcount').':'.&escape($hashid); - &Apache::lonnet::remote_devalidate_cache($server,[$cachekey]); - } - &Apache::lonnet::get_numsuppfiles($coursenum,$coursedom,1); - undef($suppchanges); - } - } + $suppchanges = 0; + my $error = &editor($r,$coursenum,$coursedom,$folder,$allowed,'',$crstype, + $supplementalflag,\%suporderhash,$iconpath,$pathitem, + \%ltitools,$canedit,$hostname); + if ($error) { + $r->print('

'.$error.'

'); + } + if ($suppchanges) { + my %servers = &Apache::lonnet::internet_dom_servers($coursedom); + my @ids=&Apache::lonnet::current_machine_ids(); + foreach my $server (keys(%servers)) { + next if (grep(/^\Q$server\E$/,@ids)); + my $hashid=$coursenum.':'.$coursedom; + my $cachekey = &escape('showsupp').':'.&escape($hashid); + &Apache::lonnet::remote_devalidate_cache($server,[$cachekey]); + } + &Apache::lonnet::has_unhidden_suppfiles($coursenum,$coursedom,1); + &Apache::lonnet::count_supptools($coursenum,$coursedom,1); + my $now = time; + if ($env{'request.course.id'} eq $coursedom.'_'.$coursenum) { + &Apache::lonnet::appenv({'request.course.suppupdated' => $now}); + } + &Apache::lonnet::put('environment',{'internal.supplementalchange' => $now}, + $coursedom,$coursenum); + &Apache::lonnet::appenv( + {'course.'.$coursedom.'_'.$coursenum.'.internal.supplementalchange' => $now}); + &Apache::lonnet::do_cache_new('suppchange',$coursedom.'_'.$coursenum,$now,600); + &Apache::lonnet::get_numsuppfiles($coursenum,$coursedom,1); + undef($suppchanges); + } } } elsif ($supplementalflag) { my $error = &editor($r,$coursenum,$coursedom,$folder,$allowed,'',$crstype, - $supplementalflag,'',$iconpath,$pathitem,'','',$hostname); + $supplementalflag,'',$iconpath,$pathitem,'',$canedit, + $hostname); if ($error) { $r->print('

'.$error.'

'); } @@ -7358,7 +7435,12 @@ sub editing_js { } elsif ($env{'docs.exit.'.$env{'request.course.id'}} eq '/adm/menu') { $backtourl = '/adm/menu'; } elsif ($supplementalflag) { - $backtourl = '/adm/supplemental'; + if (($env{'request.role.adv'}) || + (&Apache::lonnet::has_unhidden_suppfiles($coursenum,$coursedom))) { + $backtourl = '/adm/supplemental'; + } else { + $backtourl = '/adm/navmaps'; + } } else { $backtourl = '/adm/navmaps'; }
' .&Apache::loncommon::help_open_menu('Navigation Screen', - 'Navigation_Screen',undef,'RAT') + $helpitem,undef,'RAT') .''.&mt('Tools:').''.&mt('Actions').''.&mt('Document').''.&mt('Settings').''.&mt('Document').''.&mt('Settings').'"; + } else { + if ((&LONCAPA::map::getparameter($orderidx,'parameter_encrypturl'))[0]=~/^yes$/i) { + $enctext = ' checked="checked"'; + if (($ishash) && (ref($filtersref->{'encrypturl'}) eq 'ARRAY')) { + push(@{$filtersref->{'encrypturl'}},$orderidx); + } + } + $formurlhidden = 'edit_encrypturl_'.$orderidx; + $line.=(< $form_param @@ -4574,6 +4623,7 @@ $form_end; $rand_pick_text
$rand_order_text