--- loncom/interface/lonmenu.pm 2018/05/08 20:30:12 1.491 +++ loncom/interface/lonmenu.pm 2022/07/07 15:28:08 1.526 @@ -1,7 +1,7 @@ # The LearningOnline Network with CAPA # Routines to control the menu # -# $Id: lonmenu.pm,v 1.491 2018/05/08 20:30:12 raeburn Exp $ +# $Id: lonmenu.pm,v 1.526 2022/07/07 15:28:08 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,$ltitarget) +=item prep_menuitems(\@menuitem,$target,$listclass,$linkattr) This routine wraps a menuitem in proper HTML. It is used by primary_menu() and secondary_menu(). @@ -220,9 +220,9 @@ use vars qw(@desklines %category_names % my @inlineremote; sub prep_menuitem { - my ($menuitem,$ltitarget) = @_; + 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, @@ -247,8 +246,8 @@ sub prep_menuitem { # @primary_menu is filled within the BEGIN block of this module with # entries from mydesk.tab sub primary_menu { - my ($crstype,$ltimenu) = @_; - my (%menu,%ltiexc); + 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; @@ -265,10 +264,9 @@ sub primary_menu { my %roles_in_env; $rolecount = &Apache::lonroles::roles_from_env(\%roles_in_env,$update); } - my ($lti,$ltitarget); + my $lti; if ($env{'request.lti.login'}) { $lti = 1; - $ltitarget = $env{'request.lti.target'}; if (ref($ltimenu) eq 'HASH') { foreach my $item ('fullname','logout') { unless ($ltimenu->{$item}) { @@ -277,6 +275,30 @@ sub primary_menu { } } } + 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'; # @@ -292,10 +314,10 @@ sub primary_menu { # users next if $$menuitem[4] eq 'roles' ##show links depending on && (&Apache::loncommon::show_course() ##term 'Courses' or - || $env{'request.lti.login'}); ##'Roles' wanted + || $lti); ##'Roles' wanted next if $$menuitem[4] eq 'courses' ##and not LTI access && (!&Apache::loncommon::show_course() - || !$env{'request.lti.login'}); + || $lti); next if $$menuitem[4] eq 'notlti' && $lti; next if $$menuitem[4] eq 'ltiexc' @@ -312,13 +334,27 @@ 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'} && !$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]; - unless ($ltitarget eq 'iframe') { - $target = '_top'; - } } else { $link = '#'; } @@ -331,19 +367,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 ($title eq 'Personal' && $env{'user.name'} && $env{'user.domain'} ) { - unless ($ltiexc{'fullname'}) { - $title = &Apache::loncommon::plainname($env{'user.name'},$env{'user.domain'}); + 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); + $menu{$position} .= &create_submenu($link,$target,$title,\@primsub,1,undef,$listclass,$linkattr); } elsif ($link) { - $menu{$position} .= '
  • '.$title.'
  • '; + $menu{$position} .= ($listclass?'
  • ':'
  • '). + ''.$title.'
  • '; } } } elsif ($$menuitem[3] eq 'Help') { # special treatment for helplink @@ -355,13 +402,22 @@ sub primary_menu { 'helpdeskmail', $defdom,$origmail); if ($to ne '') { - $menu{$position} .= &prep_menuitem($menuitem,$ltitarget); + $menu{$position} .= &prep_menuitem($menuitem,$target,$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,$target,$listclass,$linkattr); } else { - $menu{$position} .= prep_menuitem($menuitem,$ltitarget); + $menu{$position} .= prep_menuitem($menuitem,$target,$listclass,$linkattr); } } my @output = ('',''); @@ -400,7 +456,8 @@ sub getauthor{ } sub secondary_menu { - my ($httphost,$ltiscope,$ltimenu,$noprimary) = @_; + my ($httphost,$ltiscope,$ltimenu,$noprimary,$menucoll,$menuref, + $links_disabled,$links_target) = @_; my $menu; my $crstype = &Apache::loncommon::course_type(); @@ -424,7 +481,8 @@ sub secondary_menu { my $canplc = &Apache::lonnet::allowed('plc', $crs_sec); my $author = &getauthor(); - my ($cdom,$cnum,$showsyllabus,$showfeeds,$showresv,$grouptools,$lti,$ltimapres,%ltiexc); + 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'}; @@ -448,10 +506,9 @@ sub secondary_menu { $showresv = 1; } } - my %groups = &Apache::lonnet::get_active_groups( - $env{'user.domain'}, $env{'user.name'},$cdom,$cnum); - if (%groups) { - foreach my $group (keys(%groups)) { + 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) { @@ -473,6 +530,15 @@ sub secondary_menu { } } } + if (($menucoll) && (ref($menuref) eq 'HASH')) { + %menuopts = %{$menuref}; + } + + my ($listclass,$linkattr,$target); + if ($links_disabled) { + $listclass = 'LCisDisabled'; + $linkattr = 'aria-disabled="true"'; + } my ($canmodifycoauthor); if ($env{'request.role'} eq "au./$env{'user.domain'}/") { @@ -483,9 +549,22 @@ sub secondary_menu { } } - my ($roleswitcher_js,$roleswitcher_form,$ltitarget); - if ($env{'request.lti.login'}) { - $ltitarget = $env{'request.lti.target'}; + 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) { @@ -535,13 +614,15 @@ sub secondary_menu { && $ltiexc{'logout'}; my $title = $menuitem->[3]; + if ($env{'request.course.id'} && $menucoll) { + unless ($$menuitem[5] eq '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]; - unless ($ltitarget eq 'iframe') { - $target = '_top'; - } } else { $link = '#'; } @@ -569,25 +650,32 @@ sub secondary_menu { push(@scndsub,$item); } } - if ($title eq 'Personal' && $env{'user.name'} && $env{'user.domain'} ) { + 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,$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'}) { # 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,$ltitarget + $httphost,$target,$menucoll,$menuref ); + if (($$menuitem[5]) && (!$menuopts{$$menuitem[5]})) { + next unless ($has_opa_priv); + } $menu .= $switcher; } elsif ($$menuitem[3] eq 'Help') { # special treatment for helplink next if ($crstype eq 'Placement'); @@ -605,17 +693,19 @@ 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 ($$menuitem[0] =~ m{^https?://}) { - $$menuitem[0] = 'http://'.$ENV{'SERVER_NAME'}.$$menuitem[0]; - } - unless ($$menuitem[0] =~ /(\&|\?)usehttp=1/) { - $$menuitem[0] .= (($$menuitem[0]=~/\?/) ? '&' : '?').'usehttp=1'; + unless ((&Apache::lonnet::uses_sts()) || (&Apache::lonnet::waf_allssl())) { + 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,$ltitarget); + $menu .= &prep_menuitem(\@$menuitem,$target,$listclass,$linkattr); } } if ($menu =~ /\[url\].*\[symb\]/) { @@ -653,14 +743,14 @@ 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 '') { - $disptarget = ' target="'.$target.'"'; + my $targetattr; + if (($target ne '') && ($link ne '#')) { + $targetattr = ' target="'.$target.'"'; } my $menu = '
  • '. - ''. + ''. ''.$title. ''. ' ▼'. @@ -668,7 +758,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; @@ -678,7 +768,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 ''; } @@ -737,14 +827,17 @@ sub build_submenu { } $href =~ s/\[returnurl\]/$returnurl/; } + my $targetattr; unless (($href eq '') || ($href =~ /^\#/)) { - if ($target eq '_top') { - $target = ' target="_top"'; + if ($target ne '') { + $targetattr = ' target="'.$target.'"'; } } - $menu .= '
  • '; - $menu .= '' . $title . ''; + $menu .= '
  • '; + $menu .= '' . $title . ''; $menu .= '
  • '; } } @@ -753,7 +846,8 @@ sub build_submenu { } sub innerregister { - my ($forcereg,$bread_crumbs,$group,$pagebuttonshide,$hostname,$ltiscope,$ltiuri) = @_; + my ($forcereg,$bread_crumbs,$group,$pagebuttonshide,$hostname, + $ltiscope,$ltiuri,$showncrumbsref) = @_; my $const_space = ($env{'request.state'} eq 'construct'); my $is_const_dir = 0; @@ -794,10 +888,7 @@ sub innerregister { } } } - unless (($forcereg) && - ($env{'request.noversionuri'} eq '/adm/navmaps') && - ($mapurl eq $env{'course.'.$env{'request.course.id'}.'.url'}) || - (($crstype eq 'Placement') && (!$env{'request.role.adv'})) || + unless ((($crstype eq 'Placement') && (!$env{'request.role.adv'})) || ($ltiscope eq 'map') || ($ltiscope eq 'resource')) { @crumbs = ({text => $crstype.' Contents', href => "Javascript:gopost('/adm/navmaps','')"}); @@ -848,14 +939,17 @@ sub innerregister { if ($env{'form.folderpath'}) { &prepare_functions($resurl,$forcereg,$group,undef,undef,1,$hostname); ($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'); ($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/}) { @@ -864,7 +958,10 @@ sub innerregister { $forcereg,$group,undef,undef,1,$hostname); $title = &mt('Syllabus File'); my ($trail) = - &Apache::lonhtmlcommon::docs_breadcrumbs(undef,$crstype,undef,$title,1,$hostname); + &Apache::lonhtmlcommon::docs_breadcrumbs(undef,$crstype,undef,$title,1,1); + if (ref($showncrumbsref)) { + $$showncrumbsref = 1; + } return $trail; } unless ($env{'request.state'} eq 'construct') { @@ -986,6 +1083,13 @@ sub innerregister { $currdir =~ s|[^/]+$||; my $cleandisfn = &Apache::loncommon::escape_single($thisdisfn); my $esc_currdir = &Apache::loncommon::escape_single($currdir); + my $pubfile = "/res/$udom/$uname/$thisdisfn"; + my $candelete = 1; + if (-e $londocroot.$pubfile) { + unless (&Apache::lonnet::metadata($pubfile,'obsolete')) { + undef($candelete); + } + } # # Probably should be in mydesk.tab # @@ -993,7 +1097,18 @@ sub innerregister { s&6&1&list.png&Directory&dir[_1]&golist('$esc_currdir')&List current directory 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&3©.png&Copy&resource[_4]&gocstr('/adm/cfile?action=copy','/priv/$udom/$uname/$cleandisfn')&Copy this resource +ENDMENUITEMS +# +# Rename and Delete only available if obsolete or unpublished +# + if ($candelete) { + $menuitems .= (<'.$pic.''; @@ -1822,8 +1968,17 @@ sub check_for_rcrs { if (!$showreqcrs) { foreach my $type (@reqtypes) { if ($env{'environment.reqcrsotherdom.'.$type} ne '') { - $showreqcrs = 1; - last; + my @domains = split(',',$env{'environment.reqcrsotherdom.'.$type}); + foreach my $entry (@domains) { + my ($extdom,$extopt) = split(':',$entry); + if (&Apache::lonnet::will_trust('reqcrs',$env{'user.domain'},$extdom)) { + $showreqcrs = 1; + last; + } + } + if ($showreqcrs) { + last; + } } } } @@ -1902,13 +2057,18 @@ sub done_button_js { 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'}); - @resources=$navmap->retrieveResources($mapurl,sub { $_[0]->is_problem() }); + 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)) { @@ -1960,6 +2120,7 @@ sub done_button_js {
    +
    @@ -2041,6 +2202,7 @@ END
    +
    @@ -2086,13 +2248,17 @@ 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./'. @@ -2116,14 +2282,22 @@ sub utilityfunctions { my $esc_url=&escape($currenturl); my $esc_symb=&escape($currentsymb); + my $newname = &mt('New Name'); my $countdown = &countdown_toggle_js(); - my $ltitarget; + my ($ltitarget,$deeplinktarget); if ($env{'request.lti.login'}) { $ltitarget = $env{'request.lti.target'}; } + if ($env{'request.deeplink.login'}) { + $deeplinktarget = $env{'request.deeplink.target'}; + } + my $annotateurl = '/adm/annotation'; + if ($httphost) { + $annotateurl = '/adm/annotations'; + } my $hostvar = ' function setLCHost() { var lcHostname=""; @@ -2182,6 +2356,22 @@ function gocstr(url,filename) { this.document.cstrdelete.submit(); return; } + if ((url == '/adm/cfile?action=copy') || (url == '/adm/cfile?action=rename')) { + this.document.cstrcopy.filename.value = filename; + var oldname = filename.substring(filename.lastIndexOf("/") + 1); + var newname=prompt('$newname',oldname); + if (newname == "" || !newname || newname == oldname) { + return; + } + if (url == '/adm/cfile?action=rename') { + this.document.cstrcopy.action.value = 'rename'; + } else { + this.document.cstrcopy.action.value = 'copy'; + } + this.document.cstrcopy.newfilename.value = newname; + this.document.cstrcopy.submit(); + return; + } if (url == '/adm/printout') { this.document.cstrprint.postdata.value = filename this.document.cstrprint.curseed.value = 0; @@ -2221,7 +2411,8 @@ function golist(url) { currentSymb= null; var lcHostname = setLCHost(); var ltitarget = '$ltitarget'; - if (ltitarget == 'iframe') { + var deeplinktarget = '$deeplinktarget'; + if ((ltitarget == 'iframe') || (deeplinktarget == '_self')) { document.location.href=lcHostname+url; } else { top.location.href=lcHostname+url; @@ -2231,11 +2422,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'); } } @@ -2257,7 +2448,7 @@ function annotate() { annotator.document.write( '$start_page_annotate' +"
    " + +"action='$annotateurl'>" +"" +"<\\/form>" +'$end_page_annotate'); @@ -2279,8 +2470,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'); } @@ -2320,6 +2510,9 @@ sub serverform { unless (($env{'request.lti.login'}) && ($env{'request.lti.target'} eq 'iframe')) { $target = ' target="_top"'; } + if (($env{'request.deeplink.login'}) && ($env{'request.deeplink.target'} eq '_self')) { + $target = ' target="_self"'; + } return(< @@ -2331,10 +2524,17 @@ ENDSERVERFORM } sub constspaceform { + my ($frameset) = @_; my ($target,$printtarget); - unless (($env{'request.lti.login'}) && ($env{'request.lti.target'} eq 'iframe')) { - $target = ' target="_top"'; + 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(< @@ -2349,6 +2549,11 @@ sub constspaceform { +
    + + + +
    ENDCONSTSPACEFORM } @@ -2364,12 +2569,12 @@ sub hidden_button_check { } sub roles_selector { - my ($cdom,$cnum,$httphost,$ltitarget) = @_; + 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'; @@ -2470,10 +2675,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". @@ -2490,12 +2700,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)]); } @@ -2520,16 +2737,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,'','',$ltitarget); + $switcher = &create_submenu('#',$target,&mt('Switch role'),\@submenu); } } - return ($js,$form,$switcher); + return ($js,$form,$switcher,$has_opa_priv); } sub get_all_courseroles { @@ -2696,7 +2916,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.', @@ -2707,6 +2928,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". @@ -2729,6 +2951,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}))) { @@ -2750,8 +2974,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"; @@ -2774,8 +3012,8 @@ function adhocRole(newrole) { if (rolecheck > 0) { for (var i=0; i'; } +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 { @@ -2977,13 +3303,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];