--- loncom/interface/lonmenu.pm 2021/12/13 23:26:32 1.369.2.83 +++ loncom/interface/lonmenu.pm 2022/01/03 16:37:24 1.369.2.83.2.1 @@ -1,7 +1,7 @@ # The LearningOnline Network with CAPA # Routines to control the menu # -# $Id: lonmenu.pm,v 1.369.2.83 2021/12/13 23:26:32 raeburn Exp $ +# $Id: lonmenu.pm,v 1.369.2.83.2.1 2022/01/03 16:37:24 raeburn Exp $ # # Copyright Michigan State University Board of Trustees # @@ -263,8 +263,8 @@ 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; + my ($crstype,$ltimenu,$menucoll,$menuref,$links_disabled) = @_; + my (%menu,%menuopts); # each element of @primary contains following array: # (link url, icon path, alt text, link text, condition, position) my $public; @@ -272,6 +272,9 @@ sub primary_menu { || (($env{'user.name'} eq '') && ($env{'user.domain'} eq ''))) { $public = 1; } + if (($menucoll) && (ref($menuref) eq 'HASH')) { + %menuopts = %{$menuref}; + } foreach my $menuitem (@primary_menu) { # evaluate conditions next if ref($menuitem) ne 'ARRAY'; # @@ -295,6 +298,23 @@ sub primary_menu { if ($position eq '') { $position = 'right'; } + if ($env{'request.course.id'} && $menucoll) { + if (($menuitem->[6]) && (!$menuopts{$menuitem->[6]})) { + if ($menuitem->[6] eq 'pers') { + if ($menuopts{'name'} && + $env{'user.name'} && $env{'user.domain'}) { + $menu{$position} .= '
  • '. + &Apache::loncommon::plainname($env{'user.name'}, + $env{'user.domain'}).'
  • '; + next; + } else { + next; + } + } else { + next; + } + } + } my ($listclass,$linkattr); if ($links_disabled) { $listclass = 'LCisDisabled'; @@ -316,18 +336,30 @@ sub primary_menu { ($item->[2] eq 'blog')) && (!&Apache::lonnet::usertools_access('','',$item->[2], undef,'tools'))); + if ($env{'request.course.id'} && $menucoll) { + next if ($item->[3]) && (!$menuopts{$item->[3]}); + } push(@primsub,$item); } - if (@primsub > 0) { - if ($title eq 'Personal' && $env{'user.name'} && $env{'user.domain'} ) { - $title = &Apache::loncommon::plainname($env{'user.name'},$env{'user.domain'}); - } else { + if ($title eq 'Personal') { + if ($env{'user.name'} && $env{'user.domain'}) { + unless (($env{'request.course.id'}) && ($menucoll) && (!$menuopts{'name'})) { + $title = &Apache::loncommon::plainname($env{'user.name'},$env{'user.domain'}); + } + } + next if (($env{'request.course.id'}) && ($menucoll) && ($title eq 'Personal') && + (!@primsub)); + if ($title eq 'Personal') { $title = &mt($title); } + } else { + $title = &mt($title); + } + if (@primsub > 0) { $menu{$position} .= &create_submenu($link,$target,$title,\@primsub,1,undef,$listclass,$linkattr); } elsif ($link) { $menu{$position} .= ($listclass?'
  • ':'
  • '). - ''.&mt($title).'
  • '; + ''.$title.''; } } } elsif ($$menuitem[3] eq 'Help') { # special treatment for helplink @@ -392,7 +424,7 @@ sub getauthor{ } sub secondary_menu { - my ($httphost,$links_disabled) = @_; + my ($httphost,$ltiscope,$ltimenu,$noprimary,$menucoll,$menuref,$links_disabled) = @_; my $menu; my $crstype = &Apache::loncommon::course_type(); @@ -413,9 +445,10 @@ sub secondary_menu { my $canmodpara = &Apache::lonnet::allowed('opa', $crs_sec); my $canvgr = &Apache::lonnet::allowed('vgr', $crs_sec); my $canmgr = &Apache::lonnet::allowed('mgr', $crs_sec); + my $canplc = &Apache::lonnet::allowed('plc', $crs_sec); my $author = &getauthor(); - my ($cdom,$cnum,$showsyllabus,$showfeeds,$showresv,$grouptools); + my ($cdom,$cnum,$showsyllabus,$showfeeds,$showresv,$grouptools,%menuopts); $grouptools = 0; if ($env{'request.course.id'}) { $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'}; @@ -450,6 +483,9 @@ sub secondary_menu { } } } + if (($menucoll) && (ref($menuref) eq 'HASH')) { + %menuopts = %{$menuref}; + } my ($listclass,$linkattr); if ($links_disabled) { @@ -502,12 +538,21 @@ sub secondary_menu { && !$showsyllabus; next if $$menuitem[4] eq 'showfeeds' && !$showfeeds; + next if $$menuitem[4] eq 'plc' + && !$canplc; next if $$menuitem[4] eq 'author' && !$author; next if $$menuitem[4] eq 'cca' && !$canmodifycoauthor; my $title = $menuitem->[3]; + if ($env{'request.course.id'} && $menucoll) { + if ($$menuitem[5] eq 'main') { + next if ($menuopts{$$menuitem[5]} eq 'n'); + } elsif ($$menuitem[5] ne 'roles') { + next if (($$menuitem[5]) && (!$menuopts{$$menuitem[5]})); + } + } if (defined($secondary_submenu{$title})) { my ($link,$target); if ($menuitem->[0] ne '') { @@ -544,12 +589,16 @@ sub secondary_menu { } } elsif ($$menuitem[3] eq 'Roles' && $env{'request.course.id'}) { # special treatment for role selector - ($roleswitcher_js,$roleswitcher_form,my $switcher) = + my ($switcher,$has_opa_priv); + ($roleswitcher_js,$roleswitcher_form,$switcher,$has_opa_priv) = &roles_selector( $env{'course.' . $env{'request.course.id'} . '.domain'}, $env{'course.' . $env{'request.course.id'} . '.num'}, $httphost ); + if (($$menuitem[5]) && (!$menuopts{$$menuitem[5]})) { + next unless ($has_opa_priv); + } $menu .= $switcher; } else { if ($$menuitem[3] eq 'Syllabus' && $env{'request.course.id'}) { @@ -599,6 +648,7 @@ sub secondary_menu { } $menu =~ s/\[uname\]/$$author{user}/g; $menu =~ s/\[udom\]/$$author{dom}/g; + $menu =~ s/\[javascript\]/javascript:/g; if ($env{'request.course.id'}) { $menu =~ s/\[cnum\]/$cnum/g; $menu =~ s/\[cdom\]/$cdom/g; @@ -1047,13 +1097,15 @@ 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/|default_\d+\.page$)})) { + ($env{'request.noversionuri'} !~ m{^/uploaded/$match_domain/$match_courseid/(docs/|default_\d+\.page$)}) && + ($env{'request.noversionuri'} !~ m{^/adm/.+/ext\.tool$})) { $menuitems.=(< '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])); @@ -2371,11 +2638,11 @@ function golist(url) { -function catalog_info(isMobile) { +function catalog_info(url,isMobile) { if (isMobile == 1) { - openMyModal(window.location.pathname+'.meta?modal=1',500,400,'yes'); + openMyModal(url+'.meta?modal=1',500,400,'yes'); } else { - loncatinfo=window.open(window.location.pathname+'.meta',"LONcatInfo",'height=500,width=400,resizable=yes,scrollbars=yes,location=no,menubar=no,toolbar=no'); + loncatinfo=window.open(url+'.meta',"LONcatInfo",'height=500,width=400,resizable=yes,scrollbars=yes,location=no,menubar=no,toolbar=no'); } } @@ -2497,7 +2764,7 @@ sub roles_selector { my $now = time; my (%courseroles,%seccount,%courseprivs,%roledesc); my $is_cc; - my ($js,$form,$switcher); + my ($js,$form,$switcher,$has_opa_priv); my $ccrole; if ($crstype eq 'Community') { $ccrole = 'co'; @@ -2618,12 +2885,19 @@ sub roles_selector { if ($env{'request.role'} =~ m{^\Q$role\E}) { if ($seccount{$role} > 1) { $include = 1; + } else { + if ($env{'user.priv.'.$env{'request.role'}."./$cdom/$cnum"} =~/opa\&([^\:]*)/) { + $has_opa_priv = 1; + } } } else { $include = 1; } } if ($include) { + if ($env{"user.priv.$role./$cdom/$cnum./$cdom/$cnum"} =~/opa\&([^\:]*)/) { + $has_opa_priv = 1; + } push(@submenu,['javascript:adhocRole('."'$role'".')', &Apache::lonnet::plaintext($role,$crstype)]); } @@ -2648,6 +2922,9 @@ sub roles_selector { } else { $rolename = &Apache::lonnet::plaintext($role); } + if ($env{"user.priv.$role./$cdom/$cnum./$cdom/$cnum"} =~/opa\&([^\:]*)/) { + $has_opa_priv = 1; + } push(@submenu,['javascript:adhocRole('."'$role'".')', $rolename]); } @@ -2657,7 +2934,7 @@ sub roles_selector { $switcher = &create_submenu('','',&mt('Switch role'),\@submenu); } } - return ($js,$form,$switcher); + return ($js,$form,$switcher,$has_opa_priv); } sub get_all_courseroles { @@ -3016,10 +3293,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; } } @@ -3027,11 +3314,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 = '◄ '; @@ -3042,7 +3334,7 @@ sub countdown_timer { } my $desc = &mt('Countdown to due date/time'); return < $collapse @@ -3073,13 +3365,13 @@ BEGIN { $category_positions{$entries[2]}=$entries[1]; $category_names{$entries[2]}=$entries[3]; } elsif ($configline=~/^prim\:/) { - my @entries = (split(/\:/, $configline))[1..6]; + my @entries = (split(/\:/, $configline))[1..7]; push(@primary_menu,\@entries); } elsif ($configline=~/^primsub\:/) { - my ($parent,@entries) = (split(/\:/, $configline))[1..4]; + my ($parent,@entries) = (split(/\:/, $configline))[1..5]; push(@{$primary_submenu{$parent}},\@entries); } elsif ($configline=~/^scnd\:/) { - my @entries = (split(/\:/, $configline))[1..5]; + my @entries = (split(/\:/, $configline))[1..6]; push(@secondary_menu,\@entries); } elsif ($configline=~/^scndsub\:/) { my ($parent,@entries) = (split(/\:/, $configline))[1..4];