--- loncom/interface/lonprintout.pm 2006/03/06 23:32:31 1.426 +++ loncom/interface/lonprintout.pm 2006/05/30 12:46:09 1.439 @@ -1,7 +1,7 @@ # The LearningOnline Network # Printout # -# $Id: lonprintout.pm,v 1.426 2006/03/06 23:32:31 foxr Exp $ +# $Id: lonprintout.pm,v 1.439 2006/05/30 12:46:09 www Exp $ # # Copyright Michigan State University Board of Trustees # @@ -41,6 +41,9 @@ 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; @@ -233,12 +236,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; @@ -679,7 +709,7 @@ sub get_name { 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; } @@ -994,12 +1024,8 @@ 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 +1143,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 @@ -1272,9 +1297,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 +1322,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 +1331,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 +1339,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 { @@ -1380,7 +1404,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 +1429,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 +1464,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 +1474,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, @@ -1624,13 +1672,14 @@ ENDPART $selectionmade, $helper->{'VARS'}->{'ANSWER_TYPE'}); } - #changes page's parameters for the one column output - 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'} /; - } + &Apache::lonnet::logthis("Resetting page e.g. height -> $helper->{'VARS'}->{'pagesize.height'}"); + &Apache::lonnet::logthis("Before: $result \n--------------------------\n"); + $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'} /; + + &Apache::lonnet::logthis("After: $result \n----------------------------------\n"); #-- writing .tex file in prtspool my $temp_file; @@ -1686,7 +1735,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 +1765,12 @@ ENDPART "cgi.$identifier.coursedom" => $cdom, "cgi.$identifier.resources" => $resources_printed); -$r->print(<print(< Continue - - +$end_page FINALEND } @@ -1758,9 +1807,8 @@ sub print_resources { 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]; @@ -1779,22 +1827,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 +1865,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 { @@ -2192,7 +2236,6 @@ ALL_PROBLEMS - 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) @@ -2200,11 +2243,15 @@ ALL_PROBLEMS Add two empty pages/column after each student\'s assignment Add three empty pages/column after each student\'s assignment -
- PAGESIZE -
Number of assignments printed at the same time:
- "all" +
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 Number: +
RESOURCE_SELECTOR @@ -2215,6 +2262,7 @@ RESOURCE_SELECTOR Sort by section then student Sort by students across sections. +


$resource_selector @@ -2246,8 +2294,17 @@ CHOOSE_STUDENTS 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 .=' + + push(@{$state->{CHOICES}},@{$helper->{DATA}{ALL_CODE_CHOICES}}); + + '.$/; } + + open(FH,$Apache::lonnet::perlvar{'lonTabDir'}.'/scantronformat.tab'); my $codechoice=''; foreach my $line () { @@ -2302,6 +2359,12 @@ CHOOSE_STUDENTS
+ Choose single code from list + + + $code_selection + +
Reprint a set of saved CODEs: @@ -2341,11 +2404,15 @@ CHOOSE_ANON1 Add two empty pages/column after each student\'s assignment Add three empty pages/column after each student\'s assignment - - PAGESIZE -
Number of assignments printed at the same time:
- "all" +
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 Number: +
RESOURCE_SELECTOR @@ -2355,6 +2422,7 @@ RESOURCE_SELECTOR Sort by section then student Sort by students across sections. +


@@ -2402,6 +2470,12 @@ CHOOSE_STUDENTS1
+ Choose single code from list + + + $code_selection + +
Reprint a set of saved CODEs: @@ -2810,6 +2884,12 @@ sub render { $result .= '
' . $self->{ERROR_MSG} . '
'; } + my $width = 18; + my $format = $helper->{VARS}->{$self->{'formatvar'}}; + if (substr($format, 2, 1) ne '1') { + $width = 9; + } + $result .= <How should the column be formatted?

@@ -2817,7 +2897,7 @@ sub render { - +
Width: