Annotation of loncom/interface/lonprintout.pm, revision 1.513

1.389     foxr        1: # The LearningOnline Network
1.1       www         2: # Printout
                      3: #
1.513   ! foxr        4: # $Id: lonprintout.pm,v 1.512 2008/01/21 10:24:23 foxr Exp $
1.11      albertel    5: #
                      6: # Copyright Michigan State University Board of Trustees
                      7: #
                      8: # This file is part of the LearningOnline Network with CAPA (LON-CAPA).
                      9: #
                     10: # LON-CAPA is free software; you can redistribute it and/or modify
                     11: # it under the terms of the GNU General Public License as published by
                     12: # the Free Software Foundation; either version 2 of the License, or
                     13: # (at your option) any later version.
                     14: #
                     15: # LON-CAPA is distributed in the hope that it will be useful,
                     16: # but WITHOUT ANY WARRANTY; without even the implied warranty of
                     17: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
                     18: # GNU General Public License for more details.
                     19: #
                     20: # You should have received a copy of the GNU General Public License
                     21: # along with LON-CAPA; if not, write to the Free Software
                     22: # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
                     23: #
                     24: # /home/httpd/html/adm/gpl.txt
                     25: # http://www.lon-capa.org/
                     26: #
1.3       sakharuk   27: #
1.1       www        28: package Apache::lonprintout;
                     29: 
                     30: use strict;
1.10      albertel   31: use Apache::Constants qw(:common :http);
1.2       sakharuk   32: use Apache::lonxml;
                     33: use Apache::lonnet;
1.54      sakharuk   34: use Apache::loncommon;
1.13      sakharuk   35: use Apache::inputtags;
1.54      sakharuk   36: use Apache::grades;
1.13      sakharuk   37: use Apache::edit;
1.5       sakharuk   38: use Apache::File();
1.68      sakharuk   39: use Apache::lonnavmaps;
1.511     foxr       40: use Apache::admannotations;
                     41: 
1.491     albertel   42: use LONCAPA::map();
1.34      sakharuk   43: use POSIX qw(strftime);
1.255     www        44: use Apache::lonlocal;
1.429     foxr       45: use Carp;
1.439     www        46: use LONCAPA;
1.60      sakharuk   47: 
1.397     albertel   48: my %perm;
1.454     foxr       49: my %parmhash;
1.459     foxr       50: my $resources_printed;
1.454     foxr       51: 
1.498     foxr       52: # Fetch the contents of a resource, uninterpreted.
                     53: # This is used here to fetch a latex file to be included
                     54: # verbatim into the printout<
                     55: # NOTE: Ask Guy if there is a lonnet function similar to this?
                     56: #
                     57: # Parameters:
                     58: #   URL of the file
                     59: #
                     60: sub fetch_raw_resource {
                     61:     my ($url) = @_;
                     62: 
                     63:     my $filename  = &Apache::lonnet::filelocation("", $url);
1.500     foxr       64:     my $contents  = &Apache::lonnet::getfile($filename);
1.498     foxr       65: 
1.500     foxr       66:     if ($contents == -1) {
                     67: 	return "File open failed for $filename";      # This will bomb the print.
1.498     foxr       68:     }
1.500     foxr       69:     return $contents;
1.498     foxr       70: 
                     71:     
                     72: }
                     73: 
1.511     foxr       74: #  Fetch the annotations associated with a URL and 
                     75: #  put a centered 'annotations:' title.
                     76: #  This is all suppressed if the annotations are empty.
                     77: #
                     78: sub annotate {
                     79:     my ($symb) = @_;
                     80: 
                     81:     my $annotation_text = &Apache::admannotations::get_annotation($symb, 1);
                     82: 
                     83: 
                     84:     my $result = "";
                     85: 
                     86:     if (length($annotation_text) > 0) {
                     87: 	$result .= '\\hspace*{\\fill} \\\\[\\baselineskip] \textbf{Annotations:} \\\\ ';
                     88: 	$result .= "\n";
                     89: 	$result .= &Apache::lonxml::latex_special_symbols($annotation_text,"");	# Escape latex.
                     90: 	$result .= "\n\n";
                     91:     }
                     92:     return $result;
                     93: }
                     94: 
1.486     foxr       95: #
                     96: #   printf_style_subst  item format_string repl
                     97: #  
                     98: # Does printf style substitution for a format string that
                     99: # can have %[n]item in it.. wherever, %[n]item occurs,
                    100: # rep is substituted in format_string.  Note that
                    101: # [n] is an optional integer length.  If provided,
                    102: # repl is truncated to at most [n] characters prior to 
                    103: # substitution.
                    104: #
                    105: sub printf_style_subst {
                    106:     my ($item, $format_string, $repl) = @_;
1.490     foxr      107:     my $result = "";
                    108:     while ($format_string =~ /(%)(\d*)\Q$item\E/g ) {
1.488     albertel  109: 	my $fmt = $1;
                    110: 	my $size = $2;
1.486     foxr      111: 	my $subst = $repl;
                    112: 	if ($size ne "") {
                    113: 	    $subst = substr($subst, 0, $size);
1.490     foxr      114: 	    
                    115: 	    #  Here's a nice edge case.. supose the end of the
                    116: 	    #  substring is a \.  In that case may have  just
                    117: 	    #  chopped off a TeX escape... in that case, we append
                    118: 	    #   " " for the trailing character, and let the field 
                    119: 	    #  spill over a bit (sigh).
                    120: 	    #  We don't just chop off the last character in order to deal
                    121: 	    #  with one last pathology, and that would be if substr had
                    122: 	    #  trimmed us to e.g. \\\  
                    123: 
                    124: 
                    125: 	    if ($subst =~ /\\$/) {
                    126: 		$subst .= " ";
                    127: 	    }
1.486     foxr      128: 	}
1.490     foxr      129: 	my $item_pos = pos($format_string);
                    130: 	$result .= substr($format_string, 0, $item_pos - length($size) -2) . $subst;
                    131:         $format_string = substr($format_string, pos($format_string));
1.486     foxr      132:     }
1.490     foxr      133: 
                    134:     # Put the residual format string into the result:
                    135: 
                    136:     $result .= $format_string;
                    137: 
                    138:     return $result;
1.486     foxr      139: }
                    140: 
1.454     foxr      141: 
                    142: # Format a header according to a format.  
                    143: # 
                    144: 
                    145: # Substitutions:
                    146: #     %a    - Assignment name.
                    147: #     %c    - Course name.
                    148: #     %n    - Student name.
                    149: #
                    150: sub format_page_header {
1.486     foxr      151:     my ($width, $format, $assignment, $course, $student) = @_;
1.454     foxr      152:     
1.486     foxr      153:     $width = &recalcto_mm($width); # Get width in mm.
1.454     foxr      154:     #  Default format?
                    155: 
                    156:     if ($format eq '') {
1.486     foxr      157: 	# For the default format, we may need to truncate
                    158: 	# elements..  To do this we need to get the page width.
                    159: 	# we assume that each character is about 2mm in width.
                    160: 	# (correct for the header text size??).  We ignore
                    161: 	# any formatting (e.g. boldfacing in this).
                    162: 	# 
                    163: 	# - Allow the student/course to be one line.
                    164: 	#   but only truncate the course.
                    165: 	# - Allow the assignment to be 2 lines (wrapped).
                    166: 	#
                    167: 	my $chars_per_line = $width/2; # Character/textline.
                    168: 
                    169: 
                    170: 	my $firstline = "$student $course";
                    171: 	if (length($firstline) > $chars_per_line) {
                    172: 	    my $lastchar = $chars_per_line - length($student) - 1;
                    173: 	    if ($lastchar > 0) {
                    174: 		$course = substr($course, 0, $lastchar);
                    175: 	    } else {		# Nothing left of course:
                    176: 		$course = '';
                    177: 	    }
                    178: 	}
                    179: 	if (length($assignment) > $chars_per_line) {
                    180: 	    $assignment = substr($assignment, 0, $chars_per_line);
                    181: 	}
                    182: 	
1.454     foxr      183: 	$format =  "\\textbf{$student} $course \\hfill \\thepage \\\\ \\textit{$assignment}";
                    184: 	
                    185:     } else {
1.486     foxr      186: 	# An open question is how to handle long user formatted page headers...
                    187: 	# A possible future is to support e.g. %na so that the user can control
                    188: 	# the truncation of the elements that can appear in the header.
                    189: 	#
                    190: 	$format =  &printf_style_subst("a", $format, $assignment);
                    191: 	$format =  &printf_style_subst("c", $format, $course);
                    192: 	$format =  &printf_style_subst("n", $format, $student);
1.489     foxr      193: 
                    194: 	# If the user put %'s in the format string, they  must be escaped
                    195: 	# to \% else LaTeX will think they are comments and terminate
                    196: 	# the line.. which is bad!!!
                    197: 
1.490     foxr      198: 
1.454     foxr      199:     }
                    200:     
                    201: 
                    202:     return $format;
                    203:     
                    204: }
1.397     albertel  205: 
1.385     foxr      206: #
                    207: #   Convert a numeric code to letters
                    208: #
                    209: sub num_to_letters {
                    210:     my ($num) = @_;
                    211:     my @nums= split('',$num);
                    212:     my @num_to_let=('A'..'Z');
                    213:     my $word;
                    214:     foreach my $digit (@nums) { $word.=$num_to_let[$digit]; }
                    215:     return $word;
                    216: }
                    217: #   Convert a letter code to numeric.
                    218: #
                    219: sub letters_to_num {
                    220:     my ($letters) = @_;
                    221:     my @letters = split('', uc($letters));
1.490     foxr      222:    my %substitution;
1.385     foxr      223:     my $digit = 0;
                    224:     foreach my $letter ('A'..'J') {
                    225: 	$substitution{$letter} = $digit;
                    226: 	$digit++;
                    227:     }
                    228:     #  The substitution is done as below to preserve leading
                    229:     #  zeroes which are needed to keep the code size exact
                    230:     #
                    231:     my $result ="";
                    232:     foreach my $letter (@letters) {
                    233: 	$result.=$substitution{$letter};
                    234:     }
                    235:     return $result;
                    236: }
                    237: 
1.383     foxr      238: #  Determine if a code is a valid numeric code.  Valid
                    239: #  numeric codes must be comprised entirely of digits and
1.384     albertel  240: #  have a correct number of digits.
1.383     foxr      241: #
                    242: #  Parameters:
                    243: #     value      - proposed code value.
1.384     albertel  244: #     num_digits - Number of digits required.
1.383     foxr      245: #
                    246: sub is_valid_numeric_code {
1.384     albertel  247:     my ($value, $num_digits) = @_;
1.383     foxr      248:     #   Remove leading/trailing whitespace;
1.387     foxr      249:     $value =~ s/^\s*//g;
                    250:     $value =~ s/\s*$//g;
1.383     foxr      251:     
                    252:     #  All digits?
1.387     foxr      253:     if ($value !~ /^[0-9]+$/) {
1.383     foxr      254: 	return "Numeric code $value has invalid characters - must only be digits";
                    255:     }
1.384     albertel  256:     if (length($value) != $num_digits) {
                    257: 	return "Numeric code $value incorrect number of digits (correct = $num_digits)";
                    258:     }
1.385     foxr      259:     return undef;
1.383     foxr      260: }
                    261: #   Determines if a code is a valid alhpa code.  Alpha codes
                    262: #   are ciphers that map  [A-J,a-j] -> 0..9 0..9.
1.384     albertel  263: #   They also have a correct digit count.
1.383     foxr      264: # Parameters:
                    265: #     value          - Proposed code value.
1.384     albertel  266: #     num_letters    - correct number of letters.
1.383     foxr      267: # Note:
                    268: #    leading and trailing whitespace are ignored.
                    269: #
                    270: sub is_valid_alpha_code {
1.384     albertel  271:     my ($value, $num_letters) = @_;
1.383     foxr      272:     
                    273:      # strip leading and trailing spaces.
                    274: 
                    275:     $value =~ s/^\s*//g;
                    276:     $value =~ s/\s*$//g;
                    277: 
                    278:     #  All alphas in the right range?
1.384     albertel  279:     if ($value !~ /^[A-J,a-j]+$/) {
1.383     foxr      280: 	return "Invalid letter code $value must only contain A-J";
                    281:     }
1.384     albertel  282:     if (length($value) != $num_letters) {
                    283: 	return "Letter code $value has incorrect number of letters (correct = $num_letters)";
                    284:     }
1.385     foxr      285:     return undef;
1.383     foxr      286: }
                    287: 
1.382     foxr      288: #   Determine if a code entered by the user in a helper is valid.
                    289: #   valid depends on the code type and the type of code selected.
                    290: #   The type of code selected can either be numeric or 
                    291: #   Alphabetic.  If alphabetic, the code, in fact is a simple
                    292: #   substitution cipher for the actual numeric code: 0->A, 1->B ...
                    293: #   We'll be nice and be case insensitive for alpha codes.
                    294: # Parameters:
                    295: #    code_value    - the value of the code the user typed in.
                    296: #    code_option   - The code type selected from the set in the scantron format
                    297: #                    table.
                    298: # Returns:
                    299: #    undef         - The code is valid.
                    300: #    other         - An error message indicating what's wrong.
                    301: #
                    302: sub is_code_valid {
                    303:     my ($code_value, $code_option) = @_;
1.383     foxr      304:     my ($code_type, $code_length) = ('letter', 6);	# defaults.
                    305:     open(FG, $Apache::lonnet::perlvar{'lonTabDir'}.'/scantronformat.tab');
                    306:     foreach my $line (<FG>) {
                    307: 	my ($name, $type, $length) = (split(/:/, $line))[0,2,4];
                    308: 	if($name eq $code_option) {
                    309: 	    $code_length = $length;
                    310: 	    if($type eq 'number') {
                    311: 		$code_type = 'number';
                    312: 	    }
                    313: 	}
                    314:     }
                    315:     my $valid;
                    316:     if ($code_type eq 'number') {
1.385     foxr      317: 	return &is_valid_numeric_code($code_value, $code_length);
1.383     foxr      318:     } else {
1.385     foxr      319: 	return &is_valid_alpha_code($code_value, $code_length);
1.383     foxr      320:     }
1.382     foxr      321: 
                    322: }
                    323: 
1.341     foxr      324: #   Compare two students by name.  The students are in the form
                    325: #   returned by the helper:
                    326: #      user:domain:section:last,   first:status
                    327: #   This is a helper function for the perl sort built-in  therefore:
                    328: # Implicit Inputs:
                    329: #    $a     - The first element to compare (global)
                    330: #    $b     - The second element to compare (global)
                    331: # Returns:
                    332: #   -1   - $a < $b
                    333: #    0   - $a == $b
                    334: #   +1   - $a > $b
                    335: #   Note that the initial comparison is done on the last names with the
                    336: #   first names only used to break the tie.
                    337: #
                    338: #
                    339: sub compare_names {
                    340:     #  First split the names up into the primary fields.
                    341: 
                    342:     my ($u1, $d1, $s1, $n1, $stat1) = split(/:/, $a);
                    343:     my ($u2, $d2, $s2, $n2, $stat2) = split(/:/, $b);
                    344: 
                    345:     # Now split the last name and first name of each n:
                    346:     #
                    347: 
                    348:     my ($l1,$f1) = split(/,/, $n1);
                    349:     my ($l2,$f2) = split(/,/, $n2);
                    350: 
                    351:     # We don't bother to remove the leading/trailing whitespace from the
                    352:     # firstname, unless the last names compare identical.
                    353: 
                    354:     if($l1 lt $l2) {
                    355: 	return -1;
                    356:     }
                    357:     if($l1 gt $l2) {
                    358: 	return  1;
                    359:     }
                    360: 
                    361:     # Break the tie on the first name, but there are leading (possibly trailing
                    362:     # whitespaces to get rid of first 
                    363:     #
                    364:     $f1 =~ s/^\s+//;		# Remove leading...
                    365:     $f1 =~ s/\s+$//;		# Trailing spaces from first 1...
                    366:     
                    367:     $f2 =~ s/^\s+//;
                    368:     $f2 =~ s/\s+$//;		# And the same for first 2...
                    369: 
                    370:     if($f1 lt $f2) {
                    371: 	return -1;
                    372:     }
                    373:     if($f1 gt $f2) {
                    374: 	return 1;
                    375:     }
                    376:     
                    377:     #  Must be the same name.
                    378: 
                    379:     return 0;
                    380: }
                    381: 
1.71      sakharuk  382: sub latex_header_footer_remove {
                    383:     my $text = shift;
                    384:     $text =~ s/\\end{document}//;
                    385:     $text =~ s/\\documentclass([^&]*)\\begin{document}//;
                    386:     return $text;
                    387: }
1.423     foxr      388: #
                    389: #  If necessary, encapsulate text inside 
                    390: #  a minipage env.
                    391: #  necessity is determined by the problem_split param.
                    392: #
                    393: sub encapsulate_minipage {
                    394:     my ($text) = @_;
1.427     albertel  395:     if (!($env{'form.problem.split'} =~ /yes/i)) {
1.423     foxr      396: 	$text = '\begin{minipage}{\textwidth}'.$text.'\end{minipage}';
                    397:     }
                    398:     return $text;
                    399: }
1.429     foxr      400: #
                    401: #  The NUMBER_TO_PRINT and SPLIT_PDFS
                    402: #  variables interact, this sub looks at these two parameters
                    403: #  and comes up with a final value for NUMBER_TO_PRINT which can be:
                    404: #     all     - if SPLIT_PDFS eq 'all'.
                    405: #     1       - if SPLIT_PDFS eq 'oneper'
                    406: #     section - if SPLIT_PDFS eq 'sections'
                    407: #     <unchanged> - if SPLIT_PDFS eq 'usenumber'
                    408: #
                    409: sub adjust_number_to_print {
                    410:     my $helper = shift;
1.71      sakharuk  411: 
1.429     foxr      412:     my $split_pdf = $helper->{'VARS'}->{'SPLIT_PDFS'};
                    413:     
                    414:     if ($split_pdf eq 'all') {
                    415: 	$helper->{'VARS'}->{'NUMBER_TO_PRINT'} = 'all';
                    416:     } elsif ($split_pdf eq 'oneper') {
                    417: 	$helper->{'VARS'}->{'NUMBER_TO_PRINT'} = 1;
                    418:     } elsif ($split_pdf eq 'sections') {
                    419: 	$helper->{'VARS'}->{'NUMBER_TO_PRINT'} = 'section';
                    420:     } elsif ($split_pdf eq 'usenumber') {
                    421: 	#  Unmodified.
                    422:     } else {
                    423: 	# Error!!!!
                    424: 
                    425: 	croak "bad SPLIT_PDFS: $split_pdf in lonprintout::adjust_number_to_print";
                    426:     }
                    427: }
1.71      sakharuk  428: 
1.37      sakharuk  429: sub character_chart {
                    430:     my $result = shift;	
1.116     sakharuk  431:     $result =~ s/&\#0?0?(7|9);//g;
                    432:     $result =~ s/&\#0?(10|13);//g;
                    433:     $result =~ s/&\#0?32;/ /g;
                    434:     $result =~ s/&\#0?33;/!/g;
                    435:     $result =~ s/&(\#0?34|quot);/\"/g;
                    436:     $result =~ s/&\#0?35;/\\\#/g;
                    437:     $result =~ s/&\#0?36;/\\\$/g;
                    438:     $result =~ s/&\#0?37;/\\%/g; 
                    439:     $result =~ s/&(\#0?38|amp);/\\&/g; 
                    440:     $result =~ s/&\#(0?39|146);/\'/g;
                    441:     $result =~ s/&\#0?40;/(/g;
                    442:     $result =~ s/&\#0?41;/)/g;
                    443:     $result =~ s/&\#0?42;/\*/g;
                    444:     $result =~ s/&\#0?43;/\+/g;
                    445:     $result =~ s/&\#(0?44|130);/,/g;
                    446:     $result =~ s/&\#0?45;/-/g;
                    447:     $result =~ s/&\#0?46;/\./g;
                    448:     $result =~ s/&\#0?47;/\//g;
                    449:     $result =~ s/&\#0?48;/0/g;
                    450:     $result =~ s/&\#0?49;/1/g;
                    451:     $result =~ s/&\#0?50;/2/g;
                    452:     $result =~ s/&\#0?51;/3/g;
                    453:     $result =~ s/&\#0?52;/4/g;
                    454:     $result =~ s/&\#0?53;/5/g;
                    455:     $result =~ s/&\#0?54;/6/g;
                    456:     $result =~ s/&\#0?55;/7/g;
                    457:     $result =~ s/&\#0?56;/8/g;
                    458:     $result =~ s/&\#0?57;/9/g;
1.269     albertel  459:     $result =~ s/&\#0?58;/:/g;
1.116     sakharuk  460:     $result =~ s/&\#0?59;/;/g;
                    461:     $result =~ s/&(\#0?60|lt|\#139);/\$<\$/g;
1.281     sakharuk  462:     $result =~ s/&\#0?61;/\\ensuremath\{=\}/g;
                    463:     $result =~ s/&(\#0?62|gt|\#155);/\\ensuremath\{>\}/g;
1.116     sakharuk  464:     $result =~ s/&\#0?63;/\?/g;
                    465:     $result =~ s/&\#0?65;/A/g;
                    466:     $result =~ s/&\#0?66;/B/g;
                    467:     $result =~ s/&\#0?67;/C/g;
                    468:     $result =~ s/&\#0?68;/D/g;
                    469:     $result =~ s/&\#0?69;/E/g;
                    470:     $result =~ s/&\#0?70;/F/g;
                    471:     $result =~ s/&\#0?71;/G/g;
                    472:     $result =~ s/&\#0?72;/H/g;
                    473:     $result =~ s/&\#0?73;/I/g;
                    474:     $result =~ s/&\#0?74;/J/g;
                    475:     $result =~ s/&\#0?75;/K/g;
                    476:     $result =~ s/&\#0?76;/L/g;
                    477:     $result =~ s/&\#0?77;/M/g;
                    478:     $result =~ s/&\#0?78;/N/g;
                    479:     $result =~ s/&\#0?79;/O/g;
                    480:     $result =~ s/&\#0?80;/P/g;
                    481:     $result =~ s/&\#0?81;/Q/g;
                    482:     $result =~ s/&\#0?82;/R/g;
                    483:     $result =~ s/&\#0?83;/S/g;
                    484:     $result =~ s/&\#0?84;/T/g;
                    485:     $result =~ s/&\#0?85;/U/g;
                    486:     $result =~ s/&\#0?86;/V/g;
                    487:     $result =~ s/&\#0?87;/W/g;
                    488:     $result =~ s/&\#0?88;/X/g;
                    489:     $result =~ s/&\#0?89;/Y/g;
                    490:     $result =~ s/&\#0?90;/Z/g;
                    491:     $result =~ s/&\#0?91;/[/g;
1.281     sakharuk  492:     $result =~ s/&\#0?92;/\\ensuremath\{\\setminus\}/g;
1.116     sakharuk  493:     $result =~ s/&\#0?93;/]/g;
1.281     sakharuk  494:     $result =~ s/&\#(0?94|136);/\\ensuremath\{\\wedge\}/g;
1.116     sakharuk  495:     $result =~ s/&\#(0?95|138|154);/\\underline{\\makebox[2mm]{\\strut}}/g;
                    496:     $result =~ s/&\#(0?96|145);/\`/g;
                    497:     $result =~ s/&\#0?97;/a/g;
                    498:     $result =~ s/&\#0?98;/b/g;
                    499:     $result =~ s/&\#0?99;/c/g;
                    500:     $result =~ s/&\#100;/d/g;
                    501:     $result =~ s/&\#101;/e/g;
                    502:     $result =~ s/&\#102;/f/g;
                    503:     $result =~ s/&\#103;/g/g;
                    504:     $result =~ s/&\#104;/h/g;
                    505:     $result =~ s/&\#105;/i/g;
                    506:     $result =~ s/&\#106;/j/g;
                    507:     $result =~ s/&\#107;/k/g;
                    508:     $result =~ s/&\#108;/l/g;
                    509:     $result =~ s/&\#109;/m/g;
                    510:     $result =~ s/&\#110;/n/g;
                    511:     $result =~ s/&\#111;/o/g;
                    512:     $result =~ s/&\#112;/p/g;
                    513:     $result =~ s/&\#113;/q/g;
                    514:     $result =~ s/&\#114;/r/g;
                    515:     $result =~ s/&\#115;/s/g;
                    516:     $result =~ s/&\#116;/t/g;
                    517:     $result =~ s/&\#117;/u/g;
                    518:     $result =~ s/&\#118;/v/g;
                    519:     $result =~ s/&\#119;/w/g;
                    520:     $result =~ s/&\#120;/x/g;
                    521:     $result =~ s/&\#121;/y/g;
                    522:     $result =~ s/&\#122;/z/g;
                    523:     $result =~ s/&\#123;/\\{/g;
                    524:     $result =~ s/&\#124;/\|/g;
                    525:     $result =~ s/&\#125;/\\}/g;
                    526:     $result =~ s/&\#126;/\~/g;
                    527:     $result =~ s/&\#131;/\\textflorin /g;
                    528:     $result =~ s/&\#132;/\"/g;
1.281     sakharuk  529:     $result =~ s/&\#133;/\\ensuremath\{\\ldots\}/g;
                    530:     $result =~ s/&\#134;/\\ensuremath\{\\dagger\}/g;
                    531:     $result =~ s/&\#135;/\\ensuremath\{\\ddagger\}/g;
1.116     sakharuk  532:     $result =~ s/&\#137;/\\textperthousand /g;
                    533:     $result =~ s/&\#140;/{\\OE}/g;
                    534:     $result =~ s/&\#147;/\`\`/g;
                    535:     $result =~ s/&\#148;/\'\'/g;
1.281     sakharuk  536:     $result =~ s/&\#149;/\\ensuremath\{\\bullet\}/g;
1.494     albertel  537:     $result =~ s/&(\#150|\#8211);/--/g;
1.116     sakharuk  538:     $result =~ s/&\#151;/---/g;
1.281     sakharuk  539:     $result =~ s/&\#152;/\\ensuremath\{\\sim\}/g;
1.116     sakharuk  540:     $result =~ s/&\#153;/\\texttrademark /g;
                    541:     $result =~ s/&\#156;/\\oe/g;
                    542:     $result =~ s/&\#159;/\\\"Y/g;
1.283     albertel  543:     $result =~ s/&(\#160|nbsp);/~/g;
1.116     sakharuk  544:     $result =~ s/&(\#161|iexcl);/!\`/g;
                    545:     $result =~ s/&(\#162|cent);/\\textcent /g;
                    546:     $result =~ s/&(\#163|pound);/\\pounds /g; 
                    547:     $result =~ s/&(\#164|curren);/\\textcurrency /g;
                    548:     $result =~ s/&(\#165|yen);/\\textyen /g;
                    549:     $result =~ s/&(\#166|brvbar);/\\textbrokenbar /g;
                    550:     $result =~ s/&(\#167|sect);/\\textsection /g;
                    551:     $result =~ s/&(\#168|uml);/\\texthighdieresis /g;
                    552:     $result =~ s/&(\#169|copy);/\\copyright /g;
                    553:     $result =~ s/&(\#170|ordf);/\\textordfeminine /g;
1.281     sakharuk  554:     $result =~ s/&(\#172|not);/\\ensuremath\{\\neg\}/g;
1.116     sakharuk  555:     $result =~ s/&(\#173|shy);/ - /g;
                    556:     $result =~ s/&(\#174|reg);/\\textregistered /g;
1.281     sakharuk  557:     $result =~ s/&(\#175|macr);/\\ensuremath\{^{-}\}/g;
                    558:     $result =~ s/&(\#176|deg);/\\ensuremath\{^{\\circ}\}/g;
                    559:     $result =~ s/&(\#177|plusmn);/\\ensuremath\{\\pm\}/g;
                    560:     $result =~ s/&(\#178|sup2);/\\ensuremath\{^2\}/g;
                    561:     $result =~ s/&(\#179|sup3);/\\ensuremath\{^3\}/g;
1.116     sakharuk  562:     $result =~ s/&(\#180|acute);/\\textacute /g;
1.281     sakharuk  563:     $result =~ s/&(\#181|micro);/\\ensuremath\{\\mu\}/g;
1.116     sakharuk  564:     $result =~ s/&(\#182|para);/\\P/g;
1.281     sakharuk  565:     $result =~ s/&(\#183|middot);/\\ensuremath\{\\cdot\}/g;
1.116     sakharuk  566:     $result =~ s/&(\#184|cedil);/\\c{\\strut}/g;
1.281     sakharuk  567:     $result =~ s/&(\#185|sup1);/\\ensuremath\{^1\}/g;
1.116     sakharuk  568:     $result =~ s/&(\#186|ordm);/\\textordmasculine /g;
                    569:     $result =~ s/&(\#188|frac14);/\\textonequarter /g;
                    570:     $result =~ s/&(\#189|frac12);/\\textonehalf /g;
                    571:     $result =~ s/&(\#190|frac34);/\\textthreequarters /g;
                    572:     $result =~ s/&(\#191|iquest);/?\`/g;   
                    573:     $result =~ s/&(\#192|Agrave);/\\\`{A}/g;  
                    574:     $result =~ s/&(\#193|Aacute);/\\\'{A}/g; 
                    575:     $result =~ s/&(\#194|Acirc);/\\^{A}/g;
                    576:     $result =~ s/&(\#195|Atilde);/\\~{A}/g;
                    577:     $result =~ s/&(\#196|Auml);/\\\"{A}/g; 
                    578:     $result =~ s/&(\#197|Aring);/{\\AA}/g;
                    579:     $result =~ s/&(\#198|AElig);/{\\AE}/g;
                    580:     $result =~ s/&(\#199|Ccedil);/\\c{c}/g;
                    581:     $result =~ s/&(\#200|Egrave);/\\\`{E}/g;  
                    582:     $result =~ s/&(\#201|Eacute);/\\\'{E}/g;    
                    583:     $result =~ s/&(\#202|Ecirc);/\\^{E}/g;
                    584:     $result =~ s/&(\#203|Euml);/\\\"{E}/g;
                    585:     $result =~ s/&(\#204|Igrave);/\\\`{I}/g;
                    586:     $result =~ s/&(\#205|Iacute);/\\\'{I}/g;    
                    587:     $result =~ s/&(\#206|Icirc);/\\^{I}/g;
                    588:     $result =~ s/&(\#207|Iuml);/\\\"{I}/g;    
                    589:     $result =~ s/&(\#209|Ntilde);/\\~{N}/g;
                    590:     $result =~ s/&(\#210|Ograve);/\\\`{O}/g;
                    591:     $result =~ s/&(\#211|Oacute);/\\\'{O}/g;
                    592:     $result =~ s/&(\#212|Ocirc);/\\^{O}/g;
                    593:     $result =~ s/&(\#213|Otilde);/\\~{O}/g;
                    594:     $result =~ s/&(\#214|Ouml);/\\\"{O}/g;    
1.281     sakharuk  595:     $result =~ s/&(\#215|times);/\\ensuremath\{\\times\}/g;
1.116     sakharuk  596:     $result =~ s/&(\#216|Oslash);/{\\O}/g;
                    597:     $result =~ s/&(\#217|Ugrave);/\\\`{U}/g;    
                    598:     $result =~ s/&(\#218|Uacute);/\\\'{U}/g;
                    599:     $result =~ s/&(\#219|Ucirc);/\\^{U}/g;
                    600:     $result =~ s/&(\#220|Uuml);/\\\"{U}/g;
                    601:     $result =~ s/&(\#221|Yacute);/\\\'{Y}/g;
1.329     sakharuk  602:     $result =~ s/&(\#223|szlig);/{\\ss}/g;
1.116     sakharuk  603:     $result =~ s/&(\#224|agrave);/\\\`{a}/g;
                    604:     $result =~ s/&(\#225|aacute);/\\\'{a}/g;
                    605:     $result =~ s/&(\#226|acirc);/\\^{a}/g;
                    606:     $result =~ s/&(\#227|atilde);/\\~{a}/g;
                    607:     $result =~ s/&(\#228|auml);/\\\"{a}/g;
                    608:     $result =~ s/&(\#229|aring);/{\\aa}/g;
                    609:     $result =~ s/&(\#230|aelig);/{\\ae}/g;
                    610:     $result =~ s/&(\#231|ccedil);/\\c{c}/g;
                    611:     $result =~ s/&(\#232|egrave);/\\\`{e}/g;
                    612:     $result =~ s/&(\#233|eacute);/\\\'{e}/g;
                    613:     $result =~ s/&(\#234|ecirc);/\\^{e}/g;
                    614:     $result =~ s/&(\#235|euml);/\\\"{e}/g;
                    615:     $result =~ s/&(\#236|igrave);/\\\`{i}/g;
                    616:     $result =~ s/&(\#237|iacute);/\\\'{i}/g;
                    617:     $result =~ s/&(\#238|icirc);/\\^{i}/g;
                    618:     $result =~ s/&(\#239|iuml);/\\\"{i}/g;
1.281     sakharuk  619:     $result =~ s/&(\#240|eth);/\\ensuremath\{\\partial\}/g;
1.116     sakharuk  620:     $result =~ s/&(\#241|ntilde);/\\~{n}/g;
                    621:     $result =~ s/&(\#242|ograve);/\\\`{o}/g;
                    622:     $result =~ s/&(\#243|oacute);/\\\'{o}/g;
                    623:     $result =~ s/&(\#244|ocirc);/\\^{o}/g;
                    624:     $result =~ s/&(\#245|otilde);/\\~{o}/g;
                    625:     $result =~ s/&(\#246|ouml);/\\\"{o}/g;
1.281     sakharuk  626:     $result =~ s/&(\#247|divide);/\\ensuremath\{\\div\}/g;
1.116     sakharuk  627:     $result =~ s/&(\#248|oslash);/{\\o}/g;
                    628:     $result =~ s/&(\#249|ugrave);/\\\`{u}/g; 
                    629:     $result =~ s/&(\#250|uacute);/\\\'{u}/g;
                    630:     $result =~ s/&(\#251|ucirc);/\\^{u}/g;
                    631:     $result =~ s/&(\#252|uuml);/\\\"{u}/g;
                    632:     $result =~ s/&(\#253|yacute);/\\\'{y}/g;
                    633:     $result =~ s/&(\#255|yuml);/\\\"{y}/g;
1.399     albertel  634:     $result =~ s/&\#295;/\\ensuremath\{\\hbar\}/g;
1.281     sakharuk  635:     $result =~ s/&\#952;/\\ensuremath\{\\theta\}/g;
1.117     sakharuk  636: #Greek Alphabet
1.281     sakharuk  637:     $result =~ s/&(alpha|\#945);/\\ensuremath\{\\alpha\}/g;
                    638:     $result =~ s/&(beta|\#946);/\\ensuremath\{\\beta\}/g;
                    639:     $result =~ s/&(gamma|\#947);/\\ensuremath\{\\gamma\}/g;
                    640:     $result =~ s/&(delta|\#948);/\\ensuremath\{\\delta\}/g;
                    641:     $result =~ s/&(epsilon|\#949);/\\ensuremath\{\\epsilon\}/g;
                    642:     $result =~ s/&(zeta|\#950);/\\ensuremath\{\\zeta\}/g;
                    643:     $result =~ s/&(eta|\#951);/\\ensuremath\{\\eta\}/g;
                    644:     $result =~ s/&(theta|\#952);/\\ensuremath\{\\theta\}/g;
                    645:     $result =~ s/&(iota|\#953);/\\ensuremath\{\\iota\}/g;
                    646:     $result =~ s/&(kappa|\#954);/\\ensuremath\{\\kappa\}/g;
                    647:     $result =~ s/&(lambda|\#955);/\\ensuremath\{\\lambda\}/g;
                    648:     $result =~ s/&(mu|\#956);/\\ensuremath\{\\mu\}/g;
                    649:     $result =~ s/&(nu|\#957);/\\ensuremath\{\\nu\}/g;
                    650:     $result =~ s/&(xi|\#958);/\\ensuremath\{\\xi\}/g;
1.199     sakharuk  651:     $result =~ s/&(omicron|\#959);/o/g;
1.281     sakharuk  652:     $result =~ s/&(pi|\#960);/\\ensuremath\{\\pi\}/g;
                    653:     $result =~ s/&(rho|\#961);/\\ensuremath\{\\rho\}/g;
                    654:     $result =~ s/&(sigma|\#963);/\\ensuremath\{\\sigma\}/g;
                    655:     $result =~ s/&(tau|\#964);/\\ensuremath\{\\tau\}/g;
                    656:     $result =~ s/&(upsilon|\#965);/\\ensuremath\{\\upsilon\}/g;
                    657:     $result =~ s/&(phi|\#966);/\\ensuremath\{\\phi\}/g;
                    658:     $result =~ s/&(chi|\#967);/\\ensuremath\{\\chi\}/g;
                    659:     $result =~ s/&(psi|\#968);/\\ensuremath\{\\psi\}/g;
                    660:     $result =~ s/&(omega|\#969);/\\ensuremath\{\\omega\}/g;
                    661:     $result =~ s/&(thetasym|\#977);/\\ensuremath\{\\vartheta\}/g;
                    662:     $result =~ s/&(piv|\#982);/\\ensuremath\{\\varpi\}/g;
1.199     sakharuk  663:     $result =~ s/&(Alpha|\#913);/A/g;
                    664:     $result =~ s/&(Beta|\#914);/B/g;
1.281     sakharuk  665:     $result =~ s/&(Gamma|\#915);/\\ensuremath\{\\Gamma\}/g;
                    666:     $result =~ s/&(Delta|\#916);/\\ensuremath\{\\Delta\}/g;
1.199     sakharuk  667:     $result =~ s/&(Epsilon|\#917);/E/g;
                    668:     $result =~ s/&(Zeta|\#918);/Z/g;
                    669:     $result =~ s/&(Eta|\#919);/H/g;
1.281     sakharuk  670:     $result =~ s/&(Theta|\#920);/\\ensuremath\{\\Theta\}/g;
1.199     sakharuk  671:     $result =~ s/&(Iota|\#921);/I/g;
                    672:     $result =~ s/&(Kappa|\#922);/K/g;
1.281     sakharuk  673:     $result =~ s/&(Lambda|\#923);/\\ensuremath\{\\Lambda\}/g;
1.199     sakharuk  674:     $result =~ s/&(Mu|\#924);/M/g;
                    675:     $result =~ s/&(Nu|\#925);/N/g;
1.281     sakharuk  676:     $result =~ s/&(Xi|\#926);/\\ensuremath\{\\Xi\}/g;
1.199     sakharuk  677:     $result =~ s/&(Omicron|\#927);/O/g;
1.281     sakharuk  678:     $result =~ s/&(Pi|\#928);/\\ensuremath\{\\Pi\}/g;
1.199     sakharuk  679:     $result =~ s/&(Rho|\#929);/P/g;
1.281     sakharuk  680:     $result =~ s/&(Sigma|\#931);/\\ensuremath\{\\Sigma\}/g;
1.199     sakharuk  681:     $result =~ s/&(Tau|\#932);/T/g;
1.281     sakharuk  682:     $result =~ s/&(Upsilon|\#933);/\\ensuremath\{\\Upsilon\}/g;
                    683:     $result =~ s/&(Phi|\#934);/\\ensuremath\{\\Phi\}/g;
1.199     sakharuk  684:     $result =~ s/&(Chi|\#935);/X/g;
1.281     sakharuk  685:     $result =~ s/&(Psi|\#936);/\\ensuremath\{\\Psi\}/g;
                    686:     $result =~ s/&(Omega|\#937);/\\ensuremath\{\\Omega\}/g;
1.199     sakharuk  687: #Arrows (extended HTML 4.01)
1.281     sakharuk  688:     $result =~ s/&(larr|\#8592);/\\ensuremath\{\\leftarrow\}/g;
                    689:     $result =~ s/&(uarr|\#8593);/\\ensuremath\{\\uparrow\}/g;
                    690:     $result =~ s/&(rarr|\#8594);/\\ensuremath\{\\rightarrow\}/g;
                    691:     $result =~ s/&(darr|\#8595);/\\ensuremath\{\\downarrow\}/g;
                    692:     $result =~ s/&(harr|\#8596);/\\ensuremath\{\\leftrightarrow\}/g;
                    693:     $result =~ s/&(lArr|\#8656);/\\ensuremath\{\\Leftarrow\}/g;
                    694:     $result =~ s/&(uArr|\#8657);/\\ensuremath\{\\Uparrow\}/g;
                    695:     $result =~ s/&(rArr|\#8658);/\\ensuremath\{\\Rightarrow\}/g;
                    696:     $result =~ s/&(dArr|\#8659);/\\ensuremath\{\\Downarrow\}/g;
                    697:     $result =~ s/&(hArr|\#8660);/\\ensuremath\{\\Leftrightarrow\}/g;
1.199     sakharuk  698: #Mathematical Operators (extended HTML 4.01)
1.281     sakharuk  699:     $result =~ s/&(forall|\#8704);/\\ensuremath\{\\forall\}/g;
                    700:     $result =~ s/&(part|\#8706);/\\ensuremath\{\\partial\}/g;
                    701:     $result =~ s/&(exist|\#8707);/\\ensuremath\{\\exists\}/g;
                    702:     $result =~ s/&(empty|\#8709);/\\ensuremath\{\\emptyset\}/g;
                    703:     $result =~ s/&(nabla|\#8711);/\\ensuremath\{\\nabla\}/g;
                    704:     $result =~ s/&(isin|\#8712);/\\ensuremath\{\\in\}/g;
                    705:     $result =~ s/&(notin|\#8713);/\\ensuremath\{\\notin\}/g;
                    706:     $result =~ s/&(ni|\#8715);/\\ensuremath\{\\ni\}/g;
                    707:     $result =~ s/&(prod|\#8719);/\\ensuremath\{\\prod\}/g;
                    708:     $result =~ s/&(sum|\#8721);/\\ensuremath\{\\sum\}/g;
                    709:     $result =~ s/&(minus|\#8722);/\\ensuremath\{-\}/g;
1.390     albertel  710:     $result =~ s/–/\\ensuremath\{-\}/g;
1.281     sakharuk  711:     $result =~ s/&(lowast|\#8727);/\\ensuremath\{*\}/g;
                    712:     $result =~ s/&(radic|\#8730);/\\ensuremath\{\\surd\}/g;
                    713:     $result =~ s/&(prop|\#8733);/\\ensuremath\{\\propto\}/g;
                    714:     $result =~ s/&(infin|\#8734);/\\ensuremath\{\\infty\}/g;
                    715:     $result =~ s/&(ang|\#8736);/\\ensuremath\{\\angle\}/g;
                    716:     $result =~ s/&(and|\#8743);/\\ensuremath\{\\wedge\}/g;
                    717:     $result =~ s/&(or|\#8744);/\\ensuremath\{\\vee\}/g;
                    718:     $result =~ s/&(cap|\#8745);/\\ensuremath\{\\cap\}/g;
                    719:     $result =~ s/&(cup|\#8746);/\\ensuremath\{\\cup\}/g;
                    720:     $result =~ s/&(int|\#8747);/\\ensuremath\{\\int\}/g;
                    721:     $result =~ s/&(sim|\#8764);/\\ensuremath\{\\sim\}/g;
                    722:     $result =~ s/&(cong|\#8773);/\\ensuremath\{\\cong\}/g;
                    723:     $result =~ s/&(asymp|\#8776);/\\ensuremath\{\\approx\}/g;
                    724:     $result =~ s/&(ne|\#8800);/\\ensuremath\{\\not=\}/g;
                    725:     $result =~ s/&(equiv|\#8801);/\\ensuremath\{\\equiv\}/g;
                    726:     $result =~ s/&(le|\#8804);/\\ensuremath\{\\leq\}/g;
                    727:     $result =~ s/&(ge|\#8805);/\\ensuremath\{\\geq\}/g;
                    728:     $result =~ s/&(sub|\#8834);/\\ensuremath\{\\subset\}/g;
                    729:     $result =~ s/&(sup|\#8835);/\\ensuremath\{\\supset\}/g;
                    730:     $result =~ s/&(nsub|\#8836);/\\ensuremath\{\\not\\subset\}/g;
                    731:     $result =~ s/&(sube|\#8838);/\\ensuremath\{\\subseteq\}/g;
                    732:     $result =~ s/&(supe|\#8839);/\\ensuremath\{\\supseteq\}/g;
                    733:     $result =~ s/&(oplus|\#8853);/\\ensuremath\{\\oplus\}/g;
                    734:     $result =~ s/&(otimes|\#8855);/\\ensuremath\{\\otimes\}/g;
                    735:     $result =~ s/&(perp|\#8869);/\\ensuremath\{\\perp\}/g;
                    736:     $result =~ s/&(sdot|\#8901);/\\ensuremath\{\\cdot\}/g;
1.199     sakharuk  737: #Geometric Shapes (extended HTML 4.01)
1.281     sakharuk  738:     $result =~ s/&(loz|\#9674);/\\ensuremath\{\\Diamond\}/g;
1.199     sakharuk  739: #Miscellaneous Symbols (extended HTML 4.01)
1.281     sakharuk  740:     $result =~ s/&(spades|\#9824);/\\ensuremath\{\\spadesuit\}/g;
                    741:     $result =~ s/&(clubs|\#9827);/\\ensuremath\{\\clubsuit\}/g;
                    742:     $result =~ s/&(hearts|\#9829);/\\ensuremath\{\\heartsuit\}/g;
                    743:     $result =~ s/&(diams|\#9830);/\\ensuremath\{\\diamondsuit\}/g;
1.495     foxr      744: #   Chemically useful 'things' contributed by Hon Kie (bug 4652).
                    745:     $result =~ s/&\#8636;/\\ensuremath\{\\leftharpoonup\}/g;
                    746:     $result =~ s/&\#8637;/\\ensuremath\{\\leftharpoondown\}/g;
                    747:     $result =~ s/&\#8640;/\\ensuremath\{\\rightharpoonup\}/g;
                    748:     $result =~ s/&\#8641;/\\ensuremath\{\\rightharpoondown\}/g;
                    749:     $result =~ s/&\#8652;/\\ensuremath\{\\rightleftharpoons\}/g;
                    750:     $result =~ s/&\#8605;/\\ensuremath\{\\leadsto\}/g;
                    751:     $result =~ s/&\#8617;/\\ensuremath\{\\hookleftarrow\}/g;
                    752:     $result =~ s/&\#8618;/\\ensuremath\{\\hookrightarrow\}/g;
                    753:     $result =~ s/&\#8614;/\\ensuremath\{\\mapsto\}/g;
                    754:     $result =~ s/&\#8599;/\\ensuremath\{\\nearrow\}/g;
                    755:     $result =~ s/&\#8600;/\\ensuremath\{\\searrow\}/g;
                    756:     $result =~ s/&\#8601;/\\ensuremath\{\\swarrow\}/g;
                    757:     $result =~ s/&\#8598;/\\ensuremath\{\\nwarrow\}/g;
1.513   ! foxr      758: 
        !           759:     # Left/right quotations:
        !           760: 
        !           761:     $result =~ s/&(ldquo|#8220);/\`\`/g;
        !           762:     $result =~ s/&(rdquo|#8221);/\'\'/g;
        !           763: 
        !           764: 
1.37      sakharuk  765:     return $result;
                    766: }
1.41      sakharuk  767: 
                    768: 
1.327     albertel  769:                   #width, height, oddsidemargin, evensidemargin, topmargin
                    770: my %page_formats=
                    771:     ('letter' => {
                    772: 	 'book' => {
1.493     foxr      773: 	     '1' => [ '7.1 in','9.8 in', '-0.57 in','-0.57 in','0.275 in'],
                    774: 	     '2' => ['3.66 in','9.8 in', '-0.57 in','-0.57 in','0.275 in']
1.327     albertel  775: 	 },
                    776: 	 'album' => {
1.496     foxr      777: 	     '1' => [ '8.8 in', '6.8 in','-0.55 in',  '-0.55 in','0.394 in'],
1.484     albertel  778: 	     '2' => [ '4.8 in', '6.8 in','-0.5 in', '-1.0 in','3.5 in']
1.327     albertel  779: 	 },
                    780:      },
                    781:      'legal' => {
                    782: 	 'book' => {
                    783: 	     '1' => ['7.1 in','13 in',,'-0.57 in','-0.57 in','-0.5 in'],
                    784: 	     '2' => ['3.16 in','13 in','-0.57 in','-0.57 in','-0.5 in']
                    785: 	 },
                    786: 	 'album' => {
1.376     albertel  787: 	     '1' => ['12 in','7.1 in',,'-0.57 in','-0.57 in','-0.5 in'],
                    788:              '2' => ['6.0 in','7.1 in','-1 in','-1 in','5 in']
1.327     albertel  789:           },
                    790:      },
                    791:      'tabloid' => {
                    792: 	 'book' => {
                    793: 	     '1' => ['9.8 in','16 in','-0.57 in','-0.57 in','-0.5 in'],
                    794: 	     '2' => ['4.9 in','16 in','-0.57 in','-0.57 in','-0.5 in']
                    795: 	 },
                    796: 	 'album' => {
1.376     albertel  797: 	     '1' => ['16 in','9.8 in','-0.57 in','-0.57 in','-0.5 in'],
                    798: 	     '2' => ['16 in','4.9 in','-0.57 in','-0.57 in','-0.5 in']
1.327     albertel  799:           },
                    800:      },
                    801:      'executive' => {
                    802: 	 'book' => {
                    803: 	     '1' => ['6.8 in','9 in','-0.57 in','-0.57 in','1.2 in'],
                    804: 	     '2' => ['3.1 in','9 in','-0.57 in','-0.57 in','1.2 in']
                    805: 	 },
                    806: 	 'album' => {
                    807: 	     '1' => [],
                    808: 	     '2' => []
                    809:           },
                    810:      },
                    811:      'a2' => {
                    812: 	 'book' => {
                    813: 	     '1' => [],
                    814: 	     '2' => []
                    815: 	 },
                    816: 	 'album' => {
                    817: 	     '1' => [],
                    818: 	     '2' => []
                    819:           },
                    820:      },
                    821:      'a3' => {
                    822: 	 'book' => {
                    823: 	     '1' => [],
                    824: 	     '2' => []
                    825: 	 },
                    826: 	 'album' => {
                    827: 	     '1' => [],
                    828: 	     '2' => []
                    829:           },
                    830:      },
                    831:      'a4' => {
                    832: 	 'book' => {
1.493     foxr      833: 	     '1' => ['17.6 cm','27.2 cm','-1.397 cm','-2.11 cm','-1.27 cm'],
1.496     foxr      834: 	     '2' => [ '9.1 cm','27.2 cm','-1.397 cm','-2.11 cm','-1.27 cm']
1.327     albertel  835: 	 },
                    836: 	 'album' => {
1.496     foxr      837: 	     '1' => ['21.59 cm','19.558 cm','-1.397cm','-2.11 cm','0 cm'],
1.493     foxr      838: 	     '2' => ['9.91 cm','19.558 cm','-1.397 cm','-2.11 cm','0 cm']
1.327     albertel  839: 	 },
                    840:      },
                    841:      'a5' => {
                    842: 	 'book' => {
                    843: 	     '1' => [],
                    844: 	     '2' => []
                    845: 	 },
                    846: 	 'album' => {
                    847: 	     '1' => [],
                    848: 	     '2' => []
                    849:           },
                    850:      },
                    851:      'a6' => {
                    852: 	 'book' => {
                    853: 	     '1' => [],
                    854: 	     '2' => []
                    855: 	 },
                    856: 	 'album' => {
                    857: 	     '1' => [],
                    858: 	     '2' => []
                    859:           },
                    860:      },
                    861:      );
                    862: 
1.177     sakharuk  863: sub page_format {
1.140     sakharuk  864: #
1.326     sakharuk  865: #Supported paper format: "Letter [8 1/2x11 in]",      "Legal [8 1/2x14 in]",
                    866: #                        "Ledger/Tabloid [11x17 in]", "Executive [7 1/2x10 in]",
                    867: #                        "A2 [420x594 mm]",           "A3 [297x420 mm]",
                    868: #                        "A4 [210x297 mm]",           "A5 [148x210 mm]",
                    869: #                        "A6 [105x148 mm]"
1.140     sakharuk  870: # 
                    871:     my ($papersize,$layout,$numberofcolumns) = @_; 
1.327     albertel  872:     return @{$page_formats{$papersize}->{$layout}->{$numberofcolumns}};
1.140     sakharuk  873: }
1.76      sakharuk  874: 
                    875: 
1.126     albertel  876: sub get_name {
                    877:     my ($uname,$udom)=@_;
1.373     albertel  878:     if (!defined($uname)) { $uname=$env{'user.name'}; }
                    879:     if (!defined($udom)) { $udom=$env{'user.domain'}; }
1.126     albertel  880:     my $plainname=&Apache::loncommon::plainname($uname,$udom);
1.213     albertel  881:     if ($plainname=~/^\s*$/) { $plainname=$uname.'@'.$udom; }
1.453     foxr      882:    $plainname=&Apache::lonxml::latex_special_symbols($plainname,'header');
1.213     albertel  883:     return $plainname;
1.126     albertel  884: }
                    885: 
1.213     albertel  886: sub get_course {
                    887:     my $courseidinfo;
1.373     albertel  888:     if (defined($env{'request.course.id'})) {
1.439     www       889: 	$courseidinfo = &Apache::lonxml::latex_special_symbols(&unescape($env{'course.'.$env{'request.course.id'}.'.description'}),'header');
1.213     albertel  890:     }
                    891:     return $courseidinfo;
                    892: }
1.177     sakharuk  893: 
1.76      sakharuk  894: sub page_format_transformation {
1.312     sakharuk  895:     my ($papersize,$layout,$numberofcolumns,$choice,$text,$assignment,$tableofcontents,$indexlist,$selectionmade) = @_; 
1.202     sakharuk  896:     my ($textwidth,$textheight,$oddoffset,$evenoffset,$topmargin);
1.454     foxr      897: 
1.312     sakharuk  898:     if ($selectionmade eq '4') {
1.502     foxr      899: 	if ($choice eq 'all_problems') {
                    900: 	    $assignment='Problems from the Whole Course';
                    901: 	} else {
                    902: 	    $assignment='Resources from the Whole Course';
                    903: 	}
1.312     sakharuk  904:     } else {
                    905: 	$assignment=&Apache::lonxml::latex_special_symbols($assignment,'header');
                    906:     }
1.261     sakharuk  907:     ($textwidth,$textheight,$oddoffset,$evenoffset,$topmargin) = &page_format($papersize,$layout,$numberofcolumns,$topmargin);
1.454     foxr      908: 
                    909: 
1.126     albertel  910:     my $name = &get_name();
1.213     albertel  911:     my $courseidinfo = &get_course();
                    912:     if (defined($courseidinfo)) { $courseidinfo=' - '.$courseidinfo }
1.455     albertel  913:     my $header_text  = $parmhash{'print_header_format'};
1.486     foxr      914:     $header_text     = &format_page_header($textwidth, $header_text, $assignment,
1.455     albertel  915: 					   $courseidinfo, $name);
1.319     sakharuk  916:     my $topmargintoinsert = '';
                    917:     if ($topmargin ne '0') {$topmargintoinsert='\setlength{\topmargin}{'.$topmargin.'}';}
1.325     sakharuk  918:     my $fancypagestatement='';
                    919:     if ($numberofcolumns eq '2') {
1.455     albertel  920: 	$fancypagestatement="\\fancyhead{}\\fancyhead[LO]{$header_text}";
1.325     sakharuk  921:     } else {
1.455     albertel  922: 	$fancypagestatement="\\rhead{}\\chead{}\\lhead{$header_text}";
1.325     sakharuk  923:     }
1.140     sakharuk  924:     if ($layout eq 'album') {
1.340     foxr      925: 	    $text =~ s/\\begin{document}/\\setlength{\\oddsidemargin}{$oddoffset}\\setlength{\\evensidemargin}{$evenoffset}$topmargintoinsert\n\\setlength{\\textwidth}{$textwidth}\\setlength{\\textheight}{$textheight}\\setlength{\\textfloatsep}{8pt plus 2\.0pt minus 4\.0pt}\n\\newlength{\\minipagewidth}\\setlength{\\minipagewidth}{\\textwidth\/\$number_of_columns-0\.2cm}\\usepackage{fancyhdr}\\addtolength{\\headheight}{\\baselineskip}\n\\pagestyle{fancy}$fancypagestatement\\begin{document}\\voffset=-0\.8 cm\\setcounter{page}{1}\n /;
1.140     sakharuk  926:     } elsif ($layout eq 'book') {
                    927: 	if ($choice ne 'All class print') { 
1.340     foxr      928: 	    $text =~ s/\\begin{document}/\\textheight $textheight\\oddsidemargin = $evenoffset\\evensidemargin = $evenoffset $topmargintoinsert\n\\textwidth= $textwidth\\newlength{\\minipagewidth}\\setlength{\\minipagewidth}{\\textwidth\/\$number_of_columns-0\.2cm}\n\\renewcommand{\\ref}{\\keephidden\}\\usepackage{fancyhdr}\\addtolength{\\headheight}{\\baselineskip}\\pagestyle{fancy}$fancypagestatement\\begin{document}\n\\voffset=-0\.8 cm\\setcounter{page}{1}\n/;
1.140     sakharuk  929: 	} else {
1.340     foxr      930: 	    $text =~ s/\\pagestyle{fancy}\\rhead{}\\chead{}\s*\\begin{document}/\\textheight = $textheight\\oddsidemargin = $evenoffset\n\\evensidemargin = $evenoffset $topmargintoinsert\\textwidth= $textwidth\\newlength{\\minipagewidth}\n\\setlength{\\minipagewidth}{\\textwidth\/\$number_of_columns-0\.2cm}\\renewcommand{\\ref}{\\keephidden\}\\pagestyle{fancy}\\rhead{}\\chead{}\\begin{document}\\voffset=-0\.8cm\n\\setcounter{page}{1}  \\vskip 5 mm\n /;
1.319     sakharuk  931: 	}
1.326     sakharuk  932: 	if ($papersize eq 'a4') {
1.319     sakharuk  933: 	    $text =~ s/(\\begin{document})/$1\\special{papersize=210mm,297mm}/;
1.140     sakharuk  934: 	}
                    935:     }
1.214     sakharuk  936:     if ($tableofcontents eq 'yes') {$text=~s/(\\setcounter\{page\}\{1\})/$1 \\tableofcontents\\newpage /;}
                    937:     if ($indexlist eq 'yes') {
                    938: 	$text=~s/(\\begin{document})/\\makeindex $1/;
                    939: 	$text=~s/(\\end{document})/\\strut\\\\\\strut\\printindex $1/;
                    940:     }
1.140     sakharuk  941:     return $text;
                    942: }
                    943: 
                    944: 
1.33      sakharuk  945: sub page_cleanup {
                    946:     my $result = shift;	
1.65      sakharuk  947:  
                    948:     $result =~ m/\\end{document}(\d*)$/;
1.34      sakharuk  949:     my $number_of_columns = $1;
1.33      sakharuk  950:     my $insert = '{';
1.34      sakharuk  951:     for (my $id=1;$id<=$number_of_columns;$id++) { $insert .='l'; }
1.33      sakharuk  952:     $insert .= '}';
1.65      sakharuk  953:     $result =~ s/(\\begin{longtable})INSERTTHEHEADOFLONGTABLE\\endfirsthead\\endhead/$1$insert/g;
1.34      sakharuk  954:     $result =~ s/&\s*REMOVETHEHEADOFLONGTABLE\\\\/\\\\/g;
                    955:     return $result,$number_of_columns;
1.7       sakharuk  956: }
1.5       sakharuk  957: 
1.3       sakharuk  958: 
1.60      sakharuk  959: sub details_for_menu {
1.335     albertel  960:     my ($helper)=@_;
1.373     albertel  961:     my $postdata=$env{'form.postdata'};
1.335     albertel  962:     if (!$postdata) { $postdata=$helper->{VARS}{'postdata'}; }
                    963:     my $name_of_resource = &Apache::lonnet::gettitle($postdata);
                    964:     my $symbolic = &Apache::lonnet::symbread($postdata);
1.482     albertel  965:     return if ( $symbolic eq '');
                    966: 
1.233     www       967:     my ($map,$id,$resource)=&Apache::lonnet::decode_symb($symbolic);
1.123     albertel  968:     $map=&Apache::lonnet::clutter($map);
1.269     albertel  969:     my $name_of_sequence = &Apache::lonnet::gettitle($map);
1.63      albertel  970:     if ($name_of_sequence =~ /^\s*$/) {
1.123     albertel  971: 	$map =~ m|([^/]+)$|;
                    972: 	$name_of_sequence = $1;
1.63      albertel  973:     }
1.373     albertel  974:     my $name_of_map = &Apache::lonnet::gettitle($env{'request.course.uri'});
1.63      albertel  975:     if ($name_of_map =~ /^\s*$/) {
1.373     albertel  976: 	$env{'request.course.uri'} =~ m|([^/]+)$|;
1.123     albertel  977: 	$name_of_map = $1;
                    978:     }
1.335     albertel  979:     return ($name_of_resource,$name_of_sequence,$name_of_map);
1.76      sakharuk  980: }
                    981: 
1.476     albertel  982: sub copyright_line {
                    983:     return '\noindent\makebox[\textwidth/$number_of_columns][b]{\hrulefill}\vspace*{-2 mm}\newline\noindent{\tiny Printed from LON-CAPA\copyright MSU{\hfill} Licensed under GNU General Public License } ';
                    984: }
                    985: my $end_of_student = "\n".'\special{ps:ENDOFSTUDENTSTAMP}'."\n";
1.76      sakharuk  986: 
                    987: sub latex_corrections {
1.408     albertel  988:     my ($number_of_columns,$result,$selectionmade,$answer_mode) = @_;
1.185     sakharuk  989: #    $result =~ s/\\includegraphics{/\\includegraphics\[width=\\minipagewidth\]{/g;
1.476     albertel  990:     my $copyright = &copyright_line();
1.408     albertel  991:     if ($selectionmade eq '1' || $answer_mode eq 'only') {
1.476     albertel  992: 	$result =~ s/(\\end{document})/\\strut\\vskip 0 mm $copyright $end_of_student $1/;
1.408     albertel  993:     } else {
1.476     albertel  994: 	$result =~ s/(\\end{document})/\\strut\\vspace\*{-4 mm}\\newline $copyright $end_of_student $1/;
1.316     sakharuk  995:     }
1.476     albertel  996:     $result =~ s/\$number_of_columns/$number_of_columns/g;
1.91      sakharuk  997:     $result =~ s/(\\end{longtable}\s*)(\\strut\\newline\\noindent\\makebox\[\\textwidth\/$number_of_columns\]\[b\]{\\hrulefill})/$2$1/g;
                    998:     $result =~ s/(\\end{longtable}\s*)\\strut\\newline/$1/g;
1.76      sakharuk  999: #-- LaTeX corrections     
                   1000:     my $first_comment = index($result,'<!--',0);
                   1001:     while ($first_comment != -1) {
                   1002: 	my $end_comment = index($result,'-->',$first_comment);
                   1003: 	substr($result,$first_comment,$end_comment-$first_comment+3) = '';
                   1004: 	$first_comment = index($result,'<!--',$first_comment);
                   1005:     }
                   1006:     $result =~ s/^\s+$//gm; #remove empty lines
1.377     albertel 1007:     #removes more than one empty space
                   1008:     $result =~ s|(\s\s+)|($1=~/[\n\r]/)?"\n":" "|ge;
1.76      sakharuk 1009:     $result =~ s/\\\\\s*\\vskip/\\vskip/gm;
                   1010:     $result =~ s/\\\\\s*\\noindent\s*(\\\\)+/\\\\\\noindent /g;
                   1011:     $result =~ s/{\\par }\s*\\\\/\\\\/gm;
1.313     sakharuk 1012:     $result =~ s/\\\\\s+\[/ \[/g;
1.76      sakharuk 1013:     #conversion of html characters to LaTeX equivalents
                   1014:     if ($result =~ m/&(\w+|#\d+);/) {
                   1015: 	$result = &character_chart($result);
                   1016:     }
                   1017:     $result =~ s/(\\end{tabular})\s*\\vskip 0 mm/$1/g;
                   1018:     $result =~ s/(\\begin{enumerate})\s*\\noindent/$1/g;
                   1019:     return $result;
1.60      sakharuk 1020: }
                   1021: 
1.3       sakharuk 1022: 
1.214     sakharuk 1023: sub index_table {
                   1024:     my $currentURL = shift;
                   1025:     my $insex_string='';
                   1026:     $currentURL=~s/\.([^\/+])$/\.$1\.meta/;
                   1027:     $insex_string=&Apache::lonnet::metadata($currentURL,'keywords');
                   1028:     return $insex_string;
                   1029: }
                   1030: 
                   1031: 
1.215     sakharuk 1032: sub IndexCreation {
                   1033:     my ($texversion,$currentURL)=@_;
                   1034:     my @key_words=split(/,/,&index_table($currentURL));
                   1035:     my $chunk='';
                   1036:     my $st=index $texversion,'\addcontentsline{toc}{subsection}{';
                   1037:     if ($st>0) {
                   1038: 	for (my $i=0;$i<3;$i++) {$st=(index $texversion,'}',$st+1);}
                   1039: 	$chunk=substr($texversion,0,$st+1);
                   1040: 	substr($texversion,0,$st+1)=' ';
                   1041:     }
                   1042:     foreach my $key_word (@key_words) {
                   1043: 	if ($key_word=~/\S+/) {
                   1044: 	    $texversion=~s/\b($key_word)\b/$1 \\index{$key_word} /i;
                   1045: 	}
                   1046:     }			
                   1047:     if ($st>0) {substr($texversion,0,1)=$chunk;}
                   1048:     return $texversion;
                   1049: }
                   1050: 
1.242     sakharuk 1051: sub print_latex_header {
                   1052:     my $mode=shift;
1.473     albertel 1053:     my $output='\documentclass[letterpaper,twoside]{article}\raggedbottom';
1.397     albertel 1054:     if (($mode eq 'batchmode') || (!$perm{'pav'})) {
1.242     sakharuk 1055: 	$output.='\batchmode';
                   1056:     }
1.340     foxr     1057:     $output.='\newcommand{\keephidden}[1]{}\renewcommand{\deg}{$^{\circ}$}'."\n".
1.410     foxr     1058:    	    '\usepackage{multirow}'."\n".
1.340     foxr     1059: 	     '\usepackage{longtable}\usepackage{textcomp}\usepackage{makeidx}'."\n".
1.344     foxr     1060: 	     '\usepackage[dvips]{graphicx}\usepackage{epsfig}'."\n".
1.393     foxr     1061: 	     '\usepackage{wrapfig}'.
1.344     foxr     1062: 	     '\usepackage{picins}\usepackage{calc}'."\n".
1.340     foxr     1063: 	     '\newenvironment{choicelist}{\begin{list}{}{\setlength{\rightmargin}{0in}'."\n".
                   1064: 	     '\setlength{\leftmargin}{0.13in}\setlength{\topsep}{0.05in}'."\n".
                   1065: 	     '\setlength{\itemsep}{0.022in}\setlength{\parsep}{0in}'."\n".
                   1066: 	     '\setlength{\belowdisplayskip}{0.04in}\setlength{\abovedisplayskip}{0.05in}'."\n".
                   1067: 	     '\setlength{\abovedisplayshortskip}{-0.04in}'."\n".
                   1068: 	     '\setlength{\belowdisplayshortskip}{0.04in}}}{\end{list}}'."\n".
                   1069: 	     '\renewenvironment{theindex}{\begin{list}{}{{\vskip 1mm \noindent \large'."\n".
                   1070: 	     '\textbf{Index}} \newline \setlength{\rightmargin}{0in}'."\n".
                   1071: 	     '\setlength{\leftmargin}{0.13in}\setlength{\topsep}{0.01in}'."\n".
                   1072: 	     '\setlength{\itemsep}{0.1in}\setlength{\parsep}{-0.02in}'."\n".
                   1073: 	     '\setlength{\belowdisplayskip}{0.01in}\setlength{\abovedisplayskip}{0.01in}'."\n".
                   1074: 	     '\setlength{\abovedisplayshortskip}{-0.04in}'."\n".
                   1075: 	     '\setlength{\belowdisplayshortskip}{0.01in}}}{\end{list}}\begin{document}'."\n";
1.242     sakharuk 1076:     return $output;	     
                   1077: }
                   1078: 
                   1079: sub path_to_problem {
1.328     albertel 1080:     my ($urlp,$colwidth)=@_;
1.404     albertel 1081:     $urlp=&Apache::lonnet::clutter($urlp);
                   1082: 
1.242     sakharuk 1083:     my $newurlp = '';
1.328     albertel 1084:     $colwidth=~s/\s*mm\s*$//;
                   1085: #characters average about 2 mm in width
1.360     albertel 1086:     if (length($urlp)*2 > $colwidth) {
1.404     albertel 1087: 	my @elements = split('/',$urlp);
1.328     albertel 1088: 	my $curlength=0;
                   1089: 	foreach my $element (@elements) {
1.404     albertel 1090: 	    if ($element eq '') { next; }
1.328     albertel 1091: 	    if ($curlength+(length($element)*2) > $colwidth) {
1.404     albertel 1092: 		$newurlp .=  '|\vskip -1 mm \verb|';
                   1093: 		$curlength=length($element)*2;
1.328     albertel 1094: 	    } else {
                   1095: 		$curlength+=length($element)*2;
1.242     sakharuk 1096: 	    }
1.328     albertel 1097: 	    $newurlp.='/'.$element;
1.242     sakharuk 1098: 	}
1.253     sakharuk 1099:     } else {
                   1100: 	$newurlp=$urlp;
1.242     sakharuk 1101:     }
                   1102:     return '{\small\noindent\verb|'.$newurlp.'|\vskip 0 mm}';
                   1103: }
1.215     sakharuk 1104: 
1.275     sakharuk 1105: sub recalcto_mm {
                   1106:     my $textwidth=shift;
                   1107:     my $LaTeXwidth;
1.339     albertel 1108:     if ($textwidth=~/(-?\d+\.?\d*)\s*cm/) {
1.275     sakharuk 1109: 	$LaTeXwidth = $1*10;
1.339     albertel 1110:     } elsif ($textwidth=~/(-?\d+\.?\d*)\s*mm/) {
1.275     sakharuk 1111: 	$LaTeXwidth = $1;
1.339     albertel 1112:     } elsif ($textwidth=~/(-?\d+\.?\d*)\s*in/) {
1.275     sakharuk 1113: 	$LaTeXwidth = $1*25.4;
                   1114:     }
                   1115:     $LaTeXwidth.=' mm';
                   1116:     return $LaTeXwidth;
                   1117: }
                   1118: 
1.285     albertel 1119: sub get_textwidth {
                   1120:     my ($helper,$LaTeXwidth)=@_;
1.286     albertel 1121:     my $textwidth=$LaTeXwidth;
1.285     albertel 1122:     if ($helper->{'VARS'}->{'pagesize.width'}=~/\d+/ &&
                   1123: 	$helper->{'VARS'}->{'pagesize.widthunit'}=~/\w+/) {
1.286     albertel 1124: 	$textwidth=&recalcto_mm($helper->{'VARS'}->{'pagesize.width'}.' '.
                   1125: 				$helper->{'VARS'}->{'pagesize.widthunit'});
1.285     albertel 1126:     }
1.286     albertel 1127:     return $textwidth;
1.285     albertel 1128: }
                   1129: 
1.296     sakharuk 1130: 
                   1131: sub unsupported {
1.414     albertel 1132:     my ($currentURL,$mode,$symb)=@_;
1.307     sakharuk 1133:     if ($mode ne '') {$mode='\\'.$mode}
1.308     sakharuk 1134:     my $result.= &print_latex_header($mode);
1.414     albertel 1135:     if ($currentURL=~m|^(/adm/wrapper/)?ext/|) {
                   1136: 	$currentURL=~s|^(/adm/wrapper/)?ext/|http://|;
                   1137: 	my $title=&Apache::lonnet::gettitle($symb);
                   1138: 	$title = &Apache::lonxml::latex_special_symbols($title);
                   1139: 	$result.=' \strut \\\\ '.$title.' \strut \\\\ '.$currentURL.' ';
1.296     sakharuk 1140:     } else {
                   1141: 	$result.=$currentURL;
                   1142:     }
1.419     albertel 1143:     $result.= '\vskip 0.5mm\noindent\makebox[\textwidth/$number_of_columns][b]{\hrulefill} \end{document}';
1.296     sakharuk 1144:     return $result;
                   1145: }
                   1146: 
                   1147: 
1.363     foxr     1148: #
1.395     www      1149: # List of recently generated print files
                   1150: #
                   1151: sub recently_generated {
                   1152:     my $r=shift;
                   1153:     my $prtspool=$r->dir_config('lonPrtDir');
1.400     albertel 1154:     my $zip_result;
                   1155:     my $pdf_result;
1.395     www      1156:     opendir(DIR,$prtspool);
1.400     albertel 1157: 
                   1158:     my @files = 
                   1159: 	grep(/^$env{'user.name'}_$env{'user.domain'}_printout_(\d+)_.*\.(pdf|zip)$/,readdir(DIR));
1.395     www      1160:     closedir(DIR);
1.400     albertel 1161: 
                   1162:     @files = sort {
                   1163: 	my ($actime) = (stat($prtspool.'/'.$a))[10];
                   1164: 	my ($bctime) = (stat($prtspool.'/'.$b))[10];
                   1165: 	return $bctime <=> $actime;
                   1166:     } (@files);
                   1167: 
                   1168:     foreach my $filename (@files) {
                   1169: 	my ($ext) = ($filename =~ m/(pdf|zip)$/);
                   1170: 	my ($cdev,$cino,$cmode,$cnlink,
                   1171: 	    $cuid,$cgid,$crdev,$csize,
                   1172: 	    $catime,$cmtime,$cctime,
                   1173: 	    $cblksize,$cblocks)=stat($prtspool.'/'.$filename);
                   1174: 	my $result="<a href='/prtspool/$filename'>".
                   1175: 	    &mt('Generated [_1] ([_2] bytes)',
                   1176: 		&Apache::lonlocal::locallocaltime($cctime),$csize).
                   1177: 		'</a><br />';
                   1178: 	if ($ext eq 'pdf') { $pdf_result .= $result; }
                   1179: 	if ($ext eq 'zip') { $zip_result .= $result; }
                   1180:     }
                   1181:     if ($zip_result) {
                   1182: 	$r->print('<h4>'.&mt('Recently generated printout zip files')."</h4>\n"
                   1183: 		  .$zip_result);
                   1184:     }
                   1185:     if ($pdf_result) {
                   1186: 	$r->print('<h4>'.&mt('Recently generated printouts')."</h4>\n"
                   1187: 		  .$pdf_result);
1.396     albertel 1188:     }
1.395     www      1189: }
                   1190: 
                   1191: #
1.363     foxr     1192: #   Retrieve the hash of page breaks.
                   1193: #
                   1194: #  Inputs:
                   1195: #    helper   - reference to helper object.
                   1196: #  Outputs
                   1197: #    A reference to a page break hash.
                   1198: #
                   1199: #
1.418     foxr     1200: #use Data::Dumper;
                   1201: #sub dump_helper_vars {
                   1202: #    my ($helper) = @_;
                   1203: #    my $helpervars = Dumper($helper->{'VARS'});
                   1204: #    &Apache::lonnet::logthis("Dump of helper vars:\n $helpervars");
                   1205: #}
1.363     foxr     1206: 
1.481     albertel 1207: sub get_page_breaks  {
                   1208:     my ($helper) = @_;
                   1209:     my %page_breaks;
                   1210: 
                   1211:     foreach my $break (split /\|\|\|/, $helper->{'VARS'}->{'FINISHPAGE'}) {
                   1212: 	$page_breaks{$break} = 1;
                   1213:     }
                   1214:     return %page_breaks;
                   1215: }
1.363     foxr     1216: 
1.459     foxr     1217: #  Output a sequence (recursively if neeed)
                   1218: #  from construction space.
                   1219: # Parameters:
                   1220: #    url     = URL of the sequence to print.
                   1221: #    helper  - Reference to the helper hash.
                   1222: #    form    - Copy of the format hash.
                   1223: #    LaTeXWidth
                   1224: # Returns:
                   1225: #   Text to add to the printout.
                   1226: #   NOTE if the first element of the outermost sequence
                   1227: #   is itself a sequence, the outermost caller may need to
                   1228: #   prefix the latex with the page headers stuff.
                   1229: #
                   1230: sub print_construction_sequence {
                   1231:     my ($currentURL, $helper, %form, $LaTeXwidth) = @_;
                   1232:     my $result;
                   1233:     my $rndseed=time;
                   1234:     if ($helper->{'VARS'}->{'curseed'}) {
                   1235: 	$rndseed=$helper->{'VARS'}->{'curseed'};
                   1236:     }
1.491     albertel 1237:     my $errtext=&LONCAPA::map::mapread($currentURL);
1.459     foxr     1238:     # 
                   1239:     #  These make this all support recursing for subsequences.
                   1240:     #
1.491     albertel 1241:     my @order    = @LONCAPA::map::order;
                   1242:     my @resources = @LONCAPA::map::resources; 
1.459     foxr     1243:     for (my $member=0;$member<=$#order;$member++) {
                   1244: 	$resources[$order[$member]]=~/^([^:]*):([^:]*):/;
                   1245: 	my $urlp=$2;
                   1246: 	if ($urlp=~/\.(problem|exam|quiz|assess|survey|form|library|xml|html|htm|xhtml|xhtm)$/) {
                   1247: 	    my $texversion='';
                   1248: 	    if ($helper->{'VARS'}->{'ANSWER_TYPE'} ne 'only') {
                   1249: 		$form{'problem_split'}=$parmhash{'problem_stream_switch'};
                   1250: 		$form{'suppress_tries'}=$parmhash{'suppress_tries'};
                   1251: 		$form{'latex_type'}=$helper->{'VARS'}->{'LATEX_TYPE'};
                   1252: 		$form{'rndseed'}=$rndseed;
                   1253: 		$resources_printed .=$urlp.':';
                   1254: 		$texversion=&Apache::lonnet::ssi($urlp,%form);
                   1255: 	    }
                   1256: 	    if((($helper->{'VARS'}->{'ANSWER_TYPE'} eq 'no') ||
                   1257: 		($helper->{'VARS'}->{'ANSWER_TYPE'} eq 'only')) && 
                   1258: 	       ($urlp=~/\.(problem|exam|quiz|assess|survey|form|library|page)$/)) {
                   1259: 		#  Don't permanently modify %$form...
                   1260: 		my %answerform = %form;
                   1261: 		$answerform{'grade_target'}='answer';
                   1262: 		$answerform{'answer_output_mode'}='tex';
                   1263: 		$answerform{'rndseed'}=$rndseed;
                   1264: 		$answerform{'problem_split'}=$parmhash{'problem_stream_switch'};
1.481     albertel 1265: 		if ($urlp=~/\/res\//) {$env{'request.state'}='published';}
1.459     foxr     1266: 		$resources_printed .= $urlp.':';
                   1267: 		my $answer=&Apache::lonnet::ssi($urlp,%answerform);
                   1268: 		if ($helper->{'VARS'}->{'ANSWER_TYPE'} eq 'no') {
                   1269: 		    $texversion=~s/(\\keephidden{ENDOFPROBLEM})/$answer$1/;
                   1270: 		} else {
                   1271: 		    # If necessary, encapsulate answer in minipage:
                   1272: 		    
                   1273: 		    $texversion=&print_latex_header($helper->{'VARS'}->{'LATEX_TYPE'});
1.477     albertel 1274: 		    my $title = &Apache::lonnet::gettitle($helper->{'VARS'}->{'symb'});
                   1275: 		    $title = &Apache::lonxml::latex_special_symbols($title);
                   1276: 		    my $body ='\vskip 0 mm \noindent\textbf{'.$title.'}\vskip 0 mm ';
1.459     foxr     1277: 		    $body.=&path_to_problem($urlp,$LaTeXwidth);
                   1278: 		    $body.='\vskip 1 mm '.$answer.'\end{document}';
                   1279: 		    $body = &encapsulate_minipage($body);
                   1280: 		    $texversion.=$body;
                   1281: 		}
                   1282: 	    }
                   1283: 	    $texversion = &latex_header_footer_remove($texversion);
                   1284: 
                   1285: 	    if ($helper->{'VARS'}->{'TABLE_INDEX'} eq 'yes') {
                   1286: 		$texversion=&IndexCreation($texversion,$urlp);
                   1287: 	    }
                   1288: 	    if ($helper->{'VARS'}->{'CONSTR_RESOURSE_URL'} eq 'yes') {
                   1289: 		$texversion=~s/(\\addcontentsline\{toc\}\{subsection\}\{[^\}]*\})/$1 URL: \\verb|$urlp| \\strut\\\\\\strut /;
                   1290: 	    }
                   1291: 	    $result.=$texversion;
                   1292: 
                   1293: 	} elsif ($urlp=~/\.(sequence|page)$/) {
                   1294: 	    
                   1295: 	    # header:
                   1296: 
                   1297: 	    $result.='\strut\newline\noindent Sequence/page '.$urlp.'\strut\newline\noindent\makebox[\textwidth/$number_of_columns][b]{\hrulefill}\newline\noindent ';
                   1298: 
                   1299: 	    # IF sequence, recurse:
                   1300: 	    
                   1301: 	    if ($urlp =~ /\.sequence$/) {
                   1302: 		my $sequence_url = $urlp;
                   1303: 		my $domain       = $env{'user.domain'};	# Constr. space only on local
                   1304: 		my $user         = $env{'user.name'};
                   1305: 
                   1306: 		$sequence_url    =~ s/^\/res\/$domain/\/home/;
                   1307: 		$sequence_url    =~ s/^(\/home\/$user)/$1\/public_html/;
                   1308: #		$sequence_url    =~ s|\/~([^\/]+)\/|\/home\/$1\/public_html\/|;
                   1309: 		$result .= &print_construction_sequence($sequence_url, 
                   1310: 							$helper, %form, 
                   1311: 							$LaTeXwidth);
                   1312: 	    }
                   1313: 	}  
                   1314:     }
                   1315:     if ($helper->{VARS}->{'construction'} eq '1') {$result=~s/(\\begin{document})/$1 \\fbox\{RANDOM SEED IS $rndseed\} /;}
                   1316:     return $result;
                   1317: }
                   1318: 
1.177     sakharuk 1319: sub output_data {
1.184     sakharuk 1320:     my ($r,$helper,$rparmhash) = @_;
                   1321:     my %parmhash = %$rparmhash;
1.459     foxr     1322:     $resources_printed = '';
1.499     foxr     1323:     my $do_postprocessing = 1;
1.433     albertel 1324:     my $js = <<ENDPART;
                   1325: <script type="text/javascript">
1.264     sakharuk 1326:     var editbrowser;
                   1327:     function openbrowser(formname,elementname,only,omit) {
                   1328:         var url = '/res/?';
                   1329:         if (editbrowser == null) {
                   1330:             url += 'launch=1&';
                   1331:         }
                   1332:         url += 'catalogmode=interactive&';
                   1333:         url += 'mode=parmset&';
                   1334:         url += 'form=' + formname + '&';
                   1335:         if (only != null) {
                   1336:             url += 'only=' + only + '&';
                   1337:         } 
                   1338:         if (omit != null) {
                   1339:             url += 'omit=' + omit + '&';
                   1340:         }
                   1341:         url += 'element=' + elementname + '';
                   1342:         var title = 'Browser';
                   1343:         var options = 'scrollbars=1,resizable=1,menubar=0';
                   1344:         options += ',width=700,height=600';
                   1345:         editbrowser = open(url,title,options,'1');
                   1346:         editbrowser.focus();
                   1347:     }
                   1348: </script>
1.140     sakharuk 1349: ENDPART
                   1350: 
1.512     foxr     1351: 
                   1352: 
1.433     albertel 1353:     my $start_page  = &Apache::loncommon::start_page('Preparing Printout',$js);
                   1354:     my $msg = &mt('Please stand by while processing your print request, this may take some time ...');
1.363     foxr     1355: 
1.433     albertel 1356:     $r->print($start_page."\n<p>\n$msg\n</p>\n");
1.372     foxr     1357: 
1.363     foxr     1358:     # fetch the pagebreaks and store them in the course environment
                   1359:     # The page breaks will be pulled into the hash %page_breaks which is
                   1360:     # indexed by symb and contains 1's for each break.
                   1361: 
1.373     albertel 1362:     $env{'form.pagebreaks'}  = $helper->{'VARS'}->{'FINISHPAGE'};
                   1363:     $env{'form.lastprinttype'} = $helper->{'VARS'}->{'PRINT_TYPE'}; 
1.363     foxr     1364:     &Apache::loncommon::store_course_settings('print',
1.366     foxr     1365: 					      {'pagebreaks'    => 'scalar',
                   1366: 					       'lastprinttype' => 'scalar'});
1.363     foxr     1367: 
1.364     albertel 1368:     my %page_breaks  = &get_page_breaks($helper);
1.363     foxr     1369: 
1.140     sakharuk 1370:     my $format_from_helper = $helper->{'VARS'}->{'FORMAT'};
                   1371:     my ($result,$selectionmade) = ('','');
                   1372:     my $number_of_columns = 1; #used only for pages to determine the width of the cell
                   1373:     my @temporary_array=split /\|/,$format_from_helper;
                   1374:     my ($laystyle,$numberofcolumns,$papersize)=@temporary_array;
                   1375:     if ($laystyle eq 'L') {
                   1376: 	$laystyle='album';
                   1377:     } else {
                   1378: 	$laystyle='book';
                   1379:     }
1.177     sakharuk 1380:     my ($textwidth,$textheight,$oddoffset,$evenoffset) = &page_format($papersize,$laystyle,$numberofcolumns);
1.373     albertel 1381:     my $assignment =  $env{'form.assignment'};
1.275     sakharuk 1382:     my $LaTeXwidth=&recalcto_mm($textwidth); 
1.272     sakharuk 1383:     my @print_array=();
1.274     sakharuk 1384:     my @student_names=();
1.360     albertel 1385: 
1.512     foxr     1386:      
1.360     albertel 1387:     #  Common settings for the %form has:
                   1388:     # In some cases these settings get overriddent by specific cases, but the
                   1389:     # settings are common enough to make it worthwhile factoring them out
                   1390:     # here.
                   1391:     #
                   1392:     my %form;
                   1393:     $form{'grade_target'} = 'tex';
                   1394:     $form{'textwidth'}    = &get_textwidth($helper, $LaTeXwidth);
1.372     foxr     1395: 
                   1396:     # If form.showallfoils is set, then request all foils be shown:
                   1397:     # privilege will be enforced both by not allowing the 
                   1398:     # check box selecting this option to be presnt unless it's ok,
                   1399:     # and by lonresponse's priv. check.
                   1400:     # The if is here because lonresponse.pm only cares that
                   1401:     # showallfoils is defined, not what the value is.
                   1402: 
                   1403:     if ($helper->{'VARS'}->{'showallfoils'} eq "1") { 
                   1404: 	$form{'showallfoils'} = $helper->{'VARS'}->{'showallfoils'};
                   1405:     }
1.504     albertel 1406:     
                   1407:     if ($helper->{'VARS'}->{'style_file'}=~/\w/) {
                   1408: 	&Apache::lonnet::appenv('construct.style' =>
                   1409: 				$helper->{'VARS'}->{'style_file'});
                   1410:     } elsif ($env{'construct.style'}) {
                   1411: 	&Apache::lonnet::delenv('construct\\.style');
                   1412:     }
                   1413: 
1.372     foxr     1414: 
1.140     sakharuk 1415:     if ($helper->{'VARS'}->{'PRINT_TYPE'} eq 'current_document') {
1.143     sakharuk 1416:       #-- single document - problem, page, html, xml, ...
1.343     albertel 1417: 	my ($currentURL,$cleanURL);
1.375     foxr     1418: 
1.162     sakharuk 1419: 	if ($helper->{'VARS'}->{'construction'} ne '1') {
1.185     sakharuk 1420:             #prints published resource
1.153     sakharuk 1421: 	    $currentURL=$helper->{'VARS'}->{'postdata'};
1.343     albertel 1422: 	    $cleanURL=&Apache::lonenc::check_decrypt($currentURL);
1.143     sakharuk 1423: 	} else {
1.512     foxr     1424: 
1.185     sakharuk 1425:             #prints resource from the construction space
1.240     albertel 1426: 	    $currentURL='/'.$helper->{'VARS'}->{'filename'};
1.206     sakharuk 1427: 	    if ($currentURL=~/([^?]+)/) {$currentURL=$1;}
1.343     albertel 1428: 	    $cleanURL=$currentURL;
1.143     sakharuk 1429: 	}
1.140     sakharuk 1430: 	$selectionmade = 1;
1.413     albertel 1431: 	if ($cleanURL!~m|^/adm/|
                   1432: 	    && $cleanURL=~/\.(problem|exam|quiz|assess|survey|form|library|page|xml|html|htm|xhtml|xhtm)$/) {
1.169     albertel 1433: 	    my $rndseed=time;
1.242     sakharuk 1434: 	    my $texversion='';
                   1435: 	    if ($helper->{'VARS'}->{'ANSWER_TYPE'} ne 'only') {
                   1436: 		my %moreenv;
1.343     albertel 1437: 		$moreenv{'request.filename'}=$cleanURL;
1.290     sakharuk 1438:                 if ($helper->{'VARS'}->{'probstatus'} eq 'exam') {$form{'problemtype'}='exam';}
1.242     sakharuk 1439: 		$form{'problem_split'}=$parmhash{'problem_stream_switch'};
1.310     sakharuk 1440: 		$form{'suppress_tries'}=$parmhash{'suppress_tries'};
1.242     sakharuk 1441: 		$form{'latex_type'}=$helper->{'VARS'}->{'LATEX_TYPE'};
1.309     sakharuk 1442: 		$form{'print_discussions'}=$helper->{'VARS'}->{'PRINT_DISCUSSIONS'};
1.511     foxr     1443: 		$form{'print_annotations'}=$helper->{'VARS'}->{'PRINT_ANNOTATIONS'};
                   1444: 		if (($helper->{'VARS'}->{'PRINT_DISCUSSIONS'} eq 'yes') ||
                   1445: 		    ($helper->{'VARS'}->{'PRINT_ANNOTATIONS'} eq 'yes')) {
                   1446: 		    $form{'problem_split'}='yes';
                   1447: 		}
1.242     sakharuk 1448: 		if ($helper->{'VARS'}->{'curseed'}) {
                   1449: 		    $rndseed=$helper->{'VARS'}->{'curseed'};
                   1450: 		}
                   1451: 		$form{'rndseed'}=$rndseed;
                   1452: 		&Apache::lonnet::appenv(%moreenv);
1.428     albertel 1453: 
                   1454: 		&Apache::lonxml::clear_problem_counter();
                   1455: 
1.375     foxr     1456: 		$resources_printed .= $currentURL.':';
1.275     sakharuk 1457: 		$texversion.=&Apache::lonnet::ssi($currentURL,%form);
1.428     albertel 1458: 
1.511     foxr     1459: 		#  Add annotations if required:
                   1460: 	    
1.428     albertel 1461: 		&Apache::lonxml::clear_problem_counter();
                   1462: 
1.242     sakharuk 1463: 		&Apache::lonnet::delenv('request.filename');
1.230     albertel 1464: 	    }
1.423     foxr     1465: 	    # current document with answers.. no need to encap in minipage
                   1466: 	    #  since there's only one answer.
                   1467: 
1.242     sakharuk 1468: 	    if(($helper->{'VARS'}->{'ANSWER_TYPE'} eq 'no') ||
                   1469: 	       ($helper->{'VARS'}->{'ANSWER_TYPE'} eq 'only')) {
1.353     foxr     1470: 		$form{'problem_split'}=$parmhash{'problem_stream_switch'};
1.166     albertel 1471: 		$form{'grade_target'}='answer';
1.167     albertel 1472: 		$form{'answer_output_mode'}='tex';
1.169     albertel 1473: 		$form{'rndseed'}=$rndseed;
1.401     albertel 1474:                 if ($helper->{'VARS'}->{'probstatus'} eq 'exam') {
                   1475: 		    $form{'problemtype'}='exam';
                   1476: 		}
1.375     foxr     1477: 		$resources_printed .= $currentURL.':';
1.166     albertel 1478: 		my $answer=&Apache::lonnet::ssi($currentURL,%form);
1.511     foxr     1479: 		
                   1480: 
1.242     sakharuk 1481: 		if ($helper->{'VARS'}->{'ANSWER_TYPE'} eq 'no') {
                   1482: 		    $texversion=~s/(\\keephidden{ENDOFPROBLEM})/$answer$1/;
                   1483: 		} else {
                   1484: 		    $texversion=&print_latex_header($helper->{'VARS'}->{'LATEX_TYPE'});
1.245     sakharuk 1485: 		    if ($helper->{'VARS'}->{'construction'} ne '1') {
1.477     albertel 1486: 			my $title = &Apache::lonnet::gettitle($helper->{'VARS'}->{'symb'});
                   1487: 			$title = &Apache::lonxml::latex_special_symbols($title);
                   1488: 			$texversion.='\vskip 0 mm \noindent\textbf{'.$title.'}\vskip 0 mm ';
1.343     albertel 1489: 			$texversion.=&path_to_problem($cleanURL,$LaTeXwidth);
1.245     sakharuk 1490: 		    } else {
                   1491: 			$texversion.='\vskip 0 mm \noindent\textbf{Prints from construction space - there is no title.}\vskip 0 mm ';
1.343     albertel 1492: 			my $URLpath=$cleanURL;
1.245     sakharuk 1493: 			$URLpath=~s/~([^\/]+)/public_html\/$1\/$1/;
1.504     albertel 1494: 			$texversion.=&path_to_problem($URLpath,$LaTeXwidth);
1.245     sakharuk 1495: 		    }
1.242     sakharuk 1496: 		    $texversion.='\vskip 1 mm '.$answer.'\end{document}';
                   1497: 		}
1.511     foxr     1498: 
                   1499: 
                   1500: 		
                   1501: 
                   1502: 	    }
                   1503: 	    # Print annotations.
                   1504: 
                   1505: 
                   1506: 	    if ($helper->{'VARS'}->{'PRINT_ANNOTATIONS'} eq 'yes') {
                   1507: 		my $annotation .= &annotate($currentURL);
                   1508: 		$texversion =~ s/(\\keephidden{ENDOFPROBLEM})/$annotation$1/;
1.163     sakharuk 1509: 	    }
1.511     foxr     1510: 
                   1511: 
1.214     sakharuk 1512: 	    if ($helper->{'VARS'}->{'TABLE_INDEX'} eq 'yes') {
1.215     sakharuk 1513: 		$texversion=&IndexCreation($texversion,$currentURL);
1.214     sakharuk 1514: 	    }
1.219     sakharuk 1515: 	    if ($helper->{'VARS'}->{'CONSTR_RESOURSE_URL'} eq 'yes') {
                   1516: 		$texversion=~s/(\\addcontentsline\{toc\}\{subsection\}\{[^\}]*\})/$1 URL: \\verb|$currentURL| \\strut\\\\\\strut /;
                   1517: 
                   1518: 	    }
1.162     sakharuk 1519: 	    $result .= $texversion;
                   1520: 	    if ($currentURL=~m/\.page\s*$/) {
                   1521: 		($result,$number_of_columns) = &page_cleanup($result);
                   1522: 	    }
1.413     albertel 1523:         } elsif ($cleanURL!~m|^/adm/|
                   1524: 		 && $currentURL=~/\.sequence$/ && $helper->{'VARS'}->{'construction'} eq '1') {
1.227     sakharuk 1525:             #printing content of sequence from the construction space	
                   1526: 	    $currentURL=~s|\/~([^\/]+)\/|\/home\/$1\/public_html\/|;
1.459     foxr     1527: 	    $result .= &print_latex_header($helper->{'VARS'}->{'LATEX_TYPE'});
                   1528: 	    $result .= &print_construction_sequence($currentURL, $helper, %form,
                   1529: 						    $LaTeXwidth);
                   1530: 	    $result .= '\end{document}';  
                   1531: 	    if (!($result =~ /\\begin\{document\}/)) {
                   1532: 		$result = &print_latex_header() . $result;
1.227     sakharuk 1533: 	    }
1.459     foxr     1534: 	    # End construction space sequence.
1.456     raeburn  1535: 	} elsif ($cleanURL=~/\/(smppg|syllabus|aboutme|bulletinboard)$/) { 
1.258     sakharuk 1536: 		$form{'latex_type'}=$helper->{'VARS'}->{'LATEX_TYPE'};
1.298     sakharuk 1537: 		if ($currentURL=~/\/syllabus$/) {$currentURL=~s/\/res//;}
1.375     foxr     1538: 		$resources_printed .= $currentURL.':';
1.258     sakharuk 1539: 		my $texversion=&Apache::lonnet::ssi($currentURL,%form);
1.511     foxr     1540: 		if ($helper->{'VARS'}->{'PRINT_ANNOTATIONS'} eq 'yes') {
                   1541: 		    my $annotation = &annotate($currentURL);
                   1542: 		    $texversion    =~ s/(\\end{document})/$annotation$1/;
                   1543: 		}
1.258     sakharuk 1544: 		$result .= $texversion;
1.498     foxr     1545: 	} elsif ($cleanURL =~/.tex$/) {
                   1546: 	    # For this sort of print of a single LaTeX file,
                   1547: 	    # We can just print the LaTeX file as it is uninterpreted in any way:
                   1548: 	    #
                   1549: 
                   1550: 	    $result = &fetch_raw_resource($currentURL);
1.511     foxr     1551: 	    if ($helper->{'VARS'}->{'PRINT_ANNOTATIONS'} eq 'yes') {
                   1552: 		my $annotation = &annotate($currentURL);
                   1553: 		$result =~ s/(\\end{document})/$annotation$1/;
                   1554: 	    }
                   1555: 
1.499     foxr     1556: 	    $do_postprocessing = 0; # Don't massage the result.
1.498     foxr     1557: 
1.162     sakharuk 1558: 	} else {
1.414     albertel 1559: 	    $result.=&unsupported($currentURL,$helper->{'VARS'}->{'LATEX_TYPE'},
                   1560: 				  $helper->{'VARS'}->{'symb'});
1.162     sakharuk 1561: 	}
1.354     foxr     1562:     } elsif (($helper->{'VARS'}->{'PRINT_TYPE'} eq 'map_problems')       or
1.142     sakharuk 1563:              ($helper->{'VARS'}->{'PRINT_TYPE'} eq 'map_problems_pages') or
1.354     foxr     1564:              ($helper->{'VARS'}->{'PRINT_TYPE'} eq 'all_problems')       or
                   1565: 	     ($helper->{'VARS'}->{'PRINT_TYPE'} eq 'all_resources')      or # BUGBUG
1.252     sakharuk 1566: 	     ($helper->{'VARS'}->{'PRINT_TYPE'} eq 'select_sequences')) { 
1.511     foxr     1567: 
                   1568: 
1.141     sakharuk 1569:         #-- produce an output string
1.296     sakharuk 1570: 	if ($helper->{'VARS'}->{'PRINT_TYPE'} eq 'map_problems') {
                   1571: 	    $selectionmade = 2;
                   1572: 	} elsif ($helper->{'VARS'}->{'PRINT_TYPE'} eq 'map_problems_pages') {
                   1573: 	    $selectionmade = 3;
                   1574: 	} elsif ($helper->{'VARS'}->{'PRINT_TYPE'} eq 'all_problems') {
                   1575: 	    $selectionmade = 4;
1.354     foxr     1576: 	} elsif ($helper->{'VARS'}->{'PRINT_TYPE'} eq 'all_resources') {  #BUGBUG
                   1577: 	    $selectionmade = 4;
1.296     sakharuk 1578: 	} elsif ($helper->{'VARS'}->{'PRINT_TYPE'} eq 'select_sequences') {
                   1579: 	    $selectionmade = 7;
                   1580: 	}
1.193     sakharuk 1581: 	$form{'problem_split'}=$parmhash{'problem_stream_switch'};
1.310     sakharuk 1582: 	$form{'suppress_tries'}=$parmhash{'suppress_tries'};
1.203     sakharuk 1583: 	$form{'latex_type'}=$helper->{'VARS'}->{'LATEX_TYPE'};
1.309     sakharuk 1584: 	$form{'print_discussions'}=$helper->{'VARS'}->{'PRINT_DISCUSSIONS'};
1.511     foxr     1585: 	$form{'print_annotations'} = $helper->{'VARS'}->{'PRINT_ANNOTATIONS'};
                   1586: 	if (($helper->{'VARS'}->{'PRINT_DISCUSSIONS'} eq 'yes')   ||
                   1587: 	    ($helper->{'VARS'}->{'PRINT_ANNOTATIONS'} eq 'yes') ) {
                   1588: 	    $form{'problem_split'}='yes';
                   1589: 	}
1.141     sakharuk 1590: 	my $flag_latex_header_remove = 'NO';
                   1591: 	my $flag_page_in_sequence = 'NO';
                   1592: 	my @master_seq=split /\|\|\|/, $helper->{'VARS'}->{'RESOURCES'};
1.193     sakharuk 1593: 	my $prevassignment='';
1.428     albertel 1594: 
                   1595: 	&Apache::lonxml::clear_problem_counter();
                   1596: 
1.416     foxr     1597: 	my $pbreakresources = keys %page_breaks;
1.141     sakharuk 1598: 	for (my $i=0;$i<=$#master_seq;$i++) {
1.350     foxr     1599: 
                   1600: 	    # Note due to document structure, not allowed to put \newpage
                   1601: 	    # prior to the first resource
                   1602: 
1.351     foxr     1603: 	    if (defined $page_breaks{$master_seq[$i]}) {
1.350     foxr     1604: 		if($i != 0) {
                   1605: 		    $result.="\\newpage\n";
                   1606: 		}
                   1607: 	    }
1.407     albertel 1608: 	    my ($sequence,undef,$urlp)=&Apache::lonnet::decode_symb($master_seq[$i]);
1.237     albertel 1609: 	    $urlp=&Apache::lonnet::clutter($urlp);
1.166     albertel 1610: 	    $form{'symb'}=$master_seq[$i];
1.407     albertel 1611: 
                   1612: 	    my $assignment=&Apache::lonxml::latex_special_symbols(&Apache::lonnet::gettitle($sequence),'header'); #title of the assignment which contains this problem
1.267     sakharuk 1613: 	    if ($selectionmade==7) {$helper->{VARS}->{'assignment'}=$assignment;}
1.247     sakharuk 1614: 	    if ($i==0) {$prevassignment=$assignment;}
1.297     sakharuk 1615: 	    my $texversion='';
1.413     albertel 1616: 	    if ($urlp!~m|^/adm/|
                   1617: 		&& $urlp=~/\.(problem|exam|quiz|assess|survey|form|library|page|xml|html|htm|xhtml|xhtm)$/) {
1.375     foxr     1618: 		$resources_printed .= $urlp.':';
1.428     albertel 1619: 		&Apache::lonxml::remember_problem_counter();
1.297     sakharuk 1620: 		$texversion.=&Apache::lonnet::ssi($urlp,%form);
1.296     sakharuk 1621: 		if ($urlp=~/\.page$/) {
                   1622: 		    ($texversion,my $number_of_columns_page) = &page_cleanup($texversion);
                   1623: 		    if ($number_of_columns_page > $number_of_columns) {$number_of_columns=$number_of_columns_page;} 
                   1624: 		    $texversion =~ s/\\end{document}\d*/\\end{document}/;
                   1625: 		    $flag_page_in_sequence = 'YES';
                   1626: 		} 
1.428     albertel 1627: 
1.296     sakharuk 1628: 		if(($helper->{'VARS'}->{'ANSWER_TYPE'} eq 'no') ||
                   1629: 		   ($helper->{'VARS'}->{'ANSWER_TYPE'} eq 'only')) {
1.380     foxr     1630: 		    #  Don't permanently pervert the %form hash
                   1631: 		    my %answerform = %form;
                   1632: 		    $answerform{'grade_target'}='answer';
                   1633: 		    $answerform{'answer_output_mode'}='tex';
1.375     foxr     1634: 		    $resources_printed .= $urlp.':';
1.428     albertel 1635: 
                   1636: 		    &Apache::lonxml::restore_problem_counter();
1.380     foxr     1637: 		    my $answer=&Apache::lonnet::ssi($urlp,%answerform);
1.428     albertel 1638: 
1.296     sakharuk 1639: 		    if ($helper->{'VARS'}->{'ANSWER_TYPE'} eq 'no') {
                   1640: 			$texversion=~s/(\\keephidden{ENDOFPROBLEM})/$answer$1/;
1.249     sakharuk 1641: 		    } else {
1.307     sakharuk 1642: 			if ($urlp=~/\.(problem|exam|quiz|assess|survey|form|library)$/) {
1.296     sakharuk 1643: 			    $texversion=&print_latex_header($helper->{'VARS'}->{'LATEX_TYPE'});
1.477     albertel 1644: 			    my $title = &Apache::lonnet::gettitle($master_seq[$i]);
                   1645: 			    $title = &Apache::lonxml::latex_special_symbols($title);
                   1646: 			    my $body ='\vskip 0 mm \noindent\textbf{'.$title.'}\vskip 0 mm ';
1.423     foxr     1647: 			    $body   .= &path_to_problem ($urlp,$LaTeXwidth);
                   1648: 			    $body   .='\vskip 1 mm '.$answer;
                   1649: 			    $body    = &encapsulate_minipage($body);
                   1650: 			    $texversion .= $body;
1.296     sakharuk 1651: 			} else {
                   1652: 			    $texversion='';
                   1653: 			}
1.249     sakharuk 1654: 		    }
1.511     foxr     1655: 
1.246     sakharuk 1656: 		}
1.511     foxr     1657: 		if ($helper->{'VARS'}->{'PRINT_ANNOTATIONS'} eq 'yes') {
                   1658: 		    my $annotation .= &annotate($urlp);
                   1659: 		    $texversion =~ s/(\\keephidden{ENDOFPROBLEM})/$annotation$1/;
                   1660: 		}
                   1661: 
1.296     sakharuk 1662: 		if ($flag_latex_header_remove ne 'NO') {
                   1663: 		    $texversion = &latex_header_footer_remove($texversion);
                   1664: 		} else {
                   1665: 		    $texversion =~ s/\\end{document}//;
                   1666: 		}
                   1667: 		if ($helper->{'VARS'}->{'TABLE_INDEX'} eq 'yes') {
                   1668: 		    $texversion=&IndexCreation($texversion,$urlp);
                   1669: 		}
                   1670: 		if (($selectionmade == 4) and ($assignment ne $prevassignment)) {
                   1671: 		    my $name = &get_name();
                   1672: 		    my $courseidinfo = &get_course();
                   1673: 		    if (defined($courseidinfo)) { $courseidinfo=' - '.$courseidinfo }
                   1674: 		    $prevassignment=$assignment;
1.455     albertel 1675: 		    my $header_text = $parmhash{'print_header_format'};
1.486     foxr     1676: 		    $header_text    = &format_page_header($textwidth, $header_text,
1.455     albertel 1677: 							  $assignment, 
                   1678: 							  $courseidinfo, 
                   1679: 							  $name);
1.417     foxr     1680: 		    if ($numberofcolumns eq '1') {
1.455     albertel 1681: 			$result .='\newpage \noindent\parbox{\minipagewidth}{\noindent\\lhead{'.$header_text.'}} \vskip 5 mm ';
1.416     foxr     1682: 		    } else {
1.455     albertel 1683: 			$result .='\newpage \noindent\parbox{\minipagewidth}{\noindent\\fancyhead[LO]{'.$header_text.'}} \vskip 5 mm ';
1.416     foxr     1684: 		    }			
1.296     sakharuk 1685: 		}
                   1686: 		$result .= $texversion;
                   1687: 		$flag_latex_header_remove = 'YES';   
1.456     raeburn  1688: 	    } elsif ($urlp=~/\/(smppg|syllabus|aboutme|bulletinboard)$/) { 
1.301     sakharuk 1689: 		$form{'latex_type'}=$helper->{'VARS'}->{'LATEX_TYPE'};
                   1690: 		if ($urlp=~/\/syllabus$/) {$urlp=~s/\/res//;}
1.375     foxr     1691: 		$resources_printed .= $urlp.':';
1.301     sakharuk 1692: 		my $texversion=&Apache::lonnet::ssi($urlp,%form);
1.511     foxr     1693: 		if ($helper->{'VARS'}->{'PRINT_ANNOTATIONS'} eq 'yes') {
                   1694: 		    my $annotation = &annotate($urlp);
                   1695: 		    $texversion =~ s/(\\end{document)/$annotation$1/;
                   1696: 		}
                   1697: 
1.301     sakharuk 1698: 		if ($flag_latex_header_remove ne 'NO') {
                   1699: 		    $texversion = &latex_header_footer_remove($texversion);
                   1700: 		} else {
                   1701: 		    $texversion =~ s/\\end{document}/\\vskip 0\.5mm\\noindent\\makebox\[\\textwidth\/\$number_of_columns\]\[b\]\{\\hrulefill\}/;
                   1702: 		}
                   1703: 		$result .= $texversion;
                   1704: 		$flag_latex_header_remove = 'YES'; 
1.141     sakharuk 1705: 	    } else {
1.414     albertel 1706: 		$texversion=&unsupported($urlp,$helper->{'VARS'}->{'LATEX_TYPE'},
                   1707: 					 $master_seq[$i]);
1.297     sakharuk 1708: 		if ($flag_latex_header_remove ne 'NO') {
                   1709: 		    $texversion = &latex_header_footer_remove($texversion);
                   1710: 		} else {
                   1711: 		    $texversion =~ s/\\end{document}//;
                   1712: 		}
                   1713: 		$result .= $texversion;
                   1714: 		$flag_latex_header_remove = 'YES';   
1.296     sakharuk 1715: 	    }	    
1.331     albertel 1716: 	    if (&Apache::loncommon::connection_aborted($r)) { last; }
1.141     sakharuk 1717: 	}
1.428     albertel 1718: 	&Apache::lonxml::clear_problem_counter();
1.344     foxr     1719: 	if ($flag_page_in_sequence eq 'YES') {
                   1720: 	    $result =~ s/\\usepackage{calc}/\\usepackage{calc}\\usepackage{longtable}/;
                   1721: 	}	
1.141     sakharuk 1722: 	$result .= '\end{document}';
1.284     albertel 1723:      } elsif (($helper->{'VARS'}->{'PRINT_TYPE'} eq 'problems_for_students') ||
                   1724: 	      ($helper->{'VARS'}->{'PRINT_TYPE'} eq 'resources_for_students')){
1.353     foxr     1725: 
                   1726: 
1.150     sakharuk 1727:      #-- prints assignments for whole class or for selected students  
1.284     albertel 1728: 	 my $type;
1.254     sakharuk 1729: 	 if ($helper->{'VARS'}->{'PRINT_TYPE'} eq 'problems_for_students') {
                   1730: 	     $selectionmade=5;
1.284     albertel 1731: 	     $type='problems';
1.254     sakharuk 1732: 	 } elsif ($helper->{'VARS'}->{'PRINT_TYPE'} eq 'resources_for_students') {
                   1733: 	     $selectionmade=8;
1.284     albertel 1734: 	     $type='resources';
1.254     sakharuk 1735: 	 }
1.150     sakharuk 1736: 	 my @students=split /\|\|\|/, $helper->{'VARS'}->{'STUDENTS'};
1.341     foxr     1737: 	 #   The normal sort order is by section then by students within the
                   1738: 	 #   section. If the helper var student_sort is 1, then the user has elected
                   1739: 	 #   to override this and output the students by name.
                   1740: 	 #    Each element of the students array is of the form:
                   1741: 	 #       username:domain:section:last, first:status
                   1742: 	 #    
1.429     foxr     1743: 	 #  Note that student sort is not compatible with printing 
                   1744: 	 #  1 section per pdf...so that setting overrides.
1.341     foxr     1745: 	 #   
1.429     foxr     1746: 	 if (($helper->{'VARS'}->{'student_sort'}    eq 1)  && 
                   1747: 	     ($helper->{'VARS'}->{'SPLIT_PDFS'} ne "sections")) {
1.341     foxr     1748: 	     @students = sort compare_names  @students;
                   1749: 	 }
1.429     foxr     1750: 	 &adjust_number_to_print($helper);
                   1751: 
1.278     albertel 1752:          if ($helper->{'VARS'}->{'NUMBER_TO_PRINT'} eq '0' ||
                   1753: 	     $helper->{'VARS'}->{'NUMBER_TO_PRINT'} eq 'all' ) {
                   1754: 	     $helper->{'VARS'}->{'NUMBER_TO_PRINT'}=$#students+1;
                   1755: 	 }
1.429     foxr     1756: 	 # If we are splitting on section boundaries, we need 
                   1757: 	 # to remember that in split_on_sections and 
                   1758: 	 # print all of the students in the list.
                   1759: 	 #
                   1760: 	 my $split_on_sections = 0;
                   1761: 	 if ($helper->{'VARS'}->{'NUMBER_TO_PRINT'} eq 'section') {
                   1762: 	     $split_on_sections = 1;
                   1763: 	     $helper->{'VARS'}->{'NUMBER_TO_PRINT'} = $#students+1;
                   1764: 	 }
1.150     sakharuk 1765: 	 my @master_seq=split /\|\|\|/, $helper->{'VARS'}->{'RESOURCES'};
1.350     foxr     1766: 
1.150     sakharuk 1767: 	 #loop over students
                   1768: 	 my $flag_latex_header_remove = 'NO'; 
                   1769: 	 my %moreenv;
1.330     sakharuk 1770:          $moreenv{'instructor_comments'}='hide';
1.285     albertel 1771: 	 $moreenv{'textwidth'}=&get_textwidth($helper,$LaTeXwidth);
1.309     sakharuk 1772: 	 $moreenv{'print_discussions'}=$helper->{'VARS'}->{'PRINT_DISCUSSIONS'};
1.511     foxr     1773: 	 $moreenv{'print_annotations'} = $helper->{'VARS'}->{'PRINT_ANNOTATIONS'};
1.353     foxr     1774: 	 $moreenv{'problem_split'}    = $parmhash{'problem_stream_switch'};
1.369     foxr     1775: 	 $moreenv{'suppress_tries'}   = $parmhash{'suppress_tries'};
1.511     foxr     1776: 	 if (($helper->{'VARS'}->{'PRINT_DISCUSSIONS'} eq 'yes')  ||
                   1777: 	     ($helper->{'VARS'}->{'PRINT_ANNOTATIONS'} eq 'yes')) {
                   1778: 	     $moreenv{'problem_split'}='yes';
                   1779: 	 }
1.318     albertel 1780: 	 my %prog_state=&Apache::lonhtmlcommon::Create_PrgWin($r,'Print Status','Class Print Status',$#students+1,'inline','75');
1.272     sakharuk 1781: 	 my $student_counter=-1;
1.429     foxr     1782: 	 my $i = 0;
1.430     albertel 1783: 	 my $last_section = (split(/:/,$students[0]))[2];
1.150     sakharuk 1784: 	 foreach my $person (@students) {
1.350     foxr     1785: 
1.373     albertel 1786:              my $duefile="/home/httpd/prtspool/$env{'user.name'}_$env{'user.domain'}_printout.due";
1.311     sakharuk 1787: 	     if (-e $duefile) {
                   1788: 		 my $temp_file = Apache::File->new('>>'.$duefile);
                   1789: 		 print $temp_file "1969\n";
                   1790: 	     }
1.272     sakharuk 1791: 	     $student_counter++;
1.429     foxr     1792: 	     if ($split_on_sections) {
1.430     albertel 1793: 		 my $this_section = (split(/:/,$person))[2];
1.429     foxr     1794: 		 if ($this_section ne $last_section) {
                   1795: 		     $i++;
                   1796: 		     $last_section = $this_section;
                   1797: 		 }
                   1798: 	     } else {
                   1799: 		 $i=int($student_counter/$helper->{'VARS'}{'NUMBER_TO_PRINT'});
                   1800: 	     }
1.375     foxr     1801: 	     my ($output,$fullname, $printed)=&print_resources($r,$helper,
1.353     foxr     1802: 						     $person,$type,
                   1803: 						     \%moreenv,\@master_seq,
1.360     albertel 1804: 						     $flag_latex_header_remove,
1.422     albertel 1805: 						     $LaTeXwidth);
1.375     foxr     1806: 	     $resources_printed .= ":";
1.284     albertel 1807: 	     $print_array[$i].=$output;
                   1808: 	     $student_names[$i].=$person.':'.$fullname.'_END_';
                   1809: 	     &Apache::lonhtmlcommon::Increment_PrgWin($r,\%prog_state,&mt('last student').' '.$fullname);
                   1810: 	     $flag_latex_header_remove = 'YES';
1.331     albertel 1811: 	     if (&Apache::loncommon::connection_aborted($r)) { last; }
1.284     albertel 1812: 	 }
                   1813: 	 &Apache::lonhtmlcommon::Close_PrgWin($r,\%prog_state);
                   1814: 	 $result .= $print_array[0].'  \end{document}';
                   1815:      } elsif (($helper->{'VARS'}->{'PRINT_TYPE'} eq 'problems_for_anon')     ||
                   1816: 	      ($helper->{'VARS'}->{'PRINT_TYPE'} eq 'resources_for_anon')  ) { 
1.373     albertel 1817: 	 my $cdom =$env{'course.'.$env{'request.course.id'}.'.domain'};
                   1818: 	 my $cnum =$env{'course.'.$env{'request.course.id'}.'.num'};
1.288     albertel 1819: 	 my $num_todo=$helper->{'VARS'}->{'NUMBER_TO_PRINT_TOTAL'};
                   1820: 	 my $code_name=$helper->{'VARS'}->{'ANON_CODE_STORAGE_NAME'};
1.292     albertel 1821: 	 my $old_name=$helper->{'VARS'}->{'REUSE_OLD_CODES'};
1.385     foxr     1822: 	 my $single_code = $helper->{'VARS'}->{'SINGLE_CODE'};
1.388     foxr     1823: 	 my $selected_code = $helper->{'VARS'}->{'CODE_SELECTED_FROM_LIST'};
                   1824: 
1.381     albertel 1825: 	 my $code_option=$helper->{'VARS'}->{'CODE_OPTION'};
                   1826: 	 open(FH,$Apache::lonnet::perlvar{'lonTabDir'}.'/scantronformat.tab');
                   1827: 	 my ($code_type,$code_length)=('letter',6);
                   1828: 	 foreach my $line (<FH>) {
                   1829: 	     my ($name,$type,$length) = (split(/:/,$line))[0,2,4];
                   1830: 	     if ($name eq $code_option) {
                   1831: 		 $code_length=$length;
                   1832: 		 if ($type eq 'number') { $code_type = 'number'; }
                   1833: 	     }
                   1834: 	 }
1.288     albertel 1835: 	 my %moreenv = ('textwidth' => &get_textwidth($helper,$LaTeXwidth));
1.353     foxr     1836: 	 $moreenv{'problem_split'}    = $parmhash{'problem_stream_switch'};
1.420     albertel 1837:          $moreenv{'instructor_comments'}='hide';
1.288     albertel 1838: 	 my $seed=time+($$<<16)+($$);
1.292     albertel 1839: 	 my @allcodes;
                   1840: 	 if ($old_name) {
1.381     albertel 1841: 	     my %result=&Apache::lonnet::get('CODEs',
                   1842: 					     [$old_name,"type\0$old_name"],
                   1843: 					     $cdom,$cnum);
                   1844: 	     $code_type=$result{"type\0$old_name"};
1.292     albertel 1845: 	     @allcodes=split(',',$result{$old_name});
1.336     albertel 1846: 	     $num_todo=scalar(@allcodes);
1.389     foxr     1847: 	 } elsif ($selected_code) { # Selection value is always numeric.
1.388     foxr     1848: 	     $num_todo = 1;
                   1849: 	     @allcodes = ($selected_code);
1.385     foxr     1850: 	 } elsif ($single_code) {
                   1851: 
1.387     foxr     1852: 	     $num_todo    = 1;	# Unconditionally one code to do.
1.385     foxr     1853: 	     # If an alpha code have to convert to numbers so it can be
                   1854: 	     # converted back to letters again :-)
                   1855: 	     #
                   1856: 	     if ($code_type ne 'number') {
                   1857: 		 $single_code = &letters_to_num($single_code);
                   1858: 	     }
                   1859: 	     @allcodes = ($single_code);
1.292     albertel 1860: 	 } else {
                   1861: 	     my %allcodes;
1.299     albertel 1862: 	     srand($seed);
1.292     albertel 1863: 	     for (my $i=0;$i<$num_todo;$i++) {
1.381     albertel 1864: 		 $moreenv{'CODE'}=&get_CODE(\%allcodes,$i,$seed,$code_length,
                   1865: 					    $code_type);
1.292     albertel 1866: 	     }
                   1867: 	     if ($code_name) {
                   1868: 		 &Apache::lonnet::put('CODEs',
1.381     albertel 1869: 				      {
                   1870: 					$code_name =>join(',',keys(%allcodes)),
                   1871: 					"type\0$code_name" => $code_type
                   1872: 				      },
1.292     albertel 1873: 				      $cdom,$cnum);
                   1874: 	     }
                   1875: 	     @allcodes=keys(%allcodes);
                   1876: 	 }
1.336     albertel 1877: 	 my @master_seq=split /\|\|\|/, $helper->{'VARS'}->{'RESOURCES'};
                   1878: 	 my ($type) = split(/_/,$helper->{'VARS'}->{'PRINT_TYPE'});
1.452     albertel 1879: 	 &adjust_number_to_print($helper);
1.336     albertel 1880: 	 my $number_per_page=$helper->{'VARS'}->{'NUMBER_TO_PRINT'};
                   1881: 	 if ($number_per_page eq '0' || $number_per_page eq 'all') {
                   1882: 	     $number_per_page=$num_todo;
                   1883: 	 }
                   1884: 	 my $flag_latex_header_remove = 'NO'; 
                   1885: 	 my %prog_state=&Apache::lonhtmlcommon::Create_PrgWin($r,'Print Status','Class Print Status',$num_todo,'inline','75');
1.295     albertel 1886: 	 my $count=0;
1.292     albertel 1887: 	 foreach my $code (sort(@allcodes)) {
1.295     albertel 1888: 	     my $file_num=int($count/$number_per_page);
1.381     albertel 1889: 	     if ($code_type eq 'number') { 
                   1890: 		 $moreenv{'CODE'}=$code;
                   1891: 	     } else {
                   1892: 		 $moreenv{'CODE'}=&num_to_letters($code);
                   1893: 	     }
1.375     foxr     1894: 	     my ($output,$fullname, $printed)=
1.288     albertel 1895: 		 &print_resources($r,$helper,'anonymous',$type,\%moreenv,
1.360     albertel 1896: 				  \@master_seq,$flag_latex_header_remove,
                   1897: 				  $LaTeXwidth);
1.375     foxr     1898: 	     $resources_printed .= ":";
1.295     albertel 1899: 	     $print_array[$file_num].=$output;
1.288     albertel 1900: 	     &Apache::lonhtmlcommon::Increment_PrgWin($r,\%prog_state,
                   1901: 				       &mt('last assignment').' '.$fullname);
                   1902: 	     $flag_latex_header_remove = 'YES';
1.295     albertel 1903: 	     $count++;
1.331     albertel 1904: 	     if (&Apache::loncommon::connection_aborted($r)) { last; }
1.288     albertel 1905: 	 }
                   1906: 	 &Apache::lonhtmlcommon::Close_PrgWin($r,\%prog_state);
                   1907: 	 $result .= $print_array[0].'  \end{document}';
                   1908:      } elsif ($helper->{'VARS'}->{'PRINT_TYPE'} eq 'problems_from_directory') {      
1.151     sakharuk 1909:     #prints selected problems from the subdirectory 
                   1910: 	$selectionmade = 6;
                   1911:         my @list_of_files=split /\|\|\|/, $helper->{'VARS'}->{'FILES'};
1.154     sakharuk 1912: 	@list_of_files=sort @list_of_files;
1.175     sakharuk 1913: 	my $flag_latex_header_remove = 'NO'; 
                   1914: 	my $rndseed=time;
1.230     albertel 1915: 	if ($helper->{'VARS'}->{'curseed'}) {
                   1916: 	    $rndseed=$helper->{'VARS'}->{'curseed'};
                   1917: 	}
1.151     sakharuk 1918: 	for (my $i=0;$i<=$#list_of_files;$i++) {
1.152     sakharuk 1919: 	    my $urlp = $list_of_files[$i];
1.253     sakharuk 1920: 	    $urlp=~s|//|/|;
1.152     sakharuk 1921: 	    if ($urlp=~/\//) {
1.353     foxr     1922: 		$form{'problem_split'}=$parmhash{'problem_stream_switch'};
1.175     sakharuk 1923: 		$form{'rndseed'}=$rndseed;
1.152     sakharuk 1924: 		if ($urlp =~ m|/home/([^/]+)/public_html|) {
                   1925: 		    $urlp =~ s|/home/([^/]*)/public_html|/~$1|;
                   1926: 		} else {
1.302     sakharuk 1927: 		    $urlp =~ s|^$Apache::lonnet::perlvar{'lonDocRoot'}||;
1.152     sakharuk 1928: 		}
1.375     foxr     1929: 		$resources_printed .= $urlp.':';
1.166     albertel 1930: 		my $texversion=&Apache::lonnet::ssi($urlp,%form);
1.251     sakharuk 1931: 		if(($helper->{'VARS'}->{'ANSWER_TYPE'} eq 'no') ||
1.253     sakharuk 1932: 		   ($helper->{'VARS'}->{'ANSWER_TYPE'} eq 'only')) {
1.380     foxr     1933: 		    #  Don't permanently pervert %form:
                   1934: 		    my %answerform = %form;
                   1935: 		    $answerform{'grade_target'}='answer';
                   1936: 		    $answerform{'answer_output_mode'}='tex';
                   1937: 		    $answerform{'latex_type'}=$helper->{'VARS'}->{'LATEX_TYPE'};
                   1938: 		    $answerform{'rndseed'}=$rndseed;
1.375     foxr     1939: 		    $resources_printed .= $urlp.':';
1.380     foxr     1940: 		    my $answer=&Apache::lonnet::ssi($urlp,%answerform);
1.251     sakharuk 1941: 		    if ($helper->{'VARS'}->{'ANSWER_TYPE'} eq 'no') {
                   1942: 			$texversion=~s/(\\keephidden{ENDOFPROBLEM})/$answer$1/;
                   1943: 		    } else {
1.253     sakharuk 1944: 			$texversion=&print_latex_header($helper->{'VARS'}->{'LATEX_TYPE'});
                   1945: 			if ($helper->{'VARS'}->{'construction'} ne '1') {
                   1946: 			    $texversion.='\vskip 0 mm \noindent ';
                   1947: 			    $texversion.=&path_to_problem ($urlp,$LaTeXwidth);
                   1948: 			} else {
                   1949: 			    $texversion.='\vskip 0 mm \noindent\textbf{Prints from construction space - there is no title.}\vskip 0 mm ';
                   1950: 			    my $URLpath=$urlp;
                   1951: 			    $URLpath=~s/~([^\/]+)/public_html\/$1\/$1/;
                   1952: 			    $texversion.=&path_to_problem ($URLpath,$LaTeXwidth);
                   1953: 			}
                   1954: 			$texversion.='\vskip 1 mm '.$answer.'\end{document}';
1.251     sakharuk 1955: 		    }
1.174     sakharuk 1956: 		}
1.151     sakharuk 1957:                 #this chunck is responsible for printing the path to problem
1.253     sakharuk 1958: 		my $newurlp=$urlp;
                   1959: 		if ($newurlp=~/~/) {$newurlp=~s|\/~([^\/]+)\/|\/home\/$1\/public_html\/|;}
                   1960: 		$newurlp=&path_to_problem($newurlp,$LaTeXwidth);
1.242     sakharuk 1961: 		$texversion =~ s/(\\begin{minipage}{\\textwidth})/$1 $newurlp/;
1.152     sakharuk 1962: 		if ($flag_latex_header_remove ne 'NO') {
                   1963: 		    $texversion = &latex_header_footer_remove($texversion);
                   1964: 		} else {
                   1965: 		    $texversion =~ s/\\end{document}//;
1.216     sakharuk 1966: 		}
                   1967: 		if ($helper->{'VARS'}->{'TABLE_INDEX'} eq 'yes') {
                   1968: 		    $texversion=&IndexCreation($texversion,$urlp);
1.152     sakharuk 1969: 		}
1.219     sakharuk 1970: 		if ($helper->{'VARS'}->{'CONSTR_RESOURSE_URL'} eq 'yes') {
                   1971: 		    $texversion=~s/(\\addcontentsline\{toc\}\{subsection\}\{[^\}]*\})/$1 URL: \\verb|$urlp| \\strut\\\\\\strut /;
                   1972: 		    
                   1973: 		}
1.152     sakharuk 1974: 		$result .= $texversion;
                   1975: 	    }
                   1976: 	    $flag_latex_header_remove = 'YES';  
1.151     sakharuk 1977: 	}
1.175     sakharuk 1978: 	if ($helper->{VARS}->{'construction'} eq '1') {$result=~s/(\\typeout)/ RANDOM SEED IS $rndseed $1/;}
1.152     sakharuk 1979: 	$result .= '\end{document}';      	
1.140     sakharuk 1980:     }
                   1981: #-------------------------------------------------------- corrections for the different page formats
1.499     foxr     1982: 
                   1983:     # Only post process if that has not been turned off e.g. by a raw latex resource.
                   1984: 
                   1985:     if ($do_postprocessing) {
                   1986: 	$result = &page_format_transformation($papersize,$laystyle,$numberofcolumns,$helper->{'VARS'}->{'PRINT_TYPE'},$result,$helper->{VARS}->{'assignment'},$helper->{'VARS'}->{'TABLE_CONTENTS'},$helper->{'VARS'}->{'TABLE_INDEX'},$selectionmade);
                   1987: 	$result = &latex_corrections($number_of_columns,$result,$selectionmade,
                   1988: 				     $helper->{'VARS'}->{'ANSWER_TYPE'});
                   1989: 	#if ($numberofcolumns == 1) {
1.451     albertel 1990: 	$result =~ s/\\textwidth\s*=\s*-?\d*\.?\d*\s*(cm|mm|in)/\\textwidth= $helper->{'VARS'}->{'pagesize.width'} $helper->{'VARS'}->{'pagesize.widthunit'} /;
                   1991: 	$result =~ s/\\textheight\s*=?\s*-?\d*\.?\d*\s*(cm|mm|in)/\\textheight $helper->{'VARS'}->{'pagesize.height'} $helper->{'VARS'}->{'pagesize.heightunit'} /;
                   1992: 	$result =~ s/\\evensidemargin\s*=\s*-?\d*\.?\d*\s*(cm|mm|in)/\\evensidemargin= $helper->{'VARS'}->{'pagesize.lmargin'} $helper->{'VARS'}->{'pagesize.lmarginunit'} /;
                   1993: 	$result =~ s/\\oddsidemargin\s*=\s*-?\d*\.?\d*\s*(cm|mm|in)/\\oddsidemargin= $helper->{'VARS'}->{'pagesize.lmargin'} $helper->{'VARS'}->{'pagesize.lmarginunit'} /;
1.499     foxr     1994: 	#}
                   1995:     }
1.367     foxr     1996: 
1.140     sakharuk 1997: #-- writing .tex file in prtspool 
                   1998:     my $temp_file;
1.277     albertel 1999:     my $identifier = &Apache::loncommon::get_cgi_id();
1.379     foxr     2000:     my $filename = "/home/httpd/prtspool/$env{'user.name'}_$env{'user.domain'}_printout_$identifier.tex";
1.277     albertel 2001:     if (!($#print_array>0)) { 
                   2002: 	unless ($temp_file = Apache::File->new('>'.$filename)) {
                   2003: 	    $r->log_error("Couldn't open $filename for output $!");
                   2004: 	    return SERVER_ERROR; 
                   2005: 	}
                   2006: 	print $temp_file $result;
                   2007: 	my $begin=index($result,'\begin{document}',0);
                   2008: 	my $inc=substr($result,0,$begin+16);
                   2009:     } else {
                   2010: 	my $begin=index($result,'\begin{document}',0);
                   2011: 	my $inc=substr($result,0,$begin+16);
                   2012:         for (my $i=0;$i<=$#print_array;$i++) {
                   2013: 	    if ($i==0) {
                   2014: 		$print_array[$i]=$result;
                   2015: 	    } else {
1.475     albertel 2016: 		$print_array[$i].='\end{document}';
                   2017: 		$print_array[$i] = 
                   2018: 		    &latex_corrections($number_of_columns,$print_array[$i],
                   2019: 				       $selectionmade, 
                   2020: 				       $helper->{'VARS'}->{'ANSWER_TYPE'});
                   2021: 
1.277     albertel 2022: 		my $anobegin=index($print_array[$i],'\setcounter{page}',0);
                   2023: 		substr($print_array[$i],0,$anobegin)='';
1.475     albertel 2024: 		$print_array[$i]=$inc.$print_array[$i];
1.277     albertel 2025: 	    }
1.272     sakharuk 2026: 	    my $temp_file;
1.273     sakharuk 2027: 	    my $newfilename=$filename;
1.277     albertel 2028: 	    my $num=$i+1;
1.379     foxr     2029: 	    $newfilename =~s/\.tex$//; 
                   2030: 	    $newfilename=sprintf("%s_%03d.tex",$newfilename, $num);
1.272     sakharuk 2031: 	    unless ($temp_file = Apache::File->new('>'.$newfilename)) {
                   2032: 		$r->log_error("Couldn't open $newfilename for output $!");
                   2033: 		return SERVER_ERROR; 
                   2034: 	    }
                   2035: 	    print $temp_file $print_array[$i];
                   2036: 	}
                   2037:     }
1.274     sakharuk 2038:     my $student_names='';
                   2039:     if ($#print_array>0) {
                   2040: 	for (my $i=0;$i<=$#print_array;$i++) {
                   2041: 	    $student_names.=$student_names[$i].'_ENDPERSON_';
                   2042: 	}
1.277     albertel 2043:     } else {
1.278     albertel 2044: 	if ($#student_names>-1) {
                   2045: 	    $student_names=$student_names[0].'_ENDPERSON_';
                   2046: 	} else {
1.373     albertel 2047: 	    my $fullname = &get_name($env{'user.name'},$env{'user.domain'});
                   2048: 	    $student_names=join(':',$env{'user.name'},$env{'user.domain'},
                   2049: 				$env{'request.course.sec'},$fullname).
1.278     albertel 2050: 				    '_ENDPERSON_'.'_END_';
                   2051: 	}
1.274     sakharuk 2052:     }
                   2053: 
1.276     sakharuk 2054:     my $URLback=''; #link to original document
1.510     albertel 2055:     if ($helper->{'VARS'}->{'construction'} eq '1') {
1.276     sakharuk 2056: 	#prints resource from the construction space
                   2057: 	$URLback='/'.$helper->{'VARS'}->{'filename'};
1.279     albertel 2058: 	if ($URLback=~/([^?]+)/) {
                   2059: 	    $URLback=$1;
                   2060: 	    $URLback=~s|^/~|/priv/|;
                   2061: 	}
1.276     sakharuk 2062:     }
1.375     foxr     2063:     # logic for now is too complex to trace if this has been defined
                   2064:     #  yet.
                   2065:     my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
                   2066:     my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
1.257     sakharuk 2067:     &Apache::lonnet::appenv('cgi.'.$identifier.'.file'   => $filename,
                   2068:                             'cgi.'.$identifier.'.layout'  => $laystyle,
                   2069:                             'cgi.'.$identifier.'.numcol'  => $numberofcolumns,
1.303     sakharuk 2070: 			    'cgi.'.$identifier.'.paper'  => $papersize,
1.257     sakharuk 2071:                             'cgi.'.$identifier.'.selection' => $selectionmade,
1.375     foxr     2072: 			    'cgi.'.$identifier.'.tableofcontents' => $helper->{'VARS'}->{'TABLE_CONTENTS'},
                   2073: 			    'cgi.'.$identifier.'.tableofindex' => $helper->{'VARS'}->{'TABLE_INDEX'},
1.397     albertel 2074: 			    'cgi.'.$identifier.'.role' => $perm{'pav'},
1.375     foxr     2075:                             'cgi.'.$identifier.'.numberoffiles' => $#print_array,
                   2076:                             'cgi.'.$identifier.'.studentnames' => $student_names,
                   2077:                             'cgi.'.$identifier.'.backref' => $URLback,);
                   2078:     &Apache::lonnet::appenv("cgi.$identifier.user"    => $env{'user.name'},
                   2079: 			    "cgi.$identifier.domain"  => $env{'user.domain'},
                   2080: 			    "cgi.$identifier.courseid" => $cnum, 
                   2081: 			    "cgi.$identifier.coursedom" => $cdom, 
                   2082: 			    "cgi.$identifier.resources" => $resources_printed);
                   2083: 
1.431     albertel 2084:     my $end_page = &Apache::loncommon::end_page();
                   2085:     $r->print(<<FINALEND);
1.317     albertel 2086: <br />
1.288     albertel 2087: <meta http-equiv="Refresh" content="0; url=/cgi-bin/printout.pl?$identifier" />
1.317     albertel 2088: <a href="/cgi-bin/printout.pl?$identifier">Continue</a>
1.431     albertel 2089: $end_page
1.140     sakharuk 2090: FINALEND
                   2091: }
                   2092: 
1.288     albertel 2093: 
                   2094: sub get_CODE {
1.381     albertel 2095:     my ($all_codes,$num,$seed,$size,$type)=@_;
1.288     albertel 2096:     my $max='1'.'0'x$size;
                   2097:     my $newcode;
                   2098:     while(1) {
1.392     albertel 2099: 	$newcode=sprintf("%0".$size."d",int(rand($max)));
1.288     albertel 2100: 	if (!exists($$all_codes{$newcode})) {
                   2101: 	    $$all_codes{$newcode}=1;
1.381     albertel 2102: 	    if ($type eq 'number' ) {
                   2103: 		return $newcode;
                   2104: 	    } else {
                   2105: 		return &num_to_letters($newcode);
                   2106: 	    }
1.288     albertel 2107: 	}
                   2108:     }
                   2109: }
1.140     sakharuk 2110: 
1.284     albertel 2111: sub print_resources {
1.360     albertel 2112:     my ($r,$helper,$person,$type,$moreenv,$master_seq,$remove_latex_header,
1.422     albertel 2113: 	$LaTeXwidth)=@_;
1.284     albertel 2114:     my $current_output = ''; 
1.375     foxr     2115:     my $printed = '';
1.284     albertel 2116:     my ($username,$userdomain,$usersection) = split /:/,$person;
                   2117:     my $fullname = &get_name($username,$userdomain);
1.492     foxr     2118:     my $namepostfix = "\\\\";	# Both anon and not anon should get the same vspace.
1.288     albertel 2119:     if ($person =~ 'anon') {
1.492     foxr     2120: 	$namepostfix .="Name: ";
1.288     albertel 2121: 	$fullname = "CODE - ".$moreenv->{'CODE'};
                   2122:     }
1.444     foxr     2123:     #  Fullname may have special latex characters that need \ prefixing:
                   2124:     #
                   2125: 
1.350     foxr     2126:     my $i           = 0;
1.284     albertel 2127:     #goes through all resources, checks if they are available for 
                   2128:     #current student, and produces output   
1.428     albertel 2129: 
                   2130:     &Apache::lonxml::clear_problem_counter();
1.364     albertel 2131:     my %page_breaks  = &get_page_breaks($helper);
1.476     albertel 2132:     my $columns_in_format = (split(/\|/,$helper->{'VARS'}->{'FORMAT'}))[1];
1.440     foxr     2133:     #
1.441     foxr     2134:     #   end each student with a 
1.440     foxr     2135:     #   Special that allows the post processor to even out the page
                   2136:     #   counts later.  Nasty problem this... it would be really
                   2137:     #   nice to put the special in as a postscript comment
1.441     foxr     2138:     #   e.g. \special{ps:\ENDOFSTUDENTSTAMP}  unfortunately,
1.440     foxr     2139:     #   The special gets passed the \ and dvips puts it in the output file
1.441     foxr     2140:     #   so we will just rely on prntout.pl to strip  ENDOFSTUDENTSTAMP from the
                   2141:     #   postscript.  Each ENDOFSTUDENTSTAMP will go on a line by itself.
1.440     foxr     2142:     #
1.363     foxr     2143: 
1.511     foxr     2144: 
1.284     albertel 2145:     foreach my $curresline (@{$master_seq})  {
1.351     foxr     2146: 	if (defined $page_breaks{$curresline}) {
1.350     foxr     2147: 	    if($i != 0) {
                   2148: 		$current_output.= "\\newpage\n";
                   2149: 	    }
                   2150: 	}
                   2151: 	$i++;
1.511     foxr     2152: 
1.284     albertel 2153: 	if ( !($type eq 'problems' && 
                   2154: 	       ($curresline!~ m/\.(problem|exam|quiz|assess|survey|form|library)$/)) ) {
                   2155: 	    my ($map,$id,$res_url) = &Apache::lonnet::decode_symb($curresline);
                   2156: 	    if (&Apache::lonnet::allowed('bre',$res_url)) {
1.414     albertel 2157: 		if ($res_url!~m|^ext/|
1.413     albertel 2158: 		    && $res_url=~/\.(problem|exam|quiz|assess|survey|form|library|page|xml|html|htm|xhtml|xhtm)$/) {
1.375     foxr     2159: 		    $printed .= $curresline.':';
1.428     albertel 2160: 
                   2161: 		    &Apache::lonxml::remember_problem_counter();    
                   2162: 
1.373     albertel 2163: 		    my $rendered = &Apache::loncommon::get_student_view($curresline,$username,$userdomain,$env{'request.course.id'},'tex',$moreenv);
1.428     albertel 2164: 
1.305     sakharuk 2165: 		    if(($helper->{'VARS'}->{'ANSWER_TYPE'} eq 'no') ||
                   2166: 		       ($helper->{'VARS'}->{'ANSWER_TYPE'} eq 'only')) {
1.380     foxr     2167: 			#   Use a copy of the hash so we don't pervert it on future loop passes.
                   2168: 			my %answerenv = %{$moreenv};
                   2169: 			$answerenv{'answer_output_mode'}='tex';
                   2170: 			$answerenv{'latex_type'}=$helper->{'VARS'}->{'LATEX_TYPE'};
1.428     albertel 2171: 			
                   2172: 			&Apache::lonxml::restore_problem_counter();
                   2173: 
1.380     foxr     2174: 			my $ansrendered = &Apache::loncommon::get_student_answers($curresline,$username,$userdomain,$env{'request.course.id'},%answerenv);
1.428     albertel 2175: 
1.305     sakharuk 2176: 			if ($helper->{'VARS'}->{'ANSWER_TYPE'} eq 'no') {
                   2177: 			    $rendered=~s/(\\keephidden{ENDOFPROBLEM})/$ansrendered$1/;
                   2178: 			} else {
1.423     foxr     2179: 
                   2180: 			    
                   2181: 			    my $header =&print_latex_header($helper->{'VARS'}->{'LATEX_TYPE'});
1.477     albertel 2182: 			    my $title = &Apache::lonnet::gettitle($curresline);
                   2183: 			    $title = &Apache::lonxml::latex_special_symbols($title);
                   2184: 			    my $body   ='\vskip 0 mm \noindent\textbf{'.$title.'}\vskip 0 mm ';
                   2185: 			    $body     .=&path_to_problem($res_url,$LaTeXwidth);
1.423     foxr     2186: 			    $body     .='\vskip 1 mm '.$ansrendered;
                   2187: 			    $body     = &encapsulate_minipage($body);
                   2188: 			    $rendered = $header.$body;
1.305     sakharuk 2189: 			}
                   2190: 		    }
1.511     foxr     2191: 
                   2192: 		    if ($helper->{'VARS'}->{'PRINT_ANNOTATIONS'} eq 'yes') {
                   2193: 			my $url = &Apache::lonnet::clutter($res_url);
                   2194: 			my $annotation = &annotate($url);
                   2195: 			$rendered =~  s/(\\keephidden{ENDOFPROBLEM})/$annotation$1/;
                   2196: 		    }
1.305     sakharuk 2197: 		    if ($remove_latex_header eq 'YES') {
                   2198: 			$rendered = &latex_header_footer_remove($rendered);
                   2199: 		    } else {
                   2200: 			$rendered =~ s/\\end{document}//;
                   2201: 		    }
                   2202: 		    $current_output .= $rendered;		    
1.456     raeburn  2203: 		} elsif ($res_url=~/\/(smppg|syllabus|aboutme|bulletinboard)$/) {
1.375     foxr     2204: 		    $printed .= $curresline.':';
1.373     albertel 2205: 		    my $rendered = &Apache::loncommon::get_student_view($curresline,$username,$userdomain,$env{'request.course.id'},'tex',$moreenv);
1.511     foxr     2206: 		    if ($helper->{'VARS'}->{'PRINT_ANNOTATIONS'} eq 'yes') {
                   2207: 			my $url = &Apache::lonnet::clutter($res_url);
                   2208: 			my $annotation = &annotate($url);
                   2209: 			$annotation    =~ s/(\\end{document})/$annotation$1/;
                   2210: 		    }
1.305     sakharuk 2211: 		    if ($remove_latex_header eq 'YES') {
                   2212: 			$rendered = &latex_header_footer_remove($rendered);
1.284     albertel 2213: 		    } else {
1.305     sakharuk 2214: 			$rendered =~ s/\\end{document}//;
1.284     albertel 2215: 		    }
1.421     foxr     2216: 		    $current_output .= $rendered.'\vskip 0.5mm\noindent\makebox[\textwidth/$number_of_columns][b]{\hrulefill}\strut \vskip 0 mm \strut ';
                   2217: 
1.284     albertel 2218: 		} else {
1.414     albertel 2219: 		    my $rendered = &unsupported($res_url,$helper->{'VARS'}->{'LATEX_TYPE'},$curresline);
1.305     sakharuk 2220: 		    if ($remove_latex_header ne 'NO') {
                   2221: 			$rendered = &latex_header_footer_remove($rendered);
                   2222: 		    } else {
                   2223: 			$rendered =~ s/\\end{document}//;
                   2224: 		    }
                   2225: 		    $current_output .= $rendered;
1.284     albertel 2226: 		}
                   2227: 	    }
                   2228: 	    $remove_latex_header = 'YES';
                   2229: 	}
1.331     albertel 2230: 	if (&Apache::loncommon::connection_aborted($r)) { last; }
1.284     albertel 2231:     }
                   2232:     my $courseidinfo = &get_course();
                   2233:     if (defined($courseidinfo)) { $courseidinfo=' - '.$courseidinfo }
                   2234:     if ($usersection ne '') {$courseidinfo.=' - Sec. '.$usersection}
                   2235:     my $currentassignment=&Apache::lonxml::latex_special_symbols($helper->{VARS}->{'assignment'},'header');
1.476     albertel 2236:     my $header_line =
1.486     foxr     2237: 	&format_page_header($LaTeXwidth, $parmhash{'print_header_format'},
1.476     albertel 2238: 			    $currentassignment, $courseidinfo, $fullname);
                   2239:     my $header_start = ($columns_in_format == 1) ? '\lhead'
                   2240: 	                                         : '\fancyhead[LO]';
                   2241:     $header_line = $header_start.'{'.$header_line.'}';
                   2242: 
1.284     albertel 2243:     if ($current_output=~/\\documentclass/) {
1.476     albertel 2244: 	$current_output =~ s/\\begin{document}/\\setlength{\\topmargin}{1cm} \\begin{document}\\noindent\\parbox{\\minipagewidth}{\\noindent$header_line$namepostfix}\\vskip 5 mm /;
1.284     albertel 2245:     } else {
1.476     albertel 2246: 	my $blankpages = 
                   2247: 	    '\clearpage\strut\clearpage'x$helper->{'VARS'}->{'EMPTY_PAGES'};
                   2248: 	    
                   2249: 	$current_output = '\strut\vspace*{-6 mm}\\newline'.
                   2250: 	    &copyright_line().' \newpage '.$blankpages.$end_of_student.
                   2251: 	    '\setcounter{page}{1}\noindent\parbox{\minipagewidth}{\noindent'.
                   2252: 	    $header_line.$namepostfix.'} \vskip 5 mm '.$current_output;
1.284     albertel 2253:     }
1.440     foxr     2254:     #
                   2255:     #  Close the student bracketing.
                   2256:     #
1.375     foxr     2257:     return ($current_output,$fullname, $printed);
1.284     albertel 2258: 
                   2259: }
1.140     sakharuk 2260: 
1.3       sakharuk 2261: sub handler {
                   2262: 
                   2263:     my $r = shift;
1.397     albertel 2264:     
                   2265:     &init_perm();
1.114     bowersj2 2266: 
1.416     foxr     2267: 
1.67      www      2268: 
1.397     albertel 2269:     my $helper = printHelper($r);
                   2270:     if (!ref($helper)) {
                   2271: 	return $helper;
1.60      sakharuk 2272:     }
1.177     sakharuk 2273:    
1.184     sakharuk 2274: 
1.454     foxr     2275:     %parmhash=&Apache::lonnet::coursedescription($env{'request.course.id'});
1.353     foxr     2276:  
1.416     foxr     2277: 
1.350     foxr     2278: 
                   2279: 
1.367     foxr     2280:     #  If a figure conversion queue file exists for this user.domain
                   2281:     # we delete it since it can only be bad (if it were good, printout.pl
                   2282:     # would have deleted it the last time around.
                   2283: 
1.373     albertel 2284:     my $conversion_queuefile = "/home/httpd/prtspool/$env{'user.name'}_$env{'user.domain'}_printout.dat";
1.367     foxr     2285:     if(-e $conversion_queuefile) {
                   2286: 	unlink $conversion_queuefile;
                   2287:     }
1.184     sakharuk 2288:     &output_data($r,$helper,\%parmhash);
1.2       sakharuk 2289:     return OK;
1.60      sakharuk 2290: } 
1.2       sakharuk 2291: 
1.131     bowersj2 2292: use Apache::lonhelper;
1.130     sakharuk 2293: 
1.223     bowersj2 2294: sub addMessage {
                   2295:     my $text = shift;
                   2296:     my $paramHash = Apache::lonhelper::getParamHash();
                   2297:     $paramHash->{MESSAGE_TEXT} = $text;
                   2298:     Apache::lonhelper::message->new();
                   2299: }
                   2300: 
1.416     foxr     2301: 
1.238     bowersj2 2302: 
1.397     albertel 2303: sub init_perm {
                   2304:     undef(%perm);
                   2305:     $perm{'pav'}=&Apache::lonnet::allowed('pav',$env{'request.course.id'});
                   2306:     if (!$perm{'pav'}) {
                   2307: 	$perm{'pav'}=&Apache::lonnet::allowed('pav',
                   2308: 		  $env{'request.course.id'}.'/'.$env{'request.course.sec'});
                   2309:     }
1.465     albertel 2310:     $perm{'pfo'}=&Apache::lonnet::allowed('pfo',$env{'request.course.id'});
1.397     albertel 2311:     if (!$perm{'pfo'}) {
                   2312: 	$perm{'pfo'}=&Apache::lonnet::allowed('pfo',
                   2313: 		  $env{'request.course.id'}.'/'.$env{'request.course.sec'});
                   2314:     }
                   2315: }
                   2316: 
1.507     albertel 2317: sub get_randomly_ordered_warning {
                   2318:     my ($helper,$map) = @_;
                   2319: 
                   2320:     my $message;
                   2321: 
                   2322:     my $postdata = $env{'form.postdata'} || $helper->{VARS}{'postdata'};
                   2323:     my $navmap = Apache::lonnavmaps::navmap->new();
                   2324:     my $res = $navmap->getResourceByUrl($map);
                   2325:     if ($res) {
                   2326: 	my $func = 
                   2327: 	    sub { return ($_[0]->is_map() && $_[0]->randomorder); };
                   2328: 	my @matches = $navmap->retrieveResources($res, $func,1,1,1);
                   2329: 	if (@matches) {
1.508     albertel 2330: 	    $message = "Some of the items below are in folders set to be randomly ordered. However, when printing the contents of these folders, they will be printed in the original order for all students, not the randomized order.";
1.507     albertel 2331: 	}
                   2332:     }
                   2333:     if ($message) {
                   2334: 	return '<message type="warning">'.$message.'</message>';
                   2335:     }
                   2336:     return;
                   2337: }
                   2338: 
1.131     bowersj2 2339: sub printHelper {
1.115     bowersj2 2340:     my $r = shift;
                   2341: 
                   2342:     if ($r->header_only) {
1.373     albertel 2343:         if ($env{'browser.mathml'}) {
1.241     www      2344:             &Apache::loncommon::content_type($r,'text/xml');
1.131     bowersj2 2345:         } else {
1.241     www      2346:             &Apache::loncommon::content_type($r,'text/html');
1.131     bowersj2 2347:         }
                   2348:         $r->send_http_header;
                   2349:         return OK;
1.115     bowersj2 2350:     }
                   2351: 
1.131     bowersj2 2352:     # Send header, nocache
1.373     albertel 2353:     if ($env{'browser.mathml'}) {
1.241     www      2354:         &Apache::loncommon::content_type($r,'text/xml');
1.115     bowersj2 2355:     } else {
1.241     www      2356:         &Apache::loncommon::content_type($r,'text/html');
1.115     bowersj2 2357:     }
                   2358:     &Apache::loncommon::no_cache($r);
                   2359:     $r->send_http_header;
                   2360:     $r->rflush();
                   2361: 
1.131     bowersj2 2362:     # Unfortunately, this helper is so complicated we have to
                   2363:     # write it by hand
                   2364: 
                   2365:     Apache::loncommon::get_unprocessed_cgi($ENV{QUERY_STRING});
                   2366:     
1.176     bowersj2 2367:     my $helper = Apache::lonhelper::helper->new("Printing Helper");
1.146     bowersj2 2368:     $helper->declareVar('symb');
1.156     bowersj2 2369:     $helper->declareVar('postdata');    
1.290     sakharuk 2370:     $helper->declareVar('curseed'); 
                   2371:     $helper->declareVar('probstatus');   
1.156     bowersj2 2372:     $helper->declareVar('filename');
                   2373:     $helper->declareVar('construction');
1.178     sakharuk 2374:     $helper->declareVar('assignment');
1.262     sakharuk 2375:     $helper->declareVar('style_file');
1.340     foxr     2376:     $helper->declareVar('student_sort');
1.363     foxr     2377:     $helper->declareVar('FINISHPAGE');
1.366     foxr     2378:     $helper->declareVar('PRINT_TYPE');
1.372     foxr     2379:     $helper->declareVar("showallfoils");
1.483     foxr     2380:     $helper->declareVar("STUDENTS");
1.363     foxr     2381: 
                   2382:     #  The page breaks can get loaded initially from the course environment:
1.394     foxr     2383:     # But we only do this in the initial state so that they are allowed to change.
                   2384:     #
1.366     foxr     2385: 
1.416     foxr     2386:     # $helper->{VARS}->{FINISHPAGE} = '';
1.363     foxr     2387:     
                   2388:     &Apache::loncommon::restore_course_settings('print',
1.366     foxr     2389: 						{'pagebreaks'  => 'scalar',
                   2390: 					         'lastprinttype' => 'scalar'});
                   2391:     
1.483     foxr     2392:     # This will persistently load in the data we want from the
                   2393:     # very first screen.
1.394     foxr     2394:     
                   2395:     if($helper->{VARS}->{PRINT_TYPE} eq $env{'form.lastprinttype'}) {
                   2396: 	if (!defined ($env{"form.CURRENT_STATE"})) {
                   2397: 	    
                   2398: 	    $helper->{VARS}->{FINISHPAGE} = $env{'form.pagebreaks'};
                   2399: 	} else {
                   2400: 	    my $state = $env{"form.CURRENT_STATE"};
                   2401: 	    if ($state eq "START") {
                   2402: 		$helper->{VARS}->{FINISHPAGE} = $env{'form.pagebreaks'};
                   2403: 	    }
                   2404: 	}
                   2405: 	
1.366     foxr     2406:     }
1.481     albertel 2407: 
1.483     foxr     2408: 
1.156     bowersj2 2409:     # Detect whether we're coming from construction space
1.373     albertel 2410:     if ($env{'form.postdata'}=~/^(?:http:\/\/[^\/]+\/|\/|)\~([^\/]+)\/(.*)$/) {
1.235     bowersj2 2411:         $helper->{VARS}->{'filename'} = "~$1/$2";
1.156     bowersj2 2412:         $helper->{VARS}->{'construction'} = 1;
1.481     albertel 2413:     } else {
1.373     albertel 2414:         if ($env{'form.postdata'}) {
                   2415:             $helper->{VARS}->{'symb'} = &Apache::lonnet::symbread($env{'form.postdata'});
1.482     albertel 2416: 	    if ( $helper->{VARS}->{'symb'} eq '') {
                   2417: 		$helper->{VARS}->{'postdata'} = $env{'form.postdata'};
                   2418: 	    }
1.156     bowersj2 2419:         }
1.373     albertel 2420:         if ($env{'form.symb'}) {
                   2421:             $helper->{VARS}->{'symb'} = $env{'form.symb'};
1.156     bowersj2 2422:         }
1.373     albertel 2423:         if ($env{'form.url'}) {
1.156     bowersj2 2424:             $helper->{VARS}->{'symb'} = &Apache::lonnet::symbread($helper->{VARS}->{'postdata'});
                   2425:         }
1.416     foxr     2426: 
1.157     bowersj2 2427:     }
1.481     albertel 2428: 
1.373     albertel 2429:     if ($env{'form.symb'}) {
                   2430:         $helper->{VARS}->{'symb'} = $env{'form.symb'};
1.146     bowersj2 2431:     }
1.373     albertel 2432:     if ($env{'form.url'}) {
1.140     sakharuk 2433:         $helper->{VARS}->{'symb'} = &Apache::lonnet::symbread($helper->{VARS}->{'postdata'});
1.153     sakharuk 2434: 
1.140     sakharuk 2435:     }
1.343     albertel 2436:     $helper->{VARS}->{'symb'}=
                   2437: 	&Apache::lonenc::check_encrypt($helper->{VARS}->{'symb'});
1.335     albertel 2438:     my ($resourceTitle,$sequenceTitle,$mapTitle) = &details_for_menu($helper);
1.178     sakharuk 2439:     if ($sequenceTitle ne '') {$helper->{VARS}->{'assignment'}=$sequenceTitle;}
1.481     albertel 2440: 
1.156     bowersj2 2441:     
1.146     bowersj2 2442:     # Extract map
                   2443:     my $symb = $helper->{VARS}->{'symb'};
1.156     bowersj2 2444:     my ($map, $id, $url);
                   2445:     my $subdir;
1.483     foxr     2446:     my $is_published=0;		# True when printing from resource space.
1.156     bowersj2 2447: 
                   2448:     # Get the resource name from construction space
                   2449:     if ($helper->{VARS}->{'construction'}) {
                   2450:         $resourceTitle = substr($helper->{VARS}->{'filename'}, 
                   2451:                                 rindex($helper->{VARS}->{'filename'}, '/')+1);
                   2452:         $subdir = substr($helper->{VARS}->{'filename'},
                   2453:                          0, rindex($helper->{VARS}->{'filename'}, '/') + 1);
1.481     albertel 2454:     } else {
1.482     albertel 2455: 	if ($symb ne '') {
                   2456: 	    ($map, $id, $url) = &Apache::lonnet::decode_symb($symb);
                   2457: 	    $helper->{VARS}->{'postdata'} = 
                   2458: 		&Apache::lonenc::check_encrypt(&Apache::lonnet::clutter($url));
                   2459: 	} else {
                   2460: 	    $url = $helper->{VARS}->{'postdata'};
1.483     foxr     2461: 	    $is_published=1;	# From resource space.
1.482     albertel 2462: 	}
                   2463: 	$url = &Apache::lonnet::clutter($url);
1.481     albertel 2464: 
1.156     bowersj2 2465:         if (!$resourceTitle) { # if the resource doesn't have a title, use the filename
1.238     bowersj2 2466:             my $postdata = $helper->{VARS}->{'postdata'};
                   2467:             $resourceTitle = substr($postdata, rindex($postdata, '/') + 1);
1.156     bowersj2 2468:         }
                   2469:         $subdir = &Apache::lonnet::filelocation("", $url);
1.128     bowersj2 2470:     }
1.373     albertel 2471:     if (!$helper->{VARS}->{'curseed'} && $env{'form.curseed'}) {
                   2472: 	$helper->{VARS}->{'curseed'}=$env{'form.curseed'};
1.230     albertel 2473:     }
1.373     albertel 2474:     if (!$helper->{VARS}->{'probstatus'} && $env{'form.problemtype'}) {
1.512     foxr     2475: 	$helper->{VARS}->{'probstatus'}=$env{'form.problemstatus'};
1.290     sakharuk 2476:     }
1.115     bowersj2 2477: 
1.192     bowersj2 2478:     my $userCanSeeHidden = Apache::lonnavmaps::advancedUser();
                   2479: 
1.481     albertel 2480:     Apache::lonhelper::registerHelperTags();
1.119     bowersj2 2481: 
1.131     bowersj2 2482:     # "Delete everything after the last slash."
1.119     bowersj2 2483:     $subdir =~ s|/[^/]+$||;
                   2484: 
1.131     bowersj2 2485:     # What can be printed is a very dynamic decision based on
                   2486:     # lots of factors. So we need to dynamically build this list.
                   2487:     # To prevent security leaks, states are only added to the wizard
                   2488:     # if they can be reached, which ensures manipulating the form input
                   2489:     # won't allow anyone to reach states they shouldn't have permission
                   2490:     # to reach.
                   2491: 
                   2492:     # printChoices is tracking the kind of printing the user can
                   2493:     # do, and will be used in a choices construction later.
                   2494:     # In the meantime we will be adding states and elements to
                   2495:     # the helper by hand.
                   2496:     my $printChoices = [];
                   2497:     my $paramHash;
1.130     sakharuk 2498: 
1.240     albertel 2499:     if ($resourceTitle) {
1.458     www      2500:         push @{$printChoices}, ["<b><i>$resourceTitle</i></b> (".&mt('the resource you just saw on the screen').")", 'current_document', 'PAGESIZE'];
1.156     bowersj2 2501:     }
                   2502: 
1.238     bowersj2 2503:     # Useful filter strings
1.287     albertel 2504:     my $isProblem = '($res->is_problem()||$res->contains_problem) ';
1.238     bowersj2 2505:     $isProblem .= ' && !$res->randomout()' if !$userCanSeeHidden;
1.287     albertel 2506:     my $isProblemOrMap = '$res->is_problem() || $res->contains_problem() || $res->is_sequence()';
                   2507:     my $isNotMap = '!$res->is_sequence()';
1.238     bowersj2 2508:     $isNotMap .= ' && !$res->randomout()' if !$userCanSeeHidden;
                   2509:     my $isMap = '$res->is_map()';
1.342     albertel 2510:     my $symbFilter = '$res->shown_symb()';
                   2511:     my $urlValue = '$res->link()';
1.238     bowersj2 2512: 
                   2513:     $helper->declareVar('SEQUENCE');
                   2514: 
1.465     albertel 2515:     # If we're in a sequence...
1.416     foxr     2516: 
1.465     albertel 2517:     my $start_new_option;
                   2518:     if ($perm{'pav'}) {
                   2519: 	$start_new_option = 
                   2520: 	    "<option text='".&mt('Start new page<br />before selected').
                   2521: 	    "' variable='FINISHPAGE' />";
                   2522:     }
1.238     bowersj2 2523: 
1.483     foxr     2524:     if (($helper->{'VARS'}->{'construction'} ne '1' ) &&
1.350     foxr     2525: 
1.243     bowersj2 2526: 	$helper->{VARS}->{'postdata'} &&
                   2527: 	$helper->{VARS}->{'assignment'}) {
1.131     bowersj2 2528:         # Allow problems from sequence
1.458     www      2529:         push @{$printChoices}, [&mt('Selected <b>Problems</b> in folder <b><i>[_1]</i></b>',$sequenceTitle), 'map_problems', 'CHOOSE_PROBLEMS'];
1.131     bowersj2 2530:         # Allow all resources from sequence
1.458     www      2531:         push @{$printChoices}, [&mt('Selected <b>Resources</b> in folder <b><i>[_1]</i></b>',$sequenceTitle), 'map_problems_pages', 'CHOOSE_PROBLEMS_HTML'];
1.465     albertel 2532: 
1.131     bowersj2 2533:         my $helperFragment = <<HELPERFRAGMENT;
1.155     sakharuk 2534:   <state name="CHOOSE_PROBLEMS" title="Select Problem(s) to print">
1.435     foxr     2535:     <resource variable="RESOURCES" multichoice="1" toponly='1' addstatus="1"
1.287     albertel 2536:               closeallpages="1">
1.144     bowersj2 2537:       <nextstate>PAGESIZE</nextstate>
1.435     foxr     2538:       <filterfunc>return $isProblem;</filterfunc>
1.131     bowersj2 2539:       <mapurl>$map</mapurl>
1.238     bowersj2 2540:       <valuefunc>return $symbFilter;</valuefunc>
1.465     albertel 2541:       $start_new_option
1.131     bowersj2 2542:       </resource>
                   2543:     </state>
                   2544: 
1.155     sakharuk 2545:   <state name="CHOOSE_PROBLEMS_HTML" title="Select Resource(s) to print">
1.435     foxr     2546:     <resource variable="RESOURCES" multichoice="1" toponly='1' addstatus="1"
1.287     albertel 2547:               closeallpages="1">
1.144     bowersj2 2548:       <nextstate>PAGESIZE</nextstate>
1.435     foxr     2549:       <filterfunc>return $isNotMap;</filterfunc>
1.131     bowersj2 2550:       <mapurl>$map</mapurl>
1.238     bowersj2 2551:       <valuefunc>return $symbFilter;</valuefunc>
1.465     albertel 2552:       $start_new_option
1.131     bowersj2 2553:       </resource>
                   2554:     </state>
                   2555: HELPERFRAGMENT
1.121     bowersj2 2556: 
1.326     sakharuk 2557: 	&Apache::lonxml::xmlparse($r, 'helper', $helperFragment);
1.121     bowersj2 2558:     }
                   2559: 
1.397     albertel 2560:     # If the user has pfo (print for otheres) allow them to print all 
1.354     foxr     2561:     # problems and resources  in the entier course, optionally for selected students
1.483     foxr     2562:     if ($perm{'pfo'} &&  !$is_published  &&
1.481     albertel 2563:         ($helper->{VARS}->{'postdata'}=~/\/res\// || $helper->{VARS}->{'postdata'}=~/\/(syllabus|smppg|aboutme|bulletinboard)$/)) { 
                   2564: 
1.509     albertel 2565:         push @{$printChoices}, [&mtn('Selected <b>Problems</b> from <b>entire course</b>'), 'all_problems', 'ALL_PROBLEMS'];
                   2566: 	push @{$printChoices}, [&mtn('Selected <b>Resources</b> from <b>entire course</b>'), 'all_resources', 'ALL_RESOURCES'];
1.284     albertel 2567:          &Apache::lonxml::xmlparse($r, 'helper', <<ALL_PROBLEMS);
1.155     sakharuk 2568:   <state name="ALL_PROBLEMS" title="Select Problem(s) to print">
1.287     albertel 2569:     <resource variable="RESOURCES" toponly='0' multichoice="1"
                   2570: 	suppressEmptySequences='0' addstatus="1" closeallpages="1">
1.144     bowersj2 2571:       <nextstate>PAGESIZE</nextstate>
1.192     bowersj2 2572:       <filterfunc>return $isProblemOrMap;</filterfunc>
1.287     albertel 2573:       <choicefunc>return $isNotMap;</choicefunc>
1.238     bowersj2 2574:       <valuefunc>return $symbFilter;</valuefunc>
1.465     albertel 2575:       $start_new_option
1.284     albertel 2576:     </resource>
                   2577:   </state>
1.354     foxr     2578:   <state name="ALL_RESOURCES" title="Select Resource(s) to print">
                   2579:     <resource variable="RESOURCES" toponly='0' multichoice='1'
                   2580:               suppressEmptySequences='0' addstatus='1' closeallpages='1'>
                   2581:       <nextstate>PAGESIZE</nextstate>
                   2582:       <filterfunc>return $isNotMap; </filterfunc>
                   2583:       <valuefunc>return $symbFilter;</valuefunc>
1.465     albertel 2584:       $start_new_option
1.354     foxr     2585:     </resource>
                   2586:   </state>
1.284     albertel 2587: ALL_PROBLEMS
1.132     bowersj2 2588: 
1.284     albertel 2589: 	if ($helper->{VARS}->{'assignment'}) {
1.483     foxr     2590: 	    push @{$printChoices}, [&mt("Selected <b>Problems</b> from folder <b><i>[_1]</i></b> for <b>selected people</b>",$sequenceTitle), 'problems_for_students', 'CHOOSE_STUDENTS'];
1.474     www      2591: 	    push @{$printChoices}, [&mt("Selected <b>Problems</b> from folder <b><i>[_1]</i></b> for <b>CODEd assignments</b>",$sequenceTitle), 'problems_for_anon', 'CHOOSE_ANON1'];
1.284     albertel 2592: 	}
1.424     foxr     2593: 
1.507     albertel 2594: 	my $randomly_ordered_warning = 
                   2595: 	    &get_randomly_ordered_warning($helper,$map);
                   2596: 
1.424     foxr     2597: 	# resource_selector will hold a few states that:
                   2598: 	#   - Allow resources to be selected for printing.
                   2599: 	#   - Determine pagination between assignments.
                   2600: 	#   - Determine how many assignments should be bundled into a single PDF.
                   2601:         # TODO:
                   2602: 	#    Probably good to do things like separate this up into several vars, each
                   2603: 	#    with one state, and use REGEXPs at inclusion time to set state names
                   2604: 	#    and next states for better mix and match capability
                   2605: 	#
1.284     albertel 2606: 	my $resource_selector=<<RESOURCE_SELECTOR;
1.424     foxr     2607:     <state name="SELECT_PROBLEMS" title="Select resources to print">
1.507     albertel 2608:     $randomly_ordered_warning
                   2609: 
1.424     foxr     2610:    <nextstate>PRINT_FORMATTING</nextstate> 
1.284     albertel 2611:    <message><br /><big><i><b>Select resources for the assignment</b></i></big><br /></message>
1.287     albertel 2612:     <resource variable="RESOURCES" multichoice="1" addstatus="1" 
                   2613:               closeallpages="1">
1.254     sakharuk 2614:       <filterfunc>return $isProblem;</filterfunc>
1.148     bowersj2 2615:       <mapurl>$map</mapurl>
1.254     sakharuk 2616:       <valuefunc>return $symbFilter;</valuefunc>
1.465     albertel 2617:       $start_new_option
1.147     bowersj2 2618:       </resource>
1.424     foxr     2619:     </state>
                   2620:     <state name="PRINT_FORMATTING" title="How should results be printed?">
1.155     sakharuk 2621:     <message><br /><big><i><b>How should the results be printed?</b></i></big><br /></message>
1.149     bowersj2 2622:     <choices variable="EMPTY_PAGES">
1.204     sakharuk 2623:       <choice computer='0'>Start each student\'s assignment on a new page/column (add a pagefeed after each assignment)</choice>
                   2624:       <choice computer='1'>Add one empty page/column after each student\'s assignment</choice>
                   2625:       <choice computer='2'>Add two empty pages/column after each student\'s assignment</choice>
                   2626:       <choice computer='3'>Add three empty pages/column after each student\'s assignment</choice>
1.284     albertel 2627:     </choices>
1.424     foxr     2628:     <nextstate>PAGESIZE</nextstate>
1.429     foxr     2629:     <message><hr width='33%' /><b>How do you want assignments split into PDF files? </b></message>
                   2630:     <choices variable="SPLIT_PDFS">
                   2631:        <choice computer="all">All assignments in a single PDF file</choice>
                   2632:        <choice computer="sections">Each PDF contains exactly one section</choice>
                   2633:        <choice computer="oneper">Each PDF contains exactly one assignment</choice>
1.449     albertel 2634:        <choice computer="usenumber" relatedvalue="NUMBER_TO_PRINT">
                   2635:             Specify the number of assignments per PDF:</choice>
1.429     foxr     2636:     </choices>
1.424     foxr     2637:     </state>
1.284     albertel 2638: RESOURCE_SELECTOR
                   2639: 
                   2640:         &Apache::lonxml::xmlparse($r, 'helper', <<CHOOSE_STUDENTS);
                   2641:   <state name="CHOOSE_STUDENTS" title="Select Students and Resources">
1.485     albertel 2642:       <message><b>Select sorting order of printout</b> </message>
1.340     foxr     2643:     <choices variable='student_sort'>
                   2644:       <choice computer='0'>Sort by section then student</choice>
                   2645:       <choice computer='1'>Sort by students across sections.</choice>
                   2646:     </choices>
1.437     foxr     2647:       <message><br /><hr /><br /> </message>
1.425     foxr     2648:       <student multichoice='1' variable="STUDENTS" nextstate="SELECT_PROBLEMS" coursepersonnel="1"/>
1.424     foxr     2649:   </state>
1.284     albertel 2650:     $resource_selector
1.131     bowersj2 2651: CHOOSE_STUDENTS
1.292     albertel 2652: 
1.373     albertel 2653: 	my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
                   2654: 	my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
1.292     albertel 2655:         my @names=&Apache::lonnet::getkeys('CODEs',$cdom,$cnum);
                   2656: 	my $namechoice='<choice></choice>';
1.337     albertel 2657: 	foreach my $name (sort {uc($a) cmp uc($b)} @names) {
1.294     albertel 2658: 	    if ($name =~ /^error: 2 /) { next; }
1.381     albertel 2659: 	    if ($name =~ /^type\0/) { next; }
1.292     albertel 2660: 	    $namechoice.='<choice computer="'.$name.'">'.$name.'</choice>';
                   2661: 	}
1.389     foxr     2662: 
                   2663: 
                   2664: 	my %code_values;
1.405     albertel 2665: 	my %codes_to_print;
1.411     albertel 2666: 	foreach my $key (@names) {
1.389     foxr     2667: 	    %code_values = &Apache::grades::get_codes($key, $cdom, $cnum);
1.405     albertel 2668: 	    foreach my $key (keys(%code_values)) {
                   2669: 		$codes_to_print{$key} = 1;
1.388     foxr     2670: 	    }
                   2671: 	}
1.389     foxr     2672: 
1.452     albertel 2673: 	my $code_selection;
1.405     albertel 2674: 	foreach my $code (sort {uc($a) cmp uc($b)} (keys(%codes_to_print))) {
1.389     foxr     2675: 	    my $choice  = $code;
                   2676: 	    if ($code =~ /^[A-Z]+$/) { # Alpha code
                   2677: 		$choice = &letters_to_num($code);
                   2678: 	    }
1.432     albertel 2679: 	    push(@{$helper->{DATA}{ALL_CODE_CHOICES}},[$code,$choice]);
1.388     foxr     2680: 	}
1.436     albertel 2681: 	if (%codes_to_print) {
                   2682: 	    $code_selection .='   
1.472     albertel 2683: 	    <message><b>Choose single CODE from list:</b></message>
1.448     albertel 2684: 		<message></td><td></message>
1.452     albertel 2685: 		<dropdown variable="CODE_SELECTED_FROM_LIST" multichoice="0" allowempty="0">
                   2686:                   <choice></choice>
1.448     albertel 2687:                   <exec>
                   2688:                      push(@{$state->{CHOICES}},@{$helper->{DATA}{ALL_CODE_CHOICES}});
                   2689:                   </exec>
1.452     albertel 2690: 		</dropdown>
1.468     foxr     2691: 	    <message></td></tr><tr><td></message>
1.436     albertel 2692:             '.$/;
1.448     albertel 2693: 
1.436     albertel 2694: 	}
1.432     albertel 2695: 
                   2696: 	
1.381     albertel 2697: 	open(FH,$Apache::lonnet::perlvar{'lonTabDir'}.'/scantronformat.tab');
                   2698: 	my $codechoice='';
                   2699: 	foreach my $line (<FH>) {
                   2700: 	    my ($name,$description,$code_type,$code_length)=
                   2701: 		(split(/:/,$line))[0,1,2,4];
                   2702: 	    if ($code_length > 0 && 
                   2703: 		$code_type =~/^(letter|number|-1)/) {
                   2704: 		$codechoice.='<choice computer="'.$name.'">'.$description.'</choice>';
                   2705: 	    }
                   2706: 	}
                   2707: 	if ($codechoice eq '') {
                   2708: 	    $codechoice='<choice computer="default">Default</choice>';
                   2709: 	}
1.284     albertel 2710:         &Apache::lonxml::xmlparse($r, 'helper', <<CHOOSE_ANON1);
1.468     foxr     2711:   <state name="CHOOSE_ANON1" title="Specify CODEd Assignments">
1.424     foxr     2712:     <nextstate>SELECT_PROBLEMS</nextstate>
1.468     foxr     2713:     <message><h4>Fill out one of the forms below</h4></message>
                   2714:     <message><br /><hr /> <br /></message>
                   2715:     <message><h3>Generate new CODEd Assignments</h3></message>
                   2716:     <message><table><tr><td><b>Number of CODEd assignments to print:</b></td><td></message>
1.362     albertel 2717:     <string variable="NUMBER_TO_PRINT_TOTAL" maxlength="5" size="5">
                   2718:        <validator>
                   2719: 	if (((\$helper->{'VARS'}{'NUMBER_TO_PRINT_TOTAL'}+0) < 1) &&
1.382     foxr     2720: 	    !\$helper->{'VARS'}{'REUSE_OLD_CODES'}                &&
1.388     foxr     2721:             !\$helper->{'VARS'}{'SINGLE_CODE'}                    &&
                   2722: 	    !\$helper->{'VARS'}{'CODE_SELECTED_FROM_LIST'}) {
1.362     albertel 2723: 	    return "You need to specify the number of assignments to print";
                   2724: 	}
                   2725: 	return undef;
                   2726:        </validator>
                   2727:     </string>
                   2728:     <message></td></tr><tr><td></message>
1.501     albertel 2729:     <message><b>Names to save the CODEs under for later:</b></message>
1.412     albertel 2730:     <message></td><td></message>
                   2731:     <string variable="ANON_CODE_STORAGE_NAME" maxlength="50" size="20" />
                   2732:     <message></td></tr><tr><td></message>
                   2733:     <message><b>Bubble sheet type:</b></message>
                   2734:     <message></td><td></message>
                   2735:     <dropdown variable="CODE_OPTION" multichoice="0" allowempty="0">
                   2736:     $codechoice
                   2737:     </dropdown>
1.468     foxr     2738:     <message></td></tr><tr><td colspan="2"></td></tr><tr><td></message>
                   2739:     <message></td></tr><tr><td></table></message>
1.472     albertel 2740:     <message><br /><hr /><h3>Print a Specific CODE </h3><br /><table></message>
1.468     foxr     2741:     <message><tr><td><b>Enter a CODE to print:</b></td><td></message>
1.412     albertel 2742:     <string variable="SINGLE_CODE" size="10">
1.382     foxr     2743:         <validator>
                   2744: 	   if(!\$helper->{'VARS'}{'NUMBER_TO_PRINT_TOTAL'}           &&
1.388     foxr     2745: 	      !\$helper->{'VARS'}{'REUSE_OLD_CODES'}                 &&
                   2746: 	      !\$helper->{'VARS'}{'CODE_SELECTED_FROM_LIST'}) {
1.382     foxr     2747: 	      return &Apache::lonprintout::is_code_valid(\$helper->{'VARS'}{'SINGLE_CODE'},
                   2748: 						      \$helper->{'VARS'}{'CODE_OPTION'});
                   2749: 	   } else {
                   2750: 	       return undef;	# Other forces control us.
                   2751: 	   }
                   2752:         </validator>
                   2753:     </string>
1.472     albertel 2754:     <message></td></tr><tr><td></message>
1.432     albertel 2755:         $code_selection
1.468     foxr     2756:     <message></td></tr></table></message>
1.472     albertel 2757:     <message><hr /><h3>Reprint a Set of Saved CODEs</h3><table><tr><td></message>
1.468     foxr     2758:     <message><b>Select saved CODEs:</b></message>
1.381     albertel 2759:     <message></td><td></message>
1.292     albertel 2760:     <dropdown variable="REUSE_OLD_CODES">
                   2761:         $namechoice
                   2762:     </dropdown>
1.412     albertel 2763:     <message></td></tr></table></message>
1.284     albertel 2764:   </state>
1.424     foxr     2765:   $resource_selector
1.284     albertel 2766: CHOOSE_ANON1
1.254     sakharuk 2767: 
1.272     sakharuk 2768: 
1.254     sakharuk 2769: 	if ($helper->{VARS}->{'assignment'}) {
1.483     foxr     2770: 	    push @{$printChoices}, [&mt("Selected <b>Resources</b> from folder <b><i>[_1]</i></b> for <b>selected people</b>",$sequenceTitle), 'resources_for_students', 'CHOOSE_STUDENTS1'];
1.472     albertel 2771: 	    push @{$printChoices}, [&mt("Selected <b>Resources</b> from folder <b><i>[_1]</i></b> for <b>CODEd assignments</b>",$sequenceTitle), 'resources_for_anon', 'CHOOSE_ANON2'];
1.254     sakharuk 2772: 	}
1.284     albertel 2773: 	    
                   2774: 
                   2775: 	$resource_selector=<<RESOURCE_SELECTOR;
1.424     foxr     2776:     <state name="SELECT_RESOURCES" title="Select Resources">
1.507     albertel 2777:     $randomly_ordered_warning
                   2778: 
1.424     foxr     2779:     <nextstate>PRINT_FORMATTING</nextstate>
1.254     sakharuk 2780:     <message><br /><big><i><b>Select resources for the assignment</b></i></big><br /></message>
1.287     albertel 2781:     <resource variable="RESOURCES" multichoice="1" addstatus="1" 
                   2782:               closeallpages="1">
1.254     sakharuk 2783:       <filterfunc>return $isNotMap;</filterfunc>
                   2784:       <mapurl>$map</mapurl>
                   2785:       <valuefunc>return $symbFilter;</valuefunc>
1.465     albertel 2786:       $start_new_option
1.254     sakharuk 2787:       </resource>
1.424     foxr     2788:     </state>
                   2789:     <state name="PRINT_FORMATTING" title="Format of the print job">
                   2790:     <nextstate>NUMBER_PER_PDF</nextstate>
1.254     sakharuk 2791:     <message><br /><big><i><b>How should the results be printed?</b></i></big><br /></message>
                   2792:     <choices variable="EMPTY_PAGES">
                   2793:       <choice computer='0'>Start each student\'s assignment on a new page/column (add a pagefeed after each assignment)</choice>
                   2794:       <choice computer='1'>Add one empty page/column after each student\'s assignment</choice>
                   2795:       <choice computer='2'>Add two empty pages/column after each student\'s assignment</choice>
                   2796:       <choice computer='3'>Add three empty pages/column after each student\'s assignment</choice>
1.284     albertel 2797:     </choices>
1.424     foxr     2798:     <nextstate>PAGESIZE</nextstate>
1.429     foxr     2799:     <message><hr width='33%' /><b>How do you want assignments split into PDF files? </b></message>
                   2800:     <choices variable="SPLIT_PDFS">
                   2801:        <choice computer="all">All assignments in a single PDF file</choice>
                   2802:        <choice computer="sections">Each PDF contains exactly one section</choice>
                   2803:        <choice computer="oneper">Each PDF contains exactly one assignment</choice>
1.449     albertel 2804:        <choice computer="usenumber" relatedvalue="NUMBER_TO_PRINT">
                   2805:            Specify the number of assignments per PDF:</choice>
1.429     foxr     2806:     </choices>
1.424     foxr     2807:     </state>
1.284     albertel 2808: RESOURCE_SELECTOR
                   2809: 
                   2810: 	&Apache::lonxml::xmlparse($r, 'helper', <<CHOOSE_STUDENTS1);
                   2811:   <state name="CHOOSE_STUDENTS1" title="Select Students and Resources">
1.340     foxr     2812:     <choices variable='student_sort'>
                   2813:       <choice computer='0'>Sort by section then student</choice>
                   2814:       <choice computer='1'>Sort by students across sections.</choice>
                   2815:     </choices>
1.437     foxr     2816:     <message><br /><hr /><br /></message>
1.426     foxr     2817:     <student multichoice='1' variable="STUDENTS" nextstate="SELECT_RESOURCES" coursepersonnel="1" />
1.340     foxr     2818: 
1.424     foxr     2819:     </state>
1.284     albertel 2820:     $resource_selector
1.254     sakharuk 2821: CHOOSE_STUDENTS1
                   2822: 
1.284     albertel 2823: 	&Apache::lonxml::xmlparse($r, 'helper', <<CHOOSE_ANON2);
1.472     albertel 2824:   <state name="CHOOSE_ANON2" title="Select CODEd Assignments">
1.424     foxr     2825:     <nextstate>SELECT_RESOURCES</nextstate>
1.472     albertel 2826:     <message><h4>Fill out one of the forms below</h4></message>
                   2827:     <message><br /><hr /> <br /></message>
                   2828:     <message><h3>Generate new CODEd Assignments</h3></message>
                   2829:     <message><table><tr><td><b>Number of CODEd assignments to print:</b></td><td></message>
1.362     albertel 2830:     <string variable="NUMBER_TO_PRINT_TOTAL" maxlength="5" size="5">
                   2831:        <validator>
                   2832: 	if (((\$helper->{'VARS'}{'NUMBER_TO_PRINT_TOTAL'}+0) < 1) &&
1.386     foxr     2833: 	    !\$helper->{'VARS'}{'REUSE_OLD_CODES'}                &&
1.388     foxr     2834: 	    !\$helper->{'VARS'}{'SINGLE_CODE'}                   &&
                   2835: 	    !\$helper->{'VARS'}{'CODE_SELECTED_FROM_LIST'}) {
1.362     albertel 2836: 	    return "You need to specify the number of assignments to print";
                   2837: 	}
                   2838: 	return undef;
                   2839:        </validator>
                   2840:     </string>
                   2841:     <message></td></tr><tr><td></message>
1.501     albertel 2842:     <message><b>Names to save the CODEs under for later:</b></message>
1.412     albertel 2843:     <message></td><td></message>
                   2844:     <string variable="ANON_CODE_STORAGE_NAME" maxlength="50" size="20" />
                   2845:     <message></td></tr><tr><td></message>
                   2846:     <message><b>Bubble sheet type:</b></message>
                   2847:     <message></td><td></message>
                   2848:     <dropdown variable="CODE_OPTION" multichoice="0" allowempty="0">
                   2849:     $codechoice
                   2850:     </dropdown>
1.472     albertel 2851:     <message></td></tr><tr><td></table></message>
                   2852:     <message><br /><hr /><h3>Print a Specific CODE </h3><br /><table></message>
                   2853:     <message><tr><td><b>Enter a CODE to print:</b></td><td></message>
1.412     albertel 2854:     <string variable="SINGLE_CODE" size="10">
1.386     foxr     2855:         <validator>
                   2856: 	   if(!\$helper->{'VARS'}{'NUMBER_TO_PRINT_TOTAL'}           &&
1.388     foxr     2857: 	      !\$helper->{'VARS'}{'REUSE_OLD_CODES'}                 &&
                   2858: 	      !\$helper->{'VARS'}{'CODE_SELECTED_FROM_LIST'}) {
1.386     foxr     2859: 	      return &Apache::lonprintout::is_code_valid(\$helper->{'VARS'}{'SINGLE_CODE'},
                   2860: 						      \$helper->{'VARS'}{'CODE_OPTION'});
                   2861: 	   } else {
                   2862: 	       return undef;	# Other forces control us.
                   2863: 	   }
                   2864:         </validator>
                   2865:     </string>
1.472     albertel 2866:     <message></td></tr><tr><td></message>
1.432     albertel 2867:         $code_selection
1.472     albertel 2868:     <message></td></tr></table></message>
                   2869:     <message><hr /><h3>Reprint a Set of Saved CODEs</h3><table><tr><td></message>
                   2870:     <message><b>Select saved CODEs:</b></message>
1.381     albertel 2871:     <message></td><td></message>
1.294     albertel 2872:     <dropdown variable="REUSE_OLD_CODES">
                   2873:         $namechoice
                   2874:     </dropdown>
1.412     albertel 2875:     <message></td></tr></table></message>
1.424     foxr     2876:   </state>
1.284     albertel 2877:     $resource_selector
                   2878: CHOOSE_ANON2
1.481     albertel 2879:     }
                   2880: 
1.121     bowersj2 2881:     # FIXME: That RE should come from a library somewhere.
1.483     foxr     2882:     if (($perm{'pav'} 
1.482     albertel 2883: 	&& $subdir ne $Apache::lonnet::perlvar{'lonDocRoot'}.'/res/'
                   2884: 	&& (defined($helper->{'VARS'}->{'construction'})
                   2885: 	    ||
                   2886: 	    (&Apache::lonnet::allowed('bre',$subdir) eq 'F'
                   2887: 	     && 
                   2888: 	     $helper->{VARS}->{'postdata'}=~/\.(problem|exam|quiz|assess|survey|form|library|page|xml|html|htm|xhtml|xhtm)/)
1.483     foxr     2889: 	    )) 
                   2890: 	&& $helper->{VARS}->{'assignment'} eq ""
1.482     albertel 2891: 	) {
1.238     bowersj2 2892: 
1.482     albertel 2893: 	my $pretty_dir = &Apache::lonnet::hreflocation($subdir);
                   2894:         push @{$printChoices}, [&mt("Selected <b>Problems</b> from current subdirectory <b><i>[_1]</i></b>",$pretty_dir), 'problems_from_directory', 'CHOOSE_FROM_SUBDIR'];
1.139     bowersj2 2895:         my $xmlfrag = <<CHOOSE_FROM_SUBDIR;
1.482     albertel 2896:   <state name="CHOOSE_FROM_SUBDIR" title="Select File(s) from <b><small>$pretty_dir</small></b> to print">
1.458     www      2897: 
1.138     bowersj2 2898:     <files variable="FILES" multichoice='1'>
1.144     bowersj2 2899:       <nextstate>PAGESIZE</nextstate>
1.138     bowersj2 2900:       <filechoice>return '$subdir';</filechoice>
1.139     bowersj2 2901: CHOOSE_FROM_SUBDIR
                   2902:         
1.238     bowersj2 2903:         # this is broken up because I really want interpolation above,
                   2904:         # and I really DON'T want it below
1.139     bowersj2 2905:         $xmlfrag .= <<'CHOOSE_FROM_SUBDIR';
1.225     bowersj2 2906:       <filefilter>return Apache::lonhelper::files::not_old_version($filename) &&
                   2907: 	  $filename =~ m/\.(problem|exam|quiz|assess|survey|form|library)$/;
1.131     bowersj2 2908:       </filefilter>
1.138     bowersj2 2909:       </files>
1.131     bowersj2 2910:     </state>
                   2911: CHOOSE_FROM_SUBDIR
1.139     bowersj2 2912:         &Apache::lonxml::xmlparse($r, 'helper', $xmlfrag);
1.131     bowersj2 2913:     }
1.238     bowersj2 2914: 
                   2915:     # Allow the user to select any sequence in the course, feed it to
                   2916:     # another resource selector for that sequence
1.483     foxr     2917:     if (!$helper->{VARS}->{'construction'} && !$is_published) {
1.509     albertel 2918: 	push @$printChoices, [&mtn("Selected <b>Resources</b> from <b>selected folder</b> in course"),
1.249     sakharuk 2919: 			      'select_sequences', 'CHOOSE_SEQUENCE'];
1.244     bowersj2 2920: 	my $escapedSequenceName = $helper->{VARS}->{'SEQUENCE'};
                   2921: 	#Escape apostrophes and backslashes for Perl
                   2922: 	$escapedSequenceName =~ s/\\/\\\\/g;
                   2923: 	$escapedSequenceName =~ s/'/\\'/g;
1.239     bowersj2 2924: 	&Apache::lonxml::xmlparse($r, 'helper', <<CHOOSE_FROM_ANY_SEQUENCE);
1.238     bowersj2 2925:   <state name="CHOOSE_SEQUENCE" title="Select Sequence To Print From">
                   2926:     <message>Select the sequence to print resources from:</message>
                   2927:     <resource variable="SEQUENCE">
                   2928:       <nextstate>CHOOSE_FROM_ANY_SEQUENCE</nextstate>
                   2929:       <filterfunc>return \$res->is_sequence;</filterfunc>
                   2930:       <valuefunc>return $urlValue;</valuefunc>
1.447     foxr     2931:       <choicefunc>return \$res->hasResource(\$res,sub { return !\$_[0]->is_sequence() },0,0);
1.391     foxr     2932: 	</choicefunc>
1.238     bowersj2 2933:       </resource>
                   2934:     </state>
                   2935:   <state name="CHOOSE_FROM_ANY_SEQUENCE" title="Select Resources To Print">
                   2936:     <message>(mark desired resources then click "next" button) <br /></message>
1.435     foxr     2937:     <resource variable="RESOURCES" multichoice="1" toponly='1' addstatus="1"
1.287     albertel 2938:               closeallpages="1">
1.238     bowersj2 2939:       <nextstate>PAGESIZE</nextstate>
1.466     albertel 2940:       <filterfunc>return $isNotMap</filterfunc>
1.244     bowersj2 2941:       <mapurl evaluate='1'>return '$escapedSequenceName';</mapurl>
1.238     bowersj2 2942:       <valuefunc>return $symbFilter;</valuefunc>
1.465     albertel 2943:       $start_new_option
1.238     bowersj2 2944:       </resource>
                   2945:     </state>
                   2946: CHOOSE_FROM_ANY_SEQUENCE
1.239     bowersj2 2947: }
1.481     albertel 2948: 
1.131     bowersj2 2949:     # Generate the first state, to select which resources get printed.
1.223     bowersj2 2950:     Apache::lonhelper::state->new("START", "Select Printing Options:");
1.131     bowersj2 2951:     $paramHash = Apache::lonhelper::getParamHash();
1.155     sakharuk 2952:     $paramHash->{MESSAGE_TEXT} = "";
1.131     bowersj2 2953:     Apache::lonhelper::message->new();
                   2954:     $paramHash = Apache::lonhelper::getParamHash();
                   2955:     $paramHash->{'variable'} = 'PRINT_TYPE';
                   2956:     $paramHash->{CHOICES} = $printChoices;
                   2957:     Apache::lonhelper::choices->new();
1.161     bowersj2 2958: 
1.223     bowersj2 2959:     my $startedTable = 0; # have we started an HTML table yet? (need
                   2960:                           # to close it later)
                   2961: 
1.397     albertel 2962:     if (($perm{'pav'} and &Apache::lonnet::allowed('vgr',$env{'request.course.id'})) or 
1.170     sakharuk 2963: 	($helper->{VARS}->{'construction'} eq '1')) {
1.497     www      2964: 	addMessage("<hr width='33%' /><table><tr><td align='right'>".
                   2965:                    '<label for="ANSWER_TYPE_forminput">'.
                   2966:                    &mt('Print').
                   2967:                    "</label>: </td><td>");
1.161     bowersj2 2968:         $paramHash = Apache::lonhelper::getParamHash();
1.162     sakharuk 2969: 	$paramHash->{'variable'} = 'ANSWER_TYPE';   
                   2970: 	$helper->declareVar('ANSWER_TYPE');         
1.161     bowersj2 2971:         $paramHash->{CHOICES} = [
1.242     sakharuk 2972:                                    ['Without Answers', 'yes'],
                   2973:                                    ['With Answers', 'no'],
1.368     albertel 2974:                                    ['Only Answers', 'only']
1.289     sakharuk 2975:                                 ];
1.210     sakharuk 2976:         Apache::lonhelper::dropdown->new();
1.223     bowersj2 2977: 	addMessage("</td></tr>");
                   2978: 	$startedTable = 1;
1.161     bowersj2 2979:     }
1.209     sakharuk 2980: 
1.397     albertel 2981:     if ($perm{'pav'}) {
1.223     bowersj2 2982: 	if (!$startedTable) {
1.497     www      2983: 	    addMessage("<hr width='33%' /><table><tr><td align='right'>".
                   2984:                        '<label for="LATEX_TYPE_forminput">'.
                   2985:                        &mt('LaTeX mode').
                   2986:                        "</label>: </td><td>");
1.223     bowersj2 2987: 	    $startedTable = 1;
                   2988: 	} else {
1.497     www      2989: 	    addMessage("<tr><td align='right'>".
                   2990:                        '<label for="LATEX_TYPE_forminput">'.
                   2991:                         &mt('LaTeX mode').
                   2992:                        "</label>: </td><td>");
1.223     bowersj2 2993: 	}
1.203     sakharuk 2994:         $paramHash = Apache::lonhelper::getParamHash();
                   2995: 	$paramHash->{'variable'} = 'LATEX_TYPE';   
                   2996: 	$helper->declareVar('LATEX_TYPE');  
                   2997: 	if ($helper->{VARS}->{'construction'} eq '1') {       
                   2998: 	    $paramHash->{CHOICES} = [
1.223     bowersj2 2999: 				     ['standard LaTeX mode', 'standard'], 
                   3000: 				     ['LaTeX batchmode', 'batchmode'], ];
1.203     sakharuk 3001: 	} else {
                   3002: 	    $paramHash->{CHOICES} = [
1.223     bowersj2 3003: 				     ['LaTeX batchmode', 'batchmode'],
                   3004: 				     ['standard LaTeX mode', 'standard'] ];
1.203     sakharuk 3005: 	}
1.210     sakharuk 3006:         Apache::lonhelper::dropdown->new();
1.218     sakharuk 3007:  
1.497     www      3008: 	addMessage("</td></tr><tr><td align='right'>".
1.506     albertel 3009:                    '<label for="TABLE_CONTENTS_forminput">'.
1.497     www      3010:                    &mt('Print Table of Contents').
                   3011:                    "</label>: </td><td>");
1.209     sakharuk 3012:         $paramHash = Apache::lonhelper::getParamHash();
                   3013: 	$paramHash->{'variable'} = 'TABLE_CONTENTS';   
                   3014: 	$helper->declareVar('TABLE_CONTENTS');         
                   3015:         $paramHash->{CHOICES} = [
1.223     bowersj2 3016:                                    ['No', 'no'],
                   3017:                                    ['Yes', 'yes'] ];
1.210     sakharuk 3018:         Apache::lonhelper::dropdown->new();
1.223     bowersj2 3019: 	addMessage("</td></tr>");
1.214     sakharuk 3020:         
1.220     sakharuk 3021: 	if (not $helper->{VARS}->{'construction'}) {
1.497     www      3022: 	    addMessage("<tr><td align='right'>".
                   3023:                        '<label for="TABLE_INDEX_forminput">'.
                   3024:                        &mt('Print Index').
                   3025:                        "</label>: </td><td>");
1.220     sakharuk 3026: 	    $paramHash = Apache::lonhelper::getParamHash();
                   3027: 	    $paramHash->{'variable'} = 'TABLE_INDEX';   
                   3028: 	    $helper->declareVar('TABLE_INDEX');         
                   3029: 	    $paramHash->{CHOICES} = [
1.223     bowersj2 3030: 				     ['No', 'no'],
                   3031: 				     ['Yes', 'yes'] ];
1.220     sakharuk 3032: 	    Apache::lonhelper::dropdown->new();
1.223     bowersj2 3033: 	    addMessage("</td></tr>");
1.497     www      3034: 	    addMessage("<tr><td align='right'>".
                   3035:                        '<label for="PRINT_DISCUSSIONS_forminput">'.
                   3036:                        &mt('Print Discussions').
                   3037:                        "</label>: </td><td>");
1.309     sakharuk 3038: 	    $paramHash = Apache::lonhelper::getParamHash();
                   3039: 	    $paramHash->{'variable'} = 'PRINT_DISCUSSIONS';   
                   3040: 	    $helper->declareVar('PRINT_DISCUSSIONS');         
                   3041: 	    $paramHash->{CHOICES} = [
                   3042: 				     ['No', 'no'],
                   3043: 				     ['Yes', 'yes'] ];
                   3044: 	    Apache::lonhelper::dropdown->new();
                   3045: 	    addMessage("</td></tr>");
1.372     foxr     3046: 
1.511     foxr     3047: 	    # Prompt for printing annotations too.
                   3048: 		
                   3049: 	    addMessage("<tr><td align='right'>".
                   3050: 		       '<label for="PRINT_ANNOTATIONS_forminput">'.
                   3051: 		       &mt('Print Annotations').
                   3052: 		       "</label>:</td><td>");
                   3053: 	    $paramHash = Apache::lonhelper::getParamHash();
                   3054: 	    $paramHash->{'variable'} = "PRINT_ANNOTATIONS";
                   3055: 	    $helper->declareVar("PRINT_ANNOTATIONS");
                   3056: 	    $paramHash->{CHOICES} = [
                   3057: 				     ['No', 'no'],
                   3058: 				     ['Yes', 'yes']];
                   3059: 	    Apache::lonhelper::dropdown->new();
                   3060: 	    addMessage("</td></tr>");
                   3061: 
1.397     albertel 3062: 	    addMessage("<tr><td align = 'right'>  </td><td>");
                   3063: 	    $paramHash = Apache::lonhelper::getParamHash();
                   3064: 	    $paramHash->{'multichoice'} = "true";
                   3065: 	    $paramHash->{'allowempty'}  = "true";
                   3066: 	    $paramHash->{'variable'}   = "showallfoils";
                   3067: 	    $paramHash->{'CHOICES'} = [ ["Show all foils", "1"] ];
                   3068: 	    Apache::lonhelper::choices->new();
                   3069: 	    addMessage("</td></tr>");
1.220     sakharuk 3070: 	}
1.219     sakharuk 3071: 
1.230     albertel 3072: 	if ($helper->{'VARS'}->{'construction'}) { 
1.505     albertel 3073: 	    my $stylevalue='$Apache::lonnet::env{"construct.style"}';
1.497     www      3074:             my $randseedtext=&mt("Use random seed");
                   3075:             my $stylefiletext=&mt("Use style file");
1.506     albertel 3076:             my $selectfiletext=&mt("Select style file");
1.497     www      3077: 
1.265     sakharuk 3078: 	    my $xmlfrag .= <<"RNDSEED";
1.497     www      3079: 	    <message><tr><td align='right'>
                   3080:             <label for="curseed_forminput">$randseedtext</label>:
                   3081:             </td><td></message>
1.230     albertel 3082: 	    <string variable="curseed" size="15" maxlength="15">
                   3083: 		<defaultvalue>
                   3084: 	            return $helper->{VARS}->{'curseed'};
                   3085: 	        </defaultvalue>
1.262     sakharuk 3086: 	    </string>
1.497     www      3087: 	     <message></td></tr><tr><td align="right">
1.503     albertel 3088:              <label for="style_file">$stylefiletext</label>:
1.497     www      3089:              </td><td></message>
1.504     albertel 3090:              <string variable="style_file" size="40">
                   3091: 		<defaultvalue>
1.505     albertel 3092: 	            return $stylevalue;
1.504     albertel 3093: 	        </defaultvalue>
1.506     albertel 3094:              </string><message>&nbsp; <a href="javascript:openbrowser('helpform','style_file_forminput','sty')">$selectfiletext</a> </td></tr><tr><td></td><td align="left"></message>
1.371     foxr     3095: 	     <choices allowempty="1" multichoice="true" variable="showallfoils">
1.506     albertel 3096:                 <choice computer="1">Show all foils</choice>
1.371     foxr     3097:              </choices>
1.378     albertel 3098: 	     <message></td></tr></message>
1.230     albertel 3099: RNDSEED
                   3100:             &Apache::lonxml::xmlparse($r, 'helper', $xmlfrag);
1.512     foxr     3101: 
                   3102: 
                   3103: 	    addMessage("<tr><td>Problem Type:</td><td>");
                   3104: 	    $paramHash = &Apache::lonhelper::getParamHash();
                   3105: 	    $paramHash->{'variable'} = 'probstatus'; # Already declared:
                   3106: 	    #
                   3107: 	    # Initial value from construction space:
                   3108: 	    #
                   3109: 	    if (!$helper->{VARS}->{'probstatus'} && $env{'form.problemtype'}) {
                   3110: 		$helper->{VARS}->{'probstatus'} = $env{'form.problemtype'};	# initial value
                   3111: 	    }
                   3112: 	    $paramHash->{CHOICES} = [
                   3113: 				     ['Homework problem',     'problem'],
                   3114: 				     ['Exam Problem', 'exam'],
                   3115: 				     ['Survey question',      'survey']];
                   3116: 	    Apache::lonhelper::dropdown->new();
                   3117: 	    addMessage("</td></tr>"); 
                   3118: 
1.372     foxr     3119: 	} 
1.223     bowersj2 3120:     }
1.264     sakharuk 3121: 
                   3122: 
                   3123: 
1.218     sakharuk 3124: 
1.223     bowersj2 3125:     if ($startedTable) {
                   3126: 	addMessage("</table>");
1.215     sakharuk 3127:     }
1.161     bowersj2 3128: 
1.131     bowersj2 3129:     Apache::lonprintout::page_format_state->new("FORMAT");
                   3130: 
1.144     bowersj2 3131:     # Generate the PAGESIZE state which will offer the user the margin
                   3132:     # choices if they select one column
                   3133:     Apache::lonhelper::state->new("PAGESIZE", "Set Margins");
                   3134:     Apache::lonprintout::page_size_state->new('pagesize', 'FORMAT', 'FINAL');
                   3135: 
                   3136: 
1.131     bowersj2 3137:     $helper->process();
                   3138: 
1.416     foxr     3139: 
1.131     bowersj2 3140:     # MANUAL BAILOUT CONDITION:
                   3141:     # If we're in the "final" state, bailout and return to handler
                   3142:     if ($helper->{STATE} eq 'FINAL') {
                   3143:         return $helper;
                   3144:     }    
1.130     sakharuk 3145: 
1.131     bowersj2 3146:     $r->print($helper->display());
1.395     www      3147:     if ($helper->{STATE} eq 'START') {
                   3148: 	&recently_generated($r);
                   3149:     }
1.333     albertel 3150:     &Apache::lonhelper::unregisterHelperTags();
1.115     bowersj2 3151: 
                   3152:     return OK;
                   3153: }
                   3154: 
1.1       www      3155: 
                   3156: 1;
1.119     bowersj2 3157: 
                   3158: package Apache::lonprintout::page_format_state;
                   3159: 
                   3160: =pod
                   3161: 
1.131     bowersj2 3162: =head1 Helper element: page_format_state
                   3163: 
                   3164: See lonhelper.pm documentation for discussion of the helper framework.
1.119     bowersj2 3165: 
1.131     bowersj2 3166: Apache::lonprintout::page_format_state is an element that gives the 
                   3167: user an opportunity to select the page layout they wish to print 
                   3168: with: Number of columns, portrait/landscape, and paper size. If you 
                   3169: want to change the paper size choices, change the @paperSize array 
                   3170: contents in this package.
1.119     bowersj2 3171: 
1.131     bowersj2 3172: page_format_state is always directly invoked in lonprintout.pm, so there
                   3173: is no tag interface. You actually pass parameters to the constructor.
1.119     bowersj2 3174: 
                   3175: =over 4
                   3176: 
1.131     bowersj2 3177: =item * B<new>(varName): varName is where the print information will be stored in the format FIXME.
1.119     bowersj2 3178: 
                   3179: =back
                   3180: 
                   3181: =cut
                   3182: 
1.131     bowersj2 3183: use Apache::lonhelper;
1.119     bowersj2 3184: 
                   3185: no strict;
1.131     bowersj2 3186: @ISA = ("Apache::lonhelper::element");
1.119     bowersj2 3187: use strict;
1.266     sakharuk 3188: use Apache::lonlocal;
1.373     albertel 3189: use Apache::lonnet;
1.119     bowersj2 3190: 
                   3191: my $maxColumns = 2;
1.376     albertel 3192: # it'd be nice if these all worked
                   3193: #my @paperSize = ("letter [8 1/2x11 in]", "legal [8 1/2x14 in]", 
                   3194: #                 "tabloid (ledger) [11x17 in]", "executive [7 1/2x10 in]",
                   3195: #                 "a2 [420x594 mm]", "a3 [297x420 mm]", "a4 [210x297 mm]", 
                   3196: #                 "a5 [148x210 mm]", "a6 [105x148 mm]" );
1.326     sakharuk 3197: my @paperSize = ("letter [8 1/2x11 in]", "legal [8 1/2x14 in]", 
1.376     albertel 3198: 		 "a4 [210x297 mm]");
1.119     bowersj2 3199: 
                   3200: # Tentative format: Orientation (L = Landscape, P = portrait) | Colnum |
                   3201: #                   Paper type
                   3202: 
                   3203: sub new { 
1.131     bowersj2 3204:     my $self = Apache::lonhelper::element->new();
1.119     bowersj2 3205: 
1.135     bowersj2 3206:     shift;
                   3207: 
1.131     bowersj2 3208:     $self->{'variable'} = shift;
1.134     bowersj2 3209:     my $helper = Apache::lonhelper::getHelper();
1.135     bowersj2 3210:     $helper->declareVar($self->{'variable'});
1.131     bowersj2 3211:     bless($self);
1.119     bowersj2 3212:     return $self;
                   3213: }
                   3214: 
                   3215: sub render {
                   3216:     my $self = shift;
1.131     bowersj2 3217:     my $helper = Apache::lonhelper::getHelper();
1.119     bowersj2 3218:     my $result = '';
1.131     bowersj2 3219:     my $var = $self->{'variable'};
1.266     sakharuk 3220:     my $PageLayout=&mt('Page layout');
                   3221:     my $NumberOfColumns=&mt('Number of columns');
                   3222:     my $PaperType=&mt('Paper type');
1.506     albertel 3223:     my $landscape=&mt('Landscape');
                   3224:     my $portrait=&mt('Portrait');
1.119     bowersj2 3225:     $result .= <<STATEHTML;
                   3226: 
1.223     bowersj2 3227: <hr width="33%" />
1.119     bowersj2 3228: <table cellpadding="3">
                   3229:   <tr>
1.266     sakharuk 3230:     <td align="center"><b>$PageLayout</b></td>
                   3231:     <td align="center"><b>$NumberOfColumns</b></td>
                   3232:     <td align="center"><b>$PaperType</b></td>
1.119     bowersj2 3233:   </tr>
                   3234:   <tr>
                   3235:     <td>
1.506     albertel 3236:       <label><input type="radio" name="${var}.layout" value="L" /> $landscape </label><br />
                   3237:       <label><input type="radio" name="${var}.layout" value="P" checked='1'  /> $portrait </label>
1.119     bowersj2 3238:     </td>
1.155     sakharuk 3239:     <td align="center">
1.119     bowersj2 3240:       <select name="${var}.cols">
                   3241: STATEHTML
                   3242: 
                   3243:     my $i;
                   3244:     for ($i = 1; $i <= $maxColumns; $i++) {
1.144     bowersj2 3245:         if ($i == 2) {
1.119     bowersj2 3246:             $result .= "<option value='$i' selected>$i</option>\n";
                   3247:         } else {
                   3248:             $result .= "<option value='$i'>$i</option>\n";
                   3249:         }
                   3250:     }
                   3251: 
                   3252:     $result .= "</select></td><td>\n";
                   3253:     $result .= "<select name='${var}.paper'>\n";
                   3254: 
1.373     albertel 3255:     my %parmhash=&Apache::lonnet::coursedescription($env{'request.course.id'});
1.398     albertel 3256:     my $DefaultPaperSize=lc($parmhash{'default_paper_size'});
                   3257:     $DefaultPaperSize=~s/\s//g;
1.304     sakharuk 3258:     if ($DefaultPaperSize eq '') {$DefaultPaperSize='letter';}
1.119     bowersj2 3259:     $i = 0;
                   3260:     foreach (@paperSize) {
1.326     sakharuk 3261: 	$_=~/(\w+)/;
                   3262: 	my $papersize=$1;
1.304     sakharuk 3263:         if ($paperSize[$i]=~/$DefaultPaperSize/) {
1.326     sakharuk 3264:             $result .= "<option selected value='$papersize'>" . $paperSize[$i] . "</option>\n";
1.119     bowersj2 3265:         } else {
1.326     sakharuk 3266:             $result .= "<option value='$papersize'>" . $paperSize[$i] . "</option>\n";
1.119     bowersj2 3267:         }
                   3268:         $i++;
                   3269:     }
                   3270:     $result .= "</select></td></tr></table>";
                   3271:     return $result;
1.135     bowersj2 3272: }
                   3273: 
                   3274: sub postprocess {
                   3275:     my $self = shift;
                   3276: 
                   3277:     my $var = $self->{'variable'};
1.136     bowersj2 3278:     my $helper = Apache::lonhelper->getHelper();
1.135     bowersj2 3279:     $helper->{VARS}->{$var} = 
1.373     albertel 3280:         $env{"form.$var.layout"} . '|' . $env{"form.$var.cols"} . '|' .
                   3281:         $env{"form.$var.paper"};
1.135     bowersj2 3282:     return 1;
1.119     bowersj2 3283: }
                   3284: 
                   3285: 1;
1.144     bowersj2 3286: 
                   3287: package Apache::lonprintout::page_size_state;
                   3288: 
                   3289: =pod
                   3290: 
                   3291: =head1 Helper element: page_size_state
                   3292: 
                   3293: See lonhelper.pm documentation for discussion of the helper framework.
                   3294: 
                   3295: Apache::lonprintout::page_size_state is an element that gives the 
                   3296: user the opportunity to further refine the page settings if they
                   3297: select a single-column page.
                   3298: 
                   3299: page_size_state is always directly invoked in lonprintout.pm, so there
                   3300: is no tag interface. You actually pass parameters to the constructor.
                   3301: 
                   3302: =over 4
                   3303: 
                   3304: =item * B<new>(varName): varName is where the print information will be stored in the format FIXME.
                   3305: 
                   3306: =back
                   3307: 
                   3308: =cut
                   3309: 
                   3310: use Apache::lonhelper;
1.373     albertel 3311: use Apache::lonnet;
1.144     bowersj2 3312: no strict;
                   3313: @ISA = ("Apache::lonhelper::element");
                   3314: use strict;
                   3315: 
                   3316: 
                   3317: 
                   3318: sub new { 
                   3319:     my $self = Apache::lonhelper::element->new();
                   3320: 
                   3321:     shift; # disturbs me (probably prevents subclassing) but works (drops
                   3322:            # package descriptor)... - Jeremy
                   3323: 
                   3324:     $self->{'variable'} = shift;
                   3325:     my $helper = Apache::lonhelper::getHelper();
                   3326:     $helper->declareVar($self->{'variable'});
                   3327: 
                   3328:     # The variable name of the format element, so we can look into 
                   3329:     # $helper->{VARS} to figure out whether the columns are one or two
                   3330:     $self->{'formatvar'} = shift;
                   3331: 
1.463     foxr     3332: 
1.144     bowersj2 3333:     $self->{NEXTSTATE} = shift;
                   3334:     bless($self);
1.467     foxr     3335: 
1.144     bowersj2 3336:     return $self;
                   3337: }
                   3338: 
                   3339: sub render {
                   3340:     my $self = shift;
                   3341:     my $helper = Apache::lonhelper::getHelper();
                   3342:     my $result = '';
                   3343:     my $var = $self->{'variable'};
                   3344: 
1.467     foxr     3345: 
                   3346: 
1.144     bowersj2 3347:     if (defined $self->{ERROR_MSG}) {
1.464     albertel 3348:         $result .= '<br /><span class="LC_error">' . $self->{ERROR_MSG} . '</span><br />';
1.144     bowersj2 3349:     }
                   3350: 
1.438     foxr     3351:     my $format = $helper->{VARS}->{$self->{'formatvar'}};
1.463     foxr     3352: 
                   3353:     # Use format to get sensible defaults for the margins:
                   3354: 
                   3355: 
                   3356:     my ($laystyle, $cols, $papersize) = split(/\|/, $format);
                   3357:     ($papersize)                      = split(/ /, $papersize);
                   3358: 
                   3359: 
                   3360:     if ($laystyle eq 'L') {
                   3361: 	$laystyle = 'album';
                   3362:     } else {
                   3363: 	$laystyle = 'book';
                   3364:     }
                   3365: 
                   3366: 
1.464     albertel 3367:     my %size;
                   3368:     ($size{'width_and_units'},
                   3369:      $size{'height_and_units'},
                   3370:      $size{'margin_and_units'})=
                   3371: 	 &Apache::lonprintout::page_format($papersize, $laystyle, $cols);
1.463     foxr     3372:     
1.464     albertel 3373:     foreach my $dimension ('width','height','margin') {
                   3374: 	($size{$dimension},$size{$dimension.'_unit'}) =
                   3375: 	    split(/ +/, $size{$dimension.'_and_units'},2);
                   3376:        	
                   3377: 	foreach my $unit ('cm','in') {
                   3378: 	    $size{$dimension.'_options'} .= '<option ';
                   3379: 	    if ($size{$dimension.'_unit'} eq $unit) {
                   3380: 		$size{$dimension.'_options'} .= 'selected="selected" ';
                   3381: 	    }
                   3382: 	    $size{$dimension.'_options'} .= '>'.$unit.'</option>';
                   3383: 	}
1.438     foxr     3384:     }
                   3385: 
1.470     foxr     3386:     # Adjust margin for LaTeX margin: .. requires units == cm or in.
                   3387: 
                   3388:     if ($size{'margin_unit'} eq 'in') {
                   3389: 	$size{'margin'} += 1;
                   3390:     }  else {
                   3391: 	$size{'margin'} += 2.54;
                   3392:     }
1.506     albertel 3393:     my %text = ('format' => 'How should each column be formatted?',
                   3394: 		'width'  => 'Width:',
                   3395: 		'height' => 'Height:',
                   3396: 		'margin' => 'Left Margin:',);
                   3397:     %text = &Apache::lonlocal::texthash(%text);
                   3398: 
1.144     bowersj2 3399:     $result .= <<ELEMENTHTML;
                   3400: 
1.506     albertel 3401: <p>$text{'format'}</p>
1.144     bowersj2 3402: 
                   3403: <table cellpadding='3'>
                   3404:   <tr>
1.506     albertel 3405:     <td align='right'><b>$text{'width'}</b></td>
1.464     albertel 3406:     <td align='left'><input type='text' name='$var.width' value="$size{'width'}" size='4' /></td>
1.144     bowersj2 3407:     <td align='left'>
                   3408:       <select name='$var.widthunit'>
1.464     albertel 3409:       $size{'width_options'}
1.144     bowersj2 3410:       </select>
                   3411:     </td>
                   3412:   </tr>
                   3413:   <tr>
1.506     albertel 3414:     <td align='right'><b>$text{'height'}</b></td>
1.464     albertel 3415:     <td align='left'><input type='text' name="$var.height" value="$size{'height'}" size='4' /></td>
1.144     bowersj2 3416:     <td align='left'>
                   3417:       <select name='$var.heightunit'>
1.464     albertel 3418:       $size{'height_options'}
1.144     bowersj2 3419:       </select>
                   3420:     </td>
                   3421:   </tr>
                   3422:   <tr>
1.506     albertel 3423:     <td align='right'><b>$text{'margin'}</b></td>
1.464     albertel 3424:     <td align='left'><input type='text' name='$var.lmargin' value="$size{'margin'}" size='4' /></td>
1.144     bowersj2 3425:     <td align='left'>
1.186     bowersj2 3426:       <select name='$var.lmarginunit'>
1.464     albertel 3427:       $size{'margin_options'}
1.144     bowersj2 3428:       </select>
                   3429:     </td>
                   3430:   </tr>
                   3431: </table>
                   3432: 
1.464     albertel 3433: <!--<p>Hint: Some instructors like to leave scratch space for the student by
                   3434: making the width much smaller than the width of the page.</p>-->
1.144     bowersj2 3435: 
                   3436: ELEMENTHTML
                   3437: 
                   3438:     return $result;
                   3439: }
                   3440: 
1.470     foxr     3441: 
1.144     bowersj2 3442: sub preprocess {
                   3443:     my $self = shift;
                   3444:     my $helper = Apache::lonhelper::getHelper();
                   3445: 
                   3446:     my $format = $helper->{VARS}->{$self->{'formatvar'}};
1.467     foxr     3447: 
                   3448:     #  If the user does not have 'pav' privilege, set default widths and
                   3449:     #  on to the next state right away.
                   3450:     #
                   3451:     if (!$perm{'pav'}) {
                   3452: 	my $var = $self->{'variable'};
                   3453: 	my $format = $helper->{VARS}->{$self->{'formatvar'}};
                   3454: 	
                   3455: 	my ($laystyle, $cols, $papersize) = split(/\|/, $format);
                   3456: 	($papersize)                      = split(/ /, $papersize);
                   3457: 	
                   3458: 	
                   3459: 	if ($laystyle eq 'L') {
                   3460: 	    $laystyle = 'album';
                   3461: 	} else {
                   3462: 	    $laystyle = 'book';
                   3463: 	}
                   3464: 	#  Figure out some good defaults for the print out and set them:
                   3465: 	
                   3466: 	my %size;
                   3467: 	($size{'width'},
                   3468: 	 $size{'height'},
                   3469: 	 $size{'lmargin'})=
                   3470: 	     &Apache::lonprintout::page_format($papersize, $laystyle, $cols);
                   3471: 	
                   3472: 	foreach my $dim ('width', 'height', 'lmargin') {
                   3473: 	    my ($value, $units) = split(/ /, $size{$dim});
1.470     foxr     3474: 	    	    
1.467     foxr     3475: 	    $helper->{VARS}->{"$var.".$dim}      = $value;
                   3476: 	    $helper->{VARS}->{"$var.".$dim.'unit'} = $units;
                   3477: 	    
                   3478: 	}
                   3479: 	
                   3480: 
                   3481: 	# Transition to the next state
                   3482: 
                   3483: 	$helper->changeState($self->{NEXTSTATE});
                   3484:     }
1.144     bowersj2 3485:    
                   3486:     return 1;
                   3487: }
                   3488: 
                   3489: sub postprocess {
                   3490:     my $self = shift;
                   3491: 
                   3492:     my $var = $self->{'variable'};
                   3493:     my $helper = Apache::lonhelper->getHelper();
1.373     albertel 3494:     my $width = $helper->{VARS}->{$var .'.width'} = $env{"form.${var}.width"}; 
                   3495:     my $height = $helper->{VARS}->{$var .'.height'} = $env{"form.${var}.height"}; 
                   3496:     my $lmargin = $helper->{VARS}->{$var .'.lmargin'} = $env{"form.${var}.lmargin"}; 
                   3497:     $helper->{VARS}->{$var .'.widthunit'} = $env{"form.${var}.widthunit"}; 
                   3498:     $helper->{VARS}->{$var .'.heightunit'} = $env{"form.${var}.heightunit"}; 
                   3499:     $helper->{VARS}->{$var .'.lmarginunit'} = $env{"form.${var}.lmarginunit"}; 
1.144     bowersj2 3500: 
                   3501:     my $error = '';
                   3502: 
                   3503:     # /^-?[0-9]+(\.[0-9]*)?$/ -> optional minus, at least on digit, followed 
                   3504:     # by an optional period, followed by digits, ending the string
                   3505: 
1.464     albertel 3506:     if ($width !~  /^-?[0-9]*(\.[0-9]*)?$/) {
1.144     bowersj2 3507:         $error .= "Invalid width; please type only a number.<br />\n";
                   3508:     }
1.464     albertel 3509:     if ($height !~  /^-?[0-9]*(\.[0-9]*)?$/) {
1.144     bowersj2 3510:         $error .= "Invalid height; please type only a number.<br />\n";
                   3511:     }
1.464     albertel 3512:     if ($lmargin !~  /^-?[0-9]*(\.[0-9]*)?$/) {
1.144     bowersj2 3513:         $error .= "Invalid left margin; please type only a number.<br />\n";
1.470     foxr     3514:     } else {
                   3515: 	# Adjust for LaTeX 1.0 inch margin:
                   3516: 
                   3517: 	if ($env{"form.${var}.lmarginunit"} eq "in") {
                   3518: 	    $helper->{VARS}->{$var.'.lmargin'} = $lmargin - 1;
                   3519: 	} else {
                   3520: 	    $helper->{VARS}->{$var.'.lmargin'} = $lmargin - 2.54;
                   3521: 	}
1.144     bowersj2 3522:     }
                   3523: 
                   3524:     if (!$error) {
                   3525:         Apache::lonhelper::getHelper()->changeState($self->{NEXTSTATE});
                   3526:         return 1;
                   3527:     } else {
                   3528:         $self->{ERROR_MSG} = $error;
                   3529:         return 0;
                   3530:     }
                   3531: }
                   3532: 
                   3533: 
1.119     bowersj2 3534: 
1.1       www      3535: __END__
1.6       sakharuk 3536: 

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>