--- loncom/interface/lonprintout.pm 2011/11/07 20:05:56 1.609
+++ loncom/interface/lonprintout.pm 2012/04/10 09:49:36 1.615
@@ -1,8 +1,7 @@
-
# The LearningOnline Network
# Printout
#
-# $Id: lonprintout.pm,v 1.609 2011/11/07 20:05:56 www Exp $
+# $Id: lonprintout.pm,v 1.615 2012/04/10 09:49:36 foxr Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -28,6 +27,7 @@
#
package Apache::lonprintout;
use strict;
+use POSIX;
use Apache::Constants qw(:common :http);
use Apache::lonxml;
use Apache::lonnet;
@@ -41,6 +41,7 @@ use Apache::admannotations;
use Apache::lonenc;
use Apache::entities;
use Apache::londefdef;
+# use Apache::structurelags; # for language management.
use File::Basename;
@@ -302,7 +303,6 @@ CHOOSE_RESOURCES
CHOOSE_RESOURCES
-
return $result;
}
#
@@ -435,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.
@@ -519,6 +559,7 @@ sub master_seq_to_person_seq {
# Only process resources..that are not removed by randomout...
# and are selected for printint as well.
#
+
if (! exists $nonResourceItems{$curres} && ! $curres->randomout()) {
my $symb = $curres->symb();
if (exists $seq_hash{$symb}) {
@@ -660,7 +701,29 @@ sub include_pdf {
}
-
+##
+# Collect the various \select_language{language_name}
+# latex tags to build a \usepackage[lang-list]{babel} which will
+# appear just prior to the \begin{document} at the front of the concatenated
+# set of resources:
+# @param doc - The string of latex to search/replace.
+# @return string
+# @retval - the modified document stringt.
+#
+sub collect_languages {
+ my $doc = shift;
+ my %languages;
+ while ($doc =~ /\\selectlanguage{(\w+)}/mg) {
+ $languages{$1} = 1; # allows us to request each language exactly once.
+ }
+ my @lang_list = (keys(%languages)); # List of unique languages
+ if (scalar @lang_list) {
+ my $babel_header = '\usepackage[' . join(',', @lang_list) .']{babel}'. "\n";
+ $doc =~ s/\\begin{document}/$babel_header\\begin{document}/;
+ }
+ return $doc;
+}
+#-------------------------------------------------------------------
#
# ssi_with_retries- Does the server side include of a resource.
@@ -2052,7 +2115,7 @@ sub recently_generated {
# A reference to a page break hash.
#
#
-use Data::Dumper;
+# use Data::Dumper;
# sub dump_helper_vars {
# my ($helper) = @_;
# my $helpervars = Dumper($helper->{'VARS'});
@@ -2878,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];
@@ -2993,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);
@@ -3122,6 +3185,11 @@ ENDPART
$result = set_font_size($result);
+ # Insert any babel headers required.
+
+ $result = &collect_languages($result);
+
+
#-- writing .tex file in prtspool
my $temp_file;
my $identifier = &Apache::loncommon::get_cgi_id();
@@ -3261,7 +3329,7 @@ sub print_resources {
$print_incomplete = 1;
}
if ($person eq 'anonymous') {
- $namepostfix .="Name: ";
+ $namepostfix .=&mt('Name:')." ";
$fullname = "CODE - ".$moreenv->{'CODE'};
}
@@ -3448,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();
@@ -3477,7 +3580,7 @@ sub handler {
&output_data($r,$helper,\%parmhash);
return OK;
-}
+}
use Apache::lonhelper;
@@ -3522,12 +3625,7 @@ sub get_randomly_ordered_warning {
my $func =
sub { return ($_[0]->is_map() && $_[0]->randomorder); };
my @matches = $navmap->retrieveResources($res, $func,1,1,1);
- if (@matches) {
- $message = "Some of the items below are in folders set to be randomly ordered. However, when printing the contents of these folders, they will be printed in the original order for all students, not the randomized order.";
- }
- }
- if ($message) {
- return '
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(); @@ -4906,7 +5014,5 @@ sub postprocess { } } - - __END__