--- loncom/interface/lonprintout.pm 2008/03/10 10:10:18 1.518
+++ loncom/interface/lonprintout.pm 2008/08/25 10:16:27 1.537
@@ -1,7 +1,7 @@
# The LearningOnline Network
# Printout
#
-# $Id: lonprintout.pm,v 1.518 2008/03/10 10:10:18 foxr Exp $
+# $Id: lonprintout.pm,v 1.537 2008/08/25 10:16:27 foxr Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -38,6 +38,9 @@ use Apache::edit;
use Apache::File();
use Apache::lonnavmaps;
use Apache::admannotations;
+use Apache::lonenc;
+use Apache::entities;
+
use HTTP::Response;
use LONCAPA::map();
@@ -115,7 +118,7 @@ sub annotate {
# the number of times requested by the caller.
# If we still have a proble, no text is appended to the
# output and we set some global variables.
-# to indicate to the caller an SSI error occured.
+# to indicate to the caller an SSI error occurred.
# All of this is supposed to deal with the issues described
# in LonCAPA BZ 5631 see:
# http://bugs.lon-capa.org/show_bug.cgi?id=5631
@@ -131,10 +134,10 @@ sub annotate {
# On success, returns the rendered resource identified by the resource parameter.
# Side Effects:
# The following global variables can be set:
-# ssi_error - If an unrecoverable error occured this becomes true.
+# ssi_error - If an unrecoverable error occurred this becomes true.
# It is up to the caller to initialize this to false
# if desired.
-# ssi_last_error_resource - If an unrecoverable error occured, this is the value
+# ssi_last_error_resource - If an unrecoverable error occurred, this is the value
# of the resource that could not be rendered by the ssi
# call.
# ssi_last_error - The error string fetched from the ssi response
@@ -149,12 +152,29 @@ sub ssi_with_retries {
$ssi_error = 1;
$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;
}
+sub get_student_view_with_retries {
+ my ($curresline,$retries,$username,$userdomain,$courseid,$target,$moreenv)=@_;
+
+ my ($content, $response) = &Apache::loncommon::get_student_view_with_retries($curresline,$retries,$username,$userdomain,$courseid,$target,$moreenv);
+ if (!$response->is_success) {
+ $ssi_error = 1;
+ $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;
+
+}
+
#
# printf_style_subst item format_string repl
#
@@ -209,9 +229,11 @@ 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.
# Default format?
@@ -228,38 +250,36 @@ sub format_page_header {
# - Allow the assignment to be 2 lines (wrapped).
#
my $chars_per_line = $width/2; # Character/textline.
+
- 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);
+ 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 = "\\textbf{$student} $course \\hfill \\thepage \\\\ \\textit{$assignment}";
-
- } 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!!!
+ $format .= '\\\\%c \\\\ %a';
+
}
+ # 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!!!
+
return $format;
@@ -484,12 +504,19 @@ sub adjust_number_to_print {
# Unmodified.
} else {
# Error!!!!
-
+
croak "bad SPLIT_PDFS: $split_pdf in lonprintout::adjust_number_to_print";
+
}
}
+
sub character_chart {
+ my $result = shift;
+ return &Apache::entities::replace_entities($result);
+}
+
+sub old_character_chart {
my $result = shift;
$result =~ s/&\#0?0?(7|9);//g;
$result =~ s/&\#0?(10|13);//g;
@@ -611,7 +638,7 @@ sub character_chart {
$result =~ s/&(\#165|yen);/\\textyen /g;
$result =~ s/&(\#166|brvbar);/\\textbrokenbar /g;
$result =~ s/&(\#167|sect);/\\textsection /g;
- $result =~ s/&(\#168|uml);/\\texthighdieresis /g;
+ $result =~ s/&(\#168|uml);/\\"\{\} /g;
$result =~ s/&(\#169|copy);/\\copyright /g;
$result =~ s/&(\#170|ordf);/\\textordfeminine /g;
$result =~ s/&(\#172|not);/\\ensuremath\{\\neg\}/g;
@@ -622,7 +649,7 @@ sub character_chart {
$result =~ s/&(\#177|plusmn);/\\ensuremath\{\\pm\}/g;
$result =~ s/&(\#178|sup2);/\\ensuremath\{^2\}/g;
$result =~ s/&(\#179|sup3);/\\ensuremath\{^3\}/g;
- $result =~ s/&(\#180|acute);/\\textacute /g;
+ $result =~ s/&(\#180|acute);/\\'\{\} /g;
$result =~ s/&(\#181|micro);/\\ensuremath\{\\mu\}/g;
$result =~ s/&(\#182|para);/\\P/g;
$result =~ s/&(\#183|middot);/\\ensuremath\{\\cdot\}/g;
@@ -951,6 +978,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;
}
@@ -973,7 +1002,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);
@@ -1124,7 +1152,16 @@ sub print_latex_header {
'\usepackage[dvips]{graphicx}\usepackage{epsfig}'."\n".
'\usepackage{wrapfig}'.
'\usepackage{picins}\usepackage{calc}'."\n".
- '\usepackage[utf8]{inputenc}'."\n".
+ '\usepackage[T1]{fontenc}'."\n".
+ '\usepackage[postscript]{ucs}'."\n".
+ '\usepackage[utf8x]{inputenc}'."\n".
+ '\usepackage{pifont}' . "\n".
+ '\usepackage{latexsym}'."\n".
+ '\usepackage{amsmath}'.
+ '\usepackage{amssymb}'.
+ '\usepackage{amsfonts}'.
+ '\usepackage{amsthm}'.
+ '\usepackage{amscd}'.
'\newenvironment{choicelist}{\begin{list}{}{\setlength{\rightmargin}{0in}'."\n".
'\setlength{\leftmargin}{0.13in}\setlength{\topsep}{0.05in}'."\n".
'\setlength{\itemsep}{0.022in}\setlength{\parsep}{0in}'."\n".
@@ -1471,8 +1508,8 @@ ENDPART
}
if ($helper->{'VARS'}->{'style_file'}=~/\w/) {
- &Apache::lonnet::appenv('construct.style' =>
- $helper->{'VARS'}->{'style_file'});
+ &Apache::lonnet::appenv({'construct.style' =>
+ $helper->{'VARS'}->{'style_file'}});
} elsif ($env{'construct.style'}) {
&Apache::lonnet::delenv('construct\\.style');
}
@@ -1515,7 +1552,7 @@ ENDPART
$rndseed=$helper->{'VARS'}->{'curseed'};
}
$form{'rndseed'}=$rndseed;
- &Apache::lonnet::appenv(%moreenv);
+ &Apache::lonnet::appenv(\%moreenv);
&Apache::lonxml::clear_problem_counter();
@@ -1629,7 +1666,8 @@ ENDPART
($helper->{'VARS'}->{'PRINT_TYPE'} eq 'map_problems_pages') or
($helper->{'VARS'}->{'PRINT_TYPE'} eq 'all_problems') or
($helper->{'VARS'}->{'PRINT_TYPE'} eq 'all_resources') or # BUGBUG
- ($helper->{'VARS'}->{'PRINT_TYPE'} eq 'select_sequences')) {
+ ($helper->{'VARS'}->{'PRINT_TYPE'} eq 'select_sequences')
+ ) {
#-- produce an output string
@@ -1637,7 +1675,8 @@ ENDPART
$selectionmade = 2;
} elsif ($helper->{'VARS'}->{'PRINT_TYPE'} eq 'map_problems_pages') {
$selectionmade = 3;
- } elsif ($helper->{'VARS'}->{'PRINT_TYPE'} eq 'all_problems') {
+ } elsif (($helper->{'VARS'}->{'PRINT_TYPE'} eq 'all_problems')
+ ) {
$selectionmade = 4;
} elsif ($helper->{'VARS'}->{'PRINT_TYPE'} eq 'all_resources') { #BUGBUG
$selectionmade = 4;
@@ -1663,6 +1702,9 @@ ENDPART
my $pbreakresources = keys %page_breaks;
for (my $i=0;$i<=$#master_seq;$i++) {
+ &Apache::lonenc::reset_enc();
+
+
# Note due to document structure, not allowed to put \newpage
# prior to the first resource
@@ -1671,11 +1713,13 @@ ENDPART
$result.="\\newpage\n";
}
}
- my ($sequence,undef,$urlp)=&Apache::lonnet::decode_symb($master_seq[$i]);
+ my ($sequence,$middle_thingy,$urlp)=&Apache::lonnet::decode_symb($master_seq[$i]);
$urlp=&Apache::lonnet::clutter($urlp);
$form{'symb'}=$master_seq[$i];
+
my $assignment=&Apache::lonxml::latex_special_symbols(&Apache::lonnet::gettitle($sequence),'header'); #title of the assignment which contains this problem
+
if ($selectionmade==7) {$helper->{VARS}->{'assignment'}=$assignment;}
if ($i==0) {$prevassignment=$assignment;}
my $texversion='';
@@ -1736,7 +1780,6 @@ ENDPART
if (($selectionmade == 4) and ($assignment ne $prevassignment)) {
my $name = &get_name();
my $courseidinfo = &get_course();
- if (defined($courseidinfo)) { $courseidinfo=' - '.$courseidinfo }
$prevassignment=$assignment;
my $header_text = $parmhash{'print_header_format'};
$header_text = &format_page_header($textwidth, $header_text,
@@ -1787,12 +1830,14 @@ ENDPART
}
$result .= '\end{document}';
} elsif (($helper->{'VARS'}->{'PRINT_TYPE'} eq 'problems_for_students') ||
+ ($helper->{'VARS'}->{'PRINT_TYPE'} eq 'all_problems_students') ||
($helper->{'VARS'}->{'PRINT_TYPE'} eq 'resources_for_students')){
#-- prints assignments for whole class or for selected students
my $type;
- if ($helper->{'VARS'}->{'PRINT_TYPE'} eq 'problems_for_students') {
+ if (($helper->{'VARS'}->{'PRINT_TYPE'} eq 'problems_for_students') ||
+ ($helper->{'VARS'}->{'PRINT_TYPE'} eq 'all_problems_students') ) {
$selectionmade=5;
$type='problems';
} elsif ($helper->{'VARS'}->{'PRINT_TYPE'} eq 'resources_for_students') {
@@ -1982,6 +2027,9 @@ ENDPART
$rndseed=$helper->{'VARS'}->{'curseed'};
}
for (my $i=0;$i<=$#list_of_files;$i++) {
+
+ &Apache::lonenc::reset_enc();
+
my $urlp = $list_of_files[$i];
$urlp=~s|//|/|;
if ($urlp=~/\//) {
@@ -2075,98 +2123,68 @@ ENDPART
}
}
-
- # If there's been an unrecoverable SSI error, report it to the user
- # otherwise, we can write the tex file.
- #
-
- if ($ssi_error) {
- my $end_page = &Apache::loncommon::end_page();
- $r->print(<
- I was not able to render one of the print resources ($ssi_last_error_resource)
-due to an unrecoverable error communicating with a server:
-
-$ssi_last_error;
-
-
-I recommend that you try printing again later as this may mean the server was just
-temporarily unavailable, or is down for maintenance. If this error persists, then
-please contact your LonCAPA support folks for assistance and diagnosis.
-
-
-We apologize for the inconvenience.
-
'.
+ &mt('At least one of the resources you chose to print could not be rendered due to an unrecoverable error when communicating with a server:').
+ '
'.$ssi_last_error_resource.'
'.$ssi_last_error.
+ '
'.&mt('You can continue using the link provided below, but make sure to carefully inspect your output file! The errors will be marked in the file.').'
'.
+ &mt('You may be able to reprint the individual resources for which this error occurred, as the issue may be temporary.').
+ '
'.&mt('If the error persists, please contact the [_1] for assistance.',$helpurl).'
'. + &mt('We apologize for the inconvenience.').'
'. + ''.$continue_text.''.$end_page); + } else { $r->print(<