[LON-CAPA-cvs] cvs: rat(version_2_11_X) / lonpage.pm

raeburn raeburn at source.lon-capa.org
Tue Sep 4 11:16:12 EDT 2018


raeburn		Tue Sep  4 15:16:12 2018 EDT

  Modified files:              (Branch: version_2_11_X)
    /rat	lonpage.pm 
  Log:
  - For 2.11
    Backport 1.125
  
  
Index: rat/lonpage.pm
diff -u rat/lonpage.pm:1.111.2.5 rat/lonpage.pm:1.111.2.6
--- rat/lonpage.pm:1.111.2.5	Thu Mar  1 13:25:46 2018
+++ rat/lonpage.pm	Tue Sep  4 15:16:12 2018
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # Page Handler
 #
-# $Id: lonpage.pm,v 1.111.2.5 2018/03/01 13:25:46 raeburn Exp $
+# $Id: lonpage.pm,v 1.111.2.6 2018/09/04 15:16:12 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -41,6 +41,7 @@
 use Apache::lonlocal;
 use Apache::lonmenu;
 use Apache::lonhomework;
+use Apache::lonenc();
 use HTML::TokeParser;
 use GDBM_File;
 use Apache::lonsequence;
@@ -849,23 +850,60 @@
 		'</a>';
 	}
     }
-    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 = '<img src="'.&Apache::loncommon::lonhttpdurl('/res/adm/pages/'.$icon).'"'.
+                              ' class="LC_icon" alt="'.$label.'" title="'.$title.'" />';
+                    $metainfo .= ' <a href="javascript:'.$jscall.';">'.$pic.'</a>';
+                }
+            }
+        }
+        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 = '<img src="'.&Apache::loncommon::lonhttpdurl('/res/adm/pages/'.$icon).'"'.
                           ' class="LC_icon" alt="'.$label.'" title="'.$title.'" />';
-                $metainfo .= ' <a href="javascript:'.$jscall.';">'.$pic.'</a>';
+                $metainfo .= ' <a href="javascript:open_source_'.$jsrid.'();">'.$pic.'</a>'."\n".
+                             '<script type="text/javascript">'."\n".
+                             "function open_source_$jsrid() {\n".
+                             "  sourcewin=window.open('/adm/source?inhibitmenu=yes&viewonly=1&filename=$showurl','LONsource',".
+                             "'height=500,width=600,resizable=yes,location=no,menubar=no,toolbar=no,scrollbars=yes');\n".
+                             "}\n".
+                             "</script>\n";
             }
         }
     }




More information about the LON-CAPA-cvs mailing list