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