--- loncom/interface/lonprintout.pm 2009/08/25 10:57:18 1.560.2.2 +++ loncom/interface/lonprintout.pm 2009/10/12 10:59:48 1.560.2.5 @@ -1,7 +1,10 @@ +# + + # The LearningOnline Network # Printout # -# $Id: lonprintout.pm,v 1.560.2.2 2009/08/25 10:57:18 foxr Exp $ +# $Id: lonprintout.pm,v 1.560.2.5 2009/10/12 10:59:48 foxr Exp $ # # Copyright Michigan State University Board of Trustees # @@ -89,7 +92,7 @@ sub generate_student_chooser { $sort_choice, $variable, $next_state) = @_; - + &Apache::lonnet::logthis("Student chooser next state: $next_state, this state: $this_state"); my $result = < Select sorting order of printout @@ -111,6 +114,65 @@ CHOOSE_STUDENTS return $result; } +# Generate the text needed for a resource chooser given the top level of +# the sequence/page +# +# Parameters: +# 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'" +# that control the selection and appearance of the +# resource selector. +# variable - Name of the variable to hold the choice +# next_state - Name of the next state the helper should transition +# to +# top_url - Top level URL within which to make the selector. +# If empty the top level sequence is shown. +# filter - How to filter the resources. +# value_func - function. +# choice_func - If not empty generates a with this function. +# start_new_option +# - Fragment appended after valuefunc. +# +# +sub generate_resource_chooser { + my ($this_state, + $prompt_text, + $resource_options, + $variable, + $next_state, + $top_url, + $filter, + $choice_func, + $value_func, + $start_new_option) = @_; + + &Apache::lonnet::logthis("Top URL = $top_url"); + my $result = < + + $next_state + return $filter; +CHOOSE_RESOURCES + if ($choice_func ne '') { + $result .= "return $choice_func;"; + } + if ($top_url ne '') { + $result .= "$top_url"; + } + $result .= <return $value_func; + $start_new_option + + +CHOOSE_RESOURCES + + return $result; +} + + #----------------------------------------------------------------------- @@ -2084,7 +2146,7 @@ ENDPART $texversion.=&ssi_with_retries($urlp, $ssi_retry_count, %form); &Apache::lonnet::logthis("texversion so far: $texversion"); if ($urlp=~/\.page$/) { - &Apache::lonnet::("Special page actions"); + &Apache::lonnet::logthis("Special page actions"); ($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}/; @@ -2128,7 +2190,9 @@ ENDPART } if ($flag_latex_header_remove ne 'NO') { + &Apache::lonnet::logthis("Removing header/footer 1"); $texversion = &latex_header_footer_remove($texversion); + &Apache::lonnet::logthis("With h/f removed we have: $texversion"); } else { $texversion =~ s/\\end{document}//; } @@ -2165,6 +2229,7 @@ ENDPART } if ($flag_latex_header_remove ne 'NO') { + &Apache::lonnet::logthis("Removing header & footer 2"); $texversion = &latex_header_footer_remove($texversion); } else { $texversion =~ s/\\end{document}/\\vskip 0\.5mm\\noindent\\makebox\[\\textwidth\/\$number_of_columns\]\[b\]\{\\hrulefill\}/; @@ -2192,6 +2257,7 @@ ENDPART $texversion=&unsupported($urlp,$helper->{'VARS'}->{'LATEX_TYPE'}, $master_seq[$i]); if ($flag_latex_header_remove ne 'NO') { + &Apache::lonnet::logthis("Removing header/footer 3"); $texversion = &latex_header_footer_remove($texversion); } else { $texversion =~ s/\\end{document}//; @@ -2209,6 +2275,7 @@ ENDPART } $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')){ @@ -2216,6 +2283,7 @@ ENDPART #-- 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') ) { $selectionmade=5; $type='problems'; @@ -2253,9 +2321,11 @@ ENDPART $helper->{'VARS'}->{'NUMBER_TO_PRINT'} = $#students+1; } my @master_seq=split /\|\|\|/, $helper->{'VARS'}->{'RESOURCES'}; + &Apache::lonnet::logthis("RESOURCES: ". $helper->{'VARS'}->{'RESOURCES'}); #loop over students - my $flag_latex_header_remove = 'NO'; + + my $flag_latex_header_remove = 'NO'; my %moreenv; $moreenv{'instructor_comments'}='hide'; $moreenv{'textwidth'}=&get_textwidth($helper,$LaTeXwidth); @@ -2454,6 +2524,7 @@ ENDPART $newurlp=&path_to_problem($newurlp,$LaTeXwidth); $texversion =~ s/(\\begin{minipage}{\\textwidth})/$1 $newurlp/; if ($flag_latex_header_remove ne 'NO') { + &Apache::lonnet::logthis("Removing header/footer: 4"); $texversion = &latex_header_footer_remove($texversion); } else { $texversion =~ s/\\end{document}//; @@ -2658,9 +2729,10 @@ sub print_resources { # so we will just rely on prntout.pl to strip ENDOFSTUDENTSTAMP from the # postscript. Each ENDOFSTUDENTSTAMP will go on a line by itself. # - + &Apache::lonnet::logthis("In print_resources"); foreach my $curresline (@{$master_seq}) { + &Apache::lonnet::logthis("Res: $curresline"); if (defined $page_breaks{$curresline}) { if($i != 0) { $current_output.= "\\newpage\n"; @@ -2678,7 +2750,7 @@ sub print_resources { &Apache::lonxml::remember_problem_counter(); my $rendered = &get_student_view_with_retries($curresline,$ssi_retry_count,$username,$userdomain,$env{'request.course.id'},'tex',$moreenv); - + &Apache::lonnet::logthis("student view: $rendered"); 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. @@ -2706,13 +2778,14 @@ sub print_resources { $rendered = $header.$body; } } - + &Apache::lonnet::logthis("After preprending header: $rendered"); if ($helper->{'VARS'}->{'PRINT_ANNOTATIONS'} eq 'yes') { my $url = &Apache::lonnet::clutter($res_url); my $annotation = &annotate($url); $rendered =~ s/(\\keephidden{ENDOFPROBLEM})/$annotation$1/; } if ($remove_latex_header eq 'YES') { + &Apache::lonnet::logthis("Removing header/footer: 5"); $rendered = &latex_header_footer_remove($rendered); } else { $rendered =~ s/\\end{document}//; @@ -2727,6 +2800,7 @@ sub print_resources { $annotation =~ s/(\\end{document})/$annotation$1/; } if ($remove_latex_header eq 'YES') { + &Apache::lonnet::logthis("Removing header/footer: 6"); $rendered = &latex_header_footer_remove($rendered); } else { $rendered =~ s/\\end{document}//; @@ -2736,12 +2810,14 @@ sub print_resources { my $url = &Apache::lonnet::clutter($res_url); my $rendered = &include_pdf($url); if ($remove_latex_header ne 'NO') { + &Apache::lonnet::logthis("Removing header/footer: 7"); $rendered = &latex_header_footer_remove($rendered); } $current_output .= $rendered; } else { my $rendered = &unsupported($res_url,$helper->{'VARS'}->{'LATEX_TYPE'},$curresline); if ($remove_latex_header ne 'NO') { + &Apache::lonnet::logthis("Removing header/footer: 8"); $rendered = &latex_header_footer_remove($rendered); } else { $rendered =~ s/\\end{document}//; @@ -3080,36 +3156,35 @@ sub printHelper { 'map_resources_in_page', 'CHOOSE_RESOURCES_PAGE']; } - my $helperFragment = < - - PAGESIZE - return $isProblem; - $url - return $symbFilter; - $start_new_option - - + my $helperFragment = &generate_resource_chooser('CHOOSE_PROBLEMS_PAGE', + 'Select Problem(s) to print', + "multichoice='1' toponly='1' addstatus='1' closeallpages='1'", + 'RESOURCES', + 'PAGESIZE', + $url, + $isProblem, '', $symbFilter, + $start_new_option); + + + $helperFragment .= &generate_resource_chooser('CHOOSE_RESOURCES_PAGE', + 'Select Resource(s) to print', + 'multichoice="1" toponly="1" addstatus="1" closeallpages="1"', + 'RESOURCES', + 'PAGESIZE', + $url, + $isNotMap, '', $symbFilter, + $start_new_option); + + + - - - PAGESIZE - return $isNotMap; - $url - return $symbFilter; - $start_new_option - - -HELPERFRAGMENT &Apache::lonxml::xmlparse($r, 'helper', $helperFragment); } } - if (($helper->{'VARS'}->{'construction'} ne '1' ) && + if (($helper->{'VAR'}->{'construction'} ne '1' ) && $helper->{VARS}->{'postdata'} && $helper->{VARS}->{'assignment'}) { # Allow problems from sequence @@ -3122,29 +3197,24 @@ HELPERFRAGMENT 'map_problems_pages', 'CHOOSE_PROBLEMS_HTML']; &Apache::lonnet::logthis("Map url : $map"); - my $helperFragment = < - - PAGESIZE - return $isProblem; - $map - return $symbFilter; - $start_new_option - - - - - - PAGESIZE - return $isNotMap; - $map - return $symbFilter; - $start_new_option - - -HELPERFRAGMENT + my $helperFragment = &generate_resource_chooser('CHOOSE_PROBLEMS', + 'Select Problem(s) to print', + 'multichoice="1" toponly="1" addstatus="1" closeallpages="1"', + 'RESOURCES', + 'PAGESIZE', + $map, + $isProblem, '', + $symbFilter, + $start_new_option); + $helperFragment .= &generate_resource_chooser('CHOOSE_PROBLEMS_HTML', + 'Select Resource(s) to print', + 'multichoice="1" toponly="1" addstatus="1" closeallpages="1"', + 'RESOURCES', + 'PAGESIZE', + $map, + $isNotMap, '', + $symbFilter, + $start_new_option); &Apache::lonxml::xmlparse($r, 'helper', $helperFragment); } @@ -3158,36 +3228,7 @@ HELPERFRAGMENT push @{$printChoices}, [&mtn('Selected Problems from entire course'), 'all_problems', 'ALL_PROBLEMS']; push @{$printChoices}, [&mtn('Selected Resources from entire course'), 'all_resources', 'ALL_RESOURCES']; push @{$printChoices}, [&mtn('Selected Problems from entire course for selected people'), 'all_problems_students', 'ALL_PROBLEMS_STUDENTS']; - &Apache::lonxml::xmlparse($r, 'helper', < - - PAGESIZE - return $isProblemOrMap; - return $isNotMap; - return $symbFilter; - $start_new_option - - - - - PAGESIZE - return $isNotMap; - return $symbFilter; - $start_new_option - - - - - STUDENTS1 - return $isProblemOrMap; - return $isNotMap; - return $symbFilter; - $start_new_option - - +my $suffixXml = < Select sorting order of printout @@ -3197,8 +3238,35 @@ HELPERFRAGMENT


- ALL_PROBLEMS + &Apache::lonxml::xmlparse($r, 'helper', + &generate_resource_chooser('ALL_PROBLEMS', + 'SelectProblem(s) to print', + 'multichoice="1" suppressEmptySequences="0" addstatus="1" closeallpages="1"', + 'RESOURCES', + 'PAGESIZE', + '', + $isProblemOrMap, $isNotMap, + $symbFilter, + $start_new_option) . + &generate_resource_chooser('ALL_RESOURCES', + 'Select Resource(s) to print', + " toponly='0' multichoice='1' suppressEmptySequences='0' addstatus='1' closeallpages='1'", + 'RESOURCES', + 'PAGESIZE', + '', + $isNotMap,'',$symbFilter, + $start_new_option) . + &generate_resource_chooser('ALL_PROBLEMS_STUDENTS', + 'Select Problem(s) to print', + 'toponly="0" multichoice="1" suppressEmptySequences="0" addstatus="1" closeallpages="1"', + 'RESOURCES', + 'STUDENTS1', + '', + $isProblemOrMap,'' , $symbFilter, + $start_new_option) . + $suffixXml + ); if ($helper->{VARS}->{'assignment'}) { @@ -3208,10 +3276,10 @@ ALL_PROBLEMS if ($page_ispage) { push @{$printChoices}, [&mt('Selected [_1]Problems[_2] from page [_3] for [_4]selected people[_5]', '', '', ''.$page_title.'', '', ''), - 'problems_for_students', 'CHOOSE_STUDENTS']; + 'problems_for_students_from_page', 'CHOOSE_TGT_STUDENTS_PAGE']; push @{$printChoices}, [&mt('Selected [_1]Problems[_2] from page [_3] for [_4]CODEd assignments[_5]', '', '', ''.$page_title.'', '', ''), - 'problems_for_anon', 'CHOOSE_ANON1']; + 'problems_for_anon', 'CHOOSE_ANON1_PAGE']; } push @{$printChoices}, [&mt('Selected [_1]Problems[_2] from folder [_3] for [_4]selected people[_5]', '','',''.$sequenceTitle.'','',''), @@ -3233,20 +3301,15 @@ ALL_PROBLEMS # with one state, and use REGEXPs at inclusion time to set state names # and next states for better mix and match capability # - my $resource_selector=< - $randomly_ordered_warning - - PRINT_FORMATTING -
Select resources for the assignment
- - return $isProblem; - $map - return $symbFilter; - $start_new_option - - + my $resource_selector= &generate_resource_chooser('SELECT_PROBLEMS', + 'Select resources to print', + 'multichoice="1" addstatus="1" closeallpages="1"', + 'RESOURCES', + 'PRINT_FORMATTING', + '', + $isProblem, , $symbFilter, + $start_new_option); + $resource_selector .= <
How should the results be printed?
@@ -3266,31 +3329,31 @@ ALL_PROBLEMS RESOURCE_SELECTOR + $resource_selector .= &generate_resource_chooser('CHOOSE_STUDENTS_PAGE', + 'Select Problem(s) to print', + "multichoice='1' addstatus='1' closeallpages ='1'", + 'RESOURCES', + 'PRINT_FORMATTING', + $url, + $isProblem, '', $symbFilter, + $start_new_option); + # Generate student choosers. -# &Apache::lonxml::xmlparse($r, 'helper', < -# Select sorting order of printout -# -# -# -# Sort by section then student -# Sort by students across sections. -# -#


-# -# + &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); -# $resource_selector -# CHOOSE_STUDENTS my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'}; my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'}; @@ -3416,7 +3479,6 @@ CHOOSE_ANON1 $resource_selector=< $randomly_ordered_warning - PRINT_FORMATTING
Select resources for the assignment
+ NUMBER_PER_PDF
How should the results be printed?