+'.&mt('Unable to retrieve a resource from a server:').'
+'.&mt('Resource:').' '.$ssi_error_resource.'
+'.&mt('Error:').' '.$ssi_error_message.'
+
+
'.
+&mt('It is recommended that you try again later, as this error may mean the server was just temporarily unavailable, or is down for maintenance.').' '.
+&mt('If the error persists, please contact the [_1] for assistance.',$helpurl).
+'
');
+ return;
+}
+
+#
+# --- Retrieve the parts from the metadata file.---
+# Returns an array of everything that the resources stores away
#
-# --- Retrieve the parts that matches stores_\d+ from the metadata file.---
+
sub getpartlist {
- my ($url) = @_;
- my @parts =();
- my (@metakeys) = split(/,/,&Apache::lonnet::metadata($url,'keys'));
- foreach my $key (@metakeys) {
- if ( $key =~ m/stores_(\w+)_.*/) {
- push(@parts,$key);
- }
- }
- return @parts;
-}
-
-# --- Get the symbolic name of a problem and the url
-sub get_symb_and_url {
- my ($request) = @_;
- (my $url=$ENV{'form.url'}) =~ s-^http://($ENV{'SERVER_NAME'}|$ENV{'HTTP_HOST'})--;
- my $symb=($ENV{'form.symb'} ne '' ? $ENV{'form.symb'} : (&Apache::lonnet::symbread($url)));
- if ($symb eq '') { $request->print("Unable to handle ambiguous references:$url:."); return ''; }
- return ($symb,$url);
-}
-
-# --- Retrieve the fullname for a user. Return lastname, first middle ---
-# --- Generation is attached next to the lastname if it exists. ---
-sub get_fullname {
- my ($uname,$udom) = @_;
- my %name=&Apache::lonnet::get('environment', ['lastname','generation',
- 'firstname','middlename'],
- $udom,$uname);
- my $fullname;
- my ($tmp) = keys(%name);
- if ($tmp !~ /^(con_lost|error|no_such_host)/i) {
- $fullname = &Apache::loncoursedata::ProcessFullName
- (@name{qw/lastname generation firstname middlename/});
+ my ($symb,$errorref) = @_;
+
+ my $navmap = Apache::lonnavmaps::navmap->new();
+ unless (ref($navmap)) {
+ if (ref($errorref)) {
+ $$errorref = 'navmap';
+ return;
+ }
+ }
+ my $res = $navmap->getBySymb($symb);
+ my $partlist = $res->parts();
+ my $url = $res->src();
+ my @metakeys = split(/,/,&Apache::lonnet::metadata($url,'keys'));
+
+ my @stores;
+ foreach my $part (@{ $partlist }) {
+ foreach my $key (@metakeys) {
+ if ($key =~ m/^stores_\Q$part\E_/) { push(@stores,$key); }
+ }
+ }
+ return @stores;
+}
+
+#--- Format fullname, username:domain if different for display
+#--- Use anywhere where the student names are listed
+sub nameUserString {
+ my ($type,$fullname,$uname,$udom) = @_;
+ if ($type eq 'header') {
+ return ' '.&mt('Fullname').' ('.&mt('Username').')';
} else {
- &Apache::lonnet::logthis('grades.pm: no name data for '.$uname.
- '@'.$udom.':'.$tmp);
+ return ' '.$fullname.' ('.$uname.
+ ($env{'user.domain'} eq $udom ? '' : ' ('.$udom.')').')';
}
- return $fullname;
}
#--- Get the partlist and the response type for a given problem. ---
#--- Indicate if a response type is coded handgraded or not. ---
sub response_type {
- my ($url) = shift;
- my $allkeys = &Apache::lonnet::metadata($url,'keys');
- my %seen = ();
- my (@partlist,%handgrade);
- foreach (split(/,/,&Apache::lonnet::metadata($url,'packages'))) {
- if (/^\w+response_\w+.*/) {
- my ($responsetype,$part) = split(/_/,$_,2);
- my ($partid,$respid) = split(/_/,$part);
- $responsetype =~ s/response$//; # make it compatible w/ navmaps - should move to that!!
- $handgrade{$part} = $responsetype.':'.($allkeys =~ /parameter_$part\_handgrade/ ? 'yes' : 'no');
- next if ($seen{$partid} > 0);
- $seen{$partid}++;
- push @partlist,$partid;
- }
- }
- return \@partlist,\%handgrade;
-}
-
-#--- Show resource title
-#--- and parts and response type
-sub showResourceInfo {
- my ($url,$probTitle) = @_;
- my $result ='
'.
- '
Current Resource: '.$probTitle.'
'."\n";
- my ($partlist,$handgrade) = &response_type($url);
- my %resptype = (); #,$hdgrade)=('','no');
- my $hdgrade='no';
- for (sort keys(%$handgrade)) {
- my ($responsetype,$handgrade)=split(/:/,$$handgrade{$_});
- my $partID = (split(/_/))[0];
- $resptype{$partID} = $responsetype;
- $hdgrade = $handgrade if ($handgrade eq 'yes');
- $result.='
'."\n";
- return $result,\%resptype,$hdgrade,$partlist,$handgrade;
+ my $res = $navmap->getBySymb($symb);
+ unless (ref($res)) {
+ $$response_error = 1;
+ return;
+ }
+ my $partlist = $res->parts();
+ my %vPart =
+ map { $_ => 1 } (&Apache::loncommon::get_env_multiple('form.vPart'));
+ my (%response_types,%handgrade);
+ foreach my $part (@{ $partlist }) {
+ next if (%vPart && !exists($vPart{$part}));
+
+ my @types = $res->responseType($part);
+ my @ids = $res->responseIds($part);
+ for (my $i=0; $i < scalar(@ids); $i++) {
+ $response_types{$part}{$ids[$i]} = $types[$i];
+ $handgrade{$part.'_'.$ids[$i]} =
+ &Apache::lonnet::EXT('resource.'.$part.'_'.$ids[$i].
+ '.handgrade',$symb);
+ }
+ }
+ return ($partlist,\%handgrade,\%response_types);
+}
+
+sub flatten_responseType {
+ my ($responseType) = @_;
+ my @part_response_id =
+ map {
+ my $part = $_;
+ map {
+ [$part,$_]
+ } sort(keys(%{ $responseType->{$part} }));
+ } sort(keys(%$responseType));
+ return @part_response_id;
+}
+
+sub get_display_part {
+ my ($partID,$symb)=@_;
+ my $display=&Apache::lonnet::EXT('resource.'.$partID.'.display',$symb);
+ if (defined($display) and $display ne '') {
+ $display.= ' ('
+ .&mt('Part ID: [_1]',$partID).')';
+ } else {
+ $display=$partID;
+ }
+ return $display;
+}
+
+sub reset_caches {
+ &reset_analyze_cache();
+ &reset_perm();
+}
+
+{
+ my %analyze_cache;
+ my %analyze_cache_formkeys;
+
+ sub reset_analyze_cache {
+ undef(%analyze_cache);
+ undef(%analyze_cache_formkeys);
+ }
+
+ sub get_analyze {
+ my ($symb,$uname,$udom,$no_increment,$add_to_hash)=@_;
+ my $key = "$symb\0$uname\0$udom";
+ if (exists($analyze_cache{$key})) {
+ my $getupdate = 0;
+ if (ref($add_to_hash) eq 'HASH') {
+ foreach my $item (keys(%{$add_to_hash})) {
+ if (ref($analyze_cache_formkeys{$key}) eq 'HASH') {
+ if (!exists($analyze_cache_formkeys{$key}{$item})) {
+ $getupdate = 1;
+ last;
+ }
+ } else {
+ $getupdate = 1;
+ }
+ }
+ }
+ if (!$getupdate) {
+ return $analyze_cache{$key};
+ }
+ }
+
+ my (undef,undef,$url)=&Apache::lonnet::decode_symb($symb);
+ $url=&Apache::lonnet::clutter($url);
+ my %form = ('grade_target' => 'analyze',
+ 'grade_domain' => $udom,
+ 'grade_symb' => $symb,
+ 'grade_courseid' => $env{'request.course.id'},
+ 'grade_username' => $uname,
+ 'grade_noincrement' => $no_increment);
+ if (ref($add_to_hash)) {
+ %form = (%form,%{$add_to_hash});
+ }
+ my $subresult=&ssi_with_retries($url, $ssi_retries,%form);
+ (undef,$subresult)=split(/_HASH_REF__/,$subresult,2);
+ my %analyze=&Apache::lonnet::str2hash($subresult);
+ if (ref($add_to_hash) eq 'HASH') {
+ $analyze_cache_formkeys{$key} = $add_to_hash;
+ } else {
+ $analyze_cache_formkeys{$key} = {};
+ }
+ return $analyze_cache{$key} = \%analyze;
+ }
+
+ sub get_order {
+ my ($partid,$respid,$symb,$uname,$udom,$no_increment)=@_;
+ my $analyze = &get_analyze($symb,$uname,$udom,$no_increment);
+ return $analyze->{"$partid.$respid.shown"};
+ }
+
+ sub get_radiobutton_correct_foil {
+ my ($partid,$respid,$symb,$uname,$udom)=@_;
+ my $analyze = &get_analyze($symb,$uname,$udom);
+ my $foils = &get_order($partid,$respid,$symb,$uname,$udom);
+ if (ref($foils) eq 'ARRAY') {
+ foreach my $foil (@{$foils}) {
+ if ($analyze->{"$partid.$respid.foil.value.$foil"} eq 'true') {
+ return $foil;
+ }
+ }
+ }
+ }
+
+ sub scantron_partids_tograde {
+ my ($resource,$cid,$uname,$udom,$check_for_randomlist) = @_;
+ my (%analysis,@parts);
+ if (ref($resource)) {
+ my $symb = $resource->symb();
+ my $add_to_form;
+ if ($check_for_randomlist) {
+ $add_to_form = { 'check_parts_withrandomlist' => 1,};
+ }
+ my $analyze = &get_analyze($symb,$uname,$udom,undef,$add_to_form);
+ if (ref($analyze) eq 'HASH') {
+ %analysis = %{$analyze};
+ }
+ if (ref($analysis{'parts'}) eq 'ARRAY') {
+ foreach my $part (@{$analysis{'parts'}}) {
+ my ($id,$respid) = split(/\./,$part);
+ if (!&Apache::loncommon::check_if_partid_hidden($id,$symb,$udom,$uname)) {
+ push(@parts,$part);
+ }
+ }
+ }
+ }
+ return (\%analysis,\@parts);
+ }
+
}
#--- Clean response type for display
-#--- Currently filters option response type only.
+#--- Currently filters option/rank/radiobutton/match/essay/Task
+# response types only.
sub cleanRecord {
- my ($answer,$response,$symb) = @_;
- if ($response eq 'option') {
- my (@IDs,@ans);
- foreach (split(/\&/,&Apache::lonnet::unescape($answer))) {
- my ($optionID,$ans) = split(/=/);
- push @IDs,$optionID.'';
- push @ans,$ans;
- }
- my $grayFont = '';
- return '
'.
- '
Answer
'.
- (join '
',@ans).'
'.
- '
'.$grayFont.'Option ID
'.$grayFont.
- (join '
'.$grayFont,@IDs).'
'.
- '
';
- }
- if ($response eq 'essay') {
- if (! exists ($ENV{'form.'.$symb})) {
+ my ($answer,$response,$symb,$partid,$respid,$record,$order,$version,
+ $uname,$udom) = @_;
+ my $grayFont = '';
+ if ($response =~ /^(option|rank)$/) {
+ my %answer=&Apache::lonnet::str2hash($answer);
+ my %grading=&Apache::lonnet::str2hash($record->{$version."resource.$partid.$respid.submissiongrading"});
+ my ($toprow,$bottomrow);
+ foreach my $foil (@$order) {
+ if ($grading{$foil} == 1) {
+ $toprow.='
'.$answer{$foil}.'
';
+ } else {
+ $toprow.='
'.$answer{$foil}.'
';
+ }
+ $bottomrow.='
'.$grayFont.$foil.'
';
+ }
+ return '
'.
+ '
'.&mt('Answer').'
'.$toprow.'
'.
+ '
'.$grayFont.&mt('Option ID').'
'.
+ $grayFont.$bottomrow.'
'.'
';
+ } elsif ($response eq 'match') {
+ my %answer=&Apache::lonnet::str2hash($answer);
+ my %grading=&Apache::lonnet::str2hash($record->{$version."resource.$partid.$respid.submissiongrading"});
+ my @items=&Apache::lonnet::str2array($record->{$version."resource.$partid.$respid.submissionitems"});
+ my ($toprow,$middlerow,$bottomrow);
+ foreach my $foil (@$order) {
+ my $item=shift(@items);
+ if ($grading{$foil} == 1) {
+ $toprow.='
'.$item.'
';
+ $middlerow.='
'.$grayFont.$answer{$foil}.'
';
+ } else {
+ $toprow.='
'.$item.'
';
+ $middlerow.='
'.$grayFont.$answer{$foil}.'
';
+ }
+ $bottomrow.='
'.$grayFont.$foil.'
';
+ }
+ return '
'.
+ '
'.&mt('Answer').'
'.$toprow.'
'.
+ '
'.$grayFont.&mt('Item ID').'
'.
+ $middlerow.'
'.
+ '
'.$grayFont.&mt('Option ID').'
'.
+ $bottomrow.'
'.'
';
+ } elsif ($response eq 'radiobutton') {
+ my %answer=&Apache::lonnet::str2hash($answer);
+ my ($toprow,$bottomrow);
+ my $correct =
+ &get_radiobutton_correct_foil($partid,$respid,$symb,$uname,$udom);
+ foreach my $foil (@$order) {
+ if (exists($answer{$foil})) {
+ if ($foil eq $correct) {
+ $toprow.='
'.&mt('true').'
';
+ } else {
+ $toprow.='
'.&mt('true').'
';
+ }
+ } else {
+ $toprow.='
'.&mt('false').'
';
+ }
+ $bottomrow.='
'.$grayFont.$foil.'
';
+ }
+ return '
'.
+ '
'.&mt('Answer').'
'.$toprow.'
'.
+ '
'.$grayFont.&mt('Option ID').'
'.
+ $bottomrow.'
'.'
';
+ } elsif ($response eq 'essay') {
+ if (! exists ($env{'form.'.$symb})) {
my (%keyhash) = &Apache::lonnet::dump('nohist_handgrade',
- $ENV{'course.'.$ENV{'request.course.id'}.'.domain'},
- $ENV{'course.'.$ENV{'request.course.id'}.'.num'});
+ $env{'course.'.$env{'request.course.id'}.'.domain'},
+ $env{'course.'.$env{'request.course.id'}.'.num'});
- my $loginuser = $ENV{'user.name'}.':'.$ENV{'user.domain'};
- $ENV{'form.keywords'} = $keyhash{$symb.'_keywords'} ne '' ? $keyhash{$symb.'_keywords'} : '';
- $ENV{'form.kwclr'} = $keyhash{$loginuser.'_kwclr'} ne '' ? $keyhash{$loginuser.'_kwclr'} : 'red';
- $ENV{'form.kwsize'} = $keyhash{$loginuser.'_kwsize'} ne '' ? $keyhash{$loginuser.'_kwsize'} : '0';
- $ENV{'form.kwstyle'} = $keyhash{$loginuser.'_kwstyle'} ne '' ? $keyhash{$loginuser.'_kwstyle'} : '';
- $ENV{'form.'.$symb} = 1; # so that we don't have to read it from disk for multiple sub of the same prob.
- }
- return &keywords_highlight($answer);
+ my $loginuser = $env{'user.name'}.':'.$env{'user.domain'};
+ $env{'form.keywords'} = $keyhash{$symb.'_keywords'} ne '' ? $keyhash{$symb.'_keywords'} : '';
+ $env{'form.kwclr'} = $keyhash{$loginuser.'_kwclr'} ne '' ? $keyhash{$loginuser.'_kwclr'} : 'red';
+ $env{'form.kwsize'} = $keyhash{$loginuser.'_kwsize'} ne '' ? $keyhash{$loginuser.'_kwsize'} : '0';
+ $env{'form.kwstyle'} = $keyhash{$loginuser.'_kwstyle'} ne '' ? $keyhash{$loginuser.'_kwstyle'} : '';
+ $env{'form.'.$symb} = 1; # so that we don't have to read it from disk for multiple sub of the same prob.
+ }
+ $answer =~ s-\n- -g;
+ return '
';
+ my @grade = grep(/^\Q${version}resource.$respid.$partid.\E[^.]*[.]status$/,
+ keys(%{$record}));
+ foreach my $grade (sort(@grade)) {
+ my ($dim) = ($grade =~/[.]([^.]+)[.]status$/);
+ $result.= '
'.&mt("Dimension: [_1], status [_2] ",
+ $dim, $record->{$grade}).
+ '
';
+ }
+ $result.='
';
+ return $result;
+ }
+ } elsif ( $response =~ m/(?:numerical|formula)/) {
+ $answer =
+ &Apache::loncommon::format_previous_attempt_value('submission',
+ $answer);
}
return $answer;
}
@@ -178,8 +426,7 @@ sub cleanRecord {
#-- A couple of common js functions
sub commonJSfunctions {
my $request = shift;
- $request->print(<
+ $request->print(&Apache::lonhtmlcommon::scripttag(< 1) {
@@ -203,45 +450,96 @@ sub commonJSfunctions {
}
}
} else {
- if (selectOne.selected) return selectOne.value;
+ // only one value it must be the selected one
+ return selectOne.value;
}
}
-
COMMONJSFUNCTIONS
}
#--- Dumps the class list with usernames,list of sections,
#--- section, ids and fullnames for each user.
sub getclasslist {
- my ($getsec,$filterlist) = @_;
- $getsec = $getsec eq '' ? 'all' : $getsec;
- my $classlist=&Apache::loncoursedata::get_classlist();
+ my ($getsec,$filterlist,$getgroup) = @_;
+ my @getsec;
+ my @getgroup;
+ my $stu_status = join(':',&Apache::loncommon::get_env_multiple('form.Status'));
+ if (!ref($getsec)) {
+ if ($getsec ne '' && $getsec ne 'all') {
+ @getsec=($getsec);
+ }
+ } else {
+ @getsec=@{$getsec};
+ }
+ if (grep(/^all$/,@getsec)) { undef(@getsec); }
+ if (!ref($getgroup)) {
+ if ($getgroup ne '' && $getgroup ne 'all') {
+ @getgroup=($getgroup);
+ }
+ } else {
+ @getgroup=@{$getgroup};
+ }
+ if (grep(/^all$/,@getgroup)) { undef(@getgroup); }
+
+ my ($classlist,$keylist)=&Apache::loncoursedata::get_classlist();
# Bail out if we were unable to get the classlist
return if (! defined($classlist));
+ &Apache::loncoursedata::get_group_memberships($classlist,$keylist);
#
my %sections;
my %fullnames;
- foreach (keys(%$classlist)) {
- # the following undefs are for 'domain', and 'username' respectively.
- my (undef,undef,$end,$start,$id,$section,$fullname,$status)=
- @{$classlist->{$_}};
+ foreach my $student (keys(%$classlist)) {
+ my $end =
+ $classlist->{$student}->[&Apache::loncoursedata::CL_END()];
+ my $start =
+ $classlist->{$student}->[&Apache::loncoursedata::CL_START()];
+ my $id =
+ $classlist->{$student}->[&Apache::loncoursedata::CL_ID()];
+ my $section =
+ $classlist->{$student}->[&Apache::loncoursedata::CL_SECTION()];
+ my $fullname =
+ $classlist->{$student}->[&Apache::loncoursedata::CL_FULLNAME()];
+ my $status =
+ $classlist->{$student}->[&Apache::loncoursedata::CL_STATUS()];
+ my $group =
+ $classlist->{$student}->[&Apache::loncoursedata::CL_GROUP()];
# filter students according to status selected
- if ($filterlist && $ENV{'form.Status'} ne 'Any') {
- if ($ENV{'form.Status'} ne $status) {
- delete ($classlist->{$_});
+ if ($filterlist && (!($stu_status =~ /Any/))) {
+ if (!($stu_status =~ $status)) {
+ delete($classlist->{$student});
next;
}
}
- $section = ($section ne '' ? $section : 'no');
+ # filter students according to groups selected
+ my @stu_groups = split(/,/,$group);
+ if (@getgroup) {
+ my $exclude = 1;
+ foreach my $grp (@getgroup) {
+ foreach my $stu_group (@stu_groups) {
+ if ($stu_group eq $grp) {
+ $exclude = 0;
+ }
+ }
+ if (($grp eq 'none') && !$group) {
+ $exclude = 0;
+ }
+ }
+ if ($exclude) {
+ delete($classlist->{$student});
+ }
+ }
+ $section = ($section ne '' ? $section : 'none');
if (&canview($section)) {
- if ($getsec eq 'all' || $getsec eq $section) {
+ if (!@getsec || grep(/^\Q$section\E$/,@getsec)) {
$sections{$section}++;
- $fullnames{$_}=$fullname;
+ if ($classlist->{$student}) {
+ $fullnames{$student}=$fullname;
+ }
} else {
- delete($classlist->{$_});
+ delete($classlist->{$student});
}
} else {
- delete($classlist->{$_});
+ delete($classlist->{$student});
}
}
my %seen = ();
@@ -291,11 +589,11 @@ sub canview {
#--- Retrieve the grade status of a student for all the parts
sub student_gradeStatus {
- my ($url,$symb,$udom,$uname,$partlist) = @_;
- my %record = &Apache::lonnet::restore($symb,$ENV{'request.course.id'},$udom,$uname);
+ my ($symb,$udom,$uname,$partlist) = @_;
+ my %record = &Apache::lonnet::restore($symb,$env{'request.course.id'},$udom,$uname);
my %partstatus = ();
foreach (@$partlist) {
- my ($status,$foo) = split(/_/,$record{"resource.$_.solved"},2);
+ my ($status,undef) = split(/_/,$record{"resource.$_.solved"},2);
$status = 'nothing' if ($status eq '');
$partstatus{$_} = $status;
my $subkey = "resource.$_.submitted_by";
@@ -308,19 +606,19 @@ sub student_gradeStatus {
# Use by verifyscript and viewgrades
# Shows a student's view of problem and submission
sub jscriptNform {
- my ($url,$symb) = @_;
- my $jscript=''."\n";
+ "\n");
$jscript.= '\n";
+}
+
#--- Check whether a receipt number is valid.---
sub verifyreceipt {
- my $request = shift;
+ my ($request,$symb) = @_;
- my $courseid = $ENV{'request.course.id'};
- my $receipt = unpack("%32C*",$Apache::lonnet::perlvar{'lonHostID'}).'-'.
- $ENV{'form.receipt'};
+ my $courseid = $env{'request.course.id'};
+ my $receipt = &Apache::lonnet::recprefix($courseid).'-'.
+ $env{'form.receipt'};
$receipt =~ s/[^\-\d]//g;
- my $url = $ENV{'form.url'};
- my $symb = $ENV{'form.symb'};
- unless ($symb) {
- $symb = &Apache::lonnet::symbread($url);
- }
- my $title.='
Verifying Submission Receipt '.
- $receipt.'
'."\n".
- 'Resource: '.$ENV{'form.probTitle'}.'
'."\n";
+ my $title.=
+ '
'.
+ &mt('Verifying Receipt Number [_1]',$receipt).
+ '
'."\n";
my ($string,$contents,$matches) = ('','',0);
my (undef,undef,$fullname) = &getclasslist('all','0');
-
- foreach (sort {lc($$fullname{$a}) cmp lc($$fullname{$b}) } keys %$fullname) {
+
+ my $receiptparts=0;
+ if ($env{"course.$courseid.receiptalg"} eq 'receipt2' ||
+ $env{"course.$courseid.receiptalg"} eq 'receipt3') { $receiptparts=1; }
+ my $parts=['0'];
+ if ($receiptparts) {
+ my $res_error;
+ ($parts)=&response_type($symb,\$res_error);
+ if ($res_error) {
+ return &navmap_errormsg();
+ }
+ }
+
+ my $header =
+ &Apache::loncommon::start_data_table().
+ &Apache::loncommon::start_data_table_header_row().
+ '
'.
+ &mt('The above receipt number matches the following [quant,_1,student].',$matches).
+ '
'.
+ $header.
$contents.
- '
'."\n";
+ &Apache::loncommon::end_data_table()."\n";
}
- return $string.&show_grading_menu_form($symb,$url);
+ return $string.&show_grading_menu_form($symb);
}
#--- This is called by a number of programs.
@@ -433,26 +809,28 @@ sub verifyreceipt {
#--- Also called directly when one clicks on the subm button
# on the problem page.
sub listStudents {
- my ($request) = shift;
-
- my ($symb,$url) = &get_symb_and_url($request);
- my $cdom = $ENV{"course.$ENV{'request.course.id'}.domain"};
- my $cnum = $ENV{"course.$ENV{'request.course.id'}.num"};
- my $getsec = $ENV{'form.section'} eq '' ? 'all' : $ENV{'form.section'};
- my $submitonly= $ENV{'form.submitonly'} eq '' ? 'all' : $ENV{'form.submitonly'};
-
- my $viewgrade = $ENV{'form.showgrading'} eq 'yes' ? 'View/Grade/Regrade' : 'View';
- $ENV{'form.probTitle'} = $ENV{'form.probTitle'} eq '' ?
- &Apache::lonnet::gettitle($symb) : $ENV{'form.probTitle'};
-
- my $result='
'.$viewgrade.
- ' Submissions for a Student or a Group of Students
';
+ my ($request,$symb) = @_;
- my ($table,undef,$hdgrade,$partlist,$handgrade) = &showResourceInfo($url,$ENV{'form.probTitle'});
- $result.=$table;
-
- $request->print(<
+ my $cdom = $env{"course.$env{'request.course.id'}.domain"};
+ my $cnum = $env{"course.$env{'request.course.id'}.num"};
+ my $getsec = $env{'form.section'} eq '' ? 'all' : $env{'form.section'};
+ my $getgroup = $env{'form.group'} eq '' ? 'all' : $env{'form.group'};
+ my $submitonly= $env{'form.submitonly'} eq '' ? 'all' : $env{'form.submitonly'};
+ my $viewgrade = $env{'form.showgrading'} eq 'yes' ? 'View/Grade/Regrade' : 'View';
+
+ my $result='
'
+ .&mt("$viewgrade Submissions for a Student or a Group of Students")
+ .'
';
+
+ my ($partlist,$handgrade,$responseType) = &response_type($symb
+#,$res_error
+ );
+
+ my %lt = &Apache::lonlocal::texthash (
+ 'multiple' => 'Please select a student or group of students before clicking on the Next button.',
+ 'single' => 'Please select the student before clicking on the Next button.',
+ );
+ $request->print(&Apache::lonhtmlcommon::scripttag(<
LISTJAVASCRIPT
&commonJSfunctions($request);
$request->print($result);
- my $checkhdgrade = ($ENV{'form.handgrade'} eq 'yes' && scalar(@$partlist) > 1 ) ? 'checked' : '';
- my $checklastsub = $checkhdgrade eq '' ? 'checked' : '';
- my $gradeTable=''."\n";
+ $gradeTable.=&Apache::loncommon::end_data_table()."\n".
+ ''."\n";
if ($ctr == 0) {
my $num_students=(scalar(keys(%$fullname)));
if ($num_students eq 0) {
- $gradeTable=' There are no students currently enrolled.';
+ $gradeTable=' '.&mt('There are no students currently enrolled.').'';
} else {
- $gradeTable=' '.
- 'No submissions found for this resource for any students. ('.$num_students.
- ' checked for submissions ';
+ my $submissions='submissions';
+ if ($submitonly eq 'incorrect') { $submissions = 'incorrect submissions'; }
+ if ($submitonly eq 'graded' ) { $submissions = 'ungraded submissions'; }
+ if ($submitonly eq 'queued' ) { $submissions = 'queued submissions'; }
+ $gradeTable=' '.
+ &mt('No '.$submissions.' found for this resource for any students. ([_1] students checked for '.$submissions.')',
+ $num_students).
+ ' ';
}
} elsif ($ctr == 1) {
- $gradeTable =~ s/type=checkbox/type=checkbox checked/;
+ $gradeTable =~ s/type="checkbox"/type="checkbox" checked="checked"/;
}
- $gradeTable.=&show_grading_menu_form($symb,$url);
+ $gradeTable.=&show_grading_menu_form($symb);
$request->print($gradeTable);
return '';
}
#---- Called from the listStudents routine
+
+sub check_script {
+ my ($form, $type)=@_;
+ my $chkallscript= &Apache::lonhtmlcommon::scripttag('
+ function checkall() {
+ for (i=0; i0) {
+ document.forms.'.$form.'.elements[i].checked=true;
+ }
+ }
+ }
+
+
+ function uncheckall() {
+ for (i=0; i';
+ $buttons.=' ';
+ $buttons.='';
+ $buttons.=' ';
+ return $buttons;
+}
+
# Displays the submissions for one student or a group of students
sub processGroup {
my ($request) = shift;
my $ctr = 0;
- my @stuchecked = (ref($ENV{'form.stuinfo'}) ? @{$ENV{'form.stuinfo'}}
- : ($ENV{'form.stuinfo'}));
+ my @stuchecked = &Apache::loncommon::get_env_multiple('form.stuinfo');
my $total = scalar(@stuchecked)-1;
- foreach (@stuchecked) {
- my ($uname,$udom,$fullname) = split(/:/);
- $ENV{'form.student'} = $uname;
- $ENV{'form.userdom'} = $udom;
- $ENV{'form.fullname'} = $fullname;
+ foreach my $student (@stuchecked) {
+ my ($uname,$udom,$fullname) = split(/:/,$student);
+ $env{'form.student'} = $uname;
+ $env{'form.userdom'} = $udom;
+ $env{'form.fullname'} = $fullname;
&submission($request,$ctr,$total);
$ctr++;
}
@@ -638,17 +1162,17 @@ sub processGroup {
#--- Javascript to handle the submission page functionality ---
sub sub_page_js {
my $request = shift;
- $request->print(<
+ my $alertmsg = &mt('A number equal or greater than 0 is expected. Entered value = ');
+ $request->print(&Apache::lonhtmlcommon::scripttag(<
SUBJAVASCRIPT
}
@@ -819,8 +1339,81 @@ sub sub_page_kw_js {
my $request = shift;
my $iconpath = $request->dir_config('lonIconsURL');
&commonJSfunctions($request);
- $request->print(<
+
+ my $inner_js_msg_central= &Apache::lonhtmlcommon::scripttag(< 1,
+ 'only_body' => 1,
+ 'bgcolor' =>'#FFFFFF',});
+ my $end_page_msg_central =
+ &Apache::loncommon::end_page({'js_ready' => 1});
+
+
+ my $start_page_highlight_central =
+ &Apache::loncommon::start_page('Highlight Central',
+ $inner_js_highlight_central,
+ {'js_ready' => 1,
+ 'only_body' => 1,
+ 'bgcolor' =>'#FFFFFF',});
+ my $end_page_highlight_central =
+ &Apache::loncommon::end_page({'js_ready' => 1});
+
+ my $docopen=&Apache::lonhtmlcommon::javascript_docopen();
+ $docopen=~s/^document\.//;
+ my $alertmsg = &mt('Please select a word or group of words from document and then click this link.');
+ $request->print(&Apache::lonhtmlcommon::scripttag(<", '"'];
+ var newStr = ["&", "<", ">", """];
+ var counter = 0;
+ while (counter < 4) {
+ strx = strReplace(strx,orgStr[counter],newStr[counter]);
+ counter++;
+ }
+ return strx;
+ }
+
+ function strReplace(strx, orgStr, newStr) {
+ return strx.split(orgStr).join(newStr);
+ }
+
function savedMsgHeader(Nmsg,usrctr,fullname) {
var height = 70*Nmsg+250;
var scrollbar = "no";
@@ -906,99 +1516,58 @@ sub sub_page_kw_js {
height = 600;
scrollbar = "yes";
}
-// if (window.pWin) {window.pWin.close(); window.pWin=null}
var xpos = (screen.width-600)/2;
xpos = (xpos < 0) ? '0' : xpos;
var ypos = (screen.height-height)/2-30;
ypos = (ypos < 0) ? '0' : ypos;
- pWin = window.open('', 'MessageCenter', 'toolbar=no,location=no,scrollbars='+scrollbar+',screenx='+xpos+',screeny='+ypos+',width=600,height='+height);
+ pWin = window.open('', 'MessageCenter', 'resizable=yes,toolbar=no,location=no,scrollbars='+scrollbar+',screenx='+xpos+',screeny='+ypos+',width=600,height='+height);
pWin.focus();
pDoc = pWin.document;
- pDoc.write("");
- pDoc.write("Message Central");
-
- pDoc.write("
SUBJAVASCRIPT
}
+sub get_increment {
+ my $increment = $env{'form.increment'};
+ if ($increment != 1 && $increment != .5 && $increment != .25 &&
+ $increment != .1) {
+ $increment = 1;
+ }
+ return $increment;
+}
+
+sub gradeBox_start {
+ return (
+ &Apache::loncommon::start_data_table()
+ .&Apache::loncommon::start_data_table_header_row()
+ .'
'.&mt('Part').'
'
+ .'
'.&mt('Points').'
'
+ .'
'
+ .'
'.&mt('Assign Grade').'
'
+ .'
'.&mt('Weight').'
'
+ .'
'.&mt('Grade Status').'
'
+ .&Apache::loncommon::end_data_table_header_row()
+ );
+}
+
+sub gradeBox_end {
+ return (
+ &Apache::loncommon::end_data_table()
+ );
+}
#--- displays the grading box, used in essay type problem and grading by page/sequence
sub gradeBox {
my ($request,$symb,$uname,$udom,$counter,$partid,$record) = @_;
-
- my $checkIcon = '';
-
+ my $checkIcon = '';
my $wgt = &Apache::lonnet::EXT('resource.'.$partid.'.weight',$symb,$udom,$uname);
- my $wgtmsg = ($wgt > 0 ? '(problem weight)' :
- 'problem weight assigned by computer');
+ my $wgtmsg = ($wgt > 0) ? &mt('(problem weight)')
+ : ''.&mt('problem weight assigned by computer').'';
$wgt = ($wgt > 0 ? $wgt : '1');
my $score = ($$record{'resource.'.$partid.'.awarded'} eq '' ?
- '' : $$record{'resource.'.$partid.'.awarded'}*$wgt);
+ '' : &compute_points($$record{'resource.'.$partid.'.awarded'},$wgt));
my $result=''."\n";
-
- $result.='
'.
- 'Part '.$partid.' Points:
'."\n";
-
+ my $display_part= &get_display_part($partid,$symb);
+ my %last_resets = &get_last_resets($symb,$env{'request.course.id'},
+ [$partid]);
+ my $aggtries = $$record{'resource.'.$partid.'.tries'};
+ if ($last_resets{$partid}) {
+ $aggtries = &get_num_tries($record,$last_resets{$partid},$partid);
+ }
+ $result.=&Apache::loncommon::start_data_table_row();
my $ctr = 0;
- $result.='
'."\n"; # display radio buttons in a nice table 10 across
- while ($ctr<=$wgt) {
- $result.= '
'.$ctr."
\n";
- $result.=(($ctr+1)%10 == 0 ? '
' : '');
+ my $thisweight = 0;
+ my $increment = &get_increment();
+
+ my $radio.='
'."\n"; # display radio buttons in a nice table 10 across
+ while ($thisweight<=$wgt) {
+ $radio.= '
';
return $result;
}
+sub files_exist {
+ my ($r, $symb) = @_;
+ my @students = &Apache::loncommon::get_env_multiple('form.stuinfo');
+
+ foreach my $student (@students) {
+ my ($uname,$udom,$fullname) = split(/:/,$student);
+ my %record = &Apache::lonnet::restore($symb,$env{'request.course.id'},
+ $udom,$uname);
+ my ($string,$timestamp)= &get_last_submission(\%record);
+ foreach my $submission (@$string) {
+ my ($partid,$respid) =
+ ($submission =~ /^resource\.([^\.]*)\.([^\.]*)\.submission/);
+ my $files=&get_submitted_files($udom,$uname,$partid,$respid,
+ \%record);
+ return 1 if (@$files);
+ }
+ }
+ return 0;
+}
+
+sub download_all_link {
+ my ($r,$symb) = @_;
+ my $all_students =
+ join("\n", &Apache::loncommon::get_env_multiple('form.stuinfo'));
+
+ my $parts =
+ join("\n",&Apache::loncommon::get_env_multiple('form.vPart'));
+
+ my $identifier = &Apache::loncommon::get_cgi_id();
+ &Apache::lonnet::appenv({'cgi.'.$identifier.'.students' => $all_students,
+ 'cgi.'.$identifier.'.symb' => $symb,
+ 'cgi.'.$identifier.'.parts' => $parts,});
+ $r->print(''.
+ &mt('Download All Submitted Documents').'');
+ return
+}
+
+sub build_section_inputs {
+ my $section_inputs;
+ if ($env{'form.section'} eq '') {
+ $section_inputs .= ''."\n";
+ } else {
+ my @sections = &Apache::loncommon::get_env_multiple('form.section');
+ foreach my $section (@sections) {
+ $section_inputs .= ''."\n";
+ }
+ }
+ return $section_inputs;
+}
+
# --------------------------- show submissions of a student, option to grade
sub submission {
- my ($request,$counter,$total) = @_;
-
- (my $url=$ENV{'form.url'})=~s-^http://($ENV{'SERVER_NAME'}|$ENV{'HTTP_HOST'})--;
- my ($uname,$udom) = ($ENV{'form.student'},$ENV{'form.userdom'});
- $udom = ($udom eq '' ? $ENV{'user.domain'} : $udom); #has form.userdom changed for a student?
- my $usec = &Apache::lonnet::getsection($udom,$uname,$ENV{'request.course.id'});
- $ENV{'form.fullname'} = &get_fullname ($uname,$udom) if $ENV{'form.fullname'} eq '';
+ my ($request,$counter,$total,$symb) = @_;
+ my ($uname,$udom) = ($env{'form.student'},$env{'form.userdom'});
+ $udom = ($udom eq '' ? $env{'user.domain'} : $udom); #has form.userdom changed for a student?
+ my $usec = &Apache::lonnet::getsection($udom,$uname,$env{'request.course.id'});
+ $env{'form.fullname'} = &Apache::loncommon::plainname($uname,$udom,'lastname') if $env{'form.fullname'} eq '';
- my $symb=($ENV{'form.symb'} ne '' ? $ENV{'form.symb'} : (&Apache::lonnet::symbread($url)));
- if ($symb eq '') { $request->print("Unable to handle ambiguous references:$url:."); return ''; }
+ my $probtitle=&Apache::lonnet::gettitle($symb);
+ if ($symb eq '') { $request->print("Unable to handle ambiguous references:."); return ''; }
if (!&canview($usec)) {
- $request->print('Unable to view requested student.('.
- $uname.$udom.$usec.$ENV{'request.course.id'}.')');
- $request->print(&show_grading_menu_form($symb,$url));
+ $request->print('Unable to view requested student.('.
+ $uname.':'.$udom.' in section '.$usec.' in course id '.
+ $env{'request.course.id'}.')');
+ $request->print(&show_grading_menu_form($symb));
return;
}
- $ENV{'form.lastSub'} = ($ENV{'form.lastSub'} eq '' ? 'datesub' : $ENV{'form.lastSub'});
- my $last = ($ENV{'form.lastSub'} eq 'last' ? 'last' : '');
- my $checkIcon = '';
+ my %old_essays;
# header info
if ($counter == 0) {
&sub_page_js($request);
- &sub_page_kw_js($request) if ($ENV{'form.handgrade'} eq 'yes');
- $ENV{'form.probTitle'} = $ENV{'form.probTitle'} eq '' ?
- &Apache::lonnet::gettitle($symb) : $ENV{'form.probTitle'};
-
- $request->print('
Submission Record
'."\n".
- ' Resource: '.$ENV{'form.probTitle'}.''."\n");
-
- if ($ENV{'form.handgrade'} eq 'no') {
- my $checkMark='
Note: Part(s) graded correct by the computer is marked with a '.
- $checkIcon.' symbol.'."\n";
- $request->print($checkMark);
+ &sub_page_kw_js($request) if ($env{'form.handgrade'} eq 'yes');
+ if ($env{'form.handgrade'} eq 'yes' && &files_exist($request, $symb)) {
+ &download_all_link($request, $symb);
}
+ $request->print('
'.&mt('Submission Record').'
');
# option to display problem, only once else it cause problems
# with the form later since the problem has a form.
- if ($ENV{'form.vProb'} eq 'yes' or !$ENV{'form.vProb'}) {
- $request->print(&show_problem($request,$symb,$uname,$udom,0,1));
+ if ($env{'form.vProb'} eq 'yes' or $env{'form.vAns'} eq 'yes') {
+ my $mode;
+ if ($env{'form.vProb'} eq 'yes' && $env{'form.vAns'} eq 'yes') {
+ $mode='both';
+ } elsif ($env{'form.vProb'} eq 'yes') {
+ $mode='text';
+ } elsif ($env{'form.vAns'} eq 'yes') {
+ $mode='answer';
+ }
+ &Apache::lonxml::clear_problem_counter();
+ $request->print(&show_problem($request,$symb,$uname,$udom,0,1,$mode));
}
-
+
# kwclr is the only variable that is guaranteed to be non blank
# if this subroutine has been called once.
my %keyhash = ();
- if ($ENV{'form.kwclr'} eq '' && $ENV{'form.handgrade'} eq 'yes') {
+ if ($env{'form.kwclr'} eq '' && $env{'form.handgrade'} eq 'yes') {
%keyhash = &Apache::lonnet::dump('nohist_handgrade',
- $ENV{'course.'.$ENV{'request.course.id'}.'.domain'},
- $ENV{'course.'.$ENV{'request.course.id'}.'.num'});
-
- my $loginuser = $ENV{'user.name'}.':'.$ENV{'user.domain'};
- $ENV{'form.keywords'} = $keyhash{$symb.'_keywords'} ne '' ? $keyhash{$symb.'_keywords'} : '';
- $ENV{'form.kwclr'} = $keyhash{$loginuser.'_kwclr'} ne '' ? $keyhash{$loginuser.'_kwclr'} : 'red';
- $ENV{'form.kwsize'} = $keyhash{$loginuser.'_kwsize'} ne '' ? $keyhash{$loginuser.'_kwsize'} : '0';
- $ENV{'form.kwstyle'} = $keyhash{$loginuser.'_kwstyle'} ne '' ? $keyhash{$loginuser.'_kwstyle'} : '';
- $ENV{'form.msgsub'} = $keyhash{$symb.'_subject'} ne '' ?
- $keyhash{$symb.'_subject'} : $ENV{'form.probTitle'};
- $ENV{'form.savemsgN'} = $keyhash{$symb.'_savemsgN'} ne '' ? $keyhash{$symb.'_savemsgN'} : '0';
+ $env{'course.'.$env{'request.course.id'}.'.domain'},
+ $env{'course.'.$env{'request.course.id'}.'.num'});
- }
- my $overRideScore = $ENV{'form.overRideScore'} eq '' ? 'no' : $ENV{'form.overRideScore'};
-
- $request->print(''.&show_grading_menu_form($symb);
+ }
+ $request->print($toGrade);
return;
+ } else {
+ $request->print(''."\n");
}
# essay grading message center
- if ($ENV{'form.handgrade'} eq 'yes') {
- my ($lastname,$givenn) = split(/,/,$ENV{'form.fullname'});
+ if ($env{'form.handgrade'} eq 'yes') {
+ my $result='
';
+
+ $result.='
'.
+ &mt('Send Message').'
';
+ my ($lastname,$givenn) = split(/,/,$env{'form.fullname'});
my $msgfor = $givenn.' '.$lastname;
- if (scalar(@col_fullnames) > 0) {
- my $lastone = pop @col_fullnames;
- $msgfor .= ', '.(join ', ',@col_fullnames).' and '.$lastone.'.';
+ if (scalar(@$col_fullnames) > 0) {
+ my $lastone = pop(@$col_fullnames);
+ $msgfor .= ', '.(join ', ',@$col_fullnames).' and '.$lastone.'.';
}
$msgfor =~ s/\'/\\'/g; #' stupid emacs - no! javascript
-# $result.='
'."\n".
- $result=''."\n".
+ $result.=''."\n".
''."\n";
$result.=' '.
- 'Compose Message to student'.(scalar(@col_fullnames) >= 1 ? 's' : '').' '.
+ ',\''.$msgfor.'\');" target="_self">'.
+ &mt('Compose message to student').(scalar(@$col_fullnames) >= 1 ? 's' : '').')'.
''."\n".
- ' (Message will be sent when you click on Save & Next below.)'."\n"
- if ($ENV{'form.handgrade'} eq 'yes');
+ ' ('.
+ &mt('Message will be sent when you click on Save & Next below.').")\n";
+ $result.='';
$request->print($result);
}
my %seen = ();
my @partlist;
- for (sort keys(%$handgrade)) {
- my ($partid,$respid) = split(/_/);
+ my @gradePartRespid;
+ my @part_response_id = &flatten_responseType($responseType);
+ $request->print(
+ '
'
+ .'
'.&mt('Assign Grades').'
'
+ );
+ $request->print(&gradeBox_start());
+ foreach my $part_response_id (@part_response_id) {
+ my ($partid,$respid) = @{ $part_response_id };
+ my $part_resp = join('_',@{ $part_response_id });
next if ($seen{$partid} > 0);
$seen{$partid}++;
- next if ($$handgrade{$_} =~ /:no$/ && $ENV{'form.lastSub'} =~ /^(hdgrade)$/);
- push @partlist,$partid;
-
+ next if ($$handgrade{$part_resp} ne 'yes'
+ && $env{'form.lastSub'} eq 'hdgrade');
+ push(@partlist,$partid);
+ push(@gradePartRespid,$partid.'.'.$respid);
$request->print(&gradeBox($request,$symb,$uname,$udom,$counter,$partid,\%record));
}
+ $request->print(&gradeBox_end()); #
+ $request->print('');
+
+ $request->print('
');
+ $request->print('
');
+
$result=''."\n";
+ $result.=''."\n" if ($counter == 0);
my $ctr = 0;
while ($ctr < scalar(@partlist)) {
$result.=''."\n";
$ctr++;
}
- $request->print($result.'
'."\n");
+ $request->print($result.''."\n");
+
+# Done with printing info for one student
+
+ $request->print('
');#LC_grade_show_user
+
# print end of form
if ($counter == $total) {
- my $endform='
'."\n";
- $endform.=' '."\n";
+ my $endform='
'."\n";
+ $endform.=' '."\n";
my $ntstu =''."\n";
- my $nsel = ($ENV{'form.NTSTU'} ne '' ? $ENV{'form.NTSTU'} : '1');
- $ntstu =~ s/
';
- $endform.=&show_grading_menu_form($symb,$url);
+ my $nsel = ($env{'form.NTSTU'} ne '' ? $env{'form.NTSTU'} : '1');
+ $ntstu =~ s/
';
+ $endform.=&show_grading_menu_form($symb);
$request->print($endform);
}
return '';
}
+sub check_collaborators {
+ my ($symb,$uname,$udom,$record,$handgrade,$counter) = @_;
+ my ($result,@col_fullnames);
+ my ($classlist,undef,$fullname) = &getclasslist('all','0');
+ foreach my $part (keys(%$handgrade)) {
+ my $ncol = &Apache::lonnet::EXT('resource.'.$part.
+ '.maxcollaborators',
+ $symb,$udom,$uname);
+ next if ($ncol <= 0);
+ $part =~ s/\_/\./g;
+ next if ($record->{'resource.'.$part.'.collaborators'} eq '');
+ my (@good_collaborators, @bad_collaborators);
+ foreach my $possible_collaborator
+ (split(/,?\s+/,$record->{'resource.'.$part.'.collaborators'})) {
+ $possible_collaborator =~ s/[\$\^\(\)]//g;
+ next if ($possible_collaborator eq '');
+ my ($co_name,$co_dom) = split(/\@|:/,$possible_collaborator);
+ $co_dom = $udom if (! defined($co_dom) || $co_dom =~ /^domain$/i);
+ next if ($co_name eq $uname && $co_dom eq $udom);
+ # Doing this grep allows 'fuzzy' specification
+ my @matches = grep(/^\Q$co_name\E:\Q$co_dom\E$/i,
+ keys(%$classlist));
+ if (! scalar(@matches)) {
+ push(@bad_collaborators, $possible_collaborator);
+ } else {
+ push(@good_collaborators, @matches);
+ }
+ }
+ if (scalar(@good_collaborators) != 0) {
+ $result.=' '.&mt('Collaborators: ');
+ foreach my $name (@good_collaborators) {
+ my ($lastname,$givenn) = split(/,/,$$fullname{$name});
+ push(@col_fullnames, $givenn.' '.$lastname);
+ $result.=$fullname->{$name}.' ';
+ }
+ $result.=' '."\n";
+ my ($part)=split(/\./,$part);
+ $result.=''.
+ "\n";
+ }
+ if (scalar(@bad_collaborators) > 0) {
+ $result.='
';
+ $result .= &mt('This student has submitted too many '.
+ 'collaborators. Maximum is [_1].',$ncol);
+ $result .= '
';
+ }
+ }
+ return ($result,$fullname,\@col_fullnames);
+}
+
#--- Retrieve the last submission for all the parts
sub get_last_submission {
my ($returnhash)=@_;
- my (@string,$timestamp);
+ my (@string,$timestamp,%lasthidden);
if ($$returnhash{'version'}) {
my %lasthash=();
my ($version);
for ($version=1;$version<=$$returnhash{'version'};$version++) {
- foreach (sort(split(/\:/,$$returnhash{$version.':keys'}))) {
- $lasthash{$_}=$$returnhash{$version.':'.$_};
- $timestamp = scalar(localtime($$returnhash{$version.':timestamp'}));
- }
- }
- foreach ((keys %lasthash)) {
- if ($_ =~ /\.submission$/) {
- my ($partid,$foo) = split(/submission$/,$_);
- my $draft = $lasthash{$partid.'awarddetail'} eq 'DRAFT' ?
- 'Draft Copy ' : '';
- push @string, (join(':',$_,$draft.$lasthash{$_}));
- }
+ foreach my $key (sort(split(/\:/,
+ $$returnhash{$version.':keys'}))) {
+ $lasthash{$key}=$$returnhash{$version.':'.$key};
+ $timestamp =
+ &Apache::lonlocal::locallocaltime($$returnhash{$version.':timestamp'});
+ }
+ }
+ my %typeparts;
+ my $showsurv =
+ &Apache::lonnet::allowed('vas',$env{'request.course.id'});
+ foreach my $key (sort(keys(%lasthash))) {
+ if ($key =~ /\.type$/) {
+ if (($lasthash{$key} eq 'anonsurvey') ||
+ ($lasthash{$key} eq 'anonsurveycred')) {
+ my ($ign,@parts) = split(/\./,$key);
+ pop(@parts);
+ unless ($showsurv) {
+ my $id = join(',',@parts);
+ $typeparts{$ign.'.'.$id} = $lasthash{$key};
+ }
+ delete($lasthash{$key});
+ }
+ }
+ }
+ my @hidden = keys(%typeparts);
+ foreach my $key (keys(%lasthash)) {
+ next if ($key !~ /\.submission$/);
+ my $hide;
+ if (@hidden) {
+ foreach my $id (@hidden) {
+ if ($key =~ /^\Q$id\E/) {
+ $hide = 1;
+ last;
+ }
+ }
+ }
+ my ($partid,$foo) = split(/submission$/,$key);
+ my $draft = $lasthash{$partid.'awarddetail'} eq 'DRAFT' ?
+ 'Draft Copy ' : '';
+ push(@string, join(':', $key, $hide, $draft.$lasthash{$key}));
}
}
- @string = $string[0] eq '' ? 'Nothing submitted - no attempts.' : @string;
- return \@string,\$timestamp;
+ if (!@string) {
+ $string[0] =
+ ''.&mt('Nothing submitted - no attempts.').'';
+ }
+ return (\@string,\$timestamp);
}
#--- High light keywords, with style choosen by user.
sub keywords_highlight {
my $string = shift;
- my $size = $ENV{'form.kwsize'} eq '0' ? '' : 'size='.$ENV{'form.kwsize'};
- my $styleon = $ENV{'form.kwstyle'} eq '' ? '' : $ENV{'form.kwstyle'};
+ my $size = $env{'form.kwsize'} eq '0' ? '' : 'size='.$env{'form.kwsize'};
+ my $styleon = $env{'form.kwstyle'} eq '' ? '' : $env{'form.kwstyle'};
(my $styleoff = $styleon) =~ s/\\<\//;
- my @keylist = split(/[,\s+]/,$ENV{'form.keywords'});
- foreach (@keylist) {
- $string =~ s/\b\Q$_\E(\b|\.)/$styleon$_$styleoff<\/font>/gi;
+ my @keylist = split(/[,\s+]/,$env{'form.keywords'});
+ foreach my $keyword (@keylist) {
+ $string =~ s/\b\Q$keyword\E(\b|\.)/$styleon$keyword$styleoff<\/font>/gi;
}
return $string;
}
#--- Called from submission routine
sub processHandGrade {
- my ($request) = shift;
- my $url = $ENV{'form.url'};
- my $symb = $ENV{'form.symb'};
- my $button = $ENV{'form.gradeOpt'};
- my $ngrade = $ENV{'form.NCT'};
- my $ntstu = $ENV{'form.NTSTU'};
+ my ($request,$symb) = @_;
+ my (undef,undef,$url) = &Apache::lonnet::decode_symb($symb);
+ my $button = $env{'form.gradeOpt'};
+ my $ngrade = $env{'form.NCT'};
+ my $ntstu = $env{'form.NTSTU'};
+ my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
+ my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
+
if ($button eq 'Save & Next') {
my $ctr = 0;
while ($ctr < $ngrade) {
- my ($uname,$udom) = split(/:/,$ENV{'form.unamedom'.$ctr});
- my ($errorflag,$pts,$wgt) = &saveHandGrade($request,$url,$symb,$uname,$udom,$ctr);
+ my ($uname,$udom) = split(/:/,$env{'form.unamedom'.$ctr});
+ my ($errorflag,$pts,$wgt) = &saveHandGrade($request,$symb,$uname,$udom,$ctr);
if ($errorflag eq 'no_score') {
$ctr++;
next;
}
if ($errorflag eq 'not_allowed') {
- $request->print("Not allowed to modify grades for $uname:$udom");
+ $request->print("Not allowed to modify grades for $uname:$udom");
$ctr++;
next;
}
- my $includemsg = $ENV{'form.includemsg'.$ctr};
+ my $includemsg = $env{'form.includemsg'.$ctr};
my ($subject,$message,$msgstatus) = ('','','');
+ my $restitle = &Apache::lonnet::gettitle($symb);
+ my ($feedurl,$showsymb) =
+ &get_feedurl_and_symb($symb,$uname,$udom);
+ my $messagetail;
if ($includemsg =~ /savemsg|newmsg\Q$ctr\E/) {
- $subject = $ENV{'form.msgsub'} if ($includemsg =~ /^msgsub/);
+ $subject = $env{'form.msgsub'} if ($includemsg =~ /msgsub/);
+ unless ($subject=~/\w/) { $subject=&mt('Grading Feedback'); }
+ $subject.=' ['.$restitle.']';
my (@msgnum) = split(/,/,$includemsg);
foreach (@msgnum) {
- $message.=$ENV{'form.'.$_} if ($_ =~ /savemsg|newmsg/ && $_ ne '');
+ $message.=$env{'form.'.$_} if ($_ =~ /savemsg|newmsg/ && $_ ne '');
}
$message =&Apache::lonfeedback::clear_out_html($message);
- $message.="\n\nPoint".($pts > 1 ? 's':'').' awarded = '.$pts.' out of '.$wgt;
- $message.=" for $ENV{'form.probTitle'}";
- $msgstatus = &Apache::lonmsg::user_normal_msg ($uname,$udom,
- $ENV{'form.msgsub'},$message);
- }
- if ($ENV{'form.collaborator'.$ctr}) {
- my (@collaborators) = split(/:/,$ENV{'form.collaborator'.$ctr});
- foreach (@collaborators) {
- my ($errorflag,$pts,$wgt) =
- &saveHandGrade($request,$url,$symb,$_,$udom,$ctr,$ENV{'form.unamedom'.$ctr});
- if ($errorflag eq 'not_allowed') {
- $request->print("Not allowed to modify grades for $_:$udom");
- next;
- } else {
- if ($message ne '') {
- $msgstatus = &Apache::lonmsg::user_normal_msg ($_,$udom,
- $ENV{'form.msgsub'},
- $message);
+ if ($env{'form.withgrades'.$ctr}) {
+ $message.="\n\nPoint".($pts > 1 ? 's':'').' awarded = '.$pts.' out of '.$wgt;
+ $messagetail = " for $restitle";
+ }
+ $msgstatus =
+ &Apache::lonmsg::user_normal_msg($uname,$udom,$subject,
+ $message.$messagetail,
+ undef,$feedurl,undef,
+ undef,undef,$showsymb,
+ $restitle);
+ $request->print(' '.&mt('Sending message to [_1]',$uname.':'.$udom).': '.
+ $msgstatus);
+ }
+ if ($env{'form.collaborator'.$ctr}) {
+ my @collabstrs=&Apache::loncommon::get_env_multiple("form.collaborator$ctr");
+ foreach my $collabstr (@collabstrs) {
+ my ($part,@collaborators) = split(/:/,$collabstr);
+ foreach my $collaborator (@collaborators) {
+ my ($errorflag,$pts,$wgt) =
+ &saveHandGrade($request,$symb,$collaborator,$udom,$ctr,
+ $env{'form.unamedom'.$ctr},$part);
+ if ($errorflag eq 'not_allowed') {
+ $request->print("".&mt('Not allowed to modify grades for [_1]',"$collaborator:$udom")."");
+ next;
+ } elsif ($message ne '') {
+ my ($baseurl,$showsymb) =
+ &get_feedurl_and_symb($symb,$collaborator,
+ $udom);
+ if ($env{'form.withgrades'.$ctr}) {
+ $messagetail = " for $restitle";
+ }
+ $msgstatus =
+ &Apache::lonmsg::user_normal_msg($collaborator,$udom,$subject,$message.$messagetail,undef,$baseurl,undef,undef,undef,$showsymb,$restitle);
}
}
}
@@ -1643,61 +2545,59 @@ sub processHandGrade {
}
}
- if ($ENV{'form.handgrade'} eq 'yes') {
+ if ($env{'form.handgrade'} eq 'yes') {
# Keywords sorted in alphabatical order
- my $loginuser = $ENV{'user.name'}.':'.$ENV{'user.domain'};
+ my $loginuser = $env{'user.name'}.':'.$env{'user.domain'};
my %keyhash = ();
- $ENV{'form.keywords'} =~ s/,\s{0,}|\s+/ /g;
- $ENV{'form.keywords'} =~ s/^\s+|\s+$//;
- my (@keywords) = sort(split(/\s+/,$ENV{'form.keywords'}));
- $ENV{'form.keywords'} = join(' ',@keywords);
- $keyhash{$symb.'_keywords'} = $ENV{'form.keywords'};
- $keyhash{$symb.'_subject'} = $ENV{'form.msgsub'};
- $keyhash{$loginuser.'_kwclr'} = $ENV{'form.kwclr'};
- $keyhash{$loginuser.'_kwsize'} = $ENV{'form.kwsize'};
- $keyhash{$loginuser.'_kwstyle'} = $ENV{'form.kwstyle'};
+ $env{'form.keywords'} =~ s/,\s{0,}|\s+/ /g;
+ $env{'form.keywords'} =~ s/^\s+|\s+$//;
+ my (@keywords) = sort(split(/\s+/,$env{'form.keywords'}));
+ $env{'form.keywords'} = join(' ',@keywords);
+ $keyhash{$symb.'_keywords'} = $env{'form.keywords'};
+ $keyhash{$symb.'_subject'} = $env{'form.msgsub'};
+ $keyhash{$loginuser.'_kwclr'} = $env{'form.kwclr'};
+ $keyhash{$loginuser.'_kwsize'} = $env{'form.kwsize'};
+ $keyhash{$loginuser.'_kwstyle'} = $env{'form.kwstyle'};
# message center - Order of message gets changed. Blank line is eliminated.
- # New messages are saved in ENV for the next student.
+ # New messages are saved in env for the next student.
# All messages are saved in nohist_handgrade.db
my ($ctr,$idx) = (1,1);
- while ($ctr <= $ENV{'form.savemsgN'}) {
- if ($ENV{'form.savemsg'.$ctr} ne '') {
- $keyhash{$symb.'_savemsg'.$idx} = $ENV{'form.savemsg'.$ctr};
+ while ($ctr <= $env{'form.savemsgN'}) {
+ if ($env{'form.savemsg'.$ctr} ne '') {
+ $keyhash{$symb.'_savemsg'.$idx} = $env{'form.savemsg'.$ctr};
$idx++;
}
$ctr++;
}
$ctr = 0;
while ($ctr < $ngrade) {
- if ($ENV{'form.newmsg'.$ctr} ne '') {
- $keyhash{$symb.'_savemsg'.$idx} = $ENV{'form.newmsg'.$ctr};
- $ENV{'form.savemsg'.$idx} = $ENV{'form.newmsg'.$ctr};
+ if ($env{'form.newmsg'.$ctr} ne '') {
+ $keyhash{$symb.'_savemsg'.$idx} = $env{'form.newmsg'.$ctr};
+ $env{'form.savemsg'.$idx} = $env{'form.newmsg'.$ctr};
$idx++;
}
$ctr++;
}
- $ENV{'form.savemsgN'} = --$idx;
- $keyhash{$symb.'_savemsgN'} = $ENV{'form.savemsgN'};
+ $env{'form.savemsgN'} = --$idx;
+ $keyhash{$symb.'_savemsgN'} = $env{'form.savemsgN'};
my $putresult = &Apache::lonnet::put
- ('nohist_handgrade',\%keyhash,
- $ENV{'course.'.$ENV{'request.course.id'}.'.domain'},
- $ENV{'course.'.$ENV{'request.course.id'}.'.num'});
+ ('nohist_handgrade',\%keyhash,$cdom,$cnum);
}
# Called by Save & Refresh from Highlight Attribute Window
- my (undef,undef,$fullname) = &getclasslist($ENV{'form.section'},'1');
- if ($ENV{'form.refresh'} eq 'on') {
+ my (undef,undef,$fullname) = &getclasslist($env{'form.section'},'1');
+ if ($env{'form.refresh'} eq 'on') {
my ($ctr,$total) = (0,0);
while ($ctr < $ngrade) {
- $total++ if $ENV{'form.unamedom'.$ctr} ne '';
+ $total++ if $env{'form.unamedom'.$ctr} ne '';
$ctr++;
}
- $ENV{'form.NTSTU'}=$ngrade;
+ $env{'form.NTSTU'}=$ngrade;
$ctr = 0;
while ($ctr < $total) {
- my $processUser = $ENV{'form.unamedom'.$ctr};
- ($ENV{'form.student'},$ENV{'form.userdom'}) = split(/:/,$processUser);
- $ENV{'form.fullname'} = $$fullname{$processUser};
+ my $processUser = $env{'form.unamedom'.$ctr};
+ ($env{'form.student'},$env{'form.userdom'}) = split(/:/,$processUser);
+ $env{'form.fullname'} = $$fullname{$processUser};
&submission($request,$ctr,$total-1);
$ctr++;
}
@@ -1706,71 +2606,105 @@ sub processHandGrade {
# Go directly to grade student - from submission or link from chart page
if ($button eq 'Grade Student') {
- (undef,undef,$ENV{'form.handgrade'},undef,undef) = &showResourceInfo($url);
- my $processUser = $ENV{'form.unamedom'.$ENV{'form.studentNo'}};
- ($ENV{'form.student'},$ENV{'form.userdom'}) = split(/:/,$processUser);
- $ENV{'form.fullname'} = $$fullname{$processUser};
+# (undef,undef,$env{'form.handgrade'},undef,undef) = &showResourceInfo($symb);
+ my $processUser = $env{'form.unamedom'.$env{'form.studentNo'}};
+ ($env{'form.student'},$env{'form.userdom'}) = split(/:/,$processUser);
+ $env{'form.fullname'} = $$fullname{$processUser};
&submission($request,0,0);
return '';
}
# Get the next/previous one or group of students
- my $firststu = $ENV{'form.unamedom0'};
- my $laststu = $ENV{'form.unamedom'.($ngrade-1)};
+ my $firststu = $env{'form.unamedom0'};
+ my $laststu = $env{'form.unamedom'.($ngrade-1)};
my $ctr = 2;
while ($laststu eq '') {
- $laststu = $ENV{'form.unamedom'.($ngrade-$ctr)};
+ $laststu = $env{'form.unamedom'.($ngrade-$ctr)};
$ctr++;
$laststu = $firststu if ($ctr > $ngrade);
}
my (@parsedlist,@nextlist);
my ($nextflg) = 0;
- foreach (sort {lc($$fullname{$a}) cmp lc($$fullname{$b}) } keys %$fullname) {
+ foreach my $item (sort
+ {
+ if (lc($$fullname{$a}) ne lc($$fullname{$b})) {
+ return (lc($$fullname{$a}) cmp lc($$fullname{$b}));
+ }
+ return $a cmp $b;
+ } (keys(%$fullname))) {
+# FIXME: this is fishy, looks like the button label
if ($nextflg == 1 && $button =~ /Next$/) {
- push @parsedlist,$_;
+ push(@parsedlist,$item);
}
- $nextflg = 1 if ($_ eq $laststu);
+ $nextflg = 1 if ($item eq $laststu);
if ($button eq 'Previous') {
- last if ($_ eq $firststu);
- push @parsedlist,$_;
+ last if ($item eq $firststu);
+ push(@parsedlist,$item);
}
}
$ctr = 0;
- my ($partlist,$handgrade) = &response_type($ENV{'form.url'});
+# FIXME: this is fishy, looks like the button label
@parsedlist = reverse @parsedlist if ($button eq 'Previous');
+ my $res_error;
+ my ($partlist) = &response_type($symb,\$res_error);
+ if ($res_error) {
+ $request->print(&navmap_errormsg());
+ return;
+ }
foreach my $student (@parsedlist) {
+ my $submitonly=$env{'form.submitonly'};
my ($uname,$udom) = split(/:/,$student);
- if ($ENV{'form.submitonly'} eq 'yes') {
- my (%status) = &student_gradeStatus($ENV{'form.url'},$symb,$udom,$uname,$partlist) ;
- my $statusflg = '';
- foreach (keys(%status)) {
- $statusflg = 1 if ($status{$_} ne 'nothing');
- my ($foo,$partid,$foo1) = split(/\./);
- $statusflg = '' if ($status{'resource.'.$partid.'.submitted_by'} ne '');
+
+ if ($submitonly eq 'queued') {
+ my %queue_status =
+ &Apache::bridgetask::get_student_status($symb,$cdom,$cnum,
+ $udom,$uname);
+ next if (!defined($queue_status{'gradingqueue'}));
+ }
+
+ if ($submitonly =~ /^(yes|graded|incorrect)$/) {
+# my %record = &Apache::lonnet::restore($symb,$env{'request.course.id'},$udom,$uname);
+ my %status=&student_gradeStatus($symb,$udom,$uname,$partlist);
+ my $submitted = 0;
+ my $ungraded = 0;
+ my $incorrect = 0;
+ foreach my $item (keys(%status)) {
+ $submitted = 1 if ($status{$item} ne 'nothing');
+ $ungraded = 1 if ($status{$item} =~ /^ungraded/);
+ $incorrect = 1 if ($status{$item} =~ /^incorrect/);
+ my ($foo,$partid,$foo1) = split(/\./,$item);
+ if ($status{'resource.'.$partid.'.submitted_by'} ne '') {
+ $submitted = 0;
+ }
}
- next if ($statusflg eq '');
+ next if (!$submitted && ($submitonly eq 'yes' ||
+ $submitonly eq 'incorrect' ||
+ $submitonly eq 'graded'));
+ next if (!$ungraded && ($submitonly eq 'graded'));
+ next if (!$incorrect && $submitonly eq 'incorrect');
}
- push @nextlist,$student if ($ctr < $ntstu);
+ push(@nextlist,$student) if ($ctr < $ntstu);
+ last if ($ctr == $ntstu);
$ctr++;
}
$ctr = 0;
my $total = scalar(@nextlist)-1;
- foreach (sort @nextlist) {
+ foreach (sort(@nextlist)) {
my ($uname,$udom,$submitter) = split(/:/);
- $ENV{'form.student'} = $uname;
- $ENV{'form.userdom'} = $udom;
- $ENV{'form.fullname'} = $$fullname{$_};
+ $env{'form.student'} = $uname;
+ $env{'form.userdom'} = $udom;
+ $env{'form.fullname'} = $$fullname{$_};
&submission($request,$ctr,$total);
$ctr++;
}
if ($total < 0) {
- my $the_end = '
LON-CAPA User Message
'."\n";
- $the_end.='Message: No more students for this section or class.
'."\n";
- $the_end.='Click on the button below to return to the grading menu.
'."\n";
- $the_end.=&show_grading_menu_form ($symb,$url);
+ my $the_end = '
'.&mt('LON-CAPA User Message').'
'."\n";
+ $the_end.=&mt('Message: No more students for this section or class.').'
'."\n";
+ $the_end.=&mt('Click on the button below to return to the grading menu.').'
'."\n";
+ $the_end.=&show_grading_menu_form($symb);
$request->print($the_end);
}
return '';
@@ -1778,51 +2712,385 @@ sub processHandGrade {
#---- Save the score and award for each student, if changed
sub saveHandGrade {
- my ($request,$url,$symb,$stuname,$domain,$newflg,$submitter) = @_;
+ my ($request,$symb,$stuname,$domain,$newflg,$submitter,$part) = @_;
+ my @version_parts;
my $usec = &Apache::lonnet::getsection($domain,$stuname,
- $ENV{'request.course.id'});
+ $env{'request.course.id'});
if (!&canmodify($usec)) { return('not_allowed'); }
- my %record = &Apache::lonnet::restore($symb,$ENV{'request.course.id'},$domain,$stuname);
+ my %record = &Apache::lonnet::restore($symb,$env{'request.course.id'},$domain,$stuname);
+ my @parts_graded;
my %newrecord = ();
my ($pts,$wgt) = ('','');
- foreach (split(/:/,$ENV{'form.partlist'.$newflg})) {
- if ($ENV{'form.GD_SEL'.$newflg.'_'.$_} eq 'excused') {
- if ($record{'resource.'.$_.'.solved'} ne 'excused') {
- $newrecord{'resource.'.$_.'.solved'} = 'excused';
- if (exists($record{'resource.'.$_.'.awarded'})) {
- $newrecord{'resource.'.$_.'.awarded'} = '';
+ my %aggregate = ();
+ my $aggregateflag = 0;
+ my @parts = split(/:/,$env{'form.partlist'.$newflg});
+ foreach my $new_part (@parts) {
+ #collaborator ($submi may vary for different parts
+ if ($submitter && $new_part ne $part) { next; }
+ my $dropMenu = $env{'form.GD_SEL'.$newflg.'_'.$new_part};
+ if ($dropMenu eq 'excused') {
+ if ($record{'resource.'.$new_part.'.solved'} ne 'excused') {
+ $newrecord{'resource.'.$new_part.'.solved'} = 'excused';
+ if (exists($record{'resource.'.$new_part.'.awarded'})) {
+ $newrecord{'resource.'.$new_part.'.awarded'} = '';
}
+ $newrecord{'resource.'.$new_part.'.regrader'}="$env{'user.name'}:$env{'user.domain'}";
}
- } else {
- $pts = ($ENV{'form.GD_BOX'.$newflg.'_'.$_} ne '' ?
- $ENV{'form.GD_BOX'.$newflg.'_'.$_} :
- $ENV{'form.RADVAL'.$newflg.'_'.$_});
- return 'no_score' if ($pts eq '' && $ENV{'form.GD_SEL'.$newflg.'_'.$_} eq '');
- $wgt = $ENV{'form.WGT'.$newflg.'_'.$_} eq '' ? 1 :
- $ENV{'form.WGT'.$newflg.'_'.$_};
+ } elsif ($dropMenu eq 'reset status'
+ && exists($record{'resource.'.$new_part.'.solved'})) { #don't bother if no old records -> no attempts
+ foreach my $key (keys(%record)) {
+ if ($key=~/^resource\.\Q$new_part\E\./) { $newrecord{$key} = ''; }
+ }
+ $newrecord{'resource.'.$new_part.'.regrader'}=
+ "$env{'user.name'}:$env{'user.domain'}";
+ my $totaltries = $record{'resource.'.$part.'.tries'};
+
+ my %last_resets = &get_last_resets($symb,$env{'request.course.id'},
+ [$new_part]);
+ my $aggtries =$totaltries;
+ if ($last_resets{$new_part}) {
+ $aggtries = &get_num_tries(\%record,$last_resets{$new_part},
+ $new_part);
+ }
+
+ my $solvedstatus = $record{'resource.'.$new_part.'.solved'};
+ if ($aggtries > 0) {
+ &decrement_aggs($symb,$new_part,\%aggregate,$aggtries,$totaltries,$solvedstatus);
+ $aggregateflag = 1;
+ }
+ } elsif ($dropMenu eq '') {
+ $pts = ($env{'form.GD_BOX'.$newflg.'_'.$new_part} ne '' ?
+ $env{'form.GD_BOX'.$newflg.'_'.$new_part} :
+ $env{'form.RADVAL'.$newflg.'_'.$new_part});
+ if ($pts eq '' && $env{'form.GD_SEL'.$newflg.'_'.$new_part} eq '') {
+ next;
+ }
+ $wgt = $env{'form.WGT'.$newflg.'_'.$new_part} eq '' ? 1 :
+ $env{'form.WGT'.$newflg.'_'.$new_part};
my $partial= $pts/$wgt;
- next if ($partial eq $record{'resource.'.$_.'.awarded'}); #do not update score for part if not changed.
- $newrecord{'resource.'.$_.'.awarded'} = $partial
- if ($record{'resource.'.$_.'.awarded'} ne $partial);
- my $reckey = 'resource.'.$_.'.solved';
+ if ($partial eq $record{'resource.'.$new_part.'.awarded'}) {
+ #do not update score for part if not changed.
+ &handback_files($request,$symb,$stuname,$domain,$newflg,$new_part,\%newrecord);
+ next;
+ } else {
+ push(@parts_graded,$new_part);
+ }
+ if ($record{'resource.'.$new_part.'.awarded'} ne $partial) {
+ $newrecord{'resource.'.$new_part.'.awarded'} = $partial;
+ }
+ my $reckey = 'resource.'.$new_part.'.solved';
if ($partial == 0) {
- $newrecord{$reckey} = 'incorrect_by_override'
- if ($record{$reckey} ne 'incorrect_by_override');
+ if ($record{$reckey} ne 'incorrect_by_override') {
+ $newrecord{$reckey} = 'incorrect_by_override';
+ }
} else {
- $newrecord{$reckey} = 'correct_by_override'
- if ($record{$reckey} ne 'correct_by_override');
+ if ($record{$reckey} ne 'correct_by_override') {
+ $newrecord{$reckey} = 'correct_by_override';
+ }
+ }
+ if ($submitter &&
+ ($record{'resource.'.$new_part.'.submitted_by'} ne $submitter)) {
+ $newrecord{'resource.'.$new_part.'.submitted_by'} = $submitter;
+ }
+ $newrecord{'resource.'.$new_part.'.regrader'}=
+ "$env{'user.name'}:$env{'user.domain'}";
+ }
+ # unless problem has been graded, set flag to version the submitted files
+ unless ($record{'resource.'.$new_part.'.solved'} =~ /^correct_/ ||
+ $record{'resource.'.$new_part.'.solved'} eq 'incorrect_by_override' ||
+ $dropMenu eq 'reset status')
+ {
+ push(@version_parts,$new_part);
+ }
+ }
+ my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
+ my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
+
+ if (%newrecord) {
+ if (@version_parts) {
+ my @changed_keys = &version_portfiles(\%record, \@parts_graded,
+ $env{'request.course.id'}, $symb, $domain, $stuname, \@version_parts);
+ @newrecord{@changed_keys} = @record{@changed_keys};
+ foreach my $new_part (@version_parts) {
+ &handback_files($request,$symb,$stuname,$domain,$newflg,
+ $new_part,\%newrecord);
}
- $newrecord{'resource.'.$_.'.submitted_by'} = $submitter
- if ($submitter && ($record{'resource.'.$_.'.submitted_by'} ne $submitter));
- $newrecord{'resource.'.$_.'.regrader'}="$ENV{'user.name'}:$ENV{'user.domain'}";
- }
+ }
+ &Apache::lonnet::cstore(\%newrecord,$symb,
+ $env{'request.course.id'},$domain,$stuname);
+ &check_and_remove_from_queue(\@parts,\%record,\%newrecord,$symb,
+ $cdom,$cnum,$domain,$stuname);
+ }
+ if ($aggregateflag) {
+ &Apache::lonnet::cinc('nohist_resourcetracker',\%aggregate,
+ $cdom,$cnum);
+ }
+ return ('',$pts,$wgt);
+}
+
+sub check_and_remove_from_queue {
+ my ($parts,$record,$newrecord,$symb,$cdom,$cnum,$domain,$stuname) = @_;
+ my @ungraded_parts;
+ foreach my $part (@{$parts}) {
+ if ( $record->{ 'resource.'.$part.'.awarded'} eq ''
+ && $record->{ 'resource.'.$part.'.solved' } ne 'excused'
+ && $newrecord->{'resource.'.$part.'.awarded'} eq ''
+ && $newrecord->{'resource.'.$part.'.solved' } ne 'excused'
+ ) {
+ push(@ungraded_parts, $part);
+ }
+ }
+ if ( !@ungraded_parts ) {
+ &Apache::bridgetask::remove_from_queue('gradingqueue',$symb,$cdom,
+ $cnum,$domain,$stuname);
+ }
+}
+
+sub handback_files {
+ my ($request,$symb,$stuname,$domain,$newflg,$new_part,$newrecord) = @_;
+ my $portfolio_root = '/userfiles/portfolio';
+ my $res_error;
+ my ($partlist,$handgrade,$responseType) = &response_type($symb,\$res_error);
+ if ($res_error) {
+ $request->print(' '.&navmap_errormsg().' ');
+ return;
+ }
+ my @part_response_id = &flatten_responseType($responseType);
+ foreach my $part_response_id (@part_response_id) {
+ my ($part_id,$resp_id) = @{ $part_response_id };
+ my $part_resp = join('_',@{ $part_response_id });
+ if (($env{'form.'.$newflg.'_'.$part_resp.'_returndoc1'}) && ($new_part == $part_id)) {
+ # if multiple files are uploaded names will be 'returndoc2','returndoc3'
+ my $file_counter = 1;
+ my $file_msg;
+ while ($env{'form.'.$newflg.'_'.$part_resp.'_returndoc'.$file_counter}) {
+ my $fname=$env{'form.'.$newflg.'_'.$part_resp.'_returndoc'.$file_counter.'.filename'};
+ my ($directory,$answer_file) =
+ ($env{'form.'.$newflg.'_'.$part_resp.'_origdoc'.$file_counter} =~ /^(.*?)([^\/]*)$/);
+ my ($answer_name,$answer_ver,$answer_ext) =
+ &file_name_version_ext($answer_file);
+ my ($portfolio_path) = ($directory =~ /^.+$stuname\/portfolio(.*)/);
+ my $getpropath = 1;
+ my @dir_list = &Apache::lonnet::dirlist($portfolio_root.$portfolio_path,$domain,$stuname,$getpropath);
+ my $version = &get_next_version($answer_name, $answer_ext, \@dir_list);
+ # fix file name
+ my ($save_file_name) = (($directory.$answer_name.".$version.".$answer_ext) =~ /^.+\/${stuname}\/(.*)/);
+ my $result=&Apache::lonnet::finishuserfileupload($stuname,$domain,
+ $newflg.'_'.$part_resp.'_returndoc'.$file_counter,
+ $save_file_name);
+ if ($result !~ m|^/uploaded/|) {
+ $request->print(' '.
+ &mt('An error occurred ([_1]) while trying to upload [_2].',
+ $result,$newflg.'_'.$part_resp.'_returndoc'.$file_counter).
+ '');
+ } else {
+ # mark the file as read only
+ my @files = ($save_file_name);
+ my @what = ($symb,$env{'request.course.id'},'handback');
+ &Apache::lonnet::mark_as_readonly($domain,$stuname,\@files,\@what);
+ if (exists($$newrecord{"resource.$new_part.$resp_id.handback"})) {
+ $$newrecord{"resource.$new_part.$resp_id.handback"}.=',';
+ }
+ $$newrecord{"resource.$new_part.$resp_id.handback"} .= $save_file_name;
+ $file_msg.= "\n".' '.$save_file_name." ";
+
+ }
+ $request->print(" ".$fname." will be the uploaded file name");
+ $request->print(" ".$env{'form.'.$newflg.'_'.$part_resp.'_origdoc'.$file_counter});
+ $file_counter++;
+ }
+ my $subject = "File Handed Back by Instructor ";
+ my $message = "A file has been returned that was originally submitted in reponse to: ";
+ $message .= "".&Apache::lonnet::gettitle($symb)." ";
+ $message .= ' The returned file(s) are named: '. $file_msg;
+ $message .= " and can be found in your portfolio space.";
+ my ($feedurl,$showsymb) =
+ &get_feedurl_and_symb($symb,$domain,$stuname);
+ my $restitle = &Apache::lonnet::gettitle($symb);
+ my $msgstatus =
+ &Apache::lonmsg::user_normal_msg($stuname,$domain,$subject.
+ ' (File Returned) ['.$restitle.']',$message,undef,
+ $feedurl,undef,undef,undef,$showsymb,$restitle);
+ }
+ }
+ return;
+}
+
+sub get_feedurl_and_symb {
+ my ($symb,$uname,$udom) = @_;
+ my (undef,undef,$url) = &Apache::lonnet::decode_symb($symb);
+ $url = &Apache::lonnet::clutter($url);
+ my $encrypturl=&Apache::lonnet::EXT('resource.0.encrypturl',
+ $symb,$udom,$uname);
+ if ($encrypturl =~ /^yes$/i) {
+ &Apache::lonenc::encrypted(\$url,1);
+ &Apache::lonenc::encrypted(\$symb,1);
+ }
+ return ($url,$symb);
+}
+
+sub get_submitted_files {
+ my ($udom,$uname,$partid,$respid,$record) = @_;
+ my @files;
+ if ($$record{"resource.$partid.$respid.portfiles"}) {
+ my $file_url = '/uploaded/'.$udom.'/'.$uname.'/portfolio';
+ foreach my $file (split(',',$$record{"resource.$partid.$respid.portfiles"})) {
+ push(@files,$file_url.$file);
+ }
+ }
+ if ($$record{"resource.$partid.$respid.uploadedurl"}) {
+ push(@files,$$record{"resource.$partid.$respid.uploadedurl"});
}
+ return (\@files);
+}
- if (scalar(keys(%newrecord)) > 0) {
- &Apache::lonnet::cstore(\%newrecord,$symb,
- $ENV{'request.course.id'},$domain,$stuname);
+# ----------- Provides number of tries since last reset.
+sub get_num_tries {
+ my ($record,$last_reset,$part) = @_;
+ my $timestamp = '';
+ my $num_tries = 0;
+ if ($$record{'version'}) {
+ for (my $version=$$record{'version'};$version>=1;$version--) {
+ if (exists($$record{$version.':resource.'.$part.'.solved'})) {
+ $timestamp = $$record{$version.':timestamp'};
+ if ($timestamp > $last_reset) {
+ $num_tries ++;
+ } else {
+ last;
+ }
+ }
+ }
+ }
+ return $num_tries;
+}
+
+# ----------- Determine decrements required in aggregate totals
+sub decrement_aggs {
+ my ($symb,$part,$aggregate,$aggtries,$totaltries,$solvedstatus) = @_;
+ my %decrement = (
+ attempts => 0,
+ users => 0,
+ correct => 0
+ );
+ $decrement{'attempts'} = $aggtries;
+ if ($solvedstatus =~ /^correct/) {
+ $decrement{'correct'} = 1;
+ }
+ if ($aggtries == $totaltries) {
+ $decrement{'users'} = 1;
+ }
+ foreach my $type (keys(%decrement)) {
+ $$aggregate{$symb."\0".$part."\0".$type} = -$decrement{$type};
+ }
+ return;
+}
+
+# ----------- Determine timestamps for last reset of aggregate totals for parts
+sub get_last_resets {
+ my ($symb,$courseid,$partids) =@_;
+ my %last_resets;
+ my $cdom = $env{'course.'.$courseid.'.domain'};
+ my $cname = $env{'course.'.$courseid.'.num'};
+ my @keys;
+ foreach my $part (@{$partids}) {
+ push(@keys,"$symb\0$part\0resettime");
+ }
+ my %results=&Apache::lonnet::get('nohist_resourcetracker',\@keys,
+ $cdom,$cname);
+ foreach my $part (@{$partids}) {
+ $last_resets{$part}=$results{"$symb\0$part\0resettime"};
+ }
+ return %last_resets;
+}
+
+# ----------- Handles creating versions for portfolio files as answers
+sub version_portfiles {
+ my ($record, $parts_graded, $courseid, $symb, $domain, $stu_name, $v_flag) = @_;
+ my $version_parts = join('|',@$v_flag);
+ my @returned_keys;
+ my $parts = join('|', @$parts_graded);
+ my $portfolio_root = '/userfiles/portfolio';
+ foreach my $key (keys(%$record)) {
+ my $new_portfiles;
+ if ($key =~ /^resource\.($version_parts)\./ && $key =~ /\.portfiles$/ ) {
+ my @versioned_portfiles;
+ my @portfiles = split(/\s*,\s*/,$$record{$key});
+ foreach my $file (@portfiles) {
+ &Apache::lonnet::unmark_as_readonly($domain,$stu_name,[$symb,$env{'request.course.id'}],$file);
+ my ($directory,$answer_file) =($file =~ /^(.*?)([^\/]*)$/);
+ my ($answer_name,$answer_ver,$answer_ext) =
+ &file_name_version_ext($answer_file);
+ my $getpropath = 1;
+ my @dir_list = &Apache::lonnet::dirlist($portfolio_root.$directory,$domain,$stu_name,$getpropath);
+ my $version = &get_next_version($answer_name, $answer_ext, \@dir_list);
+ my $new_answer = &version_selected_portfile($domain, $stu_name, $directory, $answer_file, $version);
+ if ($new_answer ne 'problem getting file') {
+ push(@versioned_portfiles, $directory.$new_answer);
+ &Apache::lonnet::mark_as_readonly($domain,$stu_name,
+ [$directory.$new_answer],
+ [$symb,$env{'request.course.id'},'graded']);
+ }
+ }
+ $$record{$key} = join(',',@versioned_portfiles);
+ push(@returned_keys,$key);
+ }
+ }
+ return (@returned_keys);
+}
+
+sub get_next_version {
+ my ($answer_name, $answer_ext, $dir_list) = @_;
+ my $version;
+ foreach my $row (@$dir_list) {
+ my ($file) = split(/\&/,$row,2);
+ my ($file_name,$file_version,$file_ext) =
+ &file_name_version_ext($file);
+ if (($file_name eq $answer_name) &&
+ ($file_ext eq $answer_ext)) {
+ # gets here if filename and extension match, regardless of version
+ if ($file_version ne '') {
+ # a versioned file is found so save it for later
+ if ($file_version > $version) {
+ $version = $file_version;
+ }
+ }
+ }
+ }
+ $version ++;
+ return($version);
+}
+
+sub version_selected_portfile {
+ my ($domain,$stu_name,$directory,$file_name,$version) = @_;
+ my ($answer_name,$answer_ver,$answer_ext) =
+ &file_name_version_ext($file_name);
+ my $new_answer;
+ $env{'form.copy'} = &Apache::lonnet::getfile("/uploaded/$domain/$stu_name/portfolio$directory$file_name");
+ if($env{'form.copy'} eq '-1') {
+ $new_answer = 'problem getting file';
+ } else {
+ $new_answer = $answer_name.'.'.$version.'.'.$answer_ext;
+ my $copy_result = &Apache::lonnet::finishuserfileupload(
+ $stu_name,$domain,'copy',
+ '/portfolio'.$directory.$new_answer);
+ }
+ return ($new_answer);
+}
+
+sub file_name_version_ext {
+ my ($file)=@_;
+ my @file_parts = split(/\./, $file);
+ my ($name,$version,$ext);
+ if (@file_parts > 1) {
+ $ext=pop(@file_parts);
+ if (@file_parts > 1 && $file_parts[-1] =~ /^\d+$/) {
+ $version=pop(@file_parts);
+ }
+ $name=join('.',@file_parts);
+ } else {
+ $name=join('.',@file_parts);
}
- return '',$pts,$wgt;
+ return($name,$version,$ext);
}
#--------------------------------------------------------------------------------------
@@ -1833,15 +3101,15 @@ sub saveHandGrade {
sub viewgrades_js {
my ($request) = shift;
- $request->print(<
+ my $alertmsg = &mt('A number equal or greater than 0 is expected. Entered value = ');
+ $request->print(&Apache::lonhtmlcommon::scripttag(<
VIEWJAVASCRIPT
}
#--- show scores for a section or whole class w/ option to change/update a score
sub viewgrades {
- my ($request) = shift;
+ my ($request,$symb) = @_;
&viewgrades_js($request);
- my ($symb,$url) = ($ENV{'form.symb'},$ENV{'form.url'});
- my $result='
Manual Grading
';
+ #need to make sure we have the correct data for later EXT calls,
+ #thus invalidate the cache
+ &Apache::lonnet::devalidatecourseresdata(
+ $env{'course.'.$env{'request.course.id'}.'.num'},
+ $env{'course.'.$env{'request.course.id'}.'.domain'});
+ &Apache::lonnet::clear_EXT_cache_status();
- $result.='Current Resource: '.$ENV{'form.probTitle'}.''."\n";
+ my $result='
'.&mt('Manual Grading').'
';
#view individual student submission form - called using Javascript viewOneStudent
- $result.=&jscriptNform($url,$symb);
+ $result.=&jscriptNform($symb);
#beginning of class grading form
+ my $stu_status = join(':',&Apache::loncommon::get_env_multiple('form.Status'));
$result.= ''."\n";
+ $result.=''."\n";
if (scalar(%$fullname) eq 0) {
my $colspan=3+scalar(@parts);
- $result='There are no students in section "'.$ENV{'form.section'}.
- '" with enrollment status "'.$ENV{'form.Status'}.'" to modify or grade.';
+ my $section_display = join (", ",&Apache::loncommon::get_env_multiple('form.section'));
+ my $stu_status = join(' or ',&Apache::loncommon::get_env_multiple('form.Status'));
+ $result=''.
+ &mt('There are no students in section(s) [_1] with enrollment status [_2] to modify or grade.',
+ $section_display, $stu_status).
+ '';
}
- $result.=&show_grading_menu_form($symb,$url);
+ $result.=&show_grading_menu_form($symb);
return $result;
}
#--- call by previous routine to display each student
sub viewstudentgrade {
- my ($url,$symb,$courseid,$student,$fullname,$parts,$weight) = @_;
+ my ($symb,$courseid,$student,$fullname,$parts,$weight,$ctr,$last_resets) = @_;
my ($uname,$udom) = split(/:/,$student);
- $student=~s/:/_/;
my %record=&Apache::lonnet::restore($symb,$courseid,$udom,$uname);
- my $result='
'.
+ my %aggregates = ();
+ my $result=&Apache::loncommon::start_data_table_row().'
';
+ $result.=&Apache::loncommon::end_data_table_row();
return $result;
}
#--- change scores for all the students in a section/class
# record does not get update if unchanged
sub editgrades {
- my ($request) = @_;
-
- my $symb=$ENV{'form.symb'};
- my $url =$ENV{'form.url'};
- my $title='
'."\n".
- &show_grading_menu_form ($symb,$url);
- my $msg = 'Number of records updated = '.$rec_update.
- ' for '.$count.' student'.($count <= 1 ? '' : 's').'. '.
- 'Total number of students = '.$ENV{'form.total'}.' ';
+ if (@noupdate) {
+# my $numcols=(scalar(@partid)*(scalar(@parts)-1)*2)+3;
+ my $numcols=scalar(@partid)*4+2;
+ $result .= &Apache::loncommon::start_data_table_row('LC_empty_row').
+ '
'.
+ &mt('No Changes Occurred For the Students Below').
+ '
'.
+ &mt('Number of records updated = [_1] for [quant,_2,student].',
+ $rec_update,$count).' '.
+ ''.&mt('Total number of students = [_1]',$env{'form.total'}).
+ '
';
return $title.$msg.$result;
}
@@ -2328,7 +3733,7 @@ sub split_part_type {
my ($partstr) = @_;
my ($temp,@allparts)=split(/_/,$partstr);
my $type=pop(@allparts);
- my $part=join('.',@allparts);
+ my $part=join('_',@allparts);
return ($part,$type);
}
@@ -2343,24 +3748,26 @@ sub split_part_type {
#
#--- Javascript to handle csv upload
sub csvupload_javascript_reverse_associate {
+ my $error1=&mt('You need to specify the username or the student/employee ID');
+ my $error2=&mt('You need to specify at least one grading field');
return(<2) { foundsomething=1; }
- }
- if (founduname==0 || founddomain==0) {
- alert('You need to specify at both the username and domain');
- return;
+ if (tw==1) { foundID=1; }
+ if (tw==2) { founduname=1; }
+ if (tw>3) { foundsomething=1; }
+ }
+ if (founduname==0 && foundID==0) {
+ alert('$error1');
+ return;
}
if (foundsomething==0) {
- alert('You need to specify at least one grading field');
- return;
+ alert('$error2');
+ return;
}
vf.submit();
}
@@ -2416,58 +3825,68 @@ ENDPICK
}
sub csvuploadmap_header {
- my ($request,$symb,$url,$datatoken,$distotal)= @_;
+ my ($request,$symb,$datatoken,$distotal)= @_;
my $javascript;
- if ($ENV{'form.upfile_associate'} eq 'reverse') {
+ if ($env{'form.upfile_associate'} eq 'reverse') {
$javascript=&csvupload_javascript_reverse_associate();
} else {
$javascript=&csvupload_javascript_forward_associate();
}
- my ($result) = &showResourceInfo($url,$ENV{'form.probTitle'});
-
+ my $result='';
+ my $checked=(($env{'form.noFirstLine'})?' checked="checked"':'');
+ my $ignore=&mt('Ignore First Line');
+ $symb = &Apache::lonenc::check_encrypt($symb);
$request->print(<
-
Uploading Class Grades
+
Uploading Class Grades
$result
-
+
Identify fields
Total number of records found in file: $distotal
Enter as many fields as you can. The system will inform you and bring you back
to this page if the data selected is insufficient to run your class.
-
+
+
-
-
+
+
+ value="$env{'form.upfile_associate'}" />
-
-
-
-
+
+
-
ENDPICK
- $request->print(&show_grading_menu_form($symb,$url));
+ $request->print(&Apache::lonhtmlcommon::scripttag($javascript));
return '';
}
sub csvupload_fields {
- my ($url) = @_;
- my (@parts) = &getpartlist($url);
- my @fields=(['username','Student Username'],['domain','Student Domain']);
+ my ($symb,$errorref) = @_;
+ my (@parts) = &getpartlist($symb,$errorref);
+ if (ref($errorref)) {
+ if ($$errorref) {
+ return;
+ }
+ }
+
+ my @fields=(['ID','Student/Employee ID'],
+ ['username','Student Username'],
+ ['domain','Student Domain']);
+ my (undef,undef,$url) = &Apache::lonnet::decode_symb($symb);
foreach my $part (sort(@parts)) {
my @datum;
my $display=&Apache::lonnet::metadata($url,$part.'.display');
my $name=$part;
if (!$display) { $display = $name; }
@datum=($name,$display);
+ if ($name=~/^stores_(.*)_awarded/) {
+ push(@fields,['stores_'.$1.'_points',"Points [Part: $1]"]);
+ }
push(@fields,\@datum);
}
return (@fields);
@@ -2479,73 +3898,80 @@ sub csvuploadmap_footer {
-
+
ENDPICK
}
-sub upcsvScores_form {
- my ($request) = shift;
- my ($symb,$url)=&get_symb_and_url($request);
- if (!$symb) {return '';}
- my $result =<
+sub checkforfile_js {
+ my $alertmsg = &mt('Please use the browse button to select a file from your local directory.');
+ my $result = &Apache::lonhtmlcommon::scripttag(<
CSVFORMJS
- $ENV{'form.probTitle'} = &Apache::lonnet::gettitle($symb);
- my ($table) = &showResourceInfo($url,$ENV{'form.probTitle'});
- $result.=$table;
- $result.='
'."\n";
- $result.='
'."\n";
- $result.=' Specify a file containing the class scores for current resource'.
- '.
'."\n";
+ return $result;
+}
+
+sub upcsvScores_form {
+ my ($request,$symb) = @_;
+ if (!$symb) {return '';}
+ my $result=&checkforfile_js();
+ $result.='
'."\n";
+ $result.='
'."\n";
+ $result.=' '.&mt('Specify a file containing the class scores for current resource.').
+ '
'."\n";
$result.='
'."\n";
+ my $upload=&mt("Upload Scores");
my $upfile_select=&Apache::loncommon::upfile_select_html();
+ my $ignore=&mt('Ignore First Line');
+ $symb = &Apache::lonenc::check_encrypt($symb);
$result.=<
-
-
-
+
$upfile_select
-
-
+
+
ENDUPFORM
- $result.='
'."\n";
+ $result.=&Apache::loncommon::help_open_topic("Course_Convert_To_CSV",
+ &mt("How do I create a CSV file from a spreadsheet"))
+ .'
'."\n";
$result.='
'."\n";
- $result.=&show_grading_menu_form($symb,$url);
+ $result.=&show_grading_menu_form($symb);
return $result;
}
sub csvuploadmap {
- my ($request)= @_;
- my ($symb,$url)=&get_symb_and_url($request);
+ my ($request,$symb)= @_;
if (!$symb) {return '';}
my $datatoken;
- if (!$ENV{'form.datatoken'}) {
+ if (!$env{'form.datatoken'}) {
$datatoken=&Apache::loncommon::upfile_store($request);
} else {
- $datatoken=$ENV{'form.datatoken'};
+ $datatoken=$env{'form.datatoken'};
&Apache::loncommon::load_tmp_file($request);
}
my @records=&Apache::loncommon::upfile_record_sep();
- &csvuploadmap_header($request,$symb,$url,$datatoken,$#records+1);
+ if ($env{'form.noFirstLine'}) { shift(@records); }
+ &csvuploadmap_header($request,$symb,$datatoken,$#records+1);
my ($i,$keyfields);
if (@records) {
- my @fields=&csvupload_fields($url);
-
- if ($ENV{'form.upfile_associate'} eq 'reverse') {
+ my $fieldserror;
+ my @fields=&csvupload_fields($symb,\$fieldserror);
+ if ($fieldserror) {
+ $request->print(&navmap_errormsg());
+ return;
+ }
+ if ($env{'form.upfile_associate'} eq 'reverse') {
&Apache::loncommon::csv_print_samples($request,\@records);
$i=&Apache::loncommon::csv_print_select_table($request,\@records,
\@fields);
@@ -2555,47 +3981,120 @@ sub csvuploadmap {
unshift(@fields,['none','']);
$i=&Apache::loncommon::csv_samples_select_table($request,\@records,
\@fields);
- my %sone=&Apache::loncommon::record_sep($records[0]);
- $keyfields=join(',',sort(keys(%sone)));
+ foreach my $rec (@records) {
+ my %temp = &Apache::loncommon::record_sep($rec);
+ if (%temp) {
+ $keyfields=join(',',sort(keys(%temp)));
+ last;
+ }
+ }
}
}
&csvuploadmap_footer($request,$i,$keyfields);
- $request->print(&show_grading_menu_form($symb,$url));
+ $request->print(&show_grading_menu_form($symb));
return '';
}
-sub csvuploadassign {
- my ($request)= @_;
- my ($symb,$url)=&get_symb_and_url($request);
- if (!$symb) {return '';}
- &Apache::loncommon::load_tmp_file($request);
- my @gradedata = &Apache::loncommon::upfile_record_sep();
- my @keyfields = split(/\,/,$ENV{'form.keyfields'});
- my %fields=();
- for (my $i=0; $i<=$ENV{'form.nfields'}; $i++) {
- if ($ENV{'form.upfile_associate'} eq 'reverse') {
- if ($ENV{'form.f'.$i} ne 'none') {
- $fields{$keyfields[$i]}=$ENV{'form.f'.$i};
+sub csvuploadoptions {
+ my ($request,$symb)= @_;
+ my $checked=(($env{'form.noFirstLine'})?'1':'0');
+ my $ignore=&mt('Ignore First Line');
+ $request->print(<
+
Uploading Class Grade Options
+
+
+
+
+
+ENDPICK
+ my %fields=&get_fields();
+ if (!defined($fields{'domain'})) {
+ my $domform = &Apache::loncommon::select_dom_form($env{'request.role.domain'},'default_domain');
+ $request->print("\n
Users are in domain: ".$domform."
\n");
+ }
+ foreach my $key (sort(keys(%env))) {
+ if ($key !~ /^form\.(.*)$/) { next; }
+ my $cleankey=$1;
+ if ($cleankey eq 'command') { next; }
+ $request->print(''."\n");
+ }
+ # FIXME do a check for any duplicated user ids...
+ # FIXME do a check for any invalid user ids?...
+ $request->print('
+'."\n");
+ $request->print(&show_grading_menu_form($symb));
+ return '';
+}
+
+sub get_fields {
+ my %fields;
+ my @keyfields = split(/\,/,$env{'form.keyfields'});
+ for (my $i=0; $i<=$env{'form.nfields'}; $i++) {
+ if ($env{'form.upfile_associate'} eq 'reverse') {
+ if ($env{'form.f'.$i} ne 'none') {
+ $fields{$keyfields[$i]}=$env{'form.f'.$i};
}
} else {
- if ($ENV{'form.f'.$i} ne 'none') {
- $fields{$ENV{'form.f'.$i}}=$keyfields[$i];
+ if ($env{'form.f'.$i} ne 'none') {
+ $fields{$env{'form.f'.$i}}=$keyfields[$i];
}
}
}
+ return %fields;
+}
+
+sub csvuploadassign {
+ my ($request,$symb)= @_;
+ if (!$symb) {return '';}
+ my $error_msg = '';
+ &Apache::loncommon::load_tmp_file($request);
+ my @gradedata = &Apache::loncommon::upfile_record_sep();
+ if ($env{'form.noFirstLine'}) { shift(@gradedata); }
+ my %fields=&get_fields();
$request->print('
Assigning Grades
');
- my $courseid=$ENV{'request.course.id'};
+ my $courseid=$env{'request.course.id'};
my ($classlist) = &getclasslist('all',0);
my @notallowed;
my @skipped;
my $countdone=0;
foreach my $grade (@gradedata) {
my %entries=&Apache::loncommon::record_sep($grade);
+ my $domain;
+ if ($entries{$fields{'domain'}}) {
+ $domain=$entries{$fields{'domain'}};
+ } else {
+ $domain=$env{'form.default_domain'};
+ }
+ $domain=~s/\s//g;
my $username=$entries{$fields{'username'}};
- my $domain=$entries{$fields{'domain'}};
+ $username=~s/\s//g;
+ if (!$username) {
+ my $id=$entries{$fields{'ID'}};
+ $id=~s/\s//g;
+ my %ids=&Apache::lonnet::idget($domain,$id);
+ $username=$ids{$id};
+ }
if (!exists($$classlist{"$username:$domain"})) {
- push(@skipped,"$username:$domain");
+ my $id=$entries{$fields{'ID'}};
+ $id=~s/\s//g;
+ if ($id) {
+ push(@skipped,"$id:$domain");
+ } else {
+ push(@skipped,"$username:$domain");
+ }
next;
}
my $usec=$classlist->{"$username:$domain"}[5];
@@ -2603,34 +4102,70 @@ sub csvuploadassign {
push(@notallowed,"$username:$domain");
next;
}
+ my %points;
my %grades;
foreach my $dest (keys(%fields)) {
- if ($dest eq 'username' || $dest eq 'domain') { next; }
- if ($entries{$fields{$dest}} eq '') { next; }
- my $store_key=$dest;
- $store_key=~s/^stores/resource/;
- $store_key=~s/_/\./g;
- $grades{$store_key}=$entries{$fields{$dest}};
- }
- $grades{"resource.regrader"}="$ENV{'user.name'}:$ENV{'user.domain'}";
- &Apache::lonnet::cstore(\%grades,$symb,$ENV{'request.course.id'},
- $domain,$username);
- $request->print('.');
- $request->rflush();
- $countdone++;
+ if ($dest eq 'ID' || $dest eq 'username' ||
+ $dest eq 'domain') { next; }
+ if ($entries{$fields{$dest}} =~ /^\s*$/) { next; }
+ if ($dest=~/stores_(.*)_points/) {
+ my $part=$1;
+ my $wgt =&Apache::lonnet::EXT('resource.'.$part.'.weight',
+ $symb,$domain,$username);
+ if ($wgt) {
+ $entries{$fields{$dest}}=~s/\s//g;
+ my $pcr=$entries{$fields{$dest}} / $wgt;
+ my $award=($pcr == 0) ? 'incorrect_by_override'
+ : 'correct_by_override';
+ $grades{"resource.$part.awarded"}=$pcr;
+ $grades{"resource.$part.solved"}=$award;
+ $points{$part}=1;
+ } else {
+ $error_msg = " " .
+ &mt("Some point values were assigned"
+ ." for problems with a weight "
+ ."of zero. These values were "
+ ."ignored.");
+ }
+ } else {
+ if ($dest=~/stores_(.*)_awarded/) { if ($points{$1}) {next;} }
+ if ($dest=~/stores_(.*)_solved/) { if ($points{$1}) {next;} }
+ my $store_key=$dest;
+ $store_key=~s/^stores/resource/;
+ $store_key=~s/_/\./g;
+ $grades{$store_key}=$entries{$fields{$dest}};
+ }
+ }
+ if (! %grades) {
+ push(@skipped,&mt("[_1]: no data to save","$username:$domain"));
+ } else {
+ $grades{"resource.regrader"}="$env{'user.name'}:$env{'user.domain'}";
+ my $result=&Apache::lonnet::cstore(\%grades,$symb,
+ $env{'request.course.id'},
+ $domain,$username);
+ if ($result eq 'ok') {
+ $request->print('.');
+ } else {
+ $request->print("
".
+ &mt("Failed to save data for student [_1]. Message when trying to save was: [_2]",
+ "$username:$domain",$result)."
');
- foreach my $student (@skipped) { $request->print("$student \n"); }
+ $request->print(' '.&Apache::lonhtmlcommon::confirm_success(&mt('No scores stored for the following username(s):'),1).' ');
+ $request->print(join(', ',@skipped));
}
if (@notallowed) {
- $request->print('
Students Not Allowed to Modify
');
- foreach my $student (@notallowed) { $request->print("$student \n"); }
+ $request->print(' '.&Apache::lonhtmlcommon::confirm_success(&mt('Modification of scores not allowed for the following username(s):'),1).' ');
+ $request->print(join(', ',@notallowed));
}
$request->print(" \n");
- $request->print(&show_grading_menu_form($symb,$url));
- return '';
+ $request->print(&show_grading_menu_form($symb));
+ return $error_msg;
}
#------------- end of section for handling csv file upload ---------
#
@@ -2640,46 +4175,54 @@ sub csvuploadassign {
#
#--- Select a page/sequence and a student to grade
sub pickStudentPage {
- my ($request) = shift;
+ my ($request,$symb) = @_;
- $request->print(<
+ my $alertmsg = &mt('Please select the student you wish to grade.');
+ $request->print(&Apache::lonhtmlcommon::scripttag(<
LISTJAVASCRIPT
&commonJSfunctions($request);
- my ($symb,$url) = &get_symb_and_url($request);
- my $cdom = $ENV{"course.$ENV{'request.course.id'}.domain"};
- my $cnum = $ENV{"course.$ENV{'request.course.id'}.num"};
- my $getsec = $ENV{'form.section'} eq '' ? 'all' : $ENV{'form.section'};
- my $result='
'.
- 'Manual Grading by Page or Sequence
';
+ my $cdom = $env{"course.$env{'request.course.id'}.domain"};
+ my $cnum = $env{"course.$env{'request.course.id'}.num"};
+ my $getsec = $env{'form.section'} eq '' ? 'all' : $env{'form.section'};
+
+ my $result='
'.
+ &mt('Manual Grading by Page or Sequence').'
';
$result.=''."\n";
+ if ($ptr%2 == 0) {
+ $studentTable.='
'.
+ &Apache::loncommon::end_data_table_row();
+ }
+ $studentTable.=&Apache::loncommon::end_data_table()."\n";
+ $studentTable.=''."\n";
- $studentTable.=&show_grading_menu_form($symb,$url);
+ $studentTable.=&show_grading_menu_form($symb);
$request->print($studentTable);
return '';
}
sub getSymbMap {
- my ($request) = @_;
- my $navmap = Apache::lonnavmaps::navmap-> new($ENV{'request.course.fn'}.'.db',
- $ENV{'request.course.fn'}.'_parms.db');
- $navmap->init();
-
+ my ($map_error) = @_;
+ my $navmap = Apache::lonnavmaps::navmap->new();
+ unless (ref($navmap)) {
+ if (ref($map_error)) {
+ $$map_error = 'navmap';
+ }
+ return;
+ }
my %symbx = ();
my @titles = ();
my $minder = 0;
# Gather every sequence that has problems.
- my @sequences = $navmap->retrieveResources(undef, sub { shift->is_map(); }, 1);
+ my @sequences = $navmap->retrieveResources(undef, sub { shift->is_map(); },
+ 1,0,1);
for my $sequence ($navmap->getById('0.0'), @sequences) {
if ($navmap->hasResource($sequence, sub { shift->is_problem(); }, 0) ) {
- my $title = $minder.'.'.$sequence->compTitle();
- push @titles, $title; # minder in case two titles are identical
- $symbx{$title} = $sequence->symb();
+ my $title = $minder.'.'.
+ &HTML::Entities::encode($sequence->compTitle(),'"\'&');
+ push(@titles, $title); # minder in case two titles are identical
+ $symbx{$title} = &HTML::Entities::encode($sequence->symb(),'"\'&');
$minder++;
}
}
-
- $navmap->untieHashes();
return \@titles,\%symbx;
}
#
#--- Displays a page/sequence w/wo problems, w/wo submissions
sub displayPage {
- my ($request) = shift;
-
- my ($symb,$url) = &get_symb_and_url($request);
- my $cdom = $ENV{"course.$ENV{'request.course.id'}.domain"};
- my $cnum = $ENV{"course.$ENV{'request.course.id'}.num"};
- my $getsec = $ENV{'form.section'} eq '' ? 'all' : $ENV{'form.section'};
- my $pageTitle = $ENV{'form.page'};
+ my ($request,$symb) = @_;
+ my $cdom = $env{"course.$env{'request.course.id'}.domain"};
+ my $cnum = $env{"course.$env{'request.course.id'}.num"};
+ my $getsec = $env{'form.section'} eq '' ? 'all' : $env{'form.section'};
+ my $pageTitle = $env{'form.page'};
my ($classlist,undef,$fullname) = &getclasslist($getsec,'1');
- my ($uname,$udom) = split(/:/,$ENV{'form.student'});
- my $usec=$classlist->{$ENV{'form.student'}}[5];
+ my ($uname,$udom) = split(/:/,$env{'form.student'});
+ my $usec=$classlist->{$env{'form.student'}}[5];
+
+ #need to make sure we have the correct data for later EXT calls,
+ #thus invalidate the cache
+ &Apache::lonnet::devalidatecourseresdata(
+ $env{'course.'.$env{'request.course.id'}.'.num'},
+ $env{'course.'.$env{'request.course.id'}.'.domain'});
+ &Apache::lonnet::clear_EXT_cache_status();
+
if (!&canview($usec)) {
- $request->print('Unable to view requested student.('.$ENV{'form.student'}.')');
- $request->print(&show_grading_menu_form($symb,$url));
+ $request->print(''.&mt('Unable to view requested student. ([_1])',$env{'form.student'}).'');
+ $request->print(&show_grading_menu_form($symb));
return;
}
- my $result='