--- loncom/interface/lonprintout.pm 2006/02/24 22:37:45 1.423 +++ loncom/interface/lonprintout.pm 2006/07/18 18:19:51 1.464 @@ -1,7 +1,7 @@ # The LearningOnline Network # Printout # -# $Id: lonprintout.pm,v 1.423 2006/02/24 22:37:45 foxr Exp $ +# $Id: lonprintout.pm,v 1.464 2006/07/18 18:19:51 albertel Exp $ # # Copyright Michigan State University Board of Trustees # @@ -41,8 +41,41 @@ use Apache::lonnavmaps; use Apache::lonratedt; use POSIX qw(strftime); use Apache::lonlocal; +use Carp; +use lib '/home/httpd/lib/perl/'; +use LONCAPA; my %perm; +my %parmhash; +my $resources_printed; + + +# Format a header according to a format. +# + +# Substitutions: +# %a - Assignment name. +# %c - Course name. +# %n - Student name. +# +sub format_page_header { + my ($format, $assignment, $course, $student) = @_; + + # Default format? + + if ($format eq '') { + $format = "\\textbf{$student} $course \\hfill \\thepage \\\\ \\textit{$assignment}"; + + } else { + $format =~ s/%a/$assignment/g; + $format =~ s/%c/$course/g; + $format =~ s/%n/$student/g; + } + + + return $format; + +} # # Convert a numeric code to letters @@ -233,12 +266,39 @@ sub latex_header_footer_remove { # sub encapsulate_minipage { my ($text) = @_; - if (!(env{'form.problem.split'} =~ /yes/i)) { + if (!($env{'form.problem.split'} =~ /yes/i)) { $text = '\begin{minipage}{\textwidth}'.$text.'\end{minipage}'; } return $text; } +# +# The NUMBER_TO_PRINT and SPLIT_PDFS +# variables interact, this sub looks at these two parameters +# and comes up with a final value for NUMBER_TO_PRINT which can be: +# all - if SPLIT_PDFS eq 'all'. +# 1 - if SPLIT_PDFS eq 'oneper' +# section - if SPLIT_PDFS eq 'sections' +# - if SPLIT_PDFS eq 'usenumber' +# +sub adjust_number_to_print { + my $helper = shift; + my $split_pdf = $helper->{'VARS'}->{'SPLIT_PDFS'}; + + if ($split_pdf eq 'all') { + $helper->{'VARS'}->{'NUMBER_TO_PRINT'} = 'all'; + } elsif ($split_pdf eq 'oneper') { + $helper->{'VARS'}->{'NUMBER_TO_PRINT'} = 1; + } elsif ($split_pdf eq 'sections') { + $helper->{'VARS'}->{'NUMBER_TO_PRINT'} = 'section'; + } elsif ($split_pdf eq 'usenumber') { + # Unmodified. + } else { + # Error!!!! + + croak "bad SPLIT_PDFS: $split_pdf in lonprintout::adjust_number_to_print"; + } +} sub character_chart { my $result = shift; @@ -567,7 +627,7 @@ my %page_formats= '2' => ['3.66 in','9.8 in', '-0.57 in','-0.57 in','0.7 cm'] }, 'album' => { - '1' => [ '8.8 in', '6.8 in','-40 pt in', '-60 pt','1 cm'], + '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'] }, }, @@ -623,12 +683,12 @@ my %page_formats= }, 'a4' => { 'book' => { - '1' => ['176 mm','272 mm','-40 pt in','-60 pt','-0.5 in'], - '2' => [ '91 mm','272 mm','-40 pt in','-60 pt','-0.5 in'] + '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'] }, 'album' => { - '1' => ['8.5 in','7.7 in','-40 pt in','-60 pt','0 in'], - '2' => ['3.9 in','7.7 in','-40 pt in','-60 pt','0 in'] + '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'] }, }, 'a5' => { @@ -672,14 +732,14 @@ sub get_name { if (!defined($udom)) { $udom=$env{'user.domain'}; } my $plainname=&Apache::loncommon::plainname($uname,$udom); if ($plainname=~/^\s*$/) { $plainname=$uname.'@'.$udom; } - $plainname=&Apache::lonxml::latex_special_symbols($plainname,'header'); + $plainname=&Apache::lonxml::latex_special_symbols($plainname,'header'); return $plainname; } sub get_course { my $courseidinfo; if (defined($env{'request.course.id'})) { - $courseidinfo = &Apache::lonxml::latex_special_symbols(&Apache::lonnet::unescape($env{'course.'.$env{'request.course.id'}.'.description'}),'header'); + $courseidinfo = &Apache::lonxml::latex_special_symbols(&unescape($env{'course.'.$env{'request.course.id'}.'.description'}),'header'); } return $courseidinfo; } @@ -687,22 +747,28 @@ sub get_course { sub page_format_transformation { my ($papersize,$layout,$numberofcolumns,$choice,$text,$assignment,$tableofcontents,$indexlist,$selectionmade) = @_; my ($textwidth,$textheight,$oddoffset,$evenoffset,$topmargin); + if ($selectionmade eq '4') { $assignment='Problems from the Whole Course'; } else { $assignment=&Apache::lonxml::latex_special_symbols($assignment,'header'); } ($textwidth,$textheight,$oddoffset,$evenoffset,$topmargin) = &page_format($papersize,$layout,$numberofcolumns,$topmargin); + + 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($header_text, $assignment, + $courseidinfo, $name); my $topmargintoinsert = ''; if ($topmargin ne '0') {$topmargintoinsert='\setlength{\topmargin}{'.$topmargin.'}';} my $fancypagestatement=''; if ($numberofcolumns eq '2') { - $fancypagestatement="\\fancyhead{}\\fancyhead[LO]{\\textbf{$name} $courseidinfo \\hfill \\thepage \\\\ \\textit{$assignment}}"; + $fancypagestatement="\\fancyhead{}\\fancyhead[LO]{$header_text}"; } else { - $fancypagestatement="\\rhead{}\\chead{}\\lhead{\\textbf{$name} $courseidinfo \\hfill \\thepage \\\\ \\textit{$assignment}}"; + $fancypagestatement="\\rhead{}\\chead{}\\lhead{$header_text}"; } if ($layout eq 'album') { $text =~ s/\\begin{document}/\\setlength{\\oddsidemargin}{$oddoffset}\\setlength{\\evensidemargin}{$evenoffset}$topmargintoinsert\n\\setlength{\\textwidth}{$textwidth}\\setlength{\\textheight}{$textheight}\\setlength{\\textfloatsep}{8pt plus 2\.0pt minus 4\.0pt}\n\\newlength{\\minipagewidth}\\setlength{\\minipagewidth}{\\textwidth\/\$number_of_columns-0\.2cm}\\usepackage{fancyhdr}\\addtolength{\\headheight}{\\baselineskip}\n\\pagestyle{fancy}$fancypagestatement\\begin{document}\\voffset=-0\.8 cm\\setcounter{page}{1}\n /; @@ -990,16 +1056,112 @@ sub get_page_breaks { return %page_breaks; } +# Output a sequence (recursively if neeed) +# from construction space. +# Parameters: +# url = URL of the sequence to print. +# helper - Reference to the helper hash. +# form - Copy of the format hash. +# LaTeXWidth +# Returns: +# Text to add to the printout. +# NOTE if the first element of the outermost sequence +# is itself a sequence, the outermost caller may need to +# prefix the latex with the page headers stuff. +# +sub print_construction_sequence { + my ($currentURL, $helper, %form, $LaTeXwidth) = @_; + my $result; + my $rndseed=time; + if ($helper->{'VARS'}->{'curseed'}) { + $rndseed=$helper->{'VARS'}->{'curseed'}; + } + my $errtext=&Apache::lonratedt::mapread($currentURL); + # + # These make this all support recursing for subsequences. + # + my @order = @Apache::lonratedt::order; + my @resources = @Apache::lonratedt::resources; + for (my $member=0;$member<=$#order;$member++) { + $resources[$order[$member]]=~/^([^:]*):([^:]*):/; + my $urlp=$2; + if ($urlp=~/\.(problem|exam|quiz|assess|survey|form|library|xml|html|htm|xhtml|xhtm)$/) { + my $texversion=''; + if ($helper->{'VARS'}->{'ANSWER_TYPE'} ne 'only') { + $form{'problem_split'}=$parmhash{'problem_stream_switch'}; + $form{'suppress_tries'}=$parmhash{'suppress_tries'}; + $form{'latex_type'}=$helper->{'VARS'}->{'LATEX_TYPE'}; + $form{'rndseed'}=$rndseed; + $resources_printed .=$urlp.':'; + $texversion=&Apache::lonnet::ssi($urlp,%form); + } + if((($helper->{'VARS'}->{'ANSWER_TYPE'} eq 'no') || + ($helper->{'VARS'}->{'ANSWER_TYPE'} eq 'only')) && + ($urlp=~/\.(problem|exam|quiz|assess|survey|form|library|page)$/)) { + # Don't permanently modify %$form... + my %answerform = %form; + $answerform{'grade_target'}='answer'; + $answerform{'answer_output_mode'}='tex'; + $answerform{'rndseed'}=$rndseed; + $answerform{'problem_split'}=$parmhash{'problem_stream_switch'}; + if ($urlp=~/\/res\//) {$env{'request.state'}='published';} + $resources_printed .= $urlp.':'; + my $answer=&Apache::lonnet::ssi($urlp,%answerform); + if ($helper->{'VARS'}->{'ANSWER_TYPE'} eq 'no') { + $texversion=~s/(\\keephidden{ENDOFPROBLEM})/$answer$1/; + } else { + # 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 '; + $body.=&path_to_problem($urlp,$LaTeXwidth); + $body.='\vskip 1 mm '.$answer.'\end{document}'; + $body = &encapsulate_minipage($body); + $texversion.=$body; + } + } + $texversion = &latex_header_footer_remove($texversion); + + if ($helper->{'VARS'}->{'TABLE_INDEX'} eq 'yes') { + $texversion=&IndexCreation($texversion,$urlp); + } + if ($helper->{'VARS'}->{'CONSTR_RESOURSE_URL'} eq 'yes') { + $texversion=~s/(\\addcontentsline\{toc\}\{subsection\}\{[^\}]*\})/$1 URL: \\verb|$urlp| \\strut\\\\\\strut /; + } + $result.=$texversion; + + } elsif ($urlp=~/\.(sequence|page)$/) { + + # header: + + $result.='\strut\newline\noindent Sequence/page '.$urlp.'\strut\newline\noindent\makebox[\textwidth/$number_of_columns][b]{\hrulefill}\newline\noindent '; + + # IF sequence, recurse: + + if ($urlp =~ /\.sequence$/) { + my $sequence_url = $urlp; + my $domain = $env{'user.domain'}; # Constr. space only on local + my $user = $env{'user.name'}; + + $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, + $helper, %form, + $LaTeXwidth); + } + } + } + if ($helper->{VARS}->{'construction'} eq '1') {$result=~s/(\\begin{document})/$1 \\fbox\{RANDOM SEED IS $rndseed\} /;} + return $result; +} + sub output_data { my ($r,$helper,$rparmhash) = @_; my %parmhash = %$rparmhash; - my $resources_printed = ''; - my $html=&Apache::lonxml::xmlbegin(); - my $bodytag=&Apache::loncommon::bodytag('Preparing Printout'); - $r->print(< - -LON-CAPA output for printing - -$bodytag -

-Please stand by while processing your print request, this may take some time ... -

ENDPART + my $start_page = &Apache::loncommon::start_page('Preparing Printout',$js); + my $msg = &mt('Please stand by while processing your print request, this may take some time ...'); + $r->print($start_page."\n

\n$msg\n

\n"); # fetch the pagebreaks and store them in the course environment # The page breaks will be pulled into the hash %page_breaks which is @@ -1120,12 +1279,14 @@ ENDPART } $form{'rndseed'}=$rndseed; &Apache::lonnet::appenv(%moreenv); - &Apache::lonnet::delenv('form.counter'); - &Apache::lonxml::init_counter(); - &Apache::lonxml::store_counter(); + + &Apache::lonxml::clear_problem_counter(); + $resources_printed .= $currentURL.':'; $texversion.=&Apache::lonnet::ssi($currentURL,%form); - &Apache::lonnet::delenv('form.counter'); + + &Apache::lonxml::clear_problem_counter(); + &Apache::lonnet::delenv('request.filename'); } # current document with answers.. no need to encap in minipage @@ -1172,70 +1333,15 @@ ENDPART } elsif ($cleanURL!~m|^/adm/| && $currentURL=~/\.sequence$/ && $helper->{'VARS'}->{'construction'} eq '1') { #printing content of sequence from the construction space - my $flag_latex_header_remove = 'NO'; - my $rndseed=time; - if ($helper->{'VARS'}->{'curseed'}) { - $rndseed=$helper->{'VARS'}->{'curseed'}; - } $currentURL=~s|\/~([^\/]+)\/|\/home\/$1\/public_html\/|; - my $errtext=&Apache::lonratedt::mapread($currentURL); - for (my $member=0;$member<=$#Apache::lonratedt::order;$member++) { - $Apache::lonratedt::resources[$Apache::lonratedt::order[$member]]=~/^([^:]*):([^:]*):/; - my $urlp=$2; - if ($urlp=~/\.(problem|exam|quiz|assess|survey|form|library|xml|html|htm|xhtml|xhtm)$/) { - my $texversion=''; - if ($helper->{'VARS'}->{'ANSWER_TYPE'} ne 'only') { - $form{'problem_split'}=$parmhash{'problem_stream_switch'}; - $form{'suppress_tries'}=$parmhash{'suppress_tries'}; - $form{'latex_type'}=$helper->{'VARS'}->{'LATEX_TYPE'}; - $form{'rndseed'}=$rndseed; - $resources_printed .=$urlp.':'; - $texversion=&Apache::lonnet::ssi($urlp,%form); - } - if((($helper->{'VARS'}->{'ANSWER_TYPE'} eq 'no') || - ($helper->{'VARS'}->{'ANSWER_TYPE'} eq 'only')) && - ($urlp=~/\.(problem|exam|quiz|assess|survey|form|library|page)$/)) { - # Don't permanently modify %$form... - my %answerform = %form; - $answerform{'grade_target'}='answer'; - $answerform{'answer_output_mode'}='tex'; - $answerform{'rndseed'}=$rndseed; - $answerform{'problem_split'}=$parmhash{'problem_stream_switch'}; - if ($urlp=~/\/res\//) {$env{'request.state'}='published';} - $resources_printed .= $urlp.':'; - my $answer=&Apache::lonnet::ssi($urlp,%answerform); - if ($helper->{'VARS'}->{'ANSWER_TYPE'} eq 'no') { - $texversion=~s/(\\keephidden{ENDOFPROBLEM})/$answer$1/; - } else { - # 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 '; - $body.=&path_to_problem($urlp,$LaTeXwidth); - $body.='\vskip 1 mm '.$answer.'\end{document}'; - $body = &encapsulate_minipage($body); - $texversion.=$body; - } - } - if ($flag_latex_header_remove ne 'NO') { - $texversion = &latex_header_footer_remove($texversion); - } else { - $texversion =~ s/\\end{document}//; - } - if ($helper->{'VARS'}->{'TABLE_INDEX'} eq 'yes') { - $texversion=&IndexCreation($texversion,$urlp); - } - if ($helper->{'VARS'}->{'CONSTR_RESOURSE_URpL'} eq 'yes') { - $texversion=~s/(\\addcontentsline\{toc\}\{subsection\}\{[^\}]*\})/$1 URL: \\verb|$urlp| \\strut\\\\\\strut /; - } - $result.=$texversion; - $flag_latex_header_remove = 'YES'; - } elsif ($urlp=~/\.(sequence|page)$/) { - $result.='\strut\newline\noindent Sequence/page '.$urlp.'\strut\newline\noindent\makebox[\textwidth/$number_of_columns][b]{\hrulefill}\newline\noindent '; - } + $result .= &print_latex_header($helper->{'VARS'}->{'LATEX_TYPE'}); + $result .= &print_construction_sequence($currentURL, $helper, %form, + $LaTeXwidth); + $result .= '\end{document}'; + if (!($result =~ /\\begin\{document\}/)) { + $result = &print_latex_header() . $result; } - if ($helper->{VARS}->{'construction'} eq '1') {$result=~s/(\\begin{document})/$1 \\fbox\{RANDOM SEED IS $rndseed\} /;} - $result .= '\end{document}'; + # End construction space sequence. } elsif ($cleanURL=~/\/(smppg|syllabus|aboutme|bulletinboard)$/) { $form{'latex_type'}=$helper->{'VARS'}->{'LATEX_TYPE'}; if ($currentURL=~/\/syllabus$/) {$currentURL=~s/\/res//;} @@ -1272,9 +1378,9 @@ ENDPART my $flag_page_in_sequence = 'NO'; my @master_seq=split /\|\|\|/, $helper->{'VARS'}->{'RESOURCES'}; my $prevassignment=''; - &Apache::lonnet::delenv('form.counter'); - &Apache::lonxml::init_counter(); - &Apache::lonxml::store_counter(); + + &Apache::lonxml::clear_problem_counter(); + my $pbreakresources = keys %page_breaks; for (my $i=0;$i<=$#master_seq;$i++) { @@ -1297,7 +1403,8 @@ ENDPART if ($urlp!~m|^/adm/| && $urlp=~/\.(problem|exam|quiz|assess|survey|form|library|page|xml|html|htm|xhtml|xhtm)$/) { $resources_printed .= $urlp.':'; - my $pre_counter=$env{'form.counter'}; + + &Apache::lonxml::remember_problem_counter(); $texversion.=&Apache::lonnet::ssi($urlp,%form); if ($urlp=~/\.page$/) { ($texversion,my $number_of_columns_page) = &page_cleanup($texversion); @@ -1305,10 +1412,7 @@ ENDPART $texversion =~ s/\\end{document}\d*/\\end{document}/; $flag_page_in_sequence = 'YES'; } - my ($envfile) = ($env{'user.environment'} =~m|/([^/]+)\.id$| ); - &Apache::lonnet::transfer_profile_to_env($r->dir_config('lonIDsDir'), - $envfile); - my $current_counter=$env{'form.counter'}; + if(($helper->{'VARS'}->{'ANSWER_TYPE'} eq 'no') || ($helper->{'VARS'}->{'ANSWER_TYPE'} eq 'only')) { # Don't permanently pervert the %form hash @@ -1316,9 +1420,10 @@ ENDPART $answerform{'grade_target'}='answer'; $answerform{'answer_output_mode'}='tex'; $resources_printed .= $urlp.':'; - &Apache::lonnet::appenv(('form.counter' => $pre_counter)); + + &Apache::lonxml::restore_problem_counter(); my $answer=&Apache::lonnet::ssi($urlp,%answerform); - &Apache::lonnet::appenv(('form.counter' => $current_counter)); + if ($helper->{'VARS'}->{'ANSWER_TYPE'} eq 'no') { $texversion=~s/(\\keephidden{ENDOFPROBLEM})/$answer$1/; } else { @@ -1347,10 +1452,15 @@ ENDPART my $courseidinfo = &get_course(); if (defined($courseidinfo)) { $courseidinfo=' - '.$courseidinfo } $prevassignment=$assignment; + my $header_text = $parmhash{'print_header_format'}; + $header_text = &format_page_header($header_text, + $assignment, + $courseidinfo, + $name); if ($numberofcolumns eq '1') { - $result .='\newpage \noindent\parbox{\minipagewidth}{\noindent\\lhead{\\textit{\\textbf{'.$name.'}}'.$courseidinfo.' \\hfill \\thepage \\\\ \\textit{'.$assignment.'}}} \vskip 5 mm '; + $result .='\newpage \noindent\parbox{\minipagewidth}{\noindent\\lhead{'.$header_text.'}} \vskip 5 mm '; } else { - $result .='\newpage \noindent\parbox{\minipagewidth}{\noindent\\fancyhead[LO]{\\textit{\\textbf{'.$name.'}}'.$courseidinfo.' \\hfill \\thepage \\\\ \\textit{'.$assignment.'}}} \vskip 5 mm '; + $result .='\newpage \noindent\parbox{\minipagewidth}{\noindent\\fancyhead[LO]{'.$header_text.'}} \vskip 5 mm '; } } $result .= $texversion; @@ -1380,7 +1490,7 @@ ENDPART } if (&Apache::loncommon::connection_aborted($r)) { last; } } - &Apache::lonnet::delenv('form.counter'); + &Apache::lonxml::clear_problem_counter(); if ($flag_page_in_sequence eq 'YES') { $result =~ s/\\usepackage{calc}/\\usepackage{calc}\\usepackage{longtable}/; } @@ -1405,14 +1515,28 @@ ENDPART # Each element of the students array is of the form: # username:domain:section:last, first:status # + # Note that student sort is not compatible with printing + # 1 section per pdf...so that setting overrides. # - if ($helper->{'VARS'}->{'student_sort'} eq 1) { + if (($helper->{'VARS'}->{'student_sort'} eq 1) && + ($helper->{'VARS'}->{'SPLIT_PDFS'} ne "sections")) { @students = sort compare_names @students; } + &adjust_number_to_print($helper); + if ($helper->{'VARS'}->{'NUMBER_TO_PRINT'} eq '0' || $helper->{'VARS'}->{'NUMBER_TO_PRINT'} eq 'all' ) { $helper->{'VARS'}->{'NUMBER_TO_PRINT'}=$#students+1; } + # If we are splitting on section boundaries, we need + # to remember that in split_on_sections and + # print all of the students in the list. + # + my $split_on_sections = 0; + if ($helper->{'VARS'}->{'NUMBER_TO_PRINT'} eq 'section') { + $split_on_sections = 1; + $helper->{'VARS'}->{'NUMBER_TO_PRINT'} = $#students+1; + } my @master_seq=split /\|\|\|/, $helper->{'VARS'}->{'RESOURCES'}; #loop over students @@ -1426,6 +1550,8 @@ ENDPART if ($helper->{'VARS'}->{'PRINT_DISCUSSIONS'} eq 'yes') {$moreenv{'problem_split'}='yes';} my %prog_state=&Apache::lonhtmlcommon::Create_PrgWin($r,'Print Status','Class Print Status',$#students+1,'inline','75'); my $student_counter=-1; + my $i = 0; + my $last_section = (split(/:/,$students[0]))[2]; foreach my $person (@students) { my $duefile="/home/httpd/prtspool/$env{'user.name'}_$env{'user.domain'}_printout.due"; @@ -1434,7 +1560,15 @@ ENDPART print $temp_file "1969\n"; } $student_counter++; - my $i=int($student_counter/$helper->{'VARS'}{'NUMBER_TO_PRINT'}); + if ($split_on_sections) { + my $this_section = (split(/:/,$person))[2]; + if ($this_section ne $last_section) { + $i++; + $last_section = $this_section; + } + } else { + $i=int($student_counter/$helper->{'VARS'}{'NUMBER_TO_PRINT'}); + } my ($output,$fullname, $printed)=&print_resources($r,$helper, $person,$type, \%moreenv,\@master_seq, @@ -1513,6 +1647,7 @@ ENDPART } my @master_seq=split /\|\|\|/, $helper->{'VARS'}->{'RESOURCES'}; my ($type) = split(/_/,$helper->{'VARS'}->{'PRINT_TYPE'}); + &adjust_number_to_print($helper); my $number_per_page=$helper->{'VARS'}->{'NUMBER_TO_PRINT'}; if ($number_per_page eq '0' || $number_per_page eq 'all') { $number_per_page=$num_todo; @@ -1624,13 +1759,12 @@ ENDPART $selectionmade, $helper->{'VARS'}->{'ANSWER_TYPE'}); } - #changes page's parameters for the one column output - if ($numberofcolumns == 1) { + #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/\\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; @@ -1686,7 +1820,7 @@ ENDPART my $URLback=''; #link to original document if ($helper->{'VARS'}->{'construction'} ne '1') { #prints published resource - $URLback=&Apache::lonnet::escape('/adm/flip?postdata=return:'); + $URLback=&escape('/adm/flip?postdata=return:'); } else { #prints resource from the construction space $URLback='/'.$helper->{'VARS'}->{'filename'}; @@ -1716,12 +1850,12 @@ ENDPART "cgi.$identifier.coursedom" => $cdom, "cgi.$identifier.resources" => $resources_printed); -$r->print(<print(< Continue - - +$end_page FINALEND } @@ -1755,15 +1889,27 @@ sub print_resources { $namepostfix="\\\\Name: "; $fullname = "CODE - ".$moreenv->{'CODE'}; } + # Fullname may have special latex characters that need \ prefixing: + # + my $i = 0; #goes through all resources, checks if they are available for #current student, and produces output - &Apache::lonnet::delenv('form.counter'); - &Apache::lonxml::init_counter(); - &Apache::lonxml::store_counter(); + + &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]; + # + # end each student with a + # Special that allows the post processor to even out the page + # counts later. Nasty problem this... it would be really + # nice to put the special in as a postscript comment + # e.g. \special{ps:\ENDOFSTUDENTSTAMP} unfortunately, + # The special gets passed the \ and dvips puts it in the output file + # so we will just rely on prntout.pl to strip ENDOFSTUDENTSTAMP from the + # postscript. Each ENDOFSTUDENTSTAMP will go on a line by itself. + # foreach my $curresline (@{$master_seq}) { if (defined $page_breaks{$curresline}) { @@ -1779,22 +1925,22 @@ sub print_resources { if ($res_url!~m|^ext/| && $res_url=~/\.(problem|exam|quiz|assess|survey|form|library|page|xml|html|htm|xhtml|xhtm)$/) { $printed .= $curresline.':'; - my $pre_counter=$env{'form.counter'}; + + &Apache::lonxml::remember_problem_counter(); + my $rendered = &Apache::loncommon::get_student_view($curresline,$username,$userdomain,$env{'request.course.id'},'tex',$moreenv); - my ($envfile) = - ( $env{'user.environment'} =~ m|/([^/]+)\.id$| ); - &Apache::lonnet::transfer_profile_to_env($r->dir_config('lonIDsDir'), - $envfile); - my $current_counter=$env{'form.counter'}; + if(($helper->{'VARS'}->{'ANSWER_TYPE'} eq 'no') || ($helper->{'VARS'}->{'ANSWER_TYPE'} eq 'only')) { # Use a copy of the hash so we don't pervert it on future loop passes. my %answerenv = %{$moreenv}; $answerenv{'answer_output_mode'}='tex'; $answerenv{'latex_type'}=$helper->{'VARS'}->{'LATEX_TYPE'}; - &Apache::lonnet::appenv(('form.counter' => $pre_counter)); + + &Apache::lonxml::restore_problem_counter(); + my $ansrendered = &Apache::loncommon::get_student_answers($curresline,$username,$userdomain,$env{'request.course.id'},%answerenv); - &Apache::lonnet::appenv(('form.counter' => $current_counter)); + if ($helper->{'VARS'}->{'ANSWER_TYPE'} eq 'no') { $rendered=~s/(\\keephidden{ENDOFPROBLEM})/$ansrendered$1/; } else { @@ -1817,11 +1963,7 @@ sub print_resources { } 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 ($envfile) = - ( $env{'user.environment'} =~ m|/([^/]+)\.id$| ); - &Apache::lonnet::transfer_profile_to_env($r->dir_config('lonIDsDir'), - $envfile); - my $current_counter=$env{'form.counter'}; + if ($remove_latex_header eq 'YES') { $rendered = &latex_header_footer_remove($rendered); } else { @@ -1847,22 +1989,28 @@ 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{\\textit{\\textbf{$fullname}}$courseidinfo \\hfill \\thepage \\\\ \\textit{$currentassignment}$namepostfix}}\\vskip 5 mm /; + $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]{\\textit{\\textbf{$fullname}}$courseidinfo \\hfill \\thepage \\\\ \\textit{$currentassignment}$namepostfix}}\\vskip 5 mm /; + $current_output =~ s/\\begin{document}/\\setlength{\\topmargin}{1cm} \\begin{document}\\noindent\\parbox{\\minipagewidth}{\\noindent\\fancyhead[LO]{$HeaderLine$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{\\textit{\\textbf{'.$fullname.'}}'.$courseidinfo.' \\hfill \\thepage \\\\ \\textit{'.$currentassignment.'}'.$namepostfix.'}} \vskip 5 mm '.$current_output; + $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]{\\textit{\\textbf{'.$fullname.'}}'.$courseidinfo.' \\hfill \\thepage \\\\ \\textit{'.$currentassignment.'}'.$namepostfix.'}} \vskip 5 mm '.$current_output; + $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; } } + # + # Close the student bracketing. + # + $current_output .= "\n\\special{ps:ENDOFSTUDENTSTAMP}\n"; return ($current_output,$fullname, $printed); } @@ -1881,7 +2029,7 @@ sub handler { } - my %parmhash=&Apache::lonnet::coursedescription($env{'request.course.id'}); + %parmhash=&Apache::lonnet::coursedescription($env{'request.course.id'}); @@ -2078,7 +2226,7 @@ sub printHelper { my $paramHash; if ($resourceTitle) { - push @{$printChoices}, ["$resourceTitle (".&mt('what you just saw on the screen').")", 'current_document', 'PAGESIZE']; + push @{$printChoices}, ["$resourceTitle (".&mt('the resource you just saw on the screen').")", 'current_document', 'PAGESIZE']; } # Useful filter strings @@ -2096,37 +2244,35 @@ sub printHelper { # If we're in a sequence... + my $startnew=&mt('Start new page
before selected'); if (($helper->{'VARS'}->{'construction'} ne '1') && $helper->{VARS}->{'postdata'} && $helper->{VARS}->{'assignment'}) { # Allow problems from sequence - push @{$printChoices}, ["".&mt('Problems')." ".&mt('in')." $sequenceTitle", 'map_problems', 'CHOOSE_PROBLEMS']; + push @{$printChoices}, [&mt('Selected Problems in folder [_1]',$sequenceTitle), 'map_problems', 'CHOOSE_PROBLEMS']; # Allow all resources from sequence - push @{$printChoices}, ["".&mt('Resources')." ".&mt('in')." $sequenceTitle", 'map_problems_pages', 'CHOOSE_PROBLEMS_HTML']; - + push @{$printChoices}, [&mt('Selected Resources in folder [_1]',$sequenceTitle), 'map_problems_pages', 'CHOOSE_PROBLEMS_HTML']; my $helperFragment = < - (mark them then click "next" button)
PAGESIZE return $isProblem; $map return $symbFilter; - - (mark them then click "next" button)
PAGESIZE return $isNotMap; $map return $symbFilter; -
HELPERFRAGMENT @@ -2139,45 +2285,57 @@ HELPERFRAGMENT if ($perm{'pfo'} && ($helper->{VARS}->{'postdata'}=~/\/res\// || $helper->{VARS}->{'postdata'}=~/\/(syllabus|smppg|aboutme|bulletinboard)$/)) { - push @{$printChoices}, ['Problems from entire course', 'all_problems', 'ALL_PROBLEMS']; - push @{$printChoices}, ['Resources from entire course', 'all_resources', 'ALL_RESOURCES']; + push @{$printChoices}, ['Selected Problems from entire course', 'all_problems', 'ALL_PROBLEMS']; + push @{$printChoices}, ['Selected Resources from entire course', 'all_resources', 'ALL_RESOURCES']; &Apache::lonxml::xmlparse($r, 'helper', < - (mark them then click "next" button)
PAGESIZE return $isProblemOrMap; return $isNotMap; return $symbFilter; - - (Mark them then click "next" button)
PAGESIZE return $isNotMap; return $symbFilter; -
ALL_PROBLEMS if ($helper->{VARS}->{'assignment'}) { - push @{$printChoices}, ["".&mt('Problems')." ".&mt('from')." $sequenceTitle ".&mt('for')." ".&mt('selected students')."", 'problems_for_students', 'CHOOSE_STUDENTS']; - push @{$printChoices}, ["".&mt('Problems')." ".&mt('from')." $sequenceTitle ".&mt('for')." ".&mt('anonymous students')."", 'problems_for_anon', 'CHOOSE_ANON1']; + 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']; } + + # resource_selector will hold a few states that: + # - Allow resources to be selected for printing. + # - Determine pagination between assignments. + # - Determine how many assignments should be bundled into a single PDF. + # TODO: + # Probably good to do things like separate this up into several vars, each + # with one state, and use REGEXPs at inclusion time to set state names + # and next states for better mix and match capability + # my $resource_selector=< + PRINT_FORMATTING
Select resources for the assignment
return $isProblem; $map return $symbFilter; - + +
How should the results be printed?
Start each student\'s assignment on a new page/column (add a pagefeed after each assignment) @@ -2185,20 +2343,29 @@ ALL_PROBLEMS Add two empty pages/column after each student\'s assignment Add three empty pages/column after each student\'s assignment -
Number of assignments printed at the same time:
- "all" + PAGESIZE +
How do you want assignments split into PDF files?
+ + All assignments in a single PDF file + Each PDF contains exactly one section + Each PDF contains exactly one assignment + + Specify the number of assignments per PDF: + +
RESOURCE_SELECTOR &Apache::lonxml::xmlparse($r, 'helper', < - Select sort order Sort by section then student Sort by students across sections. - $resource_selector +


+ + $resource_selector CHOOSE_STUDENTS my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'}; @@ -2221,14 +2388,30 @@ CHOOSE_STUDENTS } } - my $code_selection = "\n"; + my $code_selection; foreach my $code (sort {uc($a) cmp uc($b)} (keys(%codes_to_print))) { my $choice = $code; if ($code =~ /^[A-Z]+$/) { # Alpha code $choice = &letters_to_num($code); } - $code_selection .= ' '.$code."\n"; + push(@{$helper->{DATA}{ALL_CODE_CHOICES}},[$code,$choice]); + } + if (%codes_to_print) { + $code_selection .=' + Choose single code from list + + + + + push(@{$state->{CHOICES}},@{$helper->{DATA}{ALL_CODE_CHOICES}}); + + +
+ '.$/; + } + + open(FH,$Apache::lonnet::perlvar{'lonTabDir'}.'/scantronformat.tab'); my $codechoice=''; foreach my $line () { @@ -2244,7 +2427,7 @@ CHOOSE_STUDENTS } &Apache::lonxml::xmlparse($r, 'helper', < - PAGESIZE + SELECT_PROBLEMS
Number of anonymous assignments to print: @@ -2283,6 +2466,9 @@ CHOOSE_STUDENTS

+ $code_selection + + Reprint a set of saved CODEs: @@ -2290,26 +2476,31 @@ CHOOSE_STUDENTS

- $resource_selector + $resource_selector CHOOSE_ANON1 if ($helper->{VARS}->{'assignment'}) { - push @{$printChoices}, ["".&mt('Resources')." ".&mt('from')." $sequenceTitle ".&mt('for')." ".&mt('selected students')."", 'resources_for_students', 'CHOOSE_STUDENTS1']; - push @{$printChoices}, ["".&mt('Resources')." ".&mt('from')." $sequenceTitle ".&mt('for')." ".&mt('anonymous students')."", 'resources_for_anon', 'CHOOSE_ANON2']; + 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']; } $resource_selector=< + PRINT_FORMATTING
Select resources for the assignment
return $isNotMap; $map return $symbFilter; - + + + NUMBER_PER_PDF
How should the results be printed?
Start each student\'s assignment on a new page/column (add a pagefeed after each assignment) @@ -2317,25 +2508,34 @@ CHOOSE_ANON1 Add two empty pages/column after each student\'s assignment Add three empty pages/column after each student\'s assignment -
Number of assignments printed at the same time:
- "all" + PAGESIZE +
How do you want assignments split into PDF files?
+ + All assignments in a single PDF file + Each PDF contains exactly one section + Each PDF contains exactly one assignment + + Specify the number of assignments per PDF: + +
RESOURCE_SELECTOR &Apache::lonxml::xmlparse($r, 'helper', < - Sort by section then student Sort by students across sections. +


+ - $resource_selector + $resource_selector CHOOSE_STUDENTS1 &Apache::lonxml::xmlparse($r, 'helper', < - PAGESIZE + SELECT_RESOURCES
Number of anonymous assignments to print: @@ -2374,6 +2574,7 @@ CHOOSE_STUDENTS1

+ $code_selection Reprint a set of saved CODEs: @@ -2381,19 +2582,19 @@ CHOOSE_STUDENTS1

- $resource_selector + $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('Problems')." ".&mt('from current subdirectory')." $subdir", 'problems_from_directory', 'CHOOSE_FROM_SUBDIR']; + push @{$printChoices}, [&mt("Selected Problems from current subdirectory [_1]",$subdir), 'problems_from_directory', 'CHOOSE_FROM_SUBDIR']; my $f = '$filename'; my $xmlfrag = < - (mark them then click "next" button)
+ PAGESIZE return '$subdir'; @@ -2414,7 +2615,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'}) { - push @$printChoices, ["Resources from selected sequence in course", + push @$printChoices, ["Selected Resources from selected folder in course", 'select_sequences', 'CHOOSE_SEQUENCE']; my $escapedSequenceName = $helper->{VARS}->{'SEQUENCE'}; #Escape apostrophes and backslashes for Perl @@ -2439,7 +2640,7 @@ CHOOSE_FROM_SUBDIR return $isProblem return '$escapedSequenceName'; return $symbFilter; -