--- loncom/interface/lonprintout.pm 2004/02/03 21:57:48 1.273 +++ loncom/interface/lonprintout.pm 2004/02/17 00:26:20 1.277 @@ -1,7 +1,7 @@ # The LearningOnline Network # Printout # -# $Id: lonprintout.pm,v 1.273 2004/02/03 21:57:48 sakharuk Exp $ +# $Id: lonprintout.pm,v 1.277 2004/02/17 00:26:20 albertel Exp $ # # Copyright Michigan State University Board of Trustees # @@ -647,6 +647,20 @@ 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; @@ -696,16 +710,9 @@ ENDPART } my ($textwidth,$textheight,$oddoffset,$evenoffset) = &page_format($papersize,$laystyle,$numberofcolumns); my $assignment = $ENV{'form.assignment'}; - 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 $LaTeXwidth=&recalcto_mm($textwidth); my @print_array=(); + my @student_names=(); if ($helper->{'VARS'}->{'PRINT_TYPE'} eq 'current_document') { #-- single document - problem, page, html, xml, ... @@ -733,7 +740,12 @@ ENDPART } my %form; $form{'grade_target'}='tex'; - $form{'textwidth'}=$LaTeXwidth; + 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{'problem_split'}=$parmhash{'problem_stream_switch'}; $form{'latex_type'}=$helper->{'VARS'}->{'LATEX_TYPE'}; if ($helper->{'VARS'}->{'curseed'}) { @@ -743,7 +755,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'); } @@ -798,7 +810,12 @@ ENDPART if ($helper->{'VARS'}->{'ANSWER_TYPE'} ne 'only') { my %form; $form{'grade_target'}='tex'; - $form{'textwidth'}=$LaTeXwidth; + 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{'problem_split'}=$parmhash{'problem_stream_switch'}; $form{'latex_type'}=$helper->{'VARS'}->{'LATEX_TYPE'}; $form{'rndseed'}=$rndseed; @@ -844,7 +861,12 @@ ENDPART } elsif ($currentURL=~/\/smppg$/) { my %form; $form{'grade_target'}='tex'; - $form{'textwidth'}=$LaTeXwidth; + 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{'latex_type'}=$helper->{'VARS'}->{'LATEX_TYPE'}; my $texversion=&Apache::lonnet::ssi($currentURL,%form); $result .= $texversion; @@ -866,7 +888,12 @@ ENDPART #-- produce an output string my %form=(); $form{'grade_target'}='tex'; - $form{'textwidth'}=$LaTeXwidth; + 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{'problem_split'}=$parmhash{'problem_stream_switch'}; $form{'latex_type'}=$helper->{'VARS'}->{'LATEX_TYPE'}; my $flag_latex_header_remove = 'NO'; @@ -960,7 +987,12 @@ ENDPART #loop over students my $flag_latex_header_remove = 'NO'; my %moreenv; - $moreenv{'form.textwidth'}=$LaTeXwidth; + 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; + } &Apache::lonnet::appenv(%moreenv); my %prog_state=&Apache::lonhtmlcommon::Create_PrgWin($r,'Print Status','Class Print Status',$#students+1); my $student_counter=-1; @@ -1024,6 +1056,7 @@ ENDPART $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; } $print_array[int($student_counter/$helper->{'VARS'}->{'NUMBER_TO_PRINT'})].=$current_output; + $student_names[int($student_counter/$helper->{'VARS'}->{'NUMBER_TO_PRINT'})].=$person.':'.$fullname.'_END_'; &Apache::lonnet::delenv('form.counter'); &Apache::lonxml::init_counter(); &Apache::lonhtmlcommon::Increment_PrgWin($r,\%prog_state, @@ -1048,7 +1081,12 @@ ENDPART if ($urlp=~/\//) { my %form; $form{'grade_target'}='tex'; - $form{'textwidth'}=$LaTeXwidth; + 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{'rndseed'}=$rndseed; if ($urlp =~ m|/home/([^/]+)/public_html|) { $urlp =~ s|/home/([^/]*)/public_html|/~$1|; @@ -1117,32 +1155,60 @@ ENDPART } #-- writing .tex file in prtspool my $temp_file; - my $filename = "/home/httpd/prtspool/$ENV{'user.name'}_$ENV{'user.domain'}_printout_".time."_".rand(10000000).".tex"; - unless ($temp_file = Apache::File->new('>'.$filename)) { - $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 $identifier = &Apache::loncommon::get_cgi_id(); + my $filename = "/home/httpd/prtspool/$ENV{'user.name'}_$ENV{'user.domain'}_printout_".$identifier.".tex"; + if (!($#print_array>0)) { + unless ($temp_file = Apache::File->new('>'.$filename)) { + $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); + } else { + my $begin=index($result,'\begin{document}',0); + my $inc=substr($result,0,$begin+16); + for (my $i=0;$i<=$#print_array;$i++) { + if ($i==0) { + $print_array[$i]=$result; + } else { + 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/; + my $num=$i+1; + $newfilename =~s/\.tex$/_$num\.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 $student_names=''; + if ($#print_array>0) { + for (my $i=0;$i<=$#print_array;$i++) { + $student_names.=$student_names[$i].'_ENDPERSON_'; + } + } else { + my $fullname = &get_name($ENV{'user.name'},$ENV{'user.domain'}); + $student_names=join(':',$ENV{'user.name'},$ENV{'user.domain'}, + $ENV{'request.course.sec'},$fullname). + '_ENDPERSON_'.'_END_'; + } + my $URLback=''; #link to original document + if ($helper->{'VARS'}->{'construction'} ne '1') { + #prints published resource + $URLback=$helper->{'VARS'}->{'postdata'}; + } else { + #prints resource from the construction space + $URLback='/'.$helper->{'VARS'}->{'filename'}; + if ($URLback=~/([^?]+)/) {$URLback=$1;} } - my $identifier = time.'_'.int(rand(1000)); &Apache::lonnet::appenv('cgi.'.$identifier.'.file' => $filename, 'cgi.'.$identifier.'.layout' => $laystyle, 'cgi.'.$identifier.'.numcol' => $numberofcolumns, @@ -1150,9 +1216,10 @@ ENDPART 'cgi.'.$identifier.'tableofcontents' => $helper->{'VARS'}->{'TABLE_CONTENTS'}, 'cgi.'.$identifier.'tableofindex' => $helper->{'VARS'}->{'TABLE_INDEX'}, 'cgi.'.$identifier.'role' => $ENV{'request.role.adv'}, - 'cgi.'.$identifier.'numberoffiles' => $#print_array); + 'cgi.'.$identifier.'numberoffiles' => $#print_array, + 'cgi.'.$identifier.'studentnames' => $student_names, + 'cgi.'.$identifier.'backref' => $URLback,); - $r->print(<