[LON-CAPA-cvs] cvs: loncom /interface loncommon.pm

raeburn raeburn at source.lon-capa.org
Wed Apr 4 19:06:52 EDT 2012


raeburn		Wed Apr  4 23:06:52 2012 EDT

  Modified files:              
    /loncom/interface	loncommon.pm 
  Log:
  - Bug 3462.
    Add css which causes the body to be blank when media="print",
    if printout generation unavailable for current resource in course.
    Occurs when (a) printstartdate is in the future, or
    (b) printenddate is in the past, or (c) there is an active exam  
    block with "printout" blocked. pav, pfo or evb privs override.
  
  
Index: loncom/interface/loncommon.pm
diff -u loncom/interface/loncommon.pm:1.1063 loncom/interface/loncommon.pm:1.1064
--- loncom/interface/loncommon.pm:1.1063	Wed Apr  4 21:04:55 2012
+++ loncom/interface/loncommon.pm	Wed Apr  4 23:06:52 2012
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # a pile of common routines
 #
-# $Id: loncommon.pm,v 1.1063 2012/04/04 21:04:55 raeburn Exp $
+# $Id: loncommon.pm,v 1.1064 2012/04/04 23:06:52 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -6916,6 +6916,8 @@
 	'<head>'.
 	&font_settings();
 
+    my $inhibitprint = &print_suppression();
+
     if (!$args->{'frameset'}) {
 	$result .= &Apache::lonhtmlcommon::htmlareaheaders();
     }
@@ -6961,6 +6963,7 @@
     if (!$args->{'no_auto_mt_title'}) { $title = &mt($title); }
     $result .= '<title> LON-CAPA '.$title.'</title>'
 	.'<link rel="stylesheet" type="text/css" href="'.$url.'" />'
+        .$inhibitprint
 	.$head_extra;
     return $result.'</head>';
 }
@@ -6986,6 +6989,82 @@
 
 =pod
 
+=item * &print_suppression()
+
+In course context returns css which causes the body to be blank when media="print",
+if printout generation is unavailable for the current resource.
+
+This could be because:
+
+(a) printstartdate is in the future
+
+(b) printenddate is in the past
+
+(c) there is an active exam block with "printout"
+functionality blocked
+
+Users with pav, pfo or evb privileges are exempt.
+
+Inputs: none
+
+=cut
+
+
+sub print_suppression {
+    my $noprint;
+    if ($env{'request.course.id'}) {
+        my $scope = $env{'request.course.id'};
+        if ((&Apache::lonnet::allowed('pav',$scope)) ||
+            (&Apache::lonnet::allowed('pfo',$scope))) {
+            return;
+        }
+        if ($env{'request.course.sec'} ne '') {
+            $scope .= "/$env{'request.course.sec'}";
+            if ((&Apache::lonnet::allowed('pav',$scope)) ||
+                (&Apache::lonnet::allowed('pfo',$scope))) {
+                return; 
+            }
+        }
+        my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
+        my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
+        my $blocked = &blocking_status('printout',$cnum,$cdom); 
+        if ($blocked) {
+            my $checkrole = "cm./$cdom/$cnum";
+            if ($env{'request.course.sec'} ne '') {
+                $checkrole .= "/$env{'request.course.sec'}";
+            }
+            unless ((&Apache::lonnet::allowed('evb',undef,undef,$checkrole)) &&
+                    ($env{'request.role'} !~ m{^st\./$cdom/$cnum})) {
+                $noprint = 1;
+            }
+        }
+        unless ($noprint) {
+            my $symb = &Apache::lonnet::symbread();
+            if ($symb ne '') {
+                my $navmap = Apache::lonnavmaps::navmap->new();
+                if (ref($navmap)) {
+                    my $res = $navmap->getBySymb($symb);
+                    if (ref($res)) {
+                        if (!$res->resprintable()) {
+                            $noprint = 1;
+                        }
+                    }
+                }
+            }
+        }
+        if ($noprint) {
+            return <<"ENDSTYLE";
+<style type="text/css" media="print">
+    body { display:none }
+</style>
+ENDSTYLE
+        }
+    }
+    return;
+}
+
+=pod
+
 =item * &xml_begin()
 
 Returns the needed doctype and <html>




More information about the LON-CAPA-cvs mailing list