--- loncom/interface/lonprintout.pm 2011/11/05 21:49:25 1.602 +++ loncom/interface/lonprintout.pm 2012/03/28 21:15:41 1.613 @@ -1,8 +1,7 @@ - # The LearningOnline Network # Printout # -# $Id: lonprintout.pm,v 1.602 2011/11/05 21:49:25 www Exp $ +# $Id: lonprintout.pm,v 1.613 2012/03/28 21:15:41 ramirez Exp $ # # Copyright Michigan State University Board of Trustees # @@ -41,6 +40,7 @@ use Apache::admannotations; use Apache::lonenc; use Apache::entities; use Apache::londefdef; +# use Apache::structurelags; # for language management. use File::Basename; @@ -302,7 +302,6 @@ CHOOSE_RESOURCES CHOOSE_RESOURCES - return $result; } # @@ -519,6 +518,7 @@ sub master_seq_to_person_seq { # 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}) { @@ -634,9 +634,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); @@ -659,7 +660,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. @@ -2051,7 +2074,7 @@ sub recently_generated { # A reference to a page break hash. # # -use Data::Dumper; +# use Data::Dumper; # sub dump_helper_vars { # my ($helper) = @_; # my $helpervars = Dumper($helper->{'VARS'}); @@ -2200,18 +2223,19 @@ sub set_form_extraspace { sub print_construction_sequence { my ($currentURL, $helper, %form, $LaTeXwidth) = @_; - my $result; my $rndseed=time; if ($helper->{'VARS'}->{'curseed'}) { $rndseed=$helper->{'VARS'}->{'curseed'}; } - my $errtext=&LONCAPA::map::mapread($currentURL); + my $errtext=&LONCAPA::map::mapread(&Apache::lonnet::filelocation('',$currentURL)); + # # These make this all support recursing for subsequences. # my @order = @LONCAPA::map::order; my @resources = @LONCAPA::map::resources; + for (my $member=0;$member<=$#order;$member++) { $resources[$order[$member]]=~/^([^:]*):([^:]*):/; my $urlp=$2; @@ -2227,7 +2251,7 @@ sub print_construction_sequence { } if((($helper->{'VARS'}->{'ANSWER_TYPE'} eq 'no') || ($helper->{'VARS'}->{'ANSWER_TYPE'} eq 'only')) && - ($urlp=~/\.(problem|exam|quiz|assess|survey|form|library|page)$/)) { + ($urlp=~/$LONCAPA::assess_page_re/)) { # Don't permanently modify %$form... my %answerform = %form; $answerform{'grade_target'}='answer'; @@ -2271,17 +2295,7 @@ sub print_construction_sequence { # IF sequence, recurse: if ($urlp =~ /\.sequence$/) { -# -# FIXME: this does not work for co-authors - my $sequence_url = $urlp; - my $domain = $env{'user.domain'}; # Constr. space only on local - my $user = $env{'user.name'}; -# FIXME: the substitutions below do not seem to make sense - - $sequence_url =~ s/^\/res\/$domain/\/home/; - $sequence_url =~ s/^(\/home\/$user)/$1\/public_html/; -# $sequence_url =~ s|\/~([^\/]+)\/|\/home\/$1\/public_html\/|; - $result .= &print_construction_sequence($sequence_url, + $result .= &print_construction_sequence($urlp, $helper, %form, $LaTeXwidth); } @@ -2338,7 +2352,6 @@ sub print_construction_sequence { sub output_data { my ($r,$helper,$rparmhash) = @_; - my %parmhash = %$rparmhash; $ssi_error = 0; # This will be set nonzero by failing ssi's. $resources_printed = ''; @@ -2555,11 +2568,6 @@ ENDPART } } elsif ($cleanURL!~m|^/adm/| && $currentURL=~/\.(sequence|page)$/ && $helper->{'VARS'}->{'construction'} eq '1') { - #printing content of sequence from the construction space - -# FIXME: unclear how this would work - - $currentURL=~s|\/~([^\/]+)\/|\/home\/$1\/public_html\/|; $result .= &print_construction_sequence($currentURL, $helper, %form, $LaTeXwidth); $result .= '\end{document}'; @@ -2721,7 +2729,7 @@ ENDPART $texversion=~s/(\\keephidden{ENDOFPROBLEM})/$answer$1/; } } else { - if ($urlp=~/\.(problem|exam|quiz|assess|survey|form|library|page)$/) { + if ($urlp=~/$LONCAPA::assess_page_re/) { $texversion=&print_latex_header($helper->{'VARS'}->{'LATEX_TYPE'}); # $texversion =~ s/\\begin{document}//; # FIXME my $title = &Apache::lonnet::gettitle($master_seq[$i]); @@ -2892,7 +2900,7 @@ ENDPART ($helper->{'VARS'}->{'PRINT_ANNOTATIONS'} eq 'yes')) { $moreenv{'problem_split'}='yes'; } - my %prog_state=&Apache::lonhtmlcommon::Create_PrgWin($r,'Print Status','Class Print Status',$#students+1,'inline','75'); + my %prog_state=&Apache::lonhtmlcommon::Create_PrgWin($r,$#students+1); my $student_counter=-1; my $i = 0; my $last_section = (split(/:/,$students[0]))[2]; @@ -3007,7 +3015,7 @@ ENDPART $number_per_page=$num_todo > 0 ? $num_todo : 1; } my $flag_latex_header_remove = 'NO'; - my %prog_state=&Apache::lonhtmlcommon::Create_PrgWin($r,'Print Status','Class Print Status',$num_todo,'inline','75'); + my %prog_state=&Apache::lonhtmlcommon::Create_PrgWin($r,$num_todo); my $count=0; foreach my $code (sort(@allcodes)) { my $file_num=int($count/$number_per_page); @@ -3049,11 +3057,7 @@ ENDPART if ($urlp=~/\//) { $form{'problem_split'}=$parmhash{'problem_stream_switch'}; $form{'rndseed'}=$rndseed; - if ($urlp =~ m|/home/([^/]+)/public_html|) { - $urlp =~ s|/home/([^/]*)/public_html|/~$1|; - } else { - $urlp =~ s|^$Apache::lonnet::perlvar{'lonDocRoot'}||; - } + $urlp =~ s|^$Apache::lonnet::perlvar{'lonDocRoot'}||; $resources_printed .= $urlp.':'; my $texversion=&ssi_with_retries($urlp, $ssi_retry_count, %form); if(($helper->{'VARS'}->{'ANSWER_TYPE'} eq 'no') || @@ -3074,19 +3078,16 @@ ENDPART $texversion.='\vskip 0 mm \noindent '; $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}'; } } #this chunk is responsible for printing the path to problem - my $newurlp=$urlp; - if ($newurlp=~/~/) {$newurlp=~s|\/~([^\/]+)\/|\/home\/$1\/public_html\/|;} - $newurlp=&path_to_problem($newurlp,$LaTeXwidth); + my $newurlp=&path_to_problem($urlp,$LaTeXwidth); $texversion =~ s/(\\begin{minipage}{\\textwidth})/$1 $newurlp/; if ($flag_latex_header_remove ne 'NO') { $texversion = &latex_header_footer_remove($texversion); @@ -3135,12 +3136,7 @@ ENDPART my $URLback=''; #link to original document if ($helper->{'VARS'}->{'construction'} eq '1') { - #prints resource from the construction space - $URLback='/'.$helper->{'VARS'}->{'filename'}; - if ($URLback=~/([^?]+)/) { - $URLback=$1; - $URLback=~s|^/~|/priv/|; - } + $URLback=$helper->{'VARS'}->{'filename'}; } # # Final adjustment of the font size: @@ -3148,6 +3144,11 @@ ENDPART $result = set_font_size($result); + # Insert any babel headers required. + + $result = &collect_languages($result); + + #-- writing .tex file in prtspool my $temp_file; my $identifier = &Apache::loncommon::get_cgi_id(); @@ -3287,7 +3288,7 @@ sub print_resources { $print_incomplete = 1; } if ($person eq 'anonymous') { - $namepostfix .="Name: "; + $namepostfix .=&mt('Name:')." "; $fullname = "CODE - ".$moreenv->{'CODE'}; } @@ -3323,7 +3324,7 @@ sub print_resources { $current_output .= &get_extra_vspaces($helper, $curresline); $i++; if ( !($type eq 'problems' && - ($curresline!~ m/\.(problem|exam|quiz|assess|survey|form|library|page)$/)) ) { + ($curresline!~ m/$LONCAPA::assess_page_re/)) ) { my ($map,$id,$res_url) = &Apache::lonnet::decode_symb($curresline); if ($print_incomplete && !&incomplete($username, $userdomain, $res_url)) { next; @@ -3548,12 +3549,7 @@ sub get_randomly_ordered_warning { my $func = sub { return ($_[0]->is_map() && $_[0]->randomorder); }; my @matches = $navmap->retrieveResources($res, $func,1,1,1); - if (@matches) { - $message = "Some of the items below are in folders set to be randomly ordered. However, when printing the contents of these folders, they will be printed in the original order for all students, not the randomized order."; - } - } - if ($message) { - return ''.$message.''; + } } else { $message = "Retrieval of information about ordering of resources failed.";