--- loncom/interface/lonprintout.pm 2004/02/05 18:35:58 1.274 +++ loncom/interface/lonprintout.pm 2004/02/26 20:50:00 1.280 @@ -1,7 +1,7 @@ # The LearningOnline Network # Printout # -# $Id: lonprintout.pm,v 1.274 2004/02/05 18:35:58 sakharuk Exp $ +# $Id: lonprintout.pm,v 1.280 2004/02/26 20:50:00 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,15 +710,7 @@ 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=(); @@ -734,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'}) { @@ -744,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'); } @@ -799,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; @@ -845,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; @@ -867,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'; @@ -956,12 +982,20 @@ ENDPART $selectionmade=8; } my @students=split /\|\|\|/, $helper->{'VARS'}->{'STUDENTS'}; - if ($helper->{'VARS'}->{'NUMBER_TO_PRINT'} eq '0') {$helper->{'VARS'}->{'NUMBER_TO_PRINT'}=$#students+1;} + if ($helper->{'VARS'}->{'NUMBER_TO_PRINT'} eq '0' || + $helper->{'VARS'}->{'NUMBER_TO_PRINT'} eq 'all' ) { + $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{'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; @@ -1050,7 +1084,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|; @@ -1119,39 +1158,67 @@ 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 { + if ($#student_names>-1) { + $student_names=$student_names[0].'_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; + $URLback=~s|^/~|/priv/|; + } + } - my $identifier = time.'_'.int(rand(1000)); &Apache::lonnet::appenv('cgi.'.$identifier.'.file' => $filename, 'cgi.'.$identifier.'.layout' => $laystyle, 'cgi.'.$identifier.'.numcol' => $numberofcolumns, @@ -1160,9 +1227,9 @@ ENDPART 'cgi.'.$identifier.'tableofindex' => $helper->{'VARS'}->{'TABLE_INDEX'}, 'cgi.'.$identifier.'role' => $ENV{'request.role.adv'}, 'cgi.'.$identifier.'numberoffiles' => $#print_array, - 'cgi.'.$identifier.'studentnames' => $student_names,); + 'cgi.'.$identifier.'studentnames' => $student_names, + 'cgi.'.$identifier.'backref' => $URLback,); - $r->print(< @@ -1445,7 +1512,7 @@ CHOOSE_STUDENTS $paramHash = Apache::lonhelper::getParamHash(); $paramHash->{'variable'} = 'NUMBER_TO_PRINT'; $helper->declareVar('NUMBER_TO_PRINT'); - addMessage("
"); + addMessage("
"); if ($helper->{VARS}->{'assignment'}) { push @{$printChoices}, ["Resources from $sequenceTitle for selected students", 'resources_for_students', 'CHOOSE_STUDENTS1']; @@ -1473,7 +1540,7 @@ CHOOSE_STUDENTS1 $paramHash = Apache::lonhelper::getParamHash(); $paramHash->{'variable'} = 'NUMBER_TO_PRINT'; $helper->declareVar('NUMBER_TO_PRINT'); - addMessage("
"); + addMessage("
"); } # FIXME: That RE should come from a library somewhere. @@ -1871,7 +1938,7 @@ sub render {

Hint: Some instructors like to leave scratch space for the student by -making the width much smaller then the width of the page.

+making the width much smaller than the width of the page.

ELEMENTHTML