--- loncom/interface/lonprintout.pm 2010/07/13 00:16:28 1.582
+++ loncom/interface/lonprintout.pm 2011/09/15 16:33:57 1.583.2.5
@@ -2,7 +2,7 @@
# The LearningOnline Network
# Printout
#
-# $Id: lonprintout.pm,v 1.582 2010/07/13 00:16:28 raeburn Exp $
+# $Id: lonprintout.pm,v 1.583.2.5 2011/09/15 16:33:57 raeburn Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -256,6 +256,46 @@ CHOOSE_ANON1
return $result;
}
+# Returns the XML for choosing how assignments are to be formatted
+# that text must still be parsed by the helper xml parser.
+# Parameters: 3 (required)
+
+# helper - The helper; $helper->{'VARS'}->{'PRINT_TYPE'} used
+# to check if splitting PDFs by section can be offered.
+# title - Title for the current state.
+# this_state - State name of the chooser.
+
+sub generate_format_selector {
+ my ($helper,$title,$this_state) = @_;
+ my $secpdfoption;
+ unless (($helper->{'VARS'}->{'PRINT_TYPE'} eq 'problems_for_anon') ||
+ ($helper->{'VARS'}->{'PRINT_TYPE'} eq 'problems_for_anon_page') ||
+ ($helper->{'VARS'}->{'PRINT_TYPE'} eq 'resources_for_anon') ) {
+ $secpdfoption = 'Each PDF contains exactly one section';
+ }
+ return <
+ How should the results be printed?
+
+ Start each student\'s assignment on a new page/column (add a pagefeed after each assignment)
+ Add one empty page/column after each student\'s assignment
+ Add two empty pages/column after each student\'s assignment
+ Add three empty pages/column after each student\'s assignment
+
+ PAGESIZE
+ How do you want assignments split into PDF files?
+
+ All assignments in a single PDF file
+ $secpdfoption
+ Each PDF contains exactly one assignment
+
+ Specify the number of assignments per PDF:
+
+
+RESOURCE_SELECTOR
+}
+
+
#-----------------------------------------------------------------------
@@ -511,12 +551,12 @@ sub printf_style_subst {
# %s - The section if it is supplied.
#
sub format_page_header {
- my ($width, $format, $assignment, $course, $student, $section) = @_;
+ my ($width, $format, $assignment, $course, $student) = @_;
$width = &recalcto_mm($width); # Get width in mm.
- my $chars_per_line = int($width/1.6); # Character/textline.
+ my $chars_per_line = int($width/2); # Character/textline.
# Default format?
@@ -532,58 +572,37 @@ sub format_page_header {
# - Allow the assignment to be 2 lines (wrapped).
#
-
-
- my $name_length = int($chars_per_line *3 /4);
- my $sec_length = int($chars_per_line / 5);
-
- $format = "%$name_length".'n';
+ my $firstline = "$student $course";
+ if (length($firstline) > $chars_per_line) {
+ my $lastchar = $chars_per_line - length($student) - 1;
+ if ($lastchar > 0) {
+ $course = substr($course, 0, $lastchar);
+ } else { # Nothing left of course:
+ $course = '';
+ }
+ }
+ if (length($assignment) > $chars_per_line) {
+ $assignment = substr($assignment, 0, $chars_per_line);
+ }
- if ($section) {
- $format .= ' - Sec: '."%$sec_length".'s';
- }
+ $format = "\\textbf{$student} $course \\hfill \\thepage \\\\ \\textit{$assignment}";
- $format .= '\\\\%c \\\\ %a';
-
+ } else {
+ # An open question is how to handle long user formatted page headers...
+ # A possible future is to support e.g. %na so that the user can control
+ # the truncation of the elements that can appear in the header.
+ #
+ $format = &printf_style_subst("a", $format, $assignment);
+ $format = &printf_style_subst("c", $format, $course);
+ $format = &printf_style_subst("n", $format, $student);
+
+ # If the user put %'s in the format string, they must be escaped
+ # to \% else LaTeX will think they are comments and terminate
+ # the line.. which is bad!!!
}
- # An open question is how to handle long user formatted page headers...
- # A possible future is to support e.g. %na so that the user can control
- # the truncation of the elements that can appear in the header.
- #
- $format = &printf_style_subst("a", $format, $assignment);
- $format = &printf_style_subst("c", $format, $course);
- $format = &printf_style_subst("n", $format, $student);
- $format = &printf_style_subst("s", $format, $section);
-
- # If the user put %'s in the format string, they must be escaped
- # to \% else LaTeX will think they are comments and terminate
- # the line.. which is bad!!!
-
- # If the user has role author, $course and $assignment are empty so
- # there is '\\ \\ ' in the page header. That's cause a error in LaTeX
- if($format =~ /\\\\\s\\\\\s/) {
- #TODO find sensible caption for page header
- my $testPrintout = '\\\\'.&mt('Construction Space').' \\\\'.&mt('Test-Printout ');
- $format =~ s/\\\\\s\\\\\s/$testPrintout/;
- }
- #
- # We're going to trust LaTeX to break lines appropriately, but
- # we'll truncate anything that's more than 3 lines worth of
- # text. This is also assuming (which will probably end badly)
- # nobody's going to embed LaTeX control sequences in the title
- # header or rather that those control sequences won't get broken
- # by the stuff below.
- #
- my $total_length = 3*$chars_per_line;
- if (length($format) > $total_length) {
- $format = substr($format, 0, $total_length);
- }
-
-
return $format;
-
}
#
@@ -1279,8 +1298,6 @@ sub get_course {
my $courseidinfo;
if (defined($env{'request.course.id'})) {
$courseidinfo = &Apache::lonxml::latex_special_symbols(&unescape($env{'course.'.$env{'request.course.id'}.'.description'}),'header');
- my $sec = $env{'request.course.sec'};
-
}
return $courseidinfo;
}
@@ -1303,6 +1320,7 @@ sub page_format_transformation {
my $name = &get_name();
my $courseidinfo = &get_course();
+ if (defined($courseidinfo)) { $courseidinfo=' - '.$courseidinfo }
my $header_text = $parmhash{'print_header_format'};
$header_text = &format_page_header($textwidth, $header_text, $assignment,
$courseidinfo, $name);
@@ -1603,7 +1621,7 @@ sub print_page_in_course {
$form{'grade_target'} = 'tex';
$form{'textwidth'} = &get_textwidth($helper, $LaTeXwidth);
- $form{'pdfFormFields'} = $pdfFormFields; #
+ $form{'pdfFormFields'} = 'no';
$form{'showallfoils'} = $helper->{'VARS'}->{'showallfoils'};
$form{'problem_split'}=$parmhash{'problem_stream_switch'};
@@ -1707,8 +1725,8 @@ sub print_page_in_course {
# List of recently generated print files
#
sub recently_generated {
- my $r=shift;
- my $prtspool=$r->dir_config('lonPrtDir');
+ my ($prtspool) = @_;
+ my $output;
my $zip_result;
my $pdf_result;
opendir(DIR,$prtspool);
@@ -1741,10 +1759,10 @@ sub recently_generated {
if ($ext eq 'zip') { $zip_result .= $result; }
}
if ($zip_result || $pdf_result) {
- $r->print('');
+ $output ='';
}
if ($zip_result) {
- $r->print('