--- loncom/interface/lonprintout.pm 2018/12/29 21:21:56 1.665 +++ loncom/interface/lonprintout.pm 2022/02/09 15:46:57 1.675 @@ -1,7 +1,7 @@ # The LearningOnline Network # Printout # -# $Id: lonprintout.pm,v 1.665 2018/12/29 21:21:56 raeburn Exp $ +# $Id: lonprintout.pm,v 1.675 2022/02/09 15:46:57 raeburn Exp $ # # Copyright Michigan State University Board of Trustees # @@ -847,8 +847,9 @@ 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; @@ -1233,7 +1234,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) { my ($name, $type, $length) = (split(/:/, $line))[0,2,4]; if($name eq $code_option) { @@ -2071,16 +2072,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; @@ -2118,19 +2131,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' => @@ -2146,7 +2152,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: @@ -2156,11 +2162,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); @@ -2937,7 +2942,6 @@ ENDPART &Apache::lonenc::reset_enc(); - # Note due to document structure, not allowed to put \newpage # prior to the first resource @@ -3233,7 +3237,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); @@ -3248,18 +3252,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'}; @@ -3328,14 +3324,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, @@ -3451,12 +3444,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); + } } } # @@ -3860,8 +3879,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 '') { @@ -4058,10 +4078,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;} @@ -4496,7 +4517,7 @@ 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 '')); @@ -4802,7 +4823,7 @@ CHOOSE_FROM_ANY_SEQUENCE my $xmlfrag = << "FONT_SELECTION"; - + return 'normalsize';