--- loncom/homework/grades.pm 2002/09/20 23:46:41 1.51 +++ loncom/homework/grades.pm 2003/03/11 19:32:02 1.71 @@ -1,7 +1,7 @@ # The LearningOnline Network with CAPA # The LON-CAPA Grading handler # -# $Id: grades.pm,v 1.51 2002/09/20 23:46:41 albertel Exp $ +# $Id: grades.pm,v 1.71 2003/03/11 19:32:02 ng Exp $ # # Copyright Michigan State University Board of Trustees # @@ -31,6 +31,8 @@ # 8/20 Gerd Kortemeyer # Year 2002 # June-August H.K. Ng +# Year 2003 +# February, March H.K. Ng # package Apache::grades; @@ -39,11 +41,13 @@ use Apache::style; use Apache::lonxml; use Apache::lonnet; use Apache::loncommon; +use Apache::lonnavmaps; use Apache::lonhomework; +use Apache::loncoursedata; use Apache::lonmsg qw(:user_normal_msg); use Apache::Constants qw(:common); -# ----- These first few routines are general use routines.----- +# ----- These first few routines are general use routines.---- # # --- Retrieve the parts that matches stores_\d+ from the metadata file.--- sub getpartlist { @@ -51,7 +55,7 @@ sub getpartlist { my @parts =(); my (@metakeys) = split(/,/,&Apache::lonnet::metadata($url,'keys')); foreach my $key (@metakeys) { - if ( $key =~ m/stores_([0-9]+)_.*/) { + if ( $key =~ m/stores_(\w+)_.*/) { push(@parts,$key); } } @@ -72,13 +76,16 @@ sub get_symb_and_url { sub get_fullname { my ($uname,$udom) = @_; my %name=&Apache::lonnet::get('environment', ['lastname','generation', - 'firstname','middlename'],$udom,$uname); + 'firstname','middlename'], + $udom,$uname); 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'}; + $fullname = &Apache::loncoursedata::ProcessFullName + (@name{qw/lastname generation firstname middlename/}); + } else { + &Apache::lonnet::logthis('grades.pm: no name data for '.$uname. + '@'.$udom.':'.$tmp); } return $fullname; } @@ -91,7 +98,7 @@ sub response_type { my %seen = (); my (@partlist,%handgrade); foreach (split(/,/,&Apache::lonnet::metadata($url,'packages'))) { - if (/^\w+response_\d+.*/) { + if (/^\w+response_\w+.*/) { my ($responsetype,$part) = split(/_/,$_,2); my ($partid,$respid) = split(/_/,$part); $handgrade{$part} = $responsetype.':'.($allkeys =~ /parameter_$part\_handgrade/ ? 'yes' : 'no'); @@ -107,62 +114,32 @@ sub response_type { #--- section, ids and fullnames for each user. sub getclasslist { my ($getsec,$hideexpired) = @_; - my $now = time; - my %classlist=&Apache::lonnet::dump('classlist', - $ENV{'course.'.$ENV{'request.course.id'}.'.domain'}, - $ENV{'course.'.$ENV{'request.course.id'}.'.num'}); - my ($tmp) = keys(%classlist); + my $classlist=&Apache::loncoursedata::get_classlist(); # Bail out if we were unable to get the classlist - return if ($tmp =~ /^(con_lost|error|no_such_host)/i); - - # codes to check for fields in the classlist - # should contain end:start:id:section:fullname - for (keys %classlist) { - my (@fields) = split(/:/,$classlist{$_}); - %classlist = &reformat_classlist(\%classlist) if (scalar(@fields) <= 2); - last; - } - - my (@holdsec,@sections,%allids,%stusec,%fullname); - foreach (keys(%classlist)) { - my ($end,$start,$id,$section,$fullname)=split(/:/,$classlist{$_}); + return if (! defined($classlist)); + # + 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->{$_}}; # still a student? - if (($hideexpired) && ($end) && ($end < $now)) { - next; - } + if (($hideexpired) && ($status ne 'Active')) { + delete ($classlist->{$_}); + next; + } $section = ($section ne '' ? $section : 'no'); - push @holdsec,$section; if ($getsec eq 'all' || $getsec eq $section) { - push (@{ $classlist{$getsec} }, $_); - $allids{$_} =$id; - $stusec{$_} =$section; - $fullname{$_}=$fullname; - } + $sections{$section}++; + $fullnames{$_}=$fullname; + } else { + delete($classlist->{$_}); + } } my %seen = (); - foreach my $item (@holdsec) { - push (@sections, $item) unless $seen{$item}++; - } - return (\%classlist,\@sections,\%allids,\%stusec,\%fullname); -} - -# add id, section and fullname to the classlist.db -# done to maintain backward compatibility with older versions -sub reformat_classlist { - my ($classlist) = shift; - foreach (sort keys(%$classlist)) { - my ($unam,$udom) = split(/:/); - my $section = &Apache::lonnet::usection($udom,$unam,$ENV{'request.course.id'}); - my $fullname = &get_fullname ($unam,$udom); - my %userid = &Apache::lonnet::idrget($udom,($unam)); - $$classlist{$_} = $$classlist{$_}.':'.$userid{$unam}.':'.$section.':'.$fullname; - } - my $putresult = &Apache::lonnet::put - ('classlist',\%$classlist, - $ENV{'course.'.$ENV{'request.course.id'}.'.domain'}, - $ENV{'course.'.$ENV{'request.course.id'}.'.num'}); - - return %$classlist; + my @sections = sort(keys(%sections)); + return ($classlist,\@sections,\%fullnames); } #find user domain @@ -260,12 +237,13 @@ sub verifyreceipt { my $title.='

Verifying Submission Receipt '. $receipt.'

'."\n". - 'Resource: '.$ENV{'form.url'}.'

'."\n"; + 'Problem: '. + &Apache::lonnet::metadata($ENV{'form.url'},'title').'

'."\n"; my ($string,$contents,$matches) = ('','',0); - my ($classlist,$seclist,$ids,$stusec,$fullname) = &getclasslist('all','0'); - - foreach (sort {$$fullname{$a} cmp $$fullname{$b} } keys %$fullname) { + my (undef,undef,$fullname) = &getclasslist('all','0'); + + foreach (sort {lc($$fullname{$a}) cmp lc($$fullname{$b}) } keys %$fullname) { my ($uname,$udom)=split(/\:/); if ($receipt eq &Apache::lonnet::ireceipt($uname,$udom,$courseid,$symb)) { @@ -295,6 +273,10 @@ sub verifyreceipt { return $string.&show_grading_menu_form($symb,$url); } +# +# Pick student and page/sequence for manual grading + + #--- This is called by a number of programs. #--- Called from the Grading Menu - View/Grade an individual student #--- Also called directly when one clicks on the subm button @@ -319,18 +301,13 @@ sub listStudents { } $result.=''; - my $viewgrade; - if ($ENV{'form.handgrade'} eq 'yes') { - $viewgrade = 'View/Grade'; - } else { - $viewgrade = 'View'; - } + my $viewgrade = $ENV{'form.handgrade'} eq 'yes' ? 'View/Grade' : 'View'; $result='

 '. $viewgrade. ' Submissions for a Student or a Group of Students

'. ''.$result; + 'Problem: '.&Apache::lonnet::metadata($url,'title').''.$result; $request->print(< @@ -365,8 +342,9 @@ LISTJAVASCRIPT my $checklastsub = $ENV{'form.handgrade'} eq 'yes' ? '' : 'checked'; my $gradeTable='
'."\n". - ' View Problem: no '."\n". - ' yes
'."\n". + ' View Problem: no '."\n". + ' one student '."\n". + ' all students
'."\n". ' Submissions: '."\n"; if ($ENV{'form.handgrade'} eq 'yes') { $gradeTable.=' handgrade only'."\n"; @@ -389,7 +367,7 @@ LISTJAVASCRIPT 'onClick="javascript:checkSelect(this.form.stuinfo);" '."\n". 'value="'.$viewgrade.'" />'."\n"; - my ($classlist,$seclist,$ids,$stusec,$fullname) = &getclasslist($getsec,'0'); + my (undef,undef,$fullname) = &getclasslist($getsec,'0'); $gradeTable.='
'. - 'Resource: '.$url.'
'. ''. @@ -401,7 +379,7 @@ LISTJAVASCRIPT $gradeTable.=''."\n"; my $ctr = 0; - foreach my $student (sort {$$fullname{$a} cmp $$fullname{$b} } keys %$fullname) { + foreach my $student (sort {lc($$fullname{$a}) cmp lc($$fullname{$b}) } keys %$fullname) { my ($uname,$udom) = split(/:/,$student); my (%status) =&student_gradeStatus($url,$symb,$udom,$uname,$partlist); my $statusflg = ''; @@ -478,91 +456,175 @@ sub sub_page_js { my $request = shift; $request->print(< - function updateRadio(radioButton,formtextbox,formsel,scores,weight) { - 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 weight) { + var resp = confirm("You entered a value ("+pts+ + ") greater than the weight for the part. Accept?"); + if (resp == false) { + gradeBox.value = ""; + return; + } } - return; - } - if (pts > weight) { - var resp = confirm("You entered a value ("+pts+ - ") greater than the weight for the part. Accept?"); - if (resp == false) { - formtextbox.value = ""; - return; - } + for (var i=0; i +SUBJAVASCRIPT +} - } - document.SCORE.submit(); - } +#--- javascript for essay type problem -- +sub sub_page_kw_js { + my $request = shift; + $request->print(< //===================== Show list of keywords ==================== function keywords(keyform) { @@ -697,21 +759,21 @@ sub sub_page_js { pWin.document.write(""); pWin.document.write(""); pWin.document.write(""); - pWin.document.write(""); + pWin.document.write(""); } function displaySavedMsg(ctr,msg,shwsel) { pWin.document.write(""); pWin.document.write(""); pWin.document.write(""); - pWin.document.write(""); + pWin.document.write(""); } function newMsg(newmsg,shwsel) { pWin.document.write(""); pWin.document.write(""); pWin.document.write(""); - pWin.document.write(""); + pWin.document.write(""); } function msgTail() { @@ -820,6 +882,90 @@ function displaySavedMsg(ctr,msg,shwsel) SUBJAVASCRIPT } +#--- 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 $wgt = &Apache::lonnet::EXT('resource.'.$partid.'.weight',$symb,$udom,$uname); + my $wgtmsg = ($wgt > 0 ? '(problem weight)' : + 'problem weight assigned by computer'); + $wgt = ($wgt > 0 ? $wgt : '1'); + my $score = ($$record{'resource.'.$partid.'.awarded'} eq '' ? + '' : $$record{'resource.'.$partid.'.awarded'}*$wgt); + my $result=''."\n"; + + $result.='
Subject
"+ctr+"
New
'."\n"; + $result.=''."\n"; + $result.='
'. + 'Part '.$partid.' Points: '."\n"; + + my $ctr = 0; + $result.=''."\n"; # display radio buttons in a nice table 10 across + while ($ctr<=$wgt) { + $result.= '\n"; + $result.=(($ctr+1)%10 == 0 ? '' : ''); + $ctr++; + } + $result.='
'.$ctr."
'; + + $result.='
 or /'.$wgt.' '.$wgtmsg. + ($$record{'resource.'.$partid.'.solved'} eq 'correct_by_student' ? ' '.$checkIcon : ''). + ' '."\n"; + + $result.=''."\n"; + } else { + $result.=''. + ''."\n"; + } + $result.="  \n"; + $result.=''."\n". + ''."\n". + ''."\n"; + $result.='
'."\n"; + return $result; +} + +sub show_problem { + my ($request,$symb,$uname,$udom,$removeform,$viewon) = @_; + my $rendered=&Apache::loncommon::get_student_view($symb,$uname,$udom, + $ENV{'request.course.id'}); + if ($removeform) { + $rendered=~s|||g; + $rendered=~s|||g; + $rendered=~s|name="submit"|name="would_have_been_submit"|g; + } + my $companswer=&Apache::loncommon::get_student_answers($symb,$uname,$udom, + $ENV{'request.course.id'}); + if ($removeform) { + $companswer=~s|||g; + $companswer=~s|||g; + $rendered=~s|name="submit"|name="would_have_been_submit"|g; + } + my $result.='
'; + $result.=''; + $result.='' if ($viewon); + $result.='
View of the problem - '.$ENV{'form.fullname'}. + '
'.$rendered.'
'; + $result.='Correct answer:
'.$companswer; + $result.='
'; + $result.='

'; + return $result; +# $request->print($result); +} # --------------------------- show submissions of a student, option to grade sub submission { @@ -835,30 +981,20 @@ sub submission { 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' : ''); - $ENV{'form.vProb'} = $ENV{'form.vProb'} ne '' ? $ENV{'form.vProb'} : 'yes'; - my ($classlist,$seclist,$ids,$stusec,$fullname); +# $ENV{'form.vProb'} = $ENV{'form.vProb'} ne '' ? $ENV{'form.vProb'} : 'yes'; # header info if ($counter == 0) { &sub_page_js($request); + &sub_page_kw_js($request); $request->print('

 Submission Record

'."\n". - ' Resource: '.$url.''."\n"); + ' Problem: '. + &Apache::lonnet::metadata($url,'title').''."\n"); # 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.='
'; - $result.='
'; - $result.=' View of the problem - '.$ENV{'form.fullname'}. - '
'.$rendered.'
'; - $result.='Correct answer:
'.$companswer; - $result.='
'; - $result.='

'; - $request->print($result); + if ($ENV{'form.vProb'} eq 'yes' or !$ENV{'form.vProb'}) { + $request->print(&show_problem($request,$symb,$uname,$udom,0,1)); } # kwclr is the only variable that is guaranteed to be non blank @@ -921,6 +1057,11 @@ KEYWORDS } } + if ($ENV{'form.vProb'} eq 'all') { + $request->print('


') if ($counter > 0); + $request->print(&show_problem($request,$symb,$uname,$udom,1,1)); + } + my %record = &Apache::lonnet::restore($symb,$ENV{'request.course.id'},$udom,$uname); my ($partlist,$handgrade) = &response_type($url); @@ -937,49 +1078,61 @@ KEYWORDS # If this is handgraded, then check for collaborators my @col_fullnames; + my ($classlist,$fullname); if ($ENV{'form.handgrade'} eq 'yes') { my @col_list; - ($classlist,$seclist,$ids,$stusec,$fullname) = &getclasslist('all','0'); + ($classlist,undef,$fullname) = &getclasslist('all','0'); for (keys (%$handgrade)) { my $ncol = &Apache::lonnet::EXT('resource.'.$_. - '.maxcollaborators',$symb,$udom,$uname); - if ($ncol > 0) { - s/\_/\./g; - if ($record{'resource.'.$_.'.collaborators'} ne '') { - my (@collaborators) = split(/,?\s+/, - $record{'resource.'.$_.'.collaborators'}); - my (@badcollaborators); - if (scalar(@collaborators) != 0) { - $result.='Collaborators: '; - foreach my $collaborator (@collaborators) { - $collaborator = $collaborator =~ /\@|:/ ? - (split(/@|:/,$collaborator))[0] : $collaborator; - next if ($collaborator eq $uname); - if (!grep /^$collaborator:/i,keys %$classlist) { - push @badcollaborators,$collaborator; - next; - } - push @col_list, $collaborator; - my ($lastname,$givenn) = split(/,/,$$fullname{$collaborator.':'.$udom}); - push @col_fullnames, $givenn.' '.$lastname; - $result.=$$fullname{$collaborator.':'.$udom}.'     '; - } - $result.='
'."\n"; - $result.='
'. - 'This student has submitted '. - (scalar (@badcollaborators) > 1 ? '' : 'an'). - ' invalid collaborator'.(scalar (@badcollaborators) > 1 ? 's. ' : '. '). - (join ', ',@badcollaborators).'
' - if (scalar(@badcollaborators) > 0); - - $result.='
'. - 'This student has submitted too many collaborators. Maximum is '. - $ncol.'.
' if (scalar(@collaborators) > $ncol); - $result.=''."\n"; - } - } - } + '.maxcollaborators', + $symb,$udom,$uname); + next if ($ncol <= 0); + s/\_/\./g; + next if ($record{'resource.'.$_.'.collaborators'} eq ''); + my (@collaborators) = split(/,?\s+/, + $record{'resource.'.$_.'.collaborators'}); + my (@badcollaborators); + if (scalar(@collaborators) != 0) { + $result.='Collaborators: '; + foreach my $collaborator (@collaborators) { + my ($co_name,$co_dom) = split /\@|:/,$collaborator; + $co_dom = $udom if (! defined($co_dom)); + next if ($co_name eq $uname && $co_dom eq $udom); + # Doing this grep allows 'fuzzy' specification + my @Matches = grep /^$co_name:$co_dom/i, + keys %$classlist; + if (! scalar(@Matches)) { + push @badcollaborators,$collaborator; + next; + } + push @col_list, @Matches; + foreach (@Matches) { + my ($lastname,$givenn) = split(/,/,$$fullname{$_}); + push @col_fullnames, $givenn.' '.$lastname; + $result.=$$fullname{$_}.'     '; + } + } + $result.='
'."\n"; + if (scalar(@badcollaborators) > 0) { + $result.=''."\n" if ($ENV{'form.lastSub'} eq 'lastonly' || ($ENV{'form.lastSub'} eq 'hdgrade' && @@ -1067,48 +1225,10 @@ KEYWORDS $seen{$partid}++; next if ($$handgrade{$_} =~ /:no$/); push @partlist,$partid; - my $wgt = &Apache::lonnet::EXT('resource.'.$partid.'.weight',$symb,$udom,$uname); - my $wgtmsg = ($wgt > 0 ? '(problem weight)' : - 'problem weight assigned by computer'); - $wgt = ($wgt > 0 ? $wgt : '1'); - my $score = ($record{'resource.'.$partid.'.awarded'} eq '' ? - '' : $record{'resource.'.$partid.'.awarded'}*$wgt); - $result=''; - $result.='
'; + $result.='This student has submitted '; + if (scalar(@badcollaborators) == 1) { + $result .= 'an invalid collaborator'; + } else { + $result .= 'invalid collaborators'; + } + $result .= ': '.join(', ',@badcollaborators); + + } + if (scalar(@collaborators > $ncol)) { + $result .= '
'; + $result .= 'This student has sumbitted too many '. + 'collaborators. Maximum is '.$ncol; + $result .= '
'; + } + $result.=''."\n"; + } } } $request->print($result."\n"); @@ -1002,7 +1155,7 @@ KEYWORDS } else { my ($string,$timestamp)= &get_last_submission (%record); - my $lastsubonly.=''. + my $lastsubonly=''. ($$timestamp eq '' ? '' : 'Date Submitted: '. $$timestamp).''; if ($$timestamp eq '') { @@ -1015,7 +1168,12 @@ KEYWORDS my ($ressub,$subval) = split(/:/,$_,2); $lastsubonly.='
Part '. $partid.' ( ID '.$respid. - ' )   Answer: '. + ' )   '. + ($record{"resource.$partid.$respid.uploadedurl"}? + ' File uploaded by student Like all files provided by users, this file may contain virusses
':''). + 'Answer: '. &keywords_highlight($subval).'
'; - $result.=''."\n"; - $result.='
Part '.$partid.' Points: '; - my $ctr = 0; - $result.=''; # display radio buttons in a nice table 10 across - while ($ctr<=$wgt) { - $result.= '\n"; - $result.=(($ctr+1)%10 == 0 ? '' : ''); - $ctr++; - } - $result.='
'.$ctr."
'; + $request->print(&gradeBox($request,$symb,$uname,$udom,$counter,$partid,\%record)); - $result.='
 or /'.$wgt.' '.$wgtmsg.' '; - - $result.=''."  \n"; - $result.=''; - $result.='
'."\n"; - $request->print($result); +# $request->print($result); } $result=''."\n"; @@ -1126,7 +1246,7 @@ KEYWORDS ''."\n"; if ($ENV{'form.handgrade'} eq 'yes') { $endform.='  '."\n"; my $ntstu =''."\n"; } $endform.='  '."\n". + 'onClick="javascript:checksubmit(this.form,\'Next\');" TARGET=_self>  '."\n". '  '; + 'onClick="javascript:checksubmit(this.form,\'Previous\');" TARGET=_self>  '; $endform.='(Next and Previous do not save the scores.)'."\n" if ($ENV{'form.handgrade'} eq 'yes'); $endform.='
'; @@ -1161,9 +1281,9 @@ sub get_last_submission { for ($version=1;$version<=$returnhash{'version'};$version++) { foreach (sort(split(/\:/,$returnhash{$version.':keys'}))) { $lasthash{$_}=$returnhash{$version.':'.$_}; - if ($returnhash{$version.':'.$_} =~ /(SUBMITTED|DRAFT)$/) { +# if ($returnhash{$version.':'.$_} =~ /(SUBMITTED|DRAFT)$/) { $timestamp = scalar(localtime($returnhash{$version.':timestamp'})); - } +# } } } foreach ((keys %lasthash)) { @@ -1187,8 +1307,13 @@ sub keywords_highlight { (my $styleoff = $styleon) =~ s/\$styleon$_$styleoff\<\/font\>/gi; + $string =~ s/\b\Q$_\E(\b|\.)/\$styleon$_$styleoff\<\/font\>/gi; } + # This is not really the right place to do this, but I cannot find a + # better one at this time. So here we go - the m in the s:::mg causes + # ^ to match the beginning of a new line. So we replace(???) the beginning + # of the line with
to make things formatted a little better. + $string =~ s:^:
:mg; return $string; } @@ -1206,10 +1331,14 @@ sub processHandGrade { while ($ctr < $ngrade) { my ($uname,$udom) = split(/:/,$ENV{'form.unamedom'.$ctr}); my ($errorflag) = &saveHandGrade($request,$url,$symb,$uname,$udom,$ctr); + if ($errorflag eq 'no_score') { + $ctr++; + next; + } my $includemsg = $ENV{'form.includemsg'.$ctr}; my ($subject,$message,$msgstatus) = ('','',''); - if ($includemsg =~ /savemsg|new$ctr/) { + if ($includemsg =~ /savemsg|newmsg\Q$ctr\E/) { $subject = $ENV{'form.msgsub'} if ($includemsg =~ /^msgsub/); my (@msgnum) = split(/,/,$includemsg); foreach (@msgnum) { @@ -1297,10 +1426,10 @@ sub processHandGrade { $laststu = $firststu if ($ctr > $ngrade); } - my ($classlist,$seclist,$ids,$stusec,$fullname) = &getclasslist($ENV{'form.section'},'0'); + my (undef,undef,$fullname) = &getclasslist($ENV{'form.section'},'0'); my (@parsedlist,@nextlist); my ($nextflg) = 0; - foreach (sort {$$fullname{$a} cmp $$fullname{$b} } keys %$fullname) { + foreach (sort {lc($$fullname{$a}) cmp lc($$fullname{$b}) } keys %$fullname) { if ($nextflg == 1 && $button =~ /Next$/) { push @parsedlist,$_; } @@ -1359,12 +1488,17 @@ sub saveHandGrade { my %newrecord; foreach (split(/:/,$ENV{'form.partlist'.$newflg})) { if ($ENV{'form.GD_SEL'.$newflg.'_'.$_} eq 'excused') { - $newrecord{'resource.'.$_.'.solved'} = 'excused' - if ($record{'resource.'.$_.'.solved'} ne 'excused'); + if ($record{'resource.'.$_.'.solved'} ne 'excused') { + $newrecord{'resource.'.$_.'.solved'} = 'excused'; + if (exists($record{'resource.'.$_.'.awarded'})) { + $newrecord{'resource.'.$_.'.awarded'} = ''; + } + } } else { my $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 ''); my $wgt = $ENV{'form.WGT'.$newflg.'_'.$_} eq '' ? 1 : $ENV{'form.WGT'.$newflg.'_'.$_}; my $partial= $pts/$wgt; @@ -1441,10 +1575,10 @@ sub viewgrades_js { for (i=0;i'."\n"; + $result.='Problem: '.&Apache::lonnet::metadata($ENV{'form.url'},'title') + .''."\n"; #view individual student submission form - called using Javascript viewOneStudent $result.=&jscriptNform($url,$symb); @@ -1584,12 +1719,22 @@ sub viewgrades { ''."\n". ''."\n". ''."\n"; - $result.='To assign the same score for all the students use the radio buttons or '. - 'text box below. To assign scores individually fill in the score boxes for '. - 'each student in the table below. A part that has already '. - 'been graded does not get changed using the radio buttons or text box. '. - 'If needed, it has to be changed individually.'; - + $result.='

Assign Common Grade To '; + if ($ENV{'form.section'} eq 'all') { + $result.='Class

'; + } elsif ($ENV{'form.section'} eq 'no') { + $result.='Students in no Section '; + } else { + $result.='Students in Section '.$ENV{'form.section'}.''; + } + $result.= '
'."\n". + ''."\n"; $result.= ''."\n"; $ctsparts++; } - $result.='
'; +# $result.='To assign the same score for all the students use the radio buttons or '. +# 'text box below. To assign scores individually fill in the score boxes for '. +# 'each student in the table below. A part that has already '. +# 'been graded does not get changed using the radio buttons or text box. '. +# 'If needed, it has to be changed individually.'; +# $result.='
'; #radio buttons/text box for assigning points for a section or class. #handles different parts of a problem my ($partlist,$handgrade) = &response_type($ENV{'form.url'}); @@ -1598,7 +1743,7 @@ sub viewgrades { $result.=''; my %seen = (); for (sort keys(%$handgrade)) { - my ($partid,$respid) = split (/_/); + my ($partid,$respid) = split (/_/,$_,2); next if $seen{$partid}; $seen{$partid}++; my ($responsetype,$handgrade)=split(/:/,$$handgrade{$_}); @@ -1614,24 +1759,25 @@ sub viewgrades { my $ctr = 0; while ($ctr<=$weight{$partid}) { # display radio buttons in a nice table 10 across $result.= '\n"; $result.=(($ctr+1)%10 == 0 ? '' : ''); $ctr++; } $result.='
'.$ctr."
'; $result.= '
or /'. + $partid.'" size="4" '.'onChange="javascript:writePoint(\''. + $partid.'\','.$weight{$partid}.',\'textval\')" /> /'. $weight{$partid}.' (problem weight)
'; + $result.='
'.''.''."\n". + ''; $result.='    '; $result.=''; + } $result.= '
'."\n". ''. ''."\n"; my (@parts) = sort(&getpartlist($url)); foreach my $part (@parts) { my $display=&Apache::lonnet::metadata($url,$part.'.display'); - next if ($display =~ /^Number of Attempts/); if (!$display) { $display = &Apache::lonnet::metadata($url,$part.'.name'); } if ($display =~ /^Partial Credit Factor/) { - $_ = $display; - my ($partid) = /.*?(\d+).*/; - $result.=''."\n"; next; } - $display =~ s/Problem Status/Grade Status
/; + $display =~ s|Problem Status|Grade Status
|; $result.=''."\n"; } $result.=''; #get info for each student #list all the students - with points and grade status - my ($classlist,$seclist,$ids,$stusec,$fullname) = &getclasslist($ENV{'form.section'},'0'); + my (undef,undef,$fullname) = &getclasslist($ENV{'form.section'},'0'); my $ctr = 0; - foreach (sort {$$fullname{$a} cmp $$fullname{$b} } keys %$fullname) { + foreach (sort {lc($$fullname{$a}) cmp lc($$fullname{$b}) } keys %$fullname) { my ($uname,$udom) = split(/:/); $result.=''."\n"; $result.=&viewstudentgrade($url,$symb,$ENV{'request.course.id'}, @@ -1687,31 +1839,37 @@ sub viewstudentgrade { ''.$fullname.''. ''."\n"; - foreach my $part (@$parts) { - my ($temp,$part,$type)=split(/_/,$part); + foreach my $apart (@$parts) { + my ($part,$type) = &split_part_type($apart); my $score=$record{"resource.$part.$type"}; - next if $type eq 'tries'; if ($type eq 'awarded') { my $pts = $score eq '' ? '' : $score*$$weight{$part}; $result.=''."\n"; + 'GD_'.$uname.'_'.$part.'_awarded_s" value="'.$pts.'" />'."\n"; $result.=''."\n"; } elsif ($type eq 'solved') { my ($status,$foo)=split(/_/,$score,2); $status = 'nothing' if ($status eq ''); - $result.=''."\n"; + $result.=''."\n"; $result.='\n"; + } else { + $result.=''. + "\n"; + $result.=''."\n"; } } $result.=''; @@ -1726,7 +1884,8 @@ sub editgrades { my $symb=$ENV{'form.symb'}; my $url =$ENV{'form.url'}; my $title='

Current Grade Status

'; - $title.='Resource: '.$ENV{'form.url'}.'
'."\n"; + $title.='Problem: '. + &Apache::lonnet::metadata($ENV{'form.url'},'title').'
'."\n"; $title.='Section: '.$ENV{'form.section'}.''."\n"; $title.= &show_grading_menu_form ($symb,$url); my $result= '
FullnameUsernameDomainScore Part '.$partid.'
(weight = '. + my ($partid) = &split_part_type($part); + $result.='
Score Part '.$partid.'
(weight = '. $weight{$partid}.')
'.$display.'
'.$uname.''.$udom.'
'; } - $result .= ''; - foreach (@partid) { - $result .= ''. + foreach my $partid (@partid) { + $header .= ''. ''; + $columns{$partid}=2; + foreach my $stores (@parts) { + my ($part,$type) = &split_part_type($stores); + if ($part !~ m/^\Q$partid\E/) { next;} + if ($type eq 'awarded' || $type eq 'solved') { next; } + my $display=&Apache::lonnet::metadata($url,$stores.'.display'); + $display =~ s/\[Part: (\w)+\]//; + $header .= ''. + ''; + $columns{$partid}+=2; + } } + foreach my $partid (@partid) { + $result .= ''; + + } + $result .= ''; + $result .= $header; $result .= ''."\n"; for ($i=0; $i<$ENV{'form.total'}; $i++) { @@ -1765,38 +1944,54 @@ sub editgrades { my %newrecord; my $updateflag = 0; my @userdom = grep /^$user:/,keys %$classlist; - my ($foo,$udom) = split(/:/,$userdom[0]); + my (undef,$udom) = split(/:/,$userdom[0]); $result .= ''; - foreach (@partid) { - my $old_aw = $ENV{'form.GD_'.$user.'_'.$_.'_aw_s'}; - my $old_part = $old_aw eq '' ? '' : $old_aw/$weight{$_}; - my $old_score = $scoreptr{$ENV{'form.GD_'.$user.'_'.$_.'_sv_s'}}; - - my $awarded = $ENV{'form.GD_'.$user.'_'.$_.'_aw'}; - my $partial = $awarded eq '' ? '' : $awarded/$weight{$_}; + my $old_aw = $ENV{'form.GD_'.$user.'_'.$_.'_awarded_s'}; + my $old_part_pcr = $old_aw/($weight{$_} ne '0' ? $weight{$_}:1); + my $old_part = $old_aw eq '' ? '' : $old_part_pcr; + my $old_score = $scoreptr{$ENV{'form.GD_'.$user.'_'.$_.'_solved_s'}}; + + my $awarded = $ENV{'form.GD_'.$user.'_'.$_.'_awarded'}; + my $pcr = $awarded/($weight{$_} ne '0' ? $weight{$_} : 1); + my $partial = $awarded eq '' ? '' : $pcr; my $score; if ($partial eq '') { - $score = $scoreptr{$ENV{'form.GD_'.$user.'_'.$_.'_sv_s'}}; + $score = $scoreptr{$ENV{'form.GD_'.$user.'_'.$_.'_solved_s'}}; } elsif ($partial > 0) { $score = 'correct_by_override'; } elsif ($partial == 0) { $score = 'incorrect_by_override'; } - $score = 'excused' if (($ENV{'form.GD_'.$user.'_'.$_.'_sv'} eq 'excused') && + $score = 'excused' if (($ENV{'form.GD_'.$user.'_'.$_.'_solved'} eq 'excused') && ($score ne 'excused')); $result .= ''. ''; - next if ($old_part eq $partial && $old_score eq $score); - - $updateflag = 1; - $newrecord{'resource.'.$_.'.awarded'} = $partial if $partial ne ''; - $newrecord{'resource.'.$_.'.solved'} = $score; - $rec_update++; + 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) { + my ($part,$type) = &split_part_type($stores); + if ($part !~ m/^\Q$partid\E/) { next;} + if ($type eq 'awarded' || $type eq 'solved') { next; } + my $old_aw = $ENV{'form.GD_'.$user.'_'.$part.'_'.$type.'_s'}; + my $awarded = $ENV{'form.GD_'.$user.'_'.$part.'_'.$type}; + if ($awarded ne '' && $awarded ne $old_aw) { + $newrecord{'resource.'.$part.'.'.$type}= $awarded; + $updateflag=1; + } + $result .= ''. + ''; + } } $result .= ''."\n"; if ($updateflag) { @@ -1812,6 +2007,15 @@ sub editgrades { 'Total number of students = '.$ENV{'form.total'}.'
'; return $title.$msg.$result; } + +sub split_part_type { + my ($partstr) = @_; + my ($temp,@allparts)=split(/_/,$partstr); + my $type=pop(@allparts); + my $part=join('.',@allparts); + return ($part,$type); +} + #------------- end of section for handling grading by section/class --------- # #---------------------------------------------------------------------------- @@ -1905,7 +2109,8 @@ sub csvuploadmap_header { } my $result='
'."\n"; @@ -1740,24 +1899,44 @@ sub editgrades { 'ungraded' =>'ungraded_attempted', 'nothing' => '', ); - my ($classlist,$seclist,$ids,$stusec,$fullname) = &getclasslist($ENV{'form.section'},'0'); + my ($classlist,undef,$fullname) = &getclasslist($ENV{'form.section'},'0'); my (@partid); my %weight = (); + my %columns = (); my ($i,$ctr,$count,$rec_update) = (0,0,0,0); + + my (@parts) = sort(&getpartlist($url)); + my $header; while ($ctr < $ENV{'form.totalparts'}) { my $partid = $ENV{'form.partid_'.$ctr}; push @partid,$partid; $weight{$partid} = $ENV{'form.weight_'.$partid}; $ctr++; - $result .= 'Part '.$partid. - ' (Weight = '.$weight{$partid}.')
 Old Score  Old Score  New Score  Old '.$display.'  New '.$display.' Part '.$partid. + ' (Weight = '.$weight{$partid}.')
'.$user.' '. $$fullname{$userdom[0]}.' '.$old_aw.' '.$awarded. ($score eq 'excused' ? $score : '').' '.$old_aw.' '.$awarded.' 
'; - $result.=''; + $result.=''; my ($partlist,$handgrade) = &response_type($url); my ($resptype,$hdgrade)=('','no'); for (sort keys(%$handgrade)) { @@ -2089,7 +2294,8 @@ sub gradingmenu { if (!$symb) {return '';} my $result='

 Select a Grading Method

'; $result.='
Resource: '.$url.'
Problem: '.&Apache::lonnet::metadata($url,'title') + .'
'; - $result.=''; + $result.=''; my ($partlist,$handgrade) = &response_type($url); my ($resptype,$hdgrade)=('','no'); for (sort keys(%$handgrade)) { @@ -2104,6 +2310,7 @@ sub gradingmenu { $result.=&view_edit_entire_class_form($symb,$url).'
'; $result.=&upcsvScores_form($symb,$url).'
'; $result.=&viewGradeaStu_form($symb,$url,$resptype,$hdgrade).'
'; + $result.=&gradeByPage_form($symb,$url,$resptype,$hdgrade).'
'; $result.=&verifyReceipt_form($symb,$url) if ((&Apache::lonnet::allowed('mgr',$ENV{'request.course.id'})) && ($symb)); @@ -2113,10 +2320,10 @@ sub gradingmenu { #--- Menu for grading a section or the whole class --- sub view_edit_entire_class_form { my ($symb,$url)=@_; - my ($classlist,$sections) = &getclasslist('all','0'); + my ($classlist,$sections,undef) = &getclasslist('all','0'); my $result.='
Resource: '.$url.'
Problem: '. + &Apache::lonnet::metadata($ENV{'form.url'},'title').'
'."\n"; $result.=''."\n"; + $result.=' Grade Entire Section or Class'."\n"; $result.='
'."\n"; - $result.=' Grade Entire Class
'."\n"; $result.='
'."\n". ''."\n". @@ -2175,12 +2382,7 @@ sub viewGradeaStu_form { my $result.='
'."\n"; $result.=''."\n"; + $result.=($handgrade eq 'yes' ? 'View/Grade' : 'View').' an Individual Student\'s Submission'."\n"; $result.='
'."\n"; $result.=' '; - if ($handgrade eq 'yes') { - $result.="View/Grade "; - } else { - $result.="View "; - } - $result.='an Individual Student\'s Submission
'."\n"; $result.=''."\n". ''."\n". @@ -2216,6 +2418,461 @@ sub viewGradeaStu_form { return $result; } +#--- Handgrading problems by page/sequence for each student --- +sub gradeByPage_form { + my ($symb,$url,$response,$handgrade) = @_; + my ($classlist,$sections) = &getclasslist('all','0'); + my $result.='
'."\n"; + $result.=''."\n"; + $result.='
'."\n"; + $result.=' '; + $result.='Handgrade an Individual Student\'s by Page/Sequence
'."\n"; + $result.=''."\n". + ''."\n". + ''."\n". + ''."\n". + ''."\n". + ''."\n". + ''."\n"; + + $result.=' Select section: '."\n"; + + $result.='
 '."\n".''."\n"; + $result.='
'."\n"; + $result.='
'."\n"; + return $result; +} + +sub pickStudentPage { + my ($request) = shift; + + $request->print(< + +function checkPickOne(formname) { + var user = radioSelection(formname.student); + if (user == null) { + alert("Please select the student you wish to grade."); + return; + } + var ptr = pullDownSelection(formname.selectpage); + formname.page.value = eval("formname.page"+ptr+".value"); + formname.title.value = eval("formname.title"+ptr+".value"); + formname.submit(); +} + +function radioSelection(radioButton) { + var selection=null; + for (var i=0; i +LISTJAVASCRIPT + + my ($symb,$url) = &get_symb_and_url(); + 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

'; + + $result.='
'."
\n"; + $result.=' Problems from: '."
\n"; + $ctr=0; + foreach (@$titles) { + my ($minder,$showtitle) = ($_ =~ /(\d+)\.(.*)/); + $result.=''."\n"; + $result.=''."\n"; + $ctr++; + } + $result.=''."\n"; + $result.=''."\n"; + + $result.=' View Problems: no '."\n". + ' yes '."
\n"; + $result.=' Submission Details: '. + ' none'."\n". + ' dates and submissions'."\n". + ' all details'."\n"; + $result.=''."\n". + ''."\n". + ''."\n". + ''."

\n"; + $request->print($result); + + my $studentTable.=' Select a Student you wish to grade
'. + '
'. + ''. + ''. + ''. + ''. + ''; + + my (undef,undef,$fullname) = &getclasslist($getsec,'0'); + my $ptr = 1; + foreach my $student (sort {lc($$fullname{$a}) cmp lc($$fullname{$b}) } keys %$fullname) { + my ($uname,$udom) = split(/:/,$student); + $studentTable.=($ptr%4 == 1 ? '' : ''); + $ptr++; + } + $studentTable.='
 Fullname (username) Fullname (username) Fullname (username) Fullname (username)
' : ''); + $studentTable.=' '.$$fullname{$student}. + ' ('.$uname.($udom eq $cdom ? '':':'.$udom).')'."\n"; + $studentTable.=($ptr%4 == 0 ? '
   ' if ($ptr%4 == 2); + $studentTable.='  ' if ($ptr%4 == 3); + $studentTable.=' ' if ($ptr%4 == 0); + $studentTable.='
'."\n"; + $studentTable.='
 
'."\n"; + + $studentTable.=&show_grading_menu_form($symb,$url); + $request->print($studentTable); + + return ''; +} + +sub getSymbMap { + my $navmap = Apache::lonnavmaps::navmap-> new( + $ENV{'request.course.fn'}.'.db', + $ENV{'request.course.fn'}.'_parms.db',1, 1); + + my $res = $navmap->firstResource(); # temp resource to access constants + $navmap->init(); + + # End navmap using boilerplate + + my $iterator = $navmap->getIterator(undef, undef, undef, 1); + my $depth = 1; + $iterator->next(); # ignore first BEGIN_MAP + my $curRes = $iterator->next(); + + my %symbx = (); + my @titles = (); + my $minder=0; + while ($depth > 0) { + if ($curRes == $iterator->BEGIN_MAP()) {$depth++;} + if ($curRes == $iterator->END_MAP()) { $depth--; } + + if (ref($curRes) && $curRes->is_map()) { + my ($mapUrl, $id, $resUrl) = split(/___/, $curRes->symb()); # check map contains at least one problem + my $map = $navmap->getResourceByUrl($resUrl); # add to navmaps + + my $mapiterator = $navmap->getIterator($map->map_start(), + $map->map_finish()); + + my $mapdepth = 1; + my $countProblems = 0; + $mapiterator->next(); # skip the first BEGIN_MAP + my $mapcurRes = $mapiterator->next(); # for "current resource" + my $ctr=0; + while ($mapdepth > 0 && $ctr < 100) { + if($mapcurRes == $mapiterator->BEGIN_MAP) { $mapdepth++; } + if($mapcurRes == $mapiterator->END_MAP) { $mapdepth++; } + + if (ref($mapcurRes) && $mapcurRes->is_problem() && !$mapcurRes->randomout) { + $countProblems++; + } + $ctr++; + } + if ($countProblems > 0) { + my $title = $curRes->compTitle(); + push @titles,$minder.'.'.$title; # minder, just in case two titles are identical + $symbx{$minder.'.'.$title} = $curRes->symb(); + $minder++; + } + } + $curRes = $iterator->next(); + } + + $navmap->untieHashes(); + return \@titles,\%symbx; +} + +sub displayPage { + my ($request) = shift; + + my ($symb,$url) = &get_symb_and_url(); + 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 (undef,undef,$fullname) = &getclasslist($getsec,'0'); + my ($uname,$udom) = split(/:/,$ENV{'form.student'}); + + my $result='

 '.$ENV{'form.title'}.'

'; + $result.='

 Student: '.$$fullname{$ENV{'form.student'}}. + ' ('.$uname.($udom eq $cdom ? '':':'.$udom).')

'."\n"; + + &sub_page_js($request); + $request->print($result); + + my $navmap = Apache::lonnavmaps::navmap-> new( + $ENV{'request.course.fn'}.'.db', + $ENV{'request.course.fn'}.'_parms.db',1, 1); + my ($mapUrl, $id, $resUrl) = split(/___/, $ENV{'form.page'}); + my $map = $navmap->getResourceByUrl($resUrl); # add to navmaps + + my $iterator = $navmap->getIterator($map->map_start(), + $map->map_finish()); + + my $studentTable='
'."\n". + ''."\n". + ''."\n". + ''."\n". + ''."\n". + ''."\n". + ''."\n"; + + my $checkIcon = ''; + + $studentTable.=' Note: A problem graded correct ('.$checkIcon. + ') by the computer cannot be changed.'."\n". + '
'. + ''. + ''. + ''; + + my ($depth,$ctr,$question) = (1,0,1); + $iterator->next(); # skip the first BEGIN_MAP + my $curRes = $iterator->next(); # for "current resource" + while ($depth > 0 && $ctr < 100) { # ctr, just in case it never gets out of loop + if($curRes == $iterator->BEGIN_MAP) { $depth++; } + if($curRes == $iterator->END_MAP) { $depth++; } + + if (ref($curRes) && $curRes->is_problem() && !$curRes->randomout) { + my $parts = $curRes->parts(); + if (scalar(@{$parts}) > 1) { shift @{$parts}; } + my $title = $curRes->compTitle(); + my $symbx = $curRes->symb(); + $studentTable.=''; + $studentTable.=''; + + } + $curRes = $iterator->next(); + $ctr++; + } + $navmap->init(); + + $studentTable.='
 No  '.($ENV{'form.vProb'} eq 'no' ? 'Title' : 'Problem View').'/Grade
'.$question. + (scalar(@{$parts}) == 1 ? '' : '
('.scalar(@{$parts}).' parts)').'
'; + if ($ENV{'form.vProb'} eq 'yes') { + $studentTable.=&show_problem($request,$symbx,$uname,$udom,1); + } else { + my $companswer = &Apache::loncommon::get_student_answers( + $symbx,$uname,$udom,$ENV{'request.course.id'}); + $companswer=~s|||g; + $companswer=~s|||g; + +# while ($companswer =~ /()/s) { #//g; + $studentTable.=' '.$title.' 
 Correct answer:
'.$companswer; + } + + my %record = &Apache::lonnet::restore($symbx,$ENV{'request.course.id'},$udom,$uname); + + if ($ENV{'form.lastSub'} eq 'datesub') { + if ($record{'version'} eq '') { + $studentTable.='
 No recorded submission for this problem
'; + } else { + $studentTable.='
'. + ''. + ''. + ''. + ''; + my ($version); + for ($version=1;$version<=$record{'version'};$version++) { + my $timestamp = scalar(localtime($record{$version.':timestamp'})); + $studentTable.=''; + my @versionKeys = split(/\:/,$record{$version.':keys'}); + my @displaySub = (); + foreach my $partid (@{$parts}) { + my @matchKey = grep /^resource\.$partid\..*?\.submission$/,@versionKeys; + $displaySub[0].=(exists $record{$version.':'.$matchKey[0]}) ? + 'Part: '.$partid.' Submission: ' + .$record{$version.':'.$matchKey[0]}.'
' : ''; + $displaySub[1].=(exists $record{"$version:resource.$partid.award"}) ? + 'Part: '.$partid.' '. + $record{"$version:resource.$partid.award"}.'/'. + $record{"$version:resource.$partid.solved"}.'
' : ''; + } + $displaySub[1].=(exists $record{"$version:resource.regrader"}) ? + 'Manually graded by '.$record{"$version:resource.regrader"} : ''; + $studentTable.=''; + } + $studentTable.='
Date/TimeSubmissionStatus 
'.$timestamp.''.$displaySub[0].' '.$displaySub[1].' 
'; + } + } elsif ($ENV{'form.lastSub'} eq 'all') { + my $last = ($ENV{'form.lastSub'} eq 'last' ? 'last' : ''); + $studentTable.=&Apache::loncommon::get_previous_attempt($symbx,$uname,$udom, + $ENV{'request.course.id'}, + '','.submission'); + + } + + foreach my $partid (@{$parts}) { + $studentTable.=&gradeBox($request,$symbx,$uname,$udom,$question,$partid,\%record); + $studentTable.=''."\n"; + $question++; + } + $studentTable.='
'."\n". + '  '. + ''."\n"; + $studentTable.=&show_grading_menu_form($symb,$url); + $request->print($studentTable); + + return ''; +} + +sub updateGradeByPage { + my ($request) = shift; + + 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 (undef,undef,$fullname) = &getclasslist($getsec,'0'); + my ($uname,$udom) = split(/:/,$ENV{'form.student'}); + + my $result='

 '.$ENV{'form.title'}.'

'; + $result.='

 Student: '.$$fullname{$ENV{'form.student'}}. + ' ('.$uname.($udom eq $cdom ? '':':'.$udom).')

'."\n"; + + $request->print($result); + + my $navmap = Apache::lonnavmaps::navmap-> new( + $ENV{'request.course.fn'}.'.db', + $ENV{'request.course.fn'}.'_parms.db',1, 1); + my ($mapUrl, $id, $resUrl) = split(/___/, $ENV{'form.page'}); + my $map = $navmap->getResourceByUrl($resUrl); # add to navmaps + + my $iterator = $navmap->getIterator($map->map_start(), + $map->map_finish()); + + my $studentTable='
'. + ''. + ''. + ''. + ''. + ''; + + $iterator->next(); # skip the first BEGIN_MAP + my $curRes = $iterator->next(); # for "current resource" + my ($depth,$ctr,$question,$changeflag)= (1,0,1,0); + while ($depth > 0 && $ctr < 100) { # ctr, just in case it never gets out of loop + if($curRes == $iterator->BEGIN_MAP) { $depth++; } + if($curRes == $iterator->END_MAP) { $depth++; } + + if (ref($curRes) && $curRes->is_problem() && !$curRes->randomout) { + my $parts = $curRes->parts(); + if (scalar(@{$parts}) > 1) { shift @{$parts}; } + my $title = $curRes->compTitle(); + my $symbx = $curRes->symb(); + $studentTable.=''; + $studentTable.=''; + + my %newrecord=(); + my @displayPts=(); + foreach my $partid (@{$parts}) { + my $newpts = $ENV{'form.GD_BOX'.$question.'_'.$partid}; + my $oldpts = $ENV{'form.oldpts'.$question.'_'.$partid}; + + my $wgt = $ENV{'form.WGT'.$question.'_'.$partid} != 0 ? + $ENV{'form.WGT'.$question.'_'.$partid} : 1; + my $partial = $newpts/$wgt; + my $score; + if ($partial > 0) { + $score = 'correct_by_override'; + } elsif ($partial == 0) { + $score = 'incorrect_by_override'; + } + if ($ENV{'form.GD_SEL'.$question.'_'.$partid} eq 'excused') { + $partial = ''; + $score = 'excused'; + } + my $oldstatus = $ENV{'form.solved'.$question.'_'.$partid}; + $displayPts[0].=' Part '.$partid.' = '. + (($oldstatus eq 'excused') ? 'excused' : $oldpts). + ' 
'; + $displayPts[1].=' Part '.$partid.' = '. + ($oldstatus eq 'correct_by_student' ? $oldpts : + (($score eq 'excused') ? 'excused' : $newpts)). + ' 
'; + + $question++; + if (($oldstatus eq 'correct_by_student') || + ($newpts eq $oldpts && $score eq $oldstatus)) + { + next; + } + $newrecord{'resource.'.$partid.'.awarded'} = $partial if $partial ne ''; + $newrecord{'resource.'.$partid.'.solved'} = $score; + + $changeflag++; + } + if (scalar(keys(%newrecord)) > 0) { + $newrecord{'resource.regrader'}="$ENV{'user.name'}:$ENV{'user.domain'}"; + &Apache::lonnet::cstore(\%newrecord,$symbx,$ENV{'request.course.id'}, + $udom,$uname); + } + $studentTable.=''. + ''. + ''; + + } + $curRes = $iterator->next(); + $ctr++; + } + $navmap->init(); + + $studentTable.='
 No  Title  Previous Score  New Score 
'.$question. + (scalar(@{$parts}) == 1 ? '' : '
('.scalar(@{$parts}).' parts)').'
 '.$title.' '.$displayPts[0].''.$displayPts[1].'
'; + $studentTable.=($changeflag == 0 ? 'No score was changed or updated.' : + 'The scores were changed for '. + $changeflag.' problem'.($changeflag == 1 ? '.' : 's.')); + $studentTable.=&show_grading_menu_form($ENV{'form.symb'},$ENV{'form.url'}); + $request->print($studentTable); + + return ''; +} + + #--- Form to input a receipt number --- sub verifyReceipt_form { my ($symb,$url) = @_; @@ -2303,8 +2960,16 @@ sub handler { } else { $Apache::grades::viewgrades=&Apache::lonnet::allowed('vgr',$ENV{'request.course.id'}); if ($command eq 'submission') { - &listStudents($request) if ($ENV{'form.student'} eq ''); - &submission($request,0,0) if ($ENV{'form.student'} ne ''); + ($ENV{'form.student'} eq '' ? &listStudents($request) : &submission($request,0,0)); +# if ($command eq 'submission') { +# &listStudents($request) if ($ENV{'form.student'} eq ''); +# &submission($request,0,0) if ($ENV{'form.student'} ne ''); + } elsif ($command eq 'pickStudentPage') { + &pickStudentPage($request); + } elsif ($command eq 'displayPage') { + &displayPage($request); + } elsif ($command eq 'gradeByPage') { + &updateGradeByPage($request); } elsif ($command eq 'processGroup') { &processGroup($request); } elsif ($command eq 'gradingmenu') { 500 Internal Server Error

Internal Server Error

The server encountered an internal error or misconfiguration and was unable to complete your request.

Please contact the server administrator at root@localhost to inform them of the time this error occurred, and the actions you performed just before this error.

More information about this error may be available in the server error log.