--- loncom/interface/lonprintout.pm 2010/03/31 14:37:36 1.574 +++ loncom/interface/lonprintout.pm 2024/11/11 00:43:39 1.703 @@ -1,8 +1,7 @@ -# # The LearningOnline Network # Printout # -# $Id: lonprintout.pm,v 1.574 2010/03/31 14:37:36 wenzelju Exp $ +# $Id: lonprintout.pm,v 1.703 2024/11/11 00:43:39 raeburn Exp $ # # Copyright Michigan State University Board of Trustees # @@ -41,17 +40,17 @@ use Apache::admannotations; use Apache::lonenc; use Apache::entities; use Apache::londefdef; +# use Apache::structurelags; # for language management. use File::Basename; use HTTP::Response; - use LONCAPA::map(); -use POSIX qw(strftime); use Apache::lonlocal; use Carp; use LONCAPA; + my %perm; my %parmhash; my $resources_printed; @@ -76,7 +75,198 @@ my $font_size = 'normalsize'; # Default #---------------------------- Helper helpers. ------------------------- -# Returns the text needd for a student chooser. +## +# Filter function to determine if a resource is a printable sequence. +# +# @param $res -Resource to check. +# +# @return 1 - printable and a resource +# 0 - either notm a sequence or not printable. +# +sub printable_sequence { + my $res = shift; + + # Non-sequences are not listed: + + if (!$res->is_sequence()) { + return 0; + } + + # Person with pav or pfo can always print: + + if ($perm{'pav'} || $perm{'pfo'}) { + return 1; + } + + if ($res->is_sequence()) { + my $symb = $res->symb(); + my $navmap = $res->{NAV_MAP}; + + # Find the first resource in the map: + + my $iterator = $navmap->getIterator($res, undef, undef, 1, 1); + my $first = $iterator->next(); + + while (1) { + if ($first == $iterator->END_ITERATOR) { last; } + if (ref($first) && ! $first->is_sequence()) {last; } + $first = $iterator->next(); + } + + + # Might be an empty map: + + if (!ref($first)) { + return 0; + } + my $partsref = $first->parts(); + my @parts = @$partsref; + my ($open, $close) = $navmap->map_printdates($first, $parts[0]); + return &printable($open, $close); + } + return 0; +} + +# BZ5209: +# Create the states needed to run the helper for incomplete problems from +# the current folder for selected students. +# This includes: +# - A resource selector limited to problems (incompleteness must be +# calculated on a student per student basis. +# - A student selector. +# - Tie in to the FORMAT of the print job. +# +# States: +# CHOOSE_INCOMPLETE_PEOPLE_SEQ - Resource selection. +# CHOOSE_STUDENTS_INCOMPLETE - Student selection. +# CHOOSE_STUDENTS_INCOMPLETE_FORMAT - Format selection +# Parameters: +# helper - the helper which already contains info about the current folder we can +# purloin. +# map - the map for which incomplete problems are to be printed +# nocurrloc - True if printout called from icon/link in Tools in /adm/navmaps +# Return: +# XML that can be parsed by the helper to drive the state machine. +# +sub create_incomplete_folder_selstud_helper { + my ($helper, $map, $nocurrloc) = @_; + + + my $symbFilter = '$res->shown_symb()'; + my $selFilter = '$res->is_problem()'; + + + my $resource_chooser = &generate_resource_chooser('CHOOSE_INCOMPLETE_PEOPLE_SEQ', + 'Select problem(s) to print', + 'multichoice="1" toponly="1" addstatus="1" closeallpages="1" modallink="1" nocurrloc="'.$nocurrloc.'"', + 'RESOURCES', + 'CHOOSE_STUDENTS_INCOMPLETE', + $map, + $selFilter, + '', + $symbFilter, + ''); + + my $student_chooser = &generate_student_chooser('CHOOSE_STUDENTS_INCOMPLETE', + 'student_sort', + 'STUDENTS', + 'CHOOSE_STUDENTS_INCOMPLETE_FORMAT'); + + my $format_chooser = &generate_format_selector($helper, + 'Format of the print job', + 'CHOOSE_STUDENTS_INCOMPLETE_FORMAT'); # end state. + + return $resource_chooser . $student_chooser . $format_chooser; +} + + +# BZ 5209 +# Create the states needed to run the helper for incomplete problems from +# the current folder for selected students. +# This includes: +# - A resource selector limited to problems. (incompleteness must be calculated +# on a student per student basis. +# - A student selector. +# - Tie in to format for the print job. +# States: +# INCOMPLETE_PROBLEMS_COURSE_RESOURCES - Resource selector. +# INCOMPLETE_PROBLEMS_COURSE_STUDENTS - Student selector. +# INCOMPLETE_PROBLEMS_COURSE_FORMAT - Format selection. +# +# Parameters: +# helper - Helper we are creating states for. +# Returns: +# Text that can be parsed by the helper. +# + +sub create_incomplete_course_helper { + my $helper = shift; + + my $filter = '$res->is_problem() || $res->contains_problem() || $res->is_sequence() || $res->is_practice())'; + my $symbfilter = '$res->shown_symb()'; + + my $resource_chooser = &generate_resource_chooser('INCOMPLETE_PROBLEMS_COURSE_RESOURCES', + 'Select problem(s) to print', + 'multichoice = "1" suppressEmptySequences="0" addstatus="1" closeallpagtes="1" modallink="1"', + 'RESOURCES', + 'INCOMPLETE_PROBLEMS_COURSE_STUDENTS', + '', + $filter, + '', + $symbfilter, + ''); + + my $people_chooser = &generate_student_chooser('INCOMPLETE_PROBLEMS_COURSE_STUDENTS', + 'student_sort', + 'STUDENTS', + 'INCOMPLETE_PROBLEMS_COURSE_FORMAT'); + + my $format = &generate_format_selector($helper, + 'Format of the print job', + 'INCOMPLETE_PROBLEMS_COURSE_FORMAT'); # end state. + + return $resource_chooser . $people_chooser . $format; + + +} + +# BZ5209 +# Creates the states needed to run the print helper for a student +# that wants to print his incomplete problems from the current folder. +# Parameters: +# $helper - helper we are generating states for. +# $map - The map for which the student wants incomplete problems. +# $nocurrloc - True if printout called from icon/link in Tools in /adm/navmaps +# Returns: +# XML that defines the helper states being created. +# +# States: +# CHOOSE_INCOMPLETE_SEQ - Resource selector. +# +sub create_incomplete_folder_helper { + my ($helper, $map, $nocurrloc) = @_; + + my $filter = '$res->is_problem()'; + $filter .= ' && $res->resprintable() '; + $filter .= ' && $res->is_incomplete() '; + + my $symfilter = '$res->shown_symb()'; + + my $resource_chooser = &generate_resource_chooser('CHOOSE_INCOMPLETE_SEQ', + 'Select problem(s) to print', + 'multichoice="1", toponly ="1", addstatus="1", closeallpages="1" modallink="1" nocurrloc="'.$nocurrloc.'"', + 'RESOURCES', + 'PAGESIZE', + $map, + $filter, '', + $symfilter, + ''); + + return $resource_chooser; +} + + +# Returns the text neded for a student chooser. # that text must still be parsed by the helper xml parser. # Parameters: # this_state - State name of the chooser. @@ -86,9 +276,9 @@ my $font_size = 'normalsize'; # Default sub generate_student_chooser { - my ($this_state, - $sort_choice, - $variable, + my ($this_state, + $sort_choice, + $variable, $next_state) = @_; my $result = < @@ -100,7 +290,7 @@ sub generate_student_chooser {


- @@ -118,7 +308,8 @@ CHOOSE_STUDENTS # this_state - State name of the chooser. # prompt_text - Text to use to prompt user. # resource_options - Resource tag options e.g. -# "multichoice='1', toponly='1', addstatus='1'" +# "multichoice='1', toponly='1', addstatus='1', +# modallink='1'" # that control the selection and appearance of the # resource selector. # variable - Name of the variable to hold the choice @@ -129,7 +320,7 @@ CHOOSE_STUDENTS # filter - How to filter the resources. # value_func - function. # choice_func - If not empty generates a with this function. -# start_new_option +# start_new_option # - Fragment appended after valuefunc. # # @@ -164,7 +355,6 @@ CHOOSE_RESOURCES CHOOSE_RESOURCES - return $result; } # @@ -196,14 +386,19 @@ sub generate_code_selector {


Generate new CODEd Assignments

' @@ -1730,11 +2487,10 @@ sub recently_generated { .'' .&Apache::loncommon::end_data_table_header_row() .$zip_result - .&Apache::loncommon::end_data_table() - ); + .&Apache::loncommon::end_data_table(); } if ($pdf_result) { - $r->print('

'.&mt('Recently generated printouts')."

\n" + $output .='

'.&mt('Recently generated printouts')."

\n" .&Apache::loncommon::start_data_table() .&Apache::loncommon::start_data_table_header_row() .'' @@ -1742,9 +2498,9 @@ sub recently_generated { .'' .&Apache::loncommon::end_data_table_header_row() .$pdf_result - .&Apache::loncommon::end_data_table() - ); + .&Apache::loncommon::end_data_table(); } + return $output; } # @@ -1772,7 +2528,7 @@ sub get_page_breaks { } return %page_breaks; } -# +# # Returns text to insert for any extra vskip prior to the resource. # Parameters: # helper - Reference to the helper object driving the printout. @@ -1783,7 +2539,7 @@ sub get_page_breaks { # EXTRASPACE has the list of extra space values. # EXTRASPACE_UNITS is the set of resources for which the units are # mm. All others are 'in'. -# +# # The resource is found in the POSSIBLE_RESOURCES to get the index # of the EXTRASPACE value. # @@ -1804,7 +2560,7 @@ sub load_skips { my ($helper) = @_; - # If this is the first time, unrap the resources and extra spaces: + # If this is the first time, unwrap the resources and extra spaces: if (!$skips_loaded) { @extraspace = (split(/\|\|\|/, $helper->{'VARS'}->{'EXTRASPACE'})); @@ -1852,7 +2608,7 @@ sub get_extra_vspaces { # The resource chooser part of the helper needs more than just # the value of the extraspaces var to recover the value into a text # field option. This sub produces the required format for the saved var: -# specifically +# specifically # ||| separated fields of the form resourcename=value # # Parameters: @@ -1886,7 +2642,7 @@ sub set_form_extraspace { $env{'form.extraspace'} = $result; $env{'form.extraspace_units'} = $helper->{'VARS'}->{'EXTRASPACE_UNITS'}; return $result; - + } # Output a sequence (recursively if neeed) @@ -1904,17 +2660,20 @@ sub set_form_extraspace { # sub print_construction_sequence { my ($currentURL, $helper, %form, $LaTeXwidth) = @_; + my $result; my $rndseed=time; if ($helper->{'VARS'}->{'curseed'}) { $rndseed=$helper->{'VARS'}->{'curseed'}; } - my $errtext=&LONCAPA::map::mapread($currentURL); - # + my $errtext=&LONCAPA::map::mapread(&Apache::lonnet::filelocation('',$currentURL)); + + # # These make this all support recursing for subsequences. # my @order = @LONCAPA::map::order; - my @resources = @LONCAPA::map::resources; + my @resources = @LONCAPA::map::resources; + for (my $member=0;$member<=$#order;$member++) { $resources[$order[$member]]=~/^([^:]*):([^:]*):/; my $urlp=$2; @@ -1929,8 +2688,8 @@ sub print_construction_sequence { $texversion=&ssi_with_retries($urlp, $ssi_retry_count, %form); } if((($helper->{'VARS'}->{'ANSWER_TYPE'} eq 'no') || - ($helper->{'VARS'}->{'ANSWER_TYPE'} eq 'only')) && - ($urlp=~/\.(problem|exam|quiz|assess|survey|form|library|page)$/)) { + ($helper->{'VARS'}->{'ANSWER_TYPE'} eq 'only')) && + ($urlp=~/$LONCAPA::assess_page_re/)) { # Don't permanently modify %$form... my %answerform = %form; $answerform{'grade_target'}='answer'; @@ -1941,17 +2700,17 @@ sub print_construction_sequence { $resources_printed .= $urlp.':'; my $answer=&ssi_with_retries($urlp, $ssi_retry_count, %answerform); if ($helper->{'VARS'}->{'ANSWER_TYPE'} eq 'no') { - $texversion=~s/(\\keephidden{ENDOFPROBLEM})/$answer$1/; + $texversion=~s/(\\keephidden\{ENDOFPROBLEM})/$answer$1/; } else { # If necessary, encapsulate answer in minipage: - + $texversion=&print_latex_header($helper->{'VARS'}->{'LATEX_TYPE'}); my $title = &Apache::lonnet::gettitle($helper->{'VARS'}->{'symb'}); $title = &Apache::lonxml::latex_special_symbols($title); my $body ='\vskip 0 mm \noindent\textbf{'.$title.'}\vskip 0 mm '; $body.=&path_to_problem($urlp,$LaTeXwidth); $body.='\vskip 1 mm '.$answer.'\end{document}'; - $body = &encapsulate_minipage($body); + $body = &encapsulate_minipage($body,$answerform{'problem_split'}); $texversion.=$body; } } @@ -1966,23 +2725,16 @@ sub print_construction_sequence { $result.=$texversion; } elsif ($urlp=~/\.(sequence|page)$/) { - + # header: $result.='\strut\newline\noindent Sequence/page '.$urlp.'\strut\newline\noindent\makebox[\textwidth/$number_of_columns][b]{\hrulefill}\newline\noindent '; # IF sequence, recurse: - + if ($urlp =~ /\.sequence$/) { - my $sequence_url = $urlp; - my $domain = $env{'user.domain'}; # Constr. space only on local - my $user = $env{'user.name'}; - - $sequence_url =~ s/^\/res\/$domain/\/home/; - $sequence_url =~ s/^(\/home\/$user)/$1\/public_html/; -# $sequence_url =~ s|\/~([^\/]+)\/|\/home\/$1\/public_html\/|; - $result .= &print_construction_sequence($sequence_url, - $helper, %form, + $result .= &print_construction_sequence($urlp, + $helper, %form, $LaTeXwidth); } } @@ -1997,20 +2749,54 @@ sub print_construction_sequence { if ($member != $#order) { $texversion .= '\\ \cleardoublepage'; } - + $result .= $texversion; } } - if ($helper->{VARS}->{'construction'} eq '1') {$result=~s/(\\begin{document})/$1 \\fbox\{RANDOM SEED IS $rndseed\} /;} + if ($helper->{VARS}->{'construction'} eq '1') {$result=~s/(\\begin\{document})/$1 \\fbox\{RANDOM SEED IS $rndseed\} /;} return $result; } +# +# Top level for generating print output. +# +# May call print_resources if multiple resources will be printed. +# +# The main driver is $selectionmade which reflects the type of print out +# requested: +# Value Print type: +# 1 Print resource that's being looked at. +# 2 Print problems in a map or in a page. +# 3 Print pages in a map or resources in a page. +# 4 Print all problems or all resources. +# 5 Print problems for seleted students. +# 6 Print selected problems from a folder. +# 7 Print print selected resources from some scope. +# 8 Print resources for selected students. +# 9 Print for anonymous CODEs +# +#BZ 5209 +# 2 map_incomplete_problems_seq Print incomplete problems from the current +# folder in student context. +# 5 map_incomplete_problems_people_seq Print incomplete problems from the +# current folder in privileged context. +# 5 incomplete_problems_selpeople_course Print incomplete problems for +# selected people from the entire course. +# +# Item 101 has much the same processing as 8, +# +# Differences: Item 101, 102 require per-student filtering of the resource +# set so that only the incomplete resources are printed. +# For item 100, filtering was done at the helper level. + sub output_data { + my ($r,$helper,$rparmhash) = @_; my %parmhash = %$rparmhash; $ssi_error = 0; # This will be set nonzero by failing ssi's. $resources_printed = ''; $font_size = $helper->{'VARS'}->{'fontsize'}; + my $print_type = $helper->{'VARS'}->{'PRINT_TYPE'}; # Allows textual simplification. my $do_postprocessing = 1; my $js = < @@ -2025,7 +2811,7 @@ sub output_data { url += 'form=' + formname + '&'; if (only != null) { url += 'only=' + only + '&'; - } + } if (omit != null) { url += 'omit=' + omit + '&'; } @@ -2060,7 +2846,7 @@ ENDPART $env{'form.pagebreaks'} = $helper->{'VARS'}->{'FINISHPAGE'}; &set_form_extraspace($helper); - $env{'form.lastprinttype'} = $helper->{'VARS'}->{'PRINT_TYPE'}; + $env{'form.lastprinttype'} = $print_type; &Apache::loncommon::store_course_settings('print', {'pagebreaks' => 'scalar', 'extraspace' => 'scalar', @@ -2077,13 +2863,13 @@ ENDPART $laystyle = &map_laystyle($laystyle); my ($textwidth,$textheight,$oddoffset,$evenoffset) = &page_format($papersize,$laystyle,$numberofcolumns); my $assignment = $env{'form.assignment'}; - my $LaTeXwidth=&recalcto_mm($textwidth); + my $LaTeXwidth=&recalcto_mm($textwidth); my @print_array=(); my @student_names=(); + my $lastprinted; - - # Common settings for the %form has: - # In some cases these settings get overriddent by specific cases, but the + # Common settings for the %form hash: + # In some cases these settings get overridden by specific cases, but the # settings are common enough to make it worthwhile factoring them out # here. # @@ -2093,16 +2879,16 @@ ENDPART $form{'pdfFormFields'} = $pdfFormFields; # If form.showallfoils is set, then request all foils be shown: - # privilege will be enforced both by not allowing the + # privilege will be enforced both by not allowing the # check box selecting this option to be presnt unless it's ok, # and by lonresponse's priv. check. # The if is here because lonresponse.pm only cares that # showallfoils is defined, not what the value is. - if ($helper->{'VARS'}->{'showallfoils'} eq "1") { + if ($helper->{'VARS'}->{'showallfoils'} eq "1") { $form{'showallfoils'} = $helper->{'VARS'}->{'showallfoils'}; } - + if ($helper->{'VARS'}->{'style_file'}=~/\w/) { &Apache::lonnet::appenv({'construct.style' => $helper->{'VARS'}->{'style_file'}}); @@ -2110,8 +2896,7 @@ ENDPART &Apache::lonnet::delenv('construct.style'); } - - if ($helper->{'VARS'}->{'PRINT_TYPE'} eq 'current_document') { + if ($print_type eq 'current_document') { #-- single document - problem, page, html, xml, ... my ($currentURL,$cleanURL); @@ -2122,11 +2907,11 @@ ENDPART } else { #prints resource from the construction space - $currentURL='/'.$helper->{'VARS'}->{'filename'}; - if ($currentURL=~/([^?]+)/) {$currentURL=$1;} + $currentURL=$helper->{'VARS'}->{'filename'}; $cleanURL=$currentURL; } $selectionmade = 1; + if ($cleanURL!~m|^/adm/| && $cleanURL=~/\.(problem|exam|quiz|assess|survey|form|library|xml|html|htm|xhtml|xhtm)$/) { my $rndseed=time; @@ -2156,7 +2941,7 @@ ENDPART $texversion.=&ssi_with_retries($currentURL,$ssi_retry_count, %form); # Add annotations if required: - + &Apache::lonxml::clear_problem_counter(); &Apache::lonnet::delenv('request.filename'); @@ -2166,6 +2951,7 @@ ENDPART if(($helper->{'VARS'}->{'ANSWER_TYPE'} eq 'no') || ($helper->{'VARS'}->{'ANSWER_TYPE'} eq 'only')) { + $form{'problem_split'}=$parmhash{'problem_stream_switch'}; $form{'grade_target'}='answer'; $form{'answer_output_mode'}='tex'; @@ -2178,7 +2964,7 @@ ENDPART if ($helper->{'VARS'}->{'ANSWER_TYPE'} eq 'no') { - $texversion=~s/(\\keephidden{ENDOFPROBLEM})/$answer$1/; + $texversion=~s/(\\keephidden\{ENDOFPROBLEM})/$answer$1/; } else { $texversion=&print_latex_header($helper->{'VARS'}->{'LATEX_TYPE'}); if ($helper->{'VARS'}->{'construction'} ne '1') { @@ -2187,10 +2973,10 @@ ENDPART $texversion.='\vskip 0 mm \noindent\textbf{'.$title.'}\vskip 0 mm '; $texversion.=&path_to_problem($cleanURL,$LaTeXwidth); } else { - $texversion.='\vskip 0 mm \noindent\textbf{Prints from construction space - there is no title.}\vskip 0 mm '; - my $URLpath=$cleanURL; - $URLpath=~s/~([^\/]+)/public_html\/$1\/$1/; - $texversion.=&path_to_problem($URLpath,$LaTeXwidth); + $texversion.='\vskip 0 mm \noindent\textbf{'. + &mt("Printing from Authoring Space: No Title").'}\vskip 0 mm '; + + $texversion.=&path_to_problem($cleanURL,$LaTeXwidth); } $texversion.='\vskip 1 mm '.$answer.'\end{document}'; } @@ -2198,14 +2984,14 @@ ENDPART - + } # Print annotations. if ($helper->{'VARS'}->{'PRINT_ANNOTATIONS'} eq 'yes') { my $annotation .= &annotate($currentURL); - $texversion =~ s/(\\keephidden{ENDOFPROBLEM})/$annotation$1/; + $texversion =~ s/(\\keephidden\{ENDOFPROBLEM})/$annotation$1/; } @@ -2222,25 +3008,22 @@ ENDPART } } elsif ($cleanURL!~m|^/adm/| && $currentURL=~/\.(sequence|page)$/ && $helper->{'VARS'}->{'construction'} eq '1') { - #printing content of sequence from the construction space - - - $currentURL=~s|\/~([^\/]+)\/|\/home\/$1\/public_html\/|; $result .= &print_construction_sequence($currentURL, $helper, %form, $LaTeXwidth); - $result .= '\end{document}'; + $result .= '\end{document}'; if (!($result =~ /\\begin\{document\}/)) { $result = &print_latex_header() . $result; } # End construction space sequence. - } elsif ($cleanURL=~/\/(smppg|syllabus|aboutme|bulletinboard)$/) { + } elsif ($cleanURL=~/\/(smppg|syllabus|aboutme|bulletinboard|ext\.tool)$/) { $form{'latex_type'}=$helper->{'VARS'}->{'LATEX_TYPE'}; if ($currentURL=~/\/syllabus$/) {$currentURL=~s/\/res//;} + if ($currentURL=~/\/ext\.tool$/) {$currentURL=~s/^\/adm\/wrapper//;} $resources_printed .= $currentURL.':'; my $texversion = &ssi_with_retries($currentURL, $ssi_retry_count, %form); if ($helper->{'VARS'}->{'PRINT_ANNOTATIONS'} eq 'yes') { my $annotation = &annotate($currentURL); - $texversion =~ s/(\\end{document})/$annotation$1/; + $texversion =~ s/(\\end\{document})/$annotation$1/; } $result .= $texversion; } elsif ($cleanURL =~/\.tex$/) { @@ -2251,7 +3034,7 @@ ENDPART $result = &fetch_raw_resource($currentURL); if ($helper->{'VARS'}->{'PRINT_ANNOTATIONS'} eq 'yes') { my $annotation = &annotate($currentURL); - $result =~ s/(\\end{document})/$annotation$1/; + $result =~ s/(\\end\{document})/$annotation$1/; } $do_postprocessing = 0; # Don't massage the result. @@ -2268,37 +3051,39 @@ ENDPART $result .= &print_page_in_course($helper, $rparmhash, $cleanURL, \@page_resources); - + } else { $result.=&unsupported($currentURL,$helper->{'VARS'}->{'LATEX_TYPE'}, $helper->{'VARS'}->{'symb'}); } - } elsif (($helper->{'VARS'}->{'PRINT_TYPE'} eq 'map_problems') or - ($helper->{'VARS'}->{'PRINT_TYPE'} eq 'map_problems_in_page') or - ($helper->{'VARS'}->{'PRINT_TYPE'} eq 'map_resources_in_page') or - ($helper->{'VARS'}->{'PRINT_TYPE'} eq 'map_problems_pages') or - ($helper->{'VARS'}->{'PRINT_TYPE'} eq 'all_problems') or - ($helper->{'VARS'}->{'PRINT_TYPE'} eq 'all_resources') or # BUGBUG - ($helper->{'VARS'}->{'PRINT_TYPE'} eq 'select_sequences') - ) { - + } elsif (($print_type eq 'map_problems') or + ($print_type eq 'map_problems_in_page') or + ($print_type eq 'map_resources_in_page') or + ($print_type eq 'map_problems_pages') or + ($print_type eq 'all_problems') or + ($print_type eq 'all_resources') or # BUGBUG + ($print_type eq 'select_sequences') or + ($print_type eq 'map_incomplete_problems_seq') + ) { #-- produce an output string - if (($helper->{'VARS'}->{'PRINT_TYPE'} eq 'map_problems') or - ($helper->{'VARS'}->{'PRINT_TYPE'} eq 'map_problems_in_page') ) { + if (($print_type eq 'map_problems') or + ($print_type eq 'map_incomplete_problems_seq') or + ($print_type eq 'map_problems_in_page') ) { $selectionmade = 2; - } elsif (($helper->{'VARS'}->{'PRINT_TYPE'} eq 'map_problems_pages') or - ($helper->{'VARS'}->{'PRINT_TYPE'} eq 'map_resources_in_page')) + } elsif (($print_type eq 'map_problems_pages') or + ($print_type eq 'map_resources_in_page')) { $selectionmade = 3; - } elsif (($helper->{'VARS'}->{'PRINT_TYPE'} eq 'all_problems') + } elsif (($print_type eq 'all_problems') ) { $selectionmade = 4; - } elsif ($helper->{'VARS'}->{'PRINT_TYPE'} eq 'all_resources') { #BUGBUG + } elsif ($print_type eq 'all_resources') { #BUGBUG $selectionmade = 4; - } elsif ($helper->{'VARS'}->{'PRINT_TYPE'} eq 'select_sequences') { + } elsif ($print_type eq 'select_sequences') { $selectionmade = 7; } + $form{'problem_split'}=$parmhash{'problem_stream_switch'}; $form{'suppress_tries'}=$parmhash{'suppress_tries'}; $form{'latex_type'}=$helper->{'VARS'}->{'LATEX_TYPE'}; @@ -2315,12 +3100,10 @@ ENDPART &Apache::lonxml::clear_problem_counter(); - my $pbreakresources = keys %page_breaks; for (my $i=0;$i<=$#master_seq;$i++) { &Apache::lonenc::reset_enc(); - # Note due to document structure, not allowed to put \newpage # prior to the first resource @@ -2341,19 +3124,26 @@ ENDPART my $texversion=''; if ($urlp!~m|^/adm/| && $urlp=~/\.(problem|exam|quiz|assess|survey|form|library|page|xml|html|htm|xhtml|xhtm)$/) { + my $extension = $1; $resources_printed .= $urlp.':'; &Apache::lonxml::remember_problem_counter(); if ($flag_latex_header_remove eq 'NO') { $texversion.=&print_latex_header($helper->{'VARS'}->{'LATEX_TYPE'}); # RF - $flag_latex_header_remove = 'YES'; + unless (($helper->{'VARS'}->{'ANSWER_TYPE'} eq 'only') || + (($i==0) && + (($urlp=~/\.page$/) || + ($print_type eq 'map_problems_in_page') || + (($print_type eq 'map_resources_in_page') && ($extension !~ /^x?html?$/))))) { + $flag_latex_header_remove = 'YES'; + } } $texversion.=&ssi_with_retries($urlp, $ssi_retry_count, %form); if ($urlp=~/\.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}/; + 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(($helper->{'VARS'}->{'ANSWER_TYPE'} eq 'no') || ($helper->{'VARS'}->{'ANSWER_TYPE'} eq 'only')) { @@ -2365,19 +3155,28 @@ ENDPART &Apache::lonxml::restore_problem_counter(); my $answer=&ssi_with_retries($urlp, $ssi_retry_count, %answerform); - + if ($urlp =~ /\.page$/) { + $answer =~ s/\\end\{document}(\d*)$//; + } if ($helper->{'VARS'}->{'ANSWER_TYPE'} eq 'no') { - $texversion=~s/(\\keephidden{ENDOFPROBLEM})/$answer$1/; + if ($urlp =~ /\.page$/) { + my @probs = split(/\\keephidden\{ENDOFPROBLEM}/,$texversion); + my $lastprob = pop(@probs); + $texversion = join('\keephidden{ENDOFPROBLEM}',@probs). + $answer.'\keephidden{ENDOFPROBLEM}'.$lastprob; + } else { + $texversion=~s/(\\keephidden\{ENDOFPROBLEM})/$answer$1/; + } } else { - if ($urlp=~/\.(problem|exam|quiz|assess|survey|form|library)$/) { + if ($urlp=~/$LONCAPA::assess_page_re/) { $texversion=&print_latex_header($helper->{'VARS'}->{'LATEX_TYPE'}); - $texversion =~ s/\\begin{document}//; +# $texversion =~ s/\\begin\{document}//; # FIXME my $title = &Apache::lonnet::gettitle($master_seq[$i]); $title = &Apache::lonxml::latex_special_symbols($title); my $body ='\vskip 0 mm \noindent\textbf{'.$title.'}\vskip 0 mm '; $body .= &path_to_problem ($urlp,$LaTeXwidth); $body .='\vskip 1 mm '.$answer; - $body = &encapsulate_minipage($body); + $body = &encapsulate_minipage($body,$answerform{'problem_split'}); $texversion .= $body; } else { $texversion=''; @@ -2387,13 +3186,13 @@ ENDPART } if ($helper->{'VARS'}->{'PRINT_ANNOTATIONS'} eq 'yes') { my $annotation .= &annotate($urlp); - $texversion =~ s/(\\keephidden{ENDOFPROBLEM})/$annotation$1/; + $texversion =~ s/(\\keephidden\{ENDOFPROBLEM})/$annotation$1/; } if ($flag_latex_header_remove ne 'NO') { $texversion = &latex_header_footer_remove($texversion); } else { - $texversion =~ s/\\end{document}//; + $texversion =~ s/\\end\{document}//; } if ($helper->{'VARS'}->{'TABLE_INDEX'} eq 'yes') { $texversion=&IndexCreation($texversion,$urlp); @@ -2404,10 +3203,9 @@ ENDPART $prevassignment=$assignment; my $header_text = $parmhash{'print_header_format'}; $header_text = &format_page_header($textwidth, $header_text, - $assignment, - $courseidinfo, + $assignment, + $courseidinfo, $name); - if ($numberofcolumns eq '1') { $result .='\newpage \noindent\parbox{\minipagewidth}{\noindent\\lhead{'.$header_text.'}} \vskip 5 mm '; } else { @@ -2415,29 +3213,34 @@ ENDPART } } $result .= $texversion; - $flag_latex_header_remove = 'YES'; - } elsif ($urlp=~/\/(smppg|syllabus|aboutme|bulletinboard)$/) { + $flag_latex_header_remove = 'YES'; + } elsif ($urlp=~/\/(smppg|syllabus|aboutme|bulletinboard|ext\.tool)$/) { $form{'latex_type'}=$helper->{'VARS'}->{'LATEX_TYPE'}; if ($urlp=~/\/syllabus$/) {$urlp=~s/\/res//;} + if ($urlp=~/\/ext\.tool$/) {$urlp=~s/^\/adm\/wrapper//;} $resources_printed .= $urlp.':'; my $texversion = &ssi_with_retries($urlp, $ssi_retry_count, %form); if ($helper->{'VARS'}->{'PRINT_ANNOTATIONS'} eq 'yes') { my $annotation = &annotate($urlp); - $texversion =~ s/(\\end{document)/$annotation$1/; + $texversion =~ s/(\\end\{document)/$annotation$1/; } if ($flag_latex_header_remove ne 'NO') { $texversion = &latex_header_footer_remove($texversion); } else { - $texversion =~ s/\\end{document}/\\vskip 0\.5mm\\noindent\\makebox\[\\textwidth\/\$number_of_columns\]\[b\]\{\\hrulefill\}/; + $texversion =~ s/\\end\{document}/\\vskip 0\.5mm\\noindent\\makebox\[\\textwidth\/\$number_of_columns\]\[b\]\{\\hrulefill\}/; } $result .= $texversion; - $flag_latex_header_remove = 'YES'; + $flag_latex_header_remove = 'YES'; } elsif ($urlp=~ /\.pdf$/i) { if ($i > 0) { $result .= '\cleardoublepage'; } - $result .= &include_pdf($urlp); + my $texfrompdf = &include_pdf($urlp); + if ($flag_latex_header_remove ne 'NO') { + $texfrompdf = &latex_header_footer_remove($texfrompdf); + } + $result .= $texfrompdf; if ($i != $#master_seq) { if ($numberofcolumns eq '1') { $result .= '\newpage'; @@ -2456,34 +3259,42 @@ ENDPART if ($flag_latex_header_remove ne 'NO') { $texversion = &latex_header_footer_remove($texversion); } else { - $texversion =~ s/\\end{document}//; + $texversion =~ s/\\end\{document}//; } $result .= $texversion; - $flag_latex_header_remove = 'YES'; - } - if (&Apache::loncommon::connection_aborted($r)) { - last; + $flag_latex_header_remove = 'YES'; + } + if (&Apache::loncommon::connection_aborted($r)) { + last; } } &Apache::lonxml::clear_problem_counter(); if ($flag_page_in_sequence eq 'YES') { - $result =~ s/\\usepackage{calc}/\\usepackage{calc}\\usepackage{longtable}/; + $result =~ s/\\usepackage\{calc}/\\usepackage{calc}\\usepackage{longtable}/; } $result .= '\end{document}'; - } elsif (($helper->{'VARS'}->{'PRINT_TYPE'} eq 'problems_for_students') || - ($helper->{'VARS'}->{'PRINT_TYPE'} eq 'problems_for_students_from_page') || - ($helper->{'VARS'}->{'PRINT_TYPE'} eq 'all_problems_students') || - ($helper->{'VARS'}->{'PRINT_TYPE'} eq 'resources_for_students')){ + } elsif (($print_type eq 'problems_for_students') || + ($print_type eq 'problems_for_students_from_page') || + ($print_type eq 'all_problems_students') || + ($print_type eq 'resources_for_students') || + ($print_type eq 'incomplete_problems_selpeople_course') || + ($print_type eq 'map_incomplete_problems_people_seq') || + ($print_type eq 'select_sequences_problems_for_students') || + ($print_type eq 'select_sequences_resources_for_students')) { - #-- prints assignments for whole class or for selected students + #-- prints assignments for whole class or for selected students my $type; - if (($helper->{'VARS'}->{'PRINT_TYPE'} eq 'problems_for_students') || - ($helper->{'VARS'}->{'PRINT_TYPE'} eq 'problems_for_students_from_page') || - ($helper->{'VARS'}->{'PRINT_TYPE'} eq 'all_problems_students') ) { + if (($print_type eq 'problems_for_students') || + ($print_type eq 'problems_for_students_from_page') || + ($print_type eq 'all_problems_students') || + ($print_type eq 'incomplete_problems_selpeople_course') || + ($print_type eq 'map_incomplete_problems_people_seq') || + ($print_type eq 'select_sequences_problems_for_students')) { $selectionmade=5; $type='problems'; - } elsif ($helper->{'VARS'}->{'PRINT_TYPE'} eq 'resources_for_students') { + } elsif (($print_type eq 'resources_for_students') || + ($print_type eq 'select_sequences_resources_for_students')) { $selectionmade=8; $type='resources'; } @@ -2493,13 +3304,15 @@ ENDPART # to override this and output the students by name. # Each element of the students array is of the form: # username:domain:section:last, first:status - # - # Note that student sort is not compatible with printing + # + # Note that student sort is not compatible with printing # 1 section per pdf...so that setting overrides. - # - if (($helper->{'VARS'}->{'student_sort'} eq 1) && + # + if (($helper->{'VARS'}->{'student_sort'} eq 1) && ($helper->{'VARS'}->{'SPLIT_PDFS'} ne "sections")) { @students = sort compare_names @students; + } else { + @students = sort compare_sections @students; } &adjust_number_to_print($helper); @@ -2507,8 +3320,8 @@ ENDPART $helper->{'VARS'}->{'NUMBER_TO_PRINT'} eq 'all' ) { $helper->{'VARS'}->{'NUMBER_TO_PRINT'}=$#students+1; } - # If we are splitting on section boundaries, we need - # to remember that in split_on_sections and + # If we are splitting on section boundaries, we need + # to remember that in split_on_sections and # print all of the students in the list. # my $split_on_sections = 0; @@ -2518,6 +3331,18 @@ ENDPART } my @master_seq=split /\|\|\|/, $helper->{'VARS'}->{'RESOURCES'}; + my $map; + if ($helper->{VARS}->{'symb'}) { + unless ((($print_type eq 'all_problems_students') || + ($print_type eq 'incomplete_problems_selpeople_course')) && + $perm{'pfo'}) { + ($map, my $id, my $resource) = + &Apache::lonnet::decode_symb($helper->{VARS}->{'symb'}); + } + } elsif (($helper->{'VARS'}->{'postdata'} eq '/adm/navmaps') && ($perm{'pfo'})) { + $map = $helper->{'VARS'}->{'SEQUENCE'}; + } + #loop over students my $flag_latex_header_remove = 'NO'; @@ -2532,12 +3357,15 @@ ENDPART ($helper->{'VARS'}->{'PRINT_ANNOTATIONS'} eq 'yes')) { $moreenv{'problem_split'}='yes'; } - my %prog_state=&Apache::lonhtmlcommon::Create_PrgWin($r,'Print Status','Class Print Status',$#students+1,'inline','75'); + my %prog_state=&Apache::lonhtmlcommon::Create_PrgWin($r,$#students+1); my $student_counter=-1; my $i = 0; my $last_section = (split(/:/,$students[0]))[2]; + my $nohidemap; + if ($perm{'pav'} && $perm{'vgr'}) { + $nohidemap = 1; + } foreach my $person (@students) { - my $duefile="/home/httpd/prtspool/$env{'user.name'}_$env{'user.domain'}_printout.due"; if (-e $duefile) { my $temp_file = Apache::File->new('>>'.$duefile); @@ -2553,23 +3381,32 @@ ENDPART } else { $i=int($student_counter/$helper->{'VARS'}{'NUMBER_TO_PRINT'}); } + my $actual_seq = master_seq_to_person_seq($map, \@master_seq, + $person, undef, $nohidemap); my ($output,$fullname, $printed)=&print_resources($r,$helper, $person,$type, - \%moreenv,\@master_seq, + \%moreenv, $actual_seq, $flag_latex_header_remove, $LaTeXwidth); $resources_printed .= ":"; $print_array[$i].=$output; $student_names[$i].=$person.':'.$fullname.'_END_'; - &Apache::lonhtmlcommon::Increment_PrgWin($r,\%prog_state,&mt('last student').' '.$fullname); +# &Apache::lonhtmlcommon::Increment_PrgWin($r,\%prog_state,&mt('last student').' '.$fullname); + &Apache::lonhtmlcommon::Increment_PrgWin($r,\%prog_state,'last student'); $flag_latex_header_remove = 'YES'; + if ($printed) { + $lastprinted = $fullname; + } if (&Apache::loncommon::connection_aborted($r)) { last; } } &Apache::lonhtmlcommon::Close_PrgWin($r,\%prog_state); $result .= $print_array[0].' \end{document}'; - } elsif (($helper->{'VARS'}->{'PRINT_TYPE'} eq 'problems_for_anon') || - ($helper->{'VARS'}->{'PRINT_TYPE'} eq 'problems_for_anon_page') || - ($helper->{'VARS'}->{'PRINT_TYPE'} eq 'resources_for_anon') ) { + } elsif (($print_type eq 'problems_for_anon') || + ($print_type eq 'problems_for_anon_page') || + ($print_type eq 'resources_for_anon') || + ($print_type eq 'select_sequences_problems_for_anon') || + ($print_type eq 'select_sequences_resources_for_anon')) { + $selectionmade = 9; my $cdom =$env{'course.'.$env{'request.course.id'}.'.domain'}; my $cnum =$env{'course.'.$env{'request.course.id'}.'.num'}; my $num_todo=$helper->{'VARS'}->{'NUMBER_TO_PRINT_TOTAL'}; @@ -2577,20 +3414,34 @@ ENDPART my $old_name=$helper->{'VARS'}->{'REUSE_OLD_CODES'}; my $single_code = $helper->{'VARS'}->{'SINGLE_CODE'}; my $selected_code = $helper->{'VARS'}->{'CODE_SELECTED_FROM_LIST'}; - my $code_option=$helper->{'VARS'}->{'CODE_OPTION'}; - my @lines = &Apache::grades::get_scantronformat_file(); - my ($code_type,$code_length)=('letter',6); + my @lines = &Apache::lonnet::get_scantronformat_file(); + my ($code_type,$code_length,$bubbles_per_row)=('letter',6,10); foreach my $line (@lines) { - my ($name,$type,$length) = (split(/:/,$line))[0,2,4]; + next if (($line =~ /^\#/) || ($line eq '')); + my ($name,$type,$length,$bubbles_per_item) = + (split(/:/,$line))[0,2,4,17]; if ($name eq $code_option) { $code_length=$length; if ($type eq 'number') { $code_type = 'number'; } + chomp($bubbles_per_item); + if (($bubbles_per_item ne '') && ($bubbles_per_item > 0)) { + $bubbles_per_row = $bubbles_per_item; + } } } + my $map; + if ($helper->{VARS}{'symb'}) { + ($map, my $id, my $resource) = + &Apache::lonnet::decode_symb($helper->{VARS}{'symb'}); + } elsif (($helper->{'VARS'}->{'postdata'} eq '/adm/navmaps') && ($perm{'pfo'})) { + $map = $helper->{'VARS'}->{'SEQUENCE'}; + } my %moreenv = ('textwidth' => &get_textwidth($helper,$LaTeXwidth)); $moreenv{'problem_split'} = $parmhash{'problem_stream_switch'}; + $moreenv{'suppress_tries'} = $parmhash{'suppress_tries'}; $moreenv{'instructor_comments'}='hide'; + $moreenv{'bubbles_per_row'} = $bubbles_per_row; my $seed=time+($$<<16)+($$); my @allcodes; if ($old_name) { @@ -2620,6 +3471,8 @@ ENDPART $moreenv{'CODE'}=&get_CODE(\%allcodes,$i,$seed,$code_length, $code_type); } + $code_name =~ s/^\s+//; + $code_name =~ s/\s+$//; if ($code_name) { &Apache::lonnet::put('CODEs', { @@ -2631,25 +3484,35 @@ ENDPART @allcodes=keys(%allcodes); } my @master_seq=split /\|\|\|/, $helper->{'VARS'}->{'RESOURCES'}; - my ($type) = split(/_/,$helper->{'VARS'}->{'PRINT_TYPE'}); + my ($type) = split(/_/,$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; + if ($number_per_page eq '0' || $number_per_page eq 'all' + || $number_per_page eq 'section') { + $number_per_page=$num_todo > 0 ? $num_todo : 1; } - my $flag_latex_header_remove = 'NO'; - my %prog_state=&Apache::lonhtmlcommon::Create_PrgWin($r,'Print Status','Class Print Status',$num_todo,'inline','75'); + my $flag_latex_header_remove = 'NO'; + my %prog_state=&Apache::lonhtmlcommon::Create_PrgWin($r,$num_todo); my $count=0; + my $nohidemap; + if ($perm{'pav'} && $perm{'vgr'}) { + $nohidemap = 1; + } foreach my $code (sort(@allcodes)) { my $file_num=int($count/$number_per_page); - if ($code_type eq 'number') { + if ($code_type eq 'number') { $moreenv{'CODE'}=$code; } else { $moreenv{'CODE'}=&num_to_letters($code); } + $env{'form.CODE'} = $moreenv{'CODE'}; + my $actual_seq = master_seq_to_person_seq($map, \@master_seq, + undef, + $moreenv{'CODE'}, $nohidemap); + delete($env{'form.CODE'}); my ($output,$fullname, $printed)= &print_resources($r,$helper,'anonymous',$type,\%moreenv, - \@master_seq,$flag_latex_header_remove, + $actual_seq,$flag_latex_header_remove, $LaTeXwidth); $resources_printed .= ":"; $print_array[$file_num].=$output; @@ -2657,16 +3520,19 @@ ENDPART &mt('last assignment').' '.$fullname); $flag_latex_header_remove = 'YES'; $count++; + if ($printed) { + $lastprinted = $fullname; + } if (&Apache::loncommon::connection_aborted($r)) { last; } } &Apache::lonhtmlcommon::Close_PrgWin($r,\%prog_state); $result .= $print_array[0].' \end{document}'; - } elsif ($helper->{'VARS'}->{'PRINT_TYPE'} eq 'problems_from_directory') { - #prints selected problems from the subdirectory + } elsif ($print_type eq 'problems_from_directory') { + #prints selected problems from the subdirectory $selectionmade = 6; my @list_of_files=split /\|\|\|/, $helper->{'VARS'}->{'FILES'}; @list_of_files=sort @list_of_files; - my $flag_latex_header_remove = 'NO'; + my $flag_latex_header_remove = 'NO'; my $rndseed=time; if ($helper->{'VARS'}->{'curseed'}) { $rndseed=$helper->{'VARS'}->{'curseed'}; @@ -2680,11 +3546,7 @@ ENDPART if ($urlp=~/\//) { $form{'problem_split'}=$parmhash{'problem_stream_switch'}; $form{'rndseed'}=$rndseed; - if ($urlp =~ m|/home/([^/]+)/public_html|) { - $urlp =~ s|/home/([^/]*)/public_html|/~$1|; - } else { - $urlp =~ s|^$Apache::lonnet::perlvar{'lonDocRoot'}||; - } + $urlp =~ s|^$Apache::lonnet::perlvar{'lonDocRoot'}||; $resources_printed .= $urlp.':'; my $texversion=&ssi_with_retries($urlp, $ssi_retry_count, %form); if(($helper->{'VARS'}->{'ANSWER_TYPE'} eq 'no') || @@ -2698,42 +3560,39 @@ ENDPART $resources_printed .= $urlp.':'; my $answer=&ssi_with_retries($urlp, $ssi_retry_count, %answerform); if ($helper->{'VARS'}->{'ANSWER_TYPE'} eq 'no') { - $texversion=~s/(\\keephidden{ENDOFPROBLEM})/$answer$1/; + $texversion=~s/(\\keephidden\{ENDOFPROBLEM})/$answer$1/; } else { $texversion=&print_latex_header($helper->{'VARS'}->{'LATEX_TYPE'}); if ($helper->{'VARS'}->{'construction'} ne '1') { $texversion.='\vskip 0 mm \noindent '; $texversion.=&path_to_problem ($urlp,$LaTeXwidth); } else { - $texversion.='\vskip 0 mm \noindent\textbf{Prints from construction space - there is no title.}\vskip 0 mm '; - my $URLpath=$urlp; - $URLpath=~s/~([^\/]+)/public_html\/$1\/$1/; - $texversion.=&path_to_problem ($URLpath,$LaTeXwidth); + $texversion.='\vskip 0 mm \noindent\textbf{'. + &mt("Printing from Authoring Space: No Title").'}\vskip 0 mm '; + $texversion.=&path_to_problem ($urlp,$LaTeXwidth); } $texversion.='\vskip 1 mm '.$answer.'\end{document}'; } } #this chunk is responsible for printing the path to problem - my $newurlp=$urlp; - if ($newurlp=~/~/) {$newurlp=~s|\/~([^\/]+)\/|\/home\/$1\/public_html\/|;} - $newurlp=&path_to_problem($newurlp,$LaTeXwidth); - $texversion =~ s/(\\begin{minipage}{\\textwidth})/$1 $newurlp/; + my $newurlp=&path_to_problem($urlp,$LaTeXwidth); + $texversion =~ s/(\\begin\{minipage}\{\\textwidth})/$1 $newurlp/; if ($flag_latex_header_remove ne 'NO') { $texversion = &latex_header_footer_remove($texversion); } else { - $texversion =~ s/\\end{document}//; + $texversion =~ s/\\end\{document}//; } if ($helper->{'VARS'}->{'TABLE_INDEX'} eq 'yes') { $texversion=&IndexCreation($texversion,$urlp); } if ($helper->{'VARS'}->{'CONSTR_RESOURSE_URL'} eq 'yes') { $texversion=~s/(\\addcontentsline\{toc\}\{subsection\}\{[^\}]*\})/$1 URL: \\verb|$urlp| \\strut\\\\\\strut /; - + } $result .= $texversion; } - $flag_latex_header_remove = 'YES'; + $flag_latex_header_remove = 'YES'; } if ($helper->{VARS}->{'construction'} eq '1') {$result=~s/(\\typeout)/ RANDOM SEED IS $rndseed $1/;} $result .= '\end{document}'; @@ -2743,7 +3602,18 @@ ENDPART # Only post process if that has not been turned off e.g. by a raw latex resource. if ($do_postprocessing) { - $result = &page_format_transformation($papersize,$laystyle,$numberofcolumns,$helper->{'VARS'}->{'PRINT_TYPE'},$result,$helper->{VARS}->{'assignment'},$helper->{'VARS'}->{'TABLE_CONTENTS'},$helper->{'VARS'}->{'TABLE_INDEX'},$selectionmade); + my $mostrecent; + if ((($selectionmade == 5) || ($selectionmade == 8) || ($selectionmade == 9)) && + (($numberofcolumns == 1) || ($laystyle eq 'album' && $papersize eq 'a4'))) { + $mostrecent = $lastprinted; + } + $result = &page_format_transformation($papersize, + $laystyle,$numberofcolumns, + $print_type,$result, + $helper->{VARS}->{'assignment'}, + $helper->{'VARS'}->{'TABLE_CONTENTS'}, + $helper->{'VARS'}->{'TABLE_INDEX'}, + $selectionmade,$mostrecent); $result = &latex_corrections($number_of_columns,$result,$selectionmade, $helper->{'VARS'}->{'ANSWER_TYPE'}); #if ($numberofcolumns == 1) { @@ -2754,18 +3624,51 @@ ENDPART #} } - # Set URLback if this is a construction space print so we can provide - # a link to the resource being edited. - # + # Set URLback so we can provide a link back to the resource and to change options. + # (Since the browser back button does not currently work with https, + # the back link is useful even when there is an easy-to-miss LON-CAPA back button.) my $URLback=''; #link to original document if ($helper->{'VARS'}->{'construction'} eq '1') { - #prints resource from the construction space - $URLback='/'.$helper->{'VARS'}->{'filename'}; - if ($URLback=~/([^?]+)/) { - $URLback=$1; - $URLback=~s|^/~|/priv/|; - } + $URLback=$helper->{'VARS'}->{'filename'}; + } elsif ($helper->{VARS}{'symb'}) { + my ($map, $id, $url) = &Apache::lonnet::decode_symb($helper->{VARS}{'symb'}); + my $cdom =$env{'course.'.$env{'request.course.id'}.'.domain'}; + my $cnum =$env{'course.'.$env{'request.course.id'}.'.num'}; + my ($anchor,$usehttp,$plainurl); + $url = &Apache::lonnet::clutter($url); + $plainurl = $url; + if (($ENV{'SERVER_PORT'} == 443) && ($env{'request.course.id'}) && + (($url =~ m{^\Q/public/$cdom/$cnum/syllabus\E($|\?)}) || + ($url =~ m{^\Q/adm/wrapper/ext/\E(?!https:)}))) { + unless ((&Apache::lonnet::uses_sts()) || (&Apache::lonnet::waf_allssl())) { + $usehttp = 1; + } + } + if ($env{'request.enc'}) { + $url = &Apache::lonenc::encrypted($url); + } + if ($url ne '') { + my $symb = $helper->{VARS}{'symb'}; + if ($url =~ m{^\Q/adm/wrapper/ext/\E}) { + my $link = $url; + ($link,$anchor) = ($url =~ /^([^\#]+)(?:|(\#[^\#]+))$/); + if ($anchor) { + ($symb) = ($helper->{VARS}{'symb'} =~ /^([^\#]+)/); + } + $url = $link; + } + $URLback = $url; + if ($usehttp) { + $URLback .= (($URLback =~ /\?/) ? '&':'?').'usehttp=1'; + } + unless ($plainurl =~ /\.page$/) { + $URLback .= (($URLback =~ /\?/) ? '&':'?').'symb='.&escape($symb.$anchor); + } + } + } elsif (($helper->{VARS}->{'postdata'} eq '/adm/navmaps') && + ($env{'request.course.id'})) { + $URLback=$helper->{VARS}->{'postdata'}; } # # Final adjustment of the font size: @@ -2773,18 +3676,23 @@ ENDPART $result = set_font_size($result); -#-- writing .tex file in prtspool + # Insert any babel headers required. + + $result = &collect_languages($result); + + +#-- writing .tex file in prtspool my $temp_file; 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)) { + if (!($#print_array>0)) { unless ($temp_file = Apache::File->new('>'.$filename)) { $r->log_error("Couldn't open $filename for output $!"); - return SERVER_ERROR; + return SERVER_ERROR; } print $temp_file $result; my $begin=index($result,'\begin{document}',0); - my $inc=substr($result,0,$begin+16); + my $inc=substr($result,0,$begin+16); } else { my $begin=index($result,'\begin{document}',0); my $inc=substr($result,0,$begin+16); @@ -2793,11 +3701,11 @@ ENDPART $print_array[$i]=$result; } else { $print_array[$i].='\end{document}'; - $print_array[$i] = + $print_array[$i] = &latex_corrections($number_of_columns,$print_array[$i], - $selectionmade, + $selectionmade, $helper->{'VARS'}->{'ANSWER_TYPE'}); - + my $anobegin=index($print_array[$i],'\setcounter{page}',0); substr($print_array[$i],0,$anobegin)=''; $print_array[$i]=$inc.$print_array[$i]; @@ -2805,11 +3713,11 @@ ENDPART my $temp_file; my $newfilename=$filename; my $num=$i+1; - $newfilename =~s/\.tex$//; + $newfilename =~s/\.tex$//; $newfilename=sprintf("%s_%03d.tex",$newfilename, $num); unless ($temp_file = Apache::File->new('>'.$newfilename)) { $r->log_error("Couldn't open $newfilename for output $!"); - return SERVER_ERROR; + return SERVER_ERROR; } print $temp_file $print_array[$i]; } @@ -2844,11 +3752,11 @@ ENDPART 'cgi.'.$identifier.'.role' => $perm{'pav'}, 'cgi.'.$identifier.'.numberoffiles' => $#print_array, 'cgi.'.$identifier.'.studentnames' => $student_names, - 'cgi.'.$identifier.'.backref' => $URLback,}); + 'cgi.'.$identifier.'.backref' => &escape($URLback),}); &Apache::lonnet::appenv({"cgi.$identifier.user" => $env{'user.name'}, "cgi.$identifier.domain" => $env{'user.domain'}, - "cgi.$identifier.courseid" => $cnum, - "cgi.$identifier.coursedom" => $cdom, + "cgi.$identifier.courseid" => $cnum, + "cgi.$identifier.coursedom" => $cdom, "cgi.$identifier.resources" => $resources_printed}); my $end_page = &Apache::loncommon::end_page(); @@ -2895,36 +3803,56 @@ sub get_CODE { sub print_resources { my ($r,$helper,$person,$type,$moreenv,$master_seq,$remove_latex_header, $LaTeXwidth)=@_; - my $current_output = ''; + my $current_output = ''; my $printed = ''; my ($username,$userdomain,$usersection) = split /:/,$person; my $fullname = &get_name($username,$userdomain); my $namepostfix = "\\\\"; # Both anon and not anon should get the same vspace. - if ($person =~ 'anon') { - $namepostfix .="Name: "; + + + # + # Figure out if we need to filter the output by + # the incomplete problems for that person + # + my $print_type = $helper->{'VARS'}->{'PRINT_TYPE'}; + my $print_incomplete = 0; + if (($print_type eq 'map_incomplete_problems_people_seq') || + ($print_type eq 'incomplete_problems_selpeople_course')) { + $print_incomplete = 1; + } + if ($person eq 'anonymous') { + $namepostfix .=&mt('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 + my $actually_printed = 0; # Count of resources printed. + #goes through all resources, checks if they are available for + #current student, and produces output &Apache::lonxml::clear_problem_counter(); my %page_breaks = &get_page_breaks($helper); my $columns_in_format = (split(/\|/,$helper->{'VARS'}->{'FORMAT'}))[1]; # - # end each student with a + # 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 + # so we will just rely on printout.pl to strip ENDOFSTUDENTSTAMP from the # postscript. Each ENDOFSTUDENTSTAMP will go on a line by itself. # + my $syllabus_first = 0; + my $current_assignment = ""; + my $assignment; + my $courseidinfo = &get_course(); + my $possprint = scalar(@{$master_seq}); + foreach my $curresline (@{$master_seq}) { if (defined $page_breaks{$curresline}) { if($i != 0) { @@ -2933,22 +3861,44 @@ sub print_resources { } $current_output .= &get_extra_vspaces($helper, $curresline); $i++; + my ($map,$id,$res_url) = &Apache::lonnet::decode_symb($curresline); + + # See if we need to emit a new header: + + if ( !($type eq 'problems' && + ($curresline!~ m/$LONCAPA::assess_page_re/)) ) { + if ($print_incomplete && !&incomplete($username, $userdomain, $res_url)) { + next; + } + $actually_printed++; # we're going to print one. - if ( !($type eq 'problems' && - ($curresline!~ m/\.(problem|exam|quiz|assess|survey|form|library)$/)) ) { - my ($map,$id,$res_url) = &Apache::lonnet::decode_symb($curresline); if (&Apache::lonnet::allowed('bre',$res_url)) { if ($res_url!~m|^ext/| && $res_url=~/\.(problem|exam|quiz|assess|survey|form|library|page|xml|html|htm|xhtml|xhtm)$/) { $printed .= $curresline.':'; - &Apache::lonxml::remember_problem_counter(); + &Apache::lonxml::remember_problem_counter(); my $rendered = &get_student_view_with_retries($curresline,$ssi_retry_count,$username,$userdomain,$env{'request.course.id'},'tex',$moreenv); + if ($res_url =~ /\.page$/) { + if ($remove_latex_header eq 'NO') { + if (!($rendered =~ /\\begin\{document\}/)) { + $rendered = &print_latex_header().$rendered; + } + } +; + if ($remove_latex_header eq 'YES') { + $rendered = &latex_header_footer_remove($rendered); + } else { + $rendered =~ s/\\end\{document}\d*//; + } + } if(($helper->{'VARS'}->{'ANSWER_TYPE'} eq 'no') || ($helper->{'VARS'}->{'ANSWER_TYPE'} eq 'only')) { # Use a copy of the hash so we don't pervert it on future loop passes. my %answerenv = %{$moreenv}; $answerenv{'answer_output_mode'}='tex'; + + $answerenv{'latex_type'}=$helper->{'VARS'}->{'LATEX_TYPE'}; &Apache::lonxml::restore_problem_counter(); @@ -2956,34 +3906,34 @@ sub print_resources { my $ansrendered = &Apache::loncommon::get_student_answers($curresline,$username,$userdomain,$env{'request.course.id'},%answerenv); if ($helper->{'VARS'}->{'ANSWER_TYPE'} eq 'no') { - $rendered=~s/(\\keephidden{ENDOFPROBLEM})/$ansrendered$1/; + $rendered=~s/(\\keephidden\{ENDOFPROBLEM})/$ansrendered$1/; } else { - - my $header =&print_latex_header($helper->{'VARS'}->{'LATEX_TYPE'}); - $header =~ s/\\begin{document}//; #<<<<< + unless ($helper->{'VARS'}->{'ANSWER_TYPE'} eq 'only') { + $header =~ s/\\begin\{document}//; #<<<<< + } my $title = &Apache::lonnet::gettitle($curresline); $title = &Apache::lonxml::latex_special_symbols($title); my $body ='\vskip 0 mm \noindent\textbf{'.$title.'}\vskip 0 mm '; $body .=&path_to_problem($res_url,$LaTeXwidth); $body .='\vskip 1 mm '.$ansrendered; - $body = &encapsulate_minipage($body); + $body = &encapsulate_minipage($body,$answerenv{'problem_split'}); $rendered = $header.$body; } } if ($helper->{'VARS'}->{'PRINT_ANNOTATIONS'} eq 'yes') { my $url = &Apache::lonnet::clutter($res_url); my $annotation = &annotate($url); - $rendered =~ s/(\\keephidden{ENDOFPROBLEM})/$annotation$1/; + $rendered =~ s/(\\keephidden\{ENDOFPROBLEM})/$annotation$1/; } my $junk; if ($remove_latex_header eq 'YES') { $rendered = &latex_header_footer_remove($rendered); } else { - $rendered =~ s/\\end{document}//; + $rendered =~ s/\\end\{document}//; } - $current_output .= $rendered; - } elsif ($res_url=~/\/(smppg|syllabus|aboutme|bulletinboard)$/) { + $current_output .= $rendered; + } elsif ($res_url=~/\/(smppg|syllabus|aboutme|bulletinboard|ext\.tool)$/) { if ($i == 1) { $syllabus_first = 1; } @@ -2992,15 +3942,15 @@ sub print_resources { if ($helper->{'VARS'}->{'PRINT_ANNOTATIONS'} eq 'yes') { my $url = &Apache::lonnet::clutter($res_url); my $annotation = &annotate($url); - $annotation =~ s/(\\end{document})/$annotation$1/; + $annotation =~ s/(\\end\{document})/$annotation$1/; } if ($remove_latex_header eq 'YES') { $rendered = &latex_header_footer_remove($rendered); } else { - $rendered =~ s/\\end{document}//; + $rendered =~ s/\\end\{document}//; } $current_output .= $rendered.'\vskip 0.5mm\noindent\makebox[\textwidth/$number_of_columns][b]{\hrulefill}\strut \vskip 0 mm \strut '; - } elsif($res_url = ~/\.pdf$/) { + } elsif($res_url =~ /\.pdf$/) { my $url = &Apache::lonnet::clutter($res_url); my $rendered = &include_pdf($url); if ($remove_latex_header ne 'NO') { @@ -3012,38 +3962,81 @@ sub print_resources { if ($remove_latex_header ne 'NO') { $rendered = &latex_header_footer_remove($rendered); } else { - $rendered =~ s/\\end{document}//; + $rendered =~ s/\\end\{document}//; } $current_output .= $rendered; } } $remove_latex_header = 'YES'; - } + } + $assignment = &Apache::lonxml::latex_special_symbols( + &Apache::lonnet::gettitle($map), 'header'); + if (($assignment ne $current_assignment) && ($assignment ne "")) { + my $header_line = &format_page_header($LaTeXwidth, $parmhash{'print_header_format'}, + $assignment, $courseidinfo, + $fullname, $usersection); + my $header_start = ($columns_in_format == 1) ? '\lhead' + : '\fancyhead[LO]'; + $header_line = $header_start.'{'.$header_line.'}'; + $current_output = $current_output . $header_line; + $current_assignment = $assignment; + } + if (&Apache::loncommon::connection_aborted($r)) { last; } } + # If we are printing incomplete it's possible we don't have + # anything to print. The print subsystem is not so good at handling + # that so we're going to generate a stub that says there are no + # incomplete resources for the person. + # + if ($actually_printed == 0) { + my $message = &mt('No resources to print'); + if (!$possprint) { + if ($perm{'pav'} || $perm{'pfo'}) { + $message = &mt('There are no unhidden resources to print.')."\n\n". + &mt('The most likely reason is one of the following: ')."\n". + '\begin{itemize}'."\n". + '\item '.&mt("The 'Resource hidden from students' parameter is set for the folder being printed.")."\n". + '\item '.&mt("'Hidden' is checked in the Course Editor individually for each resource in the folder being printed.")."\n". + '\end{itemize}'."\n\n". + &mt("Note: to print a bubblesheet exam which you want to hide from students, ". + "use the Course Editor to check the 'Hidden' checkbox for the exam folder itself.")."\n"; + } + } elsif ($print_incomplete) { + $message = &mt('No incomplete resources'); + } + if ($message) { + $current_output = &encapsulate_minipage("\\vskip -10mm \n$message\n \\vskip 100 mm { }\n",$moreenv->{'problem_split'}); + } + if ($remove_latex_header eq "NO") { + $current_output = &print_latex_header() . $current_output; + } else { + $current_output = &latex_header_footer_remove($current_output); + } + } - my $courseidinfo = &get_course(); + if ($syllabus_first) { + $current_output =~ s/\\\\ Last updated:/Last updated:/ + } my $currentassignment=&Apache::lonxml::latex_special_symbols($helper->{VARS}->{'assignment'},'header'); my $header_line = - &format_page_header($LaTeXwidth, $parmhash{'print_header_format'}, - $currentassignment, $courseidinfo, $fullname, $usersection); - my $header_start = ($columns_in_format == 1) ? '\lhead' - : '\fancyhead[LO]'; - $header_line = $header_start.'{'.$header_line.'}'; - if ($current_output=~/\\documentclass/ && (!$syllabus_first)) { - $current_output =~ s/\\begin{document}/\\setlength{\\topmargin}{1cm} \\begin{document}\\noindent\\parbox{\\minipagewidth}{\\noindent$header_line$namepostfix}\\vskip 5 mm /; - } elsif ($syllabus_first) { + &format_page_header($LaTeXwidth, $parmhash{'print_header_format'}, + $currentassignment, $courseidinfo, $fullname, $usersection); + my $header_start = ($columns_in_format == 1) ? '\lhead' : '\fancyhead[LO]'; + my $newheader = $header_start.'{'.$header_line.'}'; + if ($current_output=~/\\documentclass/) { + $current_output =~ s/\\begin\{document}/\\setlength{\\topmargin}{1cm} \\begin{document}\\noindent\\parbox{\\minipagewidth}{\\noindent$newheader$namepostfix}\\vskip 5 mm /; - $current_output =~ s/\\\\ Last updated:/Last updated:/ } else { - my $blankpages = + my $blankpages = '\clearpage\strut\clearpage'x$helper->{'VARS'}->{'EMPTY_PAGES'}; - + $current_output = '\strut\vspace*{-6 mm}\\newline'. ©right_line().' \newpage '.$blankpages.$end_of_student. '\setcounter{page}{1}\noindent\parbox{\minipagewidth}{\noindent'. - $header_line.$namepostfix.'} \vskip 5 mm '.$current_output; + $newheader.$namepostfix. '} \vskip 5 mm '.$current_output; + } # # Close the student bracketing. @@ -3052,24 +4045,54 @@ sub print_resources { } +sub printing_blocked { + my ($r,$blocktext) = @_; + my $title = &mt('Preparing Printout'); + &Apache::lonhtmlcommon::clear_breadcrumbs(); + &Apache::lonhtmlcommon::add_breadcrumb({href=>'/adm/printout', + text=> $title}); + my $breadcrumbs = &Apache::lonhtmlcommon::breadcrumbs($title); + &Apache::loncommon::content_type($r,'text/html'); + &Apache::loncommon::no_cache($r); + $r->send_http_header; + $r->print(&Apache::loncommon::start_page('Preparing Printout'). + $breadcrumbs. + $blocktext. + &Apache::loncommon::end_page()); + return; +} + sub handler { my $r = shift; - - &init_perm(); - + if ($env{'request.course.id'}) { + my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'}; + my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'}; + my $clientip = &Apache::lonnet::get_requestor_ip($r); + my ($blocked,$blocktext) = + &Apache::loncommon::blocking_status('printout',$clientip,$cnum,$cdom); + if ($blocked) { + my $checkrole = "cm./$cdom/$cnum"; + if ($env{'request.course.sec'} ne '') { + $checkrole .= "/$env{'request.course.sec'}"; + } + unless ((&Apache::lonnet::allowed('evb',undef,undef,$checkrole)) && + ($env{'request.role'} !~ m{^st\./$cdom/$cnum})) { + &printing_blocked($r,$blocktext); + return OK; + } + } + } + &init_perm(); my $helper = printHelper($r); if (!ref($helper)) { return $helper; } - - - %parmhash=&Apache::lonnet::coursedescription($env{'request.course.id'}); - + %parmhash=&Apache::lonnet::coursedescription($env{'request.course.id'}); # If a figure conversion queue file exists for this user.domain # we delete it since it can only be bad (if it were good, printout.pl @@ -3079,11 +4102,10 @@ sub handler { if(-e $conversion_queuefile) { unlink $conversion_queuefile; } - &output_data($r,$helper,\%parmhash); return OK; -} +} use Apache::lonhelper; @@ -3108,6 +4130,11 @@ sub init_perm { $perm{'pfo'}=&Apache::lonnet::allowed('pfo', $env{'request.course.id'}.'/'.$env{'request.course.sec'}); } + $perm{'vgr'}=&Apache::lonnet::allowed('vgr',$env{'request.course.id'}); + if (!$perm{'vgr'}) { + $perm{'vgr'}=&Apache::lonnet::allowed('vgr', + $env{'request.course.id'}.'/'.$env{'request.course.sec'}); + } } sub get_randomly_ordered_warning { @@ -3120,18 +4147,13 @@ sub get_randomly_ordered_warning { if (defined($navmap)) { my $res = $navmap->getResourceByUrl($map); if ($res) { - my $func = + my $func = sub { return ($_[0]->is_map() && $_[0]->randomorder); }; my @matches = $navmap->retrieveResources($res, $func,1,1,1); - if (@matches) { - $message = "Some of the items below are in folders set to be randomly ordered. However, when printing the contents of these folders, they will be printed in the original order for all students, not the randomized order."; - } - } - if ($message) { - return ''.$message.''; + } } else { - $message = "Retrieval of information about ordering of resources failed."; + $message = "Retrieval of information about ordering of resources failed."; return ''.$message.''; } return; @@ -3164,12 +4186,12 @@ sub printHelper { # write it by hand Apache::loncommon::get_unprocessed_cgi($ENV{QUERY_STRING}); - + my $helper = Apache::lonhelper::helper->new("Printing Helper"); $helper->declareVar('symb'); - $helper->declareVar('postdata'); - $helper->declareVar('curseed'); - $helper->declareVar('probstatus'); + $helper->declareVar('postdata'); + $helper->declareVar('curseed'); + $helper->declareVar('probstatus'); $helper->declareVar('filename'); $helper->declareVar('construction'); $helper->declareVar('assignment'); @@ -3181,7 +4203,7 @@ sub printHelper { $helper->declareVar("STUDENTS"); $helper->declareVar("EXTRASPACE"); - + # The page breaks and extra spaces @@ -3189,19 +4211,19 @@ sub printHelper { # But we only do this in the initial state so that they are allowed to change. # - + &Apache::loncommon::restore_course_settings('print', {'pagebreaks' => 'scalar', 'extraspace' => 'scalar', 'extraspace_units' => 'scalar', 'lastprinttype' => 'scalar'}); - + # This will persistently load in the data we want from the # very first screen. - + if($helper->{VARS}->{PRINT_TYPE} eq $env{'form.lastprinttype'}) { if (!defined ($env{"form.CURRENT_STATE"})) { - + $helper->{VARS}->{FINISHPAGE} = $env{'form.pagebreaks'}; $helper->{VARS}->{EXTRASPACE} = $env{'form.extraspace'}; $helper->{VARS}->{EXTRASPACE_UNITS} = $env{'form.extraspace_units'}; @@ -3218,12 +4240,14 @@ sub printHelper { } # Detect whether we're coming from construction space - if ($env{'form.postdata'}=~/^(?:http:\/\/[^\/]+\/|\/|)\~([^\/]+)\/(.*)$/) { - $helper->{VARS}->{'filename'} = "~$1/$2"; + if ($env{'form.postdata'}=~m{^/priv}) { + $helper->{VARS}->{'filename'} = $env{'form.postdata'}; $helper->{VARS}->{'construction'} = 1; } else { if ($env{'form.postdata'}) { - $helper->{VARS}->{'symb'} = &Apache::lonnet::symbread($env{'form.postdata'}); + unless ($env{'form.postdata'} eq '/adm/navmaps') { + $helper->{VARS}->{'symb'} = &Apache::lonnet::symbread($env{'form.postdata'}); + } if ( $helper->{VARS}->{'symb'} eq '') { $helper->{VARS}->{'postdata'} = $env{'form.postdata'}; } @@ -3232,33 +4256,62 @@ sub printHelper { $helper->{VARS}->{'symb'} = $env{'form.symb'}; } if ($env{'form.url'}) { - $helper->{VARS}->{'symb'} = &Apache::lonnet::symbread($helper->{VARS}->{'postdata'}); + unless ($env{'form.url'} eq '/adm/navmaps') { + $helper->{VARS}->{'symb'} = &Apache::lonnet::symbread($helper->{VARS}->{'postdata'}); + } } - - } - - if ($env{'form.symb'}) { - $helper->{VARS}->{'symb'} = $env{'form.symb'}; } - if ($env{'form.url'}) { - $helper->{VARS}->{'symb'} = &Apache::lonnet::symbread($helper->{VARS}->{'postdata'}); + if ($helper->{VARS}->{'symb'} ne '') { + $helper->{VARS}->{'symb'}= + &Apache::lonenc::check_encrypt($helper->{VARS}->{'symb'}); + } + my ($resourceTitle,$sequenceTitle,$mapTitle,$cdom,$cnum); + if ($helper->{VARS}->{'postdata'} eq '/adm/navmaps') { + $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'}; + $cnum = $env{'course.'.$env{'request.course.id'}.'.num'}; + if ($env{'course.'.$env{'request.course.id'}.'.url'} eq + "uploaded/$cdom/$cnum/default.sequence") { + my $navmap = Apache::lonnavmaps::navmap->new(); + if (ref($navmap)) { + my @toplevelres = $navmap->retrieveResources('',sub { !(($_[0]->is_map()) || ($_[0]->src =~ /^\/adm\/navmaps/)) },0,0); + if (@toplevelres) { + my @printable; + if ($perm{'pav'} || $perm{'pfo'}) { + @printable = @toplevelres; + } else { + @printable = $navmap->retrieveResources(undef,sub { $_[0]->resprintable() },0,1); + } + if (@printable) { + $sequenceTitle = 'Main Content'; + $mapTitle = $sequenceTitle; + } + } + } + } + } else { + ($resourceTitle,$sequenceTitle,$mapTitle) = &details_for_menu($helper); } - $helper->{VARS}->{'symb'}= - &Apache::lonenc::check_encrypt($helper->{VARS}->{'symb'}); - my ($resourceTitle,$sequenceTitle,$mapTitle) = &details_for_menu($helper); if ($sequenceTitle ne '') {$helper->{VARS}->{'assignment'}=$sequenceTitle;} - # Extract map my $symb = $helper->{VARS}->{'symb'}; my ($map, $id, $url); my $subdir; my $is_published=0; # True when printing from resource space. + my $res_printable = 1; # By default the current resource is printable. + my $res_error; + my $userCanPrint = ($perm{'pav'} || $perm{'pfo'}); + my $res_printstartdate; + my $res_printenddate; + my $map_open = 0; + my $map_close = 0xffffffff; + my $course_open = 0; + my $course_close = 0xffffffff; # Get the resource name from construction space if ($helper->{VARS}->{'construction'}) { - $resourceTitle = substr($helper->{VARS}->{'filename'}, + $resourceTitle = substr($helper->{VARS}->{'filename'}, rindex($helper->{VARS}->{'filename'}, '/')+1); $subdir = substr($helper->{VARS}->{'filename'}, 0, rindex($helper->{VARS}->{'filename'}, '/') + 1); @@ -3267,9 +4320,41 @@ sub printHelper { if ($symb ne '') { ($map, $id, $url) = &Apache::lonnet::decode_symb($symb); - $helper->{VARS}->{'postdata'} = + $helper->{VARS}->{'postdata'} = &Apache::lonenc::check_encrypt(&Apache::lonnet::clutter($url)); + } elsif (($helper->{VARS}->{'postdata'} eq '/adm/navmaps') && + ($env{'request.course.id'} ne '')) { + if ($env{'course.'.$env{'request.course.id'}.'.url'} eq + "uploaded/$cdom/$cnum/default.sequence") { + $map = $env{'course.'.$env{'request.course.id'}.'.url'}; + $url = $helper->{VARS}->{'postdata'}; + } + } + if (($symb ne '') || ($map ne '')) { + if (!$userCanPrint) { + my $navmap = Apache::lonnavmaps::navmap->new(); + if (ref($navmap)) { + my $res; + if ($symb ne '') { + $res = $navmap->getBySymb($symb); + } elsif ($map ne '') { + $res = $navmap->getResourceByUrl($map); + } + if (ref($res)) { + $res_printable = $res->resprintable(); #printability in course context + ($res_printstartdate, $res_printenddate) = &get_print_dates($res); + ($course_open, $course_close) = &course_print_dates($res); + ($map_open, $map_close) = &map_print_dates($res); + } else { + $res_error = 1; + } + } else { + $res_error = 1; + } + } } else { + # Resource space. + $url = $helper->{VARS}->{'postdata'}; $is_published=1; # From resource space. } @@ -3278,11 +4363,18 @@ sub printHelper { my $postdata = $helper->{VARS}->{'postdata'}; $resourceTitle = substr($postdata, rindex($postdata, '/') + 1); } - $subdir = &Apache::lonnet::filelocation("", $url); + if (($url eq '/adm/navmaps') && ($map eq $env{'course.'.$env{'request.course.id'}.'.url'})) { + $res_printable=0; + } else { + $subdir = &Apache::lonnet::filelocation("", $url); + } + + } if (!$helper->{VARS}->{'curseed'} && $env{'form.curseed'}) { $helper->{VARS}->{'curseed'}=$env{'form.curseed'}; } + if (!$helper->{VARS}->{'probstatus'} && $env{'form.problemtype'}) { $helper->{VARS}->{'probstatus'}=$env{'form.problemstatus'}; } @@ -3308,18 +4400,28 @@ sub printHelper { my $printChoices = []; my $paramHash; - if ($resourceTitle) { + # If there is a current resource and it is printable + # Give that as a choice. + + if ($resourceTitle && $res_printable) { push @{$printChoices}, ["$resourceTitle (".&mt('the resource you just saw on the screen').")", 'current_document', 'PAGESIZE']; } # Useful filter strings - my $isProblem = '($res->is_problem()||$res->contains_problem||$res->is_practice()) '; + + my $isPrintable = ' && $res->resprintable()'; + + my $isProblem = '(($res->is_problem()||$res->contains_problem() ||$res->is_practice()))'; + $isProblem .= $isPrintable unless $userCanPrint; $isProblem .= ' && !$res->randomout()' if !$userCanSeeHidden; - my $isProblemOrMap = '$res->is_problem() || $res->contains_problem() || $res->is_sequence() || $res->is_practice()'; - my $isNotMap = '!$res->is_sequence()'; + my $isProblemOrMap = '($res->is_problem() || $res->contains_problem() || $res->is_sequence() || $res->is_practice())'; + $isProblemOrMap .= $isPrintable unless $userCanPrint; + my $isNotMap = '(!$res->is_sequence())'; + $isNotMap .= $isPrintable unless $userCanPrint; $isNotMap .= ' && !$res->randomout()' if !$userCanSeeHidden; my $isMap = '$res->is_map()'; - my $symbFilter = '$res->shown_symb()'; + $isMap .= $isPrintable unless $userCanPrint; + my $symbFilter = '$res->shown_symb() '; my $urlValue = '$res->link()'; $helper->declareVar('SEQUENCE'); @@ -3328,18 +4430,16 @@ sub printHelper { my $start_new_option; if ($perm{'pav'}) { - $start_new_option = - "
Number of CODEd assignments to print: - + if (((\$helper->{'VARS'}{'NUMBER_TO_PRINT_TOTAL'}+0) < 1) && !\$helper->{'VARS'}{'REUSE_OLD_CODES'} && !\$helper->{'VARS'}{'SINGLE_CODE'} && - !\$helper->{'VARS'}{'CODE_SELECTED_FROM_LIST'}) { + !\$helper->{'VARS'}{'CODE_SELECTED_FROM_LIST'} ) { + return "You need to specify the number of assignments to print"; } + if (((\$helper->{'VARS'}{'NUMBER_TO_PRINT_TOTAL'}+0) >= 1) && + (\$helper->{'VARS'}{'SINGLE_CODE'} ne '') ) { + return 'Specifying number of codes to print and a specific code is not compatible'; + } return undef; @@ -212,7 +407,7 @@ sub generate_code_selector {
- Bubble sheet type: + Bubblesheet type: $bubble_types @@ -228,6 +423,8 @@ sub generate_code_selector { !\$helper->{'VARS'}{'CODE_SELECTED_FROM_LIST'}) { return &Apache::lonprintout::is_code_valid(\$helper->{'VARS'}{'SINGLE_CODE'}, \$helper->{'VARS'}{'CODE_OPTION'}); + } elsif (\$helper->{'VARS'}{'SINGLE_CODE'} ne ''){ + return 'Specifying a code name is incompatible with specifying number of codes.'; } else { return undef; # Other forces control us. } @@ -249,8 +446,477 @@ CHOOSE_ANON1 return $result; } +sub generate_common_choosers { + my ($r,$helper,$map,$url,$isProblem,$symbFilter,$start_new_option) = @_; + + my $randomly_ordered_warning = + &get_randomly_ordered_warning($helper, $map); + + # code for a few states used for printout launched from both + # /adm/navmaps and from a resource by a privileged user: + # - To allow resources to be selected for printing. + # - To determine pagination between assignments. + # - To determine how many assignments should be bundled into a single PDF. + + my $resource_selector= &generate_resource_chooser('SELECT_PROBLEMS', + 'Select resources to print', + 'multichoice="1" addstatus="1" closeallpages="1" modallink="1" suppressNavmap="1"', + 'RESOURCES', + 'PRINT_FORMATTING', + $map, + $isProblem, '', $symbFilter, + $start_new_option); + $resource_selector .= &generate_format_selector($helper, + 'How should results be printed?', + 'PRINT_FORMATTING'). + &generate_resource_chooser('CHOOSE_STUDENTS_PAGE', + 'Select Problem(s) to print', + "multichoice='1' addstatus='1' closeallpages ='1' modallink='1'", + 'RESOURCES', + 'PRINT_FORMATTING', + $url, + $isProblem, '', $symbFilter, + $start_new_option); + +# Generate student choosers. + + &Apache::lonxml::xmlparse($r, 'helper', + &generate_student_chooser('CHOOSE_TGT_STUDENTS_PAGE', + 'student_sort', + 'STUDENTS', + 'CHOOSE_STUDENTS_PAGE')); + &Apache::lonxml::xmlparse($r, 'helper', + &generate_student_chooser('CHOOSE_STUDENTS', + 'student_sort', + 'STUDENTS', + 'SELECT_PROBLEMS')); + &Apache::lonxml::xmlparse($r, 'helper', $resource_selector); + + my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'}; + my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'}; + my @names=&Apache::lonnet::getkeys('CODEs',$cdom,$cnum); + my $namechoice=''; + foreach my $name (sort {uc($a) cmp uc($b)} @names) { + if ($name =~ /^error: 2 /) { next; } + if ($name =~ /^type\0/) { next; } + $namechoice.=''.$name.''; + } + + my %code_values; + my %codes_to_print; + foreach my $key (@names) { + %code_values = &Apache::grades::get_codes($key, $cdom, $cnum); + foreach my $key (keys(%code_values)) { + $codes_to_print{$key} = 1; + } + } + + 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 + $choice = &letters_to_num($code); + } + push(@{$helper->{DATA}{ALL_CODE_CHOICES}},[$code,$choice]); + } + if (%codes_to_print) { + $code_selection .=' + Choose single CODE from list: + + + + + push(@{$state->{CHOICES}},@{$helper->{DATA}{ALL_CODE_CHOICES}}); + + +
+ '.$/; + } + + my @lines = &Apache::lonnet::get_scantronformat_file(); + my $codechoice=''; + foreach my $line (@lines) { + next if (($line =~ /^\#/) || ($line eq '')); + my ($name,$description,$code_type,$code_length)= + (split(/:/,$line))[0,1,2,4]; + if ($code_length > 0 && + $code_type =~/^(letter|number|-1)/) { + $codechoice.=''.$description.''; + } + } + if ($codechoice eq '') { + $codechoice='Default'; + } + my $anon1 = &generate_code_selector($helper, + 'CHOOSE_ANON1', + 'SELECT_PROBLEMS', + $codechoice, + $code_selection, + $namechoice) . $resource_selector; + + &Apache::lonxml::xmlparse($r, 'helper',$anon1); + + my $anon_page = &generate_code_selector($helper, + 'CHOOSE_ANON1_PAGE', + 'SELECT_PROBLEMS_PAGE', + $codechoice, + $code_selection, + $namechoice) . + &generate_resource_chooser('SELECT_PROBLEMS_PAGE', + 'Select Problem(s) to print', + "multichoice='1' addstatus='1' closeallpages ='1' modallink='1'", + 'RESOURCES', + 'PRINT_FORMATTING', + $url, + $isProblem, '', $symbFilter, + $start_new_option); + &Apache::lonxml::xmlparse($r, 'helper', $anon_page); + return ($randomly_ordered_warning,$codechoice,$code_selection,$namechoice); +} + +# Returns the XML for choosing how assignments are to be formatted +# that text must still be parsed by the helper xml parser. +# Parameters: 3 (required) + +# helper - The helper; $helper->{'VARS'}->{'PRINT_TYPE'} used +# to check if splitting PDFs by section can be offered. +# title - Title for the current state. +# this_state - State name of the chooser. + +sub generate_format_selector { + my ($helper,$title,$this_state) = @_; + my $secpdfoption; + unless (($helper->{'VARS'}->{'PRINT_TYPE'} eq 'problems_for_anon') || + ($helper->{'VARS'}->{'PRINT_TYPE'} eq 'problems_for_anon_page') || + ($helper->{'VARS'}->{'PRINT_TYPE'} eq 'resources_for_anon') || + ($helper->{'VARS'}->{'PRINT_TYPE'} eq 'select_sequences_problems_for_anon') || + ($helper->{'VARS'}->{'PRINT_TYPE'} eq 'select_sequences_resources_for_anon')) { + $secpdfoption = 'Each PDF contains exactly one section'; + } + return < +
How should the results be printed?
+ + Start each student\'s assignment on a new page/column (add a pagefeed after each assignment) + Add one empty page/column after each student\'s assignment + Add two empty pages/column after each student\'s assignment + Add three empty pages/column after each student\'s assignment + + PAGESIZE +
How do you want assignments split into PDF files?
+ + All assignments in a single PDF file + $secpdfoption + Each PDF contains exactly one assignment + + Specify the number of assignments per PDF: + + +RESOURCE_SELECTOR +} + #----------------------------------------------------------------------- +# Computes an open and close date from a list of open/close dates for a resource's +# parts. +# +# @param \@opens - reference to an array of open dates. +# @param \@closes - reference to an array of close dates. +# +# @return ($open, $close) +# +# @note If open/close dates are not defined they will be returned as undef +# @note It is possible for there to be no overlap in which case -1,-1 +# will be returned. +# @note The algorithm used is to take the latest open date and the earliest end date. +# +sub compute_open_window { + my ($opensref, $closesref) = @_; + + my @opens = @$opensref; + my @closes = @$closesref; + + # latest open date: + my $latest_open; + + foreach my $open (@opens) { + if (!defined($latest_open) || ($open > $latest_open)) { + $latest_open = $open; + } + } + # Earliest close: + + my $earliest_close; + foreach my $close (@closes) { + if (!defined($earliest_close) || ($close < $earliest_close)) { + $earliest_close = $close; + } + } + + # If no overlap...both are -1 as promised. + + if (($earliest_close ne '') && ($latest_open ne '') + && ($earliest_close < $latest_open)) { + $latest_open = -1; + $earliest_close = -1; + } + + return ($latest_open, $earliest_close); + +} + +## +# Determines if 'now' is within the set of printable dates. +# +# @param $open_date - Starting date/timestamp. +# @param $close_date - Ending date/timestamp. +# +# @return 0 - Not open. +# @return 1 - open. +# +sub printable { + my ($open_date, $close_date) = @_; + + + my $now = time(); + + # Have to do a bit of fancy footwork around undefined open/close dates: + + if ($open_date && ($open_date > $now)) { + return 0; + } + + if ($close_date && ($close_date < $now)) { + return 0; + } + + return 1; + +} + +## +# Returns the innermost print start/print end dates for a resource. +# This is done by looking at the start/end dates for its parts and choosing +# the intersection of those dates. +# +# @param res - lonnvamaps::resource object that represents the resource. +# +# @return (opendate, closedate) +# +# @note If open/close dates are not defined they will be returned as undef +# @note It is possible for there to be no overlap in which case -1,-1 +# will be returned. +# @note The algorithm used is to take the latest open date and the earliest end date. +# For consistency with &printable() in lonnavmaps.pm determination of start +# date for printing checks printstartdate param first, then, if not set, +# opendate param, then, if not set, contentopen param. + +sub get_print_dates { + my $res = shift; + my $partsref = $res->parts(); + my @parts; + if (ref($partsref) eq 'ARRAY') { + @parts = @{$partsref}; + } + my $open_date; + my $close_date; + my @open_dates; + my @close_dates; + + + if (@parts) { + foreach my $part (@parts) { + my $partopen = $res->parmval('printstartdate', $part); + my $partclose = $res->parmval('printenddate', $part); + if (!$partopen) { + $partopen = $res->parmval('opendate',$part); + } + if (!$partopen) { + $partopen = $res->parmval('contentopen',$part); + } + if ($partopen) { + push(@open_dates, $partopen); + } + if ($partclose) { + push(@close_dates, $partclose); + } + push(@open_dates, $partopen); + push(@close_dates, $partclose); + } + } + + ($open_date, $close_date) = &compute_open_window(\@open_dates, \@close_dates); + + return ($open_date, $close_date); +} + +## +# Get the dates for which a course says a resource can be printed. This is like +# get_print_dates but namvaps::course_print_dates are gotten...and not converted +# to times either. +# +# @param $res - Reference to a resource hash from lonnavmaps::resource. +# +# @return (opendate, closedate) +# +sub course_print_dates { + my $res = shift; + my $partsref = $res->parts(); + my @parts = @$partsref; + my $open_date; + my $close_date; + my @open_dates; + my @close_dates; + my $navmap = $res->{NAV_MAP}; # Slightly OO dirty. + + # Don't bother looping over undefined or empty parts array; + + if (@parts) { + foreach my $part (@parts) { + my ($partopen, $partclose) = $navmap->course_printdates($res, $part); + push(@open_dates, $partopen); + push(@close_dates, $partclose); + } + ($open_date, $close_date) = &compute_open_window(\@open_dates, \@close_dates); + } + return ($open_date, $close_date); +} +## +# Same as above but for the enclosing map: +# +sub map_print_dates { + my $res = shift; + my $partsref = $res->parts(); + my @parts = @$partsref; + my $open_date; + my $close_date; + my @open_dates; + my @close_dates; + my $navmap = $res->{NAV_MAP}; # slightly OO dirty. + + + # Don't bother looping over undefined or empty parts array; + + if (@parts) { + foreach my $part (@parts) { + my ($partopen, $partclose) = $navmap->map_printdates($res, $part); + push(@open_dates, $partopen); + push(@close_dates, $partclose); + } + ($open_date, $close_date) = &compute_open_window(\@open_dates, \@close_dates); + } + return ($open_date, $close_date); +} + +# Determine if a resource is incomplete given the map: +# Parameters: +# $username - Name of user for whom we are checking. +# $domain - Domain of user we are checking. +# $map - map name. +# Returns: +# 0 - map is not incomplete. +# 1 - map is incomplete. +# +sub incomplete { + my ($username, $domain, $map) = @_; + + + my $navmap = Apache::lonnavmaps::navmap->new($username, $domain); + + + if (defined($navmap)) { + my $res = $navmap->getResourceByUrl($map); + my $result = $res->is_incomplete(); + return $result; + } else { + return 1; + } +} +# +# When printing for students, the resources and order of the +# resources may need to be altered if there are folders with +# random selectiopn or random ordering (or both) enabled. +# This sub computes the set of resources to print for a student +# modified both by random ordering and selection and filtered +# to only those that are in the original set selected to be printed. +# +# Parameters: +# $map - The URL of the folder being printed. +# Used to determine which startResource and finishResource +# to use when using the navmap's getIterator method. +# $seq - The original set of resources to print. +# (really an array of resource names (array of symb's). +# $who - Student/domain for whome the sequence will be generated. +# $code - CODE being printed when printing Problems/Resources +# from folder for CODEd assignments +# $nohidemap - If true, parameter in map for hiddenresource will be +# ignored. The user calling the routine should have +# both the pav and vgr privileges if this is set to true). +# +# Implicit inputs: +# $ +# Returns: +# reference to an array of resources that can be passed to +# print_resources. +# +sub master_seq_to_person_seq { + my ($map, $seq, $who, $code, $nohidemap) = @_; + + + my ($username, $userdomain, $usersection) = split(/:/, $who); + + # Toss the sequence up into a hash so that we have O(1) lookup time. + # on the items that come out of the user's list of resources. + # + + my %seq_hash = map {$_ => 1} @$seq; + my @output_seq; + + my $unhidden; + if ($nohidemap) { + $unhidden = &Apache::lonnet::clutter($map); + } + + my $navmap = Apache::lonnavmaps::navmap->new($username, $userdomain, + $code, $unhidden); + my ($start,$finish); + + if ($map) { + my $mapres = $navmap->getResourceByUrl($map); + if ($mapres->is_map()) { + $start = $mapres->map_start(); + $finish = $mapres->map_finish(); + } + } + unless ($start && $finish) { + $start = $navmap->firstResource(); + $finish = $navmap->finishResource(); + } + + my $iterator = $navmap->getIterator($start,$finish,{},1); + + # Iterate on the resource..select the items that are randomly selected + # and that are in the seq_hash. Presumably the iterator will take care + # of the random ordering part of the deal. + # + my $curres; + while ($curres = $iterator->next()) { + # + # Only process resources..that are not removed by randomout... + # and are selected for printint as well. + # + if (ref($curres) && ! $curres->randomout()) { + my $currsymb = $curres->symb(); + if (exists($seq_hash{$currsymb})) { + push(@output_seq, $currsymb); + } + } + } + + return \@output_seq; # for now. + +} + # Fetch the contents of a resource, uninterpreted. # This is used here to fetch a latex file to be included @@ -271,10 +937,10 @@ sub fetch_raw_resource { } return $contents; - + } -# Fetch the annotations associated with a URL and +# Fetch the annotations associated with a URL and # put a centered 'annotations:' title. # This is all suppressed if the annotations are empty. # @@ -306,23 +972,31 @@ sub set_font_size { my ($text) = @_; - $text =~ s/\\begin{document}/\\begin{document}{\\$font_size/; - $text =~ s/\\end{document}/}\\end{document}/; + # There appear to be cases where the font directive is empty.. in which + # case the first substitution would insert a spurious \ oh happy day. + # as this has been the cause of much mystery and hair pulling _sigh_ + + if ($font_size ne '') { + + $text =~ s/\\begin\{document}/\\begin{document}{\\$font_size/; + $text =~ s/\\end\{document}/}\\end{document}/; + + } return $text; } -# include_pdf - PDF files are included into the +# include_pdf - PDF files are included into the # output as follows: # - The PDF, if necessary, is replicated. # - The PDF is added to the list of files to convert to postscript (along with the images). # - The LaTeX is added to include the final converted postscript in the file as an included -# job. The assumption is that the includedpsheader.ps header will be included. +# job. The assumption is that the includepsheader.ps header will be included. # # Parameters: # pdf_uri - URI of the PDF file to include. -# +# # Returns: # The LaTeX to include. # @@ -342,13 +1016,14 @@ sub include_pdf { $file = &Apache::lonnet::filelocation('',$pdf_uri); } - # The file isn ow replicated locally.. or it did not exist in the first place + # The file is now replicated locally ... or it did not exist in the first place # (unlikely). If it did exist, add the pdf to the set of files/images that - # need tob e converted for this print job: + # need to be converted for this print job: - $file =~ s|(.*)/res/|/home/httpd/html/res/|; + my $londocroot = $Apache::lonnet::perlvar{'lonDocRoot'}; + $file =~ s{(.*)/res/}{$londocroot/res/}; - open(FILE,">>/home/httpd/prtspool/$env{'user.name'}_$env{'user.domain'}_printout.dat"); + open(FILE,">>","$Apache::lonnet::perlvar{'lonPrtDir'}/$env{'user.name'}_$env{'user.domain'}_printout.dat"); print FILE ("$file\n"); close (FILE); @@ -371,7 +1046,29 @@ sub include_pdf { } - +## +# Collect the various \select_language{language_name} +# latex tags to build a \usepackage[lang-list]{babel} which will +# appear just prior to the \begin{document} at the front of the concatenated +# set of resources: +# @param doc - The string of latex to search/replace. +# @return string +# @retval - the modified document stringt. +# +sub collect_languages { + my $doc = shift; + my %languages; + while ($doc =~ /\\selectlanguage\{(\w+)}/mg) { + $languages{$1} = 1; # allows us to request each language exactly once. + } + my @lang_list = (keys(%languages)); # List of unique languages + if (scalar @lang_list) { + my $babel_header = '\usepackage[' . join(',', @lang_list) .']{babel}'. "\n"; + $doc =~ s/\\begin\{document}/$babel_header\\begin{document}/; + } + return $doc; +} +#------------------------------------------------------------------- # # ssi_with_retries- Does the server side include of a resource. @@ -379,7 +1076,7 @@ sub include_pdf { # the number of times requested by the caller. # If we still have a proble, no text is appended to the # output and we set some global variables. -# to indicate to the caller an SSI error occurred. +# to indicate to the caller an SSI error occurred. # All of this is supposed to deal with the issues described # in LonCAPA BZ 5631 see: # http://bugs.lon-capa.org/show_bug.cgi?id=5631 @@ -389,7 +1086,7 @@ sub include_pdf { # resource - The resource to include. This is passed directly, without # interpretation to lonnet::ssi. # form - The form hash parameters that guide the interpretation of the resource -# +# # retries - Number of retries allowed before giving up completely. # Returns: # On success, returns the rendered resource identified by the resource parameter. @@ -418,7 +1115,6 @@ sub ssi_with_retries { $ssi_last_error_resource = $resource; $ssi_last_error = $response->code . " " . $response->message; $content='\section*{!!! An error occurred !!!}'; - &Apache::lonnet::logthis("Error in SSI resource: $resource Error: $ssi_last_error"); } return $content; @@ -434,7 +1130,6 @@ sub get_student_view_with_retries { $ssi_last_error_resource = $curresline.' for user '.$username.':'.$userdomain; $ssi_last_error = $response->code . " " . $response->message; $content='\section*{!!! An error occurred !!!}'; - &Apache::lonnet::logthis("Error in SSI (student view) resource: $curresline Error: $ssi_last_error User: $username:$userdomain"); } return $content; @@ -442,12 +1137,12 @@ sub get_student_view_with_retries { # # 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 +# repl is truncated to at most [n] characters prior to # substitution. # sub printf_style_subst { @@ -459,15 +1154,15 @@ sub printf_style_subst { 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 + + # Here's a nice edge case ... suppose 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 + # " " 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. \\\ + # trimmed us to e.g. \\\ if ($subst =~ /\\$/) { @@ -487,8 +1182,8 @@ sub printf_style_subst { } -# Format a header according to a format. -# +# Format a header according to a format. +# # Substitutions: # %a - Assignment name. @@ -512,7 +1207,7 @@ sub format_page_header { # 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). @@ -528,9 +1223,10 @@ sub format_page_header { if ($section) { $format .= ' - Sec: '."%$sec_length".'s'; } + $format .= '\\hfill\\thepage'; $format .= '\\\\%c \\\\ %a'; - + } # An open question is how to handle long user formatted page headers... @@ -541,17 +1237,17 @@ sub format_page_header { $format = &printf_style_subst("c", $format, $course); $format = &printf_style_subst("n", $format, $student); $format = &printf_style_subst("s", $format, $section); - - + + # 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!!! - + # If the user has role author, $course and $assignment are empty so # there is '\\ \\ ' in the page header. That's cause a error in LaTeX if($format =~ /\\\\\s\\\\\s/) { #TODO find sensible caption for page header - my $testPrintout = '\\\\'.&mt('Construction Space').' \\\\'.&mt('Test-Printout '); + my $testPrintout = '\\\\'.&mt('Authoring Space').' \\\\'.&mt('Test-Printout '); $format =~ s/\\\\\s\\\\\s/$testPrintout/; } # @@ -569,7 +1265,7 @@ sub format_page_header { return $format; - + } # @@ -617,7 +1313,7 @@ sub is_valid_numeric_code { # 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"; @@ -638,7 +1334,7 @@ sub is_valid_numeric_code { # sub is_valid_alpha_code { my ($value, $num_letters) = @_; - + # strip leading and trailing spaces. $value =~ s/^\s*//g; @@ -656,7 +1352,7 @@ sub is_valid_alpha_code { # 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 +# 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. @@ -671,8 +1367,9 @@ sub is_valid_alpha_code { sub is_code_valid { my ($code_value, $code_option) = @_; my ($code_type, $code_length) = ('letter', 6); # defaults. - my @lines = &Apache::grades::get_scantronformat_file(); + my @lines = &Apache::lonnet::get_scantronformat_file(); foreach my $line (@lines) { + next if (($line =~ /^\#/) || ($line eq '')); my ($name, $type, $length) = (split(/:/, $line))[0,2,4]; if($name eq $code_option) { $code_length = $length; @@ -689,6 +1386,22 @@ sub is_code_valid { } } +# +# Compare two students by section (Used to sort by section). +# +# Implicit inputs, +# $a - The first one +# $b - The second one. +# +# Returns: +# a-section cmp b-section +# +sub compare_sections { + my ($u1, $d1, $s1, $n1, $stat1) = split(/:/, $a); + my ($u2, $d2, $s2, $n2, $stat2) = split(/:/, $b); + + return $s1 cmp $s2; +} # Compare two students by name. The students are in the form # returned by the helper: @@ -728,11 +1441,11 @@ sub compare_names { } # Break the tie on the first name, but there are leading (possibly trailing - # whitespaces to get rid of first + # 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... @@ -742,7 +1455,7 @@ sub compare_names { if($f1 gt $f2) { return 1; } - + # Must be the same name. return 0; @@ -750,18 +1463,18 @@ sub compare_names { sub latex_header_footer_remove { my $text = shift; - $text =~ s/\\end{document}//; - $text =~ s/\\documentclass([^&]*)\\begin{document}//; + $text =~ s/\\end\{document}//; + $text =~ s/\\documentclass([^&]*)\\begin\{document}//; return $text; } # -# If necessary, encapsulate text inside +# 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)) { + my ($text,$problem_split) = @_; + if (!($problem_split =~ /yes/i)) { $text = '\begin{minipage}{\textwidth}'.$text.'\end{minipage}'; } return $text; @@ -779,7 +1492,7 @@ 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') { @@ -811,8 +1524,8 @@ sub old_character_chart { $result =~ s/&(\#0?34|quot);/\"/g; $result =~ s/&\#0?35;/\\\#/g; $result =~ s/&\#0?36;/\\\$/g; - $result =~ s/&\#0?37;/\\%/g; - $result =~ s/&(\#0?38|amp);/\\&/g; + $result =~ s/&\#0?37;/\\%/g; + $result =~ s/&(\#0?38|amp);/\\&/g; $result =~ s/&\#(0?39|146);/\'/g; $result =~ s/&\#0?40;/(/g; $result =~ s/&\#0?41;/)/g; @@ -919,7 +1632,7 @@ sub old_character_chart { $result =~ s/&(\#160|nbsp);/~/g; $result =~ s/&(\#161|iexcl);/!\`/g; $result =~ s/&(\#162|cent);/\\textcent /g; - $result =~ s/&(\#163|pound);/\\pounds /g; + $result =~ s/&(\#163|pound);/\\pounds /g; $result =~ s/&(\#164|curren);/\\textcurrency /g; $result =~ s/&(\#165|yen);/\\textyen /g; $result =~ s/&(\#166|brvbar);/\\textbrokenbar /g; @@ -945,32 +1658,32 @@ sub old_character_chart { $result =~ s/&(\#188|frac14);/\\textonequarter /g; $result =~ s/&(\#189|frac12);/\\textonehalf /g; $result =~ s/&(\#190|frac34);/\\textthreequarters /g; - $result =~ s/&(\#191|iquest);/?\`/g; - $result =~ s/&(\#192|Agrave);/\\\`{A}/g; - $result =~ s/&(\#193|Aacute);/\\\'{A}/g; + $result =~ s/&(\#191|iquest);/?\`/g; + $result =~ s/&(\#192|Agrave);/\\\`{A}/g; + $result =~ s/&(\#193|Aacute);/\\\'{A}/g; $result =~ s/&(\#194|Acirc);/\\^{A}/g; $result =~ s/&(\#195|Atilde);/\\~{A}/g; - $result =~ s/&(\#196|Auml);/\\\"{A}/g; + $result =~ s/&(\#196|Auml);/\\\"{A}/g; $result =~ s/&(\#197|Aring);/{\\AA}/g; $result =~ s/&(\#198|AElig);/{\\AE}/g; $result =~ s/&(\#199|Ccedil);/\\c{c}/g; - $result =~ s/&(\#200|Egrave);/\\\`{E}/g; - $result =~ s/&(\#201|Eacute);/\\\'{E}/g; + $result =~ s/&(\#200|Egrave);/\\\`{E}/g; + $result =~ s/&(\#201|Eacute);/\\\'{E}/g; $result =~ s/&(\#202|Ecirc);/\\^{E}/g; $result =~ s/&(\#203|Euml);/\\\"{E}/g; $result =~ s/&(\#204|Igrave);/\\\`{I}/g; - $result =~ s/&(\#205|Iacute);/\\\'{I}/g; + $result =~ s/&(\#205|Iacute);/\\\'{I}/g; $result =~ s/&(\#206|Icirc);/\\^{I}/g; - $result =~ s/&(\#207|Iuml);/\\\"{I}/g; + $result =~ s/&(\#207|Iuml);/\\\"{I}/g; $result =~ s/&(\#209|Ntilde);/\\~{N}/g; $result =~ s/&(\#210|Ograve);/\\\`{O}/g; $result =~ s/&(\#211|Oacute);/\\\'{O}/g; $result =~ s/&(\#212|Ocirc);/\\^{O}/g; $result =~ s/&(\#213|Otilde);/\\~{O}/g; - $result =~ s/&(\#214|Ouml);/\\\"{O}/g; + $result =~ s/&(\#214|Ouml);/\\\"{O}/g; $result =~ s/&(\#215|times);/\\ensuremath\{\\times\}/g; $result =~ s/&(\#216|Oslash);/{\\O}/g; - $result =~ s/&(\#217|Ugrave);/\\\`{U}/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; @@ -1001,7 +1714,7 @@ sub old_character_chart { $result =~ s/&(\#246|ouml);/\\\"{o}/g; $result =~ s/&(\#247|divide);/\\ensuremath\{\\div\}/g; $result =~ s/&(\#248|oslash);/{\\o}/g; - $result =~ s/&(\#249|ugrave);/\\\`{u}/g; + $result =~ s/&(\#249|ugrave);/\\\`{u}/g; $result =~ s/&(\#250|uacute);/\\\'{u}/g; $result =~ s/&(\#251|ucirc);/\\^{u}/g; $result =~ s/&(\#252|uuml);/\\\"{u}/g; @@ -1148,12 +1861,12 @@ sub old_character_chart { 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'] + '1' => [ '7.1 in','9.7 in', '-0.57 in','-0.57 in','0.1 in'], + '2' => ['3.66 in','9.8 in', '-0.57 in','-0.57 in','0.1 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'] + '1' => [ '8.8 in', '6.8 in','-0.55 in', '-0.55 in','-0.5 in'], + '2' => [ '4.8 in', '6.7 in','-0.5 in', '-1.0 in','3.0 in'] }, }, 'legal' => { @@ -1163,7 +1876,7 @@ my %page_formats= }, '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'] + '2' => ['5.7 in','7.1 in','-1 in','-1 in','5 in'] }, }, 'tabloid' => { @@ -1212,8 +1925,8 @@ my %page_formats= '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'] + '1' => ['24.0 cm','18.0 cm','-1.0 cm','-1.0 cm','-1.25 cm'], + '2' => ['11.5 cm','18.0 cm','-0.7 cm','-1.7 cm','-1.25 cm'] }, }, 'a5' => { @@ -1245,8 +1958,8 @@ sub page_format { # "A2 [420x594 mm]", "A3 [297x420 mm]", # "A4 [210x297 mm]", "A5 [148x210 mm]", # "A6 [105x148 mm]" -# - my ($papersize,$layout,$numberofcolumns) = @_; +# + my ($papersize,$layout,$numberofcolumns) = @_; return @{$page_formats{$papersize}->{$layout}->{$numberofcolumns}}; } @@ -1266,13 +1979,14 @@ sub get_course { if (defined($env{'request.course.id'})) { $courseidinfo = &Apache::lonxml::latex_special_symbols(&unescape($env{'course.'.$env{'request.course.id'}.'.description'}),'header'); my $sec = $env{'request.course.sec'}; - + } return $courseidinfo; } sub page_format_transformation { - my ($papersize,$layout,$numberofcolumns,$choice,$text,$assignment,$tableofcontents,$indexlist,$selectionmade) = @_; + my ($papersize,$layout,$numberofcolumns,$choice,$text,$assignment,$tableofcontents, + $indexlist,$selectionmade,$mostrecent) = @_; my ($textwidth,$textheight,$oddoffset,$evenoffset,$topmargin); if ($selectionmade eq '4') { @@ -1286,8 +2000,12 @@ sub page_format_transformation { } ($textwidth,$textheight,$oddoffset,$evenoffset,$topmargin) = &page_format($papersize,$layout,$numberofcolumns,$topmargin); - - my $name = &get_name(); + my $name; + if ($mostrecent ne '') { + $name = $mostrecent; + } else { + $name = &get_name(); + } my $courseidinfo = &get_course(); my $header_text = $parmhash{'print_header_format'}; $header_text = &format_page_header($textwidth, $header_text, $assignment, @@ -1297,25 +2015,58 @@ sub page_format_transformation { my $fancypagestatement=''; if ($numberofcolumns eq '2') { $fancypagestatement="\\fancyhead{}\\fancyhead[LO]{$header_text}"; + if ($parmhash{'print_header_format'} eq '') { + $fancypagestatement .= "\\fancyhead[RE]{\\thepage \\\\[\\baselineskip]}"; + } } else { $fancypagestatement="\\rhead{}\\chead{}\\lhead{$header_text}"; } + $fancypagestatement .= "\\fancyfoot{}"; + my ($paperwidth,$paperheight); 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\\usepackage{booktabs}\\begin{document}\\voffset=-0\.8 cm\\setcounter{page}{1}\n /; + $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\\usepackage{booktabs}\\begin{document}\\voffset=-0\.8 cm\\setcounter{page}{1}\n /; + if ($papersize eq 'a4') { + $paperwidth = '29.7cm'; + $paperheight = '21cm'; + } elsif ($numberofcolumns eq '1') { + if ($papersize eq 'letter') { + $paperwidth = '11in'; + $paperheight = '8.5in'; + } elsif ($papersize eq 'legal') { + $paperwidth = '14in'; + $paperheight = '8.5in'; + } + } } elsif ($layout eq 'book') { - if ($choice ne 'All class print') { - $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\\usepackage{booktabs}\\begin{document}\n\\voffset=-0\.8 cm\\setcounter{page}{1}\n/; + if ($choice ne 'All class print') { + $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\\usepackage{booktabs}\\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\n\\evensidemargin = $evenoffset $topmargintoinsert\\textwidth= $textwidth\\newlength{\\minipagewidth}\n\\setlength{\\minipagewidth}{\\textwidth\/\$number_of_columns-0\.2cm}\\renewcommand{\\ref}{\\keephidden\}\\pagestyle{fancy}\\rhead{}\\chead{}\\usepackage{booktabs}\\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\}/; + $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{}\\usepackage{booktabs}\\begin{document}\\voffset=-0\.8cm\n\\setcounter{page}{1} \\vskip 5 mm\n /; } + if ($papersize eq 'a4') { + $paperwidth = '21cm'; + $paperheight = '29.7cm'; + } elsif ($papersize eq 'letter') { + $paperwidth = '8.5in'; + $paperheight = '11.5in'; + } elsif ($papersize eq 'legal') { + $paperwidth = '8.5in'; + $paperheight = '14.0in'; + } + } + if ($paperwidth ne '' && $paperheight ne '') { + my $papersize_text; + if ($perm{'pav'}) { + $papersize_text = '\\special{papersize='.$paperwidth.','.$paperheight.'}'; + } else { + $papersize_text = '\special{papersize='.$paperwidth.','.$paperheight.'}'; + } + $text =~ s/(\\begin\{document})/$1$papersize_text/; } 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/; + $text=~s/(\\begin\{document})/\\makeindex $1/; + $text=~s/(\\end\{document})/\\strut\\\\\\strut\\printindex $1/; } return $text; } @@ -1323,13 +2074,13 @@ sub page_format_transformation { sub page_cleanup { my $result = shift; - - $result =~ m/\\end{document}(\d*)$/; + + $result =~ m/\\end\{document}(\d*)$/; my $number_of_columns = $1; my $insert = '{'; for (my $id=1;$id<=$number_of_columns;$id++) { $insert .='l'; } $insert .= '}'; - $result =~ s/(\\begin{longtable})INSERTTHEHEADOFLONGTABLE\\endfirsthead\\endhead/$1$insert/g; + $result =~ s/(\\begin\{longtable})INSERTTHEHEADOFLONGTABLE\\endfirsthead\\endhead/$1$insert/g; $result =~ s/&\s*REMOVETHEHEADOFLONGTABLE\\\\/\\\\/g; return $result,$number_of_columns; } @@ -1365,17 +2116,17 @@ my $end_of_student = "\n".'\special{ps:E sub latex_corrections { my ($number_of_columns,$result,$selectionmade,$answer_mode) = @_; -# $result =~ s/\\includegraphics{/\\includegraphics\[width=\\minipagewidth\]{/g; +# $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/; + $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/(\\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 + $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 my $first_comment = index($result,'',$first_comment); @@ -1393,8 +2144,8 @@ sub latex_corrections { if ($result =~ m/&(\w+|#\d+);/) { $result = &character_chart($result); } - $result =~ s/(\\end{tabular})\s*\\vskip 0 mm/$1/g; - $result =~ s/(\\begin{enumerate})\s*\\noindent/$1/g; + $result =~ s/(\\end\{tabular})\s*\\vskip 0 mm/$1/g; + $result =~ s/(\\begin\{enumerate})\s*\\noindent/$1/g; return $result; } @@ -1487,15 +2238,28 @@ sub get_textwidth { sub unsupported { my ($currentURL,$mode,$symb)=@_; + my $cleanURL=&Apache::lonenc::check_decrypt($currentURL); + my $shown = $currentURL; + if (($cleanURL ne $currentURL) || ($symb =~ m{/^enc/})) { + $shown = &mt('URL not shown (encrypted)'); + } if ($mode ne '') {$mode='\\'.$mode} - my $result.= &print_latex_header($mode); - if ($currentURL=~m|^(/adm/wrapper/)?ext/|) { - $currentURL=~s|^(/adm/wrapper/)?ext/|http://|; - my $title=&Apache::lonnet::gettitle($symb); - $title = &Apache::lonxml::latex_special_symbols($title); - $result.=' \strut \\\\ '.$title.' \strut \\\\ '.$currentURL.' '; + my $result = &print_latex_header($mode); + if ($cleanURL=~m|^(/adm/wrapper)?/ext/|) { + $cleanURL=~s|^(/adm/wrapper)?/ext/|http://|; + $cleanURL=~s|^http://https://|https://|; + if ($shown eq $currentURL) { + $shown = &Apache::lonxml::latex_special_symbols($cleanURL); + } + my $title=&Apache::lonnet::gettitle($symb); + $title = &Apache::lonxml::latex_special_symbols($title); + $result.=' \strut \\\\ \textit{'.$title.'} \strut \\\\ '.$shown.' '; } else { - $result.=$currentURL; + if ($shown eq $currentURL) { + $result.=&Apache::lonxml::latex_special_symbols($currentURL); + } else { + $result.=$shown; + } } $result.= '\vskip 0.5mm\noindent\makebox[\textwidth/$number_of_columns][b]{\hrulefill} \end{document}'; return $result; @@ -1516,6 +2280,7 @@ sub map_laystyle { sub print_page_in_course { my ($helper, $rparmhash, $currentURL, $resources) = @_; + my %parmhash = %$rparmhash; my @page_resources = @$resources; my $mode = $helper->{'VARS'}->{'LATEX_TYPE'}; @@ -1530,19 +2295,14 @@ sub print_page_in_course { $laystyle = &map_laystyle($laystyle); my ($textwidth,$textheight,$oddoffset,$evenoffset) = &page_format($papersize,$laystyle, $numberofcolumns); - my $LaTeXwidth=&recalcto_mm($textwidth); - + my $LaTeXwidth=&recalcto_mm($textwidth); if ($mode ne '') {$mode='\\'.$mode} my $result = &print_latex_header($mode); - if ($currentURL=~m|^(/adm/wrapper/)?ext/|) { - $currentURL=~s|^(/adm/wrapper/)?ext/|http://|; - my $title=&Apache::lonnet::gettitle($symb); - $title = &Apache::lonxml::latex_special_symbols($title); - } else { - $result.=$currentURL; - } - $result .= '\\\\'; + + my $title=&Apache::lonnet::gettitle($currentURL); + $title = &Apache::lonxml::latex_special_symbols($title); + $result .= '\noindent\textit{'.$title.'}\\\\'; if ($helper->{'VARS'}->{'style_file'}=~/\w/) { &Apache::lonnet::appenv({'construct.style' => @@ -1551,27 +2311,30 @@ sub print_page_in_course { &Apache::lonnet::delenv('construct.style'); } - # First is the overall page description. This is then followed by the + # First is the overall page description. This is then followed by the # components of the page. Each of which must be printed independently. - my $the_page = shift(@page_resources); + my $the_page = shift(@page_resources); foreach my $resource (@page_resources) { my $resource_src = $resource->src(); # Essentially the URL of the resource. - $result .= $resource->title() . '\\\\'; + my $current_url = $resource->link(); # Recurse if a .page: if ($resource_src =~ /.page$/i) { my $navmap = Apache::lonnavmaps::navmap->new(); my @page_resources = $navmap->retrieveResources($resource_src); - $result .= &print_page_in_course($helper, $rparmhash, + $result .= &print_page_in_course($helper, $rparmhash, $resource_src, \@page_resources); - } - # these resources go through the XML transformer: + } elsif ($resource->ext()) { + $result.=&latex_header_footer_remove(&unsupported($current_url,$mode,$resource->symb)); + } elsif ($resource_src =~ /\.(problem|exam|quiz|assess|survey|form|library|xml|html|htm|xhtml|xhtm)$/) { + # these resources go through the XML transformer: + $result .= &Apache::lonxml::latex_special_symbols($resource->title()) . '\\\\'; - elsif ($resource_src =~ /\.(problem|exam|quiz|assess|survey|form|library|page|xml|html|htm\xhtml|xhtm)$/) { my $urlp = &Apache::lonnet::clutter($resource_src); + my %form; my %moreenv; @@ -1581,9 +2344,9 @@ sub print_page_in_course { $form{'grade_target'} = 'tex'; $form{'textwidth'} = &get_textwidth($helper, $LaTeXwidth); - $form{'pdfFormFiels'} = $pdfFormFields; # - $form{'showallfoils'} = $helper->{'VARS'}->{'showallfoils'}; - + $form{'pdfFormFields'} = $pdfFormFields; # + $form{'showallfoils'} = $helper->{'VARS'}->{'showallfoils'}; + $form{'problem_split'}=$parmhash{'problem_stream_switch'}; $form{'suppress_tries'}=$parmhash{'suppress_tries'}; $form{'latex_type'}=$helper->{'VARS'}->{'LATEX_TYPE'}; @@ -1599,7 +2362,7 @@ sub print_page_in_course { } $form{'rndseed'}=$rndseed; &Apache::lonnet::appenv(\%moreenv); - + &Apache::lonxml::clear_problem_counter(); my $texversion = &ssi_with_retries($urlp, $ssi_retry_count, %form); @@ -1624,7 +2387,7 @@ sub print_page_in_course { my $answer=&ssi_with_retries($urlp,$ssi_retry_count, %answerform); if ($helper->{'VARS'}->{'ANSWER_TYPE'} eq 'no') { - $texversion=~s/(\\keephidden{ENDOFPROBLEM})/$answer$1/; + $texversion=~s/(\\keephidden\{ENDOFPROBLEM})/$answer$1/; } else { $texversion= &print_latex_header($helper->{'VARS'}->{'LATEX_TYPE'}); if ($helper->{'VARS'}->{'construction'} ne '1') { @@ -1633,27 +2396,21 @@ sub print_page_in_course { $texversion.='\vskip 0 mm \noindent\textbf{'.$title.'}\vskip 0 mm '; $texversion.=&path_to_problem($urlp,$LaTeXwidth); } else { - $texversion.='\vskip 0 mm \noindent\textbf{Prints from construction space - there is no title.}\vskip 0 mm '; - my $URLpath=$urlp; - $URLpath=~s/~([^\/]+)/public_html\/$1\/$1/; - $texversion.=&path_to_problem($URLpath,$LaTeXwidth); + $texversion.='\vskip 0 mm \noindent\textbf{'. + &mt("Printing from Authoring Space: No Title").'}\vskip 0 mm '; + $texversion.=&path_to_problem($urlp,$LaTeXwidth); } $texversion.='\vskip 1 mm '.$answer.'\end{document}'; } - - - - - } # Print annotations. if ($helper->{'VARS'}->{'PRINT_ANNOTATIONS'} eq 'yes') { my $annotation .= &annotate($currentURL); - $texversion =~ s/(\\keephidden{ENDOFPROBLEM})/$annotation$1/; + $texversion =~ s/(\\keephidden\{ENDOFPROBLEM})/$annotation$1/; } - + if ($helper->{'VARS'}->{'TABLE_INDEX'} eq 'yes') { $texversion=&IndexCreation($texversion,$currentURL); } @@ -1685,13 +2442,13 @@ sub print_page_in_course { # List of recently generated print files # sub recently_generated { - my $r=shift; - my $prtspool=$r->dir_config('lonPrtDir'); + my ($prtspool) = @_; + my $output; my $zip_result; my $pdf_result; opendir(DIR,$prtspool); - my @files = + my @files = grep(/^$env{'user.name'}_$env{'user.domain'}_printout_(\d+)_.*\.(pdf|zip)$/,readdir(DIR)); closedir(DIR); @@ -1719,10 +2476,10 @@ sub recently_generated { if ($ext eq 'zip') { $zip_result .= $result; } } if ($zip_result || $pdf_result) { - $r->print('
'); + $output ='
'; } if ($zip_result) { - $r->print('

'.&mt('Recently generated printout zip files')."

\n" + $output .='

'.&mt('Recently generated printout zip files')."

\n" .&Apache::loncommon::start_data_table() .&Apache::loncommon::start_data_table_header_row() .'
'.&mt('Download').''.&mt('File Size (Bytes)').''.&mt('Download').''.&mt('File Size (Bytes)').' - - - - push(@{$state->{CHOICES}},@{$helper->{DATA}{ALL_CODE_CHOICES}}); - - -
- '.$/; - - } + my ($randomly_ordered_warning,$codechoice,$code_selection,$namechoice) = + &generate_common_choosers($r,$helper,$map,$url,$isProblem,$symbFilter,$start_new_option); - my @lines = &Apache::grades::get_scantronformat_file(); - my $codechoice=''; - foreach my $line (@lines) { - my ($name,$description,$code_type,$code_length)= - (split(/:/,$line))[0,1,2,4]; - if ($code_length > 0 && - $code_type =~/^(letter|number|-1)/) { - $codechoice.=''.$description.''; - } - } - if ($codechoice eq '') { - $codechoice='Default'; - } - my $anon1 = &generate_code_selector($helper, - 'CHOOSE_ANON1', - 'SELECT_PROBLEMS', - $codechoice, - $code_selection, - $namechoice) . $resource_selector; - - - &Apache::lonxml::xmlparse($r, 'helper',$anon1); - - my $anon_page = &generate_code_selector($helper, - 'CHOOSE_ANON1_PAGE', - 'SELECT_PROBLEMS_PAGE', - $codechoice, - $code_selection, - $namechoice) . - &generate_resource_chooser('SELECT_PROBLEMS_PAGE', - 'Select Problem(s) to print', - "multichoice='1' addstatus='1' closeallpages ='1'", - 'RESOURCES', - 'PRINT_FORMATTING', - $url, - $isProblem, '', $symbFilter, - $start_new_option); - &Apache::lonxml::xmlparse($r, 'helper', $anon_page); + if ($helper->{VARS}->{'assignment'}) { + # Assignment printing: - if ($helper->{VARS}->{'assignment'}) { push @{$printChoices}, [&mt('Selected [_1]Resources[_2] from folder [_3] for [_4]selected people[_5]','','',''.$sequenceTitle.'','',''), 'resources_for_students', 'CHOOSE_STUDENTS1']; push @{$printChoices}, [&mt('Selected [_1]Resources[_2] from folder [_3] for [_4]CODEd assignments[_5]','','',''.$sequenceTitle.'','',''), 'resources_for_anon', 'CHOOSE_ANON2']; } - - $resource_selector=< $randomly_ordered_warning PRINT_FORMATTING
Select resources for the assignment
- + return $isNotMap; $map return $symbFilter; $start_new_option - - - NUMBER_PER_PDF -
How should the results be printed?
- - Start each student\'s assignment on a new page/column (add a pagefeed after each assignment) - Add one empty page/column after each student\'s assignment - Add two empty pages/column after each student\'s assignment - Add three empty pages/column after each student\'s assignment - - PAGESIZE -
How do you want assignments split into PDF files?
- - All assignments in a single PDF file - Each PDF contains exactly one section - Each PDF contains exactly one assignment - - Specify the number of assignments per PDF: - -
RESOURCE_SELECTOR + $resource_selector .= &generate_format_selector($helper, + 'Format of the print job', + 'PRINT_FORMATTING'); &Apache::lonxml::xmlparse($r, 'helper', < @@ -3710,7 +4728,7 @@ CHOOSE_STUDENTS1


Generate new CODEd Assignments

Number of CODEd assignments to print: - + if (((\$helper->{'VARS'}{'NUMBER_TO_PRINT_TOTAL'}+0) < 1) && !\$helper->{'VARS'}{'REUSE_OLD_CODES'} && @@ -3718,6 +4736,10 @@ CHOOSE_STUDENTS1 !\$helper->{'VARS'}{'CODE_SELECTED_FROM_LIST'}) { return "You need to specify the number of assignments to print"; } + if (((\$helper->{'VARS'}{'NUMBER_TO_PRINT_TOTAL'}+0) >= 1) && + (\$helper->{'VARS'}{'SINGLE_CODE'} ne '') ) { + return 'Specifying number of codes to print and a specific code is not compatible'; + } return undef; @@ -3726,7 +4748,7 @@ CHOOSE_STUDENTS1
- Bubble sheet type: + Bubblesheet type: $codechoice @@ -3741,6 +4763,8 @@ CHOOSE_STUDENTS1 !\$helper->{'VARS'}{'CODE_SELECTED_FROM_LIST'}) { return &Apache::lonprintout::is_code_valid(\$helper->{'VARS'}{'SINGLE_CODE'}, \$helper->{'VARS'}{'CODE_OPTION'}); + } elsif (\$helper->{'VARS'}{'SINGLE_CODE'} ne ''){ + return 'Specifying a code name is incompatible specifying number of codes.'; } else { return undef; # Other forces control us. } @@ -3763,6 +4787,7 @@ CHOOSE_ANON2 # FIXME: That RE should come from a library somewhere. if (($perm{'pav'} + && ($subdir ne '') && $subdir ne $Apache::lonnet::perlvar{'lonDocRoot'}.'/res/' && (defined($helper->{'VARS'}->{'construction'}) || @@ -3781,7 +4806,7 @@ CHOOSE_ANON2 PAGESIZE return '$subdir'; CHOOSE_FROM_SUBDIR - + # this is broken up because I really want interpolation above, # and I really DON'T want it below $xmlfrag .= <<'CHOOSE_FROM_SUBDIR'; @@ -3796,19 +4821,153 @@ CHOOSE_FROM_SUBDIR # Allow the user to select any sequence in the course, feed it to # another resource selector for that sequence - if (!$helper->{VARS}->{'construction'} && !$is_published) { - push @$printChoices, [&mtn("Selected Resources from selected folder in course"), - 'select_sequences', 'CHOOSE_SEQUENCE']; - my $escapedSequenceName = $helper->{VARS}->{'SEQUENCE'}; - #Escape apostrophes and backslashes for Perl - $escapedSequenceName =~ s/\\/\\\\/g; - $escapedSequenceName =~ s/'/\\'/g; - &Apache::lonxml::xmlparse($r, 'helper', <{VARS}->{'construction'}) && + (!$is_published || (($subdir eq '') && ($url eq '/adm/navmaps')))) { + push(@$printChoices,[&mt('Selected [_1]Resources[_2] from [_3]selected folder[_4] in course', + '','','',''), + 'select_sequences','CHOOSE_SEQUENCE']); + my $escapedSequenceName; + if ($helper->{VARS}->{'SEQUENCE'} ne '') { + $escapedSequenceName = $helper->{VARS}->{'SEQUENCE'}; + } elsif (($subdir eq '') && ($url eq '/adm/navmaps')) { + my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'}; + my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'}; + if ($env{'course.'.$env{'request.course.id'}.'.url'} eq + "uploaded/$cdom/$cnum/default.sequence") { + $escapedSequenceName = $env{'course.'.$env{'request.course.id'}.'.url'}; + } + } + #Escape apostrophes and backslashes for Perl + $escapedSequenceName =~ s/\\/\\\\/g; + $escapedSequenceName =~ s/'/\\'/g; + my $nocurrloc; + if (($subdir eq '') && ($url eq '/adm/navmaps')) { + $nocurrloc = 'nocurrloc="1"'; + if ($perm{'pfo'}) { + push(@{$printChoices}, + [&mt('Selected [_1]Problems[_2] from [_3]selected folder[_4] in course for [_5]selected people[_6]', + '','','','','',''), + 'select_sequences_problems_for_students','CHOOSE_SEQUENCE_STUDENTS'], + [&mt('Selected [_1]Problems[_2] from [_3]selected folder[_4] in course for [_5]CODEd assignments[_6]', + '','','','','',''), + 'select_sequences_problems_for_anon','CHOOSE_SEQUENCE_ANON1'], + [&mt('Selected [_1]Resources[_2] from [_3]selected folder[_4] in course for [_5]selected people[_6]', + '','','','','',''), + 'select_sequences_resources_for_students','CHOOSE_SEQUENCE_STUDENTS1'], + [&mt('Selected [_1]Resources[_2] from [_3]selected folder[_4] in course for [_5]CODEd assignments[_6]', + '','','','','',''), + 'select_sequences_resources_for_anon','CHOOSE_SEQUENCE_ANON2']); + if ($escapedSequenceName) { + my ($randomly_ordered_warning,$codechoice,$code_selection,$namechoice) = + &generate_common_choosers($r,$helper,$escapedSequenceName,$escapedSequenceName, + $isProblem,$symbFilter,$start_new_option); + + my $resource_selector = < + + Sort by section then student + Sort by students across sections. + +


+ + + + + $randomly_ordered_warning + PRINT_FORMATTING + (mark desired resources then click "next" button)
+ + return $isNotMap; + $escapedSequenceName + return $symbFilter; + $start_new_option + +
+RESOURCE_SELECTOR + + my $anon3 = &generate_code_selector($helper, + 'CHOOSE_ANON3', + 'SELECT_RESOURCES', + $codechoice, + $code_selection, + $namechoice) . $resource_selector; + + &Apache::lonxml::xmlparse($r, 'helper',$anon3); + } + } + } + if (($subdir eq '') && ($url eq '/adm/navmaps') && ($perm{'pfo'})) { + &Apache::lonxml::xmlparse($r, 'helper', < Select the sequence to print resources from: CHOOSE_FROM_ANY_SEQUENCE - return \$res->is_sequence; + return &Apache::lonprintout::printable_sequence(\$res); + return $urlValue; + return \$res->hasResource(\$res,sub { return !\$_[0]->is_sequence() },0,0); + + + + + Select the sequence to print resources from: + + CHOOSE_STUDENTS + return &Apache::lonprintout::printable_sequence(\$res); + return $urlValue; + return \$res->hasResource(\$res,sub { return !\$_[0]->is_sequence() },0,0); + + + + + Select the sequence to print resources from: + + CHOOSE_ANON1 + return &Apache::lonprintout::printable_sequence(\$res); + return $urlValue; + return \$res->hasResource(\$res,sub { return !\$_[0]->is_sequence() },0,0); + + + + + Select the sequence to print resources from: + + CHOOSE_STUDENTS2 + return &Apache::lonprintout::printable_sequence(\$res); + return $urlValue; + return \$res->hasResource(\$res,sub { return !\$_[0]->is_sequence() },0,0); + + + + + Select the sequence to print resources from: + + CHOOSE_ANON3 + return &Apache::lonprintout::printable_sequence(\$res); + return $urlValue; + return \$res->hasResource(\$res,sub { return !\$_[0]->is_sequence() },0,0); + + + + + (mark desired resources then click "next" button)
+ + PAGESIZE + return $isNotMap + return '$escapedSequenceName'; + return $symbFilter; + $start_new_option + +
+CHOOSE_FROM_ANY_SEQUENCE + } else { + &Apache::lonxml::xmlparse($r, 'helper', < + Select the sequence to print resources from: + + CHOOSE_FROM_ANY_SEQUENCE + return &Apache::lonprintout::printable_sequence(\$res); return $urlValue; return \$res->hasResource(\$res,sub { return !\$_[0]->is_sequence() },0,0); @@ -3817,7 +4976,7 @@ CHOOSE_FROM_SUBDIR (mark desired resources then click "next" button)
+ closeallpages="1" modallink="1" suppressNavmap="1" $nocurrloc> PAGESIZE return $isNotMap return '$escapedSequenceName'; @@ -3826,10 +4985,59 @@ CHOOSE_FROM_SUBDIR
CHOOSE_FROM_ANY_SEQUENCE -} + } + } + my $numchoices = 0; + if (ref($printChoices) eq 'ARRAY') { + $numchoices = @{$printChoices}; + } + # Early out if nothing to print + if (!$numchoices) { + $r->print(&Apache::loncommon::start_page('Printing Helper'). + '

'.&mt('Unable to determine print context').'

'. + '

'.&mt('Please display a resource, and then click the "Print" button/icon').'

'); + my $prtspool=$r->dir_config('lonPrtDir'); + my $footer = &recently_generated($prtspool); + $r->print($footer.&Apache::loncommon::end_page()); + return OK; + } # Generate the first state, to select which resources get printed. Apache::lonhelper::state->new("START", "Select Printing Options:"); + if (!$res_printable) { + my $noprintmsg; + if ($res_error) { + $noprintmsg = &mt('Print availability for current resource could not be determined'); + } else { + my $now = time; + my $shownprintstart = &Apache::lonlocal::locallocaltime($res_printstartdate); + my $shownprintend = &Apache::lonlocal::locallocaltime($res_printenddate); + if (($res_printenddate) && ($res_printenddate < $now)) { + $noprintmsg = &mt('Printing for current resource no longer available (ended: [_1])', + $shownprintend); + } else { + if (($res_printstartdate) && ($res_printstartdate > $now)) { + if (($res_printenddate) && ($res_printenddate > $now) && ($res_printenddate > $res_printstartdate)) { + $noprintmsg = &mt('Printing for current resource is only possible between [_1] and [_2]', + $shownprintstart,$shownprintend); + } elsif (!$res_printenddate) { + $noprintmsg = &mt('Printing for current resource will only be possible starting [_1]', + $shownprintstart); + } else { + $noprintmsg = &mt('Printing for current resource is unavailable'); + } + } + } + } + + if ($noprintmsg) { + $paramHash = Apache::lonhelper::getParamHash(); + $paramHash->{MESSAGE_TEXT} = + '

'.$noprintmsg.'

'; + Apache::lonhelper::message->new(); + } + } + $paramHash = Apache::lonhelper::getParamHash(); $paramHash = Apache::lonhelper::getParamHash(); $paramHash->{MESSAGE_TEXT} = ""; Apache::lonhelper::message->new(); @@ -3841,7 +5049,7 @@ CHOOSE_FROM_ANY_SEQUENCE my $startedTable = 0; # have we started an HTML table yet? (need # to close it later) - if (($perm{'pav'} and &Apache::lonnet::allowed('vgr',$env{'request.course.id'})) or + if (($perm{'pav'} and $perm{'vgr'}) or ($helper->{VARS}->{'construction'} eq '1')) { &addMessage('
' .'

'.&mt('Print Options').'

' @@ -3853,8 +5061,8 @@ CHOOSE_FROM_ANY_SEQUENCE ) ); $paramHash = Apache::lonhelper::getParamHash(); - $paramHash->{'variable'} = 'ANSWER_TYPE'; - $helper->declareVar('ANSWER_TYPE'); + $paramHash->{'variable'} = 'ANSWER_TYPE'; + $helper->declareVar('ANSWER_TYPE'); $paramHash->{CHOICES} = [ ['Without Answers', 'yes'], ['With Answers', 'no'], @@ -3872,8 +5080,8 @@ CHOOSE_FROM_ANY_SEQUENCE &addMessage(&Apache::lonhtmlcommon::row_title(&mt('Font Size'))); my $xmlfrag = << "FONT_SELECTION"; - - + + return 'normalsize'; @@ -3909,11 +5117,11 @@ FONT_SELECTION ); } $paramHash = Apache::lonhelper::getParamHash(); - $paramHash->{'variable'} = 'LATEX_TYPE'; - $helper->declareVar('LATEX_TYPE'); - if ($helper->{VARS}->{'construction'} eq '1') { + $paramHash->{'variable'} = 'LATEX_TYPE'; + $helper->declareVar('LATEX_TYPE'); + if ($helper->{VARS}->{'construction'} eq '1') { $paramHash->{CHOICES} = [ - ['standard LaTeX mode', 'standard'], + ['standard LaTeX mode', 'standard'], ['LaTeX batchmode', 'batchmode'], ]; } else { $paramHash->{CHOICES} = [ @@ -3921,7 +5129,7 @@ FONT_SELECTION ['standard LaTeX mode', 'standard'] ]; } Apache::lonhelper::dropdown->new(); - + &addMessage(&Apache::lonhtmlcommon::row_closure() .&Apache::lonhtmlcommon::row_title( ' @@ -4086,12 +5294,14 @@ PROBTYPE # If we're in the "final" state, bailout and return to handler if ($helper->{STATE} eq 'FINAL') { return $helper; - } + } - $r->print($helper->display()); + my $footer; if ($helper->{STATE} eq 'START') { - &recently_generated($r); + my $prtspool=$r->dir_config('lonPrtDir'); + $footer = &recently_generated($prtspool); } + $r->print($helper->display($footer)); &Apache::lonhelper::unregisterHelperTags(); return OK; @@ -4108,10 +5318,10 @@ package Apache::lonprintout::page_format See lonhelper.pm documentation for discussion of the helper framework. -Apache::lonprintout::page_format_state is an element that gives the -user an opportunity to select the page layout they wish to print -with: Number of columns, portrait/landscape, and paper size. If you -want to change the paper size choices, change the @paperSize array +Apache::lonprintout::page_format_state is an element that gives the +user an opportunity to select the page layout they wish to print +with: Number of columns, portrait/landscape, and paper size. If you +want to change the paper size choices, change the @paperSize array contents in this package. page_format_state is always directly invoked in lonprintout.pm, so there @@ -4135,17 +5345,17 @@ use Apache::lonnet; my $maxColumns = 2; # it'd be nice if these all worked -#my @paperSize = ("letter [8 1/2x11 in]", "legal [8 1/2x14 in]", +#my @paperSize = ("letter [8 1/2x11 in]", "legal [8 1/2x14 in]", # "tabloid (ledger) [11x17 in]", "executive [7 1/2x10 in]", -# "a2 [420x594 mm]", "a3 [297x420 mm]", "a4 [210x297 mm]", +# "a2 [420x594 mm]", "a3 [297x420 mm]", "a4 [210x297 mm]", # "a5 [148x210 mm]", "a6 [105x148 mm]" ); -my @paperSize = ("letter [8 1/2x11 in]", "legal [8 1/2x14 in]", +my @paperSize = ("letter [8 1/2x11 in]", "legal [8 1/2x14 in]", "a4 [210x297 mm]"); # Tentative format: Orientation (L = Landscape, P = portrait) | Colnum | # Paper type -sub new { +sub new { my $self = Apache::lonhelper::element->new(); shift; @@ -4167,10 +5377,10 @@ sub render { my $PaperType=&mt('Paper type'); my $landscape=&mt('Landscape'); my $portrait=&mt('Portrait'); - my $pdfFormLabel=&mt('PDF-Formfields'); - my $with=&mt('with Formfields'); - my $without=&mt('without Formfields'); - + my $pdfFormLabel=&mt('PDF Form Fields'); + my $with=&mt('with Form Fields'); + my $without=&mt('without Form Fields'); + $result.='

'.&mt('Layout Options').'

' .&Apache::loncommon::start_data_table() @@ -4237,7 +5447,7 @@ sub postprocess { my $var = $self->{'variable'}; my $helper = Apache::lonhelper->getHelper(); - $helper->{VARS}->{$var} = + $helper->{VARS}->{$var} = $env{"form.$var.layout"} . '|' . $env{"form.$var.cols"} . '|' . $env{"form.$var.paper"} . '|' . $env{"form.$var.pdfFormFields"}; return 1; @@ -4253,7 +5463,7 @@ package Apache::lonprintout::page_size_s See lonhelper.pm documentation for discussion of the helper framework. -Apache::lonprintout::page_size_state is an element that gives the +Apache::lonprintout::page_size_state is an element that gives the user the opportunity to further refine the page settings if they select a single-column page. @@ -4276,7 +5486,7 @@ use strict; -sub new { +sub new { my $self = Apache::lonhelper::element->new(); shift; # disturbs me (probably prevents subclassing) but works (drops @@ -4286,7 +5496,7 @@ sub new { my $helper = Apache::lonhelper::getHelper(); $helper->declareVar($self->{'variable'}); - # The variable name of the format element, so we can look into + # The variable name of the format element, so we can look into # $helper->{VARS} to figure out whether the columns are one or two $self->{'formatvar'} = shift; @@ -4326,7 +5536,7 @@ sub render { $size{'height_and_units'}, $size{'margin_and_units'})= &Apache::lonprintout::page_format($papersize, $laystyle, $cols); - + foreach my $dimension ('width','height','margin') { ($size{$dimension},$size{$dimension.'_unit'}) = split(/ +/, $size{$dimension.'_and_units'},2); @@ -4411,10 +5621,10 @@ sub preprocess { foreach my $dim ('width', 'height', 'lmargin') { my ($value, $units) = split(/ /, $size{$dim}); - + $helper->{VARS}->{"$var.".$dim} = $value; $helper->{VARS}->{"$var.".$dim.'unit'} = $units; - + } @@ -4422,7 +5632,7 @@ sub preprocess { $helper->changeState($self->{NEXTSTATE}); } - + return 1; } @@ -4431,16 +5641,16 @@ 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 + # /^-?[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]*)?$/) { @@ -4470,7 +5680,5 @@ sub postprocess { } } - - __END__