--- loncom/interface/lonprintout.pm 2011/12/26 13:47:18 1.610.2.1 +++ 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.610.2.1 2011/12/26 13:47:18 foxr 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. @@ -2900,7 +2941,7 @@ ENDPART ($helper->{'VARS'}->{'PRINT_ANNOTATIONS'} eq 'yes')) { $moreenv{'problem_split'}='yes'; } - my %prog_state=&Apache::lonhtmlcommon::Create_PrgWin($r,'Print Status','Class Print Status',$#students+1,'inline','75'); + my %prog_state=&Apache::lonhtmlcommon::Create_PrgWin($r,$#students+1); my $student_counter=-1; my $i = 0; my $last_section = (split(/:/,$students[0]))[2]; @@ -3015,7 +3056,7 @@ ENDPART $number_per_page=$num_todo > 0 ? $num_todo : 1; } my $flag_latex_header_remove = 'NO'; - my %prog_state=&Apache::lonhtmlcommon::Create_PrgWin($r,'Print Status','Class Print Status',$num_todo,'inline','75'); + my %prog_state=&Apache::lonhtmlcommon::Create_PrgWin($r,$num_todo); my $count=0; foreach my $code (sort(@allcodes)) { my $file_num=int($count/$number_per_page); @@ -3288,7 +3329,7 @@ sub print_resources { $print_incomplete = 1; } if ($person eq 'anonymous') { - $namepostfix .="Name: "; + $namepostfix .=&mt('Name:')." "; $fullname = "CODE - ".$moreenv->{'CODE'}; } @@ -3475,9 +3516,44 @@ sub print_resources { } +sub printing_blocked { + my ($r,$blocktext) = @_; + my $title = &mt('Preparing Printout'); + &Apache::lonhtmlcommon::clear_breadcrumbs(); + &Apache::lonhtmlcommon::add_breadcrumb({href=>'/adm/printout', + text=> $title}); + my $breadcrumbs = &Apache::lonhtmlcommon::breadcrumbs($title); + &Apache::loncommon::content_type($r,'text/html'); + &Apache::loncommon::no_cache($r); + $r->send_http_header; + $r->print(&Apache::loncommon::start_page('Preparing Printout'). + $breadcrumbs. + $blocktext. + &Apache::loncommon::end_page()); + return; +} + sub handler { my $r = shift; + + if ($env{'request.course.id'}) { + my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'}; + my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'}; + my ($blocked,$blocktext) = + &Apache::loncommon::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})) { + &printing_blocked($r,$blocktext); + return OK; + } + } + } &init_perm(); @@ -3504,7 +3580,7 @@ sub handler { &output_data($r,$helper,\%parmhash); return OK; -} +} use Apache::lonhelper; @@ -3678,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'}) { @@ -3694,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. @@ -3743,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 @@ -4286,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(); @@ -4928,7 +5014,5 @@ sub postprocess { } } - - __END__