--- loncom/interface/lonprintout.pm 2018/10/02 19:25:30 1.627.2.25 +++ loncom/interface/lonprintout.pm 2023/01/17 18:09:25 1.627.2.32.2.3 @@ -1,7 +1,7 @@ # The LearningOnline Network # Printout # -# $Id: lonprintout.pm,v 1.627.2.25 2018/10/02 19:25:30 raeburn Exp $ +# $Id: lonprintout.pm,v 1.627.2.32.2.3 2023/01/17 18:09:25 raeburn Exp $ # # Copyright Michigan State University Board of Trustees # @@ -848,8 +848,8 @@ sub set_font_size { if ($font_size ne '') { $text =~ s/\\begin\{document}/\\begin{document}{\\$font_size/; + $text =~ s/\\end\{document}/}\\end{document}/; } - $text =~ s/\\end\{document}/}\\end{document}/; return $text; @@ -1238,7 +1238,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]; @@ -1344,8 +1344,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; @@ -2076,16 +2076,28 @@ sub get_textwidth { sub unsupported { my ($currentURL,$mode,$symb)=@_; + my $cleanURL=&Apache::lonenc::check_decrypt($currentURL); + my $shown = $currentURL; + if (($cleanURL ne $currentURL) || ($symb =~ m{/^enc/})) { + $shown = &mt('URL not shown (encrypted)'); + } if ($mode ne '') {$mode='\\'.$mode} - 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.' '; + my $result = &print_latex_header($mode); + if ($cleanURL=~m|^(/adm/wrapper/)?ext/|) { + $cleanURL=~s|^(/adm/wrapper/)?ext/|http://|; + $cleanURL=~s|^http://https://|https://|; + if ($shown eq $currentURL) { + $shown = &Apache::lonxml::latex_special_symbols($cleanURL); + } + my $title=&Apache::lonnet::gettitle($symb); + $title = &Apache::lonxml::latex_special_symbols($title); + $result.=' \strut \\\\ \textit{'.$title.'} \strut \\\\ '.$shown.' '; } else { - $result.=$currentURL; + if ($shown eq $currentURL) { + $result.=&Apache::lonxml::latex_special_symbols($currentURL); + } else { + $result.=$shown; + } } $result.= '\vskip 0.5mm\noindent\makebox[\textwidth/$number_of_columns][b]{\hrulefill} \end{document}'; return $result; @@ -2123,19 +2135,12 @@ sub print_page_in_course { $numberofcolumns); my $LaTeXwidth=&recalcto_mm($textwidth); - if ($mode ne '') {$mode='\\'.$mode} my $result = &print_latex_header($mode); - if ($currentURL=~m|^(/adm/wrapper/)?ext/|) { - $currentURL=~s|^(/adm/wrapper/)?ext/|http://|; - my $title=&Apache::lonnet::gettitle($symb); - $title = &Apache::lonxml::latex_special_symbols($title); - } else { - my $esc_currentURL= $currentURL; - $esc_currentURL =~ s/_/\\_/g; - $result.=$esc_currentURL; - } - $result .= '\\\\'; + + my $title=&Apache::lonnet::gettitle($currentURL); + $title = &Apache::lonxml::latex_special_symbols($title); + $result .= '\noindent\textit{'.$title.'}\\\\'; if ($helper->{'VARS'}->{'style_file'}=~/\w/) { &Apache::lonnet::appenv({'construct.style' => @@ -2151,7 +2156,7 @@ sub print_page_in_course { foreach my $resource (@page_resources) { my $resource_src = $resource->src(); # Essentially the URL of the resource. - $result .= $resource->title() . '\\\\'; + my $current_url = $resource->link(); # Recurse if a .page: @@ -2161,11 +2166,10 @@ sub print_page_in_course { $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: - - elsif ($resource_src =~ /\.(problem|exam|quiz|assess|survey|form|library|xml|html|htm|xhtml|xhtm)$/) { + $result.=&latex_header_footer_remove(&unsupported($current_url,$mode,$resource->symb)); + } elsif ($resource_src =~ /\.(problem|exam|quiz|assess|survey|form|library|xml|html|htm|xhtml|xhtm)$/) { + # these resources go through the XML transformer: + $result .= &Apache::lonxml::latex_special_symbols($resource->title()) . '\\\\'; my $urlp = &Apache::lonnet::clutter($resource_src); @@ -2549,7 +2553,7 @@ sub print_construction_sequence { my $body ='\vskip 0 mm \noindent\textbf{'.$title.'}\vskip 0 mm '; $body.=&path_to_problem($urlp,$LaTeXwidth); $body.='\vskip 1 mm '.$answer.'\end{document}'; - $body = &encapsulate_minipage($body); + $body = &encapsulate_minipage($body,$answerform{'problem_split'}); $texversion.=$body; } } @@ -2941,7 +2945,6 @@ ENDPART &Apache::lonenc::reset_enc(); - # Note due to document structure, not allowed to put \newpage # prior to the first resource @@ -3014,7 +3017,7 @@ ENDPART my $body ='\vskip 0 mm \noindent\textbf{'.$title.'}\vskip 0 mm '; $body .= &path_to_problem ($urlp,$LaTeXwidth); $body .='\vskip 1 mm '.$answer; - $body = &encapsulate_minipage($body); + $body = &encapsulate_minipage($body,$answerform{'problem_split'}); $texversion .= $body; } else { $texversion=''; @@ -3228,7 +3231,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'}; @@ -3237,10 +3240,10 @@ 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); + next if (($line =~ /^\#/) || ($line eq '')); my ($name,$type,$length,$bubbles_per_item) = (split(/:/,$line))[0,2,4,17]; if ($name eq $code_option) { @@ -3252,18 +3255,10 @@ ENDPART } } } - my ($randomorder,$randompick,$map); + my $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'}; @@ -3332,14 +3327,11 @@ ENDPART } else { $moreenv{'CODE'}=&num_to_letters($code); } - my $actual_seq = \@master_seq; - if ($randomorder || $randompick) { - $env{'form.CODE'} = $moreenv{'CODE'}; - $actual_seq = master_seq_to_person_seq($map, \@master_seq, - undef, - $moreenv{'CODE'}, $nohidemap); - delete($env{'form.CODE'}); - } + $env{'form.CODE'} = $moreenv{'CODE'}; + my $actual_seq = master_seq_to_person_seq($map, \@master_seq, + undef, + $moreenv{'CODE'}, $nohidemap); + delete($env{'form.CODE'}); my ($output,$fullname, $printed)= &print_resources($r,$helper,'anonymous',$type,\%moreenv, $actual_seq,$flag_latex_header_remove, @@ -3354,7 +3346,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'}; @@ -3455,12 +3447,38 @@ ENDPART $URLback=$helper->{'VARS'}->{'filename'}; } elsif ($helper->{VARS}{'symb'}) { my ($map, $id, $url) = &Apache::lonnet::decode_symb($helper->{VARS}{'symb'}); + my $cdom =$env{'course.'.$env{'request.course.id'}.'.domain'}; + my $cnum =$env{'course.'.$env{'request.course.id'}.'.num'}; + my ($anchor,$usehttp,$plainurl); $url = &Apache::lonnet::clutter($url); + $plainurl = $url; + if (($ENV{'SERVER_PORT'} == 443) && ($env{'request.course.id'}) && + (($url =~ m{^\Q/public/$cdom/$cnum/syllabus\E($|\?)}) || + ($url =~ m{^\Q/adm/wrapper/ext/\E(?!https:)}))) { + unless ((&Apache::lonnet::uses_sts()) || (&Apache::lonnet::waf_allssl())) { + $usehttp = 1; + } + } if ($env{'request.enc'}) { $url = &Apache::lonenc::encrypted($url); } if ($url ne '') { - $URLback = $url.(($url =~ /\?/) ? '&':'?').'symb='.$helper->{VARS}{'symb'}; + my $symb = $helper->{VARS}{'symb'}; + if ($url =~ m{^\Q/adm/wrapper/ext/\E}) { + my $link = $url; + ($link,$anchor) = ($url =~ /^([^\#]+)(?:|(\#[^\#]+))$/); + if ($anchor) { + ($symb) = ($helper->{VARS}{'symb'} =~ /^([^\#]+)/); + } + $url = $link; + } + $URLback = $url; + if ($usehttp) { + $URLback .= (($URLback =~ /\?/) ? '&':'?').'usehttp=1'; + } + unless ($plainurl =~ /\.page$/) { + $URLback .= (($URLback =~ /\?/) ? '&':'?').'symb='.&escape($symb.$anchor); + } } } # @@ -3714,7 +3732,7 @@ sub print_resources { my $body ='\vskip 0 mm \noindent\textbf{'.$title.'}\vskip 0 mm '; $body .=&path_to_problem($res_url,$LaTeXwidth); $body .='\vskip 1 mm '.$ansrendered; - $body = &encapsulate_minipage($body); + $body = &encapsulate_minipage($body,$answerenv{'problem_split'}); $rendered = $header.$body; } } @@ -3804,7 +3822,7 @@ sub print_resources { $message = &mt('No incomplete resources'); } if ($message) { - $current_output = &encapsulate_minipage("\\vskip -10mm \n$message\n \\vskip 100 mm { }\n"); + $current_output = &encapsulate_minipage("\\vskip -10mm \n$message\n \\vskip 100 mm { }\n",$moreenv->{'problem_split'}); } if ($remove_latex_header eq "NO") { $current_output = &print_latex_header() . $current_output; @@ -3865,8 +3883,9 @@ sub handler { if ($env{'request.course.id'}) { my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'}; my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'}; + my $clientip = &Apache::lonnet::get_requestor_ip($r); my ($blocked,$blocktext) = - &Apache::loncommon::blocking_status('printout',$cnum,$cdom); + &Apache::loncommon::blocking_status('printout',$clientip,$cnum,$cdom); if ($blocked) { my $checkrole = "cm./$cdom/$cnum"; if ($env{'request.course.sec'} ne '') { @@ -4053,20 +4072,16 @@ sub printHelper { $helper->{VARS}->{'symb'} = $env{'form.symb'}; } if ($env{'form.url'}) { - $helper->{VARS}->{'symb'} = &Apache::lonnet::symbread($helper->{VARS}->{'postdata'}); + unless ($env{'form.url'} eq '/adm/navmaps') { + $helper->{VARS}->{'symb'} = &Apache::lonnet::symbread($helper->{VARS}->{'postdata'}); + } } - - } - - if ($env{'form.symb'}) { - $helper->{VARS}->{'symb'} = $env{'form.symb'}; } - if ($env{'form.url'}) { - $helper->{VARS}->{'symb'} = &Apache::lonnet::symbread($helper->{VARS}->{'postdata'}); + if ($helper->{VARS}->{'symb'} ne '') { + $helper->{VARS}->{'symb'}= + &Apache::lonenc::check_encrypt($helper->{VARS}->{'symb'}); } - $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;} @@ -4287,7 +4302,7 @@ sub printHelper { if ($userCanPrint || &printable($map_open, $map_close)) { push(@{$printChoices}, - [&mt('Selected [_1]Incomplete Problems[_2] from folder [_3]' . $textSuffix, + [&mt('Selected [_1]Incomplete Problems[_2] from folder [_3]' . $textSuffix, '', '', ''. $sequenceTitle . ''), $printSelector, @@ -4337,7 +4352,8 @@ sub printHelper { # BZ 5209 - incomplete problems from entire course: push(@{$printChoices}, - [&mtn('Selected Incomplete Problems from entire course for selected people'), + [&mt('Selected [_1]Incomplete Problems[_2] from [_3]entire course[_4] for [_5]selected people[_6]', + '','','','','',''), 'incomplete_problems_selpeople_course', 'INCOMPLETE_PROBLEMS_COURSE_RESOURCES']); my $helperFragment = &create_incomplete_course_helper($helper); # Create needed states. @@ -4345,9 +4361,9 @@ sub printHelper { # Selected problems/resources from entire course: - push @{$printChoices}, [&mtn('Selected Problems from entire course'), 'all_problems', 'ALL_PROBLEMS']; - push @{$printChoices}, [&mtn('Selected Resources from entire course'), 'all_resources', 'ALL_RESOURCES']; - push @{$printChoices}, [&mtn('Selected Problems from entire course for selected people'), 'all_problems_students', 'ALL_PROBLEMS_STUDENTS']; + push @{$printChoices}, [&mt('Selected [_1]Problems[_2] from [_3]entire course[_4]','','','',''), 'all_problems', 'ALL_PROBLEMS']; + push @{$printChoices}, [&mt('Selected [_1]Resources[_2] from [_3]entire course[_4]','','','',''), 'all_resources', 'ALL_RESOURCES']; + push @{$printChoices}, [&mt('Selected [_1]Problems[_2] from [_3]entire course[_4] for [_5]selected people[_6]','','','','','',''), 'all_problems_students', 'ALL_PROBLEMS_STUDENTS']; my $suffixXml = < Select sorting order of printout @@ -4501,9 +4517,10 @@ ALL_PROBLEMS } - my @lines = &Apache::grades::get_scantronformat_file(); + 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 && @@ -4681,8 +4698,9 @@ CHOOSE_FROM_SUBDIR # Allow the user to select any sequence in the course, feed it to # another resource selector for that sequence if (!$helper->{VARS}->{'construction'} && !$is_published) { - push @$printChoices, [&mtn("Selected Resources from selected folder in course"), - 'select_sequences', 'CHOOSE_SEQUENCE']; + push(@$printChoices, [&mt('Selected [_1]Resources[_2] from [_3]selected folder[_4] in course', + '','','',''), + 'select_sequences', 'CHOOSE_SEQUENCE']); my $escapedSequenceName = $helper->{VARS}->{'SEQUENCE'}; #Escape apostrophes and backslashes for Perl $escapedSequenceName =~ s/\\/\\\\/g; @@ -4701,7 +4719,7 @@ CHOOSE_FROM_SUBDIR (mark desired resources then click "next" button)
+ closeallpages="1" modallink="1" suppressNavmap="1"> PAGESIZE return $isNotMap return '$escapedSequenceName'; @@ -4712,6 +4730,21 @@ 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) { @@ -4791,7 +4824,7 @@ CHOOSE_FROM_ANY_SEQUENCE my $xmlfrag = << "FONT_SELECTION"; - + return 'normalsize';