--- loncom/interface/lonprintout.pm 2009/08/25 10:57:18 1.560.2.2 +++ loncom/interface/lonprintout.pm 2009/10/27 10:17:18 1.563 @@ -1,7 +1,8 @@ +# # 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.563 2009/10/27 10:17:18 foxr Exp $ # # Copyright Michigan State University Board of Trustees # @@ -89,7 +90,6 @@ sub generate_student_chooser { $sort_choice, $variable, $next_state) = @_; - my $result = < Select sorting order of printout @@ -111,6 +111,144 @@ 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) = @_; + + 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; +} +# +# Generate the helper XML for a code choice helper dialog: +# +# Paramters: +# $helper - Reference to the helper. +# $state - Name of the state for the chooser. +# $next_state - Name fo the state to follow the chooser. +# $bubble_types - Populates the bubble sheet type dropt down. +# $code_selections - Provides set of code choices that have been used +# $saved_codes - Provides the list of saved codes. +# +# Returns; +# The Xml of the code chooser. +# +sub generate_code_selector { + my ($helper, + $state, + $next_state, + $bubble_types, + $code_selections, + $saved_codes) = @_; # Unpack the parameters. + + my $result = < + $next_state +

Fill out one of the forms below

+


+

Generate new CODEd Assignments

+
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'}) { + return "You need to specify the number of assignments to print"; + } + return undef; + + +
+ Names to save the CODEs under for later: + + +
+ Bubble sheet type: + + + $bubble_types + +
+
+

Print a Specific CODE


+
Enter a CODE to print: + + + if(!\$helper->{'VARS'}{'NUMBER_TO_PRINT_TOTAL'} && + !\$helper->{'VARS'}{'REUSE_OLD_CODES'} && + !\$helper->{'VARS'}{'CODE_SELECTED_FROM_LIST'}) { + return &Apache::lonprintout::is_code_valid(\$helper->{'VARS'}{'SINGLE_CODE'}, + \$helper->{'VARS'}{'CODE_OPTION'}); + } else { + return undef; # Other forces control us. + } + + +
+ $code_selections +
+

Reprint a Set of Saved CODEs

+ Select saved CODEs: + + + $saved_codes + +
+ +CHOOSE_ANON1 + + return $result; +} + #----------------------------------------------------------------------- @@ -1125,9 +1263,9 @@ sub page_format_transformation { if ($selectionmade eq '4') { if ($choice eq 'all_problems') { - $assignment='Problems from the Whole Course'; + $assignment=&mt('Problems from the Whole Course'); } else { - $assignment='Resources from the Whole Course'; + $assignment=&mt('Resources from the Whole Course'); } } else { $assignment=&Apache::lonxml::latex_special_symbols($assignment,'header'); @@ -1604,7 +1742,7 @@ sub recently_generated { # A reference to a page break hash. # # -use Data::Dumper; +# use Data::Dumper; #sub dump_helper_vars { # my ($helper) = @_; # my $helpervars = Dumper($helper->{'VARS'}); @@ -2022,7 +2160,6 @@ ENDPART } elsif (($helper->{'VARS'}->{'PRINT_TYPE'} eq 'map_problems_pages') or ($helper->{'VARS'}->{'PRINT_TYPE'} eq 'map_resources_in_page')) { - &Apache::lonnet::logthis("Selectionmade => 3"); $selectionmade = 3; } elsif (($helper->{'VARS'}->{'PRINT_TYPE'} eq 'all_problems') ) { @@ -2066,7 +2203,6 @@ ENDPART $urlp=&Apache::lonnet::clutter($urlp); $form{'symb'}=$master_seq[$i]; - &Apache::lonnet::logthis("Element $i Sequence $sequence Middle $middle_thingy URLP $urlp"); my $assignment=&Apache::lonxml::latex_special_symbols(&Apache::lonnet::gettitle($sequence),'header'); #title of the assignment which contains this problem if ($selectionmade==7) {$helper->{VARS}->{'assignment'}=$assignment;} @@ -2074,17 +2210,11 @@ ENDPART my $texversion=''; if ($urlp!~m|^/adm/| && $urlp=~/\.(problem|exam|quiz|assess|survey|form|library|page|xml|html|htm|xhtml|xhtm)$/) { - &Apache::lonnet::logthis("Problem"); $resources_printed .= $urlp.':'; &Apache::lonxml::remember_problem_counter(); - &Apache::lonnet::logthis("Fetching tex for $urlp"); - my $debug = Dumper(%form); - &Apache::lonnet::logthis("Form: $debug"); $texversion.=&ssi_with_retries($urlp, $ssi_retry_count, %form); - &Apache::lonnet::logthis("texversion so far: $texversion"); if ($urlp=~/\.page$/) { - &Apache::lonnet::("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}/; @@ -2106,7 +2236,6 @@ ENDPART $texversion=~s/(\\keephidden{ENDOFPROBLEM})/$answer$1/; } else { if ($urlp=~/\.(problem|exam|quiz|assess|survey|form|library)$/) { - &Apache::lonnet::logthis("problem printing"); $texversion=&print_latex_header($helper->{'VARS'}->{'LATEX_TYPE'}); $texversion =~ s/\\begin{document}//; my $title = &Apache::lonnet::gettitle($master_seq[$i]); @@ -2152,7 +2281,6 @@ ENDPART } } $result .= $texversion; - &Apache::lonnet::logthis("About to set rem header true with $result"); $flag_latex_header_remove = 'YES'; } elsif ($urlp=~/\/(smppg|syllabus|aboutme|bulletinboard)$/) { $form{'latex_type'}=$helper->{'VARS'}->{'LATEX_TYPE'}; @@ -2209,6 +2337,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 +2345,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'; @@ -2255,7 +2385,8 @@ ENDPART my @master_seq=split /\|\|\|/, $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); @@ -2303,6 +2434,7 @@ ENDPART &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') ) { my $cdom =$env{'course.'.$env{'request.course.id'}.'.domain'}; my $cnum =$env{'course.'.$env{'request.course.id'}.'.num'}; @@ -2659,7 +2791,6 @@ sub print_resources { # postscript. Each ENDOFSTUDENTSTAMP will go on a line by itself. # - foreach my $curresline (@{$master_seq}) { if (defined $page_breaks{$curresline}) { if($i != 0) { @@ -2678,7 +2809,6 @@ 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); - 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,12 +2836,12 @@ sub print_resources { $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/; } + my $junk; if ($remove_latex_header eq 'YES') { $rendered = &latex_header_footer_remove($rendered); } else { @@ -2994,7 +3124,6 @@ sub printHelper { } else { $url = $helper->{VARS}->{'postdata'}; $is_published=1; # From resource space. - &Apache::lonnet::logthis("Resource url $url"); } $url = &Apache::lonnet::clutter($url); if (!$resourceTitle) { # if the resource doesn't have a title, use the filename @@ -3064,52 +3193,53 @@ sub printHelper { my $varspostdata = $helper->{VARS}->{'postdata'}; my $varsassignment = $helper->{VARS}->{'assignment'}; my $page_navmap = Apache::lonnavmaps::navmap->new(); - my @page_resources = $page_navmap->retrieveResources($url); - if(defined($page_resources[0])) { - $page_ispage = $page_resources[0]->is_page(); - $page_title = $page_resources[0]->title(); - my $resourcesymb = $page_resources[0]->symb(); - my ($pagemap, $pageid, $pageurl) = &Apache::lonnet::decode_symb($symb); - if ($page_ispage) { - push @{$printChoices}, - [&mt('Selected [_1]Problems[_2] from page [_3]', '', '', ''.$page_title.''), - 'map_problems_in_page', - 'CHOOSE_PROBLEMS_PAGE']; - push @{$printChoices}, - [&mt('Selected [_1]Resources[_2] from page [_3]', '', '', ''.$page_title.''), - 'map_resources_in_page', - 'CHOOSE_RESOURCES_PAGE']; - } - my $helperFragment = < - - PAGESIZE - return $isProblem; - $url - return $symbFilter; - $start_new_option - - + if (defined($page_navmap)) { + my @page_resources = $page_navmap->retrieveResources($url); + if(defined($page_resources[0])) { + $page_ispage = $page_resources[0]->is_page(); + $page_title = $page_resources[0]->title(); + my $resourcesymb = $page_resources[0]->symb(); + my ($pagemap, $pageid, $pageurl) = &Apache::lonnet::decode_symb($symb); + if ($page_ispage) { + push @{$printChoices}, + [&mt('Selected [_1]Problems[_2] from page [_3]', '', '', ''.$page_title.''), + 'map_problems_in_page', + 'CHOOSE_PROBLEMS_PAGE']; + push @{$printChoices}, + [&mt('Selected [_1]Resources[_2] from page [_3]', '', '', ''.$page_title.''), + 'map_resources_in_page', + 'CHOOSE_RESOURCES_PAGE']; + } + 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 @@ -3121,30 +3251,24 @@ HELPERFRAGMENT push @{$printChoices}, [&mt('Selected [_1]Resources[_2] from folder [_3]','','',''.$sequenceTitle.''), '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 +3282,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 +3292,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 +3330,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_page', 'CHOOSE_ANON1_PAGE']; } push @{$printChoices}, [&mt('Selected [_1]Problems[_2] from folder [_3] for [_4]selected people[_5]', '','',''.$sequenceTitle.'','',''), @@ -3233,20 +3355,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 +3383,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'}; @@ -3348,63 +3465,31 @@ RESOURCE_SELECTOR if ($codechoice eq '') { $codechoice='Default'; } - &Apache::lonxml::xmlparse($r, 'helper', < - SELECT_PROBLEMS -

Fill out one of the forms below

-


-

Generate new CODEd Assignments

-
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'}) { - return "You need to specify the number of assignments to print"; - } - return undef; - - -
- Names to save the CODEs under for later: - - -
- Bubble sheet type: - - - $codechoice - -
-
-

Print a Specific CODE


-
Enter a CODE to print: - - - if(!\$helper->{'VARS'}{'NUMBER_TO_PRINT_TOTAL'} && - !\$helper->{'VARS'}{'REUSE_OLD_CODES'} && - !\$helper->{'VARS'}{'CODE_SELECTED_FROM_LIST'}) { - return &Apache::lonprintout::is_code_valid(\$helper->{'VARS'}{'SINGLE_CODE'}, - \$helper->{'VARS'}{'CODE_OPTION'}); - } else { - return undef; # Other forces control us. - } - - -
- $code_selection -
-

Reprint a Set of Saved CODEs

- Select saved CODEs: - - - $namechoice - -
- - $resource_selector -CHOOSE_ANON1 + 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'}) { @@ -3416,7 +3501,6 @@ CHOOSE_ANON1 $resource_selector=< $randomly_ordered_warning - PRINT_FORMATTING
Select resources for the assignment
+ NUMBER_PER_PDF
How should the results be printed?