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

foxr foxr at source.lon-capa.org
Tue Apr 10 05:49:37 EDT 2012


foxr		Tue Apr 10 09:49:37 2012 EDT

  Modified files:              
    /loncom/interface	lonprintout.pm 
  Log:
  BZ3462 Inidicate why it's not possible to print the current resource
  
  
Index: loncom/interface/lonprintout.pm
diff -u loncom/interface/lonprintout.pm:1.614 loncom/interface/lonprintout.pm:1.615
--- loncom/interface/lonprintout.pm:1.614	Wed Apr  4 21:04:56 2012
+++ loncom/interface/lonprintout.pm	Tue Apr 10 09:49:36 2012
@@ -1,7 +1,7 @@
 # The LearningOnline Network
 # Printout
 #
-# $Id: lonprintout.pm,v 1.614 2012/04/04 21:04:56 raeburn Exp $
+# $Id: lonprintout.pm,v 1.615 2012/04/10 09:49:36 foxr Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -27,6 +27,7 @@
 #
 package Apache::lonprintout;
 use strict;
+use POSIX;
 use Apache::Constants qw(:common :http);
 use Apache::lonxml;
 use Apache::lonnet;
@@ -434,6 +435,46 @@
 
 #-----------------------------------------------------------------------
 
+##
+# Returns the innermost print start/print end dates for a resource.
+# This is done by looking at the start/end dates for its parts and choosing
+# the intersection of those dates.
+# 
+# @param res - lonnvamaps::resource object that represents the resource.
+#
+# @return (opendate, closedate)
+#
+# @note If open/close dates are not defined they will be retunred as undef
+# @note It is possible for there to be no overlap in which case -1,-1 
+#       will be returned.
+# @note The algorithm used is to take the latest open date and the earliest end date.
+#
+
+sub get_print_dates {
+    my $res = shift;
+    my $partsref = $res->parts();
+    my @parts   = @$partsref;
+    my $open_date;
+    my $close_date;
+
+    if (defined(@parts) && (scalar(@parts) > 0)) {
+	foreach my $part (@parts) {
+	    my $partopen  = $res->parmval('printstartdate', $part);
+	    my $partclose = $res->parmval('printenddate',  $part);
+	    
+	    $open_date  = POSIX::strftime('%D', localtime($partopen));
+	    $close_date = POSIX::strftime('%D', localtime($partclose));
+	    
+	    # TODO: Complete this function and use it to tailor the
+	    #       can't print current resource message.
+	    #
+	    
+	}
+    }
+
+    return ($open_date, $close_date);
+}
+
 # Determine if a resource is incomplete given the map:
 # Parameters:
 #   $username - Name of user for whom we are checking.
@@ -3713,6 +3754,8 @@
     my $is_published=0;		# True when printing from resource space.
     my $res_printable = 1;	# By default the current resource is printable.    
     my $userCanPrint = ($perm{'pav'} || $perm{'pfo'});
+    my $res_printstartdate;
+    my $res_printenddate;
 
     # Get the resource name from construction space
     if ($helper->{VARS}->{'construction'}) {
@@ -3729,7 +3772,8 @@
 		&Apache::lonenc::check_encrypt(&Apache::lonnet::clutter($url));
 	    my $navmap = Apache::lonnavmaps::navmap->new();
 	    my $res   = $navmap->getBySymb($symb);
-	    $res_printable  = $res->resprintable() || $userCanPrint; #printability in course context
+	    $res_printable  = $res->resprintable() | $userCanPrint; #printability in course context
+	    ($res_printstartdate, $res_printenddate) = 	&get_print_dates($res);
 	} else {
 	    # Resource space.
 
@@ -3778,8 +3822,7 @@
 
     if ($resourceTitle && $res_printable) {
         push @{$printChoices}, ["<b><i>$resourceTitle</i></b> (".&mt('the resource you just saw on the screen').")", 'current_document', 'PAGESIZE'];
-    }
-    
+    } 
 
     # Useful filter strings
 
@@ -4321,6 +4364,14 @@
 
     # Generate the first state, to select which resources get printed.
     Apache::lonhelper::state->new("START", "Select Printing Options:");
+    if (!$res_printable) {
+	$paramHash = Apache::lonhelper::getParamHash();
+	$paramHash->{MESSAGE_TEXT} = 
+	    &mt('<p><b>Printing for current resource is only possible between [_1] and [_1]</b></p>',
+	    $res_printstartdate, $res_printenddate);
+	Apache::lonhelper::message->new();
+    }
+    $paramHash = Apache::lonhelper::getParamHash();
     $paramHash = Apache::lonhelper::getParamHash();
     $paramHash->{MESSAGE_TEXT} = "";
     Apache::lonhelper::message->new();




More information about the LON-CAPA-cvs mailing list