--- loncom/interface/lonprintout.pm 2006/05/24 10:49:04 1.438 +++ loncom/interface/lonprintout.pm 2006/07/03 13:48:41 1.455 @@ -1,7 +1,7 @@ # The LearningOnline Network # Printout # -# $Id: lonprintout.pm,v 1.438 2006/05/24 10:49:04 foxr Exp $ +# $Id: lonprintout.pm,v 1.455 2006/07/03 13:48:41 albertel Exp $ # # Copyright Michigan State University Board of Trustees # @@ -42,8 +42,39 @@ use Apache::lonratedt; use POSIX qw(strftime); use Apache::lonlocal; use Carp; +use lib '/home/httpd/lib/perl/'; +use LONCAPA; my %perm; +my %parmhash; + + +# Format a header according to a format. +# + +# Substitutions: +# %a - Assignment name. +# %c - Course name. +# %n - Student name. +# +sub format_page_header { + my ($format, $assignment, $course, $student) = @_; + + # Default format? + + if ($format eq '') { + $format = "\\textbf{$student} $course \\hfill \\thepage \\\\ \\textit{$assignment}"; + + } else { + $format =~ s/%a/$assignment/g; + $format =~ s/%c/$course/g; + $format =~ s/%n/$student/g; + } + + + return $format; + +} # # Convert a numeric code to letters @@ -700,14 +731,14 @@ sub get_name { if (!defined($udom)) { $udom=$env{'user.domain'}; } my $plainname=&Apache::loncommon::plainname($uname,$udom); if ($plainname=~/^\s*$/) { $plainname=$uname.'@'.$udom; } - $plainname=&Apache::lonxml::latex_special_symbols($plainname,'header'); + $plainname=&Apache::lonxml::latex_special_symbols($plainname,'header'); return $plainname; } 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; } @@ -715,22 +746,28 @@ sub get_course { sub page_format_transformation { my ($papersize,$layout,$numberofcolumns,$choice,$text,$assignment,$tableofcontents,$indexlist,$selectionmade) = @_; my ($textwidth,$textheight,$oddoffset,$evenoffset,$topmargin); + if ($selectionmade eq '4') { $assignment='Problems from the Whole Course'; } else { $assignment=&Apache::lonxml::latex_special_symbols($assignment,'header'); } ($textwidth,$textheight,$oddoffset,$evenoffset,$topmargin) = &page_format($papersize,$layout,$numberofcolumns,$topmargin); + + my $name = &get_name(); my $courseidinfo = &get_course(); if (defined($courseidinfo)) { $courseidinfo=' - '.$courseidinfo } + my $header_text = $parmhash{'print_header_format'}; + $header_text = &format_page_header($header_text, $assignment, + $courseidinfo, $name); my $topmargintoinsert = ''; if ($topmargin ne '0') {$topmargintoinsert='\setlength{\topmargin}{'.$topmargin.'}';} my $fancypagestatement=''; if ($numberofcolumns eq '2') { - $fancypagestatement="\\fancyhead{}\\fancyhead[LO]{\\textbf{$name} $courseidinfo \\hfill \\thepage \\\\ \\textit{$assignment}}"; + $fancypagestatement="\\fancyhead{}\\fancyhead[LO]{$header_text}"; } else { - $fancypagestatement="\\rhead{}\\chead{}\\lhead{\\textbf{$name} $courseidinfo \\hfill \\thepage \\\\ \\textit{$assignment}}"; + $fancypagestatement="\\rhead{}\\chead{}\\lhead{$header_text}"; } if ($layout eq 'album') { $text =~ s/\\begin{document}/\\setlength{\\oddsidemargin}{$oddoffset}\\setlength{\\evensidemargin}{$evenoffset}$topmargintoinsert\n\\setlength{\\textwidth}{$textwidth}\\setlength{\\textheight}{$textheight}\\setlength{\\textfloatsep}{8pt plus 2\.0pt minus 4\.0pt}\n\\newlength{\\minipagewidth}\\setlength{\\minipagewidth}{\\textwidth\/\$number_of_columns-0\.2cm}\\usepackage{fancyhdr}\\addtolength{\\headheight}{\\baselineskip}\n\\pagestyle{fancy}$fancypagestatement\\begin{document}\\voffset=-0\.8 cm\\setcounter{page}{1}\n /; @@ -1259,7 +1296,7 @@ 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)$/) { + } elsif ($cleanURL=~/\/(smppg|grppg|syllabus|aboutme|bulletinboard)$/) { $form{'latex_type'}=$helper->{'VARS'}->{'LATEX_TYPE'}; if ($currentURL=~/\/syllabus$/) {$currentURL=~s/\/res//;} $resources_printed .= $currentURL.':'; @@ -1369,15 +1406,20 @@ ENDPART my $courseidinfo = &get_course(); if (defined($courseidinfo)) { $courseidinfo=' - '.$courseidinfo } $prevassignment=$assignment; + my $header_text = $parmhash{'print_header_format'}; + $header_text = &format_page_header($header_text, + $assignment, + $courseidinfo, + $name); if ($numberofcolumns eq '1') { - $result .='\newpage \noindent\parbox{\minipagewidth}{\noindent\\lhead{\\textit{\\textbf{'.$name.'}}'.$courseidinfo.' \\hfill \\thepage \\\\ \\textit{'.$assignment.'}}} \vskip 5 mm '; + $result .='\newpage \noindent\parbox{\minipagewidth}{\noindent\\lhead{'.$header_text.'}} \vskip 5 mm '; } else { - $result .='\newpage \noindent\parbox{\minipagewidth}{\noindent\\fancyhead[LO]{\\textit{\\textbf{'.$name.'}}'.$courseidinfo.' \\hfill \\thepage \\\\ \\textit{'.$assignment.'}}} \vskip 5 mm '; + $result .='\newpage \noindent\parbox{\minipagewidth}{\noindent\\fancyhead[LO]{'.$header_text.'}} \vskip 5 mm '; } } $result .= $texversion; $flag_latex_header_remove = 'YES'; - } elsif ($urlp=~/\/(smppg|syllabus|aboutme|bulletinboard)$/) { + } elsif ($urlp=~/\/(smppg|grppg|syllabus|aboutme|bulletinboard)$/) { $form{'latex_type'}=$helper->{'VARS'}->{'LATEX_TYPE'}; if ($urlp=~/\/syllabus$/) {$urlp=~s/\/res//;} $resources_printed .= $urlp.':'; @@ -1559,6 +1601,7 @@ ENDPART } my @master_seq=split /\|\|\|/, $helper->{'VARS'}->{'RESOURCES'}; my ($type) = split(/_/,$helper->{'VARS'}->{'PRINT_TYPE'}); + &adjust_number_to_print($helper); my $number_per_page=$helper->{'VARS'}->{'NUMBER_TO_PRINT'}; if ($number_per_page eq '0' || $number_per_page eq 'all') { $number_per_page=$num_todo; @@ -1670,14 +1713,12 @@ ENDPART $selectionmade, $helper->{'VARS'}->{'ANSWER_TYPE'}); } - &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"); + 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'} /; + } #-- writing .tex file in prtspool my $temp_file; @@ -1733,7 +1774,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'}; @@ -1802,6 +1843,9 @@ sub print_resources { $namepostfix="\\\\Name: "; $fullname = "CODE - ".$moreenv->{'CODE'}; } + # Fullname may have special latex characters that need \ prefixing: + # + my $i = 0; #goes through all resources, checks if they are available for #current student, and produces output @@ -1810,6 +1854,16 @@ sub print_resources { my %page_breaks = &get_page_breaks($helper); my @format_array = split(/\|/,$helper->{'VARS'}->{'FORMAT'}); my $columns_in_format = $format_array[1]; + # + # end each student with a + # Special that allows the post processor to even out the page + # counts later. Nasty problem this... it would be really + # nice to put the special in as a postscript comment + # e.g. \special{ps:\ENDOFSTUDENTSTAMP} unfortunately, + # The special gets passed the \ and dvips puts it in the output file + # so we will just rely on prntout.pl to strip ENDOFSTUDENTSTAMP from the + # postscript. Each ENDOFSTUDENTSTAMP will go on a line by itself. + # foreach my $curresline (@{$master_seq}) { if (defined $page_breaks{$curresline}) { @@ -1860,7 +1914,7 @@ sub print_resources { $rendered =~ s/\\end{document}//; } $current_output .= $rendered; - } elsif ($res_url=~/\/(smppg|syllabus|aboutme|bulletinboard)$/) { + } elsif ($res_url=~/\/(smppg|grppg|syllabus|aboutme|bulletinboard)$/) { $printed .= $curresline.':'; my $rendered = &Apache::loncommon::get_student_view($curresline,$username,$userdomain,$env{'request.course.id'},'tex',$moreenv); @@ -1889,22 +1943,29 @@ sub print_resources { if (defined($courseidinfo)) { $courseidinfo=' - '.$courseidinfo } if ($usersection ne '') {$courseidinfo.=' - Sec. '.$usersection} my $currentassignment=&Apache::lonxml::latex_special_symbols($helper->{VARS}->{'assignment'},'header'); + my $HeaderLine = $parmhash{'print_header_format'}; + $HeaderLine = format_page_header($HeaderLine, $currentassignment, $courseidinfo, $fullname); + &Apache::lonnet::logthis("Hdr format: $HeaderLine"); if ($current_output=~/\\documentclass/) { if ($columns_in_format == 1) { - $current_output =~ s/\\begin{document}/\\setlength{\\topmargin}{1cm} \\begin{document}\\noindent\\parbox{\\minipagewidth}{\\noindent\\lhead{\\textit{\\textbf{$fullname}}$courseidinfo \\hfill \\thepage \\\\ \\textit{$currentassignment}$namepostfix}}\\vskip 5 mm /; + $current_output =~ s/\\begin{document}/\\setlength{\\topmargin}{1cm} \\begin{document}\\noindent\\parbox{\\minipagewidth}{\\noindent\\lhead{$HeaderLine$namepostfix}}\\vskip 5 mm /; } else { - $current_output =~ s/\\begin{document}/\\setlength{\\topmargin}{1cm} \\begin{document}\\noindent\\parbox{\\minipagewidth}{\\noindent\\fancyhead[LO]{\\textit{\\textbf{$fullname}}$courseidinfo \\hfill \\thepage \\\\ \\textit{$currentassignment}$namepostfix}}\\vskip 5 mm /; + $current_output =~ s/\\begin{document}/\\setlength{\\topmargin}{1cm} \\begin{document}\\noindent\\parbox{\\minipagewidth}{\\noindent\\fancyhead[LO]{$HeaderLine$namepostfix}}\\vskip 5 mm /; } } else { my $blankpages = ''; for (my $j=0;$j<$helper->{'VARS'}->{'EMPTY_PAGES'};$j++) {$blankpages.='\clearpage\strut\clearpage';} if ($columns_in_format == 1) { - $current_output = '\strut\vspace*{-6 mm}\\newline\\noindent\\makebox[\\textwidth/$number_of_columns][b]{\\hrulefill}\vspace*{-2 mm}\\newline\\noindent{\\tiny Printed from LON-CAPA\\copyright MSU{\\hfill} Licensed under GNU General Public License }\\newpage '.$blankpages.'\setcounter{page}{1}\noindent\parbox{\minipagewidth}{\noindent\\lhead{\\textit{\\textbf{'.$fullname.'}}'.$courseidinfo.' \\hfill \\thepage \\\\ \\textit{'.$currentassignment.'}'.$namepostfix.'}} \vskip 5 mm '.$current_output; + $current_output = '\strut\vspace*{-6 mm}\\newline\\noindent\\makebox[\\textwidth/$number_of_columns][b]{\\hrulefill}\vspace*{-2 mm}\\newline\\noindent{\\tiny Printed from LON-CAPA\\copyright MSU{\\hfill} Licensed under GNU General Public License }\\newpage '.$blankpages.'\setcounter{page}{1}\noindent\parbox{\minipagewidth}{\noindent\\lhead{'.$HeaderLine.'}'.$namepostfix.'} \vskip 5 mm '.$current_output; } else { - $current_output = '\strut\vspace*{-6 mm}\\newline\\noindent\\makebox[\\textwidth/$number_of_columns][b]{\\hrulefill}\vspace*{-2 mm}\\newline\\noindent{\\tiny Printed from LON-CAPA\\copyright MSU{\\hfill} Licensed under GNU General Public License }\\newpage '.$blankpages.'\setcounter{page}{1}\noindent\parbox{\minipagewidth}{\noindent\\fancyhead[LO]{\\textit{\\textbf{'.$fullname.'}}'.$courseidinfo.' \\hfill \\thepage \\\\ \\textit{'.$currentassignment.'}'.$namepostfix.'}} \vskip 5 mm '.$current_output; + $current_output = '\strut\vspace*{-6 mm}\\newline\\noindent\\makebox[\\textwidth/$number_of_columns][b]{\\hrulefill}\vspace*{-2 mm}\\newline\\noindent{\\tiny Printed from LON-CAPA\\copyright MSU{\\hfill} Licensed under GNU General Public License }\\newpage '.$blankpages.'\setcounter{page}{1}\noindent\parbox{\minipagewidth}{\noindent\\fancyhead[LO]{'.$HeaderLine.'}'.$namepostfix.'} \vskip 5 mm '.$current_output; } } + # + # Close the student bracketing. + # + $current_output .= "\n\\special{ps:ENDOFSTUDENTSTAMP}\n"; return ($current_output,$fullname, $printed); } @@ -1923,7 +1984,7 @@ sub handler { } - my %parmhash=&Apache::lonnet::coursedescription($env{'request.course.id'}); + %parmhash=&Apache::lonnet::coursedescription($env{'request.course.id'}); @@ -2179,7 +2240,7 @@ HELPERFRAGMENT # If the user has pfo (print for otheres) allow them to print all # problems and resources in the entier course, optionally for selected students if ($perm{'pfo'} && - ($helper->{VARS}->{'postdata'}=~/\/res\// || $helper->{VARS}->{'postdata'}=~/\/(syllabus|smppg|aboutme|bulletinboard)$/)) { + ($helper->{VARS}->{'postdata'}=~/\/res\// || $helper->{VARS}->{'postdata'}=~/\/(syllabus|smppg|grppg|aboutme|bulletinboard)$/)) { push @{$printChoices}, ['Problems from entire course', 'all_problems', 'ALL_PROBLEMS']; push @{$printChoices}, ['Resources from entire course', 'all_resources', 'ALL_RESOURCES']; @@ -2247,8 +2308,8 @@ ALL_PROBLEMS All assignments in a single PDF file Each PDF contains exactly one section Each PDF contains exactly one assignment - - Specify Number: + + Specify the number of assignments per PDF: RESOURCE_SELECTOR @@ -2286,7 +2347,7 @@ CHOOSE_STUDENTS } } - my $code_selection = "\n"; + my $code_selection; foreach my $code (sort {uc($a) cmp uc($b)} (keys(%codes_to_print))) { my $choice = $code; if ($code =~ /^[A-Z]+$/) { # Alpha code @@ -2296,10 +2357,17 @@ CHOOSE_STUDENTS } if (%codes_to_print) { $code_selection .=' - - push(@{$state->{CHOICES}},@{$helper->{DATA}{ALL_CODE_CHOICES}}); - + Choose single code from list + + + + + push(@{$state->{CHOICES}},@{$helper->{DATA}{ALL_CODE_CHOICES}}); + + +
'.$/; + } @@ -2357,12 +2425,9 @@ CHOOSE_STUDENTS
- Choose single code from list - - $code_selection - -
+ + Reprint a set of saved CODEs: @@ -2408,8 +2473,8 @@ CHOOSE_ANON1 All assignments in a single PDF file Each PDF contains exactly one section Each PDF contains exactly one assignment - - Specify Number: + + Specify the number of assignments per PDF: RESOURCE_SELECTOR @@ -2468,12 +2533,7 @@ CHOOSE_STUDENTS1
- Choose single code from list - - $code_selection - -
Reprint a set of saved CODEs: @@ -2936,9 +2996,9 @@ sub preprocess { my $helper = Apache::lonhelper::getHelper(); my $format = $helper->{VARS}->{$self->{'formatvar'}}; -# if (substr($format, 2, 1) ne '1') { -# $helper->changeState($self->{NEXTSTATE}); -# } + if (substr($format, 2, 1) ne '1') { + $helper->changeState($self->{NEXTSTATE}); + } return 1; }