--- loncom/homework/grades.pm	2003/08/07 17:32:21	1.132
+++ loncom/homework/grades.pm	2003/09/18 18:45:28	1.139
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # The LON-CAPA Grading handler
 #
-# $Id: grades.pm,v 1.132 2003/08/07 17:32:21 bowersj2 Exp $
+# $Id: grades.pm,v 1.139 2003/09/18 18:45:28 albertel Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -218,7 +218,8 @@ sub commonJSfunctions {
 		}
 	    }
 	} else {
-	    if (selectOne.selected) return selectOne.value;
+            // only one value it must be the selected one
+	    return selectOne.value;
 	}
     }
 </script>
@@ -517,8 +518,8 @@ LISTJAVASCRIPT
     my $saveStatus = $ENV{'form.Status'} eq '' ? 'Active' : $ENV{'form.Status'};
     $ENV{'form.Status'} = $saveStatus;
 
-    $gradeTable.='<input type="radio" name="lastSub" value="lastonly" '.$checklastsub.' /> last sub only'."\n".
-	'<input type="radio" name="lastSub" value="last" /> last sub & parts info'."\n".
+    $gradeTable.='<input type="radio" name="lastSub" value="lastonly" '.$checklastsub.' /> last submission only'."\n".
+	'<input type="radio" name="lastSub" value="last" /> last submission & parts info'."\n".
 	'<input type="radio" name="lastSub" value="datesub" /> by dates and submissions'."\n".
 	'<input type="radio" name="lastSub" value="all" /> all details'."\n".
 	'<input type="hidden" name="section"     value="'.$getsec.'" />'."\n".
@@ -544,7 +545,7 @@ LISTJAVASCRIPT
     $gradeTable.='<input type="button" '."\n".
 	'onClick="javascript:checkSelect(this.form.stuinfo);" '."\n".
 	'value="Next->" />'."\n";
-
+    $gradeTable.='<input type="checkbox" name="checkPlag" checked="on">Check For Plagiarism</input>';
     my (undef, undef, $fullname) = &getclasslist($getsec,'1');  
     $gradeTable.='<table border="0"><tr><td bgcolor="#777777">'.
 	'<table border="0"><tr bgcolor="#e6ffff">';
@@ -1461,13 +1462,20 @@ KEYWORDS
 				my ($ressub,$subval) = split(/:/,$_,2);
                             # Similarity check
 				my $similar='';
-				my ($oname,$odom,$ocrsid,$oessay,$osim)=&most_similar($uname,$udom,$subval);
-				if ($osim) {
-				    $osim=int($osim*100.0);
-				    $similar='<hr /><h3><font color="#FF0000">Essay is '.$osim.
-					'% similar to an essay by '.&Apache::loncommon::plainname($oname,$odom).
-					'</font></h3><blockquote><i>'.
-					&keywords_highlight($oessay).'</i></blockquote><hr />';
+				my $oname;
+				my $odom;
+				my $ocrsid;
+				my $oessay;
+				my $osim;
+				if($ENV{'form.checkPlag'}){
+				    ($oname,$odom,$ocrsid,$oessay,$osim)=&most_similar($uname,$udom,$subval);
+				    if ($osim) {
+					$osim=int($osim*100.0);
+					$similar='<hr /><h3><font color="#FF0000">Essay is '.$osim.
+					    '% similar to an essay by '.&Apache::loncommon::plainname($oname,$odom).
+					    '</font></h3><blockquote><i>'.
+					    &keywords_highlight($oessay).'</i></blockquote><hr />';
+				    }
 				}
 				$lastsubonly.='<tr><td bgcolor="#ffffe6"><b>Part '.
 				    $partid.'</b> <font color="#999999">( ID '.$respid.
@@ -1480,7 +1488,7 @@ KEYWORDS
 				     'this file may contain virusses</font><br />':'').
 				     '<b>Submitted Answer: </b>'.
 				     &cleanRecord($subval,$responsetype,$symb).
-				      '<br /><br />'.$similar."\n"
+				     '<br /><br />'.$similar."\n"
 				     if ($ENV{'form.lastSub'} eq 'lastonly' || 
 					 ($ENV{'form.lastSub'} eq 'hdgrade' && 
 					  $$handgrade{$part} =~ /:yes$/));
@@ -2327,18 +2335,17 @@ sub editgrades {
 		$newrecord{'resource.'.$_.'.awarded'} = 0;
 		$newrecord{'resource.'.$_.'.regrader'}="$ENV{'user.name'}:$ENV{'user.domain'}";
 		$updateflag = 1;
+	    } elsif (!($old_part eq $partial && $old_score eq $score)) {
+		$updateflag = 1;
+		$newrecord{'resource.'.$_.'.awarded'}  = $partial if $partial ne '';
+		$newrecord{'resource.'.$_.'.solved'}   = $score;
+		$rec_update++;
 	    }
 
 	    $line .= '<td align="center">'.$old_aw.'&nbsp;</td>'.
 		'<td align="center">'.$awarded.
 		($score eq 'excused' ? $score : '').'&nbsp;</td>';
 
-	    if (!($old_part eq $partial && $old_score eq $score)) {
-		$updateflag = 1;
-		$newrecord{'resource.'.$_.'.awarded'}  = $partial if $partial ne '';
-		$newrecord{'resource.'.$_.'.solved'}   = $score;
-		$rec_update++;
-	    }
 
 	    my $partid=$_;
 	    foreach my $stores (@parts) {
@@ -2510,7 +2517,6 @@ to this page if the data selected is ins
 $javascript
 </script>
 ENDPICK
-    $request->print(&show_grading_menu_form($symb,$url));
     return '';
 
 }
@@ -2727,7 +2733,9 @@ LISTJAVASCRIPT
     $result.='<form action="/adm/grades" method="post" name="displayPage">'."\n";
     $result.='&nbsp;<b>Problems from:</b> <select name="selectpage">'."\n";
     my ($titles,$symbx) = &getSymbMap($request);
-    my ($curpage,$type,$mapId) = ($symb =~ /(.*?\.(page|sequence))___(\d+)___/); 
+    my ($curpage) =&Apache::lonnet::decode_symb($symb); 
+#    my ($curpage,$mapId) =&Apache::lonnet::decode_symb($symb); 
+#    my $type=($curpage =~ /\.(page|sequence)/);
     my $ctr=0;
     foreach (@$titles) {
 	my ($minder,$showtitle) = ($_ =~ /(\d+)\.(.*)/);
@@ -2845,7 +2853,7 @@ sub displayPage {
     $request->print($result);
 
     my $navmap = Apache::lonnavmaps::navmap->new();
-    my ($mapUrl, $id, $resUrl) = split(/___/, $ENV{'form.page'});
+    my ($mapUrl, $id, $resUrl)=&Apache::lonnet::decode_symb($ENV{'form.page'});
     my $map = $navmap->getResourceByUrl($resUrl); # add to navmaps
 
     my $iterator = $navmap->getIterator($map->map_start(),
@@ -3007,7 +3015,7 @@ sub updateGradeByPage {
     $request->print($result);
 
     my $navmap = Apache::lonnavmaps::navmap->new();
-    my ($mapUrl, $id, $resUrl) = split(/___/, $ENV{'form.page'});
+    my ($mapUrl, $id, $resUrl) = &Apache::lonnet::decode_symb( $ENV{'form.page'});
     my $map = $navmap->getResourceByUrl($resUrl); # add to navmaps
 
     my $iterator = $navmap->getIterator($map->map_start(),
@@ -3129,7 +3137,7 @@ sub getSequenceDropDown {
     my ($request,$symb)=@_;
     my $result='<select name="selectpage">'."\n";
     my ($titles,$symbx) = &getSymbMap($request);
-    my ($curpage,$type,$mapId) = ($symb =~ /(.*?\.(page|sequence))___(\d+)___/); 
+    my ($curpage)=&Apache::lonnet::decode_symb($symb); 
     my $ctr=0;
     foreach (@$titles) {
 	my ($minder,$showtitle) = ($_ =~ /(\d+)\.(.*)/);
@@ -3315,7 +3323,7 @@ sub scantron_filter {
 
 sub scantron_process_students {
     my ($r) = @_;
-    my (undef,undef,$sequence)=split(/___/,$ENV{'form.selectpage'});
+    my (undef,undef,$sequence)=&Apache::lonnet::decode_symb($ENV{'form.selectpage'});
     my ($symb,$url)=&get_symb_and_url($r);
     if (!$symb) {return '';}
     my $default_form_data=&defaultFormData($symb,$url);
@@ -3601,7 +3609,7 @@ sub handler {
     my $command=$ENV{'form.command'};
     if (!$url) {
 	my ($temp1,$temp2);
-	($temp1,$temp2,$ENV{'form.url'})=split(/___/,$symb);
+	($temp1,$temp2,$ENV{'form.url'})=&Apache::lonnet::decode_symb($symb);
 	$url = $ENV{'form.url'};
     }
     &send_header($request);
@@ -3614,7 +3622,7 @@ sub handler {
 		my ($tsymb,$tuname,$tudom,$tcrsid)=
 		    &Apache::lonnet::checkin($token);
 		if ($tsymb) {
-		    my ($map,$id,$url)=split(/\_\_\_/,$tsymb);
+		    my ($map,$id,$url)=&Apache::lonnet::decode_symb($tsymb);
 		    if (&Apache::lonnet::allowed('mgr',$tcrsid)) {
 			$request->print(&Apache::lonnet::ssi_body('/res/'.$url,
 					  ('grade_username' => $tuname,