Annotation of loncom/interface/lonprintout.pm, revision 1.700
1.389 foxr 1: # The LearningOnline Network
1.1 www 2: # Printout
3: #
1.700 ! raeburn 4: # $Id: lonprintout.pm,v 1.699 2024/11/08 20:37:25 raeburn Exp $
1.11 albertel 5: #
6: # Copyright Michigan State University Board of Trustees
7: #
8: # This file is part of the LearningOnline Network with CAPA (LON-CAPA).
9: #
10: # LON-CAPA is free software; you can redistribute it and/or modify
11: # it under the terms of the GNU General Public License as published by
12: # the Free Software Foundation; either version 2 of the License, or
13: # (at your option) any later version.
14: #
15: # LON-CAPA is distributed in the hope that it will be useful,
16: # but WITHOUT ANY WARRANTY; without even the implied warranty of
17: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18: # GNU General Public License for more details.
19: #
20: # You should have received a copy of the GNU General Public License
21: # along with LON-CAPA; if not, write to the Free Software
22: # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23: #
24: # /home/httpd/html/adm/gpl.txt
25: # http://www.lon-capa.org/
26: #
1.3 sakharuk 27: #
1.1 www 28: package Apache::lonprintout;
29: use strict;
1.10 albertel 30: use Apache::Constants qw(:common :http);
1.2 sakharuk 31: use Apache::lonxml;
32: use Apache::lonnet;
1.54 sakharuk 33: use Apache::loncommon;
1.13 sakharuk 34: use Apache::inputtags;
1.54 sakharuk 35: use Apache::grades;
1.13 sakharuk 36: use Apache::edit;
1.5 sakharuk 37: use Apache::File();
1.68 sakharuk 38: use Apache::lonnavmaps;
1.511 foxr 39: use Apache::admannotations;
1.521 foxr 40: use Apache::lonenc;
1.531 foxr 41: use Apache::entities;
1.550 foxr 42: use Apache::londefdef;
1.612 foxr 43: # use Apache::structurelags; # for language management.
1.550 foxr 44:
45: use File::Basename;
1.531 foxr 46:
1.515 foxr 47: use HTTP::Response;
1.491 albertel 48: use LONCAPA::map();
1.255 www 49: use Apache::lonlocal;
1.429 foxr 50: use Carp;
1.439 www 51: use LONCAPA;
1.60 sakharuk 52:
1.588 foxr 53:
1.397 albertel 54: my %perm;
1.454 foxr 55: my %parmhash;
1.459 foxr 56: my $resources_printed;
1.454 foxr 57:
1.515 foxr 58: # Global variables that describe errors in ssi calls detected by ssi_with_retries.
59: #
60:
61: my $ssi_error; # True if there was an ssi error.
62: my $ssi_last_error_resource; # The resource URI that could not be fetched.
63: my $ssi_last_error; # The error text from the server. (e.g. 500 Server timed out).
64:
65: #
66: # Our ssi max retry count.
67: #
68:
69: my $ssi_retry_count = 5; # Some arbitrary value.
70:
71:
1.556 foxr 72: # Font size:
73:
74: my $font_size = 'normalsize'; # Default is normalsize...
75:
1.562 foxr 76: #---------------------------- Helper helpers. -------------------------
77:
1.699 raeburn 78: ##
1.616 foxr 79: # Filter function to determine if a resource is a printable sequence.
80: #
81: # @param $res -Resource to check.
82: #
83: # @return 1 - printable and a resource
84: # 0 - either notm a sequence or not printable.
85: #
86: sub printable_sequence {
87: my $res = shift;
88:
89: # Non-sequences are not listed:
90:
91: if (!$res->is_sequence()) {
92: return 0;
93: }
94:
95: # Person with pav or pfo can always print:
96:
97: if ($perm{'pav'} || $perm{'pfo'}) {
98: return 1;
99: }
100:
101: if ($res->is_sequence()) {
102: my $symb = $res->symb();
103: my $navmap = $res->{NAV_MAP};
104:
105: # Find the first resource in the map:
106:
107: my $iterator = $navmap->getIterator($res, undef, undef, 1, 1);
108: my $first = $iterator->next();
109:
110: while (1) {
1.617 foxr 111: if ($first == $iterator->END_ITERATOR) { last; }
1.616 foxr 112: if (ref($first) && ! $first->is_sequence()) {last; }
113: $first = $iterator->next();
114: }
115:
116:
117: # Might be an empty map:
118:
119: if (!ref($first)) {
120: return 0;
121: }
122: my $partsref = $first->parts();
123: my @parts = @$partsref;
124: my ($open, $close) = $navmap->map_printdates($first, $parts[0]);
125: return &printable($open, $close);
126: }
127: return 0;
128: }
129:
1.590 foxr 130: # BZ5209:
131: # Create the states needed to run the helper for incomplete problems from
132: # the current folder for selected students.
133: # This includes:
134: # - A resource selector limited to problems (incompleteness must be
135: # calculated on a student per student basis.
136: # - A student selector.
137: # - Tie in to the FORMAT of the print job.
138: #
139: # States:
140: # CHOOSE_INCOMPLETE_PEOPLE_SEQ - Resource selection.
141: # CHOOSE_STUDENTS_INCOMPLETE - Student selection.
142: # CHOOSE_STUDENTS_INCOMPLETE_FORMAT - Format selection
143: # Parameters:
144: # helper - the helper which already contains info about the current folder we can
145: # purloin.
1.679 raeburn 146: # map - the map for which incomplete problems are to be printed
147: # nocurrloc - True if printout called from icon/link in Tools in /adm/navmaps
1.590 foxr 148: # Return:
149: # XML that can be parsed by the helper to drive the state machine.
150: #
1.629 raeburn 151: sub create_incomplete_folder_selstud_helper {
1.679 raeburn 152: my ($helper, $map, $nocurrloc) = @_;
1.590 foxr 153:
154:
155: my $symbFilter = '$res->shown_symb()';
156: my $selFilter = '$res->is_problem()';
157:
158:
159: my $resource_chooser = &generate_resource_chooser('CHOOSE_INCOMPLETE_PEOPLE_SEQ',
160: 'Select problem(s) to print',
1.679 raeburn 161: 'multichoice="1" toponly="1" addstatus="1" closeallpages="1" modallink="1" nocurrloc="'.$nocurrloc.'"',
1.590 foxr 162: 'RESOURCES',
163: 'CHOOSE_STUDENTS_INCOMPLETE',
164: $map,
165: $selFilter,
166: '',
1.699 raeburn 167: $symbFilter,
1.590 foxr 168: '');
169:
170: my $student_chooser = &generate_student_chooser('CHOOSE_STUDENTS_INCOMPLETE',
171: 'student_sort',
172: 'STUDENTS',
173: 'CHOOSE_STUDENTS_INCOMPLETE_FORMAT');
174:
175: my $format_chooser = &generate_format_selector($helper,
176: 'Format of the print job',
1.598 raeburn 177: 'CHOOSE_STUDENTS_INCOMPLETE_FORMAT'); # end state.
1.590 foxr 178:
179: return $resource_chooser . $student_chooser . $format_chooser;
1.699 raeburn 180: }
1.590 foxr 181:
182:
183: # BZ 5209
184: # Create the states needed to run the helper for incomplete problems from
185: # the current folder for selected students.
186: # This includes:
187: # - A resource selector limited to problems. (incompleteness must be calculated
188: # on a student per student basis.
189: # - A student selector.
190: # - Tie in to format for the print job.
191: # States:
192: # INCOMPLETE_PROBLEMS_COURSE_RESOURCES - Resource selector.
193: # INCOMPLETE_PROBLEMS_COURSE_STUDENTS - Student selector.
194: # INCOMPLETE_PROBLEMS_COURSE_FORMAT - Format selection.
195: #
196: # Parameters:
197: # helper - Helper we are creating states for.
198: # Returns:
199: # Text that can be parsed by the helper.
1.699 raeburn 200: #
1.590 foxr 201:
202: sub create_incomplete_course_helper {
203: my $helper = shift;
204:
205: my $filter = '$res->is_problem() || $res->contains_problem() || $res->is_sequence() || $res->is_practice())';
206: my $symbfilter = '$res->shown_symb()';
1.699 raeburn 207:
1.590 foxr 208: my $resource_chooser = &generate_resource_chooser('INCOMPLETE_PROBLEMS_COURSE_RESOURCES',
209: 'Select problem(s) to print',
1.661 raeburn 210: 'multichoice = "1" suppressEmptySequences="0" addstatus="1" closeallpagtes="1" modallink="1"',
1.590 foxr 211: 'RESOURCES',
212: 'INCOMPLETE_PROBLEMS_COURSE_STUDENTS',
213: '',
214: $filter,
215: '',
216: $symbfilter,
217: '');
218:
219: my $people_chooser = &generate_student_chooser('INCOMPLETE_PROBLEMS_COURSE_STUDENTS',
220: 'student_sort',
221: 'STUDENTS',
222: 'INCOMPLETE_PROBLEMS_COURSE_FORMAT');
223:
224: my $format = &generate_format_selector($helper,
225: 'Format of the print job',
226: 'INCOMPLETE_PROBLEMS_COURSE_FORMAT'); # end state.
227:
228: return $resource_chooser . $people_chooser . $format;
229:
230:
231: }
232:
1.699 raeburn 233: # BZ5209
1.590 foxr 234: # Creates the states needed to run the print helper for a student
235: # that wants to print his incomplete problems from the current folder.
236: # Parameters:
237: # $helper - helper we are generating states for.
238: # $map - The map for which the student wants incomplete problems.
1.679 raeburn 239: # $nocurrloc - True if printout called from icon/link in Tools in /adm/navmaps
1.590 foxr 240: # Returns:
241: # XML that defines the helper states being created.
242: #
243: # States:
244: # CHOOSE_INCOMPLETE_SEQ - Resource selector.
245: #
246: sub create_incomplete_folder_helper {
1.679 raeburn 247: my ($helper, $map, $nocurrloc) = @_;
1.590 foxr 248:
249: my $filter = '$res->is_problem()';
250: $filter .= ' && $res->resprintable() ';
251: $filter .= ' && $res->is_incomplete() ';
252:
253: my $symfilter = '$res->shown_symb()';
254:
255: my $resource_chooser = &generate_resource_chooser('CHOOSE_INCOMPLETE_SEQ',
256: 'Select problem(s) to print',
1.679 raeburn 257: 'multichoice="1", toponly ="1", addstatus="1", closeallpages="1" modallink="1" nocurrloc="'.$nocurrloc.'"',
1.590 foxr 258: 'RESOURCES',
259: 'PAGESIZE',
260: $map,
1.699 raeburn 261: $filter, '',
1.590 foxr 262: $symfilter,
263: '');
264:
265: return $resource_chooser;
266: }
267:
268:
269: # Returns the text neded for a student chooser.
1.562 foxr 270: # that text must still be parsed by the helper xml parser.
271: # Parameters:
272: # this_state - State name of the chooser.
273: # sort_choice - variable to hold the sorting choice.
274: # variable - Name of variable to hold students.
275: # next_state - State after chooser.
276:
277:
278: sub generate_student_chooser {
1.699 raeburn 279: my ($this_state,
280: $sort_choice,
281: $variable,
1.562 foxr 282: $next_state) = @_;
283: my $result = <<CHOOSE_STUDENTS;
284: <state name="$this_state" title="Select Students and Resources">
285: <message><b>Select sorting order of printout</b> </message>
286:
287: <choices variable="$sort_choice">
288: <choice computer='0'>Sort by section then student</choice>
289: <choice computer='1'>Sort by students across sections.</choice>
290: </choices>
291:
292: <message><br /><hr /><br /> </message>
1.699 raeburn 293: <student multichoice='1'
1.562 foxr 294: variable="$variable"
295: nextstate="$next_state"
296: coursepersonnel="1" />
297: </state>
298:
299: CHOOSE_STUDENTS
300:
301: return $result;
302: }
303:
304: # Generate the text needed for a resource chooser given the top level of
305: # the sequence/page
306: #
307: # Parameters:
308: # this_state - State name of the chooser.
309: # prompt_text - Text to use to prompt user.
310: # resource_options - Resource tag options e.g.
1.661 raeburn 311: # "multichoice='1', toponly='1', addstatus='1',
1.699 raeburn 312: # modallink='1'"
1.562 foxr 313: # that control the selection and appearance of the
314: # resource selector.
315: # variable - Name of the variable to hold the choice
316: # next_state - Name of the next state the helper should transition
317: # to
318: # top_url - Top level URL within which to make the selector.
319: # If empty the top level sequence is shown.
320: # filter - How to filter the resources.
321: # value_func - <valuefunc> function.
322: # choice_func - If not empty generates a <choicefunc> with this function.
1.699 raeburn 323: # start_new_option
1.562 foxr 324: # - Fragment appended after valuefunc.
325: #
326: #
327: sub generate_resource_chooser {
328: my ($this_state,
329: $prompt_text,
330: $resource_options,
331: $variable,
332: $next_state,
333: $top_url,
334: $filter,
335: $choice_func,
336: $value_func,
337: $start_new_option) = @_;
338:
339: my $result = <<CHOOSE_RESOURCES;
340: <state name="$this_state" title="$prompt_text">
341: <resource variable="$variable" $resource_options
342: closeallpages="1">
343: <nextstate>$next_state</nextstate>
344: <filterfunc>return $filter;</filterfunc>
345: CHOOSE_RESOURCES
346: if ($choice_func ne '') {
347: $result .= "<choicefunc>return $choice_func;</choicefunc>";
348: }
349: if ($top_url ne '') {
350: $result .= "<mapurl>$top_url</mapurl>";
351: }
352: $result .= <<CHOOSE_RESOURCES;
353: <valuefunc>return $value_func;</valuefunc>
354: $start_new_option
355: </resource>
356: </state>
357: CHOOSE_RESOURCES
358: return $result;
359: }
360: #
361: # Generate the helper XML for a code choice helper dialog:
362: #
363: # Paramters:
364: # $helper - Reference to the helper.
365: # $state - Name of the state for the chooser.
366: # $next_state - Name fo the state to follow the chooser.
367: # $bubble_types - Populates the bubble sheet type dropt down.
368: # $code_selections - Provides set of code choices that have been used
369: # $saved_codes - Provides the list of saved codes.
370: #
371: # Returns;
372: # The Xml of the code chooser.
373: #
374: sub generate_code_selector {
375: my ($helper,
376: $state,
377: $next_state,
378: $bubble_types,
379: $code_selections,
380: $saved_codes) = @_; # Unpack the parameters.
381:
382: my $result = <<CHOOSE_ANON1;
383: <state name="$state" title="Specify CODEd Assignments">
384: <nextstate>$next_state</nextstate>
385: <message><h4>Fill out one of the forms below</h4></message>
386: <message><br /><hr /> <br /></message>
387: <message><h3>Generate new CODEd Assignments</h3></message>
388: <message><table><tr><td><b>Number of CODEd assignments to print:</b></td><td></message>
1.579 foxr 389: <string variable="NUMBER_TO_PRINT_TOTAL" maxlength="5" size="5" noproceed="1">
1.562 foxr 390: <validator>
391: if (((\$helper->{'VARS'}{'NUMBER_TO_PRINT_TOTAL'}+0) < 1) &&
392: !\$helper->{'VARS'}{'REUSE_OLD_CODES'} &&
393: !\$helper->{'VARS'}{'SINGLE_CODE'} &&
1.578 foxr 394: !\$helper->{'VARS'}{'CODE_SELECTED_FROM_LIST'} ) {
395:
1.562 foxr 396: return "You need to specify the number of assignments to print";
397: }
1.578 foxr 398: if (((\$helper->{'VARS'}{'NUMBER_TO_PRINT_TOTAL'}+0) >= 1) &&
399: (\$helper->{'VARS'}{'SINGLE_CODE'} ne '') ) {
400: return 'Specifying number of codes to print and a specific code is not compatible';
401: }
1.562 foxr 402: return undef;
403: </validator>
404: </string>
405: <message></td></tr><tr><td></message>
406: <message><b>Names to save the CODEs under for later:</b></message>
407: <message></td><td></message>
408: <string variable="ANON_CODE_STORAGE_NAME" maxlength="50" size="20" />
409: <message></td></tr><tr><td></message>
1.599 raeburn 410: <message><b>Bubblesheet type:</b></message>
1.562 foxr 411: <message></td><td></message>
412: <dropdown variable="CODE_OPTION" multichoice="0" allowempty="0">
413: $bubble_types
414: </dropdown>
415: <message></td></tr><tr><td colspan="2"></td></tr><tr><td></message>
416: <message></td></tr><tr><td></table></message>
417: <message><br /><hr /><h3>Print a Specific CODE </h3><br /><table></message>
418: <message><tr><td><b>Enter a CODE to print:</b></td><td></message>
419: <string variable="SINGLE_CODE" size="10">
420: <validator>
421: if(!\$helper->{'VARS'}{'NUMBER_TO_PRINT_TOTAL'} &&
422: !\$helper->{'VARS'}{'REUSE_OLD_CODES'} &&
423: !\$helper->{'VARS'}{'CODE_SELECTED_FROM_LIST'}) {
424: return &Apache::lonprintout::is_code_valid(\$helper->{'VARS'}{'SINGLE_CODE'},
425: \$helper->{'VARS'}{'CODE_OPTION'});
1.577 foxr 426: } elsif (\$helper->{'VARS'}{'SINGLE_CODE'} ne ''){
1.578 foxr 427: return 'Specifying a code name is incompatible with specifying number of codes.';
1.562 foxr 428: } else {
429: return undef; # Other forces control us.
430: }
431: </validator>
432: </string>
433: <message></td></tr><tr><td></message>
434: $code_selections
435: <message></td></tr></table></message>
436: <message><hr /><h3>Reprint a Set of Saved CODEs</h3><table><tr><td></message>
437: <message><b>Select saved CODEs:</b></message>
438: <message></td><td></message>
439: <dropdown variable="REUSE_OLD_CODES">
440: $saved_codes
441: </dropdown>
442: <message></td></tr></table></message>
443: </state>
444: CHOOSE_ANON1
445:
446: return $result;
447: }
448:
1.679 raeburn 449: sub generate_common_choosers {
450: my ($r,$helper,$map,$url,$isProblem,$symbFilter,$start_new_option) = @_;
451:
452: my $randomly_ordered_warning =
453: &get_randomly_ordered_warning($helper, $map);
454:
1.699 raeburn 455: # code for a few states used for printout launched from both
1.688 raeburn 456: # /adm/navmaps and from a resource by a privileged user:
1.679 raeburn 457: # - To allow resources to be selected for printing.
458: # - To determine pagination between assignments.
459: # - To determine how many assignments should be bundled into a single PDF.
460:
461: my $resource_selector= &generate_resource_chooser('SELECT_PROBLEMS',
462: 'Select resources to print',
463: 'multichoice="1" addstatus="1" closeallpages="1" modallink="1" suppressNavmap="1"',
464: 'RESOURCES',
465: 'PRINT_FORMATTING',
466: $map,
467: $isProblem, '', $symbFilter,
468: $start_new_option);
469: $resource_selector .= &generate_format_selector($helper,
470: 'How should results be printed?',
471: 'PRINT_FORMATTING').
472: &generate_resource_chooser('CHOOSE_STUDENTS_PAGE',
473: 'Select Problem(s) to print',
474: "multichoice='1' addstatus='1' closeallpages ='1' modallink='1'",
475: 'RESOURCES',
476: 'PRINT_FORMATTING',
477: $url,
478: $isProblem, '', $symbFilter,
479: $start_new_option);
480:
481: # Generate student choosers.
482:
483: &Apache::lonxml::xmlparse($r, 'helper',
484: &generate_student_chooser('CHOOSE_TGT_STUDENTS_PAGE',
485: 'student_sort',
486: 'STUDENTS',
487: 'CHOOSE_STUDENTS_PAGE'));
488: &Apache::lonxml::xmlparse($r, 'helper',
489: &generate_student_chooser('CHOOSE_STUDENTS',
490: 'student_sort',
491: 'STUDENTS',
492: 'SELECT_PROBLEMS'));
493: &Apache::lonxml::xmlparse($r, 'helper', $resource_selector);
494:
495: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
496: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
497: my @names=&Apache::lonnet::getkeys('CODEs',$cdom,$cnum);
498: my $namechoice='<choice></choice>';
499: foreach my $name (sort {uc($a) cmp uc($b)} @names) {
500: if ($name =~ /^error: 2 /) { next; }
501: if ($name =~ /^type\0/) { next; }
502: $namechoice.='<choice computer="'.$name.'">'.$name.'</choice>';
503: }
504:
505: my %code_values;
506: my %codes_to_print;
507: foreach my $key (@names) {
508: %code_values = &Apache::grades::get_codes($key, $cdom, $cnum);
509: foreach my $key (keys(%code_values)) {
510: $codes_to_print{$key} = 1;
511: }
512: }
513:
514: my $code_selection;
515: foreach my $code (sort {uc($a) cmp uc($b)} (keys(%codes_to_print))) {
516: my $choice = $code;
517: if ($code =~ /^[A-Z]+$/) { # Alpha code
518: $choice = &letters_to_num($code);
519: }
520: push(@{$helper->{DATA}{ALL_CODE_CHOICES}},[$code,$choice]);
521: }
522: if (%codes_to_print) {
523: $code_selection .='
524: <message><b>Choose single CODE from list:</b></message>
525: <message></td><td></message>
526: <dropdown variable="CODE_SELECTED_FROM_LIST" multichoice="0" allowempty="0">
527: <choice></choice>
528: <exec>
529: push(@{$state->{CHOICES}},@{$helper->{DATA}{ALL_CODE_CHOICES}});
530: </exec>
531: </dropdown>
532: <message></td></tr><tr><td></message>
533: '.$/;
534: }
535:
536: my @lines = &Apache::lonnet::get_scantronformat_file();
537: my $codechoice='';
538: foreach my $line (@lines) {
539: next if (($line =~ /^\#/) || ($line eq ''));
540: my ($name,$description,$code_type,$code_length)=
541: (split(/:/,$line))[0,1,2,4];
542: if ($code_length > 0 &&
543: $code_type =~/^(letter|number|-1)/) {
544: $codechoice.='<choice computer="'.$name.'">'.$description.'</choice>';
545: }
546: }
547: if ($codechoice eq '') {
548: $codechoice='<choice computer="default">Default</choice>';
549: }
550: my $anon1 = &generate_code_selector($helper,
551: 'CHOOSE_ANON1',
552: 'SELECT_PROBLEMS',
553: $codechoice,
554: $code_selection,
555: $namechoice) . $resource_selector;
556:
557: &Apache::lonxml::xmlparse($r, 'helper',$anon1);
558:
559: my $anon_page = &generate_code_selector($helper,
560: 'CHOOSE_ANON1_PAGE',
561: 'SELECT_PROBLEMS_PAGE',
562: $codechoice,
563: $code_selection,
564: $namechoice) .
565: &generate_resource_chooser('SELECT_PROBLEMS_PAGE',
566: 'Select Problem(s) to print',
567: "multichoice='1' addstatus='1' closeallpages ='1' modallink='1'",
568: 'RESOURCES',
569: 'PRINT_FORMATTING',
570: $url,
571: $isProblem, '', $symbFilter,
572: $start_new_option);
573: &Apache::lonxml::xmlparse($r, 'helper', $anon_page);
574: return ($randomly_ordered_warning,$codechoice,$code_selection,$namechoice);
575: }
576:
1.699 raeburn 577: # Returns the XML for choosing how assignments are to be formatted
1.598 raeburn 578: # that text must still be parsed by the helper xml parser.
579: # Parameters: 3 (required)
580:
581: # helper - The helper; $helper->{'VARS'}->{'PRINT_TYPE'} used
582: # to check if splitting PDFs by section can be offered.
1.699 raeburn 583: # title - Title for the current state.
1.598 raeburn 584: # this_state - State name of the chooser.
585:
1.586 raeburn 586: sub generate_format_selector {
1.598 raeburn 587: my ($helper,$title,$this_state) = @_;
1.586 raeburn 588: my $secpdfoption;
589: unless (($helper->{'VARS'}->{'PRINT_TYPE'} eq 'problems_for_anon') ||
590: ($helper->{'VARS'}->{'PRINT_TYPE'} eq 'problems_for_anon_page') ||
1.679 raeburn 591: ($helper->{'VARS'}->{'PRINT_TYPE'} eq 'resources_for_anon') ||
592: ($helper->{'VARS'}->{'PRINT_TYPE'} eq 'select_sequences_problems_for_anon') ||
593: ($helper->{'VARS'}->{'PRINT_TYPE'} eq 'select_sequences_resources_for_anon')) {
1.586 raeburn 594: $secpdfoption = '<choice computer="sections">Each PDF contains exactly one section</choice>';
595: }
596: return <<RESOURCE_SELECTOR;
1.598 raeburn 597: <state name="$this_state" title="$title">
1.586 raeburn 598: <message><br /><big><i><b>How should the results be printed?</b></i></big><br /></message>
599: <choices variable="EMPTY_PAGES">
600: <choice computer='0'>Start each student\'s assignment on a new page/column (add a pagefeed after each assignment)</choice>
601: <choice computer='1'>Add one empty page/column after each student\'s assignment</choice>
602: <choice computer='2'>Add two empty pages/column after each student\'s assignment</choice>
603: <choice computer='3'>Add three empty pages/column after each student\'s assignment</choice>
604: </choices>
605: <nextstate>PAGESIZE</nextstate>
606: <message><hr width='33%' /><b>How do you want assignments split into PDF files? </b></message>
607: <choices variable="SPLIT_PDFS">
608: <choice computer="all">All assignments in a single PDF file</choice>
609: $secpdfoption
610: <choice computer="oneper">Each PDF contains exactly one assignment</choice>
611: <choice computer="usenumber" relatedvalue="NUMBER_TO_PRINT">
612: Specify the number of assignments per PDF:</choice>
613: </choices>
614: </state>
615: RESOURCE_SELECTOR
616: }
617:
1.562 foxr 618: #-----------------------------------------------------------------------
619:
1.616 foxr 620: # Computes an open and close date from a list of open/close dates for a resource's
621: # parts.
622: #
623: # @param \@opens - reference to an array of open dates.
624: # @param \@closes - reference to an array of close dates.
625: #
1.699 raeburn 626: # @return ($open, $close)
1.616 foxr 627: #
1.638 raeburn 628: # @note If open/close dates are not defined they will be returned as undef
1.699 raeburn 629: # @note It is possible for there to be no overlap in which case -1,-1
1.616 foxr 630: # will be returned.
631: # @note The algorithm used is to take the latest open date and the earliest end date.
632: #
633: sub compute_open_window {
634: my ($opensref, $closesref) = @_;
635:
636: my @opens = @$opensref;
637: my @closes = @$closesref;
638:
639: # latest open date:
640: my $latest_open;
641:
642: foreach my $open (@opens) {
643: if (!defined($latest_open) || ($open > $latest_open)) {
644: $latest_open = $open;
645: }
646: }
647: # Earliest close:
648:
649: my $earliest_close;
650: foreach my $close (@closes) {
651: if (!defined($earliest_close) || ($close < $earliest_close)) {
652: $earliest_close = $close;
653: }
654: }
655:
656: # If no overlap...both are -1 as promised.
657:
1.638 raeburn 658: if (($earliest_close ne '') && ($latest_open ne '')
1.616 foxr 659: && ($earliest_close < $latest_open)) {
660: $latest_open = -1;
661: $earliest_close = -1;
662: }
1.699 raeburn 663:
1.616 foxr 664: return ($latest_open, $earliest_close);
1.699 raeburn 665:
1.616 foxr 666: }
667:
668: ##
669: # Determines if 'now' is within the set of printable dates.
670: #
671: # @param $open_date - Starting date/timestamp.
672: # @param $close_date - Ending date/timestamp.
673: #
674: # @return 0 - Not open.
675: # @return 1 - open.
676: #
677: sub printable {
678: my ($open_date, $close_date) = @_;
679:
680:
681: my $now = time();
682:
683: # Have to do a bit of fancy footwork around undefined open/close dates:
684:
685: if ($open_date && ($open_date > $now)) {
686: return 0;
687: }
688:
689: if ($close_date && ($close_date < $now)) {
690: return 0;
691: }
1.699 raeburn 692:
1.616 foxr 693: return 1;
694:
695: }
696:
1.615 foxr 697: ##
698: # Returns the innermost print start/print end dates for a resource.
699: # This is done by looking at the start/end dates for its parts and choosing
700: # the intersection of those dates.
1.699 raeburn 701: #
1.615 foxr 702: # @param res - lonnvamaps::resource object that represents the resource.
703: #
704: # @return (opendate, closedate)
705: #
1.638 raeburn 706: # @note If open/close dates are not defined they will be returned as undef
1.699 raeburn 707: # @note It is possible for there to be no overlap in which case -1,-1
1.615 foxr 708: # will be returned.
709: # @note The algorithm used is to take the latest open date and the earliest end date.
1.638 raeburn 710: # For consistency with &printable() in lonnavmaps.pm determination of start
711: # date for printing checks printstartdate param first, then, if not set,
712: # opendate param, then, if not set, contentopen param.
1.615 foxr 713:
714: sub get_print_dates {
715: my $res = shift;
716: my $partsref = $res->parts();
1.620 raeburn 717: my @parts;
718: if (ref($partsref) eq 'ARRAY') {
719: @parts = @{$partsref};
720: }
1.615 foxr 721: my $open_date;
722: my $close_date;
1.616 foxr 723: my @open_dates;
724: my @close_dates;
725:
1.615 foxr 726:
1.620 raeburn 727: if (@parts) {
1.615 foxr 728: foreach my $part (@parts) {
729: my $partopen = $res->parmval('printstartdate', $part);
730: my $partclose = $res->parmval('printenddate', $part);
1.638 raeburn 731: if (!$partopen) {
732: $partopen = $res->parmval('opendate',$part);
733: }
734: if (!$partopen) {
735: $partopen = $res->parmval('contentopen',$part);
736: }
737: if ($partopen) {
738: push(@open_dates, $partopen);
739: }
740: if ($partclose) {
741: push(@close_dates, $partclose);
742: }
1.616 foxr 743: push(@open_dates, $partopen);
744: push(@close_dates, $partclose);
745: }
746: }
747:
748: ($open_date, $close_date) = &compute_open_window(\@open_dates, \@close_dates);
749:
750: return ($open_date, $close_date);
751: }
752:
753: ##
754: # Get the dates for which a course says a resource can be printed. This is like
755: # get_print_dates but namvaps::course_print_dates are gotten...and not converted
756: # to times either.
757: #
1.689 raeburn 758: # @param $res - Reference to a resource hash from lonnavmaps::resource.
1.616 foxr 759: #
760: # @return (opendate, closedate)
761: #
762: sub course_print_dates {
763: my $res = shift;
764: my $partsref = $res->parts();
765: my @parts = @$partsref;
766: my $open_date;
767: my $close_date;
768: my @open_dates;
769: my @close_dates;
770: my $navmap = $res->{NAV_MAP}; # Slightly OO dirty.
771:
1.688 raeburn 772: # Don't bother looping over undefined or empty parts array;
1.616 foxr 773:
1.620 raeburn 774: if (@parts) {
1.616 foxr 775: foreach my $part (@parts) {
776: my ($partopen, $partclose) = $navmap->course_printdates($res, $part);
777: push(@open_dates, $partopen);
778: push(@close_dates, $partclose);
1.615 foxr 779: }
1.616 foxr 780: ($open_date, $close_date) = &compute_open_window(\@open_dates, \@close_dates);
1.615 foxr 781: }
1.616 foxr 782: return ($open_date, $close_date);
783: }
784: ##
785: # Same as above but for the enclosing map:
786: #
787: sub map_print_dates {
788: my $res = shift;
789: my $partsref = $res->parts();
790: my @parts = @$partsref;
791: my $open_date;
792: my $close_date;
793: my @open_dates;
794: my @close_dates;
795: my $navmap = $res->{NAV_MAP}; # slightly OO dirty.
796:
797:
1.688 raeburn 798: # Don't bother looping over undefined or empty parts array;
1.615 foxr 799:
1.620 raeburn 800: if (@parts) {
1.616 foxr 801: foreach my $part (@parts) {
802: my ($partopen, $partclose) = $navmap->map_printdates($res, $part);
803: push(@open_dates, $partopen);
804: push(@close_dates, $partclose);
805: }
806: ($open_date, $close_date) = &compute_open_window(\@open_dates, \@close_dates);
807: }
1.615 foxr 808: return ($open_date, $close_date);
809: }
810:
1.591 foxr 811: # Determine if a resource is incomplete given the map:
812: # Parameters:
813: # $username - Name of user for whom we are checking.
814: # $domain - Domain of user we are checking.
815: # $map - map name.
816: # Returns:
817: # 0 - map is not incomplete.
818: # 1 - map is incomplete.
819: #
820: sub incomplete {
821: my ($username, $domain, $map) = @_;
822:
823:
1.595 foxr 824: my $navmap = Apache::lonnavmaps::navmap->new($username, $domain);
1.699 raeburn 825:
1.591 foxr 826:
827: if (defined($navmap)) {
828: my $res = $navmap->getResourceByUrl($map);
829: my $result = $res->is_incomplete();
830: return $result;
831: } else {
832: return 1;
833: }
834: }
1.595 foxr 835: #
1.646 raeburn 836: # When printing for students, the resources and order of the
1.595 foxr 837: # resources may need to be altered if there are folders with
838: # random selectiopn or random ordering (or both) enabled.
839: # This sub computes the set of resources to print for a student
840: # modified both by random ordering and selection and filtered
1.646 raeburn 841: # to only those that are in the original set selected to be printed.
1.595 foxr 842: #
843: # Parameters:
1.626 raeburn 844: # $map - The URL of the folder being printed.
845: # Used to determine which startResource and finishResource
846: # to use when using the navmap's getIterator method.
847: # $seq - The original set of resources to print.
1.600 foxr 848: # (really an array of resource names (array of symb's).
1.595 foxr 849: # $who - Student/domain for whome the sequence will be generated.
1.626 raeburn 850: # $code - CODE being printed when printing Problems/Resources
851: # from folder for CODEd assignments
1.646 raeburn 852: # $nohidemap - If true, parameter in map for hiddenresource will be
853: # ignored. The user calling the routine should have
854: # both the pav and vgr privileges if this is set to true).
1.595 foxr 855: #
856: # Implicit inputs:
857: # $
858: # Returns:
859: # reference to an array of resources that can be passed to
860: # print_resources.
1.699 raeburn 861: #
1.595 foxr 862: sub master_seq_to_person_seq {
1.631 raeburn 863: my ($map, $seq, $who, $code, $nohidemap) = @_;
1.595 foxr 864:
865:
866: my ($username, $userdomain, $usersection) = split(/:/, $who);
867:
868: # Toss the sequence up into a hash so that we have O(1) lookup time.
869: # on the items that come out of the user's list of resources.
870: #
1.626 raeburn 871:
1.595 foxr 872: my %seq_hash = map {$_ => 1} @$seq;
873: my @output_seq;
1.631 raeburn 874:
875: my $unhidden;
1.647 raeburn 876: if ($nohidemap) {
1.631 raeburn 877: $unhidden = &Apache::lonnet::clutter($map);
878: }
1.699 raeburn 879:
1.625 raeburn 880: my $navmap = Apache::lonnavmaps::navmap->new($username, $userdomain,
1.631 raeburn 881: $code, $unhidden);
1.626 raeburn 882: my ($start,$finish);
1.595 foxr 883:
1.626 raeburn 884: if ($map) {
885: my $mapres = $navmap->getResourceByUrl($map);
886: if ($mapres->is_map()) {
887: $start = $mapres->map_start();
888: $finish = $mapres->map_finish();
889: }
890: }
891: unless ($start && $finish) {
892: $start = $navmap->firstResource();
893: $finish = $navmap->finishResource();
894: }
895:
896: my $iterator = $navmap->getIterator($start,$finish,{},1);
1.595 foxr 897:
898: # Iterate on the resource..select the items that are randomly selected
1.688 raeburn 899: # and that are in the seq_hash. Presumably the iterator will take care
1.689 raeburn 900: # of the random ordering part of the deal.
1.595 foxr 901: #
902: my $curres;
903: while ($curres = $iterator->next()) {
904: #
1.600 foxr 905: # Only process resources..that are not removed by randomout...
906: # and are selected for printint as well.
1.595 foxr 907: #
1.626 raeburn 908: if (ref($curres) && ! $curres->randomout()) {
909: my $currsymb = $curres->symb();
910: if (exists($seq_hash{$currsymb})) {
911: push(@output_seq, $currsymb);
1.595 foxr 912: }
913: }
914: }
915:
916: return \@output_seq; # for now.
1.699 raeburn 917:
1.595 foxr 918: }
919:
1.515 foxr 920:
1.498 foxr 921: # Fetch the contents of a resource, uninterpreted.
922: # This is used here to fetch a latex file to be included
923: # verbatim into the printout<
924: # NOTE: Ask Guy if there is a lonnet function similar to this?
925: #
926: # Parameters:
927: # URL of the file
928: #
929: sub fetch_raw_resource {
930: my ($url) = @_;
931:
932: my $filename = &Apache::lonnet::filelocation("", $url);
1.500 foxr 933: my $contents = &Apache::lonnet::getfile($filename);
1.498 foxr 934:
1.500 foxr 935: if ($contents == -1) {
936: return "File open failed for $filename"; # This will bomb the print.
1.498 foxr 937: }
1.500 foxr 938: return $contents;
1.498 foxr 939:
1.699 raeburn 940:
1.498 foxr 941: }
942:
1.699 raeburn 943: # Fetch the annotations associated with a URL and
1.511 foxr 944: # put a centered 'annotations:' title.
945: # This is all suppressed if the annotations are empty.
946: #
947: sub annotate {
948: my ($symb) = @_;
949:
1.559 foxr 950: my $annotation_text = &Apache::loncommon::get_annotation($symb, 1);
1.511 foxr 951:
952:
953: my $result = "";
954:
955: if (length($annotation_text) > 0) {
956: $result .= '\\hspace*{\\fill} \\\\[\\baselineskip] \textbf{Annotations:} \\\\ ';
957: $result .= "\n";
958: $result .= &Apache::lonxml::latex_special_symbols($annotation_text,""); # Escape latex.
959: $result .= "\n\n";
960: }
961: return $result;
962: }
963:
1.556 foxr 964: #
965: # Set a global document font size:
966: # This is done by replacing \begin{document}
967: # with \begin{document}{\some-font-directive
968: # and \end{document} with
969: # }\end{document
970: #
971: sub set_font_size {
972:
973: my ($text) = @_;
974:
1.575 foxr 975: # There appear to be cases where the font directive is empty.. in which
1.688 raeburn 976: # case the first substitution would insert a spurious \ oh happy day.
1.575 foxr 977: # as this has been the cause of much mystery and hair pulling _sigh_
978:
979: if ($font_size ne '') {
980:
1.649 raeburn 981: $text =~ s/\\begin\{document}/\\begin{document}{\\$font_size/;
1.669 raeburn 982: $text =~ s/\\end\{document}/}\\end{document}/;
983:
1.575 foxr 984: }
1.556 foxr 985: return $text;
986:
987:
988: }
989:
1.699 raeburn 990: # include_pdf - PDF files are included into the
1.550 foxr 991: # output as follows:
992: # - The PDF, if necessary, is replicated.
993: # - The PDF is added to the list of files to convert to postscript (along with the images).
994: # - The LaTeX is added to include the final converted postscript in the file as an included
1.688 raeburn 995: # job. The assumption is that the includepsheader.ps header will be included.
1.550 foxr 996: #
997: # Parameters:
998: # pdf_uri - URI of the PDF file to include.
1.699 raeburn 999: #
1.550 foxr 1000: # Returns:
1001: # The LaTeX to include.
1002: #
1003: # Assumptions:
1004: # The uri is actually a PDF file
1005: # The postscript will have the includepsheader.ps included.
1006: #
1007: #
1008: sub include_pdf {
1009: my ($pdf_uri) = @_;
1010:
1011: # Where is the file? If not local we'll need to repcopy it:'
1012:
1013: my $file = &Apache::lonnet::filelocation('', $pdf_uri);
1014: if (! -e $file) {
1015: &Apache::lonnet::repcopy($file);
1016: $file = &Apache::lonnet::filelocation('',$pdf_uri);
1017: }
1018:
1.688 raeburn 1019: # The file is now replicated locally ... or it did not exist in the first place
1.550 foxr 1020: # (unlikely). If it did exist, add the pdf to the set of files/images that
1.688 raeburn 1021: # need to be converted for this print job:
1.550 foxr 1022:
1.608 raeburn 1023: my $londocroot = $Apache::lonnet::perlvar{'lonDocRoot'};
1024: $file =~ s{(.*)/res/}{$londocroot/res/};
1.550 foxr 1025:
1.659 raeburn 1026: open(FILE,">>","$Apache::lonnet::perlvar{'lonPrtDir'}/$env{'user.name'}_$env{'user.domain'}_printout.dat");
1.550 foxr 1027: print FILE ("$file\n");
1028: close (FILE);
1029:
1030: # Construct the special to put out. To do this we need to get the
1031: # resulting filename after conversion. The file will have the same name
1032: # but will be in the user's spool directory with converted images.
1033:
1034: my $dirname = "/home/httpd/prtspool/$env{'user.name'}/";
1035: my ( $base, $path, $ext) = &fileparse($file, '.pdf');
1036: # my $destname = $dirname.'/'.$base.'.eps'; # Not really an eps but easier in printout.pl
1037: $base =~ s/ /\_/g;
1038:
1039:
1.551 foxr 1040: my $output = &print_latex_header();
1.550 foxr 1041: $output .= '\special{ps: _begin_job_ ('
1042: .$base.'.pdf.eps'.
1043: ')run _end_job_}';
1044:
1045: return $output;
1046:
1047:
1048: }
1.612 foxr 1049: ##
1050: # Collect the various \select_language{language_name}
1051: # latex tags to build a \usepackage[lang-list]{babel} which will
1052: # appear just prior to the \begin{document} at the front of the concatenated
1053: # set of resources:
1054: # @param doc - The string of latex to search/replace.
1055: # @return string
1056: # @retval - the modified document stringt.
1057: #
1058: sub collect_languages {
1059: my $doc = shift;
1060: my %languages;
1.649 raeburn 1061: while ($doc =~ /\\selectlanguage\{(\w+)}/mg) {
1.612 foxr 1062: $languages{$1} = 1; # allows us to request each language exactly once.
1063: }
1064: my @lang_list = (keys(%languages)); # List of unique languages
1065: if (scalar @lang_list) {
1066: my $babel_header = '\usepackage[' . join(',', @lang_list) .']{babel}'. "\n";
1.649 raeburn 1067: $doc =~ s/\\begin\{document}/$babel_header\\begin{document}/;
1.612 foxr 1068: }
1069: return $doc;
1070: }
1071: #-------------------------------------------------------------------
1.515 foxr 1072:
1073: #
1.559 foxr 1074: # ssi_with_retries- Does the server side include of a resource.
1.515 foxr 1075: # if the ssi call returns an error we'll retry it up to
1076: # the number of times requested by the caller.
1077: # If we still have a proble, no text is appended to the
1078: # output and we set some global variables.
1.699 raeburn 1079: # to indicate to the caller an SSI error occurred.
1.515 foxr 1080: # All of this is supposed to deal with the issues described
1081: # in LonCAPA BZ 5631 see:
1082: # http://bugs.lon-capa.org/show_bug.cgi?id=5631
1083: # by informing the user that this happened.
1084: #
1085: # Parameters:
1086: # resource - The resource to include. This is passed directly, without
1087: # interpretation to lonnet::ssi.
1088: # form - The form hash parameters that guide the interpretation of the resource
1.699 raeburn 1089: #
1.515 foxr 1090: # retries - Number of retries allowed before giving up completely.
1091: # Returns:
1092: # On success, returns the rendered resource identified by the resource parameter.
1093: # Side Effects:
1094: # The following global variables can be set:
1.523 raeburn 1095: # ssi_error - If an unrecoverable error occurred this becomes true.
1.515 foxr 1096: # It is up to the caller to initialize this to false
1097: # if desired.
1.523 raeburn 1098: # ssi_last_error_resource - If an unrecoverable error occurred, this is the value
1.515 foxr 1099: # of the resource that could not be rendered by the ssi
1100: # call.
1101: # ssi_last_error - The error string fetched from the ssi response
1102: # in the event of an error.
1103: #
1104: sub ssi_with_retries {
1105: my ($resource, $retries, %form) = @_;
1106:
1.559 foxr 1107: my $target = $form{'grade_target'};
1108: my $aom = $form{'answer_output_mode'};
1109:
1110:
1.515 foxr 1111:
1.516 foxr 1112: my ($content, $response) = &Apache::loncommon::ssi_with_retries($resource, $retries, %form);
1113: if (!$response->is_success) {
1.515 foxr 1114: $ssi_error = 1;
1115: $ssi_last_error_resource = $resource;
1.516 foxr 1116: $ssi_last_error = $response->code . " " . $response->message;
1.528 raeburn 1117: $content='\section*{!!! An error occurred !!!}';
1.515 foxr 1118: }
1.516 foxr 1119:
1120: return $content;
1121:
1.515 foxr 1122: }
1123:
1.524 www 1124: sub get_student_view_with_retries {
1125: my ($curresline,$retries,$username,$userdomain,$courseid,$target,$moreenv)=@_;
1126:
1127: my ($content, $response) = &Apache::loncommon::get_student_view_with_retries($curresline,$retries,$username,$userdomain,$courseid,$target,$moreenv);
1128: if (!$response->is_success) {
1129: $ssi_error = 1;
1.526 www 1130: $ssi_last_error_resource = $curresline.' for user '.$username.':'.$userdomain;
1.524 www 1131: $ssi_last_error = $response->code . " " . $response->message;
1.528 raeburn 1132: $content='\section*{!!! An error occurred !!!}';
1.524 www 1133: }
1134: return $content;
1135:
1136: }
1137:
1.486 foxr 1138: #
1139: # printf_style_subst item format_string repl
1.699 raeburn 1140: #
1.486 foxr 1141: # Does printf style substitution for a format string that
1142: # can have %[n]item in it.. wherever, %[n]item occurs,
1143: # rep is substituted in format_string. Note that
1144: # [n] is an optional integer length. If provided,
1.699 raeburn 1145: # repl is truncated to at most [n] characters prior to
1.486 foxr 1146: # substitution.
1147: #
1148: sub printf_style_subst {
1149: my ($item, $format_string, $repl) = @_;
1.490 foxr 1150: my $result = "";
1151: while ($format_string =~ /(%)(\d*)\Q$item\E/g ) {
1.488 albertel 1152: my $fmt = $1;
1153: my $size = $2;
1.486 foxr 1154: my $subst = $repl;
1155: if ($size ne "") {
1156: $subst = substr($subst, 0, $size);
1.699 raeburn 1157:
1.689 raeburn 1158: # Here's a nice edge case ... suppose the end of the
1.688 raeburn 1159: # substring is a \. In that case may have just
1.490 foxr 1160: # chopped off a TeX escape... in that case, we append
1.699 raeburn 1161: # " " for the trailing character, and let the field
1.490 foxr 1162: # spill over a bit (sigh).
1163: # We don't just chop off the last character in order to deal
1164: # with one last pathology, and that would be if substr had
1.699 raeburn 1165: # trimmed us to e.g. \\\
1.490 foxr 1166:
1167:
1168: if ($subst =~ /\\$/) {
1169: $subst .= " ";
1170: }
1.486 foxr 1171: }
1.490 foxr 1172: my $item_pos = pos($format_string);
1173: $result .= substr($format_string, 0, $item_pos - length($size) -2) . $subst;
1174: $format_string = substr($format_string, pos($format_string));
1.486 foxr 1175: }
1.490 foxr 1176:
1177: # Put the residual format string into the result:
1178:
1179: $result .= $format_string;
1180:
1181: return $result;
1.486 foxr 1182: }
1183:
1.454 foxr 1184:
1.699 raeburn 1185: # Format a header according to a format.
1186: #
1.454 foxr 1187:
1188: # Substitutions:
1189: # %a - Assignment name.
1190: # %c - Course name.
1191: # %n - Student name.
1.537 foxr 1192: # %s - The section if it is supplied.
1.454 foxr 1193: #
1194: sub format_page_header {
1.537 foxr 1195: my ($width, $format, $assignment, $course, $student, $section) = @_;
1196:
1.565 foxr 1197:
1198:
1.486 foxr 1199: $width = &recalcto_mm($width); # Get width in mm.
1.565 foxr 1200: my $chars_per_line = int($width/1.6); # Character/textline.
1201:
1.454 foxr 1202: # Default format?
1203:
1204: if ($format eq '') {
1.486 foxr 1205: # For the default format, we may need to truncate
1206: # elements.. To do this we need to get the page width.
1207: # we assume that each character is about 2mm in width.
1208: # (correct for the header text size??). We ignore
1209: # any formatting (e.g. boldfacing in this).
1.699 raeburn 1210: #
1.486 foxr 1211: # - Allow the student/course to be one line.
1212: # but only truncate the course.
1213: # - Allow the assignment to be 2 lines (wrapped).
1214: #
1.565 foxr 1215:
1.537 foxr 1216:
1217:
1218: my $name_length = int($chars_per_line *3 /4);
1219: my $sec_length = int($chars_per_line / 5);
1.486 foxr 1220:
1.537 foxr 1221: $format = "%$name_length".'n';
1.486 foxr 1222:
1.537 foxr 1223: if ($section) {
1224: $format .= ' - Sec: '."%$sec_length".'s';
1.486 foxr 1225: }
1.700 ! raeburn 1226: $format .= '\\hfill\\thepage';
1.489 foxr 1227:
1.537 foxr 1228: $format .= '\\\\%c \\\\ %a';
1.699 raeburn 1229:
1.490 foxr 1230:
1.454 foxr 1231: }
1.537 foxr 1232: # An open question is how to handle long user formatted page headers...
1233: # A possible future is to support e.g. %na so that the user can control
1234: # the truncation of the elements that can appear in the header.
1235: #
1236: $format = &printf_style_subst("a", $format, $assignment);
1237: $format = &printf_style_subst("c", $format, $course);
1238: $format = &printf_style_subst("n", $format, $student);
1239: $format = &printf_style_subst("s", $format, $section);
1.699 raeburn 1240:
1241:
1.537 foxr 1242: # If the user put %'s in the format string, they must be escaped
1243: # to \% else LaTeX will think they are comments and terminate
1244: # the line.. which is bad!!!
1.699 raeburn 1245:
1.538 onken 1246: # If the user has role author, $course and $assignment are empty so
1247: # there is '\\ \\ ' in the page header. That's cause a error in LaTeX
1248: if($format =~ /\\\\\s\\\\\s/) {
1249: #TODO find sensible caption for page header
1.633 raeburn 1250: my $testPrintout = '\\\\'.&mt('Authoring Space').' \\\\'.&mt('Test-Printout ');
1.538 onken 1251: $format =~ s/\\\\\s\\\\\s/$testPrintout/;
1252: }
1.565 foxr 1253: #
1254: # We're going to trust LaTeX to break lines appropriately, but
1255: # we'll truncate anything that's more than 3 lines worth of
1256: # text. This is also assuming (which will probably end badly)
1257: # nobody's going to embed LaTeX control sequences in the title
1258: # header or rather that those control sequences won't get broken
1259: # by the stuff below.
1260: #
1261: my $total_length = 3*$chars_per_line;
1262: if (length($format) > $total_length) {
1263: $format = substr($format, 0, $total_length);
1264: }
1265:
1.454 foxr 1266:
1267: return $format;
1.699 raeburn 1268:
1.454 foxr 1269: }
1.397 albertel 1270:
1.385 foxr 1271: #
1272: # Convert a numeric code to letters
1273: #
1274: sub num_to_letters {
1275: my ($num) = @_;
1276: my @nums= split('',$num);
1277: my @num_to_let=('A'..'Z');
1278: my $word;
1279: foreach my $digit (@nums) { $word.=$num_to_let[$digit]; }
1280: return $word;
1281: }
1282: # Convert a letter code to numeric.
1283: #
1284: sub letters_to_num {
1285: my ($letters) = @_;
1286: my @letters = split('', uc($letters));
1.490 foxr 1287: my %substitution;
1.385 foxr 1288: my $digit = 0;
1289: foreach my $letter ('A'..'J') {
1290: $substitution{$letter} = $digit;
1291: $digit++;
1292: }
1293: # The substitution is done as below to preserve leading
1294: # zeroes which are needed to keep the code size exact
1295: #
1296: my $result ="";
1297: foreach my $letter (@letters) {
1298: $result.=$substitution{$letter};
1299: }
1300: return $result;
1301: }
1302:
1.383 foxr 1303: # Determine if a code is a valid numeric code. Valid
1304: # numeric codes must be comprised entirely of digits and
1.384 albertel 1305: # have a correct number of digits.
1.383 foxr 1306: #
1307: # Parameters:
1308: # value - proposed code value.
1.384 albertel 1309: # num_digits - Number of digits required.
1.383 foxr 1310: #
1311: sub is_valid_numeric_code {
1.384 albertel 1312: my ($value, $num_digits) = @_;
1.383 foxr 1313: # Remove leading/trailing whitespace;
1.387 foxr 1314: $value =~ s/^\s*//g;
1315: $value =~ s/\s*$//g;
1.699 raeburn 1316:
1.383 foxr 1317: # All digits?
1.387 foxr 1318: if ($value !~ /^[0-9]+$/) {
1.383 foxr 1319: return "Numeric code $value has invalid characters - must only be digits";
1320: }
1.384 albertel 1321: if (length($value) != $num_digits) {
1322: return "Numeric code $value incorrect number of digits (correct = $num_digits)";
1323: }
1.385 foxr 1324: return undef;
1.383 foxr 1325: }
1326: # Determines if a code is a valid alhpa code. Alpha codes
1327: # are ciphers that map [A-J,a-j] -> 0..9 0..9.
1.384 albertel 1328: # They also have a correct digit count.
1.383 foxr 1329: # Parameters:
1330: # value - Proposed code value.
1.384 albertel 1331: # num_letters - correct number of letters.
1.383 foxr 1332: # Note:
1333: # leading and trailing whitespace are ignored.
1334: #
1335: sub is_valid_alpha_code {
1.384 albertel 1336: my ($value, $num_letters) = @_;
1.699 raeburn 1337:
1.383 foxr 1338: # strip leading and trailing spaces.
1339:
1340: $value =~ s/^\s*//g;
1341: $value =~ s/\s*$//g;
1342:
1343: # All alphas in the right range?
1.384 albertel 1344: if ($value !~ /^[A-J,a-j]+$/) {
1.383 foxr 1345: return "Invalid letter code $value must only contain A-J";
1346: }
1.384 albertel 1347: if (length($value) != $num_letters) {
1348: return "Letter code $value has incorrect number of letters (correct = $num_letters)";
1349: }
1.385 foxr 1350: return undef;
1.383 foxr 1351: }
1352:
1.382 foxr 1353: # Determine if a code entered by the user in a helper is valid.
1354: # valid depends on the code type and the type of code selected.
1.699 raeburn 1355: # The type of code selected can either be numeric or
1.382 foxr 1356: # Alphabetic. If alphabetic, the code, in fact is a simple
1357: # substitution cipher for the actual numeric code: 0->A, 1->B ...
1358: # We'll be nice and be case insensitive for alpha codes.
1359: # Parameters:
1360: # code_value - the value of the code the user typed in.
1361: # code_option - The code type selected from the set in the scantron format
1362: # table.
1363: # Returns:
1364: # undef - The code is valid.
1365: # other - An error message indicating what's wrong.
1366: #
1367: sub is_code_valid {
1368: my ($code_value, $code_option) = @_;
1.383 foxr 1369: my ($code_type, $code_length) = ('letter', 6); # defaults.
1.668 raeburn 1370: my @lines = &Apache::lonnet::get_scantronformat_file();
1.542 raeburn 1371: foreach my $line (@lines) {
1.678 raeburn 1372: next if (($line =~ /^\#/) || ($line eq ''));
1.383 foxr 1373: my ($name, $type, $length) = (split(/:/, $line))[0,2,4];
1374: if($name eq $code_option) {
1375: $code_length = $length;
1376: if($type eq 'number') {
1377: $code_type = 'number';
1378: }
1379: }
1380: }
1381: my $valid;
1382: if ($code_type eq 'number') {
1.385 foxr 1383: return &is_valid_numeric_code($code_value, $code_length);
1.383 foxr 1384: } else {
1.385 foxr 1385: return &is_valid_alpha_code($code_value, $code_length);
1.383 foxr 1386: }
1.382 foxr 1387:
1388: }
1.618 foxr 1389: #
1390: # Compare two students by section (Used to sort by section).
1391: #
1.699 raeburn 1392: # Implicit inputs,
1.618 foxr 1393: # $a - The first one
1394: # $b - The second one.
1395: #
1396: # Returns:
1397: # a-section cmp b-section
1398: #
1399: sub compare_sections {
1400: my ($u1, $d1, $s1, $n1, $stat1) = split(/:/, $a);
1401: my ($u2, $d2, $s2, $n2, $stat2) = split(/:/, $b);
1402:
1403: return $s1 cmp $s2;
1404: }
1.382 foxr 1405:
1.341 foxr 1406: # Compare two students by name. The students are in the form
1407: # returned by the helper:
1408: # user:domain:section:last, first:status
1409: # This is a helper function for the perl sort built-in therefore:
1410: # Implicit Inputs:
1411: # $a - The first element to compare (global)
1412: # $b - The second element to compare (global)
1413: # Returns:
1414: # -1 - $a < $b
1415: # 0 - $a == $b
1416: # +1 - $a > $b
1417: # Note that the initial comparison is done on the last names with the
1418: # first names only used to break the tie.
1419: #
1420: #
1421: sub compare_names {
1422: # First split the names up into the primary fields.
1423:
1424: my ($u1, $d1, $s1, $n1, $stat1) = split(/:/, $a);
1425: my ($u2, $d2, $s2, $n2, $stat2) = split(/:/, $b);
1426:
1427: # Now split the last name and first name of each n:
1428: #
1429:
1430: my ($l1,$f1) = split(/,/, $n1);
1431: my ($l2,$f2) = split(/,/, $n2);
1432:
1433: # We don't bother to remove the leading/trailing whitespace from the
1434: # firstname, unless the last names compare identical.
1435:
1436: if($l1 lt $l2) {
1437: return -1;
1438: }
1439: if($l1 gt $l2) {
1440: return 1;
1441: }
1442:
1443: # Break the tie on the first name, but there are leading (possibly trailing
1.688 raeburn 1444: # whitespaces to get rid of first)
1.341 foxr 1445: #
1446: $f1 =~ s/^\s+//; # Remove leading...
1447: $f1 =~ s/\s+$//; # Trailing spaces from first 1...
1.699 raeburn 1448:
1.341 foxr 1449: $f2 =~ s/^\s+//;
1450: $f2 =~ s/\s+$//; # And the same for first 2...
1451:
1452: if($f1 lt $f2) {
1453: return -1;
1454: }
1455: if($f1 gt $f2) {
1456: return 1;
1457: }
1.699 raeburn 1458:
1.341 foxr 1459: # Must be the same name.
1460:
1461: return 0;
1462: }
1463:
1.71 sakharuk 1464: sub latex_header_footer_remove {
1465: my $text = shift;
1.649 raeburn 1466: $text =~ s/\\end\{document}//;
1467: $text =~ s/\\documentclass([^&]*)\\begin\{document}//;
1.71 sakharuk 1468: return $text;
1469: }
1.423 foxr 1470: #
1.699 raeburn 1471: # If necessary, encapsulate text inside
1.423 foxr 1472: # a minipage env.
1473: # necessity is determined by the problem_split param.
1474: #
1475: sub encapsulate_minipage {
1.676 raeburn 1476: my ($text,$problem_split) = @_;
1477: if (!($problem_split =~ /yes/i)) {
1.423 foxr 1478: $text = '\begin{minipage}{\textwidth}'.$text.'\end{minipage}';
1479: }
1480: return $text;
1481: }
1.429 foxr 1482: #
1483: # The NUMBER_TO_PRINT and SPLIT_PDFS
1484: # variables interact, this sub looks at these two parameters
1485: # and comes up with a final value for NUMBER_TO_PRINT which can be:
1486: # all - if SPLIT_PDFS eq 'all'.
1487: # 1 - if SPLIT_PDFS eq 'oneper'
1488: # section - if SPLIT_PDFS eq 'sections'
1489: # <unchanged> - if SPLIT_PDFS eq 'usenumber'
1490: #
1491: sub adjust_number_to_print {
1492: my $helper = shift;
1.71 sakharuk 1493:
1.429 foxr 1494: my $split_pdf = $helper->{'VARS'}->{'SPLIT_PDFS'};
1.699 raeburn 1495:
1.429 foxr 1496: if ($split_pdf eq 'all') {
1497: $helper->{'VARS'}->{'NUMBER_TO_PRINT'} = 'all';
1498: } elsif ($split_pdf eq 'oneper') {
1499: $helper->{'VARS'}->{'NUMBER_TO_PRINT'} = 1;
1500: } elsif ($split_pdf eq 'sections') {
1501: $helper->{'VARS'}->{'NUMBER_TO_PRINT'} = 'section';
1502: } elsif ($split_pdf eq 'usenumber') {
1503: # Unmodified.
1504: } else {
1505: # Error!!!!
1.536 foxr 1506:
1507: croak "bad SPLIT_PDFS: $split_pdf in lonprintout::adjust_number_to_print";
1.429 foxr 1508:
1509: }
1510: }
1.71 sakharuk 1511:
1.531 foxr 1512:
1.37 sakharuk 1513: sub character_chart {
1.531 foxr 1514: my $result = shift;
1515: return &Apache::entities::replace_entities($result);
1516: }
1517:
1518: sub old_character_chart {
1.37 sakharuk 1519: my $result = shift;
1.116 sakharuk 1520: $result =~ s/&\#0?0?(7|9);//g;
1521: $result =~ s/&\#0?(10|13);//g;
1522: $result =~ s/&\#0?32;/ /g;
1523: $result =~ s/&\#0?33;/!/g;
1524: $result =~ s/&(\#0?34|quot);/\"/g;
1525: $result =~ s/&\#0?35;/\\\#/g;
1526: $result =~ s/&\#0?36;/\\\$/g;
1.699 raeburn 1527: $result =~ s/&\#0?37;/\\%/g;
1528: $result =~ s/&(\#0?38|amp);/\\&/g;
1.116 sakharuk 1529: $result =~ s/&\#(0?39|146);/\'/g;
1530: $result =~ s/&\#0?40;/(/g;
1531: $result =~ s/&\#0?41;/)/g;
1532: $result =~ s/&\#0?42;/\*/g;
1533: $result =~ s/&\#0?43;/\+/g;
1534: $result =~ s/&\#(0?44|130);/,/g;
1535: $result =~ s/&\#0?45;/-/g;
1536: $result =~ s/&\#0?46;/\./g;
1537: $result =~ s/&\#0?47;/\//g;
1538: $result =~ s/&\#0?48;/0/g;
1539: $result =~ s/&\#0?49;/1/g;
1540: $result =~ s/&\#0?50;/2/g;
1541: $result =~ s/&\#0?51;/3/g;
1542: $result =~ s/&\#0?52;/4/g;
1543: $result =~ s/&\#0?53;/5/g;
1544: $result =~ s/&\#0?54;/6/g;
1545: $result =~ s/&\#0?55;/7/g;
1546: $result =~ s/&\#0?56;/8/g;
1547: $result =~ s/&\#0?57;/9/g;
1.269 albertel 1548: $result =~ s/&\#0?58;/:/g;
1.116 sakharuk 1549: $result =~ s/&\#0?59;/;/g;
1550: $result =~ s/&(\#0?60|lt|\#139);/\$<\$/g;
1.281 sakharuk 1551: $result =~ s/&\#0?61;/\\ensuremath\{=\}/g;
1552: $result =~ s/&(\#0?62|gt|\#155);/\\ensuremath\{>\}/g;
1.116 sakharuk 1553: $result =~ s/&\#0?63;/\?/g;
1554: $result =~ s/&\#0?65;/A/g;
1555: $result =~ s/&\#0?66;/B/g;
1556: $result =~ s/&\#0?67;/C/g;
1557: $result =~ s/&\#0?68;/D/g;
1558: $result =~ s/&\#0?69;/E/g;
1559: $result =~ s/&\#0?70;/F/g;
1560: $result =~ s/&\#0?71;/G/g;
1561: $result =~ s/&\#0?72;/H/g;
1562: $result =~ s/&\#0?73;/I/g;
1563: $result =~ s/&\#0?74;/J/g;
1564: $result =~ s/&\#0?75;/K/g;
1565: $result =~ s/&\#0?76;/L/g;
1566: $result =~ s/&\#0?77;/M/g;
1567: $result =~ s/&\#0?78;/N/g;
1568: $result =~ s/&\#0?79;/O/g;
1569: $result =~ s/&\#0?80;/P/g;
1570: $result =~ s/&\#0?81;/Q/g;
1571: $result =~ s/&\#0?82;/R/g;
1572: $result =~ s/&\#0?83;/S/g;
1573: $result =~ s/&\#0?84;/T/g;
1574: $result =~ s/&\#0?85;/U/g;
1575: $result =~ s/&\#0?86;/V/g;
1576: $result =~ s/&\#0?87;/W/g;
1577: $result =~ s/&\#0?88;/X/g;
1578: $result =~ s/&\#0?89;/Y/g;
1579: $result =~ s/&\#0?90;/Z/g;
1580: $result =~ s/&\#0?91;/[/g;
1.281 sakharuk 1581: $result =~ s/&\#0?92;/\\ensuremath\{\\setminus\}/g;
1.116 sakharuk 1582: $result =~ s/&\#0?93;/]/g;
1.281 sakharuk 1583: $result =~ s/&\#(0?94|136);/\\ensuremath\{\\wedge\}/g;
1.116 sakharuk 1584: $result =~ s/&\#(0?95|138|154);/\\underline{\\makebox[2mm]{\\strut}}/g;
1585: $result =~ s/&\#(0?96|145);/\`/g;
1586: $result =~ s/&\#0?97;/a/g;
1587: $result =~ s/&\#0?98;/b/g;
1588: $result =~ s/&\#0?99;/c/g;
1589: $result =~ s/&\#100;/d/g;
1590: $result =~ s/&\#101;/e/g;
1591: $result =~ s/&\#102;/f/g;
1592: $result =~ s/&\#103;/g/g;
1593: $result =~ s/&\#104;/h/g;
1594: $result =~ s/&\#105;/i/g;
1595: $result =~ s/&\#106;/j/g;
1596: $result =~ s/&\#107;/k/g;
1597: $result =~ s/&\#108;/l/g;
1598: $result =~ s/&\#109;/m/g;
1599: $result =~ s/&\#110;/n/g;
1600: $result =~ s/&\#111;/o/g;
1601: $result =~ s/&\#112;/p/g;
1602: $result =~ s/&\#113;/q/g;
1603: $result =~ s/&\#114;/r/g;
1604: $result =~ s/&\#115;/s/g;
1605: $result =~ s/&\#116;/t/g;
1606: $result =~ s/&\#117;/u/g;
1607: $result =~ s/&\#118;/v/g;
1608: $result =~ s/&\#119;/w/g;
1609: $result =~ s/&\#120;/x/g;
1610: $result =~ s/&\#121;/y/g;
1611: $result =~ s/&\#122;/z/g;
1612: $result =~ s/&\#123;/\\{/g;
1613: $result =~ s/&\#124;/\|/g;
1614: $result =~ s/&\#125;/\\}/g;
1615: $result =~ s/&\#126;/\~/g;
1616: $result =~ s/&\#131;/\\textflorin /g;
1617: $result =~ s/&\#132;/\"/g;
1.281 sakharuk 1618: $result =~ s/&\#133;/\\ensuremath\{\\ldots\}/g;
1619: $result =~ s/&\#134;/\\ensuremath\{\\dagger\}/g;
1620: $result =~ s/&\#135;/\\ensuremath\{\\ddagger\}/g;
1.116 sakharuk 1621: $result =~ s/&\#137;/\\textperthousand /g;
1622: $result =~ s/&\#140;/{\\OE}/g;
1623: $result =~ s/&\#147;/\`\`/g;
1624: $result =~ s/&\#148;/\'\'/g;
1.281 sakharuk 1625: $result =~ s/&\#149;/\\ensuremath\{\\bullet\}/g;
1.494 albertel 1626: $result =~ s/&(\#150|\#8211);/--/g;
1.116 sakharuk 1627: $result =~ s/&\#151;/---/g;
1.281 sakharuk 1628: $result =~ s/&\#152;/\\ensuremath\{\\sim\}/g;
1.116 sakharuk 1629: $result =~ s/&\#153;/\\texttrademark /g;
1630: $result =~ s/&\#156;/\\oe/g;
1631: $result =~ s/&\#159;/\\\"Y/g;
1.283 albertel 1632: $result =~ s/&(\#160|nbsp);/~/g;
1.116 sakharuk 1633: $result =~ s/&(\#161|iexcl);/!\`/g;
1634: $result =~ s/&(\#162|cent);/\\textcent /g;
1.699 raeburn 1635: $result =~ s/&(\#163|pound);/\\pounds /g;
1.116 sakharuk 1636: $result =~ s/&(\#164|curren);/\\textcurrency /g;
1637: $result =~ s/&(\#165|yen);/\\textyen /g;
1638: $result =~ s/&(\#166|brvbar);/\\textbrokenbar /g;
1639: $result =~ s/&(\#167|sect);/\\textsection /g;
1.530 foxr 1640: $result =~ s/&(\#168|uml);/\\"\{\} /g;
1.116 sakharuk 1641: $result =~ s/&(\#169|copy);/\\copyright /g;
1642: $result =~ s/&(\#170|ordf);/\\textordfeminine /g;
1.281 sakharuk 1643: $result =~ s/&(\#172|not);/\\ensuremath\{\\neg\}/g;
1.116 sakharuk 1644: $result =~ s/&(\#173|shy);/ - /g;
1645: $result =~ s/&(\#174|reg);/\\textregistered /g;
1.281 sakharuk 1646: $result =~ s/&(\#175|macr);/\\ensuremath\{^{-}\}/g;
1647: $result =~ s/&(\#176|deg);/\\ensuremath\{^{\\circ}\}/g;
1648: $result =~ s/&(\#177|plusmn);/\\ensuremath\{\\pm\}/g;
1649: $result =~ s/&(\#178|sup2);/\\ensuremath\{^2\}/g;
1650: $result =~ s/&(\#179|sup3);/\\ensuremath\{^3\}/g;
1.530 foxr 1651: $result =~ s/&(\#180|acute);/\\'\{\} /g;
1.281 sakharuk 1652: $result =~ s/&(\#181|micro);/\\ensuremath\{\\mu\}/g;
1.116 sakharuk 1653: $result =~ s/&(\#182|para);/\\P/g;
1.281 sakharuk 1654: $result =~ s/&(\#183|middot);/\\ensuremath\{\\cdot\}/g;
1.116 sakharuk 1655: $result =~ s/&(\#184|cedil);/\\c{\\strut}/g;
1.281 sakharuk 1656: $result =~ s/&(\#185|sup1);/\\ensuremath\{^1\}/g;
1.116 sakharuk 1657: $result =~ s/&(\#186|ordm);/\\textordmasculine /g;
1658: $result =~ s/&(\#188|frac14);/\\textonequarter /g;
1659: $result =~ s/&(\#189|frac12);/\\textonehalf /g;
1660: $result =~ s/&(\#190|frac34);/\\textthreequarters /g;
1.699 raeburn 1661: $result =~ s/&(\#191|iquest);/?\`/g;
1662: $result =~ s/&(\#192|Agrave);/\\\`{A}/g;
1663: $result =~ s/&(\#193|Aacute);/\\\'{A}/g;
1.116 sakharuk 1664: $result =~ s/&(\#194|Acirc);/\\^{A}/g;
1665: $result =~ s/&(\#195|Atilde);/\\~{A}/g;
1.699 raeburn 1666: $result =~ s/&(\#196|Auml);/\\\"{A}/g;
1.116 sakharuk 1667: $result =~ s/&(\#197|Aring);/{\\AA}/g;
1668: $result =~ s/&(\#198|AElig);/{\\AE}/g;
1669: $result =~ s/&(\#199|Ccedil);/\\c{c}/g;
1.699 raeburn 1670: $result =~ s/&(\#200|Egrave);/\\\`{E}/g;
1671: $result =~ s/&(\#201|Eacute);/\\\'{E}/g;
1.116 sakharuk 1672: $result =~ s/&(\#202|Ecirc);/\\^{E}/g;
1673: $result =~ s/&(\#203|Euml);/\\\"{E}/g;
1674: $result =~ s/&(\#204|Igrave);/\\\`{I}/g;
1.699 raeburn 1675: $result =~ s/&(\#205|Iacute);/\\\'{I}/g;
1.116 sakharuk 1676: $result =~ s/&(\#206|Icirc);/\\^{I}/g;
1.699 raeburn 1677: $result =~ s/&(\#207|Iuml);/\\\"{I}/g;
1.116 sakharuk 1678: $result =~ s/&(\#209|Ntilde);/\\~{N}/g;
1679: $result =~ s/&(\#210|Ograve);/\\\`{O}/g;
1680: $result =~ s/&(\#211|Oacute);/\\\'{O}/g;
1681: $result =~ s/&(\#212|Ocirc);/\\^{O}/g;
1682: $result =~ s/&(\#213|Otilde);/\\~{O}/g;
1.699 raeburn 1683: $result =~ s/&(\#214|Ouml);/\\\"{O}/g;
1.281 sakharuk 1684: $result =~ s/&(\#215|times);/\\ensuremath\{\\times\}/g;
1.116 sakharuk 1685: $result =~ s/&(\#216|Oslash);/{\\O}/g;
1.699 raeburn 1686: $result =~ s/&(\#217|Ugrave);/\\\`{U}/g;
1.116 sakharuk 1687: $result =~ s/&(\#218|Uacute);/\\\'{U}/g;
1688: $result =~ s/&(\#219|Ucirc);/\\^{U}/g;
1689: $result =~ s/&(\#220|Uuml);/\\\"{U}/g;
1690: $result =~ s/&(\#221|Yacute);/\\\'{Y}/g;
1.329 sakharuk 1691: $result =~ s/&(\#223|szlig);/{\\ss}/g;
1.116 sakharuk 1692: $result =~ s/&(\#224|agrave);/\\\`{a}/g;
1693: $result =~ s/&(\#225|aacute);/\\\'{a}/g;
1694: $result =~ s/&(\#226|acirc);/\\^{a}/g;
1695: $result =~ s/&(\#227|atilde);/\\~{a}/g;
1696: $result =~ s/&(\#228|auml);/\\\"{a}/g;
1697: $result =~ s/&(\#229|aring);/{\\aa}/g;
1698: $result =~ s/&(\#230|aelig);/{\\ae}/g;
1699: $result =~ s/&(\#231|ccedil);/\\c{c}/g;
1700: $result =~ s/&(\#232|egrave);/\\\`{e}/g;
1701: $result =~ s/&(\#233|eacute);/\\\'{e}/g;
1702: $result =~ s/&(\#234|ecirc);/\\^{e}/g;
1703: $result =~ s/&(\#235|euml);/\\\"{e}/g;
1704: $result =~ s/&(\#236|igrave);/\\\`{i}/g;
1705: $result =~ s/&(\#237|iacute);/\\\'{i}/g;
1706: $result =~ s/&(\#238|icirc);/\\^{i}/g;
1707: $result =~ s/&(\#239|iuml);/\\\"{i}/g;
1.281 sakharuk 1708: $result =~ s/&(\#240|eth);/\\ensuremath\{\\partial\}/g;
1.116 sakharuk 1709: $result =~ s/&(\#241|ntilde);/\\~{n}/g;
1710: $result =~ s/&(\#242|ograve);/\\\`{o}/g;
1711: $result =~ s/&(\#243|oacute);/\\\'{o}/g;
1712: $result =~ s/&(\#244|ocirc);/\\^{o}/g;
1713: $result =~ s/&(\#245|otilde);/\\~{o}/g;
1714: $result =~ s/&(\#246|ouml);/\\\"{o}/g;
1.281 sakharuk 1715: $result =~ s/&(\#247|divide);/\\ensuremath\{\\div\}/g;
1.116 sakharuk 1716: $result =~ s/&(\#248|oslash);/{\\o}/g;
1.699 raeburn 1717: $result =~ s/&(\#249|ugrave);/\\\`{u}/g;
1.116 sakharuk 1718: $result =~ s/&(\#250|uacute);/\\\'{u}/g;
1719: $result =~ s/&(\#251|ucirc);/\\^{u}/g;
1720: $result =~ s/&(\#252|uuml);/\\\"{u}/g;
1721: $result =~ s/&(\#253|yacute);/\\\'{y}/g;
1722: $result =~ s/&(\#255|yuml);/\\\"{y}/g;
1.399 albertel 1723: $result =~ s/&\#295;/\\ensuremath\{\\hbar\}/g;
1.281 sakharuk 1724: $result =~ s/&\#952;/\\ensuremath\{\\theta\}/g;
1.117 sakharuk 1725: #Greek Alphabet
1.281 sakharuk 1726: $result =~ s/&(alpha|\#945);/\\ensuremath\{\\alpha\}/g;
1727: $result =~ s/&(beta|\#946);/\\ensuremath\{\\beta\}/g;
1728: $result =~ s/&(gamma|\#947);/\\ensuremath\{\\gamma\}/g;
1729: $result =~ s/&(delta|\#948);/\\ensuremath\{\\delta\}/g;
1730: $result =~ s/&(epsilon|\#949);/\\ensuremath\{\\epsilon\}/g;
1731: $result =~ s/&(zeta|\#950);/\\ensuremath\{\\zeta\}/g;
1732: $result =~ s/&(eta|\#951);/\\ensuremath\{\\eta\}/g;
1733: $result =~ s/&(theta|\#952);/\\ensuremath\{\\theta\}/g;
1734: $result =~ s/&(iota|\#953);/\\ensuremath\{\\iota\}/g;
1735: $result =~ s/&(kappa|\#954);/\\ensuremath\{\\kappa\}/g;
1736: $result =~ s/&(lambda|\#955);/\\ensuremath\{\\lambda\}/g;
1737: $result =~ s/&(mu|\#956);/\\ensuremath\{\\mu\}/g;
1738: $result =~ s/&(nu|\#957);/\\ensuremath\{\\nu\}/g;
1739: $result =~ s/&(xi|\#958);/\\ensuremath\{\\xi\}/g;
1.199 sakharuk 1740: $result =~ s/&(omicron|\#959);/o/g;
1.281 sakharuk 1741: $result =~ s/&(pi|\#960);/\\ensuremath\{\\pi\}/g;
1742: $result =~ s/&(rho|\#961);/\\ensuremath\{\\rho\}/g;
1743: $result =~ s/&(sigma|\#963);/\\ensuremath\{\\sigma\}/g;
1744: $result =~ s/&(tau|\#964);/\\ensuremath\{\\tau\}/g;
1745: $result =~ s/&(upsilon|\#965);/\\ensuremath\{\\upsilon\}/g;
1746: $result =~ s/&(phi|\#966);/\\ensuremath\{\\phi\}/g;
1747: $result =~ s/&(chi|\#967);/\\ensuremath\{\\chi\}/g;
1748: $result =~ s/&(psi|\#968);/\\ensuremath\{\\psi\}/g;
1749: $result =~ s/&(omega|\#969);/\\ensuremath\{\\omega\}/g;
1750: $result =~ s/&(thetasym|\#977);/\\ensuremath\{\\vartheta\}/g;
1751: $result =~ s/&(piv|\#982);/\\ensuremath\{\\varpi\}/g;
1.199 sakharuk 1752: $result =~ s/&(Alpha|\#913);/A/g;
1753: $result =~ s/&(Beta|\#914);/B/g;
1.281 sakharuk 1754: $result =~ s/&(Gamma|\#915);/\\ensuremath\{\\Gamma\}/g;
1755: $result =~ s/&(Delta|\#916);/\\ensuremath\{\\Delta\}/g;
1.199 sakharuk 1756: $result =~ s/&(Epsilon|\#917);/E/g;
1757: $result =~ s/&(Zeta|\#918);/Z/g;
1758: $result =~ s/&(Eta|\#919);/H/g;
1.281 sakharuk 1759: $result =~ s/&(Theta|\#920);/\\ensuremath\{\\Theta\}/g;
1.199 sakharuk 1760: $result =~ s/&(Iota|\#921);/I/g;
1761: $result =~ s/&(Kappa|\#922);/K/g;
1.281 sakharuk 1762: $result =~ s/&(Lambda|\#923);/\\ensuremath\{\\Lambda\}/g;
1.199 sakharuk 1763: $result =~ s/&(Mu|\#924);/M/g;
1764: $result =~ s/&(Nu|\#925);/N/g;
1.281 sakharuk 1765: $result =~ s/&(Xi|\#926);/\\ensuremath\{\\Xi\}/g;
1.199 sakharuk 1766: $result =~ s/&(Omicron|\#927);/O/g;
1.281 sakharuk 1767: $result =~ s/&(Pi|\#928);/\\ensuremath\{\\Pi\}/g;
1.199 sakharuk 1768: $result =~ s/&(Rho|\#929);/P/g;
1.281 sakharuk 1769: $result =~ s/&(Sigma|\#931);/\\ensuremath\{\\Sigma\}/g;
1.199 sakharuk 1770: $result =~ s/&(Tau|\#932);/T/g;
1.281 sakharuk 1771: $result =~ s/&(Upsilon|\#933);/\\ensuremath\{\\Upsilon\}/g;
1772: $result =~ s/&(Phi|\#934);/\\ensuremath\{\\Phi\}/g;
1.199 sakharuk 1773: $result =~ s/&(Chi|\#935);/X/g;
1.281 sakharuk 1774: $result =~ s/&(Psi|\#936);/\\ensuremath\{\\Psi\}/g;
1775: $result =~ s/&(Omega|\#937);/\\ensuremath\{\\Omega\}/g;
1.199 sakharuk 1776: #Arrows (extended HTML 4.01)
1.281 sakharuk 1777: $result =~ s/&(larr|\#8592);/\\ensuremath\{\\leftarrow\}/g;
1778: $result =~ s/&(uarr|\#8593);/\\ensuremath\{\\uparrow\}/g;
1779: $result =~ s/&(rarr|\#8594);/\\ensuremath\{\\rightarrow\}/g;
1780: $result =~ s/&(darr|\#8595);/\\ensuremath\{\\downarrow\}/g;
1781: $result =~ s/&(harr|\#8596);/\\ensuremath\{\\leftrightarrow\}/g;
1782: $result =~ s/&(lArr|\#8656);/\\ensuremath\{\\Leftarrow\}/g;
1783: $result =~ s/&(uArr|\#8657);/\\ensuremath\{\\Uparrow\}/g;
1784: $result =~ s/&(rArr|\#8658);/\\ensuremath\{\\Rightarrow\}/g;
1785: $result =~ s/&(dArr|\#8659);/\\ensuremath\{\\Downarrow\}/g;
1786: $result =~ s/&(hArr|\#8660);/\\ensuremath\{\\Leftrightarrow\}/g;
1.199 sakharuk 1787: #Mathematical Operators (extended HTML 4.01)
1.281 sakharuk 1788: $result =~ s/&(forall|\#8704);/\\ensuremath\{\\forall\}/g;
1789: $result =~ s/&(part|\#8706);/\\ensuremath\{\\partial\}/g;
1790: $result =~ s/&(exist|\#8707);/\\ensuremath\{\\exists\}/g;
1791: $result =~ s/&(empty|\#8709);/\\ensuremath\{\\emptyset\}/g;
1792: $result =~ s/&(nabla|\#8711);/\\ensuremath\{\\nabla\}/g;
1793: $result =~ s/&(isin|\#8712);/\\ensuremath\{\\in\}/g;
1794: $result =~ s/&(notin|\#8713);/\\ensuremath\{\\notin\}/g;
1795: $result =~ s/&(ni|\#8715);/\\ensuremath\{\\ni\}/g;
1796: $result =~ s/&(prod|\#8719);/\\ensuremath\{\\prod\}/g;
1797: $result =~ s/&(sum|\#8721);/\\ensuremath\{\\sum\}/g;
1798: $result =~ s/&(minus|\#8722);/\\ensuremath\{-\}/g;
1.390 albertel 1799: $result =~ s/–/\\ensuremath\{-\}/g;
1.281 sakharuk 1800: $result =~ s/&(lowast|\#8727);/\\ensuremath\{*\}/g;
1801: $result =~ s/&(radic|\#8730);/\\ensuremath\{\\surd\}/g;
1802: $result =~ s/&(prop|\#8733);/\\ensuremath\{\\propto\}/g;
1803: $result =~ s/&(infin|\#8734);/\\ensuremath\{\\infty\}/g;
1804: $result =~ s/&(ang|\#8736);/\\ensuremath\{\\angle\}/g;
1805: $result =~ s/&(and|\#8743);/\\ensuremath\{\\wedge\}/g;
1806: $result =~ s/&(or|\#8744);/\\ensuremath\{\\vee\}/g;
1807: $result =~ s/&(cap|\#8745);/\\ensuremath\{\\cap\}/g;
1808: $result =~ s/&(cup|\#8746);/\\ensuremath\{\\cup\}/g;
1809: $result =~ s/&(int|\#8747);/\\ensuremath\{\\int\}/g;
1810: $result =~ s/&(sim|\#8764);/\\ensuremath\{\\sim\}/g;
1811: $result =~ s/&(cong|\#8773);/\\ensuremath\{\\cong\}/g;
1812: $result =~ s/&(asymp|\#8776);/\\ensuremath\{\\approx\}/g;
1813: $result =~ s/&(ne|\#8800);/\\ensuremath\{\\not=\}/g;
1814: $result =~ s/&(equiv|\#8801);/\\ensuremath\{\\equiv\}/g;
1815: $result =~ s/&(le|\#8804);/\\ensuremath\{\\leq\}/g;
1816: $result =~ s/&(ge|\#8805);/\\ensuremath\{\\geq\}/g;
1817: $result =~ s/&(sub|\#8834);/\\ensuremath\{\\subset\}/g;
1818: $result =~ s/&(sup|\#8835);/\\ensuremath\{\\supset\}/g;
1819: $result =~ s/&(nsub|\#8836);/\\ensuremath\{\\not\\subset\}/g;
1820: $result =~ s/&(sube|\#8838);/\\ensuremath\{\\subseteq\}/g;
1821: $result =~ s/&(supe|\#8839);/\\ensuremath\{\\supseteq\}/g;
1822: $result =~ s/&(oplus|\#8853);/\\ensuremath\{\\oplus\}/g;
1823: $result =~ s/&(otimes|\#8855);/\\ensuremath\{\\otimes\}/g;
1824: $result =~ s/&(perp|\#8869);/\\ensuremath\{\\perp\}/g;
1825: $result =~ s/&(sdot|\#8901);/\\ensuremath\{\\cdot\}/g;
1.199 sakharuk 1826: #Geometric Shapes (extended HTML 4.01)
1.281 sakharuk 1827: $result =~ s/&(loz|\#9674);/\\ensuremath\{\\Diamond\}/g;
1.199 sakharuk 1828: #Miscellaneous Symbols (extended HTML 4.01)
1.281 sakharuk 1829: $result =~ s/&(spades|\#9824);/\\ensuremath\{\\spadesuit\}/g;
1830: $result =~ s/&(clubs|\#9827);/\\ensuremath\{\\clubsuit\}/g;
1831: $result =~ s/&(hearts|\#9829);/\\ensuremath\{\\heartsuit\}/g;
1832: $result =~ s/&(diams|\#9830);/\\ensuremath\{\\diamondsuit\}/g;
1.495 foxr 1833: # Chemically useful 'things' contributed by Hon Kie (bug 4652).
1.515 foxr 1834:
1.495 foxr 1835: $result =~ s/&\#8636;/\\ensuremath\{\\leftharpoonup\}/g;
1836: $result =~ s/&\#8637;/\\ensuremath\{\\leftharpoondown\}/g;
1837: $result =~ s/&\#8640;/\\ensuremath\{\\rightharpoonup\}/g;
1838: $result =~ s/&\#8641;/\\ensuremath\{\\rightharpoondown\}/g;
1839: $result =~ s/&\#8652;/\\ensuremath\{\\rightleftharpoons\}/g;
1840: $result =~ s/&\#8605;/\\ensuremath\{\\leadsto\}/g;
1841: $result =~ s/&\#8617;/\\ensuremath\{\\hookleftarrow\}/g;
1842: $result =~ s/&\#8618;/\\ensuremath\{\\hookrightarrow\}/g;
1843: $result =~ s/&\#8614;/\\ensuremath\{\\mapsto\}/g;
1844: $result =~ s/&\#8599;/\\ensuremath\{\\nearrow\}/g;
1845: $result =~ s/&\#8600;/\\ensuremath\{\\searrow\}/g;
1846: $result =~ s/&\#8601;/\\ensuremath\{\\swarrow\}/g;
1847: $result =~ s/&\#8598;/\\ensuremath\{\\nwarrow\}/g;
1.513 foxr 1848:
1849: # Left/right quotations:
1850:
1851: $result =~ s/&(ldquo|#8220);/\`\`/g;
1852: $result =~ s/&(rdquo|#8221);/\'\'/g;
1853:
1854:
1.559 foxr 1855:
1.37 sakharuk 1856: return $result;
1857: }
1.41 sakharuk 1858:
1859:
1.327 albertel 1860: #width, height, oddsidemargin, evensidemargin, topmargin
1861: my %page_formats=
1862: ('letter' => {
1863: 'book' => {
1.493 foxr 1864: '1' => [ '7.1 in','9.8 in', '-0.57 in','-0.57 in','0.275 in'],
1.696 raeburn 1865: '2' => ['3.66 in','9.8 in', '-0.57 in','-0.57 in','0.275 in']
1.327 albertel 1866: },
1867: 'album' => {
1.496 foxr 1868: '1' => [ '8.8 in', '6.8 in','-0.55 in', '-0.55 in','0.394 in'],
1.698 raeburn 1869: '2' => [ '4.8 in', '6.8 in','-0.5 in', '-1.0 in','3.0 in']
1.327 albertel 1870: },
1871: },
1872: 'legal' => {
1873: 'book' => {
1874: '1' => ['7.1 in','13 in',,'-0.57 in','-0.57 in','-0.5 in'],
1.514 foxr 1875: '2' => ['3.66 in','13 in','-0.57 in','-0.57 in','-0.5 in']
1.327 albertel 1876: },
1877: 'album' => {
1.376 albertel 1878: '1' => ['12 in','7.1 in',,'-0.57 in','-0.57 in','-0.5 in'],
1879: '2' => ['6.0 in','7.1 in','-1 in','-1 in','5 in']
1.327 albertel 1880: },
1881: },
1882: 'tabloid' => {
1883: 'book' => {
1884: '1' => ['9.8 in','16 in','-0.57 in','-0.57 in','-0.5 in'],
1885: '2' => ['4.9 in','16 in','-0.57 in','-0.57 in','-0.5 in']
1886: },
1887: 'album' => {
1.376 albertel 1888: '1' => ['16 in','9.8 in','-0.57 in','-0.57 in','-0.5 in'],
1889: '2' => ['16 in','4.9 in','-0.57 in','-0.57 in','-0.5 in']
1.327 albertel 1890: },
1891: },
1892: 'executive' => {
1893: 'book' => {
1894: '1' => ['6.8 in','9 in','-0.57 in','-0.57 in','1.2 in'],
1895: '2' => ['3.1 in','9 in','-0.57 in','-0.57 in','1.2 in']
1896: },
1897: 'album' => {
1898: '1' => [],
1899: '2' => []
1900: },
1901: },
1902: 'a2' => {
1903: 'book' => {
1904: '1' => [],
1905: '2' => []
1906: },
1907: 'album' => {
1908: '1' => [],
1909: '2' => []
1910: },
1911: },
1912: 'a3' => {
1913: 'book' => {
1914: '1' => [],
1915: '2' => []
1916: },
1917: 'album' => {
1918: '1' => [],
1919: '2' => []
1920: },
1921: },
1922: 'a4' => {
1923: 'book' => {
1.493 foxr 1924: '1' => ['17.6 cm','27.2 cm','-1.397 cm','-2.11 cm','-1.27 cm'],
1.496 foxr 1925: '2' => [ '9.1 cm','27.2 cm','-1.397 cm','-2.11 cm','-1.27 cm']
1.327 albertel 1926: },
1927: 'album' => {
1.496 foxr 1928: '1' => ['21.59 cm','19.558 cm','-1.397cm','-2.11 cm','0 cm'],
1.698 raeburn 1929: '2' => ['9.91 cm','19.558 cm','-1.397 cm','-2.11 cm','-1 cm']
1.327 albertel 1930: },
1931: },
1932: 'a5' => {
1933: 'book' => {
1934: '1' => [],
1935: '2' => []
1936: },
1937: 'album' => {
1938: '1' => [],
1939: '2' => []
1940: },
1941: },
1942: 'a6' => {
1943: 'book' => {
1944: '1' => [],
1945: '2' => []
1946: },
1947: 'album' => {
1948: '1' => [],
1949: '2' => []
1950: },
1951: },
1952: );
1953:
1.177 sakharuk 1954: sub page_format {
1.140 sakharuk 1955: #
1.326 sakharuk 1956: #Supported paper format: "Letter [8 1/2x11 in]", "Legal [8 1/2x14 in]",
1957: # "Ledger/Tabloid [11x17 in]", "Executive [7 1/2x10 in]",
1958: # "A2 [420x594 mm]", "A3 [297x420 mm]",
1959: # "A4 [210x297 mm]", "A5 [148x210 mm]",
1960: # "A6 [105x148 mm]"
1.699 raeburn 1961: #
1962: my ($papersize,$layout,$numberofcolumns) = @_;
1.327 albertel 1963: return @{$page_formats{$papersize}->{$layout}->{$numberofcolumns}};
1.140 sakharuk 1964: }
1.76 sakharuk 1965:
1966:
1.126 albertel 1967: sub get_name {
1968: my ($uname,$udom)=@_;
1.373 albertel 1969: if (!defined($uname)) { $uname=$env{'user.name'}; }
1970: if (!defined($udom)) { $udom=$env{'user.domain'}; }
1.126 albertel 1971: my $plainname=&Apache::loncommon::plainname($uname,$udom);
1.213 albertel 1972: if ($plainname=~/^\s*$/) { $plainname=$uname.'@'.$udom; }
1.453 foxr 1973: $plainname=&Apache::lonxml::latex_special_symbols($plainname,'header');
1.213 albertel 1974: return $plainname;
1.126 albertel 1975: }
1976:
1.213 albertel 1977: sub get_course {
1978: my $courseidinfo;
1.373 albertel 1979: if (defined($env{'request.course.id'})) {
1.439 www 1980: $courseidinfo = &Apache::lonxml::latex_special_symbols(&unescape($env{'course.'.$env{'request.course.id'}.'.description'}),'header');
1.537 foxr 1981: my $sec = $env{'request.course.sec'};
1.699 raeburn 1982:
1.213 albertel 1983: }
1984: return $courseidinfo;
1985: }
1.177 sakharuk 1986:
1.76 sakharuk 1987: sub page_format_transformation {
1.699 raeburn 1988: my ($papersize,$layout,$numberofcolumns,$choice,$text,$assignment,$tableofcontents,$indexlist,$selectionmade) = @_;
1.202 sakharuk 1989: my ($textwidth,$textheight,$oddoffset,$evenoffset,$topmargin);
1.454 foxr 1990:
1.312 sakharuk 1991: if ($selectionmade eq '4') {
1.502 foxr 1992: if ($choice eq 'all_problems') {
1.561 bisitz 1993: $assignment=&mt('Problems from the Whole Course');
1.502 foxr 1994: } else {
1.561 bisitz 1995: $assignment=&mt('Resources from the Whole Course');
1.502 foxr 1996: }
1.312 sakharuk 1997: } else {
1998: $assignment=&Apache::lonxml::latex_special_symbols($assignment,'header');
1999: }
1.261 sakharuk 2000: ($textwidth,$textheight,$oddoffset,$evenoffset,$topmargin) = &page_format($papersize,$layout,$numberofcolumns,$topmargin);
1.454 foxr 2001:
2002:
1.126 albertel 2003: my $name = &get_name();
1.213 albertel 2004: my $courseidinfo = &get_course();
1.455 albertel 2005: my $header_text = $parmhash{'print_header_format'};
1.486 foxr 2006: $header_text = &format_page_header($textwidth, $header_text, $assignment,
1.455 albertel 2007: $courseidinfo, $name);
1.319 sakharuk 2008: my $topmargintoinsert = '';
2009: if ($topmargin ne '0') {$topmargintoinsert='\setlength{\topmargin}{'.$topmargin.'}';}
1.325 sakharuk 2010: my $fancypagestatement='';
2011: if ($numberofcolumns eq '2') {
1.455 albertel 2012: $fancypagestatement="\\fancyhead{}\\fancyhead[LO]{$header_text}";
1.700 ! raeburn 2013: if ($parmhash{'print_header_format'} eq '') {
! 2014: $fancypagestatement .= "\\fancyhead[RE]{\\thepage \\\\[\\baselineskip]}";
! 2015: }
1.325 sakharuk 2016: } else {
1.455 albertel 2017: $fancypagestatement="\\rhead{}\\chead{}\\lhead{$header_text}";
1.325 sakharuk 2018: }
1.700 ! raeburn 2019: $fancypagestatement .= "\\fancyfoot{}";
1.698 raeburn 2020: my ($paperwidth,$paperheight);
1.140 sakharuk 2021: if ($layout eq 'album') {
1.649 raeburn 2022: $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 /;
1.698 raeburn 2023: if ($papersize eq 'a4') {
2024: $paperwidth = '29.7cm';
2025: $paperheight = '21cm';
2026: } elsif ($numberofcolumns eq '1') {
2027: if ($papersize eq 'letter') {
2028: $paperwidth = '11in';
2029: $paperheight = '8.5in';
2030: } elsif ($papersize eq 'legal') {
2031: $paperwidth = '14in';
2032: $paperheight = '8.5in';
2033: }
2034: }
1.140 sakharuk 2035: } elsif ($layout eq 'book') {
1.699 raeburn 2036: if ($choice ne 'All class print') {
1.649 raeburn 2037: $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/;
1.140 sakharuk 2038: } else {
1.649 raeburn 2039: $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 /;
1.319 sakharuk 2040: }
1.698 raeburn 2041: if ($papersize eq 'a4') {
2042: $paperwidth = '21cm';
2043: $paperheight = '29.7cm';
2044: } elsif ($papersize eq 'letter') {
2045: $paperwidth = '8.5in';
2046: $paperheight = '11.5in';
2047: } elsif ($papersize eq 'legal') {
2048: $paperwidth = '8.5in';
2049: $paperheight = '14.0in';
2050: }
2051: }
2052: if ($paperwidth ne '' && $paperheight ne '') {
2053: my $papersize_text;
2054: if ($perm{'pav'}) {
2055: $papersize_text = '\\special{papersize='.$paperwidth.','.$paperheight.'}';
2056: } else {
2057: $papersize_text = '\special{papersize='.$paperwidth.','.$paperheight.'}';
2058: }
2059: $text =~ s/(\\begin\{document})/$1$papersize_text/;
1.140 sakharuk 2060: }
1.214 sakharuk 2061: if ($tableofcontents eq 'yes') {$text=~s/(\\setcounter\{page\}\{1\})/$1 \\tableofcontents\\newpage /;}
2062: if ($indexlist eq 'yes') {
1.649 raeburn 2063: $text=~s/(\\begin\{document})/\\makeindex $1/;
2064: $text=~s/(\\end\{document})/\\strut\\\\\\strut\\printindex $1/;
1.214 sakharuk 2065: }
1.140 sakharuk 2066: return $text;
2067: }
2068:
2069:
1.33 sakharuk 2070: sub page_cleanup {
2071: my $result = shift;
1.699 raeburn 2072:
1.649 raeburn 2073: $result =~ m/\\end\{document}(\d*)$/;
1.34 sakharuk 2074: my $number_of_columns = $1;
1.33 sakharuk 2075: my $insert = '{';
1.34 sakharuk 2076: for (my $id=1;$id<=$number_of_columns;$id++) { $insert .='l'; }
1.33 sakharuk 2077: $insert .= '}';
1.649 raeburn 2078: $result =~ s/(\\begin\{longtable})INSERTTHEHEADOFLONGTABLE\\endfirsthead\\endhead/$1$insert/g;
1.34 sakharuk 2079: $result =~ s/&\s*REMOVETHEHEADOFLONGTABLE\\\\/\\\\/g;
2080: return $result,$number_of_columns;
1.7 sakharuk 2081: }
1.5 sakharuk 2082:
1.3 sakharuk 2083:
1.60 sakharuk 2084: sub details_for_menu {
1.335 albertel 2085: my ($helper)=@_;
1.373 albertel 2086: my $postdata=$env{'form.postdata'};
1.335 albertel 2087: if (!$postdata) { $postdata=$helper->{VARS}{'postdata'}; }
2088: my $name_of_resource = &Apache::lonnet::gettitle($postdata);
2089: my $symbolic = &Apache::lonnet::symbread($postdata);
1.482 albertel 2090: return if ( $symbolic eq '');
2091:
1.233 www 2092: my ($map,$id,$resource)=&Apache::lonnet::decode_symb($symbolic);
1.123 albertel 2093: $map=&Apache::lonnet::clutter($map);
1.269 albertel 2094: my $name_of_sequence = &Apache::lonnet::gettitle($map);
1.63 albertel 2095: if ($name_of_sequence =~ /^\s*$/) {
1.123 albertel 2096: $map =~ m|([^/]+)$|;
2097: $name_of_sequence = $1;
1.63 albertel 2098: }
1.373 albertel 2099: my $name_of_map = &Apache::lonnet::gettitle($env{'request.course.uri'});
1.63 albertel 2100: if ($name_of_map =~ /^\s*$/) {
1.373 albertel 2101: $env{'request.course.uri'} =~ m|([^/]+)$|;
1.123 albertel 2102: $name_of_map = $1;
2103: }
1.335 albertel 2104: return ($name_of_resource,$name_of_sequence,$name_of_map);
1.76 sakharuk 2105: }
2106:
1.476 albertel 2107: sub copyright_line {
2108: 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 } ';
2109: }
2110: my $end_of_student = "\n".'\special{ps:ENDOFSTUDENTSTAMP}'."\n";
1.76 sakharuk 2111:
2112: sub latex_corrections {
1.408 albertel 2113: my ($number_of_columns,$result,$selectionmade,$answer_mode) = @_;
1.649 raeburn 2114: # $result =~ s/\\includegraphics\{/\\includegraphics\[width=\\minipagewidth\]{/g;
1.476 albertel 2115: my $copyright = ©right_line();
1.408 albertel 2116: if ($selectionmade eq '1' || $answer_mode eq 'only') {
1.649 raeburn 2117: $result =~ s/(\\end\{document})/\\strut\\vskip 0 mm $copyright $end_of_student $1/;
1.408 albertel 2118: } else {
1.649 raeburn 2119: $result =~ s/(\\end\{document})/\\strut\\vspace\*{-4 mm}\\newline $copyright $end_of_student $1/;
1.316 sakharuk 2120: }
1.476 albertel 2121: $result =~ s/\$number_of_columns/$number_of_columns/g;
1.662 raeburn 2122: $result =~ s/(\\end\{longtable}\s*)(\\strut\\newline\\noindent\\makebox\[\\textwidth\/$number_of_columns\]\[b\]\{\\hrulefill})/$2$1/g;
1.649 raeburn 2123: $result =~ s/(\\end\{longtable}\s*)\\strut\\newline/$1/g;
1.699 raeburn 2124: #-- LaTeX corrections
1.76 sakharuk 2125: my $first_comment = index($result,'<!--',0);
2126: while ($first_comment != -1) {
2127: my $end_comment = index($result,'-->',$first_comment);
2128: substr($result,$first_comment,$end_comment-$first_comment+3) = '';
2129: $first_comment = index($result,'<!--',$first_comment);
2130: }
2131: $result =~ s/^\s+$//gm; #remove empty lines
1.377 albertel 2132: #removes more than one empty space
2133: $result =~ s|(\s\s+)|($1=~/[\n\r]/)?"\n":" "|ge;
1.76 sakharuk 2134: $result =~ s/\\\\\s*\\vskip/\\vskip/gm;
2135: $result =~ s/\\\\\s*\\noindent\s*(\\\\)+/\\\\\\noindent /g;
2136: $result =~ s/{\\par }\s*\\\\/\\\\/gm;
1.313 sakharuk 2137: $result =~ s/\\\\\s+\[/ \[/g;
1.76 sakharuk 2138: #conversion of html characters to LaTeX equivalents
2139: if ($result =~ m/&(\w+|#\d+);/) {
2140: $result = &character_chart($result);
2141: }
1.650 raeburn 2142: $result =~ s/(\\end\{tabular})\s*\\vskip 0 mm/$1/g;
2143: $result =~ s/(\\begin\{enumerate})\s*\\noindent/$1/g;
1.76 sakharuk 2144: return $result;
1.60 sakharuk 2145: }
2146:
1.3 sakharuk 2147:
1.214 sakharuk 2148: sub index_table {
2149: my $currentURL = shift;
2150: my $insex_string='';
2151: $currentURL=~s/\.([^\/+])$/\.$1\.meta/;
2152: $insex_string=&Apache::lonnet::metadata($currentURL,'keywords');
2153: return $insex_string;
2154: }
2155:
2156:
1.215 sakharuk 2157: sub IndexCreation {
2158: my ($texversion,$currentURL)=@_;
2159: my @key_words=split(/,/,&index_table($currentURL));
2160: my $chunk='';
2161: my $st=index $texversion,'\addcontentsline{toc}{subsection}{';
2162: if ($st>0) {
2163: for (my $i=0;$i<3;$i++) {$st=(index $texversion,'}',$st+1);}
2164: $chunk=substr($texversion,0,$st+1);
2165: substr($texversion,0,$st+1)=' ';
2166: }
2167: foreach my $key_word (@key_words) {
2168: if ($key_word=~/\S+/) {
2169: $texversion=~s/\b($key_word)\b/$1 \\index{$key_word} /i;
2170: }
2171: }
2172: if ($st>0) {substr($texversion,0,1)=$chunk;}
2173: return $texversion;
2174: }
2175:
1.242 sakharuk 2176: sub print_latex_header {
2177: my $mode=shift;
1.550 foxr 2178:
2179: return &Apache::londefdef::latex_header($mode);
1.242 sakharuk 2180: }
2181:
2182: sub path_to_problem {
1.328 albertel 2183: my ($urlp,$colwidth)=@_;
1.404 albertel 2184: $urlp=&Apache::lonnet::clutter($urlp);
2185:
1.242 sakharuk 2186: my $newurlp = '';
1.328 albertel 2187: $colwidth=~s/\s*mm\s*$//;
2188: #characters average about 2 mm in width
1.360 albertel 2189: if (length($urlp)*2 > $colwidth) {
1.404 albertel 2190: my @elements = split('/',$urlp);
1.328 albertel 2191: my $curlength=0;
2192: foreach my $element (@elements) {
1.404 albertel 2193: if ($element eq '') { next; }
1.328 albertel 2194: if ($curlength+(length($element)*2) > $colwidth) {
1.404 albertel 2195: $newurlp .= '|\vskip -1 mm \verb|';
2196: $curlength=length($element)*2;
1.328 albertel 2197: } else {
2198: $curlength+=length($element)*2;
1.242 sakharuk 2199: }
1.328 albertel 2200: $newurlp.='/'.$element;
1.242 sakharuk 2201: }
1.253 sakharuk 2202: } else {
2203: $newurlp=$urlp;
1.242 sakharuk 2204: }
2205: return '{\small\noindent\verb|'.$newurlp.'|\vskip 0 mm}';
2206: }
1.215 sakharuk 2207:
1.275 sakharuk 2208: sub recalcto_mm {
2209: my $textwidth=shift;
2210: my $LaTeXwidth;
1.339 albertel 2211: if ($textwidth=~/(-?\d+\.?\d*)\s*cm/) {
1.275 sakharuk 2212: $LaTeXwidth = $1*10;
1.339 albertel 2213: } elsif ($textwidth=~/(-?\d+\.?\d*)\s*mm/) {
1.275 sakharuk 2214: $LaTeXwidth = $1;
1.339 albertel 2215: } elsif ($textwidth=~/(-?\d+\.?\d*)\s*in/) {
1.275 sakharuk 2216: $LaTeXwidth = $1*25.4;
2217: }
2218: $LaTeXwidth.=' mm';
2219: return $LaTeXwidth;
2220: }
2221:
1.285 albertel 2222: sub get_textwidth {
2223: my ($helper,$LaTeXwidth)=@_;
1.286 albertel 2224: my $textwidth=$LaTeXwidth;
1.285 albertel 2225: if ($helper->{'VARS'}->{'pagesize.width'}=~/\d+/ &&
2226: $helper->{'VARS'}->{'pagesize.widthunit'}=~/\w+/) {
1.286 albertel 2227: $textwidth=&recalcto_mm($helper->{'VARS'}->{'pagesize.width'}.' '.
2228: $helper->{'VARS'}->{'pagesize.widthunit'});
1.285 albertel 2229: }
1.286 albertel 2230: return $textwidth;
1.285 albertel 2231: }
2232:
1.296 sakharuk 2233:
2234: sub unsupported {
1.414 albertel 2235: my ($currentURL,$mode,$symb)=@_;
1.672 raeburn 2236: my $cleanURL=&Apache::lonenc::check_decrypt($currentURL);
2237: my $shown = $currentURL;
2238: if (($cleanURL ne $currentURL) || ($symb =~ m{/^enc/})) {
2239: $shown = &mt('URL not shown (encrypted)');
2240: }
1.307 sakharuk 2241: if ($mode ne '') {$mode='\\'.$mode}
1.672 raeburn 2242: my $result = &print_latex_header($mode);
2243: if ($cleanURL=~m|^(/adm/wrapper)?/ext/|) {
2244: $cleanURL=~s|^(/adm/wrapper)?/ext/|http://|;
2245: $cleanURL=~s|^http://https://|https://|;
2246: if ($shown eq $currentURL) {
2247: $shown = &Apache::lonxml::latex_special_symbols($cleanURL);
2248: }
2249: my $title=&Apache::lonnet::gettitle($symb);
2250: $title = &Apache::lonxml::latex_special_symbols($title);
2251: $result.=' \strut \\\\ \textit{'.$title.'} \strut \\\\ '.$shown.' ';
1.296 sakharuk 2252: } else {
1.672 raeburn 2253: if ($shown eq $currentURL) {
2254: $result.=&Apache::lonxml::latex_special_symbols($currentURL);
2255: } else {
2256: $result.=$shown;
2257: }
1.296 sakharuk 2258: }
1.419 albertel 2259: $result.= '\vskip 0.5mm\noindent\makebox[\textwidth/$number_of_columns][b]{\hrulefill} \end{document}';
1.296 sakharuk 2260: return $result;
2261: }
2262:
1.559 foxr 2263: #
2264: # Map from helper layout style to the book/album:
2265: #
2266: sub map_laystyle {
2267: my ($laystyle) = @_;
2268: if ($laystyle eq 'L') {
2269: $laystyle='album';
2270: } else {
2271: $laystyle='book';
2272: }
2273: return $laystyle;
2274: }
2275:
2276: sub print_page_in_course {
2277: my ($helper, $rparmhash, $currentURL, $resources) = @_;
1.602 www 2278:
1.559 foxr 2279: my %parmhash = %$rparmhash;
2280: my @page_resources = @$resources;
2281: my $mode = $helper->{'VARS'}->{'LATEX_TYPE'};
2282: my $symb = $helper->{'VARS'}->{'symb'};
2283:
2284:
2285: my $format_from_helper = $helper->{'VARS'}->{'FORMAT'};
2286:
2287:
2288: my @temporary_array=split /\|/,$format_from_helper;
2289: my ($laystyle,$numberofcolumns,$papersize,$pdfFormFields)=@temporary_array;
2290: $laystyle = &map_laystyle($laystyle);
2291: my ($textwidth,$textheight,$oddoffset,$evenoffset) = &page_format($papersize,$laystyle,
2292: $numberofcolumns);
1.699 raeburn 2293: my $LaTeXwidth=&recalcto_mm($textwidth);
1.559 foxr 2294:
2295: if ($mode ne '') {$mode='\\'.$mode}
1.562 foxr 2296: my $result = &print_latex_header($mode);
1.672 raeburn 2297:
2298: my $title=&Apache::lonnet::gettitle($currentURL);
2299: $title = &Apache::lonxml::latex_special_symbols($title);
2300: $result .= '\noindent\textit{'.$title.'}\\\\';
1.559 foxr 2301:
2302: if ($helper->{'VARS'}->{'style_file'}=~/\w/) {
2303: &Apache::lonnet::appenv({'construct.style' =>
2304: $helper->{'VARS'}->{'style_file'}});
2305: } elsif ($env{'construct.style'}) {
2306: &Apache::lonnet::delenv('construct.style');
2307: }
2308:
1.699 raeburn 2309: # First is the overall page description. This is then followed by the
1.559 foxr 2310: # components of the page. Each of which must be printed independently.
1.699 raeburn 2311: my $the_page = shift(@page_resources);
1.559 foxr 2312:
2313:
2314: foreach my $resource (@page_resources) {
2315: my $resource_src = $resource->src(); # Essentially the URL of the resource.
1.672 raeburn 2316: my $current_url = $resource->link();
1.559 foxr 2317:
2318: # Recurse if a .page:
2319:
2320: if ($resource_src =~ /.page$/i) {
2321: my $navmap = Apache::lonnavmaps::navmap->new();
2322: my @page_resources = $navmap->retrieveResources($resource_src);
1.699 raeburn 2323: $result .= &print_page_in_course($helper, $rparmhash,
1.559 foxr 2324: $resource_src, \@page_resources);
1.624 raeburn 2325: } elsif ($resource->ext()) {
1.672 raeburn 2326: $result.=&latex_header_footer_remove(&unsupported($current_url,$mode,$resource->symb));
2327: } elsif ($resource_src =~ /\.(problem|exam|quiz|assess|survey|form|library|xml|html|htm|xhtml|xhtm)$/) {
2328: # these resources go through the XML transformer:
2329: $result .= &Apache::lonxml::latex_special_symbols($resource->title()) . '\\\\';
1.602 www 2330:
1.559 foxr 2331: my $urlp = &Apache::lonnet::clutter($resource_src);
1.602 www 2332:
1.559 foxr 2333: my %form;
2334: my %moreenv;
2335:
2336: &Apache::lonxml::remember_problem_counter();
2337: $moreenv{'request.filename'}=$urlp;
2338: if ($helper->{'VARS'}->{'probstatus'} eq 'exam') {$form{'problemtype'}='exam';}
2339:
2340: $form{'grade_target'} = 'tex';
2341: $form{'textwidth'} = &get_textwidth($helper, $LaTeXwidth);
1.699 raeburn 2342: $form{'pdfFormFields'} = $pdfFormFields; #
2343: $form{'showallfoils'} = $helper->{'VARS'}->{'showallfoils'};
2344:
1.559 foxr 2345: $form{'problem_split'}=$parmhash{'problem_stream_switch'};
2346: $form{'suppress_tries'}=$parmhash{'suppress_tries'};
2347: $form{'latex_type'}=$helper->{'VARS'}->{'LATEX_TYPE'};
2348: $form{'print_discussions'}=$helper->{'VARS'}->{'PRINT_DISCUSSIONS'};
2349: $form{'print_annotations'}=$helper->{'VARS'}->{'PRINT_ANNOTATIONS'};
2350: if (($helper->{'VARS'}->{'PRINT_DISCUSSIONS'} eq 'yes') ||
2351: ($helper->{'VARS'}->{'PRINT_ANNOTATIONS'} eq 'yes')) {
2352: $form{'problem_split'}='yes';
2353: }
2354: my $rndseed = time;
2355: if ($helper->{'VARS'}->{'curseed'}) {
2356: $rndseed=$helper->{'VARS'}->{'curseed'};
2357: }
2358: $form{'rndseed'}=$rndseed;
2359: &Apache::lonnet::appenv(\%moreenv);
1.699 raeburn 2360:
1.559 foxr 2361: &Apache::lonxml::clear_problem_counter();
2362:
2363: my $texversion = &ssi_with_retries($urlp, $ssi_retry_count, %form);
2364:
2365:
2366: # current document with answers.. no need to encap in minipage
2367: # since there's only one answer.
2368:
2369: if(($helper->{'VARS'}->{'ANSWER_TYPE'} eq 'no') ||
2370: ($helper->{'VARS'}->{'ANSWER_TYPE'} eq 'only')) {
2371: my %answerform = %form;
2372:
2373:
2374: $answerform{'problem_split'}=$parmhash{'problem_stream_switch'};
2375: $answerform{'grade_target'}='answer';
2376: $answerform{'answer_output_mode'}='tex';
2377: $answerform{'rndseed'}=$rndseed;
2378: if ($helper->{'VARS'}->{'probstatus'} eq 'exam') {
2379: $answerform{'problemtype'}='exam';
2380: }
2381: $resources_printed .= $urlp.':';
2382: my $answer=&ssi_with_retries($urlp,$ssi_retry_count, %answerform);
2383:
2384: if ($helper->{'VARS'}->{'ANSWER_TYPE'} eq 'no') {
1.649 raeburn 2385: $texversion=~s/(\\keephidden\{ENDOFPROBLEM})/$answer$1/;
1.559 foxr 2386: } else {
1.562 foxr 2387: $texversion= &print_latex_header($helper->{'VARS'}->{'LATEX_TYPE'});
1.559 foxr 2388: if ($helper->{'VARS'}->{'construction'} ne '1') {
2389: my $title = &Apache::lonnet::gettitle($helper->{'VARS'}->{'symb'});
2390: $title = &Apache::lonxml::latex_special_symbols($title);
2391: $texversion.='\vskip 0 mm \noindent\textbf{'.$title.'}\vskip 0 mm ';
2392: $texversion.=&path_to_problem($urlp,$LaTeXwidth);
2393: } else {
1.602 www 2394: $texversion.='\vskip 0 mm \noindent\textbf{'.
1.633 raeburn 2395: &mt("Printing from Authoring Space: No Title").'}\vskip 0 mm ';
1.602 www 2396: $texversion.=&path_to_problem($urlp,$LaTeXwidth);
1.559 foxr 2397: }
2398: $texversion.='\vskip 1 mm '.$answer.'\end{document}';
2399: }
2400: }
2401: # Print annotations.
2402:
2403:
2404: if ($helper->{'VARS'}->{'PRINT_ANNOTATIONS'} eq 'yes') {
2405: my $annotation .= &annotate($currentURL);
1.649 raeburn 2406: $texversion =~ s/(\\keephidden\{ENDOFPROBLEM})/$annotation$1/;
1.559 foxr 2407: }
1.699 raeburn 2408:
1.559 foxr 2409: if ($helper->{'VARS'}->{'TABLE_INDEX'} eq 'yes') {
2410: $texversion=&IndexCreation($texversion,$currentURL);
2411: }
2412: if ($helper->{'VARS'}->{'CONSTR_RESOURSE_URL'} eq 'yes') {
2413: $texversion=~s/(\\addcontentsline\{toc\}\{subsection\}\{[^\}]*\})/$1 URL: \\verb|$currentURL| \\strut\\\\\\strut /;
2414:
2415: }
1.562 foxr 2416: $texversion = &latex_header_footer_remove($texversion);
2417:
2418: # the first remaining line is a comment from londefdef the second
2419: # line seems to be an extraneous \vskip 1mm \\\\ :
2420: # (imperfect removal from header_footer_remove?
2421:
2422: $texversion =~ s/\\vskip 1mm \\\\\\\\//;
2423:
1.559 foxr 2424: $result .= $texversion;
2425: if ($currentURL=~m/\.page\s*$/) {
2426: ($result,$numberofcolumns) = &page_cleanup($result);
2427: }
2428: }
2429: }
2430:
2431: $result.= '\vskip 0.5mm\noindent\makebox[\textwidth/$number_of_columns][b]{\hrulefill} \end{document}';
2432: return $result;
2433: }
2434:
1.296 sakharuk 2435:
1.363 foxr 2436: #
1.395 www 2437: # List of recently generated print files
2438: #
2439: sub recently_generated {
1.584 raeburn 2440: my ($prtspool) = @_;
2441: my $output;
1.400 albertel 2442: my $zip_result;
2443: my $pdf_result;
1.395 www 2444: opendir(DIR,$prtspool);
1.400 albertel 2445:
1.699 raeburn 2446: my @files =
1.400 albertel 2447: grep(/^$env{'user.name'}_$env{'user.domain'}_printout_(\d+)_.*\.(pdf|zip)$/,readdir(DIR));
1.395 www 2448: closedir(DIR);
1.400 albertel 2449:
2450: @files = sort {
2451: my ($actime) = (stat($prtspool.'/'.$a))[10];
2452: my ($bctime) = (stat($prtspool.'/'.$b))[10];
2453: return $bctime <=> $actime;
2454: } (@files);
2455:
2456: foreach my $filename (@files) {
2457: my ($ext) = ($filename =~ m/(pdf|zip)$/);
2458: my ($cdev,$cino,$cmode,$cnlink,
2459: $cuid,$cgid,$crdev,$csize,
2460: $catime,$cmtime,$cctime,
2461: $cblksize,$cblocks)=stat($prtspool.'/'.$filename);
1.544 bisitz 2462: my $ext_text = 'pdf' ? &mt('PDF File'):&mt('Zip File');
2463: my $result=&Apache::loncommon::start_data_table_row()
2464: .'<td>'
2465: .'<a href="/prtspool/'.$filename.'">'.$ext_text.'</a>'
2466: .'</td>'
2467: .'<td>'.&Apache::lonlocal::locallocaltime($cctime).'</td>'
2468: .'<td align="right">'.$csize.'</td>'
2469: .&Apache::loncommon::end_data_table_row();
1.400 albertel 2470: if ($ext eq 'pdf') { $pdf_result .= $result; }
2471: if ($ext eq 'zip') { $zip_result .= $result; }
2472: }
1.544 bisitz 2473: if ($zip_result || $pdf_result) {
1.584 raeburn 2474: $output ='<hr />';
1.544 bisitz 2475: }
1.400 albertel 2476: if ($zip_result) {
1.584 raeburn 2477: $output .='<h3>'.&mt('Recently generated printout zip files')."</h3>\n"
1.544 bisitz 2478: .&Apache::loncommon::start_data_table()
2479: .&Apache::loncommon::start_data_table_header_row()
2480: .'<th>'.&mt('Download').'</th>'
2481: .'<th>'.&mt('Creation Date').'</th>'
2482: .'<th>'.&mt('File Size (Bytes)').'</th>'
2483: .&Apache::loncommon::end_data_table_header_row()
2484: .$zip_result
1.584 raeburn 2485: .&Apache::loncommon::end_data_table();
1.400 albertel 2486: }
2487: if ($pdf_result) {
1.584 raeburn 2488: $output .='<h3>'.&mt('Recently generated printouts')."</h3>\n"
1.544 bisitz 2489: .&Apache::loncommon::start_data_table()
2490: .&Apache::loncommon::start_data_table_header_row()
2491: .'<th>'.&mt('Download').'</th>'
2492: .'<th>'.&mt('Creation Date').'</th>'
2493: .'<th>'.&mt('File Size (Bytes)').'</th>'
2494: .&Apache::loncommon::end_data_table_header_row()
2495: .$pdf_result
1.584 raeburn 2496: .&Apache::loncommon::end_data_table();
1.396 albertel 2497: }
1.584 raeburn 2498: return $output;
1.395 www 2499: }
2500:
2501: #
1.363 foxr 2502: # Retrieve the hash of page breaks.
2503: #
2504: # Inputs:
2505: # helper - reference to helper object.
2506: # Outputs
2507: # A reference to a page break hash.
2508: #
2509: #
1.610 foxr 2510: # use Data::Dumper;
1.569 foxr 2511: # sub dump_helper_vars {
1.418 foxr 2512: # my ($helper) = @_;
2513: # my $helpervars = Dumper($helper->{'VARS'});
2514: # &Apache::lonnet::logthis("Dump of helper vars:\n $helpervars");
2515: #}
1.363 foxr 2516:
1.481 albertel 2517: sub get_page_breaks {
2518: my ($helper) = @_;
2519: my %page_breaks;
2520:
2521: foreach my $break (split /\|\|\|/, $helper->{'VARS'}->{'FINISHPAGE'}) {
2522: $page_breaks{$break} = 1;
2523: }
2524: return %page_breaks;
2525: }
1.699 raeburn 2526: #
1.569 foxr 2527: # Returns text to insert for any extra vskip prior to the resource.
2528: # Parameters:
2529: # helper - Reference to the helper object driving the printout.
2530: # resource - Identifies the resource about to be printed.
2531: #
2532: # This is done as follows:
2533: # POSSIBLE_RESOURCES has the list of possible resources.
2534: # EXTRASPACE has the list of extra space values.
1.570 foxr 2535: # EXTRASPACE_UNITS is the set of resources for which the units are
2536: # mm. All others are 'in'.
1.699 raeburn 2537: #
1.569 foxr 2538: # The resource is found in the POSSIBLE_RESOURCES to get the index
2539: # of the EXTRASPACE value.
2540: #
2541: # In order to speed this up for lengthy printouts, the first time,
2542: # POSSIBLE_RESOURCES is turned into a look up hash and
2543: # EXTRASPACE is turned into an array.
2544: #
2545:
2546:
2547: my %possible_resources;
1.570 foxr 2548: my %extraspace_mm;
1.569 foxr 2549: my @extraspace;
2550: my $skips_loaded = 0;
2551:
2552: # Function to load the skips hash and array
2553:
2554: sub load_skips {
2555:
2556: my ($helper) = @_;
2557:
1.689 raeburn 2558: # If this is the first time, unwrap the resources and extra spaces:
1.569 foxr 2559:
2560: if (!$skips_loaded) {
2561: @extraspace = (split(/\|\|\|/, $helper->{'VARS'}->{'EXTRASPACE'}));
2562: my @resource_list = (split(/\|\|\|/, $helper->{'VARS'}->{'POSSIBLE_RESOURCES'}));
2563: my $i = 0;
2564: foreach my $resource (@resource_list) {
2565: $possible_resources{$resource} = $i;
2566: $i++;
2567: }
1.570 foxr 2568: foreach my $mm_resource (split(/\|\|\|/, $helper->{'VARS'}->{'EXTRASPACE_UNITS'})) {
2569: $extraspace_mm{$mm_resource} = 1;
2570: }
1.569 foxr 2571: $skips_loaded = 1;
2572: }
2573: }
2574:
2575: sub get_extra_vspaces {
2576: my ($helper, $resource) = @_;
2577:
2578: &load_skips($helper);
2579:
2580: # Lookup the resource in the possible resources hash.. that is the index
2581: # into the extraspace array that gives us either an empty string or
2582: # the number of mm to skip:
2583:
2584: my $index = $possible_resources{$resource};
2585: my $skip = $extraspace[$index];
2586:
2587: my $result = '';
2588: if ($skip ne '') {
1.570 foxr 2589: my $units = 'in';
2590: if (defined($extraspace_mm{$resource})) {
2591: $units = 'mm';
2592: }
2593: $result = '\vskip '.$skip.' '.$units;
1.569 foxr 2594: }
1.570 foxr 2595:
2596:
1.569 foxr 2597: return $result;
2598:
2599:
2600: }
2601:
2602: #
2603: # The resource chooser part of the helper needs more than just
2604: # the value of the extraspaces var to recover the value into a text
2605: # field option. This sub produces the required format for the saved var:
1.699 raeburn 2606: # specifically
1.569 foxr 2607: # ||| separated fields of the form resourcename=value
2608: #
2609: # Parameters:
2610: # $helper - Refers to the helper we are configuring
2611: # Implicit input:
2612: # $helper->{'VARS'}->{'EXTRASPACE'} - the spaces helper var has the text field
2613: # value.
1.570 foxr 2614: # $helper->{'VARS'}->{'EXTRASPACE_UNITS'} - units for the skips (checkboxes).
1.569 foxr 2615: # $helper->{'VARS'}->{'POSSIBLE_RESOURCES'} - has the list of resources. |||
2616: # separated of course.
2617: # Implicit outputs:
1.570 foxr 2618: # $env{'form.extraspace'}
2619: # $env{'form.extraspace_units'}
1.569 foxr 2620: #
2621: sub set_form_extraspace {
2622: my ($helper) = @_;
2623:
2624: # the most convenient way to do this is to drive from the skips arrays/hash.
2625: # may not be the fastest, but this is once per print request so it's not so
2626: # speed critical:
2627:
2628: &load_skips($helper);
2629:
2630: my $result = '';
2631:
2632: foreach my $resource (keys(%possible_resources)) {
2633: my $vskip = $extraspace[$possible_resources{$resource}];
2634: $result .= $resource .'=' . $vskip . '|||';
2635: }
2636:
2637: $env{'form.extraspace'} = $result;
1.570 foxr 2638: $env{'form.extraspace_units'} = $helper->{'VARS'}->{'EXTRASPACE_UNITS'};
1.569 foxr 2639: return $result;
1.699 raeburn 2640:
1.569 foxr 2641: }
1.363 foxr 2642:
1.459 foxr 2643: # Output a sequence (recursively if neeed)
2644: # from construction space.
2645: # Parameters:
2646: # url = URL of the sequence to print.
2647: # helper - Reference to the helper hash.
2648: # form - Copy of the format hash.
2649: # LaTeXWidth
2650: # Returns:
2651: # Text to add to the printout.
2652: # NOTE if the first element of the outermost sequence
2653: # is itself a sequence, the outermost caller may need to
2654: # prefix the latex with the page headers stuff.
2655: #
2656: sub print_construction_sequence {
2657: my ($currentURL, $helper, %form, $LaTeXwidth) = @_;
1.590 foxr 2658:
1.459 foxr 2659: my $result;
2660: my $rndseed=time;
2661: if ($helper->{'VARS'}->{'curseed'}) {
2662: $rndseed=$helper->{'VARS'}->{'curseed'};
2663: }
1.606 www 2664: my $errtext=&LONCAPA::map::mapread(&Apache::lonnet::filelocation('',$currentURL));
2665:
1.699 raeburn 2666: #
1.459 foxr 2667: # These make this all support recursing for subsequences.
2668: #
1.491 albertel 2669: my @order = @LONCAPA::map::order;
1.699 raeburn 2670: my @resources = @LONCAPA::map::resources;
1.606 www 2671:
1.459 foxr 2672: for (my $member=0;$member<=$#order;$member++) {
2673: $resources[$order[$member]]=~/^([^:]*):([^:]*):/;
2674: my $urlp=$2;
2675: if ($urlp=~/\.(problem|exam|quiz|assess|survey|form|library|xml|html|htm|xhtml|xhtm)$/) {
2676: my $texversion='';
2677: if ($helper->{'VARS'}->{'ANSWER_TYPE'} ne 'only') {
2678: $form{'problem_split'}=$parmhash{'problem_stream_switch'};
2679: $form{'suppress_tries'}=$parmhash{'suppress_tries'};
2680: $form{'latex_type'}=$helper->{'VARS'}->{'LATEX_TYPE'};
2681: $form{'rndseed'}=$rndseed;
2682: $resources_printed .=$urlp.':';
1.515 foxr 2683: $texversion=&ssi_with_retries($urlp, $ssi_retry_count, %form);
1.459 foxr 2684: }
2685: if((($helper->{'VARS'}->{'ANSWER_TYPE'} eq 'no') ||
1.699 raeburn 2686: ($helper->{'VARS'}->{'ANSWER_TYPE'} eq 'only')) &&
1.609 www 2687: ($urlp=~/$LONCAPA::assess_page_re/)) {
1.459 foxr 2688: # Don't permanently modify %$form...
2689: my %answerform = %form;
2690: $answerform{'grade_target'}='answer';
2691: $answerform{'answer_output_mode'}='tex';
2692: $answerform{'rndseed'}=$rndseed;
2693: $answerform{'problem_split'}=$parmhash{'problem_stream_switch'};
1.481 albertel 2694: if ($urlp=~/\/res\//) {$env{'request.state'}='published';}
1.459 foxr 2695: $resources_printed .= $urlp.':';
1.515 foxr 2696: my $answer=&ssi_with_retries($urlp, $ssi_retry_count, %answerform);
1.459 foxr 2697: if ($helper->{'VARS'}->{'ANSWER_TYPE'} eq 'no') {
1.649 raeburn 2698: $texversion=~s/(\\keephidden\{ENDOFPROBLEM})/$answer$1/;
1.459 foxr 2699: } else {
2700: # If necessary, encapsulate answer in minipage:
1.699 raeburn 2701:
1.459 foxr 2702: $texversion=&print_latex_header($helper->{'VARS'}->{'LATEX_TYPE'});
1.477 albertel 2703: my $title = &Apache::lonnet::gettitle($helper->{'VARS'}->{'symb'});
2704: $title = &Apache::lonxml::latex_special_symbols($title);
2705: my $body ='\vskip 0 mm \noindent\textbf{'.$title.'}\vskip 0 mm ';
1.459 foxr 2706: $body.=&path_to_problem($urlp,$LaTeXwidth);
2707: $body.='\vskip 1 mm '.$answer.'\end{document}';
1.676 raeburn 2708: $body = &encapsulate_minipage($body,$answerform{'problem_split'});
1.459 foxr 2709: $texversion.=$body;
2710: }
2711: }
2712: $texversion = &latex_header_footer_remove($texversion);
2713:
2714: if ($helper->{'VARS'}->{'TABLE_INDEX'} eq 'yes') {
2715: $texversion=&IndexCreation($texversion,$urlp);
2716: }
2717: if ($helper->{'VARS'}->{'CONSTR_RESOURSE_URL'} eq 'yes') {
2718: $texversion=~s/(\\addcontentsline\{toc\}\{subsection\}\{[^\}]*\})/$1 URL: \\verb|$urlp| \\strut\\\\\\strut /;
2719: }
2720: $result.=$texversion;
2721:
2722: } elsif ($urlp=~/\.(sequence|page)$/) {
1.699 raeburn 2723:
1.459 foxr 2724: # header:
2725:
2726: $result.='\strut\newline\noindent Sequence/page '.$urlp.'\strut\newline\noindent\makebox[\textwidth/$number_of_columns][b]{\hrulefill}\newline\noindent ';
2727:
2728: # IF sequence, recurse:
1.699 raeburn 2729:
1.459 foxr 2730: if ($urlp =~ /\.sequence$/) {
1.699 raeburn 2731: $result .= &print_construction_sequence($urlp,
2732: $helper, %form,
1.459 foxr 2733: $LaTeXwidth);
2734: }
1.550 foxr 2735: }
2736: elsif ($urlp =~ /\.pdf$/i) {
1.552 foxr 2737: my $texversion;
2738: if ($member != 0) {
2739: $texversion .= '\cleardoublepage';
2740: }
2741:
2742: $texversion .= &include_pdf($urlp);
2743: $texversion = &latex_header_footer_remove($texversion);
2744: if ($member != $#order) {
2745: $texversion .= '\\ \cleardoublepage';
2746: }
1.699 raeburn 2747:
1.551 foxr 2748: $result .= $texversion;
1.550 foxr 2749: }
1.459 foxr 2750: }
1.650 raeburn 2751: if ($helper->{VARS}->{'construction'} eq '1') {$result=~s/(\\begin\{document})/$1 \\fbox\{RANDOM SEED IS $rndseed\} /;}
1.459 foxr 2752: return $result;
2753: }
2754:
1.590 foxr 2755: #
2756: # Top level for generating print output.
2757: #
2758: # May call print_resources if multiple resources will be printed.
2759: #
2760: # The main driver is $selectionmade which reflects the type of print out
2761: # requested:
2762: # Value Print type:
2763: # 1 Print resource that's being looked at.
2764: # 2 Print problems in a map or in a page.
2765: # 3 Print pages in a map or resources in a page.
2766: # 4 Print all problems or all resources.
2767: # 5 Print problems for seleted students.
2768: # 6 Print selected problems from a folder.
2769: # 7 Print print selected resources from some scope.
2770: # 8 Print resources for selected students.
2771: #
2772: #BZ 5209
2773: # 2 map_incomplete_problems_seq Print incomplete problems from the current
2774: # folder in student context.
1.591 foxr 2775: # 5 map_incomplete_problems_people_seq Print incomplete problems from the
1.590 foxr 2776: # current folder in privileged context.
1.591 foxr 2777: # 5 incomplete_problems_selpeople_course Print incomplete problems for
1.590 foxr 2778: # selected people from the entire course.
2779: #
2780: # Item 101 has much the same processing as 8,
2781: #
2782: # Differences: Item 101, 102 require per-student filtering of the resource
2783: # set so that only the incomplete resources are printed.
2784: # For item 100, filtering was done at the helper level.
2785:
1.177 sakharuk 2786: sub output_data {
1.621 foxr 2787:
1.184 sakharuk 2788: my ($r,$helper,$rparmhash) = @_;
2789: my %parmhash = %$rparmhash;
1.515 foxr 2790: $ssi_error = 0; # This will be set nonzero by failing ssi's.
1.459 foxr 2791: $resources_printed = '';
1.556 foxr 2792: $font_size = $helper->{'VARS'}->{'fontsize'};
1.590 foxr 2793: my $print_type = $helper->{'VARS'}->{'PRINT_TYPE'}; # Allows textual simplification.
1.499 foxr 2794: my $do_postprocessing = 1;
1.433 albertel 2795: my $js = <<ENDPART;
2796: <script type="text/javascript">
1.264 sakharuk 2797: var editbrowser;
2798: function openbrowser(formname,elementname,only,omit) {
2799: var url = '/res/?';
2800: if (editbrowser == null) {
2801: url += 'launch=1&';
2802: }
2803: url += 'catalogmode=interactive&';
2804: url += 'mode=parmset&';
2805: url += 'form=' + formname + '&';
2806: if (only != null) {
2807: url += 'only=' + only + '&';
1.699 raeburn 2808: }
1.264 sakharuk 2809: if (omit != null) {
2810: url += 'omit=' + omit + '&';
2811: }
2812: url += 'element=' + elementname + '';
2813: var title = 'Browser';
2814: var options = 'scrollbars=1,resizable=1,menubar=0';
2815: options += ',width=700,height=600';
2816: editbrowser = open(url,title,options,'1');
2817: editbrowser.focus();
2818: }
2819: </script>
1.140 sakharuk 2820: ENDPART
2821:
1.512 foxr 2822:
1.558 bisitz 2823: # Breadcrumbs
2824: #FIXME: Choose better/different breadcrumbs?!? Links?
2825: my $brcrum = [{'href' => '',
2826: 'text' => 'Helper'}, #FIXME: Different origin possible than print out helper?
2827: {'href' => '',
2828: 'text' => 'Preparing Printout'}];
2829:
2830: my $start_page = &Apache::loncommon::start_page('Preparing Printout',
2831: $js,
2832: {'bread_crumbs' => $brcrum,});
1.433 albertel 2833: my $msg = &mt('Please stand by while processing your print request, this may take some time ...');
1.363 foxr 2834:
1.433 albertel 2835: $r->print($start_page."\n<p>\n$msg\n</p>\n");
1.372 foxr 2836:
1.363 foxr 2837: # fetch the pagebreaks and store them in the course environment
2838: # The page breaks will be pulled into the hash %page_breaks which is
2839: # indexed by symb and contains 1's for each break.
2840:
1.373 albertel 2841: $env{'form.pagebreaks'} = $helper->{'VARS'}->{'FINISHPAGE'};
1.569 foxr 2842: &set_form_extraspace($helper);
1.699 raeburn 2843: $env{'form.lastprinttype'} = $print_type;
1.363 foxr 2844: &Apache::loncommon::store_course_settings('print',
1.366 foxr 2845: {'pagebreaks' => 'scalar',
1.569 foxr 2846: 'extraspace' => 'scalar',
1.570 foxr 2847: 'extraspace_units' => 'scalar',
1.366 foxr 2848: 'lastprinttype' => 'scalar'});
1.364 albertel 2849: my %page_breaks = &get_page_breaks($helper);
1.363 foxr 2850:
1.140 sakharuk 2851: my $format_from_helper = $helper->{'VARS'}->{'FORMAT'};
2852: my ($result,$selectionmade) = ('','');
2853: my $number_of_columns = 1; #used only for pages to determine the width of the cell
2854: my @temporary_array=split /\|/,$format_from_helper;
1.539 onken 2855: my ($laystyle,$numberofcolumns,$papersize,$pdfFormFields)=@temporary_array;
1.559 foxr 2856:
2857: $laystyle = &map_laystyle($laystyle);
1.177 sakharuk 2858: my ($textwidth,$textheight,$oddoffset,$evenoffset) = &page_format($papersize,$laystyle,$numberofcolumns);
1.373 albertel 2859: my $assignment = $env{'form.assignment'};
1.699 raeburn 2860: my $LaTeXwidth=&recalcto_mm($textwidth);
1.272 sakharuk 2861: my @print_array=();
1.274 sakharuk 2862: my @student_names=();
1.360 albertel 2863:
1.699 raeburn 2864:
1.688 raeburn 2865: # Common settings for the %form hash:
2866: # In some cases these settings get overridden by specific cases, but the
1.360 albertel 2867: # settings are common enough to make it worthwhile factoring them out
2868: # here.
2869: #
2870: my %form;
2871: $form{'grade_target'} = 'tex';
2872: $form{'textwidth'} = &get_textwidth($helper, $LaTeXwidth);
1.539 onken 2873: $form{'pdfFormFields'} = $pdfFormFields;
1.372 foxr 2874:
2875: # If form.showallfoils is set, then request all foils be shown:
1.699 raeburn 2876: # privilege will be enforced both by not allowing the
1.372 foxr 2877: # check box selecting this option to be presnt unless it's ok,
2878: # and by lonresponse's priv. check.
2879: # The if is here because lonresponse.pm only cares that
2880: # showallfoils is defined, not what the value is.
2881:
1.699 raeburn 2882: if ($helper->{'VARS'}->{'showallfoils'} eq "1") {
1.372 foxr 2883: $form{'showallfoils'} = $helper->{'VARS'}->{'showallfoils'};
2884: }
1.699 raeburn 2885:
1.504 albertel 2886: if ($helper->{'VARS'}->{'style_file'}=~/\w/) {
1.520 raeburn 2887: &Apache::lonnet::appenv({'construct.style' =>
2888: $helper->{'VARS'}->{'style_file'}});
1.504 albertel 2889: } elsif ($env{'construct.style'}) {
1.549 raeburn 2890: &Apache::lonnet::delenv('construct.style');
1.504 albertel 2891: }
2892:
1.590 foxr 2893: if ($print_type eq 'current_document') {
1.143 sakharuk 2894: #-- single document - problem, page, html, xml, ...
1.343 albertel 2895: my ($currentURL,$cleanURL);
1.375 foxr 2896:
1.162 sakharuk 2897: if ($helper->{'VARS'}->{'construction'} ne '1') {
1.185 sakharuk 2898: #prints published resource
1.153 sakharuk 2899: $currentURL=$helper->{'VARS'}->{'postdata'};
1.343 albertel 2900: $cleanURL=&Apache::lonenc::check_decrypt($currentURL);
1.143 sakharuk 2901: } else {
1.512 foxr 2902:
1.185 sakharuk 2903: #prints resource from the construction space
1.602 www 2904: $currentURL=$helper->{'VARS'}->{'filename'};
1.343 albertel 2905: $cleanURL=$currentURL;
1.143 sakharuk 2906: }
1.140 sakharuk 2907: $selectionmade = 1;
1.651 raeburn 2908:
1.413 albertel 2909: if ($cleanURL!~m|^/adm/|
1.557 foxr 2910: && $cleanURL=~/\.(problem|exam|quiz|assess|survey|form|library|xml|html|htm|xhtml|xhtm)$/) {
1.169 albertel 2911: my $rndseed=time;
1.242 sakharuk 2912: my $texversion='';
2913: if ($helper->{'VARS'}->{'ANSWER_TYPE'} ne 'only') {
2914: my %moreenv;
1.343 albertel 2915: $moreenv{'request.filename'}=$cleanURL;
1.290 sakharuk 2916: if ($helper->{'VARS'}->{'probstatus'} eq 'exam') {$form{'problemtype'}='exam';}
1.242 sakharuk 2917: $form{'problem_split'}=$parmhash{'problem_stream_switch'};
1.310 sakharuk 2918: $form{'suppress_tries'}=$parmhash{'suppress_tries'};
1.242 sakharuk 2919: $form{'latex_type'}=$helper->{'VARS'}->{'LATEX_TYPE'};
1.309 sakharuk 2920: $form{'print_discussions'}=$helper->{'VARS'}->{'PRINT_DISCUSSIONS'};
1.511 foxr 2921: $form{'print_annotations'}=$helper->{'VARS'}->{'PRINT_ANNOTATIONS'};
2922: if (($helper->{'VARS'}->{'PRINT_DISCUSSIONS'} eq 'yes') ||
2923: ($helper->{'VARS'}->{'PRINT_ANNOTATIONS'} eq 'yes')) {
2924: $form{'problem_split'}='yes';
2925: }
1.242 sakharuk 2926: if ($helper->{'VARS'}->{'curseed'}) {
2927: $rndseed=$helper->{'VARS'}->{'curseed'};
2928: }
2929: $form{'rndseed'}=$rndseed;
1.520 raeburn 2930: &Apache::lonnet::appenv(\%moreenv);
1.428 albertel 2931:
2932: &Apache::lonxml::clear_problem_counter();
2933:
1.375 foxr 2934: $resources_printed .= $currentURL.':';
1.515 foxr 2935: $texversion.=&ssi_with_retries($currentURL,$ssi_retry_count, %form);
1.428 albertel 2936:
1.511 foxr 2937: # Add annotations if required:
1.699 raeburn 2938:
1.428 albertel 2939: &Apache::lonxml::clear_problem_counter();
2940:
1.242 sakharuk 2941: &Apache::lonnet::delenv('request.filename');
1.230 albertel 2942: }
1.423 foxr 2943: # current document with answers.. no need to encap in minipage
2944: # since there's only one answer.
2945:
1.242 sakharuk 2946: if(($helper->{'VARS'}->{'ANSWER_TYPE'} eq 'no') ||
2947: ($helper->{'VARS'}->{'ANSWER_TYPE'} eq 'only')) {
1.602 www 2948:
1.353 foxr 2949: $form{'problem_split'}=$parmhash{'problem_stream_switch'};
1.166 albertel 2950: $form{'grade_target'}='answer';
1.167 albertel 2951: $form{'answer_output_mode'}='tex';
1.169 albertel 2952: $form{'rndseed'}=$rndseed;
1.401 albertel 2953: if ($helper->{'VARS'}->{'probstatus'} eq 'exam') {
2954: $form{'problemtype'}='exam';
2955: }
1.375 foxr 2956: $resources_printed .= $currentURL.':';
1.515 foxr 2957: my $answer=&ssi_with_retries($currentURL,$ssi_retry_count, %form);
1.511 foxr 2958:
2959:
1.242 sakharuk 2960: if ($helper->{'VARS'}->{'ANSWER_TYPE'} eq 'no') {
1.649 raeburn 2961: $texversion=~s/(\\keephidden\{ENDOFPROBLEM})/$answer$1/;
1.242 sakharuk 2962: } else {
2963: $texversion=&print_latex_header($helper->{'VARS'}->{'LATEX_TYPE'});
1.245 sakharuk 2964: if ($helper->{'VARS'}->{'construction'} ne '1') {
1.477 albertel 2965: my $title = &Apache::lonnet::gettitle($helper->{'VARS'}->{'symb'});
2966: $title = &Apache::lonxml::latex_special_symbols($title);
2967: $texversion.='\vskip 0 mm \noindent\textbf{'.$title.'}\vskip 0 mm ';
1.343 albertel 2968: $texversion.=&path_to_problem($cleanURL,$LaTeXwidth);
1.245 sakharuk 2969: } else {
1.602 www 2970: $texversion.='\vskip 0 mm \noindent\textbf{'.
1.633 raeburn 2971: &mt("Printing from Authoring Space: No Title").'}\vskip 0 mm ';
1.602 www 2972:
2973: $texversion.=&path_to_problem($cleanURL,$LaTeXwidth);
1.245 sakharuk 2974: }
1.242 sakharuk 2975: $texversion.='\vskip 1 mm '.$answer.'\end{document}';
2976: }
1.511 foxr 2977:
2978:
2979:
2980:
1.699 raeburn 2981:
1.511 foxr 2982: }
2983: # Print annotations.
2984:
2985:
2986: if ($helper->{'VARS'}->{'PRINT_ANNOTATIONS'} eq 'yes') {
2987: my $annotation .= &annotate($currentURL);
1.649 raeburn 2988: $texversion =~ s/(\\keephidden\{ENDOFPROBLEM})/$annotation$1/;
1.163 sakharuk 2989: }
1.511 foxr 2990:
2991:
1.214 sakharuk 2992: if ($helper->{'VARS'}->{'TABLE_INDEX'} eq 'yes') {
1.215 sakharuk 2993: $texversion=&IndexCreation($texversion,$currentURL);
1.214 sakharuk 2994: }
1.219 sakharuk 2995: if ($helper->{'VARS'}->{'CONSTR_RESOURSE_URL'} eq 'yes') {
2996: $texversion=~s/(\\addcontentsline\{toc\}\{subsection\}\{[^\}]*\})/$1 URL: \\verb|$currentURL| \\strut\\\\\\strut /;
2997:
2998: }
1.162 sakharuk 2999: $result .= $texversion;
3000: if ($currentURL=~m/\.page\s*$/) {
3001: ($result,$number_of_columns) = &page_cleanup($result);
3002: }
1.413 albertel 3003: } elsif ($cleanURL!~m|^/adm/|
1.557 foxr 3004: && $currentURL=~/\.(sequence|page)$/ && $helper->{'VARS'}->{'construction'} eq '1') {
1.459 foxr 3005: $result .= &print_construction_sequence($currentURL, $helper, %form,
3006: $LaTeXwidth);
1.699 raeburn 3007: $result .= '\end{document}';
1.459 foxr 3008: if (!($result =~ /\\begin\{document\}/)) {
3009: $result = &print_latex_header() . $result;
1.227 sakharuk 3010: }
1.459 foxr 3011: # End construction space sequence.
1.699 raeburn 3012: } elsif ($cleanURL=~/\/(smppg|syllabus|aboutme|bulletinboard|ext\.tool)$/) {
1.258 sakharuk 3013: $form{'latex_type'}=$helper->{'VARS'}->{'LATEX_TYPE'};
1.298 sakharuk 3014: if ($currentURL=~/\/syllabus$/) {$currentURL=~s/\/res//;}
1.660 raeburn 3015: if ($currentURL=~/\/ext\.tool$/) {$currentURL=~s/^\/adm\/wrapper//;}
1.375 foxr 3016: $resources_printed .= $currentURL.':';
1.567 foxr 3017: my $texversion = &ssi_with_retries($currentURL, $ssi_retry_count, %form);
1.511 foxr 3018: if ($helper->{'VARS'}->{'PRINT_ANNOTATIONS'} eq 'yes') {
3019: my $annotation = &annotate($currentURL);
1.649 raeburn 3020: $texversion =~ s/(\\end\{document})/$annotation$1/;
1.511 foxr 3021: }
1.258 sakharuk 3022: $result .= $texversion;
1.550 foxr 3023: } elsif ($cleanURL =~/\.tex$/) {
1.498 foxr 3024: # For this sort of print of a single LaTeX file,
3025: # We can just print the LaTeX file as it is uninterpreted in any way:
3026: #
3027:
3028: $result = &fetch_raw_resource($currentURL);
1.511 foxr 3029: if ($helper->{'VARS'}->{'PRINT_ANNOTATIONS'} eq 'yes') {
3030: my $annotation = &annotate($currentURL);
1.649 raeburn 3031: $result =~ s/(\\end\{document})/$annotation$1/;
1.511 foxr 3032: }
3033:
1.499 foxr 3034: $do_postprocessing = 0; # Don't massage the result.
1.498 foxr 3035:
1.550 foxr 3036: } elsif ($cleanURL =~ /\.pdf$/i) {
3037: $result .= &include_pdf($cleanURL);
1.551 foxr 3038: $result .= '\end{document}';
1.559 foxr 3039: } elsif ($cleanURL =~ /\.page$/i) { # Print page in non construction space contexts.
3040:
3041: # Determine the set of resources in the map of the page:
3042:
3043: my $navmap = Apache::lonnavmaps::navmap->new();
3044: my @page_resources = $navmap->retrieveResources($cleanURL);
3045: $result .= &print_page_in_course($helper, $rparmhash,
3046: $cleanURL, \@page_resources);
3047:
1.699 raeburn 3048:
1.162 sakharuk 3049: } else {
1.414 albertel 3050: $result.=&unsupported($currentURL,$helper->{'VARS'}->{'LATEX_TYPE'},
3051: $helper->{'VARS'}->{'symb'});
1.162 sakharuk 3052: }
1.590 foxr 3053: } elsif (($print_type eq 'map_problems') or
3054: ($print_type eq 'map_problems_in_page') or
3055: ($print_type eq 'map_resources_in_page') or
3056: ($print_type eq 'map_problems_pages') or
3057: ($print_type eq 'all_problems') or
3058: ($print_type eq 'all_resources') or # BUGBUG
3059: ($print_type eq 'select_sequences') or
3060: ($print_type eq 'map_incomplete_problems_seq')
1.582 raeburn 3061: ) {
1.699 raeburn 3062:
1.141 sakharuk 3063: #-- produce an output string
1.590 foxr 3064: if (($print_type eq 'map_problems') or
3065: ($print_type eq 'map_incomplete_problems_seq') or
3066: ($print_type eq 'map_problems_in_page') ) {
1.296 sakharuk 3067: $selectionmade = 2;
1.590 foxr 3068: } elsif (($print_type eq 'map_problems_pages') or
3069: ($print_type eq 'map_resources_in_page'))
1.562 foxr 3070: {
1.296 sakharuk 3071: $selectionmade = 3;
1.699 raeburn 3072: } elsif (($print_type eq 'all_problems')
1.536 foxr 3073: ) {
1.296 sakharuk 3074: $selectionmade = 4;
1.590 foxr 3075: } elsif ($print_type eq 'all_resources') { #BUGBUG
1.354 foxr 3076: $selectionmade = 4;
1.590 foxr 3077: } elsif ($print_type eq 'select_sequences') {
1.296 sakharuk 3078: $selectionmade = 7;
3079: }
1.590 foxr 3080:
1.193 sakharuk 3081: $form{'problem_split'}=$parmhash{'problem_stream_switch'};
1.310 sakharuk 3082: $form{'suppress_tries'}=$parmhash{'suppress_tries'};
1.203 sakharuk 3083: $form{'latex_type'}=$helper->{'VARS'}->{'LATEX_TYPE'};
1.309 sakharuk 3084: $form{'print_discussions'}=$helper->{'VARS'}->{'PRINT_DISCUSSIONS'};
1.511 foxr 3085: $form{'print_annotations'} = $helper->{'VARS'}->{'PRINT_ANNOTATIONS'};
3086: if (($helper->{'VARS'}->{'PRINT_DISCUSSIONS'} eq 'yes') ||
3087: ($helper->{'VARS'}->{'PRINT_ANNOTATIONS'} eq 'yes') ) {
3088: $form{'problem_split'}='yes';
3089: }
1.141 sakharuk 3090: my $flag_latex_header_remove = 'NO';
3091: my $flag_page_in_sequence = 'NO';
3092: my @master_seq=split /\|\|\|/, $helper->{'VARS'}->{'RESOURCES'};
1.193 sakharuk 3093: my $prevassignment='';
1.428 albertel 3094:
3095: &Apache::lonxml::clear_problem_counter();
3096:
1.141 sakharuk 3097: for (my $i=0;$i<=$#master_seq;$i++) {
1.350 foxr 3098:
1.521 foxr 3099: &Apache::lonenc::reset_enc();
3100:
1.350 foxr 3101: # Note due to document structure, not allowed to put \newpage
3102: # prior to the first resource
3103:
1.351 foxr 3104: if (defined $page_breaks{$master_seq[$i]}) {
1.350 foxr 3105: if($i != 0) {
3106: $result.="\\newpage\n";
3107: }
3108: }
1.569 foxr 3109: $result .= &get_extra_vspaces($helper, $master_seq[$i]);
1.564 foxr 3110: my ($sequence,$middle_thingy,$urlp)=&Apache::lonnet::decode_symb($master_seq[$i]);
1.237 albertel 3111: $urlp=&Apache::lonnet::clutter($urlp);
1.166 albertel 3112: $form{'symb'}=$master_seq[$i];
1.407 albertel 3113:
3114: my $assignment=&Apache::lonxml::latex_special_symbols(&Apache::lonnet::gettitle($sequence),'header'); #title of the assignment which contains this problem
1.521 foxr 3115:
1.267 sakharuk 3116: if ($selectionmade==7) {$helper->{VARS}->{'assignment'}=$assignment;}
1.247 sakharuk 3117: if ($i==0) {$prevassignment=$assignment;}
1.297 sakharuk 3118: my $texversion='';
1.413 albertel 3119: if ($urlp!~m|^/adm/|
3120: && $urlp=~/\.(problem|exam|quiz|assess|survey|form|library|page|xml|html|htm|xhtml|xhtm)$/) {
1.651 raeburn 3121: my $extension = $1;
1.375 foxr 3122: $resources_printed .= $urlp.':';
1.428 albertel 3123: &Apache::lonxml::remember_problem_counter();
1.566 foxr 3124: if ($flag_latex_header_remove eq 'NO') {
3125: $texversion.=&print_latex_header($helper->{'VARS'}->{'LATEX_TYPE'}); # RF
1.582 raeburn 3126: unless (($helper->{'VARS'}->{'ANSWER_TYPE'} eq 'only') ||
1.652 raeburn 3127: (($i==0) &&
1.582 raeburn 3128: (($urlp=~/\.page$/) ||
1.590 foxr 3129: ($print_type eq 'map_problems_in_page') ||
1.652 raeburn 3130: (($print_type eq 'map_resources_in_page') && ($extension !~ /^x?html?$/))))) {
1.582 raeburn 3131: $flag_latex_header_remove = 'YES';
3132: }
1.566 foxr 3133: }
1.515 foxr 3134: $texversion.=&ssi_with_retries($urlp, $ssi_retry_count, %form);
1.296 sakharuk 3135: if ($urlp=~/\.page$/) {
3136: ($texversion,my $number_of_columns_page) = &page_cleanup($texversion);
1.699 raeburn 3137: if ($number_of_columns_page > $number_of_columns) {$number_of_columns=$number_of_columns_page;}
1.649 raeburn 3138: $texversion =~ s/\\end\{document}\d*/\\end{document}/;
1.296 sakharuk 3139: $flag_page_in_sequence = 'YES';
1.582 raeburn 3140: }
1.428 albertel 3141:
1.296 sakharuk 3142: if(($helper->{'VARS'}->{'ANSWER_TYPE'} eq 'no') ||
3143: ($helper->{'VARS'}->{'ANSWER_TYPE'} eq 'only')) {
1.380 foxr 3144: # Don't permanently pervert the %form hash
3145: my %answerform = %form;
3146: $answerform{'grade_target'}='answer';
3147: $answerform{'answer_output_mode'}='tex';
1.375 foxr 3148: $resources_printed .= $urlp.':';
1.428 albertel 3149:
3150: &Apache::lonxml::restore_problem_counter();
1.515 foxr 3151: my $answer=&ssi_with_retries($urlp, $ssi_retry_count, %answerform);
1.582 raeburn 3152: if ($urlp =~ /\.page$/) {
1.649 raeburn 3153: $answer =~ s/\\end\{document}(\d*)$//;
1.582 raeburn 3154: }
1.296 sakharuk 3155: if ($helper->{'VARS'}->{'ANSWER_TYPE'} eq 'no') {
1.582 raeburn 3156: if ($urlp =~ /\.page$/) {
1.649 raeburn 3157: my @probs = split(/\\keephidden\{ENDOFPROBLEM}/,$texversion);
1.582 raeburn 3158: my $lastprob = pop(@probs);
3159: $texversion = join('\keephidden{ENDOFPROBLEM}',@probs).
3160: $answer.'\keephidden{ENDOFPROBLEM}'.$lastprob;
3161: } else {
1.649 raeburn 3162: $texversion=~s/(\\keephidden\{ENDOFPROBLEM})/$answer$1/;
1.582 raeburn 3163: }
1.249 sakharuk 3164: } else {
1.609 www 3165: if ($urlp=~/$LONCAPA::assess_page_re/) {
1.296 sakharuk 3166: $texversion=&print_latex_header($helper->{'VARS'}->{'LATEX_TYPE'});
1.649 raeburn 3167: # $texversion =~ s/\\begin\{document}//; # FIXME
1.477 albertel 3168: my $title = &Apache::lonnet::gettitle($master_seq[$i]);
3169: $title = &Apache::lonxml::latex_special_symbols($title);
3170: my $body ='\vskip 0 mm \noindent\textbf{'.$title.'}\vskip 0 mm ';
1.423 foxr 3171: $body .= &path_to_problem ($urlp,$LaTeXwidth);
3172: $body .='\vskip 1 mm '.$answer;
1.676 raeburn 3173: $body = &encapsulate_minipage($body,$answerform{'problem_split'});
1.423 foxr 3174: $texversion .= $body;
1.296 sakharuk 3175: } else {
3176: $texversion='';
3177: }
1.249 sakharuk 3178: }
1.511 foxr 3179:
1.246 sakharuk 3180: }
1.511 foxr 3181: if ($helper->{'VARS'}->{'PRINT_ANNOTATIONS'} eq 'yes') {
3182: my $annotation .= &annotate($urlp);
1.649 raeburn 3183: $texversion =~ s/(\\keephidden\{ENDOFPROBLEM})/$annotation$1/;
1.511 foxr 3184: }
3185:
1.296 sakharuk 3186: if ($flag_latex_header_remove ne 'NO') {
3187: $texversion = &latex_header_footer_remove($texversion);
3188: } else {
1.649 raeburn 3189: $texversion =~ s/\\end\{document}//;
1.296 sakharuk 3190: }
3191: if ($helper->{'VARS'}->{'TABLE_INDEX'} eq 'yes') {
3192: $texversion=&IndexCreation($texversion,$urlp);
3193: }
3194: if (($selectionmade == 4) and ($assignment ne $prevassignment)) {
3195: my $name = &get_name();
3196: my $courseidinfo = &get_course();
3197: $prevassignment=$assignment;
1.455 albertel 3198: my $header_text = $parmhash{'print_header_format'};
1.486 foxr 3199: $header_text = &format_page_header($textwidth, $header_text,
1.699 raeburn 3200: $assignment,
3201: $courseidinfo,
1.455 albertel 3202: $name);
1.417 foxr 3203: if ($numberofcolumns eq '1') {
1.455 albertel 3204: $result .='\newpage \noindent\parbox{\minipagewidth}{\noindent\\lhead{'.$header_text.'}} \vskip 5 mm ';
1.416 foxr 3205: } else {
1.455 albertel 3206: $result .='\newpage \noindent\parbox{\minipagewidth}{\noindent\\fancyhead[LO]{'.$header_text.'}} \vskip 5 mm ';
1.416 foxr 3207: }
1.296 sakharuk 3208: }
3209: $result .= $texversion;
1.699 raeburn 3210: $flag_latex_header_remove = 'YES';
3211: } elsif ($urlp=~/\/(smppg|syllabus|aboutme|bulletinboard|ext\.tool)$/) {
1.301 sakharuk 3212: $form{'latex_type'}=$helper->{'VARS'}->{'LATEX_TYPE'};
3213: if ($urlp=~/\/syllabus$/) {$urlp=~s/\/res//;}
1.660 raeburn 3214: if ($urlp=~/\/ext\.tool$/) {$urlp=~s/^\/adm\/wrapper//;}
1.375 foxr 3215: $resources_printed .= $urlp.':';
1.567 foxr 3216: my $texversion = &ssi_with_retries($urlp, $ssi_retry_count, %form);
1.511 foxr 3217: if ($helper->{'VARS'}->{'PRINT_ANNOTATIONS'} eq 'yes') {
3218: my $annotation = &annotate($urlp);
1.649 raeburn 3219: $texversion =~ s/(\\end\{document)/$annotation$1/;
1.511 foxr 3220: }
3221:
1.301 sakharuk 3222: if ($flag_latex_header_remove ne 'NO') {
3223: $texversion = &latex_header_footer_remove($texversion);
1.550 foxr 3224: } else {
1.649 raeburn 3225: $texversion =~ s/\\end\{document}/\\vskip 0\.5mm\\noindent\\makebox\[\\textwidth\/\$number_of_columns\]\[b\]\{\\hrulefill\}/;
1.301 sakharuk 3226: }
3227: $result .= $texversion;
1.699 raeburn 3228: $flag_latex_header_remove = 'YES';
1.550 foxr 3229: } elsif ($urlp=~ /\.pdf$/i) {
3230: if ($i > 0) {
3231: $result .= '\cleardoublepage';
3232: }
1.580 raeburn 3233: my $texfrompdf = &include_pdf($urlp);
3234: if ($flag_latex_header_remove ne 'NO') {
3235: $texfrompdf = &latex_header_footer_remove($texfrompdf);
3236: }
3237: $result .= $texfrompdf;
1.550 foxr 3238: if ($i != $#master_seq) {
3239: if ($numberofcolumns eq '1') {
3240: $result .= '\newpage';
3241: } else {
3242: # the \\'s seem to be needed to let LaTeX know there's something
3243: # on the page since LaTeX seems to not like to clear an empty page.
3244: #
3245: $result .= '\\ \cleardoublepage';
3246: }
3247: }
3248: $flag_latex_header_remove = 'YES';
3249:
1.141 sakharuk 3250: } else {
1.414 albertel 3251: $texversion=&unsupported($urlp,$helper->{'VARS'}->{'LATEX_TYPE'},
3252: $master_seq[$i]);
1.297 sakharuk 3253: if ($flag_latex_header_remove ne 'NO') {
3254: $texversion = &latex_header_footer_remove($texversion);
3255: } else {
1.649 raeburn 3256: $texversion =~ s/\\end\{document}//;
1.297 sakharuk 3257: }
3258: $result .= $texversion;
1.699 raeburn 3259: $flag_latex_header_remove = 'YES';
1.582 raeburn 3260: }
1.699 raeburn 3261: if (&Apache::loncommon::connection_aborted($r)) {
3262: last;
1.550 foxr 3263: }
1.141 sakharuk 3264: }
1.428 albertel 3265: &Apache::lonxml::clear_problem_counter();
1.344 foxr 3266: if ($flag_page_in_sequence eq 'YES') {
1.649 raeburn 3267: $result =~ s/\\usepackage\{calc}/\\usepackage{calc}\\usepackage{longtable}/;
1.344 foxr 3268: }
1.141 sakharuk 3269: $result .= '\end{document}';
1.590 foxr 3270: } elsif (($print_type eq 'problems_for_students') ||
3271: ($print_type eq 'problems_for_students_from_page') ||
3272: ($print_type eq 'all_problems_students') ||
1.591 foxr 3273: ($print_type eq 'resources_for_students') ||
3274: ($print_type eq 'incomplete_problems_selpeople_course') ||
1.679 raeburn 3275: ($print_type eq 'map_incomplete_problems_people_seq') ||
3276: ($print_type eq 'select_sequences_problems_for_students') ||
3277: ($print_type eq 'select_sequences_resources_for_students')) {
1.353 foxr 3278:
3279:
1.699 raeburn 3280: #-- prints assignments for whole class or for selected students
1.284 albertel 3281: my $type;
1.590 foxr 3282: if (($print_type eq 'problems_for_students') ||
3283: ($print_type eq 'problems_for_students_from_page') ||
1.591 foxr 3284: ($print_type eq 'all_problems_students') ||
3285: ($print_type eq 'incomplete_problems_selpeople_course') ||
1.679 raeburn 3286: ($print_type eq 'map_incomplete_problems_people_seq') ||
3287: ($print_type eq 'select_sequences_problems_for_students')) {
1.254 sakharuk 3288: $selectionmade=5;
1.284 albertel 3289: $type='problems';
1.679 raeburn 3290: } elsif (($print_type eq 'resources_for_students') ||
3291: ($print_type eq 'select_sequences_resources_for_students')) {
1.254 sakharuk 3292: $selectionmade=8;
1.284 albertel 3293: $type='resources';
1.254 sakharuk 3294: }
1.150 sakharuk 3295: my @students=split /\|\|\|/, $helper->{'VARS'}->{'STUDENTS'};
1.341 foxr 3296: # The normal sort order is by section then by students within the
3297: # section. If the helper var student_sort is 1, then the user has elected
3298: # to override this and output the students by name.
3299: # Each element of the students array is of the form:
3300: # username:domain:section:last, first:status
1.699 raeburn 3301: #
3302: # Note that student sort is not compatible with printing
1.429 foxr 3303: # 1 section per pdf...so that setting overrides.
1.699 raeburn 3304: #
3305: if (($helper->{'VARS'}->{'student_sort'} eq 1) &&
1.429 foxr 3306: ($helper->{'VARS'}->{'SPLIT_PDFS'} ne "sections")) {
1.341 foxr 3307: @students = sort compare_names @students;
1.618 foxr 3308: } else {
1.699 raeburn 3309: @students = sort compare_sections @students;
1.341 foxr 3310: }
1.429 foxr 3311: &adjust_number_to_print($helper);
3312:
1.278 albertel 3313: if ($helper->{'VARS'}->{'NUMBER_TO_PRINT'} eq '0' ||
3314: $helper->{'VARS'}->{'NUMBER_TO_PRINT'} eq 'all' ) {
3315: $helper->{'VARS'}->{'NUMBER_TO_PRINT'}=$#students+1;
3316: }
1.699 raeburn 3317: # If we are splitting on section boundaries, we need
3318: # to remember that in split_on_sections and
1.429 foxr 3319: # print all of the students in the list.
3320: #
3321: my $split_on_sections = 0;
3322: if ($helper->{'VARS'}->{'NUMBER_TO_PRINT'} eq 'section') {
3323: $split_on_sections = 1;
3324: $helper->{'VARS'}->{'NUMBER_TO_PRINT'} = $#students+1;
3325: }
1.150 sakharuk 3326: my @master_seq=split /\|\|\|/, $helper->{'VARS'}->{'RESOURCES'};
1.350 foxr 3327:
1.626 raeburn 3328: my $map;
3329: if ($helper->{VARS}->{'symb'}) {
1.687 raeburn 3330: unless ((($print_type eq 'all_problems_students') ||
3331: ($print_type eq 'incomplete_problems_selpeople_course')) &&
3332: $perm{'pfo'}) {
3333: ($map, my $id, my $resource) =
3334: &Apache::lonnet::decode_symb($helper->{VARS}->{'symb'});
3335: }
1.692 raeburn 3336: } elsif (($helper->{'VARS'}->{'postdata'} eq '/adm/navmaps') && ($perm{'pfo'})) {
3337: $map = $helper->{'VARS'}->{'SEQUENCE'};
1.626 raeburn 3338: }
3339:
1.150 sakharuk 3340: #loop over students
1.562 foxr 3341:
3342: my $flag_latex_header_remove = 'NO';
1.150 sakharuk 3343: my %moreenv;
1.330 sakharuk 3344: $moreenv{'instructor_comments'}='hide';
1.285 albertel 3345: $moreenv{'textwidth'}=&get_textwidth($helper,$LaTeXwidth);
1.309 sakharuk 3346: $moreenv{'print_discussions'}=$helper->{'VARS'}->{'PRINT_DISCUSSIONS'};
1.511 foxr 3347: $moreenv{'print_annotations'} = $helper->{'VARS'}->{'PRINT_ANNOTATIONS'};
1.353 foxr 3348: $moreenv{'problem_split'} = $parmhash{'problem_stream_switch'};
1.369 foxr 3349: $moreenv{'suppress_tries'} = $parmhash{'suppress_tries'};
1.511 foxr 3350: if (($helper->{'VARS'}->{'PRINT_DISCUSSIONS'} eq 'yes') ||
3351: ($helper->{'VARS'}->{'PRINT_ANNOTATIONS'} eq 'yes')) {
3352: $moreenv{'problem_split'}='yes';
3353: }
1.611 www 3354: my %prog_state=&Apache::lonhtmlcommon::Create_PrgWin($r,$#students+1);
1.272 sakharuk 3355: my $student_counter=-1;
1.429 foxr 3356: my $i = 0;
1.430 albertel 3357: my $last_section = (split(/:/,$students[0]))[2];
1.647 raeburn 3358: my $nohidemap;
3359: if ($perm{'pav'} && $perm{'vgr'}) {
3360: $nohidemap = 1;
3361: }
1.150 sakharuk 3362: foreach my $person (@students) {
1.373 albertel 3363: my $duefile="/home/httpd/prtspool/$env{'user.name'}_$env{'user.domain'}_printout.due";
1.311 sakharuk 3364: if (-e $duefile) {
3365: my $temp_file = Apache::File->new('>>'.$duefile);
3366: print $temp_file "1969\n";
3367: }
1.272 sakharuk 3368: $student_counter++;
1.429 foxr 3369: if ($split_on_sections) {
1.430 albertel 3370: my $this_section = (split(/:/,$person))[2];
1.429 foxr 3371: if ($this_section ne $last_section) {
3372: $i++;
3373: $last_section = $this_section;
3374: }
3375: } else {
3376: $i=int($student_counter/$helper->{'VARS'}{'NUMBER_TO_PRINT'});
3377: }
1.626 raeburn 3378: my $actual_seq = master_seq_to_person_seq($map, \@master_seq,
1.647 raeburn 3379: $person, undef, $nohidemap);
1.375 foxr 3380: my ($output,$fullname, $printed)=&print_resources($r,$helper,
1.353 foxr 3381: $person,$type,
1.595 foxr 3382: \%moreenv, $actual_seq,
1.360 albertel 3383: $flag_latex_header_remove,
1.422 albertel 3384: $LaTeXwidth);
1.375 foxr 3385: $resources_printed .= ":";
1.284 albertel 3386: $print_array[$i].=$output;
3387: $student_names[$i].=$person.':'.$fullname.'_END_';
1.581 bisitz 3388: # &Apache::lonhtmlcommon::Increment_PrgWin($r,\%prog_state,&mt('last student').' '.$fullname);
3389: &Apache::lonhtmlcommon::Increment_PrgWin($r,\%prog_state,'last student');
1.284 albertel 3390: $flag_latex_header_remove = 'YES';
1.331 albertel 3391: if (&Apache::loncommon::connection_aborted($r)) { last; }
1.284 albertel 3392: }
3393: &Apache::lonhtmlcommon::Close_PrgWin($r,\%prog_state);
3394: $result .= $print_array[0].' \end{document}';
1.590 foxr 3395: } elsif (($print_type eq 'problems_for_anon') ||
3396: ($print_type eq 'problems_for_anon_page') ||
1.679 raeburn 3397: ($print_type eq 'resources_for_anon') ||
3398: ($print_type eq 'select_sequences_problems_for_anon') ||
3399: ($print_type eq 'select_sequences_resources_for_anon')) {
1.373 albertel 3400: my $cdom =$env{'course.'.$env{'request.course.id'}.'.domain'};
3401: my $cnum =$env{'course.'.$env{'request.course.id'}.'.num'};
1.288 albertel 3402: my $num_todo=$helper->{'VARS'}->{'NUMBER_TO_PRINT_TOTAL'};
3403: my $code_name=$helper->{'VARS'}->{'ANON_CODE_STORAGE_NAME'};
1.292 albertel 3404: my $old_name=$helper->{'VARS'}->{'REUSE_OLD_CODES'};
1.385 foxr 3405: my $single_code = $helper->{'VARS'}->{'SINGLE_CODE'};
1.388 foxr 3406: my $selected_code = $helper->{'VARS'}->{'CODE_SELECTED_FROM_LIST'};
1.381 albertel 3407: my $code_option=$helper->{'VARS'}->{'CODE_OPTION'};
1.668 raeburn 3408: my @lines = &Apache::lonnet::get_scantronformat_file();
1.596 raeburn 3409: my ($code_type,$code_length,$bubbles_per_row)=('letter',6,10);
1.542 raeburn 3410: foreach my $line (@lines) {
1.678 raeburn 3411: next if (($line =~ /^\#/) || ($line eq ''));
1.699 raeburn 3412: my ($name,$type,$length,$bubbles_per_item) =
1.596 raeburn 3413: (split(/:/,$line))[0,2,4,17];
1.381 albertel 3414: if ($name eq $code_option) {
3415: $code_length=$length;
3416: if ($type eq 'number') { $code_type = 'number'; }
1.699 raeburn 3417: chomp($bubbles_per_item);
1.596 raeburn 3418: if (($bubbles_per_item ne '') && ($bubbles_per_item > 0)) {
1.699 raeburn 3419: $bubbles_per_row = $bubbles_per_item;
1.596 raeburn 3420: }
1.381 albertel 3421: }
3422: }
1.675 raeburn 3423: my $map;
1.625 raeburn 3424: if ($helper->{VARS}{'symb'}) {
1.626 raeburn 3425: ($map, my $id, my $resource) =
3426: &Apache::lonnet::decode_symb($helper->{VARS}{'symb'});
1.692 raeburn 3427: } elsif (($helper->{'VARS'}->{'postdata'} eq '/adm/navmaps') && ($perm{'pfo'})) {
3428: $map = $helper->{'VARS'}->{'SEQUENCE'};
1.625 raeburn 3429: }
1.288 albertel 3430: my %moreenv = ('textwidth' => &get_textwidth($helper,$LaTeXwidth));
1.353 foxr 3431: $moreenv{'problem_split'} = $parmhash{'problem_stream_switch'};
1.697 raeburn 3432: $moreenv{'suppress_tries'} = $parmhash{'suppress_tries'};
1.420 albertel 3433: $moreenv{'instructor_comments'}='hide';
1.596 raeburn 3434: $moreenv{'bubbles_per_row'} = $bubbles_per_row;
1.288 albertel 3435: my $seed=time+($$<<16)+($$);
1.292 albertel 3436: my @allcodes;
3437: if ($old_name) {
1.381 albertel 3438: my %result=&Apache::lonnet::get('CODEs',
3439: [$old_name,"type\0$old_name"],
3440: $cdom,$cnum);
3441: $code_type=$result{"type\0$old_name"};
1.292 albertel 3442: @allcodes=split(',',$result{$old_name});
1.336 albertel 3443: $num_todo=scalar(@allcodes);
1.389 foxr 3444: } elsif ($selected_code) { # Selection value is always numeric.
1.388 foxr 3445: $num_todo = 1;
3446: @allcodes = ($selected_code);
1.385 foxr 3447: } elsif ($single_code) {
3448:
1.387 foxr 3449: $num_todo = 1; # Unconditionally one code to do.
1.385 foxr 3450: # If an alpha code have to convert to numbers so it can be
3451: # converted back to letters again :-)
3452: #
3453: if ($code_type ne 'number') {
3454: $single_code = &letters_to_num($single_code);
3455: }
3456: @allcodes = ($single_code);
1.292 albertel 3457: } else {
3458: my %allcodes;
1.299 albertel 3459: srand($seed);
1.292 albertel 3460: for (my $i=0;$i<$num_todo;$i++) {
1.381 albertel 3461: $moreenv{'CODE'}=&get_CODE(\%allcodes,$i,$seed,$code_length,
3462: $code_type);
1.292 albertel 3463: }
1.645 raeburn 3464: $code_name =~ s/^\s+//;
3465: $code_name =~ s/\s+$//;
1.292 albertel 3466: if ($code_name) {
3467: &Apache::lonnet::put('CODEs',
1.381 albertel 3468: {
3469: $code_name =>join(',',keys(%allcodes)),
3470: "type\0$code_name" => $code_type
3471: },
1.292 albertel 3472: $cdom,$cnum);
3473: }
3474: @allcodes=keys(%allcodes);
3475: }
1.336 albertel 3476: my @master_seq=split /\|\|\|/, $helper->{'VARS'}->{'RESOURCES'};
1.590 foxr 3477: my ($type) = split(/_/,$print_type);
1.452 albertel 3478: &adjust_number_to_print($helper);
1.336 albertel 3479: my $number_per_page=$helper->{'VARS'}->{'NUMBER_TO_PRINT'};
1.587 foxr 3480: if ($number_per_page eq '0' || $number_per_page eq 'all'
3481: || $number_per_page eq 'section') {
3482: $number_per_page=$num_todo > 0 ? $num_todo : 1;
1.336 albertel 3483: }
1.699 raeburn 3484: my $flag_latex_header_remove = 'NO';
1.611 www 3485: my %prog_state=&Apache::lonhtmlcommon::Create_PrgWin($r,$num_todo);
1.295 albertel 3486: my $count=0;
1.647 raeburn 3487: my $nohidemap;
3488: if ($perm{'pav'} && $perm{'vgr'}) {
3489: $nohidemap = 1;
3490: }
1.292 albertel 3491: foreach my $code (sort(@allcodes)) {
1.295 albertel 3492: my $file_num=int($count/$number_per_page);
1.699 raeburn 3493: if ($code_type eq 'number') {
1.381 albertel 3494: $moreenv{'CODE'}=$code;
3495: } else {
3496: $moreenv{'CODE'}=&num_to_letters($code);
3497: }
1.675 raeburn 3498: $env{'form.CODE'} = $moreenv{'CODE'};
3499: my $actual_seq = master_seq_to_person_seq($map, \@master_seq,
3500: undef,
3501: $moreenv{'CODE'}, $nohidemap);
3502: delete($env{'form.CODE'});
1.375 foxr 3503: my ($output,$fullname, $printed)=
1.288 albertel 3504: &print_resources($r,$helper,'anonymous',$type,\%moreenv,
1.625 raeburn 3505: $actual_seq,$flag_latex_header_remove,
1.360 albertel 3506: $LaTeXwidth);
1.375 foxr 3507: $resources_printed .= ":";
1.295 albertel 3508: $print_array[$file_num].=$output;
1.288 albertel 3509: &Apache::lonhtmlcommon::Increment_PrgWin($r,\%prog_state,
3510: &mt('last assignment').' '.$fullname);
3511: $flag_latex_header_remove = 'YES';
1.295 albertel 3512: $count++;
1.331 albertel 3513: if (&Apache::loncommon::connection_aborted($r)) { last; }
1.288 albertel 3514: }
3515: &Apache::lonhtmlcommon::Close_PrgWin($r,\%prog_state);
3516: $result .= $print_array[0].' \end{document}';
1.665 raeburn 3517: } elsif ($print_type eq 'problems_from_directory') {
1.699 raeburn 3518: #prints selected problems from the subdirectory
1.151 sakharuk 3519: $selectionmade = 6;
3520: my @list_of_files=split /\|\|\|/, $helper->{'VARS'}->{'FILES'};
1.154 sakharuk 3521: @list_of_files=sort @list_of_files;
1.699 raeburn 3522: my $flag_latex_header_remove = 'NO';
1.175 sakharuk 3523: my $rndseed=time;
1.230 albertel 3524: if ($helper->{'VARS'}->{'curseed'}) {
3525: $rndseed=$helper->{'VARS'}->{'curseed'};
3526: }
1.151 sakharuk 3527: for (my $i=0;$i<=$#list_of_files;$i++) {
1.521 foxr 3528:
3529: &Apache::lonenc::reset_enc();
3530:
1.152 sakharuk 3531: my $urlp = $list_of_files[$i];
1.253 sakharuk 3532: $urlp=~s|//|/|;
1.152 sakharuk 3533: if ($urlp=~/\//) {
1.353 foxr 3534: $form{'problem_split'}=$parmhash{'problem_stream_switch'};
1.175 sakharuk 3535: $form{'rndseed'}=$rndseed;
1.603 www 3536: $urlp =~ s|^$Apache::lonnet::perlvar{'lonDocRoot'}||;
1.375 foxr 3537: $resources_printed .= $urlp.':';
1.515 foxr 3538: my $texversion=&ssi_with_retries($urlp, $ssi_retry_count, %form);
1.251 sakharuk 3539: if(($helper->{'VARS'}->{'ANSWER_TYPE'} eq 'no') ||
1.253 sakharuk 3540: ($helper->{'VARS'}->{'ANSWER_TYPE'} eq 'only')) {
1.380 foxr 3541: # Don't permanently pervert %form:
3542: my %answerform = %form;
3543: $answerform{'grade_target'}='answer';
3544: $answerform{'answer_output_mode'}='tex';
3545: $answerform{'latex_type'}=$helper->{'VARS'}->{'LATEX_TYPE'};
3546: $answerform{'rndseed'}=$rndseed;
1.375 foxr 3547: $resources_printed .= $urlp.':';
1.515 foxr 3548: my $answer=&ssi_with_retries($urlp, $ssi_retry_count, %answerform);
1.251 sakharuk 3549: if ($helper->{'VARS'}->{'ANSWER_TYPE'} eq 'no') {
1.649 raeburn 3550: $texversion=~s/(\\keephidden\{ENDOFPROBLEM})/$answer$1/;
1.251 sakharuk 3551: } else {
1.253 sakharuk 3552: $texversion=&print_latex_header($helper->{'VARS'}->{'LATEX_TYPE'});
3553: if ($helper->{'VARS'}->{'construction'} ne '1') {
3554: $texversion.='\vskip 0 mm \noindent ';
3555: $texversion.=&path_to_problem ($urlp,$LaTeXwidth);
3556: } else {
1.604 www 3557: $texversion.='\vskip 0 mm \noindent\textbf{'.
1.633 raeburn 3558: &mt("Printing from Authoring Space: No Title").'}\vskip 0 mm ';
1.604 www 3559: $texversion.=&path_to_problem ($urlp,$LaTeXwidth);
1.253 sakharuk 3560: }
3561: $texversion.='\vskip 1 mm '.$answer.'\end{document}';
1.251 sakharuk 3562: }
1.174 sakharuk 3563: }
1.515 foxr 3564: #this chunk is responsible for printing the path to problem
3565:
1.603 www 3566: my $newurlp=&path_to_problem($urlp,$LaTeXwidth);
1.649 raeburn 3567: $texversion =~ s/(\\begin\{minipage}\{\\textwidth})/$1 $newurlp/;
1.152 sakharuk 3568: if ($flag_latex_header_remove ne 'NO') {
3569: $texversion = &latex_header_footer_remove($texversion);
3570: } else {
1.649 raeburn 3571: $texversion =~ s/\\end\{document}//;
1.216 sakharuk 3572: }
3573: if ($helper->{'VARS'}->{'TABLE_INDEX'} eq 'yes') {
3574: $texversion=&IndexCreation($texversion,$urlp);
1.152 sakharuk 3575: }
1.219 sakharuk 3576: if ($helper->{'VARS'}->{'CONSTR_RESOURSE_URL'} eq 'yes') {
3577: $texversion=~s/(\\addcontentsline\{toc\}\{subsection\}\{[^\}]*\})/$1 URL: \\verb|$urlp| \\strut\\\\\\strut /;
1.699 raeburn 3578:
1.219 sakharuk 3579: }
1.152 sakharuk 3580: $result .= $texversion;
3581: }
1.699 raeburn 3582: $flag_latex_header_remove = 'YES';
1.151 sakharuk 3583: }
1.175 sakharuk 3584: if ($helper->{VARS}->{'construction'} eq '1') {$result=~s/(\\typeout)/ RANDOM SEED IS $rndseed $1/;}
1.152 sakharuk 3585: $result .= '\end{document}';
1.140 sakharuk 3586: }
3587: #-------------------------------------------------------- corrections for the different page formats
1.499 foxr 3588:
3589: # Only post process if that has not been turned off e.g. by a raw latex resource.
3590:
3591: if ($do_postprocessing) {
1.590 foxr 3592: $result = &page_format_transformation($papersize,
3593: $laystyle,$numberofcolumns,
3594: $print_type,$result,
3595: $helper->{VARS}->{'assignment'},
3596: $helper->{'VARS'}->{'TABLE_CONTENTS'},
3597: $helper->{'VARS'}->{'TABLE_INDEX'},
3598: $selectionmade);
1.499 foxr 3599: $result = &latex_corrections($number_of_columns,$result,$selectionmade,
3600: $helper->{'VARS'}->{'ANSWER_TYPE'});
3601: #if ($numberofcolumns == 1) {
1.451 albertel 3602: $result =~ s/\\textwidth\s*=\s*-?\d*\.?\d*\s*(cm|mm|in)/\\textwidth= $helper->{'VARS'}->{'pagesize.width'} $helper->{'VARS'}->{'pagesize.widthunit'} /;
3603: $result =~ s/\\textheight\s*=?\s*-?\d*\.?\d*\s*(cm|mm|in)/\\textheight $helper->{'VARS'}->{'pagesize.height'} $helper->{'VARS'}->{'pagesize.heightunit'} /;
3604: $result =~ s/\\evensidemargin\s*=\s*-?\d*\.?\d*\s*(cm|mm|in)/\\evensidemargin= $helper->{'VARS'}->{'pagesize.lmargin'} $helper->{'VARS'}->{'pagesize.lmarginunit'} /;
3605: $result =~ s/\\oddsidemargin\s*=\s*-?\d*\.?\d*\s*(cm|mm|in)/\\oddsidemargin= $helper->{'VARS'}->{'pagesize.lmargin'} $helper->{'VARS'}->{'pagesize.lmarginunit'} /;
1.499 foxr 3606: #}
3607: }
1.367 foxr 3608:
1.648 damieng 3609: # Set URLback so we can provide a link back to the resource and to change options.
3610: # (Since the browser back button does not currently work with https,
3611: # the back link is useful even when there is an easy-to-miss LON-CAPA back button.)
1.274 sakharuk 3612:
1.276 sakharuk 3613: my $URLback=''; #link to original document
1.510 albertel 3614: if ($helper->{'VARS'}->{'construction'} eq '1') {
1.607 www 3615: $URLback=$helper->{'VARS'}->{'filename'};
1.648 damieng 3616: } elsif ($helper->{VARS}{'symb'}) {
3617: my ($map, $id, $url) = &Apache::lonnet::decode_symb($helper->{VARS}{'symb'});
1.666 raeburn 3618: my $cdom =$env{'course.'.$env{'request.course.id'}.'.domain'};
3619: my $cnum =$env{'course.'.$env{'request.course.id'}.'.num'};
1.672 raeburn 3620: my ($anchor,$usehttp,$plainurl);
1.653 raeburn 3621: $url = &Apache::lonnet::clutter($url);
1.672 raeburn 3622: $plainurl = $url;
1.666 raeburn 3623: if (($ENV{'SERVER_PORT'} == 443) && ($env{'request.course.id'}) &&
3624: (($url =~ m{^\Q/public/$cdom/$cnum/syllabus\E($|\?)}) ||
3625: ($url =~ m{^\Q/adm/wrapper/ext/\E(?!https:)}))) {
1.673 raeburn 3626: unless ((&Apache::lonnet::uses_sts()) || (&Apache::lonnet::waf_allssl())) {
1.666 raeburn 3627: $usehttp = 1;
3628: }
3629: }
1.653 raeburn 3630: if ($env{'request.enc'}) {
1.699 raeburn 3631: $url = &Apache::lonenc::encrypted($url);
1.653 raeburn 3632: }
1.658 raeburn 3633: if ($url ne '') {
1.666 raeburn 3634: my $symb = $helper->{VARS}{'symb'};
3635: if ($url =~ m{^\Q/adm/wrapper/ext/\E}) {
3636: my $link = $url;
3637: ($link,$anchor) = ($url =~ /^([^\#]+)(?:|(\#[^\#]+))$/);
3638: if ($anchor) {
3639: ($symb) = ($helper->{VARS}{'symb'} =~ /^([^\#]+)/);
3640: }
3641: $url = $link;
3642: }
3643: $URLback = $url;
3644: if ($usehttp) {
3645: $URLback .= (($URLback =~ /\?/) ? '&':'?').'usehttp=1';
3646: }
1.672 raeburn 3647: unless ($plainurl =~ /\.page$/) {
3648: $URLback .= (($URLback =~ /\?/) ? '&':'?').'symb='.&escape($symb.$anchor);
3649: }
1.658 raeburn 3650: }
1.679 raeburn 3651: } elsif (($helper->{VARS}->{'postdata'} eq '/adm/navmaps') &&
3652: ($env{'request.course.id'})) {
3653: $URLback=$helper->{VARS}->{'postdata'};
1.276 sakharuk 3654: }
1.556 foxr 3655: #
3656: # Final adjustment of the font size:
3657: #
3658:
3659: $result = set_font_size($result);
1.375 foxr 3660:
1.612 foxr 3661: # Insert any babel headers required.
3662:
3663: $result = &collect_languages($result);
3664:
3665:
1.699 raeburn 3666: #-- writing .tex file in prtspool
1.525 www 3667: my $temp_file;
3668: my $identifier = &Apache::loncommon::get_cgi_id();
3669: my $filename = "/home/httpd/prtspool/$env{'user.name'}_$env{'user.domain'}_printout_$identifier.tex";
1.699 raeburn 3670: if (!($#print_array>0)) {
1.525 www 3671: unless ($temp_file = Apache::File->new('>'.$filename)) {
3672: $r->log_error("Couldn't open $filename for output $!");
1.699 raeburn 3673: return SERVER_ERROR;
1.525 www 3674: }
3675: print $temp_file $result;
3676: my $begin=index($result,'\begin{document}',0);
1.699 raeburn 3677: my $inc=substr($result,0,$begin+16);
1.515 foxr 3678: } else {
1.525 www 3679: my $begin=index($result,'\begin{document}',0);
3680: my $inc=substr($result,0,$begin+16);
3681: for (my $i=0;$i<=$#print_array;$i++) {
3682: if ($i==0) {
3683: $print_array[$i]=$result;
3684: } else {
3685: $print_array[$i].='\end{document}';
1.699 raeburn 3686: $print_array[$i] =
1.525 www 3687: &latex_corrections($number_of_columns,$print_array[$i],
1.699 raeburn 3688: $selectionmade,
1.525 www 3689: $helper->{'VARS'}->{'ANSWER_TYPE'});
1.699 raeburn 3690:
1.525 www 3691: my $anobegin=index($print_array[$i],'\setcounter{page}',0);
3692: substr($print_array[$i],0,$anobegin)='';
3693: $print_array[$i]=$inc.$print_array[$i];
3694: }
3695: my $temp_file;
3696: my $newfilename=$filename;
3697: my $num=$i+1;
1.699 raeburn 3698: $newfilename =~s/\.tex$//;
1.525 www 3699: $newfilename=sprintf("%s_%03d.tex",$newfilename, $num);
3700: unless ($temp_file = Apache::File->new('>'.$newfilename)) {
3701: $r->log_error("Couldn't open $newfilename for output $!");
1.699 raeburn 3702: return SERVER_ERROR;
1.525 www 3703: }
3704: print $temp_file $print_array[$i];
3705: }
3706: }
3707: my $student_names='';
3708: if ($#print_array>0) {
3709: for (my $i=0;$i<=$#print_array;$i++) {
3710: $student_names.=$student_names[$i].'_ENDPERSON_';
1.515 foxr 3711: }
1.525 www 3712: } else {
3713: if ($#student_names>-1) {
3714: $student_names=$student_names[0].'_ENDPERSON_';
1.515 foxr 3715: } else {
1.525 www 3716: my $fullname = &get_name($env{'user.name'},$env{'user.domain'});
3717: $student_names=join(':',$env{'user.name'},$env{'user.domain'},
1.515 foxr 3718: $env{'request.course.sec'},$fullname).
3719: '_ENDPERSON_'.'_END_';
3720: }
1.525 www 3721: }
1.515 foxr 3722:
1.525 www 3723: # logic for now is too complex to trace if this has been defined
3724: # yet.
3725: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
3726: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
3727: &Apache::lonnet::appenv({'cgi.'.$identifier.'.file' => $filename,
1.515 foxr 3728: 'cgi.'.$identifier.'.layout' => $laystyle,
3729: 'cgi.'.$identifier.'.numcol' => $numberofcolumns,
3730: 'cgi.'.$identifier.'.paper' => $papersize,
3731: 'cgi.'.$identifier.'.selection' => $selectionmade,
3732: 'cgi.'.$identifier.'.tableofcontents' => $helper->{'VARS'}->{'TABLE_CONTENTS'},
3733: 'cgi.'.$identifier.'.tableofindex' => $helper->{'VARS'}->{'TABLE_INDEX'},
3734: 'cgi.'.$identifier.'.role' => $perm{'pav'},
3735: 'cgi.'.$identifier.'.numberoffiles' => $#print_array,
3736: 'cgi.'.$identifier.'.studentnames' => $student_names,
1.655 raeburn 3737: 'cgi.'.$identifier.'.backref' => &escape($URLback),});
1.525 www 3738: &Apache::lonnet::appenv({"cgi.$identifier.user" => $env{'user.name'},
1.515 foxr 3739: "cgi.$identifier.domain" => $env{'user.domain'},
1.699 raeburn 3740: "cgi.$identifier.courseid" => $cnum,
3741: "cgi.$identifier.coursedom" => $cdom,
1.520 raeburn 3742: "cgi.$identifier.resources" => $resources_printed});
1.515 foxr 3743:
1.525 www 3744: my $end_page = &Apache::loncommon::end_page();
1.529 raeburn 3745: my $continue_text = &mt('Continue');
1.525 www 3746: # If there's been an unrecoverable SSI error, report it to the user
3747: if ($ssi_error) {
3748: my $helpurl = &Apache::loncommon::top_nav_help('Helpdesk');
1.554 bisitz 3749: $r->print('<br /><p class="LC_error">'.&mt('An unrecoverable network error occurred:').'</p><p>'.
1.526 www 3750: &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:').
3751: '<br />'.$ssi_last_error_resource.'<br />'.$ssi_last_error.
3752: '</p><p>'.&mt('You can continue using the link provided below, but make sure to carefully inspect your output file! The errors will be marked in the file.').'<br />'.
1.528 raeburn 3753: &mt('You may be able to reprint the individual resources for which this error occurred, as the issue may be temporary.').
1.525 www 3754: '<br />'.&mt('If the error persists, please contact the [_1] for assistance.',$helpurl).'</p><p>'.
3755: &mt('We apologize for the inconvenience.').'</p>'.
1.528 raeburn 3756: '<a href="/cgi-bin/printout.pl?'.$identifier.'">'.$continue_text.'</a>'.$end_page);
1.525 www 3757: } else {
1.515 foxr 3758: $r->print(<<FINALEND);
1.317 albertel 3759: <br />
1.288 albertel 3760: <meta http-equiv="Refresh" content="0; url=/cgi-bin/printout.pl?$identifier" />
1.528 raeburn 3761: <a href="/cgi-bin/printout.pl?$identifier">$continue_text</a>
1.431 albertel 3762: $end_page
1.140 sakharuk 3763: FINALEND
1.528 raeburn 3764: } # endif ssi errors.
1.140 sakharuk 3765: }
3766:
1.288 albertel 3767:
3768: sub get_CODE {
1.381 albertel 3769: my ($all_codes,$num,$seed,$size,$type)=@_;
1.288 albertel 3770: my $max='1'.'0'x$size;
3771: my $newcode;
3772: while(1) {
1.392 albertel 3773: $newcode=sprintf("%0".$size."d",int(rand($max)));
1.288 albertel 3774: if (!exists($$all_codes{$newcode})) {
3775: $$all_codes{$newcode}=1;
1.381 albertel 3776: if ($type eq 'number' ) {
3777: return $newcode;
3778: } else {
3779: return &num_to_letters($newcode);
3780: }
1.288 albertel 3781: }
3782: }
3783: }
1.140 sakharuk 3784:
1.284 albertel 3785: sub print_resources {
1.360 albertel 3786: my ($r,$helper,$person,$type,$moreenv,$master_seq,$remove_latex_header,
1.422 albertel 3787: $LaTeXwidth)=@_;
1.699 raeburn 3788: my $current_output = '';
1.375 foxr 3789: my $printed = '';
1.284 albertel 3790: my ($username,$userdomain,$usersection) = split /:/,$person;
3791: my $fullname = &get_name($username,$userdomain);
1.492 foxr 3792: my $namepostfix = "\\\\"; # Both anon and not anon should get the same vspace.
1.600 foxr 3793:
1.619 foxr 3794:
1.591 foxr 3795: #
3796: # Figure out if we need to filter the output by
3797: # the incomplete problems for that person
3798: #
3799: my $print_type = $helper->{'VARS'}->{'PRINT_TYPE'};
3800: my $print_incomplete = 0;
3801: if (($print_type eq 'map_incomplete_problems_people_seq') ||
3802: ($print_type eq 'incomplete_problems_selpeople_course')) {
3803: $print_incomplete = 1;
3804: }
1.596 raeburn 3805: if ($person eq 'anonymous') {
1.613 ramirez 3806: $namepostfix .=&mt('Name:')." ";
1.288 albertel 3807: $fullname = "CODE - ".$moreenv->{'CODE'};
3808: }
1.590 foxr 3809:
1.444 foxr 3810: # Fullname may have special latex characters that need \ prefixing:
3811: #
3812:
1.350 foxr 3813: my $i = 0;
1.591 foxr 3814: my $actually_printed = 0; # Count of resources printed.
1.699 raeburn 3815: #goes through all resources, checks if they are available for
3816: #current student, and produces output
1.428 albertel 3817:
3818: &Apache::lonxml::clear_problem_counter();
1.364 albertel 3819: my %page_breaks = &get_page_breaks($helper);
1.476 albertel 3820: my $columns_in_format = (split(/\|/,$helper->{'VARS'}->{'FORMAT'}))[1];
1.440 foxr 3821: #
1.699 raeburn 3822: # end each student with a
1.440 foxr 3823: # Special that allows the post processor to even out the page
3824: # counts later. Nasty problem this... it would be really
3825: # nice to put the special in as a postscript comment
1.441 foxr 3826: # e.g. \special{ps:\ENDOFSTUDENTSTAMP} unfortunately,
1.440 foxr 3827: # The special gets passed the \ and dvips puts it in the output file
1.689 raeburn 3828: # so we will just rely on printout.pl to strip ENDOFSTUDENTSTAMP from the
1.441 foxr 3829: # postscript. Each ENDOFSTUDENTSTAMP will go on a line by itself.
1.440 foxr 3830: #
1.591 foxr 3831:
1.568 foxr 3832: my $syllabus_first = 0;
1.619 foxr 3833: my $current_assignment = "";
3834: my $assignment;
3835: my $courseidinfo = &get_course();
1.643 raeburn 3836: my $possprint = scalar(@{$master_seq});
1.619 foxr 3837:
1.284 albertel 3838: foreach my $curresline (@{$master_seq}) {
1.351 foxr 3839: if (defined $page_breaks{$curresline}) {
1.350 foxr 3840: if($i != 0) {
3841: $current_output.= "\\newpage\n";
3842: }
3843: }
1.569 foxr 3844: $current_output .= &get_extra_vspaces($helper, $curresline);
1.350 foxr 3845: $i++;
1.619 foxr 3846: my ($map,$id,$res_url) = &Apache::lonnet::decode_symb($curresline);
3847:
3848: # See if we need to emit a new header:
3849:
1.699 raeburn 3850: if ( !($type eq 'problems' &&
1.609 www 3851: ($curresline!~ m/$LONCAPA::assess_page_re/)) ) {
1.591 foxr 3852: if ($print_incomplete && !&incomplete($username, $userdomain, $res_url)) {
3853: next;
3854: }
3855: $actually_printed++; # we're going to print one.
1.639 raeburn 3856:
1.284 albertel 3857: if (&Apache::lonnet::allowed('bre',$res_url)) {
1.414 albertel 3858: if ($res_url!~m|^ext/|
1.413 albertel 3859: && $res_url=~/\.(problem|exam|quiz|assess|survey|form|library|page|xml|html|htm|xhtml|xhtm)$/) {
1.375 foxr 3860: $printed .= $curresline.':';
1.699 raeburn 3861: &Apache::lonxml::remember_problem_counter();
1.428 albertel 3862:
1.526 www 3863: my $rendered = &get_student_view_with_retries($curresline,$ssi_retry_count,$username,$userdomain,$env{'request.course.id'},'tex',$moreenv);
1.582 raeburn 3864: if ($res_url =~ /\.page$/) {
3865: if ($remove_latex_header eq 'NO') {
3866: if (!($rendered =~ /\\begin\{document\}/)) {
3867: $rendered = &print_latex_header().$rendered;
3868: }
3869: }
1.591 foxr 3870: ;
1.582 raeburn 3871: if ($remove_latex_header eq 'YES') {
3872: $rendered = &latex_header_footer_remove($rendered);
3873: } else {
1.649 raeburn 3874: $rendered =~ s/\\end\{document}\d*//;
1.582 raeburn 3875: }
3876: }
1.305 sakharuk 3877: if(($helper->{'VARS'}->{'ANSWER_TYPE'} eq 'no') ||
3878: ($helper->{'VARS'}->{'ANSWER_TYPE'} eq 'only')) {
1.380 foxr 3879: # Use a copy of the hash so we don't pervert it on future loop passes.
3880: my %answerenv = %{$moreenv};
3881: $answerenv{'answer_output_mode'}='tex';
1.591 foxr 3882:
3883:
1.380 foxr 3884: $answerenv{'latex_type'}=$helper->{'VARS'}->{'LATEX_TYPE'};
1.428 albertel 3885:
3886: &Apache::lonxml::restore_problem_counter();
3887:
1.380 foxr 3888: my $ansrendered = &Apache::loncommon::get_student_answers($curresline,$username,$userdomain,$env{'request.course.id'},%answerenv);
1.428 albertel 3889:
1.305 sakharuk 3890: if ($helper->{'VARS'}->{'ANSWER_TYPE'} eq 'no') {
1.649 raeburn 3891: $rendered=~s/(\\keephidden\{ENDOFPROBLEM})/$ansrendered$1/;
1.305 sakharuk 3892: } else {
1.423 foxr 3893: my $header =&print_latex_header($helper->{'VARS'}->{'LATEX_TYPE'});
1.582 raeburn 3894: unless ($helper->{'VARS'}->{'ANSWER_TYPE'} eq 'only') {
1.649 raeburn 3895: $header =~ s/\\begin\{document}//; #<<<<<
1.582 raeburn 3896: }
1.477 albertel 3897: my $title = &Apache::lonnet::gettitle($curresline);
3898: $title = &Apache::lonxml::latex_special_symbols($title);
3899: my $body ='\vskip 0 mm \noindent\textbf{'.$title.'}\vskip 0 mm ';
3900: $body .=&path_to_problem($res_url,$LaTeXwidth);
1.423 foxr 3901: $body .='\vskip 1 mm '.$ansrendered;
1.676 raeburn 3902: $body = &encapsulate_minipage($body,$answerenv{'problem_split'});
1.423 foxr 3903: $rendered = $header.$body;
1.305 sakharuk 3904: }
3905: }
1.511 foxr 3906: if ($helper->{'VARS'}->{'PRINT_ANNOTATIONS'} eq 'yes') {
3907: my $url = &Apache::lonnet::clutter($res_url);
3908: my $annotation = &annotate($url);
1.649 raeburn 3909: $rendered =~ s/(\\keephidden\{ENDOFPROBLEM})/$annotation$1/;
1.511 foxr 3910: }
1.562 foxr 3911: my $junk;
1.305 sakharuk 3912: if ($remove_latex_header eq 'YES') {
3913: $rendered = &latex_header_footer_remove($rendered);
3914: } else {
1.649 raeburn 3915: $rendered =~ s/\\end\{document}//;
1.305 sakharuk 3916: }
1.699 raeburn 3917: $current_output .= $rendered;
1.660 raeburn 3918: } elsif ($res_url=~/\/(smppg|syllabus|aboutme|bulletinboard|ext\.tool)$/) {
1.568 foxr 3919: if ($i == 1) {
3920: $syllabus_first = 1;
3921: }
1.375 foxr 3922: $printed .= $curresline.':';
1.528 raeburn 3923: my $rendered = &get_student_view_with_retries($curresline,$ssi_retry_count,$username,$userdomain,$env{'request.course.id'},'tex',$moreenv);
1.511 foxr 3924: if ($helper->{'VARS'}->{'PRINT_ANNOTATIONS'} eq 'yes') {
3925: my $url = &Apache::lonnet::clutter($res_url);
3926: my $annotation = &annotate($url);
1.649 raeburn 3927: $annotation =~ s/(\\end\{document})/$annotation$1/;
1.511 foxr 3928: }
1.305 sakharuk 3929: if ($remove_latex_header eq 'YES') {
3930: $rendered = &latex_header_footer_remove($rendered);
1.284 albertel 3931: } else {
1.649 raeburn 3932: $rendered =~ s/\\end\{document}//;
1.284 albertel 3933: }
1.421 foxr 3934: $current_output .= $rendered.'\vskip 0.5mm\noindent\makebox[\textwidth/$number_of_columns][b]{\hrulefill}\strut \vskip 0 mm \strut ';
1.690 raeburn 3935: } elsif($res_url =~ /\.pdf$/) {
1.552 foxr 3936: my $url = &Apache::lonnet::clutter($res_url);
3937: my $rendered = &include_pdf($url);
3938: if ($remove_latex_header ne 'NO') {
3939: $rendered = &latex_header_footer_remove($rendered);
3940: }
3941: $current_output .= $rendered;
1.284 albertel 3942: } else {
1.414 albertel 3943: my $rendered = &unsupported($res_url,$helper->{'VARS'}->{'LATEX_TYPE'},$curresline);
1.305 sakharuk 3944: if ($remove_latex_header ne 'NO') {
3945: $rendered = &latex_header_footer_remove($rendered);
3946: } else {
1.649 raeburn 3947: $rendered =~ s/\\end\{document}//;
1.305 sakharuk 3948: }
3949: $current_output .= $rendered;
1.284 albertel 3950: }
3951: }
3952: $remove_latex_header = 'YES';
1.590 foxr 3953: }
1.619 foxr 3954: $assignment = &Apache::lonxml::latex_special_symbols(
3955: &Apache::lonnet::gettitle($map), 'header');
3956: if (($assignment ne $current_assignment) && ($assignment ne "")) {
3957: my $header_line = &format_page_header($LaTeXwidth, $parmhash{'print_header_format'},
1.699 raeburn 3958: $assignment, $courseidinfo,
1.619 foxr 3959: $fullname, $usersection);
3960: my $header_start = ($columns_in_format == 1) ? '\lhead'
3961: : '\fancyhead[LO]';
3962: $header_line = $header_start.'{'.$header_line.'}';
3963: $current_output = $current_output . $header_line;
3964: $current_assignment = $assignment;
3965: }
3966:
1.331 albertel 3967: if (&Apache::loncommon::connection_aborted($r)) { last; }
1.284 albertel 3968: }
1.591 foxr 3969: # If we are printing incomplete it's possible we don't have
3970: # anything to print. The print subsystem is not so good at handling
3971: # that so we're going to generate a stub that says there are no
3972: # incomplete resources for the person.
3973: #
1.593 foxr 3974:
1.591 foxr 3975: if ($actually_printed == 0) {
1.643 raeburn 3976: my $message = &mt('No resources to print');
3977: if (!$possprint) {
3978: if ($perm{'pav'} || $perm{'pfo'}) {
3979: $message = &mt('There are no unhidden resources to print.')."\n\n".
3980: &mt('The most likely reason is one of the following: ')."\n".
3981: '\begin{itemize}'."\n".
3982: '\item '.&mt("The 'Resource hidden from students' parameter is set for the folder being printed.")."\n".
3983: '\item '.&mt("'Hidden' is checked in the Course Editor individually for each resource in the folder being printed.")."\n".
3984: '\end{itemize}'."\n\n".
3985: &mt("Note: to print a bubblesheet exam which you want to hide from students, ".
3986: "use the Course Editor to check the 'Hidden' checkbox for the exam folder itself.")."\n";
3987: }
3988: } elsif ($print_incomplete) {
3989: $message = &mt('No incomplete resources');
3990: }
1.699 raeburn 3991: if ($message) {
1.676 raeburn 3992: $current_output = &encapsulate_minipage("\\vskip -10mm \n$message\n \\vskip 100 mm { }\n",$moreenv->{'problem_split'});
1.643 raeburn 3993: }
1.593 foxr 3994: if ($remove_latex_header eq "NO") {
3995: $current_output = &print_latex_header() . $current_output;
3996: } else {
3997: $current_output = &latex_header_footer_remove($current_output);
3998: }
1.591 foxr 3999: }
1.552 foxr 4000:
1.583 raeburn 4001: if ($syllabus_first) {
4002: $current_output =~ s/\\\\ Last updated:/Last updated:/
4003: }
1.642 raeburn 4004: my $currentassignment=&Apache::lonxml::latex_special_symbols($helper->{VARS}->{'assignment'},'header');
4005: my $header_line =
4006: &format_page_header($LaTeXwidth, $parmhash{'print_header_format'},
4007: $currentassignment, $courseidinfo, $fullname, $usersection);
4008: my $header_start = ($columns_in_format == 1) ? '\lhead' : '\fancyhead[LO]';
4009: my $newheader = $header_start.'{'.$header_line.'}';
1.583 raeburn 4010: if ($current_output=~/\\documentclass/) {
1.649 raeburn 4011: $current_output =~ s/\\begin\{document}/\\setlength{\\topmargin}{1cm} \\begin{document}\\noindent\\parbox{\\minipagewidth}{\\noindent$newheader$namepostfix}\\vskip 5 mm /;
1.619 foxr 4012:
1.284 albertel 4013: } else {
1.699 raeburn 4014: my $blankpages =
1.476 albertel 4015: '\clearpage\strut\clearpage'x$helper->{'VARS'}->{'EMPTY_PAGES'};
1.619 foxr 4016:
1.476 albertel 4017: $current_output = '\strut\vspace*{-6 mm}\\newline'.
4018: ©right_line().' \newpage '.$blankpages.$end_of_student.
1.639 raeburn 4019: '\setcounter{page}{1}\noindent\parbox{\minipagewidth}{\noindent'.
4020: $newheader.$namepostfix. '} \vskip 5 mm '.$current_output;
1.619 foxr 4021:
1.284 albertel 4022: }
1.440 foxr 4023: #
4024: # Close the student bracketing.
4025: #
1.375 foxr 4026: return ($current_output,$fullname, $printed);
1.284 albertel 4027:
4028: }
1.140 sakharuk 4029:
1.614 raeburn 4030: sub printing_blocked {
4031: my ($r,$blocktext) = @_;
4032: my $title = &mt('Preparing Printout');
4033: &Apache::lonhtmlcommon::clear_breadcrumbs();
4034: &Apache::lonhtmlcommon::add_breadcrumb({href=>'/adm/printout',
4035: text=> $title});
4036: my $breadcrumbs = &Apache::lonhtmlcommon::breadcrumbs($title);
4037: &Apache::loncommon::content_type($r,'text/html');
4038: &Apache::loncommon::no_cache($r);
4039: $r->send_http_header;
4040: $r->print(&Apache::loncommon::start_page('Preparing Printout').
4041: $breadcrumbs.
4042: $blocktext.
4043: &Apache::loncommon::end_page());
4044: return;
4045: }
4046:
1.3 sakharuk 4047: sub handler {
4048:
4049: my $r = shift;
1.614 raeburn 4050:
4051: if ($env{'request.course.id'}) {
4052: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
4053: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
1.674 raeburn 4054: my $clientip = &Apache::lonnet::get_requestor_ip($r);
1.699 raeburn 4055: my ($blocked,$blocktext) =
1.674 raeburn 4056: &Apache::loncommon::blocking_status('printout',$clientip,$cnum,$cdom);
1.614 raeburn 4057: if ($blocked) {
4058: my $checkrole = "cm./$cdom/$cnum";
4059: if ($env{'request.course.sec'} ne '') {
4060: $checkrole .= "/$env{'request.course.sec'}";
4061: }
1.699 raeburn 4062: unless ((&Apache::lonnet::allowed('evb',undef,undef,$checkrole)) &&
1.614 raeburn 4063: ($env{'request.role'} !~ m{^st\./$cdom/$cnum})) {
4064: &printing_blocked($r,$blocktext);
4065: return OK;
4066: }
4067: }
4068: }
1.699 raeburn 4069:
1.397 albertel 4070: &init_perm();
4071: my $helper = printHelper($r);
4072: if (!ref($helper)) {
4073: return $helper;
1.60 sakharuk 4074: }
1.699 raeburn 4075:
1.184 sakharuk 4076:
1.454 foxr 4077: %parmhash=&Apache::lonnet::coursedescription($env{'request.course.id'});
1.350 foxr 4078:
1.367 foxr 4079: # If a figure conversion queue file exists for this user.domain
4080: # we delete it since it can only be bad (if it were good, printout.pl
4081: # would have deleted it the last time around.
4082:
1.373 albertel 4083: my $conversion_queuefile = "/home/httpd/prtspool/$env{'user.name'}_$env{'user.domain'}_printout.dat";
1.367 foxr 4084: if(-e $conversion_queuefile) {
4085: unlink $conversion_queuefile;
4086: }
1.515 foxr 4087:
1.184 sakharuk 4088: &output_data($r,$helper,\%parmhash);
1.2 sakharuk 4089: return OK;
1.614 raeburn 4090: }
1.2 sakharuk 4091:
1.131 bowersj2 4092: use Apache::lonhelper;
1.130 sakharuk 4093:
1.223 bowersj2 4094: sub addMessage {
4095: my $text = shift;
4096: my $paramHash = Apache::lonhelper::getParamHash();
4097: $paramHash->{MESSAGE_TEXT} = $text;
4098: Apache::lonhelper::message->new();
4099: }
4100:
1.416 foxr 4101:
1.238 bowersj2 4102:
1.397 albertel 4103: sub init_perm {
4104: undef(%perm);
4105: $perm{'pav'}=&Apache::lonnet::allowed('pav',$env{'request.course.id'});
4106: if (!$perm{'pav'}) {
4107: $perm{'pav'}=&Apache::lonnet::allowed('pav',
4108: $env{'request.course.id'}.'/'.$env{'request.course.sec'});
4109: }
1.465 albertel 4110: $perm{'pfo'}=&Apache::lonnet::allowed('pfo',$env{'request.course.id'});
1.397 albertel 4111: if (!$perm{'pfo'}) {
4112: $perm{'pfo'}=&Apache::lonnet::allowed('pfo',
4113: $env{'request.course.id'}.'/'.$env{'request.course.sec'});
4114: }
1.585 raeburn 4115: $perm{'vgr'}=&Apache::lonnet::allowed('vgr',$env{'request.course.id'});
4116: if (!$perm{'vgr'}) {
4117: $perm{'vgr'}=&Apache::lonnet::allowed('vgr',
4118: $env{'request.course.id'}.'/'.$env{'request.course.sec'});
4119: }
1.397 albertel 4120: }
4121:
1.507 albertel 4122: sub get_randomly_ordered_warning {
4123: my ($helper,$map) = @_;
4124:
4125: my $message;
4126:
4127: my $postdata = $env{'form.postdata'} || $helper->{VARS}{'postdata'};
4128: my $navmap = Apache::lonnavmaps::navmap->new();
1.547 raeburn 4129: if (defined($navmap)) {
4130: my $res = $navmap->getResourceByUrl($map);
4131: if ($res) {
1.699 raeburn 4132: my $func =
1.547 raeburn 4133: sub { return ($_[0]->is_map() && $_[0]->randomorder); };
4134: my @matches = $navmap->retrieveResources($res, $func,1,1,1);
1.610 foxr 4135:
1.547 raeburn 4136: }
4137: } else {
1.699 raeburn 4138: $message = "Retrieval of information about ordering of resources failed.";
1.547 raeburn 4139: return '<message type="warning">'.$message.'</message>';
1.507 albertel 4140: }
4141: return;
4142: }
4143:
1.131 bowersj2 4144: sub printHelper {
1.115 bowersj2 4145: my $r = shift;
4146:
4147: if ($r->header_only) {
1.373 albertel 4148: if ($env{'browser.mathml'}) {
1.241 www 4149: &Apache::loncommon::content_type($r,'text/xml');
1.131 bowersj2 4150: } else {
1.241 www 4151: &Apache::loncommon::content_type($r,'text/html');
1.131 bowersj2 4152: }
4153: $r->send_http_header;
4154: return OK;
1.115 bowersj2 4155: }
4156:
1.131 bowersj2 4157: # Send header, nocache
1.373 albertel 4158: if ($env{'browser.mathml'}) {
1.241 www 4159: &Apache::loncommon::content_type($r,'text/xml');
1.115 bowersj2 4160: } else {
1.241 www 4161: &Apache::loncommon::content_type($r,'text/html');
1.115 bowersj2 4162: }
4163: &Apache::loncommon::no_cache($r);
4164: $r->send_http_header;
4165: $r->rflush();
4166:
1.131 bowersj2 4167: # Unfortunately, this helper is so complicated we have to
4168: # write it by hand
4169:
4170: Apache::loncommon::get_unprocessed_cgi($ENV{QUERY_STRING});
1.699 raeburn 4171:
1.176 bowersj2 4172: my $helper = Apache::lonhelper::helper->new("Printing Helper");
1.146 bowersj2 4173: $helper->declareVar('symb');
1.699 raeburn 4174: $helper->declareVar('postdata');
4175: $helper->declareVar('curseed');
4176: $helper->declareVar('probstatus');
1.156 bowersj2 4177: $helper->declareVar('filename');
4178: $helper->declareVar('construction');
1.178 sakharuk 4179: $helper->declareVar('assignment');
1.262 sakharuk 4180: $helper->declareVar('style_file');
1.340 foxr 4181: $helper->declareVar('student_sort');
1.363 foxr 4182: $helper->declareVar('FINISHPAGE');
1.366 foxr 4183: $helper->declareVar('PRINT_TYPE');
1.372 foxr 4184: $helper->declareVar("showallfoils");
1.483 foxr 4185: $helper->declareVar("STUDENTS");
1.569 foxr 4186: $helper->declareVar("EXTRASPACE");
1.518 foxr 4187:
1.699 raeburn 4188:
1.518 foxr 4189:
4190:
1.569 foxr 4191: # The page breaks and extra spaces
4192: # can get loaded initially from the course environment:
1.394 foxr 4193: # But we only do this in the initial state so that they are allowed to change.
4194: #
1.366 foxr 4195:
1.699 raeburn 4196:
1.363 foxr 4197: &Apache::loncommon::restore_course_settings('print',
1.366 foxr 4198: {'pagebreaks' => 'scalar',
1.569 foxr 4199: 'extraspace' => 'scalar',
1.570 foxr 4200: 'extraspace_units' => 'scalar',
1.366 foxr 4201: 'lastprinttype' => 'scalar'});
1.699 raeburn 4202:
1.483 foxr 4203: # This will persistently load in the data we want from the
4204: # very first screen.
1.699 raeburn 4205:
1.394 foxr 4206: if($helper->{VARS}->{PRINT_TYPE} eq $env{'form.lastprinttype'}) {
4207: if (!defined ($env{"form.CURRENT_STATE"})) {
1.699 raeburn 4208:
1.394 foxr 4209: $helper->{VARS}->{FINISHPAGE} = $env{'form.pagebreaks'};
1.569 foxr 4210: $helper->{VARS}->{EXTRASPACE} = $env{'form.extraspace'};
1.570 foxr 4211: $helper->{VARS}->{EXTRASPACE_UNITS} = $env{'form.extraspace_units'};
1.394 foxr 4212: } else {
4213: my $state = $env{"form.CURRENT_STATE"};
4214: if ($state eq "START") {
4215: $helper->{VARS}->{FINISHPAGE} = $env{'form.pagebreaks'};
1.569 foxr 4216: $helper->{VARS}->{EXTRASPACE} = $env{'form.extraspace'};
1.570 foxr 4217: $helper->{VARS}->{EXTRASPACE_UNITS} = $env{'form.extraspace_units'};
4218:
1.394 foxr 4219: }
4220: }
4221:
1.366 foxr 4222: }
1.481 albertel 4223:
1.156 bowersj2 4224: # Detect whether we're coming from construction space
1.602 www 4225: if ($env{'form.postdata'}=~m{^/priv}) {
4226: $helper->{VARS}->{'filename'} = $env{'form.postdata'};
1.156 bowersj2 4227: $helper->{VARS}->{'construction'} = 1;
1.481 albertel 4228: } else {
1.373 albertel 4229: if ($env{'form.postdata'}) {
1.679 raeburn 4230: unless ($env{'form.postdata'} eq '/adm/navmaps') {
4231: $helper->{VARS}->{'symb'} = &Apache::lonnet::symbread($env{'form.postdata'});
4232: }
1.482 albertel 4233: if ( $helper->{VARS}->{'symb'} eq '') {
4234: $helper->{VARS}->{'postdata'} = $env{'form.postdata'};
4235: }
1.156 bowersj2 4236: }
1.373 albertel 4237: if ($env{'form.symb'}) {
4238: $helper->{VARS}->{'symb'} = $env{'form.symb'};
1.156 bowersj2 4239: }
1.373 albertel 4240: if ($env{'form.url'}) {
1.685 raeburn 4241: unless ($env{'form.url'} eq '/adm/navmaps') {
4242: $helper->{VARS}->{'symb'} = &Apache::lonnet::symbread($helper->{VARS}->{'postdata'});
4243: }
1.156 bowersj2 4244: }
1.157 bowersj2 4245: }
1.481 albertel 4246:
1.667 raeburn 4247: if ($helper->{VARS}->{'symb'} ne '') {
4248: $helper->{VARS}->{'symb'}=
4249: &Apache::lonenc::check_encrypt($helper->{VARS}->{'symb'});
4250: }
1.679 raeburn 4251: my ($resourceTitle,$sequenceTitle,$mapTitle,$cdom,$cnum);
4252: if ($helper->{VARS}->{'postdata'} eq '/adm/navmaps') {
4253: $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
4254: $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
4255: if ($env{'course.'.$env{'request.course.id'}.'.url'} eq
4256: "uploaded/$cdom/$cnum/default.sequence") {
4257: my $navmap = Apache::lonnavmaps::navmap->new();
4258: if (ref($navmap)) {
4259: my @toplevelres = $navmap->retrieveResources('',sub { !(($_[0]->is_map()) || ($_[0]->src =~ /^\/adm\/navmaps/)) },0,0);
4260: if (@toplevelres) {
4261: my @printable;
4262: if ($perm{'pav'} || $perm{'pfo'}) {
4263: @printable = @toplevelres;
4264: } else {
4265: @printable = $navmap->retrieveResources(undef,sub { $_[0]->resprintable() },0,1);
4266: }
4267: if (@printable) {
4268: $sequenceTitle = 'Main Content';
4269: $mapTitle = $sequenceTitle;
4270: }
4271: }
4272: }
4273: }
4274: } else {
4275: ($resourceTitle,$sequenceTitle,$mapTitle) = &details_for_menu($helper);
4276: }
1.178 sakharuk 4277: if ($sequenceTitle ne '') {$helper->{VARS}->{'assignment'}=$sequenceTitle;}
1.481 albertel 4278:
1.146 bowersj2 4279: # Extract map
4280: my $symb = $helper->{VARS}->{'symb'};
1.156 bowersj2 4281: my ($map, $id, $url);
4282: my $subdir;
1.483 foxr 4283: my $is_published=0; # True when printing from resource space.
1.699 raeburn 4284: my $res_printable = 1; # By default the current resource is printable.
1.663 raeburn 4285: my $res_error;
1.589 foxr 4286: my $userCanPrint = ($perm{'pav'} || $perm{'pfo'});
1.615 foxr 4287: my $res_printstartdate;
4288: my $res_printenddate;
1.616 foxr 4289: my $map_open = 0;
4290: my $map_close = 0xffffffff;
4291: my $course_open = 0;
4292: my $course_close = 0xffffffff;
1.156 bowersj2 4293:
4294: # Get the resource name from construction space
4295: if ($helper->{VARS}->{'construction'}) {
1.699 raeburn 4296: $resourceTitle = substr($helper->{VARS}->{'filename'},
1.156 bowersj2 4297: rindex($helper->{VARS}->{'filename'}, '/')+1);
4298: $subdir = substr($helper->{VARS}->{'filename'},
4299: 0, rindex($helper->{VARS}->{'filename'}, '/') + 1);
1.481 albertel 4300: } else {
1.562 foxr 4301: # From course space:
4302:
1.482 albertel 4303: if ($symb ne '') {
4304: ($map, $id, $url) = &Apache::lonnet::decode_symb($symb);
1.699 raeburn 4305: $helper->{VARS}->{'postdata'} =
1.482 albertel 4306: &Apache::lonenc::check_encrypt(&Apache::lonnet::clutter($url));
1.679 raeburn 4307: } elsif (($helper->{VARS}->{'postdata'} eq '/adm/navmaps') &&
4308: ($env{'request.course.id'} ne '')) {
4309: if ($env{'course.'.$env{'request.course.id'}.'.url'} eq
4310: "uploaded/$cdom/$cnum/default.sequence") {
4311: $map = $env{'course.'.$env{'request.course.id'}.'.url'};
4312: $url = $helper->{VARS}->{'postdata'};
4313: }
4314: }
4315: if (($symb ne '') || ($map ne '')) {
1.663 raeburn 4316: if (!$userCanPrint) {
4317: my $navmap = Apache::lonnavmaps::navmap->new();
4318: if (ref($navmap)) {
1.679 raeburn 4319: my $res;
4320: if ($symb ne '') {
4321: $res = $navmap->getBySymb($symb);
4322: } elsif ($map ne '') {
4323: $res = $navmap->getResourceByUrl($map);
4324: }
1.663 raeburn 4325: if (ref($res)) {
4326: $res_printable = $res->resprintable(); #printability in course context
4327: ($res_printstartdate, $res_printenddate) = &get_print_dates($res);
4328: ($course_open, $course_close) = &course_print_dates($res);
4329: ($map_open, $map_close) = &map_print_dates($res);
4330: } else {
1.699 raeburn 4331: $res_error = 1;
1.663 raeburn 4332: }
4333: } else {
4334: $res_error = 1;
4335: }
4336: }
1.482 albertel 4337: } else {
1.589 foxr 4338: # Resource space.
4339:
1.482 albertel 4340: $url = $helper->{VARS}->{'postdata'};
1.483 foxr 4341: $is_published=1; # From resource space.
1.482 albertel 4342: }
4343: $url = &Apache::lonnet::clutter($url);
1.156 bowersj2 4344: if (!$resourceTitle) { # if the resource doesn't have a title, use the filename
1.238 bowersj2 4345: my $postdata = $helper->{VARS}->{'postdata'};
4346: $resourceTitle = substr($postdata, rindex($postdata, '/') + 1);
1.156 bowersj2 4347: }
1.679 raeburn 4348: if (($url eq '/adm/navmaps') && ($map eq $env{'course.'.$env{'request.course.id'}.'.url'})) {
4349: $res_printable=0;
4350: } else {
4351: $subdir = &Apache::lonnet::filelocation("", $url);
4352: }
1.589 foxr 4353:
4354:
1.128 bowersj2 4355: }
1.373 albertel 4356: if (!$helper->{VARS}->{'curseed'} && $env{'form.curseed'}) {
4357: $helper->{VARS}->{'curseed'}=$env{'form.curseed'};
1.230 albertel 4358: }
1.616 foxr 4359:
1.373 albertel 4360: if (!$helper->{VARS}->{'probstatus'} && $env{'form.problemtype'}) {
1.512 foxr 4361: $helper->{VARS}->{'probstatus'}=$env{'form.problemstatus'};
1.290 sakharuk 4362: }
1.115 bowersj2 4363:
1.192 bowersj2 4364: my $userCanSeeHidden = Apache::lonnavmaps::advancedUser();
4365:
1.481 albertel 4366: Apache::lonhelper::registerHelperTags();
1.119 bowersj2 4367:
1.131 bowersj2 4368: # "Delete everything after the last slash."
1.119 bowersj2 4369: $subdir =~ s|/[^/]+$||;
4370:
1.131 bowersj2 4371: # What can be printed is a very dynamic decision based on
4372: # lots of factors. So we need to dynamically build this list.
4373: # To prevent security leaks, states are only added to the wizard
4374: # if they can be reached, which ensures manipulating the form input
4375: # won't allow anyone to reach states they shouldn't have permission
4376: # to reach.
4377:
4378: # printChoices is tracking the kind of printing the user can
4379: # do, and will be used in a choices construction later.
4380: # In the meantime we will be adding states and elements to
4381: # the helper by hand.
4382: my $printChoices = [];
4383: my $paramHash;
1.130 sakharuk 4384:
1.589 foxr 4385: # If there is a current resource and it is printable
4386: # Give that as a choice.
4387:
4388: if ($resourceTitle && $res_printable) {
1.458 www 4389: push @{$printChoices}, ["<b><i>$resourceTitle</i></b> (".&mt('the resource you just saw on the screen').")", 'current_document', 'PAGESIZE'];
1.699 raeburn 4390: }
1.156 bowersj2 4391:
1.238 bowersj2 4392: # Useful filter strings
1.589 foxr 4393:
4394: my $isPrintable = ' && $res->resprintable()';
4395:
1.590 foxr 4396: my $isProblem = '(($res->is_problem()||$res->contains_problem() ||$res->is_practice()))';
1.589 foxr 4397: $isProblem .= $isPrintable unless $userCanPrint;
1.238 bowersj2 4398: $isProblem .= ' && !$res->randomout()' if !$userCanSeeHidden;
1.589 foxr 4399: my $isProblemOrMap = '($res->is_problem() || $res->contains_problem() || $res->is_sequence() || $res->is_practice())';
4400: $isProblemOrMap .= $isPrintable unless $userCanPrint;
4401: my $isNotMap = '(!$res->is_sequence())';
4402: $isNotMap .= $isPrintable unless $userCanPrint;
1.238 bowersj2 4403: $isNotMap .= ' && !$res->randomout()' if !$userCanSeeHidden;
1.589 foxr 4404: my $isMap = '$res->is_map()';
4405: $isMap .= $isPrintable unless $userCanPrint;
4406: my $symbFilter = '$res->shown_symb() ';
1.342 albertel 4407: my $urlValue = '$res->link()';
1.238 bowersj2 4408:
4409: $helper->declareVar('SEQUENCE');
4410:
1.465 albertel 4411: # If we're in a sequence...
1.416 foxr 4412:
1.465 albertel 4413: my $start_new_option;
4414: if ($perm{'pav'}) {
1.699 raeburn 4415: $start_new_option =
1.634 bisitz 4416: "<option text='".&mt('Start new page[_1]before selected','<br />').
1.569 foxr 4417: "' variable='FINISHPAGE' />".
1.634 bisitz 4418: "<option text='".&mt('Extra space[_1]before selected','<br />').
1.569 foxr 4419: "' variable='EXTRASPACE' type='text' />" .
4420: "<option " .
1.570 foxr 4421: "' variable='POSSIBLE_RESOURCES' type='hidden' />".
1.634 bisitz 4422: "<option text='".&mt('Space units[_1]check for mm','<br />').
1.570 foxr 4423: "' variable='EXTRASPACE_UNITS' type='checkbox' />"
4424: ;
1.465 albertel 4425: }
1.238 bowersj2 4426:
1.562 foxr 4427: # If not construction space user can print the components of a page:
4428:
4429: my $page_ispage;
4430: my $page_title;
4431: if (!$helper->{VARS}->{'construction'}) {
4432: my $varspostdata = $helper->{VARS}->{'postdata'};
4433: my $varsassignment = $helper->{VARS}->{'assignment'};
4434: my $page_navmap = Apache::lonnavmaps::navmap->new();
1.563 foxr 4435: if (defined($page_navmap)) {
4436: my @page_resources = $page_navmap->retrieveResources($url);
4437: if(defined($page_resources[0])) {
4438: $page_ispage = $page_resources[0]->is_page();
4439: $page_title = $page_resources[0]->title();
4440: my $resourcesymb = $page_resources[0]->symb();
4441: my ($pagemap, $pageid, $pageurl) = &Apache::lonnet::decode_symb($symb);
4442: if ($page_ispage) {
1.699 raeburn 4443: push @{$printChoices},
4444: [&mt('Selected [_1]Problems[_2] from page [_3]', '<b>', '</b>', '<b><i>'.$page_title.'</i></b>'),
4445: 'map_problems_in_page',
1.563 foxr 4446: 'CHOOSE_PROBLEMS_PAGE'];
1.699 raeburn 4447: push @{$printChoices},
4448: [&mt('Selected [_1]Resources[_2] from page [_3]', '<b>', '</b>', '<b><i>'.$page_title.'</i></b>'),
4449: 'map_resources_in_page',
1.563 foxr 4450: 'CHOOSE_RESOURCES_PAGE'];
4451: }
1.562 foxr 4452: my $helperFragment = &generate_resource_chooser('CHOOSE_PROBLEMS_PAGE',
4453: 'Select Problem(s) to print',
1.661 raeburn 4454: "multichoice='1' toponly='1' addstatus='1' closeallpages='1' modallink='1'",
1.562 foxr 4455: 'RESOURCES',
4456: 'PAGESIZE',
4457: $url,
4458: $isProblem, '', $symbFilter,
4459: $start_new_option);
4460:
4461:
4462: $helperFragment .= &generate_resource_chooser('CHOOSE_RESOURCES_PAGE',
4463: 'Select Resource(s) to print',
1.679 raeburn 4464: 'multichoice="1" toponly="1" addstatus="1" closeallpages="1" modallink="1" suppressNavmap="1"',
1.562 foxr 4465: 'RESOURCES',
4466: 'PAGESIZE',
4467: $url,
4468: $isNotMap, '', $symbFilter,
4469: $start_new_option);
4470:
1.679 raeburn 4471:
1.562 foxr 4472:
4473:
4474:
4475: &Apache::lonxml::xmlparse($r, 'helper', $helperFragment);
4476:
1.563 foxr 4477: }
4478: }
1.562 foxr 4479: }
4480:
4481: if (($helper->{'VAR'}->{'construction'} ne '1' ) &&
1.243 bowersj2 4482: $helper->{VARS}->{'postdata'} &&
4483: $helper->{VARS}->{'assignment'}) {
1.590 foxr 4484:
4485: # BZ 5209 - Print incomplete problems from sequence:
4486: # the exact form of this depends on whether or not we are privileged or a mere
4487: # plebe of s student:
4488:
1.679 raeburn 4489: my $optionText = '';
1.590 foxr 4490: my $printSelector = 'map_incomplete_problems_seq';
4491: my $nextState = 'CHOOSE_INCOMPLETE_SEQ';
4492: my $textSuffix = '';
1.679 raeburn 4493: my $nocurrloc = '';
4494: if ($helper->{VARS}->{'postdata'} eq '/adm/navmaps') {
4495: $nocurrloc = 1;
4496: }
1.590 foxr 4497:
1.616 foxr 4498: if ($userCanPrint) {
1.590 foxr 4499: $printSelector = 'map_incomplete_problems_people_seq';
4500: $nextState = 'CHOOSE_INCOMPLETE_PEOPLE_SEQ';
4501: $textSuffix = ' for selected students';
4502: my $helperStates =
1.699 raeburn 4503: &create_incomplete_folder_selstud_helper($helper, $map, $nocurrloc);
1.590 foxr 4504: &Apache::lonxml::xmlparse($r, 'helper', $helperStates);
4505: } else {
1.616 foxr 4506: if (&printable($map_open, $map_close)) {
1.679 raeburn 4507: my $helperStates = &create_incomplete_folder_helper($helper, $map, $nocurrloc); # Create needed states for student.
1.616 foxr 4508: &Apache::lonxml::xmlparse($r, 'helper', $helperStates);
4509: } else {
4510: # TODO: Figure out how to break the news...this folder is not printable.
4511: }
1.590 foxr 4512: }
4513:
1.616 foxr 4514: if ($userCanPrint || &printable($map_open, $map_close)) {
1.679 raeburn 4515: if ($helper->{VARS}->{'postdata'} eq '/adm/navmaps') {
4516: $optionText = &mt('Selected [_1]Incomplete Problems[_2] [_3]not in a folder[_4]' . $textSuffix,
4517: '<b>','</b>','<i>','</i>');
4518: } else {
1.686 raeburn 4519: $optionText = &mt('Selected [_1]Incomplete Problems[_2] from folder [_3]' . $textSuffix,
1.679 raeburn 4520: '<b>','</b>','<b><i>'.$sequenceTitle.'</b></i>');
4521: }
1.616 foxr 4522: push(@{$printChoices},
1.679 raeburn 4523: [$optionText,
1.616 foxr 4524: $printSelector,
4525: $nextState]);
4526: }
1.131 bowersj2 4527: # Allow problems from sequence
1.616 foxr 4528: if ($userCanPrint || &printable($map_open, $map_close)) {
1.679 raeburn 4529: if ($helper->{VARS}->{'postdata'} eq '/adm/navmaps') {
4530: $optionText = &mt('Selected [_1]Problems[_2] [_3]not in a folder[_4]','<b>','</b>','<i>','</i>');
4531: } else {
4532: $optionText = &mt('Selected [_1]Problems[_2] from folder [_3]','<b>','</b>','<b><i>'.$sequenceTitle.'</i></b>');
4533: }
1.699 raeburn 4534: push @{$printChoices},
4535: [$optionText,
4536: 'map_problems',
1.562 foxr 4537: 'CHOOSE_PROBLEMS'];
1.616 foxr 4538: # Allow all resources from sequence
1.679 raeburn 4539: if ($helper->{VARS}->{'postdata'} eq '/adm/navmaps') {
4540: $optionText = &mt('Selected [_1]Resources[_2] [_3]not in a folder[_4]','<b>','</b>','<i>','</i>');
4541: } else {
4542: $optionText = &mt('Selected [_1]Resources[_2] from folder [_3]','<b>','</b>','<b><i>'.$sequenceTitle.'</i></b>');
4543: }
1.699 raeburn 4544: push @{$printChoices}, [$optionText,
4545: 'map_problems_pages',
1.616 foxr 4546: 'CHOOSE_PROBLEMS_HTML'];
4547: my $helperFragment = &generate_resource_chooser('CHOOSE_PROBLEMS',
4548: 'Select Problem(s) to print',
1.679 raeburn 4549: 'multichoice="1" toponly="1" addstatus="1" closeallpages="1" modallink="1" nocurrloc="'.$nocurrloc.'"',
1.616 foxr 4550: 'RESOURCES',
4551: 'PAGESIZE',
4552: $map,
1.621 foxr 4553: $isProblem, '',
1.616 foxr 4554: $symbFilter,
4555: $start_new_option);
4556: $helperFragment .= &generate_resource_chooser('CHOOSE_PROBLEMS_HTML',
4557: 'Select Resource(s) to print',
1.679 raeburn 4558: 'multichoice="1" toponly="1" addstatus="1" closeallpages="1" modallink="1" nocurrloc="'.$nocurrloc.'" suppressNavmap="1"',
1.616 foxr 4559: 'RESOURCES',
4560: 'PAGESIZE',
4561: $map,
4562: $isNotMap, '',
4563: $symbFilter,
4564: $start_new_option);
1.699 raeburn 4565:
1.616 foxr 4566: &Apache::lonxml::xmlparse($r, 'helper', $helperFragment);
4567: } else {
4568: # TODO: Figure out how to tell them the folder is not printable.
4569: }
1.121 bowersj2 4570: }
1.699 raeburn 4571: # If the user has pfo (print for others) allow them to print all
1.616 foxr 4572: # problems and resources in the entire course, optionally for selected students
4573: my $post_data = $helper->{VARS}->{'postdata'};
1.699 raeburn 4574:
1.483 foxr 4575: if ($perm{'pfo'} && !$is_published &&
1.679 raeburn 4576: ($post_data=~/\/res\// || $post_data =~/\/(syllabus|smppg|aboutme|bulletinboard)$/)) {
1.481 albertel 4577:
1.590 foxr 4578: # BZ 5209 - incomplete problems from entire course:
4579:
4580: push(@{$printChoices},
1.683 raeburn 4581: [&mt('Selected [_1]Incomplete Problems[_2] from [_3]entire course[_4] for [_5]selected people[_6]',
4582: '<b>','</b>','<b>','</b>','<b>','</b>'),
1.590 foxr 4583: 'incomplete_problems_selpeople_course', 'INCOMPLETE_PROBLEMS_COURSE_RESOURCES']);
4584: my $helperFragment = &create_incomplete_course_helper($helper); # Create needed states.
4585:
4586: &Apache::lonxml::xmlparse($r, 'helper', $helperFragment);
4587:
4588: # Selected problems/resources from entire course:
4589:
1.683 raeburn 4590: push @{$printChoices}, [&mt('Selected [_1]Problems[_2] from [_3]entire course[_4]','<b>','</b>','<b>','</b>'), 'all_problems', 'ALL_PROBLEMS'];
4591: push @{$printChoices}, [&mt('Selected [_1]Resources[_2] from [_3]entire course[_4]','<b>','</b>','<b>','</b>'), 'all_resources', 'ALL_RESOURCES'];
4592: push @{$printChoices}, [&mt('Selected [_1]Problems[_2] from [_3]entire course[_4] for [_5]selected people[_6]','<b>','</b>','<b>','</b>','<b>','</b>'), 'all_problems_students', 'ALL_PROBLEMS_STUDENTS'];
1.562 foxr 4593: my $suffixXml = <<ALL_PROBLEMS;
1.536 foxr 4594: <state name="STUDENTS1" title="Select People">
4595: <message><b>Select sorting order of printout</b> </message>
4596: <choices variable='student_sort'>
4597: <choice computer='0'>Sort by section then student</choice>
4598: <choice computer='1'>Sort by students across sections.</choice>
4599: </choices>
4600: <message><br /><hr /><br /> </message>
4601: <student multichoice='1' variable="STUDENTS" nextstate="PRINT_FORMATTING" coursepersonnel="1"/>
4602: </state>
1.284 albertel 4603: ALL_PROBLEMS
1.699 raeburn 4604: &Apache::lonxml::xmlparse($r, 'helper',
1.562 foxr 4605: &generate_resource_chooser('ALL_PROBLEMS',
1.635 bisitz 4606: 'Select Problem(s) to print',
1.661 raeburn 4607: 'multichoice="1" suppressEmptySequences="0" addstatus="1" closeallpages="1" modallink="1"',
1.562 foxr 4608: 'RESOURCES',
4609: 'PAGESIZE',
4610: '',
4611: $isProblemOrMap, $isNotMap,
4612: $symbFilter,
4613: $start_new_option) .
4614: &generate_resource_chooser('ALL_RESOURCES',
4615: 'Select Resource(s) to print',
1.679 raeburn 4616: 'toponly="0" multichoice="1" suppressEmptySequences="0" addstatus="1" closeallpages="1" modallink="1" suppressNavmap="1"',
1.562 foxr 4617: 'RESOURCES',
4618: 'PAGESIZE',
4619: '',
4620: $isNotMap,'',$symbFilter,
4621: $start_new_option) .
4622: &generate_resource_chooser('ALL_PROBLEMS_STUDENTS',
4623: 'Select Problem(s) to print',
1.661 raeburn 4624: 'toponly="0" multichoice="1" suppressEmptySequences="0" addstatus="1" closeallpages="1" modallink="1"',
1.562 foxr 4625: 'RESOURCES',
4626: 'STUDENTS1',
4627: '',
4628: $isProblemOrMap,'' , $symbFilter,
4629: $start_new_option) .
4630: $suffixXml
4631: );
1.132 bowersj2 4632:
1.284 albertel 4633: if ($helper->{VARS}->{'assignment'}) {
1.562 foxr 4634:
4635: # If we were looking at a page, allow a selection of problems from the page
4636: # either for selected students or for coded assignments.
4637:
4638: if ($page_ispage) {
4639: push @{$printChoices}, [&mt('Selected [_1]Problems[_2] from page [_3] for [_4]selected people[_5]',
4640: '<b>', '</b>', '<b><i>'.$page_title.'</i></b>', '<b>', '</b>'),
4641: 'problems_for_students_from_page', 'CHOOSE_TGT_STUDENTS_PAGE'];
4642: push @{$printChoices}, [&mt('Selected [_1]Problems[_2] from page [_3] for [_4]CODEd assignments[_5]',
4643: '<b>', '</b>', '<b><i>'.$page_title.'</i></b>', '<b>', '</b>'),
4644: 'problems_for_anon_page', 'CHOOSE_ANON1_PAGE'];
4645: }
4646: push @{$printChoices}, [&mt('Selected [_1]Problems[_2] from folder [_3] for [_4]selected people[_5]',
1.699 raeburn 4647: '<b>','</b>','<b><i>'.$sequenceTitle.'</i></b>','<b>','</b>'),
1.562 foxr 4648: 'problems_for_students', 'CHOOSE_STUDENTS'];
4649: push @{$printChoices}, [&mt('Selected [_1]Problems[_2] from folder [_3] for [_4]CODEd assignments[_5]',
1.699 raeburn 4650: '<b>','</b>','<b><i>'.$sequenceTitle.'</i></b>','<b>','</b>'),
1.562 foxr 4651: 'problems_for_anon', 'CHOOSE_ANON1'];
1.284 albertel 4652: }
1.424 foxr 4653:
1.679 raeburn 4654: my ($randomly_ordered_warning,$codechoice,$code_selection,$namechoice) =
4655: &generate_common_choosers($r,$helper,$map,$url,$isProblem,$symbFilter,$start_new_option);
1.272 sakharuk 4656:
1.254 sakharuk 4657: if ($helper->{VARS}->{'assignment'}) {
1.590 foxr 4658:
4659: # Assignment printing:
4660:
1.546 bisitz 4661: 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'];
4662: 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'];
1.254 sakharuk 4663: }
1.284 albertel 4664:
1.679 raeburn 4665: # resource_selector will hold a few states that:
4666: # - Allow resources to be selected for printing.
4667: # - Determine pagination between assignments.
4668: # - Determine how many assignments should be bundled into a single PDF.
4669: # TODO:
4670: # Probably good to do things like separate this up into several vars, each
4671: # with one state, and use REGEXPs at inclusion time to set state names
4672: # and next states for better mix and match capability
4673: #
4674:
4675: my $resource_selector=<<RESOURCE_SELECTOR;
1.424 foxr 4676: <state name="SELECT_RESOURCES" title="Select Resources">
1.507 albertel 4677: $randomly_ordered_warning
1.424 foxr 4678: <nextstate>PRINT_FORMATTING</nextstate>
1.254 sakharuk 4679: <message><br /><big><i><b>Select resources for the assignment</b></i></big><br /></message>
1.699 raeburn 4680: <resource variable="RESOURCES" multichoice="1" addstatus="1"
1.661 raeburn 4681: closeallpages="1" modallink="1">
1.254 sakharuk 4682: <filterfunc>return $isNotMap;</filterfunc>
4683: <mapurl>$map</mapurl>
4684: <valuefunc>return $symbFilter;</valuefunc>
1.465 albertel 4685: $start_new_option
1.254 sakharuk 4686: </resource>
1.424 foxr 4687: </state>
1.284 albertel 4688: RESOURCE_SELECTOR
4689:
1.586 raeburn 4690: $resource_selector .= &generate_format_selector($helper,
4691: 'Format of the print job',
1.598 raeburn 4692: 'PRINT_FORMATTING');
1.284 albertel 4693: &Apache::lonxml::xmlparse($r, 'helper', <<CHOOSE_STUDENTS1);
4694: <state name="CHOOSE_STUDENTS1" title="Select Students and Resources">
1.340 foxr 4695: <choices variable='student_sort'>
4696: <choice computer='0'>Sort by section then student</choice>
4697: <choice computer='1'>Sort by students across sections.</choice>
4698: </choices>
1.437 foxr 4699: <message><br /><hr /><br /></message>
1.426 foxr 4700: <student multichoice='1' variable="STUDENTS" nextstate="SELECT_RESOURCES" coursepersonnel="1" />
1.340 foxr 4701:
1.424 foxr 4702: </state>
1.284 albertel 4703: $resource_selector
1.254 sakharuk 4704: CHOOSE_STUDENTS1
4705:
1.284 albertel 4706: &Apache::lonxml::xmlparse($r, 'helper', <<CHOOSE_ANON2);
1.472 albertel 4707: <state name="CHOOSE_ANON2" title="Select CODEd Assignments">
1.424 foxr 4708: <nextstate>SELECT_RESOURCES</nextstate>
1.472 albertel 4709: <message><h4>Fill out one of the forms below</h4></message>
4710: <message><br /><hr /> <br /></message>
4711: <message><h3>Generate new CODEd Assignments</h3></message>
4712: <message><table><tr><td><b>Number of CODEd assignments to print:</b></td><td></message>
1.579 foxr 4713: <string variable="NUMBER_TO_PRINT_TOTAL" maxlength="5" size="5" noproceed="1">
1.362 albertel 4714: <validator>
4715: if (((\$helper->{'VARS'}{'NUMBER_TO_PRINT_TOTAL'}+0) < 1) &&
1.386 foxr 4716: !\$helper->{'VARS'}{'REUSE_OLD_CODES'} &&
1.388 foxr 4717: !\$helper->{'VARS'}{'SINGLE_CODE'} &&
4718: !\$helper->{'VARS'}{'CODE_SELECTED_FROM_LIST'}) {
1.362 albertel 4719: return "You need to specify the number of assignments to print";
4720: }
1.578 foxr 4721: if (((\$helper->{'VARS'}{'NUMBER_TO_PRINT_TOTAL'}+0) >= 1) &&
4722: (\$helper->{'VARS'}{'SINGLE_CODE'} ne '') ) {
4723: return 'Specifying number of codes to print and a specific code is not compatible';
4724: }
1.362 albertel 4725: return undef;
4726: </validator>
4727: </string>
4728: <message></td></tr><tr><td></message>
1.501 albertel 4729: <message><b>Names to save the CODEs under for later:</b></message>
1.412 albertel 4730: <message></td><td></message>
4731: <string variable="ANON_CODE_STORAGE_NAME" maxlength="50" size="20" />
4732: <message></td></tr><tr><td></message>
1.599 raeburn 4733: <message><b>Bubblesheet type:</b></message>
1.412 albertel 4734: <message></td><td></message>
4735: <dropdown variable="CODE_OPTION" multichoice="0" allowempty="0">
4736: $codechoice
4737: </dropdown>
1.472 albertel 4738: <message></td></tr><tr><td></table></message>
4739: <message><br /><hr /><h3>Print a Specific CODE </h3><br /><table></message>
4740: <message><tr><td><b>Enter a CODE to print:</b></td><td></message>
1.412 albertel 4741: <string variable="SINGLE_CODE" size="10">
1.386 foxr 4742: <validator>
4743: if(!\$helper->{'VARS'}{'NUMBER_TO_PRINT_TOTAL'} &&
1.388 foxr 4744: !\$helper->{'VARS'}{'REUSE_OLD_CODES'} &&
4745: !\$helper->{'VARS'}{'CODE_SELECTED_FROM_LIST'}) {
1.386 foxr 4746: return &Apache::lonprintout::is_code_valid(\$helper->{'VARS'}{'SINGLE_CODE'},
4747: \$helper->{'VARS'}{'CODE_OPTION'});
1.577 foxr 4748: } elsif (\$helper->{'VARS'}{'SINGLE_CODE'} ne ''){
1.578 foxr 4749: return 'Specifying a code name is incompatible specifying number of codes.';
1.386 foxr 4750: } else {
4751: return undef; # Other forces control us.
4752: }
4753: </validator>
4754: </string>
1.472 albertel 4755: <message></td></tr><tr><td></message>
1.432 albertel 4756: $code_selection
1.472 albertel 4757: <message></td></tr></table></message>
4758: <message><hr /><h3>Reprint a Set of Saved CODEs</h3><table><tr><td></message>
4759: <message><b>Select saved CODEs:</b></message>
1.381 albertel 4760: <message></td><td></message>
1.294 albertel 4761: <dropdown variable="REUSE_OLD_CODES">
4762: $namechoice
4763: </dropdown>
1.412 albertel 4764: <message></td></tr></table></message>
1.424 foxr 4765: </state>
1.284 albertel 4766: $resource_selector
4767: CHOOSE_ANON2
1.481 albertel 4768: }
4769:
1.121 bowersj2 4770: # FIXME: That RE should come from a library somewhere.
1.483 foxr 4771: if (($perm{'pav'}
1.679 raeburn 4772: && ($subdir ne '')
1.482 albertel 4773: && $subdir ne $Apache::lonnet::perlvar{'lonDocRoot'}.'/res/'
4774: && (defined($helper->{'VARS'}->{'construction'})
4775: ||
4776: (&Apache::lonnet::allowed('bre',$subdir) eq 'F'
4777: &&
4778: $helper->{VARS}->{'postdata'}=~/\.(problem|exam|quiz|assess|survey|form|library|page|xml|html|htm|xhtml|xhtm)/)
1.483 foxr 4779: ))
4780: && $helper->{VARS}->{'assignment'} eq ""
1.482 albertel 4781: ) {
4782: my $pretty_dir = &Apache::lonnet::hreflocation($subdir);
1.546 bisitz 4783: 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'];
1.139 bowersj2 4784: my $xmlfrag = <<CHOOSE_FROM_SUBDIR;
1.482 albertel 4785: <state name="CHOOSE_FROM_SUBDIR" title="Select File(s) from <b><small>$pretty_dir</small></b> to print">
1.458 www 4786:
1.138 bowersj2 4787: <files variable="FILES" multichoice='1'>
1.144 bowersj2 4788: <nextstate>PAGESIZE</nextstate>
1.138 bowersj2 4789: <filechoice>return '$subdir';</filechoice>
1.139 bowersj2 4790: CHOOSE_FROM_SUBDIR
1.699 raeburn 4791:
1.238 bowersj2 4792: # this is broken up because I really want interpolation above,
4793: # and I really DON'T want it below
1.139 bowersj2 4794: $xmlfrag .= <<'CHOOSE_FROM_SUBDIR';
1.225 bowersj2 4795: <filefilter>return Apache::lonhelper::files::not_old_version($filename) &&
4796: $filename =~ m/\.(problem|exam|quiz|assess|survey|form|library)$/;
1.131 bowersj2 4797: </filefilter>
1.138 bowersj2 4798: </files>
1.131 bowersj2 4799: </state>
4800: CHOOSE_FROM_SUBDIR
1.139 bowersj2 4801: &Apache::lonxml::xmlparse($r, 'helper', $xmlfrag);
1.131 bowersj2 4802: }
1.238 bowersj2 4803:
4804: # Allow the user to select any sequence in the course, feed it to
4805: # another resource selector for that sequence
1.679 raeburn 4806: if ((!$helper->{VARS}->{'construction'}) &&
4807: (!$is_published || (($subdir eq '') && ($url eq '/adm/navmaps')))) {
1.681 raeburn 4808: push(@$printChoices,[&mt('Selected [_1]Resources[_2] from [_3]selected folder[_4] in course',
4809: '<b>','</b>','<b>','</b>'),
1.682 raeburn 4810: 'select_sequences','CHOOSE_SEQUENCE']);
1.679 raeburn 4811: my $escapedSequenceName;
4812: if ($helper->{VARS}->{'SEQUENCE'} ne '') {
4813: $escapedSequenceName = $helper->{VARS}->{'SEQUENCE'};
4814: } elsif (($subdir eq '') && ($url eq '/adm/navmaps')) {
4815: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
4816: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
4817: if ($env{'course.'.$env{'request.course.id'}.'.url'} eq
4818: "uploaded/$cdom/$cnum/default.sequence") {
4819: $escapedSequenceName = $env{'course.'.$env{'request.course.id'}.'.url'};
4820: }
4821: }
4822: #Escape apostrophes and backslashes for Perl
4823: $escapedSequenceName =~ s/\\/\\\\/g;
4824: $escapedSequenceName =~ s/'/\\'/g;
1.682 raeburn 4825: my $nocurrloc;
1.679 raeburn 4826: if (($subdir eq '') && ($url eq '/adm/navmaps')) {
1.682 raeburn 4827: $nocurrloc = 'nocurrloc="1"';
1.680 raeburn 4828: if ($perm{'pfo'}) {
1.679 raeburn 4829: push(@{$printChoices},
4830: [&mt('Selected [_1]Problems[_2] from [_3]selected folder[_4] in course for [_5]selected people[_6]',
4831: '<b>','</b>','<b>','</b>','<b>','</b>'),
4832: 'select_sequences_problems_for_students','CHOOSE_SEQUENCE_STUDENTS'],
4833: [&mt('Selected [_1]Problems[_2] from [_3]selected folder[_4] in course for [_5]CODEd assignments[_6]',
4834: '<b>','</b>','<b>','</b>','<b>','</b>'),
4835: 'select_sequences_problems_for_anon','CHOOSE_SEQUENCE_ANON1'],
4836: [&mt('Selected [_1]Resources[_2] from [_3]selected folder[_4] in course for [_5]selected people[_6]',
4837: '<b>','</b>','<b>','</b>','<b>','</b>'),
4838: 'select_sequences_resources_for_students','CHOOSE_SEQUENCE_STUDENTS1'],
4839: [&mt('Selected [_1]Resources[_2] from [_3]selected folder[_4] in course for [_5]CODEd assignments[_6]',
4840: '<b>','</b>','<b>','</b>','<b>','</b>'),
1.681 raeburn 4841: 'select_sequences_resources_for_anon','CHOOSE_SEQUENCE_ANON2']);
1.679 raeburn 4842: if ($escapedSequenceName) {
1.691 raeburn 4843: my ($randomly_ordered_warning,$codechoice,$code_selection,$namechoice) =
4844: &generate_common_choosers($r,$helper,$escapedSequenceName,$escapedSequenceName,
4845: $isProblem,$symbFilter,$start_new_option);
4846:
1.693 raeburn 4847: my $resource_selector = <<RESOURCE_SELECTOR;
1.691 raeburn 4848: <state name="CHOOSE_STUDENTS2" title="Select Students and Resources">
4849: <choices variable='student_sort'>
4850: <choice computer='0'>Sort by section then student</choice>
4851: <choice computer='1'>Sort by students across sections.</choice>
4852: </choices>
4853: <message><br /><hr /><br /></message>
4854: <student multichoice='1' variable="STUDENTS" nextstate="SELECT_RESOURCES" coursepersonnel="1" />
4855:
4856: </state>
4857: <state name="SELECT_RESOURCES" title="Select Resources">
4858: $randomly_ordered_warning
4859: <nextstate>PRINT_FORMATTING</nextstate>
4860: <message>(mark desired resources then click "next" button) <br /></message>
4861: <resource variable="RESOURCES" multichoice="1" addstatus="1"
1.694 raeburn 4862: closeallpages="1" modallink="1" suppressNavmap="1" $nocurrloc>
1.691 raeburn 4863: <filterfunc>return $isNotMap;</filterfunc>
1.694 raeburn 4864: <mapurl>$escapedSequenceName</mapurl>
1.691 raeburn 4865: <valuefunc>return $symbFilter;</valuefunc>
4866: $start_new_option
4867: </resource>
4868: </state>
4869: RESOURCE_SELECTOR
4870:
4871: my $anon3 = &generate_code_selector($helper,
4872: 'CHOOSE_ANON3',
4873: 'SELECT_RESOURCES',
4874: $codechoice,
4875: $code_selection,
4876: $namechoice) . $resource_selector;
4877:
4878: &Apache::lonxml::xmlparse($r, 'helper',$anon3);
1.679 raeburn 4879: }
4880: }
4881: }
4882: if (($subdir eq '') && ($url eq '/adm/navmaps') && ($perm{'pfo'})) {
1.691 raeburn 4883: &Apache::lonxml::xmlparse($r, 'helper', <<CHOOSE_FROM_ANY_SEQUENCE);
1.679 raeburn 4884: <state name="CHOOSE_SEQUENCE" title="Select Sequence To Print From">
4885: <message>Select the sequence to print resources from:</message>
4886: <resource variable="SEQUENCE">
4887: <nextstate>CHOOSE_FROM_ANY_SEQUENCE</nextstate>
4888: <filterfunc>return &Apache::lonprintout::printable_sequence(\$res);</filterfunc>
4889: <valuefunc>return $urlValue;</valuefunc>
4890: <choicefunc>return \$res->hasResource(\$res,sub { return !\$_[0]->is_sequence() },0,0);
4891: </choicefunc>
4892: </resource>
4893: </state>
4894: <state name="CHOOSE_SEQUENCE_STUDENTS" title="Select Sequence To Print From">
4895: <message>Select the sequence to print resources from:</message>
4896: <resource variable="SEQUENCE">
4897: <nextstate>CHOOSE_STUDENTS</nextstate>
4898: <filterfunc>return &Apache::lonprintout::printable_sequence(\$res);</filterfunc>
4899: <valuefunc>return $urlValue;</valuefunc>
4900: <choicefunc>return \$res->hasResource(\$res,sub { return !\$_[0]->is_sequence() },0,0);
4901: </choicefunc>
4902: </resource>
4903: </state>
4904: <state name="CHOOSE_SEQUENCE_ANON1" title="Select Sequence To Print From">
4905: <message>Select the sequence to print resources from:</message>
4906: <resource variable="SEQUENCE">
4907: <nextstate>CHOOSE_ANON1</nextstate>
4908: <filterfunc>return &Apache::lonprintout::printable_sequence(\$res);</filterfunc>
4909: <valuefunc>return $urlValue;</valuefunc>
4910: <choicefunc>return \$res->hasResource(\$res,sub { return !\$_[0]->is_sequence() },0,0);
4911: </choicefunc>
4912: </resource>
4913: </state>
4914: <state name="CHOOSE_SEQUENCE_STUDENTS1" title="Select Sequence To Print From">
4915: <message>Select the sequence to print resources from:</message>
4916: <resource variable="SEQUENCE">
1.691 raeburn 4917: <nextstate>CHOOSE_STUDENTS2</nextstate>
1.679 raeburn 4918: <filterfunc>return &Apache::lonprintout::printable_sequence(\$res);</filterfunc>
4919: <valuefunc>return $urlValue;</valuefunc>
4920: <choicefunc>return \$res->hasResource(\$res,sub { return !\$_[0]->is_sequence() },0,0);
4921: </choicefunc>
4922: </resource>
4923: </state>
4924: <state name="CHOOSE_SEQUENCE_ANON2" title="Select Sequence To Print From">
4925: <message>Select the sequence to print resources from:</message>
4926: <resource variable="SEQUENCE">
1.691 raeburn 4927: <nextstate>CHOOSE_ANON3</nextstate>
1.679 raeburn 4928: <filterfunc>return &Apache::lonprintout::printable_sequence(\$res);</filterfunc>
4929: <valuefunc>return $urlValue;</valuefunc>
4930: <choicefunc>return \$res->hasResource(\$res,sub { return !\$_[0]->is_sequence() },0,0);
4931: </choicefunc>
4932: </resource>
4933: </state>
4934: <state name="CHOOSE_FROM_ANY_SEQUENCE" title="Select Resources To Print">
4935: <message>(mark desired resources then click "next" button) <br /></message>
4936: <resource variable="RESOURCES" multichoice="1" toponly='1' addstatus="1"
1.684 raeburn 4937: closeallpages="1" modallink="1" suppressNavmap="1" $nocurrloc>
1.679 raeburn 4938: <nextstate>PAGESIZE</nextstate>
4939: <filterfunc>return $isNotMap</filterfunc>
4940: <mapurl evaluate='1'>return '$escapedSequenceName';</mapurl>
4941: <valuefunc>return $symbFilter;</valuefunc>
4942: $start_new_option
4943: </resource>
4944: </state>
4945: CHOOSE_FROM_ANY_SEQUENCE
4946: } else {
4947: &Apache::lonxml::xmlparse($r, 'helper', <<CHOOSE_FROM_ANY_SEQUENCE);
1.238 bowersj2 4948: <state name="CHOOSE_SEQUENCE" title="Select Sequence To Print From">
4949: <message>Select the sequence to print resources from:</message>
4950: <resource variable="SEQUENCE">
4951: <nextstate>CHOOSE_FROM_ANY_SEQUENCE</nextstate>
1.616 foxr 4952: <filterfunc>return &Apache::lonprintout::printable_sequence(\$res);</filterfunc>
1.238 bowersj2 4953: <valuefunc>return $urlValue;</valuefunc>
1.447 foxr 4954: <choicefunc>return \$res->hasResource(\$res,sub { return !\$_[0]->is_sequence() },0,0);
1.391 foxr 4955: </choicefunc>
1.238 bowersj2 4956: </resource>
4957: </state>
4958: <state name="CHOOSE_FROM_ANY_SEQUENCE" title="Select Resources To Print">
4959: <message>(mark desired resources then click "next" button) <br /></message>
1.435 foxr 4960: <resource variable="RESOURCES" multichoice="1" toponly='1' addstatus="1"
1.684 raeburn 4961: closeallpages="1" modallink="1" suppressNavmap="1" $nocurrloc>
1.238 bowersj2 4962: <nextstate>PAGESIZE</nextstate>
1.466 albertel 4963: <filterfunc>return $isNotMap</filterfunc>
1.244 bowersj2 4964: <mapurl evaluate='1'>return '$escapedSequenceName';</mapurl>
1.238 bowersj2 4965: <valuefunc>return $symbFilter;</valuefunc>
1.465 albertel 4966: $start_new_option
1.238 bowersj2 4967: </resource>
4968: </state>
4969: CHOOSE_FROM_ANY_SEQUENCE
1.679 raeburn 4970: }
4971: }
1.664 raeburn 4972: my $numchoices = 0;
4973: if (ref($printChoices) eq 'ARRAY') {
4974: $numchoices = @{$printChoices};
4975: }
4976: # Early out if nothing to print
4977: if (!$numchoices) {
4978: $r->print(&Apache::loncommon::start_page('Printing Helper').
4979: '<h2>'.&mt('Unable to determine print context').'</h2>'.
4980: '<p>'.&mt('Please display a resource, and then click the "Print" button/icon').'</p>');
4981: my $prtspool=$r->dir_config('lonPrtDir');
4982: my $footer = &recently_generated($prtspool);
4983: $r->print($footer.&Apache::loncommon::end_page());
4984: return OK;
4985: }
4986:
1.131 bowersj2 4987: # Generate the first state, to select which resources get printed.
1.223 bowersj2 4988: Apache::lonhelper::state->new("START", "Select Printing Options:");
1.615 foxr 4989: if (!$res_printable) {
1.638 raeburn 4990: my $noprintmsg;
1.663 raeburn 4991: if ($res_error) {
4992: $noprintmsg = &mt('Print availability for current resource could not be determined');
4993: } else {
4994: my $now = time;
4995: my $shownprintstart = &Apache::lonlocal::locallocaltime($res_printstartdate);
4996: my $shownprintend = &Apache::lonlocal::locallocaltime($res_printenddate);
4997: if (($res_printenddate) && ($res_printenddate < $now)) {
1.638 raeburn 4998: $noprintmsg = &mt('Printing for current resource no longer available (ended: [_1])',
4999: $shownprintend);
1.663 raeburn 5000: } else {
5001: if (($res_printstartdate) && ($res_printstartdate > $now)) {
5002: if (($res_printenddate) && ($res_printenddate > $now) && ($res_printenddate > $res_printstartdate)) {
5003: $noprintmsg = &mt('Printing for current resource is only possible between [_1] and [_2]',
5004: $shownprintstart,$shownprintend);
5005: } elsif (!$res_printenddate) {
5006: $noprintmsg = &mt('Printing for current resource will only be possible starting [_1]',
5007: $shownprintstart);
5008: } else {
5009: $noprintmsg = &mt('Printing for current resource is unavailable');
5010: }
1.638 raeburn 5011: }
5012: }
5013: }
5014:
5015: if ($noprintmsg) {
5016: $paramHash = Apache::lonhelper::getParamHash();
1.699 raeburn 5017: $paramHash->{MESSAGE_TEXT} =
1.638 raeburn 5018: '<p class="LC_info">'.$noprintmsg.'</p>';
5019: Apache::lonhelper::message->new();
5020: }
1.615 foxr 5021: }
5022: $paramHash = Apache::lonhelper::getParamHash();
1.131 bowersj2 5023: $paramHash = Apache::lonhelper::getParamHash();
1.155 sakharuk 5024: $paramHash->{MESSAGE_TEXT} = "";
1.131 bowersj2 5025: Apache::lonhelper::message->new();
5026: $paramHash = Apache::lonhelper::getParamHash();
5027: $paramHash->{'variable'} = 'PRINT_TYPE';
5028: $paramHash->{CHOICES} = $printChoices;
5029: Apache::lonhelper::choices->new();
1.161 bowersj2 5030:
1.223 bowersj2 5031: my $startedTable = 0; # have we started an HTML table yet? (need
5032: # to close it later)
5033:
1.585 raeburn 5034: if (($perm{'pav'} and $perm{'vgr'}) or
1.170 sakharuk 5035: ($helper->{VARS}->{'construction'} eq '1')) {
1.544 bisitz 5036: &addMessage('<br />'
5037: .'<h3>'.&mt('Print Options').'</h3>'
5038: .&Apache::lonhtmlcommon::start_pick_box()
5039: .&Apache::lonhtmlcommon::row_title(
5040: '<label for="ANSWER_TYPE_forminput">'
5041: .&mt('Print Answers')
5042: .'</label>'
5043: )
5044: );
1.161 bowersj2 5045: $paramHash = Apache::lonhelper::getParamHash();
1.699 raeburn 5046: $paramHash->{'variable'} = 'ANSWER_TYPE';
5047: $helper->declareVar('ANSWER_TYPE');
1.161 bowersj2 5048: $paramHash->{CHOICES} = [
1.242 sakharuk 5049: ['Without Answers', 'yes'],
5050: ['With Answers', 'no'],
1.368 albertel 5051: ['Only Answers', 'only']
1.289 sakharuk 5052: ];
1.210 sakharuk 5053: Apache::lonhelper::dropdown->new();
1.544 bisitz 5054: &addMessage(&Apache::lonhtmlcommon::row_closure());
1.223 bowersj2 5055: $startedTable = 1;
1.556 foxr 5056:
5057: #
5058: # Select font size.
5059: #
5060:
5061: $helper->declareVar('fontsize');
5062: &addMessage(&Apache::lonhtmlcommon::row_title(&mt('Font Size')));
5063: my $xmlfrag = << "FONT_SELECTION";
5064:
1.699 raeburn 5065:
1.669 raeburn 5066: <dropdown variable='fontsize' multichoice='0' allowempty='0'>
1.556 foxr 5067: <defaultvalue>
5068: return 'normalsize';
5069: </defaultvalue>
5070: <choice computer='tiny'>Tiny</choice>
5071: <choice computer='sub/superscriptsize'>Script Size</choice>
5072: <choice computer='footnotesize'>Footnote Size</choice>
5073: <choice computer='small'>Small</choice>
5074: <choice computer='normalsize'>Normal (default)</choice>
5075: <choice computer='large'>larger than normal</choice>
5076: <choice computer='Large'>Even larger than normal</choice>
5077: <choice computer='LARGE'>Still larger than normal</choice>
5078: <choice computer='huge'>huge font size</choice>
5079: <choice computer='Huge'>Largest possible size</choice>
5080: </dropdown>
5081: FONT_SELECTION
5082: &Apache::lonxml::xmlparse($r, 'helper', $xmlfrag);
5083: &addMessage(&Apache::lonhtmlcommon::row_closure(1));
1.161 bowersj2 5084: }
1.209 sakharuk 5085:
1.397 albertel 5086: if ($perm{'pav'}) {
1.223 bowersj2 5087: if (!$startedTable) {
1.497 www 5088: addMessage("<hr width='33%' /><table><tr><td align='right'>".
5089: '<label for="LATEX_TYPE_forminput">'.
5090: &mt('LaTeX mode').
5091: "</label>: </td><td>");
1.223 bowersj2 5092: $startedTable = 1;
5093: } else {
1.544 bisitz 5094: &addMessage(&Apache::lonhtmlcommon::row_title(
5095: '<label for="LATEX_TYPE_forminput">'
5096: .&mt('LaTeX mode')
5097: .'</label>'
5098: )
5099: );
1.223 bowersj2 5100: }
1.203 sakharuk 5101: $paramHash = Apache::lonhelper::getParamHash();
1.699 raeburn 5102: $paramHash->{'variable'} = 'LATEX_TYPE';
5103: $helper->declareVar('LATEX_TYPE');
5104: if ($helper->{VARS}->{'construction'} eq '1') {
1.203 sakharuk 5105: $paramHash->{CHOICES} = [
1.699 raeburn 5106: ['standard LaTeX mode', 'standard'],
1.223 bowersj2 5107: ['LaTeX batchmode', 'batchmode'], ];
1.203 sakharuk 5108: } else {
5109: $paramHash->{CHOICES} = [
1.223 bowersj2 5110: ['LaTeX batchmode', 'batchmode'],
5111: ['standard LaTeX mode', 'standard'] ];
1.203 sakharuk 5112: }
1.210 sakharuk 5113: Apache::lonhelper::dropdown->new();
1.699 raeburn 5114:
1.544 bisitz 5115: &addMessage(&Apache::lonhtmlcommon::row_closure()
5116: .&Apache::lonhtmlcommon::row_title(
5117: '<label for="TABLE_CONTENTS_forminput">'
5118: .&mt('Print Table of Contents')
5119: .'</label>'
5120: )
5121: );
1.209 sakharuk 5122: $paramHash = Apache::lonhelper::getParamHash();
1.699 raeburn 5123: $paramHash->{'variable'} = 'TABLE_CONTENTS';
5124: $helper->declareVar('TABLE_CONTENTS');
1.209 sakharuk 5125: $paramHash->{CHOICES} = [
1.223 bowersj2 5126: ['No', 'no'],
5127: ['Yes', 'yes'] ];
1.210 sakharuk 5128: Apache::lonhelper::dropdown->new();
1.544 bisitz 5129: &addMessage(&Apache::lonhtmlcommon::row_closure());
1.699 raeburn 5130:
1.220 sakharuk 5131: if (not $helper->{VARS}->{'construction'}) {
1.545 bisitz 5132: &addMessage(&Apache::lonhtmlcommon::row_title(
5133: '<label for="TABLE_INDEX_forminput">'
5134: .&mt('Print Index')
5135: .'</label>'
5136: )
5137: );
1.220 sakharuk 5138: $paramHash = Apache::lonhelper::getParamHash();
1.699 raeburn 5139: $paramHash->{'variable'} = 'TABLE_INDEX';
5140: $helper->declareVar('TABLE_INDEX');
1.220 sakharuk 5141: $paramHash->{CHOICES} = [
1.223 bowersj2 5142: ['No', 'no'],
5143: ['Yes', 'yes'] ];
1.220 sakharuk 5144: Apache::lonhelper::dropdown->new();
1.545 bisitz 5145: &addMessage(&Apache::lonhtmlcommon::row_closure());
5146: &addMessage(&Apache::lonhtmlcommon::row_title(
5147: '<label for="PRINT_DISCUSSIONS_forminput">'
5148: .&mt('Print Discussions')
5149: .'</label>'
5150: )
5151: );
1.309 sakharuk 5152: $paramHash = Apache::lonhelper::getParamHash();
1.699 raeburn 5153: $paramHash->{'variable'} = 'PRINT_DISCUSSIONS';
5154: $helper->declareVar('PRINT_DISCUSSIONS');
1.309 sakharuk 5155: $paramHash->{CHOICES} = [
5156: ['No', 'no'],
5157: ['Yes', 'yes'] ];
5158: Apache::lonhelper::dropdown->new();
1.545 bisitz 5159: &addMessage(&Apache::lonhtmlcommon::row_closure());
1.372 foxr 5160:
1.511 foxr 5161: # Prompt for printing annotations too.
5162:
1.545 bisitz 5163: &addMessage(&Apache::lonhtmlcommon::row_title(
5164: '<label for="PRINT_ANNOTATIONS_forminput">'
5165: .&mt('Print Annotations')
5166: .'</label>'
5167: )
5168: );
1.511 foxr 5169: $paramHash = Apache::lonhelper::getParamHash();
5170: $paramHash->{'variable'} = "PRINT_ANNOTATIONS";
5171: $helper->declareVar("PRINT_ANNOTATIONS");
5172: $paramHash->{CHOICES} = [
5173: ['No', 'no'],
5174: ['Yes', 'yes']];
5175: Apache::lonhelper::dropdown->new();
1.545 bisitz 5176: &addMessage(&Apache::lonhtmlcommon::row_closure());
1.511 foxr 5177:
1.545 bisitz 5178: &addMessage(&Apache::lonhtmlcommon::row_title(&mt('Foils')));
1.397 albertel 5179: $paramHash = Apache::lonhelper::getParamHash();
5180: $paramHash->{'multichoice'} = "true";
5181: $paramHash->{'allowempty'} = "true";
5182: $paramHash->{'variable'} = "showallfoils";
1.555 bisitz 5183: $paramHash->{'CHOICES'} = [ [&mt('Show All Foils'), "1"] ];
1.397 albertel 5184: Apache::lonhelper::choices->new();
1.545 bisitz 5185: &addMessage(&Apache::lonhtmlcommon::row_closure(1));
1.220 sakharuk 5186: }
1.219 sakharuk 5187:
1.699 raeburn 5188: if ($helper->{'VARS'}->{'construction'}) {
1.505 albertel 5189: my $stylevalue='$Apache::lonnet::env{"construct.style"}';
1.497 www 5190: my $randseedtext=&mt("Use random seed");
5191: my $stylefiletext=&mt("Use style file");
1.506 albertel 5192: my $selectfiletext=&mt("Select style file");
1.497 www 5193:
1.544 bisitz 5194: my $xmlfrag .= '<message>'
5195: .&Apache::lonhtmlcommon::row_title('<label for="curseed_forminput">'
5196: .$randseedtext
5197: .'</label>'
5198: )
5199: .'</message>
5200: <string variable="curseed" size="15" maxlength="15">
5201: <defaultvalue>
5202: return '.$helper->{VARS}->{'curseed'}.';
5203: </defaultvalue>'
5204: .'</string>'
5205: .'<message>'
5206: .&Apache::lonhtmlcommon::row_closure()
5207: .&Apache::lonhtmlcommon::row_title('<label for="style_file">'
5208: .$stylefiletext
5209: .'</label>'
5210: )
5211: .'</message>
1.504 albertel 5212: <string variable="style_file" size="40">
1.544 bisitz 5213: <defaultvalue>
5214: return '.$stylevalue.';
5215: </defaultvalue>
5216: </string><message> '
5217: .qq|<a href="javascript:openbrowser('helpform','style_file_forminput','sty')">|
5218: .$selectfiletext.'</a>'
5219: .&Apache::lonhtmlcommon::row_closure()
1.555 bisitz 5220: .&Apache::lonhtmlcommon::row_title(&mt('Show All Foils'))
1.544 bisitz 5221: .'</message>
1.371 foxr 5222: <choices allowempty="1" multichoice="true" variable="showallfoils">
1.544 bisitz 5223: <choice computer="1"> </choice>
5224: </choices>'
5225: .'<message>'
5226: .&Apache::lonhtmlcommon::row_closure()
5227: .'</message>';
1.230 albertel 5228: &Apache::lonxml::xmlparse($r, 'helper', $xmlfrag);
1.512 foxr 5229:
5230:
1.544 bisitz 5231: &addMessage(&Apache::lonhtmlcommon::row_title(&mt('Problem Type')));
1.512 foxr 5232: #
5233: # Initial value from construction space:
5234: #
5235: if (!$helper->{VARS}->{'probstatus'} && $env{'form.problemtype'}) {
5236: $helper->{VARS}->{'probstatus'} = $env{'form.problemtype'}; # initial value
5237: }
1.518 foxr 5238: $xmlfrag = << "PROBTYPE";
5239: <dropdown variable="probstatus" multichoice="0" allowempty="0">
5240: <defaultvalue>
5241: return "$helper->{VARS}->{'probstatus'}";
5242: </defaultvalue>
5243: <choice computer="problem">Homework Problem</choice>
1.628 bisitz 5244: <choice computer="exam">Bubblesheet Exam Problem</choice>
1.518 foxr 5245: <choice computer="survey">Survey question</choice>
1.572 raeburn 5246: ,choice computer="anonsurvey"Anonymous survey question</choice>
1.518 foxr 5247: </dropdown>
5248: PROBTYPE
5249: &Apache::lonxml::xmlparse($r, 'helper', $xmlfrag);
1.544 bisitz 5250: &addMessage(&Apache::lonhtmlcommon::row_closure(1));
1.512 foxr 5251:
1.556 foxr 5252:
5253:
1.544 bisitz 5254: }
1.223 bowersj2 5255: }
1.264 sakharuk 5256:
5257:
5258:
1.218 sakharuk 5259:
1.223 bowersj2 5260: if ($startedTable) {
1.544 bisitz 5261: &addMessage(&Apache::lonhtmlcommon::end_pick_box());
1.215 sakharuk 5262: }
1.161 bowersj2 5263:
1.131 bowersj2 5264: Apache::lonprintout::page_format_state->new("FORMAT");
5265:
1.144 bowersj2 5266: # Generate the PAGESIZE state which will offer the user the margin
5267: # choices if they select one column
5268: Apache::lonhelper::state->new("PAGESIZE", "Set Margins");
5269: Apache::lonprintout::page_size_state->new('pagesize', 'FORMAT', 'FINAL');
5270:
5271:
1.131 bowersj2 5272: $helper->process();
5273:
1.416 foxr 5274:
1.131 bowersj2 5275: # MANUAL BAILOUT CONDITION:
5276: # If we're in the "final" state, bailout and return to handler
5277: if ($helper->{STATE} eq 'FINAL') {
5278: return $helper;
1.699 raeburn 5279: }
1.130 sakharuk 5280:
1.584 raeburn 5281: my $footer;
1.395 www 5282: if ($helper->{STATE} eq 'START') {
1.699 raeburn 5283: my $prtspool=$r->dir_config('lonPrtDir');
1.584 raeburn 5284: $footer = &recently_generated($prtspool);
1.395 www 5285: }
1.584 raeburn 5286: $r->print($helper->display($footer));
1.333 albertel 5287: &Apache::lonhelper::unregisterHelperTags();
1.115 bowersj2 5288:
5289: return OK;
5290: }
5291:
1.1 www 5292:
5293: 1;
1.119 bowersj2 5294:
5295: package Apache::lonprintout::page_format_state;
5296:
5297: =pod
5298:
1.131 bowersj2 5299: =head1 Helper element: page_format_state
5300:
5301: See lonhelper.pm documentation for discussion of the helper framework.
1.119 bowersj2 5302:
1.699 raeburn 5303: Apache::lonprintout::page_format_state is an element that gives the
5304: user an opportunity to select the page layout they wish to print
5305: with: Number of columns, portrait/landscape, and paper size. If you
5306: want to change the paper size choices, change the @paperSize array
1.131 bowersj2 5307: contents in this package.
1.119 bowersj2 5308:
1.131 bowersj2 5309: page_format_state is always directly invoked in lonprintout.pm, so there
5310: is no tag interface. You actually pass parameters to the constructor.
1.119 bowersj2 5311:
5312: =over 4
5313:
1.131 bowersj2 5314: =item * B<new>(varName): varName is where the print information will be stored in the format FIXME.
1.119 bowersj2 5315:
5316: =back
5317:
5318: =cut
5319:
1.131 bowersj2 5320: use Apache::lonhelper;
1.119 bowersj2 5321:
5322: no strict;
1.131 bowersj2 5323: @ISA = ("Apache::lonhelper::element");
1.119 bowersj2 5324: use strict;
1.266 sakharuk 5325: use Apache::lonlocal;
1.373 albertel 5326: use Apache::lonnet;
1.119 bowersj2 5327:
5328: my $maxColumns = 2;
1.376 albertel 5329: # it'd be nice if these all worked
1.699 raeburn 5330: #my @paperSize = ("letter [8 1/2x11 in]", "legal [8 1/2x14 in]",
1.376 albertel 5331: # "tabloid (ledger) [11x17 in]", "executive [7 1/2x10 in]",
1.699 raeburn 5332: # "a2 [420x594 mm]", "a3 [297x420 mm]", "a4 [210x297 mm]",
1.376 albertel 5333: # "a5 [148x210 mm]", "a6 [105x148 mm]" );
1.699 raeburn 5334: my @paperSize = ("letter [8 1/2x11 in]", "legal [8 1/2x14 in]",
1.376 albertel 5335: "a4 [210x297 mm]");
1.119 bowersj2 5336:
5337: # Tentative format: Orientation (L = Landscape, P = portrait) | Colnum |
5338: # Paper type
5339:
1.699 raeburn 5340: sub new {
1.131 bowersj2 5341: my $self = Apache::lonhelper::element->new();
1.119 bowersj2 5342:
1.135 bowersj2 5343: shift;
5344:
1.131 bowersj2 5345: $self->{'variable'} = shift;
1.134 bowersj2 5346: my $helper = Apache::lonhelper::getHelper();
1.135 bowersj2 5347: $helper->declareVar($self->{'variable'});
1.131 bowersj2 5348: bless($self);
1.119 bowersj2 5349: return $self;
5350: }
5351:
5352: sub render {
5353: my $self = shift;
1.131 bowersj2 5354: my $helper = Apache::lonhelper::getHelper();
1.119 bowersj2 5355: my $result = '';
1.131 bowersj2 5356: my $var = $self->{'variable'};
1.266 sakharuk 5357: my $PageLayout=&mt('Page layout');
5358: my $NumberOfColumns=&mt('Number of columns');
5359: my $PaperType=&mt('Paper type');
1.506 albertel 5360: my $landscape=&mt('Landscape');
5361: my $portrait=&mt('Portrait');
1.641 bisitz 5362: my $pdfFormLabel=&mt('PDF Form Fields');
5363: my $with=&mt('with Form Fields');
5364: my $without=&mt('without Form Fields');
1.699 raeburn 5365:
1.556 foxr 5366:
1.544 bisitz 5367: $result.='<h3>'.&mt('Layout Options').'</h3>'
5368: .&Apache::loncommon::start_data_table()
5369: .&Apache::loncommon::start_data_table_header_row()
5370: .'<th>'.$PageLayout.'</th>'
5371: .'<th>'.$NumberOfColumns.'</th>'
5372: .'<th>'.$PaperType.'</th>'
5373: .'<th>'.$pdfFormLabel.'</th>'
5374: .&Apache::loncommon::end_data_table_header_row()
5375: .&Apache::loncommon::start_data_table_row()
5376: .'<td>'
5377: .'<label><input type="radio" name="'.${var}.'.layout" value="L" />'.$landscape.'</label><br />'
5378: .'<label><input type="radio" name="'.${var}.'.layout" value="P" checked="checked" />'.$portrait.'</label>'
5379: .'</td>';
1.119 bowersj2 5380:
1.544 bisitz 5381: $result.='<td align="center">'
5382: .'<select name="'.${var}.'.cols">';
1.119 bowersj2 5383:
5384: my $i;
5385: for ($i = 1; $i <= $maxColumns; $i++) {
1.144 bowersj2 5386: if ($i == 2) {
1.553 bisitz 5387: $result .= '<option value="'.$i.'" selected="selected">'.$i.'</option>'."\n";
1.119 bowersj2 5388: } else {
1.553 bisitz 5389: $result .= '<option value="'.$i.'">'.$i.'</option>'."\n";
1.119 bowersj2 5390: }
5391: }
5392:
5393: $result .= "</select></td><td>\n";
5394: $result .= "<select name='${var}.paper'>\n";
5395:
1.373 albertel 5396: my %parmhash=&Apache::lonnet::coursedescription($env{'request.course.id'});
1.398 albertel 5397: my $DefaultPaperSize=lc($parmhash{'default_paper_size'});
5398: $DefaultPaperSize=~s/\s//g;
1.304 sakharuk 5399: if ($DefaultPaperSize eq '') {$DefaultPaperSize='letter';}
1.119 bowersj2 5400: $i = 0;
5401: foreach (@paperSize) {
1.326 sakharuk 5402: $_=~/(\w+)/;
5403: my $papersize=$1;
1.304 sakharuk 5404: if ($paperSize[$i]=~/$DefaultPaperSize/) {
1.553 bisitz 5405: $result .= '<option selected="selected" value="'.$papersize.'">'.$paperSize[$i].'</option>'."\n";
1.119 bowersj2 5406: } else {
1.553 bisitz 5407: $result .= '<option value="'.$papersize.'">'.$paperSize[$i].'</option>'."\n";
1.119 bowersj2 5408: }
5409: $i++;
5410: }
1.539 onken 5411: $result .= <<HTML;
5412: </select>
5413: </td>
5414: <td align='center'>
5415: <select name='${var}.pdfFormFields'>
1.553 bisitz 5416: <option selected="selected" value="no">$without</option>
5417: <option value="yes">$with</option>
1.539 onken 5418: </select>
5419: </td>
5420: HTML
1.544 bisitz 5421: $result.=&Apache::loncommon::end_data_table_row()
5422: .&Apache::loncommon::end_data_table();
1.539 onken 5423:
1.119 bowersj2 5424: return $result;
1.135 bowersj2 5425: }
5426:
5427: sub postprocess {
5428: my $self = shift;
5429:
5430: my $var = $self->{'variable'};
1.136 bowersj2 5431: my $helper = Apache::lonhelper->getHelper();
1.699 raeburn 5432: $helper->{VARS}->{$var} =
1.373 albertel 5433: $env{"form.$var.layout"} . '|' . $env{"form.$var.cols"} . '|' .
1.539 onken 5434: $env{"form.$var.paper"} . '|' . $env{"form.$var.pdfFormFields"};
1.135 bowersj2 5435: return 1;
1.119 bowersj2 5436: }
5437:
5438: 1;
1.144 bowersj2 5439:
5440: package Apache::lonprintout::page_size_state;
5441:
5442: =pod
5443:
5444: =head1 Helper element: page_size_state
5445:
5446: See lonhelper.pm documentation for discussion of the helper framework.
5447:
1.699 raeburn 5448: Apache::lonprintout::page_size_state is an element that gives the
1.144 bowersj2 5449: user the opportunity to further refine the page settings if they
5450: select a single-column page.
5451:
5452: page_size_state is always directly invoked in lonprintout.pm, so there
5453: is no tag interface. You actually pass parameters to the constructor.
5454:
5455: =over 4
5456:
5457: =item * B<new>(varName): varName is where the print information will be stored in the format FIXME.
5458:
5459: =back
5460:
5461: =cut
5462:
5463: use Apache::lonhelper;
1.373 albertel 5464: use Apache::lonnet;
1.144 bowersj2 5465: no strict;
5466: @ISA = ("Apache::lonhelper::element");
5467: use strict;
5468:
5469:
5470:
1.699 raeburn 5471: sub new {
1.144 bowersj2 5472: my $self = Apache::lonhelper::element->new();
5473:
5474: shift; # disturbs me (probably prevents subclassing) but works (drops
5475: # package descriptor)... - Jeremy
5476:
5477: $self->{'variable'} = shift;
5478: my $helper = Apache::lonhelper::getHelper();
5479: $helper->declareVar($self->{'variable'});
5480:
1.699 raeburn 5481: # The variable name of the format element, so we can look into
1.144 bowersj2 5482: # $helper->{VARS} to figure out whether the columns are one or two
5483: $self->{'formatvar'} = shift;
5484:
1.463 foxr 5485:
1.144 bowersj2 5486: $self->{NEXTSTATE} = shift;
5487: bless($self);
1.467 foxr 5488:
1.144 bowersj2 5489: return $self;
5490: }
5491:
5492: sub render {
5493: my $self = shift;
5494: my $helper = Apache::lonhelper::getHelper();
5495: my $result = '';
5496: my $var = $self->{'variable'};
5497:
1.467 foxr 5498:
5499:
1.144 bowersj2 5500: if (defined $self->{ERROR_MSG}) {
1.464 albertel 5501: $result .= '<br /><span class="LC_error">' . $self->{ERROR_MSG} . '</span><br />';
1.144 bowersj2 5502: }
5503:
1.438 foxr 5504: my $format = $helper->{VARS}->{$self->{'formatvar'}};
1.463 foxr 5505:
5506: # Use format to get sensible defaults for the margins:
5507:
5508:
5509: my ($laystyle, $cols, $papersize) = split(/\|/, $format);
5510: ($papersize) = split(/ /, $papersize);
5511:
1.559 foxr 5512: $laystyle = &Apache::lonprintout::map_laystyle($laystyle);
1.463 foxr 5513:
5514:
5515:
1.464 albertel 5516: my %size;
5517: ($size{'width_and_units'},
5518: $size{'height_and_units'},
5519: $size{'margin_and_units'})=
5520: &Apache::lonprintout::page_format($papersize, $laystyle, $cols);
1.699 raeburn 5521:
1.464 albertel 5522: foreach my $dimension ('width','height','margin') {
5523: ($size{$dimension},$size{$dimension.'_unit'}) =
5524: split(/ +/, $size{$dimension.'_and_units'},2);
5525:
5526: foreach my $unit ('cm','in') {
5527: $size{$dimension.'_options'} .= '<option ';
5528: if ($size{$dimension.'_unit'} eq $unit) {
5529: $size{$dimension.'_options'} .= 'selected="selected" ';
5530: }
5531: $size{$dimension.'_options'} .= '>'.$unit.'</option>';
5532: }
1.438 foxr 5533: }
5534:
1.470 foxr 5535: # Adjust margin for LaTeX margin: .. requires units == cm or in.
5536:
5537: if ($size{'margin_unit'} eq 'in') {
5538: $size{'margin'} += 1;
5539: } else {
5540: $size{'margin'} += 2.54;
5541: }
1.548 bisitz 5542: my %lt = &Apache::lonlocal::texthash(
5543: 'format' => 'How should each column be formatted?',
5544: 'width' => 'Width',
5545: 'height' => 'Height',
5546: 'margin' => 'Left Margin'
5547: );
5548:
5549: $result .= '<p>'.$lt{'format'}.'</p>'
5550: .&Apache::lonhtmlcommon::start_pick_box()
5551: .&Apache::lonhtmlcommon::row_title($lt{'width'})
5552: .'<input type="text" name="'.$var.'.width" value="'.$size{'width'}.'" size="4" />'
5553: .'<select name="'.$var.'.widthunit">'
5554: .$size{'width_options'}
5555: .'</select>'
5556: .&Apache::lonhtmlcommon::row_closure()
5557: .&Apache::lonhtmlcommon::row_title($lt{'height'})
5558: .'<input type="text" name="'.$var.'.height" value="'.$size{'height'}.'" size="4" />'
5559: .'<select name="'.$var.'.heightunit">'
5560: .$size{'height_options'}
5561: .'</select>'
5562: .&Apache::lonhtmlcommon::row_closure()
5563: .&Apache::lonhtmlcommon::row_title($lt{'margin'})
5564: .'<input type="text" name="'.$var.'.lmargin" value="'.$size{'margin'}.'" size="4" />'
5565: .'<select name="'.$var.'.lmarginunit">'
5566: .$size{'margin_options'}
5567: .'</select>'
5568: .&Apache::lonhtmlcommon::row_closure(1)
5569: .&Apache::lonhtmlcommon::end_pick_box();
5570: # <p>Hint: Some instructors like to leave scratch space for the student by
5571: # making the width much smaller than the width of the page.</p>
1.144 bowersj2 5572:
5573: return $result;
5574: }
5575:
1.470 foxr 5576:
1.144 bowersj2 5577: sub preprocess {
5578: my $self = shift;
5579: my $helper = Apache::lonhelper::getHelper();
5580:
5581: my $format = $helper->{VARS}->{$self->{'formatvar'}};
1.467 foxr 5582:
5583: # If the user does not have 'pav' privilege, set default widths and
5584: # on to the next state right away.
5585: #
5586: if (!$perm{'pav'}) {
5587: my $var = $self->{'variable'};
5588: my $format = $helper->{VARS}->{$self->{'formatvar'}};
5589:
5590: my ($laystyle, $cols, $papersize) = split(/\|/, $format);
5591: ($papersize) = split(/ /, $papersize);
5592:
5593:
1.560 foxr 5594: $laystyle = &Apache::lonprintout::map_laystyle($laystyle);
1.559 foxr 5595:
1.467 foxr 5596: # Figure out some good defaults for the print out and set them:
5597:
5598: my %size;
5599: ($size{'width'},
5600: $size{'height'},
5601: $size{'lmargin'})=
5602: &Apache::lonprintout::page_format($papersize, $laystyle, $cols);
5603:
5604: foreach my $dim ('width', 'height', 'lmargin') {
5605: my ($value, $units) = split(/ /, $size{$dim});
1.699 raeburn 5606:
1.467 foxr 5607: $helper->{VARS}->{"$var.".$dim} = $value;
5608: $helper->{VARS}->{"$var.".$dim.'unit'} = $units;
1.699 raeburn 5609:
1.467 foxr 5610: }
5611:
5612:
5613: # Transition to the next state
5614:
5615: $helper->changeState($self->{NEXTSTATE});
5616: }
1.699 raeburn 5617:
1.144 bowersj2 5618: return 1;
5619: }
5620:
5621: sub postprocess {
5622: my $self = shift;
5623:
5624: my $var = $self->{'variable'};
5625: my $helper = Apache::lonhelper->getHelper();
1.699 raeburn 5626: my $width = $helper->{VARS}->{$var .'.width'} = $env{"form.${var}.width"};
5627: my $height = $helper->{VARS}->{$var .'.height'} = $env{"form.${var}.height"};
5628: my $lmargin = $helper->{VARS}->{$var .'.lmargin'} = $env{"form.${var}.lmargin"};
5629: $helper->{VARS}->{$var .'.widthunit'} = $env{"form.${var}.widthunit"};
5630: $helper->{VARS}->{$var .'.heightunit'} = $env{"form.${var}.heightunit"};
5631: $helper->{VARS}->{$var .'.lmarginunit'} = $env{"form.${var}.lmarginunit"};
1.144 bowersj2 5632:
5633: my $error = '';
5634:
1.699 raeburn 5635: # /^-?[0-9]+(\.[0-9]*)?$/ -> optional minus, at least on digit, followed
1.144 bowersj2 5636: # by an optional period, followed by digits, ending the string
5637:
1.464 albertel 5638: if ($width !~ /^-?[0-9]*(\.[0-9]*)?$/) {
1.144 bowersj2 5639: $error .= "Invalid width; please type only a number.<br />\n";
5640: }
1.464 albertel 5641: if ($height !~ /^-?[0-9]*(\.[0-9]*)?$/) {
1.144 bowersj2 5642: $error .= "Invalid height; please type only a number.<br />\n";
5643: }
1.464 albertel 5644: if ($lmargin !~ /^-?[0-9]*(\.[0-9]*)?$/) {
1.144 bowersj2 5645: $error .= "Invalid left margin; please type only a number.<br />\n";
1.470 foxr 5646: } else {
5647: # Adjust for LaTeX 1.0 inch margin:
5648:
5649: if ($env{"form.${var}.lmarginunit"} eq "in") {
5650: $helper->{VARS}->{$var.'.lmargin'} = $lmargin - 1;
5651: } else {
5652: $helper->{VARS}->{$var.'.lmargin'} = $lmargin - 2.54;
5653: }
1.144 bowersj2 5654: }
5655:
5656: if (!$error) {
5657: Apache::lonhelper::getHelper()->changeState($self->{NEXTSTATE});
5658: return 1;
5659: } else {
5660: $self->{ERROR_MSG} = $error;
5661: return 0;
5662: }
5663: }
5664:
1.1 www 5665: __END__
1.6 sakharuk 5666:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>