Annotation of loncom/interface/lonprintout.pm, revision 1.705
1.389 foxr 1: # The LearningOnline Network
1.1 www 2: # Printout
3: #
1.705 ! raeburn 4: # $Id: lonprintout.pm,v 1.704 2024/11/11 03:20:46 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.
1.705 ! raeburn 815: # $section - Section for user for whom we are checking.
1.591 foxr 816: # $map - map name.
817: # Returns:
818: # 0 - map is not incomplete.
819: # 1 - map is incomplete.
820: #
821: sub incomplete {
1.705 ! raeburn 822: my ($username, $domain, $section, $map) = @_;
1.591 foxr 823:
824:
1.705 ! raeburn 825: my $navmap = Apache::lonnavmaps::navmap->new($username, $domain, $section);
1.699 raeburn 826:
1.591 foxr 827:
828: if (defined($navmap)) {
829: my $res = $navmap->getResourceByUrl($map);
830: my $result = $res->is_incomplete();
831: return $result;
832: } else {
833: return 1;
834: }
835: }
1.595 foxr 836: #
1.646 raeburn 837: # When printing for students, the resources and order of the
1.595 foxr 838: # resources may need to be altered if there are folders with
839: # random selectiopn or random ordering (or both) enabled.
840: # This sub computes the set of resources to print for a student
841: # modified both by random ordering and selection and filtered
1.646 raeburn 842: # to only those that are in the original set selected to be printed.
1.595 foxr 843: #
844: # Parameters:
1.626 raeburn 845: # $map - The URL of the folder being printed.
846: # Used to determine which startResource and finishResource
847: # to use when using the navmap's getIterator method.
848: # $seq - The original set of resources to print.
1.600 foxr 849: # (really an array of resource names (array of symb's).
1.595 foxr 850: # $who - Student/domain for whome the sequence will be generated.
1.626 raeburn 851: # $code - CODE being printed when printing Problems/Resources
852: # from folder for CODEd assignments
1.646 raeburn 853: # $nohidemap - If true, parameter in map for hiddenresource will be
854: # ignored. The user calling the routine should have
855: # both the pav and vgr privileges if this is set to true).
1.595 foxr 856: #
857: # Implicit inputs:
858: # $
859: # Returns:
860: # reference to an array of resources that can be passed to
861: # print_resources.
1.699 raeburn 862: #
1.595 foxr 863: sub master_seq_to_person_seq {
1.631 raeburn 864: my ($map, $seq, $who, $code, $nohidemap) = @_;
1.595 foxr 865:
866:
867: my ($username, $userdomain, $usersection) = split(/:/, $who);
868:
869: # Toss the sequence up into a hash so that we have O(1) lookup time.
870: # on the items that come out of the user's list of resources.
871: #
1.626 raeburn 872:
1.595 foxr 873: my %seq_hash = map {$_ => 1} @$seq;
874: my @output_seq;
1.631 raeburn 875:
876: my $unhidden;
1.647 raeburn 877: if ($nohidemap) {
1.631 raeburn 878: $unhidden = &Apache::lonnet::clutter($map);
879: }
1.699 raeburn 880:
1.625 raeburn 881: my $navmap = Apache::lonnavmaps::navmap->new($username, $userdomain,
1.705 ! raeburn 882: $usersection, $code, $unhidden);
1.626 raeburn 883: my ($start,$finish);
1.595 foxr 884:
1.626 raeburn 885: if ($map) {
886: my $mapres = $navmap->getResourceByUrl($map);
887: if ($mapres->is_map()) {
888: $start = $mapres->map_start();
889: $finish = $mapres->map_finish();
890: }
891: }
892: unless ($start && $finish) {
893: $start = $navmap->firstResource();
894: $finish = $navmap->finishResource();
895: }
896:
897: my $iterator = $navmap->getIterator($start,$finish,{},1);
1.595 foxr 898:
899: # Iterate on the resource..select the items that are randomly selected
1.688 raeburn 900: # and that are in the seq_hash. Presumably the iterator will take care
1.689 raeburn 901: # of the random ordering part of the deal.
1.595 foxr 902: #
903: my $curres;
904: while ($curres = $iterator->next()) {
905: #
1.600 foxr 906: # Only process resources..that are not removed by randomout...
907: # and are selected for printint as well.
1.595 foxr 908: #
1.626 raeburn 909: if (ref($curres) && ! $curres->randomout()) {
910: my $currsymb = $curres->symb();
911: if (exists($seq_hash{$currsymb})) {
912: push(@output_seq, $currsymb);
1.595 foxr 913: }
914: }
915: }
916:
917: return \@output_seq; # for now.
1.699 raeburn 918:
1.595 foxr 919: }
920:
1.515 foxr 921:
1.498 foxr 922: # Fetch the contents of a resource, uninterpreted.
923: # This is used here to fetch a latex file to be included
924: # verbatim into the printout<
925: # NOTE: Ask Guy if there is a lonnet function similar to this?
926: #
927: # Parameters:
928: # URL of the file
929: #
930: sub fetch_raw_resource {
931: my ($url) = @_;
932:
933: my $filename = &Apache::lonnet::filelocation("", $url);
1.500 foxr 934: my $contents = &Apache::lonnet::getfile($filename);
1.498 foxr 935:
1.500 foxr 936: if ($contents == -1) {
937: return "File open failed for $filename"; # This will bomb the print.
1.498 foxr 938: }
1.500 foxr 939: return $contents;
1.498 foxr 940:
1.699 raeburn 941:
1.498 foxr 942: }
943:
1.699 raeburn 944: # Fetch the annotations associated with a URL and
1.511 foxr 945: # put a centered 'annotations:' title.
946: # This is all suppressed if the annotations are empty.
947: #
948: sub annotate {
949: my ($symb) = @_;
950:
1.559 foxr 951: my $annotation_text = &Apache::loncommon::get_annotation($symb, 1);
1.511 foxr 952:
953:
954: my $result = "";
955:
956: if (length($annotation_text) > 0) {
957: $result .= '\\hspace*{\\fill} \\\\[\\baselineskip] \textbf{Annotations:} \\\\ ';
958: $result .= "\n";
959: $result .= &Apache::lonxml::latex_special_symbols($annotation_text,""); # Escape latex.
960: $result .= "\n\n";
961: }
962: return $result;
963: }
964:
1.556 foxr 965: #
966: # Set a global document font size:
967: # This is done by replacing \begin{document}
968: # with \begin{document}{\some-font-directive
969: # and \end{document} with
970: # }\end{document
971: #
972: sub set_font_size {
973:
974: my ($text) = @_;
975:
1.575 foxr 976: # There appear to be cases where the font directive is empty.. in which
1.688 raeburn 977: # case the first substitution would insert a spurious \ oh happy day.
1.575 foxr 978: # as this has been the cause of much mystery and hair pulling _sigh_
979:
980: if ($font_size ne '') {
981:
1.649 raeburn 982: $text =~ s/\\begin\{document}/\\begin{document}{\\$font_size/;
1.669 raeburn 983: $text =~ s/\\end\{document}/}\\end{document}/;
984:
1.575 foxr 985: }
1.556 foxr 986: return $text;
987:
988:
989: }
990:
1.699 raeburn 991: # include_pdf - PDF files are included into the
1.550 foxr 992: # output as follows:
993: # - The PDF, if necessary, is replicated.
994: # - The PDF is added to the list of files to convert to postscript (along with the images).
995: # - The LaTeX is added to include the final converted postscript in the file as an included
1.688 raeburn 996: # job. The assumption is that the includepsheader.ps header will be included.
1.550 foxr 997: #
998: # Parameters:
999: # pdf_uri - URI of the PDF file to include.
1.699 raeburn 1000: #
1.550 foxr 1001: # Returns:
1002: # The LaTeX to include.
1003: #
1004: # Assumptions:
1005: # The uri is actually a PDF file
1006: # The postscript will have the includepsheader.ps included.
1007: #
1008: #
1009: sub include_pdf {
1010: my ($pdf_uri) = @_;
1011:
1012: # Where is the file? If not local we'll need to repcopy it:'
1013:
1014: my $file = &Apache::lonnet::filelocation('', $pdf_uri);
1015: if (! -e $file) {
1016: &Apache::lonnet::repcopy($file);
1017: $file = &Apache::lonnet::filelocation('',$pdf_uri);
1018: }
1019:
1.688 raeburn 1020: # The file is now replicated locally ... or it did not exist in the first place
1.550 foxr 1021: # (unlikely). If it did exist, add the pdf to the set of files/images that
1.688 raeburn 1022: # need to be converted for this print job:
1.550 foxr 1023:
1.608 raeburn 1024: my $londocroot = $Apache::lonnet::perlvar{'lonDocRoot'};
1025: $file =~ s{(.*)/res/}{$londocroot/res/};
1.550 foxr 1026:
1.659 raeburn 1027: open(FILE,">>","$Apache::lonnet::perlvar{'lonPrtDir'}/$env{'user.name'}_$env{'user.domain'}_printout.dat");
1.550 foxr 1028: print FILE ("$file\n");
1029: close (FILE);
1030:
1031: # Construct the special to put out. To do this we need to get the
1032: # resulting filename after conversion. The file will have the same name
1033: # but will be in the user's spool directory with converted images.
1034:
1035: my $dirname = "/home/httpd/prtspool/$env{'user.name'}/";
1036: my ( $base, $path, $ext) = &fileparse($file, '.pdf');
1037: # my $destname = $dirname.'/'.$base.'.eps'; # Not really an eps but easier in printout.pl
1038: $base =~ s/ /\_/g;
1039:
1040:
1.551 foxr 1041: my $output = &print_latex_header();
1.550 foxr 1042: $output .= '\special{ps: _begin_job_ ('
1043: .$base.'.pdf.eps'.
1044: ')run _end_job_}';
1045:
1046: return $output;
1047:
1048:
1049: }
1.612 foxr 1050: ##
1051: # Collect the various \select_language{language_name}
1052: # latex tags to build a \usepackage[lang-list]{babel} which will
1053: # appear just prior to the \begin{document} at the front of the concatenated
1054: # set of resources:
1055: # @param doc - The string of latex to search/replace.
1056: # @return string
1057: # @retval - the modified document stringt.
1058: #
1059: sub collect_languages {
1060: my $doc = shift;
1061: my %languages;
1.649 raeburn 1062: while ($doc =~ /\\selectlanguage\{(\w+)}/mg) {
1.612 foxr 1063: $languages{$1} = 1; # allows us to request each language exactly once.
1064: }
1065: my @lang_list = (keys(%languages)); # List of unique languages
1066: if (scalar @lang_list) {
1067: my $babel_header = '\usepackage[' . join(',', @lang_list) .']{babel}'. "\n";
1.649 raeburn 1068: $doc =~ s/\\begin\{document}/$babel_header\\begin{document}/;
1.612 foxr 1069: }
1070: return $doc;
1071: }
1072: #-------------------------------------------------------------------
1.515 foxr 1073:
1074: #
1.559 foxr 1075: # ssi_with_retries- Does the server side include of a resource.
1.515 foxr 1076: # if the ssi call returns an error we'll retry it up to
1077: # the number of times requested by the caller.
1078: # If we still have a proble, no text is appended to the
1079: # output and we set some global variables.
1.699 raeburn 1080: # to indicate to the caller an SSI error occurred.
1.515 foxr 1081: # All of this is supposed to deal with the issues described
1082: # in LonCAPA BZ 5631 see:
1083: # http://bugs.lon-capa.org/show_bug.cgi?id=5631
1084: # by informing the user that this happened.
1085: #
1086: # Parameters:
1087: # resource - The resource to include. This is passed directly, without
1088: # interpretation to lonnet::ssi.
1089: # form - The form hash parameters that guide the interpretation of the resource
1.699 raeburn 1090: #
1.515 foxr 1091: # retries - Number of retries allowed before giving up completely.
1092: # Returns:
1093: # On success, returns the rendered resource identified by the resource parameter.
1094: # Side Effects:
1095: # The following global variables can be set:
1.523 raeburn 1096: # ssi_error - If an unrecoverable error occurred this becomes true.
1.515 foxr 1097: # It is up to the caller to initialize this to false
1098: # if desired.
1.523 raeburn 1099: # ssi_last_error_resource - If an unrecoverable error occurred, this is the value
1.515 foxr 1100: # of the resource that could not be rendered by the ssi
1101: # call.
1102: # ssi_last_error - The error string fetched from the ssi response
1103: # in the event of an error.
1104: #
1105: sub ssi_with_retries {
1106: my ($resource, $retries, %form) = @_;
1107:
1.559 foxr 1108: my $target = $form{'grade_target'};
1109: my $aom = $form{'answer_output_mode'};
1110:
1111:
1.515 foxr 1112:
1.516 foxr 1113: my ($content, $response) = &Apache::loncommon::ssi_with_retries($resource, $retries, %form);
1114: if (!$response->is_success) {
1.515 foxr 1115: $ssi_error = 1;
1116: $ssi_last_error_resource = $resource;
1.516 foxr 1117: $ssi_last_error = $response->code . " " . $response->message;
1.528 raeburn 1118: $content='\section*{!!! An error occurred !!!}';
1.515 foxr 1119: }
1.516 foxr 1120:
1121: return $content;
1122:
1.515 foxr 1123: }
1124:
1.524 www 1125: sub get_student_view_with_retries {
1126: my ($curresline,$retries,$username,$userdomain,$courseid,$target,$moreenv)=@_;
1127:
1128: my ($content, $response) = &Apache::loncommon::get_student_view_with_retries($curresline,$retries,$username,$userdomain,$courseid,$target,$moreenv);
1129: if (!$response->is_success) {
1130: $ssi_error = 1;
1.526 www 1131: $ssi_last_error_resource = $curresline.' for user '.$username.':'.$userdomain;
1.524 www 1132: $ssi_last_error = $response->code . " " . $response->message;
1.528 raeburn 1133: $content='\section*{!!! An error occurred !!!}';
1.524 www 1134: }
1135: return $content;
1136:
1137: }
1138:
1.486 foxr 1139: #
1140: # printf_style_subst item format_string repl
1.699 raeburn 1141: #
1.486 foxr 1142: # Does printf style substitution for a format string that
1143: # can have %[n]item in it.. wherever, %[n]item occurs,
1144: # rep is substituted in format_string. Note that
1145: # [n] is an optional integer length. If provided,
1.699 raeburn 1146: # repl is truncated to at most [n] characters prior to
1.486 foxr 1147: # substitution.
1148: #
1149: sub printf_style_subst {
1150: my ($item, $format_string, $repl) = @_;
1.490 foxr 1151: my $result = "";
1152: while ($format_string =~ /(%)(\d*)\Q$item\E/g ) {
1.488 albertel 1153: my $fmt = $1;
1154: my $size = $2;
1.486 foxr 1155: my $subst = $repl;
1156: if ($size ne "") {
1157: $subst = substr($subst, 0, $size);
1.699 raeburn 1158:
1.689 raeburn 1159: # Here's a nice edge case ... suppose the end of the
1.688 raeburn 1160: # substring is a \. In that case may have just
1.490 foxr 1161: # chopped off a TeX escape... in that case, we append
1.699 raeburn 1162: # " " for the trailing character, and let the field
1.490 foxr 1163: # spill over a bit (sigh).
1164: # We don't just chop off the last character in order to deal
1165: # with one last pathology, and that would be if substr had
1.699 raeburn 1166: # trimmed us to e.g. \\\
1.490 foxr 1167:
1168:
1169: if ($subst =~ /\\$/) {
1170: $subst .= " ";
1171: }
1.486 foxr 1172: }
1.490 foxr 1173: my $item_pos = pos($format_string);
1174: $result .= substr($format_string, 0, $item_pos - length($size) -2) . $subst;
1175: $format_string = substr($format_string, pos($format_string));
1.486 foxr 1176: }
1.490 foxr 1177:
1178: # Put the residual format string into the result:
1179:
1180: $result .= $format_string;
1181:
1182: return $result;
1.486 foxr 1183: }
1184:
1.454 foxr 1185:
1.699 raeburn 1186: # Format a header according to a format.
1187: #
1.454 foxr 1188:
1189: # Substitutions:
1190: # %a - Assignment name.
1191: # %c - Course name.
1192: # %n - Student name.
1.537 foxr 1193: # %s - The section if it is supplied.
1.454 foxr 1194: #
1195: sub format_page_header {
1.537 foxr 1196: my ($width, $format, $assignment, $course, $student, $section) = @_;
1197:
1.565 foxr 1198:
1199:
1.486 foxr 1200: $width = &recalcto_mm($width); # Get width in mm.
1.565 foxr 1201: my $chars_per_line = int($width/1.6); # Character/textline.
1202:
1.454 foxr 1203: # Default format?
1204:
1205: if ($format eq '') {
1.486 foxr 1206: # For the default format, we may need to truncate
1207: # elements.. To do this we need to get the page width.
1208: # we assume that each character is about 2mm in width.
1209: # (correct for the header text size??). We ignore
1210: # any formatting (e.g. boldfacing in this).
1.699 raeburn 1211: #
1.486 foxr 1212: # - Allow the student/course to be one line.
1213: # but only truncate the course.
1214: # - Allow the assignment to be 2 lines (wrapped).
1215: #
1.565 foxr 1216:
1.537 foxr 1217:
1218:
1219: my $name_length = int($chars_per_line *3 /4);
1220: my $sec_length = int($chars_per_line / 5);
1.486 foxr 1221:
1.537 foxr 1222: $format = "%$name_length".'n';
1.486 foxr 1223:
1.537 foxr 1224: if ($section) {
1225: $format .= ' - Sec: '."%$sec_length".'s';
1.486 foxr 1226: }
1.700 raeburn 1227: $format .= '\\hfill\\thepage';
1.489 foxr 1228:
1.537 foxr 1229: $format .= '\\\\%c \\\\ %a';
1.699 raeburn 1230:
1.490 foxr 1231:
1.454 foxr 1232: }
1.537 foxr 1233: # An open question is how to handle long user formatted page headers...
1234: # A possible future is to support e.g. %na so that the user can control
1235: # the truncation of the elements that can appear in the header.
1236: #
1237: $format = &printf_style_subst("a", $format, $assignment);
1238: $format = &printf_style_subst("c", $format, $course);
1239: $format = &printf_style_subst("n", $format, $student);
1240: $format = &printf_style_subst("s", $format, $section);
1.699 raeburn 1241:
1242:
1.537 foxr 1243: # If the user put %'s in the format string, they must be escaped
1244: # to \% else LaTeX will think they are comments and terminate
1245: # the line.. which is bad!!!
1.699 raeburn 1246:
1.538 onken 1247: # If the user has role author, $course and $assignment are empty so
1248: # there is '\\ \\ ' in the page header. That's cause a error in LaTeX
1249: if($format =~ /\\\\\s\\\\\s/) {
1250: #TODO find sensible caption for page header
1.633 raeburn 1251: my $testPrintout = '\\\\'.&mt('Authoring Space').' \\\\'.&mt('Test-Printout ');
1.538 onken 1252: $format =~ s/\\\\\s\\\\\s/$testPrintout/;
1253: }
1.565 foxr 1254: #
1255: # We're going to trust LaTeX to break lines appropriately, but
1256: # we'll truncate anything that's more than 3 lines worth of
1257: # text. This is also assuming (which will probably end badly)
1258: # nobody's going to embed LaTeX control sequences in the title
1259: # header or rather that those control sequences won't get broken
1260: # by the stuff below.
1261: #
1262: my $total_length = 3*$chars_per_line;
1263: if (length($format) > $total_length) {
1264: $format = substr($format, 0, $total_length);
1265: }
1266:
1.454 foxr 1267:
1268: return $format;
1.699 raeburn 1269:
1.454 foxr 1270: }
1.397 albertel 1271:
1.385 foxr 1272: #
1273: # Convert a numeric code to letters
1274: #
1275: sub num_to_letters {
1276: my ($num) = @_;
1277: my @nums= split('',$num);
1278: my @num_to_let=('A'..'Z');
1279: my $word;
1280: foreach my $digit (@nums) { $word.=$num_to_let[$digit]; }
1281: return $word;
1282: }
1283: # Convert a letter code to numeric.
1284: #
1285: sub letters_to_num {
1286: my ($letters) = @_;
1287: my @letters = split('', uc($letters));
1.490 foxr 1288: my %substitution;
1.385 foxr 1289: my $digit = 0;
1290: foreach my $letter ('A'..'J') {
1291: $substitution{$letter} = $digit;
1292: $digit++;
1293: }
1294: # The substitution is done as below to preserve leading
1295: # zeroes which are needed to keep the code size exact
1296: #
1297: my $result ="";
1298: foreach my $letter (@letters) {
1299: $result.=$substitution{$letter};
1300: }
1301: return $result;
1302: }
1303:
1.383 foxr 1304: # Determine if a code is a valid numeric code. Valid
1305: # numeric codes must be comprised entirely of digits and
1.384 albertel 1306: # have a correct number of digits.
1.383 foxr 1307: #
1308: # Parameters:
1309: # value - proposed code value.
1.384 albertel 1310: # num_digits - Number of digits required.
1.383 foxr 1311: #
1312: sub is_valid_numeric_code {
1.384 albertel 1313: my ($value, $num_digits) = @_;
1.383 foxr 1314: # Remove leading/trailing whitespace;
1.387 foxr 1315: $value =~ s/^\s*//g;
1316: $value =~ s/\s*$//g;
1.699 raeburn 1317:
1.383 foxr 1318: # All digits?
1.387 foxr 1319: if ($value !~ /^[0-9]+$/) {
1.383 foxr 1320: return "Numeric code $value has invalid characters - must only be digits";
1321: }
1.384 albertel 1322: if (length($value) != $num_digits) {
1323: return "Numeric code $value incorrect number of digits (correct = $num_digits)";
1324: }
1.385 foxr 1325: return undef;
1.383 foxr 1326: }
1327: # Determines if a code is a valid alhpa code. Alpha codes
1328: # are ciphers that map [A-J,a-j] -> 0..9 0..9.
1.384 albertel 1329: # They also have a correct digit count.
1.383 foxr 1330: # Parameters:
1331: # value - Proposed code value.
1.384 albertel 1332: # num_letters - correct number of letters.
1.383 foxr 1333: # Note:
1334: # leading and trailing whitespace are ignored.
1335: #
1336: sub is_valid_alpha_code {
1.384 albertel 1337: my ($value, $num_letters) = @_;
1.699 raeburn 1338:
1.383 foxr 1339: # strip leading and trailing spaces.
1340:
1341: $value =~ s/^\s*//g;
1342: $value =~ s/\s*$//g;
1343:
1344: # All alphas in the right range?
1.384 albertel 1345: if ($value !~ /^[A-J,a-j]+$/) {
1.383 foxr 1346: return "Invalid letter code $value must only contain A-J";
1347: }
1.384 albertel 1348: if (length($value) != $num_letters) {
1349: return "Letter code $value has incorrect number of letters (correct = $num_letters)";
1350: }
1.385 foxr 1351: return undef;
1.383 foxr 1352: }
1353:
1.382 foxr 1354: # Determine if a code entered by the user in a helper is valid.
1355: # valid depends on the code type and the type of code selected.
1.699 raeburn 1356: # The type of code selected can either be numeric or
1.382 foxr 1357: # Alphabetic. If alphabetic, the code, in fact is a simple
1358: # substitution cipher for the actual numeric code: 0->A, 1->B ...
1359: # We'll be nice and be case insensitive for alpha codes.
1360: # Parameters:
1361: # code_value - the value of the code the user typed in.
1362: # code_option - The code type selected from the set in the scantron format
1363: # table.
1364: # Returns:
1365: # undef - The code is valid.
1366: # other - An error message indicating what's wrong.
1367: #
1368: sub is_code_valid {
1369: my ($code_value, $code_option) = @_;
1.383 foxr 1370: my ($code_type, $code_length) = ('letter', 6); # defaults.
1.668 raeburn 1371: my @lines = &Apache::lonnet::get_scantronformat_file();
1.542 raeburn 1372: foreach my $line (@lines) {
1.678 raeburn 1373: next if (($line =~ /^\#/) || ($line eq ''));
1.383 foxr 1374: my ($name, $type, $length) = (split(/:/, $line))[0,2,4];
1375: if($name eq $code_option) {
1376: $code_length = $length;
1377: if($type eq 'number') {
1378: $code_type = 'number';
1379: }
1380: }
1381: }
1382: my $valid;
1383: if ($code_type eq 'number') {
1.385 foxr 1384: return &is_valid_numeric_code($code_value, $code_length);
1.383 foxr 1385: } else {
1.385 foxr 1386: return &is_valid_alpha_code($code_value, $code_length);
1.383 foxr 1387: }
1.382 foxr 1388:
1389: }
1.618 foxr 1390: #
1391: # Compare two students by section (Used to sort by section).
1392: #
1.699 raeburn 1393: # Implicit inputs,
1.618 foxr 1394: # $a - The first one
1395: # $b - The second one.
1396: #
1397: # Returns:
1398: # a-section cmp b-section
1399: #
1400: sub compare_sections {
1401: my ($u1, $d1, $s1, $n1, $stat1) = split(/:/, $a);
1402: my ($u2, $d2, $s2, $n2, $stat2) = split(/:/, $b);
1403:
1404: return $s1 cmp $s2;
1405: }
1.382 foxr 1406:
1.341 foxr 1407: # Compare two students by name. The students are in the form
1408: # returned by the helper:
1409: # user:domain:section:last, first:status
1410: # This is a helper function for the perl sort built-in therefore:
1411: # Implicit Inputs:
1412: # $a - The first element to compare (global)
1413: # $b - The second element to compare (global)
1414: # Returns:
1415: # -1 - $a < $b
1416: # 0 - $a == $b
1417: # +1 - $a > $b
1418: # Note that the initial comparison is done on the last names with the
1419: # first names only used to break the tie.
1420: #
1421: #
1422: sub compare_names {
1423: # First split the names up into the primary fields.
1424:
1425: my ($u1, $d1, $s1, $n1, $stat1) = split(/:/, $a);
1426: my ($u2, $d2, $s2, $n2, $stat2) = split(/:/, $b);
1427:
1428: # Now split the last name and first name of each n:
1429: #
1430:
1431: my ($l1,$f1) = split(/,/, $n1);
1432: my ($l2,$f2) = split(/,/, $n2);
1433:
1434: # We don't bother to remove the leading/trailing whitespace from the
1435: # firstname, unless the last names compare identical.
1436:
1437: if($l1 lt $l2) {
1438: return -1;
1439: }
1440: if($l1 gt $l2) {
1441: return 1;
1442: }
1443:
1444: # Break the tie on the first name, but there are leading (possibly trailing
1.688 raeburn 1445: # whitespaces to get rid of first)
1.341 foxr 1446: #
1447: $f1 =~ s/^\s+//; # Remove leading...
1448: $f1 =~ s/\s+$//; # Trailing spaces from first 1...
1.699 raeburn 1449:
1.341 foxr 1450: $f2 =~ s/^\s+//;
1451: $f2 =~ s/\s+$//; # And the same for first 2...
1452:
1453: if($f1 lt $f2) {
1454: return -1;
1455: }
1456: if($f1 gt $f2) {
1457: return 1;
1458: }
1.699 raeburn 1459:
1.341 foxr 1460: # Must be the same name.
1461:
1462: return 0;
1463: }
1464:
1.71 sakharuk 1465: sub latex_header_footer_remove {
1466: my $text = shift;
1.649 raeburn 1467: $text =~ s/\\end\{document}//;
1468: $text =~ s/\\documentclass([^&]*)\\begin\{document}//;
1.71 sakharuk 1469: return $text;
1470: }
1.423 foxr 1471: #
1.699 raeburn 1472: # If necessary, encapsulate text inside
1.423 foxr 1473: # a minipage env.
1474: # necessity is determined by the problem_split param.
1475: #
1476: sub encapsulate_minipage {
1.676 raeburn 1477: my ($text,$problem_split) = @_;
1478: if (!($problem_split =~ /yes/i)) {
1.423 foxr 1479: $text = '\begin{minipage}{\textwidth}'.$text.'\end{minipage}';
1480: }
1481: return $text;
1482: }
1.429 foxr 1483: #
1484: # The NUMBER_TO_PRINT and SPLIT_PDFS
1485: # variables interact, this sub looks at these two parameters
1486: # and comes up with a final value for NUMBER_TO_PRINT which can be:
1487: # all - if SPLIT_PDFS eq 'all'.
1488: # 1 - if SPLIT_PDFS eq 'oneper'
1489: # section - if SPLIT_PDFS eq 'sections'
1490: # <unchanged> - if SPLIT_PDFS eq 'usenumber'
1491: #
1492: sub adjust_number_to_print {
1493: my $helper = shift;
1.71 sakharuk 1494:
1.429 foxr 1495: my $split_pdf = $helper->{'VARS'}->{'SPLIT_PDFS'};
1.699 raeburn 1496:
1.429 foxr 1497: if ($split_pdf eq 'all') {
1498: $helper->{'VARS'}->{'NUMBER_TO_PRINT'} = 'all';
1499: } elsif ($split_pdf eq 'oneper') {
1500: $helper->{'VARS'}->{'NUMBER_TO_PRINT'} = 1;
1501: } elsif ($split_pdf eq 'sections') {
1502: $helper->{'VARS'}->{'NUMBER_TO_PRINT'} = 'section';
1503: } elsif ($split_pdf eq 'usenumber') {
1504: # Unmodified.
1505: } else {
1506: # Error!!!!
1.536 foxr 1507:
1508: croak "bad SPLIT_PDFS: $split_pdf in lonprintout::adjust_number_to_print";
1.429 foxr 1509:
1510: }
1511: }
1.71 sakharuk 1512:
1.531 foxr 1513:
1.37 sakharuk 1514: sub character_chart {
1.531 foxr 1515: my $result = shift;
1516: return &Apache::entities::replace_entities($result);
1517: }
1518:
1519: sub old_character_chart {
1.37 sakharuk 1520: my $result = shift;
1.116 sakharuk 1521: $result =~ s/&\#0?0?(7|9);//g;
1522: $result =~ s/&\#0?(10|13);//g;
1523: $result =~ s/&\#0?32;/ /g;
1524: $result =~ s/&\#0?33;/!/g;
1525: $result =~ s/&(\#0?34|quot);/\"/g;
1526: $result =~ s/&\#0?35;/\\\#/g;
1527: $result =~ s/&\#0?36;/\\\$/g;
1.699 raeburn 1528: $result =~ s/&\#0?37;/\\%/g;
1529: $result =~ s/&(\#0?38|amp);/\\&/g;
1.116 sakharuk 1530: $result =~ s/&\#(0?39|146);/\'/g;
1531: $result =~ s/&\#0?40;/(/g;
1532: $result =~ s/&\#0?41;/)/g;
1533: $result =~ s/&\#0?42;/\*/g;
1534: $result =~ s/&\#0?43;/\+/g;
1535: $result =~ s/&\#(0?44|130);/,/g;
1536: $result =~ s/&\#0?45;/-/g;
1537: $result =~ s/&\#0?46;/\./g;
1538: $result =~ s/&\#0?47;/\//g;
1539: $result =~ s/&\#0?48;/0/g;
1540: $result =~ s/&\#0?49;/1/g;
1541: $result =~ s/&\#0?50;/2/g;
1542: $result =~ s/&\#0?51;/3/g;
1543: $result =~ s/&\#0?52;/4/g;
1544: $result =~ s/&\#0?53;/5/g;
1545: $result =~ s/&\#0?54;/6/g;
1546: $result =~ s/&\#0?55;/7/g;
1547: $result =~ s/&\#0?56;/8/g;
1548: $result =~ s/&\#0?57;/9/g;
1.269 albertel 1549: $result =~ s/&\#0?58;/:/g;
1.116 sakharuk 1550: $result =~ s/&\#0?59;/;/g;
1551: $result =~ s/&(\#0?60|lt|\#139);/\$<\$/g;
1.281 sakharuk 1552: $result =~ s/&\#0?61;/\\ensuremath\{=\}/g;
1553: $result =~ s/&(\#0?62|gt|\#155);/\\ensuremath\{>\}/g;
1.116 sakharuk 1554: $result =~ s/&\#0?63;/\?/g;
1555: $result =~ s/&\#0?65;/A/g;
1556: $result =~ s/&\#0?66;/B/g;
1557: $result =~ s/&\#0?67;/C/g;
1558: $result =~ s/&\#0?68;/D/g;
1559: $result =~ s/&\#0?69;/E/g;
1560: $result =~ s/&\#0?70;/F/g;
1561: $result =~ s/&\#0?71;/G/g;
1562: $result =~ s/&\#0?72;/H/g;
1563: $result =~ s/&\#0?73;/I/g;
1564: $result =~ s/&\#0?74;/J/g;
1565: $result =~ s/&\#0?75;/K/g;
1566: $result =~ s/&\#0?76;/L/g;
1567: $result =~ s/&\#0?77;/M/g;
1568: $result =~ s/&\#0?78;/N/g;
1569: $result =~ s/&\#0?79;/O/g;
1570: $result =~ s/&\#0?80;/P/g;
1571: $result =~ s/&\#0?81;/Q/g;
1572: $result =~ s/&\#0?82;/R/g;
1573: $result =~ s/&\#0?83;/S/g;
1574: $result =~ s/&\#0?84;/T/g;
1575: $result =~ s/&\#0?85;/U/g;
1576: $result =~ s/&\#0?86;/V/g;
1577: $result =~ s/&\#0?87;/W/g;
1578: $result =~ s/&\#0?88;/X/g;
1579: $result =~ s/&\#0?89;/Y/g;
1580: $result =~ s/&\#0?90;/Z/g;
1581: $result =~ s/&\#0?91;/[/g;
1.281 sakharuk 1582: $result =~ s/&\#0?92;/\\ensuremath\{\\setminus\}/g;
1.116 sakharuk 1583: $result =~ s/&\#0?93;/]/g;
1.281 sakharuk 1584: $result =~ s/&\#(0?94|136);/\\ensuremath\{\\wedge\}/g;
1.116 sakharuk 1585: $result =~ s/&\#(0?95|138|154);/\\underline{\\makebox[2mm]{\\strut}}/g;
1586: $result =~ s/&\#(0?96|145);/\`/g;
1587: $result =~ s/&\#0?97;/a/g;
1588: $result =~ s/&\#0?98;/b/g;
1589: $result =~ s/&\#0?99;/c/g;
1590: $result =~ s/&\#100;/d/g;
1591: $result =~ s/&\#101;/e/g;
1592: $result =~ s/&\#102;/f/g;
1593: $result =~ s/&\#103;/g/g;
1594: $result =~ s/&\#104;/h/g;
1595: $result =~ s/&\#105;/i/g;
1596: $result =~ s/&\#106;/j/g;
1597: $result =~ s/&\#107;/k/g;
1598: $result =~ s/&\#108;/l/g;
1599: $result =~ s/&\#109;/m/g;
1600: $result =~ s/&\#110;/n/g;
1601: $result =~ s/&\#111;/o/g;
1602: $result =~ s/&\#112;/p/g;
1603: $result =~ s/&\#113;/q/g;
1604: $result =~ s/&\#114;/r/g;
1605: $result =~ s/&\#115;/s/g;
1606: $result =~ s/&\#116;/t/g;
1607: $result =~ s/&\#117;/u/g;
1608: $result =~ s/&\#118;/v/g;
1609: $result =~ s/&\#119;/w/g;
1610: $result =~ s/&\#120;/x/g;
1611: $result =~ s/&\#121;/y/g;
1612: $result =~ s/&\#122;/z/g;
1613: $result =~ s/&\#123;/\\{/g;
1614: $result =~ s/&\#124;/\|/g;
1615: $result =~ s/&\#125;/\\}/g;
1616: $result =~ s/&\#126;/\~/g;
1617: $result =~ s/&\#131;/\\textflorin /g;
1618: $result =~ s/&\#132;/\"/g;
1.281 sakharuk 1619: $result =~ s/&\#133;/\\ensuremath\{\\ldots\}/g;
1620: $result =~ s/&\#134;/\\ensuremath\{\\dagger\}/g;
1621: $result =~ s/&\#135;/\\ensuremath\{\\ddagger\}/g;
1.116 sakharuk 1622: $result =~ s/&\#137;/\\textperthousand /g;
1623: $result =~ s/&\#140;/{\\OE}/g;
1624: $result =~ s/&\#147;/\`\`/g;
1625: $result =~ s/&\#148;/\'\'/g;
1.281 sakharuk 1626: $result =~ s/&\#149;/\\ensuremath\{\\bullet\}/g;
1.494 albertel 1627: $result =~ s/&(\#150|\#8211);/--/g;
1.116 sakharuk 1628: $result =~ s/&\#151;/---/g;
1.281 sakharuk 1629: $result =~ s/&\#152;/\\ensuremath\{\\sim\}/g;
1.116 sakharuk 1630: $result =~ s/&\#153;/\\texttrademark /g;
1631: $result =~ s/&\#156;/\\oe/g;
1632: $result =~ s/&\#159;/\\\"Y/g;
1.283 albertel 1633: $result =~ s/&(\#160|nbsp);/~/g;
1.116 sakharuk 1634: $result =~ s/&(\#161|iexcl);/!\`/g;
1635: $result =~ s/&(\#162|cent);/\\textcent /g;
1.699 raeburn 1636: $result =~ s/&(\#163|pound);/\\pounds /g;
1.116 sakharuk 1637: $result =~ s/&(\#164|curren);/\\textcurrency /g;
1638: $result =~ s/&(\#165|yen);/\\textyen /g;
1639: $result =~ s/&(\#166|brvbar);/\\textbrokenbar /g;
1640: $result =~ s/&(\#167|sect);/\\textsection /g;
1.530 foxr 1641: $result =~ s/&(\#168|uml);/\\"\{\} /g;
1.116 sakharuk 1642: $result =~ s/&(\#169|copy);/\\copyright /g;
1643: $result =~ s/&(\#170|ordf);/\\textordfeminine /g;
1.281 sakharuk 1644: $result =~ s/&(\#172|not);/\\ensuremath\{\\neg\}/g;
1.116 sakharuk 1645: $result =~ s/&(\#173|shy);/ - /g;
1646: $result =~ s/&(\#174|reg);/\\textregistered /g;
1.281 sakharuk 1647: $result =~ s/&(\#175|macr);/\\ensuremath\{^{-}\}/g;
1648: $result =~ s/&(\#176|deg);/\\ensuremath\{^{\\circ}\}/g;
1649: $result =~ s/&(\#177|plusmn);/\\ensuremath\{\\pm\}/g;
1650: $result =~ s/&(\#178|sup2);/\\ensuremath\{^2\}/g;
1651: $result =~ s/&(\#179|sup3);/\\ensuremath\{^3\}/g;
1.530 foxr 1652: $result =~ s/&(\#180|acute);/\\'\{\} /g;
1.281 sakharuk 1653: $result =~ s/&(\#181|micro);/\\ensuremath\{\\mu\}/g;
1.116 sakharuk 1654: $result =~ s/&(\#182|para);/\\P/g;
1.281 sakharuk 1655: $result =~ s/&(\#183|middot);/\\ensuremath\{\\cdot\}/g;
1.116 sakharuk 1656: $result =~ s/&(\#184|cedil);/\\c{\\strut}/g;
1.281 sakharuk 1657: $result =~ s/&(\#185|sup1);/\\ensuremath\{^1\}/g;
1.116 sakharuk 1658: $result =~ s/&(\#186|ordm);/\\textordmasculine /g;
1659: $result =~ s/&(\#188|frac14);/\\textonequarter /g;
1660: $result =~ s/&(\#189|frac12);/\\textonehalf /g;
1661: $result =~ s/&(\#190|frac34);/\\textthreequarters /g;
1.699 raeburn 1662: $result =~ s/&(\#191|iquest);/?\`/g;
1663: $result =~ s/&(\#192|Agrave);/\\\`{A}/g;
1664: $result =~ s/&(\#193|Aacute);/\\\'{A}/g;
1.116 sakharuk 1665: $result =~ s/&(\#194|Acirc);/\\^{A}/g;
1666: $result =~ s/&(\#195|Atilde);/\\~{A}/g;
1.699 raeburn 1667: $result =~ s/&(\#196|Auml);/\\\"{A}/g;
1.116 sakharuk 1668: $result =~ s/&(\#197|Aring);/{\\AA}/g;
1669: $result =~ s/&(\#198|AElig);/{\\AE}/g;
1670: $result =~ s/&(\#199|Ccedil);/\\c{c}/g;
1.699 raeburn 1671: $result =~ s/&(\#200|Egrave);/\\\`{E}/g;
1672: $result =~ s/&(\#201|Eacute);/\\\'{E}/g;
1.116 sakharuk 1673: $result =~ s/&(\#202|Ecirc);/\\^{E}/g;
1674: $result =~ s/&(\#203|Euml);/\\\"{E}/g;
1675: $result =~ s/&(\#204|Igrave);/\\\`{I}/g;
1.699 raeburn 1676: $result =~ s/&(\#205|Iacute);/\\\'{I}/g;
1.116 sakharuk 1677: $result =~ s/&(\#206|Icirc);/\\^{I}/g;
1.699 raeburn 1678: $result =~ s/&(\#207|Iuml);/\\\"{I}/g;
1.116 sakharuk 1679: $result =~ s/&(\#209|Ntilde);/\\~{N}/g;
1680: $result =~ s/&(\#210|Ograve);/\\\`{O}/g;
1681: $result =~ s/&(\#211|Oacute);/\\\'{O}/g;
1682: $result =~ s/&(\#212|Ocirc);/\\^{O}/g;
1683: $result =~ s/&(\#213|Otilde);/\\~{O}/g;
1.699 raeburn 1684: $result =~ s/&(\#214|Ouml);/\\\"{O}/g;
1.281 sakharuk 1685: $result =~ s/&(\#215|times);/\\ensuremath\{\\times\}/g;
1.116 sakharuk 1686: $result =~ s/&(\#216|Oslash);/{\\O}/g;
1.699 raeburn 1687: $result =~ s/&(\#217|Ugrave);/\\\`{U}/g;
1.116 sakharuk 1688: $result =~ s/&(\#218|Uacute);/\\\'{U}/g;
1689: $result =~ s/&(\#219|Ucirc);/\\^{U}/g;
1690: $result =~ s/&(\#220|Uuml);/\\\"{U}/g;
1691: $result =~ s/&(\#221|Yacute);/\\\'{Y}/g;
1.329 sakharuk 1692: $result =~ s/&(\#223|szlig);/{\\ss}/g;
1.116 sakharuk 1693: $result =~ s/&(\#224|agrave);/\\\`{a}/g;
1694: $result =~ s/&(\#225|aacute);/\\\'{a}/g;
1695: $result =~ s/&(\#226|acirc);/\\^{a}/g;
1696: $result =~ s/&(\#227|atilde);/\\~{a}/g;
1697: $result =~ s/&(\#228|auml);/\\\"{a}/g;
1698: $result =~ s/&(\#229|aring);/{\\aa}/g;
1699: $result =~ s/&(\#230|aelig);/{\\ae}/g;
1700: $result =~ s/&(\#231|ccedil);/\\c{c}/g;
1701: $result =~ s/&(\#232|egrave);/\\\`{e}/g;
1702: $result =~ s/&(\#233|eacute);/\\\'{e}/g;
1703: $result =~ s/&(\#234|ecirc);/\\^{e}/g;
1704: $result =~ s/&(\#235|euml);/\\\"{e}/g;
1705: $result =~ s/&(\#236|igrave);/\\\`{i}/g;
1706: $result =~ s/&(\#237|iacute);/\\\'{i}/g;
1707: $result =~ s/&(\#238|icirc);/\\^{i}/g;
1708: $result =~ s/&(\#239|iuml);/\\\"{i}/g;
1.281 sakharuk 1709: $result =~ s/&(\#240|eth);/\\ensuremath\{\\partial\}/g;
1.116 sakharuk 1710: $result =~ s/&(\#241|ntilde);/\\~{n}/g;
1711: $result =~ s/&(\#242|ograve);/\\\`{o}/g;
1712: $result =~ s/&(\#243|oacute);/\\\'{o}/g;
1713: $result =~ s/&(\#244|ocirc);/\\^{o}/g;
1714: $result =~ s/&(\#245|otilde);/\\~{o}/g;
1715: $result =~ s/&(\#246|ouml);/\\\"{o}/g;
1.281 sakharuk 1716: $result =~ s/&(\#247|divide);/\\ensuremath\{\\div\}/g;
1.116 sakharuk 1717: $result =~ s/&(\#248|oslash);/{\\o}/g;
1.699 raeburn 1718: $result =~ s/&(\#249|ugrave);/\\\`{u}/g;
1.116 sakharuk 1719: $result =~ s/&(\#250|uacute);/\\\'{u}/g;
1720: $result =~ s/&(\#251|ucirc);/\\^{u}/g;
1721: $result =~ s/&(\#252|uuml);/\\\"{u}/g;
1722: $result =~ s/&(\#253|yacute);/\\\'{y}/g;
1723: $result =~ s/&(\#255|yuml);/\\\"{y}/g;
1.399 albertel 1724: $result =~ s/&\#295;/\\ensuremath\{\\hbar\}/g;
1.281 sakharuk 1725: $result =~ s/&\#952;/\\ensuremath\{\\theta\}/g;
1.117 sakharuk 1726: #Greek Alphabet
1.281 sakharuk 1727: $result =~ s/&(alpha|\#945);/\\ensuremath\{\\alpha\}/g;
1728: $result =~ s/&(beta|\#946);/\\ensuremath\{\\beta\}/g;
1729: $result =~ s/&(gamma|\#947);/\\ensuremath\{\\gamma\}/g;
1730: $result =~ s/&(delta|\#948);/\\ensuremath\{\\delta\}/g;
1731: $result =~ s/&(epsilon|\#949);/\\ensuremath\{\\epsilon\}/g;
1732: $result =~ s/&(zeta|\#950);/\\ensuremath\{\\zeta\}/g;
1733: $result =~ s/&(eta|\#951);/\\ensuremath\{\\eta\}/g;
1734: $result =~ s/&(theta|\#952);/\\ensuremath\{\\theta\}/g;
1735: $result =~ s/&(iota|\#953);/\\ensuremath\{\\iota\}/g;
1736: $result =~ s/&(kappa|\#954);/\\ensuremath\{\\kappa\}/g;
1737: $result =~ s/&(lambda|\#955);/\\ensuremath\{\\lambda\}/g;
1738: $result =~ s/&(mu|\#956);/\\ensuremath\{\\mu\}/g;
1739: $result =~ s/&(nu|\#957);/\\ensuremath\{\\nu\}/g;
1740: $result =~ s/&(xi|\#958);/\\ensuremath\{\\xi\}/g;
1.199 sakharuk 1741: $result =~ s/&(omicron|\#959);/o/g;
1.281 sakharuk 1742: $result =~ s/&(pi|\#960);/\\ensuremath\{\\pi\}/g;
1743: $result =~ s/&(rho|\#961);/\\ensuremath\{\\rho\}/g;
1744: $result =~ s/&(sigma|\#963);/\\ensuremath\{\\sigma\}/g;
1745: $result =~ s/&(tau|\#964);/\\ensuremath\{\\tau\}/g;
1746: $result =~ s/&(upsilon|\#965);/\\ensuremath\{\\upsilon\}/g;
1747: $result =~ s/&(phi|\#966);/\\ensuremath\{\\phi\}/g;
1748: $result =~ s/&(chi|\#967);/\\ensuremath\{\\chi\}/g;
1749: $result =~ s/&(psi|\#968);/\\ensuremath\{\\psi\}/g;
1750: $result =~ s/&(omega|\#969);/\\ensuremath\{\\omega\}/g;
1751: $result =~ s/&(thetasym|\#977);/\\ensuremath\{\\vartheta\}/g;
1752: $result =~ s/&(piv|\#982);/\\ensuremath\{\\varpi\}/g;
1.199 sakharuk 1753: $result =~ s/&(Alpha|\#913);/A/g;
1754: $result =~ s/&(Beta|\#914);/B/g;
1.281 sakharuk 1755: $result =~ s/&(Gamma|\#915);/\\ensuremath\{\\Gamma\}/g;
1756: $result =~ s/&(Delta|\#916);/\\ensuremath\{\\Delta\}/g;
1.199 sakharuk 1757: $result =~ s/&(Epsilon|\#917);/E/g;
1758: $result =~ s/&(Zeta|\#918);/Z/g;
1759: $result =~ s/&(Eta|\#919);/H/g;
1.281 sakharuk 1760: $result =~ s/&(Theta|\#920);/\\ensuremath\{\\Theta\}/g;
1.199 sakharuk 1761: $result =~ s/&(Iota|\#921);/I/g;
1762: $result =~ s/&(Kappa|\#922);/K/g;
1.281 sakharuk 1763: $result =~ s/&(Lambda|\#923);/\\ensuremath\{\\Lambda\}/g;
1.199 sakharuk 1764: $result =~ s/&(Mu|\#924);/M/g;
1765: $result =~ s/&(Nu|\#925);/N/g;
1.281 sakharuk 1766: $result =~ s/&(Xi|\#926);/\\ensuremath\{\\Xi\}/g;
1.199 sakharuk 1767: $result =~ s/&(Omicron|\#927);/O/g;
1.281 sakharuk 1768: $result =~ s/&(Pi|\#928);/\\ensuremath\{\\Pi\}/g;
1.199 sakharuk 1769: $result =~ s/&(Rho|\#929);/P/g;
1.281 sakharuk 1770: $result =~ s/&(Sigma|\#931);/\\ensuremath\{\\Sigma\}/g;
1.199 sakharuk 1771: $result =~ s/&(Tau|\#932);/T/g;
1.281 sakharuk 1772: $result =~ s/&(Upsilon|\#933);/\\ensuremath\{\\Upsilon\}/g;
1773: $result =~ s/&(Phi|\#934);/\\ensuremath\{\\Phi\}/g;
1.199 sakharuk 1774: $result =~ s/&(Chi|\#935);/X/g;
1.281 sakharuk 1775: $result =~ s/&(Psi|\#936);/\\ensuremath\{\\Psi\}/g;
1776: $result =~ s/&(Omega|\#937);/\\ensuremath\{\\Omega\}/g;
1.199 sakharuk 1777: #Arrows (extended HTML 4.01)
1.281 sakharuk 1778: $result =~ s/&(larr|\#8592);/\\ensuremath\{\\leftarrow\}/g;
1779: $result =~ s/&(uarr|\#8593);/\\ensuremath\{\\uparrow\}/g;
1780: $result =~ s/&(rarr|\#8594);/\\ensuremath\{\\rightarrow\}/g;
1781: $result =~ s/&(darr|\#8595);/\\ensuremath\{\\downarrow\}/g;
1782: $result =~ s/&(harr|\#8596);/\\ensuremath\{\\leftrightarrow\}/g;
1783: $result =~ s/&(lArr|\#8656);/\\ensuremath\{\\Leftarrow\}/g;
1784: $result =~ s/&(uArr|\#8657);/\\ensuremath\{\\Uparrow\}/g;
1785: $result =~ s/&(rArr|\#8658);/\\ensuremath\{\\Rightarrow\}/g;
1786: $result =~ s/&(dArr|\#8659);/\\ensuremath\{\\Downarrow\}/g;
1787: $result =~ s/&(hArr|\#8660);/\\ensuremath\{\\Leftrightarrow\}/g;
1.199 sakharuk 1788: #Mathematical Operators (extended HTML 4.01)
1.281 sakharuk 1789: $result =~ s/&(forall|\#8704);/\\ensuremath\{\\forall\}/g;
1790: $result =~ s/&(part|\#8706);/\\ensuremath\{\\partial\}/g;
1791: $result =~ s/&(exist|\#8707);/\\ensuremath\{\\exists\}/g;
1792: $result =~ s/&(empty|\#8709);/\\ensuremath\{\\emptyset\}/g;
1793: $result =~ s/&(nabla|\#8711);/\\ensuremath\{\\nabla\}/g;
1794: $result =~ s/&(isin|\#8712);/\\ensuremath\{\\in\}/g;
1795: $result =~ s/&(notin|\#8713);/\\ensuremath\{\\notin\}/g;
1796: $result =~ s/&(ni|\#8715);/\\ensuremath\{\\ni\}/g;
1797: $result =~ s/&(prod|\#8719);/\\ensuremath\{\\prod\}/g;
1798: $result =~ s/&(sum|\#8721);/\\ensuremath\{\\sum\}/g;
1799: $result =~ s/&(minus|\#8722);/\\ensuremath\{-\}/g;
1.390 albertel 1800: $result =~ s/–/\\ensuremath\{-\}/g;
1.281 sakharuk 1801: $result =~ s/&(lowast|\#8727);/\\ensuremath\{*\}/g;
1802: $result =~ s/&(radic|\#8730);/\\ensuremath\{\\surd\}/g;
1803: $result =~ s/&(prop|\#8733);/\\ensuremath\{\\propto\}/g;
1804: $result =~ s/&(infin|\#8734);/\\ensuremath\{\\infty\}/g;
1805: $result =~ s/&(ang|\#8736);/\\ensuremath\{\\angle\}/g;
1806: $result =~ s/&(and|\#8743);/\\ensuremath\{\\wedge\}/g;
1807: $result =~ s/&(or|\#8744);/\\ensuremath\{\\vee\}/g;
1808: $result =~ s/&(cap|\#8745);/\\ensuremath\{\\cap\}/g;
1809: $result =~ s/&(cup|\#8746);/\\ensuremath\{\\cup\}/g;
1810: $result =~ s/&(int|\#8747);/\\ensuremath\{\\int\}/g;
1811: $result =~ s/&(sim|\#8764);/\\ensuremath\{\\sim\}/g;
1812: $result =~ s/&(cong|\#8773);/\\ensuremath\{\\cong\}/g;
1813: $result =~ s/&(asymp|\#8776);/\\ensuremath\{\\approx\}/g;
1814: $result =~ s/&(ne|\#8800);/\\ensuremath\{\\not=\}/g;
1815: $result =~ s/&(equiv|\#8801);/\\ensuremath\{\\equiv\}/g;
1816: $result =~ s/&(le|\#8804);/\\ensuremath\{\\leq\}/g;
1817: $result =~ s/&(ge|\#8805);/\\ensuremath\{\\geq\}/g;
1818: $result =~ s/&(sub|\#8834);/\\ensuremath\{\\subset\}/g;
1819: $result =~ s/&(sup|\#8835);/\\ensuremath\{\\supset\}/g;
1820: $result =~ s/&(nsub|\#8836);/\\ensuremath\{\\not\\subset\}/g;
1821: $result =~ s/&(sube|\#8838);/\\ensuremath\{\\subseteq\}/g;
1822: $result =~ s/&(supe|\#8839);/\\ensuremath\{\\supseteq\}/g;
1823: $result =~ s/&(oplus|\#8853);/\\ensuremath\{\\oplus\}/g;
1824: $result =~ s/&(otimes|\#8855);/\\ensuremath\{\\otimes\}/g;
1825: $result =~ s/&(perp|\#8869);/\\ensuremath\{\\perp\}/g;
1826: $result =~ s/&(sdot|\#8901);/\\ensuremath\{\\cdot\}/g;
1.199 sakharuk 1827: #Geometric Shapes (extended HTML 4.01)
1.281 sakharuk 1828: $result =~ s/&(loz|\#9674);/\\ensuremath\{\\Diamond\}/g;
1.199 sakharuk 1829: #Miscellaneous Symbols (extended HTML 4.01)
1.281 sakharuk 1830: $result =~ s/&(spades|\#9824);/\\ensuremath\{\\spadesuit\}/g;
1831: $result =~ s/&(clubs|\#9827);/\\ensuremath\{\\clubsuit\}/g;
1832: $result =~ s/&(hearts|\#9829);/\\ensuremath\{\\heartsuit\}/g;
1833: $result =~ s/&(diams|\#9830);/\\ensuremath\{\\diamondsuit\}/g;
1.495 foxr 1834: # Chemically useful 'things' contributed by Hon Kie (bug 4652).
1.515 foxr 1835:
1.495 foxr 1836: $result =~ s/&\#8636;/\\ensuremath\{\\leftharpoonup\}/g;
1837: $result =~ s/&\#8637;/\\ensuremath\{\\leftharpoondown\}/g;
1838: $result =~ s/&\#8640;/\\ensuremath\{\\rightharpoonup\}/g;
1839: $result =~ s/&\#8641;/\\ensuremath\{\\rightharpoondown\}/g;
1840: $result =~ s/&\#8652;/\\ensuremath\{\\rightleftharpoons\}/g;
1841: $result =~ s/&\#8605;/\\ensuremath\{\\leadsto\}/g;
1842: $result =~ s/&\#8617;/\\ensuremath\{\\hookleftarrow\}/g;
1843: $result =~ s/&\#8618;/\\ensuremath\{\\hookrightarrow\}/g;
1844: $result =~ s/&\#8614;/\\ensuremath\{\\mapsto\}/g;
1845: $result =~ s/&\#8599;/\\ensuremath\{\\nearrow\}/g;
1846: $result =~ s/&\#8600;/\\ensuremath\{\\searrow\}/g;
1847: $result =~ s/&\#8601;/\\ensuremath\{\\swarrow\}/g;
1848: $result =~ s/&\#8598;/\\ensuremath\{\\nwarrow\}/g;
1.513 foxr 1849:
1850: # Left/right quotations:
1851:
1852: $result =~ s/&(ldquo|#8220);/\`\`/g;
1853: $result =~ s/&(rdquo|#8221);/\'\'/g;
1854:
1855:
1.559 foxr 1856:
1.37 sakharuk 1857: return $result;
1858: }
1.41 sakharuk 1859:
1860:
1.327 albertel 1861: #width, height, oddsidemargin, evensidemargin, topmargin
1862: my %page_formats=
1863: ('letter' => {
1864: 'book' => {
1.704 raeburn 1865: '1' => [ '7.1 in','9.7 in', '-0.57 in','-0.57 in','-0.5 in'],
1866: '2' => ['3.66 in','9.8 in', '-0.57 in','-0.57 in','-0.5 in']
1.327 albertel 1867: },
1868: 'album' => {
1.701 raeburn 1869: '1' => [ '8.8 in', '6.8 in','-0.55 in', '-0.55 in','-0.5 in'],
1870: '2' => [ '4.8 in', '6.7 in','-0.5 in', '-1.0 in','3.0 in']
1.327 albertel 1871: },
1872: },
1873: 'legal' => {
1874: 'book' => {
1875: '1' => ['7.1 in','13 in',,'-0.57 in','-0.57 in','-0.5 in'],
1.514 foxr 1876: '2' => ['3.66 in','13 in','-0.57 in','-0.57 in','-0.5 in']
1.327 albertel 1877: },
1878: 'album' => {
1.376 albertel 1879: '1' => ['12 in','7.1 in',,'-0.57 in','-0.57 in','-0.5 in'],
1.701 raeburn 1880: '2' => ['5.7 in','7.1 in','-1 in','-1 in','5 in']
1.327 albertel 1881: },
1882: },
1883: 'tabloid' => {
1884: 'book' => {
1885: '1' => ['9.8 in','16 in','-0.57 in','-0.57 in','-0.5 in'],
1886: '2' => ['4.9 in','16 in','-0.57 in','-0.57 in','-0.5 in']
1887: },
1888: 'album' => {
1.376 albertel 1889: '1' => ['16 in','9.8 in','-0.57 in','-0.57 in','-0.5 in'],
1890: '2' => ['16 in','4.9 in','-0.57 in','-0.57 in','-0.5 in']
1.327 albertel 1891: },
1892: },
1893: 'executive' => {
1894: 'book' => {
1895: '1' => ['6.8 in','9 in','-0.57 in','-0.57 in','1.2 in'],
1896: '2' => ['3.1 in','9 in','-0.57 in','-0.57 in','1.2 in']
1897: },
1898: 'album' => {
1899: '1' => [],
1900: '2' => []
1901: },
1902: },
1903: 'a2' => {
1904: 'book' => {
1905: '1' => [],
1906: '2' => []
1907: },
1908: 'album' => {
1909: '1' => [],
1910: '2' => []
1911: },
1912: },
1913: 'a3' => {
1914: 'book' => {
1915: '1' => [],
1916: '2' => []
1917: },
1918: 'album' => {
1919: '1' => [],
1920: '2' => []
1921: },
1922: },
1923: 'a4' => {
1924: 'book' => {
1.493 foxr 1925: '1' => ['17.6 cm','27.2 cm','-1.397 cm','-2.11 cm','-1.27 cm'],
1.496 foxr 1926: '2' => [ '9.1 cm','27.2 cm','-1.397 cm','-2.11 cm','-1.27 cm']
1.327 albertel 1927: },
1928: 'album' => {
1.702 raeburn 1929: '1' => ['24.0 cm','18.0 cm','-1.0 cm','-1.0 cm','-1.25 cm'],
1930: '2' => ['11.5 cm','18.0 cm','-0.7 cm','-1.7 cm','-1.25 cm']
1.327 albertel 1931: },
1932: },
1933: 'a5' => {
1934: 'book' => {
1935: '1' => [],
1936: '2' => []
1937: },
1938: 'album' => {
1939: '1' => [],
1940: '2' => []
1941: },
1942: },
1943: 'a6' => {
1944: 'book' => {
1945: '1' => [],
1946: '2' => []
1947: },
1948: 'album' => {
1949: '1' => [],
1950: '2' => []
1951: },
1952: },
1953: );
1954:
1.177 sakharuk 1955: sub page_format {
1.140 sakharuk 1956: #
1.326 sakharuk 1957: #Supported paper format: "Letter [8 1/2x11 in]", "Legal [8 1/2x14 in]",
1958: # "Ledger/Tabloid [11x17 in]", "Executive [7 1/2x10 in]",
1959: # "A2 [420x594 mm]", "A3 [297x420 mm]",
1960: # "A4 [210x297 mm]", "A5 [148x210 mm]",
1961: # "A6 [105x148 mm]"
1.699 raeburn 1962: #
1963: my ($papersize,$layout,$numberofcolumns) = @_;
1.327 albertel 1964: return @{$page_formats{$papersize}->{$layout}->{$numberofcolumns}};
1.140 sakharuk 1965: }
1.76 sakharuk 1966:
1967:
1.126 albertel 1968: sub get_name {
1969: my ($uname,$udom)=@_;
1.373 albertel 1970: if (!defined($uname)) { $uname=$env{'user.name'}; }
1971: if (!defined($udom)) { $udom=$env{'user.domain'}; }
1.126 albertel 1972: my $plainname=&Apache::loncommon::plainname($uname,$udom);
1.213 albertel 1973: if ($plainname=~/^\s*$/) { $plainname=$uname.'@'.$udom; }
1.453 foxr 1974: $plainname=&Apache::lonxml::latex_special_symbols($plainname,'header');
1.213 albertel 1975: return $plainname;
1.126 albertel 1976: }
1977:
1.213 albertel 1978: sub get_course {
1979: my $courseidinfo;
1.373 albertel 1980: if (defined($env{'request.course.id'})) {
1.439 www 1981: $courseidinfo = &Apache::lonxml::latex_special_symbols(&unescape($env{'course.'.$env{'request.course.id'}.'.description'}),'header');
1.537 foxr 1982: my $sec = $env{'request.course.sec'};
1.699 raeburn 1983:
1.213 albertel 1984: }
1985: return $courseidinfo;
1986: }
1.177 sakharuk 1987:
1.76 sakharuk 1988: sub page_format_transformation {
1.703 raeburn 1989: my ($papersize,$layout,$numberofcolumns,$choice,$text,$assignment,$tableofcontents,
1990: $indexlist,$selectionmade,$mostrecent) = @_;
1.202 sakharuk 1991: my ($textwidth,$textheight,$oddoffset,$evenoffset,$topmargin);
1.454 foxr 1992:
1.312 sakharuk 1993: if ($selectionmade eq '4') {
1.502 foxr 1994: if ($choice eq 'all_problems') {
1.561 bisitz 1995: $assignment=&mt('Problems from the Whole Course');
1.502 foxr 1996: } else {
1.561 bisitz 1997: $assignment=&mt('Resources from the Whole Course');
1.502 foxr 1998: }
1.312 sakharuk 1999: } else {
2000: $assignment=&Apache::lonxml::latex_special_symbols($assignment,'header');
2001: }
1.261 sakharuk 2002: ($textwidth,$textheight,$oddoffset,$evenoffset,$topmargin) = &page_format($papersize,$layout,$numberofcolumns,$topmargin);
1.454 foxr 2003:
1.703 raeburn 2004: my $name;
2005: if ($mostrecent ne '') {
2006: $name = $mostrecent;
2007: } else {
2008: $name = &get_name();
2009: }
1.213 albertel 2010: my $courseidinfo = &get_course();
1.455 albertel 2011: my $header_text = $parmhash{'print_header_format'};
1.486 foxr 2012: $header_text = &format_page_header($textwidth, $header_text, $assignment,
1.455 albertel 2013: $courseidinfo, $name);
1.319 sakharuk 2014: my $topmargintoinsert = '';
2015: if ($topmargin ne '0') {$topmargintoinsert='\setlength{\topmargin}{'.$topmargin.'}';}
1.325 sakharuk 2016: my $fancypagestatement='';
2017: if ($numberofcolumns eq '2') {
1.455 albertel 2018: $fancypagestatement="\\fancyhead{}\\fancyhead[LO]{$header_text}";
1.700 raeburn 2019: if ($parmhash{'print_header_format'} eq '') {
2020: $fancypagestatement .= "\\fancyhead[RE]{\\thepage \\\\[\\baselineskip]}";
2021: }
1.325 sakharuk 2022: } else {
1.455 albertel 2023: $fancypagestatement="\\rhead{}\\chead{}\\lhead{$header_text}";
1.325 sakharuk 2024: }
1.700 raeburn 2025: $fancypagestatement .= "\\fancyfoot{}";
1.698 raeburn 2026: my ($paperwidth,$paperheight);
1.140 sakharuk 2027: if ($layout eq 'album') {
1.649 raeburn 2028: $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 2029: if ($papersize eq 'a4') {
2030: $paperwidth = '29.7cm';
1.704 raeburn 2031: $paperheight = '21.0cm';
1.698 raeburn 2032: } elsif ($numberofcolumns eq '1') {
2033: if ($papersize eq 'letter') {
1.704 raeburn 2034: $paperwidth = '11.0in';
1.698 raeburn 2035: $paperheight = '8.5in';
2036: } elsif ($papersize eq 'legal') {
1.704 raeburn 2037: $paperwidth = '14.0in';
1.698 raeburn 2038: $paperheight = '8.5in';
2039: }
2040: }
1.140 sakharuk 2041: } elsif ($layout eq 'book') {
1.699 raeburn 2042: if ($choice ne 'All class print') {
1.649 raeburn 2043: $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 2044: } else {
1.649 raeburn 2045: $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 2046: }
1.698 raeburn 2047: if ($papersize eq 'a4') {
1.704 raeburn 2048: $paperwidth = '21.0cm';
1.698 raeburn 2049: $paperheight = '29.7cm';
2050: } elsif ($papersize eq 'letter') {
2051: $paperwidth = '8.5in';
1.704 raeburn 2052: $paperheight = '11.0in';
1.698 raeburn 2053: } elsif ($papersize eq 'legal') {
2054: $paperwidth = '8.5in';
2055: $paperheight = '14.0in';
2056: }
2057: }
2058: if ($paperwidth ne '' && $paperheight ne '') {
2059: my $papersize_text;
2060: if ($perm{'pav'}) {
2061: $papersize_text = '\\special{papersize='.$paperwidth.','.$paperheight.'}';
2062: } else {
2063: $papersize_text = '\special{papersize='.$paperwidth.','.$paperheight.'}';
2064: }
2065: $text =~ s/(\\begin\{document})/$1$papersize_text/;
1.140 sakharuk 2066: }
1.214 sakharuk 2067: if ($tableofcontents eq 'yes') {$text=~s/(\\setcounter\{page\}\{1\})/$1 \\tableofcontents\\newpage /;}
2068: if ($indexlist eq 'yes') {
1.649 raeburn 2069: $text=~s/(\\begin\{document})/\\makeindex $1/;
2070: $text=~s/(\\end\{document})/\\strut\\\\\\strut\\printindex $1/;
1.214 sakharuk 2071: }
1.140 sakharuk 2072: return $text;
2073: }
2074:
2075:
1.33 sakharuk 2076: sub page_cleanup {
2077: my $result = shift;
1.699 raeburn 2078:
1.649 raeburn 2079: $result =~ m/\\end\{document}(\d*)$/;
1.34 sakharuk 2080: my $number_of_columns = $1;
1.33 sakharuk 2081: my $insert = '{';
1.34 sakharuk 2082: for (my $id=1;$id<=$number_of_columns;$id++) { $insert .='l'; }
1.33 sakharuk 2083: $insert .= '}';
1.649 raeburn 2084: $result =~ s/(\\begin\{longtable})INSERTTHEHEADOFLONGTABLE\\endfirsthead\\endhead/$1$insert/g;
1.34 sakharuk 2085: $result =~ s/&\s*REMOVETHEHEADOFLONGTABLE\\\\/\\\\/g;
2086: return $result,$number_of_columns;
1.7 sakharuk 2087: }
1.5 sakharuk 2088:
1.3 sakharuk 2089:
1.60 sakharuk 2090: sub details_for_menu {
1.335 albertel 2091: my ($helper)=@_;
1.373 albertel 2092: my $postdata=$env{'form.postdata'};
1.335 albertel 2093: if (!$postdata) { $postdata=$helper->{VARS}{'postdata'}; }
2094: my $name_of_resource = &Apache::lonnet::gettitle($postdata);
2095: my $symbolic = &Apache::lonnet::symbread($postdata);
1.482 albertel 2096: return if ( $symbolic eq '');
2097:
1.233 www 2098: my ($map,$id,$resource)=&Apache::lonnet::decode_symb($symbolic);
1.123 albertel 2099: $map=&Apache::lonnet::clutter($map);
1.269 albertel 2100: my $name_of_sequence = &Apache::lonnet::gettitle($map);
1.63 albertel 2101: if ($name_of_sequence =~ /^\s*$/) {
1.123 albertel 2102: $map =~ m|([^/]+)$|;
2103: $name_of_sequence = $1;
1.63 albertel 2104: }
1.373 albertel 2105: my $name_of_map = &Apache::lonnet::gettitle($env{'request.course.uri'});
1.63 albertel 2106: if ($name_of_map =~ /^\s*$/) {
1.373 albertel 2107: $env{'request.course.uri'} =~ m|([^/]+)$|;
1.123 albertel 2108: $name_of_map = $1;
2109: }
1.335 albertel 2110: return ($name_of_resource,$name_of_sequence,$name_of_map);
1.76 sakharuk 2111: }
2112:
1.476 albertel 2113: sub copyright_line {
2114: 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 } ';
2115: }
2116: my $end_of_student = "\n".'\special{ps:ENDOFSTUDENTSTAMP}'."\n";
1.76 sakharuk 2117:
2118: sub latex_corrections {
1.408 albertel 2119: my ($number_of_columns,$result,$selectionmade,$answer_mode) = @_;
1.649 raeburn 2120: # $result =~ s/\\includegraphics\{/\\includegraphics\[width=\\minipagewidth\]{/g;
1.476 albertel 2121: my $copyright = ©right_line();
1.408 albertel 2122: if ($selectionmade eq '1' || $answer_mode eq 'only') {
1.649 raeburn 2123: $result =~ s/(\\end\{document})/\\strut\\vskip 0 mm $copyright $end_of_student $1/;
1.408 albertel 2124: } else {
1.649 raeburn 2125: $result =~ s/(\\end\{document})/\\strut\\vspace\*{-4 mm}\\newline $copyright $end_of_student $1/;
1.316 sakharuk 2126: }
1.476 albertel 2127: $result =~ s/\$number_of_columns/$number_of_columns/g;
1.662 raeburn 2128: $result =~ s/(\\end\{longtable}\s*)(\\strut\\newline\\noindent\\makebox\[\\textwidth\/$number_of_columns\]\[b\]\{\\hrulefill})/$2$1/g;
1.649 raeburn 2129: $result =~ s/(\\end\{longtable}\s*)\\strut\\newline/$1/g;
1.699 raeburn 2130: #-- LaTeX corrections
1.76 sakharuk 2131: my $first_comment = index($result,'<!--',0);
2132: while ($first_comment != -1) {
2133: my $end_comment = index($result,'-->',$first_comment);
2134: substr($result,$first_comment,$end_comment-$first_comment+3) = '';
2135: $first_comment = index($result,'<!--',$first_comment);
2136: }
2137: $result =~ s/^\s+$//gm; #remove empty lines
1.377 albertel 2138: #removes more than one empty space
2139: $result =~ s|(\s\s+)|($1=~/[\n\r]/)?"\n":" "|ge;
1.76 sakharuk 2140: $result =~ s/\\\\\s*\\vskip/\\vskip/gm;
2141: $result =~ s/\\\\\s*\\noindent\s*(\\\\)+/\\\\\\noindent /g;
2142: $result =~ s/{\\par }\s*\\\\/\\\\/gm;
1.313 sakharuk 2143: $result =~ s/\\\\\s+\[/ \[/g;
1.76 sakharuk 2144: #conversion of html characters to LaTeX equivalents
2145: if ($result =~ m/&(\w+|#\d+);/) {
2146: $result = &character_chart($result);
2147: }
1.650 raeburn 2148: $result =~ s/(\\end\{tabular})\s*\\vskip 0 mm/$1/g;
2149: $result =~ s/(\\begin\{enumerate})\s*\\noindent/$1/g;
1.76 sakharuk 2150: return $result;
1.60 sakharuk 2151: }
2152:
1.3 sakharuk 2153:
1.214 sakharuk 2154: sub index_table {
2155: my $currentURL = shift;
2156: my $insex_string='';
2157: $currentURL=~s/\.([^\/+])$/\.$1\.meta/;
2158: $insex_string=&Apache::lonnet::metadata($currentURL,'keywords');
2159: return $insex_string;
2160: }
2161:
2162:
1.215 sakharuk 2163: sub IndexCreation {
2164: my ($texversion,$currentURL)=@_;
2165: my @key_words=split(/,/,&index_table($currentURL));
2166: my $chunk='';
2167: my $st=index $texversion,'\addcontentsline{toc}{subsection}{';
2168: if ($st>0) {
2169: for (my $i=0;$i<3;$i++) {$st=(index $texversion,'}',$st+1);}
2170: $chunk=substr($texversion,0,$st+1);
2171: substr($texversion,0,$st+1)=' ';
2172: }
2173: foreach my $key_word (@key_words) {
2174: if ($key_word=~/\S+/) {
2175: $texversion=~s/\b($key_word)\b/$1 \\index{$key_word} /i;
2176: }
2177: }
2178: if ($st>0) {substr($texversion,0,1)=$chunk;}
2179: return $texversion;
2180: }
2181:
1.242 sakharuk 2182: sub print_latex_header {
2183: my $mode=shift;
1.550 foxr 2184:
2185: return &Apache::londefdef::latex_header($mode);
1.242 sakharuk 2186: }
2187:
2188: sub path_to_problem {
1.328 albertel 2189: my ($urlp,$colwidth)=@_;
1.404 albertel 2190: $urlp=&Apache::lonnet::clutter($urlp);
2191:
1.242 sakharuk 2192: my $newurlp = '';
1.328 albertel 2193: $colwidth=~s/\s*mm\s*$//;
2194: #characters average about 2 mm in width
1.360 albertel 2195: if (length($urlp)*2 > $colwidth) {
1.404 albertel 2196: my @elements = split('/',$urlp);
1.328 albertel 2197: my $curlength=0;
2198: foreach my $element (@elements) {
1.404 albertel 2199: if ($element eq '') { next; }
1.328 albertel 2200: if ($curlength+(length($element)*2) > $colwidth) {
1.404 albertel 2201: $newurlp .= '|\vskip -1 mm \verb|';
2202: $curlength=length($element)*2;
1.328 albertel 2203: } else {
2204: $curlength+=length($element)*2;
1.242 sakharuk 2205: }
1.328 albertel 2206: $newurlp.='/'.$element;
1.242 sakharuk 2207: }
1.253 sakharuk 2208: } else {
2209: $newurlp=$urlp;
1.242 sakharuk 2210: }
2211: return '{\small\noindent\verb|'.$newurlp.'|\vskip 0 mm}';
2212: }
1.215 sakharuk 2213:
1.275 sakharuk 2214: sub recalcto_mm {
2215: my $textwidth=shift;
2216: my $LaTeXwidth;
1.339 albertel 2217: if ($textwidth=~/(-?\d+\.?\d*)\s*cm/) {
1.275 sakharuk 2218: $LaTeXwidth = $1*10;
1.339 albertel 2219: } elsif ($textwidth=~/(-?\d+\.?\d*)\s*mm/) {
1.275 sakharuk 2220: $LaTeXwidth = $1;
1.339 albertel 2221: } elsif ($textwidth=~/(-?\d+\.?\d*)\s*in/) {
1.275 sakharuk 2222: $LaTeXwidth = $1*25.4;
2223: }
2224: $LaTeXwidth.=' mm';
2225: return $LaTeXwidth;
2226: }
2227:
1.285 albertel 2228: sub get_textwidth {
2229: my ($helper,$LaTeXwidth)=@_;
1.286 albertel 2230: my $textwidth=$LaTeXwidth;
1.285 albertel 2231: if ($helper->{'VARS'}->{'pagesize.width'}=~/\d+/ &&
2232: $helper->{'VARS'}->{'pagesize.widthunit'}=~/\w+/) {
1.286 albertel 2233: $textwidth=&recalcto_mm($helper->{'VARS'}->{'pagesize.width'}.' '.
2234: $helper->{'VARS'}->{'pagesize.widthunit'});
1.285 albertel 2235: }
1.286 albertel 2236: return $textwidth;
1.285 albertel 2237: }
2238:
1.296 sakharuk 2239:
2240: sub unsupported {
1.414 albertel 2241: my ($currentURL,$mode,$symb)=@_;
1.672 raeburn 2242: my $cleanURL=&Apache::lonenc::check_decrypt($currentURL);
2243: my $shown = $currentURL;
2244: if (($cleanURL ne $currentURL) || ($symb =~ m{/^enc/})) {
2245: $shown = &mt('URL not shown (encrypted)');
2246: }
1.307 sakharuk 2247: if ($mode ne '') {$mode='\\'.$mode}
1.672 raeburn 2248: my $result = &print_latex_header($mode);
2249: if ($cleanURL=~m|^(/adm/wrapper)?/ext/|) {
2250: $cleanURL=~s|^(/adm/wrapper)?/ext/|http://|;
2251: $cleanURL=~s|^http://https://|https://|;
2252: if ($shown eq $currentURL) {
2253: $shown = &Apache::lonxml::latex_special_symbols($cleanURL);
2254: }
2255: my $title=&Apache::lonnet::gettitle($symb);
2256: $title = &Apache::lonxml::latex_special_symbols($title);
2257: $result.=' \strut \\\\ \textit{'.$title.'} \strut \\\\ '.$shown.' ';
1.296 sakharuk 2258: } else {
1.672 raeburn 2259: if ($shown eq $currentURL) {
2260: $result.=&Apache::lonxml::latex_special_symbols($currentURL);
2261: } else {
2262: $result.=$shown;
2263: }
1.296 sakharuk 2264: }
1.419 albertel 2265: $result.= '\vskip 0.5mm\noindent\makebox[\textwidth/$number_of_columns][b]{\hrulefill} \end{document}';
1.296 sakharuk 2266: return $result;
2267: }
2268:
1.559 foxr 2269: #
2270: # Map from helper layout style to the book/album:
2271: #
2272: sub map_laystyle {
2273: my ($laystyle) = @_;
2274: if ($laystyle eq 'L') {
2275: $laystyle='album';
2276: } else {
2277: $laystyle='book';
2278: }
2279: return $laystyle;
2280: }
2281:
2282: sub print_page_in_course {
2283: my ($helper, $rparmhash, $currentURL, $resources) = @_;
1.602 www 2284:
1.559 foxr 2285: my %parmhash = %$rparmhash;
2286: my @page_resources = @$resources;
2287: my $mode = $helper->{'VARS'}->{'LATEX_TYPE'};
2288: my $symb = $helper->{'VARS'}->{'symb'};
2289:
2290:
2291: my $format_from_helper = $helper->{'VARS'}->{'FORMAT'};
2292:
2293:
2294: my @temporary_array=split /\|/,$format_from_helper;
2295: my ($laystyle,$numberofcolumns,$papersize,$pdfFormFields)=@temporary_array;
2296: $laystyle = &map_laystyle($laystyle);
2297: my ($textwidth,$textheight,$oddoffset,$evenoffset) = &page_format($papersize,$laystyle,
2298: $numberofcolumns);
1.699 raeburn 2299: my $LaTeXwidth=&recalcto_mm($textwidth);
1.559 foxr 2300:
2301: if ($mode ne '') {$mode='\\'.$mode}
1.562 foxr 2302: my $result = &print_latex_header($mode);
1.672 raeburn 2303:
2304: my $title=&Apache::lonnet::gettitle($currentURL);
2305: $title = &Apache::lonxml::latex_special_symbols($title);
2306: $result .= '\noindent\textit{'.$title.'}\\\\';
1.559 foxr 2307:
2308: if ($helper->{'VARS'}->{'style_file'}=~/\w/) {
2309: &Apache::lonnet::appenv({'construct.style' =>
2310: $helper->{'VARS'}->{'style_file'}});
2311: } elsif ($env{'construct.style'}) {
2312: &Apache::lonnet::delenv('construct.style');
2313: }
2314:
1.699 raeburn 2315: # First is the overall page description. This is then followed by the
1.559 foxr 2316: # components of the page. Each of which must be printed independently.
1.699 raeburn 2317: my $the_page = shift(@page_resources);
1.559 foxr 2318:
2319:
2320: foreach my $resource (@page_resources) {
2321: my $resource_src = $resource->src(); # Essentially the URL of the resource.
1.672 raeburn 2322: my $current_url = $resource->link();
1.559 foxr 2323:
2324: # Recurse if a .page:
2325:
2326: if ($resource_src =~ /.page$/i) {
2327: my $navmap = Apache::lonnavmaps::navmap->new();
2328: my @page_resources = $navmap->retrieveResources($resource_src);
1.699 raeburn 2329: $result .= &print_page_in_course($helper, $rparmhash,
1.559 foxr 2330: $resource_src, \@page_resources);
1.624 raeburn 2331: } elsif ($resource->ext()) {
1.672 raeburn 2332: $result.=&latex_header_footer_remove(&unsupported($current_url,$mode,$resource->symb));
2333: } elsif ($resource_src =~ /\.(problem|exam|quiz|assess|survey|form|library|xml|html|htm|xhtml|xhtm)$/) {
2334: # these resources go through the XML transformer:
2335: $result .= &Apache::lonxml::latex_special_symbols($resource->title()) . '\\\\';
1.602 www 2336:
1.559 foxr 2337: my $urlp = &Apache::lonnet::clutter($resource_src);
1.602 www 2338:
1.559 foxr 2339: my %form;
2340: my %moreenv;
2341:
2342: &Apache::lonxml::remember_problem_counter();
2343: $moreenv{'request.filename'}=$urlp;
2344: if ($helper->{'VARS'}->{'probstatus'} eq 'exam') {$form{'problemtype'}='exam';}
2345:
2346: $form{'grade_target'} = 'tex';
2347: $form{'textwidth'} = &get_textwidth($helper, $LaTeXwidth);
1.699 raeburn 2348: $form{'pdfFormFields'} = $pdfFormFields; #
2349: $form{'showallfoils'} = $helper->{'VARS'}->{'showallfoils'};
2350:
1.559 foxr 2351: $form{'problem_split'}=$parmhash{'problem_stream_switch'};
2352: $form{'suppress_tries'}=$parmhash{'suppress_tries'};
2353: $form{'latex_type'}=$helper->{'VARS'}->{'LATEX_TYPE'};
2354: $form{'print_discussions'}=$helper->{'VARS'}->{'PRINT_DISCUSSIONS'};
2355: $form{'print_annotations'}=$helper->{'VARS'}->{'PRINT_ANNOTATIONS'};
2356: if (($helper->{'VARS'}->{'PRINT_DISCUSSIONS'} eq 'yes') ||
2357: ($helper->{'VARS'}->{'PRINT_ANNOTATIONS'} eq 'yes')) {
2358: $form{'problem_split'}='yes';
2359: }
2360: my $rndseed = time;
2361: if ($helper->{'VARS'}->{'curseed'}) {
2362: $rndseed=$helper->{'VARS'}->{'curseed'};
2363: }
2364: $form{'rndseed'}=$rndseed;
2365: &Apache::lonnet::appenv(\%moreenv);
1.699 raeburn 2366:
1.559 foxr 2367: &Apache::lonxml::clear_problem_counter();
2368:
2369: my $texversion = &ssi_with_retries($urlp, $ssi_retry_count, %form);
2370:
2371:
2372: # current document with answers.. no need to encap in minipage
2373: # since there's only one answer.
2374:
2375: if(($helper->{'VARS'}->{'ANSWER_TYPE'} eq 'no') ||
2376: ($helper->{'VARS'}->{'ANSWER_TYPE'} eq 'only')) {
2377: my %answerform = %form;
2378:
2379:
2380: $answerform{'problem_split'}=$parmhash{'problem_stream_switch'};
2381: $answerform{'grade_target'}='answer';
2382: $answerform{'answer_output_mode'}='tex';
2383: $answerform{'rndseed'}=$rndseed;
2384: if ($helper->{'VARS'}->{'probstatus'} eq 'exam') {
2385: $answerform{'problemtype'}='exam';
2386: }
2387: $resources_printed .= $urlp.':';
2388: my $answer=&ssi_with_retries($urlp,$ssi_retry_count, %answerform);
2389:
2390: if ($helper->{'VARS'}->{'ANSWER_TYPE'} eq 'no') {
1.649 raeburn 2391: $texversion=~s/(\\keephidden\{ENDOFPROBLEM})/$answer$1/;
1.559 foxr 2392: } else {
1.562 foxr 2393: $texversion= &print_latex_header($helper->{'VARS'}->{'LATEX_TYPE'});
1.559 foxr 2394: if ($helper->{'VARS'}->{'construction'} ne '1') {
2395: my $title = &Apache::lonnet::gettitle($helper->{'VARS'}->{'symb'});
2396: $title = &Apache::lonxml::latex_special_symbols($title);
2397: $texversion.='\vskip 0 mm \noindent\textbf{'.$title.'}\vskip 0 mm ';
2398: $texversion.=&path_to_problem($urlp,$LaTeXwidth);
2399: } else {
1.602 www 2400: $texversion.='\vskip 0 mm \noindent\textbf{'.
1.633 raeburn 2401: &mt("Printing from Authoring Space: No Title").'}\vskip 0 mm ';
1.602 www 2402: $texversion.=&path_to_problem($urlp,$LaTeXwidth);
1.559 foxr 2403: }
2404: $texversion.='\vskip 1 mm '.$answer.'\end{document}';
2405: }
2406: }
2407: # Print annotations.
2408:
2409:
2410: if ($helper->{'VARS'}->{'PRINT_ANNOTATIONS'} eq 'yes') {
2411: my $annotation .= &annotate($currentURL);
1.649 raeburn 2412: $texversion =~ s/(\\keephidden\{ENDOFPROBLEM})/$annotation$1/;
1.559 foxr 2413: }
1.699 raeburn 2414:
1.559 foxr 2415: if ($helper->{'VARS'}->{'TABLE_INDEX'} eq 'yes') {
2416: $texversion=&IndexCreation($texversion,$currentURL);
2417: }
2418: if ($helper->{'VARS'}->{'CONSTR_RESOURSE_URL'} eq 'yes') {
2419: $texversion=~s/(\\addcontentsline\{toc\}\{subsection\}\{[^\}]*\})/$1 URL: \\verb|$currentURL| \\strut\\\\\\strut /;
2420:
2421: }
1.562 foxr 2422: $texversion = &latex_header_footer_remove($texversion);
2423:
2424: # the first remaining line is a comment from londefdef the second
2425: # line seems to be an extraneous \vskip 1mm \\\\ :
2426: # (imperfect removal from header_footer_remove?
2427:
2428: $texversion =~ s/\\vskip 1mm \\\\\\\\//;
2429:
1.559 foxr 2430: $result .= $texversion;
2431: if ($currentURL=~m/\.page\s*$/) {
2432: ($result,$numberofcolumns) = &page_cleanup($result);
2433: }
2434: }
2435: }
2436:
2437: $result.= '\vskip 0.5mm\noindent\makebox[\textwidth/$number_of_columns][b]{\hrulefill} \end{document}';
2438: return $result;
2439: }
2440:
1.296 sakharuk 2441:
1.363 foxr 2442: #
1.395 www 2443: # List of recently generated print files
2444: #
2445: sub recently_generated {
1.584 raeburn 2446: my ($prtspool) = @_;
2447: my $output;
1.400 albertel 2448: my $zip_result;
2449: my $pdf_result;
1.395 www 2450: opendir(DIR,$prtspool);
1.400 albertel 2451:
1.699 raeburn 2452: my @files =
1.400 albertel 2453: grep(/^$env{'user.name'}_$env{'user.domain'}_printout_(\d+)_.*\.(pdf|zip)$/,readdir(DIR));
1.395 www 2454: closedir(DIR);
1.400 albertel 2455:
2456: @files = sort {
2457: my ($actime) = (stat($prtspool.'/'.$a))[10];
2458: my ($bctime) = (stat($prtspool.'/'.$b))[10];
2459: return $bctime <=> $actime;
2460: } (@files);
2461:
2462: foreach my $filename (@files) {
2463: my ($ext) = ($filename =~ m/(pdf|zip)$/);
2464: my ($cdev,$cino,$cmode,$cnlink,
2465: $cuid,$cgid,$crdev,$csize,
2466: $catime,$cmtime,$cctime,
2467: $cblksize,$cblocks)=stat($prtspool.'/'.$filename);
1.544 bisitz 2468: my $ext_text = 'pdf' ? &mt('PDF File'):&mt('Zip File');
2469: my $result=&Apache::loncommon::start_data_table_row()
2470: .'<td>'
2471: .'<a href="/prtspool/'.$filename.'">'.$ext_text.'</a>'
2472: .'</td>'
2473: .'<td>'.&Apache::lonlocal::locallocaltime($cctime).'</td>'
2474: .'<td align="right">'.$csize.'</td>'
2475: .&Apache::loncommon::end_data_table_row();
1.400 albertel 2476: if ($ext eq 'pdf') { $pdf_result .= $result; }
2477: if ($ext eq 'zip') { $zip_result .= $result; }
2478: }
1.544 bisitz 2479: if ($zip_result || $pdf_result) {
1.584 raeburn 2480: $output ='<hr />';
1.544 bisitz 2481: }
1.400 albertel 2482: if ($zip_result) {
1.584 raeburn 2483: $output .='<h3>'.&mt('Recently generated printout zip files')."</h3>\n"
1.544 bisitz 2484: .&Apache::loncommon::start_data_table()
2485: .&Apache::loncommon::start_data_table_header_row()
2486: .'<th>'.&mt('Download').'</th>'
2487: .'<th>'.&mt('Creation Date').'</th>'
2488: .'<th>'.&mt('File Size (Bytes)').'</th>'
2489: .&Apache::loncommon::end_data_table_header_row()
2490: .$zip_result
1.584 raeburn 2491: .&Apache::loncommon::end_data_table();
1.400 albertel 2492: }
2493: if ($pdf_result) {
1.584 raeburn 2494: $output .='<h3>'.&mt('Recently generated printouts')."</h3>\n"
1.544 bisitz 2495: .&Apache::loncommon::start_data_table()
2496: .&Apache::loncommon::start_data_table_header_row()
2497: .'<th>'.&mt('Download').'</th>'
2498: .'<th>'.&mt('Creation Date').'</th>'
2499: .'<th>'.&mt('File Size (Bytes)').'</th>'
2500: .&Apache::loncommon::end_data_table_header_row()
2501: .$pdf_result
1.584 raeburn 2502: .&Apache::loncommon::end_data_table();
1.396 albertel 2503: }
1.584 raeburn 2504: return $output;
1.395 www 2505: }
2506:
2507: #
1.363 foxr 2508: # Retrieve the hash of page breaks.
2509: #
2510: # Inputs:
2511: # helper - reference to helper object.
2512: # Outputs
2513: # A reference to a page break hash.
2514: #
2515: #
1.610 foxr 2516: # use Data::Dumper;
1.569 foxr 2517: # sub dump_helper_vars {
1.418 foxr 2518: # my ($helper) = @_;
2519: # my $helpervars = Dumper($helper->{'VARS'});
2520: # &Apache::lonnet::logthis("Dump of helper vars:\n $helpervars");
2521: #}
1.363 foxr 2522:
1.481 albertel 2523: sub get_page_breaks {
2524: my ($helper) = @_;
2525: my %page_breaks;
2526:
2527: foreach my $break (split /\|\|\|/, $helper->{'VARS'}->{'FINISHPAGE'}) {
2528: $page_breaks{$break} = 1;
2529: }
2530: return %page_breaks;
2531: }
1.699 raeburn 2532: #
1.569 foxr 2533: # Returns text to insert for any extra vskip prior to the resource.
2534: # Parameters:
2535: # helper - Reference to the helper object driving the printout.
2536: # resource - Identifies the resource about to be printed.
2537: #
2538: # This is done as follows:
2539: # POSSIBLE_RESOURCES has the list of possible resources.
2540: # EXTRASPACE has the list of extra space values.
1.570 foxr 2541: # EXTRASPACE_UNITS is the set of resources for which the units are
2542: # mm. All others are 'in'.
1.699 raeburn 2543: #
1.569 foxr 2544: # The resource is found in the POSSIBLE_RESOURCES to get the index
2545: # of the EXTRASPACE value.
2546: #
2547: # In order to speed this up for lengthy printouts, the first time,
2548: # POSSIBLE_RESOURCES is turned into a look up hash and
2549: # EXTRASPACE is turned into an array.
2550: #
2551:
2552:
2553: my %possible_resources;
1.570 foxr 2554: my %extraspace_mm;
1.569 foxr 2555: my @extraspace;
2556: my $skips_loaded = 0;
2557:
2558: # Function to load the skips hash and array
2559:
2560: sub load_skips {
2561:
2562: my ($helper) = @_;
2563:
1.689 raeburn 2564: # If this is the first time, unwrap the resources and extra spaces:
1.569 foxr 2565:
2566: if (!$skips_loaded) {
2567: @extraspace = (split(/\|\|\|/, $helper->{'VARS'}->{'EXTRASPACE'}));
2568: my @resource_list = (split(/\|\|\|/, $helper->{'VARS'}->{'POSSIBLE_RESOURCES'}));
2569: my $i = 0;
2570: foreach my $resource (@resource_list) {
2571: $possible_resources{$resource} = $i;
2572: $i++;
2573: }
1.570 foxr 2574: foreach my $mm_resource (split(/\|\|\|/, $helper->{'VARS'}->{'EXTRASPACE_UNITS'})) {
2575: $extraspace_mm{$mm_resource} = 1;
2576: }
1.569 foxr 2577: $skips_loaded = 1;
2578: }
2579: }
2580:
2581: sub get_extra_vspaces {
2582: my ($helper, $resource) = @_;
2583:
2584: &load_skips($helper);
2585:
2586: # Lookup the resource in the possible resources hash.. that is the index
2587: # into the extraspace array that gives us either an empty string or
2588: # the number of mm to skip:
2589:
2590: my $index = $possible_resources{$resource};
2591: my $skip = $extraspace[$index];
2592:
2593: my $result = '';
2594: if ($skip ne '') {
1.570 foxr 2595: my $units = 'in';
2596: if (defined($extraspace_mm{$resource})) {
2597: $units = 'mm';
2598: }
2599: $result = '\vskip '.$skip.' '.$units;
1.569 foxr 2600: }
1.570 foxr 2601:
2602:
1.569 foxr 2603: return $result;
2604:
2605:
2606: }
2607:
2608: #
2609: # The resource chooser part of the helper needs more than just
2610: # the value of the extraspaces var to recover the value into a text
2611: # field option. This sub produces the required format for the saved var:
1.699 raeburn 2612: # specifically
1.569 foxr 2613: # ||| separated fields of the form resourcename=value
2614: #
2615: # Parameters:
2616: # $helper - Refers to the helper we are configuring
2617: # Implicit input:
2618: # $helper->{'VARS'}->{'EXTRASPACE'} - the spaces helper var has the text field
2619: # value.
1.570 foxr 2620: # $helper->{'VARS'}->{'EXTRASPACE_UNITS'} - units for the skips (checkboxes).
1.569 foxr 2621: # $helper->{'VARS'}->{'POSSIBLE_RESOURCES'} - has the list of resources. |||
2622: # separated of course.
2623: # Implicit outputs:
1.570 foxr 2624: # $env{'form.extraspace'}
2625: # $env{'form.extraspace_units'}
1.569 foxr 2626: #
2627: sub set_form_extraspace {
2628: my ($helper) = @_;
2629:
2630: # the most convenient way to do this is to drive from the skips arrays/hash.
2631: # may not be the fastest, but this is once per print request so it's not so
2632: # speed critical:
2633:
2634: &load_skips($helper);
2635:
2636: my $result = '';
2637:
2638: foreach my $resource (keys(%possible_resources)) {
2639: my $vskip = $extraspace[$possible_resources{$resource}];
2640: $result .= $resource .'=' . $vskip . '|||';
2641: }
2642:
2643: $env{'form.extraspace'} = $result;
1.570 foxr 2644: $env{'form.extraspace_units'} = $helper->{'VARS'}->{'EXTRASPACE_UNITS'};
1.569 foxr 2645: return $result;
1.699 raeburn 2646:
1.569 foxr 2647: }
1.363 foxr 2648:
1.459 foxr 2649: # Output a sequence (recursively if neeed)
2650: # from construction space.
2651: # Parameters:
2652: # url = URL of the sequence to print.
2653: # helper - Reference to the helper hash.
2654: # form - Copy of the format hash.
2655: # LaTeXWidth
2656: # Returns:
2657: # Text to add to the printout.
2658: # NOTE if the first element of the outermost sequence
2659: # is itself a sequence, the outermost caller may need to
2660: # prefix the latex with the page headers stuff.
2661: #
2662: sub print_construction_sequence {
2663: my ($currentURL, $helper, %form, $LaTeXwidth) = @_;
1.590 foxr 2664:
1.459 foxr 2665: my $result;
2666: my $rndseed=time;
2667: if ($helper->{'VARS'}->{'curseed'}) {
2668: $rndseed=$helper->{'VARS'}->{'curseed'};
2669: }
1.606 www 2670: my $errtext=&LONCAPA::map::mapread(&Apache::lonnet::filelocation('',$currentURL));
2671:
1.699 raeburn 2672: #
1.459 foxr 2673: # These make this all support recursing for subsequences.
2674: #
1.491 albertel 2675: my @order = @LONCAPA::map::order;
1.699 raeburn 2676: my @resources = @LONCAPA::map::resources;
1.606 www 2677:
1.459 foxr 2678: for (my $member=0;$member<=$#order;$member++) {
2679: $resources[$order[$member]]=~/^([^:]*):([^:]*):/;
2680: my $urlp=$2;
2681: if ($urlp=~/\.(problem|exam|quiz|assess|survey|form|library|xml|html|htm|xhtml|xhtm)$/) {
2682: my $texversion='';
2683: if ($helper->{'VARS'}->{'ANSWER_TYPE'} ne 'only') {
2684: $form{'problem_split'}=$parmhash{'problem_stream_switch'};
2685: $form{'suppress_tries'}=$parmhash{'suppress_tries'};
2686: $form{'latex_type'}=$helper->{'VARS'}->{'LATEX_TYPE'};
2687: $form{'rndseed'}=$rndseed;
2688: $resources_printed .=$urlp.':';
1.515 foxr 2689: $texversion=&ssi_with_retries($urlp, $ssi_retry_count, %form);
1.459 foxr 2690: }
2691: if((($helper->{'VARS'}->{'ANSWER_TYPE'} eq 'no') ||
1.699 raeburn 2692: ($helper->{'VARS'}->{'ANSWER_TYPE'} eq 'only')) &&
1.609 www 2693: ($urlp=~/$LONCAPA::assess_page_re/)) {
1.459 foxr 2694: # Don't permanently modify %$form...
2695: my %answerform = %form;
2696: $answerform{'grade_target'}='answer';
2697: $answerform{'answer_output_mode'}='tex';
2698: $answerform{'rndseed'}=$rndseed;
2699: $answerform{'problem_split'}=$parmhash{'problem_stream_switch'};
1.481 albertel 2700: if ($urlp=~/\/res\//) {$env{'request.state'}='published';}
1.459 foxr 2701: $resources_printed .= $urlp.':';
1.515 foxr 2702: my $answer=&ssi_with_retries($urlp, $ssi_retry_count, %answerform);
1.459 foxr 2703: if ($helper->{'VARS'}->{'ANSWER_TYPE'} eq 'no') {
1.649 raeburn 2704: $texversion=~s/(\\keephidden\{ENDOFPROBLEM})/$answer$1/;
1.459 foxr 2705: } else {
2706: # If necessary, encapsulate answer in minipage:
1.699 raeburn 2707:
1.459 foxr 2708: $texversion=&print_latex_header($helper->{'VARS'}->{'LATEX_TYPE'});
1.477 albertel 2709: my $title = &Apache::lonnet::gettitle($helper->{'VARS'}->{'symb'});
2710: $title = &Apache::lonxml::latex_special_symbols($title);
2711: my $body ='\vskip 0 mm \noindent\textbf{'.$title.'}\vskip 0 mm ';
1.459 foxr 2712: $body.=&path_to_problem($urlp,$LaTeXwidth);
2713: $body.='\vskip 1 mm '.$answer.'\end{document}';
1.676 raeburn 2714: $body = &encapsulate_minipage($body,$answerform{'problem_split'});
1.459 foxr 2715: $texversion.=$body;
2716: }
2717: }
2718: $texversion = &latex_header_footer_remove($texversion);
2719:
2720: if ($helper->{'VARS'}->{'TABLE_INDEX'} eq 'yes') {
2721: $texversion=&IndexCreation($texversion,$urlp);
2722: }
2723: if ($helper->{'VARS'}->{'CONSTR_RESOURSE_URL'} eq 'yes') {
2724: $texversion=~s/(\\addcontentsline\{toc\}\{subsection\}\{[^\}]*\})/$1 URL: \\verb|$urlp| \\strut\\\\\\strut /;
2725: }
2726: $result.=$texversion;
2727:
2728: } elsif ($urlp=~/\.(sequence|page)$/) {
1.699 raeburn 2729:
1.459 foxr 2730: # header:
2731:
2732: $result.='\strut\newline\noindent Sequence/page '.$urlp.'\strut\newline\noindent\makebox[\textwidth/$number_of_columns][b]{\hrulefill}\newline\noindent ';
2733:
2734: # IF sequence, recurse:
1.699 raeburn 2735:
1.459 foxr 2736: if ($urlp =~ /\.sequence$/) {
1.699 raeburn 2737: $result .= &print_construction_sequence($urlp,
2738: $helper, %form,
1.459 foxr 2739: $LaTeXwidth);
2740: }
1.550 foxr 2741: }
2742: elsif ($urlp =~ /\.pdf$/i) {
1.552 foxr 2743: my $texversion;
2744: if ($member != 0) {
2745: $texversion .= '\cleardoublepage';
2746: }
2747:
2748: $texversion .= &include_pdf($urlp);
2749: $texversion = &latex_header_footer_remove($texversion);
2750: if ($member != $#order) {
2751: $texversion .= '\\ \cleardoublepage';
2752: }
1.699 raeburn 2753:
1.551 foxr 2754: $result .= $texversion;
1.550 foxr 2755: }
1.459 foxr 2756: }
1.650 raeburn 2757: if ($helper->{VARS}->{'construction'} eq '1') {$result=~s/(\\begin\{document})/$1 \\fbox\{RANDOM SEED IS $rndseed\} /;}
1.459 foxr 2758: return $result;
2759: }
2760:
1.590 foxr 2761: #
2762: # Top level for generating print output.
2763: #
2764: # May call print_resources if multiple resources will be printed.
2765: #
2766: # The main driver is $selectionmade which reflects the type of print out
2767: # requested:
2768: # Value Print type:
2769: # 1 Print resource that's being looked at.
2770: # 2 Print problems in a map or in a page.
2771: # 3 Print pages in a map or resources in a page.
2772: # 4 Print all problems or all resources.
2773: # 5 Print problems for seleted students.
2774: # 6 Print selected problems from a folder.
2775: # 7 Print print selected resources from some scope.
2776: # 8 Print resources for selected students.
1.703 raeburn 2777: # 9 Print for anonymous CODEs
1.590 foxr 2778: #
2779: #BZ 5209
2780: # 2 map_incomplete_problems_seq Print incomplete problems from the current
2781: # folder in student context.
1.591 foxr 2782: # 5 map_incomplete_problems_people_seq Print incomplete problems from the
1.590 foxr 2783: # current folder in privileged context.
1.591 foxr 2784: # 5 incomplete_problems_selpeople_course Print incomplete problems for
1.590 foxr 2785: # selected people from the entire course.
2786: #
2787: # Item 101 has much the same processing as 8,
2788: #
2789: # Differences: Item 101, 102 require per-student filtering of the resource
2790: # set so that only the incomplete resources are printed.
2791: # For item 100, filtering was done at the helper level.
2792:
1.177 sakharuk 2793: sub output_data {
1.621 foxr 2794:
1.184 sakharuk 2795: my ($r,$helper,$rparmhash) = @_;
2796: my %parmhash = %$rparmhash;
1.515 foxr 2797: $ssi_error = 0; # This will be set nonzero by failing ssi's.
1.459 foxr 2798: $resources_printed = '';
1.556 foxr 2799: $font_size = $helper->{'VARS'}->{'fontsize'};
1.590 foxr 2800: my $print_type = $helper->{'VARS'}->{'PRINT_TYPE'}; # Allows textual simplification.
1.499 foxr 2801: my $do_postprocessing = 1;
1.433 albertel 2802: my $js = <<ENDPART;
2803: <script type="text/javascript">
1.264 sakharuk 2804: var editbrowser;
2805: function openbrowser(formname,elementname,only,omit) {
2806: var url = '/res/?';
2807: if (editbrowser == null) {
2808: url += 'launch=1&';
2809: }
2810: url += 'catalogmode=interactive&';
2811: url += 'mode=parmset&';
2812: url += 'form=' + formname + '&';
2813: if (only != null) {
2814: url += 'only=' + only + '&';
1.699 raeburn 2815: }
1.264 sakharuk 2816: if (omit != null) {
2817: url += 'omit=' + omit + '&';
2818: }
2819: url += 'element=' + elementname + '';
2820: var title = 'Browser';
2821: var options = 'scrollbars=1,resizable=1,menubar=0';
2822: options += ',width=700,height=600';
2823: editbrowser = open(url,title,options,'1');
2824: editbrowser.focus();
2825: }
2826: </script>
1.140 sakharuk 2827: ENDPART
2828:
1.512 foxr 2829:
1.558 bisitz 2830: # Breadcrumbs
2831: #FIXME: Choose better/different breadcrumbs?!? Links?
2832: my $brcrum = [{'href' => '',
2833: 'text' => 'Helper'}, #FIXME: Different origin possible than print out helper?
2834: {'href' => '',
2835: 'text' => 'Preparing Printout'}];
2836:
2837: my $start_page = &Apache::loncommon::start_page('Preparing Printout',
2838: $js,
2839: {'bread_crumbs' => $brcrum,});
1.433 albertel 2840: my $msg = &mt('Please stand by while processing your print request, this may take some time ...');
1.363 foxr 2841:
1.433 albertel 2842: $r->print($start_page."\n<p>\n$msg\n</p>\n");
1.372 foxr 2843:
1.363 foxr 2844: # fetch the pagebreaks and store them in the course environment
2845: # The page breaks will be pulled into the hash %page_breaks which is
2846: # indexed by symb and contains 1's for each break.
2847:
1.373 albertel 2848: $env{'form.pagebreaks'} = $helper->{'VARS'}->{'FINISHPAGE'};
1.569 foxr 2849: &set_form_extraspace($helper);
1.699 raeburn 2850: $env{'form.lastprinttype'} = $print_type;
1.363 foxr 2851: &Apache::loncommon::store_course_settings('print',
1.366 foxr 2852: {'pagebreaks' => 'scalar',
1.569 foxr 2853: 'extraspace' => 'scalar',
1.570 foxr 2854: 'extraspace_units' => 'scalar',
1.366 foxr 2855: 'lastprinttype' => 'scalar'});
1.364 albertel 2856: my %page_breaks = &get_page_breaks($helper);
1.363 foxr 2857:
1.140 sakharuk 2858: my $format_from_helper = $helper->{'VARS'}->{'FORMAT'};
2859: my ($result,$selectionmade) = ('','');
2860: my $number_of_columns = 1; #used only for pages to determine the width of the cell
2861: my @temporary_array=split /\|/,$format_from_helper;
1.539 onken 2862: my ($laystyle,$numberofcolumns,$papersize,$pdfFormFields)=@temporary_array;
1.559 foxr 2863:
2864: $laystyle = &map_laystyle($laystyle);
1.177 sakharuk 2865: my ($textwidth,$textheight,$oddoffset,$evenoffset) = &page_format($papersize,$laystyle,$numberofcolumns);
1.373 albertel 2866: my $assignment = $env{'form.assignment'};
1.699 raeburn 2867: my $LaTeXwidth=&recalcto_mm($textwidth);
1.272 sakharuk 2868: my @print_array=();
1.274 sakharuk 2869: my @student_names=();
1.703 raeburn 2870: my $lastprinted;
1.699 raeburn 2871:
1.688 raeburn 2872: # Common settings for the %form hash:
2873: # In some cases these settings get overridden by specific cases, but the
1.360 albertel 2874: # settings are common enough to make it worthwhile factoring them out
2875: # here.
2876: #
2877: my %form;
2878: $form{'grade_target'} = 'tex';
2879: $form{'textwidth'} = &get_textwidth($helper, $LaTeXwidth);
1.539 onken 2880: $form{'pdfFormFields'} = $pdfFormFields;
1.372 foxr 2881:
2882: # If form.showallfoils is set, then request all foils be shown:
1.699 raeburn 2883: # privilege will be enforced both by not allowing the
1.372 foxr 2884: # check box selecting this option to be presnt unless it's ok,
2885: # and by lonresponse's priv. check.
2886: # The if is here because lonresponse.pm only cares that
2887: # showallfoils is defined, not what the value is.
2888:
1.699 raeburn 2889: if ($helper->{'VARS'}->{'showallfoils'} eq "1") {
1.372 foxr 2890: $form{'showallfoils'} = $helper->{'VARS'}->{'showallfoils'};
2891: }
1.699 raeburn 2892:
1.504 albertel 2893: if ($helper->{'VARS'}->{'style_file'}=~/\w/) {
1.520 raeburn 2894: &Apache::lonnet::appenv({'construct.style' =>
2895: $helper->{'VARS'}->{'style_file'}});
1.504 albertel 2896: } elsif ($env{'construct.style'}) {
1.549 raeburn 2897: &Apache::lonnet::delenv('construct.style');
1.504 albertel 2898: }
2899:
1.590 foxr 2900: if ($print_type eq 'current_document') {
1.143 sakharuk 2901: #-- single document - problem, page, html, xml, ...
1.343 albertel 2902: my ($currentURL,$cleanURL);
1.375 foxr 2903:
1.162 sakharuk 2904: if ($helper->{'VARS'}->{'construction'} ne '1') {
1.185 sakharuk 2905: #prints published resource
1.153 sakharuk 2906: $currentURL=$helper->{'VARS'}->{'postdata'};
1.343 albertel 2907: $cleanURL=&Apache::lonenc::check_decrypt($currentURL);
1.143 sakharuk 2908: } else {
1.512 foxr 2909:
1.185 sakharuk 2910: #prints resource from the construction space
1.602 www 2911: $currentURL=$helper->{'VARS'}->{'filename'};
1.343 albertel 2912: $cleanURL=$currentURL;
1.143 sakharuk 2913: }
1.140 sakharuk 2914: $selectionmade = 1;
1.651 raeburn 2915:
1.413 albertel 2916: if ($cleanURL!~m|^/adm/|
1.557 foxr 2917: && $cleanURL=~/\.(problem|exam|quiz|assess|survey|form|library|xml|html|htm|xhtml|xhtm)$/) {
1.169 albertel 2918: my $rndseed=time;
1.242 sakharuk 2919: my $texversion='';
2920: if ($helper->{'VARS'}->{'ANSWER_TYPE'} ne 'only') {
2921: my %moreenv;
1.343 albertel 2922: $moreenv{'request.filename'}=$cleanURL;
1.290 sakharuk 2923: if ($helper->{'VARS'}->{'probstatus'} eq 'exam') {$form{'problemtype'}='exam';}
1.242 sakharuk 2924: $form{'problem_split'}=$parmhash{'problem_stream_switch'};
1.310 sakharuk 2925: $form{'suppress_tries'}=$parmhash{'suppress_tries'};
1.242 sakharuk 2926: $form{'latex_type'}=$helper->{'VARS'}->{'LATEX_TYPE'};
1.309 sakharuk 2927: $form{'print_discussions'}=$helper->{'VARS'}->{'PRINT_DISCUSSIONS'};
1.511 foxr 2928: $form{'print_annotations'}=$helper->{'VARS'}->{'PRINT_ANNOTATIONS'};
2929: if (($helper->{'VARS'}->{'PRINT_DISCUSSIONS'} eq 'yes') ||
2930: ($helper->{'VARS'}->{'PRINT_ANNOTATIONS'} eq 'yes')) {
2931: $form{'problem_split'}='yes';
2932: }
1.242 sakharuk 2933: if ($helper->{'VARS'}->{'curseed'}) {
2934: $rndseed=$helper->{'VARS'}->{'curseed'};
2935: }
2936: $form{'rndseed'}=$rndseed;
1.520 raeburn 2937: &Apache::lonnet::appenv(\%moreenv);
1.428 albertel 2938:
2939: &Apache::lonxml::clear_problem_counter();
2940:
1.375 foxr 2941: $resources_printed .= $currentURL.':';
1.515 foxr 2942: $texversion.=&ssi_with_retries($currentURL,$ssi_retry_count, %form);
1.428 albertel 2943:
1.511 foxr 2944: # Add annotations if required:
1.699 raeburn 2945:
1.428 albertel 2946: &Apache::lonxml::clear_problem_counter();
2947:
1.242 sakharuk 2948: &Apache::lonnet::delenv('request.filename');
1.230 albertel 2949: }
1.423 foxr 2950: # current document with answers.. no need to encap in minipage
2951: # since there's only one answer.
2952:
1.242 sakharuk 2953: if(($helper->{'VARS'}->{'ANSWER_TYPE'} eq 'no') ||
2954: ($helper->{'VARS'}->{'ANSWER_TYPE'} eq 'only')) {
1.602 www 2955:
1.353 foxr 2956: $form{'problem_split'}=$parmhash{'problem_stream_switch'};
1.166 albertel 2957: $form{'grade_target'}='answer';
1.167 albertel 2958: $form{'answer_output_mode'}='tex';
1.169 albertel 2959: $form{'rndseed'}=$rndseed;
1.401 albertel 2960: if ($helper->{'VARS'}->{'probstatus'} eq 'exam') {
2961: $form{'problemtype'}='exam';
2962: }
1.375 foxr 2963: $resources_printed .= $currentURL.':';
1.515 foxr 2964: my $answer=&ssi_with_retries($currentURL,$ssi_retry_count, %form);
1.511 foxr 2965:
2966:
1.242 sakharuk 2967: if ($helper->{'VARS'}->{'ANSWER_TYPE'} eq 'no') {
1.649 raeburn 2968: $texversion=~s/(\\keephidden\{ENDOFPROBLEM})/$answer$1/;
1.242 sakharuk 2969: } else {
2970: $texversion=&print_latex_header($helper->{'VARS'}->{'LATEX_TYPE'});
1.245 sakharuk 2971: if ($helper->{'VARS'}->{'construction'} ne '1') {
1.477 albertel 2972: my $title = &Apache::lonnet::gettitle($helper->{'VARS'}->{'symb'});
2973: $title = &Apache::lonxml::latex_special_symbols($title);
2974: $texversion.='\vskip 0 mm \noindent\textbf{'.$title.'}\vskip 0 mm ';
1.343 albertel 2975: $texversion.=&path_to_problem($cleanURL,$LaTeXwidth);
1.245 sakharuk 2976: } else {
1.602 www 2977: $texversion.='\vskip 0 mm \noindent\textbf{'.
1.633 raeburn 2978: &mt("Printing from Authoring Space: No Title").'}\vskip 0 mm ';
1.602 www 2979:
2980: $texversion.=&path_to_problem($cleanURL,$LaTeXwidth);
1.245 sakharuk 2981: }
1.242 sakharuk 2982: $texversion.='\vskip 1 mm '.$answer.'\end{document}';
2983: }
1.511 foxr 2984:
2985:
2986:
2987:
1.699 raeburn 2988:
1.511 foxr 2989: }
2990: # Print annotations.
2991:
2992:
2993: if ($helper->{'VARS'}->{'PRINT_ANNOTATIONS'} eq 'yes') {
2994: my $annotation .= &annotate($currentURL);
1.649 raeburn 2995: $texversion =~ s/(\\keephidden\{ENDOFPROBLEM})/$annotation$1/;
1.163 sakharuk 2996: }
1.511 foxr 2997:
2998:
1.214 sakharuk 2999: if ($helper->{'VARS'}->{'TABLE_INDEX'} eq 'yes') {
1.215 sakharuk 3000: $texversion=&IndexCreation($texversion,$currentURL);
1.214 sakharuk 3001: }
1.219 sakharuk 3002: if ($helper->{'VARS'}->{'CONSTR_RESOURSE_URL'} eq 'yes') {
3003: $texversion=~s/(\\addcontentsline\{toc\}\{subsection\}\{[^\}]*\})/$1 URL: \\verb|$currentURL| \\strut\\\\\\strut /;
3004:
3005: }
1.162 sakharuk 3006: $result .= $texversion;
3007: if ($currentURL=~m/\.page\s*$/) {
3008: ($result,$number_of_columns) = &page_cleanup($result);
3009: }
1.413 albertel 3010: } elsif ($cleanURL!~m|^/adm/|
1.557 foxr 3011: && $currentURL=~/\.(sequence|page)$/ && $helper->{'VARS'}->{'construction'} eq '1') {
1.459 foxr 3012: $result .= &print_construction_sequence($currentURL, $helper, %form,
3013: $LaTeXwidth);
1.699 raeburn 3014: $result .= '\end{document}';
1.459 foxr 3015: if (!($result =~ /\\begin\{document\}/)) {
3016: $result = &print_latex_header() . $result;
1.227 sakharuk 3017: }
1.459 foxr 3018: # End construction space sequence.
1.699 raeburn 3019: } elsif ($cleanURL=~/\/(smppg|syllabus|aboutme|bulletinboard|ext\.tool)$/) {
1.258 sakharuk 3020: $form{'latex_type'}=$helper->{'VARS'}->{'LATEX_TYPE'};
1.298 sakharuk 3021: if ($currentURL=~/\/syllabus$/) {$currentURL=~s/\/res//;}
1.660 raeburn 3022: if ($currentURL=~/\/ext\.tool$/) {$currentURL=~s/^\/adm\/wrapper//;}
1.375 foxr 3023: $resources_printed .= $currentURL.':';
1.567 foxr 3024: my $texversion = &ssi_with_retries($currentURL, $ssi_retry_count, %form);
1.511 foxr 3025: if ($helper->{'VARS'}->{'PRINT_ANNOTATIONS'} eq 'yes') {
3026: my $annotation = &annotate($currentURL);
1.649 raeburn 3027: $texversion =~ s/(\\end\{document})/$annotation$1/;
1.511 foxr 3028: }
1.258 sakharuk 3029: $result .= $texversion;
1.550 foxr 3030: } elsif ($cleanURL =~/\.tex$/) {
1.498 foxr 3031: # For this sort of print of a single LaTeX file,
3032: # We can just print the LaTeX file as it is uninterpreted in any way:
3033: #
3034:
3035: $result = &fetch_raw_resource($currentURL);
1.511 foxr 3036: if ($helper->{'VARS'}->{'PRINT_ANNOTATIONS'} eq 'yes') {
3037: my $annotation = &annotate($currentURL);
1.649 raeburn 3038: $result =~ s/(\\end\{document})/$annotation$1/;
1.511 foxr 3039: }
3040:
1.499 foxr 3041: $do_postprocessing = 0; # Don't massage the result.
1.498 foxr 3042:
1.550 foxr 3043: } elsif ($cleanURL =~ /\.pdf$/i) {
3044: $result .= &include_pdf($cleanURL);
1.551 foxr 3045: $result .= '\end{document}';
1.559 foxr 3046: } elsif ($cleanURL =~ /\.page$/i) { # Print page in non construction space contexts.
3047:
3048: # Determine the set of resources in the map of the page:
3049:
3050: my $navmap = Apache::lonnavmaps::navmap->new();
3051: my @page_resources = $navmap->retrieveResources($cleanURL);
3052: $result .= &print_page_in_course($helper, $rparmhash,
3053: $cleanURL, \@page_resources);
3054:
1.699 raeburn 3055:
1.162 sakharuk 3056: } else {
1.414 albertel 3057: $result.=&unsupported($currentURL,$helper->{'VARS'}->{'LATEX_TYPE'},
3058: $helper->{'VARS'}->{'symb'});
1.162 sakharuk 3059: }
1.590 foxr 3060: } elsif (($print_type eq 'map_problems') or
3061: ($print_type eq 'map_problems_in_page') or
3062: ($print_type eq 'map_resources_in_page') or
3063: ($print_type eq 'map_problems_pages') or
3064: ($print_type eq 'all_problems') or
3065: ($print_type eq 'all_resources') or # BUGBUG
3066: ($print_type eq 'select_sequences') or
3067: ($print_type eq 'map_incomplete_problems_seq')
1.582 raeburn 3068: ) {
1.699 raeburn 3069:
1.141 sakharuk 3070: #-- produce an output string
1.590 foxr 3071: if (($print_type eq 'map_problems') or
3072: ($print_type eq 'map_incomplete_problems_seq') or
3073: ($print_type eq 'map_problems_in_page') ) {
1.296 sakharuk 3074: $selectionmade = 2;
1.590 foxr 3075: } elsif (($print_type eq 'map_problems_pages') or
3076: ($print_type eq 'map_resources_in_page'))
1.562 foxr 3077: {
1.296 sakharuk 3078: $selectionmade = 3;
1.699 raeburn 3079: } elsif (($print_type eq 'all_problems')
1.536 foxr 3080: ) {
1.296 sakharuk 3081: $selectionmade = 4;
1.590 foxr 3082: } elsif ($print_type eq 'all_resources') { #BUGBUG
1.354 foxr 3083: $selectionmade = 4;
1.590 foxr 3084: } elsif ($print_type eq 'select_sequences') {
1.296 sakharuk 3085: $selectionmade = 7;
3086: }
1.590 foxr 3087:
1.193 sakharuk 3088: $form{'problem_split'}=$parmhash{'problem_stream_switch'};
1.310 sakharuk 3089: $form{'suppress_tries'}=$parmhash{'suppress_tries'};
1.203 sakharuk 3090: $form{'latex_type'}=$helper->{'VARS'}->{'LATEX_TYPE'};
1.309 sakharuk 3091: $form{'print_discussions'}=$helper->{'VARS'}->{'PRINT_DISCUSSIONS'};
1.511 foxr 3092: $form{'print_annotations'} = $helper->{'VARS'}->{'PRINT_ANNOTATIONS'};
3093: if (($helper->{'VARS'}->{'PRINT_DISCUSSIONS'} eq 'yes') ||
3094: ($helper->{'VARS'}->{'PRINT_ANNOTATIONS'} eq 'yes') ) {
3095: $form{'problem_split'}='yes';
3096: }
1.141 sakharuk 3097: my $flag_latex_header_remove = 'NO';
3098: my $flag_page_in_sequence = 'NO';
3099: my @master_seq=split /\|\|\|/, $helper->{'VARS'}->{'RESOURCES'};
1.193 sakharuk 3100: my $prevassignment='';
1.428 albertel 3101:
3102: &Apache::lonxml::clear_problem_counter();
3103:
1.141 sakharuk 3104: for (my $i=0;$i<=$#master_seq;$i++) {
1.350 foxr 3105:
1.521 foxr 3106: &Apache::lonenc::reset_enc();
3107:
1.350 foxr 3108: # Note due to document structure, not allowed to put \newpage
3109: # prior to the first resource
3110:
1.351 foxr 3111: if (defined $page_breaks{$master_seq[$i]}) {
1.350 foxr 3112: if($i != 0) {
3113: $result.="\\newpage\n";
3114: }
3115: }
1.569 foxr 3116: $result .= &get_extra_vspaces($helper, $master_seq[$i]);
1.564 foxr 3117: my ($sequence,$middle_thingy,$urlp)=&Apache::lonnet::decode_symb($master_seq[$i]);
1.237 albertel 3118: $urlp=&Apache::lonnet::clutter($urlp);
1.166 albertel 3119: $form{'symb'}=$master_seq[$i];
1.407 albertel 3120:
3121: my $assignment=&Apache::lonxml::latex_special_symbols(&Apache::lonnet::gettitle($sequence),'header'); #title of the assignment which contains this problem
1.521 foxr 3122:
1.267 sakharuk 3123: if ($selectionmade==7) {$helper->{VARS}->{'assignment'}=$assignment;}
1.247 sakharuk 3124: if ($i==0) {$prevassignment=$assignment;}
1.297 sakharuk 3125: my $texversion='';
1.413 albertel 3126: if ($urlp!~m|^/adm/|
3127: && $urlp=~/\.(problem|exam|quiz|assess|survey|form|library|page|xml|html|htm|xhtml|xhtm)$/) {
1.651 raeburn 3128: my $extension = $1;
1.375 foxr 3129: $resources_printed .= $urlp.':';
1.428 albertel 3130: &Apache::lonxml::remember_problem_counter();
1.566 foxr 3131: if ($flag_latex_header_remove eq 'NO') {
3132: $texversion.=&print_latex_header($helper->{'VARS'}->{'LATEX_TYPE'}); # RF
1.582 raeburn 3133: unless (($helper->{'VARS'}->{'ANSWER_TYPE'} eq 'only') ||
1.652 raeburn 3134: (($i==0) &&
1.582 raeburn 3135: (($urlp=~/\.page$/) ||
1.590 foxr 3136: ($print_type eq 'map_problems_in_page') ||
1.652 raeburn 3137: (($print_type eq 'map_resources_in_page') && ($extension !~ /^x?html?$/))))) {
1.582 raeburn 3138: $flag_latex_header_remove = 'YES';
3139: }
1.566 foxr 3140: }
1.515 foxr 3141: $texversion.=&ssi_with_retries($urlp, $ssi_retry_count, %form);
1.296 sakharuk 3142: if ($urlp=~/\.page$/) {
3143: ($texversion,my $number_of_columns_page) = &page_cleanup($texversion);
1.699 raeburn 3144: if ($number_of_columns_page > $number_of_columns) {$number_of_columns=$number_of_columns_page;}
1.649 raeburn 3145: $texversion =~ s/\\end\{document}\d*/\\end{document}/;
1.296 sakharuk 3146: $flag_page_in_sequence = 'YES';
1.582 raeburn 3147: }
1.428 albertel 3148:
1.296 sakharuk 3149: if(($helper->{'VARS'}->{'ANSWER_TYPE'} eq 'no') ||
3150: ($helper->{'VARS'}->{'ANSWER_TYPE'} eq 'only')) {
1.380 foxr 3151: # Don't permanently pervert the %form hash
3152: my %answerform = %form;
3153: $answerform{'grade_target'}='answer';
3154: $answerform{'answer_output_mode'}='tex';
1.375 foxr 3155: $resources_printed .= $urlp.':';
1.428 albertel 3156:
3157: &Apache::lonxml::restore_problem_counter();
1.515 foxr 3158: my $answer=&ssi_with_retries($urlp, $ssi_retry_count, %answerform);
1.582 raeburn 3159: if ($urlp =~ /\.page$/) {
1.649 raeburn 3160: $answer =~ s/\\end\{document}(\d*)$//;
1.582 raeburn 3161: }
1.296 sakharuk 3162: if ($helper->{'VARS'}->{'ANSWER_TYPE'} eq 'no') {
1.582 raeburn 3163: if ($urlp =~ /\.page$/) {
1.649 raeburn 3164: my @probs = split(/\\keephidden\{ENDOFPROBLEM}/,$texversion);
1.582 raeburn 3165: my $lastprob = pop(@probs);
3166: $texversion = join('\keephidden{ENDOFPROBLEM}',@probs).
3167: $answer.'\keephidden{ENDOFPROBLEM}'.$lastprob;
3168: } else {
1.649 raeburn 3169: $texversion=~s/(\\keephidden\{ENDOFPROBLEM})/$answer$1/;
1.582 raeburn 3170: }
1.249 sakharuk 3171: } else {
1.609 www 3172: if ($urlp=~/$LONCAPA::assess_page_re/) {
1.296 sakharuk 3173: $texversion=&print_latex_header($helper->{'VARS'}->{'LATEX_TYPE'});
1.649 raeburn 3174: # $texversion =~ s/\\begin\{document}//; # FIXME
1.477 albertel 3175: my $title = &Apache::lonnet::gettitle($master_seq[$i]);
3176: $title = &Apache::lonxml::latex_special_symbols($title);
3177: my $body ='\vskip 0 mm \noindent\textbf{'.$title.'}\vskip 0 mm ';
1.423 foxr 3178: $body .= &path_to_problem ($urlp,$LaTeXwidth);
3179: $body .='\vskip 1 mm '.$answer;
1.676 raeburn 3180: $body = &encapsulate_minipage($body,$answerform{'problem_split'});
1.423 foxr 3181: $texversion .= $body;
1.296 sakharuk 3182: } else {
3183: $texversion='';
3184: }
1.249 sakharuk 3185: }
1.511 foxr 3186:
1.246 sakharuk 3187: }
1.511 foxr 3188: if ($helper->{'VARS'}->{'PRINT_ANNOTATIONS'} eq 'yes') {
3189: my $annotation .= &annotate($urlp);
1.649 raeburn 3190: $texversion =~ s/(\\keephidden\{ENDOFPROBLEM})/$annotation$1/;
1.511 foxr 3191: }
3192:
1.296 sakharuk 3193: if ($flag_latex_header_remove ne 'NO') {
3194: $texversion = &latex_header_footer_remove($texversion);
3195: } else {
1.649 raeburn 3196: $texversion =~ s/\\end\{document}//;
1.296 sakharuk 3197: }
3198: if ($helper->{'VARS'}->{'TABLE_INDEX'} eq 'yes') {
3199: $texversion=&IndexCreation($texversion,$urlp);
3200: }
3201: if (($selectionmade == 4) and ($assignment ne $prevassignment)) {
3202: my $name = &get_name();
3203: my $courseidinfo = &get_course();
3204: $prevassignment=$assignment;
1.455 albertel 3205: my $header_text = $parmhash{'print_header_format'};
1.486 foxr 3206: $header_text = &format_page_header($textwidth, $header_text,
1.699 raeburn 3207: $assignment,
3208: $courseidinfo,
1.455 albertel 3209: $name);
1.417 foxr 3210: if ($numberofcolumns eq '1') {
1.455 albertel 3211: $result .='\newpage \noindent\parbox{\minipagewidth}{\noindent\\lhead{'.$header_text.'}} \vskip 5 mm ';
1.416 foxr 3212: } else {
1.455 albertel 3213: $result .='\newpage \noindent\parbox{\minipagewidth}{\noindent\\fancyhead[LO]{'.$header_text.'}} \vskip 5 mm ';
1.416 foxr 3214: }
1.296 sakharuk 3215: }
3216: $result .= $texversion;
1.699 raeburn 3217: $flag_latex_header_remove = 'YES';
3218: } elsif ($urlp=~/\/(smppg|syllabus|aboutme|bulletinboard|ext\.tool)$/) {
1.301 sakharuk 3219: $form{'latex_type'}=$helper->{'VARS'}->{'LATEX_TYPE'};
3220: if ($urlp=~/\/syllabus$/) {$urlp=~s/\/res//;}
1.660 raeburn 3221: if ($urlp=~/\/ext\.tool$/) {$urlp=~s/^\/adm\/wrapper//;}
1.375 foxr 3222: $resources_printed .= $urlp.':';
1.567 foxr 3223: my $texversion = &ssi_with_retries($urlp, $ssi_retry_count, %form);
1.511 foxr 3224: if ($helper->{'VARS'}->{'PRINT_ANNOTATIONS'} eq 'yes') {
3225: my $annotation = &annotate($urlp);
1.649 raeburn 3226: $texversion =~ s/(\\end\{document)/$annotation$1/;
1.511 foxr 3227: }
3228:
1.301 sakharuk 3229: if ($flag_latex_header_remove ne 'NO') {
3230: $texversion = &latex_header_footer_remove($texversion);
1.550 foxr 3231: } else {
1.649 raeburn 3232: $texversion =~ s/\\end\{document}/\\vskip 0\.5mm\\noindent\\makebox\[\\textwidth\/\$number_of_columns\]\[b\]\{\\hrulefill\}/;
1.301 sakharuk 3233: }
3234: $result .= $texversion;
1.699 raeburn 3235: $flag_latex_header_remove = 'YES';
1.550 foxr 3236: } elsif ($urlp=~ /\.pdf$/i) {
3237: if ($i > 0) {
3238: $result .= '\cleardoublepage';
3239: }
1.580 raeburn 3240: my $texfrompdf = &include_pdf($urlp);
3241: if ($flag_latex_header_remove ne 'NO') {
3242: $texfrompdf = &latex_header_footer_remove($texfrompdf);
3243: }
3244: $result .= $texfrompdf;
1.550 foxr 3245: if ($i != $#master_seq) {
3246: if ($numberofcolumns eq '1') {
3247: $result .= '\newpage';
3248: } else {
3249: # the \\'s seem to be needed to let LaTeX know there's something
3250: # on the page since LaTeX seems to not like to clear an empty page.
3251: #
3252: $result .= '\\ \cleardoublepage';
3253: }
3254: }
3255: $flag_latex_header_remove = 'YES';
3256:
1.141 sakharuk 3257: } else {
1.414 albertel 3258: $texversion=&unsupported($urlp,$helper->{'VARS'}->{'LATEX_TYPE'},
3259: $master_seq[$i]);
1.297 sakharuk 3260: if ($flag_latex_header_remove ne 'NO') {
3261: $texversion = &latex_header_footer_remove($texversion);
3262: } else {
1.649 raeburn 3263: $texversion =~ s/\\end\{document}//;
1.297 sakharuk 3264: }
3265: $result .= $texversion;
1.699 raeburn 3266: $flag_latex_header_remove = 'YES';
1.582 raeburn 3267: }
1.699 raeburn 3268: if (&Apache::loncommon::connection_aborted($r)) {
3269: last;
1.550 foxr 3270: }
1.141 sakharuk 3271: }
1.428 albertel 3272: &Apache::lonxml::clear_problem_counter();
1.344 foxr 3273: if ($flag_page_in_sequence eq 'YES') {
1.649 raeburn 3274: $result =~ s/\\usepackage\{calc}/\\usepackage{calc}\\usepackage{longtable}/;
1.344 foxr 3275: }
1.141 sakharuk 3276: $result .= '\end{document}';
1.590 foxr 3277: } elsif (($print_type eq 'problems_for_students') ||
3278: ($print_type eq 'problems_for_students_from_page') ||
3279: ($print_type eq 'all_problems_students') ||
1.591 foxr 3280: ($print_type eq 'resources_for_students') ||
3281: ($print_type eq 'incomplete_problems_selpeople_course') ||
1.679 raeburn 3282: ($print_type eq 'map_incomplete_problems_people_seq') ||
3283: ($print_type eq 'select_sequences_problems_for_students') ||
3284: ($print_type eq 'select_sequences_resources_for_students')) {
1.353 foxr 3285:
3286:
1.699 raeburn 3287: #-- prints assignments for whole class or for selected students
1.284 albertel 3288: my $type;
1.590 foxr 3289: if (($print_type eq 'problems_for_students') ||
3290: ($print_type eq 'problems_for_students_from_page') ||
1.591 foxr 3291: ($print_type eq 'all_problems_students') ||
3292: ($print_type eq 'incomplete_problems_selpeople_course') ||
1.679 raeburn 3293: ($print_type eq 'map_incomplete_problems_people_seq') ||
3294: ($print_type eq 'select_sequences_problems_for_students')) {
1.254 sakharuk 3295: $selectionmade=5;
1.284 albertel 3296: $type='problems';
1.679 raeburn 3297: } elsif (($print_type eq 'resources_for_students') ||
3298: ($print_type eq 'select_sequences_resources_for_students')) {
1.254 sakharuk 3299: $selectionmade=8;
1.284 albertel 3300: $type='resources';
1.254 sakharuk 3301: }
1.150 sakharuk 3302: my @students=split /\|\|\|/, $helper->{'VARS'}->{'STUDENTS'};
1.341 foxr 3303: # The normal sort order is by section then by students within the
3304: # section. If the helper var student_sort is 1, then the user has elected
3305: # to override this and output the students by name.
3306: # Each element of the students array is of the form:
3307: # username:domain:section:last, first:status
1.699 raeburn 3308: #
3309: # Note that student sort is not compatible with printing
1.429 foxr 3310: # 1 section per pdf...so that setting overrides.
1.699 raeburn 3311: #
3312: if (($helper->{'VARS'}->{'student_sort'} eq 1) &&
1.429 foxr 3313: ($helper->{'VARS'}->{'SPLIT_PDFS'} ne "sections")) {
1.341 foxr 3314: @students = sort compare_names @students;
1.618 foxr 3315: } else {
1.699 raeburn 3316: @students = sort compare_sections @students;
1.341 foxr 3317: }
1.429 foxr 3318: &adjust_number_to_print($helper);
3319:
1.278 albertel 3320: if ($helper->{'VARS'}->{'NUMBER_TO_PRINT'} eq '0' ||
3321: $helper->{'VARS'}->{'NUMBER_TO_PRINT'} eq 'all' ) {
3322: $helper->{'VARS'}->{'NUMBER_TO_PRINT'}=$#students+1;
3323: }
1.699 raeburn 3324: # If we are splitting on section boundaries, we need
3325: # to remember that in split_on_sections and
1.429 foxr 3326: # print all of the students in the list.
3327: #
3328: my $split_on_sections = 0;
3329: if ($helper->{'VARS'}->{'NUMBER_TO_PRINT'} eq 'section') {
3330: $split_on_sections = 1;
3331: $helper->{'VARS'}->{'NUMBER_TO_PRINT'} = $#students+1;
3332: }
1.150 sakharuk 3333: my @master_seq=split /\|\|\|/, $helper->{'VARS'}->{'RESOURCES'};
1.350 foxr 3334:
1.626 raeburn 3335: my $map;
3336: if ($helper->{VARS}->{'symb'}) {
1.687 raeburn 3337: unless ((($print_type eq 'all_problems_students') ||
3338: ($print_type eq 'incomplete_problems_selpeople_course')) &&
3339: $perm{'pfo'}) {
3340: ($map, my $id, my $resource) =
3341: &Apache::lonnet::decode_symb($helper->{VARS}->{'symb'});
3342: }
1.692 raeburn 3343: } elsif (($helper->{'VARS'}->{'postdata'} eq '/adm/navmaps') && ($perm{'pfo'})) {
3344: $map = $helper->{'VARS'}->{'SEQUENCE'};
1.626 raeburn 3345: }
3346:
1.150 sakharuk 3347: #loop over students
1.562 foxr 3348:
3349: my $flag_latex_header_remove = 'NO';
1.150 sakharuk 3350: my %moreenv;
1.330 sakharuk 3351: $moreenv{'instructor_comments'}='hide';
1.285 albertel 3352: $moreenv{'textwidth'}=&get_textwidth($helper,$LaTeXwidth);
1.309 sakharuk 3353: $moreenv{'print_discussions'}=$helper->{'VARS'}->{'PRINT_DISCUSSIONS'};
1.511 foxr 3354: $moreenv{'print_annotations'} = $helper->{'VARS'}->{'PRINT_ANNOTATIONS'};
1.353 foxr 3355: $moreenv{'problem_split'} = $parmhash{'problem_stream_switch'};
1.369 foxr 3356: $moreenv{'suppress_tries'} = $parmhash{'suppress_tries'};
1.511 foxr 3357: if (($helper->{'VARS'}->{'PRINT_DISCUSSIONS'} eq 'yes') ||
3358: ($helper->{'VARS'}->{'PRINT_ANNOTATIONS'} eq 'yes')) {
3359: $moreenv{'problem_split'}='yes';
3360: }
1.611 www 3361: my %prog_state=&Apache::lonhtmlcommon::Create_PrgWin($r,$#students+1);
1.272 sakharuk 3362: my $student_counter=-1;
1.429 foxr 3363: my $i = 0;
1.430 albertel 3364: my $last_section = (split(/:/,$students[0]))[2];
1.647 raeburn 3365: my $nohidemap;
3366: if ($perm{'pav'} && $perm{'vgr'}) {
3367: $nohidemap = 1;
3368: }
1.150 sakharuk 3369: foreach my $person (@students) {
1.373 albertel 3370: my $duefile="/home/httpd/prtspool/$env{'user.name'}_$env{'user.domain'}_printout.due";
1.311 sakharuk 3371: if (-e $duefile) {
3372: my $temp_file = Apache::File->new('>>'.$duefile);
3373: print $temp_file "1969\n";
3374: }
1.272 sakharuk 3375: $student_counter++;
1.429 foxr 3376: if ($split_on_sections) {
1.430 albertel 3377: my $this_section = (split(/:/,$person))[2];
1.429 foxr 3378: if ($this_section ne $last_section) {
3379: $i++;
3380: $last_section = $this_section;
3381: }
3382: } else {
3383: $i=int($student_counter/$helper->{'VARS'}{'NUMBER_TO_PRINT'});
3384: }
1.626 raeburn 3385: my $actual_seq = master_seq_to_person_seq($map, \@master_seq,
1.647 raeburn 3386: $person, undef, $nohidemap);
1.375 foxr 3387: my ($output,$fullname, $printed)=&print_resources($r,$helper,
1.353 foxr 3388: $person,$type,
1.595 foxr 3389: \%moreenv, $actual_seq,
1.360 albertel 3390: $flag_latex_header_remove,
1.422 albertel 3391: $LaTeXwidth);
1.375 foxr 3392: $resources_printed .= ":";
1.284 albertel 3393: $print_array[$i].=$output;
3394: $student_names[$i].=$person.':'.$fullname.'_END_';
1.581 bisitz 3395: # &Apache::lonhtmlcommon::Increment_PrgWin($r,\%prog_state,&mt('last student').' '.$fullname);
3396: &Apache::lonhtmlcommon::Increment_PrgWin($r,\%prog_state,'last student');
1.284 albertel 3397: $flag_latex_header_remove = 'YES';
1.703 raeburn 3398: if ($printed) {
3399: $lastprinted = $fullname;
3400: }
1.331 albertel 3401: if (&Apache::loncommon::connection_aborted($r)) { last; }
1.284 albertel 3402: }
3403: &Apache::lonhtmlcommon::Close_PrgWin($r,\%prog_state);
3404: $result .= $print_array[0].' \end{document}';
1.590 foxr 3405: } elsif (($print_type eq 'problems_for_anon') ||
3406: ($print_type eq 'problems_for_anon_page') ||
1.679 raeburn 3407: ($print_type eq 'resources_for_anon') ||
3408: ($print_type eq 'select_sequences_problems_for_anon') ||
3409: ($print_type eq 'select_sequences_resources_for_anon')) {
1.703 raeburn 3410: $selectionmade = 9;
1.373 albertel 3411: my $cdom =$env{'course.'.$env{'request.course.id'}.'.domain'};
3412: my $cnum =$env{'course.'.$env{'request.course.id'}.'.num'};
1.288 albertel 3413: my $num_todo=$helper->{'VARS'}->{'NUMBER_TO_PRINT_TOTAL'};
3414: my $code_name=$helper->{'VARS'}->{'ANON_CODE_STORAGE_NAME'};
1.292 albertel 3415: my $old_name=$helper->{'VARS'}->{'REUSE_OLD_CODES'};
1.385 foxr 3416: my $single_code = $helper->{'VARS'}->{'SINGLE_CODE'};
1.388 foxr 3417: my $selected_code = $helper->{'VARS'}->{'CODE_SELECTED_FROM_LIST'};
1.381 albertel 3418: my $code_option=$helper->{'VARS'}->{'CODE_OPTION'};
1.668 raeburn 3419: my @lines = &Apache::lonnet::get_scantronformat_file();
1.596 raeburn 3420: my ($code_type,$code_length,$bubbles_per_row)=('letter',6,10);
1.542 raeburn 3421: foreach my $line (@lines) {
1.678 raeburn 3422: next if (($line =~ /^\#/) || ($line eq ''));
1.699 raeburn 3423: my ($name,$type,$length,$bubbles_per_item) =
1.596 raeburn 3424: (split(/:/,$line))[0,2,4,17];
1.381 albertel 3425: if ($name eq $code_option) {
3426: $code_length=$length;
3427: if ($type eq 'number') { $code_type = 'number'; }
1.699 raeburn 3428: chomp($bubbles_per_item);
1.596 raeburn 3429: if (($bubbles_per_item ne '') && ($bubbles_per_item > 0)) {
1.699 raeburn 3430: $bubbles_per_row = $bubbles_per_item;
1.596 raeburn 3431: }
1.381 albertel 3432: }
3433: }
1.675 raeburn 3434: my $map;
1.625 raeburn 3435: if ($helper->{VARS}{'symb'}) {
1.626 raeburn 3436: ($map, my $id, my $resource) =
3437: &Apache::lonnet::decode_symb($helper->{VARS}{'symb'});
1.692 raeburn 3438: } elsif (($helper->{'VARS'}->{'postdata'} eq '/adm/navmaps') && ($perm{'pfo'})) {
3439: $map = $helper->{'VARS'}->{'SEQUENCE'};
1.625 raeburn 3440: }
1.288 albertel 3441: my %moreenv = ('textwidth' => &get_textwidth($helper,$LaTeXwidth));
1.353 foxr 3442: $moreenv{'problem_split'} = $parmhash{'problem_stream_switch'};
1.697 raeburn 3443: $moreenv{'suppress_tries'} = $parmhash{'suppress_tries'};
1.420 albertel 3444: $moreenv{'instructor_comments'}='hide';
1.596 raeburn 3445: $moreenv{'bubbles_per_row'} = $bubbles_per_row;
1.288 albertel 3446: my $seed=time+($$<<16)+($$);
1.292 albertel 3447: my @allcodes;
3448: if ($old_name) {
1.381 albertel 3449: my %result=&Apache::lonnet::get('CODEs',
3450: [$old_name,"type\0$old_name"],
3451: $cdom,$cnum);
3452: $code_type=$result{"type\0$old_name"};
1.292 albertel 3453: @allcodes=split(',',$result{$old_name});
1.336 albertel 3454: $num_todo=scalar(@allcodes);
1.389 foxr 3455: } elsif ($selected_code) { # Selection value is always numeric.
1.388 foxr 3456: $num_todo = 1;
3457: @allcodes = ($selected_code);
1.385 foxr 3458: } elsif ($single_code) {
3459:
1.387 foxr 3460: $num_todo = 1; # Unconditionally one code to do.
1.385 foxr 3461: # If an alpha code have to convert to numbers so it can be
3462: # converted back to letters again :-)
3463: #
3464: if ($code_type ne 'number') {
3465: $single_code = &letters_to_num($single_code);
3466: }
3467: @allcodes = ($single_code);
1.292 albertel 3468: } else {
3469: my %allcodes;
1.299 albertel 3470: srand($seed);
1.292 albertel 3471: for (my $i=0;$i<$num_todo;$i++) {
1.381 albertel 3472: $moreenv{'CODE'}=&get_CODE(\%allcodes,$i,$seed,$code_length,
3473: $code_type);
1.292 albertel 3474: }
1.645 raeburn 3475: $code_name =~ s/^\s+//;
3476: $code_name =~ s/\s+$//;
1.292 albertel 3477: if ($code_name) {
3478: &Apache::lonnet::put('CODEs',
1.381 albertel 3479: {
3480: $code_name =>join(',',keys(%allcodes)),
3481: "type\0$code_name" => $code_type
3482: },
1.292 albertel 3483: $cdom,$cnum);
3484: }
3485: @allcodes=keys(%allcodes);
3486: }
1.336 albertel 3487: my @master_seq=split /\|\|\|/, $helper->{'VARS'}->{'RESOURCES'};
1.590 foxr 3488: my ($type) = split(/_/,$print_type);
1.452 albertel 3489: &adjust_number_to_print($helper);
1.336 albertel 3490: my $number_per_page=$helper->{'VARS'}->{'NUMBER_TO_PRINT'};
1.587 foxr 3491: if ($number_per_page eq '0' || $number_per_page eq 'all'
3492: || $number_per_page eq 'section') {
3493: $number_per_page=$num_todo > 0 ? $num_todo : 1;
1.336 albertel 3494: }
1.699 raeburn 3495: my $flag_latex_header_remove = 'NO';
1.611 www 3496: my %prog_state=&Apache::lonhtmlcommon::Create_PrgWin($r,$num_todo);
1.295 albertel 3497: my $count=0;
1.647 raeburn 3498: my $nohidemap;
3499: if ($perm{'pav'} && $perm{'vgr'}) {
3500: $nohidemap = 1;
3501: }
1.292 albertel 3502: foreach my $code (sort(@allcodes)) {
1.295 albertel 3503: my $file_num=int($count/$number_per_page);
1.699 raeburn 3504: if ($code_type eq 'number') {
1.381 albertel 3505: $moreenv{'CODE'}=$code;
3506: } else {
3507: $moreenv{'CODE'}=&num_to_letters($code);
3508: }
1.675 raeburn 3509: $env{'form.CODE'} = $moreenv{'CODE'};
3510: my $actual_seq = master_seq_to_person_seq($map, \@master_seq,
3511: undef,
3512: $moreenv{'CODE'}, $nohidemap);
3513: delete($env{'form.CODE'});
1.375 foxr 3514: my ($output,$fullname, $printed)=
1.288 albertel 3515: &print_resources($r,$helper,'anonymous',$type,\%moreenv,
1.625 raeburn 3516: $actual_seq,$flag_latex_header_remove,
1.360 albertel 3517: $LaTeXwidth);
1.375 foxr 3518: $resources_printed .= ":";
1.295 albertel 3519: $print_array[$file_num].=$output;
1.288 albertel 3520: &Apache::lonhtmlcommon::Increment_PrgWin($r,\%prog_state,
3521: &mt('last assignment').' '.$fullname);
3522: $flag_latex_header_remove = 'YES';
1.295 albertel 3523: $count++;
1.703 raeburn 3524: if ($printed) {
3525: $lastprinted = $fullname;
3526: }
1.331 albertel 3527: if (&Apache::loncommon::connection_aborted($r)) { last; }
1.288 albertel 3528: }
3529: &Apache::lonhtmlcommon::Close_PrgWin($r,\%prog_state);
3530: $result .= $print_array[0].' \end{document}';
1.665 raeburn 3531: } elsif ($print_type eq 'problems_from_directory') {
1.699 raeburn 3532: #prints selected problems from the subdirectory
1.151 sakharuk 3533: $selectionmade = 6;
3534: my @list_of_files=split /\|\|\|/, $helper->{'VARS'}->{'FILES'};
1.154 sakharuk 3535: @list_of_files=sort @list_of_files;
1.699 raeburn 3536: my $flag_latex_header_remove = 'NO';
1.175 sakharuk 3537: my $rndseed=time;
1.230 albertel 3538: if ($helper->{'VARS'}->{'curseed'}) {
3539: $rndseed=$helper->{'VARS'}->{'curseed'};
3540: }
1.151 sakharuk 3541: for (my $i=0;$i<=$#list_of_files;$i++) {
1.521 foxr 3542:
3543: &Apache::lonenc::reset_enc();
3544:
1.152 sakharuk 3545: my $urlp = $list_of_files[$i];
1.253 sakharuk 3546: $urlp=~s|//|/|;
1.152 sakharuk 3547: if ($urlp=~/\//) {
1.353 foxr 3548: $form{'problem_split'}=$parmhash{'problem_stream_switch'};
1.175 sakharuk 3549: $form{'rndseed'}=$rndseed;
1.603 www 3550: $urlp =~ s|^$Apache::lonnet::perlvar{'lonDocRoot'}||;
1.375 foxr 3551: $resources_printed .= $urlp.':';
1.515 foxr 3552: my $texversion=&ssi_with_retries($urlp, $ssi_retry_count, %form);
1.251 sakharuk 3553: if(($helper->{'VARS'}->{'ANSWER_TYPE'} eq 'no') ||
1.253 sakharuk 3554: ($helper->{'VARS'}->{'ANSWER_TYPE'} eq 'only')) {
1.380 foxr 3555: # Don't permanently pervert %form:
3556: my %answerform = %form;
3557: $answerform{'grade_target'}='answer';
3558: $answerform{'answer_output_mode'}='tex';
3559: $answerform{'latex_type'}=$helper->{'VARS'}->{'LATEX_TYPE'};
3560: $answerform{'rndseed'}=$rndseed;
1.375 foxr 3561: $resources_printed .= $urlp.':';
1.515 foxr 3562: my $answer=&ssi_with_retries($urlp, $ssi_retry_count, %answerform);
1.251 sakharuk 3563: if ($helper->{'VARS'}->{'ANSWER_TYPE'} eq 'no') {
1.649 raeburn 3564: $texversion=~s/(\\keephidden\{ENDOFPROBLEM})/$answer$1/;
1.251 sakharuk 3565: } else {
1.253 sakharuk 3566: $texversion=&print_latex_header($helper->{'VARS'}->{'LATEX_TYPE'});
3567: if ($helper->{'VARS'}->{'construction'} ne '1') {
3568: $texversion.='\vskip 0 mm \noindent ';
3569: $texversion.=&path_to_problem ($urlp,$LaTeXwidth);
3570: } else {
1.604 www 3571: $texversion.='\vskip 0 mm \noindent\textbf{'.
1.633 raeburn 3572: &mt("Printing from Authoring Space: No Title").'}\vskip 0 mm ';
1.604 www 3573: $texversion.=&path_to_problem ($urlp,$LaTeXwidth);
1.253 sakharuk 3574: }
3575: $texversion.='\vskip 1 mm '.$answer.'\end{document}';
1.251 sakharuk 3576: }
1.174 sakharuk 3577: }
1.515 foxr 3578: #this chunk is responsible for printing the path to problem
3579:
1.603 www 3580: my $newurlp=&path_to_problem($urlp,$LaTeXwidth);
1.649 raeburn 3581: $texversion =~ s/(\\begin\{minipage}\{\\textwidth})/$1 $newurlp/;
1.152 sakharuk 3582: if ($flag_latex_header_remove ne 'NO') {
3583: $texversion = &latex_header_footer_remove($texversion);
3584: } else {
1.649 raeburn 3585: $texversion =~ s/\\end\{document}//;
1.216 sakharuk 3586: }
3587: if ($helper->{'VARS'}->{'TABLE_INDEX'} eq 'yes') {
3588: $texversion=&IndexCreation($texversion,$urlp);
1.152 sakharuk 3589: }
1.219 sakharuk 3590: if ($helper->{'VARS'}->{'CONSTR_RESOURSE_URL'} eq 'yes') {
3591: $texversion=~s/(\\addcontentsline\{toc\}\{subsection\}\{[^\}]*\})/$1 URL: \\verb|$urlp| \\strut\\\\\\strut /;
1.699 raeburn 3592:
1.219 sakharuk 3593: }
1.152 sakharuk 3594: $result .= $texversion;
3595: }
1.699 raeburn 3596: $flag_latex_header_remove = 'YES';
1.151 sakharuk 3597: }
1.175 sakharuk 3598: if ($helper->{VARS}->{'construction'} eq '1') {$result=~s/(\\typeout)/ RANDOM SEED IS $rndseed $1/;}
1.152 sakharuk 3599: $result .= '\end{document}';
1.140 sakharuk 3600: }
3601: #-------------------------------------------------------- corrections for the different page formats
1.499 foxr 3602:
3603: # Only post process if that has not been turned off e.g. by a raw latex resource.
3604:
3605: if ($do_postprocessing) {
1.703 raeburn 3606: my $mostrecent;
3607: if ((($selectionmade == 5) || ($selectionmade == 8) || ($selectionmade == 9)) &&
3608: (($numberofcolumns == 1) || ($laystyle eq 'album' && $papersize eq 'a4'))) {
3609: $mostrecent = $lastprinted;
3610: }
1.590 foxr 3611: $result = &page_format_transformation($papersize,
3612: $laystyle,$numberofcolumns,
3613: $print_type,$result,
3614: $helper->{VARS}->{'assignment'},
3615: $helper->{'VARS'}->{'TABLE_CONTENTS'},
3616: $helper->{'VARS'}->{'TABLE_INDEX'},
1.703 raeburn 3617: $selectionmade,$mostrecent);
1.499 foxr 3618: $result = &latex_corrections($number_of_columns,$result,$selectionmade,
3619: $helper->{'VARS'}->{'ANSWER_TYPE'});
3620: #if ($numberofcolumns == 1) {
1.451 albertel 3621: $result =~ s/\\textwidth\s*=\s*-?\d*\.?\d*\s*(cm|mm|in)/\\textwidth= $helper->{'VARS'}->{'pagesize.width'} $helper->{'VARS'}->{'pagesize.widthunit'} /;
3622: $result =~ s/\\textheight\s*=?\s*-?\d*\.?\d*\s*(cm|mm|in)/\\textheight $helper->{'VARS'}->{'pagesize.height'} $helper->{'VARS'}->{'pagesize.heightunit'} /;
3623: $result =~ s/\\evensidemargin\s*=\s*-?\d*\.?\d*\s*(cm|mm|in)/\\evensidemargin= $helper->{'VARS'}->{'pagesize.lmargin'} $helper->{'VARS'}->{'pagesize.lmarginunit'} /;
3624: $result =~ s/\\oddsidemargin\s*=\s*-?\d*\.?\d*\s*(cm|mm|in)/\\oddsidemargin= $helper->{'VARS'}->{'pagesize.lmargin'} $helper->{'VARS'}->{'pagesize.lmarginunit'} /;
1.499 foxr 3625: #}
3626: }
1.367 foxr 3627:
1.648 damieng 3628: # Set URLback so we can provide a link back to the resource and to change options.
3629: # (Since the browser back button does not currently work with https,
3630: # the back link is useful even when there is an easy-to-miss LON-CAPA back button.)
1.274 sakharuk 3631:
1.276 sakharuk 3632: my $URLback=''; #link to original document
1.510 albertel 3633: if ($helper->{'VARS'}->{'construction'} eq '1') {
1.607 www 3634: $URLback=$helper->{'VARS'}->{'filename'};
1.648 damieng 3635: } elsif ($helper->{VARS}{'symb'}) {
3636: my ($map, $id, $url) = &Apache::lonnet::decode_symb($helper->{VARS}{'symb'});
1.666 raeburn 3637: my $cdom =$env{'course.'.$env{'request.course.id'}.'.domain'};
3638: my $cnum =$env{'course.'.$env{'request.course.id'}.'.num'};
1.672 raeburn 3639: my ($anchor,$usehttp,$plainurl);
1.653 raeburn 3640: $url = &Apache::lonnet::clutter($url);
1.672 raeburn 3641: $plainurl = $url;
1.666 raeburn 3642: if (($ENV{'SERVER_PORT'} == 443) && ($env{'request.course.id'}) &&
3643: (($url =~ m{^\Q/public/$cdom/$cnum/syllabus\E($|\?)}) ||
3644: ($url =~ m{^\Q/adm/wrapper/ext/\E(?!https:)}))) {
1.673 raeburn 3645: unless ((&Apache::lonnet::uses_sts()) || (&Apache::lonnet::waf_allssl())) {
1.666 raeburn 3646: $usehttp = 1;
3647: }
3648: }
1.653 raeburn 3649: if ($env{'request.enc'}) {
1.699 raeburn 3650: $url = &Apache::lonenc::encrypted($url);
1.653 raeburn 3651: }
1.658 raeburn 3652: if ($url ne '') {
1.666 raeburn 3653: my $symb = $helper->{VARS}{'symb'};
3654: if ($url =~ m{^\Q/adm/wrapper/ext/\E}) {
3655: my $link = $url;
3656: ($link,$anchor) = ($url =~ /^([^\#]+)(?:|(\#[^\#]+))$/);
3657: if ($anchor) {
3658: ($symb) = ($helper->{VARS}{'symb'} =~ /^([^\#]+)/);
3659: }
3660: $url = $link;
3661: }
3662: $URLback = $url;
3663: if ($usehttp) {
3664: $URLback .= (($URLback =~ /\?/) ? '&':'?').'usehttp=1';
3665: }
1.672 raeburn 3666: unless ($plainurl =~ /\.page$/) {
3667: $URLback .= (($URLback =~ /\?/) ? '&':'?').'symb='.&escape($symb.$anchor);
3668: }
1.658 raeburn 3669: }
1.679 raeburn 3670: } elsif (($helper->{VARS}->{'postdata'} eq '/adm/navmaps') &&
3671: ($env{'request.course.id'})) {
3672: $URLback=$helper->{VARS}->{'postdata'};
1.276 sakharuk 3673: }
1.556 foxr 3674: #
3675: # Final adjustment of the font size:
3676: #
3677:
3678: $result = set_font_size($result);
1.375 foxr 3679:
1.612 foxr 3680: # Insert any babel headers required.
3681:
3682: $result = &collect_languages($result);
3683:
3684:
1.699 raeburn 3685: #-- writing .tex file in prtspool
1.525 www 3686: my $temp_file;
3687: my $identifier = &Apache::loncommon::get_cgi_id();
3688: my $filename = "/home/httpd/prtspool/$env{'user.name'}_$env{'user.domain'}_printout_$identifier.tex";
1.699 raeburn 3689: if (!($#print_array>0)) {
1.525 www 3690: unless ($temp_file = Apache::File->new('>'.$filename)) {
3691: $r->log_error("Couldn't open $filename for output $!");
1.699 raeburn 3692: return SERVER_ERROR;
1.525 www 3693: }
3694: print $temp_file $result;
3695: my $begin=index($result,'\begin{document}',0);
1.699 raeburn 3696: my $inc=substr($result,0,$begin+16);
1.515 foxr 3697: } else {
1.525 www 3698: my $begin=index($result,'\begin{document}',0);
3699: my $inc=substr($result,0,$begin+16);
3700: for (my $i=0;$i<=$#print_array;$i++) {
3701: if ($i==0) {
3702: $print_array[$i]=$result;
3703: } else {
3704: $print_array[$i].='\end{document}';
1.699 raeburn 3705: $print_array[$i] =
1.525 www 3706: &latex_corrections($number_of_columns,$print_array[$i],
1.699 raeburn 3707: $selectionmade,
1.525 www 3708: $helper->{'VARS'}->{'ANSWER_TYPE'});
1.699 raeburn 3709:
1.525 www 3710: my $anobegin=index($print_array[$i],'\setcounter{page}',0);
3711: substr($print_array[$i],0,$anobegin)='';
3712: $print_array[$i]=$inc.$print_array[$i];
3713: }
3714: my $temp_file;
3715: my $newfilename=$filename;
3716: my $num=$i+1;
1.699 raeburn 3717: $newfilename =~s/\.tex$//;
1.525 www 3718: $newfilename=sprintf("%s_%03d.tex",$newfilename, $num);
3719: unless ($temp_file = Apache::File->new('>'.$newfilename)) {
3720: $r->log_error("Couldn't open $newfilename for output $!");
1.699 raeburn 3721: return SERVER_ERROR;
1.525 www 3722: }
3723: print $temp_file $print_array[$i];
3724: }
3725: }
3726: my $student_names='';
3727: if ($#print_array>0) {
3728: for (my $i=0;$i<=$#print_array;$i++) {
3729: $student_names.=$student_names[$i].'_ENDPERSON_';
1.515 foxr 3730: }
1.525 www 3731: } else {
3732: if ($#student_names>-1) {
3733: $student_names=$student_names[0].'_ENDPERSON_';
1.515 foxr 3734: } else {
1.525 www 3735: my $fullname = &get_name($env{'user.name'},$env{'user.domain'});
3736: $student_names=join(':',$env{'user.name'},$env{'user.domain'},
1.515 foxr 3737: $env{'request.course.sec'},$fullname).
3738: '_ENDPERSON_'.'_END_';
3739: }
1.525 www 3740: }
1.515 foxr 3741:
1.525 www 3742: # logic for now is too complex to trace if this has been defined
3743: # yet.
3744: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
3745: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
3746: &Apache::lonnet::appenv({'cgi.'.$identifier.'.file' => $filename,
1.515 foxr 3747: 'cgi.'.$identifier.'.layout' => $laystyle,
3748: 'cgi.'.$identifier.'.numcol' => $numberofcolumns,
3749: 'cgi.'.$identifier.'.paper' => $papersize,
3750: 'cgi.'.$identifier.'.selection' => $selectionmade,
3751: 'cgi.'.$identifier.'.tableofcontents' => $helper->{'VARS'}->{'TABLE_CONTENTS'},
3752: 'cgi.'.$identifier.'.tableofindex' => $helper->{'VARS'}->{'TABLE_INDEX'},
3753: 'cgi.'.$identifier.'.role' => $perm{'pav'},
3754: 'cgi.'.$identifier.'.numberoffiles' => $#print_array,
3755: 'cgi.'.$identifier.'.studentnames' => $student_names,
1.655 raeburn 3756: 'cgi.'.$identifier.'.backref' => &escape($URLback),});
1.525 www 3757: &Apache::lonnet::appenv({"cgi.$identifier.user" => $env{'user.name'},
1.515 foxr 3758: "cgi.$identifier.domain" => $env{'user.domain'},
1.699 raeburn 3759: "cgi.$identifier.courseid" => $cnum,
3760: "cgi.$identifier.coursedom" => $cdom,
1.520 raeburn 3761: "cgi.$identifier.resources" => $resources_printed});
1.515 foxr 3762:
1.525 www 3763: my $end_page = &Apache::loncommon::end_page();
1.529 raeburn 3764: my $continue_text = &mt('Continue');
1.525 www 3765: # If there's been an unrecoverable SSI error, report it to the user
3766: if ($ssi_error) {
3767: my $helpurl = &Apache::loncommon::top_nav_help('Helpdesk');
1.554 bisitz 3768: $r->print('<br /><p class="LC_error">'.&mt('An unrecoverable network error occurred:').'</p><p>'.
1.526 www 3769: &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:').
3770: '<br />'.$ssi_last_error_resource.'<br />'.$ssi_last_error.
3771: '</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 3772: &mt('You may be able to reprint the individual resources for which this error occurred, as the issue may be temporary.').
1.525 www 3773: '<br />'.&mt('If the error persists, please contact the [_1] for assistance.',$helpurl).'</p><p>'.
3774: &mt('We apologize for the inconvenience.').'</p>'.
1.528 raeburn 3775: '<a href="/cgi-bin/printout.pl?'.$identifier.'">'.$continue_text.'</a>'.$end_page);
1.525 www 3776: } else {
1.515 foxr 3777: $r->print(<<FINALEND);
1.317 albertel 3778: <br />
1.288 albertel 3779: <meta http-equiv="Refresh" content="0; url=/cgi-bin/printout.pl?$identifier" />
1.528 raeburn 3780: <a href="/cgi-bin/printout.pl?$identifier">$continue_text</a>
1.431 albertel 3781: $end_page
1.140 sakharuk 3782: FINALEND
1.528 raeburn 3783: } # endif ssi errors.
1.140 sakharuk 3784: }
3785:
1.288 albertel 3786:
3787: sub get_CODE {
1.381 albertel 3788: my ($all_codes,$num,$seed,$size,$type)=@_;
1.288 albertel 3789: my $max='1'.'0'x$size;
3790: my $newcode;
3791: while(1) {
1.392 albertel 3792: $newcode=sprintf("%0".$size."d",int(rand($max)));
1.288 albertel 3793: if (!exists($$all_codes{$newcode})) {
3794: $$all_codes{$newcode}=1;
1.381 albertel 3795: if ($type eq 'number' ) {
3796: return $newcode;
3797: } else {
3798: return &num_to_letters($newcode);
3799: }
1.288 albertel 3800: }
3801: }
3802: }
1.140 sakharuk 3803:
1.284 albertel 3804: sub print_resources {
1.360 albertel 3805: my ($r,$helper,$person,$type,$moreenv,$master_seq,$remove_latex_header,
1.422 albertel 3806: $LaTeXwidth)=@_;
1.699 raeburn 3807: my $current_output = '';
1.375 foxr 3808: my $printed = '';
1.284 albertel 3809: my ($username,$userdomain,$usersection) = split /:/,$person;
3810: my $fullname = &get_name($username,$userdomain);
1.492 foxr 3811: my $namepostfix = "\\\\"; # Both anon and not anon should get the same vspace.
1.600 foxr 3812:
1.619 foxr 3813:
1.591 foxr 3814: #
3815: # Figure out if we need to filter the output by
3816: # the incomplete problems for that person
3817: #
3818: my $print_type = $helper->{'VARS'}->{'PRINT_TYPE'};
3819: my $print_incomplete = 0;
3820: if (($print_type eq 'map_incomplete_problems_people_seq') ||
3821: ($print_type eq 'incomplete_problems_selpeople_course')) {
3822: $print_incomplete = 1;
3823: }
1.596 raeburn 3824: if ($person eq 'anonymous') {
1.613 ramirez 3825: $namepostfix .=&mt('Name:')." ";
1.288 albertel 3826: $fullname = "CODE - ".$moreenv->{'CODE'};
3827: }
1.590 foxr 3828:
1.444 foxr 3829: # Fullname may have special latex characters that need \ prefixing:
3830: #
3831:
1.350 foxr 3832: my $i = 0;
1.591 foxr 3833: my $actually_printed = 0; # Count of resources printed.
1.699 raeburn 3834: #goes through all resources, checks if they are available for
3835: #current student, and produces output
1.428 albertel 3836:
3837: &Apache::lonxml::clear_problem_counter();
1.364 albertel 3838: my %page_breaks = &get_page_breaks($helper);
1.476 albertel 3839: my $columns_in_format = (split(/\|/,$helper->{'VARS'}->{'FORMAT'}))[1];
1.440 foxr 3840: #
1.699 raeburn 3841: # end each student with a
1.440 foxr 3842: # Special that allows the post processor to even out the page
3843: # counts later. Nasty problem this... it would be really
3844: # nice to put the special in as a postscript comment
1.441 foxr 3845: # e.g. \special{ps:\ENDOFSTUDENTSTAMP} unfortunately,
1.440 foxr 3846: # The special gets passed the \ and dvips puts it in the output file
1.689 raeburn 3847: # so we will just rely on printout.pl to strip ENDOFSTUDENTSTAMP from the
1.441 foxr 3848: # postscript. Each ENDOFSTUDENTSTAMP will go on a line by itself.
1.440 foxr 3849: #
1.591 foxr 3850:
1.568 foxr 3851: my $syllabus_first = 0;
1.619 foxr 3852: my $current_assignment = "";
3853: my $assignment;
3854: my $courseidinfo = &get_course();
1.643 raeburn 3855: my $possprint = scalar(@{$master_seq});
1.619 foxr 3856:
1.284 albertel 3857: foreach my $curresline (@{$master_seq}) {
1.351 foxr 3858: if (defined $page_breaks{$curresline}) {
1.350 foxr 3859: if($i != 0) {
3860: $current_output.= "\\newpage\n";
3861: }
3862: }
1.569 foxr 3863: $current_output .= &get_extra_vspaces($helper, $curresline);
1.350 foxr 3864: $i++;
1.619 foxr 3865: my ($map,$id,$res_url) = &Apache::lonnet::decode_symb($curresline);
3866:
3867: # See if we need to emit a new header:
3868:
1.699 raeburn 3869: if ( !($type eq 'problems' &&
1.609 www 3870: ($curresline!~ m/$LONCAPA::assess_page_re/)) ) {
1.705 ! raeburn 3871: if ($print_incomplete && !&incomplete($username, $userdomain, $usersection, $res_url)) {
1.591 foxr 3872: next;
3873: }
3874: $actually_printed++; # we're going to print one.
1.639 raeburn 3875:
1.284 albertel 3876: if (&Apache::lonnet::allowed('bre',$res_url)) {
1.414 albertel 3877: if ($res_url!~m|^ext/|
1.413 albertel 3878: && $res_url=~/\.(problem|exam|quiz|assess|survey|form|library|page|xml|html|htm|xhtml|xhtm)$/) {
1.375 foxr 3879: $printed .= $curresline.':';
1.699 raeburn 3880: &Apache::lonxml::remember_problem_counter();
1.428 albertel 3881:
1.526 www 3882: my $rendered = &get_student_view_with_retries($curresline,$ssi_retry_count,$username,$userdomain,$env{'request.course.id'},'tex',$moreenv);
1.582 raeburn 3883: if ($res_url =~ /\.page$/) {
3884: if ($remove_latex_header eq 'NO') {
3885: if (!($rendered =~ /\\begin\{document\}/)) {
3886: $rendered = &print_latex_header().$rendered;
3887: }
3888: }
1.591 foxr 3889: ;
1.582 raeburn 3890: if ($remove_latex_header eq 'YES') {
3891: $rendered = &latex_header_footer_remove($rendered);
3892: } else {
1.649 raeburn 3893: $rendered =~ s/\\end\{document}\d*//;
1.582 raeburn 3894: }
3895: }
1.305 sakharuk 3896: if(($helper->{'VARS'}->{'ANSWER_TYPE'} eq 'no') ||
3897: ($helper->{'VARS'}->{'ANSWER_TYPE'} eq 'only')) {
1.380 foxr 3898: # Use a copy of the hash so we don't pervert it on future loop passes.
3899: my %answerenv = %{$moreenv};
3900: $answerenv{'answer_output_mode'}='tex';
1.591 foxr 3901:
3902:
1.380 foxr 3903: $answerenv{'latex_type'}=$helper->{'VARS'}->{'LATEX_TYPE'};
1.428 albertel 3904:
3905: &Apache::lonxml::restore_problem_counter();
3906:
1.380 foxr 3907: my $ansrendered = &Apache::loncommon::get_student_answers($curresline,$username,$userdomain,$env{'request.course.id'},%answerenv);
1.428 albertel 3908:
1.305 sakharuk 3909: if ($helper->{'VARS'}->{'ANSWER_TYPE'} eq 'no') {
1.649 raeburn 3910: $rendered=~s/(\\keephidden\{ENDOFPROBLEM})/$ansrendered$1/;
1.305 sakharuk 3911: } else {
1.423 foxr 3912: my $header =&print_latex_header($helper->{'VARS'}->{'LATEX_TYPE'});
1.582 raeburn 3913: unless ($helper->{'VARS'}->{'ANSWER_TYPE'} eq 'only') {
1.649 raeburn 3914: $header =~ s/\\begin\{document}//; #<<<<<
1.582 raeburn 3915: }
1.477 albertel 3916: my $title = &Apache::lonnet::gettitle($curresline);
3917: $title = &Apache::lonxml::latex_special_symbols($title);
3918: my $body ='\vskip 0 mm \noindent\textbf{'.$title.'}\vskip 0 mm ';
3919: $body .=&path_to_problem($res_url,$LaTeXwidth);
1.423 foxr 3920: $body .='\vskip 1 mm '.$ansrendered;
1.676 raeburn 3921: $body = &encapsulate_minipage($body,$answerenv{'problem_split'});
1.423 foxr 3922: $rendered = $header.$body;
1.305 sakharuk 3923: }
3924: }
1.511 foxr 3925: if ($helper->{'VARS'}->{'PRINT_ANNOTATIONS'} eq 'yes') {
3926: my $url = &Apache::lonnet::clutter($res_url);
3927: my $annotation = &annotate($url);
1.649 raeburn 3928: $rendered =~ s/(\\keephidden\{ENDOFPROBLEM})/$annotation$1/;
1.511 foxr 3929: }
1.562 foxr 3930: my $junk;
1.305 sakharuk 3931: if ($remove_latex_header eq 'YES') {
3932: $rendered = &latex_header_footer_remove($rendered);
3933: } else {
1.649 raeburn 3934: $rendered =~ s/\\end\{document}//;
1.305 sakharuk 3935: }
1.699 raeburn 3936: $current_output .= $rendered;
1.660 raeburn 3937: } elsif ($res_url=~/\/(smppg|syllabus|aboutme|bulletinboard|ext\.tool)$/) {
1.568 foxr 3938: if ($i == 1) {
3939: $syllabus_first = 1;
3940: }
1.375 foxr 3941: $printed .= $curresline.':';
1.528 raeburn 3942: my $rendered = &get_student_view_with_retries($curresline,$ssi_retry_count,$username,$userdomain,$env{'request.course.id'},'tex',$moreenv);
1.511 foxr 3943: if ($helper->{'VARS'}->{'PRINT_ANNOTATIONS'} eq 'yes') {
3944: my $url = &Apache::lonnet::clutter($res_url);
3945: my $annotation = &annotate($url);
1.649 raeburn 3946: $annotation =~ s/(\\end\{document})/$annotation$1/;
1.511 foxr 3947: }
1.305 sakharuk 3948: if ($remove_latex_header eq 'YES') {
3949: $rendered = &latex_header_footer_remove($rendered);
1.284 albertel 3950: } else {
1.649 raeburn 3951: $rendered =~ s/\\end\{document}//;
1.284 albertel 3952: }
1.421 foxr 3953: $current_output .= $rendered.'\vskip 0.5mm\noindent\makebox[\textwidth/$number_of_columns][b]{\hrulefill}\strut \vskip 0 mm \strut ';
1.690 raeburn 3954: } elsif($res_url =~ /\.pdf$/) {
1.552 foxr 3955: my $url = &Apache::lonnet::clutter($res_url);
3956: my $rendered = &include_pdf($url);
3957: if ($remove_latex_header ne 'NO') {
3958: $rendered = &latex_header_footer_remove($rendered);
3959: }
3960: $current_output .= $rendered;
1.284 albertel 3961: } else {
1.414 albertel 3962: my $rendered = &unsupported($res_url,$helper->{'VARS'}->{'LATEX_TYPE'},$curresline);
1.305 sakharuk 3963: if ($remove_latex_header ne 'NO') {
3964: $rendered = &latex_header_footer_remove($rendered);
3965: } else {
1.649 raeburn 3966: $rendered =~ s/\\end\{document}//;
1.305 sakharuk 3967: }
3968: $current_output .= $rendered;
1.284 albertel 3969: }
3970: }
3971: $remove_latex_header = 'YES';
1.590 foxr 3972: }
1.619 foxr 3973: $assignment = &Apache::lonxml::latex_special_symbols(
3974: &Apache::lonnet::gettitle($map), 'header');
3975: if (($assignment ne $current_assignment) && ($assignment ne "")) {
3976: my $header_line = &format_page_header($LaTeXwidth, $parmhash{'print_header_format'},
1.699 raeburn 3977: $assignment, $courseidinfo,
1.619 foxr 3978: $fullname, $usersection);
3979: my $header_start = ($columns_in_format == 1) ? '\lhead'
3980: : '\fancyhead[LO]';
3981: $header_line = $header_start.'{'.$header_line.'}';
3982: $current_output = $current_output . $header_line;
3983: $current_assignment = $assignment;
3984: }
3985:
1.331 albertel 3986: if (&Apache::loncommon::connection_aborted($r)) { last; }
1.284 albertel 3987: }
1.591 foxr 3988: # If we are printing incomplete it's possible we don't have
3989: # anything to print. The print subsystem is not so good at handling
3990: # that so we're going to generate a stub that says there are no
3991: # incomplete resources for the person.
3992: #
1.593 foxr 3993:
1.591 foxr 3994: if ($actually_printed == 0) {
1.643 raeburn 3995: my $message = &mt('No resources to print');
3996: if (!$possprint) {
3997: if ($perm{'pav'} || $perm{'pfo'}) {
3998: $message = &mt('There are no unhidden resources to print.')."\n\n".
3999: &mt('The most likely reason is one of the following: ')."\n".
4000: '\begin{itemize}'."\n".
4001: '\item '.&mt("The 'Resource hidden from students' parameter is set for the folder being printed.")."\n".
4002: '\item '.&mt("'Hidden' is checked in the Course Editor individually for each resource in the folder being printed.")."\n".
4003: '\end{itemize}'."\n\n".
4004: &mt("Note: to print a bubblesheet exam which you want to hide from students, ".
4005: "use the Course Editor to check the 'Hidden' checkbox for the exam folder itself.")."\n";
4006: }
4007: } elsif ($print_incomplete) {
4008: $message = &mt('No incomplete resources');
4009: }
1.699 raeburn 4010: if ($message) {
1.676 raeburn 4011: $current_output = &encapsulate_minipage("\\vskip -10mm \n$message\n \\vskip 100 mm { }\n",$moreenv->{'problem_split'});
1.643 raeburn 4012: }
1.593 foxr 4013: if ($remove_latex_header eq "NO") {
4014: $current_output = &print_latex_header() . $current_output;
4015: } else {
4016: $current_output = &latex_header_footer_remove($current_output);
4017: }
1.591 foxr 4018: }
1.552 foxr 4019:
1.583 raeburn 4020: if ($syllabus_first) {
4021: $current_output =~ s/\\\\ Last updated:/Last updated:/
4022: }
1.642 raeburn 4023: my $currentassignment=&Apache::lonxml::latex_special_symbols($helper->{VARS}->{'assignment'},'header');
4024: my $header_line =
4025: &format_page_header($LaTeXwidth, $parmhash{'print_header_format'},
4026: $currentassignment, $courseidinfo, $fullname, $usersection);
4027: my $header_start = ($columns_in_format == 1) ? '\lhead' : '\fancyhead[LO]';
4028: my $newheader = $header_start.'{'.$header_line.'}';
1.583 raeburn 4029: if ($current_output=~/\\documentclass/) {
1.649 raeburn 4030: $current_output =~ s/\\begin\{document}/\\setlength{\\topmargin}{1cm} \\begin{document}\\noindent\\parbox{\\minipagewidth}{\\noindent$newheader$namepostfix}\\vskip 5 mm /;
1.619 foxr 4031:
1.284 albertel 4032: } else {
1.699 raeburn 4033: my $blankpages =
1.476 albertel 4034: '\clearpage\strut\clearpage'x$helper->{'VARS'}->{'EMPTY_PAGES'};
1.619 foxr 4035:
1.476 albertel 4036: $current_output = '\strut\vspace*{-6 mm}\\newline'.
4037: ©right_line().' \newpage '.$blankpages.$end_of_student.
1.639 raeburn 4038: '\setcounter{page}{1}\noindent\parbox{\minipagewidth}{\noindent'.
4039: $newheader.$namepostfix. '} \vskip 5 mm '.$current_output;
1.619 foxr 4040:
1.284 albertel 4041: }
1.440 foxr 4042: #
4043: # Close the student bracketing.
4044: #
1.375 foxr 4045: return ($current_output,$fullname, $printed);
1.284 albertel 4046:
4047: }
1.140 sakharuk 4048:
1.614 raeburn 4049: sub printing_blocked {
4050: my ($r,$blocktext) = @_;
4051: my $title = &mt('Preparing Printout');
4052: &Apache::lonhtmlcommon::clear_breadcrumbs();
4053: &Apache::lonhtmlcommon::add_breadcrumb({href=>'/adm/printout',
4054: text=> $title});
4055: my $breadcrumbs = &Apache::lonhtmlcommon::breadcrumbs($title);
4056: &Apache::loncommon::content_type($r,'text/html');
4057: &Apache::loncommon::no_cache($r);
4058: $r->send_http_header;
4059: $r->print(&Apache::loncommon::start_page('Preparing Printout').
4060: $breadcrumbs.
4061: $blocktext.
4062: &Apache::loncommon::end_page());
4063: return;
4064: }
4065:
1.3 sakharuk 4066: sub handler {
4067:
4068: my $r = shift;
1.614 raeburn 4069:
4070: if ($env{'request.course.id'}) {
4071: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
4072: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
1.674 raeburn 4073: my $clientip = &Apache::lonnet::get_requestor_ip($r);
1.699 raeburn 4074: my ($blocked,$blocktext) =
1.674 raeburn 4075: &Apache::loncommon::blocking_status('printout',$clientip,$cnum,$cdom);
1.614 raeburn 4076: if ($blocked) {
4077: my $checkrole = "cm./$cdom/$cnum";
4078: if ($env{'request.course.sec'} ne '') {
4079: $checkrole .= "/$env{'request.course.sec'}";
4080: }
1.699 raeburn 4081: unless ((&Apache::lonnet::allowed('evb',undef,undef,$checkrole)) &&
1.614 raeburn 4082: ($env{'request.role'} !~ m{^st\./$cdom/$cnum})) {
4083: &printing_blocked($r,$blocktext);
4084: return OK;
4085: }
4086: }
4087: }
1.699 raeburn 4088:
1.397 albertel 4089: &init_perm();
4090: my $helper = printHelper($r);
4091: if (!ref($helper)) {
4092: return $helper;
1.60 sakharuk 4093: }
1.699 raeburn 4094:
1.184 sakharuk 4095:
1.454 foxr 4096: %parmhash=&Apache::lonnet::coursedescription($env{'request.course.id'});
1.350 foxr 4097:
1.367 foxr 4098: # If a figure conversion queue file exists for this user.domain
4099: # we delete it since it can only be bad (if it were good, printout.pl
4100: # would have deleted it the last time around.
4101:
1.373 albertel 4102: my $conversion_queuefile = "/home/httpd/prtspool/$env{'user.name'}_$env{'user.domain'}_printout.dat";
1.367 foxr 4103: if(-e $conversion_queuefile) {
4104: unlink $conversion_queuefile;
4105: }
1.515 foxr 4106:
1.184 sakharuk 4107: &output_data($r,$helper,\%parmhash);
1.2 sakharuk 4108: return OK;
1.614 raeburn 4109: }
1.2 sakharuk 4110:
1.131 bowersj2 4111: use Apache::lonhelper;
1.130 sakharuk 4112:
1.223 bowersj2 4113: sub addMessage {
4114: my $text = shift;
4115: my $paramHash = Apache::lonhelper::getParamHash();
4116: $paramHash->{MESSAGE_TEXT} = $text;
4117: Apache::lonhelper::message->new();
4118: }
4119:
1.416 foxr 4120:
1.238 bowersj2 4121:
1.397 albertel 4122: sub init_perm {
4123: undef(%perm);
4124: $perm{'pav'}=&Apache::lonnet::allowed('pav',$env{'request.course.id'});
4125: if (!$perm{'pav'}) {
4126: $perm{'pav'}=&Apache::lonnet::allowed('pav',
4127: $env{'request.course.id'}.'/'.$env{'request.course.sec'});
4128: }
1.465 albertel 4129: $perm{'pfo'}=&Apache::lonnet::allowed('pfo',$env{'request.course.id'});
1.397 albertel 4130: if (!$perm{'pfo'}) {
4131: $perm{'pfo'}=&Apache::lonnet::allowed('pfo',
4132: $env{'request.course.id'}.'/'.$env{'request.course.sec'});
4133: }
1.585 raeburn 4134: $perm{'vgr'}=&Apache::lonnet::allowed('vgr',$env{'request.course.id'});
4135: if (!$perm{'vgr'}) {
4136: $perm{'vgr'}=&Apache::lonnet::allowed('vgr',
4137: $env{'request.course.id'}.'/'.$env{'request.course.sec'});
4138: }
1.397 albertel 4139: }
4140:
1.507 albertel 4141: sub get_randomly_ordered_warning {
4142: my ($helper,$map) = @_;
4143:
4144: my $message;
4145:
4146: my $postdata = $env{'form.postdata'} || $helper->{VARS}{'postdata'};
4147: my $navmap = Apache::lonnavmaps::navmap->new();
1.547 raeburn 4148: if (defined($navmap)) {
4149: my $res = $navmap->getResourceByUrl($map);
4150: if ($res) {
1.699 raeburn 4151: my $func =
1.547 raeburn 4152: sub { return ($_[0]->is_map() && $_[0]->randomorder); };
4153: my @matches = $navmap->retrieveResources($res, $func,1,1,1);
1.610 foxr 4154:
1.547 raeburn 4155: }
4156: } else {
1.699 raeburn 4157: $message = "Retrieval of information about ordering of resources failed.";
1.547 raeburn 4158: return '<message type="warning">'.$message.'</message>';
1.507 albertel 4159: }
4160: return;
4161: }
4162:
1.131 bowersj2 4163: sub printHelper {
1.115 bowersj2 4164: my $r = shift;
4165:
4166: if ($r->header_only) {
1.373 albertel 4167: if ($env{'browser.mathml'}) {
1.241 www 4168: &Apache::loncommon::content_type($r,'text/xml');
1.131 bowersj2 4169: } else {
1.241 www 4170: &Apache::loncommon::content_type($r,'text/html');
1.131 bowersj2 4171: }
4172: $r->send_http_header;
4173: return OK;
1.115 bowersj2 4174: }
4175:
1.131 bowersj2 4176: # Send header, nocache
1.373 albertel 4177: if ($env{'browser.mathml'}) {
1.241 www 4178: &Apache::loncommon::content_type($r,'text/xml');
1.115 bowersj2 4179: } else {
1.241 www 4180: &Apache::loncommon::content_type($r,'text/html');
1.115 bowersj2 4181: }
4182: &Apache::loncommon::no_cache($r);
4183: $r->send_http_header;
4184: $r->rflush();
4185:
1.131 bowersj2 4186: # Unfortunately, this helper is so complicated we have to
4187: # write it by hand
4188:
4189: Apache::loncommon::get_unprocessed_cgi($ENV{QUERY_STRING});
1.699 raeburn 4190:
1.176 bowersj2 4191: my $helper = Apache::lonhelper::helper->new("Printing Helper");
1.146 bowersj2 4192: $helper->declareVar('symb');
1.699 raeburn 4193: $helper->declareVar('postdata');
4194: $helper->declareVar('curseed');
4195: $helper->declareVar('probstatus');
1.156 bowersj2 4196: $helper->declareVar('filename');
4197: $helper->declareVar('construction');
1.178 sakharuk 4198: $helper->declareVar('assignment');
1.262 sakharuk 4199: $helper->declareVar('style_file');
1.340 foxr 4200: $helper->declareVar('student_sort');
1.363 foxr 4201: $helper->declareVar('FINISHPAGE');
1.366 foxr 4202: $helper->declareVar('PRINT_TYPE');
1.372 foxr 4203: $helper->declareVar("showallfoils");
1.483 foxr 4204: $helper->declareVar("STUDENTS");
1.569 foxr 4205: $helper->declareVar("EXTRASPACE");
1.518 foxr 4206:
1.699 raeburn 4207:
1.518 foxr 4208:
4209:
1.569 foxr 4210: # The page breaks and extra spaces
4211: # can get loaded initially from the course environment:
1.394 foxr 4212: # But we only do this in the initial state so that they are allowed to change.
4213: #
1.366 foxr 4214:
1.699 raeburn 4215:
1.363 foxr 4216: &Apache::loncommon::restore_course_settings('print',
1.366 foxr 4217: {'pagebreaks' => 'scalar',
1.569 foxr 4218: 'extraspace' => 'scalar',
1.570 foxr 4219: 'extraspace_units' => 'scalar',
1.366 foxr 4220: 'lastprinttype' => 'scalar'});
1.699 raeburn 4221:
1.483 foxr 4222: # This will persistently load in the data we want from the
4223: # very first screen.
1.699 raeburn 4224:
1.394 foxr 4225: if($helper->{VARS}->{PRINT_TYPE} eq $env{'form.lastprinttype'}) {
4226: if (!defined ($env{"form.CURRENT_STATE"})) {
1.699 raeburn 4227:
1.394 foxr 4228: $helper->{VARS}->{FINISHPAGE} = $env{'form.pagebreaks'};
1.569 foxr 4229: $helper->{VARS}->{EXTRASPACE} = $env{'form.extraspace'};
1.570 foxr 4230: $helper->{VARS}->{EXTRASPACE_UNITS} = $env{'form.extraspace_units'};
1.394 foxr 4231: } else {
4232: my $state = $env{"form.CURRENT_STATE"};
4233: if ($state eq "START") {
4234: $helper->{VARS}->{FINISHPAGE} = $env{'form.pagebreaks'};
1.569 foxr 4235: $helper->{VARS}->{EXTRASPACE} = $env{'form.extraspace'};
1.570 foxr 4236: $helper->{VARS}->{EXTRASPACE_UNITS} = $env{'form.extraspace_units'};
4237:
1.394 foxr 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>