--- loncom/interface/lonprintout.pm 2006/07/20 03:47:09 1.466 +++ loncom/interface/lonprintout.pm 2007/04/26 09:32:23 1.500 @@ -1,7 +1,8 @@ +# # The LearningOnline Network # Printout # -# $Id: lonprintout.pm,v 1.466 2006/07/20 03:47:09 albertel Exp $ +# $Id: lonprintout.pm,v 1.500 2007/04/26 09:32:23 foxr Exp $ # # Copyright Michigan State University Board of Trustees # @@ -22,7 +23,6 @@ # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA # # /home/httpd/html/adm/gpl.txt -# # http://www.lon-capa.org/ # # @@ -38,17 +38,84 @@ use Apache::grades; use Apache::edit; use Apache::File(); use Apache::lonnavmaps; -use Apache::lonratedt; +use LONCAPA::map(); use POSIX qw(strftime); use Apache::lonlocal; use Carp; -use lib '/home/httpd/lib/perl/'; use LONCAPA; my %perm; my %parmhash; my $resources_printed; +# Fetch the contents of a resource, uninterpreted. +# This is used here to fetch a latex file to be included +# verbatim into the printout< +# NOTE: Ask Guy if there is a lonnet function similar to this? +# +# Parameters: +# URL of the file +# +sub fetch_raw_resource { + my ($url) = @_; + + my $filename = &Apache::lonnet::filelocation("", $url); + my $contents = &Apache::lonnet::getfile($filename); + + if ($contents == -1) { + return "File open failed for $filename"; # This will bomb the print. + } + return $contents; + + +} + +# +# printf_style_subst item format_string repl +# +# Does printf style substitution for a format string that +# can have %[n]item in it.. wherever, %[n]item occurs, +# rep is substituted in format_string. Note that +# [n] is an optional integer length. If provided, +# repl is truncated to at most [n] characters prior to +# substitution. +# +sub printf_style_subst { + my ($item, $format_string, $repl) = @_; + my $result = ""; + while ($format_string =~ /(%)(\d*)\Q$item\E/g ) { + my $fmt = $1; + my $size = $2; + my $subst = $repl; + if ($size ne "") { + $subst = substr($subst, 0, $size); + + # Here's a nice edge case.. supose the end of the + # substring is a \. In that case may have just + # chopped off a TeX escape... in that case, we append + # " " for the trailing character, and let the field + # spill over a bit (sigh). + # We don't just chop off the last character in order to deal + # with one last pathology, and that would be if substr had + # trimmed us to e.g. \\\ + + + if ($subst =~ /\\$/) { + $subst .= " "; + } + } + my $item_pos = pos($format_string); + $result .= substr($format_string, 0, $item_pos - length($size) -2) . $subst; + $format_string = substr($format_string, pos($format_string)); + } + + # Put the residual format string into the result: + + $result .= $format_string; + + return $result; +} + # Format a header according to a format. # @@ -59,17 +126,54 @@ my $resources_printed; # %n - Student name. # sub format_page_header { - my ($format, $assignment, $course, $student) = @_; + my ($width, $format, $assignment, $course, $student) = @_; + $width = &recalcto_mm($width); # Get width in mm. # Default format? if ($format eq '') { + # For the default format, we may need to truncate + # elements.. To do this we need to get the page width. + # we assume that each character is about 2mm in width. + # (correct for the header text size??). We ignore + # any formatting (e.g. boldfacing in this). + # + # - Allow the student/course to be one line. + # but only truncate the course. + # - 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); + } + $format = "\\textbf{$student} $course \\hfill \\thepage \\\\ \\textit{$assignment}"; } else { - $format =~ s/%a/$assignment/g; - $format =~ s/%c/$course/g; - $format =~ s/%n/$student/g; + # 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!!! + + } @@ -93,7 +197,7 @@ sub num_to_letters { sub letters_to_num { my ($letters) = @_; my @letters = split('', uc($letters)); - my %substitution; + my %substitution; my $digit = 0; foreach my $letter ('A'..'J') { $substitution{$letter} = $digit; @@ -408,7 +512,7 @@ sub character_chart { $result =~ s/&\#147;/\`\`/g; $result =~ s/&\#148;/\'\'/g; $result =~ s/&\#149;/\\ensuremath\{\\bullet\}/g; - $result =~ s/&\#150;/--/g; + $result =~ s/&(\#150|\#8211);/--/g; $result =~ s/&\#151;/---/g; $result =~ s/&\#152;/\\ensuremath\{\\sim\}/g; $result =~ s/&\#153;/\\texttrademark /g; @@ -615,6 +719,20 @@ sub character_chart { $result =~ s/&(clubs|\#9827);/\\ensuremath\{\\clubsuit\}/g; $result =~ s/&(hearts|\#9829);/\\ensuremath\{\\heartsuit\}/g; $result =~ s/&(diams|\#9830);/\\ensuremath\{\\diamondsuit\}/g; +# Chemically useful 'things' contributed by Hon Kie (bug 4652). + $result =~ s/&\#8636;/\\ensuremath\{\\leftharpoonup\}/g; + $result =~ s/&\#8637;/\\ensuremath\{\\leftharpoondown\}/g; + $result =~ s/&\#8640;/\\ensuremath\{\\rightharpoonup\}/g; + $result =~ s/&\#8641;/\\ensuremath\{\\rightharpoondown\}/g; + $result =~ s/&\#8652;/\\ensuremath\{\\rightleftharpoons\}/g; + $result =~ s/&\#8605;/\\ensuremath\{\\leadsto\}/g; + $result =~ s/&\#8617;/\\ensuremath\{\\hookleftarrow\}/g; + $result =~ s/&\#8618;/\\ensuremath\{\\hookrightarrow\}/g; + $result =~ s/&\#8614;/\\ensuremath\{\\mapsto\}/g; + $result =~ s/&\#8599;/\\ensuremath\{\\nearrow\}/g; + $result =~ s/&\#8600;/\\ensuremath\{\\searrow\}/g; + $result =~ s/&\#8601;/\\ensuremath\{\\swarrow\}/g; + $result =~ s/&\#8598;/\\ensuremath\{\\nwarrow\}/g; return $result; } @@ -623,12 +741,12 @@ sub character_chart { my %page_formats= ('letter' => { 'book' => { - '1' => [ '7.1 in','9.8 in', '-0.57 in','-0.57 in','0.7 cm'], - '2' => ['3.66 in','9.8 in', '-0.57 in','-0.57 in','0.7 cm'] + '1' => [ '7.1 in','9.8 in', '-0.57 in','-0.57 in','0.275 in'], + '2' => ['3.66 in','9.8 in', '-0.57 in','-0.57 in','0.275 in'] }, 'album' => { - '1' => [ '8.8 in', '6.8 in','-0.55 in', '-0.83 in','1 cm'], - '2' => [ '4.4 in', '6.8 in','-0.5 in', '-1.5 in','3.5 in'] + '1' => [ '8.8 in', '6.8 in','-0.55 in', '-0.55 in','0.394 in'], + '2' => [ '4.8 in', '6.8 in','-0.5 in', '-1.0 in','3.5 in'] }, }, 'legal' => { @@ -683,12 +801,12 @@ my %page_formats= }, 'a4' => { 'book' => { - '1' => ['17.6 cm','27.2 cm','-0.55 in','-0.83 in','-0.5 in'], - '2' => [ '9.1 cm','27.2 cm','-0.55 in','-0.83 in','-0.5 in'] + '1' => ['17.6 cm','27.2 cm','-1.397 cm','-2.11 cm','-1.27 cm'], + '2' => [ '9.1 cm','27.2 cm','-1.397 cm','-2.11 cm','-1.27 cm'] }, 'album' => { - '1' => ['8.5 in','7.7 in','-0.55 in','-0.83 in','0 in'], - '2' => ['3.9 in','7.7 in','-0.55 in','-0.83 in','0 in'] + '1' => ['21.59 cm','19.558 cm','-1.397cm','-2.11 cm','0 cm'], + '2' => ['9.91 cm','19.558 cm','-1.397 cm','-2.11 cm','0 cm'] }, }, 'a5' => { @@ -760,7 +878,7 @@ sub page_format_transformation { my $courseidinfo = &get_course(); if (defined($courseidinfo)) { $courseidinfo=' - '.$courseidinfo } my $header_text = $parmhash{'print_header_format'}; - $header_text = &format_page_header($header_text, $assignment, + $header_text = &format_page_header($textwidth, $header_text, $assignment, $courseidinfo, $name); my $topmargintoinsert = ''; if ($topmargin ne '0') {$topmargintoinsert='\setlength{\topmargin}{'.$topmargin.'}';} @@ -811,6 +929,8 @@ sub details_for_menu { if (!$postdata) { $postdata=$helper->{VARS}{'postdata'}; } my $name_of_resource = &Apache::lonnet::gettitle($postdata); my $symbolic = &Apache::lonnet::symbread($postdata); + return if ( $symbolic eq ''); + my ($map,$id,$resource)=&Apache::lonnet::decode_symb($symbolic); $map=&Apache::lonnet::clutter($map); my $name_of_sequence = &Apache::lonnet::gettitle($map); @@ -826,16 +946,21 @@ sub details_for_menu { return ($name_of_resource,$name_of_sequence,$name_of_map); } +sub copyright_line { + return '\noindent\makebox[\textwidth/$number_of_columns][b]{\hrulefill}\vspace*{-2 mm}\newline\noindent{\tiny Printed from LON-CAPA\copyright MSU{\hfill} Licensed under GNU General Public License } '; +} +my $end_of_student = "\n".'\special{ps:ENDOFSTUDENTSTAMP}'."\n"; sub latex_corrections { my ($number_of_columns,$result,$selectionmade,$answer_mode) = @_; # $result =~ s/\\includegraphics{/\\includegraphics\[width=\\minipagewidth\]{/g; - $result =~ s/\$number_of_columns/$number_of_columns/g; + my $copyright = ©right_line(); if ($selectionmade eq '1' || $answer_mode eq 'only') { - $result =~ s/(\\end{document})/\\strut\\vskip 0 mm\\noindent\\makebox\[\\textwidth\/$number_of_columns\]\[b\]{\\hrulefill}\\newline\\noindent\\tiny Printed from LON-CAPA\\copyright MSU{\\hfill} Licensed under GNU General Public License $1/; + $result =~ s/(\\end{document})/\\strut\\vskip 0 mm $copyright $end_of_student $1/; } else { - $result =~ s/(\\end{document})/\\strut\\vspace\*{-4 mm}\\newline\\noindent\\makebox\[\\textwidth\/$number_of_columns\]\[b\]{\\hrulefill}\\newline\\noindent\\tiny Printed from LON-CAPA\\copyright MSU{\\hfill} Licensed under GNU General Public License $1/; + $result =~ s/(\\end{document})/\\strut\\vspace\*{-4 mm}\\newline $copyright $end_of_student $1/; } + $result =~ s/\$number_of_columns/$number_of_columns/g; $result =~ s/(\\end{longtable}\s*)(\\strut\\newline\\noindent\\makebox\[\\textwidth\/$number_of_columns\]\[b\]{\\hrulefill})/$2$1/g; $result =~ s/(\\end{longtable}\s*)\\strut\\newline/$1/g; #-- LaTeX corrections @@ -892,7 +1017,7 @@ sub IndexCreation { sub print_latex_header { my $mode=shift; - my $output='\documentclass[letterpaper,twoside]{article}'; + my $output='\documentclass[letterpaper,twoside]{article}\raggedbottom'; if (($mode eq 'batchmode') || (!$perm{'pav'})) { $output.='\batchmode'; } @@ -1076,12 +1201,12 @@ sub print_construction_sequence { if ($helper->{'VARS'}->{'curseed'}) { $rndseed=$helper->{'VARS'}->{'curseed'}; } - my $errtext=&Apache::lonratedt::mapread($currentURL); + my $errtext=&LONCAPA::map::mapread($currentURL); # # These make this all support recursing for subsequences. # - my @order = @Apache::lonratedt::order; - my @resources = @Apache::lonratedt::resources; + my @order = @LONCAPA::map::order; + my @resources = @LONCAPA::map::resources; for (my $member=0;$member<=$#order;$member++) { $resources[$order[$member]]=~/^([^:]*):([^:]*):/; my $urlp=$2; @@ -1113,7 +1238,9 @@ sub print_construction_sequence { # If necessary, encapsulate answer in minipage: $texversion=&print_latex_header($helper->{'VARS'}->{'LATEX_TYPE'}); - my $body ='\vskip 0 mm \noindent\textbf{'.&Apache::lonnet::gettitle($helper->{'VARS'}->{'symb'}).'}\vskip 0 mm '; + my $title = &Apache::lonnet::gettitle($helper->{'VARS'}->{'symb'}); + $title = &Apache::lonxml::latex_special_symbols($title); + my $body ='\vskip 0 mm \noindent\textbf{'.$title.'}\vskip 0 mm '; $body.=&path_to_problem($urlp,$LaTeXwidth); $body.='\vskip 1 mm '.$answer.'\end{document}'; $body = &encapsulate_minipage($body); @@ -1160,6 +1287,7 @@ sub output_data { my ($r,$helper,$rparmhash) = @_; my %parmhash = %$rparmhash; $resources_printed = ''; + my $do_postprocessing = 1; my $js = < var editbrowser; @@ -1308,7 +1436,9 @@ ENDPART } else { $texversion=&print_latex_header($helper->{'VARS'}->{'LATEX_TYPE'}); if ($helper->{'VARS'}->{'construction'} ne '1') { - $texversion.='\vskip 0 mm \noindent\textbf{'.&Apache::lonnet::gettitle($helper->{'VARS'}->{'symb'}).'}\vskip 0 mm '; + my $title = &Apache::lonnet::gettitle($helper->{'VARS'}->{'symb'}); + $title = &Apache::lonxml::latex_special_symbols($title); + $texversion.='\vskip 0 mm \noindent\textbf{'.$title.'}\vskip 0 mm '; $texversion.=&path_to_problem($cleanURL,$LaTeXwidth); } else { $texversion.='\vskip 0 mm \noindent\textbf{Prints from construction space - there is no title.}\vskip 0 mm '; @@ -1348,6 +1478,14 @@ ENDPART $resources_printed .= $currentURL.':'; my $texversion=&Apache::lonnet::ssi($currentURL,%form); $result .= $texversion; + } elsif ($cleanURL =~/.tex$/) { + # For this sort of print of a single LaTeX file, + # We can just print the LaTeX file as it is uninterpreted in any way: + # + + $result = &fetch_raw_resource($currentURL); + $do_postprocessing = 0; # Don't massage the result. + } else { $result.=&unsupported($currentURL,$helper->{'VARS'}->{'LATEX_TYPE'}, $helper->{'VARS'}->{'symb'}); @@ -1429,7 +1567,9 @@ ENDPART } else { if ($urlp=~/\.(problem|exam|quiz|assess|survey|form|library)$/) { $texversion=&print_latex_header($helper->{'VARS'}->{'LATEX_TYPE'}); - my $body ='\vskip 0 mm \noindent\textbf{'.&Apache::lonnet::gettitle($master_seq[$i]).'}\vskip 0 mm '; + my $title = &Apache::lonnet::gettitle($master_seq[$i]); + $title = &Apache::lonxml::latex_special_symbols($title); + my $body ='\vskip 0 mm \noindent\textbf{'.$title.'}\vskip 0 mm '; $body .= &path_to_problem ($urlp,$LaTeXwidth); $body .='\vskip 1 mm '.$answer; $body = &encapsulate_minipage($body); @@ -1453,7 +1593,7 @@ ENDPART if (defined($courseidinfo)) { $courseidinfo=' - '.$courseidinfo } $prevassignment=$assignment; my $header_text = $parmhash{'print_header_format'}; - $header_text = &format_page_header($header_text, + $header_text = &format_page_header($textwidth, $header_text, $assignment, $courseidinfo, $name); @@ -1750,21 +1890,20 @@ ENDPART $result .= '\end{document}'; } #-------------------------------------------------------- corrections for the different page formats - $result = &page_format_transformation($papersize,$laystyle,$numberofcolumns,$helper->{'VARS'}->{'PRINT_TYPE'},$result,$helper->{VARS}->{'assignment'},$helper->{'VARS'}->{'TABLE_CONTENTS'},$helper->{'VARS'}->{'TABLE_INDEX'},$selectionmade); - $result = &latex_corrections($number_of_columns,$result,$selectionmade, - $helper->{'VARS'}->{'ANSWER_TYPE'}); - for (my $i=1;$i<=$#print_array;$i++) { - $print_array[$i] = - &latex_corrections($number_of_columns,$print_array[$i], - $selectionmade, - $helper->{'VARS'}->{'ANSWER_TYPE'}); - } - #if ($numberofcolumns == 1) { + + # Only post process if that has not been turned off e.g. by a raw latex resource. + + if ($do_postprocessing) { + $result = &page_format_transformation($papersize,$laystyle,$numberofcolumns,$helper->{'VARS'}->{'PRINT_TYPE'},$result,$helper->{VARS}->{'assignment'},$helper->{'VARS'}->{'TABLE_CONTENTS'},$helper->{'VARS'}->{'TABLE_INDEX'},$selectionmade); + $result = &latex_corrections($number_of_columns,$result,$selectionmade, + $helper->{'VARS'}->{'ANSWER_TYPE'}); + #if ($numberofcolumns == 1) { $result =~ s/\\textwidth\s*=\s*-?\d*\.?\d*\s*(cm|mm|in)/\\textwidth= $helper->{'VARS'}->{'pagesize.width'} $helper->{'VARS'}->{'pagesize.widthunit'} /; $result =~ s/\\textheight\s*=?\s*-?\d*\.?\d*\s*(cm|mm|in)/\\textheight $helper->{'VARS'}->{'pagesize.height'} $helper->{'VARS'}->{'pagesize.heightunit'} /; $result =~ s/\\evensidemargin\s*=\s*-?\d*\.?\d*\s*(cm|mm|in)/\\evensidemargin= $helper->{'VARS'}->{'pagesize.lmargin'} $helper->{'VARS'}->{'pagesize.lmarginunit'} /; $result =~ s/\\oddsidemargin\s*=\s*-?\d*\.?\d*\s*(cm|mm|in)/\\oddsidemargin= $helper->{'VARS'}->{'pagesize.lmargin'} $helper->{'VARS'}->{'pagesize.lmarginunit'} /; - #} + #} + } #-- writing .tex file in prtspool my $temp_file; @@ -1785,9 +1924,15 @@ ENDPART 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].'\end{document}'; + $print_array[$i]=$inc.$print_array[$i]; } my $temp_file; my $newfilename=$filename; @@ -1884,9 +2029,9 @@ sub print_resources { my $printed = ''; my ($username,$userdomain,$usersection) = split /:/,$person; my $fullname = &get_name($username,$userdomain); - my $namepostfix; + my $namepostfix = "\\\\"; # Both anon and not anon should get the same vspace. if ($person =~ 'anon') { - $namepostfix="\\\\Name: "; + $namepostfix .="Name: "; $fullname = "CODE - ".$moreenv->{'CODE'}; } # Fullname may have special latex characters that need \ prefixing: @@ -1898,8 +2043,7 @@ sub print_resources { &Apache::lonxml::clear_problem_counter(); my %page_breaks = &get_page_breaks($helper); - my @format_array = split(/\|/,$helper->{'VARS'}->{'FORMAT'}); - my $columns_in_format = $format_array[1]; + my $columns_in_format = (split(/\|/,$helper->{'VARS'}->{'FORMAT'}))[1]; # # end each student with a # Special that allows the post processor to even out the page @@ -1947,8 +2091,10 @@ sub print_resources { my $header =&print_latex_header($helper->{'VARS'}->{'LATEX_TYPE'}); - my $body ='\vskip 0 mm \noindent\textbf{'.&Apache::lonnet::gettitle($curresline).'}\vskip 0 mm '; - $body .=&path_to_problem($res_url,$LaTeXwidth); + my $title = &Apache::lonnet::gettitle($curresline); + $title = &Apache::lonxml::latex_special_symbols($title); + my $body ='\vskip 0 mm \noindent\textbf{'.$title.'}\vskip 0 mm '; + $body .=&path_to_problem($res_url,$LaTeXwidth); $body .='\vskip 1 mm '.$ansrendered; $body = &encapsulate_minipage($body); $rendered = $header.$body; @@ -1989,28 +2135,27 @@ sub print_resources { if (defined($courseidinfo)) { $courseidinfo=' - '.$courseidinfo } if ($usersection ne '') {$courseidinfo.=' - Sec. '.$usersection} my $currentassignment=&Apache::lonxml::latex_special_symbols($helper->{VARS}->{'assignment'},'header'); - my $HeaderLine = $parmhash{'print_header_format'}; - $HeaderLine = format_page_header($HeaderLine, $currentassignment, $courseidinfo, $fullname); - if ($current_output=~/\\documentclass/) { - if ($columns_in_format == 1) { - $current_output =~ s/\\begin{document}/\\setlength{\\topmargin}{1cm} \\begin{document}\\noindent\\parbox{\\minipagewidth}{\\noindent\\lhead{$HeaderLine$namepostfix}}\\vskip 5 mm /; - } else { - $current_output =~ s/\\begin{document}/\\setlength{\\topmargin}{1cm} \\begin{document}\\noindent\\parbox{\\minipagewidth}{\\noindent\\fancyhead[LO]{$HeaderLine$namepostfix}}\\vskip 5 mm /; + my $header_line = + &format_page_header($LaTeXwidth, $parmhash{'print_header_format'}, + $currentassignment, $courseidinfo, $fullname); + my $header_start = ($columns_in_format == 1) ? '\lhead' + : '\fancyhead[LO]'; + $header_line = $header_start.'{'.$header_line.'}'; - } + if ($current_output=~/\\documentclass/) { + $current_output =~ s/\\begin{document}/\\setlength{\\topmargin}{1cm} \\begin{document}\\noindent\\parbox{\\minipagewidth}{\\noindent$header_line$namepostfix}\\vskip 5 mm /; } else { - my $blankpages = ''; - for (my $j=0;$j<$helper->{'VARS'}->{'EMPTY_PAGES'};$j++) {$blankpages.='\clearpage\strut\clearpage';} - if ($columns_in_format == 1) { - $current_output = '\strut\vspace*{-6 mm}\\newline\\noindent\\makebox[\\textwidth/$number_of_columns][b]{\\hrulefill}\vspace*{-2 mm}\\newline\\noindent{\\tiny Printed from LON-CAPA\\copyright MSU{\\hfill} Licensed under GNU General Public License }\\newpage '.$blankpages.'\setcounter{page}{1}\noindent\parbox{\minipagewidth}{\noindent\\lhead{'.$HeaderLine.'}'.$namepostfix.'} \vskip 5 mm '.$current_output; - } else { - $current_output = '\strut\vspace*{-6 mm}\\newline\\noindent\\makebox[\\textwidth/$number_of_columns][b]{\\hrulefill}\vspace*{-2 mm}\\newline\\noindent{\\tiny Printed from LON-CAPA\\copyright MSU{\\hfill} Licensed under GNU General Public License }\\newpage '.$blankpages.'\setcounter{page}{1}\noindent\parbox{\minipagewidth}{\noindent\\fancyhead[LO]{'.$HeaderLine.'}'.$namepostfix.'} \vskip 5 mm '.$current_output; - } + my $blankpages = + '\clearpage\strut\clearpage'x$helper->{'VARS'}->{'EMPTY_PAGES'}; + + $current_output = '\strut\vspace*{-6 mm}\\newline'. + ©right_line().' \newpage '.$blankpages.$end_of_student. + '\setcounter{page}{1}\noindent\parbox{\minipagewidth}{\noindent'. + $header_line.$namepostfix.'} \vskip 5 mm '.$current_output; } # # Close the student bracketing. # - $current_output .= "\n\\special{ps:ENDOFSTUDENTSTAMP}\n"; return ($current_output,$fullname, $printed); } @@ -2112,6 +2257,7 @@ sub printHelper { $helper->declareVar('FINISHPAGE'); $helper->declareVar('PRINT_TYPE'); $helper->declareVar("showallfoils"); + $helper->declareVar("STUDENTS"); # The page breaks can get loaded initially from the course environment: # But we only do this in the initial state so that they are allowed to change. @@ -2123,6 +2269,8 @@ sub printHelper { {'pagebreaks' => 'scalar', 'lastprinttype' => 'scalar'}); + # This will persistently load in the data we want from the + # very first screen. if($helper->{VARS}->{PRINT_TYPE} eq $env{'form.lastprinttype'}) { if (!defined ($env{"form.CURRENT_STATE"})) { @@ -2137,9 +2285,7 @@ sub printHelper { } - - # This will persistently load in the data we want from the - # very first screen. + # Detect whether we're coming from construction space if ($env{'form.postdata'}=~/^(?:http:\/\/[^\/]+\/|\/|)\~([^\/]+)\/(.*)$/) { $helper->{VARS}->{'filename'} = "~$1/$2"; @@ -2147,6 +2293,9 @@ sub printHelper { } else { if ($env{'form.postdata'}) { $helper->{VARS}->{'symb'} = &Apache::lonnet::symbread($env{'form.postdata'}); + if ( $helper->{VARS}->{'symb'} eq '') { + $helper->{VARS}->{'postdata'} = $env{'form.postdata'}; + } } if ($env{'form.symb'}) { $helper->{VARS}->{'symb'} = $env{'form.symb'}; @@ -2174,6 +2323,7 @@ sub printHelper { my $symb = $helper->{VARS}->{'symb'}; my ($map, $id, $url); my $subdir; + my $is_published=0; # True when printing from resource space. # Get the resource name from construction space if ($helper->{VARS}->{'construction'}) { @@ -2182,9 +2332,15 @@ sub printHelper { $subdir = substr($helper->{VARS}->{'filename'}, 0, rindex($helper->{VARS}->{'filename'}, '/') + 1); } else { - ($map, $id, $url) = &Apache::lonnet::decode_symb($symb); - $helper->{VARS}->{'postdata'} = - &Apache::lonenc::check_encrypt(&Apache::lonnet::clutter($url)); + if ($symb ne '') { + ($map, $id, $url) = &Apache::lonnet::decode_symb($symb); + $helper->{VARS}->{'postdata'} = + &Apache::lonenc::check_encrypt(&Apache::lonnet::clutter($url)); + } else { + $url = $helper->{VARS}->{'postdata'}; + $is_published=1; # From resource space. + } + $url = &Apache::lonnet::clutter($url); if (!$resourceTitle) { # if the resource doesn't have a title, use the filename my $postdata = $helper->{VARS}->{'postdata'}; @@ -2205,11 +2361,6 @@ sub printHelper { # "Delete everything after the last slash." $subdir =~ s|/[^/]+$||; - if (not $helper->{VARS}->{'construction'}) { - $subdir=$Apache::lonnet::perlvar{'lonDocRoot'}.'/res/'.$subdir; - } - # "Remove all duplicate slashes." - $subdir =~ s|/+|/|g; # What can be printed is a very dynamic decision based on # lots of factors. So we need to dynamically build this list. @@ -2250,7 +2401,7 @@ sub printHelper { "' variable='FINISHPAGE' />"; } - if (($helper->{'VARS'}->{'construction'} ne '1') && + if (($helper->{'VARS'}->{'construction'} ne '1' ) && $helper->{VARS}->{'postdata'} && $helper->{VARS}->{'assignment'}) { @@ -2288,7 +2439,7 @@ HELPERFRAGMENT # If the user has pfo (print for otheres) allow them to print all # problems and resources in the entier course, optionally for selected students - if ($perm{'pfo'} && + if ($perm{'pfo'} && !$is_published && ($helper->{VARS}->{'postdata'}=~/\/res\// || $helper->{VARS}->{'postdata'}=~/\/(syllabus|smppg|aboutme|bulletinboard)$/)) { push @{$printChoices}, ['Selected Problems from entire course', 'all_problems', 'ALL_PROBLEMS']; @@ -2316,8 +2467,8 @@ HELPERFRAGMENT ALL_PROBLEMS if ($helper->{VARS}->{'assignment'}) { - push @{$printChoices}, [&mt("Selected Problems from folder [_1] for selected students",$sequenceTitle), 'problems_for_students', 'CHOOSE_STUDENTS']; - push @{$printChoices}, [&mt("Selected Problems from folder [_1] for anonymous students",$sequenceTitle), 'problems_for_anon', 'CHOOSE_ANON1']; + push @{$printChoices}, [&mt("Selected Problems from folder [_1] for selected people",$sequenceTitle), 'problems_for_students', 'CHOOSE_STUDENTS']; + push @{$printChoices}, [&mt("Selected Problems from folder [_1] for CODEd assignments",$sequenceTitle), 'problems_for_anon', 'CHOOSE_ANON1']; } # resource_selector will hold a few states that: @@ -2363,7 +2514,7 @@ RESOURCE_SELECTOR &Apache::lonxml::xmlparse($r, 'helper', < - Select sort order + Select sorting order of printout Sort by section then student Sort by students across sections. @@ -2404,7 +2555,7 @@ CHOOSE_STUDENTS } if (%codes_to_print) { $code_selection .=' - Choose single code from list + Choose single CODE from list: @@ -2412,7 +2563,7 @@ CHOOSE_STUDENTS push(@{$state->{CHOICES}},@{$helper->{DATA}{ALL_CODE_CHOICES}}); -
+ '.$/; } @@ -2432,9 +2583,12 @@ CHOOSE_STUDENTS $codechoice='Default'; } &Apache::lonxml::xmlparse($r, 'helper', < + SELECT_PROBLEMS -
Number of anonymous assignments to print: +

Fill out one of the forms below

+


+

Generate new CODEd Assignments

+
Number of CODEd assignments to print: if (((\$helper->{'VARS'}{'NUMBER_TO_PRINT_TOTAL'}+0) < 1) && @@ -2456,9 +2610,10 @@ CHOOSE_STUDENTS $codechoice -

-
- Enter a CODE to print: +
+
+

Print a Specific CODE


+
Enter a CODE to print: if(!\$helper->{'VARS'}{'NUMBER_TO_PRINT_TOTAL'} && @@ -2471,25 +2626,24 @@ CHOOSE_STUDENTS } -

+
$code_selection - - - Reprint a set of saved CODEs: +
+

Reprint a Set of Saved CODEs

+ Select saved CODEs: $namechoice
-
$resource_selector CHOOSE_ANON1 if ($helper->{VARS}->{'assignment'}) { - push @{$printChoices}, [&mt("Selected Resources from folder [_1] for selected students",$sequenceTitle), 'resources_for_students', 'CHOOSE_STUDENTS1']; - push @{$printChoices}, [&mt("Selected Resources from folder [_1] for anonymous students",$sequenceTitle), 'resources_for_anon', 'CHOOSE_ANON2']; + push @{$printChoices}, [&mt("Selected Resources from folder [_1] for selected people",$sequenceTitle), 'resources_for_students', 'CHOOSE_STUDENTS1']; + push @{$printChoices}, [&mt("Selected Resources from folder [_1] for CODEd assignments",$sequenceTitle), 'resources_for_anon', 'CHOOSE_ANON2']; } @@ -2540,9 +2694,12 @@ RESOURCE_SELECTOR CHOOSE_STUDENTS1 &Apache::lonxml::xmlparse($r, 'helper', < + SELECT_RESOURCES -
Number of anonymous assignments to print: +

Fill out one of the forms below

+


+

Generate new CODEd Assignments

+
Number of CODEd assignments to print: if (((\$helper->{'VARS'}{'NUMBER_TO_PRINT_TOTAL'}+0) < 1) && @@ -2564,9 +2721,9 @@ CHOOSE_STUDENTS1 $codechoice -

-
- Enter a CODE to print: +
+

Print a Specific CODE


+
Enter a CODE to print: if(!\$helper->{'VARS'}{'NUMBER_TO_PRINT_TOTAL'} && @@ -2579,27 +2736,37 @@ CHOOSE_STUDENTS1 } -

+
$code_selection - Reprint a set of saved CODEs: +
+

Reprint a Set of Saved CODEs

+ Select saved CODEs: $namechoice
-
$resource_selector CHOOSE_ANON2 } # FIXME: That RE should come from a library somewhere. - if ((((&Apache::lonnet::allowed('bre',$subdir) eq 'F') and ($helper->{VARS}->{'postdata'}=~/\.(problem|exam|quiz|assess|survey|form|library|page|xml|html|htm|xhtml|xhtm)/)) or defined $helper->{'VARS'}->{'construction'}) and $perm{'pav'} and $subdir ne $Apache::lonnet::perlvar{'lonDocRoot'}.'/res/') { - push @{$printChoices}, [&mt("Selected Problems from current subdirectory [_1]",$subdir), 'problems_from_directory', 'CHOOSE_FROM_SUBDIR']; + if (($perm{'pav'} + && $subdir ne $Apache::lonnet::perlvar{'lonDocRoot'}.'/res/' + && (defined($helper->{'VARS'}->{'construction'}) + || + (&Apache::lonnet::allowed('bre',$subdir) eq 'F' + && + $helper->{VARS}->{'postdata'}=~/\.(problem|exam|quiz|assess|survey|form|library|page|xml|html|htm|xhtml|xhtm)/) + )) + && $helper->{VARS}->{'assignment'} eq "" + ) { - my $f = '$filename'; + my $pretty_dir = &Apache::lonnet::hreflocation($subdir); + push @{$printChoices}, [&mt("Selected Problems from current subdirectory [_1]",$pretty_dir), 'problems_from_directory', 'CHOOSE_FROM_SUBDIR']; my $xmlfrag = < + PAGESIZE @@ -2620,7 +2787,7 @@ CHOOSE_FROM_SUBDIR # Allow the user to select any sequence in the course, feed it to # another resource selector for that sequence - if (!$helper->{VARS}->{'construction'}) { + if (!$helper->{VARS}->{'construction'} && !$is_published) { push @$printChoices, ["Selected Resources from selected folder in course", 'select_sequences', 'CHOOSE_SEQUENCE']; my $escapedSequenceName = $helper->{VARS}->{'SEQUENCE'}; @@ -2667,7 +2834,10 @@ CHOOSE_FROM_ANY_SEQUENCE if (($perm{'pav'} and &Apache::lonnet::allowed('vgr',$env{'request.course.id'})) or ($helper->{VARS}->{'construction'} eq '1')) { - addMessage("
Print: "); + addMessage("
". + ': "); $paramHash = Apache::lonhelper::getParamHash(); $paramHash->{'variable'} = 'ANSWER_TYPE'; $helper->declareVar('ANSWER_TYPE'); @@ -2683,10 +2853,16 @@ CHOOSE_FROM_ANY_SEQUENCE if ($perm{'pav'}) { if (!$startedTable) { - addMessage("
LaTeX mode: "); + addMessage("
"); if (not $helper->{VARS}->{'construction'}) { - addMessage(""); - addMessage("
". + ': "); $startedTable = 1; } else { - addMessage("
LaTeX mode: "); + addMessage("
". + ': "); } $paramHash = Apache::lonhelper::getParamHash(); $paramHash->{'variable'} = 'LATEX_TYPE'; @@ -2702,7 +2878,10 @@ CHOOSE_FROM_ANY_SEQUENCE } Apache::lonhelper::dropdown->new(); - addMessage("
Print Table of Contents: "); + addMessage("
". + ''. + &mt('Print Table of Contents'). + ": "); $paramHash = Apache::lonhelper::getParamHash(); $paramHash->{'variable'} = 'TABLE_CONTENTS'; $helper->declareVar('TABLE_CONTENTS'); @@ -2713,7 +2892,10 @@ CHOOSE_FROM_ANY_SEQUENCE addMessage("
Print Index: "); + addMessage("
". + ': "); $paramHash = Apache::lonhelper::getParamHash(); $paramHash->{'variable'} = 'TABLE_INDEX'; $helper->declareVar('TABLE_INDEX'); @@ -2722,7 +2904,10 @@ CHOOSE_FROM_ANY_SEQUENCE ['Yes', 'yes'] ]; Apache::lonhelper::dropdown->new(); addMessage("
Print Discussions: "); + addMessage("
". + ': "); $paramHash = Apache::lonhelper::getParamHash(); $paramHash->{'variable'} = 'PRINT_DISCUSSIONS'; $helper->declareVar('PRINT_DISCUSSIONS'); @@ -2744,14 +2929,21 @@ CHOOSE_FROM_ANY_SEQUENCE if ($helper->{'VARS'}->{'construction'}) { my $stylevalue=$env{'construct.style'}; + my $randseedtext=&mt("Use random seed"); + my $stylefiletext=&mt("Use style file"); + my $xmlfrag .= <<"RNDSEED"; -
Use random seed: +
+ : + return $helper->{VARS}->{'curseed'}; -
Use style file: +
+ : +   Select style file
Show all foils? @@ -2975,6 +3167,7 @@ sub new { $self->{NEXTSTATE} = shift; bless($self); + return $self; } @@ -2984,6 +3177,8 @@ sub render { my $result = ''; my $var = $self->{'variable'}; + + if (defined $self->{ERROR_MSG}) { $result .= '
' . $self->{ERROR_MSG} . '
'; } @@ -3023,9 +3218,16 @@ sub render { } } - $result .= <How should each column be formatted?

@@ -3067,12 +3269,50 @@ ELEMENTHTML return $result; } -# If the user didn't select 1 column, skip this state. + sub preprocess { my $self = shift; my $helper = Apache::lonhelper::getHelper(); my $format = $helper->{VARS}->{$self->{'formatvar'}}; + + # If the user does not have 'pav' privilege, set default widths and + # on to the next state right away. + # + if (!$perm{'pav'}) { + my $var = $self->{'variable'}; + my $format = $helper->{VARS}->{$self->{'formatvar'}}; + + my ($laystyle, $cols, $papersize) = split(/\|/, $format); + ($papersize) = split(/ /, $papersize); + + + if ($laystyle eq 'L') { + $laystyle = 'album'; + } else { + $laystyle = 'book'; + } + # Figure out some good defaults for the print out and set them: + + my %size; + ($size{'width'}, + $size{'height'}, + $size{'lmargin'})= + &Apache::lonprintout::page_format($papersize, $laystyle, $cols); + + foreach my $dim ('width', 'height', 'lmargin') { + my ($value, $units) = split(/ /, $size{$dim}); + + $helper->{VARS}->{"$var.".$dim} = $value; + $helper->{VARS}->{"$var.".$dim.'unit'} = $units; + + } + + + # Transition to the next state + + $helper->changeState($self->{NEXTSTATE}); + } return 1; } @@ -3102,6 +3342,14 @@ sub postprocess { } if ($lmargin !~ /^-?[0-9]*(\.[0-9]*)?$/) { $error .= "Invalid left margin; please type only a number.
\n"; + } else { + # Adjust for LaTeX 1.0 inch margin: + + if ($env{"form.${var}.lmarginunit"} eq "in") { + $helper->{VARS}->{$var.'.lmargin'} = $lmargin - 1; + } else { + $helper->{VARS}->{$var.'.lmargin'} = $lmargin - 2.54; + } } if (!$error) {