--- loncom/homework/grades.pm 2002/05/08 18:59:37 1.23
+++ loncom/homework/grades.pm 2002/07/08 21:18:54 1.37
@@ -1,7 +1,7 @@
# The LearningOnline Network with CAPA
# The LON-CAPA Grading handler
#
-# $Id: grades.pm,v 1.23 2002/05/08 18:59:37 www Exp $
+# $Id: grades.pm,v 1.37 2002/07/08 21:18:54 ng Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -29,6 +29,9 @@
# 6/8 Gerd Kortemeyer
# 7/26 H.K. Ng
# 8/20 Gerd Kortemeyer
+# Year 2002
+# June, July 2002 H.K. Ng
+#
package Apache::grades;
use strict;
@@ -50,6 +53,7 @@ sub moreinfo {
if ($ENV{'form.symb'}) {
$request->print(''."\n");
}
+# $request->print(''."\n");
$request->print(''."\n");
$request->print("Student:".''."
\n");
$request->print("Domain:".''."
\n");
@@ -62,9 +66,8 @@ sub moreinfo {
sub verifyreceipt {
my $request=shift;
my $courseid=$ENV{'request.course.id'};
- my $chome=$ENV{"course.$courseid.home"};
- my $cdom=$ENV{"course.$courseid.domain"};
- my $cnum=$ENV{"course.$courseid.num"};
+# my $cdom=$ENV{"course.$courseid.domain"};
+# my $cnum=$ENV{"course.$courseid.num"};
my $receipt=unpack("%32C*",$Apache::lonnet::perlvar{'lonHostID'}).'-'.
$ENV{'form.receipt'};
$receipt=~s/[^\-\d]//g;
@@ -75,8 +78,8 @@ sub verifyreceipt {
if ((&Apache::lonnet::allowed('mgr',$courseid)) && ($symb)) {
$request->print('
Verifying Submission Receipt '.$receipt.'
');
my $matches=0;
- my (%classlist) = &getclasslist($cdom,$cnum,$chome,'0');
- foreach my $student ( sort(@{ $classlist{'allids'} }) ) {
+ my ($classlist) = &getclasslist('all','0');
+ foreach my $student ( sort(@{ $$classlist{'all'} }) ) {
my ($uname,$udom)=split(/\:/,$student);
if ($receipt eq
&Apache::lonnet::ireceipt($uname,$udom,$courseid,$symb)) {
@@ -84,88 +87,138 @@ sub verifyreceipt {
$matches++;
}
}
- $request->print(''.$matches.' match(es)
');
+ $request->printf(''.$matches." match%s
",$matches <= 1 ? '' : 'es');
+# needs to print who is matched
}
return '';
}
+sub student_gradeStatus {
+ my ($url,$udom,$uname) = @_;
+ my $symb=($ENV{'form.symb'} ne '' ? $ENV{'form.symb'} : (&Apache::lonnet::symbread($url)));
+ my %record= &Apache::lonnet::restore($symb,$ENV{'request.course.id'},$udom,$uname);
+ foreach my $part (&getpartlist($url)) {
+ my ($temp,$part,$type)=split(/_/,$part);
+ if ($type eq 'solved') {
+ my ($status,$foo)=split(/_/,$record{"resource.$part.$type"},2);
+ $status = 'partial' if ($foo =~ /^partially/);
+ $status = 'nothing' if ($status eq '');
+ return $type,$status;
+ }
+ }
+ return '';
+}
+
+sub get_fullname {
+ my ($sname,$sdom) = @_;
+ my %name=&Apache::lonnet::get('environment', ['lastname','generation',
+ 'firstname','middlename'],
+ $sdom,$sname);
+ my $fullname;
+ my ($tmp) = keys(%name);
+ if ($tmp !~ /^(con_lost|error|no_such_host)/i) {
+ $fullname=$name{'lastname'}.$name{'generation'};
+ if ($fullname =~ /[^\s]+/) { $fullname.=', '; }
+ $fullname.=$name{'firstname'}.' '.$name{'middlename'};
+ }
+ return $fullname;
+}
+
sub listStudents {
my ($request) = shift;
- my $chome=$ENV{"course.$ENV{'request.course.id'}.home"};
- my $cdom=$ENV{"course.$ENV{'request.course.id'}.domain"};
- my $cnum=$ENV{"course.$ENV{'request.course.id'}.num"};
- my $hostver=unpack("%32C*",$Apache::lonnet::perlvar{'lonHostID'});
- $request->print(<Verify a Submission Receipt Issued by this Server
-
+ENDPICK
+}
+
+sub csvuploadmap {
+ my ($request)= @_;
+ my ($symb,$url)=&get_symb_and_url($request);
+ if (!$symb) {return '';}
+ my $datatoken;
+ if (!$ENV{'form.datatoken'}) {
+ $datatoken=&Apache::loncommon::upfile_store($request);
+ } else {
+ $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);
+ my $i;
+ my $keyfields;
+ if (@records) {
+ my @fields=&csvupload_fields($url);
+ if ($ENV{'form.upfile_associate'} eq 'reverse') {
+ &Apache::loncommon::csv_print_samples($request,\@records);
+ $i=&Apache::loncommon::csv_print_select_table($request,\@records,
+ \@fields);
+ foreach (@fields) { $keyfields.=$_->[0].','; }
+ chop($keyfields);
+ } else {
+ 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)));
+ }
+ }
+ &csvuploadmap_footer($request,$i,$keyfields);
+ 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};
+ }
+ } else {
+ if ($ENV{'form.f'.$i} ne 'none') {
+ $fields{$ENV{'form.f'.$i}}=$keyfields[$i];
+ }
+ }
+ }
+ $request->print('Assigning Grades
');
+ my $courseid=$ENV{'request.course.id'};
+# my $cdom=$ENV{"course.$courseid.domain"};
+# my $cnum=$ENV{"course.$courseid.num"};
+ my ($classlist) = &getclasslist('all','1');
+ my @skipped;
+ my $countdone=0;
+ foreach my $grade (@gradedata) {
+ my %entries=&Apache::loncommon::record_sep($grade);
+ my $username=$entries{$fields{'username'}};
+ my $domain=$entries{$fields{'domain'}};
+ if (!exists($$classlist{"$username:$domain"})) {
+ push(@skipped,"$username:$domain");
+ next;
+ }
+ 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++;
+ }
+ $request->print("
Stored $countdone students\n");
+ if (@skipped) {
+ $request->print('
Skipped Students
');
+ foreach my $student (@skipped) { $request->print("
$student"); }
+ }
+ $request->print(&view_edit_entire_class_form($symb,$url));
+ $request->print(&show_grading_menu_form($symb,$url));
+ return '';
+}
+
sub send_header {
my ($request)= @_;
$request->print(&Apache::lontexconvert::header());
@@ -422,8 +1504,6 @@ sub send_footer {
sub handler {
my $request=$_[0];
- if ( $ENV{'user.name'} eq 'albertel' ) {$Apache::lonxml::debug=1;} else {$Apache::lonxml::debug=0;}
-
if ($ENV{'browser.mathml'}) {
$request->content_type('text/xml');
} else {
@@ -469,16 +1549,40 @@ sub handler {
}
}
} else {
+ #&Apache::lonhomework::showhashsubset(\%ENV,'^form');
$Apache::grades::viewgrades=&Apache::lonnet::allowed('vgr',$ENV{'request.course.id'});
if ($command eq 'submission') {
&listStudents($request) if ($ENV{'form.student'} eq '');
- $request->print(&submission($request)) if ($ENV{'form.student'} ne '');
+ &submission($request,0,0) if ($ENV{'form.student'} ne '');
+ } elsif ($command eq 'processGroup') {
+ &processGroup($request);
+ } elsif ($command eq 'gradingmenu') {
+ $request->print(&gradingmenu($request));
} elsif ($command eq 'viewgrades') {
$request->print(&viewgrades($request));
+ } elsif ($command eq 'handgrade') {
+ $request->print(&processHandGrade($request));
} elsif ($command eq 'editgrades') {
$request->print(&editgrades($request));
} elsif ($command eq 'verify') {
$request->print(&verifyreceipt($request));
+ } elsif ($command eq 'csvupload') {
+ $request->print(&csvupload($request));
+ } elsif ($command eq 'csvuploadmap') {
+ $request->print(&csvuploadmap($request));
+# } elsif ($command eq 'receiptInput') {
+# &receiptInput($request);
+ } elsif ($command eq 'csvuploadassign') {
+ if ($ENV{'form.associate'} ne 'Reverse Association') {
+ $request->print(&csvuploadassign($request));
+ } else {
+ if ( $ENV{'form.upfile_associate'} ne 'reverse' ) {
+ $ENV{'form.upfile_associate'} = 'reverse';
+ } else {
+ $ENV{'form.upfile_associate'} = 'forward';
+ }
+ $request->print(&csvuploadmap($request));
+ }
} else {
$request->print("Unknown action: $command:");
}