--- loncom/interface/lonmenu.pm 2019/08/06 16:49:01 1.369.2.76 +++ loncom/interface/lonmenu.pm 2022/03/25 21:25:37 1.369.2.83.4.1 @@ -1,7 +1,7 @@ # The LearningOnline Network with CAPA # Routines to control the menu # -# $Id: lonmenu.pm,v 1.369.2.76 2019/08/06 16:49:01 raeburn Exp $ +# $Id: lonmenu.pm,v 1.369.2.83.4.1 2022/03/25 21:25:37 raeburn Exp $ # # Copyright Michigan State University Board of Trustees # @@ -240,7 +240,7 @@ use vars qw(@desklines %category_names % my @inlineremote; sub prep_menuitem { - my ($menuitem) = @_; + my ($menuitem,$listclass,$linkattr) = @_; return '' unless(ref($menuitem) eq 'ARRAY'); my $link; if ($$menuitem[1]) { # graphical Link @@ -250,10 +250,10 @@ sub prep_menuitem { } else { # textual Link $link = &mt($$menuitem[3]); } - return '
  • ':'
  • ').'$link
  • |; + . qq| href="$$menuitem[0]" target="_top" $linkattr>$link|; } # primary_menu() evaluates @primary_menu and returns a two item array, @@ -263,6 +263,7 @@ sub prep_menuitem { # @primary_menu is filled within the BEGIN block of this module with # entries from mydesk.tab sub primary_menu { + my ($links_disabled) = @_; my %menu; # each element of @primary contains following array: # (link url, icon path, alt text, link text, condition, position) @@ -294,6 +295,11 @@ sub primary_menu { if ($position eq '') { $position = 'right'; } + my ($listclass,$linkattr); + if ($links_disabled) { + $listclass = 'LCisDisabled'; + $linkattr = 'aria-disabled="true"'; + } if (defined($primary_submenu{$title})) { my ($link,$target); if ($menuitem->[0] ne '') { @@ -318,9 +324,10 @@ sub primary_menu { } else { $title = &mt($title); } - $menu{$position} .= &create_submenu($link,$target,$title,\@primsub,1); + $menu{$position} .= &create_submenu($link,$target,$title,\@primsub,1,undef,$listclass,$linkattr); } elsif ($link) { - $menu{$position} .= '
  • '.&mt($title).'
  • '; + $menu{$position} .= ($listclass?'
  • ':'
  • '). + ''.&mt($title).'
  • '; } } } elsif ($$menuitem[3] eq 'Help') { # special treatment for helplink @@ -331,13 +338,22 @@ sub primary_menu { 'helpdeskmail', $defdom,$origmail); if ($to ne '') { - $menu{$position} .= &prep_menuitem($menuitem); + $menu{$position} .= &prep_menuitem($menuitem,$listclass,$linkattr); } } else { - $menu{$position} .= '
  • '.&Apache::loncommon::top_nav_help('Help').'
  • '; + $menu{$position} .= ($listclass?'
  • ':'
  • '). + &Apache::loncommon::top_nav_help('Help',$linkattr). + '
  • '; + } + } elsif ($$menuitem[3] eq 'Log In') { + if ($public) { + if (&Apache::lonnet::get_saml_landing()) { + $$menuitem[0] = '/adm/login'; + } } + $menu{$position} .= prep_menuitem($menuitem,$listclass,$linkattr); } else { - $menu{$position} .= prep_menuitem($menuitem); + $menu{$position} .= prep_menuitem($menuitem,$listclass,$linkattr); } } my @output = ('',''); @@ -376,7 +392,7 @@ sub getauthor{ } sub secondary_menu { - my ($httphost) = @_; + my ($httphost,$links_disabled) = @_; my $menu; my $crstype = &Apache::loncommon::course_type(); @@ -424,7 +440,7 @@ sub secondary_menu { } } if ($env{'request.course.groups'} ne '') { - foreach my $group (split(/:/,$env{'request.course.groups'}) { + 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); @@ -435,6 +451,12 @@ sub secondary_menu { } } + my ($listclass,$linkattr); + if ($links_disabled) { + $listclass = 'LCisDisabled'; + $linkattr = 'aria-disabled="true"'; + } + my ($canmodifycoauthor); if ($env{'request.role'} eq "au./$env{'user.domain'}/") { my $extent = "$env{'user.domain'}/$env{'user.name'}"; @@ -512,9 +534,12 @@ sub secondary_menu { } } if (@scndsub > 0) { - $menu .= &create_submenu($link,$target,$title,\@scndsub,1); + $menu .= &create_submenu($link,$target,&mt($title),\@scndsub,1,undef, + $listclass,$linkattr); } elsif ($link ne '#') { - $menu .= '
  • '.&mt($title).'
  • '; + $menu .= ($listclass?'
  • ':'
  • '). + ''. + &mt($title).'
  • '; } } } elsif ($$menuitem[3] eq 'Roles' && $env{'request.course.id'}) { @@ -539,7 +564,7 @@ sub secondary_menu { } 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 ((&Apache::lonnet::uses_sts()) || (&Apache::lonnet::waf_allssl())) { unless ($$menuitem[0] =~ m{^https?://}) { $$menuitem[0] = 'http://'.$ENV{'SERVER_NAME'}.$$menuitem[0]; } @@ -551,7 +576,7 @@ sub secondary_menu { } $$menuitem[0] = &HTML::Entities::encode($$menuitem[0],'&<>"'); } - $menu .= &prep_menuitem(\@$menuitem); + $menu .= &prep_menuitem(\@$menuitem,$listclass,$linkattr); } } if ($menu =~ /\[url\].*\[symb\]/) { @@ -588,7 +613,7 @@ sub secondary_menu { } sub create_submenu { - my ($link,$target,$title,$submenu,$translate,$addclass) = @_; + my ($link,$target,$title,$submenu,$translate,$addclass,$listclass,$linkattr) = @_; return unless (ref($submenu) eq 'ARRAY'); my $disptarget; if ($target ne '') { @@ -603,7 +628,7 @@ sub create_submenu { # $link and $title are only used in the initial string written in $menu # as seen above, not needed for nested submenus - $menu .= &build_submenu($target, $submenu, $translate, '1'); + $menu .= &build_submenu($target, $submenu, $translate, '1', $listclass, $linkattr); $menu .= ''; return $menu; @@ -613,7 +638,7 @@ sub create_submenu { # build the dropdown (and nested submenus) recursively # see perldoc create_submenu documentation for further information sub build_submenu { - my ($target, $submenu, $translate, $first_level) = @_; + my ($target, $submenu, $translate, $first_level, $listclass, $linkattr) = @_; unless (@{$submenu}) { return ''; } @@ -676,8 +701,10 @@ sub build_submenu { $target = ' target="_top"'; } - $menu .= '
  • '; - $menu .= '' . $title . ''; + $menu .= '
  • '; + $menu .= '' . $title . ''; $menu .= '
  • '; } } @@ -735,7 +762,7 @@ sub innerregister { $newmail= 'swmenu.setstatus("you have","messages");'; } - my ($mapurl,$resurl,$crstype); + my ($mapurl,$resurl,$crstype,$navmap); if ($env{'request.course.id'}) { # @@ -743,13 +770,25 @@ sub innerregister { # $crstype = &Apache::loncommon::course_type(); if ($env{'request.symb'}) { - ($mapurl, my $rid, $resurl) = &Apache::lonnet::decode_symb(&Apache::lonnet::symbread()); + my $ignorenull; + unless ($env{'request.noversionuri'} eq '/adm/navmaps') { + $ignorenull = 1; + } + my $symb = &Apache::lonnet::symbread('','',$ignorenull); + ($mapurl, my $rid, $resurl) = &Apache::lonnet::decode_symb($symb); my $coursetitle = $env{'course.'.$env{'request.course.id'}.'.description'}; my $maptitle = &Apache::lonnet::gettitle($mapurl); - my $restitle = &Apache::lonnet::gettitle(&Apache::lonnet::symbread()); + my $restitle = &Apache::lonnet::gettitle($symb); - my @crumbs; + my (@crumbs,@mapcrumbs); + 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); + } + } unless (($forcereg) && ($env{'request.noversionuri'} eq '/adm/navmaps') && ($mapurl eq $env{'course.'.$env{'request.course.id'}.'.url'})) { @@ -757,15 +796,22 @@ sub innerregister { href => "Javascript:gopost('/adm/navmaps','')"}); } if ($mapurl ne $env{'course.'.$env{'request.course.id'}.'.url'}) { - push(@crumbs, {text => '...', - no_mt => 1}); + if (@mapcrumbs) { + push(@crumbs,@mapcrumbs); + } else { + push(@crumbs, {text => '...', + no_mt => 1}); + } } - push @crumbs, {text => $maptitle, no_mt => 1} if ($maptitle - && $maptitle ne 'default.sequence' - && $maptitle ne $coursetitle); - - push @crumbs, {text => $restitle, no_mt => 1} if $restitle; + unless ((@mapcrumbs) || (!$maptitle) || ($maptitle eq 'default.sequence') || + ($mapurl eq $env{'course.'.$env{'request.course.id'}.'.url'})) { + push @crumbs, {text => $maptitle, no_mt => 1, + href => &Apache::lonnet::clutter($mapurl).'?navmap=1'}; + } + if ($restitle && !@mapcrumbs) { + push(@crumbs,{text => $restitle, no_mt => 1}); + } my @tools; if ($env{'request.filename'} =~ /\.page$/) { my %breadcrumb_tools = &Apache::lonhtmlcommon::current_breadcrumb_tools(); @@ -1000,12 +1046,13 @@ if ($env{'browser.mobile'}) { } 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/})) { + 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.=(< 0) { @@ -2161,6 +2225,220 @@ 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 $shownsymb = &HTML::Entities::encode(&Apache::lonenc::check_encrypt($env{'request.symb'})); + 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])); @@ -2354,6 +2632,11 @@ function open_StoredLinks_Import(rat) { newWin.focus(); } +function open_source() { + 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'); +} + (function (\$) { \$(document).ready(function () { \$.single=function(a){return function(b){a[0]=b;return a}}(\$([1])); @@ -2947,10 +3230,20 @@ 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+$interval[0] > time) { + if ($first_access+$timelimit > time) { $hastimeleft = 1; } } @@ -2958,11 +3251,16 @@ sub countdown_timer { if (($duedate && $duedate > time) || (!$duedate && $hastimeleft) || ($slot_name ne '' && $slothastime)) { - my ($collapse,$expand,$alttxt,$title,$currdisp); + my ($collapse,$expand,$alttxt,$title,$currdisp,$donebutton); 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 = '◄ '; @@ -2973,7 +3271,7 @@ sub countdown_timer { } my $desc = &mt('Countdown to due date/time'); return < $collapse