--- loncom/interface/lonprintout.pm 2018/09/02 16:36:29 1.627.2.23 +++ loncom/interface/lonprintout.pm 2019/02/05 19:03:38 1.627.2.23.2.1 @@ -1,7 +1,7 @@ # The LearningOnline Network # Printout # -# $Id: lonprintout.pm,v 1.627.2.23 2018/09/02 16:36:29 raeburn Exp $ +# $Id: lonprintout.pm,v 1.627.2.23.2.1 2019/02/05 19:03:38 raeburn Exp $ # # Copyright Michigan State University Board of Trustees # @@ -1237,7 +1237,7 @@ 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]; @@ -3227,7 +3227,7 @@ ENDPART $result .= $print_array[0].' \end{document}'; } elsif (($print_type eq 'problems_for_anon') || ($print_type eq 'problems_for_anon_page') || - ($print_type eq 'resources_for_anon') ) { + ($print_type eq 'resources_for_anon') ) { my $cdom =$env{'course.'.$env{'request.course.id'}.'.domain'}; my $cnum =$env{'course.'.$env{'request.course.id'}.'.num'}; my $num_todo=$helper->{'VARS'}->{'NUMBER_TO_PRINT_TOTAL'}; @@ -3236,7 +3236,7 @@ ENDPART 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 @lines = &Apache::lonnet::get_scantronformat_file(); my ($code_type,$code_length,$bubbles_per_row)=('letter',6,10); foreach my $line (@lines) { chomp($line); @@ -3353,7 +3353,7 @@ ENDPART } &Apache::lonhtmlcommon::Close_PrgWin($r,\%prog_state); $result .= $print_array[0].' \end{document}'; - } elsif ($print_type eq 'problems_from_directory') { + } elsif ($print_type eq 'problems_from_directory') { #prints selected problems from the subdirectory $selectionmade = 6; my @list_of_files=split /\|\|\|/, $helper->{'VARS'}->{'FILES'}; @@ -4062,10 +4062,11 @@ sub printHelper { } if ($env{'form.url'}) { $helper->{VARS}->{'symb'} = &Apache::lonnet::symbread($helper->{VARS}->{'postdata'}); - } - $helper->{VARS}->{'symb'}= - &Apache::lonenc::check_encrypt($helper->{VARS}->{'symb'}); + if ($helper->{VARS}->{'symb'} ne '') { + $helper->{VARS}->{'symb'}= + &Apache::lonenc::check_encrypt($helper->{VARS}->{'symb'}); + } my ($resourceTitle,$sequenceTitle,$mapTitle) = &details_for_menu($helper); if ($sequenceTitle ne '') {$helper->{VARS}->{'assignment'}=$sequenceTitle;} @@ -4076,6 +4077,7 @@ sub printHelper { my $subdir; my $is_published=0; # True when printing from resource space. my $res_printable = 1; # By default the current resource is printable. + my $res_error; my $userCanPrint = ($perm{'pav'} || $perm{'pfo'}); my $res_printstartdate; my $res_printenddate; @@ -4097,13 +4099,22 @@ sub printHelper { ($map, $id, $url) = &Apache::lonnet::decode_symb($symb); $helper->{VARS}->{'postdata'} = &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_printstartdate, $res_printenddate) = &get_print_dates($res); - ($course_open, $course_close) = &course_print_dates($res); - ($map_open, $map_close) = &map_print_dates($res); - + if (!$userCanPrint) { + my $navmap = Apache::lonnavmaps::navmap->new(); + if (ref($navmap)) { + my $res = $navmap->getBySymb($symb); + if (ref($res)) { + $res_printable = $res->resprintable(); #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); + } else { + $res_error = 1; + } + } else { + $res_error = 1; + } + } } else { # Resource space. @@ -4490,7 +4501,7 @@ ALL_PROBLEMS } - my @lines = &Apache::grades::get_scantronformat_file(); + my @lines = &Apache::lonnet::get_scantronformat_file(); my $codechoice=''; foreach my $line (@lines) { my ($name,$description,$code_type,$code_length)= @@ -4701,26 +4712,45 @@ CHOOSE_FROM_SUBDIR CHOOSE_FROM_ANY_SEQUENCE } + my $numchoices = 0; + if (ref($printChoices) eq 'ARRAY') { + $numchoices = @{$printChoices}; + } + # Early out if nothing to print + if (!$numchoices) { + $r->print(&Apache::loncommon::start_page('Printing Helper'). + '

'.&mt('Unable to determine print context').'

'. + '

'.&mt('Please display a resource, and then click the "Print" button/icon').'

'); + my $prtspool=$r->dir_config('lonPrtDir'); + my $footer = &recently_generated($prtspool); + $r->print($footer.&Apache::loncommon::end_page()); + return OK; + } + # Generate the first state, to select which resources get printed. Apache::lonhelper::state->new("START", "Select Printing Options:"); if (!$res_printable) { - my $now = time; - my $shownprintstart = &Apache::lonlocal::locallocaltime($res_printstartdate); - my $shownprintend = &Apache::lonlocal::locallocaltime($res_printenddate); my $noprintmsg; - if (($res_printenddate) && ($res_printenddate < $now)) { + if ($res_error) { + $noprintmsg = &mt('Print availability for current resource could not be determined'); + } else { + my $now = time; + my $shownprintstart = &Apache::lonlocal::locallocaltime($res_printstartdate); + my $shownprintend = &Apache::lonlocal::locallocaltime($res_printenddate); + if (($res_printenddate) && ($res_printenddate < $now)) { $noprintmsg = &mt('Printing for current resource no longer available (ended: [_1])', $shownprintend); - } else { - if (($res_printstartdate) && ($res_printstartdate > $now)) { - if (($res_printenddate) && ($res_printenddate > $now) && ($res_printenddate > $res_printstartdate)) { - $noprintmsg = &mt('Printing for current resource is only possible between [_1] and [_2]', - $shownprintstart,$shownprintend); - } elsif (!$res_printenddate) { - $noprintmsg = &mt('Printing for current resource will only be possible starting [_1]', - $shownprintstart); - } else { - $noprintmsg = &mt('Printing for current resource is unavailable'); + } else { + if (($res_printstartdate) && ($res_printstartdate > $now)) { + if (($res_printenddate) && ($res_printenddate > $now) && ($res_printenddate > $res_printstartdate)) { + $noprintmsg = &mt('Printing for current resource is only possible between [_1] and [_2]', + $shownprintstart,$shownprintend); + } elsif (!$res_printenddate) { + $noprintmsg = &mt('Printing for current resource will only be possible starting [_1]', + $shownprintstart); + } else { + $noprintmsg = &mt('Printing for current resource is unavailable'); + } } } }