--- loncom/interface/lonprintout.pm 2012/04/04 21:04:56 1.614 +++ loncom/interface/lonprintout.pm 2012/04/10 09:49:36 1.615 @@ -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 @@ RESOURCE_SELECTOR #----------------------------------------------------------------------- +## +# 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 @@ sub printHelper { 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 @@ sub printHelper { &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 @@ sub printHelper { if ($resourceTitle && $res_printable) { push @{$printChoices}, ["$resourceTitle (".&mt('the resource you just saw on the screen').")", 'current_document', 'PAGESIZE']; - } - + } # Useful filter strings @@ -4321,6 +4364,14 @@ CHOOSE_FROM_ANY_SEQUENCE # 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('

Printing for current resource is only possible between [_1] and [_1]

', + $res_printstartdate, $res_printenddate); + Apache::lonhelper::message->new(); + } + $paramHash = Apache::lonhelper::getParamHash(); $paramHash = Apache::lonhelper::getParamHash(); $paramHash->{MESSAGE_TEXT} = ""; Apache::lonhelper::message->new();