--- loncom/interface/lonprintout.pm 2012/05/28 10:31:17 1.616 +++ loncom/interface/lonprintout.pm 2012/11/20 12:03:06 1.622 @@ -1,7 +1,7 @@ # The LearningOnline Network # Printout # -# $Id: lonprintout.pm,v 1.616 2012/05/28 10:31:17 foxr Exp $ +# $Id: lonprintout.pm,v 1.622 2012/11/20 12:03:06 foxr Exp $ # # Copyright Michigan State University Board of Trustees # @@ -102,7 +102,6 @@ sub printable_sequence { if ($res->is_sequence()) { my $symb = $res->symb(); - &Apache::lonnet::logthis("Symb: $symb"); my $navmap = $res->{NAV_MAP}; # Find the first resource in the map: @@ -111,14 +110,7 @@ sub printable_sequence { my $first = $iterator->next(); while (1) { - if ($first == $iterator->END_ITERATOR) { - &Apache::lonnet::logthis("End of iterator"); - last; } - if (ref($first)) { - &Apache::lonnet::logthis("Looking at: " . $first->symb()); - } else { - &Apache::lonnet::logthis("Got: $first"); - } + if ($first == $iterator->END_ITERATOR) { last; } if (ref($first) && ! $first->is_sequence()) {last; } $first = $iterator->next(); } @@ -127,16 +119,11 @@ sub printable_sequence { # Might be an empty map: if (!ref($first)) { - &Apache::lonnet::logthis("printable_sequence: empty"); return 0; } my $partsref = $first->parts(); my @parts = @$partsref; - &Apache::lonnet::logthis("Dates for " . $first->symb()); my ($open, $close) = $navmap->map_printdates($first, $parts[0]); - &Apache::lonnet::logthis("Opens $open, closes $close"); - &Apache::lonnet::logthis(ctime($open)); - &Apache::lonnet::logthis(ctime($close)); return &printable($open, $close); } return 0; @@ -595,14 +582,17 @@ sub printable { sub get_print_dates { my $res = shift; my $partsref = $res->parts(); - my @parts = @$partsref; + my @parts; + if (ref($partsref) eq 'ARRAY') { + @parts = @{$partsref}; + } my $open_date; my $close_date; my @open_dates; my @close_dates; - if (defined(@parts) && (scalar(@parts) > 0)) { + if (@parts) { foreach my $part (@parts) { my $partopen = $res->parmval('printstartdate', $part); my $partclose = $res->parmval('printenddate', $part); @@ -645,7 +635,7 @@ sub course_print_dates { # Don't bother looping over undefined or empty parts arraY; - if (defined(@parts) && (scalar(@parts) > 0)) { + if (@parts) { foreach my $part (@parts) { my ($partopen, $partclose) = $navmap->course_printdates($res, $part); push(@open_dates, $partopen); @@ -671,7 +661,7 @@ sub map_print_dates { # Don't bother looping over undefined or empty parts arraY; - if (defined(@parts) && (scalar(@parts) > 0)) { + if (@parts) { foreach my $part (@parts) { my ($partopen, $partclose) = $navmap->map_printdates($res, $part); push(@open_dates, $partopen); @@ -1246,6 +1236,22 @@ sub is_code_valid { } } +# +# Compare two students by section (Used to sort by section). +# +# Implicit inputs, +# $a - The first one +# $b - The second one. +# +# Returns: +# a-section cmp b-section +# +sub compare_sections { + my ($u1, $d1, $s1, $n1, $stat1) = split(/:/, $a); + my ($u2, $d2, $s2, $n2, $stat2) = split(/:/, $b); + + return $s1 cmp $s2; +} # Compare two students by name. The students are in the form # returned by the helper: @@ -2599,6 +2605,7 @@ sub print_construction_sequence { # For item 100, filtering was done at the helper level. sub output_data { + my ($r,$helper,$rparmhash) = @_; my %parmhash = %$rparmhash; $ssi_error = 0; # This will be set nonzero by failing ssi's. @@ -2872,7 +2879,6 @@ ENDPART ($print_type eq 'select_sequences') or ($print_type eq 'map_incomplete_problems_seq') ) { - #-- produce an output string if (($print_type eq 'map_problems') or @@ -3015,7 +3021,6 @@ ENDPART $assignment, $courseidinfo, $name); - if ($numberofcolumns eq '1') { $result .='\newpage \noindent\parbox{\minipagewidth}{\noindent\\lhead{'.$header_text.'}} \vskip 5 mm '; } else { @@ -3116,6 +3121,8 @@ ENDPART if (($helper->{'VARS'}->{'student_sort'} eq 1) && ($helper->{'VARS'}->{'SPLIT_PDFS'} ne "sections")) { @students = sort compare_names @students; + } else { + @students = sort compare_sections @students; } &adjust_number_to_print($helper); @@ -3525,6 +3532,7 @@ sub print_resources { my $fullname = &get_name($username,$userdomain); my $namepostfix = "\\\\"; # Both anon and not anon should get the same vspace. + # # Figure out if we need to filter the output by # the incomplete problems for that person @@ -3563,6 +3571,10 @@ sub print_resources { # my $syllabus_first = 0; + my $current_assignment = ""; + my $assignment; + my $courseidinfo = &get_course(); + foreach my $curresline (@{$master_seq}) { if (defined $page_breaks{$curresline}) { if($i != 0) { @@ -3571,9 +3583,12 @@ sub print_resources { } $current_output .= &get_extra_vspaces($helper, $curresline); $i++; + my ($map,$id,$res_url) = &Apache::lonnet::decode_symb($curresline); + + # See if we need to emit a new header: + if ( !($type eq 'problems' && ($curresline!~ m/$LONCAPA::assess_page_re/)) ) { - my ($map,$id,$res_url) = &Apache::lonnet::decode_symb($curresline); if ($print_incomplete && !&incomplete($username, $userdomain, $res_url)) { next; } @@ -3677,6 +3692,19 @@ sub print_resources { } $remove_latex_header = 'YES'; } + $assignment = &Apache::lonxml::latex_special_symbols( + &Apache::lonnet::gettitle($map), 'header'); + if (($assignment ne $current_assignment) && ($assignment ne "")) { + my $header_line = &format_page_header($LaTeXwidth, $parmhash{'print_header_format'}, + $assignment, $courseidinfo, + $fullname, $usersection); + my $header_start = ($columns_in_format == 1) ? '\lhead' + : '\fancyhead[LO]'; + $header_line = $header_start.'{'.$header_line.'}'; + $current_output = $current_output . $header_line; + $current_assignment = $assignment; + } + if (&Apache::loncommon::connection_aborted($r)) { last; } } # If we are printing incomplete it's possible we don't have @@ -3697,24 +3725,32 @@ sub print_resources { 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 = - &format_page_header($LaTeXwidth, $parmhash{'print_header_format'}, - $currentassignment, $courseidinfo, $fullname, $usersection); - my $header_start = ($columns_in_format == 1) ? '\lhead' - : '\fancyhead[LO]'; - $header_line = $header_start.'{'.$header_line.'}'; + if (0) { + 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); + my $header_start = ($columns_in_format == 1) ? '\lhead' + : '\fancyhead[LO]'; + $header_line = $header_start.'{'.$header_line.'}'; + } if ($current_output=~/\\documentclass/) { - $current_output =~ s/\\begin{document}/\\setlength{\\topmargin}{1cm} \\begin{document}\\noindent\\parbox{\\minipagewidth}{\\noindent$header_line$namepostfix}\\vskip 5 mm /; +# $current_output =~ s/\\begin{document}/\\setlength{\\topmargin}{1cm} \\begin{document}\\noindent\\parbox{\\minipagewidth}{\\noindent$header_line$namepostfix}\\vskip 5 mm /; + $current_output =~ s/\\begin{document}/\\setlength{\\topmargin}{1cm} \\begin{document}\\noindent\\parbox{\\minipagewidth}{\\noindent$namepostfix}\\vskip 5 mm /; + } else { my $blankpages = '\clearpage\strut\clearpage'x$helper->{'VARS'}->{'EMPTY_PAGES'}; - + +# $current_output = '\strut\vspace*{-6 mm}\\newline'. +# ©right_line().' \newpage '.$blankpages.$end_of_student. +# '\setcounter{page}{1}\noindent\parbox{\minipagewidth}{\noindent'. +# $header_line.$namepostfix. '} \vskip 5 mm '.$current_output; $current_output = '\strut\vspace*{-6 mm}\\newline'. ©right_line().' \newpage '.$blankpages.$end_of_student. - '\setcounter{page}{1}\noindent\parbox{\minipagewidth}{\noindent'. - $header_line.$namepostfix.'} \vskip 5 mm '.$current_output; + '\setcounter{page}{1}\noindent\parbox{\minipagewidth}{\noindent' + .$namepostfix. '} \vskip 5 mm '.$current_output; + } # # Close the student bracketing. @@ -3763,7 +3799,6 @@ sub handler { } &init_perm(); - my $helper = printHelper($r); if (!ref($helper)) { return $helper; @@ -4182,7 +4217,7 @@ sub printHelper { 'RESOURCES', 'PAGESIZE', $map, - ! $isProblem, '', + $isProblem, '', $symbFilter, $start_new_option); $helperFragment .= &generate_resource_chooser('CHOOSE_PROBLEMS_HTML',