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