--- loncom/interface/lonprintout.pm 2010/04/19 10:29:40 1.575 +++ loncom/interface/lonprintout.pm 2011/04/25 16:59:54 1.587 @@ -2,7 +2,7 @@ # The LearningOnline Network # Printout # -# $Id: lonprintout.pm,v 1.575 2010/04/19 10:29:40 foxr Exp $ +# $Id: lonprintout.pm,v 1.587 2011/04/25 16:59:54 foxr Exp $ # # Copyright Michigan State University Board of Trustees # @@ -196,14 +196,19 @@ sub generate_code_selector {


Generate new CODEd Assignments

' @@ -1743,11 +1783,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() .'' @@ -1755,9 +1794,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; } # @@ -2123,7 +2162,6 @@ ENDPART &Apache::lonnet::delenv('construct.style'); } - if ($helper->{'VARS'}->{'PRINT_TYPE'} eq 'current_document') { #-- single document - problem, page, html, xml, ... my ($currentURL,$cleanURL); @@ -2293,9 +2331,9 @@ ENDPART ($helper->{'VARS'}->{'PRINT_TYPE'} eq 'all_problems') or ($helper->{'VARS'}->{'PRINT_TYPE'} eq 'all_resources') or # BUGBUG ($helper->{'VARS'}->{'PRINT_TYPE'} eq 'select_sequences') - ) { - + ) { + #-- produce an output string if (($helper->{'VARS'}->{'PRINT_TYPE'} eq 'map_problems') or ($helper->{'VARS'}->{'PRINT_TYPE'} eq 'map_problems_in_page') ) { @@ -2358,7 +2396,13 @@ ENDPART &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$/) || + ($helper->{'VARS'}->{'PRINT_TYPE'} eq 'map_problems_in_page') || + ($helper->{'VARS'}->{'PRINT_TYPE'} eq 'map_resources_in_page')))) { + $flag_latex_header_remove = 'YES'; + } } $texversion.=&ssi_with_retries($urlp, $ssi_retry_count, %form); if ($urlp=~/\.page$/) { @@ -2366,7 +2410,7 @@ ENDPART 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')) { @@ -2378,13 +2422,22 @@ 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=~/\.(problem|exam|quiz|assess|survey|form|library|page)$/) { $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 '; @@ -2450,7 +2503,11 @@ ENDPART 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'; @@ -2473,7 +2530,7 @@ ENDPART } $result .= $texversion; $flag_latex_header_remove = 'YES'; - } + } if (&Apache::loncommon::connection_aborted($r)) { last; } @@ -2574,7 +2631,8 @@ ENDPART $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 (&Apache::loncommon::connection_aborted($r)) { last; } } @@ -2647,8 +2705,9 @@ ENDPART my ($type) = split(/_/,$helper->{'VARS'}->{'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'); @@ -2948,7 +3007,7 @@ sub print_resources { $i++; if ( !($type eq 'problems' && - ($curresline!~ m/\.(problem|exam|quiz|assess|survey|form|library)$/)) ) { + ($curresline!~ m/\.(problem|exam|quiz|assess|survey|form|library|page)$/)) ) { my ($map,$id,$res_url) = &Apache::lonnet::decode_symb($curresline); if (&Apache::lonnet::allowed('bre',$res_url)) { if ($res_url!~m|^ext/| @@ -2957,6 +3016,18 @@ 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 ($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. @@ -2974,7 +3045,9 @@ sub print_resources { 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 '; @@ -3035,7 +3108,9 @@ sub print_resources { if (&Apache::loncommon::connection_aborted($r)) { last; } } - + if ($syllabus_first) { + $current_output =~ s/\\\\ Last updated:/Last updated:/ + } my $courseidinfo = &get_course(); my $currentassignment=&Apache::lonxml::latex_special_symbols($helper->{VARS}->{'assignment'},'header'); my $header_line = @@ -3044,11 +3119,8 @@ sub print_resources { my $header_start = ($columns_in_format == 1) ? '\lhead' : '\fancyhead[LO]'; $header_line = $header_start.'{'.$header_line.'}'; - if ($current_output=~/\\documentclass/ && (!$syllabus_first)) { + if ($current_output=~/\\documentclass/) { $current_output =~ s/\\begin{document}/\\setlength{\\topmargin}{1cm} \\begin{document}\\noindent\\parbox{\\minipagewidth}{\\noindent$header_line$namepostfix}\\vskip 5 mm /; - } elsif ($syllabus_first) { - - $current_output =~ s/\\\\ Last updated:/Last updated:/ } else { my $blankpages = '\clearpage\strut\clearpage'x$helper->{'VARS'}->{'EMPTY_PAGES'}; @@ -3121,6 +3193,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 { @@ -3533,27 +3610,15 @@ ALL_PROBLEMS $map, $isProblem, '', $symbFilter, $start_new_option); - $resource_selector .= < -
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_resource_chooser('CHOOSE_STUDENTS_PAGE', + 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') ) { + $secpdfoption = 'Each PDF contains exactly one section'; + } + $resource_selector .= &generate_format_selector($helper, + 'How should results be printed?'). + &generate_resource_chooser('CHOOSE_STUDENTS_PAGE', 'Select Problem(s) to print', "multichoice='1' addstatus='1' closeallpages ='1'", 'RESOURCES', @@ -3681,28 +3746,12 @@ RESOURCE_SELECTOR $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 + my $nextstate = 'NUMBER_PER_PDF'; + $resource_selector .= &generate_format_selector($helper, + 'Format of the print job', + $nextstate); &Apache::lonxml::xmlparse($r, 'helper', < @@ -3723,7 +3772,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'} && !\$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; @@ -228,6 +233,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,6 +256,37 @@ CHOOSE_ANON1 return $result; } +sub generate_format_selector { + my ($helper,$title,$nextstate) = @_; + 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') ) { + $secpdfoption = 'Each PDF contains exactly one section'; + } + return < + $nextstate +
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 +} + #----------------------------------------------------------------------- @@ -1553,7 +1591,9 @@ sub print_page_in_course { my $title=&Apache::lonnet::gettitle($symb); $title = &Apache::lonxml::latex_special_symbols($title); } else { - $result.=$currentURL; + my $esc_currentURL= $currentURL; + $esc_currentURL =~ s/_/\\_/g; + $result.=$esc_currentURL; } $result .= '\\\\'; @@ -1583,7 +1623,7 @@ sub print_page_in_course { } # these resources go through the XML transformer: - elsif ($resource_src =~ /\.(problem|exam|quiz|assess|survey|form|library|page|xml|html|htm\xhtml|xhtm)$/) { + elsif ($resource_src =~ /\.(problem|exam|quiz|assess|survey|form|library|xml|html|htm|xhtml|xhtm)$/) { my $urlp = &Apache::lonnet::clutter($resource_src); my %form; my %moreenv; @@ -1594,7 +1634,7 @@ sub print_page_in_course { $form{'grade_target'} = 'tex'; $form{'textwidth'} = &get_textwidth($helper, $LaTeXwidth); - $form{'pdfFormFiels'} = $pdfFormFields; # + $form{'pdfFormFields'} = $pdfFormFields; # $form{'showallfoils'} = $helper->{'VARS'}->{'showallfoils'}; $form{'problem_split'}=$parmhash{'problem_stream_switch'}; @@ -1698,8 +1738,8 @@ 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); @@ -1732,10 +1772,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)').'
Number of CODEd assignments to print: - + if (((\$helper->{'VARS'}{'NUMBER_TO_PRINT_TOTAL'}+0) < 1) && !\$helper->{'VARS'}{'REUSE_OLD_CODES'} && @@ -3731,6 +3780,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; @@ -3754,6 +3807,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. } @@ -3854,7 +3909,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').'

' @@ -4101,10 +4156,12 @@ PROBTYPE 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;