[system] / trunk / pg / macros / problemPreserveAnswers.pl Repository:
ViewVC logotype

Annotation of /trunk/pg/macros/problemPreserveAnswers.pl

Parent Directory Parent Directory | Revision Log Revision Log


Revision 5342 - (view) (download) (as text)

1 : dpvc 5342
2 :     =pod
3 :    
4 :     ######################################################################
5 :     #
6 :     # This file implements a fragile hack to overcome a problem with
7 :     # PGbasicmacros.pl, which removes special characters from student
8 :     # answers (in order to prevent EV3 from mishandling them).
9 :     #
10 :     # Unfortunately, this means that "sticky" answers will lose
11 :     # those characters, which makes it very difficult to answer
12 :     # problems with more than one answer when the student wants
13 :     # to submit several times while working on later parts.
14 :     #
15 :     # The real fix to to rewrite PGbasicmacros.pl to handle
16 :     # this better, but this hack will handle the situation for
17 :     # now until that can be accomplished.
18 :     #
19 :     # To use this hack, simply load the file using
20 :     #
21 :     # loadMacros("problemPreserveAnswers.pl");
22 :     #
23 :     # at the top of your PG file.
24 :     #
25 :    
26 :     =cut
27 :    
28 :     sub _problemPreserveAnswers_init {PreserveAnswers::Init()}
29 :    
30 :     package PreserveAnswers;
31 :    
32 :     #
33 :     # Escape the specials in answers, and then
34 :     # override ENDDOCUMENT() to restore the answers
35 :     # to their original values.
36 :     #
37 :     sub Init {
38 :     PreserveAnswers::EscapeAnswers();
39 :     $PreserveAnswers::ENDDOCUMENT = \&main::ENDDOCUMENT;
40 :     main::PG_restricted_eval
41 :     ('sub ENDDOCUMENT {PreserveAnswers::RestoreAnswers(); &$PreserveAnswers::ENDDOCUMENT(@_)}');
42 :     }
43 :    
44 :     #
45 :     # This is a fragile hack to prevent PG from removing the
46 :     # dollar signs in currency answers (and everything else as well).
47 :     # PGbasicmacros.pl needs to be fixed to allow this without
48 :     # having to do this terrible hack.
49 :     #
50 :     sub EscapeAnswers {
51 :     my $original = $main::inputs_ref_orig = {%{$main::inputs_ref}};
52 :     my $inputs = $main::inputs_ref;
53 :     foreach my $id (keys %{$original}) {
54 :     my $value = $original->{$id};
55 :     next if !defined($value) || ref($value);
56 :     $value =~ s/([\\\$@\`])/EscapeHTMLchar($1)/ge;
57 :     $inputs->{$id} = $value;
58 :     }
59 :     }
60 :    
61 :     sub EscapeHTMLchar {main::spf(ord(shift),"&#x%02X;")}
62 :    
63 :     sub RestoreAnswers {
64 :     my $original = $main::inputs_ref_orig;
65 :     my $inputs = $main::inputs_ref;
66 :     foreach my $id (keys %{$original}) {$inputs->{$id} = $original->{$id}}
67 :     }
68 :    
69 :     our $ENDDOCUMENT;
70 :    
71 :     ######################################################################
72 :    
73 :     1;

aubreyja at gmail dot com
ViewVC Help
Powered by ViewVC 1.0.9