--- loncom/interface/lonprintout.pm 2012/12/08 20:10:26 1.625 +++ loncom/interface/lonprintout.pm 2014/02/08 23:49:12 1.639 @@ -1,7 +1,7 @@ # The LearningOnline Network # Printout # -# $Id: lonprintout.pm,v 1.625 2012/12/08 20:10:26 raeburn Exp $ +# $Id: lonprintout.pm,v 1.639 2014/02/08 23:49:12 raeburn Exp $ # # Copyright Michigan State University Board of Trustees # @@ -27,7 +27,6 @@ # package Apache::lonprintout; use strict; -use POSIX; use Apache::Constants qw(:common :http); use Apache::lonxml; use Apache::lonnet; @@ -47,7 +46,6 @@ use File::Basename; use HTTP::Response; use LONCAPA::map(); -use POSIX qw(ctime); use Apache::lonlocal; use Carp; use LONCAPA; @@ -149,8 +147,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) = @_; @@ -495,7 +492,7 @@ RESOURCE_SELECTOR # # @return ($open, $close) # -# @note If open/close dates are not defined they will be retunred as undef +# @note If open/close dates are not defined they will be returned as undef # @note It is possible for there to be no overlap in which case -1,-1 # will be returned. # @note The algorithm used is to take the latest open date and the earliest end date. @@ -525,7 +522,7 @@ sub compute_open_window { # If no overlap...both are -1 as promised. - if (defined($earliest_close) && defined($latest_open) + if (($earliest_close ne '') && ($latest_open ne '') && ($earliest_close < $latest_open)) { $latest_open = -1; $earliest_close = -1; @@ -573,11 +570,13 @@ sub printable { # # @return (opendate, closedate) # -# @note If open/close dates are not defined they will be retunred as undef +# @note If open/close dates are not defined they will be returned as undef # @note It is possible for there to be no overlap in which case -1,-1 # will be returned. # @note The algorithm used is to take the latest open date and the earliest end date. -# +# For consistency with &printable() in lonnavmaps.pm determination of start +# date for printing checks printstartdate param first, then, if not set, +# opendate param, then, if not set, contentopen param. sub get_print_dates { my $res = shift; @@ -596,7 +595,18 @@ sub get_print_dates { foreach my $part (@parts) { my $partopen = $res->parmval('printstartdate', $part); my $partclose = $res->parmval('printenddate', $part); - + if (!$partopen) { + $partopen = $res->parmval('opendate',$part); + } + if (!$partopen) { + $partopen = $res->parmval('contentopen',$part); + } + if ($partopen) { + push(@open_dates, $partopen); + } + if ($partclose) { + push(@close_dates, $partclose); + } push(@open_dates, $partopen); push(@close_dates, $partclose); } @@ -604,13 +614,6 @@ sub get_print_dates { ($open_date, $close_date) = &compute_open_window(\@open_dates, \@close_dates); - if ($open_date) { - $open_date = POSIX::strftime('%D', localtime($open_date)); - } - if ($close_date) { - $close_date = POSIX::strftime('%D', localtime($close_date)); - } - return ($open_date, $close_date); } @@ -705,11 +708,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,34 +724,40 @@ sub incomplete { # print_resources. # sub master_seq_to_person_seq { - my ($helper, $seq, $who, $code) = @_; + my ($map, $seq, $who, $code, $nohidemap) = @_; 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 $unhidden; + if ($perm{'pav'} && $perm{'vgr'} && $nohidemap) { + $unhidden = &Apache::lonnet::clutter($map); + } - my ($map, $id, $url) = &Apache::lonnet::decode_symb($helper->{VARS}->{'symb'}); my $navmap = Apache::lonnavmaps::navmap->new($username, $userdomain, - $code); - 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 + $code, $unhidden); + 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 @@ -757,15 +769,13 @@ 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. @@ -1099,7 +1109,7 @@ sub format_page_header { # there is '\\ \\ ' in the page header. That's cause a error in LaTeX if($format =~ /\\\\\s\\\\\s/) { #TODO find sensible caption for page header - my $testPrintout = '\\\\'.&mt('Construction Space').' \\\\'.&mt('Test-Printout '); + my $testPrintout = '\\\\'.&mt('Authoring Space').' \\\\'.&mt('Test-Printout '); $format =~ s/\\\\\s\\\\\s/$testPrintout/; } # @@ -2212,7 +2222,7 @@ sub print_page_in_course { $texversion.=&path_to_problem($urlp,$LaTeXwidth); } else { $texversion.='\vskip 0 mm \noindent\textbf{'. - &mt("Printing from Construction Space: No Title").'}\vskip 0 mm '; + &mt("Printing from Authoring Space: No Title").'}\vskip 0 mm '; $texversion.=&path_to_problem($urlp,$LaTeXwidth); } $texversion.='\vskip 1 mm '.$answer.'\end{document}'; @@ -2793,7 +2803,7 @@ ENDPART $texversion.=&path_to_problem($cleanURL,$LaTeXwidth); } else { $texversion.='\vskip 0 mm \noindent\textbf{'. - &mt("Printing from Construction Space: No Title").'}\vskip 0 mm '; + &mt("Printing from Authoring Space: No Title").'}\vskip 0 mm '; $texversion.=&path_to_problem($cleanURL,$LaTeXwidth); } @@ -3145,6 +3155,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'; @@ -3179,7 +3195,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, undef, 1); my ($output,$fullname, $printed)=&print_resources($r,$helper, $person,$type, \%moreenv, $actual_seq, @@ -3221,16 +3238,16 @@ ENDPART } } } - my ($randomorder,$randompick); + 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)) { - my ($map,$id,$resource) = - &Apache::lonnet::decode_symb($helper->{VARS}{'symb'}); if ($map) { - my $res = $navmap->getResourceByUrl($map); - $randomorder = $res->randomorder(); - $randompick = $res->randompick(); + my $mapres = $navmap->getResourceByUrl($map); + $randomorder = $mapres->randomorder(); + $randompick = $mapres->randompick(); } } } @@ -3296,10 +3313,11 @@ ENDPART $moreenv{'CODE'}=&num_to_letters($code); } my $actual_seq = \@master_seq; - if ($randomorder) { + if ($randomorder || $randompick) { $env{'form.CODE'} = $moreenv{'CODE'}; - $actual_seq = master_seq_to_person_seq($helper,\@master_seq,undef, - $moreenv{'CODE'}); + $actual_seq = master_seq_to_person_seq($map, \@master_seq, + undef, + $moreenv{'CODE'}, 1); delete($env{'form.CODE'}); } my ($output,$fullname, $printed)= @@ -3357,7 +3375,7 @@ ENDPART $texversion.=&path_to_problem ($urlp,$LaTeXwidth); } else { $texversion.='\vskip 0 mm \noindent\textbf{'. - &mt("Printing from Construction Space: No Title").'}\vskip 0 mm '; + &mt("Printing from Authoring Space: No Title").'}\vskip 0 mm '; $texversion.=&path_to_problem ($urlp,$LaTeXwidth); } $texversion.='\vskip 1 mm '.$answer.'\end{document}'; @@ -3594,6 +3612,7 @@ sub print_resources { # my $syllabus_first = 0; + my $assessment_first = 0; my $current_assignment = ""; my $assignment; my $courseidinfo = &get_course(); @@ -3615,7 +3634,11 @@ sub print_resources { if ($print_incomplete && !&incomplete($username, $userdomain, $res_url)) { next; } + if ((!$actually_printed) && ($curresline =~ m/$LONCAPA::assess_re/)) { + $assessment_first = 1; + } $actually_printed++; # we're going to print one. + if (&Apache::lonnet::allowed('bre',$res_url)) { if ($res_url!~m|^ext/| && $res_url=~/\.(problem|exam|quiz|assess|survey|form|library|page|xml|html|htm|xhtml|xhtm)$/) { @@ -3748,31 +3771,27 @@ sub print_resources { if ($syllabus_first) { $current_output =~ s/\\\\ Last updated:/Last updated:/ } - if (0) { + my $newheader; + unless ($assessment_first) { 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.'}'; + $newheader = $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$namepostfix}\\vskip 5 mm /; + $current_output =~ s/\\begin{document}/\\setlength{\\topmargin}{1cm} \\begin{document}\\noindent\\parbox{\\minipagewidth}{\\noindent$newheader$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' - .$namepostfix. '} \vskip 5 mm '.$current_output; + '\setcounter{page}{1}\noindent\parbox{\minipagewidth}{\noindent'. + $newheader.$namepostfix. '} \vskip 5 mm '.$current_output; } # @@ -4041,7 +4060,7 @@ sub printHelper { &Apache::lonenc::check_encrypt(&Apache::lonnet::clutter($url)); my $navmap = Apache::lonnavmaps::navmap->new(); my $res = $navmap->getBySymb($symb); - $res_printable = $res->resprintable() | $userCanPrint; #printability in course context + $res_printable = $res->resprintable() || $userCanPrint; #printability in course context ($res_printstartdate, $res_printenddate) = &get_print_dates($res); ($course_open, $course_close) = &course_print_dates($res); ($map_open, $map_close) = &map_print_dates($res); @@ -4121,13 +4140,13 @@ sub printHelper { my $start_new_option; if ($perm{'pav'}) { $start_new_option = - "