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