--- loncom/interface/lonmenu.pm 2017/09/10 00:11:27 1.479 +++ loncom/interface/lonmenu.pm 2017/09/29 19:18:10 1.480 @@ -1,7 +1,7 @@ # The LearningOnline Network with CAPA # Routines to control the menu # -# $Id: lonmenu.pm,v 1.479 2017/09/10 00:11:27 raeburn Exp $ +# $Id: lonmenu.pm,v 1.480 2017/09/29 19:18:10 raeburn Exp $ # # Copyright Michigan State University Board of Trustees # @@ -1114,8 +1114,9 @@ sub prepare_functions { } my $editbutton = ''; + my $viewsrcbutton = ''; # -# Determine whether or not to display 'Edit' icon/button +# Determine whether or not to display 'Edit' or 'View Source' icon/button # if ($resurl =~ m{^/?adm/($match_domain)/($match_username)/aboutme$}) { my $file=&Apache::lonnet::declutter($env{'request.filename'}); @@ -1199,6 +1200,26 @@ sub prepare_functions { $forceedit,$forceview,$forcereg, $hostname); } + if ((($cfile eq '') || (!$editbutton)) && + ($resurl =~ /$LONCAPA::assess_re/)) { + my $showurl = &Apache::lonnet::clutter($resurl); + if ((&Apache::lonnet::allowed('cre','/')) && + (&Apache::lonnet::metadata($resurl,'sourceavail') eq 'open')) { + $viewsrcbutton = 1; + } elsif (&Apache::lonnet::allowed('vxc',$env{'request.course.id'})) { + if ($showurl =~ m{^\Q/res/$cdom/\E($match_username)/}) { + my $auname = $1; + if (($env{'request.course.adhocsrcaccess'} ne '') && + (grep(/^\Q$auname\E$/,split(/,/,$env{'request.course.adhocsrcaccess'})))) { + $viewsrcbutton = 1; + } + } + } + if ($viewsrcbutton) { + &switch('','',6,1,'pcstr.png','View Source','resource[_2]','open_source()', + 'View source code'); + } + } } } } @@ -1276,7 +1297,7 @@ sub prepare_functions { &advtools_crumbs(@inlineremote); return $editbutton; } elsif ($env{'request.registered'}) { - return $editbutton; + return $editbutton || $viewsrcbutton; } else { if (ref($bread_crumbs) eq 'ARRAY') { if (@inlineremote > 0) { @@ -2083,6 +2104,12 @@ function open_StoredLinks_Import(rat) { newWin.focus(); } +function open_source() { + var url = escape(window.location.pathname); + sourcewin=window.open('/adm/source?inhibitmenu=yes&viewonly=1&filename='+url,'LONsource', + 'height=500,width=600,resizable=yes,location=no,menubar=no,toolbar=no,scrollbars=yes'); +} + (function (\$) { \$(document).ready(function () { \$.single=function(a){return function(b){a[0]=b;return a}}(\$([1]));