--- loncom/homework/inputtags.pm 2010/08/08 02:00:50 1.267 +++ loncom/homework/inputtags.pm 2010/12/31 19:10:16 1.271.2.4 @@ -1,7 +1,7 @@ # The LearningOnline Network with CAPA # input definitons # -# $Id: inputtags.pm,v 1.267 2010/08/08 02:00:50 raeburn Exp $ +# $Id: inputtags.pm,v 1.271.2.4 2010/12/31 19:10:16 raeburn Exp $ # # Copyright Michigan State University Board of Trustees # @@ -175,7 +175,18 @@ sub start_textfield { if ($target eq 'web') { $Apache::lonxml::evaluate--; my $partid=$Apache::inputtags::part; - my $oldresponse = &HTML::Entities::encode($Apache::lonhomework::history{"resource.$partid.$resid.submission"},'<>&"'); + my ($oldresponse,$newvariation); + if ((($Apache::lonhomework::history{"resource.$partid.type"} eq 'randomizetry') || + ($Apache::lonhomework::type eq 'randomizetry')) && + ($Apache::inputtags::status[-1] eq 'CAN_ANSWER')) { + if ($env{'form.'.$partid.'.rndseed'} ne + $Apache::lonhomework::history{"resource.$partid.rndseed"}) { + $newvariation = 1; + } + } + unless ($newvariation) { + $oldresponse = &HTML::Entities::encode($Apache::lonhomework::history{"resource.$partid.$resid.submission"},'<>&"'); + } if ($Apache::inputtags::status[-1] eq 'CAN_ANSWER') { my $cols = &Apache::lonxml::get_param('cols',$parstack,$safeeval); if ( $cols eq '') { $cols = 80; } @@ -331,16 +342,27 @@ sub start_textline { $maxlength = ' maxlength="'.$size.'"'; } } - my $oldresponse = $Apache::lonhomework::history{"resource.$partid.$id.submission"}; - &Apache::lonxml::debug("oldresponse $oldresponse is ".ref($oldresponse)); - - if (ref($oldresponse) eq 'ARRAY') { - $oldresponse = $oldresponse->[$#Apache::inputtags::inputlist]; - } - $oldresponse = &HTML::Entities::encode($oldresponse,'<>&"'); - $oldresponse =~ s/^\s+//; - $oldresponse =~ s/\s+$//; - $oldresponse =~ s/\s+/ /g; + my ($oldresponse,$newvariation); + if ((($Apache::lonhomework::history{"resource.$partid.type"} eq 'randomizetry') || + ($Apache::lonhomework::type eq 'randomizetry')) && + ($Apache::inputtags::status[-1] eq 'CAN_ANSWER')) { + if ($env{'form.'.$partid.'.rndseed'} ne + $Apache::lonhomework::history{"resource.$partid.rndseed"}) { + $newvariation = 1; + } + } + unless ($newvariation) { + $oldresponse = $Apache::lonhomework::history{"resource.$partid.$id.submission"}; + &Apache::lonxml::debug("oldresponse $oldresponse is ".ref($oldresponse)); + + if (ref($oldresponse) eq 'ARRAY') { + $oldresponse = $oldresponse->[$#Apache::inputtags::inputlist]; + } + $oldresponse = &HTML::Entities::encode($oldresponse,'<>&"'); + $oldresponse =~ s/^\s+//; + $oldresponse =~ s/\s+$//; + $oldresponse =~ s/\s+/ /g; + } if ($Apache::lonhomework::type ne 'exam') { my $addchars=&Apache::lonxml::get_param('addchars',$parstack,$safeeval); $result=''; @@ -484,7 +506,7 @@ sub file_selector { my $current_files_display = ¤t_file_submissions($part,$id); my $addfiles; if ($current_files_display) { - $result .= &Apache::lonhtmlcommon::row_title(&mt('Currently submitted files:')). + $result .= &Apache::lonhtmlcommon::row_title(&mt('Currently submitted files')). $current_files_display. &Apache::lonhtmlcommon::row_closure(); $addfiles = &mt('Submit other file(s)'); @@ -527,27 +549,31 @@ sub current_file_submissions { my ($part,$id) = @_; my $jspart=$part; $jspart=~s/\./_/g; - my $uploadedfile=&HTML::Entities::encode($Apache::lonhomework::history{"resource.$part.$id.uploadedfile"},'<>&"'); + my $uploadedfile=$Apache::lonhomework::history{"resource.$part.$id.uploadedfile"}; my $portfiles=$Apache::lonhomework::history{"resource.$part.$id.portfiles"}; return if (($uploadedfile eq '') && ($portfiles !~/[^\s]/)); my $header = &Apache::loncommon::start_data_table(). - &Apache::loncommon::start_data_table_header_row(). - ''.&mt('Delete?').''. - ''.&mt('Name').''. + &Apache::loncommon::start_data_table_header_row(); + if ($Apache::inputtags::status[-1] eq 'CAN_ANSWER') { + $header .= ''.&mt('Delete?').''; + } + $header .= ''.&mt('File').''. ''.&mt('Size (MB)').''. ''.&mt('Last Modified').''. &Apache::loncommon::end_data_table_header_row(); my (undef,$crsid,$udom,$uname)=&Apache::lonnet::whichuser(); my ($cdom,$cnum) = ($crsid =~ /^($LONCAPA::match_domain)_($LONCAPA::match_courseid)$/); - my ($result,$header_shown,%okfiles,%rows,@bad_file_list); + my ($result,$header_shown,%okfiles,%rows,%legacy,@bad_file_list); if ($uploadedfile) { my $url=$Apache::lonhomework::history{"resource.$part.$id.uploadedurl"}; - my ($path,$name) = ($url =~ m{^/uploaded/\Q$cdom\E/\Q$cnum\E/(essayresponse/.+/)([^/]+))}); + my $link = &HTML::Entities::encode($url,'<>&"'); + my ($path,$name) = ($url =~ m{^(/uploaded/\Q$udom\E/\Q$uname\E/essayresponse.*/)([^/]+)$}); my ($status,$hashref,$error) = - ¤t_file_info($url,$uploadedfile,$name,$path); + ¤t_file_info($url,$link,$name,$path); if ($status eq 'ok') { push(@{$okfiles{$name}},$url); $rows{$url} = $hashref; + $legacy{$url} = 1; &Apache::lonxml::extlink($url); &Apache::lonnet::allowuploaded('/adm/essayresponse',$url); } else { @@ -570,6 +596,7 @@ sub current_file_submissions { } } } + my $num = 0; foreach my $name (sort(keys(%okfiles))) { if (ref($okfiles{$name}) eq 'ARRAY') { foreach my $url (@{$okfiles{$name}}) { @@ -584,11 +611,20 @@ sub current_file_submissions { $header_shown = 1; } $result.= - &Apache::loncommon::start_data_table_row()."\n". - ''."\n". + &Apache::loncommon::start_data_table_row()."\n"; + if ($Apache::inputtags::status[-1] eq 'CAN_ANSWER') { + $result .= + ''."\n"; + $num ++; + } + my $showname = $rows{$url}{path}.$name; + if ($legacy{$url}) { + $showname = $name.' '.&mt('not in portfolio'); + } + $result .= ''.$name.''."\n". + '" border="0" alt="" />'.$showname.''."\n". ''.$rows{$url}{size}.''."\n". ''.$rows{$url}{lastmodified}.''."\n". &Apache::loncommon::end_data_table_row(); @@ -598,7 +634,9 @@ sub current_file_submissions { } } if ($header_shown) { - $result .= &Apache::loncommon::end_data_table(); + $result .= &Apache::loncommon::end_data_table(). + '
'. + &mt('Exclude existing file(s) from grading by checking the "Delete?" checkbox(es) and clicking "Submit Answer"').''; } if (@bad_file_list) { my $bad_files = ''. @@ -1228,9 +1266,13 @@ sub setgradedata { &Apache::response::add_to_gradingqueue(); } if (($Apache::lonhomework::type eq 'anonsurvey') || - ($Apache::lonhomework::type eq 'anonsurveycred')) { + ($Apache::lonhomework::type eq 'anonsurveycred') || + ($Apache::lonhomework::type eq 'randomizetry')) { $Apache::lonhomework::results{"resource.$id.type"} = $Apache::lonhomework::type; } + if ($Apache::lonhomework::type eq 'randomizetry') { + $Apache::lonhomework::results{"resource.$id.rndseed"} = $env{'form.'.$id.'.rndseed'}; + } } sub find_which_previous { @@ -1439,6 +1481,7 @@ sub previous_tries { my $count; my %count_lookup; + my $lastrndseed; foreach my $i (1..$Apache::lonhomework::history{'version'}) { my $prefix = $i.":resource.$id"; @@ -1452,7 +1495,8 @@ sub previous_tries { next if (!exists($Apache::lonhomework::history{"$prefix.award"})); $count++; $count_lookup{$i} = $count; - + my $curr_rndseed = $Apache::lonhomework::history{"$prefix.rndseed"}; + my ($previousmsg,$latemessage,$message,$trystr); ($previousmsg,$latemessage,$message,$trystr) = @@ -1474,6 +1518,11 @@ sub previous_tries { {$1 $txt_correct. $3}s; } my $trystr = "(".&mt('Try [_1]',$Apache::lonhomework::history{"$prefix.tries"}).")"; + if ($curr_rndseed || $lastrndseed) { + if ($curr_rndseed ne $lastrndseed) { + $trystr .= '
'.&mt('New problem variation this try.').''; + } + } $message =~ s{()}{ $trystr $1}; } my ($class) = ($message =~ m{