--- loncom/interface/lonmenu.pm 2023/09/02 15:56:34 1.369.2.83.2.9 +++ loncom/interface/lonmenu.pm 2024/02/28 19:08:32 1.369.2.83.2.18 @@ -1,7 +1,7 @@ # The LearningOnline Network with CAPA # Routines to control the menu # -# $Id: lonmenu.pm,v 1.369.2.83.2.9 2023/09/02 15:56:34 raeburn Exp $ +# $Id: lonmenu.pm,v 1.369.2.83.2.18 2024/02/28 19:08:32 raeburn Exp $ # # Copyright Michigan State University Board of Trustees # @@ -266,7 +266,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,$links_target) = @_; + my ($crstype,$ltimenu,$menucoll,$menuref,$links_disabled,$links_target,$collapsible) = @_; my (%menu,%ltiexc,%menuopts); # each element of @primary contains following array: # (link url, icon path, alt text, link text, condition, position) @@ -370,6 +370,19 @@ sub primary_menu { ($item->[2] eq 'blog')) && (!&Apache::lonnet::usertools_access('','',$item->[2], undef,'tools'))); + if (($item->[2] eq 'browsepub') && ($item->[0] eq '/res/')) { + if ($env{'request.role'} =~ /^au\./) { + $item->[0] .= $env{'request.role.domain'}.'/?launch=1'; + } elsif ($env{'request.role'} =~ m{^ca\./($match_domain)/($match_username)$}) { + $item->[0] .= $1.'/'.$2.'/?launch=1'; + } elsif (&Apache::lonnet::allowed('bre',$env{'user.domain'})) { + $item->[0] .= $env{'user.domain'}.'/?launch=1'; + } elsif (&Apache::lonnet::allowed('bro','/res/')) { + $item->[0] .= '?launch=1'; + } else { + next; + } + } if ($env{'request.course.id'} && $menucoll) { next if ($item->[3]) && (!$menuopts{$item->[3]}); } @@ -424,6 +437,10 @@ sub primary_menu { } my @output = ('',''); if ($menu{'left'} ne '') { + if ($collapsible) { + $menu{'left'} = ($listclass?'
  • ':'
  • '). + ' 
  • '.$menu{'left'}; + } $output[0] = "
      $menu{'left'}
    "; } if ($menu{'right'} ne '') { @@ -1009,6 +1026,18 @@ sub innerregister { $$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') { &Apache::lonhtmlcommon::clear_breadcrumbs(); @@ -1117,6 +1146,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 @@ -1148,8 +1273,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 .= (<'.$pic. - ''.$top.' '; + ''.$top.' '.$form; } } return ''; @@ -2652,6 +2786,114 @@ 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