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