--- loncom/interface/lonmenu.pm 2017/09/15 23:19:00 1.369.2.71.4.3 +++ loncom/interface/lonmenu.pm 2017/10/14 22:37:15 1.369.2.71.4.4 @@ -1,7 +1,7 @@ # The LearningOnline Network with CAPA # Routines to control the menu # -# $Id: lonmenu.pm,v 1.369.2.71.4.3 2017/09/15 23:19:00 raeburn Exp $ +# $Id: lonmenu.pm,v 1.369.2.71.4.4 2017/10/14 22:37:15 raeburn Exp $ # # Copyright Michigan State University Board of Trustees # @@ -1484,8 +1484,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'}); @@ -1568,6 +1569,29 @@ sub prepare_functions { $editbutton = &get_editbutton($cfile,$home,$switchserver, $forceedit,$forceview,$forcereg); } + 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; + } elsif ((&Apache::lonnet::metadata($resurl,'sourceavail') eq 'open') && + (&Apache::lonnet::allowed('bre','/'))) { + $viewsrcbutton = 1; + } + } + } + if ($viewsrcbutton) { + &switch('','',6,1,'pcstr.png','View Source','resource[_2]','open_source()', + 'View source code'); + } + } } } } @@ -1641,7 +1665,7 @@ sub prepare_functions { &advtools_crumbs(@inlineremote); return $editbutton; } elsif (($env{'request.registered'}) && (!ref($forbodytag))) { - return $editbutton; + return $editbutton || $viewsrcbutton; } else { if (ref($bread_crumbs) eq 'ARRAY') { if (@inlineremote > 0) { @@ -2519,6 +2543,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]));