--- loncom/interface/lonprintout.pm 2003/05/02 15:48:26 1.143 +++ loncom/interface/lonprintout.pm 2003/05/02 19:18:39 1.144 @@ -1,7 +1,7 @@ # The LearningOnline Network # Printout # -# $Id: lonprintout.pm,v 1.143 2003/05/02 15:48:26 sakharuk Exp $ +# $Id: lonprintout.pm,v 1.144 2003/05/02 19:18:39 bowersj2 Exp $ # # Copyright Michigan State University Board of Trustees # @@ -1821,7 +1821,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\//) { @@ -1837,8 +1837,8 @@ sub printHelper { my $helperFragment = < Select problems to print: - - FINAL + + PAGESIZE return $isProblemOrMap return $isProblem $map @@ -1848,8 +1848,8 @@ sub printHelper { Select resources to print: - - FINAL + + PAGESIZE return $isNotMap; $map return $symb @@ -1873,7 +1873,7 @@ HELPERFRAGMENT Select problems to print: - FINAL + PAGESIZE return $isProblemOrMap return $isProblem return $symb @@ -1882,7 +1882,7 @@ HELPERFRAGMENT Select the students you wish to print the problems for: - + CHOOSE_STUDENTS } @@ -1896,7 +1896,7 @@ CHOOSE_STUDENTS Select problems you wish to print from $subdir - FINAL + PAGESIZE return '$subdir'; CHOOSE_FROM_SUBDIR @@ -1922,6 +1922,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: @@ -1999,9 +2005,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"; @@ -2060,5 +2063,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__