version 1.37, 2001/08/06 20:05:57
|
version 1.45, 2001/08/20 23:31:07
|
Line 1
|
Line 1
|
# The LON-CAPA response handler |
# The LearningOnline Network with CAPA |
# |
|
# various response type definitons response definition |
# various response type definitons response definition |
# |
|
# YEAR=2000 |
|
# 9/14,9/19,11/21,11/22 Guy Albertelli |
|
# 11/23,11/24,11/28 Gerd Kortemeyer |
# 11/23,11/24,11/28 Gerd Kortemeyer |
# 11/28,11/29,12/4,12/11,12/19,12/28 Guy Albertelli |
# Guy Albertelli |
# YEAR=2001 |
# 08/04,08/07 Gerd Kortemeyer |
# 1/8,1/10,1/19,1/22,2/7,2/19,4/4,4/7,4/16,5/4,5/31,6/2,6/29 Guy Albertelli |
|
# 7/10,7/13,8/3 |
|
# 8/4 Gerd Kortemeyer |
|
# 8/5,8/6 Guy Albertelli |
|
# 8/6 Scott Harrison |
|
|
|
package Apache::response; |
package Apache::response; |
use strict; |
use strict; |
|
|
# ======================================================================= BEGIN |
|
sub BEGIN { |
sub BEGIN { |
&Apache::lonxml::register('Apache::response',('responseparam', |
&Apache::lonxml::register('Apache::response',('responseparam','caparesponse','numericalresponse','stringresponse','radiobuttonresponse','optionresponse','imageresponse','essayresponse','dataresponse')); |
'caparesponse', |
|
'numericalresponse', |
|
'stringresponse', |
|
'radiobuttonresponse', |
|
'optionresponse', |
|
'imageresponse', |
|
'essayresponse')); |
|
} |
} |
|
|
# ======================================= Start response (return scalar string) |
|
sub start_response { |
sub start_response { |
my ($parstack,$safeeval) = @_; |
my ($parstack,$safeeval)=@_; |
my $id = &Apache::lonxml::get_param('id',$parstack,$safeeval); |
my $id= &Apache::lonxml::get_param('id',$parstack,$safeeval); |
if ($id eq '') { $id = $Apache::lonxml::curdepth; } |
if ($id eq '') { $id = $Apache::lonxml::curdepth; } |
push (@Apache::inputtags::response,$id); |
push (@Apache::inputtags::response,$id); |
push (@Apache::inputtags::responselist,$id); |
push (@Apache::inputtags::responselist,$id); |
@Apache::inputtags::inputlist = (); |
@Apache::inputtags::inputlist=(); |
return $id; |
return $id; |
} |
} |
|
|
# ================================================================ End response |
|
sub end_response { |
sub end_response { |
pop @Apache::inputtags::response; |
pop @Apache::inputtags::response; |
@Apache::inputtags::inputlist = (); |
@Apache::inputtags::inputlist=(); |
|
return ''; |
|
} |
|
|
|
sub start_hintresponse { |
|
my ($parstack,$safeeval)=@_; |
|
my $id= &Apache::lonxml::get_param('id',$parstack,$safeeval); |
|
if ($id eq '') { $id = $Apache::lonxml::curdepth; } |
|
push (@Apache::inputtags::response,$id); |
|
return $id; |
|
} |
|
|
|
sub end_hintresponse { |
|
pop @Apache::inputtags::response; |
return ''; |
return ''; |
} |
} |
|
|
# =========================================================== Set random number |
# used by response to set the non-safe space random number generator to something |
# used by response to set the non-safe space random number generator to |
# that is stable and unique based on the part number and response number |
# something that is stable and unique based on the part number and response |
|
# number |
|
sub setrandomnumber { |
sub setrandomnumber { |
my $rndseed = &Apache::lonnet::rndseed(); |
my $rndseed=&Apache::lonnet::rndseed(); |
&Apache::lonxml::debug("randseed $rndseed"); |
&Apache::lonxml::debug("randseed $rndseed"); |
# $rndseed = unpack("%32i",$rndseed); |
# $rndseed=unpack("%32i",$rndseed); |
$rndseed = $rndseed |
$rndseed=$rndseed |
+(&Apache::lonnet::numval($Apache::inputtags::part) << 10); |
+(&Apache::lonnet::numval($Apache::inputtags::part) << 10); |
if (defined($Apache::inputtags::response['-1'])) { |
if (defined($Apache::inputtags::response['-1'])) { |
$rndseed = $rndseed |
$rndseed=$rndseed |
+&Apache::lonnet::numval($Apache::inputtags::response['-1']); |
+&Apache::lonnet::numval($Apache::inputtags::response['-1']); |
} |
} |
srand($rndseed); |
srand($rndseed); |
&Apache::lonxml::debug("randseed $rndseed"); |
&Apache::lonxml::debug("randseed $rndseed"); |
return ''; |
return ''; |
} |
} |
|
|
# ================================= write meta parameter (return scalar string) |
|
sub meta_parameter_write { |
sub meta_parameter_write { |
my ($name,$type,$default,$display) = @_; |
my ($name,$type,$default,$display)=@_; |
return '<parameter part="'.$Apache::inputtags::part. |
my $partref=$Apache::inputtags::part; |
'" name="'.$name. |
my $result='<parameter part="'.$Apache::inputtags::part.'"'; |
'" type="'.$type. |
if (defined($Apache::inputtags::response[-1])) { |
'" default="'.$default. |
$result.= ' id="'.$Apache::inputtags::response[-1].'"'; |
'" display="'.$display. |
$partref.='_'.$Apache::inputtags::response[-1]; |
' [Part: '.$Apache::inputtags::part.']"></parameter>'. |
} |
"\n"; |
$result.= ' name="'.$name.'"'. |
|
' type="'.$type.'"'. |
|
($default?' default="'.$default.'"':''). |
|
($display?' display="'.$display.' [Part: '.$partref.']"':'') |
|
.'></parameter>' |
|
."\n"; |
|
return $result; |
} |
} |
|
|
# =================================== write meta package (return scalar string) |
|
sub meta_package_write { |
sub meta_package_write { |
my $name=shift; |
my $name=shift; |
return '<parameter part="'.$Apache::inputtags::part. |
my $result = '<parameter part="'.$Apache::inputtags::part.'"'; |
'" package="'.$name.'"></parameter>'. |
if(defined($Apache::inputtags::response[-1])) { |
"\n"; |
$result.= ' id="'.$Apache::inputtags::response[-1].'"'; |
|
} |
|
$result.=' package="'.$name.'"></parameter>'."\n"; |
|
return $result; |
} |
} |
|
|
# ==================================== write meta stores (return scalar string) |
|
sub meta_stores_write { |
sub meta_stores_write { |
my ($name,$type,$display)=@_; |
my ($name,$type,$display)=@_; |
return '<stores part="'.$Apache::inputtags::part. |
my $partref=$Apache::inputtags::part; |
'" name="'.$name. |
my $result = '<stores part="'.$Apache::inputtags::part.'"'; |
'" type="'.$type. |
if (defined($Apache::inputtags::response[-1])) { |
'" display="'.$display. |
$result.= ' id="'.$Apache::inputtags::response[-1].'"'; |
' [Part: '.$Apache::inputtags::part.']"></stores>'. |
$partref.='_'.$Apache::inputtags::response[-1]; |
"\n"; |
} |
|
$result.= ' name="'.$name.'"'. |
|
' type="'.$type.'"'. |
|
' display="'.$display.' [Part: '.$partref.']"'. |
|
"></stores>\n"; |
} |
} |
|
|
# ============================ write meta mandatory part (return scalar string) |
|
sub mandatory_part_meta { |
sub mandatory_part_meta { |
# |
# |
# Autogenerate metadata for mandatory |
# Autogenerate metadata for mandatory |
Line 104 sub mandatory_part_meta {
|
Line 106 sub mandatory_part_meta {
|
# output (to lonspreadsheet) |
# output (to lonspreadsheet) |
# of each part |
# of each part |
# |
# |
return |
return |
# &meta_parameter_write('opendate','date_start','', |
# &meta_parameter_write('opendate','date_start','', |
# 'Opening Date'). |
# 'Opening Date'). |
# &meta_parameter_write('duedate','date_end','', |
# &meta_parameter_write('duedate','date_end','', |
Line 115 sub mandatory_part_meta {
|
Line 117 sub mandatory_part_meta {
|
# 'Available Points'). |
# 'Available Points'). |
# &meta_parameter_write('maxtries','int_pos','', |
# &meta_parameter_write('maxtries','int_pos','', |
# 'Maximum Number of Tries'). |
# 'Maximum Number of Tries'). |
&meta_package_write('part'); |
&meta_package_write('part'). |
&meta_stores_write('solved','string', |
&meta_stores_write('solved','string', |
'Problem Status'). |
'Problem Status'). |
&meta_stores_write('tries','int_zeropos', |
&meta_stores_write('tries','int_zeropos', |
'Number of Attempts'). |
'Number of Attempts'). |
&meta_stores_write('awarded','float', |
&meta_stores_write('awarded','float', |
'Partial Credit Factor'); |
'Partial Credit Factor'); |
# |
# |
# Note: responseid-specific data 'submission' and 'awarddetail' |
# Note: responseid-specific data 'submission' and 'awarddetail' |
Line 129 sub mandatory_part_meta {
|
Line 131 sub mandatory_part_meta {
|
} |
} |
|
|
sub check_for_previous { |
sub check_for_previous { |
my ($curresponse,$partid,$id) = @_; |
my ($curresponse,$partid,$id) = @_; |
my %previous; |
my %previous; |
$previous{'used'} = 0; |
$previous{'used'} = 0; |
foreach my $key (reverse(sort(keys(%Apache::lonhomework::history)))) { |
foreach my $key (reverse(sort(keys(%Apache::lonhomework::history)))) { |
if ($key =~ /resource\.$partid\.$id\.submission/) { |
if ($key =~ /resource\.$partid\.$id\.submission/) { |
&Apache::lonxml::debug("Trying $key"); |
&Apache::lonxml::debug("Trying $key"); |
my $pastresponse=$Apache::lonhomework::history{$key}; |
my $pastresponse=$Apache::lonhomework::history{$key}; |
if ($pastresponse eq $curresponse) { |
if ($pastresponse eq $curresponse) { |
$previous{'used'} = 1; |
$previous{'used'} = 1; |
my $history; |
my $history; |
if ( $key =~ /^(\d+):/ ) { |
if ( $key =~ /^(\d+):/ ) { |
$history=$1; |
$history=$1; |
$previous{'award'} = $Apache::lonhomework::history{ |
$previous{'award'} = $Apache::lonhomework::history{"$history:resource.$partid.$id.awarddetail"}; |
"$history:resource.$partid.$id.awarddetail"}; |
$previous{'last'}='0'; |
$previous{'last'} = '0'; |
} else { |
} else { |
$previous{'award'} = $Apache::lonhomework::history{"resource.$partid.$id.awarddetail"}; |
$previous{'award'} = $Apache::lonhomework::history{ |
$previous{'last'}='1'; |
"resource.$partid.$id.awarddetail"}; |
|
$previous{'last'} = '1'; |
|
} |
|
if (! $previous{'award'} ) { $previous{'award'} = 'UNKNOWN';} |
|
&Apache::lonxml::debug( |
|
"got a match :$previous{'award'}:$previous{'used'}:"); |
|
last; |
|
} |
|
} |
} |
|
if (! $previous{'award'} ) { $previous{'award'} = 'UNKNOWN'; } |
|
&Apache::lonxml::debug("got a match :$previous{'award'}:$previous{'used'}:"); |
|
last; |
|
} |
} |
} |
return %previous; |
} |
|
return %previous; |
} |
} |
|
|
# ================================== Start capa response (return scalar string) |
|
sub start_caparesponse { |
sub start_caparesponse { |
require Apache::caparesponse; |
require Apache::caparesponse; |
import Apache::caparesponse; |
import Apache::caparesponse; |
my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style) = @_; |
my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_; |
# print "\n<br />\nsimple caparesponse\n"; |
# print "\n<br />\nsimple caparesponse\n"; |
return &Apache::caparesponse::start_caparesponse($target,$token,$tagstack, |
return &Apache::caparesponse::start_caparesponse($target,$token,$tagstack,$parstack,$parser,$safeeval,$style); |
$parstack,$parser, |
|
$safeeval,$style); |
|
} |
} |
|
|
# ================================ Start string response (return scalar string) |
|
sub start_stringresponse { |
sub start_stringresponse { |
require Apache::caparesponse; |
require Apache::caparesponse; |
import Apache::caparesponse; |
import Apache::caparesponse; |
my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style) = @_; |
my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_; |
return &Apache::caparesponse::start_stringresponse($target,$token, |
return &Apache::caparesponse::start_stringresponse($target,$token,$tagstack,$parstack,$parser,$safeeval,$style); |
$tagstack,$parstack, |
|
$parser,$safeeval, |
|
$style); |
|
} |
} |
|
|
# ============================= Start numerical response (return scalar string) |
|
sub start_numericalresponse { |
sub start_numericalresponse { |
require Apache::caparesponse; |
require Apache::caparesponse; |
import Apache::caparesponse; |
import Apache::caparesponse; |
my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style) = @_; |
my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_; |
return &Apache::caparesponse::start_numericalresponse |
return &Apache::caparesponse::start_numericalresponse |
($target,$token,$tagstack,$parstack,$parser,$safeeval,$style); |
($target,$token,$tagstack,$parstack,$parser,$safeeval,$style); |
} |
} |
|
|
# ========================== Start radio button response (return scalar string) |
|
sub start_radiobuttonresponse { |
sub start_radiobuttonresponse { |
require Apache::radiobuttonresponse; |
require Apache::radiobuttonresponse; |
import Apache::radiobuttonresponse; |
import Apache::radiobuttonresponse; |
my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style) = @_; |
my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_; |
return &Apache::radiobuttonresponse::start_radiobuttonresponse( |
return &Apache::radiobuttonresponse::start_radiobuttonresponse($target,$token,$tagstack,$parstack,$parser,$safeeval,$style); |
$target,$token,$tagstack,$parstack,$parser,$safeeval,$style); |
|
} |
} |
|
|
# ================================ Start option response (return scalar string) |
|
sub start_optionresponse { |
sub start_optionresponse { |
require Apache::optionresponse; |
require Apache::optionresponse; |
import Apache::optionresponse; |
import Apache::optionresponse; |
my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style) = @_; |
my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_; |
return &Apache::optionresponse::start_optionresponse( |
return &Apache::optionresponse::start_optionresponse($target,$token,$tagstack,$parstack,$parser,$safeeval,$style); |
$target,$token,$tagstack,$parstack,$parser,$safeeval,$style); |
|
} |
} |
|
|
# ================================= Start image response (return scalar string) |
|
sub start_imageresponse { |
sub start_imageresponse { |
require Apache::imageresponse; |
require Apache::imageresponse; |
import Apache::imageresponse; |
import Apache::imageresponse; |
my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style) = @_; |
my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_; |
return &Apache::imageresponse::start_imageresponse( |
return &Apache::imageresponse::start_imageresponse($target,$token,$tagstack,$parstack,$parser,$safeeval,$style); |
$target,$token,$tagstack,$parstack,$parser,$safeeval,$style); |
|
} |
} |
|
|
# ================================= Start essay response (return scalar string) |
|
sub start_essayresponse { |
sub start_essayresponse { |
require Apache::essayresponse; |
require Apache::essayresponse; |
import Apache::essayresponse; |
import Apache::essayresponse; |
my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style) = @_; |
my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_; |
return &Apache::essayresponse::start_essayresponse( |
return &Apache::essayresponse::start_essayresponse($target,$token,$tagstack,$parstack,$parser,$safeeval,$style); |
$target,$token,$tagstack,$parstack,$parser,$safeeval,$style); |
} |
|
|
|
sub view_or_modify { |
|
my ($symb,$courseid,$domain,$name) = &Apache::lonhomework::which_user(); |
|
my $myself=0; |
|
if ( ($user eq $ENV{'user.name'}) && ($domain eq $ENV{'user.domain'}) ) { |
|
$myself=1; |
|
} |
|
my $vgr=&Apache::lonnet::allowed('vgr',$courseid); |
|
my $mgr=&Apache::lonnet::allowed('vgr',$courseid); |
|
if ($mgr) { return "M"; } |
|
if ($vgr) { return "V"; } |
|
if ($myself) { return "V"; } |
|
return ''; |
} |
} |
|
|
# ================================= Start param response (return scalar string) |
sub start_dataresponse { |
sub start_responseparam { |
my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_; |
my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_; |
my $id = &Apache::response::start_response($parstack,$safeeval); |
if ($target eq 'grade' || $target eq 'web') { |
my $result; |
my $default = &Apache::lonxml::get_param('default',$parstack, |
if ($target eq 'web') { |
$safeeval); |
$result = $token->[2]->{'display'}.':'; |
|
} elsif ($target eq 'meta') { |
|
$result = &Apache::response::meta_stores_write($token->[2]->{'name'}, |
|
$token->[2]->{'type'}, |
|
$token->[2]->{'display'}); |
|
$result .= &Apache::response::meta_package_write('dataresponse'); |
|
} |
|
return $result; |
|
} |
|
|
|
sub end_dataresponse { |
|
my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_; |
|
my $result; |
|
if ( $target eq 'web' ) { |
|
} elsif ($target eq 'grade' ) { |
|
if ( defined $ENV{'form.submitted'}) { |
|
my ($symb,$courseid,$domain,$name)=&Apache::lonhomework::which_user(); |
|
my $allowed=&Apache::lonnet::allowed('mgr',$courseid); |
|
if ($allowed) { |
|
&Apache::response::setup_params('datasubmission'); |
|
my $partid = $Apache::inputtags::part; |
|
my $id = $Apache::inputtags::response['-1']; |
|
my $response = $ENV{'form.HWVAL'.$id}; |
my $name = &Apache::lonxml::get_param('name',$parstack,$safeeval); |
my $name = &Apache::lonxml::get_param('name',$parstack,$safeeval); |
&Apache::lonxml::debug("looking for resource.". |
if ( $response =~ /[^\s]/) { |
$Apache::inputtags::part.".$name"); |
$Apache::lonhomework::results{"resource.$partid.$id.$name"}= |
my $value = &Apache::lonnet::EXT("resource.$Apache::inputtags::part". |
$response; |
".$name"); |
$Apache::lonhomework::results{ |
&Apache::lonxml::debug("$name has value :$value: and default :". |
"resource.$partid.$id.submission"}= |
"$default:"); |
$response; |
if ($value eq '' || $value eq 'con_lost') { |
$Apache::lonhomework::results{ |
&Apache::lonxml::debug("defaulting"); |
"resource.$partid.$id.awarddetail"}= |
$Apache::inputtags::params{$name}=$default; |
'SUBMITTED'; |
} else { |
|
&Apache::lonxml::debug("using value"); |
|
$Apache::inputtags::params{$name}=$value; |
|
} |
|
return ''; |
|
} elsif ($target eq 'meta') { |
|
return &meta_parameter_write($token->[2]->{'name'}, |
|
$token->[2]->{'type'}, |
|
$token->[2]->{'default'}, |
|
$token->[2]->{'description'}); |
|
} elsif ($target eq 'edit') { |
|
my $result .= &Apache::edit::tag_start($target,$token, |
|
&Apache::lonxml::description($token)); |
|
$result .= &Apache::edit::text_arg('Name:','name',$token). |
|
&Apache::edit::text_arg('Type:','type',$token). |
|
&Apache::edit::text_arg('Description:','description', |
|
$token). |
|
&Apache::edit::text_arg('Default:','default',$token). |
|
"</td></tr>"; |
|
$result .= &Apache::edit::end_table; |
|
return $result; |
|
} elsif ($target eq 'modified') { |
|
my $result; |
|
my $constructtag = &Apache::edit::get_new_args($token,$parstack, |
|
$safeeval,'name','type', |
|
'description','default'); |
|
if ($constructtag) { |
|
$result = &Apache::edit::rebuild_tag($token); |
|
$result .= &Apache::edit::handle_insert(); |
|
} |
} |
return $result; |
} else { |
|
$result='Not Permitted to change values.' |
} else { |
} |
return ''; |
|
} |
} |
|
} |
|
&Apache::response::end_response; |
|
return $result; |
|
} |
|
|
|
sub start_responseparam { |
|
my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_; |
|
my $result=''; |
|
if ($target eq 'meta') { |
|
$result = &meta_parameter_write($token->[2]->{'name'}, |
|
$token->[2]->{'type'}, |
|
$token->[2]->{'default'}, |
|
$token->[2]->{'description'}); |
|
} elsif ($target eq 'edit') { |
|
$result.=&Apache::edit::tag_start($target,$token, |
|
&Apache::lonxml::description($token)); |
|
$result.=&Apache::edit::text_arg('Name:','name',$token). |
|
&Apache::edit::text_arg('Type:','type',$token). |
|
&Apache::edit::text_arg('Description:','description',$token). |
|
&Apache::edit::text_arg('Default:','default',$token). |
|
"</td></tr>"; |
|
$result.=&Apache::edit::end_table; |
|
} elsif ($target eq 'modified') { |
|
my $constructtag=&Apache::edit::get_new_args($token,$parstack,$safeeval, |
|
'name','type','description', |
|
'default'); |
|
if ($constructtag) { |
|
$result = &Apache::edit::rebuild_tag($token); |
|
$result.=&Apache::edit::handle_insert(); |
|
} |
|
} |
|
return $result; |
} |
} |
|
|
# ========================================================== End response param |
|
sub end_responseparam { |
sub end_responseparam { |
my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_; |
my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_; |
if ($target eq 'edit') { return ('','no'); } |
if ($target eq 'edit') { return ('','no'); } |
return ''; |
return ''; |
} |
} |
|
|
1; |
sub setup_params { |
|
my ($tag) = @_; |
|
|
|
@Apache::inputtags::params=(); |
|
my %paramlist=(); |
|
foreach my $key (keys(%Apache::lonnet::packagetab)) { |
|
if ($key =~ /^$tag/) { |
|
my ($package,$name) = split(/&/,$key); |
|
$paramlist{$name}=1; |
|
} |
|
} |
|
foreach my $key (keys(%paramlist)) { |
|
my $entry= 'resource.'.$Apache::inputtags::part; |
|
if (defined($Apache::inputtags::response[-1])) { |
|
$entry.='_'.$Apache::inputtags::response[-1]; |
|
} |
|
$entry.='.'.$key; |
|
&Apache::lonxml::debug("looking for $entry"); |
|
my $value = &Apache::lonnet::EXT("$entry"); |
|
&Apache::lonxml::debug("$key has value :$value:"); |
|
if ($value eq 'con_lost' || $value =~ /^error:/) { |
|
&Apache::lonxml::debug("using nothing"); |
|
$Apache::inputtags::params{$key}=''; |
|
} else { |
|
&Apache::lonxml::debug("using value"); |
|
$Apache::inputtags::params{$key}=$value; |
|
} |
|
} |
|
} |
|
|
|
1; |
__END__ |
__END__ |
|
|