--- loncom/homework/inputtags.pm 2010/09/13 04:26:26 1.260.4.2
+++ loncom/homework/inputtags.pm 2010/02/28 23:27:36 1.261
@@ -1,7 +1,7 @@
# The LearningOnline Network with CAPA
# input definitons
#
-# $Id: inputtags.pm,v 1.260.4.2 2010/09/13 04:26:26 raeburn Exp $
+# $Id: inputtags.pm,v 1.261 2010/02/28 23:27:36 raeburn Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -53,7 +53,6 @@ package Apache::inputtags;
use HTML::Entities();
use strict;
use Apache::loncommon;
-use Apache::lonhtmlcommon;
use Apache::lonlocal;
use Apache::lonnet;
use LONCAPA;
@@ -480,177 +479,87 @@ sub file_selector {
$jspart=~s/\./_/g;
my $result;
- my $current_files_display = ¤t_file_submissions($part,$id);
- my $addfiles;
- if ($current_files_display) {
- $result .= &Apache::lonhtmlcommon::row_title(&mt('Currently submitted files')).
- $current_files_display.
- &Apache::lonhtmlcommon::row_closure();
- $addfiles = &mt('Submit other file(s)');
- } else {
- $addfiles = &mt('Choose file(s) to submit');
- }
- $result .= &Apache::lonhtmlcommon::row_title($addfiles);
- my $constraints;
- if ($uploadedfiletypes ne '*') {
- $constraints =
- &mt('Allowed filetypes: [_1]',''.$uploadedfiletypes.' ').' ';
- }
- if ($maxfilesize) {
- $constraints .= &mt('Combined size of all files not to exceed: [_1] MB[_2].',
- ''.$maxfilesize.' ').' ';
- }
- if ($constraints) {
- $result .= $constraints.' ';
+
+ $result.='
';
+ if (($uploadedfiletypes ne '*') || ($maxfilesize)) {
+ if ($uploadedfiletypes ne '*') {
+ $result.=
+ &mt('Allowed filetypes: [_1]',''.$uploadedfiletypes.' ').' ';
+ }
+ if ($maxfilesize) {
+ $result.=&mt('Combined size of files not to exceed: [_1] MB[_2].',
+ ''.$maxfilesize.' ').' ';
+ }
+ $result .= ' ';
}
if ($which eq 'uploadonly' || $which eq 'both') {
- $result.=&mt('Submit a file: (only one file per submission)').
+ $result.=&mt('Submit a file: (only one file can be uploaded)').
' ';
+ $result .= &show_past_file_submission($part,$id);
}
if ( $which eq 'both') {
$result.=' '.''.&mt('OR:').' ';
}
if ($which eq 'portfolioonly' || $which eq 'both') {
$result.=$extratext.''.
- &mt('Select Portfolio Files: (one or more files per submission)').' '.
+ &mt('Select Portfolio Files').' '.
' '.
' ';
-
+ $result .= &show_past_portfile_submission($part,$id);
}
- $result.=&Apache::lonhtmlcommon::row_closure(1);
+ $result.=' ';
return $result;
}
-sub current_file_submissions {
+sub show_past_file_submission {
my ($part,$id) = @_;
- my $jspart=$part;
- $jspart=~s/\./_/g;
- 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();
- 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,%legacy,@bad_file_list);
- if ($uploadedfile) {
- my $url=$Apache::lonhomework::history{"resource.$part.$id.uploadedurl"};
- 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,$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 {
- push(@bad_file_list,$error);
- }
- }
- if ($portfiles =~ /[^\s]/) {
- my $prefix = "/uploaded/$udom/$uname/portfolio";
- foreach my $file (split(/\s*,\s*/,&unescape($portfiles))) {
- my ($path,$name) = ($file =~ m{^(.*/)([^/]+)$});
- my $url = $prefix.$path.$name;
- my $uploadedfile = &HTML::Entities::encode($url,'<>&"');
- my ($status,$hashref,$error) =
- ¤t_file_info($url,$uploadedfile,$name,$path);
- if ($status eq 'ok') {
- push(@{$okfiles{$name}},$url);
- $rows{$url} = $hashref;
- } else {
- push(@bad_file_list,$error);
- }
- }
- }
- foreach my $name (sort(keys(%okfiles))) {
- if (ref($okfiles{$name}) eq 'ARRAY') {
- foreach my $url (@{$okfiles{$name}}) {
- if (ref($rows{$url}) eq 'HASH') {
- my $link = $rows{$url}{link};
- my $portfile = $rows{$url}{path}.$rows{$url}{name};
- $portfile = &HTML::Entities::encode($portfile,'<>&"');
- if ($link) {
- my $icon=&Apache::loncommon::icon($url);
- unless ($header_shown) {
- $result .= $header;
- $header_shown = 1;
- }
- $result.=
- &Apache::loncommon::start_data_table_row()."\n";
- if ($Apache::inputtags::status[-1] eq 'CAN_ANSWER') {
- $result .=
- ' '."\n";
- }
- my $showname = $rows{$url}{path}.$name;
- if ($legacy{$url}) {
- $showname = $name.' '.&mt('not in portfolio');
- }
- if ($env{'request.uri'} eq '/res/gci/gci/internal/submission.problem') {
- $showname = $name;
- }
- $result .=
- ' '.$showname.' '."\n".
- ''.$rows{$url}{size}.' '."\n".
- ''.$rows{$url}{lastmodified}.' '."\n".
- &Apache::loncommon::end_data_table_row();
- }
- }
- }
- }
- }
- if ($header_shown) {
- $result .= &Apache::loncommon::end_data_table();
+ my $uploadedfile= &HTML::Entities::encode($Apache::lonhomework::history{"resource.$part.$id.uploadedfile"},'<>&"');
+
+ return if (!$uploadedfile);
+
+ my $url=$Apache::lonhomework::history{"resource.$part.$id.uploadedurl"};
+ &Apache::lonxml::extlink($url);
+ &Apache::lonnet::allowuploaded('/adm/essayresponse',$url);
+ my $icon=&Apache::loncommon::icon($url);
+ my $curfile=' '.$uploadedfile.' ';
+ return &mt('Currently submitted: [_1]',''.$curfile.' ');
+
+}
+
+sub show_past_portfile_submission {
+ my ($part,$id) = @_;
+ if ($Apache::lonhomework::history{"resource.$part.$id.portfiles"}!~/[^\s]/){
+ return;
}
+ my (@file_list,@bad_file_list);
+ foreach my $file (split(/\s*,\s*/,&unescape($Apache::lonhomework::history{"resource.$part.$id.portfiles"}))) {
+ my (undef,undef,$domain,$user)=&Apache::lonnet::whichuser();
+ my $url="/uploaded/$domain/$user/portfolio$file";
+ my $icon=&Apache::loncommon::icon($url);
+ push(@file_list,' '.$file.' ');
+ if (! &Apache::lonnet::stat_file($url)) {
+ &Apache::lonnet::logthis("bad file is $url");
+ push(@bad_file_list,' '.$file.' ');
+ }
+ }
+ my $files = ''.
+ join(' , ',@file_list).
+ ' ';
+ my $result = &mt("Portfolio files previously selected: [_1]",$files);
if (@bad_file_list) {
- my $bad_files = ''.
- join(' , ',@bad_file_list).
- ' ';
- $result.=''.
- &mt("These file(s) don't exist: [_1]",$bad_files).
- '
';
+ my $bad_files = ''.
+ join(' , ',@bad_file_list).
+ ' ';
+ $result.=''
+ .&mt("These file(s) don't exist: [_1]",$bad_files)
+ .'
';
}
return $result;
-}
-sub current_file_info {
- my ($url,$uploadedfile,$name,$path) = @_;
- my ($status,$error,%info);
- my @stat = &Apache::lonnet::stat_file($url);
- if ((@stat) && ($stat[0] ne 'no_such_dir')) {
- my ($lastmod,$size);
- if ($stat[9] =~ /^\d+$/) {
- $lastmod = &Apache::lonlocal::locallocaltime($stat[9]);
- }
- $size = $stat[7]/(1024*1024);
- $size = sprintf("%.3f",$size);
- %info = (
- link => $uploadedfile,
- name => $name,
- path => $path,
- size => $size,
- lastmodified => $lastmod,
- );
- $status = 'ok';
- } else {
- &Apache::lonnet::logthis("bad file is $url");
- my $icon=&Apache::loncommon::icon($url);
- $error = ' '.$uploadedfile.' ';
- }
- return ($status,\%info,$error);
}
sub valid_award {
@@ -663,9 +572,11 @@ sub valid_award {
'UNIT_NOTNEEDED', 'WANTED_NUMERIC',
'BAD_FORMULA', 'INTERNAL_ERROR', 'SIG_FAIL', 'INCORRECT',
'MISORDERED_RANK', 'INVALID_FILETYPE',
- 'EXCESS_FILESIZE', 'FILENAME_INUSE',
- 'DRAFT', 'SUBMITTED', 'ASSIGNED_SCORE',
- 'APPROX_ANS', 'EXACT_ANS','COMMA_FAIL') {
+ 'EXCESS_FILESIZE', 'DRAFT',
+ 'SUBMITTED', 'SUBMITTED_CREDIT',
+ 'ANONYMOUS', 'ANONYMOUS_CREDIT',
+ 'ASSIGNED_SCORE', 'APPROX_ANS',
+ 'EXACT_ANS','COMMA_FAIL') {
if ($award eq $possibleaward) { return 1; }
}
return 0;
@@ -678,8 +589,8 @@ sub valid_award {
'UNIT_IRRECONCIBLE', 'UNIT_FAIL', 'NO_UNIT',
'UNIT_NOTNEEDED', 'WANTED_NUMERIC', 'BAD_FORMULA', 'INTERNAL_ERROR',
'COMMA_FAIL', 'SIG_FAIL', 'INCORRECT', 'MISORDERED_RANK',
- 'INVALID_FILETYPE', 'EXCESS_FILESIZE', 'FILENAME_INUSE',
- 'DRAFT', 'SUBMITTED',
+ 'INVALID_FILETYPE', 'EXCESS_FILESIZE', 'DRAFT', 'SUBMITTED',
+ 'SUBMITTED_CREDIT', 'ANONYMOUS', 'ANONYMOUS_CREDIT',
'ASSIGNED_SCORE', 'APPROX_ANS', 'EXACT_ANS');
my $i=0;
my %fwd_awards = map { ($_,$i++) } @awards;
@@ -703,7 +614,7 @@ sub hide_award {
return 1;
}
if ($award =~
- /^(?:EXACT_ANS|APPROX_ANS|SUBMITTED|ASSIGNED_SCORE|INCORRECT)/) {
+ /^(?:EXACT_ANS|APPROX_ANS|SUBMITTED|SUBMITTED_CREDIT|ANONYMOUS|ANONYMOUS_CREDIT|ASSIGNED_SCORE|INCORRECT)/) {
return 1;
}
return 0;
@@ -909,16 +820,6 @@ sub decideoutput {
$message = &mt('Submission won\'t be graded. The combined size of submitted files exceeded the amount allowed.');
$css_class=$possible_class{'not_charged_try'};
$button=1;
- } elsif ($award eq 'FILENAME_INUSE') {
- $message = &mt('You have already uploaded a file with that filename.');
- if ($target eq 'tex') {
- $message.= "\\\\\n";
- } else {
- $message .= ' ';
- }
- $message .= &mt('Please use a different file name.');
- $css_class=$possible_class{'not_charged_try'};
- $button=1;
} elsif ($award eq 'INVALID_FILETYPE') {
$message = &mt("Submission won't be graded. The type of file submitted is not allowed.");
$css_class=$possible_class{'not_charged_try'};
@@ -971,15 +872,20 @@ sub decideoutput {
$css_class=$possible_class{'charged_try'};
$button=1;
} elsif ($award eq 'SUBMITTED') {
- if ($env{'request.uri'} eq '/res/gci/gci/internal/submission.problem') {
- if ($target eq 'web') {
- $message .= ' '.&mt('Thank you for making a submission to the Geosciences Concept Inventory via the GCI Web Center.');
- }
- } else {
- $message = &mt("Your submission has been recorded.");
- }
+ $message = &mt("Your submission has been recorded.");
$css_class=$possible_class{'no_grade'};
$button=1;
+ } elsif ($award eq 'SUBMITTED_CREDIT') {
+ $message = &mt("Your submission has been recorded, and credit awarded.");
+ $css_class=$possible_class{'correct'};
+ $button=1;
+ } elsif ($award eq 'ANONYMOUS') {
+ $message = &mt("Your anonymous submission has been recorded.");
+ $css_class=$possible_class{'no_grade'};
+ $button=1;
+ } elsif ($award eq 'ANONYMOUS_CREDIT') {
+ $message = &mt("Your anonymous submission has been recorded, and credit awarded.");
+ $css_class=$possible_class{'correct'};
} elsif ($award eq 'DRAFT') {
$message = &mt("Copy saved but not submitted.");
$css_class=$possible_class{'not_charged_try'};
@@ -1030,14 +936,7 @@ sub decideoutput {
if (&Apache::lonhomework::hide_problem_status()
&& $Apache::inputtags::status[-1] ne 'SHOW_ANSWER'
&& &hide_award($award)) {
- if ($env{'request.uri'} eq '/res/gci/gci/internal/submission.problem') {
- if ($target eq 'web') {
- $message = &mt("Your submission has been recorded.").' '.
- &mt('Thank you for making a submission to the Geosciences Concept Inventory via the GCI Web Center.');
- }
- } else {
- $message = &mt("Answer Submitted: Your final submission will be graded after the due date.");
- }
+ $message = &mt("Answer Submitted: Your final submission will be graded after the due date.");
$css_class=$possible_class{'no_grade'};
$button=1;
}
@@ -1150,6 +1049,18 @@ sub setgradedata {
$Apache::lonhomework::results{"resource.$id.solved"} =
$solvemsg;
$Apache::lonhomework::results{"resource.$id.awarded"} = '1';
+ } elsif ( $award eq 'SUBMITTED_CREDIT' ) {
+ $Apache::lonhomework::results{"resource.$id.tries"} =
+ $Apache::lonhomework::history{"resource.$id.tries"} + 1;
+ $Apache::lonhomework::results{"resource.$id.solved"} =
+ 'credit_attempted';
+ $Apache::lonhomework::results{"resource.$id.awarded"} = '1';
+ } elsif ( $award eq 'ANONYMOUS_CREDIT' ) {
+ $Apache::lonhomework::results{"resource.$id.tries"} =
+ $Apache::lonhomework::history{"resource.$id.tries"} + 1;
+ $Apache::lonhomework::results{"resource.$id.solved"} =
+ 'credit_attempted';
+ $Apache::lonhomework::results{"resource.$id.awarded"} = '1';
} elsif ( $award eq 'INCORRECT' ) {
$Apache::lonhomework::results{"resource.$id.tries"} =
$Apache::lonhomework::history{"resource.$id.tries"} + 1;
@@ -1164,6 +1075,11 @@ sub setgradedata {
$Apache::lonhomework::history{"resource.$id.tries"} + 1;
$Apache::lonhomework::results{"resource.$id.solved"} =
'ungraded_attempted';
+ } elsif ( $award eq 'ANONYMOUS' ) {
+ $Apache::lonhomework::results{"resource.$id.tries"} =
+ $Apache::lonhomework::history{"resource.$id.tries"} + 1;
+ $Apache::lonhomework::results{"resource.$id.solved"} =
+ 'ungraded_attempted';
} elsif ( $award eq 'DRAFT' ) {
$Apache::lonhomework::results{"resource.$id.solved"} = '';
} elsif ( $award eq 'NO_RESPONSE' ) {
@@ -1223,6 +1139,10 @@ sub setgradedata {
if ($award eq 'SUBMITTED') {
&Apache::response::add_to_gradingqueue();
}
+ if (($Apache::lonhomework::type eq 'anonsurvey') ||
+ ($Apache::lonhomework::type eq 'anonsurveycred')) {
+ $Apache::lonhomework::results{"resource.$id.type"} = $Apache::lonhomework::type;
+ }
}
sub find_which_previous {
@@ -1337,6 +1257,9 @@ sub get_grade_messages {
if ( $maxtries eq 'con_lost' ) { $maxtries = '0'; }
my $tries_text=&mt('Tries');
if ( $Apache::lonhomework::type eq 'survey' ||
+ $Apache::lonhomework::type eq 'surveycred' ||
+ $Apache::lonhomework::type eq 'anonsurvey' ||
+ $Apache::lonhomework::type eq 'anonsurveycred' ||
$Apache::lonhomework::parsing_a_task) {
$tries_text=&mt('Submissions');
}
@@ -1352,19 +1275,15 @@ sub get_grade_messages {
$trystr = '\vskip 0 mm ';
}
} else {
- $trystr = '';
- my %parmhash=&Apache::lonnet::coursedescription($env{'request.course.id'});
- if ($parmhash{'suppress_tries'} ne 'yes') {
- $trystr .= "$tries_text $tries";
- if ($Apache::lonhomework::parsing_a_task) {
- } elsif($env{'request.state'} ne 'construct') {
- $trystr.="/$maxtries";
- } else {
- if (defined($Apache::inputtags::params{'maxtries'})) {
- $trystr.="/".$Apache::inputtags::params{'maxtries'};
- }
- }
- }
+ $trystr = ' '.$tries_text." $tries";
+ if ($Apache::lonhomework::parsing_a_task) {
+ } elsif($env{'request.state'} ne 'construct') {
+ $trystr.="/$maxtries";
+ } else {
+ if (defined($Apache::inputtags::params{'maxtries'})) {
+ $trystr.="/".$Apache::inputtags::params{'maxtries'};
+ }
+ }
$trystr.=" ";
}
}
@@ -1407,14 +1326,10 @@ sub gradestatus {
}
if ( $showbutton ) {
if ($target ne 'tex') {
- my $submit_text = &mt('Submit Answer');
- if ($env{'request.uri'} eq '/res/gci/gci/internal/submission.problem') {
- $submit_text = &mt('Submit Questions');
- }
$button =
' ';
+ value="'.&mt('Submit Answer').'" />';
}
}
@@ -1510,12 +1425,8 @@ sub previous_tries {
$output.=' ';
my $windowopen=&Apache::lonhtmlcommon::javascript_docopen();
- my $pagetitle = 'Previous Tries';
- if ($env{'request.uri'} eq '/res/gci/gci/internal/submission.problem') {
- $pagetitle = 'Submission History';
- }
my $start_page =
- &Apache::loncommon::start_page($pagetitle, undef,
+ &Apache::loncommon::start_page('Previous Tries', undef,
{'only_body' => 1,
'bgcolor' => '#FFFFFF',
'js_ready' => 1,
@@ -1526,15 +1437,11 @@ sub previous_tries {
$prefix =~ tr{.}{_};
my $function_name = "LONCAPA_previous_tries_".$prefix.
$Apache::lonxml::curdepth.'_'.$env{'form.counter'};
- my $triestext = &mt('Previous Tries');
- if ($env{'request.uri'} eq '/res/gci/gci/internal/submission.problem') {
- $triestext = &mt('Submission History');
- }
my $result ="".$triestext." ";
+".&mt("Previous Tries")." ";
#use Data::Dumper;
#&Apache::lonnet::logthis(&Dumper(\%Apache::inputtags::submission_display));
return $result;