--- loncom/interface/lonprintout.pm 2010/11/13 01:57:14 1.568.2.10
+++ loncom/interface/lonprintout.pm 2011/06/16 11:59:16 1.592
@@ -1,8 +1,8 @@
-#
+
# 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.592 2011/06/16 11:59:16 foxr Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -45,13 +45,13 @@ use Apache::londefdef;
use File::Basename;
use HTTP::Response;
-
use LONCAPA::map();
use POSIX qw(strftime);
use Apache::lonlocal;
use Carp;
use LONCAPA;
+
my %perm;
my %parmhash;
my $resources_printed;
@@ -76,7 +76,146 @@ my $font_size = 'normalsize'; # Default
#---------------------------- Helper helpers. -------------------------
-# Returns the text needd for a student chooser.
+# 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.
@@ -196,14 +335,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;
@@ -228,6 +372,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 +395,77 @@ CHOOSE_ANON1
return $result;
}
+sub generate_format_selector {
+ my ($helper,$title,$nextstate, $thisstate) = @_;
+ my $secpdfoption;
+ my $state = 'PRINT_FORMATTING';
+ if ($thisstate) {
+ $state = $thisstate;
+ }
+ 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 <
+ $nextstate
+ 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
+}
+
#-----------------------------------------------------------------------
+# 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) = @_;
+
+ # Manipulate the env so the navmap is made
+ # in the context of the appropriate user:
+
+ my $me = $env{'user.name'};
+ my $my_domain = $env{'user.domain'};
+
+ $env{'user.name'} = $username;
+ $env{'user.domain'} = $domain;
+
+ my $navmap = Apache::lonnavmaps::navmap->new();
+
+ $env{'user.name'} = $me; # Restore user/domain context.
+ $env{'user.domain'} = $my_domain;
+
+ if (defined($navmap)) {
+ my $res = $navmap->getResourceByUrl($map);
+ my $result = $res->is_incomplete();
+ return $result;
+ } else {
+ return 1;
+ }
+}
# Fetch the contents of a resource, uninterpreted.
# This is used here to fetch a latex file to be included
@@ -312,10 +527,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
@@ -499,12 +716,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 +740,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;
+
}
#
@@ -1245,6 +1487,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 +1511,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 +1531,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 /;}
@@ -1527,7 +1770,7 @@ sub print_page_in_course {
} else {
my $esc_currentURL= $currentURL;
$esc_currentURL =~ s/_/\\_/g;
- $result.=$esc_currentURL;
+ $result.=$esc_currentURL;
}
$result .= '\\\\';
@@ -1568,7 +1811,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'};
@@ -1674,7 +1917,6 @@ sub print_page_in_course {
sub recently_generated {
my ($prtspool) = @_;
my $output;
-
my $zip_result;
my $pdf_result;
opendir(DIR,$prtspool);
@@ -1707,7 +1949,7 @@ sub recently_generated {
if ($ext eq 'zip') { $zip_result .= $result; }
}
if ($zip_result || $pdf_result) {
- $output = '';
+ $output ='';
}
if ($zip_result) {
$output .='