--- loncom/interface/lonprintout.pm 2005/02/22 16:08:11 1.364 +++ loncom/interface/lonprintout.pm 2005/12/19 23:27:28 1.410 @@ -1,7 +1,7 @@ -# The LearningOnline Network +# The LearningOnline Network # Printout # -# $Id: lonprintout.pm,v 1.364 2005/02/22 16:08:11 albertel Exp $ +# $Id: lonprintout.pm,v 1.410 2005/12/19 23:27:28 foxr Exp $ # # Copyright Michigan State University Board of Trustees # @@ -42,6 +42,126 @@ use Apache::lonratedt; use POSIX qw(strftime); use Apache::lonlocal; +my %perm; + +# +# Convert a numeric code to letters +# +sub num_to_letters { + my ($num) = @_; + my @nums= split('',$num); + my @num_to_let=('A'..'Z'); + my $word; + foreach my $digit (@nums) { $word.=$num_to_let[$digit]; } + return $word; +} +# Convert a letter code to numeric. +# +sub letters_to_num { + my ($letters) = @_; + my @letters = split('', uc($letters)); + my %substitution; + my $digit = 0; + foreach my $letter ('A'..'J') { + $substitution{$letter} = $digit; + $digit++; + } + # The substitution is done as below to preserve leading + # zeroes which are needed to keep the code size exact + # + my $result =""; + foreach my $letter (@letters) { + $result.=$substitution{$letter}; + } + return $result; +} + +# Determine if a code is a valid numeric code. Valid +# numeric codes must be comprised entirely of digits and +# have a correct number of digits. +# +# Parameters: +# value - proposed code value. +# num_digits - Number of digits required. +# +sub is_valid_numeric_code { + my ($value, $num_digits) = @_; + # Remove leading/trailing whitespace; + $value =~ s/^\s*//g; + $value =~ s/\s*$//g; + + # All digits? + if ($value !~ /^[0-9]+$/) { + return "Numeric code $value has invalid characters - must only be digits"; + } + if (length($value) != $num_digits) { + return "Numeric code $value incorrect number of digits (correct = $num_digits)"; + } + return undef; +} +# Determines if a code is a valid alhpa code. Alpha codes +# are ciphers that map [A-J,a-j] -> 0..9 0..9. +# They also have a correct digit count. +# Parameters: +# value - Proposed code value. +# num_letters - correct number of letters. +# Note: +# leading and trailing whitespace are ignored. +# +sub is_valid_alpha_code { + my ($value, $num_letters) = @_; + + # strip leading and trailing spaces. + + $value =~ s/^\s*//g; + $value =~ s/\s*$//g; + + # All alphas in the right range? + if ($value !~ /^[A-J,a-j]+$/) { + return "Invalid letter code $value must only contain A-J"; + } + if (length($value) != $num_letters) { + return "Letter code $value has incorrect number of letters (correct = $num_letters)"; + } + return undef; +} + +# Determine if a code entered by the user in a helper is valid. +# valid depends on the code type and the type of code selected. +# The type of code selected can either be numeric or +# Alphabetic. If alphabetic, the code, in fact is a simple +# substitution cipher for the actual numeric code: 0->A, 1->B ... +# We'll be nice and be case insensitive for alpha codes. +# Parameters: +# code_value - the value of the code the user typed in. +# code_option - The code type selected from the set in the scantron format +# table. +# Returns: +# undef - The code is valid. +# other - An error message indicating what's wrong. +# +sub is_code_valid { + my ($code_value, $code_option) = @_; + my ($code_type, $code_length) = ('letter', 6); # defaults. + open(FG, $Apache::lonnet::perlvar{'lonTabDir'}.'/scantronformat.tab'); + foreach my $line () { + my ($name, $type, $length) = (split(/:/, $line))[0,2,4]; + if($name eq $code_option) { + $code_length = $length; + if($type eq 'number') { + $code_type = 'number'; + } + } + } + my $valid; + if ($code_type eq 'number') { + return &is_valid_numeric_code($code_value, $code_length); + } else { + return &is_valid_alpha_code($code_value, $code_length); + } + +} + # Compare two students by name. The students are in the form # returned by the helper: # user:domain:section:last, first:status @@ -313,6 +433,7 @@ sub character_chart { $result =~ s/&(\#252|uuml);/\\\"{u}/g; $result =~ s/&(\#253|yacute);/\\\'{y}/g; $result =~ s/&(\#255|yuml);/\\\"{y}/g; + $result =~ s/&\#295;/\\ensuremath\{\\hbar\}/g; $result =~ s/&\#952;/\\ensuremath\{\\theta\}/g; #Greek Alphabet $result =~ s/&(alpha|\#945);/\\ensuremath\{\\alpha\}/g; @@ -388,6 +509,7 @@ sub character_chart { $result =~ s/&(prod|\#8719);/\\ensuremath\{\\prod\}/g; $result =~ s/&(sum|\#8721);/\\ensuremath\{\\sum\}/g; $result =~ s/&(minus|\#8722);/\\ensuremath\{-\}/g; + $result =~ s/–/\\ensuremath\{-\}/g; $result =~ s/&(lowast|\#8727);/\\ensuremath\{*\}/g; $result =~ s/&(radic|\#8730);/\\ensuremath\{\\surd\}/g; $result =~ s/&(prop|\#8733);/\\ensuremath\{\\propto\}/g; @@ -443,8 +565,8 @@ my %page_formats= '2' => ['3.16 in','13 in','-0.57 in','-0.57 in','-0.5 in'] }, 'album' => { - '1' => [], - '2' => [] + '1' => ['12 in','7.1 in',,'-0.57 in','-0.57 in','-0.5 in'], + '2' => ['6.0 in','7.1 in','-1 in','-1 in','5 in'] }, }, 'tabloid' => { @@ -453,8 +575,8 @@ my %page_formats= '2' => ['4.9 in','16 in','-0.57 in','-0.57 in','-0.5 in'] }, 'album' => { - '1' => [], - '2' => [] + '1' => ['16 in','9.8 in','-0.57 in','-0.57 in','-0.5 in'], + '2' => ['16 in','4.9 in','-0.57 in','-0.57 in','-0.5 in'] }, }, 'executive' => { @@ -534,8 +656,8 @@ sub page_format { sub get_name { my ($uname,$udom)=@_; - if (!defined($uname)) { $uname=$ENV{'user.name'}; } - if (!defined($udom)) { $udom=$ENV{'user.domain'}; } + if (!defined($uname)) { $uname=$env{'user.name'}; } + if (!defined($udom)) { $udom=$env{'user.domain'}; } my $plainname=&Apache::loncommon::plainname($uname,$udom); if ($plainname=~/^\s*$/) { $plainname=$uname.'@'.$udom; } $plainname=&Apache::lonxml::latex_special_symbols($plainname,'header'); @@ -544,8 +666,8 @@ sub get_name { sub get_course { my $courseidinfo; - if (defined($ENV{'request.course.id'})) { - $courseidinfo = &Apache::lonxml::latex_special_symbols(&Apache::lonnet::unescape($ENV{'course.'.$ENV{'request.course.id'}.'.description'}),'header'); + if (defined($env{'request.course.id'})) { + $courseidinfo = &Apache::lonxml::latex_special_symbols(&Apache::lonnet::unescape($env{'course.'.$env{'request.course.id'}.'.description'}),'header'); } return $courseidinfo; } @@ -607,7 +729,7 @@ sub page_cleanup { sub details_for_menu { my ($helper)=@_; - my $postdata=$ENV{'form.postdata'}; + my $postdata=$env{'form.postdata'}; if (!$postdata) { $postdata=$helper->{VARS}{'postdata'}; } my $name_of_resource = &Apache::lonnet::gettitle($postdata); my $symbolic = &Apache::lonnet::symbread($postdata); @@ -618,9 +740,9 @@ sub details_for_menu { $map =~ m|([^/]+)$|; $name_of_sequence = $1; } - my $name_of_map = &Apache::lonnet::gettitle($ENV{'request.course.uri'}); + my $name_of_map = &Apache::lonnet::gettitle($env{'request.course.uri'}); if ($name_of_map =~ /^\s*$/) { - $ENV{'request.course.uri'} =~ m|([^/]+)$|; + $env{'request.course.uri'} =~ m|([^/]+)$|; $name_of_map = $1; } return ($name_of_resource,$name_of_sequence,$name_of_map); @@ -628,15 +750,14 @@ sub details_for_menu { sub latex_corrections { - - my ($number_of_columns,$result,$selectionmade) = @_; + my ($number_of_columns,$result,$selectionmade,$answer_mode) = @_; # $result =~ s/\\includegraphics{/\\includegraphics\[width=\\minipagewidth\]{/g; $result =~ s/\$number_of_columns/$number_of_columns/g; - if ($selectionmade ne '1') { - $result =~ s/(\\end{document})/\\strut\\vspace\*{-4 mm}\\newline\\noindent\\makebox\[\\textwidth\/$number_of_columns\]\[b\]{\\hrulefill}\\newline\\noindent\\tiny Printed from LON-CAPA\\copyright MSU{\\hfill} Licensed under GNU General Public License $1/; + if ($selectionmade eq '1' || $answer_mode eq 'only') { + $result =~ s/(\\end{document})/\\strut\\vskip 0 mm\\noindent\\makebox\[\\textwidth\/$number_of_columns\]\[b\]{\\hrulefill}\\newline\\noindent\\tiny Printed from LON-CAPA\\copyright MSU{\\hfill} Licensed under GNU General Public License $1/; } else { - $result =~ s/(\\end{document})/\\strut\\newline\\noindent\\makebox\[\\textwidth\/$number_of_columns\]\[b\]{\\hrulefill}\\newline\\noindent\\tiny Printed from LON-CAPA\\copyright MSU{\\hfill} Licensed under GNU General Public License $1/; + $result =~ s/(\\end{document})/\\strut\\vspace\*{-4 mm}\\newline\\noindent\\makebox\[\\textwidth\/$number_of_columns\]\[b\]{\\hrulefill}\\newline\\noindent\\tiny Printed from LON-CAPA\\copyright MSU{\\hfill} Licensed under GNU General Public License $1/; } $result =~ s/(\\end{longtable}\s*)(\\strut\\newline\\noindent\\makebox\[\\textwidth\/$number_of_columns\]\[b\]{\\hrulefill})/$2$1/g; $result =~ s/(\\end{longtable}\s*)\\strut\\newline/$1/g; @@ -648,7 +769,8 @@ sub latex_corrections { $first_comment = index($result,'