--- loncom/interface/lonprintout.pm 2003/05/05 20:14:32 1.151
+++ loncom/interface/lonprintout.pm 2003/05/14 20:16:56 1.172
@@ -1,7 +1,7 @@
# The LearningOnline Network
# Printout
#
-# $Id: lonprintout.pm,v 1.151 2003/05/05 20:14:32 sakharuk Exp $
+# $Id: lonprintout.pm,v 1.172 2003/05/14 20:16:56 bowersj2 Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -481,15 +481,16 @@ ENDPART
$selectionmade = 1;
if ($ENV{'form.url'}=~/\.(problem|exam|quiz|assess|survey|form|library|page|xml|html|htm|xhtml|xhtm)$/) {
my %moreenv;
- $moreenv{'form.grade_target'}='tex';
if (&Apache::lonnet::allowed('bre',$ENV{'form.url'})) {
$ENV{'form.url'}=~s/http:\/\/[^\/]+//;
}
$moreenv{'request.filename'}=$ENV{'form.url'};
- $moreenv{'form.textwidth'}=$LaTeXwidth;
+ my %form;
+ $form{'textwidth'}=$LaTeXwidth;
+ $form{'grade_target'}='tex';
&Apache::lonnet::appenv(%moreenv);
- my $texversion=&Apache::lonnet::ssi($ENV{'form.url'});
- &Apache::lonnet::delenv('form.grade_target','form.textwidth','form.counter');
+ my $texversion=&Apache::lonnet::ssi($ENV{'form.url'},%form);
+ &Apache::lonnet::delenv('form.counter');
$result .= $texversion;
if ($ENV{'form.url'}=~m/\.page\s*$/) {
($result,$number_of_columns) = &page_cleanup($result);
@@ -523,13 +524,12 @@ ENDPART
} elsif ($choice eq 'Standard LaTeX output for whole primary sequence') {
$selectionmade = 3;
}
- my %moreenv;
- $moreenv{'form.grade_target'}='tex';
- $moreenv{'form.textwidth'}=$LaTeXwidth;
- &Apache::lonnet::appenv(%moreenv);
+ my %form;
+ $form{'textwidth'}=$LaTeXwidth;
+ $form{'grade_target'}='tex';
+ $form{'symb'}=$symb;
#&Apache::lonnet::logthis("Trying to get $urlp with symb $symb");
- my $texversion=&Apache::lonnet::ssi($urlp,('symb'=>$symb));
- &Apache::lonnet::delenv('form.grade_target','form.textwidth');
+ my $texversion=&Apache::lonnet::ssi($urlp,%form);
if ($urlp =~ m/\.page/) {
($texversion,my $number_of_columns_page) = &page_cleanup($texversion);
if ($number_of_columns_page > $number_of_columns) {$number_of_columns=$number_of_columns_page;}
@@ -563,12 +563,11 @@ ENDPART
my ($urlp,$symb) = split /&&/, $file_seq[$i];
$urlp=~s/\/home\/httpd\/html//;
if ($urlp=~m/\.(problem|exam|quiz|assess|survey|form|library)/) {
- my %moreenv;
- $moreenv{'form.grade_target'}='tex';
- $moreenv{'form.textwidth'}=$LaTeXwidth;
- &Apache::lonnet::appenv(%moreenv);
- my $texversion=&Apache::lonnet::ssi($urlp,('symb'=>$symb));
- &Apache::lonnet::delenv('form.grade_target','form.textwidth');
+ my %form;
+ $form{'grade_target'}='tex';
+ $form{'textwidth'}=$LaTeXwidth;
+ $form{'symb'}=$symb;
+ my $texversion=&Apache::lonnet::ssi($urlp,%form);
if ($flag_latex_header_remove ne 'NO') {
$texversion = &latex_header_footer_remove($texversion);
} else {
@@ -658,17 +657,15 @@ ENDPART
for (my $i=0;$i<=$#list_of_files;$i++) {
my $urlp = $list_of_files[$i];
if ($urlp=~/\//) {
- my %moreenv;
- $moreenv{'form.grade_target'}='tex';
- $moreenv{'form.textwidth'}=$LaTeXwidth;
- &Apache::lonnet::appenv(%moreenv);
+ my %form;
+ $form{'grade_target'}='tex';
+ $form{'textwidth'}=$LaTeXwidth;
if ($urlp =~ m|/home/([^/]+)/public_html|) {
$urlp =~ s|/home/([^/]*)/public_html|/~$1|;
} else {
$urlp =~ s|^/home/httpd/html||;
}
- my $texversion=&Apache::lonnet::ssi($urlp);
- &Apache::lonnet::delenv('form.grade_target','form.textwidth');
+ my $texversion=&Apache::lonnet::ssi($urlp,%form);
#this chunck is responsible for printing the path to problem
my $newurlp = '';
my $HowMany = length($urlp)*2;
@@ -1037,7 +1034,6 @@ sub character_chart {
$result =~ s/&(Phi|\#934);/\$\\Phi \$/g;
$result =~ s/&(Psi|\#936);/\$\\Psi \$/g;
$result =~ s/&(Omega|\#937);/\$\\Omega \$/g;
-
return $result;
}
@@ -1350,24 +1346,6 @@ ENDPART
}
my ($textwidth,$textheight,$oddoffset,$evenoffset) = &page_format_new($papersize,$laystyle,$numberofcolumns);
my $assignment = $ENV{'form.assignment'};
-# if ($choice eq 'Subdirectory print') {
-# if ($ENV{'form.layout'} eq '') {$layout = 'CAPA';}
-# if ($ENV{'form.papersize'} eq '') {$papersize = 'Letter [8 1/2x11 in]';}
-# if ($ENV{'form.numberofcolumns'} eq '') {$numberofcolumns = 2;}
-# }
-# if (($choice eq 'Standard LaTeX output for current document') &&
-# ($ENV{'form.url'}=~m|^/~|)) {
-# if ($ENV{'form.layout'} eq '') {$layout = 'CAPA';}
-# if ($ENV{'form.papersize'} eq '') {$papersize = 'Letter [8 1/2x11 in]';}
-# if ($ENV{'form.numberofcolumns'} eq '') {$numberofcolumns = 2;}
-# }
-
-
-# my ($textwidth,$textheight,$oddoffset,$evenoffset) = &page_format($papersize,$layout,$numberofcolumns);
-# if ($numberofcolumns == 1) {
-# $textwidth=$ENV{'form.width'};
-# $textheight=$ENV{'form.height'};
-# }
my $LaTeXwidth;
if ($textwidth=~/(\d+)\s*cm/) {
$LaTeXwidth = $1*10;
@@ -1377,33 +1355,45 @@ ENDPART
$LaTeXwidth = $1*25.4;
}
$LaTeXwidth.=' mm';
-
-
+
if ($helper->{'VARS'}->{'PRINT_TYPE'} eq 'current_document') {
#-- single document - problem, page, html, xml, ...
my $currentURL;
- if (defined $helper->{'VARS'}->{'url'}) {
- $currentURL=$helper->{'VARS'}->{'url'};
- } else {
+ if ($helper->{'VARS'}->{'construction'} ne '1') {
+ #prins published resource
$currentURL=$helper->{'VARS'}->{'postdata'};
+ } else {
+ #prins resource from the construction space
+ $currentURL=$helper->{'VARS'}->{'filename'};
+ $currentURL=~s/\/home\//\/~/;
+ $currentURL=~s/public_html\///;
}
$selectionmade = 1;
if ($currentURL=~/\.(problem|exam|quiz|assess|survey|form|library|page|xml|html|htm|xhtml|xhtm)$/) {
- my %moreenv;
- $moreenv{'form.grade_target'}='tex';
- if (&Apache::lonnet::allowed('bre',$currentURL)) {
- $currentURL=~s/http:\/\/[^\/]+//;
- }
- $moreenv{'request.filename'}=$currentURL;
- $moreenv{'form.textwidth'}=$LaTeXwidth;
- &Apache::lonnet::appenv(%moreenv);
- my $texversion=&Apache::lonnet::ssi($currentURL);
- &Apache::lonnet::delenv('form.grade_target','form.textwidth','form.counter');
- $result .= $texversion;
- if ($currentURL=~m/\.page\s*$/) {
- ($result,$number_of_columns) = &page_cleanup($result);
- }
- } else {
+ my %moreenv;
+ $moreenv{'request.filename'}=$currentURL;
+ my %form;
+ $form{'grade_target'}='tex';
+ $form{'textwidth'}=$LaTeXwidth;
+ my $rndseed=time;
+ $form{'rndseed'}=$rndseed;
+ &Apache::lonnet::appenv(%moreenv);
+ my $texversion=&Apache::lonnet::ssi($currentURL,%form);
+ &Apache::lonnet::delenv('form.counter');
+ &Apache::lonnet::delenv('request.filename');
+ if($helper->{'VARS'}->{'ANSWER_TYPE'} eq 'no') {
+ my %form;
+ $form{'grade_target'}='answer';
+ $form{'answer_output_mode'}='tex';
+ $form{'rndseed'}=$rndseed;
+ my $answer=&Apache::lonnet::ssi($currentURL,%form);
+ $texversion=~s/(\\keephidden{ENDOFPROBLEM})/$answer$1/;
+ }
+ $result .= $texversion;
+ if ($currentURL=~m/\.page\s*$/) {
+ ($result,$number_of_columns) = &page_cleanup($result);
+ }
+ } else {
# $result='\documentclass[letterpaper]{article}\usepackage{calc}\begin{document}Printout of this type of document is currently not supported: ';
# if ($ENV{'form.url'}=~/\/(aboutme|syllabus|bulletinboard|smppg)$/) {
# $result.=$1;
@@ -1411,9 +1401,7 @@ ENDPART
# $result.=$ENV{'form.url'};
# }
# $result.=' \end{document}'
- }
-
-
+ }
} elsif (($helper->{'VARS'}->{'PRINT_TYPE'} eq 'map_problems') or
($helper->{'VARS'}->{'PRINT_TYPE'} eq 'map_problems_pages') or
($helper->{'VARS'}->{'PRINT_TYPE'} eq 'all_problems')) {
@@ -1431,13 +1419,12 @@ ENDPART
} elsif ($helper->{'VARS'}->{'PRINT_TYPE'} eq 'all_problems') {
$selectionmade = 4;
}
- my %moreenv;
- $moreenv{'form.grade_target'}='tex';
- $moreenv{'form.textwidth'}=$LaTeXwidth;
- &Apache::lonnet::appenv(%moreenv);
+ my %form;
+ $form{'grade_target'}='tex';
+ $form{'textwidth'}=$LaTeXwidth;
+ $form{'symb'}=$master_seq[$i];
#&Apache::lonnet::logthis("Trying to get $urlp with symb $master_seq[$i]");
- my $texversion=&Apache::lonnet::ssi($urlp,('symb'=>$master_seq[$i]));
- &Apache::lonnet::delenv('form.grade_target','form.textwidth');
+ my $texversion=&Apache::lonnet::ssi($urlp,%form);
if ($urlp=~/\.page$/) {
($texversion,my $number_of_columns_page) = &page_cleanup($texversion);
if ($number_of_columns_page > $number_of_columns) {$number_of_columns=$number_of_columns_page;}
@@ -1449,6 +1436,13 @@ ENDPART
} else {
$texversion =~ s/\\end{document}//;
}
+ if($helper->{'VARS'}->{'ANSWER_TYPE'} eq 'no') {
+ my %form;
+ $form{'grade_target'}='answer';
+ $form{'answer_output_mode'}='tex';
+ my $answer=&Apache::lonnet::ssi($urlp,%form);
+ $texversion=~s/(\\keephidden{ENDOFPROBLEM})/$answer$1/;
+ }
$result .= $texversion;
$flag_latex_header_remove = 'YES';
}
@@ -1509,51 +1503,50 @@ ENDPART
#prints selected problems from the subdirectory
$selectionmade = 6;
my @list_of_files=split /\|\|\|/, $helper->{'VARS'}->{'FILES'};
+ @list_of_files=sort @list_of_files;
my $flag_latex_header_remove = 'NO';
for (my $i=0;$i<=$#list_of_files;$i++) {
-# my $urlp = $list_of_files[$i];
-# if ($urlp=~/\//) {
- my %moreenv;
- $moreenv{'form.grade_target'}='tex';
- $moreenv{'form.textwidth'}=$LaTeXwidth;
- &Apache::lonnet::appenv(%moreenv);
-# if ($urlp =~ m|/home/([^/]+)/public_html|) {
-# $urlp =~ s|/home/([^/]*)/public_html|/~$1|;
-# } else {
-# $urlp =~ s|^/home/httpd/html||;
-# }
-# my $texversion=&Apache::lonnet::ssi($urlp);
- &Apache::lonnet::delenv('form.grade_target','form.textwidth');
+ my $urlp = $list_of_files[$i];
+ if ($urlp=~/\//) {
+ my %form;
+ $form{'grade_target'}='tex';
+ $form{'textwidth'}=$LaTeXwidth;
+ if ($urlp =~ m|/home/([^/]+)/public_html|) {
+ $urlp =~ s|/home/([^/]*)/public_html|/~$1|;
+ } else {
+ $urlp =~ s|^/home/httpd/html||;
+ }
+ my $texversion=&Apache::lonnet::ssi($urlp,%form);
#this chunck is responsible for printing the path to problem
-# my $newurlp = '';
-# my $HowMany = length($urlp)*2;
-# if ($HowMany > $LaTeXwidth) {
-# my @temporrary = split '/',$urlp;
-# my $HowManyNew = 0;
-# for (my $ii=0;$ii<=$#temporrary;$ii++) {
-# if ($temporrary[$ii] ne '') {
-# $HowManyNew += length($temporrary[$ii])*2;
-# if ($HowManyNew < $LaTeXwidth ) {
-# $newurlp .= '/'.$temporrary[$ii];
-# } else {
-# $HowManyNew = 0;
-# $newurlp .= '|\vskip -1 mm \noindent \verb|';
-# $ii--;
-# }
-# }
-# }
-# }
-# $texversion =~ s/(\\begin{minipage}{\\textwidth})/$1 {\\small\\noindent\\verb|$newurlp\|\\vskip 0 mm}/;
-# if ($flag_latex_header_remove ne 'NO') {
-# $texversion = &latex_header_footer_remove($texversion);
-# } else {
-# $texversion =~ s/\\end{document}//;
-# }
-# $result .= $texversion;
-# }
-# $flag_latex_header_remove = 'YES';
+ my $newurlp = '';
+ my $HowMany = length($urlp)*2;
+ if ($HowMany > $LaTeXwidth) {
+ my @temporrary = split '/',$urlp;
+ my $HowManyNew = 0;
+ for (my $ii=0;$ii<=$#temporrary;$ii++) {
+ if ($temporrary[$ii] ne '') {
+ $HowManyNew += length($temporrary[$ii])*2;
+ if ($HowManyNew < $LaTeXwidth ) {
+ $newurlp .= '/'.$temporrary[$ii];
+ } else {
+ $HowManyNew = 0;
+ $newurlp .= '|\vskip -1 mm \noindent \verb|';
+ $ii--;
+ }
+ }
+ }
+ }
+ $texversion =~ s/(\\begin{minipage}{\\textwidth})/$1 {\\small\\noindent\\verb|$newurlp\|\\vskip 0 mm}/;
+ if ($flag_latex_header_remove ne 'NO') {
+ $texversion = &latex_header_footer_remove($texversion);
+ } else {
+ $texversion =~ s/\\end{document}//;
+ }
+ $result .= $texversion;
+ }
+ $flag_latex_header_remove = 'YES';
}
-# $result .= '\end{document}';
+ $result .= '\end{document}';
}
#-------------------------------------------------------- corrections for the different page formats
$result = &page_format_transformation_new($papersize,$laystyle,$numberofcolumns,$helper->{'VARS'}->{'PRINT_TYPE'},$result,$helper->{VARS}->{'assignment'});
@@ -1599,12 +1592,13 @@ sub handler {
return $result;
}
$helper = $result;
-
+
+
-# my $key;
-# foreach $key (keys %{$helper->{'VARS'}}) {
-# $r->print(' '.$key.'->'.$helper->{'VARS'}->{$key}.'
');
-# }
+ my $key;
+ foreach $key (keys %{$helper->{'VARS'}}) {
+ $r->print(' '.$key.'->'.$helper->{'VARS'}->{$key}.'<-
');
+ }
# return OK;
@@ -1707,41 +1701,71 @@ sub printHelper {
my $helper = Apache::lonhelper::helper->new("Printing Wizard");
$helper->declareVar('symb');
- $helper->declareVar('postdata');
+ $helper->declareVar('postdata');
+ $helper->declareVar('filename');
+ $helper->declareVar('construction');
# This will persistently load in the data we want from the
# very first screen.
- if ($ENV{'form.postdata'}) {
- $helper->{VARS}->{'symb'} = &Apache::lonnet::symbread($ENV{'form.postdata'});
+ # Detect whether we're coming from construction space
+ if ($ENV{'form.postdata'} =~ /http:\/\// ) {
+ $ENV{'form.postdata'} =~ /http:\/\/[a-zA-Z.]+\/~([a-zA-Z0-9]+)\/(.*)/;
+ $helper->{VARS}->{'filename'} = "/home/$1/public_html/$2";
+ $helper->{VARS}->{'construction'} = 1;
+ } else {
+ if ($ENV{'form.postdata'}) {
+ $helper->{VARS}->{'symb'} = &Apache::lonnet::symbread($ENV{'form.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 ($ENV{'form.symb'}) {
$helper->{VARS}->{'symb'} = $ENV{'form.symb'};
}
if ($ENV{'form.url'}) {
$helper->{VARS}->{'symb'} = &Apache::lonnet::symbread($helper->{VARS}->{'postdata'});
- }
+ }
my ($resourceTitle,$sequenceTitle,$mapTitle) = &details_for_menu;
$helper->{VARS}->{'assignment'} = $sequenceTitle;
+
# Extract map
my $symb = $helper->{VARS}->{'symb'};
- my ($map, $id, $url) = split(/___/, $symb);
- $helper->{VARS}->{'postdata'} = Apache::lonnet::clutter($url);
+ my ($map, $id, $url);
+ my $subdir;
+
+ # Get the resource name from construction space
+ if ($helper->{VARS}->{'construction'}) {
+ $resourceTitle = substr($helper->{VARS}->{'filename'},
+ rindex($helper->{VARS}->{'filename'}, '/')+1);
+ $subdir = substr($helper->{VARS}->{'filename'},
+ 0, rindex($helper->{VARS}->{'filename'}, '/') + 1);
+ } else {
+ ($map, $id, $url) = split(/___/, $symb);
+ $helper->{VARS}->{'postdata'} = Apache::lonnet::clutter($url);
- if (!$resourceTitle) { # if the resource doesn't have a title, use the filename
- my $url = $helper->{VARS}->{'postdata'};
- $resourceTitle = substr($url, rindex($url, '/') + 1);
+ if (!$resourceTitle) { # if the resource doesn't have a title, use the filename
+ my $url = $helper->{VARS}->{'postdata'};
+ $resourceTitle = substr($url, rindex($url, '/') + 1);
+ }
+ $subdir = &Apache::lonnet::filelocation("", $url);
}
Apache::lonhelper::registerHelperTags();
- my $subdir = &Apache::lonnet::filelocation("", $url);
-
# "Delete everything after the last slash."
$subdir =~ s|/[^/]+$||;
- $subdir = '/home/httpd/html/res'.$subdir.'/';
+ if (not $helper->{VARS}->{'construction'}) {
+ $subdir='/home/httpd/html/res/'.$subdir;
+ }
+
# What can be printed is a very dynamic decision based on
# lots of factors. So we need to dynamically build this list.
@@ -1756,24 +1780,27 @@ sub printHelper {
# the helper by hand.
my $printChoices = [];
my $paramHash;
- # We can always print the current screen.
- push @{$printChoices}, ["$resourceTitle (exactly what was on the screen)", 'current_document', 'PAGESIZE'];
+ if ($resourceTitle) {
+ push @{$printChoices}, ["$resourceTitle (prints what you just saw on the screen)", 'current_document', 'PAGESIZE'];
+ }
+
+ $r->print($helper->{VARS}->{'postdata'});
# If we're in a sequence...
- if ($helper->{VARS}->{'postdata'} =~ /\/res\//) {
+ if ($helper->{'VARS'}->{'construction'} ne '1') {
# Allow problems from sequence
- push @{$printChoices}, ["Problems from $sequenceTitle", 'map_problems', 'CHOOSE_PROBLEMS'];
+ push @{$printChoices}, ["Problem(s) from $sequenceTitle", 'map_problems', 'CHOOSE_PROBLEMS'];
# Allow all resources from sequence
- push @{$printChoices}, ["Problems and pages from $sequenceTitle", 'map_problems_pages', 'CHOOSE_PROBLEMS_HTML'];
+ push @{$printChoices}, ["Everything (problem(s), page(s), html/xml file(s)) from $sequenceTitle", 'map_problems_pages', 'CHOOSE_PROBLEMS_HTML'];
my $isProblem = '$res->is_problem();';
my $isProblemOrMap = '$res->is_problem() || $res->is_map()';
my $isNotMap = '!$res->is_map();';
my $symb = '$res->symb();';
my $helperFragment = <
Select resources for the assignment
How should the results be printed?
Next option is available only for advanced users:
";
+ Apache::lonhelper::message->new();
+ $paramHash = Apache::lonhelper::getParamHash();
+ $paramHash->{'variable'} = 'ANSWER_TYPE';
+ $helper->declareVar('ANSWER_TYPE');
+ $paramHash->{CHOICES} = [
+ ['Print without answer', 'yes'],
+ ['Print with answers', 'no'] ];
+ Apache::lonhelper::choices->new();
+ }
+
Apache::lonprintout::page_format_state->new("FORMAT");
# Generate the PAGESIZE state which will offer the user the margin
@@ -1956,19 +1999,19 @@ sub render {
$result .= <
What page format do you prefer?
Layout | -Columns | +Page layout | +Number of columns | Paper type |
- Landscape - Portrait + Landscape + Portrait |
- + |