--- loncom/interface/lonmenu.pm 2021/12/13 23:26:32 1.369.2.83 +++ loncom/interface/lonmenu.pm 2023/12/29 19:53:25 1.369.2.83.2.13 @@ -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.13 2023/12/29 19:53:25 raeburn Exp $ # # Copyright Michigan State University Board of Trustees # @@ -99,7 +99,7 @@ It gets filled in the BEGIN block of thi =over -=item prep_menuitems(\@menuitem) +=item prep_menuitems(\@menuitem,$target,$listclass,$linkattr) This routine wraps a menuitem in proper HTML. It is used by primary_menu() and secondary_menu(). @@ -240,9 +240,9 @@ use vars qw(@desklines %category_names % my @inlineremote; sub prep_menuitem { - my ($menuitem,$listclass,$linkattr) = @_; + my ($menuitem,$target,$listclass,$linkattr) = @_; return '' unless(ref($menuitem) eq 'ARRAY'); - my $link; + my ($link,$targetattr); if ($$menuitem[1]) { # graphical Link $link = "':'
  • ').'$link
  • |; + . qq| href="$$menuitem[0]"$targetattr $linkattr>$link|; } # primary_menu() evaluates @primary_menu and returns a two item array, @@ -263,8 +266,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,$links_target) = @_; + my (%menu,%ltiexc,%menuopts); # each element of @primary contains following array: # (link url, icon path, alt text, link text, condition, position) my $public; @@ -272,6 +275,41 @@ sub primary_menu { || (($env{'user.name'} eq '') && ($env{'user.domain'} eq ''))) { $public = 1; } + my $lti; + if ($env{'request.lti.login'}) { + $lti = 1; + if (ref($ltimenu) eq 'HASH') { + foreach my $item ('fullname','logout') { + unless ($ltimenu->{$item}) { + $ltiexc{$item} = 1; + } + } + } + } + my ($listclass,$linkattr,$target); + if ($links_disabled) { + $listclass = 'LCisDisabled'; + $linkattr = 'aria-disabled="true"'; + } + if ($links_target ne '') { + $target = $links_target; + } else { + my ($ltitarget,$deeplinktarget); + if ($env{'request.lti.login'}) { + $ltitarget = $env{'request.lti.target'}; + } + if ($env{'request.deeplink.login'}) { + $deeplinktarget = $env{'request.deeplink.target'}; + } + if (($ltitarget eq 'iframe') || ($deeplinktarget eq '_self')) { + $target = '_self'; + } else { + $target = '_top'; + } + } + if (($menucoll) && (ref($menuref) eq 'HASH')) { + %menuopts = %{$menuref}; + } foreach my $menuitem (@primary_menu) { # evaluate conditions next if ref($menuitem) ne 'ARRAY'; # @@ -286,25 +324,41 @@ sub primary_menu { && !$public; # only visible to public # users next if $$menuitem[4] eq 'roles' ##show links depending on - && &Apache::loncommon::show_course(); ##term 'Courses' or - next if $$menuitem[4] eq 'courses' ##'Roles' wanted - && !&Apache::loncommon::show_course(); ## - + && (&Apache::loncommon::show_course() ##term 'Courses' or + || $lti); ##'Roles' wanted + next if $$menuitem[4] eq 'courses' ##and not LTI access + && (!&Apache::loncommon::show_course() + || $lti); + next if $$menuitem[4] eq 'notlti' + && $lti; + next if $$menuitem[4] eq 'ltiexc' + && exists($ltiexc{lc($menuitem->[3])}); my $title = $menuitem->[3]; my $position = $menuitem->[5]; if ($position eq '') { $position = 'right'; } - my ($listclass,$linkattr); - if ($links_disabled) { - $listclass = 'LCisDisabled'; - $linkattr = 'aria-disabled="true"'; + if ($env{'request.course.id'} && $menucoll) { + if (($menuitem->[6]) && (!$menuopts{$menuitem->[6]})) { + if ($menuitem->[6] eq 'pers') { + if ($menuopts{'name'} && !$ltiexc{'fullname'} && + $env{'user.name'} && $env{'user.domain'}) { + $menu{$position} .= '
  • '. + &Apache::loncommon::plainname($env{'user.name'}, + $env{'user.domain'}).'
  • '; + next; + } else { + next; + } + } else { + next; + } + } } if (defined($primary_submenu{$title})) { - my ($link,$target); + my $link; if ($menuitem->[0] ne '') { $link = $menuitem->[0]; - $target = '_top'; } else { $link = '#'; } @@ -316,18 +370,43 @@ sub primary_menu { ($item->[2] eq 'blog')) && (!&Apache::lonnet::usertools_access('','',$item->[2], undef,'tools'))); + if ($item->[2] eq 'browsepub') { + if ($env{'request.role'} =~ /^au\./) { + $item->[0] = '/res/'.$env{'request.role.domain'}.'/?launch=1'; + } elsif ($env{'request.role'} =~ /^ca\./($match_domain)/($match_user)$/) { + $item->[0] = '/res/'.$1.'/'.$2.'/?launch=1'; + } elsif (&Apache::lonnet::allowed('bre',$env{'user.domain'})) { + $item->[0] = '/res/'.$env{'user.domain'}.'/?launch=1'; + } elsif (&Apache::lonnet::allowed('bro','/res/')) { + $item->[0] = '/res/?launch=1'; + } else { + next; + } + } + 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'} && !$ltiexc{'fullname'}) { + 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 @@ -338,7 +417,7 @@ sub primary_menu { 'helpdeskmail', $defdom,$origmail); if ($to ne '') { - $menu{$position} .= &prep_menuitem($menuitem,$listclass,$linkattr); + $menu{$position} .= &prep_menuitem($menuitem,$target,$listclass,$linkattr); } } else { $menu{$position} .= ($listclass?'
  • ':'
  • '). @@ -351,9 +430,9 @@ sub primary_menu { $$menuitem[0] = '/adm/login'; } } - $menu{$position} .= prep_menuitem($menuitem,$listclass,$linkattr); + $menu{$position} .= prep_menuitem($menuitem,$target,$listclass,$linkattr); } else { - $menu{$position} .= prep_menuitem($menuitem,$listclass,$linkattr); + $menu{$position} .= prep_menuitem($menuitem,$target,$listclass,$linkattr); } } my @output = ('',''); @@ -392,7 +471,8 @@ sub getauthor{ } sub secondary_menu { - my ($httphost,$links_disabled) = @_; + my ($httphost,$ltiscope,$ltimenu,$noprimary,$menucoll,$menuref, + $links_disabled,$links_target) = @_; my $menu; my $crstype = &Apache::loncommon::course_type(); @@ -413,9 +493,11 @@ 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, + $lti,$ltimapres,%ltiexc,%menuopts); $grouptools = 0; if ($env{'request.course.id'}) { $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'}; @@ -449,9 +531,25 @@ sub secondary_menu { } } } + if ($env{'request.lti.login'}) { + $lti = 1; + if (ref($ltimenu) eq 'HASH') { + foreach my $item ('fullname','coursetitle','role','logout','grades') { + unless ($ltimenu->{$item}) { + $ltiexc{$item} = 1; + } + } + } + if (($ltiscope eq 'map') || ($ltiscope eq 'resource')) { + $ltimapres = 1; + } + } + } + if (($menucoll) && (ref($menuref) eq 'HASH')) { + %menuopts = %{$menuref}; } - my ($listclass,$linkattr); + my ($listclass,$linkattr,$target); if ($links_disabled) { $listclass = 'LCisDisabled'; $linkattr = 'aria-disabled="true"'; @@ -467,6 +565,22 @@ sub secondary_menu { } my ($roleswitcher_js,$roleswitcher_form); + if ($links_target ne '') { + $target = $links_target; + } else { + my ($ltitarget,$deeplinktarget); + if ($env{'request.lti.login'}) { + $ltitarget = $env{'request.lti.target'}; + } + if ($env{'request.deeplink.login'}) { + $deeplinktarget = $env{'request.deeplink.target'}; + } + if (($ltitarget eq 'iframe') || ($deeplinktarget eq '_self')) { + $target = '_self'; + } else { + $target = '_top'; + } + } foreach my $menuitem (@secondary_menu) { # evaluate conditions @@ -481,7 +595,7 @@ sub secondary_menu { next if $$menuitem[4] eq 'crseditCommunity' && ($crstype eq 'Course'); next if $$menuitem[4] eq 'nvgr' - && $canvgr; + && ($canvgr || $ltiexc{'grades'}); next if $$menuitem[4] eq 'vgr' && !$canvgr; next if $$menuitem[4] eq 'viewusers' @@ -502,17 +616,33 @@ 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; + next if $$menuitem[4] eq 'notltimapres' + && $ltimapres; + next if $$menuitem[4] eq 'notlti' + && $lti; + next if $$menuitem[4] eq 'lti' + && (!$lti || !$noprimary); + next if $$menuitem[3] eq 'Logout' + && $ltiexc{'logout'}; 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); + my $link; if ($menuitem->[0] ne '') { $link = $menuitem->[0]; - $target = '_top'; } else { $link = '#'; } @@ -530,9 +660,21 @@ sub secondary_menu { next if ($item->[2] eq 'params' && !$canmodpara && !$canviewpara); next if ($item->[2] eq 'author' && !$author); next if ($item->[2] eq 'cca' && !$canmodifycoauthor); + next if ($item->[2] eq 'lti' && !$lti); + if ($item->[2] =~ /^lti(portfolio|wishlist|blog)$/) { + my $tool = $1; + next if !$lti; + next if (!&Apache::lonnet::usertools_access('','',$tool, + undef,'tools')); + } push(@scndsub,$item); } } + if ($title eq 'Personal' && $env{'user.name'} && $env{'user.domain'}) { + unless ($ltiexc{'fullname'}) { + $title = &Apache::loncommon::plainname($env{'user.name'},$env{'user.domain'}); + } + } if (@scndsub > 0) { $menu .= &create_submenu($link,$target,&mt($title),\@scndsub,1,undef, $listclass,$linkattr); @@ -544,12 +686,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 + $httphost,$target,$menucoll,$menuref ); + if (($$menuitem[5]) && (!$menuopts{$$menuitem[5]})) { + next unless ($has_opa_priv); + } $menu .= $switcher; } else { if ($$menuitem[3] eq 'Syllabus' && $env{'request.course.id'}) { @@ -576,7 +722,7 @@ sub secondary_menu { } $$menuitem[0] = &HTML::Entities::encode($$menuitem[0],'&<>"'); } - $menu .= &prep_menuitem(\@$menuitem,$listclass,$linkattr); + $menu .= &prep_menuitem(\@$menuitem,$target,$listclass,$linkattr); } } if ($menu =~ /\[url\].*\[symb\]/) { @@ -599,6 +745,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; @@ -615,12 +762,12 @@ sub secondary_menu { sub create_submenu { my ($link,$target,$title,$submenu,$translate,$addclass,$listclass,$linkattr) = @_; return unless (ref($submenu) eq 'ARRAY'); - my $disptarget; - if ($target ne '') { - $disptarget = ' target="'.$target.'"'; + my $targetattr; + if (($target ne '') && ($link ne '#')) { + $targetattr = ' target="'.$target.'"'; } my $menu = '
  • '. - ''. + ''. ''.$title. ''. ' ▼'. @@ -697,14 +844,17 @@ sub build_submenu { } $href =~ s/\[returnurl\]/$returnurl/; } + my $targetattr; unless (($href eq '') || ($href =~ /^\#/)) { - $target = ' target="_top"'; + if ($target ne '') { + $targetattr = ' target="'.$target.'"'; + } } $menu .= '
  • '; - $menu .= '' . $title . ''; + $menu .= '' . $title . ''; $menu .= '
  • '; } } @@ -741,7 +891,8 @@ sub registerurl { } sub innerregister { - my ($forcereg,$bread_crumbs,$group,$pagebuttonshide,$hostname) = @_; + my ($forcereg,$bread_crumbs,$group,$pagebuttonshide,$hostname, + $ltiscope,$ltiuri,$showncrumbsref) = @_; my $const_space = ($env{'request.state'} eq 'construct'); my $is_const_dir = 0; @@ -782,30 +933,33 @@ sub innerregister { my $restitle = &Apache::lonnet::gettitle($symb); 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); + if (($env{'request.noversionuri'} ne '/adm/navmaps') && ($mapurl ne '')) { + unless ($ltiscope eq 'resource') { + if (($mapurl ne $env{'course.'.$env{'request.course.id'}.'.url'}) && + !(($ltiscope eq 'map') && (&Apache::lonnet::clutter($resurl) eq $ltiuri))) { + $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'})) { + unless (($ltiscope eq 'map') || ($ltiscope eq 'resource')) { @crumbs = ({text => $crstype.' Contents', href => "Javascript:gopost('/adm/navmaps','')"}); } if ($mapurl ne $env{'course.'.$env{'request.course.id'}.'.url'}) { if (@mapcrumbs) { push(@crumbs,@mapcrumbs); - } else { + } elsif (($ltiscope ne 'map') && ($ltiscope ne 'resource')) { push(@crumbs, {text => '...', no_mt => 1}); } } unless ((@mapcrumbs) || (!$maptitle) || ($maptitle eq 'default.sequence') || - ($mapurl eq $env{'course.'.$env{'request.course.id'}.'.url'})) { + ($mapurl eq $env{'course.'.$env{'request.course.id'}.'.url'}) || + ($ltiscope eq 'resource')) { push @crumbs, {text => $maptitle, no_mt => 1, href => &Apache::lonnet::clutter($mapurl).'?navmap=1'}; } @@ -834,27 +988,51 @@ sub innerregister { if ($env{'form.title'}) { $title = $env{'form.title'}; } - my $trail; + my ($trail,$cnum,$cdom); + if ($env{'form.folderpath'}) { + $cnum = $env{'course.'.$env{'request.course.id'}.'.num'}; + $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'}; + &Apache::loncommon::validate_folderpath(1,'',$cnum,$cdom); + } if ($env{'form.folderpath'}) { &prepare_functions($resurl,$forcereg,$group,undef,undef,1,$hostname); + $title = &HTML::Entities::encode($title,'\'"<>&'); ($trail) = - &Apache::lonhtmlcommon::docs_breadcrumbs(undef,$crstype,undef,$title,1); + &Apache::lonhtmlcommon::docs_breadcrumbs(undef,$crstype,undef,$title,1,1); } else { &Apache::lonhtmlcommon::add_breadcrumb( {text => "Supplemental $crstype Content", href => "javascript:gopost('/adm/supplemental','')"}); - $title = &mt('View Resource'); + $title = &HTML::Entities::encode(&mt('View Resource'),'\'"<>&'); ($trail) = - &Apache::lonhtmlcommon::docs_breadcrumbs(undef,$crstype,undef,$title,1); + &Apache::lonhtmlcommon::docs_breadcrumbs(undef,$crstype,undef,$title,1,1); + } + if (ref($showncrumbsref)) { + $$showncrumbsref = 1; } return $trail; } elsif ($resurl =~ m{^\Q/uploaded$courseurl/portfolio/syllabus/}) { &Apache::lonhtmlcommon::clear_breadcrumbs(); &prepare_functions('/public'.$courseurl."/syllabus", $forcereg,$group,undef,undef,1,$hostname); - $title = &mt('Syllabus File'); + $title = &HTML::Entities::encode(&mt('Syllabus File'),'\'"<>&'); + my ($trail) = + &Apache::lonhtmlcommon::docs_breadcrumbs(undef,$crstype,undef,$title,1,1); + if (ref($showncrumbsref)) { + $$showncrumbsref = 1; + } + return $trail; + } elsif (($resurl eq '/public'.$courseurl.'/syllabus') && + ($env{'form.folderpath'})) { + if ($env{'form.title'}) { + $title = $env{'form.title'}; + } else { + $title = 'Syllabus'; + } + &prepare_functions($resurl,$forcereg,$group,undef,undef,1,$hostname); + $title = &HTML::Entities::encode($title,'\'"<>&'); my ($trail) = - &Apache::lonhtmlcommon::docs_breadcrumbs(undef,$crstype,undef,$title,1,$hostname); + &Apache::lonhtmlcommon::docs_breadcrumbs(undef,$crstype,undef,$title,1,1); return $trail; } unless ($env{'request.state'} eq 'construct') { @@ -906,8 +1084,14 @@ sub innerregister { $perms{'mdc'} = &Apache::lonnet::allowed('mdc',$env{'request.course.id'}); $perms{'cev'} = &Apache::lonnet::allowed('cev',$env{'request.course.id'}); my @privs; + my $gradable_exttool; if ($env{'request.symb'} ne '') { - if ($env{'request.filename'}=~/$LONCAPA::assess_re/) { + if ($env{'request.noversionuri'} =~ m{^/adm/$cdom/$cnum/(\d+)/ext\.tool$}) { + if (&Apache::lonnet::EXT('resource.0.gradable') =~ /^yes$/i) { + $gradable_exttool = 1; + push(@privs,('mgr','vgr')); + } + } elsif ($env{'request.filename'}=~/$LONCAPA::assess_re/) { push(@privs,('mgr','vgr')); } push(@privs,('opa','vpa')); @@ -922,8 +1106,8 @@ sub innerregister { # # Determine whether or not to show Grades and Submissions buttons # - if ($env{'request.symb'} ne '' && - $env{'request.filename'}=~/$LONCAPA::assess_re/) { + if (($env{'request.symb'} ne '') && + (($env{'request.filename'}=~/$LONCAPA::assess_re/) || ($gradable_exttool))) { if ($perms{'mgr'}) { $hwkadd.= &switch('','',7,2,'pgrd.png','Content Grades', 'grades[_4]', @@ -958,6 +1142,102 @@ sub innerregister { 'Folder/Page Content'); } # End modifiable folder/page container check + +# +# Determine whether to show View As button for shortcut to display problem, answer, and submissions +# + + if (($env{'request.symb'} ne '') && + ($env{'request.filename'}=~/$LONCAPA::assess_re/) && + (($perms{'mgr'}) || ($perms{'vgr'}))) { + my ($viewas,$text,$change,$visibility,$vuname,$vudom,$vid,$leftvis,$defdom, + $domselector,$righticon); + my %lt = &Apache::lonlocal::texthash( + view => 'View', + upda => 'Update', + ); + my $possdomstr = $env{'course.'.$env{'request.course.id'}.'.internal.userdomains'}; + if ($possdomstr =~ /,/) { + my @possdoms = split(/,/,$possdomstr); + if ($env{'request.user_in_effect'} =~ /^$match_username:($match_domain)$/) { + $defdom = $1; + } elsif (grep(/^\Q$cdom\E$/,@possdoms)) { + $defdom = $cdom; + } elsif (&Apache::lonnet::domain($possdoms[0]) ne '') { + $defdom = $possdoms[0]; + } + $domselector = &Apache::loncommon::select_dom_form($defdom,'vudom','','','',\@possdoms); + } elsif (($possdomstr ne '') && (&Apache::lonnet::domain($possdomstr) ne '')) { + if ($env{'request.user_in_effect'} =~ /^$match_username:($match_domain)$/) { + $defdom = $1; + } else { + $defdom = $possdomstr; + } + } + if ($env{'request.user_in_effect'} =~ /^($match_username):($match_domain)$/) { + ($vuname,$vudom) = ($1,$2); + unless (&Apache::lonnet::is_advanced_user($vudom,$vuname)) { + $vid = (&Apache::lonnet::idrget($vudom,$vuname))[1]; + } + $viewas = $env{'request.user_in_effect'}; + $text = $lt{'upda'}; + $change = 'off'; + $visibility = 'inline'; + $leftvis = 'none'; + $defdom = $vudom; + $righticon = '✖'; + } else { + $text = $lt{'view'}; + $change = 'on'; + $visibility = 'none'; + $leftvis = 'inline'; + if ($defdom eq '') { + $defdom = $cdom; + } + } + my $sellink = &Apache::loncommon::selectstudent_link('userview','vuname','vudom','','','vuidentifier'); + my $selscript=&Apache::loncommon::studentbrowser_javascript(); + my $shownsymb = &HTML::Entities::encode(&Apache::lonenc::check_encrypt($env{'request.symb'}),'<>&"'); + my $input; + my @items = ( + '', + '' + ); + if ($domselector) { + push(@items,$domselector); + $input = &mt('[_1]User:[_2] or [_3]ID:[_4] at [_5] | ',@items); + } else { + $input = &mt('[_1]Username:[_2] or [_3]ID:[_4] | ',@items). + ''; + } + $input .= '', + ''; + my $chooser = < +►  + +
    +
    + +$input +$sellink + +
    +
    + +$righticon + +END + &switch('','',7,5,'viewuser.png','View As','user[_1]', + 'toggleViewAsUser('."'$change'".')', + 'View As','','','',$chooser); + } +# End view as user check + } # End course context @@ -989,8 +1269,16 @@ s&6&1&list.png&Directory&dir[_1]&golist( s&6&2&rtrv.png&Retrieve&version[_1]&gocstr('/adm/retrieve','/priv/$udom/$uname/$cleandisfn')&Retrieve old version s&6&3&pub.png&Publish&resource[_3]&gocstr('/adm/publish','/priv/$udom/$uname/$cleandisfn')&Publish this resource s&7&1&del.png&Delete&resource[_2]&gocstr('/adm/cfile?action=delete','/priv/$udom/$uname/$cleandisfn')&Delete this resource +ENDMENUITEMS + +# +# Print only makes sense for certain mime types +# + if ($thisdisfn=~/\.(xml|html|htm|xhtml|xhtm|tex)$/ || $thisdisfn=~/$LONCAPA::assess_re/) { + $menuitems .= (<new(); + if (ref($navmap)) { + my $mapres = $navmap->getResourceByUrl($ltiuri); + if (ref($mapres)) { + if ($navmap->isLastResource($mapres,$env{'request.symb'})) { + $showforw = 0; + } + if ($navmap->isFirstResource($mapres,$env{'request.symb'})) { + $showback = 0; + } + } + } + if ($showback) { + $menuitems.=" +s&2&1&back.png&&&gopost('/adm/flip','back:'+currentURL)&Previous content resource&&1"; + } + if ($showforw) { + $menuitems.=" +s&2&3&forw.png&&&gopost('/adm/flip','forward:'+currentURL)&Next content resource&&3"; + } + } else { + $menuitems.=" +s&2&1&back.png&&&gopost('/adm/flip','back:'+currentURL)&Previous content resource&&1 +s&2&3&forw.png&&&gopost('/adm/flip','forward:'+currentURL)&Next content resource&&3"; + } + $menuitems .= (<'; $inlineremote[$idx] = ''. - $pic.''.$top.' '; + $pic.''.$top.' '.$form; } # Remote $img=~s/\.png$/\.gif/; @@ -1859,7 +2200,8 @@ sub switch { unless ($env{'request.state'} eq 'construct') { push(@tools,63); } - if (($env{'environment.icons'} eq 'iconsonly') && + if ((($env{'environment.icons'} eq 'iconsonly') || + ($env{'environment.icons'} eq '') && ($env{'request.lti.login'})) && (grep(/^$idx$/,@tools))) { $inlineremote[$idx] = ''.$pic.''; @@ -2225,6 +2567,328 @@ 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 view_as_js { + my ($url,$symb) = @_; + my %lt = &Apache::lonlocal::texthash( + ente => 'Enter a username or a student/employee ID', + info => 'Information you entered does not match a valid course user', + ); + &js_escape(\%lt); + return <<"END"; + +function toggleViewAsUser(change) { + if (document.getElementById('LC_selectuser')) { + var seluserid = document.getElementById('LC_selectuser'); + var currstyle = seluserid.style.display; + if (change == 'off') { + document.userview.elements['LC_viewas'].value = ''; + document.userview.elements['vuname'].value = ''; + document.userview.elements['vid'].value = ''; + document.userview.submit(); + return; + } + if ((document.getElementById('usexpand')) && (document.getElementById('uscollapse'))) { + if (currstyle == 'inline') { + seluserid.style.display = 'none'; + document.getElementById('usexpand').innerHTML='► '; + document.getElementById('uscollapse').innerHTML=''; + } else { + seluserid.style.display = 'inline'; + document.getElementById('usexpand').innerHTML=''; + document.getElementById('uscollapse').innerHTML='◄ '; + toggleIdentifier(document.userview); + } + } + } + return; +} + +function validCourseUser(form,change) { + var possuname = form.elements['vuname'].value; + var possuid = form.elements['vid'].value; + var domelem = form.elements['vudom']; + var possudom = ''; + if ((domelem.tagName === 'INPUT') && ((domelem.type === 'text') || (domelem.type === 'hidden'))) { + possudom = domelem.value; + } else if (domelem.tagName === 'SELECT') { + possudom = domelem.options[domelem.selectedIndex].value; + } + if ((possuname == '') && (possuid == '')) { + if (change == 'off') { + form.elements['LC_viewas'].value = ''; + form.submit(); + } else { + alert("$lt{'ente'}"); + } + return; + } + var http = new XMLHttpRequest(); + var url = "/adm/courseuser"; + var params = "uname="+possuname+"&uid="+possuid+"&udom="+possudom; + http.open("POST", url, true); + http.setRequestHeader("Content-type", "application/x-www-form-urlencoded"); + http.onreadystatechange = function() { + if (http.readyState == 4 && http.status == 200) { + var data = JSON.parse(http.responseText); + if (Array.isArray(data.match)) { + var len = data.match.length; + if (len == 2) { + if (data.match[0] != '' && data.match[1] != '') { + form.elements['LC_viewas'].value = data.match[0]+':'+data.match[1]; + form.submit(); + } + } else { + alert("$lt{'info'}"); + } + } + } + return; + } + http.send(params); + return false; +} + +function toggleIdentifier(form) { + if ((document.getElementById('LC_vuname')) && (document.getElementById('LC_vid'))) { + var radioelem = form.elements['vuidentifier']; + if (radioelem.length > 0) { + var i; + for (i=0; i +
    @@ -2454,15 +3169,27 @@ ENDSERVERFORM } sub constspaceform { + my ($frameset) = @_; + my ($target,$printtarget); + if ($frameset) { + $target = ' target="_parent"'; + $printtarget = ' target="_parent"'; + } else { + unless ((($env{'request.lti.login'}) && ($env{'request.lti.target'} eq 'iframe')) || + (($env{'request.deeplink.login'}) && ($env{'request.deeplink.target'} eq '_self'))) { + $target = ' target="_top"'; + $printtarget = ' target="_top"'; + } + } return(< + -
    +
    -
    + @@ -2492,12 +3219,12 @@ sub hidden_button_check { } sub roles_selector { - my ($cdom,$cnum,$httphost) = @_; + my ($cdom,$cnum,$httphost,$target,$menucoll,$menuref) = @_; my $crstype = &Apache::loncommon::course_type(); 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'; @@ -2598,10 +3325,15 @@ sub roles_selector { } } if ((keys(%seccount) > 1) || ($numdiffsec > 1)) { + my $targetattr; + if ($target ne '') { + $targetattr = ' target="'.$target.'"'; + } my @submenu; - $js = &jump_to_role($cdom,$cnum,\%seccount,\%courseroles,\%courseprivs,\%roledesc,$privref); + $js = &jump_to_role($cdom,$cnum,\%seccount,\%courseroles,\%courseprivs, + \%roledesc,$privref,$menucoll,$menuref); $form = - ''."\n". + ''."\n". ' '."\n". ' '."\n". @@ -2618,12 +3350,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,16 +3387,19 @@ 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]); } } } if (@submenu > 0) { - $switcher = &create_submenu('','',&mt('Switch role'),\@submenu); + $switcher = &create_submenu('#',$target,&mt('Switch role'),\@submenu); } } - return ($js,$form,$switcher); + return ($js,$form,$switcher,$has_opa_priv); } sub get_all_courseroles { @@ -2824,7 +3566,8 @@ sub get_customadhoc_roles { } sub jump_to_role { - my ($cdom,$cnum,$seccount,$courseroles,$courseprivs,$roledesc,$privref) = @_; + my ($cdom,$cnum,$seccount,$courseroles,$courseprivs,$roledesc,$privref, + $menucoll,$menuref) = @_; my %lt = &Apache::lonlocal::texthash( this => 'This role has section(s) associated with it.', ente => 'Enter a specific section.', @@ -2835,6 +3578,7 @@ sub jump_to_role { role => 'The role you selected is not permitted to view the current page.', swit => 'Switch role, but display Main Menu page instead?', ); + &js_escape(\%lt); my $js; if (ref($courseroles) eq 'HASH') { $js = ' var secpick = new Array("'.$lt{'ente'}.'","'.$lt{'orlb'}.'");'."\n". @@ -2857,6 +3601,8 @@ sub jump_to_role { } } my $checkroles = 0; + my $fallback = '/adm/menu'; + my $displaymsg = $lt{'swit'}; if ((ref($privref) eq 'ARRAY') && (@{$privref} > 0) && (ref($courseprivs) eq 'HASH')) { my %disallowed; foreach my $role (sort(keys(%{$courseprivs}))) { @@ -2878,8 +3624,22 @@ sub jump_to_role { $checkroles = 1; $js .= " var disallow = new Array('".join("','",keys(%disallowed))."');\n". " var rolecheck = 1;\n"; + if ($menucoll) { + if (ref($menuref) eq 'HASH') { + if ($menuref->{'main'} eq 'n') { + $fallback = '/adm/navmaps'; + if (&Apache::loncommon::course_type() eq 'Community') { + $displaymsg = &mt('Switch role, but display Community Contents page instead?'); + } else { + $displaymsg = &mt('Switch role, but display Course Contents page instead?'); + } + &js_escape(\$displaymsg); + } + } + } } } + &js_escape(\$fallback); if (!$checkroles) { $js .= " var disallow = new Array();\n". " rolecheck = 0;\n"; @@ -2902,8 +3662,8 @@ function adhocRole(newrole) { if (rolecheck > 0) { for (var i=0; i{'starttime'} < $now) && @@ -3016,10 +3786,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 +3807,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 +3827,7 @@ sub countdown_timer { } my $desc = &mt('Countdown to due date/time'); return < $collapse @@ -3057,6 +3842,94 @@ END return; } +sub linkprot_exit { + if (($env{'request.course.id'}) && ($env{'request.deeplink.login'})) { + my ($deeplink_symb,$deeplink); + my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'}; + my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'}; + if (($cnum ne '') && ($cdom ne '')) { + $deeplink_symb = &Apache::loncommon::deeplink_login_symb($cnum,$cdom); + if ($deeplink_symb) { + if ($deeplink_symb =~ /\.(page|sequence)$/) { + my $mapname = &Apache::lonnet::deversion((&Apache::lonnet::decode_symb($deeplink_symb))[2]); + my $navmap = Apache::lonnavmaps::navmap->new(); + if (ref($navmap)) { + $deeplink = $navmap->get_mapparam(undef,$mapname,'0.deeplink'); + } + } else { + $deeplink = &Apache::lonnet::EXT('resource.0.deeplink',$deeplink_symb); + } + if ($deeplink ne '') { + my ($state,$others,$listed,$scope,$protect,$display,$target,$exit) = split(/,/,$deeplink); + my %lt = &Apache::lonlocal::texthash( + title => 'Exit Tool', + okdone => 'Click "OK" to exit embedded tool', + cancel => 'Click "Cancel" to continue working.', + ok => 'OK', + exit => 'Cancel', + ); + if ($exit) { + my ($show,$text) = split(/:/,$exit); + unless ($show eq 'no') { + my $height = 250; + my $width = 300; + my $exitbuttontext; + if ($text eq '') { + $exitbuttontext = &mt('Exit Tool'); + } else { + $exitbuttontext = $text; + } + return < + + + + +
    +

    $lt{'okdone'} $lt{'cancel'}

    +
    + + + +END + } + } + } + } + } + } + return; +} + # ================================================================ Main Program BEGIN { @@ -3073,13 +3946,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];