--- loncom/interface/lonprintout.pm 2003/05/14 13:10:11 1.166 +++ loncom/interface/lonprintout.pm 2008/02/26 10:46:14 1.515 @@ -1,7 +1,7 @@ # The LearningOnline Network # Printout # -# $Id: lonprintout.pm,v 1.166 2003/05/14 13:10:11 albertel Exp $ +# $Id: lonprintout.pm,v 1.515 2008/02/26 10:46:14 foxr Exp $ # # Copyright Michigan State University Board of Trustees # @@ -22,20 +22,8 @@ # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA # # /home/httpd/html/adm/gpl.txt -# # http://www.lon-capa.org/ # -# (Internal Server Error Handler -# -# (Login Screen -# 5/21/99,5/22,5/25,5/26,5/31,6/2,6/10,7/12,7/14, -# 1/14/00,5/29,5/30,6/1,6/29,7/1,11/9 Gerd Kortemeyer) -# -# 3/1/1 Gerd Kortemeyer) -# -# 3/1 Gerd Kortemeyer -# -# 9/17 Alex Sakharuk # package Apache::lonprintout; @@ -49,741 +37,425 @@ use Apache::grades; use Apache::edit; use Apache::File(); use Apache::lonnavmaps; +use Apache::admannotations; +use HTTP::Response; + +use LONCAPA::map(); use POSIX qw(strftime); -use GDBM_File; +use Apache::lonlocal; +use Carp; +use LONCAPA; + +my %perm; +my %parmhash; +my $resources_printed; +# Global variables that describe errors in ssi calls detected by ssi_with_retries. +# -my %hash; -my $LaTeXwidth = 0; +my $ssi_error; # True if there was an ssi error. +my $ssi_last_error_resource; # The resource URI that could not be fetched. +my $ssi_last_error; # The error text from the server. (e.g. 500 Server timed out). -sub headerform { - my $r = shift; - $r->print(< - -LON-CAPA output for printing - - -
-ENDHEADER +# +# Our ssi max retry count. +# - if ($ENV{'form.postdata'}=~m|^/res/|) { - $r->print(<Path to current document: $ENV{'form.postdata'}

-ENDHEADER1 - } -} +my $ssi_retry_count = 5; # Some arbitrary value. -sub menu_for_output { - my $r = shift; - my ($title_for_single_resource,$title_for_sequence,$title_for_main_map) = &details_for_menu; - my $assignment = $title_for_sequence; - if ($title_for_single_resource ne '') {$title_for_single_resource = '"'.$title_for_single_resource.'"';} - if ($title_for_sequence ne '') {$title_for_sequence = '"'.$title_for_sequence.'"';} - if ($title_for_main_map ne '') {$title_for_main_map = '"'.$title_for_main_map.'"';} - $ENV{'form.postdata'} =~ s|http://[^/]+||; - my $subdir_to_print = $ENV{'form.postdata'}; - $subdir_to_print =~ m/\/([^\/]+)$/; - $subdir_to_print =~ s/\Q$1\E//; - $r->print(<What do you want to print? Make a choice.
- - - - Current document $title_for_single_resource -(prints what you just saw on the screen)
-ENDMENUOUT1 - if ($ENV{'form.postdata'}=~/\/res\//) { - $r->print(< Problem(s) from $title_for_sequence
- Problem(s) plus page(s) or html/xml file(s) from $title_for_sequence
-ENDMENUOUT2 - } - if (($ENV{'request.role'}=~m/^cc\./ or $ENV{'request.role'}=~m/^in\./ or $ENV{'request.role'}=~m/^ta\./) and ($ENV{'form.postdata'}=~/\/res\//)) { - $r->print(< All problems in this course (warning: this may be time consuming)
-
- All problems from $title_for_sequence for selected students

-ENDMENUOUT6 - } - my $subdirtoprint = &Apache::lonnet::filelocation("",$ENV{'form.url'}); - $subdirtoprint =~ s/\/[^\/]+$//; - if ((&Apache::lonnet::allowed('bre',$subdirtoprint) eq 'F') and ($ENV{'form.postdata'}=~/\.(problem|exam|quiz|assess|survey|form|library|page|xml|html|htm|xhtml|xhtm)/)) { - $r->print(< Problems from current subdirectory $subdir_to_print
-ENDMENUOUT4 - } - $r->print(<



-

And what page format do you prefer?

- - - - - - - -
- Landscape
- Portrait
-
  - Number of columns: - - Paper size (format [width x height]): -
-
- -ENDMENUOUT5 -} +# Fetch the contents of a resource, uninterpreted. +# This is used here to fetch a latex file to be included +# verbatim into the printout< +# NOTE: Ask Guy if there is a lonnet function similar to this? +# +# Parameters: +# URL of the file +# +sub fetch_raw_resource { + my ($url) = @_; + my $filename = &Apache::lonnet::filelocation("", $url); + my $contents = &Apache::lonnet::getfile($filename); -sub sequence_content_menu { - my ($key_to,$r) = @_; - my $primary_sequence; - my $symbolic = &Apache::lonnet::symbread($ENV{'form.url'}); - my @sequence = split('___',$symbolic); - $primary_sequence=&Apache::lonnet::clutter($sequence[0]); - my @master_seq = &coming_from_hash($primary_sequence); - my @titles_master_seq = (); - for (my $i=0;$i<=$#master_seq;$i++) { - my ($path,$title,$symb) = split /&&/,$master_seq[$i]; - $master_seq[$i] = $path.'&&'.$symb; - push @titles_master_seq, $title; - } - my @master_seq_view = @master_seq; - if ($ENV{'user.adv'}) { - for (my $i=0;$i<=$#master_seq_view;$i++) { - $master_seq_view[$i]=~/___\d+___(.+)$/; - $master_seq_view[$i]='/'.$1; - } - } else { - for (my $i=0;$i<=$#master_seq_view;$i++) { - $master_seq_view[$i]=' '; - } - } - $r->print(< - - - - - -

Mark item(s) which you want to print

- - -  -  - -

-ENDMENUOUT1 - my $inc=0; - for (my $i=0;$i<=$#master_seq_view;$i++) { - if ($key_to==1 && $master_seq[$i]=~/\.(problem|exam|quiz|assess|survey|form|library)$/) { - $r->print('
'."\n".''. - $titles_master_seq[$i].'   '.$master_seq_view[$i].''); - $inc++; - } elsif ($key_to==0 && $master_seq[$i]=~/\.(problem|exam|quiz|assess|survey|form|library|xml|htm|html|page)$/) { - $r->print('
'."\n".''. - $titles_master_seq[$i].'   '.$master_seq_view[$i].''); - $inc++; - } - } - $r->print(<
- - -  -  - -ENDMENUOUT2 + return $contents; + } +# Fetch the annotations associated with a URL and +# put a centered 'annotations:' title. +# This is all suppressed if the annotations are empty. +# +sub annotate { + my ($symb) = @_; -sub problem_choice_menu { - my $r = shift; - my $subdirtoprint = &Apache::lonnet::filelocation("",$ENV{'form.url'}); - $subdirtoprint =~ s/\/[^\/]+$//; - my @list_of_files = (); - my @content_directory = (); - $r->print("Subdir: " . $subdirtoprint . "
"); - if ($subdirtoprint =~ m|/home/([^/]+)/public_html|) { - #localmachine CSTR space - my $user=$1; - my $domain=$Apache::lonnet::perlvar{'lonDefDomain'}; - @content_directory = &Apache::lonnet::dirlist($subdirtoprint, - $domain, $user,''); - } else { - #local library server res space (allows to print only from the own library server) - @content_directory = &Apache::lonnet::dirlist($subdirtoprint,$ENV{'user.domain'}, $ENV{'user.name'},''); - } - for (my $iy=0;$iy<=$#content_directory;$iy++) { - my @tempo_array = split(/&/,$content_directory[$iy]); - if ($tempo_array[0] =~ m/^[^\.]+\.(problem|exam|quiz|assess|survey|form|library)$/) { - push(@list_of_files,$tempo_array[0]); - } - } - $subdirtoprint =~ s/\/$//; - for (my $i=0;$i<=$#list_of_files;$i++) { - $list_of_files[$i] = $subdirtoprint.'/'.$list_of_files[$i]; - } - $r->print(< - - - -

Mark problems which you want to print

- -  -  - -

-ENDMENUOUT1 - my $i=0; - foreach my $file (sort @list_of_files) { - $r->print('
'. - $file); - $i++; + my $result = ""; + + if (length($annotation_text) > 0) { + $result .= '\\hspace*{\\fill} \\\\[\\baselineskip] \textbf{Annotations:} \\\\ '; + $result .= "\n"; + $result .= &Apache::lonxml::latex_special_symbols($annotation_text,""); # Escape latex. + $result .= "\n\n"; } - $r->print(<
- - - -  -  - -ENDMENUOUT2 + return $result; } -sub additional_class_menu { - my $r = shift; - $r->print(< - - - - -

Select student(s) whose assignment you want to print

-ENDMENUOUT1 - my %courselist=&Apache::lonnet::dump( - 'classlist', - $ENV{'course.'.$ENV{'request.course.id'}.'.domain'}, - $ENV{'course.'.$ENV{'request.course.id'}.'.num'}); - my $now=time; - $r->print(< - function checkall() { - for (i=0; i -  - -  - -

-ENDDISHEADER - my $i = 0; - foreach (sort keys %courselist) { - my ($end,$start)=split(/\:/,$courselist{$_}); - my $active=1; - if (($end) && ($now>$end)) { $active=0; } - if ($active) { - my ($sname,$sdom)=split(/\:/,$_); - my %reply=&Apache::lonnet::get('environment', - ['firstname','middlename','lastname','generation'], - $sdom,$sname); - my $section=&Apache::lonnet::usection - ($sdom,$sname,$ENV{'request.course.id'}); - if ($section == -1) { $section = ''; } - $r->print( - '
'. - $reply{'firstname'}.' '. - $reply{'middlename'}.' '. - $reply{'lastname'}.' '. - $reply{'generation'}. - ' ('.$_.') '.$section); - $i++; - } + my $ok = 0; # True if we got a good response. + my $content; + my $response; + + # Try to get the ssi done. within the retries count: + + do { + ($content, $response) = &Apache::lonnet::ssi($resource, %form); + $ok = $response->is_success; + $retries--; + } while (!$ok && ($retries > 0)); + + # Two cases: ok is true we have valid data, if not, retries have been exhausted + # if ok is true, $response->content is what we want to return.. otherwise + # set the error information: + + if ($ok) { + return $content; + } else { + $ssi_error = 1; + $ssi_last_error_resource = $resource; + $ssi_last_error = $response->code." ". $response->message; + return ''; # Nothing we can add to the printout that makes sense. } - $r->print(<

-
Number of blank pages added to each student assignments to print these assignments on physically different sheets (requires manual addjustment):
-
- - - - -ENDMENUOUT2 } +# +# printf_style_subst item format_string repl +# +# Does printf style substitution for a format string that +# can have %[n]item in it.. wherever, %[n]item occurs, +# rep is substituted in format_string. Note that +# [n] is an optional integer length. If provided, +# repl is truncated to at most [n] characters prior to +# substitution. +# +sub printf_style_subst { + my ($item, $format_string, $repl) = @_; + my $result = ""; + while ($format_string =~ /(%)(\d*)\Q$item\E/g ) { + my $fmt = $1; + my $size = $2; + my $subst = $repl; + if ($size ne "") { + $subst = substr($subst, 0, $size); + + # Here's a nice edge case.. supose the end of the + # substring is a \. In that case may have just + # chopped off a TeX escape... in that case, we append + # " " for the trailing character, and let the field + # spill over a bit (sigh). + # We don't just chop off the last character in order to deal + # with one last pathology, and that would be if substr had + # trimmed us to e.g. \\\ + + + if ($subst =~ /\\$/) { + $subst .= " "; + } + } + my $item_pos = pos($format_string); + $result .= substr($format_string, 0, $item_pos - length($size) -2) . $subst; + $format_string = substr($format_string, pos($format_string)); + } -sub additional_print_menu { - my $r = shift; - my $what_to_print = ''; - for (my $i=0; $i<$ENV{'form.numberofstudents'};$i++) { - $what_to_print .= ''; - } - for (my $i=0; $i<$ENV{'form.numberofproblems'};$i++) { - $what_to_print .= ''; - } - for (my $i=0; $i<$ENV{'form.numberoffiles'};$i++) { - $what_to_print .= ''; - } - $r->print(< - - - - - - - - - -Define one column layout parameters:
-Width:
-Height:
-Left margin:
- - - - - -ENDMENUOUT + # Put the residual format string into the result: + + $result .= $format_string; + + return $result; } -sub output_data { - my $r = shift; - $r->print(< - -LON-CAPA output for printing - - -


-ENDPART +# Format a header according to a format. +# - my $choice = $ENV{'form.choice'}; - my $layout = $ENV{'form.layout'}; - my $numberofcolumns = $ENV{'form.numberofcolumns'}; - my $papersize = $ENV{'form.papersize'}; - my $laystyle = 'book'; - my $assignment = $ENV{'form.assignment'}; - if ($choice eq 'Subdirectory print') { - if ($ENV{'form.layout'} eq '') {$layout = 'CAPA';} - if ($ENV{'form.papersize'} eq '') {$papersize = 'Letter [8 1/2x11 in]';} - if ($ENV{'form.numberofcolumns'} eq '') {$numberofcolumns = 2;} - } - if (($choice eq 'Standard LaTeX output for current document') && - ($ENV{'form.url'}=~m|^/~|)) { - if ($ENV{'form.layout'} eq '') {$layout = 'CAPA';} - if ($ENV{'form.papersize'} eq '') {$papersize = 'Letter [8 1/2x11 in]';} - if ($ENV{'form.numberofcolumns'} eq '') {$numberofcolumns = 2;} - } - my $result = ''; - my $number_of_columns = 1; #used only for pages to determine the width of the cell - my $selectionmade = ''; - my ($textwidth,$textheight,$oddoffset,$evenoffset) = &page_format($papersize,$layout,$numberofcolumns); - if ($numberofcolumns == 1) { - $textwidth=$ENV{'form.width'}; - $textheight=$ENV{'form.height'}; - } - my $LaTeXwidth; - if ($textwidth=~/(\d+\s*cm)/) { - $LaTeXwidth = $1*10; - } elsif ($textwidth=~/(\d+\s*mm)/) { - $LaTeXwidth = $1; - } - if ($choice eq 'Standard LaTeX output for current document') { - #-- single document - problem, page, html, xml, ... - $selectionmade = 1; - if ($ENV{'form.url'}=~/\.(problem|exam|quiz|assess|survey|form|library|page|xml|html|htm|xhtml|xhtm)$/) { - my %moreenv; - if (&Apache::lonnet::allowed('bre',$ENV{'form.url'})) { - $ENV{'form.url'}=~s/http:\/\/[^\/]+//; - } - $moreenv{'request.filename'}=$ENV{'form.url'}; - my %form; - $from{'textwidth'}=$LaTeXwidth; - $form{'grade_target'}='tex'; - &Apache::lonnet::appenv(%moreenv); - my $texversion=&Apache::lonnet::ssi($ENV{'form.url'},%form); - &Apache::lonnet::delenv('form.counter'); - $result .= $texversion; - if ($ENV{'form.url'}=~m/\.page\s*$/) { - ($result,$number_of_columns) = &page_cleanup($result); - } - } else { - $result='\documentclass[letterpaper]{article}\usepackage{calc}\begin{document}Printout of this type of document is currently not supported: '; - if ($ENV{'form.url'}=~/\/(aboutme|syllabus|bulletinboard|smppg)$/) { - $result.=$1; - } else { - $result.=$ENV{'form.url'}; - } - $result.=' \end{document}' - } - } elsif ($choice eq 'Standard LaTeX output for the primary sequence' or - $choice eq 'Standard LaTeX output for whole primary sequence') { - #-- minimal sequence to which the current document belongs - #-- where is the primary sequence containing file? - my @master_seq = (); - for (my $i=0; $i<$ENV{'form.numberoffiles'};$i++) { - if ($ENV{'form.whatfile'.$i}=~/\S/) { - push @master_seq,$ENV{'form.whatfile'.$i}; - } - } - #-- produce an output string - my $flag_latex_header_remove = 'NO'; - my $flag_page_in_sequence = 'NO'; - for (my $i=0;$i<=$#master_seq;$i++) { - my ($urlp,$symb) = split /&&/, $master_seq[$i]; - if ($choice eq 'Standard LaTeX output for the primary sequence') { - $selectionmade = 2; - } elsif ($choice eq 'Standard LaTeX output for whole primary sequence') { - $selectionmade = 3; - } - my %form; - $form{'textwidth'}=$LaTeXwidth; - $form{'grade_target'}='tex'; - $form{'symb'}=$symb; - #&Apache::lonnet::logthis("Trying to get $urlp with symb $symb"); - my $texversion=&Apache::lonnet::ssi($urlp,%form); - if ($urlp =~ m/\.page/) { - ($texversion,my $number_of_columns_page) = &page_cleanup($texversion); - if ($number_of_columns_page > $number_of_columns) {$number_of_columns=$number_of_columns_page;} - $texversion =~ s/\\end{document}\d*/\\end{document}/; - $flag_page_in_sequence = 'YES'; - } - if ($flag_latex_header_remove ne 'NO') { - $texversion = &latex_header_footer_remove($texversion); - } else { - $texversion =~ s/\\end{document}//; - } - $result .= $texversion; - $flag_latex_header_remove = 'YES'; - } - &Apache::lonnet::delenv('form.counter'); - if ($flag_page_in_sequence eq 'YES') {$result =~ s/\\usepackage{calc}/\\usepackage{calc}\\usepackage{longtable}/;} - $result .= '\end{document}'; - } elsif ($choice eq 'Standard LaTeX output for the top level sequence') { - # where is the main sequence of the course? - $selectionmade = 4; - my $main_seq=&Apache::lonnet::clutter($ENV{'request.course.uri'}); - my @file_seq = &coming_from_hash($main_seq); - for (my $i=0;$i<=$#file_seq;$i++) { - my ($path,$title,$symb) = split /&&/,$file_seq[$i]; - $file_seq[$i] = $path.'&&'.$symb; - } - my $flag_latex_header_remove = 'NO'; - #-- produce an output string - for (my $i=0;$i<=$#file_seq;$i++) { - if (not $file_seq[$i]=~/^&&/) { - my ($urlp,$symb) = split /&&/, $file_seq[$i]; - $urlp=~s/\/home\/httpd\/html//; - if ($urlp=~m/\.(problem|exam|quiz|assess|survey|form|library)/) { - my %form; - $form{'grade_target'}='tex'; - $form{'textwidth'}=$LaTeXwidth; - $form{'symb'}=$symb; - my $texversion=&Apache::lonnet::ssi($urlp,%form); - if ($flag_latex_header_remove ne 'NO') { - $texversion = &latex_header_footer_remove($texversion); - } else { - $texversion =~ s/\\end{document}//; - } - $result .= $texversion; - $flag_latex_header_remove = 'YES'; - } - } - } - $result .= '\end{document}'; - } elsif ($choice eq 'All class print') { - #-- prints assignments for whole class or for selected students - $selectionmade = 5; - my @students = (); - for (my $i=0; $i<$ENV{'form.numberofstudents'};$i++) { - if ($ENV{'form.whomtoprint'.$i}=~/:/) { - push @students,$ENV{'form.whomtoprint'.$i}; - } - } - #where is the primary sequence containing current resource (the same for all students)? - my $symbolic = &Apache::lonnet::symbread($ENV{'form.url'}); - my @sequence = split('___',$symbolic); - my $primary_sequence; +# Substitutions: +# %a - Assignment name. +# %c - Course name. +# %n - Student name. +# +sub format_page_header { + my ($width, $format, $assignment, $course, $student) = @_; + + $width = &recalcto_mm($width); # Get width in mm. + # Default format? - $primary_sequence=&Apache::lonnet::clutter($sequence[0]); - my @master_seq = &coming_from_hash($primary_sequence); - for (my $i=0;$i<=$#master_seq;$i++) { - my ($path,$title,$symb) = split /&&/,$master_seq[$i]; - $master_seq[$i] = $path.'&&'.$symb; - } - #loop over students - my $flag_latex_header_remove = 'NO'; - my %moreenv; - $moreenv{'form.textwidth'}=$LaTeXwidth; - &Apache::lonnet::appenv(%moreenv); - my %prog_state=&Apache::lonhtmlcommon::Create_PrgWin($r,'Print Status','Class Print Status',$#students+1); - foreach my $person (@students) { - my $current_output = ''; - my ($usersection,$username,$userdomain) = split /:/,$person; - my $fullname = &get_name($username,$userdomain); - #goes through all resources, checks if they are available for current student, and produces output - foreach my $curresline (@master_seq) { - my ($curres,$symb) = split /&&/, $curresline; - if ($curres=~ m/\.(problem|exam|quiz|assess|survey|form|library)/) { - my ($map,$id,$res_url) = split(/___/,$symb); - if (&Apache::lonnet::allowed('bre',$res_url)) { - my $rendered = &Apache::loncommon::get_student_view($symb,$username,$userdomain, - $ENV{'request.course.id'},'tex'); - if ($flag_latex_header_remove eq 'YES') { - $rendered = &latex_header_footer_remove($rendered); - } else { - $rendered =~ s/\\end{document}//; - } - $current_output .= $rendered; - } - $flag_latex_header_remove = 'YES'; - } + if ($format eq '') { + # For the default format, we may need to truncate + # elements.. To do this we need to get the page width. + # we assume that each character is about 2mm in width. + # (correct for the header text size??). We ignore + # any formatting (e.g. boldfacing in this). + # + # - Allow the student/course to be one line. + # but only truncate the course. + # - Allow the assignment to be 2 lines (wrapped). + # + my $chars_per_line = $width/2; # Character/textline. + + + my $firstline = "$student $course"; + if (length($firstline) > $chars_per_line) { + my $lastchar = $chars_per_line - length($student) - 1; + if ($lastchar > 0) { + $course = substr($course, 0, $lastchar); + } else { # Nothing left of course: + $course = ''; } - my $courseidinfo = $ENV{'course.'.$ENV{'request.course.id'}.'.description'}; - if ($current_output=~/\\documentclass/) { - $current_output =~ s/\\begin{document}/\\setlength{\\topmargin}{1cm}\\usepackage{fancyhdr}\\pagestyle{fancy}\\rhead{}\\chead{} \\begin{document}\\noindent\\lhead{\\textit{\\textbf{$fullname}} - $courseidinfo \\hfill \\thepage \\\\ \\textit{$assignment}}\\vskip 3 mm /; - } else { - my $blanspages = ''; - for (my $j=0;$j<$ENV{'form.addedpages'};$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 \\vskip 3mm'.$blanspages.'\setcounter{page}{1}\noindent\parbox{\minipagewidth}{\noindent\\lhead{\\textit{\\textbf{'.$fullname.'}} - '.$courseidinfo.' \\hfill \\thepage \\\\ \\textit{'.$assignment.'}}\hskip 1.4in } \vskip 5 mm '.$current_output; - } - $result .= $current_output; - &Apache::lonnet::delenv('form.counter'); - &Apache::lonxml::init_counter(); - &Apache::lonhtmlcommon::Increment_PrgWin($r,\%prog_state, - 'last student '.$fullname); } - &Apache::lonhtmlcommon::Close_PrgWin($r,\%prog_state); - $result .= '\end{document}'; - &Apache::lonnet::delenv('form.textwidth'); - } elsif ($choice eq 'Subdirectory print') { - #prints selected problems from the subdirectory - $selectionmade = 6; - my @list_of_files = (); - for (my $i=0; $i<$ENV{'form.numberofproblems'};$i++) { - if ($ENV{'form.whattoprint'.$i}=~/^\//) { - push @list_of_files,$ENV{'form.whattoprint'.$i}; - } - } - my $flag_latex_header_remove = 'NO'; - for (my $i=0;$i<=$#list_of_files;$i++) { - my $urlp = $list_of_files[$i]; - if ($urlp=~/\//) { - my %form; - $form{'grade_target'}='tex'; - $form{'textwidth'}=$LaTeXwidth; - if ($urlp =~ m|/home/([^/]+)/public_html|) { - $urlp =~ s|/home/([^/]*)/public_html|/~$1|; - } else { - $urlp =~ s|^/home/httpd/html||; - } - my $texversion=&Apache::lonnet::ssi($urlp,%form); - #this chunck is responsible for printing the path to problem - my $newurlp = ''; - my $HowMany = length($urlp)*2; - if ($HowMany > $LaTeXwidth) { - my @temporrary = split '/',$urlp; - my $HowManyNew = 0; - for (my $ii=0;$ii<=$#temporrary;$ii++) { - if ($temporrary[$ii] ne '') { - $HowManyNew += length($temporrary[$ii])*2; - if ($HowManyNew < $LaTeXwidth ) { - $newurlp .= '/'.$temporrary[$ii]; - } else { - $HowManyNew = 0; - $newurlp .= '|\vskip -1 mm \noindent \verb|'; - $ii--; - } - } - } - } - $texversion =~ s/(\\begin{minipage}{\\textwidth})/$1 {\\small\\noindent\\verb|$newurlp\|\\vskip 0 mm}/; - if ($flag_latex_header_remove ne 'NO') { - $texversion = &latex_header_footer_remove($texversion); - } else { - $texversion =~ s/\\end{document}//; - } - $result .= $texversion; - } - $flag_latex_header_remove = 'YES'; + if (length($assignment) > $chars_per_line) { + $assignment = substr($assignment, 0, $chars_per_line); } - $result .= '\end{document}'; + + $format = "\\textbf{$student} $course \\hfill \\thepage \\\\ \\textit{$assignment}"; + + } else { + # An open question is how to handle long user formatted page headers... + # A possible future is to support e.g. %na so that the user can control + # the truncation of the elements that can appear in the header. + # + $format = &printf_style_subst("a", $format, $assignment); + $format = &printf_style_subst("c", $format, $course); + $format = &printf_style_subst("n", $format, $student); + + # If the user put %'s in the format string, they must be escaped + # to \% else LaTeX will think they are comments and terminate + # the line.. which is bad!!! + + } -#-------------------------------------------------------- corrections for the different page formats - $result = &page_format_transformation($papersize,$layout,$numberofcolumns,$choice,$result,$assignment); - if ($layout eq 'CBI') { - $laystyle = 'album'; - } - $result = &latex_corrections($number_of_columns,$result); - #changes page's parameters for the one column output - if ($ENV{'form.numberofcolumns'} == 1) { - $result =~ s/\\textwidth= 9cm/\\textwidth= $ENV{'form.width'}/; - $result =~ s/\\textheight 25\.9cm/\\textheight $ENV{'form.height'}/; - $result =~ s/\\evensidemargin = -0\.57in/\\evensidemargin= $ENV{'form.leftmargin'}/; - $result =~ s/\\oddsidemargin = -0\.57in/\\oddsidemargin= $ENV{'form.leftmargin'}/; + + + return $format; + +} + +# +# Convert a numeric code to letters +# +sub num_to_letters { + my ($num) = @_; + my @nums= split('',$num); + my @num_to_let=('A'..'Z'); + my $word; + foreach my $digit (@nums) { $word.=$num_to_let[$digit]; } + return $word; +} +# Convert a letter code to numeric. +# +sub letters_to_num { + my ($letters) = @_; + my @letters = split('', uc($letters)); + my %substitution; + my $digit = 0; + foreach my $letter ('A'..'J') { + $substitution{$letter} = $digit; + $digit++; + } + # The substitution is done as below to preserve leading + # zeroes which are needed to keep the code size exact + # + my $result =""; + foreach my $letter (@letters) { + $result.=$substitution{$letter}; } -#-- 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; -$r->print(< - - -FINALEND + return $result; } +# Determine if a code is a valid numeric code. Valid +# numeric codes must be comprised entirely of digits and +# have a correct number of digits. +# +# Parameters: +# value - proposed code value. +# num_digits - Number of digits required. +# +sub is_valid_numeric_code { + my ($value, $num_digits) = @_; + # Remove leading/trailing whitespace; + $value =~ s/^\s*//g; + $value =~ s/\s*$//g; + + # All digits? + if ($value !~ /^[0-9]+$/) { + return "Numeric code $value has invalid characters - must only be digits"; + } + if (length($value) != $num_digits) { + return "Numeric code $value incorrect number of digits (correct = $num_digits)"; + } + return undef; +} +# Determines if a code is a valid alhpa code. Alpha codes +# are ciphers that map [A-J,a-j] -> 0..9 0..9. +# They also have a correct digit count. +# Parameters: +# value - Proposed code value. +# num_letters - correct number of letters. +# Note: +# leading and trailing whitespace are ignored. +# +sub is_valid_alpha_code { + my ($value, $num_letters) = @_; + + # strip leading and trailing spaces. -sub coming_from_hash { + $value =~ s/^\s*//g; + $value =~ s/\s*$//g; - my $mainsequence = shift; - my @resourcelist = (); - my $mapid = $hash{'map_pc_'.$mainsequence}; - my $mapstart = $hash{'map_start_'.$mainsequence}; - my $mapfinish = $hash{'map_finish_'.$mainsequence}; - my $current_resource = $mapstart; - while ($current_resource ne $mapfinish) { - if ($hash{'src_'.$current_resource}=~/\.sequence$/) { - push @resourcelist,&coming_from_hash($hash{'src_'.$current_resource}); - } else { - my $presymb=&Apache::lonnet::declutter($mainsequence); - my $rid = $current_resource; - if ($rid=~/,/) { - my @rid = split /,/, $rid; - foreach my $rid_element (@rid) { - if ($rid_element =~ m/^$mapid\.(\d*)/) { - $rid = $1; - last; - } - } - } else { - $rid =~ m/^$mapid\.(\d*)/; - $rid = $1; - } - my $symb = $presymb.'___'.$rid.'___'. - &Apache::lonnet::declutter($hash{'src_'.$current_resource}); - push @resourcelist,$hash{'src_'.$current_resource}.'&&'.$hash{'title_'.$current_resource}.'&&'.$symb; - } - $current_resource = $hash{'goesto_'.$hash{'to_'.$current_resource}}; - } - #needs if final resource in the map (type="finish") contains something - if ($hash{'src_'.$current_resource}=~/\.sequence$/) { - push @resourcelist,&coming_from_hash($hash{'src_'.$current_resource}); - } else { - my $presymb=&Apache::lonnet::declutter($mainsequence); - my $rid = $current_resource; - if ($rid=~/,/) { - my @rid = split /,/, $rid; - foreach my $rid_element (@rid) { - if ($rid_element =~ m/^$mapid\.(\d*)/) { - $rid = $1; - last; - } - } - } else { - $rid =~ m/^$mapid\.(\d*)/; - $rid = $1; + # All alphas in the right range? + if ($value !~ /^[A-J,a-j]+$/) { + return "Invalid letter code $value must only contain A-J"; + } + if (length($value) != $num_letters) { + return "Letter code $value has incorrect number of letters (correct = $num_letters)"; + } + return undef; +} + +# Determine if a code entered by the user in a helper is valid. +# valid depends on the code type and the type of code selected. +# The type of code selected can either be numeric or +# Alphabetic. If alphabetic, the code, in fact is a simple +# substitution cipher for the actual numeric code: 0->A, 1->B ... +# We'll be nice and be case insensitive for alpha codes. +# Parameters: +# code_value - the value of the code the user typed in. +# code_option - The code type selected from the set in the scantron format +# table. +# Returns: +# undef - The code is valid. +# other - An error message indicating what's wrong. +# +sub is_code_valid { + my ($code_value, $code_option) = @_; + my ($code_type, $code_length) = ('letter', 6); # defaults. + open(FG, $Apache::lonnet::perlvar{'lonTabDir'}.'/scantronformat.tab'); + foreach my $line () { + my ($name, $type, $length) = (split(/:/, $line))[0,2,4]; + if($name eq $code_option) { + $code_length = $length; + if($type eq 'number') { + $code_type = 'number'; } - my $symb = $presymb.'___'.$rid.'___'. - &Apache::lonnet::declutter($hash{'src_'.$current_resource}); - push @resourcelist,$hash{'src_'.$current_resource}.'&&'.$hash{'title_'.$current_resource}.'&&'.$symb; } - $current_resource = $hash{'goesto_'.$hash{'to_'.$current_resource}}; - return @resourcelist; + } + my $valid; + if ($code_type eq 'number') { + return &is_valid_numeric_code($code_value, $code_length); + } else { + return &is_valid_alpha_code($code_value, $code_length); + } + } +# Compare two students by name. The students are in the form +# returned by the helper: +# user:domain:section:last, first:status +# This is a helper function for the perl sort built-in therefore: +# Implicit Inputs: +# $a - The first element to compare (global) +# $b - The second element to compare (global) +# Returns: +# -1 - $a < $b +# 0 - $a == $b +# +1 - $a > $b +# Note that the initial comparison is done on the last names with the +# first names only used to break the tie. +# +# +sub compare_names { + # First split the names up into the primary fields. + + my ($u1, $d1, $s1, $n1, $stat1) = split(/:/, $a); + my ($u2, $d2, $s2, $n2, $stat2) = split(/:/, $b); + + # Now split the last name and first name of each n: + # + + my ($l1,$f1) = split(/,/, $n1); + my ($l2,$f2) = split(/,/, $n2); + + # We don't bother to remove the leading/trailing whitespace from the + # firstname, unless the last names compare identical. + + if($l1 lt $l2) { + return -1; + } + if($l1 gt $l2) { + return 1; + } + + # Break the tie on the first name, but there are leading (possibly trailing + # whitespaces to get rid of first + # + $f1 =~ s/^\s+//; # Remove leading... + $f1 =~ s/\s+$//; # Trailing spaces from first 1... + + $f2 =~ s/^\s+//; + $f2 =~ s/\s+$//; # And the same for first 2... + + if($f1 lt $f2) { + return -1; + } + if($f1 gt $f2) { + return 1; + } + + # Must be the same name. + + return 0; +} sub latex_header_footer_remove { my $text = shift; @@ -791,7 +463,46 @@ sub latex_header_footer_remove { $text =~ s/\\documentclass([^&]*)\\begin{document}//; return $text; } +# +# If necessary, encapsulate text inside +# a minipage env. +# necessity is determined by the problem_split param. +# +sub encapsulate_minipage { + my ($text) = @_; + if (!($env{'form.problem.split'} =~ /yes/i)) { + $text = '\begin{minipage}{\textwidth}'.$text.'\end{minipage}'; + } + return $text; +} +# +# The NUMBER_TO_PRINT and SPLIT_PDFS +# variables interact, this sub looks at these two parameters +# and comes up with a final value for NUMBER_TO_PRINT which can be: +# all - if SPLIT_PDFS eq 'all'. +# 1 - if SPLIT_PDFS eq 'oneper' +# section - if SPLIT_PDFS eq 'sections' +# - if SPLIT_PDFS eq 'usenumber' +# +sub adjust_number_to_print { + my $helper = shift; + + my $split_pdf = $helper->{'VARS'}->{'SPLIT_PDFS'}; + + if ($split_pdf eq 'all') { + $helper->{'VARS'}->{'NUMBER_TO_PRINT'} = 'all'; + } elsif ($split_pdf eq 'oneper') { + $helper->{'VARS'}->{'NUMBER_TO_PRINT'} = 1; + } elsif ($split_pdf eq 'sections') { + $helper->{'VARS'}->{'NUMBER_TO_PRINT'} = 'section'; + } elsif ($split_pdf eq 'usenumber') { + # Unmodified. + } else { + # Error!!!! + croak "bad SPLIT_PDFS: $split_pdf in lonprintout::adjust_number_to_print"; + } +} sub character_chart { my $result = shift; @@ -826,8 +537,8 @@ sub character_chart { $result =~ s/&\#0?58;/:/g; $result =~ s/&\#0?59;/;/g; $result =~ s/&(\#0?60|lt|\#139);/\$<\$/g; - $result =~ s/&\#0?61;/\$=\$/g; - $result =~ s/&(\#0?62|gt|\#155);/\$>\$/g; + $result =~ s/&\#0?61;/\\ensuremath\{=\}/g; + $result =~ s/&(\#0?62|gt|\#155);/\\ensuremath\{>\}/g; $result =~ s/&\#0?63;/\?/g; $result =~ s/&\#0?65;/A/g; $result =~ s/&\#0?66;/B/g; @@ -856,9 +567,9 @@ sub character_chart { $result =~ s/&\#0?89;/Y/g; $result =~ s/&\#0?90;/Z/g; $result =~ s/&\#0?91;/[/g; - $result =~ s/&\#0?92;/\$\\setminus\$/g; + $result =~ s/&\#0?92;/\\ensuremath\{\\setminus\}/g; $result =~ s/&\#0?93;/]/g; - $result =~ s/&\#(0?94|136);/\$\\wedge\$/g; + $result =~ s/&\#(0?94|136);/\\ensuremath\{\\wedge\}/g; $result =~ s/&\#(0?95|138|154);/\\underline{\\makebox[2mm]{\\strut}}/g; $result =~ s/&\#(0?96|145);/\`/g; $result =~ s/&\#0?97;/a/g; @@ -893,21 +604,21 @@ sub character_chart { $result =~ s/&\#126;/\~/g; $result =~ s/&\#131;/\\textflorin /g; $result =~ s/&\#132;/\"/g; - $result =~ s/&\#133;/\$\\ldots\$/g; - $result =~ s/&\#134;/\$\\dagger\$/g; - $result =~ s/&\#135;/\$\\ddagger\$/g; + $result =~ s/&\#133;/\\ensuremath\{\\ldots\}/g; + $result =~ s/&\#134;/\\ensuremath\{\\dagger\}/g; + $result =~ s/&\#135;/\\ensuremath\{\\ddagger\}/g; $result =~ s/&\#137;/\\textperthousand /g; $result =~ s/&\#140;/{\\OE}/g; $result =~ s/&\#147;/\`\`/g; $result =~ s/&\#148;/\'\'/g; - $result =~ s/&\#149;/\$\\bullet\$/g; - $result =~ s/&\#150;/--/g; + $result =~ s/&\#149;/\\ensuremath\{\\bullet\}/g; + $result =~ s/&(\#150|\#8211);/--/g; $result =~ s/&\#151;/---/g; - $result =~ s/&\#152;/\$\\sim\$/g; + $result =~ s/&\#152;/\\ensuremath\{\\sim\}/g; $result =~ s/&\#153;/\\texttrademark /g; $result =~ s/&\#156;/\\oe/g; $result =~ s/&\#159;/\\\"Y/g; - $result =~ s/&(\#160|nbsp);//g; + $result =~ s/&(\#160|nbsp);/~/g; $result =~ s/&(\#161|iexcl);/!\`/g; $result =~ s/&(\#162|cent);/\\textcent /g; $result =~ s/&(\#163|pound);/\\pounds /g; @@ -918,20 +629,20 @@ sub character_chart { $result =~ s/&(\#168|uml);/\\texthighdieresis /g; $result =~ s/&(\#169|copy);/\\copyright /g; $result =~ s/&(\#170|ordf);/\\textordfeminine /g; - $result =~ s/&(\#172|not);/\$\\neg\$/g; + $result =~ s/&(\#172|not);/\\ensuremath\{\\neg\}/g; $result =~ s/&(\#173|shy);/ - /g; $result =~ s/&(\#174|reg);/\\textregistered /g; - $result =~ s/&(\#175|macr);/\$^{-}\$/g; - $result =~ s/&(\#176|deg);/\$^{\\circ}\$/g; - $result =~ s/&(\#177|plusmn);/\$\\pm\$/g; - $result =~ s/&(\#178|sup2);/\$^2\$/g; - $result =~ s/&(\#179|sup3);/\$^3\$/g; + $result =~ s/&(\#175|macr);/\\ensuremath\{^{-}\}/g; + $result =~ s/&(\#176|deg);/\\ensuremath\{^{\\circ}\}/g; + $result =~ s/&(\#177|plusmn);/\\ensuremath\{\\pm\}/g; + $result =~ s/&(\#178|sup2);/\\ensuremath\{^2\}/g; + $result =~ s/&(\#179|sup3);/\\ensuremath\{^3\}/g; $result =~ s/&(\#180|acute);/\\textacute /g; - $result =~ s/&(\#181|micro);/\$\\mu\$/g; + $result =~ s/&(\#181|micro);/\\ensuremath\{\\mu\}/g; $result =~ s/&(\#182|para);/\\P/g; - $result =~ s/&(\#183|middot);/\$\\cdot\$/g; + $result =~ s/&(\#183|middot);/\\ensuremath\{\\cdot\}/g; $result =~ s/&(\#184|cedil);/\\c{\\strut}/g; - $result =~ s/&(\#185|sup1);/\$^1\$/g; + $result =~ s/&(\#185|sup1);/\\ensuremath\{^1\}/g; $result =~ s/&(\#186|ordm);/\\textordmasculine /g; $result =~ s/&(\#188|frac14);/\\textonequarter /g; $result =~ s/&(\#189|frac12);/\\textonehalf /g; @@ -959,14 +670,14 @@ sub character_chart { $result =~ s/&(\#212|Ocirc);/\\^{O}/g; $result =~ s/&(\#213|Otilde);/\\~{O}/g; $result =~ s/&(\#214|Ouml);/\\\"{O}/g; - $result =~ s/&(\#215|times);/\$\\times\$/g; + $result =~ s/&(\#215|times);/\\ensuremath\{\\times\}/g; $result =~ s/&(\#216|Oslash);/{\\O}/g; $result =~ s/&(\#217|Ugrave);/\\\`{U}/g; $result =~ s/&(\#218|Uacute);/\\\'{U}/g; $result =~ s/&(\#219|Ucirc);/\\^{U}/g; $result =~ s/&(\#220|Uuml);/\\\"{U}/g; $result =~ s/&(\#221|Yacute);/\\\'{Y}/g; - $result =~ s/&(\#223|szlig);/\\ss/g; + $result =~ s/&(\#223|szlig);/{\\ss}/g; $result =~ s/&(\#224|agrave);/\\\`{a}/g; $result =~ s/&(\#225|aacute);/\\\'{a}/g; $result =~ s/&(\#226|acirc);/\\^{a}/g; @@ -983,14 +694,14 @@ sub character_chart { $result =~ s/&(\#237|iacute);/\\\'{i}/g; $result =~ s/&(\#238|icirc);/\\^{i}/g; $result =~ s/&(\#239|iuml);/\\\"{i}/g; - $result =~ s/&(\#240|eth);/\$\\partial\$/g; + $result =~ s/&(\#240|eth);/\\ensuremath\{\\partial\}/g; $result =~ s/&(\#241|ntilde);/\\~{n}/g; $result =~ s/&(\#242|ograve);/\\\`{o}/g; $result =~ s/&(\#243|oacute);/\\\'{o}/g; $result =~ s/&(\#244|ocirc);/\\^{o}/g; $result =~ s/&(\#245|otilde);/\\~{o}/g; $result =~ s/&(\#246|ouml);/\\\"{o}/g; - $result =~ s/&(\#247|divide);/\$\\div\$/g; + $result =~ s/&(\#247|divide);/\\ensuremath\{\\div\}/g; $result =~ s/&(\#248|oslash);/{\\o}/g; $result =~ s/&(\#249|ugrave);/\\\`{u}/g; $result =~ s/&(\#250|uacute);/\\\'{u}/g; @@ -998,261 +709,318 @@ sub character_chart { $result =~ s/&(\#252|uuml);/\\\"{u}/g; $result =~ s/&(\#253|yacute);/\\\'{y}/g; $result =~ s/&(\#255|yuml);/\\\"{y}/g; - $result =~ s/&\#952;/\$\\theta\$/g; + $result =~ s/&\#295;/\\ensuremath\{\\hbar\}/g; + $result =~ s/&\#952;/\\ensuremath\{\\theta\}/g; #Greek Alphabet - $result =~ s/&(alpha|\#945);/\$\\alpha \$/g; - $result =~ s/&(beta|\#946);/\$\\beta \$/g; - $result =~ s/&(gamma|\#947);/\$\\gamma \$/g; - $result =~ s/&(delta|\#948);/\$\\delta \$/g; - $result =~ s/&(epsilon|\#949);/\$\\epsilon \$/g; - $result =~ s/&(zeta|\#950);/\$\\zeta \$/g; - $result =~ s/&(eta|\#951);/\$\\eta \$/g; - $result =~ s/&(theta|\#952);/\$\\theta \$/g; - $result =~ s/&(iota|\#953);/\$\\iota \$/g; - $result =~ s/&(kappa|\#954);/\$\\kappa \$/g; - $result =~ s/&(lambda|\#955);/\$\\lambda \$/g; - $result =~ s/&(mu|\#956);/\$\\mu \$/g; - $result =~ s/&(nu|\#957);/\$\\nu \$/g; - $result =~ s/&(xi|\#958);/\$\\xi \$/g; - $result =~ s/&(pi|\#960);/\$\\pi \$/g; - $result =~ s/&(rho|\#961);/\$\\rho \$/g; - $result =~ s/&(sigma|\#963);/\$\\sigma \$/g; - $result =~ s/&(tau|\#964);/\$\\tau \$/g; - $result =~ s/&(upsilon|\#965);/\$\\upsilon \$/g; - $result =~ s/&(phi|\#966);/\$\\phi \$/g; - $result =~ s/&(chi|\#967);/\$\\chi \$/g; - $result =~ s/&(psi|\#968);/\$\\psi \$/g; - $result =~ s/&(omega|\#969);/\$\\omega \$/g; - $result =~ s/&(Gamma|\#915);/\$\\Gamma \$/g; - $result =~ s/&(Delta|\#916);/\$\\Delta \$/g; - $result =~ s/&(Theta|\#920);/\$\\Theta \$/g; - $result =~ s/&(Lambda|\#923);/\$\\Lambda \$/g; - $result =~ s/&(Xi|\#926);/\$\\Xi \$/g; - $result =~ s/&(Pi|\#928);/\$\\Pi \$/g; - $result =~ s/&(Sigma|\#931);/\$\\Sigma \$/g; - $result =~ s/&(Upsilon|\#933);/\$\\Upsilon \$/g; - $result =~ s/&(Phi|\#934);/\$\\Phi \$/g; - $result =~ s/&(Psi|\#936);/\$\\Psi \$/g; - $result =~ s/&(Omega|\#937);/\$\\Omega \$/g; + $result =~ s/&(alpha|\#945);/\\ensuremath\{\\alpha\}/g; + $result =~ s/&(beta|\#946);/\\ensuremath\{\\beta\}/g; + $result =~ s/&(gamma|\#947);/\\ensuremath\{\\gamma\}/g; + $result =~ s/&(delta|\#948);/\\ensuremath\{\\delta\}/g; + $result =~ s/&(epsilon|\#949);/\\ensuremath\{\\epsilon\}/g; + $result =~ s/&(zeta|\#950);/\\ensuremath\{\\zeta\}/g; + $result =~ s/&(eta|\#951);/\\ensuremath\{\\eta\}/g; + $result =~ s/&(theta|\#952);/\\ensuremath\{\\theta\}/g; + $result =~ s/&(iota|\#953);/\\ensuremath\{\\iota\}/g; + $result =~ s/&(kappa|\#954);/\\ensuremath\{\\kappa\}/g; + $result =~ s/&(lambda|\#955);/\\ensuremath\{\\lambda\}/g; + $result =~ s/&(mu|\#956);/\\ensuremath\{\\mu\}/g; + $result =~ s/&(nu|\#957);/\\ensuremath\{\\nu\}/g; + $result =~ s/&(xi|\#958);/\\ensuremath\{\\xi\}/g; + $result =~ s/&(omicron|\#959);/o/g; + $result =~ s/&(pi|\#960);/\\ensuremath\{\\pi\}/g; + $result =~ s/&(rho|\#961);/\\ensuremath\{\\rho\}/g; + $result =~ s/&(sigma|\#963);/\\ensuremath\{\\sigma\}/g; + $result =~ s/&(tau|\#964);/\\ensuremath\{\\tau\}/g; + $result =~ s/&(upsilon|\#965);/\\ensuremath\{\\upsilon\}/g; + $result =~ s/&(phi|\#966);/\\ensuremath\{\\phi\}/g; + $result =~ s/&(chi|\#967);/\\ensuremath\{\\chi\}/g; + $result =~ s/&(psi|\#968);/\\ensuremath\{\\psi\}/g; + $result =~ s/&(omega|\#969);/\\ensuremath\{\\omega\}/g; + $result =~ s/&(thetasym|\#977);/\\ensuremath\{\\vartheta\}/g; + $result =~ s/&(piv|\#982);/\\ensuremath\{\\varpi\}/g; + $result =~ s/&(Alpha|\#913);/A/g; + $result =~ s/&(Beta|\#914);/B/g; + $result =~ s/&(Gamma|\#915);/\\ensuremath\{\\Gamma\}/g; + $result =~ s/&(Delta|\#916);/\\ensuremath\{\\Delta\}/g; + $result =~ s/&(Epsilon|\#917);/E/g; + $result =~ s/&(Zeta|\#918);/Z/g; + $result =~ s/&(Eta|\#919);/H/g; + $result =~ s/&(Theta|\#920);/\\ensuremath\{\\Theta\}/g; + $result =~ s/&(Iota|\#921);/I/g; + $result =~ s/&(Kappa|\#922);/K/g; + $result =~ s/&(Lambda|\#923);/\\ensuremath\{\\Lambda\}/g; + $result =~ s/&(Mu|\#924);/M/g; + $result =~ s/&(Nu|\#925);/N/g; + $result =~ s/&(Xi|\#926);/\\ensuremath\{\\Xi\}/g; + $result =~ s/&(Omicron|\#927);/O/g; + $result =~ s/&(Pi|\#928);/\\ensuremath\{\\Pi\}/g; + $result =~ s/&(Rho|\#929);/P/g; + $result =~ s/&(Sigma|\#931);/\\ensuremath\{\\Sigma\}/g; + $result =~ s/&(Tau|\#932);/T/g; + $result =~ s/&(Upsilon|\#933);/\\ensuremath\{\\Upsilon\}/g; + $result =~ s/&(Phi|\#934);/\\ensuremath\{\\Phi\}/g; + $result =~ s/&(Chi|\#935);/X/g; + $result =~ s/&(Psi|\#936);/\\ensuremath\{\\Psi\}/g; + $result =~ s/&(Omega|\#937);/\\ensuremath\{\\Omega\}/g; +#Arrows (extended HTML 4.01) + $result =~ s/&(larr|\#8592);/\\ensuremath\{\\leftarrow\}/g; + $result =~ s/&(uarr|\#8593);/\\ensuremath\{\\uparrow\}/g; + $result =~ s/&(rarr|\#8594);/\\ensuremath\{\\rightarrow\}/g; + $result =~ s/&(darr|\#8595);/\\ensuremath\{\\downarrow\}/g; + $result =~ s/&(harr|\#8596);/\\ensuremath\{\\leftrightarrow\}/g; + $result =~ s/&(lArr|\#8656);/\\ensuremath\{\\Leftarrow\}/g; + $result =~ s/&(uArr|\#8657);/\\ensuremath\{\\Uparrow\}/g; + $result =~ s/&(rArr|\#8658);/\\ensuremath\{\\Rightarrow\}/g; + $result =~ s/&(dArr|\#8659);/\\ensuremath\{\\Downarrow\}/g; + $result =~ s/&(hArr|\#8660);/\\ensuremath\{\\Leftrightarrow\}/g; +#Mathematical Operators (extended HTML 4.01) + $result =~ s/&(forall|\#8704);/\\ensuremath\{\\forall\}/g; + $result =~ s/&(part|\#8706);/\\ensuremath\{\\partial\}/g; + $result =~ s/&(exist|\#8707);/\\ensuremath\{\\exists\}/g; + $result =~ s/&(empty|\#8709);/\\ensuremath\{\\emptyset\}/g; + $result =~ s/&(nabla|\#8711);/\\ensuremath\{\\nabla\}/g; + $result =~ s/&(isin|\#8712);/\\ensuremath\{\\in\}/g; + $result =~ s/&(notin|\#8713);/\\ensuremath\{\\notin\}/g; + $result =~ s/&(ni|\#8715);/\\ensuremath\{\\ni\}/g; + $result =~ s/&(prod|\#8719);/\\ensuremath\{\\prod\}/g; + $result =~ s/&(sum|\#8721);/\\ensuremath\{\\sum\}/g; + $result =~ s/&(minus|\#8722);/\\ensuremath\{-\}/g; + $result =~ s/–/\\ensuremath\{-\}/g; + $result =~ s/&(lowast|\#8727);/\\ensuremath\{*\}/g; + $result =~ s/&(radic|\#8730);/\\ensuremath\{\\surd\}/g; + $result =~ s/&(prop|\#8733);/\\ensuremath\{\\propto\}/g; + $result =~ s/&(infin|\#8734);/\\ensuremath\{\\infty\}/g; + $result =~ s/&(ang|\#8736);/\\ensuremath\{\\angle\}/g; + $result =~ s/&(and|\#8743);/\\ensuremath\{\\wedge\}/g; + $result =~ s/&(or|\#8744);/\\ensuremath\{\\vee\}/g; + $result =~ s/&(cap|\#8745);/\\ensuremath\{\\cap\}/g; + $result =~ s/&(cup|\#8746);/\\ensuremath\{\\cup\}/g; + $result =~ s/&(int|\#8747);/\\ensuremath\{\\int\}/g; + $result =~ s/&(sim|\#8764);/\\ensuremath\{\\sim\}/g; + $result =~ s/&(cong|\#8773);/\\ensuremath\{\\cong\}/g; + $result =~ s/&(asymp|\#8776);/\\ensuremath\{\\approx\}/g; + $result =~ s/&(ne|\#8800);/\\ensuremath\{\\not=\}/g; + $result =~ s/&(equiv|\#8801);/\\ensuremath\{\\equiv\}/g; + $result =~ s/&(le|\#8804);/\\ensuremath\{\\leq\}/g; + $result =~ s/&(ge|\#8805);/\\ensuremath\{\\geq\}/g; + $result =~ s/&(sub|\#8834);/\\ensuremath\{\\subset\}/g; + $result =~ s/&(sup|\#8835);/\\ensuremath\{\\supset\}/g; + $result =~ s/&(nsub|\#8836);/\\ensuremath\{\\not\\subset\}/g; + $result =~ s/&(sube|\#8838);/\\ensuremath\{\\subseteq\}/g; + $result =~ s/&(supe|\#8839);/\\ensuremath\{\\supseteq\}/g; + $result =~ s/&(oplus|\#8853);/\\ensuremath\{\\oplus\}/g; + $result =~ s/&(otimes|\#8855);/\\ensuremath\{\\otimes\}/g; + $result =~ s/&(perp|\#8869);/\\ensuremath\{\\perp\}/g; + $result =~ s/&(sdot|\#8901);/\\ensuremath\{\\cdot\}/g; +#Geometric Shapes (extended HTML 4.01) + $result =~ s/&(loz|\#9674);/\\ensuremath\{\\Diamond\}/g; +#Miscellaneous Symbols (extended HTML 4.01) + $result =~ s/&(spades|\#9824);/\\ensuremath\{\\spadesuit\}/g; + $result =~ s/&(clubs|\#9827);/\\ensuremath\{\\clubsuit\}/g; + $result =~ s/&(hearts|\#9829);/\\ensuremath\{\\heartsuit\}/g; + $result =~ s/&(diams|\#9830);/\\ensuremath\{\\diamondsuit\}/g; +# Chemically useful 'things' contributed by Hon Kie (bug 4652). + + $result =~ s/&\#8636;/\\ensuremath\{\\leftharpoonup\}/g; + $result =~ s/&\#8637;/\\ensuremath\{\\leftharpoondown\}/g; + $result =~ s/&\#8640;/\\ensuremath\{\\rightharpoonup\}/g; + $result =~ s/&\#8641;/\\ensuremath\{\\rightharpoondown\}/g; + $result =~ s/&\#8652;/\\ensuremath\{\\rightleftharpoons\}/g; + $result =~ s/&\#8605;/\\ensuremath\{\\leadsto\}/g; + $result =~ s/&\#8617;/\\ensuremath\{\\hookleftarrow\}/g; + $result =~ s/&\#8618;/\\ensuremath\{\\hookrightarrow\}/g; + $result =~ s/&\#8614;/\\ensuremath\{\\mapsto\}/g; + $result =~ s/&\#8599;/\\ensuremath\{\\nearrow\}/g; + $result =~ s/&\#8600;/\\ensuremath\{\\searrow\}/g; + $result =~ s/&\#8601;/\\ensuremath\{\\swarrow\}/g; + $result =~ s/&\#8598;/\\ensuremath\{\\nwarrow\}/g; + + # Left/right quotations: + + $result =~ s/&(ldquo|#8220);/\`\`/g; + $result =~ s/&(rdquo|#8221);/\'\'/g; + + return $result; } - sub page_format { - my ($papersize,$layout,$numberofcolumns) = @_; - my ($textwidth,$textheight,$oddoffset,$evenoffset) = (0,0,0,0); - if ($papersize=~/Letter/) { - if ($layout eq 'CAPA') { - if ($numberofcolumns == 1) { - $textwidth = '18 cm'; - $textheight = '25.9 cm'; - $oddoffset = '-0.57 in'; - $evenoffset = '-0.57 in'; - } elsif ($numberofcolumns == 2) { - $textwidth = '93 mm'; - $textheight = '25.9 cm'; - $oddoffset = '-0.57 in'; - $evenoffset = '-0.57 in'; - } - } elsif ($layout eq 'CBI') { - if ($numberofcolumns eq '1') { - $textwidth = '8.8 in'; - $textheight = '6.8 in'; - $oddoffset = '-40 pt'; - $evenoffset = '-60 pt'; - } elsif ($numberofcolumns == 2) { - $textwidth = '4.2 in'; - $textheight = '6.8 in'; - $oddoffset = '-40 pt'; - $evenoffset = '-60 pt'; - } - } -# } elsif($papersize=~/Legal/) { -# } elsif($papersize=~/Ledger/) { -# } elsif($papersize=~/Executive/) { - } elsif($papersize=~/A4/) { - if ($layout eq 'CAPA') { - if ($numberofcolumns == 1) { - $textwidth = '18 cm'; - $textheight = '28 cm'; - $oddoffset = '-0.57 in'; - $evenoffset = '-0.57 in'; - } elsif ($numberofcolumns == 2) { - $textwidth = '96 mm'; - $textheight = '2 cm'; - $oddoffset = '-0.57 in'; - $evenoffset = '-0.57 in'; - } - } elsif ($layout eq 'CBI') { - if ($numberofcolumns eq '1') { - $textwidth = '8.5 in'; - $textheight = '7.7 in'; - $oddoffset = '-40 pt'; - $evenoffset = '-60 pt'; - } elsif ($numberofcolumns == 2) { - $textwidth = '3.9 in'; - $textheight = '7.7 in'; - $oddoffset = '-40 pt'; - $evenoffset = '-60 pt'; - } - } -# } elsif($papersize=~/A3/) { -# } elsif($papersize=~/A2/) { -# } elsif($papersize=~/A5/) { -# } elsif($papersize=~/A6/) { - } - return $textwidth,$textheight,$oddoffset,$evenoffset; -} - - -sub page_format_new { -# -#Correspondence between $papersize variable and real paper format: -# 0 - "Letter [8 1/2x11 in]" -# 1 - "Legal [8 1/2x14 in]" -# 2 - "Ledger/Tabloid [11x17 in]" -# 3 - "Executive [7 1/2x10 in]" -# 4 - "A2 [420x594 mm]" -# 5 - "A3 [297x420 mm]" -# 6 - "A4 [210x297 mm]" -# 7 - "A5 [148x210 mm]" -# 8 - "A6 [105x148 mm]" + #width, height, oddsidemargin, evensidemargin, topmargin +my %page_formats= + ('letter' => { + 'book' => { + '1' => [ '7.1 in','9.8 in', '-0.57 in','-0.57 in','0.275 in'], + '2' => ['3.66 in','9.8 in', '-0.57 in','-0.57 in','0.275 in'] + }, + 'album' => { + '1' => [ '8.8 in', '6.8 in','-0.55 in', '-0.55 in','0.394 in'], + '2' => [ '4.8 in', '6.8 in','-0.5 in', '-1.0 in','3.5 in'] + }, + }, + 'legal' => { + 'book' => { + '1' => ['7.1 in','13 in',,'-0.57 in','-0.57 in','-0.5 in'], + '2' => ['3.66 in','13 in','-0.57 in','-0.57 in','-0.5 in'] + }, + 'album' => { + '1' => ['12 in','7.1 in',,'-0.57 in','-0.57 in','-0.5 in'], + '2' => ['6.0 in','7.1 in','-1 in','-1 in','5 in'] + }, + }, + 'tabloid' => { + 'book' => { + '1' => ['9.8 in','16 in','-0.57 in','-0.57 in','-0.5 in'], + '2' => ['4.9 in','16 in','-0.57 in','-0.57 in','-0.5 in'] + }, + 'album' => { + '1' => ['16 in','9.8 in','-0.57 in','-0.57 in','-0.5 in'], + '2' => ['16 in','4.9 in','-0.57 in','-0.57 in','-0.5 in'] + }, + }, + 'executive' => { + 'book' => { + '1' => ['6.8 in','9 in','-0.57 in','-0.57 in','1.2 in'], + '2' => ['3.1 in','9 in','-0.57 in','-0.57 in','1.2 in'] + }, + 'album' => { + '1' => [], + '2' => [] + }, + }, + 'a2' => { + 'book' => { + '1' => [], + '2' => [] + }, + 'album' => { + '1' => [], + '2' => [] + }, + }, + 'a3' => { + 'book' => { + '1' => [], + '2' => [] + }, + 'album' => { + '1' => [], + '2' => [] + }, + }, + 'a4' => { + 'book' => { + '1' => ['17.6 cm','27.2 cm','-1.397 cm','-2.11 cm','-1.27 cm'], + '2' => [ '9.1 cm','27.2 cm','-1.397 cm','-2.11 cm','-1.27 cm'] + }, + 'album' => { + '1' => ['21.59 cm','19.558 cm','-1.397cm','-2.11 cm','0 cm'], + '2' => ['9.91 cm','19.558 cm','-1.397 cm','-2.11 cm','0 cm'] + }, + }, + 'a5' => { + 'book' => { + '1' => [], + '2' => [] + }, + 'album' => { + '1' => [], + '2' => [] + }, + }, + 'a6' => { + 'book' => { + '1' => [], + '2' => [] + }, + 'album' => { + '1' => [], + '2' => [] + }, + }, + ); + +sub page_format { +# +#Supported paper format: "Letter [8 1/2x11 in]", "Legal [8 1/2x14 in]", +# "Ledger/Tabloid [11x17 in]", "Executive [7 1/2x10 in]", +# "A2 [420x594 mm]", "A3 [297x420 mm]", +# "A4 [210x297 mm]", "A5 [148x210 mm]", +# "A6 [105x148 mm]" # my ($papersize,$layout,$numberofcolumns) = @_; - my ($textwidth,$textheight,$oddoffset,$evenoffset) = (0,0,0,0); - if ($papersize eq '0') { - if ($layout eq 'book') { - if ($numberofcolumns == 1) { - $textwidth = '18 cm'; - $textheight = '25.9 cm'; - $oddoffset = '-0.57 in'; - $evenoffset = '-0.57 in'; - } elsif ($numberofcolumns == 2) { - $textwidth = '93 mm'; - $textheight = '25.9 cm'; - $oddoffset = '-0.57 in'; - $evenoffset = '-0.57 in'; - } - } elsif ($layout eq 'album') { - if ($numberofcolumns eq '1') { - $textwidth = '8.8 in'; - $textheight = '6.8 in'; - $oddoffset = '-40 pt'; - $evenoffset = '-60 pt'; - } elsif ($numberofcolumns == 2) { - $textwidth = '4.2 in'; - $textheight = '6.8 in'; - $oddoffset = '-40 pt'; - $evenoffset = '-60 pt'; - } - } -# } elsif($papersize eq '1') { -# } elsif($papersize eq '2') { -# } elsif($papersize eq '3'/) { - } elsif($papersize eq '6') { - if ($layout eq 'book') { - if ($numberofcolumns == 1) { - $textwidth = '18 cm'; - $textheight = '28 cm'; - $oddoffset = '-0.57 in'; - $evenoffset = '-0.57 in'; - } elsif ($numberofcolumns == 2) { - $textwidth = '96 mm'; - $textheight = '2 cm'; - $oddoffset = '-0.57 in'; - $evenoffset = '-0.57 in'; - } - } elsif ($layout eq 'album') { - if ($numberofcolumns eq '1') { - $textwidth = '8.5 in'; - $textheight = '7.7 in'; - $oddoffset = '-40 pt'; - $evenoffset = '-60 pt'; - } elsif ($numberofcolumns == 2) { - $textwidth = '3.9 in'; - $textheight = '7.7 in'; - $oddoffset = '-40 pt'; - $evenoffset = '-60 pt'; - } - } -# } elsif($papersize eq '5') { -# } elsif($papersize eq '4') { -# } elsif($papersize eq '7') { -# } elsif($papersize eq '8') { - } - return $textwidth,$textheight,$oddoffset,$evenoffset; + return @{$page_formats{$papersize}->{$layout}->{$numberofcolumns}}; } sub get_name { my ($uname,$udom)=@_; - if (!defined($uname)) { $uname=$ENV{'user.name'}; } - if (!defined($udom)) { $uname=$ENV{'user.domain'}; } + if (!defined($uname)) { $uname=$env{'user.name'}; } + if (!defined($udom)) { $udom=$env{'user.domain'}; } my $plainname=&Apache::loncommon::plainname($uname,$udom); - if ($plainname=~/^\s*$/) { $plainname=$uname; } - return &Apache::lonxml::latex_special_symbols($plainname,undef,undef, - 'header'); + if ($plainname=~/^\s*$/) { $plainname=$uname.'@'.$udom; } + $plainname=&Apache::lonxml::latex_special_symbols($plainname,'header'); + return $plainname; } -sub page_format_transformation { - my ($papersize,$layout,$numberofcolumns,$choice,$text,$assignment) = @_; - my ($textwidth,$textheight,$oddoffset,$evenoffset); - $assignment=~s/_/ /g; - if ($numberofcolumns != 1) { - ($textwidth,$textheight,$oddoffset,$evenoffset) = &page_format($papersize,$layout,$numberofcolumns); - } else { - ($textwidth,$textheight,$oddoffset,$evenoffset) = ($ENV{'form.width'},$ENV{'form.height'},$ENV{'form.leftmargin'},$ENV{'form.leftmargin'}); - } - my $name = &get_name(); - if ($name =~ /^\s*$/) { - $name=&Apache::lonxml::latex_special_symbols($ENV{'user.name'},undef, - undef,'header'); - } - my $courseidinfo = &Apache::lonxml::latex_special_symbols(&Apache::lonnet::unescape($ENV{'course.'.$ENV{'request.course.id'}.'.description'}),'','','header'); - if ($layout eq 'CBI') { - $text =~ s/\\begin{document}/\\setlength{\\oddsidemargin}{$oddoffset}\\setlength{\\evensidemargin}{$evenoffset}\\setlength{\\topmargin}{200pt}\\setlength{\\textwidth}{$textwidth}\\setlength{\\textheight}{$textheight}\\setlength{\\parindent}{20pt}\\setlength{\\marginparwidth}{90pt}\\setlength{\\textfloatsep}{8pt plus 2\.0pt minus 4\.0pt}\\newlength{\\minipagewidth}\\setlength{\\minipagewidth}{\\textwidth\/\$number_of_columns-0\.2cm} \\begin{document}\\setcounter{page}{1}\\noindent\\parbox{\\minipagewidth}{\\noindent\\fbox{\\textbf{$name}} \\hfill $courseidinfo} \\vskip 5 mm /; - } elsif ($layout eq 'CAPA') { - if ($choice ne 'All class print') { - $text =~ s/\\begin{document}/\\textheight $textheight\\oddsidemargin = $evenoffset\\evensidemargin = $evenoffset\\textwidth= $textwidth\\newlength{\\minipagewidth}\\setlength{\\minipagewidth}{\\textwidth\/\$number_of_columns-0\.2cm}\\renewcommand{\\ref}{\\keephidden\}\\usepackage{fancyhdr}\\pagestyle{fancy}\\rhead{}\\chead{}\\lhead{\\textbf{$name} - $courseidinfo \\hfill \\thepage \\\\ \\textit{$assignment}}\\begin{document}\\voffset=-0\.8 cm\\setcounter{page}{1}/; - } else { - $text =~ s/\\pagestyle{fancy}\\rhead{}\\chead{}\s*\\begin{document}/\\textheight $textheight\\oddsidemargin = $evenoffset\\evensidemargin = $evenoffset\\textwidth= $textwidth\\newlength{\\minipagewidth}\\setlength{\\minipagewidth}{\\textwidth\/\$number_of_columns-0\.2cm}\\renewcommand{\\ref}{\\keephidden\}\\pagestyle{fancy}\\rhead{}\\chead{}\\begin{document}\\voffset=-0\.8cm\\setcounter{page}{1} \\vskip 5 mm /; - - } +sub get_course { + my $courseidinfo; + if (defined($env{'request.course.id'})) { + $courseidinfo = &Apache::lonxml::latex_special_symbols(&unescape($env{'course.'.$env{'request.course.id'}.'.description'}),'header'); } - return $text; + return $courseidinfo; } +sub page_format_transformation { + my ($papersize,$layout,$numberofcolumns,$choice,$text,$assignment,$tableofcontents,$indexlist,$selectionmade) = @_; + my ($textwidth,$textheight,$oddoffset,$evenoffset,$topmargin); -sub page_format_transformation_new { - my ($papersize,$layout,$numberofcolumns,$choice,$text,$assignment) = @_; - my ($textwidth,$textheight,$oddoffset,$evenoffset); - $assignment=~s/_/ /g; - if ($numberofcolumns != 1) { - ($textwidth,$textheight,$oddoffset,$evenoffset) = &page_format_new($papersize,$layout,$numberofcolumns); + if ($selectionmade eq '4') { + if ($choice eq 'all_problems') { + $assignment='Problems from the Whole Course'; } else { - ($textwidth,$textheight,$oddoffset,$evenoffset) = ($ENV{'form.width'},$ENV{'form.height'},$ENV{'form.leftmargin'},$ENV{'form.leftmargin'}); + $assignment='Resources 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(); - if ($name =~ /^\s*$/) { - $name=&Apache::lonxml::latex_special_symbols($ENV{'user.name'},undef, - undef,'header'); + my $courseidinfo = &get_course(); + if (defined($courseidinfo)) { $courseidinfo=' - '.$courseidinfo } + my $header_text = $parmhash{'print_header_format'}; + $header_text = &format_page_header($textwidth, $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]{$header_text}"; + } else { + $fancypagestatement="\\rhead{}\\chead{}\\lhead{$header_text}"; } - my $courseidinfo = &Apache::lonxml::latex_special_symbols(&Apache::lonnet::unescape($ENV{'course.'.$ENV{'request.course.id'}.'.description'}),'','','header'); if ($layout eq 'album') { - $text =~ s/\\begin{document}/\\setlength{\\oddsidemargin}{$oddoffset}\\setlength{\\evensidemargin}{$evenoffset}\\setlength{\\topmargin}{200pt}\\setlength{\\textwidth}{$textwidth}\\setlength{\\textheight}{$textheight}\\setlength{\\parindent}{20pt}\\setlength{\\marginparwidth}{90pt}\\setlength{\\textfloatsep}{8pt plus 2\.0pt minus 4\.0pt}\\newlength{\\minipagewidth}\\setlength{\\minipagewidth}{\\textwidth\/\$number_of_columns-0\.2cm} \\begin{document}\\setcounter{page}{1}\\noindent\\parbox{\\minipagewidth}{\\noindent\\fbox{\\textbf{$name}} \\hfill $courseidinfo} \\vskip 5 mm /; + $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 /; } elsif ($layout eq 'book') { if ($choice ne 'All class print') { - $text =~ s/\\begin{document}/\\textheight $textheight\\oddsidemargin = $evenoffset\\evensidemargin = $evenoffset\\textwidth= $textwidth\\newlength{\\minipagewidth}\\setlength{\\minipagewidth}{\\textwidth\/\$number_of_columns-0\.2cm}\\renewcommand{\\ref}{\\keephidden\}\\usepackage{fancyhdr}\\pagestyle{fancy}\\rhead{}\\chead{}\\lhead{\\textbf{$name} - $courseidinfo \\hfill \\thepage \\\\ \\textit{$assignment}}\\begin{document}\\voffset=-0\.8 cm\\setcounter{page}{1}/; + $text =~ s/\\begin{document}/\\textheight $textheight\\oddsidemargin = $evenoffset\\evensidemargin = $evenoffset $topmargintoinsert\n\\textwidth= $textwidth\\newlength{\\minipagewidth}\\setlength{\\minipagewidth}{\\textwidth\/\$number_of_columns-0\.2cm}\n\\renewcommand{\\ref}{\\keephidden\}\\usepackage{fancyhdr}\\addtolength{\\headheight}{\\baselineskip}\\pagestyle{fancy}$fancypagestatement\\begin{document}\n\\voffset=-0\.8 cm\\setcounter{page}{1}\n/; } else { - $text =~ s/\\pagestyle{fancy}\\rhead{}\\chead{}\s*\\begin{document}/\\textheight $textheight\\oddsidemargin = $evenoffset\\evensidemargin = $evenoffset\\textwidth= $textwidth\\newlength{\\minipagewidth}\\setlength{\\minipagewidth}{\\textwidth\/\$number_of_columns-0\.2cm}\\renewcommand{\\ref}{\\keephidden\}\\pagestyle{fancy}\\rhead{}\\chead{}\\begin{document}\\voffset=-0\.8cm\\setcounter{page}{1} \\vskip 5 mm /; - + $text =~ s/\\pagestyle{fancy}\\rhead{}\\chead{}\s*\\begin{document}/\\textheight = $textheight\\oddsidemargin = $evenoffset\n\\evensidemargin = $evenoffset $topmargintoinsert\\textwidth= $textwidth\\newlength{\\minipagewidth}\n\\setlength{\\minipagewidth}{\\textwidth\/\$number_of_columns-0\.2cm}\\renewcommand{\\ref}{\\keephidden\}\\pagestyle{fancy}\\rhead{}\\chead{}\\begin{document}\\voffset=-0\.8cm\n\\setcounter{page}{1} \\vskip 5 mm\n /; + } + if ($papersize eq 'a4') { + $text =~ s/(\\begin{document})/$1\\special{papersize=210mm,297mm}/; } } + if ($tableofcontents eq 'yes') {$text=~s/(\\setcounter\{page\}\{1\})/$1 \\tableofcontents\\newpage /;} + if ($indexlist eq 'yes') { + $text=~s/(\\begin{document})/\\makeindex $1/; + $text=~s/(\\end{document})/\\strut\\\\\\strut\\printindex $1/; + } return $text; } - sub page_cleanup { my $result = shift; @@ -1268,34 +1036,43 @@ sub page_cleanup { sub details_for_menu { + my ($helper)=@_; + my $postdata=$env{'form.postdata'}; + if (!$postdata) { $postdata=$helper->{VARS}{'postdata'}; } + my $name_of_resource = &Apache::lonnet::gettitle($postdata); + my $symbolic = &Apache::lonnet::symbread($postdata); + return if ( $symbolic eq ''); - my $name_of_resourse = $hash{'title_'.$hash{'ids_'.$ENV{'form.postdata'}}}; - my $symbolic = &Apache::lonnet::symbread($ENV{'form.postdata'}); - my ($map,$id,$resource)=split(/___/,$symbolic); + my ($map,$id,$resource)=&Apache::lonnet::decode_symb($symbolic); $map=&Apache::lonnet::clutter($map); - my $name_of_sequence; - $name_of_sequence = $hash{'title_'.$hash{'ids_'.$map}}; + my $name_of_sequence = &Apache::lonnet::gettitle($map); if ($name_of_sequence =~ /^\s*$/) { $map =~ m|([^/]+)$|; $name_of_sequence = $1; } - my $name_of_map = $hash{'title_'.$hash{'ids_'.&Apache::lonnet::clutter($ENV{'request.course.uri'})}}; + my $name_of_map = &Apache::lonnet::gettitle($env{'request.course.uri'}); if ($name_of_map =~ /^\s*$/) { - $ENV{'request.course.uri'} =~ m|([^/]+)$|; + $env{'request.course.uri'} =~ m|([^/]+)$|; $name_of_map = $1; } - return ($name_of_resourse,$name_of_sequence,$name_of_map); - + 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) = @_; - - $result =~ s/\\includegraphics{/\\includegraphics\[width=\\minipagewidth\]{/g; + my ($number_of_columns,$result,$selectionmade,$answer_mode) = @_; +# $result =~ s/\\includegraphics{/\\includegraphics\[width=\\minipagewidth\]{/g; + my $copyright = ©right_line(); + if ($selectionmade eq '1' || $answer_mode eq 'only') { + $result =~ s/(\\end{document})/\\strut\\vskip 0 mm $copyright $end_of_student $1/; + } else { + $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{document})/\\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 $1/; $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 @@ -1306,34 +1083,370 @@ sub latex_corrections { $first_comment = index($result,' ELEMENTHTML return $result; } -# If the user didn't select 1 column, skip this state. + sub preprocess { my $self = shift; my $helper = Apache::lonhelper::getHelper(); my $format = $helper->{VARS}->{$self->{'formatvar'}}; - if (substr($format, 2, 1) ne '1') { - $helper->changeState($self->{NEXTSTATE}); + + # If the user does not have 'pav' privilege, set default widths and + # on to the next state right away. + # + if (!$perm{'pav'}) { + my $var = $self->{'variable'}; + my $format = $helper->{VARS}->{$self->{'formatvar'}}; + + my ($laystyle, $cols, $papersize) = split(/\|/, $format); + ($papersize) = split(/ /, $papersize); + + + if ($laystyle eq 'L') { + $laystyle = 'album'; + } else { + $laystyle = 'book'; + } + # Figure out some good defaults for the print out and set them: + + my %size; + ($size{'width'}, + $size{'height'}, + $size{'lmargin'})= + &Apache::lonprintout::page_format($papersize, $laystyle, $cols); + + foreach my $dim ('width', 'height', 'lmargin') { + my ($value, $units) = split(/ /, $size{$dim}); + + $helper->{VARS}->{"$var.".$dim} = $value; + $helper->{VARS}->{"$var.".$dim.'unit'} = $units; + + } + + + # Transition to the next state + + $helper->changeState($self->{NEXTSTATE}); } return 1; @@ -2166,26 +3610,34 @@ sub postprocess { my $var = $self->{'variable'}; my $helper = Apache::lonhelper->getHelper(); - my $width = $helper->{VARS}->{$var .'.width'} = $ENV{"form.${var}.width"}; - my $height = $helper->{VARS}->{$var .'.height'} = $ENV{"form.${var}.height"}; - my $lmargin = $helper->{VARS}->{$var .'.lmargin'} = $ENV{"form.${var}.lmargin"}; - $helper->{VARS}->{$var .'.widthunit'} = $ENV{"form.${var}.widthunit"}; - $helper->{VARS}->{$var .'.heightunit'} = $ENV{"form.${var}.heightunit"}; - $helper->{VARS}->{$var .'.lmarginunit'} = $ENV{"form.${var}.lmarginunit"}; + my $width = $helper->{VARS}->{$var .'.width'} = $env{"form.${var}.width"}; + my $height = $helper->{VARS}->{$var .'.height'} = $env{"form.${var}.height"}; + my $lmargin = $helper->{VARS}->{$var .'.lmargin'} = $env{"form.${var}.lmargin"}; + $helper->{VARS}->{$var .'.widthunit'} = $env{"form.${var}.widthunit"}; + $helper->{VARS}->{$var .'.heightunit'} = $env{"form.${var}.heightunit"}; + $helper->{VARS}->{$var .'.lmarginunit'} = $env{"form.${var}.lmarginunit"}; my $error = ''; # /^-?[0-9]+(\.[0-9]*)?$/ -> optional minus, at least on digit, followed # by an optional period, followed by digits, ending the string - if ($width !~ /^-?[0-9]+(\.[0-9]*)?$/) { + if ($width !~ /^-?[0-9]*(\.[0-9]*)?$/) { $error .= "Invalid width; please type only a number.
\n"; } - if ($height !~ /^-?[0-9]+(\.[0-9]*)?$/) { + if ($height !~ /^-?[0-9]*(\.[0-9]*)?$/) { $error .= "Invalid height; please type only a number.
\n"; } - if ($lmargin !~ /^-?[0-9]+(\.[0-9]*)?$/) { + if ($lmargin !~ /^-?[0-9]*(\.[0-9]*)?$/) { $error .= "Invalid left margin; please type only a number.
\n"; + } else { + # Adjust for LaTeX 1.0 inch margin: + + if ($env{"form.${var}.lmarginunit"} eq "in") { + $helper->{VARS}->{$var.'.lmargin'} = $lmargin - 1; + } else { + $helper->{VARS}->{$var.'.lmargin'} = $lmargin - 2.54; + } } if (!$error) { 500 Internal Server Error

Internal Server Error

The server encountered an internal error or misconfiguration and was unable to complete your request.

Please contact the server administrator at root@localhost to inform them of the time this error occurred, and the actions you performed just before this error.

More information about this error may be available in the server error log.