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