--- loncom/interface/lonmenu.pm 2022/10/27 20:33:31 1.528 +++ loncom/interface/lonmenu.pm 2023/09/28 15:56:48 1.538 @@ -1,7 +1,7 @@ # The LearningOnline Network with CAPA # Routines to control the menu # -# $Id: lonmenu.pm,v 1.528 2022/10/27 20:33:31 raeburn Exp $ +# $Id: lonmenu.pm,v 1.538 2023/09/28 15:56:48 raeburn Exp $ # # Copyright Michigan State University Board of Trustees # @@ -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(); @@ -943,13 +942,14 @@ sub innerregister { } 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,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,1); } @@ -961,13 +961,25 @@ sub innerregister { &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,1); + return $trail; } unless ($env{'request.state'} eq 'construct') { &Apache::lonhtmlcommon::clear_breadcrumbs(); @@ -1061,11 +1073,78 @@ 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','','','vuidentifier'); + my $selscript=&Apache::loncommon::studentbrowser_javascript(); + my $shownsymb = &HTML::Entities::encode(&Apache::lonenc::check_encrypt($env{'request.symb'}),'<>&"'); + my $input = &mt('[_1]Username:[_2] or [_3]ID:[_4] | ', + '', + ''). + ''. + '', + ''; + 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 @@ -1074,16 +1153,25 @@ 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 ''; @@ -2254,6 +2353,108 @@ 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 possudom = form.elements['vudom'].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