[LON-CAPA-cvs] cvs: loncom /interface lonprintout.pm

albertel lon-capa-cvs@mail.lon-capa.org
Thu, 03 Aug 2006 02:36:57 -0000


albertel		Wed Aug  2 22:36:57 2006 EDT

  Modified files:              
    /loncom/interface	lonprintout.pm 
  Log:
  - some reduction in copy&paste coding
  
  
Index: loncom/interface/lonprintout.pm
diff -u loncom/interface/lonprintout.pm:1.475 loncom/interface/lonprintout.pm:1.476
--- loncom/interface/lonprintout.pm:1.475	Wed Aug  2 20:26:39 2006
+++ loncom/interface/lonprintout.pm	Wed Aug  2 22:36:56 2006
@@ -2,7 +2,7 @@
 # The LearningOnline Network
 # Printout
 #
-# $Id: lonprintout.pm,v 1.475 2006/08/03 00:26:39 albertel Exp $
+# $Id: lonprintout.pm,v 1.476 2006/08/03 02:36:56 albertel Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -827,16 +827,21 @@
     return ($name_of_resource,$name_of_sequence,$name_of_map);
 }
 
+sub copyright_line {
+    return '\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 } ';
+}
+my $end_of_student = "\n".'\special{ps:ENDOFSTUDENTSTAMP}'."\n";
 
 sub latex_corrections {
     my ($number_of_columns,$result,$selectionmade,$answer_mode) = @_;
 #    $result =~ s/\\includegraphics{/\\includegraphics\[width=\\minipagewidth\]{/g;
-    $result =~ s/\$number_of_columns/$number_of_columns/g;
+    my $copyright = &copyright_line();
     if ($selectionmade eq '1' || $answer_mode eq 'only') {
-	$result =~ s/(\\end{document})/\\strut\\vskip 0 mm\\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 \n\\special{ps:ENDOFSTUDENTSTAMP}\n $1/;
+	$result =~ s/(\\end{document})/\\strut\\vskip 0 mm $copyright $end_of_student $1/;
     } else {
-	$result =~ s/(\\end{document})/\\strut\\vspace\*{-4 mm}\\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 \n\\special{ps:ENDOFSTUDENTSTAMP}\n $1/;
+	$result =~ s/(\\end{document})/\\strut\\vspace\*{-4 mm}\\newline $copyright $end_of_student $1/;
     }
+    $result =~ s/\$number_of_columns/$number_of_columns/g;
     $result =~ s/(\\end{longtable}\s*)(\\strut\\newline\\noindent\\makebox\[\\textwidth\/$number_of_columns\]\[b\]{\\hrulefill})/$2$1/g;
     $result =~ s/(\\end{longtable}\s*)\\strut\\newline/$1/g;
 #-- LaTeX corrections     
@@ -1899,8 +1904,7 @@
 
     &Apache::lonxml::clear_problem_counter();
     my %page_breaks  = &get_page_breaks($helper);
-    my @format_array = split(/\|/,$helper->{'VARS'}->{'FORMAT'});
-    my $columns_in_format = $format_array[1];
+    my $columns_in_format = (split(/\|/,$helper->{'VARS'}->{'FORMAT'}))[1];
     #
     #   end each student with a 
     #   Special that allows the post processor to even out the page
@@ -1990,23 +1994,23 @@
     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);
-    if ($current_output=~/\\documentclass/) {
-	if ($columns_in_format == 1) {
-	    $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]{$HeaderLine$namepostfix}}\\vskip 5 mm /;
+    my $header_line =
+	&format_page_header($parmhash{'print_header_format'},
+			    $currentassignment, $courseidinfo, $fullname);
+    my $header_start = ($columns_in_format == 1) ? '\lhead'
+	                                         : '\fancyhead[LO]';
+    $header_line = $header_start.'{'.$header_line.'}';
 
-	}
+    if ($current_output=~/\\documentclass/) {
+	$current_output =~ s/\\begin{document}/\\setlength{\\topmargin}{1cm} \\begin{document}\\noindent\\parbox{\\minipagewidth}{\\noindent$header_line$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."\n\\special{ps:ENDOFSTUDENTSTAMP}\n".'\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."\n\\special{ps:ENDOFSTUDENTSTAMP}\n".'\setcounter{page}{1}\noindent\parbox{\minipagewidth}{\noindent\\fancyhead[LO]{'.$HeaderLine.'}'.$namepostfix.'} \vskip 5 mm '.$current_output;
-	}
+	my $blankpages = 
+	    '\clearpage\strut\clearpage'x$helper->{'VARS'}->{'EMPTY_PAGES'};
+	    
+	$current_output = '\strut\vspace*{-6 mm}\\newline'.
+	    &copyright_line().' \newpage '.$blankpages.$end_of_student.
+	    '\setcounter{page}{1}\noindent\parbox{\minipagewidth}{\noindent'.
+	    $header_line.$namepostfix.'} \vskip 5 mm '.$current_output;
     }
     #
     #  Close the student bracketing.