--- loncom/interface/lonprintout.pm 2004/02/19 19:35:06 1.270.2.1 +++ loncom/interface/lonprintout.pm 2004/02/03 21:57:48 1.273 @@ -1,7 +1,7 @@ # The LearningOnline Network # Printout # -# $Id: lonprintout.pm,v 1.270.2.1 2004/02/19 19:35:06 albertel Exp $ +# $Id: lonprintout.pm,v 1.273 2004/02/03 21:57:48 sakharuk Exp $ # # Copyright Michigan State University Board of Trustees # @@ -647,20 +647,6 @@ sub path_to_problem { return '{\small\noindent\verb|'.$newurlp.'|\vskip 0 mm}'; } -sub recalcto_mm { - my $textwidth=shift; - my $LaTeXwidth; - if ($textwidth=~/(\d+\.?\d*)\s*cm/) { - $LaTeXwidth = $1*10; - } elsif ($textwidth=~/(\d+\.?\d*)\s*mm/) { - $LaTeXwidth = $1; - } elsif ($textwidth=~/(\d+\.?\d*)\s*in/) { - $LaTeXwidth = $1*25.4; - } - $LaTeXwidth.=' mm'; - return $LaTeXwidth; -} - sub output_data { my ($r,$helper,$rparmhash) = @_; my %parmhash = %$rparmhash; @@ -710,7 +696,17 @@ ENDPART } my ($textwidth,$textheight,$oddoffset,$evenoffset) = &page_format($papersize,$laystyle,$numberofcolumns); my $assignment = $ENV{'form.assignment'}; - my $LaTeXwidth=&recalcto_mm($textwidth); + my $LaTeXwidth; + if ($textwidth=~/(\d+\.?\d*)\s*cm/) { + $LaTeXwidth = $1*10; + } elsif ($textwidth=~/(\d+\.?\d*)\s*mm/) { + $LaTeXwidth = $1; + } elsif ($textwidth=~/(\d+\.?\d*)\s*in/) { + $LaTeXwidth = $1*25.4; + } + $LaTeXwidth.=' mm'; + my @print_array=(); + if ($helper->{'VARS'}->{'PRINT_TYPE'} eq 'current_document') { #-- single document - problem, page, html, xml, ... my $currentURL; @@ -737,12 +733,7 @@ ENDPART } my %form; $form{'grade_target'}='tex'; - if ($helper->{'VARS'}->{'pagesize.width'}=~/\d+/ && - $helper->{'VARS'}->{'pagesize.widthunit'}=~/\w+/) { - $form{'textwidth'}=&recalcto_mm($helper->{'VARS'}->{'pagesize.width'}.' '.$helper->{'VARS'}->{'pagesize.widthunit'}); - } else { - $form{'textwidth'}=$LaTeXwidth; - } + $form{'textwidth'}=$LaTeXwidth; $form{'problem_split'}=$parmhash{'problem_stream_switch'}; $form{'latex_type'}=$helper->{'VARS'}->{'LATEX_TYPE'}; if ($helper->{'VARS'}->{'curseed'}) { @@ -752,7 +743,7 @@ ENDPART &Apache::lonnet::appenv(%moreenv); &Apache::lonnet::delenv('form.counter'); &Apache::lonxml::init_counter(); - $texversion.=&Apache::lonnet::ssi($currentURL,%form); + $texversion=&Apache::lonnet::ssi($currentURL,%form); &Apache::lonnet::delenv('form.counter'); &Apache::lonnet::delenv('request.filename'); } @@ -807,12 +798,7 @@ ENDPART if ($helper->{'VARS'}->{'ANSWER_TYPE'} ne 'only') { my %form; $form{'grade_target'}='tex'; - if ($helper->{'VARS'}->{'pagesize.width'}=~/\d+/ && - $helper->{'VARS'}->{'pagesize.widthunit'}=~/\w+/) { - $form{'textwidth'}=&recalcto_mm($helper->{'VARS'}->{'pagesize.width'}.' '.$helper->{'VARS'}->{'pagesize.widthunit'}); - } else { - $form{'textwidth'}=$LaTeXwidth; - } + $form{'textwidth'}=$LaTeXwidth; $form{'problem_split'}=$parmhash{'problem_stream_switch'}; $form{'latex_type'}=$helper->{'VARS'}->{'LATEX_TYPE'}; $form{'rndseed'}=$rndseed; @@ -858,12 +844,7 @@ ENDPART } elsif ($currentURL=~/\/smppg$/) { my %form; $form{'grade_target'}='tex'; - if ($helper->{'VARS'}->{'pagesize.width'}=~/\d+/ && - $helper->{'VARS'}->{'pagesize.widthunit'}=~/\w+/) { - $form{'textwidth'}=&recalcto_mm($helper->{'VARS'}->{'pagesize.width'}.' '.$helper->{'VARS'}->{'pagesize.widthunit'}); - } else { - $form{'textwidth'}=$LaTeXwidth; - } + $form{'textwidth'}=$LaTeXwidth; $form{'latex_type'}=$helper->{'VARS'}->{'LATEX_TYPE'}; my $texversion=&Apache::lonnet::ssi($currentURL,%form); $result .= $texversion; @@ -885,12 +866,7 @@ ENDPART #-- produce an output string my %form=(); $form{'grade_target'}='tex'; - if ($helper->{'VARS'}->{'pagesize.width'}=~/\d+/ && - $helper->{'VARS'}->{'pagesize.widthunit'}=~/\w+/) { - $form{'textwidth'}=&recalcto_mm($helper->{'VARS'}->{'pagesize.width'}.' '.$helper->{'VARS'}->{'pagesize.widthunit'}); - } else { - $form{'textwidth'}=$LaTeXwidth; - } + $form{'textwidth'}=$LaTeXwidth; $form{'problem_split'}=$parmhash{'problem_stream_switch'}; $form{'latex_type'}=$helper->{'VARS'}->{'LATEX_TYPE'}; my $flag_latex_header_remove = 'NO'; @@ -979,22 +955,19 @@ ENDPART $selectionmade=8; } my @students=split /\|\|\|/, $helper->{'VARS'}->{'STUDENTS'}; + if ($helper->{'VARS'}->{'NUMBER_TO_PRINT'} eq '0') {$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; - if ($helper->{'VARS'}->{'pagesize.width'}=~/\d+/ && - $helper->{'VARS'}->{'pagesize.widthunit'}=~/\w+/) { - $moreenv{'textwidth'}=&recalcto_mm($helper->{'VARS'}->{'pagesize.width'}.' '.$helper->{'VARS'}->{'pagesize.widthunit'}); - } else { - $moreenv{'textwidth'}=$LaTeXwidth; - } + $moreenv{'form.textwidth'}=$LaTeXwidth; &Apache::lonnet::appenv(%moreenv); my %prog_state=&Apache::lonhtmlcommon::Create_PrgWin($r,'Print Status','Class Print Status',$#students+1); + my $student_counter=-1; foreach my $person (@students) { + $student_counter++; my $current_output = ''; -# my ($usersection,$username,$userdomain) = split /:/,$person; - my ($username,$userdomain) = split /:/,$person; + my ($username,$userdomain,$usersection) = split /:/,$person; my $fullname = &get_name($username,$userdomain); if ($parmhash{'anonymous_quiz'}=~/yes/) {$fullname=' ';} #put here something reasonable for anonymous exams or quiz @@ -1041,6 +1014,7 @@ ENDPART } my $courseidinfo = &get_course(); if (defined($courseidinfo)) { $courseidinfo=' - '.$courseidinfo } + if ($usersection ne '') {$courseidinfo.=' - Sec. '.$usersection} my $currentassignment=&Apache::lonxml::latex_special_symbols($helper->{VARS}->{'assignment'},'header'); if ($current_output=~/\\documentclass/) { $current_output =~ s/\\begin{document}/\\setlength{\\topmargin}{1cm} \\begin{document}\\noindent\\lhead{\\textit{\\textbf{$fullname}}$courseidinfo \\hfill \\thepage \\\\ \\textit{$currentassignment}}\\vskip 3 mm /; @@ -1049,14 +1023,14 @@ ENDPART for (my $j=0;$j<$helper->{'VARS'}->{'EMPTY_PAGES'};$j++) {$blanspages.='\clearpage\strut\clearpage';} $current_output = '\strut\\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 }\\newpage '.$blanspages.'\setcounter{page}{1}\noindent\parbox{\minipagewidth}{\noindent\\lhead{\\textit{\\textbf{'.$fullname.'}}'.$courseidinfo.' \\hfill \\thepage \\\\ \\textit{'.$currentassignment.'}}} \vskip -5 mm '.$current_output; } - $result .= $current_output; + $print_array[int($student_counter/$helper->{'VARS'}->{'NUMBER_TO_PRINT'})].=$current_output; &Apache::lonnet::delenv('form.counter'); &Apache::lonxml::init_counter(); &Apache::lonhtmlcommon::Increment_PrgWin($r,\%prog_state, &mt('last student').' '.$fullname); } &Apache::lonhtmlcommon::Close_PrgWin($r,\%prog_state); - $result .= '\end{document}'; + $result .= $print_array[0].' \end{document}'; &Apache::lonnet::delenv('form.textwidth'); } elsif ($helper->{'VARS'}->{'PRINT_TYPE'} eq 'problems_from_directory') { #prints selected problems from the subdirectory @@ -1074,12 +1048,7 @@ ENDPART if ($urlp=~/\//) { my %form; $form{'grade_target'}='tex'; - if ($helper->{'VARS'}->{'pagesize.width'}=~/\d+/ && - $helper->{'VARS'}->{'pagesize.widthunit'}=~/\w+/) { - $form{'textwidth'}=&recalcto_mm($helper->{'VARS'}->{'pagesize.width'}.' '.$helper->{'VARS'}->{'pagesize.widthunit'}); - } else { - $form{'textwidth'}=$LaTeXwidth; - } + $form{'textwidth'}=$LaTeXwidth; $form{'rndseed'}=$rndseed; if ($urlp =~ m|/home/([^/]+)/public_html|) { $urlp =~ s|/home/([^/]*)/public_html|/~$1|; @@ -1138,6 +1107,7 @@ ENDPART #-------------------------------------------------------- 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'}); $result = &latex_corrections($number_of_columns,$result); + for (my $i=1;$i<=$#print_array;$i++) {$print_array[$i] = &latex_corrections($number_of_columns,$print_array[$i]);} #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'} /; @@ -1152,6 +1122,25 @@ ENDPART $r->log_error("Couldn't open $filename for output $!"); return SERVER_ERROR; } + print $temp_file $result; + my $begin=index($result,'\begin{document}',0); + my $inc=substr($result,0,$begin+16); + if ($#print_array>0) { + for (my $i=1;$i<=$#print_array;$i++) { + my $anobegin=index($print_array[$i],'\setcounter{page}',0); + substr($print_array[$i],0,$anobegin)=''; + $print_array[$i]=$inc.$print_array[$i].'\end{document}'; + my $temp_file; + my $newfilename=$filename; + $newfilename =~s/\.tex$/_add$i\.tex/; + unless ($temp_file = Apache::File->new('>'.$newfilename)) { + $r->log_error("Couldn't open $newfilename for output $!"); + return SERVER_ERROR; + } + print $temp_file $print_array[$i]; + } + + } my $identifier = time.'_'.int(rand(1000)); &Apache::lonnet::appenv('cgi.'.$identifier.'.file' => $filename, @@ -1160,9 +1149,9 @@ ENDPART 'cgi.'.$identifier.'.selection' => $selectionmade, 'cgi.'.$identifier.'tableofcontents' => $helper->{'VARS'}->{'TABLE_CONTENTS'}, 'cgi.'.$identifier.'tableofindex' => $helper->{'VARS'}->{'TABLE_INDEX'}, - 'cgi.'.$identifier.'role' => $ENV{'request.role.adv'}); + 'cgi.'.$identifier.'role' => $ENV{'request.role.adv'}, + 'cgi.'.$identifier.'numberoffiles' => $#print_array); - print $temp_file $result; $r->print(< @@ -1412,7 +1401,6 @@ HELPERFRAGMENT if ($helper->{VARS}->{'assignment'}) { push @{$printChoices}, ["Problems from $sequenceTitle for selected students", 'problems_for_students', 'CHOOSE_STUDENTS']; } - &Apache::lonxml::xmlparse($r, 'helper', < (mark them then click "next" button)
@@ -1443,10 +1431,16 @@ HELPERFRAGMENT CHOOSE_STUDENTS + addMessage("
Number of assignments printed at the same time: "); + $paramHash = Apache::lonhelper::getParamHash(); + $paramHash->{'variable'} = 'NUMBER_TO_PRINT'; + $helper->declareVar('NUMBER_TO_PRINT'); + addMessage("
"); + if ($helper->{VARS}->{'assignment'}) { push @{$printChoices}, ["Resources from $sequenceTitle for selected students", 'resources_for_students', 'CHOOSE_STUDENTS1']; } - &Apache::lonxml::xmlparse($r, 'helper', <
Select resources for the assignment
@@ -1465,6 +1459,11 @@ CHOOSE_STUDENTS CHOOSE_STUDENTS1 + addMessage("
Number of assignments printed at the same time: "); + $paramHash = Apache::lonhelper::getParamHash(); + $paramHash->{'variable'} = 'NUMBER_TO_PRINT'; + $helper->declareVar('NUMBER_TO_PRINT'); + addMessage("
"); } # FIXME: That RE should come from a library somewhere.