--- loncom/interface/lonprintout.pm 2005/02/09 19:53:55 1.343.2.3 +++ loncom/interface/lonprintout.pm 2005/02/22 11:43:05 1.363 @@ -1,7 +1,7 @@ -# The LearningOnline Network +# The LearningOnline Network # Printout # -# $Id: lonprintout.pm,v 1.343.2.3 2005/02/09 19:53:55 albertel Exp $ +# $Id: lonprintout.pm,v 1.363 2005/02/22 11:43:05 foxr Exp $ # # Copyright Michigan State University Board of Trustees # @@ -42,9 +42,6 @@ use Apache::lonratedt; use POSIX qw(strftime); use Apache::lonlocal; -my $LaTeXwidth = 0; - - # Compare two students by name. The students are in the form # returned by the helper: # user:domain:section:last, first:status @@ -698,7 +695,7 @@ sub IndexCreation { sub print_latex_header { my $mode=shift; my $output='\documentclass[letterpaper]{article}'; - if ($mode eq 'batchmode' || !$ENV{'request.role.adv'}) { + if (($mode eq 'batchmode') || (!$ENV{'request.role.adv'})) { $output.='\batchmode'; } $output.='\newcommand{\keephidden}[1]{}\renewcommand{\deg}{$^{\circ}$}'."\n". @@ -726,7 +723,7 @@ sub path_to_problem { my $newurlp = ''; $colwidth=~s/\s*mm\s*$//; #characters average about 2 mm in width - if (length($urlp)*2 > $LaTeXwidth) { + if (length($urlp)*2 > $colwidth) { my @elements = split '/',$urlp; my $curlength=0; foreach my $element (@elements) { @@ -784,13 +781,38 @@ sub unsupported { } +# +# Retrieve the hash of page breaks. +# +# Inputs: +# helper - reference to helper object. +# Outputs +# A reference to a page break hash. +# +# + +sub get_page_breaks { + my ($helper) = @_; + my %page_breaks; + + + + foreach my $break (split /\|\|\|/, $helper->{'VARS'}->{'FINISHPAGE'}) { + $page_breaks{$break} = 1; + } + + return \%page_breaks; +} + sub output_data { my ($r,$helper,$rparmhash) = @_; my %parmhash = %$rparmhash; + 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 + + # fetch the pagebreaks and store them in the course environment + # The page breaks will be pulled into the hash %page_breaks which is + # indexed by symb and contains 1's for each break. + + $ENV{'form.pagebreaks'} = $helper->{'VARS'}->{'FINISHPAGE'}; + &Apache::loncommon::store_course_settings('print', + {'pagebreaks' => 'scalar'}); + + my $page_hashref = &get_page_breaks($helper); + my %page_breaks = %$page_hashref; + + + my $format_from_helper = $helper->{'VARS'}->{'FORMAT'}; my ($result,$selectionmade) = ('',''); my $number_of_columns = 1; #used only for pages to determine the width of the cell @@ -836,6 +871,15 @@ ENDPART my $LaTeXwidth=&recalcto_mm($textwidth); my @print_array=(); my @student_names=(); + + # Common settings for the %form has: + # In some cases these settings get overriddent by specific cases, but the + # settings are common enough to make it worthwhile factoring them out + # here. + # + my %form; + $form{'grade_target'} = 'tex'; + $form{'textwidth'} = &get_textwidth($helper, $LaTeXwidth); if ($helper->{'VARS'}->{'PRINT_TYPE'} eq 'current_document') { #-- single document - problem, page, html, xml, ... @@ -863,10 +907,7 @@ ENDPART my $user = $ENV{'user.name'}; my $put_result = &Apache::lonnet::put('environment',{'construct.style'=>$helper->{'VARS'}->{'style_file'}},$dom,$user); } - my %form; if ($helper->{'VARS'}->{'probstatus'} eq 'exam') {$form{'problemtype'}='exam';} - $form{'grade_target'}='tex'; - $form{'textwidth'}=&get_textwidth($helper,$LaTeXwidth); $form{'problem_split'}=$parmhash{'problem_stream_switch'}; $form{'suppress_tries'}=$parmhash{'suppress_tries'}; $form{'latex_type'}=$helper->{'VARS'}->{'LATEX_TYPE'}; @@ -885,7 +926,7 @@ ENDPART } if(($helper->{'VARS'}->{'ANSWER_TYPE'} eq 'no') || ($helper->{'VARS'}->{'ANSWER_TYPE'} eq 'only')) { - my %form; + $form{'problem_split'}=$parmhash{'problem_stream_switch'}; $form{'grade_target'}='answer'; $form{'answer_output_mode'}='tex'; $form{'rndseed'}=$rndseed; @@ -932,9 +973,6 @@ ENDPART if ($urlp=~/\.(problem|exam|quiz|assess|survey|form|library|xml|html|htm|xhtml|xhtm)$/) { my $texversion=''; if ($helper->{'VARS'}->{'ANSWER_TYPE'} ne 'only') { - my %form; - $form{'grade_target'}='tex'; - $form{'textwidth'}=&get_textwidth($helper,$LaTeXwidth); $form{'problem_split'}=$parmhash{'problem_stream_switch'}; $form{'suppress_tries'}=$parmhash{'suppress_tries'}; $form{'latex_type'}=$helper->{'VARS'}->{'LATEX_TYPE'}; @@ -944,10 +982,10 @@ ENDPART if((($helper->{'VARS'}->{'ANSWER_TYPE'} eq 'no') || ($helper->{'VARS'}->{'ANSWER_TYPE'} eq 'only')) && ($urlp=~/\.(problem|exam|quiz|assess|survey|form|library|page)$/)) { - my %form; $form{'grade_target'}='answer'; $form{'answer_output_mode'}='tex'; $form{'rndseed'}=$rndseed; + $form{'problem_split'}=$parmhash{'problem_stream_switch'}; if ($urlp=~/\/res\//) {$ENV{'request.state'}='published';} my $answer=&Apache::lonnet::ssi($urlp,%form); if ($helper->{'VARS'}->{'ANSWER_TYPE'} eq 'no') { @@ -979,9 +1017,6 @@ ENDPART if ($helper->{VARS}->{'construction'} eq '1') {$result=~s/(\\begin{document})/$1 \\fbox\{RANDOM SEED IS $rndseed\} /;} $result .= '\end{document}'; } elsif ($cleanURL=~/\/(smppg|syllabus|aboutme|bulletinboard)$/) { - my %form; - $form{'grade_target'}='tex'; - $form{'textwidth'}=&get_textwidth($helper,$LaTeXwidth); $form{'latex_type'}=$helper->{'VARS'}->{'LATEX_TYPE'}; if ($currentURL=~/\/syllabus$/) {$currentURL=~s/\/res//;} my $texversion=&Apache::lonnet::ssi($currentURL,%form); @@ -989,9 +1024,10 @@ ENDPART } else { $result.=&unsupported($currentURL,$helper->{'VARS'}->{'LATEX_TYPE'}); } - } elsif (($helper->{'VARS'}->{'PRINT_TYPE'} eq 'map_problems') or + } elsif (($helper->{'VARS'}->{'PRINT_TYPE'} eq 'map_problems') or ($helper->{'VARS'}->{'PRINT_TYPE'} eq 'map_problems_pages') or - ($helper->{'VARS'}->{'PRINT_TYPE'} eq 'all_problems') or + ($helper->{'VARS'}->{'PRINT_TYPE'} eq 'all_problems') or + ($helper->{'VARS'}->{'PRINT_TYPE'} eq 'all_resources') or # BUGBUG ($helper->{'VARS'}->{'PRINT_TYPE'} eq 'select_sequences')) { #-- produce an output string if ($helper->{'VARS'}->{'PRINT_TYPE'} eq 'map_problems') { @@ -1000,12 +1036,11 @@ ENDPART $selectionmade = 3; } elsif ($helper->{'VARS'}->{'PRINT_TYPE'} eq 'all_problems') { $selectionmade = 4; + } elsif ($helper->{'VARS'}->{'PRINT_TYPE'} eq 'all_resources') { #BUGBUG + $selectionmade = 4; } elsif ($helper->{'VARS'}->{'PRINT_TYPE'} eq 'select_sequences') { $selectionmade = 7; } - my %form=(); - $form{'grade_target'}='tex'; - $form{'textwidth'}=&get_textwidth($helper,$LaTeXwidth); $form{'problem_split'}=$parmhash{'problem_stream_switch'}; $form{'suppress_tries'}=$parmhash{'suppress_tries'}; $form{'latex_type'}=$helper->{'VARS'}->{'LATEX_TYPE'}; @@ -1018,6 +1053,15 @@ ENDPART &Apache::lonnet::delenv('form.counter'); &Apache::lonxml::init_counter(); for (my $i=0;$i<=$#master_seq;$i++) { + + # Note due to document structure, not allowed to put \newpage + # prior to the first resource + + if (defined $page_breaks{$master_seq[$i]}) { + if($i != 0) { + $result.="\\newpage\n"; + } + } my (undef,undef,$urlp)=&Apache::lonnet::decode_symb($master_seq[$i]); $urlp=&Apache::lonnet::clutter($urlp); $form{'symb'}=$master_seq[$i]; @@ -1042,7 +1086,6 @@ ENDPART my $current_counter=$ENV{'form.counter'}; if(($helper->{'VARS'}->{'ANSWER_TYPE'} eq 'no') || ($helper->{'VARS'}->{'ANSWER_TYPE'} eq 'only')) { - my %form; $form{'grade_target'}='answer'; $form{'answer_output_mode'}='tex'; my $answer=&Apache::lonnet::ssi($urlp,%form); @@ -1078,9 +1121,6 @@ ENDPART $result .= $texversion; $flag_latex_header_remove = 'YES'; } elsif ($urlp=~/\/(smppg|syllabus|aboutme|bulletinboard)$/) { - my %form; - $form{'grade_target'}='tex'; - $form{'textwidth'}=&get_textwidth($helper,$LaTeXwidth); $form{'latex_type'}=$helper->{'VARS'}->{'LATEX_TYPE'}; if ($urlp=~/\/syllabus$/) {$urlp=~s/\/res//;} my $texversion=&Apache::lonnet::ssi($urlp,%form); @@ -1110,6 +1150,8 @@ ENDPART $result .= '\end{document}'; } elsif (($helper->{'VARS'}->{'PRINT_TYPE'} eq 'problems_for_students') || ($helper->{'VARS'}->{'PRINT_TYPE'} eq 'resources_for_students')){ + + #-- prints assignments for whole class or for selected students my $type; if ($helper->{'VARS'}->{'PRINT_TYPE'} eq 'problems_for_students') { @@ -1135,16 +1177,19 @@ ENDPART $helper->{'VARS'}->{'NUMBER_TO_PRINT'}=$#students+1; } my @master_seq=split /\|\|\|/, $helper->{'VARS'}->{'RESOURCES'}; + #loop over students my $flag_latex_header_remove = 'NO'; my %moreenv; $moreenv{'instructor_comments'}='hide'; $moreenv{'textwidth'}=&get_textwidth($helper,$LaTeXwidth); $moreenv{'print_discussions'}=$helper->{'VARS'}->{'PRINT_DISCUSSIONS'}; + $moreenv{'problem_split'} = $parmhash{'problem_stream_switch'}; 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; foreach my $person (@students) { + my $duefile="/home/httpd/prtspool/$ENV{'user.name'}_$ENV{'user.domain'}_printout.due"; if (-e $duefile) { my $temp_file = Apache::File->new('>>'.$duefile); @@ -1152,7 +1197,11 @@ ENDPART } $student_counter++; my $i=int($student_counter/$helper->{'VARS'}{'NUMBER_TO_PRINT'}); - my ($output,$fullname)=&print_resources($r,$helper,$person,$type,\%moreenv,\@master_seq,$flag_latex_header_remove); + my ($output,$fullname)=&print_resources($r,$helper, + $person,$type, + \%moreenv,\@master_seq, + $flag_latex_header_remove, + $LaTeXwidth); $print_array[$i].=$output; $student_names[$i].=$person.':'.$fullname.'_END_'; &Apache::lonhtmlcommon::Increment_PrgWin($r,\%prog_state,&mt('last student').' '.$fullname); @@ -1169,6 +1218,7 @@ ENDPART my $code_name=$helper->{'VARS'}->{'ANON_CODE_STORAGE_NAME'}; my $old_name=$helper->{'VARS'}->{'REUSE_OLD_CODES'}; my %moreenv = ('textwidth' => &get_textwidth($helper,$LaTeXwidth)); + $moreenv{'problem_split'} = $parmhash{'problem_stream_switch'}; my $seed=time+($$<<16)+($$); my @allcodes; if ($old_name) { @@ -1202,7 +1252,8 @@ ENDPART $moreenv{'CODE'}=&num_to_letters($code); my ($output,$fullname)= &print_resources($r,$helper,'anonymous',$type,\%moreenv, - \@master_seq,$flag_latex_header_remove); + \@master_seq,$flag_latex_header_remove, + $LaTeXwidth); $print_array[$file_num].=$output; &Apache::lonhtmlcommon::Increment_PrgWin($r,\%prog_state, &mt('last assignment').' '.$fullname); @@ -1226,9 +1277,7 @@ ENDPART my $urlp = $list_of_files[$i]; $urlp=~s|//|/|; if ($urlp=~/\//) { - my %form; - $form{'grade_target'}='tex'; - $form{'textwidth'}=&get_textwidth($helper,$LaTeXwidth); + $form{'problem_split'}=$parmhash{'problem_stream_switch'}; $form{'rndseed'}=$rndseed; if ($urlp =~ m|/home/([^/]+)/public_html|) { $urlp =~ s|/home/([^/]*)/public_html|/~$1|; @@ -1238,7 +1287,6 @@ ENDPART my $texversion=&Apache::lonnet::ssi($urlp,%form); if(($helper->{'VARS'}->{'ANSWER_TYPE'} eq 'no') || ($helper->{'VARS'}->{'ANSWER_TYPE'} eq 'only')) { - my %form; $form{'grade_target'}='answer'; $form{'answer_output_mode'}='tex'; $form{'latex_type'}=$helper->{'VARS'}->{'LATEX_TYPE'}; @@ -1402,7 +1450,8 @@ sub get_CODE { } sub print_resources { - my ($r,$helper,$person,$type,$moreenv,$master_seq,$remove_latex_header)=@_; + my ($r,$helper,$person,$type,$moreenv,$master_seq,$remove_latex_header, + $LaTeXwidth)=@_; my $current_output = ''; my ($username,$userdomain,$usersection) = split /:/,$person; my $fullname = &get_name($username,$userdomain); @@ -1411,11 +1460,22 @@ sub print_resources { $namepostfix="\\\\Name: "; $fullname = "CODE - ".$moreenv->{'CODE'}; } + 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(); + + my $page_hashref = &get_page_breaks($helper); + my %page_breaks = %$page_hashref; + foreach my $curresline (@{$master_seq}) { + if (defined $page_breaks{$curresline}) { + if($i != 0) { + $current_output.= "\\newpage\n"; + } + } + $i++; if ( !($type eq 'problems' && ($curresline!~ m/\.(problem|exam|quiz|assess|survey|form|library)$/)) ) { my ($map,$id,$res_url) = &Apache::lonnet::decode_symb($curresline); @@ -1520,13 +1580,15 @@ sub handler { # return OK; my %parmhash=&Apache::lonnet::coursedescription($ENV{'request.course.id'}); - + # my $key; # foreach $key (keys %parmhash) { # $r->print(' '.$key.'->'.$parmhash{$key}.'<-
'); # } -# return OK; +# + + &output_data($r,$helper,\%parmhash); return OK; } @@ -1580,6 +1642,14 @@ sub printHelper { $helper->declareVar('assignment'); $helper->declareVar('style_file'); $helper->declareVar('student_sort'); + $helper->declareVar('FINISHPAGE'); + + # The page breaks can get loaded initially from the course environment: + + &Apache::loncommon::restore_course_settings('print', + {'pagebreaks' => 'scalar'}); + + $helper->{VARS}->{FINISHPAGE} = $ENV{'form.pagebreaks'}; # This will persistently load in the data we want from the # very first screen. @@ -1692,6 +1762,7 @@ sub printHelper { # If we're in a sequence... if (($helper->{'VARS'}->{'construction'} ne '1') && + $helper->{VARS}->{'postdata'} && $helper->{VARS}->{'assignment'}) { # Allow problems from sequence @@ -1708,6 +1779,7 @@ sub printHelper { return $isProblem; $map return $symbFilter; +