version 1.1, 2000/01/21 20:01:28
|
version 1.2, 2000/02/22 21:32:17
|
Line 1
|
Line 1
|
# The LearningOnline Network with CAPA |
# The LearningOnline Network with CAPA |
# Problem Handler |
# Problem Handler |
# |
# |
# 12/15-01/21 Gerd Kortemeyer |
# 12/15-01/21,01/24 Gerd Kortemeyer |
|
|
package Apache::lonproblem; |
package Apache::lonproblem; |
|
|
Line 37 print "\n---------------\n$outstring\n";
|
Line 37 print "\n---------------\n$outstring\n";
|
return 1; #change to ok |
return 1; #change to ok |
} |
} |
|
|
|
# ============================================================================= |
# ============================================================= Parsing Routine |
# ============================================================= Parsing Routine |
# Takes $parsestring and $target |
# Takes $parsestring and $target |
|
# ============================================================================= |
|
|
sub xmlparse { |
sub xmlparse { |
|
|
my ($r,$parsestring,$target) = @_; |
my ($r,$parsestring,$target) = @_; |
|
|
my $safeeval = new Safe; |
my $safeeval = new Safe 'Script'; |
|
|
|
my $parsereval = new Safe 'Parser'; |
|
|
my $parser=HTML::TokeParser->new(\$parsestring); |
my $parser=HTML::TokeParser->new(\$parsestring); |
|
|
Line 54 my $outtext='';
|
Line 58 my $outtext='';
|
|
|
my %toptoplevel = ( 'problem' => 'Problem', |
my %toptoplevel = ( 'problem' => 'Problem', |
'entryform' => 'Entry Form', |
'entryform' => 'Entry Form', |
'survey' => 'Survey' ); |
'survey' => 'Survey', |
|
'graded' => 'Manually Graded' ); |
|
|
my %answertags = ( 'item' => 'Question Item', |
|
'inlinetext' => 'Inline Text' ); |
|
|
|
my %includetags = ( 'codelib' => 'Code Library' ); |
# --------------------------------------------------------------- Toplevel Tags |
|
|
my %topleveltags = ( 'block' => 'Condition Block', |
my %topleveltags = ( 'block' => 'Condition Block', |
'answer' => 'Answer Field', |
'part' => 'Problem Part'; |
'include' => 'Include Section', |
'include' => 'Include Section', |
|
'answer' => 'Answerfield'; |
'script' => 'Script', |
'script' => 'Script', |
'outtext' => 'Text Block' ); |
'outtext' => 'Text Block' ); |
|
|
|
# ---------------------------------------------------------- Preregistered Tags |
|
|
my %xmltags = ( %answertags, %includetags, |
my %includetags = ( 'scriptlib' => 'Script Library', |
%topleveltags, %toptoplevel ); |
'parserlib' => 'Parser Library' ); |
|
|
|
# -------------------------------------------------------------------- All Tags |
|
|
|
my %xmltags = ( %includetags, %topleveltags, %toptoplevel ); |
|
|
my $toplevel = ''; |
my $toplevel = ''; |
my $above = ''; |
my $above = ''; |
|
|
my %answertypes = ( 'true_false' => 'True/False', |
|
'multiple_choice' => 'Multiple Choice', |
|
'numerical' => 'Numerical', |
|
'numerical_units' => 'Numerical with Units' ); |
|
|
|
# --------------------------------------------------- Depth counter for editing |
# --------------------------------------------------- Depth counter for editing |
|
|
my @depthcounter=(); |
my @depthcounter=(); |
Line 90 my @stack=('');
|
Line 95 my @stack=('');
|
|
|
# -------------------------------------------------------------- Init $saveeval |
# -------------------------------------------------------------- Init $saveeval |
|
|
if ($target eq 'web') { |
&init_safeeval($safeeval); |
&init_safeeval($safeeval); |
|
} |
|
|
|
# ---------------------------------------------------------- Parse $parsestring |
# ---------------------------------------------------------- Parse $parsestring |
|
|
my $token; |
my $token; |
|
|
while ($token=$parser->get_token) { |
while ($token=$parser->get_token) { |
|
# ============================================================================= |
if ($token->[0] eq 'S') { |
if ($token->[0] eq 'S') { |
# ------------------------------------------------------------------- Start Tag |
# =================================================================== Start Tag |
|
# --------------------------------------------------------------- Depth Counter |
if (defined($xmltags{$token->[1]})) { |
if (defined($xmltags{$token->[1]})) { |
if ($depth<$olddepth-1) { |
if ($depth<$olddepth-1) { |
$#depthcounter--; |
$#depthcounter--; |
Line 112 while ($token=$parser->get_token) {
|
Line 117 while ($token=$parser->get_token) {
|
$olddepth=$depth; |
$olddepth=$depth; |
} |
} |
} |
} |
|
# ----------------------------------------------------------------------------- |
|
|
|
|
if ($target eq 'web') { |
if ($target eq 'web') { |
my $sub="start_$token->[1]"; |
my $sub="start_$token->[1]"; |
{ |
{ |
Line 123 while ($token=$parser->get_token) {
|
Line 131 while ($token=$parser->get_token) {
|
} |
} |
} |
} |
} |
} |
|
|
if ($target eq 'edit') { |
if ($target eq 'edit') { |
my $depthlabel=join('_',@depthcounter); |
my $depthlabel=join('_',@depthcounter); |
if (defined($xmltags{$token->[1]})) { |
if (defined($xmltags{$token->[1]})) { |
Line 148 while ($token=$parser->get_token) {
|
Line 157 while ($token=$parser->get_token) {
|
$stack[$#stack].=$token->[4]; |
$stack[$#stack].=$token->[4]; |
} |
} |
} |
} |
|
|
if ($target eq 'modified') { |
if ($target eq 'modified') { |
} |
} |
|
|
|
# ============================================================================= |
} elsif ($token->[0] eq 'E') { |
} elsif ($token->[0] eq 'E') { |
# --------------------------------------------------------------------- End Tag |
# ===================================================================== End Tag |
|
|
if ($target eq 'web') { |
if ($target eq 'web') { |
my $sub="end_$token->[1]"; |
my $sub="end_$token->[1]"; |
{ |
{ |
Line 163 while ($token=$parser->get_token) {
|
Line 176 while ($token=$parser->get_token) {
|
} |
} |
} |
} |
} |
} |
|
|
if ($target eq 'edit') { |
if ($target eq 'edit') { |
if (defined($xmltags{$token->[1]})) { |
if (defined($xmltags{$token->[1]})) { |
my $sub="end_edit_$token->[1]"; |
my $sub="end_edit_$token->[1]"; |
Line 174 while ($token=$parser->get_token) {
|
Line 188 while ($token=$parser->get_token) {
|
} |
} |
} |
} |
} |
} |
|
|
if ($target eq 'modified') { |
if ($target eq 'modified') { |
} |
} |
|
# --------------------------------------------------------------- Depth Counter |
if (defined($xmltags{$token->[1]})) { $depth--; } |
if (defined($xmltags{$token->[1]})) { $depth--; } |
|
# ----------------------------------------------------------------------------- |
|
# ============================================================================= |
} elsif ($token->[0] eq 'T') { |
} elsif ($token->[0] eq 'T') { |
# ------------------------------------------------------------------------ Text |
# ================================================================= Parsed Text |
$stack[$#stack].=$token->[1]; |
$stack[$#stack].=$token->[1]; |
} |
} |
} |
} |
Line 187 return $outtext;
|
Line 205 return $outtext;
|
} |
} |
# ============================================================================= |
# ============================================================================= |
|
|
# -------------------------------------------- Initialize routines in $safeeval |
# --------------------------------------------------------------- Execute Token |
|
|
sub init_safeeval { |
|
my $safeeval=shift; |
|
my $initprg=<<'ENDINIT'; |
|
|
|
# -------------------------------------------- Initializations inside $safeeval |
|
|
|
$e=25; |
|
$c=20; |
|
|
|
ENDINIT |
|
# ---------------------------------------------------------------- Execute that |
|
$safeeval->reval($initprg); |
|
} |
|
|
|
# ------------------------------------------------- Helper Routines for Editing |
# ------------------------------------------------- Helper Routines for Editing |
|
|
Line 226 sub insertmenu {
|
Line 232 sub insertmenu {
|
} |
} |
&rawprint($r,"\n".'</select></td></tr></table><br>'."\n"); |
&rawprint($r,"\n".'</select></td></tr></table><br>'."\n"); |
} |
} |
|
|
# ----------------------------------------------- Helper Routines for Renderers |
# ============================================================================= |
|
# ================================================ Routines for Safe Evaluation |
|
# ============================================================================= |
|
|
|
# -------------------------------------------- Initialize routines in $safeeval |
|
|
|
sub init_safeeval { |
|
my $safeeval=shift; |
|
my $initprg=<<'ENDINIT'; |
|
|
|
# -------------------------------------------- Initializations inside $safeeval |
|
|
|
$e=25; |
|
$c=20; |
|
|
|
ENDINIT |
|
# ---------------------------------------------------------------- Execute that |
|
$safeeval->reval($initprg); |
|
} |
|
|
|
# ----------------------------------------------- Routines that use Safe Spaces |
|
|
sub printout { |
sub printout { |
my ($r,$data,$safeeval)=@_; |
my ($r,$data,$safespace)=@_; |
$r->print($safeeval->reval('return qq('.$data.');')); |
$r->print($safespace->reval('return qq('.$data.');')); |
} |
} |
|
|
sub runfile { |
sub runfile { |
my ($r,$filename,$safeeval)=@_; |
my ($r,$filename,$safespace)=@_; |
my $includespath=$r->dir_config('lonIncludes'); |
my $includefile; |
$safeeval->rdo($includespath.'/'.$filename); |
if ($filename=~/^\//) { |
|
$includefile=$filename; |
|
} else { |
|
$includefile=$r->dir_config('lonIncludes'); |
|
$includefile.='/'.$filename; |
|
} |
|
if (-e $includefile) { |
|
$safespace->rdo($includefile); |
|
} |
} |
} |
|
|
sub run { |
sub run { |
my ($expression,$safeeval)=@_; |
my ($expression,$safespace)=@_; |
$safeeval->reval($expression); |
$safespace->reval($expression); |
} |
} |
|
|
sub booleanexpr { |
sub booleanexpr { |
my ($expression,$safeeval)=@_; |
my ($expression,$safespace)=@_; |
return $safeeval->reval('return '.$expression.';'); |
return $safespace->reval('return '.$expression.';'); |
} |
} |
|
|
# -------------------------------------------------- Tag Handlers for Rendering |
|
|
# ============================================================================= |
|
# ================================================== Tag Handlers for Rendering |
|
# ============================================================================= |
|
|
sub start_block { |
sub start_block { |
my ($r,$token,$parser,$safeeval,$stackref)=@_; |
my ($r,$token,$parser,$safeeval,$stackref)=@_; |
Line 301 sub end_inlinetext {
|
Line 338 sub end_inlinetext {
|
&end_outtext(@_); |
&end_outtext(@_); |
} |
} |
|
|
sub start_codelib { |
sub start_scriptlib { |
|
my ($r,$token,$parser,$safeeval,$stackref)=@_; |
|
&runfile($r,$parser->get_text('/scriptlib'),$safeeval); |
|
} |
|
|
|
sub start_parserlib { |
my ($r,$token,$parser,$safeeval,$stackref)=@_; |
my ($r,$token,$parser,$safeeval,$stackref)=@_; |
&runfile($r,$parser->get_text('/codelib'),$safeeval); |
&runfile($r,$parser->get_text('/parserlib'),$parsereval); |
} |
} |
|
|
|
|
sub start_answer { |
sub start_answer { |
my ($r,$token,$parser,$safeeval,$stackref)=@_; |
my ($r,$token,$parser,$safeeval,$stackref)=@_; |
$stackref->[$#$stackref+1]='<answer>::'. |
$stackref->[$#$stackref+1]='<answer>::'. |
Line 333 sub start_item {
|
Line 376 sub start_item {
|
|
|
sub end_item {} |
sub end_item {} |
|
|
# ------------------------------------------------------------ Edit Tag Handler |
# ============================================================================= |
|
# ==================================================== Tag Handlers for Editing |
|
# ============================================================================= |
|
|
sub start_edit_outtext { |
sub start_edit_outtext { |
my ($r,$token,$parser,$description,$depthlabel,$above,$answertyperef, |
my ($r,$token,$parser,$description,$depthlabel,$above,$answertyperef, |