--- loncom/interface/lonprintout.pm 2017/01/29 16:02:29 1.653 +++ loncom/interface/lonprintout.pm 2023/02/08 15:15:24 1.687 @@ -1,7 +1,7 @@ # The LearningOnline Network # Printout # -# $Id: lonprintout.pm,v 1.653 2017/01/29 16:02:29 raeburn Exp $ +# $Id: lonprintout.pm,v 1.687 2023/02/08 15:15:24 raeburn Exp $ # # Copyright Michigan State University Board of Trustees # @@ -143,12 +143,13 @@ sub printable_sequence { # Parameters: # helper - the helper which already contains info about the current folder we can # purloin. -# url - Top url of the sequence +# 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) = @_; + my ($helper, $map, $nocurrloc) = @_; my $symbFilter = '$res->shown_symb()'; @@ -157,7 +158,7 @@ sub create_incomplete_folder_selstud_hel my $resource_chooser = &generate_resource_chooser('CHOOSE_INCOMPLETE_PEOPLE_SEQ', 'Select problem(s) to print', - 'multichoice="1" toponly="1" addstatus="1" closeallpages="1"', + 'multichoice="1" toponly="1" addstatus="1" closeallpages="1" modallink="1" nocurrloc="'.$nocurrloc.'"', 'RESOURCES', 'CHOOSE_STUDENTS_INCOMPLETE', $map, @@ -206,7 +207,7 @@ sub create_incomplete_course_helper { my $resource_chooser = &generate_resource_chooser('INCOMPLETE_PROBLEMS_COURSE_RESOURCES', 'Select problem(s) to print', - 'multichoice = "1" suppressEmptySequences="0" addstatus="1" closeallpagtes="1"', + 'multichoice = "1" suppressEmptySequences="0" addstatus="1" closeallpagtes="1" modallink="1"', 'RESOURCES', 'INCOMPLETE_PROBLEMS_COURSE_STUDENTS', '', @@ -235,6 +236,7 @@ sub create_incomplete_course_helper { # 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. # @@ -242,7 +244,7 @@ sub create_incomplete_course_helper { # CHOOSE_INCOMPLETE_SEQ - Resource selector. # sub create_incomplete_folder_helper { - my ($helper, $map) = @_; + my ($helper, $map, $nocurrloc) = @_; my $filter = '$res->is_problem()'; $filter .= ' && $res->resprintable() '; @@ -252,7 +254,7 @@ sub create_incomplete_folder_helper { my $resource_chooser = &generate_resource_chooser('CHOOSE_INCOMPLETE_SEQ', 'Select problem(s) to print', - 'multichoice="1", toponly ="1", addstatus="1", closeallpages="1"', + 'multichoice="1", toponly ="1", addstatus="1", closeallpages="1" modallink="1" nocurrloc="'.$nocurrloc.'"', 'RESOURCES', 'PAGESIZE', $map, @@ -306,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 @@ -443,6 +446,134 @@ 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/navmpas 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) @@ -457,7 +588,9 @@ sub generate_format_selector { 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 '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 <>$Apache::lonnet::perlvar{'lonPrtDir'}/$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); @@ -1232,8 +1366,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; @@ -1337,8 +1472,8 @@ sub latex_header_footer_remove { # 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; @@ -1956,7 +2091,7 @@ sub latex_corrections { $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\\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,'