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