--- loncom/homework/grades.pm 2003/03/27 21:26:07 1.78
+++ loncom/homework/grades.pm 2003/06/13 15:43:28 1.96
@@ -1,7 +1,7 @@
# The LearningOnline Network with CAPA
# The LON-CAPA Grading handler
#
-# $Id: grades.pm,v 1.78 2003/03/27 21:26:07 albertel Exp $
+# $Id: grades.pm,v 1.96 2003/06/13 15:43:28 albertel Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -46,6 +46,9 @@ use Apache::lonhomework;
use Apache::loncoursedata;
use Apache::lonmsg qw(:user_normal_msg);
use Apache::Constants qw(:common);
+use String::Similarity;
+
+my %oldessays=();
# ----- These first few routines are general use routines.----
#
@@ -221,6 +224,50 @@ sub jscriptNform {
}
#------------------ End of general use routines --------------------
+
+#
+# Find most similar essay
+#
+
+sub most_similar {
+ my ($uname,$udom,$uessay)=@_;
+
+# ignore spaces and punctuation
+
+ $uessay=~s/\W+/ /gs;
+
+# these will be returned. Do not care if not at least 50 percent similar
+ my $limit=0.6;
+ my $sname='';
+ my $sdom='';
+ my $scrsid='';
+ my $sessay='';
+# go through all essays ...
+ foreach my $tkey (keys %oldessays) {
+ my ($tname,$tdom,$tcrsid)=split(/\./,$tkey);
+# ... except the same student
+ if (($tname ne $uname) || ($tdom ne $udom)) {
+ my $tessay=$oldessays{$tkey};
+ $tessay=~s/\W+/ /gs;
+# String similarity gives up if not even limit
+ my $tsimilar=&String::Similarity::similarity($uessay,$tessay,$limit);
+# Found one
+ if ($tsimilar>$limit) {
+ $limit=$tsimilar;
+ $sname=$tname;
+ $sdom=$tdom;
+ $scrsid=$tcrsid;
+ $sessay=$oldessays{$tkey};
+ }
+ }
+ }
+ if ($limit>0.6) {
+ return ($sname,$sdom,$scrsid,$sessay,$limit);
+ } else {
+ return ('','','','',0);
+ }
+}
+
#-------------------------------------------------------------------
#------------------------------------ Receipt Verification Routines
@@ -343,8 +390,8 @@ LISTJAVASCRIPT
my $checklastsub = $ENV{'form.handgrade'} eq 'yes' ? '' : 'checked';
my $gradeTable='
'."\n";
if ($ctr == 0) {
- $gradeTable=' '.
- 'No submission found for this resource. ';
+ my $num_students=(scalar(keys(%$fullname)));
+ if ($num_students eq 0) {
+ $gradeTable=' There are no students currently enrolled.';
+ } else {
+ $gradeTable=' '.
+ 'No submissions found for this resource for any students. ('.$num_students.' checked for submissions ';
+ }
} elsif ($ctr == 1) {
$gradeTable =~ s/type=checkbox/type=checkbox checked/;
}
@@ -628,6 +680,7 @@ SUBJAVASCRIPT
#--- javascript for essay type problem --
sub sub_page_kw_js {
my $request = shift;
+ my $iconpath = $request->dir_config('lonIconsURL');
$request->print(<
@@ -675,6 +728,12 @@ sub sub_page_kw_js {
}
//====================== Script for composing message ==============
+ // preload images
+ img1 = new Image();
+ img1.src = "$iconpath/mailbkgrd.gif";
+ img2 = new Image();
+ img2.src = "$iconpath/mailto.gif";
+
function msgCenter(msgform,usrctr,fullname) {
var Nmsg = msgform.savemsgN.value;
savedMsgHeader(Nmsg,usrctr,fullname);
@@ -710,7 +769,7 @@ sub sub_page_kw_js {
height = 600;
scrollbar = "yes";
}
-// if (window.pWin) window.pWin.close();
+// if (window.pWin) {window.pWin.close(); window.pWin=null}
pWin = window.open('', 'MessageCenter', 'toolbar=no,location=no,scrollbars='+scrollbar+',screenx=70,screeny=75,width=600,height='+height);
pWin.focus();
pDoc = pWin.document;
@@ -729,18 +788,23 @@ sub sub_page_kw_js {
pDoc.write(" if (document.msgcenter.subchk.checked) {");
pDoc.write(" msgchk = \\"msgsub,\\";");
pDoc.write(" }");
- pDoc.write( "for (var i=1; i<=nmsg; i++) {");
+ pDoc.write(" var includemsg = 0;");
+ pDoc.write(" for (var i=1; i<=nmsg; i++) {");
pDoc.write(" var opnmsg = eval(\\"opener.document.SCORE.savemsg\\"+i);");
pDoc.write(" var frmmsg = eval(\\"document.msgcenter.msg\\"+i);");
pDoc.write(" opnmsg.value = frmmsg.value;");
pDoc.write(" var chkbox = eval(\\"document.msgcenter.msgn\\"+i);");
pDoc.write(" if (chkbox.checked) {");
pDoc.write(" msgchk += \\"savemsg\\"+i+\\",\\";");
+ pDoc.write(" includemsg = 1;");
pDoc.write(" }");
pDoc.write(" }");
pDoc.write(" if (document.msgcenter.newmsgchk.checked) {");
pDoc.write(" msgchk += \\"newmsg\\"+usrctr;");
+ pDoc.write(" includemsg = 1;");
pDoc.write(" }");
+ pDoc.write(" imgformname = eval(\\"opener.document.SCORE.mailicon\\"+usrctr);");
+ pDoc.write(" imgformname.src = \\"$iconpath/\\"+((includemsg) ? \\"mailto.gif\\" : \\"mailbkgrd.gif\\");");
pDoc.write(" var includemsg = eval(\\"opener.document.SCORE.includemsg\\"+usrctr);");
pDoc.write(" includemsg.value = msgchk;");
@@ -1030,7 +1094,7 @@ sub submission {
$request->print('