--- loncom/interface/lonprintout.pm 2003/05/02 13:39:04 1.141 +++ loncom/interface/lonprintout.pm 2003/05/05 14:30:23 1.146 @@ -1,7 +1,7 @@ # The LearningOnline Network # Printout # -# $Id: lonprintout.pm,v 1.141 2003/05/02 13:39:04 sakharuk Exp $ +# $Id: lonprintout.pm,v 1.146 2003/05/05 14:30:23 bowersj2 Exp $ # # Copyright Michigan State University Board of Trustees # @@ -1389,21 +1389,27 @@ ENDPART if ($helper->{'VARS'}->{'PRINT_TYPE'} eq 'current_document') { - #-- single document - problem, page, html, xml, ... + #-- single document - problem, page, html, xml, ... + my $currentURL; + if (defined $helper->{'VARS'}->{'url'}) { + $currentURL=$helper->{'VARS'}->{'url'}; + } else { + $currentURL=$helper->{'VARS'}->{'postdata'}; + } $selectionmade = 1; - if ($helper->{'VARS'}->{'url'}=~/\.(problem|exam|quiz|assess|survey|form|library|page|xml|html|htm|xhtml|xhtm)$/) { + 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',$helper->{'VARS'}->{'url'})) { - $helper->{'VARS'}->{'url'}=~s/http:\/\/[^\/]+//; - } - $moreenv{'request.filename'}=$helper->{'VARS'}->{'url'}; + 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($helper->{'VARS'}->{'url'}); + my $texversion=&Apache::lonnet::ssi($currentURL); &Apache::lonnet::delenv('form.grade_target','form.textwidth','form.counter'); $result .= $texversion; - if ($helper->{'VARS'}->{'url'}=~m/\.page\s*$/) { + if ($currentURL=~m/\.page\s*$/) { ($result,$number_of_columns) = &page_cleanup($result); } } else { @@ -1417,7 +1423,9 @@ ENDPART } - } elsif ($helper->{'VARS'}->{'PRINT_TYPE'} eq 'map_problems') { + } 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')) { #-- produce an output string my $flag_latex_header_remove = 'NO'; my $flag_page_in_sequence = 'NO'; @@ -1432,9 +1440,11 @@ ENDPART $master_seq[$i]=~/___\d+___(.*)$/; my $urlp='/res/'.$1; if ($helper->{'VARS'}->{'PRINT_TYPE'} eq 'map_problems') { - $selectionmade = 2; -# } elsif ($choice eq 'Standard LaTeX output for whole primary sequence') { -# $selectionmade = 3; + $selectionmade = 2; + } elsif ($helper->{'VARS'}->{'PRINT_TYPE'} eq 'map_problems_pages') { + $selectionmade = 3; + } elsif ($helper->{'VARS'}->{'PRINT_TYPE'} eq 'all_problems') { + $selectionmade = 4; } my %moreenv; $moreenv{'form.grade_target'}='tex'; @@ -1635,7 +1645,7 @@ ENDPART } print $temp_file $result; - +# $r->print(< @@ -1659,7 +1669,7 @@ sub handler { $helper = $result; - my $key; +# my $key; # foreach $key (keys %{$helper->{'VARS'}}) { # $r->print(' '.$key.'->'.$helper->{'VARS'}->{$key}.'
'); # } @@ -1764,22 +1774,30 @@ sub printHelper { Apache::loncommon::get_unprocessed_cgi($ENV{QUERY_STRING}); my $helper = Apache::lonhelper::helper->new("Printing Wizard"); + $helper->declareVar('symb'); + $helper->declareVar('postdata'); # This will persistently load in the data we want from the # very first screen. - if (defined($ENV{'form.postdata'})) { - $helper->{VARS}->{'postdata'} = $ENV{'form.postdata'}; + if ($ENV{'form.postdata'}) { + $helper->{VARS}->{'symb'} = &Apache::lonnet::symbread($ENV{'form.postdata'}); } - if (defined($ENV{'form.symb'})) { - $helper->{VARS}->{'symb'} = &Apache::lonnet::symbread($helper->{VARS}->{'postdata'}); + if ($ENV{'form.symb'}) { + $helper->{VARS}->{'symb'} = $ENV{'form.symb'}; } - if (defined($ENV{'form.url'})) { - $helper->{VARS}->{'url'} = $helper->{VARS}->{'postdata'}; + 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); + if (!$resourceTitle) { # if the resource doesn't have a title, use the filename my $url = $helper->{VARS}->{'postdata'}; $resourceTitle = substr($url, rindex($url, '/') + 1); @@ -1787,11 +1805,7 @@ sub printHelper { Apache::lonhelper::registerHelperTags(); - # Extract map - my $symb = $helper->{VARS}->{'symb'}; - my ($map, $id, $url) = split(/__/, $symb); - - my $subdir = &Apache::lonnet::filelocation("", $helper->{VARS}->{'postdata'}); + my $subdir = &Apache::lonnet::filelocation("", $url); # "Delete everything after the last slash." $subdir =~ s|/[^/]+$||; @@ -1811,7 +1825,7 @@ sub printHelper { my $paramHash; # We can always print the current screen. - push @{$printChoices}, ["$resourceTitle (exactly what was on the screen)", 'current_document', 'FINAL']; + push @{$printChoices}, ["$resourceTitle (exactly what was on the screen)", 'current_document', 'PAGESIZE']; # If we're in a sequence... if ($helper->{VARS}->{'postdata'} =~ /\/res\//) { @@ -1827,10 +1841,9 @@ sub printHelper { my $helperFragment = < Select problems to print: - - FINAL - return $isProblemOrMap - return $isProblem + + PAGESIZE + return $isProblem $map return $symb @@ -1838,9 +1851,9 @@ sub printHelper { Select resources to print: - - FINAL - return $isNotMap; + + PAGESIZE + return $isNotMap; $map return $symb @@ -1863,7 +1876,7 @@ HELPERFRAGMENT Select problems to print: - FINAL + PAGESIZE return $isProblemOrMap return $isProblem return $symb @@ -1872,7 +1885,7 @@ HELPERFRAGMENT Select the students you wish to print the problems for: - + CHOOSE_STUDENTS } @@ -1886,7 +1899,7 @@ CHOOSE_STUDENTS Select problems you wish to print from $subdir - FINAL + PAGESIZE return '$subdir'; CHOOSE_FROM_SUBDIR @@ -1912,6 +1925,12 @@ CHOOSE_FROM_SUBDIR Apache::lonhelper::choices->new(); Apache::lonprintout::page_format_state->new("FORMAT"); + # Generate the PAGESIZE state which will offer the user the margin + # choices if they select one column + Apache::lonhelper::state->new("PAGESIZE", "Set Margins"); + Apache::lonprintout::page_size_state->new('pagesize', 'FORMAT', 'FINAL'); + + $helper->process(); # MANUAL BAILOUT CONDITION: @@ -1989,9 +2008,6 @@ sub render { my $helper = Apache::lonhelper::getHelper(); my $result = ''; my $var = $self->{'variable'}; - my $curVal = $helper->{VARS}->{$var}; - - my ($layout, $cols, $paper) = split(/\|/, $curVal); $result .= <\n"; } else { $result .= "\n"; @@ -2050,5 +2066,160 @@ sub postprocess { 1; +package Apache::lonprintout::page_size_state; + +=pod + +=head1 Helper element: page_size_state + +See lonhelper.pm documentation for discussion of the helper framework. + +Apache::lonprintout::page_size_state is an element that gives the +user the opportunity to further refine the page settings if they +select a single-column page. + +page_size_state is always directly invoked in lonprintout.pm, so there +is no tag interface. You actually pass parameters to the constructor. + +=over 4 + +=item * B(varName): varName is where the print information will be stored in the format FIXME. + +=back + +=cut + +use Apache::lonhelper; + +no strict; +@ISA = ("Apache::lonhelper::element"); +use strict; + + + +sub new { + my $self = Apache::lonhelper::element->new(); + + shift; # disturbs me (probably prevents subclassing) but works (drops + # package descriptor)... - Jeremy + + $self->{'variable'} = shift; + my $helper = Apache::lonhelper::getHelper(); + $helper->declareVar($self->{'variable'}); + + # The variable name of the format element, so we can look into + # $helper->{VARS} to figure out whether the columns are one or two + $self->{'formatvar'} = shift; + + # The state to transition to after selection, or after discovering + # the cols are not set to 1 + $self->{NEXTSTATE} = shift; + bless($self); + return $self; +} + +sub render { + my $self = shift; + my $helper = Apache::lonhelper::getHelper(); + my $result = ''; + my $var = $self->{'variable'}; + + if (defined $self->{ERROR_MSG}) { + $result .= '
' . $self->{ERROR_MSG} . '
'; + } + + $result .= <How should the column be formatted?

+ + + + + + + + + + + + + + + + + +
Width: + +
Height: + +
Left margin: + +
+ +

Hint: Some instructors like to leave scratch space for the student by +making the width much smaller then the width of the page.

+ +ELEMENTHTML + + return $result; +} + +# If the user didn't select 1 column, skip this state. +sub preprocess { + my $self = shift; + my $helper = Apache::lonhelper::getHelper(); + + my $format = $helper->{VARS}->{$self->{'formatvar'}}; + if (substr($format, 2, 1) ne '1') { + $helper->changeState($self->{NEXTSTATE}); + } + + return 1; +} + +sub postprocess { + my $self = shift; + + my $var = $self->{'variable'}; + my $helper = Apache::lonhelper->getHelper(); + my $width = $helper->{VARS}->{$var .'.width'} = $ENV{"form.${var}.width"}; + my $height = $helper->{VARS}->{$var .'.height'} = $ENV{"form.${var}.height"}; + my $lmargin = $helper->{VARS}->{$var .'.lmargin'} = $ENV{"form.${var}.lmargin"}; + $helper->{VARS}->{$var .'.widthunit'} = $ENV{"form.${var}.widthunit"}; + $helper->{VARS}->{$var .'.heightunit'} = $ENV{"form.${var}.heightunit"}; + $helper->{VARS}->{$var .'.lmarginunit'} = $ENV{"form.${var}.lmarginunit"}; + + my $error = ''; + + # /^-?[0-9]+(\.[0-9]*)?$/ -> optional minus, at least on digit, followed + # by an optional period, followed by digits, ending the string + + if ($width !~ /^-?[0-9]+(\.[0-9]*)?$/) { + $error .= "Invalid width; please type only a number.
\n"; + } + if ($height !~ /^-?[0-9]+(\.[0-9]*)?$/) { + $error .= "Invalid height; please type only a number.
\n"; + } + if ($lmargin !~ /^-?[0-9]+(\.[0-9]*)?$/) { + $error .= "Invalid left margin; please type only a number.
\n"; + } + + if (!$error) { + Apache::lonhelper::getHelper()->changeState($self->{NEXTSTATE}); + return 1; + } else { + $self->{ERROR_MSG} = $error; + return 0; + } +} + + + __END__