--- loncom/interface/lonmenu.pm 2023/09/02 15:56:34 1.369.2.83.2.9 +++ loncom/interface/lonmenu.pm 2023/09/06 16:05:23 1.369.2.83.2.10 @@ -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.10 2023/09/06 16:05:23 raeburn Exp $ # # Copyright Michigan State University Board of Trustees # @@ -1117,6 +1117,71 @@ 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 @@ -1985,7 +2050,7 @@ sub advtools_crumbs { 'advtools', @funcs[61,64,65,66,67,74]); } elsif ($env{'request.noversionuri'} !~ m{^/adm/(navmaps|viewclasslist)(\?|$)}) { &Apache::lonhtmlcommon::add_breadcrumb_tool( - 'advtools', @funcs[61,71,72,73,74,92]); + 'advtools', @funcs[61,71,72,73,74,75,92]); } elsif ($env{'request.noversionuri'} eq '/adm/viewclasslist') { &Apache::lonhtmlcommon::add_breadcrumb_tool( 'advtools', $funcs[61]); @@ -2010,7 +2075,7 @@ sub clear { # The javascript is usually similar to "go('/adm/roles')" or "cstrgo(..)". sub switch { - my ($uname,$udom,$row,$col,$img,$top,$bot,$act,$desc,$cat,$nobreak,$infunc)=@_; + my ($uname,$udom,$row,$col,$img,$top,$bot,$act,$desc,$cat,$nobreak,$infunc,$form)=@_; $act=~s/\$uname/$uname/g; $act=~s/\$udom/$udom/g; $top=&mt($top); @@ -2029,7 +2094,7 @@ sub switch { '" align="'.($nobreak==3?'right':'left').'" class="LC_icon" />'; $inlineremote[$idx] = ''. - $pic.''.$top.' '; + $pic.''.$top.' '.$form; } # Remote $img=~s/\.png$/\.gif/; @@ -2652,6 +2717,79 @@ 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) { + 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 (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])); @@ -2692,6 +2830,24 @@ sub utilityfunctions { my $countdown = &countdown_toggle_js(); + 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'}; @@ -2891,6 +3047,8 @@ function open_aboutLC() { $countdown +$viewuser + ENDUTILITY }