--- loncom/homework/inputtags.pm 2000/07/25 21:27:30 1.1 +++ loncom/homework/inputtags.pm 2001/11/12 20:27:28 1.46 @@ -1,38 +1,392 @@ # The LearningOnline Network with CAPA # input definitons +# 2/19 Guy package Apache::inputtags; use strict; sub BEGIN { - &Apache::lonxml::register('Apache::inputtags',('textline','answergroup')); + &Apache::lonxml::register('Apache::inputtags',('textarea','textline','datasubmission')); } + sub initialize_inputtags { - $Apache::inputtags::curvalue=0; + # list of current input ids + @Apache::inputtags::input=(); + # list of all input ids seen in this problem + @Apache::inputtags::inputlist=(); + # list of all current response ids + @Apache::inputtags::response=(); + # list of all response ids seen in this problem + @Apache::inputtags::responselist=(); + # list of whether or not a specific response was previously used + @Apache::inputtags::previous=(); + # id of current part, 0 means that no part is current (inside only + $Apache::inputtags::part=''; + # list of problem date statuses, the first element is for + # if there is a second element it is for the current + @Apache::inputtags::status=(); + # hash of defined params for the current response + %Apache::inputtags::params=(); + # list of all ids, for , these get join()ed and prepended + @Apache::inputtags::import=(); +} + +sub start_input { + my ($parstack,$safeeval)=@_; + my $id = &Apache::lonxml::get_param('id',$parstack,$safeeval); + if ($id eq '') { $id = $Apache::lonxml::curdepth; } + push (@Apache::inputtags::input,$id); + push (@Apache::inputtags::inputlist,$id); + return $id; +} + +sub end_input { + pop @Apache::inputtags::input; + return ''; +} + +sub start_textarea { + my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_; + my $result = ""; + my $id = &start_input($parstack,$safeeval); + if ($target eq 'web') { + my $oldresponse = $Apache::lonhomework::history{"resource.$Apache::inputtags::part.$Apache::inputtags::response['-1'].submission"}; + my $cols = &Apache::lonxml::get_param('cols',$parstack,$safeeval); + if ( $cols eq '') { $cols = 80; } + my $rows = &Apache::lonxml::get_param('rows',$parstack,$safeeval); + if ( $rows eq '') { $rows = 10; } + if ($Apache::inputtags::status[-1] eq 'CAN_ANSWER') { + $result= '"; + } + } + &end_input; + return ''; } sub start_textline { - my ($target,$token,$parstack,$parser,$safeeval)=@_; + my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_; my $result = ""; - $Apache::inputtags::curvalue++; if ($target eq 'web') { - $result= ''; + my $size = &Apache::lonxml::get_param('size',$parstack,$safeeval); + if ($size eq '') { $size=20; } + my $partid=$Apache::inputtags::part; + my $id=$Apache::inputtags::response['-1']; + my $oldresponse = + $Apache::lonhomework::history{"resource.$partid.$id.submission"}; + if ($Apache::inputtags::status[-1] eq 'CAN_ANSWER') { + $result= ''; + } else { + $result=''.$oldresponse.''; + } + } elsif ($target eq 'edit') { + $result=&Apache::edit::tag_start($target,$token, + &Apache::lonxml::description($token)); + $result.=&Apache::edit::text_arg('Size:','size',$token,'5').""; + $result.=&Apache::edit::end_table; + } elsif ($target eq 'modified') { + my $constructtag=&Apache::edit::get_new_args($token,$parstack,$safeeval,'size'); + if ($constructtag) { $result = &Apache::edit::rebuild_tag($token); } } return $result; } sub end_textline { - my ($target,$token,$parstack,$parser,$safeeval)=@_; + my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_; + if ($target eq 'edit') { return ('','no'); } + return ""; } -sub start_answergroup { +sub start_datasubmission { + my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_; + my $id = &Apache::response::start_response($parstack,$safeeval); + my $result; + if ($target eq 'meta') { + $result = &Apache::response::meta_stores_write($token->[2]->{'name'}, + $token->[2]->{'type'}, + $token->[2]->{'display'}); + $result .= &Apache::response::meta_package_write('datasubmission'); + } + return $result; } -sub end_answergroup { - return '$message"; + if ($previousmsg) { + $previousmsg="$previousmsg"; + } + } + my $tries = $Apache::lonhomework::history{"resource.$id.tries"}; + my $maxtries = &Apache::lonnet::EXT("resource.$id.maxtries"); + &Apache::lonxml::debug("got maxtries of :$maxtries:"); + if ( $tries eq '' ) { $tries = '0'; } + if ( $maxtries eq '' ) { $maxtries = '2'; } + if ( $maxtries eq 'con_lost' ) { $maxtries = '0'; } + if ( $showbutton ) { + $trystr = "Tries $tries/$maxtries"; + } + if ( $status eq 'SHOW_ANSWER' || $status eq 'CANNOT_ANSWER') {$showbutton = 0;} + if ( $showbutton ) { + $button = '
'; + } + } + my $output= $previousmsg.$message.$trystr; + if ($output =~ /^\s*$/) { + return $button; + } else { + return $button.''.$previousmsg.$message.$trystr.'
'; + } +} 1; __END__