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