--- loncom/interface/lonprintout.pm 2012/11/20 12:01:54 1.621 +++ loncom/interface/lonprintout.pm 2013/01/04 01:27:31 1.627.2.3 @@ -1,7 +1,7 @@ # The LearningOnline Network # Printout # -# $Id: lonprintout.pm,v 1.621 2012/11/20 12:01:54 foxr Exp $ +# $Id: lonprintout.pm,v 1.627.2.3 2013/01/04 01:27:31 raeburn Exp $ # # Copyright Michigan State University Board of Trustees # @@ -149,8 +149,7 @@ sub printable_sequence { # Return: # XML that can be parsed by the helper to drive the state machine. # -sub create_incomplete_folder_selstud_helper($helper) -{ +sub create_incomplete_folder_selstud_helper { my ($helper, $map) = @_; @@ -705,11 +704,14 @@ sub incomplete { # to only those that are in the original set selcted to be printed. # # Parameters: -# $helper - The helper we need $helper->{'VARS'}->{'symb'} -# to construct the navmap and the iteration. -# $seq - The original set of resources to print +# $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 # # Implicit inputs: # $ @@ -718,33 +720,35 @@ sub incomplete { # print_resources. # sub master_seq_to_person_seq { - my ($helper, $seq, $who) = @_; + my ($map, $seq, $who, $code) = @_; 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 ($map, $id, $url) = &Apache::lonnet::decode_symb($helper->{VARS}->{'symb'}); - my $navmap = Apache::lonnavmaps::navmap->new($username, $userdomain); - my $iterator = $navmap->getIterator($navmap->firstResource(), - $navmap->finishResource(), - {}, 1); - my %nonResourceItems = ( - $iterator->BEGIN_MAP => 1, - $iterator->BEGIN_BRANCH => 1, - $iterator->END_BRANCH => 1, - $iterator->END_MAP => 1, - $iterator->FORWARD => 1, - $iterator->BACKWARD => 1 + my $navmap = Apache::lonnavmaps::navmap->new($username, $userdomain, + $code); + 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(); + } - ); # These items are not resources but appear in the midst of iteration. + my $iterator = $navmap->getIterator($start,$finish,{},1); # Iterate on the resource..select the items that are randomly selected # and that are in the seq_has. Presumably the iterator will take care @@ -756,15 +760,14 @@ sub master_seq_to_person_seq { # Only process resources..that are not removed by randomout... # and are selected for printint as well. # - - if (! exists $nonResourceItems{$curres} && ! $curres->randomout()) { - my $symb = $curres->symb(); - if (exists $seq_hash{$symb}) { - push(@output_seq, $symb); + + if (ref($curres) && ! $curres->randomout()) { + my $currsymb = $curres->symb(); + if (exists($seq_hash{$currsymb})) { + push(@output_seq, $currsymb); } } } - return \@output_seq; # for now. @@ -1044,12 +1047,12 @@ sub printf_style_subst { # %s - The section if it is supplied. # sub format_page_header { - my ($width, $format, $assignment, $course, $student, $section) = @_; + my ($width, $format, $assignment, $course, $student) = @_; $width = &recalcto_mm($width); # Get width in mm. - my $chars_per_line = int($width/1.6); # Character/textline. + my $chars_per_line = int($width/2); # Character/textline. # Default format? @@ -1065,34 +1068,38 @@ sub format_page_header { # - Allow the assignment to be 2 lines (wrapped). # - + my $firstline = "$student $course"; + if (length($firstline) > $chars_per_line) { + my $lastchar = $chars_per_line - length($student) - 1; + if ($lastchar > 0) { + $course = substr($course, 0, $lastchar); + } else { # Nothing left of course: + $course = ''; + } + } + if (length($assignment) > $chars_per_line) { + $assignment = substr($assignment, 0, $chars_per_line); + } - my $name_length = int($chars_per_line *3 /4); - my $sec_length = int($chars_per_line / 5); + $format = "\\textbf{$student} $course \\hfill \\thepage \\\\ \\textit{$assignment}"; - $format = "%$name_length".'n'; + } else { + # An open question is how to handle long user formatted page headers... + # A possible future is to support e.g. %na so that the user can control + # the truncation of the elements that can appear in the header. + # + $format = &printf_style_subst("a", $format, $assignment); + $format = &printf_style_subst("c", $format, $course); + $format = &printf_style_subst("n", $format, $student); + + # 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 ($section) { - $format .= ' - Sec: '."%$sec_length".'s'; - } + } - $format .= '\\\\%c \\\\ %a'; - + return $format; - } - # An open question is how to handle long user formatted page headers... - # A possible future is to support e.g. %na so that the user can control - # the truncation of the elements that can appear in the header. - # - $format = &printf_style_subst("a", $format, $assignment); - $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 @@ -1828,8 +1835,6 @@ sub get_course { my $courseidinfo; 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; } @@ -1852,6 +1857,7 @@ sub page_format_transformation { my $name = &get_name(); my $courseidinfo = &get_course(); + if (defined($courseidinfo)) { $courseidinfo=' - '.$courseidinfo } my $header_text = $parmhash{'print_header_format'}; $header_text = &format_page_header($textwidth, $header_text, $assignment, $courseidinfo, $name); @@ -2060,6 +2066,7 @@ sub unsupported { my $result.= &print_latex_header($mode); if ($currentURL=~m|^(/adm/wrapper/)?ext/|) { $currentURL=~s|^(/adm/wrapper/)?ext/|http://|; + $currentURL=~s|^http://https://|https://|; my $title=&Apache::lonnet::gettitle($symb); $title = &Apache::lonxml::latex_special_symbols($title); $result.=' \strut \\\\ '.$title.' \strut \\\\ '.$currentURL.' '; @@ -2139,6 +2146,8 @@ sub print_page_in_course { my @page_resources = $navmap->retrieveResources($resource_src); $result .= &print_page_in_course($helper, $rparmhash, $resource_src, \@page_resources); + } elsif ($resource->ext()) { + $result .= &unsupported($currentURL,$mode,$symb); } # these resources go through the XML transformer: @@ -2155,7 +2164,7 @@ sub print_page_in_course { $form{'grade_target'} = 'tex'; $form{'textwidth'} = &get_textwidth($helper, $LaTeXwidth); - $form{'pdfFormFields'} = $pdfFormFields; # + $form{'pdfFormFields'} = 'no'; # $form{'showallfoils'} = $helper->{'VARS'}->{'showallfoils'}; $form{'problem_split'}=$parmhash{'problem_stream_switch'}; @@ -2605,7 +2614,6 @@ sub print_construction_sequence { # For item 100, filtering was done at the helper level. sub output_data { - &Apache::lonnet::logthis("outptu_data"); my ($r,$helper,$rparmhash) = @_; my %parmhash = %$rparmhash; @@ -2692,7 +2700,7 @@ ENDPART my %form; $form{'grade_target'} = 'tex'; $form{'textwidth'} = &get_textwidth($helper, $LaTeXwidth); - $form{'pdfFormFields'} = $pdfFormFields; + $form{'pdfFormFields'} = 'no'; # If form.showallfoils is set, then request all foils be shown: # privilege will be enforced both by not allowing the @@ -2880,8 +2888,6 @@ ENDPART ($print_type eq 'select_sequences') or ($print_type eq 'map_incomplete_problems_seq') ) { - &Apache::lonnet::logthis("map_problems maybe"); - &Apache::lonnet::logthis($print_type eq 'map_problems' ? " Yes" : "No"); #-- produce an output string if (($print_type eq 'map_problems') or @@ -3018,6 +3024,7 @@ ENDPART if (($selectionmade == 4) and ($assignment ne $prevassignment)) { my $name = &get_name(); my $courseidinfo = &get_course(); + if (defined($courseidinfo)) { $courseidinfo=' - '.$courseidinfo } $prevassignment=$assignment; my $header_text = $parmhash{'print_header_format'}; $header_text = &format_page_header($textwidth, $header_text, @@ -3144,6 +3151,12 @@ ENDPART } my @master_seq=split /\|\|\|/, $helper->{'VARS'}->{'RESOURCES'}; + my $map; + if ($helper->{VARS}->{'symb'}) { + ($map, my $id, my $resource) = + &Apache::lonnet::decode_symb($helper->{VARS}->{'symb'}); + } + #loop over students my $flag_latex_header_remove = 'NO'; @@ -3178,7 +3191,8 @@ ENDPART } else { $i=int($student_counter/$helper->{'VARS'}{'NUMBER_TO_PRINT'}); } - my $actual_seq = master_seq_to_person_seq($helper, \@master_seq, $person); + my $actual_seq = master_seq_to_person_seq($map, \@master_seq, + $person); my ($output,$fullname, $printed)=&print_resources($r,$helper, $person,$type, \%moreenv, $actual_seq, @@ -3204,7 +3218,6 @@ 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,$bubbles_per_row)=('letter',6,10); @@ -3221,6 +3234,19 @@ ENDPART } } } + my ($randomorder,$randompick,$map); + if ($helper->{VARS}{'symb'}) { + ($map, my $id, my $resource) = + &Apache::lonnet::decode_symb($helper->{VARS}{'symb'}); + my $navmap = Apache::lonnavmaps::navmap->new(); + if (defined($navmap)) { + if ($map) { + my $mapres = $navmap->getResourceByUrl($map); + $randomorder = $mapres->randomorder(); + $randompick = $mapres->randompick(); + } + } + } my %moreenv = ('textwidth' => &get_textwidth($helper,$LaTeXwidth)); $moreenv{'problem_split'} = $parmhash{'problem_stream_switch'}; $moreenv{'instructor_comments'}='hide'; @@ -3282,9 +3308,17 @@ ENDPART } else { $moreenv{'CODE'}=&num_to_letters($code); } + my $actual_seq = \@master_seq; + if ($randomorder) { + $env{'form.CODE'} = $moreenv{'CODE'}; + $actual_seq = master_seq_to_person_seq($map, \@master_seq, + undef, + $moreenv{'CODE'}); + 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; @@ -3577,6 +3611,8 @@ sub print_resources { my $current_assignment = ""; my $assignment; my $courseidinfo = &get_course(); + if (defined($courseidinfo)) { $courseidinfo=' - '.$courseidinfo } + if ($usersection ne '') {$courseidinfo.=' - Sec. '.$usersection} foreach my $curresline (@{$master_seq}) { if (defined $page_breaks{$curresline}) { @@ -3700,7 +3736,7 @@ sub print_resources { if (($assignment ne $current_assignment) && ($assignment ne "")) { my $header_line = &format_page_header($LaTeXwidth, $parmhash{'print_header_format'}, $assignment, $courseidinfo, - $fullname, $usersection); + $fullname); my $header_start = ($columns_in_format == 1) ? '\lhead' : '\fancyhead[LO]'; $header_line = $header_start.'{'.$header_line.'}'; @@ -3732,7 +3768,7 @@ sub print_resources { 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); + $currentassignment, $courseidinfo, $fullname); my $header_start = ($columns_in_format == 1) ? '\lhead' : '\fancyhead[LO]'; $header_line = $header_start.'{'.$header_line.'}'; @@ -3802,7 +3838,6 @@ sub handler { } &init_perm(); - &Apache::lonnet::logthis("Handler"); my $helper = printHelper($r); if (!ref($helper)) { return $helper; @@ -4629,8 +4664,8 @@ CHOOSE_FROM_ANY_SEQUENCE if (!$res_printable) { $paramHash = Apache::lonhelper::getParamHash(); $paramHash->{MESSAGE_TEXT} = - &mt('

Printing for current resource is only possible between [_1] and [_1]

', - $res_printstartdate, $res_printenddate); + &mt('[_1]Printing for current resource is only possible between [_2] and [_3]', + '

',$res_printstartdate, $res_printenddate.'

'); Apache::lonhelper::message->new(); } $paramHash = Apache::lonhelper::getParamHash(); @@ -4973,9 +5008,6 @@ 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'); $result.='

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

' @@ -4984,7 +5016,6 @@ sub render { .''.$PageLayout.'' .''.$NumberOfColumns.'' .''.$PaperType.'' - .''.$pdfFormLabel.'' .&Apache::loncommon::end_data_table_header_row() .&Apache::loncommon::start_data_table_row() .'' @@ -5025,12 +5056,6 @@ sub render { $result .= < - - - HTML $result.=&Apache::loncommon::end_data_table_row() .&Apache::loncommon::end_data_table();