version 1.519.2.2, 2008/03/24 00:03:05
|
version 1.534, 2008/05/05 10:48:56
|
Line 39 use Apache::File();
|
Line 39 use Apache::File();
|
use Apache::lonnavmaps; |
use Apache::lonnavmaps; |
use Apache::admannotations; |
use Apache::admannotations; |
use Apache::lonenc; |
use Apache::lonenc; |
|
use Apache::entities; |
|
|
use HTTP::Response; |
use HTTP::Response; |
|
|
use LONCAPA::map(); |
use LONCAPA::map(); |
Line 116 sub annotate {
|
Line 118 sub annotate {
|
# the number of times requested by the caller. |
# the number of times requested by the caller. |
# If we still have a proble, no text is appended to the |
# If we still have a proble, no text is appended to the |
# output and we set some global variables. |
# 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 |
# All of this is supposed to deal with the issues described |
# in LonCAPA BZ 5631 see: |
# in LonCAPA BZ 5631 see: |
# http://bugs.lon-capa.org/show_bug.cgi?id=5631 |
# http://bugs.lon-capa.org/show_bug.cgi?id=5631 |
Line 132 sub annotate {
|
Line 134 sub annotate {
|
# On success, returns the rendered resource identified by the resource parameter. |
# On success, returns the rendered resource identified by the resource parameter. |
# Side Effects: |
# Side Effects: |
# The following global variables can be set: |
# 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 |
# It is up to the caller to initialize this to false |
# if desired. |
# 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 |
# of the resource that could not be rendered by the ssi |
# call. |
# call. |
# ssi_last_error - The error string fetched from the ssi response |
# ssi_last_error - The error string fetched from the ssi response |
Line 150 sub ssi_with_retries {
|
Line 152 sub ssi_with_retries {
|
$ssi_error = 1; |
$ssi_error = 1; |
$ssi_last_error_resource = $resource; |
$ssi_last_error_resource = $resource; |
$ssi_last_error = $response->code . " " . $response->message; |
$ssi_last_error = $response->code . " " . $response->message; |
|
$content='\section*{!!! An error occurred !!!}'; |
&Apache::lonnet::logthis("Error in SSI resource: $resource Error: $ssi_last_error"); |
&Apache::lonnet::logthis("Error in SSI resource: $resource Error: $ssi_last_error"); |
} |
} |
|
|
Line 158 sub ssi_with_retries {
|
Line 160 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 |
# printf_style_subst item format_string repl |
# |
# |
Line 492 sub adjust_number_to_print {
|
Line 509 sub adjust_number_to_print {
|
} |
} |
} |
} |
|
|
|
|
sub character_chart { |
sub character_chart { |
|
my $result = shift; |
|
return &Apache::entities::replace_entities($result); |
|
} |
|
|
|
sub old_character_chart { |
my $result = shift; |
my $result = shift; |
$result =~ s/&\#0?0?(7|9);//g; |
$result =~ s/&\#0?0?(7|9);//g; |
$result =~ s/&\#0?(10|13);//g; |
$result =~ s/&\#0?(10|13);//g; |
Line 614 sub character_chart {
|
Line 637 sub character_chart {
|
$result =~ s/&(\#165|yen);/\\textyen /g; |
$result =~ s/&(\#165|yen);/\\textyen /g; |
$result =~ s/&(\#166|brvbar);/\\textbrokenbar /g; |
$result =~ s/&(\#166|brvbar);/\\textbrokenbar /g; |
$result =~ s/&(\#167|sect);/\\textsection /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/&(\#169|copy);/\\copyright /g; |
$result =~ s/&(\#170|ordf);/\\textordfeminine /g; |
$result =~ s/&(\#170|ordf);/\\textordfeminine /g; |
$result =~ s/&(\#172|not);/\\ensuremath\{\\neg\}/g; |
$result =~ s/&(\#172|not);/\\ensuremath\{\\neg\}/g; |
Line 625 sub character_chart {
|
Line 648 sub character_chart {
|
$result =~ s/&(\#177|plusmn);/\\ensuremath\{\\pm\}/g; |
$result =~ s/&(\#177|plusmn);/\\ensuremath\{\\pm\}/g; |
$result =~ s/&(\#178|sup2);/\\ensuremath\{^2\}/g; |
$result =~ s/&(\#178|sup2);/\\ensuremath\{^2\}/g; |
$result =~ s/&(\#179|sup3);/\\ensuremath\{^3\}/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/&(\#181|micro);/\\ensuremath\{\\mu\}/g; |
$result =~ s/&(\#182|para);/\\P/g; |
$result =~ s/&(\#182|para);/\\P/g; |
$result =~ s/&(\#183|middot);/\\ensuremath\{\\cdot\}/g; |
$result =~ s/&(\#183|middot);/\\ensuremath\{\\cdot\}/g; |
Line 1127 sub print_latex_header {
|
Line 1150 sub print_latex_header {
|
'\usepackage[dvips]{graphicx}\usepackage{epsfig}'."\n". |
'\usepackage[dvips]{graphicx}\usepackage{epsfig}'."\n". |
'\usepackage{wrapfig}'. |
'\usepackage{wrapfig}'. |
'\usepackage{picins}\usepackage{calc}'."\n". |
'\usepackage{picins}\usepackage{calc}'."\n". |
'\usepackage[utf8]{inputenc}'."\n". |
'\usepackage[T1]{fontenc}'."\n". |
|
'\usepackage[postscript]{ucs}'."\n". |
|
'\usepackage[utf8x]{inputenc}'."\n". |
|
'\usepacakge{pifont}' . "\n". |
|
'\usepackage{latexsym}'."\n". |
|
'\usepackage{amsmath}'. |
|
'\usepackage{amssymb}'. |
|
'\usepackage{amsfonts}'. |
|
'\usepackage{amsthm}'. |
|
'\usepackage{amscd}'. |
'\newenvironment{choicelist}{\begin{list}{}{\setlength{\rightmargin}{0in}'."\n". |
'\newenvironment{choicelist}{\begin{list}{}{\setlength{\rightmargin}{0in}'."\n". |
'\setlength{\leftmargin}{0.13in}\setlength{\topsep}{0.05in}'."\n". |
'\setlength{\leftmargin}{0.13in}\setlength{\topsep}{0.05in}'."\n". |
'\setlength{\itemsep}{0.022in}\setlength{\parsep}{0in}'."\n". |
'\setlength{\itemsep}{0.022in}\setlength{\parsep}{0in}'."\n". |
Line 1474 ENDPART
|
Line 1506 ENDPART
|
} |
} |
|
|
if ($helper->{'VARS'}->{'style_file'}=~/\w/) { |
if ($helper->{'VARS'}->{'style_file'}=~/\w/) { |
&Apache::lonnet::appenv('construct.style' => |
&Apache::lonnet::appenv({'construct.style' => |
$helper->{'VARS'}->{'style_file'}); |
$helper->{'VARS'}->{'style_file'}}); |
} elsif ($env{'construct.style'}) { |
} elsif ($env{'construct.style'}) { |
&Apache::lonnet::delenv('construct\\.style'); |
&Apache::lonnet::delenv('construct\\.style'); |
} |
} |
Line 1518 ENDPART
|
Line 1550 ENDPART
|
$rndseed=$helper->{'VARS'}->{'curseed'}; |
$rndseed=$helper->{'VARS'}->{'curseed'}; |
} |
} |
$form{'rndseed'}=$rndseed; |
$form{'rndseed'}=$rndseed; |
&Apache::lonnet::appenv(%moreenv); |
&Apache::lonnet::appenv(\%moreenv); |
|
|
&Apache::lonxml::clear_problem_counter(); |
&Apache::lonxml::clear_problem_counter(); |
|
|
Line 1666 ENDPART
|
Line 1698 ENDPART
|
my $pbreakresources = keys %page_breaks; |
my $pbreakresources = keys %page_breaks; |
for (my $i=0;$i<=$#master_seq;$i++) { |
for (my $i=0;$i<=$#master_seq;$i++) { |
|
|
&Apache::lonenc::reset_enc(); |
&Apache::lonenc::reset_enc(); |
|
|
|
|
# Note due to document structure, not allowed to put \newpage |
# Note due to document structure, not allowed to put \newpage |
# prior to the first resource |
# prior to the first resource |
Line 1676 ENDPART
|
Line 1709 ENDPART
|
$result.="\\newpage\n"; |
$result.="\\newpage\n"; |
} |
} |
} |
} |
my ($sequence,$middle_thingy,$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); |
$urlp=&Apache::lonnet::clutter($urlp); |
$form{'symb'}=$master_seq[$i]; |
$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 |
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 ($selectionmade==7) {$helper->{VARS}->{'assignment'}=$assignment;} |
Line 1989 ENDPART
|
Line 2023 ENDPART
|
} |
} |
for (my $i=0;$i<=$#list_of_files;$i++) { |
for (my $i=0;$i<=$#list_of_files;$i++) { |
|
|
&Apache::lonenc::reset_enc(); |
&Apache::lonenc::reset_enc(); |
|
|
my $urlp = $list_of_files[$i]; |
my $urlp = $list_of_files[$i]; |
$urlp=~s|//|/|; |
$urlp=~s|//|/|; |
Line 2084 ENDPART
|
Line 2118 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 $helpurl = &Apache::loncommon::top_nav_help('Helpdesk'); |
|
my $end_page = &Apache::loncommon::end_page(); |
|
$r->print(' |
|
<br /> |
|
<h2>'.&mt('An unrecoverable error occured:').'</h2> |
|
<p> |
|
'.&mt('One of the resources ([_1]) you chose to print could not be rendered due to an unrecoverable error when communicating with a server:',$ssi_last_error_resource).' |
|
<br /> |
|
'.$ssi_last_error.' |
|
</p> |
|
<p>'. |
|
&mt('It is recommended that you try printing again later, as this error may mean the server was just temporarily unavailable, or is down for maintenance.').'<br />'. |
|
&mt('If the error persists, please contact the [_1] for assistance.',$helpurl). |
|
'</p><p>'. |
|
&mt('We apologize for the inconvenience.'). |
|
'</p>'. |
|
$end_page); |
|
|
|
} else { |
|
|
|
#-- writing .tex file in prtspool |
#-- writing .tex file in prtspool |
my $temp_file; |
my $temp_file; |
my $identifier = &Apache::loncommon::get_cgi_id(); |
my $identifier = &Apache::loncommon::get_cgi_id(); |
my $filename = "/home/httpd/prtspool/$env{'user.name'}_$env{'user.domain'}_printout_$identifier.tex"; |
my $filename = "/home/httpd/prtspool/$env{'user.name'}_$env{'user.domain'}_printout_$identifier.tex"; |
if (!($#print_array>0)) { |
if (!($#print_array>0)) { |
unless ($temp_file = Apache::File->new('>'.$filename)) { |
unless ($temp_file = Apache::File->new('>'.$filename)) { |
$r->log_error("Couldn't open $filename for output $!"); |
$r->log_error("Couldn't open $filename for output $!"); |
return SERVER_ERROR; |
return SERVER_ERROR; |
} |
} |
print $temp_file $result; |
print $temp_file $result; |
my $begin=index($result,'\begin{document}',0); |
my $begin=index($result,'\begin{document}',0); |
my $inc=substr($result,0,$begin+16); |
my $inc=substr($result,0,$begin+16); |
} else { |
} else { |
my $begin=index($result,'\begin{document}',0); |
my $begin=index($result,'\begin{document}',0); |
my $inc=substr($result,0,$begin+16); |
my $inc=substr($result,0,$begin+16); |
for (my $i=0;$i<=$#print_array;$i++) { |
for (my $i=0;$i<=$#print_array;$i++) { |
if ($i==0) { |
if ($i==0) { |
$print_array[$i]=$result; |
$print_array[$i]=$result; |
} else { |
} else { |
$print_array[$i].='\end{document}'; |
$print_array[$i].='\end{document}'; |
$print_array[$i] = |
$print_array[$i] = |
&latex_corrections($number_of_columns,$print_array[$i], |
&latex_corrections($number_of_columns,$print_array[$i], |
$selectionmade, |
$selectionmade, |
$helper->{'VARS'}->{'ANSWER_TYPE'}); |
$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=''; |
} else { |
if ($#print_array>0) { |
if ($#student_names>-1) { |
for (my $i=0;$i<=$#print_array;$i++) { |
$student_names=$student_names[0].'_ENDPERSON_'; |
$student_names.=$student_names[$i].'_ENDPERSON_'; |
|
} |
|
} else { |
} else { |
if ($#student_names>-1) { |
my $fullname = &get_name($env{'user.name'},$env{'user.domain'}); |
$student_names=$student_names[0].'_ENDPERSON_'; |
$student_names=join(':',$env{'user.name'},$env{'user.domain'}, |
} 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). |
$env{'request.course.sec'},$fullname). |
'_ENDPERSON_'.'_END_'; |
'_ENDPERSON_'.'_END_'; |
} |
|
} |
} |
|
} |
|
|
# logic for now is too complex to trace if this has been defined |
# logic for now is too complex to trace if this has been defined |
# yet. |
# yet. |
my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'}; |
my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'}; |
my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'}; |
my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'}; |
&Apache::lonnet::appenv('cgi.'.$identifier.'.file' => $filename, |
&Apache::lonnet::appenv({'cgi.'.$identifier.'.file' => $filename, |
'cgi.'.$identifier.'.layout' => $laystyle, |
'cgi.'.$identifier.'.layout' => $laystyle, |
'cgi.'.$identifier.'.numcol' => $numberofcolumns, |
'cgi.'.$identifier.'.numcol' => $numberofcolumns, |
'cgi.'.$identifier.'.paper' => $papersize, |
'cgi.'.$identifier.'.paper' => $papersize, |
Line 2183 $end_page);
|
Line 2189 $end_page);
|
'cgi.'.$identifier.'.role' => $perm{'pav'}, |
'cgi.'.$identifier.'.role' => $perm{'pav'}, |
'cgi.'.$identifier.'.numberoffiles' => $#print_array, |
'cgi.'.$identifier.'.numberoffiles' => $#print_array, |
'cgi.'.$identifier.'.studentnames' => $student_names, |
'cgi.'.$identifier.'.studentnames' => $student_names, |
'cgi.'.$identifier.'.backref' => $URLback,); |
'cgi.'.$identifier.'.backref' => $URLback,}); |
&Apache::lonnet::appenv("cgi.$identifier.user" => $env{'user.name'}, |
&Apache::lonnet::appenv({"cgi.$identifier.user" => $env{'user.name'}, |
"cgi.$identifier.domain" => $env{'user.domain'}, |
"cgi.$identifier.domain" => $env{'user.domain'}, |
"cgi.$identifier.courseid" => $cnum, |
"cgi.$identifier.courseid" => $cnum, |
"cgi.$identifier.coursedom" => $cdom, |
"cgi.$identifier.coursedom" => $cdom, |
"cgi.$identifier.resources" => $resources_printed); |
"cgi.$identifier.resources" => $resources_printed}); |
|
|
my $end_page = &Apache::loncommon::end_page(); |
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('<br /><h2>'.&mt('An unrecoverable network error occurred:').'</h2><p> '. |
|
&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:'). |
|
'<br />'.$ssi_last_error_resource.'<br />'.$ssi_last_error. |
|
'</p><p>'.&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.').'<br />'. |
|
&mt('You may be able to reprint the individual resources for which this error occurred, as the issue may be temporary.'). |
|
'<br />'.&mt('If the error persists, please contact the [_1] for assistance.',$helpurl).'</p><p>'. |
|
&mt('We apologize for the inconvenience.').'</p>'. |
|
'<a href="/cgi-bin/printout.pl?'.$identifier.'">'.$continue_text.'</a>'.$end_page); |
|
} else { |
$r->print(<<FINALEND); |
$r->print(<<FINALEND); |
<br /> |
<br /> |
<meta http-equiv="Refresh" content="0; url=/cgi-bin/printout.pl?$identifier" /> |
<meta http-equiv="Refresh" content="0; url=/cgi-bin/printout.pl?$identifier" /> |
<a href="/cgi-bin/printout.pl?$identifier">Continue</a> |
<a href="/cgi-bin/printout.pl?$identifier">$continue_text</a> |
$end_page |
$end_page |
FINALEND |
FINALEND |
} # endif ssi errors. |
} # endif ssi errors. |
} |
} |
|
|
|
|
Line 2270 sub print_resources {
|
Line 2289 sub print_resources {
|
|
|
&Apache::lonxml::remember_problem_counter(); |
&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') || |
if(($helper->{'VARS'}->{'ANSWER_TYPE'} eq 'no') || |
($helper->{'VARS'}->{'ANSWER_TYPE'} eq 'only')) { |
($helper->{'VARS'}->{'ANSWER_TYPE'} eq 'only')) { |
Line 2312 sub print_resources {
|
Line 2331 sub print_resources {
|
$current_output .= $rendered; |
$current_output .= $rendered; |
} elsif ($res_url=~/\/(smppg|syllabus|aboutme|bulletinboard)$/) { |
} elsif ($res_url=~/\/(smppg|syllabus|aboutme|bulletinboard)$/) { |
$printed .= $curresline.':'; |
$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') { |
if ($helper->{'VARS'}->{'PRINT_ANNOTATIONS'} eq 'yes') { |
my $url = &Apache::lonnet::clutter($res_url); |
my $url = &Apache::lonnet::clutter($res_url); |
my $annotation = &annotate($url); |
my $annotation = &annotate($url); |