--- loncom/interface/lonprintout.pm 2008/03/11 09:52:56 1.519
+++ loncom/interface/lonprintout.pm 2008/04/04 16:46:23 1.519.2.4
@@ -1,7 +1,7 @@
# The LearningOnline Network
# Printout
#
-# $Id: lonprintout.pm,v 1.519 2008/03/11 09:52:56 foxr Exp $
+# $Id: lonprintout.pm,v 1.519.2.4 2008/04/04 16:46:23 raeburn Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -38,6 +38,7 @@ use Apache::edit;
use Apache::File();
use Apache::lonnavmaps;
use Apache::admannotations;
+use Apache::lonenc;
use HTTP::Response;
use LONCAPA::map();
@@ -115,7 +116,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 +132,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,7 +150,7 @@ 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");
}
@@ -157,6 +158,19 @@ sub ssi_with_retries {
}
+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
#
@@ -1665,6 +1679,8 @@ 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
@@ -1673,11 +1689,12 @@ 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='';
@@ -1984,6 +2001,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=~/\//) {
@@ -2082,117 +2102,104 @@ ENDPART
# otherwise, we can write the tex file.
#
- if ($ssi_error) {
- my $end_page = &Apache::loncommon::end_page();
- $r->print(<
-
An unrecoverable error occured:
-
- 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.
-
-$end_page
-ERROR_END
- } else {
-
#-- writing .tex file in prtspool
- my $temp_file;
- my $identifier = &Apache::loncommon::get_cgi_id();
- my $filename = "/home/httpd/prtspool/$env{'user.name'}_$env{'user.domain'}_printout_$identifier.tex";
- if (!($#print_array>0)) {
- unless ($temp_file = Apache::File->new('>'.$filename)) {
- $r->log_error("Couldn't open $filename for output $!");
- return SERVER_ERROR;
- }
- print $temp_file $result;
- my $begin=index($result,'\begin{document}',0);
- my $inc=substr($result,0,$begin+16);
- } else {
- my $begin=index($result,'\begin{document}',0);
- my $inc=substr($result,0,$begin+16);
- for (my $i=0;$i<=$#print_array;$i++) {
- if ($i==0) {
- $print_array[$i]=$result;
- } else {
- $print_array[$i].='\end{document}';
- $print_array[$i] =
- &latex_corrections($number_of_columns,$print_array[$i],
- $selectionmade,
- $helper->{'VARS'}->{'ANSWER_TYPE'});
+ my $temp_file;
+ my $identifier = &Apache::loncommon::get_cgi_id();
+ my $filename = "/home/httpd/prtspool/$env{'user.name'}_$env{'user.domain'}_printout_$identifier.tex";
+ if (!($#print_array>0)) {
+ unless ($temp_file = Apache::File->new('>'.$filename)) {
+ $r->log_error("Couldn't open $filename for output $!");
+ return SERVER_ERROR;
+ }
+ print $temp_file $result;
+ my $begin=index($result,'\begin{document}',0);
+ my $inc=substr($result,0,$begin+16);
+ } else {
+ my $begin=index($result,'\begin{document}',0);
+ my $inc=substr($result,0,$begin+16);
+ for (my $i=0;$i<=$#print_array;$i++) {
+ if ($i==0) {
+ $print_array[$i]=$result;
+ } else {
+ $print_array[$i].='\end{document}';
+ $print_array[$i] =
+ &latex_corrections($number_of_columns,$print_array[$i],
+ $selectionmade,
+ $helper->{'VARS'}->{'ANSWER_TYPE'});
- my $anobegin=index($print_array[$i],'\setcounter{page}',0);
- substr($print_array[$i],0,$anobegin)='';
- $print_array[$i]=$inc.$print_array[$i];
- }
- my $temp_file;
- my $newfilename=$filename;
- my $num=$i+1;
- $newfilename =~s/\.tex$//;
- $newfilename=sprintf("%s_%03d.tex",$newfilename, $num);
- unless ($temp_file = Apache::File->new('>'.$newfilename)) {
- $r->log_error("Couldn't open $newfilename for output $!");
- return SERVER_ERROR;
- }
- print $temp_file $print_array[$i];
+ my $anobegin=index($print_array[$i],'\setcounter{page}',0);
+ substr($print_array[$i],0,$anobegin)='';
+ $print_array[$i]=$inc.$print_array[$i];
+ }
+ my $temp_file;
+ my $newfilename=$filename;
+ my $num=$i+1;
+ $newfilename =~s/\.tex$//;
+ $newfilename=sprintf("%s_%03d.tex",$newfilename, $num);
+ unless ($temp_file = Apache::File->new('>'.$newfilename)) {
+ $r->log_error("Couldn't open $newfilename for output $!");
+ return SERVER_ERROR;
}
-
+ print $temp_file $print_array[$i];
}
- my $student_names='';
- if ($#print_array>0) {
- for (my $i=0;$i<=$#print_array;$i++) {
- $student_names.=$student_names[$i].'_ENDPERSON_';
- }
+ }
+ my $student_names='';
+ if ($#print_array>0) {
+ for (my $i=0;$i<=$#print_array;$i++) {
+ $student_names.=$student_names[$i].'_ENDPERSON_';
+ }
+ } else {
+ if ($#student_names>-1) {
+ $student_names=$student_names[0].'_ENDPERSON_';
} else {
- if ($#student_names>-1) {
- $student_names=$student_names[0].'_ENDPERSON_';
- } else {
- my $fullname = &get_name($env{'user.name'},$env{'user.domain'});
- $student_names=join(':',$env{'user.name'},$env{'user.domain'},
- $env{'request.course.sec'},$fullname).
- '_ENDPERSON_'.'_END_';
- }
+ my $fullname = &get_name($env{'user.name'},$env{'user.domain'});
+ $student_names=join(':',$env{'user.name'},$env{'user.domain'},
+ $env{'request.course.sec'},$fullname).
+ '_ENDPERSON_'.'_END_';
}
+ }
- # logic for now is too complex to trace if this has been defined
- # yet.
- my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
- my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
- &Apache::lonnet::appenv('cgi.'.$identifier.'.file' => $filename,
- 'cgi.'.$identifier.'.layout' => $laystyle,
- 'cgi.'.$identifier.'.numcol' => $numberofcolumns,
- 'cgi.'.$identifier.'.paper' => $papersize,
- 'cgi.'.$identifier.'.selection' => $selectionmade,
- 'cgi.'.$identifier.'.tableofcontents' => $helper->{'VARS'}->{'TABLE_CONTENTS'},
- 'cgi.'.$identifier.'.tableofindex' => $helper->{'VARS'}->{'TABLE_INDEX'},
- 'cgi.'.$identifier.'.role' => $perm{'pav'},
- 'cgi.'.$identifier.'.numberoffiles' => $#print_array,
- 'cgi.'.$identifier.'.studentnames' => $student_names,
- 'cgi.'.$identifier.'.backref' => $URLback,);
- &Apache::lonnet::appenv("cgi.$identifier.user" => $env{'user.name'},
- "cgi.$identifier.domain" => $env{'user.domain'},
- "cgi.$identifier.courseid" => $cnum,
- "cgi.$identifier.coursedom" => $cdom,
- "cgi.$identifier.resources" => $resources_printed);
-
- my $end_page = &Apache::loncommon::end_page();
+ # logic for now is too complex to trace if this has been defined
+ # yet.
+ my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
+ my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
+ &Apache::lonnet::appenv('cgi.'.$identifier.'.file' => $filename,
+ 'cgi.'.$identifier.'.layout' => $laystyle,
+ 'cgi.'.$identifier.'.numcol' => $numberofcolumns,
+ 'cgi.'.$identifier.'.paper' => $papersize,
+ 'cgi.'.$identifier.'.selection' => $selectionmade,
+ 'cgi.'.$identifier.'.tableofcontents' => $helper->{'VARS'}->{'TABLE_CONTENTS'},
+ 'cgi.'.$identifier.'.tableofindex' => $helper->{'VARS'}->{'TABLE_INDEX'},
+ 'cgi.'.$identifier.'.role' => $perm{'pav'},
+ 'cgi.'.$identifier.'.numberoffiles' => $#print_array,
+ 'cgi.'.$identifier.'.studentnames' => $student_names,
+ 'cgi.'.$identifier.'.backref' => $URLback,);
+ &Apache::lonnet::appenv("cgi.$identifier.user" => $env{'user.name'},
+ "cgi.$identifier.domain" => $env{'user.domain'},
+ "cgi.$identifier.courseid" => $cnum,
+ "cgi.$identifier.coursedom" => $cdom,
+ "cgi.$identifier.resources" => $resources_printed);
+ my $end_page = &Apache::loncommon::end_page();
+ my $continue_text = &mt('Continue');
+ # If there's been an unrecoverable SSI error, report it to the user
+ if ($ssi_error) {
+ my $helpurl = &Apache::loncommon::top_nav_help('Helpdesk');
+ $r->print('
'.&mt('An unrecoverable network error occurred:').'
'.
+ &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.').'
'.
+ ''.&mt('Continue').''.$end_page);
+ } else {
$r->print(<
Continue
$end_page
FINALEND
- } # endif ssi errors.
+ } # endif ssi errors.
}
@@ -2265,7 +2272,7 @@ sub print_resources {
&Apache::lonxml::remember_problem_counter();
- my $rendered = &Apache::loncommon::get_student_view($curresline,$username,$userdomain,$env{'request.course.id'},'tex',$moreenv);
+ my $rendered = &get_student_view_with_retries($curresline,$ssi_retry_count,$username,$userdomain,$env{'request.course.id'},'tex',$moreenv);
if(($helper->{'VARS'}->{'ANSWER_TYPE'} eq 'no') ||
($helper->{'VARS'}->{'ANSWER_TYPE'} eq 'only')) {
@@ -2307,7 +2314,7 @@ sub print_resources {
$current_output .= $rendered;
} elsif ($res_url=~/\/(smppg|syllabus|aboutme|bulletinboard)$/) {
$printed .= $curresline.':';
- my $rendered = &Apache::loncommon::get_student_view($curresline,$username,$userdomain,$env{'request.course.id'},'tex',$moreenv);
+ my $rendered = &get_student_view_with_retries($curresline,$ssi_retry_count,$username,$userdomain,$env{'request.course.id'},'tex',$moreenv);
if ($helper->{'VARS'}->{'PRINT_ANNOTATIONS'} eq 'yes') {
my $url = &Apache::lonnet::clutter($res_url);
my $annotation = &annotate($url);