--- loncom/homework/inputtags.pm 2000/07/25 21:27:30 1.1 +++ loncom/homework/inputtags.pm 2001/08/06 18:00:34 1.42 @@ -1,38 +1,400 @@ -# The LearningOnline Network with CAPA -# input definitons +# The LON-CAPA input tags +# +# Input definitions. +# +# YEAR=2000 +# 7/25,9/11,9/19,10/2,10/11,11/21,11/28,12/1,12/4,12/8,12/11 Guy Albertelli +# 12/12 Guy Albertelli +# 12/12 Gerd Kortemeyer +# 12/12,12/15,12/21 Guy Albertelli +# YEAR=2001 +# 1/4,1/5,1/6,1/10,1/15,1/24,2/19 Guy Albertelli +# 8/6 Scott Harrison package Apache::inputtags; use strict; +# ======================================================================= BEGIN sub BEGIN { - &Apache::lonxml::register('Apache::inputtags',('textline','answergroup')); + &Apache::lonxml::register('Apache::inputtags', + ('textarea','textline','datasubmission')); } +# ======================================================= Initialize input tags 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 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 = (); } +# ========================================== Start input (return scalar string) +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; +} + +# =================================================================== End input +sub end_input { + pop @Apache::inputtags::input; + return ''; +} + +# ====================================== Start text area (return scalar string) +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; } + $result= '"; + } + &end_input; + return ''; +} + +# ====================================== Start text line (return scalar string) sub start_textline { - my ($target,$token,$parstack,$parser,$safeeval)=@_; - my $result = ""; - $Apache::inputtags::curvalue++; - if ($target eq 'web') { - $result= ''; - } - return $result; + my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_; + my $result = ""; + if ($target eq 'web') { + my $size = &Apache::lonxml::get_param('size',$parstack,$safeeval); + if ($size eq '') { $size=20; } + my $oldresponse = $Apache::lonhomework::history{'resource.'. + $Apache::inputtags::part.'.'. + $Apache::inputtags::response['-1'].'.submission'}; + $result = ''; + } + if ($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; + } + if ($target eq 'modified') { + my $constructtag = &Apache::edit::get_new_args($token,$parstack, + $safeeval,'size'); + if ($constructtag) { $result = &Apache::edit::rebuild_tag($token); } + } + return $result; } +# =============================================================== End text line sub end_textline { - my ($target,$token,$parstack,$parser,$safeeval)=@_; + my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_; + if ($target eq 'edit') { return ('','no'); } + return ""; +} + +# ======================================================= Start data submission +sub start_datasubmission { + return ''; } -sub start_answergroup { +# ========================================================= End data submission +sub end_datasubmission { + my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_; + if ( $target == 'web' ) { + return ''; + } + return ''; } -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__ -