--- loncom/interface/lonmenu.pm 2021/11/15 22:36:37 1.511 +++ loncom/interface/lonmenu.pm 2023/09/27 14:07:47 1.537 @@ -1,7 +1,7 @@ # The LearningOnline Network with CAPA # Routines to control the menu # -# $Id: lonmenu.pm,v 1.511 2021/11/15 22:36:37 raeburn Exp $ +# $Id: lonmenu.pm,v 1.537 2023/09/27 14:07:47 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(). @@ -210,7 +210,6 @@ use Apache::lonenc(); use Apache::lonlocal; use Apache::lonmsg(); use LONCAPA qw(:DEFAULT :match); -use LONCAPA::ltiutils; use HTML::Entities(); use Apache::lonwishlist(); @@ -220,9 +219,9 @@ use vars qw(@desklines %category_names % my @inlineremote; sub prep_menuitem { - my ($menuitem,$ltitarget,$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, @@ -247,7 +245,7 @@ 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,$menucoll,$menuref,$links_disabled) = @_; + 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) @@ -265,10 +263,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 +274,27 @@ 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}; } @@ -332,18 +350,10 @@ sub primary_menu { } } } - my ($listclass,$linkattr); - if ($links_disabled) { - $listclass = 'LCisDisabled'; - $linkattr = 'aria-disabled="true"'; - } 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 = '#'; } @@ -391,7 +401,7 @@ sub primary_menu { 'helpdeskmail', $defdom,$origmail); if ($to ne '') { - $menu{$position} .= &prep_menuitem($menuitem,$ltitarget,$listclass,$linkattr); + $menu{$position} .= &prep_menuitem($menuitem,$target,$listclass,$linkattr); } } else { $menu{$position} .= ($listclass?'
  • ':'
  • '). @@ -404,9 +414,9 @@ sub primary_menu { $$menuitem[0] = '/adm/login'; } } - $menu{$position} .= prep_menuitem($menuitem,$ltitarget,$listclass,$linkattr); + $menu{$position} .= prep_menuitem($menuitem,$target,$listclass,$linkattr); } else { - $menu{$position} .= prep_menuitem($menuitem,$ltitarget,$listclass,$linkattr); + $menu{$position} .= prep_menuitem($menuitem,$target,$listclass,$linkattr); } } my @output = ('',''); @@ -445,7 +455,8 @@ sub getauthor{ } sub secondary_menu { - my ($httphost,$ltiscope,$ltimenu,$noprimary,$menucoll,$menuref,$links_disabled) = @_; + my ($httphost,$ltiscope,$ltimenu,$noprimary,$menucoll,$menuref, + $links_disabled,$links_target) = @_; my $menu; my $crstype = &Apache::loncommon::course_type(); @@ -522,7 +533,7 @@ sub secondary_menu { %menuopts = %{$menuref}; } - my ($listclass,$linkattr); + my ($listclass,$linkattr,$target); if ($links_disabled) { $listclass = 'LCisDisabled'; $linkattr = 'aria-disabled="true"'; @@ -537,9 +548,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) { @@ -595,12 +619,9 @@ sub secondary_menu { } } 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 = '#'; } @@ -637,7 +658,7 @@ sub secondary_menu { $menu .= &create_submenu($link,$target,&mt($title),\@scndsub,1,undef, $listclass,$linkattr); } elsif ($link ne '#') { - $menu .= ($listclass?'
  • ':''). + $menu .= ($listclass?'
  • ':'
  • '). ''. &mt($title).'
  • '; } @@ -649,7 +670,7 @@ sub secondary_menu { &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); @@ -683,7 +704,7 @@ sub secondary_menu { } $$menuitem[0] = &HTML::Entities::encode($$menuitem[0],'&<>"'); } - $menu .= &prep_menuitem(\@$menuitem,$ltitarget,$listclass,$linkattr); + $menu .= &prep_menuitem(\@$menuitem,$target,$listclass,$linkattr); } } if ($menu =~ /\[url\].*\[symb\]/) { @@ -723,12 +744,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. ''. ' ▼'. @@ -805,16 +826,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 .= '' . $title . ''; $menu .= '
  • '; } } @@ -823,7 +845,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; @@ -864,10 +887,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','')"}); @@ -914,27 +934,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,$hostname); + &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,1); return $trail; } unless ($env{'request.state'} eq 'construct') { @@ -1029,11 +1073,76 @@ 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,$righticon); + my %lt = &Apache::lonlocal::texthash( + view => 'View', + upda => 'Update', + ); + 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'; + $defdom = $cdom; + } + my $sellink = &Apache::loncommon::selectstudent_link('userview','vuname','vudom'); + my $selscript=&Apache::loncommon::studentbrowser_javascript(); + my $shownsymb = &HTML::Entities::encode(&Apache::lonenc::check_encrypt($env{'request.symb'}),'<>&"'); + my $input = &mt('User: [_1] or ID: [_2] at: [_3]', + '', + '', + &Apache::loncommon::select_dom_form($defdom,'vudom')). + '', + ''; + 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 # Prepare the rest of the buttons - my ($menuitems,$got_prt,$got_wishlist); + my ($menuitems,$got_prt,$got_wishlist,$crsauthor); if ($const_space) { # # We are in construction space @@ -1042,28 +1151,62 @@ sub innerregister { my $londocroot = $Apache::lonnet::perlvar{'lonDocRoot'}; my ($udom,$uname,$thisdisfn) = ($env{'request.filename'}=~m{^\Q$londocroot/priv/\E([^/]+)/([^/]+)/(.*)$}); + my $crsauthor; + if (($env{'request.course.id'}) && + ($env{'course.'.$env{'request.course.id'}.'.num'} eq $uname) && + ($env{'course.'.$env{'request.course.id'}.'.domain'} eq $udom)) { + $crsauthor = 1; + } my $currdir = '/priv/'.$udom.'/'.$uname.'/'.$thisdisfn; if ($currdir =~ m-/$-) { $is_const_dir = 1; - if ($thisdisfn eq '') { - unless (($env{'request.course.id'}) && - ($env{'course.'.$env{'request.course.id'}.'.num'} eq $uname) && - ($env{'course.'.$env{'request.course.id'}.'.domain'} eq $udom)) { - $is_const_dir = 2; - } + if (($thisdisfn eq '') && ($crsauthor)) { + $is_const_dir = 2; } + my $esc_currdir = &Apache::loncommon::escape_single($currdir); + $menuitems=(<'.$pic. - ''.$top.' '; + ''.$top.' '.$form; } } return ''; @@ -1902,8 +2074,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; + } } } } @@ -2170,6 +2351,83 @@ 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='◄ '; + } + } + } + return; +} + +function validCourseUser(form,change) { + var possuname = form.elements['vuname'].value; + var possuid = form.elements['vid'].value; + var possudom = form.elements['vudom'].options[form.elements['vudom'].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; +} + +END +} + sub utilityfunctions { my ($httphost) = @_; my $currenturl=&Apache::lonnet::clutter(&Apache::lonnet::fixversion((split(/\?/,$env{'request.noversionuri'}))[0])); @@ -2207,13 +2465,35 @@ 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 $viewuser; + if (($env{'request.course.id'}) && + ($env{'request.symb'} ne '') && + ($env{'request.filename'}=~/$LONCAPA::assess_re/)) { + my $canview; + foreach my $priv ('msg','vgr') { + $canview = &Apache::lonnet::allowed($priv,$env{'request.course.id'}); + if (!$canview && $env{'request.course.sec'} ne '') { + $canview = + &Apache::lonnet::allowed($priv,"$env{'request.course.id'}/$env{'request.course.sec'}"); + } + last if ($canview); + } + if ($canview) { + $viewuser = &view_as_js($esc_url,$esc_symb); + } + } + + 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) { @@ -2277,6 +2557,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; @@ -2316,7 +2612,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; @@ -2406,6 +2703,8 @@ function open_aboutLC() { $countdown +$viewuser + ENDUTILITY } @@ -2414,6 +2713,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(< @@ -2425,10 +2727,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(< @@ -2443,6 +2752,11 @@ sub constspaceform { +
    + + + +
    ENDCONSTSPACEFORM } @@ -2458,7 +2772,7 @@ 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); @@ -2564,10 +2878,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". @@ -2630,7 +2949,7 @@ sub roles_selector { } } if (@submenu > 0) { - $switcher = &create_submenu('','',&mt('Switch role'),\@submenu,'','',$ltitarget); + $switcher = &create_submenu('#',$target,&mt('Switch role'),\@submenu); } } return ($js,$form,$switcher,$has_opa_priv); @@ -2800,7 +3119,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.', @@ -2811,6 +3131,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". @@ -2833,6 +3154,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}))) { @@ -2854,8 +3177,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"; @@ -2878,8 +3215,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 {