--- loncom/interface/lonmenu.pm 2017/11/01 09:01:39 1.369.2.71.4.5 +++ loncom/interface/lonmenu.pm 2020/05/03 20:51:58 1.369.2.81 @@ -1,7 +1,7 @@ # The LearningOnline Network with CAPA # Routines to control the menu # -# $Id: lonmenu.pm,v 1.369.2.71.4.5 2017/11/01 09:01:39 raeburn Exp $ +# $Id: lonmenu.pm,v 1.369.2.81 2020/05/03 20:51:58 raeburn Exp $ # # Copyright Michigan State University Board of Trustees # @@ -399,7 +399,8 @@ sub secondary_menu { my $canmgr = &Apache::lonnet::allowed('mgr', $crs_sec); my $author = &getauthor(); - my ($cdom,$cnum,$showsyllabus,$showfeeds,$showresv); + my ($cdom,$cnum,$showsyllabus,$showfeeds,$showresv,$grouptools); + $grouptools = 0; if ($env{'request.course.id'}) { $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'}; $cnum = $env{'course.'.$env{'request.course.id'}.'.num'}; @@ -422,6 +423,16 @@ sub secondary_menu { $showresv = 1; } } + if ($env{'request.course.groups'} ne '') { + foreach my $group (split(/:/,$env{'request.course.groups'})) { + next unless ($group =~ /^\w+$/); + my @privs = split(/:/,$env{"user.priv.$env{'request.role'}./$cdom/$cnum/$group"}); + shift(@privs); + if (@privs) { + $grouptools ++; + } + } + } } my ($canmodifycoauthor); @@ -433,11 +444,6 @@ sub secondary_menu { } } - my %groups = &Apache::lonnet::get_active_groups( - $env{'user.domain'}, $env{'user.name'}, - $env{'course.' . $env{'request.course.id'} . '.domain'}, - $env{'course.' . $env{'request.course.id'} . '.num'}); - my ($roleswitcher_js,$roleswitcher_form); foreach my $menuitem (@secondary_menu) { @@ -469,7 +475,7 @@ sub secondary_menu { next if $$menuitem[4] eq 'params' && (!$canmodpara && !$canviewpara); next if $$menuitem[4] eq 'nvcg' - && ($canviewgrps || !%groups); + && ($canviewgrps || !$grouptools); next if $$menuitem[4] eq 'showsyllabus' && !$showsyllabus; next if $$menuitem[4] eq 'showfeeds' @@ -499,6 +505,9 @@ sub secondary_menu { next if ($item->[2] eq 'mgr' && !$canmgr); next if ($item->[2] eq 'vcg' && !$canviewgrps); next if ($item->[2] eq 'crsedit' && !$canedit && !$canvieweditor); + next if ($item->[2] eq 'params' && !$canmodpara && !$canviewpara); + next if ($item->[2] eq 'author' && !$author); + next if ($item->[2] eq 'cca' && !$canmodifycoauthor); push(@scndsub,$item); } } @@ -522,12 +531,25 @@ sub secondary_menu { my $url = $$menuitem[0]; $url =~ s{\[cdom\]/\[cnum\]}{$cdom/$cnum}; if (&Apache::lonnet::is_on_map($url)) { - unless ($$menuitem[0] =~ /\?register=1/) { - $$menuitem[0] .= '?register=1'; + unless ($$menuitem[0] =~ /(\?|\&)register=1/) { + $$menuitem[0] .= (($$menuitem[0]=~/\?/)? '&' : '?').'register=1'; } } else { - $$menuitem[0] =~ s{\?register=1}{}; + $$menuitem[0] =~ s{\&?register=1}{}; } + if ($env{'course.'.$env{'request.course.id'}.'.externalsyllabus'} =~ m{^http://}) { + if (($ENV{'SERVER_PORT'} == 443) || ($env{'request.use_absolute'} =~ m{^https://})) { + unless (&Apache::lonnet::uses_sts()) { + unless ($$menuitem[0] =~ m{^https?://}) { + $$menuitem[0] = 'http://'.$ENV{'SERVER_NAME'}.$$menuitem[0]; + } + unless ($$menuitem[0] =~ /(\&|\?)usehttp=1/) { + $$menuitem[0] .= (($$menuitem[0]=~/\?/) ? '&' : '?').'usehttp=1'; + } + } + } + } + $$menuitem[0] = &HTML::Entities::encode($$menuitem[0],'&<>"'); } $menu .= &prep_menuitem(\@$menuitem); } @@ -635,6 +657,20 @@ sub build_submenu { next unless (($env{'user.name'} ne '') && ($env{'user.domain'} ne '')); $href =~ s/\[domain\]/$env{'user.domain'}/g; $href =~ s/\[user\]/$env{'user.name'}/g; + } elsif (($href =~ m{^/adm/preferences\?}) && ($href =~ /\[returnurl\]/)) { + my $returnurl = $ENV{'REQUEST_URI'}; + if ($ENV{'REQUEST_URI'} =~ m{/adm/preferences\?action=(?:changedomcoord|authorsettings)\&returnurl=([^\&]+)$}) { + $returnurl = $1; + } + if (($returnurl =~ m{^/adm/createuser($|\?action=)}) || + ($returnurl =~ m{^/priv/$match_domain/$match_username}) || + ($returnurl =~ m{^/res(/?$|/$match_domain/$match_username)})) { + $returnurl =~ s{\?.*$}{}; + $returnurl = '&returnurl='.&HTML::Entities::encode($returnurl,'"<>&\''); + } else { + undef($returnurl); + } + $href =~ s/\[returnurl\]/$returnurl/; } unless (($href eq '') || ($href =~ /^\#/)) { $target = ' target="_top"'; @@ -678,7 +714,7 @@ sub registerurl { } sub innerregister { - my ($forcereg,$bread_crumbs,$group,$pagebuttonshide) = @_; + my ($forcereg,$bread_crumbs,$group,$pagebuttonshide,$hostname) = @_; my $const_space = ($env{'request.state'} eq 'construct'); my $is_const_dir = 0; @@ -699,12 +735,13 @@ sub innerregister { $newmail= 'swmenu.setstatus("you have","messages");'; } - my ($mapurl,$resurl,$navmap); + my ($mapurl,$resurl,$crstype,$navmap); if ($env{'request.course.id'}) { # #course_type: Course or Community # + $crstype = &Apache::loncommon::course_type(); if ($env{'request.symb'}) { my $ignorenull; unless ($env{'request.noversionuri'} eq '/adm/navmaps') { @@ -718,7 +755,8 @@ sub innerregister { my $restitle = &Apache::lonnet::gettitle($symb); my (@crumbs,@mapcrumbs); - if (($env{'request.noversionuri'} ne '/adm/navmaps') && ($mapurl ne '')) { + if (($env{'request.noversionuri'} ne '/adm/navmaps') && ($mapurl ne '') && + ($mapurl ne $env{'course.'.$env{'request.course.id'}.'.url'})) { $navmap = Apache::lonnavmaps::navmap->new(); if (ref($navmap)) { @mapcrumbs = $navmap->recursed_crumbs($mapurl,$restitle); @@ -727,8 +765,7 @@ sub innerregister { unless (($forcereg) && ($env{'request.noversionuri'} eq '/adm/navmaps') && ($mapurl eq $env{'course.'.$env{'request.course.id'}.'.url'})) { - @crumbs = ({text => Apache::loncommon::course_type() - . ' Contents', + @crumbs = ({text => $crstype.' Contents', href => "Javascript:gopost('/adm/navmaps','')"}); } if ($mapurl ne $env{'course.'.$env{'request.course.id'}.'.url'}) { @@ -740,9 +777,10 @@ sub innerregister { } } - unless ((@mapcrumbs) || (!$maptitle) || ($maptitle eq 'default.sequence') || + unless ((@mapcrumbs) || (!$maptitle) || ($maptitle eq 'default.sequence') || ($mapurl eq $env{'course.'.$env{'request.course.id'}.'.url'})) { - push @crumbs, {text => $maptitle, no_mt => 1, href => $mapurl}; + push @crumbs, {text => $maptitle, no_mt => 1, + href => &Apache::lonnet::clutter($mapurl).'?navmap=1'}; } if ($restitle && !@mapcrumbs) { push(@crumbs,{text => $restitle, no_mt => 1}); @@ -762,7 +800,6 @@ sub innerregister { } else { $resurl = $env{'request.noversionuri'}; my $courseurl = &Apache::lonnet::courseid_to_courseurl($env{'request.course.id'}); - my $crstype = &Apache::loncommon::course_type(); my $title = &mt('View Resource'); if ($resurl =~ m{^\Q/uploaded$courseurl/supplemental/\E(default|\d+)/}) { &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},['folderpath','title']); @@ -772,7 +809,7 @@ sub innerregister { } my $trail; if ($env{'form.folderpath'}) { - &prepare_functions($resurl,$forcereg,$group,undef,undef,1); + &prepare_functions($resurl,$forcereg,$group,undef,undef,1,$hostname); ($trail) = &Apache::lonhtmlcommon::docs_breadcrumbs(undef,$crstype,undef,$title,1); } else { @@ -787,10 +824,10 @@ sub innerregister { } elsif ($resurl =~ m{^\Q/uploaded$courseurl/portfolio/syllabus/}) { &Apache::lonhtmlcommon::clear_breadcrumbs(); &prepare_functions('/public'.$courseurl."/syllabus", - $forcereg,$group,undef,undef,1); + $forcereg,$group,undef,undef,1,$hostname); $title = &mt('Syllabus File'); my ($trail) = - &Apache::lonhtmlcommon::docs_breadcrumbs(undef,$crstype,undef,$title,1); + &Apache::lonhtmlcommon::docs_breadcrumbs(undef,$crstype,undef,$title,1,$hostname); return $trail; } unless ($env{'request.state'} eq 'construct') { @@ -827,7 +864,7 @@ sub innerregister { if (($env{'environment.remote'} eq 'on') && ($env{'request.symb'})) { &Apache::lonhtmlcommon::clear_breadcrumbs(); } - $editbutton = &prepare_functions($resurl,$forcereg,$group); + $editbutton = &prepare_functions($resurl,$forcereg,$group,'','','',$hostname); } if ($editbutton eq '') { $editbutton = &clear(6,1); @@ -981,13 +1018,14 @@ if ($env{'browser.mobile'}) { $is_mobile = 1; } - unless ($env{'request.noversionuri'}=~/\/(bulletinboard|smppg|navmaps|syllabus|aboutme|viewclasslist|portfolio|ext\.tool)(\?|$)/) { - if ((!$env{'request.enc'}) && ($env{'request.noversionuri'} !~ m{^/adm/wrapper/ext/}) && ($env{'request.noversionuri'} !~ m{^/uploaded/$match_domain/$match_courseid/docs/})) { + unless ($env{'request.noversionuri'}=~/\/(bulletinboard|smppg|navmaps|syllabus|aboutme|viewclasslist|portfolio)(\?|$)/) { + if ((!$env{'request.enc'}) && ($env{'request.noversionuri'} !~ m{^/adm/wrapper/ext/}) && + ($env{'request.noversionuri'} !~ m{^/uploaded/$match_domain/$match_courseid/(docs/|default_\d+\.page$)})) { $menuitems.=(<&"')); + my $link = '/adm/coursedocs?command=direct&forcesupplement=1&supppath='. + "$esc_path&anchor=$suppanchor"; + if ($env{'request.use_absolute'} ne '') { + $link = $env{'request.use_absolute'}.$link; + } &switch('','',7,4,'docs-22x22.png','Edit Folder','parms[_2]', - "location.href='/adm/coursedocs?command=direct&forcesupplement=1&supppath=$esc_path&anchor=$suppanchor'", - 'Folder/Page Content','','',1); + "location.href='$link'",'Folder/Page Content'); } } } @@ -2148,228 +2193,21 @@ function toggleCountdown() { END } -# This creates a "done button" for timed events. The confirmation box is a jQuery -# dialog widget. If the interval parameter requires a proctor key for the timed -# event to be marked done, there will also be a textbox where that can be entered. -# Clicking OK will set the value of LC_interval_done to 'true', and, if needed will -# set the value of LC_interval_done_proctorpass to the text entered in that box, -# and submit the corresponding form. -# -# The &zero_time() routine in lonhomework.pm is called when a page is rendered if -# LC_interval_done is true. -# -sub done_button_js { - my ($type,$width,$height,$proctor,$donebuttontext) = @_; - return unless (($type eq 'map') || ($type eq 'resource')); - my %lt = &Apache::lonlocal::texthash( - title => 'WARNING!', - preamble => 'You are trying to end this timed event early.', - map => 'Confirming that you are done will cause the time to expire and prevent you from changing any answers in the current folder.', - resource => 'Confirming that you are done will cause the time to expire for this question, and prevent you from changing your answer(s).', - okdone => 'Click "OK" if you are completely finished.', - cancel => 'Click "Cancel" to continue working.', - proctor => 'Ask a proctor to enter the key, then click "OK" if you are completely finished.', - ok => 'OK', - exit => 'Cancel', - key => 'Key:', - nokey => 'A proctor key is required', - ); - my $navmap = Apache::lonnavmaps::navmap->new(); - my ($missing,$tried) = (0,0); - if (ref($navmap)) { - my @resources=(); - if ($type eq 'map') { - my ($mapurl,$rid,$resurl)=&Apache::lonnet::decode_symb($env{'request.symb'}); - if ($env{'request.symb'} =~ /\.page$/) { - @resources=$navmap->retrieveResources($resurl,sub { $_[0]->is_problem() }); - } else { - @resources=$navmap->retrieveResources($mapurl,sub { $_[0]->is_problem() }); - } - } else { - my $res = $navmap->getBySymb($env{'request.symb'}); - if (ref($res)) { - if ($res->is_problem()) { - push(@resources,$res); - } - } - } - foreach my $res (@resources) { - if (ref($res->parts()) eq 'ARRAY') { - foreach my $part (@{$res->parts()}) { - if (!$res->tries($part)) { - $missing++; - } else { - $tried++; - } - } - } - } - } - if ($missing) { - $lt{'miss'} .= '

'; - if ($type eq 'map') { - $lt{'miss'} .= &mt('Submissions are missing for [quant,_1,question part,question parts] in this folder.',$missing); - } else { - $lt{'miss'} .= &mt('Submissions are missing for [quant,_1,part] in this question.',$missing); - } - if ($missing > 1) { - $lt{'miss'} .= ' '.&mt('If you confirm you are done you will be unable to submit answers for them.').''; - } else { - $lt{'miss'} .= ' '.&mt('If you confirm you are done you will be unable to submit an answer for it.').'

'; - } - } - $donebuttontext = &HTML::Entities::encode($donebuttontext,'<>&"'); - if ($proctor) { - if ($height !~ /^\d+$/) { - $height = 400; - if ($missing) { - $height += 60; - } - } - if ($width !~ /^\d+$/) { - $width = 400; - if ($missing) { - $width += 60; - } - } - return < - - - - - -
-

$lt{'preamble'} $lt{$type}

- $lt{'miss'} -

$lt{'proctor'}

-
- - -
-

$lt{'cancel'}

-
- - - -END - } else { - if ($height !~ /^\d+$/) { - $height = 320; - if ($missing) { - $height += 60; - } - } - if ($width !~ /^\d+$/) { - $width = 320; - if ($missing) { - $width += 60; - } - } - if ($missing) { - $lt{'miss'} = '

'.$lt{'miss'}.'

'; - } - return < - - - - -

-

$lt{'preamble'} $lt{$type} $lt{'miss'} $lt{'okdone'} $lt{'cancel'}

-
- - - -END - } -} - sub utilityfunctions { my ($httphost) = @_; my $currenturl=&Apache::lonnet::clutter(&Apache::lonnet::fixversion((split(/\?/,$env{'request.noversionuri'}))[0])); - if ($currenturl =~ m{^/adm/wrapper/ext/} - && $env{'request.external.querystring'} ) { + my $currentsymb=&Apache::lonenc::check_encrypt($env{'request.symb'}); + if ($currenturl =~ m{^/adm/wrapper/ext/}) { + if ($env{'request.external.querystring'}) { $currenturl .= ($currenturl=~/\?/)?'&':'?'.$env{'request.external.querystring'}; + } + my ($anchor) = ($env{'request.symb'} =~ /(\#[^\#]+)$/); + if (($anchor) && ($currenturl !~ /\Q$anchor\E$/)) { + $currenturl .= $1; + } } $currenturl=&Apache::lonenc::check_encrypt(&unescape($currenturl)); - my $currentsymb=&Apache::lonenc::check_encrypt($env{'request.symb'}); - my $dc_popup_cid; if ($env{'user.adv'} && exists($env{'user.role.dc./'. $env{'course.'.$env{'request.course.id'}. @@ -2395,6 +2233,10 @@ sub utilityfunctions { my $countdown = &countdown_toggle_js(); + my $annotateurl = '/adm/annotation'; + if ($httphost) { + $annotateurl = '/adm/annotations'; + } my $hostvar = ' function setLCHost() { var lcHostname=""; @@ -2523,7 +2365,7 @@ function annotate() { annotator.document.write( '$start_page_annotate' +"
" + +"action='$annotateurl'>" +"" +"<\\/form>" +'$end_page_annotate'); @@ -2545,8 +2387,7 @@ function open_StoredLinks_Import(rat) { } function open_source() { - var url = escape(window.location.pathname); - sourcewin=window.open('/adm/source?inhibitmenu=yes&viewonly=1&filename='+url,'LONsource', + sourcewin=window.open('/adm/source?inhibitmenu=yes&viewonly=1&filename='+currentURL,'LONsource', 'height=500,width=600,resizable=yes,location=no,menubar=no,toolbar=no,scrollbars=yes'); } @@ -2633,11 +2474,11 @@ sub roles_selector { } my ($privref,$gotsymb,$destsymb); my $destinationurl = $ENV{'REQUEST_URI'}; - if ($destinationurl =~ /\?symb=/) { + if ($destinationurl =~ /(\?|\&)symb=/) { $gotsymb = 1; } elsif ($destinationurl =~ m{^/enc/}) { my $plainurl = &Apache::lonenc::unencrypted($destinationurl); - if ($plainurl =~ /\?symb=/) { + if ($plainurl =~ /(\?|\&)symb=/) { $gotsymb = 1; } } @@ -3143,20 +2984,10 @@ sub countdown_timer { } my $duedate = &Apache::lonnet::EXT("resource.0.duedate"); my @interval=&Apache::lonnet::EXT("resource.0.interval"); - my ($timelimit,$usesdone,$donebuttontext,$proctor,$secret); if (@interval > 1) { - ($timelimit,my $donesuffix) = split(/_/,$interval[0],2); - if ($donesuffix =~ /^done\:([^\:]+)\:(.*)$/) { - $usesdone = 'done'; - $donebuttontext = $1; - (undef,$proctor,$secret) = split(/_/,$2); - } elsif ($donesuffix =~ /^done(|_.+)$/) { - $donebuttontext = &mt('Done'); - ($usesdone,$proctor,$secret) = split(/_/,$donesuffix); - } my $first_access=&Apache::lonnet::get_first_access($interval[1]); if ($first_access > 0) { - if ($first_access+$timelimit > time) { + if ($first_access+$interval[0] > time) { $hastimeleft = 1; } } @@ -3164,16 +2995,11 @@ sub countdown_timer { if (($duedate && $duedate > time) || (!$duedate && $hastimeleft) || ($slot_name ne '' && $slothastime)) { - my ($collapse,$expand,$alttxt,$title,$currdisp,$donebutton); + my ($collapse,$expand,$alttxt,$title,$currdisp); if ((@interval > 1 && $hastimeleft) || ($type eq 'Task' && $slothastime)) { $currdisp = 'inline'; $collapse = '► '; - if ((@interval > 1) && ($hastimeleft)) { - if ($usesdone eq 'done') { - $donebutton = &done_button_js($interval[1],'','',$proctor,$donebuttontext); - } - } } else { $currdisp = 'none'; $expand = '◄ '; @@ -3184,7 +3010,7 @@ sub countdown_timer { } my $desc = &mt('Countdown to due date/time'); return < $collapse