[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 6058 - (view) (download) (as text)

1 : sh002i 5556 ################################################################################
2 :     # WeBWorK Online Homework Delivery System
3 :     # Copyright 2000-2007 The WeBWorK Project, http://openwebwork.sf.net/
4 : gage 6058 # $CVSHeader$
5 : sh002i 5556 #
6 :     # This program is free software; you can redistribute it and/or modify it under
7 :     # the terms of either: (a) the GNU General Public License as published by the
8 :     # Free Software Foundation; either version 2, or (at your option) any later
9 :     # version, or (b) the "Artistic License" which comes with this package.
10 :     #
11 :     # This program is distributed in the hope that it will be useful, but WITHOUT
12 :     # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
13 :     # FOR A PARTICULAR PURPOSE. See either the GNU General Public License or the
14 :     # Artistic License for more details.
15 :     ################################################################################
16 :    
17 : sh002i 5553 =head1 NAME
18 : dpvc 5342
19 : sh002i 5553 problemPreserveAnswers.pl - Allow sticky answers to preserve special characters.
20 : dpvc 5342
21 : sh002i 5553 =head1 DESCRIPTION
22 : dpvc 5373
23 : sh002i 5553 This file implements a fragile hack to overcome a problem with
24 :     PGbasicmacros.pl, which removes special characters from student
25 :     answers (in order to prevent EV3 from mishandling them).
26 : dpvc 5342
27 : sh002i 5553 Unfortunately, this means that "sticky" answers will lose
28 :     those characters, which makes it very difficult to answer
29 :     problems with more than one answer when the student wants
30 :     to submit several times while working on later parts.
31 :    
32 :     The real fix to to rewrite PGbasicmacros.pl to handle
33 :     this better, but this hack will handle the situation for
34 :     now until that can be accomplished.
35 :    
36 :     To use this hack, simply load the file using
37 :    
38 :     loadMacros("problemPreserveAnswers.pl");
39 :    
40 :     at the top of your PG file.
41 :    
42 : dpvc 5342 =cut
43 :    
44 : sh002i 5553 sub _problemPreserveAnswers_init {PreserveAnswers::Init()}
45 :    
46 : dpvc 5342 package PreserveAnswers;
47 :    
48 :     #
49 :     # Escape the specials in answers, and then
50 :     # override ENDDOCUMENT() to restore the answers
51 :     # to their original values.
52 :     #
53 :     sub Init {
54 :     PreserveAnswers::EscapeAnswers();
55 :     $PreserveAnswers::ENDDOCUMENT = \&main::ENDDOCUMENT;
56 :     main::PG_restricted_eval
57 :     ('sub ENDDOCUMENT {PreserveAnswers::RestoreAnswers(); &$PreserveAnswers::ENDDOCUMENT(@_)}');
58 :     }
59 :    
60 :     #
61 :     # This is a fragile hack to prevent PG from removing the
62 :     # dollar signs in currency answers (and everything else as well).
63 :     # PGbasicmacros.pl needs to be fixed to allow this without
64 :     # having to do this terrible hack.
65 :     #
66 :     sub EscapeAnswers {
67 :     my $original = $main::inputs_ref_orig = {%{$main::inputs_ref}};
68 :     my $inputs = $main::inputs_ref;
69 :     foreach my $id (keys %{$original}) {
70 :     my $value = $original->{$id};
71 :     next if !defined($value) || ref($value);
72 : dpvc 5388 $value =~ s/([\\\$@\`"&<>])/EscapeHTMLchar($1)/ge;
73 : dpvc 5342 $inputs->{$id} = $value;
74 :     }
75 :     }
76 :    
77 :     sub EscapeHTMLchar {main::spf(ord(shift),"&#x%02X;")}
78 :    
79 :     sub RestoreAnswers {
80 :     my $original = $main::inputs_ref_orig;
81 :     my $inputs = $main::inputs_ref;
82 :     foreach my $id (keys %{$original}) {$inputs->{$id} = $original->{$id}}
83 :     }
84 :    
85 : dpvc 5373 our $ENDDOCUMENT; # holds pointer to original ENDDOCUMENT
86 : dpvc 5342
87 :     ######################################################################
88 :    
89 :     1;

aubreyja at gmail dot com
ViewVC Help
Powered by ViewVC 1.0.9