--- rat/lonpage.pm 2017/09/11 12:48:08 1.120.4.2
+++ rat/lonpage.pm 2017/10/14 22:16:59 1.120.4.3
@@ -1,7 +1,7 @@
# The LearningOnline Network with CAPA
# Page Handler
#
-# $Id: lonpage.pm,v 1.120.4.2 2017/09/11 12:48:08 raeburn Exp $
+# $Id: lonpage.pm,v 1.120.4.3 2017/10/14 22:16:59 raeburn Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -42,6 +42,7 @@ use Apache::lonlocal;
use Apache::lonmenu;
use Apache::lonhomework;
use Apache::lonparmset;
+use Apache::lonenc();
use HTML::TokeParser;
use GDBM_File;
use Apache::lonsequence;
@@ -949,23 +950,60 @@ sub get_buttons {
'';
}
}
- if (($env{'request.course.id'}) && (&Apache::lonnet::allowed('mdc',$env{'request.course.id'}))) {
+ if ($env{'request.course.id'}) {
my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
my $file=&Apache::lonnet::declutter($hash->{'src_'.$rid});
- my ($cfile,$home,$switchserver,$forceedit,$forceview) =
- &Apache::lonnet::can_edit_resource($file,$cnum,$cdom,$hash->{'src_'.$rid},$symb);
- if ($cfile ne '') {
- my $jscall = &Apache::lonhtmlcommon::jump_to_editres($cfile,$home,$switchserver,
- $forceedit,1,$symb,undef,
- &escape($env{'form.title'}));
- if ($jscall) {
+ my $editbutton = '';
+ if (&Apache::lonnet::allowed('mdc',$env{'request.course.id'})) {
+ my ($cfile,$home,$switchserver,$forceedit,$forceview) =
+ &Apache::lonnet::can_edit_resource($file,$cnum,$cdom,$hash->{'src_'.$rid},$symb);
+ if ($cfile ne '') {
+ my $jscall = &Apache::lonhtmlcommon::jump_to_editres($cfile,$home,$switchserver,
+ $forceedit,1,$symb,undef,
+ &escape($env{'form.title'}));
+ if ($jscall) {
+ $editbutton = 1;
+ my $icon = 'pcstr.png';
+ my $label = &mt('Edit');
+ my $title = &mt('Edit this resource');
+ my $pic = '';
+ $metainfo .= ' '.$pic.'';
+ }
+ }
+ }
+ if ((!$editbutton) && ($file=~/$LONCAPA::assess_re/)) {
+ my $url = &Apache::lonnet::clutter($file);
+ my $viewsrcbutton;
+ if ((&Apache::lonnet::allowed('cre','/')) &&
+ (&Apache::lonnet::metadata($url,'sourceavail') eq 'open')) {
+ $viewsrcbutton = 1;
+ } elsif (&Apache::lonnet::allowed('vxc',$env{'request.course.id'})) {
+ if ($url =~ m{^\Q/res/$cdom/\E($LONCAPA::match_username)/}) {
+ my $auname = $1;
+ if (($env{'request.course.adhocsrcaccess'} ne '') &&
+ (grep(/^\Q$auname\E$/,split(/,/,$env{'request.course.adhocsrcaccess'})))) {
+ $viewsrcbutton = 1;
+ }
+ }
+ }
+ if ($viewsrcbutton) {
my $icon = 'pcstr.png';
- my $label = &mt('Edit');
- my $title = &mt('Edit this resource');
+ my $label = &mt('View Source');
+ my $title = &mt('View source code');
+ my $jsrid = $rid;
+ $jsrid =~ s/\./_/g;
+ my $showurl = &escape(&Apache::lonenc::check_encrypt($url));
my $pic = '';
- $metainfo .= ' '.$pic.'';
+ $metainfo .= ' '.$pic.''."\n".
+ '\n";
}
}
}