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