--- loncom/homework/grades.pm 2002/07/03 21:05:33 1.35
+++ loncom/homework/grades.pm 2002/07/10 21:08:38 1.38
@@ -1,7 +1,7 @@
# The LearningOnline Network with CAPA
# The LON-CAPA Grading handler
#
-# $Id: grades.pm,v 1.35 2002/07/03 21:05:33 ng Exp $
+# $Id: grades.pm,v 1.38 2002/07/10 21:08:38 ng Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -40,7 +40,9 @@ use Apache::lonxml;
use Apache::lonnet;
use Apache::loncommon;
use Apache::lonhomework;
+use Apache::lonmsg qw(:user_normal_msg);
use Apache::Constants qw(:common);
+use Time::HiRes qw( gettimeofday tv_interval );
sub moreinfo {
my ($request,$reason) = @_;
@@ -136,9 +138,11 @@ sub listStudents {
Resource: $ENV{'form.url'}
View Problem: no
- yes
- Submissions: last
- all
+ yes
+ Submissions:
+ last sub only
+ last sub & parts info
+ all details
@@ -157,7 +161,12 @@ ENDTABLEST
}
$request->print(''."\n");
+ my $t0=&Time::HiRes::time();
+
my ($classlist) = &getclasslist($getsec,'0');
+ my $t1=&Time::HiRes::time();
+ print "getclasslist=",$t1-$t0," ";
+
foreach my $student ( sort(@{ $$classlist{$getsec} }) ) {
my ($sname,$sdom) = split(/:/,$student);
my ($type,$status) = &student_gradeStatus($ENV{'form.url'},$cdom,$sname);
@@ -176,6 +185,8 @@ ENDTABLEST
$request->print('');
}
}
+ my $t2=&Time::HiRes::time();
+ print "processclasslist=",$t2-$t1," ";
$request->print('');
$request->print('
';
+ $result.='';
return $result;
}
@@ -350,81 +361,6 @@ sub setstudentgrade {
sub submission {
my ($request,$counter,$total) = @_;
- if ($counter == 0) {
- $request->print(<
- function updateRadio(radioButton,formtextbox,formsel,wgt) {
- var pts = formtextbox.value;
- var resetbox =false;
- if (isNaN(pts) || pts < 0) {
- alert("A number equal or greater than 0 is expected. Entered value = "+pts);
- for (var i=0; i 0 && pts < wgt) {
- formsel[4].selected = true;
- }
- if (pts == wgt) {
- formsel[0].selected = true;
- }
- return;
- }
-
- function keywords(keyform) {
- var keywds = keyform.value;
- var nret = prompt("Keywords list, separate by a space or comma. Add/delete to list if desired.",keywds);
- if (nret==null) return;
- keyform.value = nret;
- return;
- }
-
- function addmsg(msgform) {
- var msg = msgform.value;
- var nret = prompt("Enter the message you wish to send to the student.",msg);
- if (nret==null) return;
- msgform.value = nret;
- return;
- }
-
- function savedmsg(msgform) {
- var Nmsg = msgform.value;
- var nret = prompt("Number of saved messages = ",Nmsg);
- if (nret==null) return;
- msgform.value = nret;
- return;
- }
-
-
-JAVASCRIPT
-}
(my $url=$ENV{'form.url'})=~s-^http://($ENV{'SERVER_NAME'}|$ENV{'HTTP_HOST'})--;
if ($ENV{'form.student'} eq '') { &moreinfo($request,'Need student login id'); return ''; }
my ($uname,$udom) = &finduser($ENV{'form.student'});
@@ -433,82 +369,104 @@ JAVASCRIPT
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 $last = ($ENV{'form.lastSub'} eq 'last' ? 'last' : '');
-#
-# header info
- if ($counter == 0) {
- $request->print('
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' && $counter == 0) {
- my $rendered=&Apache::loncommon::get_student_view($symb,$uname,$udom,
- $ENV{'request.course.id'});
- my $companswer=&Apache::loncommon::get_student_answers($symb,$uname,$udom,
- $ENV{'request.course.id'});
- my $result.='
';
- $request->print($result);
- }
-#
-# beginning of form
+ # header info
if ($counter == 0) {
- my %keyhash = &Apache::lonnet::get
- ('nohist_handgrade',[$symb.'_keywords'],
- $ENV{'course.'.$ENV{'request.course.id'}.'.domain'},
- $ENV{'course.'.$ENV{'request.course.id'}.'.num'});
+ &sub_page_js($request);
+ $request->print('
Submission Record
'.
+ ' Resource: '.$url.'');
+
+ # 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') {
+ my $rendered=&Apache::loncommon::get_student_view($symb,$uname,$udom,
+ $ENV{'request.course.id'});
+ my $companswer=&Apache::loncommon::get_student_answers($symb,$uname,$udom,
+ $ENV{'request.course.id'});
+ my $result.='
';
+ $request->print($result);
+ }
+
+ # kwclr is the only variable that is non blank if this has been used once.
+ my %keyhash = ();
+ if ($ENV{'form.kwclr'} eq '') {
+ %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'} : &Apache::lonnet::metadata($url,'title');
+ $ENV{'form.savemsgN'} = $keyhash{$symb.'_savemsgN'} ne '' ? $keyhash{$symb.'_savemsgN'} : '0';
+ }
$request->print('';
$request->print($endform);
}
+
return '';
}
sub get_last_submission {
my ($symb,$username,$domain,$course)=@_;
if ($symb) {
+ my (@string,@timestamp);
my (%returnhash)=&Apache::lonnet::restore($symb,$course,$domain,$username);
if ($returnhash{'version'}) {
my %lasthash=();
- my $version;
+ my ($version);
for ($version=1;$version<=$returnhash{'version'};$version++) {
foreach (sort(split(/\:/,$returnhash{$version.':keys'}))) {
$lasthash{$_}=$returnhash{$version.':'.$_};
}
}
foreach ((keys %lasthash)) {
- if ($_ =~ /\.submission$/) {return $lasthash{$_}}
+ print "lasthash key=$_ ";
+ if ($_ =~ /\.submission$/) {push @string, $_,$lasthash{$_}}
+ if ($_ =~ /timestamp/) {push @timestamp, scalar(localtime($lasthash{$_}))};
+# if ($_ =~ /\.submission$/) {$string = $lasthash{$_}}
+# if ($_ =~ /timestamp/) {$timestamp=scalar(localtime($lasthash{$_}))};
}
- return '';
}
+ @string = $string[0] eq '' ? 'Nothing submitted - no attempts.' : @string;
+ return \@string,\@timestamp;
}
}
sub keywords_highlight {
my $string = shift;
- (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)));
- my %keyhash = &Apache::lonnet::get
- ('nohist_handgrade',[$symb.'_keywords'],
- $ENV{'course.'.$ENV{'request.course.id'}.'.domain'},
- $ENV{'course.'.$ENV{'request.course.id'}.'.num'});
- my @keylist = split(/[,\s+]/,$keyhash{$symb.'_keywords'});
- foreach my $word (@keylist) {
- next if ($word eq '');
- $string =~ s/\b$word(\b|\.)/\$word\<\/font\>/gi;
+ 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) {
+ # next if ($_ eq '');
+ $string =~ s/\b$_(\b|\.)/\$styleon$_$styleoff\<\/font\>/gi;
}
return $string;
}
@@ -638,27 +617,67 @@ sub processHandGrade {
my $button = $ENV{'form.gradeOpt'};
my $ngrade = $ENV{'form.NCT'};
my $ntstu = $ENV{'form.NTSTU'};
- my $keywords= $ENV{'form.keywords'};
- my $addmsg = $ENV{'form.addmsg'};
- print "addmsg=$addmsg ";
- if ($keywords ne '') {
- my $crsname = $ENV{'course.'.$ENV{'request.course.id'}.'.num'};
- my $crsdom = $ENV{'course.'.$ENV{'request.course.id'}.'.domain'};
- my $putresult = &Apache::lonnet::put
- ('nohist_handgrade',{$symb.'_keywords' => $keywords},
- $crsdom,$crsname);
+
+ my $loginuser = $ENV{'user.name'}.':'.$ENV{'user.domain'};
+ my %keyhash = ();
+ $ENV{'form.keywords'} =~ s/,\s{0,}|\s+/ /g;
+ $keyhash{$symb.'_handgrade'} = 'activated';
+ $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'};
+
+ my ($ctr,$idx) = (1,1);
+ 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};
+ $idx++;
+ }
+ $ctr++;
}
+ $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'});
+
my (@parts) = sort(&getpartlist($url));
if ($button eq 'Save & Next') {
my $ctr = 0;
- while ($ctr < $ENV{'form.NCT'}) {
+ while ($ctr < $ngrade) {
my ($uname,$udom) = split(/:/,$ENV{'form.unamedom'.$ctr});
&saveHandGrade($url,$symb,$uname,$udom,$ctr,@parts);
+
+ my $includemsg = $ENV{'form.includemsg'.$ctr};
+ my ($subject,$message,$msgstatus) = ('','','');
+ if ($includemsg =~ /savemsg|new$ctr/) {
+ $subject = $ENV{'form.msgsub'} if ($includemsg =~ /^msgsub/);
+ my (@msgnum) = split(/,/,$includemsg);
+ foreach (@msgnum) {
+ $message.=$ENV{'form.'.$_} if ($_ =~ /savemsg|newmsg/ && $_ ne '');
+ }
+ $message =~ s/\s+/ /g;
+ $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) {
&saveHandGrade($url,$symb,$_,$udom,$ctr,@parts);
+ if ($message ne '') {
+ $msgstatus = &Apache::lonmsg::user_normal_msg ($uname,$udom,$ENV{'form.msgsub'},$message);
+ }
}
}
$ctr++;
@@ -668,11 +687,13 @@ sub processHandGrade {
my $laststu = $ENV{'form.unamedom'.($ngrade-1)};
my ($classlist) = &getclasslist($ENV{'form.section'},'0');
-
my (@nextlist,@prevlist);
my ($nextflg,$prevflg,$ctr,$ctprev) = (0,0,0,0);
foreach my $student ( sort(@{ $$classlist{$ENV{'form.section'}} }) ) {
my ($uname,$udom) = split(/:/,$student);
+ my ($type,$status) = &student_gradeStatus($ENV{'form.url'},$udom,$uname);
+ next if ($status eq 'nothing' && $ENV{'form.submitonly'} eq 'yes');
+
if ($nextflg == 1 && $button =~ /Next$/) {
push @nextlist,$uname if ($ctr < $ntstu);
$ctr++;
@@ -703,8 +724,14 @@ sub processHandGrade {
&submission($request,$ctr,$total);
$ctr++;
}
-
- return 'The End';
+ 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);
+ $request->print($the_end);
+ }
+ return '';
}
sub saveHandGrade {
@@ -783,6 +810,11 @@ sub gradingmenu {
my $allkeys = &Apache::lonnet::metadata($url,'keys');
my $handgrade = ($allkeys =~ /parameter_.*?_handgrade/ ? 'yes' : 'no');
my ($responsetype,$foo) = split(/_/,&Apache::lonnet::metadata($url,'packages'));
+ $allkeys=~s/,/\ /g;
+# print "allkeys=$allkeys
";
+ $Apache::lonxml::debug=1;
+ &Apache::lonxml::debug(join(':',&Apache::lonnet::metadata($url,'packages')));
+ $Apache::lonxml::debug=0;
my $result='
Select a Grading Method
';
$result.='
';
@@ -791,11 +823,20 @@ sub gradingmenu {
$result.='
Type:
'.
'
'.$responsetype.' Handgrade: '.$handgrade.'
';
$result.='
';
-
+ my $t0=&Time::HiRes::time();
$result.=&view_edit_entire_class_form($symb,$url).' ';
+ my $t1=&Time::HiRes::time();
+ print "elapsed10=",$t1-$t0," ";
$result.=&upcsvScores_form($symb,$url).' ';
+ my $t2=&Time::HiRes::time();
+ print "elapsed21=",$t2-$t1," ";
$result.=&viewGradeaStu_form($symb,$url,$responsetype,$handgrade).' ';
+ my $t3=&Time::HiRes::time();
+ print "elapsed32=",$t3-$t2," ";
$result.=&verifyReceipt_form($symb,$url);
+ my $t4=&Time::HiRes::time();
+ print "elapsed43=",$t4-$t3," ";
+ print "Total elapsed time=",$t4-$t0," ";
return $result;
}
@@ -842,7 +883,16 @@ ENDUPFORM
sub viewGradeaStu_form {
my ($symb,$url,$response,$handgrade) = @_;
+
+
+ my $t3=&Time::HiRes::time();
+
my ($classlist,$sections) = &getclasslist('all','0');
+
+ my $t4=&Time::HiRes::time();
+ print "elapsed_getclasslist=",$t4-$t3," ";
+
+
my $result.='
'."\n";
$result.='
'."\n";
$result.=' View/Grade an Individual Student\'s Submission
'."\n";
@@ -909,8 +959,8 @@ sub viewgrades {
my ($cdom,$cnum) = split(/_/,$ENV{'request.course.id'});
#print "Found $cdom:$cnum ";
my ($classlist) = &getclasslist('all','0');
- my $headerclr = '"#ccffff"';
- my $cellclr = '"#ffffcc"';
+ my $headerclr = '"#ddffff"';
+ my $cellclr = '"#ffffdd"';
#get list of parts for this problem
my (@parts) = sort(&getpartlist($url));
@@ -925,7 +975,7 @@ sub viewgrades {
''."\n".
'
'."\n".
'
'."\n".
- '
Username
Name
Domain
'."\n";
+ '
Username
Fullname
Domain
'."\n";
foreach my $part (@parts) {
my $display=&Apache::lonnet::metadata($url,$part.'.display');
if (!$display) { $display = &Apache::lonnet::metadata($url,$part.'.name'); }
@@ -934,7 +984,7 @@ sub viewgrades {
$result.='
';
#get info for each student
foreach my $student ( sort(@{ $$classlist{'all'} }) ) {
- my $display=&viewstudentgrade($url,$symb,$ENV{'request.course.id'},$student,@parts);
+# my $display=&viewstudentgrade($url,$symb,$ENV{'request.course.id'},$student,@parts);
# print "ID=$ENV{'request.course.id'}:STU=$student:DIS=$display: \n";
$result.=&viewstudentgrade($url,$symb,$ENV{'request.course.id'},$student,@parts);
}
@@ -973,6 +1023,289 @@ sub editgrades {
return $result;
}
+sub sub_page_js {
+ my $request = shift;
+ $request->print(<
+ function updateRadio(radioButton,formtextbox,formsel,wgt) {
+ var pts = formtextbox.value;
+ var resetbox =false;
+ if (isNaN(pts) || pts < 0) {
+ alert("A number equal or greater than 0 is expected. Entered value = "+pts);
+ for (var i=0; i 0 && pts < wgt) {
+ formsel[4].selected = true;
+ }
+ if (pts == wgt) {
+ formsel[0].selected = true;
+ }
+ return;
+ }
+
+ function keywords(keyform) {
+ var keywds = keyform.value;
+ var nret = prompt("Keywords list, separated by a space. Add/delete to list if desired.",keywds);
+ if (nret==null) return;
+ keyform.value = nret;
+ return;
+ }
+
+//===================== Script to add keyword(s) ==================
+ function getSel() {
+ if (document.getSelection) txt = document.getSelection();
+ else if (document.selection) txt = document.selection.createRange().text;
+ else return;
+ var cleantxt = txt.replace(new RegExp('([\\f\\n\\r\\t\\v ])+', 'g')," ");
+ if (cleantxt=="") {
+ alert("Select a word or group of words from document and then click this link.");
+ return;
+ }
+ var nret = prompt("Add selection to keyword list? Edit if desired.",cleantxt);
+ if (nret==null) return;
+ var curlist = document.SCORE.keywords.value;
+ document.SCORE.keywords.value = curlist+" "+nret;
+ return;
+ }
+
+//====================== Script for composing message ==============
+ function msgCenter(msgform,usrctr,fullname) {
+ var Nmsg = msgform.savemsgN.value;
+ savedMsgHeader(Nmsg,usrctr,fullname);
+ var subject = msgform.msgsub.value;
+ var rtrchk = eval("document.SCORE.includemsg"+usrctr);
+ var msgchk = rtrchk.value;
+// alert("checked=>"+msgchk);
+ re = /msgsub/;
+ var shwsel = "";
+ if (re.test(msgchk)) { shwsel = "checked" }
+ displaySubject(subject,shwsel);
+ for (var i=1; i<=Nmsg; i++) {
+ var testpt = "savemsg"+i+",";
+ re = /testpt/;
+ shwsel = "";
+ if (re.test(msgchk)) { shwsel = "checked" }
+ var message = eval("document.SCORE.savemsg"+i+".value");
+ displaySavedMsg(i,message,shwsel);
+ }
+ newmsg = eval("document.SCORE.newmsg"+usrctr+".value");
+ shwsel = "";
+ re = /newmsg/;
+ if (re.test(msgchk)) { shwsel = "checked" }
+ newMsg(newmsg,shwsel);
+ msgTail();
+ return;
+ }
+
+ function savedMsgHeader(Nmsg,usrctr,fullname) {
+ var height = 30*Nmsg+250;
+ var scrollbar = "no";
+ if (height > 600) {
+ height = 600;
+ scrollbar = "yes";
+ }
+/* if (window.pWin)
+ window.pWin.close(); */
+ pWin = window.open('', 'MessageCenter', 'toolbar=no,location=no,scrollbars='+scrollbar+',screenx=70,screeny=75,width=600,height='+height);
+ pWin.document.write("");
+ pWin.document.write("Message Central");
+
+ pWin.document.write("
+SUBJAVASCRIPT
+}
+
sub csvupload_javascript_reverse_associate {
return(<