--- loncom/interface/lonprintout.pm 2010/11/13 01:57:14 1.568.2.10
+++ loncom/interface/lonprintout.pm 2012/06/11 11:07:33 1.619
@@ -1,8 +1,7 @@
-#
# The LearningOnline Network
# Printout
#
-# $Id: lonprintout.pm,v 1.568.2.10 2010/11/13 01:57:14 raeburn Exp $
+# $Id: lonprintout.pm,v 1.619 2012/06/11 11:07:33 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,17 +41,18 @@ use Apache::admannotations;
use Apache::lonenc;
use Apache::entities;
use Apache::londefdef;
+# use Apache::structurelags; # for language management.
use File::Basename;
use HTTP::Response;
-
use LONCAPA::map();
-use POSIX qw(strftime);
+use POSIX qw(ctime);
use Apache::lonlocal;
use Carp;
use LONCAPA;
+
my %perm;
my %parmhash;
my $resources_printed;
@@ -76,7 +77,197 @@ my $font_size = 'normalsize'; # Default
#---------------------------- Helper helpers. -------------------------
-# Returns the text needd for a student chooser.
+##
+# Filter function to determine if a resource is a printable sequence.
+#
+# @param $res -Resource to check.
+#
+# @return 1 - printable and a resource
+# 0 - either notm a sequence or not printable.
+#
+sub printable_sequence {
+ my $res = shift;
+
+ # Non-sequences are not listed:
+
+ if (!$res->is_sequence()) {
+ return 0;
+ }
+
+ # Person with pav or pfo can always print:
+
+ if ($perm{'pav'} || $perm{'pfo'}) {
+ return 1;
+ }
+
+ if ($res->is_sequence()) {
+ my $symb = $res->symb();
+ my $navmap = $res->{NAV_MAP};
+
+ # Find the first resource in the map:
+
+ my $iterator = $navmap->getIterator($res, undef, undef, 1, 1);
+ my $first = $iterator->next();
+
+ while (1) {
+ if ($first == $iterator->END_ITERATOR) { last; }
+ if (ref($first) && ! $first->is_sequence()) {last; }
+ $first = $iterator->next();
+ }
+
+
+ # Might be an empty map:
+
+ if (!ref($first)) {
+ return 0;
+ }
+ my $partsref = $first->parts();
+ my @parts = @$partsref;
+ my ($open, $close) = $navmap->map_printdates($first, $parts[0]);
+ return &printable($open, $close);
+ }
+ return 0;
+}
+
+# BZ5209:
+# Create the states needed to run the helper for incomplete problems from
+# the current folder for selected students.
+# This includes:
+# - A resource selector limited to problems (incompleteness must be
+# calculated on a student per student basis.
+# - A student selector.
+# - Tie in to the FORMAT of the print job.
+#
+# States:
+# CHOOSE_INCOMPLETE_PEOPLE_SEQ - Resource selection.
+# CHOOSE_STUDENTS_INCOMPLETE - Student selection.
+# CHOOSE_STUDENTS_INCOMPLETE_FORMAT - Format selection
+# Parameters:
+# helper - the helper which already contains info about the current folder we can
+# purloin.
+# url - Top url of the sequence
+# Return:
+# XML that can be parsed by the helper to drive the state machine.
+#
+sub create_incomplete_folder_selstud_helper($helper)
+{
+ my ($helper, $map) = @_;
+
+
+ my $symbFilter = '$res->shown_symb()';
+ my $selFilter = '$res->is_problem()';
+
+
+ my $resource_chooser = &generate_resource_chooser('CHOOSE_INCOMPLETE_PEOPLE_SEQ',
+ 'Select problem(s) to print',
+ 'multichoice="1" toponly="1" addstatus="1" closeallpages="1"',
+ 'RESOURCES',
+ 'CHOOSE_STUDENTS_INCOMPLETE',
+ $map,
+ $selFilter,
+ '',
+ $symbFilter,
+ '');
+
+ my $student_chooser = &generate_student_chooser('CHOOSE_STUDENTS_INCOMPLETE',
+ 'student_sort',
+ 'STUDENTS',
+ 'CHOOSE_STUDENTS_INCOMPLETE_FORMAT');
+
+ my $format_chooser = &generate_format_selector($helper,
+ 'Format of the print job',
+ 'CHOOSE_STUDENTS_INCOMPLETE_FORMAT'); # end state.
+
+ return $resource_chooser . $student_chooser . $format_chooser;
+}
+
+
+# BZ 5209
+# Create the states needed to run the helper for incomplete problems from
+# the current folder for selected students.
+# This includes:
+# - A resource selector limited to problems. (incompleteness must be calculated
+# on a student per student basis.
+# - A student selector.
+# - Tie in to format for the print job.
+# States:
+# INCOMPLETE_PROBLEMS_COURSE_RESOURCES - Resource selector.
+# INCOMPLETE_PROBLEMS_COURSE_STUDENTS - Student selector.
+# INCOMPLETE_PROBLEMS_COURSE_FORMAT - Format selection.
+#
+# Parameters:
+# helper - Helper we are creating states for.
+# Returns:
+# Text that can be parsed by the helper.
+#
+
+sub create_incomplete_course_helper {
+ my $helper = shift;
+
+ my $filter = '$res->is_problem() || $res->contains_problem() || $res->is_sequence() || $res->is_practice())';
+ my $symbfilter = '$res->shown_symb()';
+
+ my $resource_chooser = &generate_resource_chooser('INCOMPLETE_PROBLEMS_COURSE_RESOURCES',
+ 'Select problem(s) to print',
+ 'multichoice = "1" suppressEmptySequences="0" addstatus="1" closeallpagtes="1"',
+ 'RESOURCES',
+ 'INCOMPLETE_PROBLEMS_COURSE_STUDENTS',
+ '',
+ $filter,
+ '',
+ $symbfilter,
+ '');
+
+ my $people_chooser = &generate_student_chooser('INCOMPLETE_PROBLEMS_COURSE_STUDENTS',
+ 'student_sort',
+ 'STUDENTS',
+ 'INCOMPLETE_PROBLEMS_COURSE_FORMAT');
+
+ my $format = &generate_format_selector($helper,
+ 'Format of the print job',
+ 'INCOMPLETE_PROBLEMS_COURSE_FORMAT'); # end state.
+
+ return $resource_chooser . $people_chooser . $format;
+
+
+}
+
+# BZ5209
+# Creates the states needed to run the print helper for a student
+# that wants to print his incomplete problems from the current folder.
+# Parameters:
+# $helper - helper we are generating states for.
+# $map - The map for which the student wants incomplete problems.
+# Returns:
+# XML that defines the helper states being created.
+#
+# States:
+# CHOOSE_INCOMPLETE_SEQ - Resource selector.
+#
+sub create_incomplete_folder_helper {
+ my ($helper, $map) = @_;
+
+ my $filter = '$res->is_problem()';
+ $filter .= ' && $res->resprintable() ';
+ $filter .= ' && $res->is_incomplete() ';
+
+ my $symfilter = '$res->shown_symb()';
+
+ my $resource_chooser = &generate_resource_chooser('CHOOSE_INCOMPLETE_SEQ',
+ 'Select problem(s) to print',
+ 'multichoice="1", toponly ="1", addstatus="1", closeallpages="1"',
+ 'RESOURCES',
+ 'PAGESIZE',
+ $map,
+ $filter, '',
+ $symfilter,
+ '');
+
+ return $resource_chooser;
+}
+
+
+# Returns the text neded for a student chooser.
# that text must still be parsed by the helper xml parser.
# Parameters:
# this_state - State name of the chooser.
@@ -164,7 +355,6 @@ CHOOSE_RESOURCES
CHOOSE_RESOURCES
-
return $result;
}
#
@@ -196,14 +386,19 @@ sub generate_code_selector {
Generate new CODEd Assignments
Number of CODEd assignments to print:
-
+
if (((\$helper->{'VARS'}{'NUMBER_TO_PRINT_TOTAL'}+0) < 1) &&
!\$helper->{'VARS'}{'REUSE_OLD_CODES'} &&
!\$helper->{'VARS'}{'SINGLE_CODE'} &&
- !\$helper->{'VARS'}{'CODE_SELECTED_FROM_LIST'}) {
+ !\$helper->{'VARS'}{'CODE_SELECTED_FROM_LIST'} ) {
+
return "You need to specify the number of assignments to print";
}
+ if (((\$helper->{'VARS'}{'NUMBER_TO_PRINT_TOTAL'}+0) >= 1) &&
+ (\$helper->{'VARS'}{'SINGLE_CODE'} ne '') ) {
+ return 'Specifying number of codes to print and a specific code is not compatible';
+ }
return undef;
@@ -212,7 +407,7 @@ sub generate_code_selector {
- Bubble sheet type:
+ Bubblesheet type:
$bubble_types
@@ -228,6 +423,8 @@ sub generate_code_selector {
!\$helper->{'VARS'}{'CODE_SELECTED_FROM_LIST'}) {
return &Apache::lonprintout::is_code_valid(\$helper->{'VARS'}{'SINGLE_CODE'},
\$helper->{'VARS'}{'CODE_OPTION'});
+ } elsif (\$helper->{'VARS'}{'SINGLE_CODE'} ne ''){
+ return 'Specifying a code name is incompatible with specifying number of codes.';
} else {
return undef; # Other forces control us.
}
@@ -249,8 +446,327 @@ 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
+}
+
#-----------------------------------------------------------------------
+# Computes an open and close date from a list of open/close dates for a resource's
+# parts.
+#
+# @param \@opens - reference to an array of open dates.
+# @param \@closes - reference to an array of close dates.
+#
+# @return ($open, $close)
+#
+# @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 compute_open_window {
+ my ($opensref, $closesref) = @_;
+
+ my @opens = @$opensref;
+ my @closes = @$closesref;
+
+ # latest open date:
+ my $latest_open;
+
+ foreach my $open (@opens) {
+ if (!defined($latest_open) || ($open > $latest_open)) {
+ $latest_open = $open;
+ }
+ }
+ # Earliest close:
+
+ my $earliest_close;
+ foreach my $close (@closes) {
+ if (!defined($earliest_close) || ($close < $earliest_close)) {
+ $earliest_close = $close;
+ }
+ }
+
+ # If no overlap...both are -1 as promised.
+
+ if (defined($earliest_close) && defined($latest_open)
+ && ($earliest_close < $latest_open)) {
+ $latest_open = -1;
+ $earliest_close = -1;
+ }
+
+ return ($latest_open, $earliest_close);
+
+}
+
+##
+# Determines if 'now' is within the set of printable dates.
+#
+# @param $open_date - Starting date/timestamp.
+# @param $close_date - Ending date/timestamp.
+#
+# @return 0 - Not open.
+# @return 1 - open.
+#
+sub printable {
+ my ($open_date, $close_date) = @_;
+
+
+ my $now = time();
+
+ # Have to do a bit of fancy footwork around undefined open/close dates:
+
+ if ($open_date && ($open_date > $now)) {
+ return 0;
+ }
+
+ if ($close_date && ($close_date < $now)) {
+ return 0;
+ }
+
+ return 1;
+
+}
+
+##
+# 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;
+ my @open_dates;
+ my @close_dates;
+
+
+ if (defined(@parts) && (scalar(@parts) > 0)) {
+ foreach my $part (@parts) {
+ my $partopen = $res->parmval('printstartdate', $part);
+ my $partclose = $res->parmval('printenddate', $part);
+
+ push(@open_dates, $partopen);
+ push(@close_dates, $partclose);
+ }
+ }
+
+ ($open_date, $close_date) = &compute_open_window(\@open_dates, \@close_dates);
+
+ if ($open_date) {
+ $open_date = POSIX::strftime('%D', localtime($open_date));
+ }
+ if ($close_date) {
+ $close_date = POSIX::strftime('%D', localtime($close_date));
+ }
+
+ return ($open_date, $close_date);
+}
+
+##
+# Get the dates for which a course says a resource can be printed. This is like
+# get_print_dates but namvaps::course_print_dates are gotten...and not converted
+# to times either.
+#
+# @param $res - Reference to a resource has from lonnvampas::resource.
+#
+# @return (opendate, closedate)
+#
+sub course_print_dates {
+ my $res = shift;
+ my $partsref = $res->parts();
+ my @parts = @$partsref;
+ my $open_date;
+ my $close_date;
+ my @open_dates;
+ my @close_dates;
+ my $navmap = $res->{NAV_MAP}; # Slightly OO dirty.
+
+ # Don't bother looping over undefined or empty parts arraY;
+
+ if (defined(@parts) && (scalar(@parts) > 0)) {
+ foreach my $part (@parts) {
+ my ($partopen, $partclose) = $navmap->course_printdates($res, $part);
+ push(@open_dates, $partopen);
+ push(@close_dates, $partclose);
+ }
+ ($open_date, $close_date) = &compute_open_window(\@open_dates, \@close_dates);
+ }
+ return ($open_date, $close_date);
+}
+##
+# Same as above but for the enclosing map:
+#
+sub map_print_dates {
+ my $res = shift;
+ my $partsref = $res->parts();
+ my @parts = @$partsref;
+ my $open_date;
+ my $close_date;
+ my @open_dates;
+ my @close_dates;
+ my $navmap = $res->{NAV_MAP}; # slightly OO dirty.
+
+
+ # Don't bother looping over undefined or empty parts arraY;
+
+ if (defined(@parts) && (scalar(@parts) > 0)) {
+ foreach my $part (@parts) {
+ my ($partopen, $partclose) = $navmap->map_printdates($res, $part);
+ push(@open_dates, $partopen);
+ push(@close_dates, $partclose);
+ }
+ ($open_date, $close_date) = &compute_open_window(\@open_dates, \@close_dates);
+ }
+ return ($open_date, $close_date);
+}
+
+# Determine if a resource is incomplete given the map:
+# Parameters:
+# $username - Name of user for whom we are checking.
+# $domain - Domain of user we are checking.
+# $map - map name.
+# Returns:
+# 0 - map is not incomplete.
+# 1 - map is incomplete.
+#
+sub incomplete {
+ my ($username, $domain, $map) = @_;
+
+
+ my $navmap = Apache::lonnavmaps::navmap->new($username, $domain);
+
+
+ if (defined($navmap)) {
+ my $res = $navmap->getResourceByUrl($map);
+ my $result = $res->is_incomplete();
+ return $result;
+ } else {
+ return 1;
+ }
+}
+#
+# When printing for students, the resoures and order of the
+# resources may need to be altered if there are folders with
+# random selectiopn or random ordering (or both) enabled.
+# This sub computes the set of resources to print for a student
+# modified both by random ordering and selection and filtered
+# to only those that are in the original set selcted to be printed.
+#
+# Parameters:
+# $helper - The helper we need $helper->{'VARS'}->{'symb'}
+# to construct the navmap and the iteration.
+# $seq - The original set of resources to print
+# (really an array of resource names (array of symb's).
+# $who - Student/domain for whome the sequence will be generated.
+#
+# Implicit inputs:
+# $
+# Returns:
+# reference to an array of resources that can be passed to
+# print_resources.
+#
+sub master_seq_to_person_seq {
+ my ($helper, $seq, $who) = @_;
+
+
+ my ($username, $userdomain, $usersection) = split(/:/, $who);
+
+
+ # Toss the sequence up into a hash so that we have O(1) lookup time.
+ # on the items that come out of the user's list of resources.
+ #
+
+ my %seq_hash = map {$_ => 1} @$seq;
+ my @output_seq;
+
+ my ($map, $id, $url) = &Apache::lonnet::decode_symb($helper->{VARS}->{'symb'});
+ my $navmap = Apache::lonnavmaps::navmap->new($username, $userdomain);
+ my $iterator = $navmap->getIterator($navmap->firstResource(),
+ $navmap->finishResource(),
+ {}, 1);
+ my %nonResourceItems = (
+ $iterator->BEGIN_MAP => 1,
+ $iterator->BEGIN_BRANCH => 1,
+ $iterator->END_BRANCH => 1,
+ $iterator->END_MAP => 1,
+ $iterator->FORWARD => 1,
+ $iterator->BACKWARD => 1
+
+ ); # These items are not resources but appear in the midst of iteration.
+
+ # Iterate on the resource..select the items that are randomly selected
+ # and that are in the seq_has. Presumably the iterator will take care
+ # of the random ordering part of the deal.
+ #
+ my $curres;
+ while ($curres = $iterator->next()) {
+ #
+ # 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}) {
+ push(@output_seq, $symb);
+ }
+ }
+ }
+
+
+ return \@output_seq; # for now.
+
+}
+
# Fetch the contents of a resource, uninterpreted.
# This is used here to fetch a latex file to be included
@@ -312,10 +828,12 @@ sub set_font_size {
if ($font_size ne '') {
- $text =~ s/\\begin{document}/\\begin{document}{\\$font_size/;
+ $text =~ s/\\begin{document}/\\begin{document}{\\$font_size/;
}
$text =~ s/\\end{document}/}\\end{document}/;
return $text;
+
+
}
# include_pdf - PDF files are included into the
@@ -351,9 +869,10 @@ sub include_pdf {
# (unlikely). If it did exist, add the pdf to the set of files/images that
# need tob e converted for this print job:
- $file =~ s|(.*)/res/|/home/httpd/html/res/|;
+ my $londocroot = $Apache::lonnet::perlvar{'lonDocRoot'};
+ $file =~ s{(.*)/res/}{$londocroot/res/};
- open(FILE,">>/home/httpd/prtspool/$env{'user.name'}_$env{'user.domain'}_printout.dat");
+ open(FILE,">>$Apache::lonnet::perlvar{'lonPrtDir'}/$env{'user.name'}_$env{'user.domain'}_printout.dat");
print FILE ("$file\n");
close (FILE);
@@ -376,7 +895,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.
@@ -423,7 +964,6 @@ sub ssi_with_retries {
$ssi_last_error_resource = $resource;
$ssi_last_error = $response->code . " " . $response->message;
$content='\section*{!!! An error occurred !!!}';
- &Apache::lonnet::logthis("Error in SSI resource: $resource Error: $ssi_last_error");
}
return $content;
@@ -439,7 +979,6 @@ sub get_student_view_with_retries {
$ssi_last_error_resource = $curresline.' for user '.$username.':'.$userdomain;
$ssi_last_error = $response->code . " " . $response->message;
$content='\section*{!!! An error occurred !!!}';
- &Apache::lonnet::logthis("Error in SSI (student view) resource: $curresline Error: $ssi_last_error User: $username:$userdomain");
}
return $content;
@@ -499,12 +1038,15 @@ sub printf_style_subst {
# %a - Assignment name.
# %c - Course name.
# %n - Student name.
+# %s - The section if it is supplied.
#
sub format_page_header {
- my ($width, $format, $assignment, $course, $student) = @_;
+ my ($width, $format, $assignment, $course, $student, $section) = @_;
+
+
$width = &recalcto_mm($width); # Get width in mm.
- my $chars_per_line = int($width/2); # Character/textline.
+ my $chars_per_line = int($width/1.6); # Character/textline.
# Default format?
@@ -520,36 +1062,58 @@ sub format_page_header {
# - Allow the assignment to be 2 lines (wrapped).
#
- 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);
- }
+
- $format = "\\textbf{$student} $course \\hfill \\thepage \\\\ \\textit{$assignment}";
+ my $name_length = int($chars_per_line *3 /4);
+ my $sec_length = int($chars_per_line / 5);
+
+ $format = "%$name_length".'n';
+
+ if ($section) {
+ $format .= ' - Sec: '."%$sec_length".'s';
+ }
+
+ $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;
+
}
#
@@ -669,6 +1233,22 @@ sub is_code_valid {
}
}
+#
+# Compare two students by section (Used to sort by section).
+#
+# Implicit inputs,
+# $a - The first one
+# $b - The second one.
+#
+# Returns:
+# a-section cmp b-section
+#
+sub compare_sections {
+ my ($u1, $d1, $s1, $n1, $stat1) = split(/:/, $a);
+ my ($u2, $d2, $s2, $n2, $stat2) = split(/:/, $b);
+
+ return $s1 cmp $s2;
+}
# Compare two students by name. The students are in the form
# returned by the helper:
@@ -1245,6 +1825,8 @@ 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;
}
@@ -1267,7 +1849,6 @@ 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);
@@ -1288,13 +1869,13 @@ sub page_format_transformation {
$text =~ s/\\pagestyle{fancy}\\rhead{}\\chead{}\s*\\begin{document}/\\textheight = $textheight\\oddsidemargin = $evenoffset\n\\evensidemargin = $evenoffset $topmargintoinsert\\textwidth= $textwidth\\newlength{\\minipagewidth}\n\\setlength{\\minipagewidth}{\\textwidth\/\$number_of_columns-0\.2cm}\\renewcommand{\\ref}{\\keephidden\}\\pagestyle{fancy}\\rhead{}\\chead{}\\usepackage{booktabs}\\begin{document}\\voffset=-0\.8cm\n\\setcounter{page}{1} \\vskip 5 mm\n /;
}
if ($papersize eq 'a4') {
- my $papersize_text;
- if ($perm{'pav'}) {
- $papersize_text = '\\special{papersize=210mm,297mm}';
- } else {
- $papersize_text = '\special{papersize=210mm,297mm}';
- }
- $text =~ s/(\\begin{document})/$1$papersize_text/;
+ my $papersize_text;
+ if ($perm{'pav'}) {
+ $papersize_text = '\\special{papersize=210mm,297mm}';
+ } else {
+ $papersize_text = '\special{papersize=210mm,297mm}';
+ }
+ $text =~ s/(\\begin{document})/$1$papersize_text/;
}
}
if ($tableofcontents eq 'yes') {$text=~s/(\\setcounter\{page\}\{1\})/$1 \\tableofcontents\\newpage /;}
@@ -1501,6 +2082,7 @@ sub map_laystyle {
sub print_page_in_course {
my ($helper, $rparmhash, $currentURL, $resources) = @_;
+
my %parmhash = %$rparmhash;
my @page_resources = @$resources;
my $mode = $helper->{'VARS'}->{'LATEX_TYPE'};
@@ -1527,7 +2109,7 @@ sub print_page_in_course {
} else {
my $esc_currentURL= $currentURL;
$esc_currentURL =~ s/_/\\_/g;
- $result.=$esc_currentURL;
+ $result.=$esc_currentURL;
}
$result .= '\\\\';
@@ -1557,8 +2139,10 @@ sub print_page_in_course {
}
# these resources go through the XML transformer:
- elsif ($resource_src =~ /\.(problem|exam|quiz|assess|survey|form|library|xml|html|htm|xhtml|xhtm)$/) {
+ elsif ($resource_src =~ /\.(problem|exam|quiz|assess|survey|form|library|xml|html|htm|xhtml|xhtm)$/) {
+
my $urlp = &Apache::lonnet::clutter($resource_src);
+
my %form;
my %moreenv;
@@ -1568,7 +2152,7 @@ sub print_page_in_course {
$form{'grade_target'} = 'tex';
$form{'textwidth'} = &get_textwidth($helper, $LaTeXwidth);
- $form{'pdfFormFields'} = 'no';
+ $form{'pdfFormFields'} = $pdfFormFields; #
$form{'showallfoils'} = $helper->{'VARS'}->{'showallfoils'};
$form{'problem_split'}=$parmhash{'problem_stream_switch'};
@@ -1620,10 +2204,9 @@ sub print_page_in_course {
$texversion.='\vskip 0 mm \noindent\textbf{'.$title.'}\vskip 0 mm ';
$texversion.=&path_to_problem($urlp,$LaTeXwidth);
} else {
- $texversion.='\vskip 0 mm \noindent\textbf{Prints from construction space - there is no title.}\vskip 0 mm ';
- my $URLpath=$urlp;
- $URLpath=~s/~([^\/]+)/public_html\/$1\/$1/;
- $texversion.=&path_to_problem($URLpath,$LaTeXwidth);
+ $texversion.='\vskip 0 mm \noindent\textbf{'.
+ &mt("Printing from Construction Space: No Title").'}\vskip 0 mm ';
+ $texversion.=&path_to_problem($urlp,$LaTeXwidth);
}
$texversion.='\vskip 1 mm '.$answer.'\end{document}';
}
@@ -1674,7 +2257,6 @@ sub print_page_in_course {
sub recently_generated {
my ($prtspool) = @_;
my $output;
-
my $zip_result;
my $pdf_result;
opendir(DIR,$prtspool);
@@ -1707,7 +2289,7 @@ sub recently_generated {
if ($ext eq 'zip') { $zip_result .= $result; }
}
if ($zip_result || $pdf_result) {
- $output = '';
+ $output ='';
}
if ($zip_result) {
$output .='