--- loncom/homework/grades.pm 2002/10/17 14:35:34 1.57 +++ loncom/homework/grades.pm 2003/03/14 17:46:31 1.72 @@ -1,7 +1,7 @@ # The LearningOnline Network with CAPA # The LON-CAPA Grading handler # -# $Id: grades.pm,v 1.57 2002/10/17 14:35:34 matthew Exp $ +# $Id: grades.pm,v 1.72 2003/03/14 17:46:31 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,12 +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 { @@ -206,6 +209,9 @@ sub jscriptNform { $jscript.= '
'."\n". ''."\n". ''."\n". + ''."\n". + ''."\n". + ''."\n". ''."\n". ''."\n". ''."\n". @@ -234,7 +240,7 @@ sub verifyreceipt { my $title.='

Verifying Submission Receipt '. $receipt.'

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

'."\n"; + 'Problem: '.$ENV{'form.probTitle'}.'

'."\n"; my ($string,$contents,$matches) = ('','',0); my (undef,undef,$fullname) = &getclasslist('all','0'); @@ -276,7 +282,7 @@ sub verifyreceipt { sub listStudents { my ($request) = shift; - my ($symb,$url) = &get_symb_and_url(); + my ($symb,$url) = &get_symb_and_url($request); 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'}; @@ -293,18 +299,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; + '
'. - 'Resource: '.$url.'
'.$result; $request->print(< @@ -339,8 +340,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"; @@ -353,6 +355,9 @@ LISTJAVASCRIPT ''."\n". '
'."\n". '
'."\n". + ''."\n". + ''."\n". + ''."\n". ''."\n". ''."\n". 'To '.lc($viewgrade).' a submission, click on the check box next to the student\'s name. Then '."\n". @@ -452,91 +457,177 @@ 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) { @@ -611,7 +702,7 @@ sub sub_page_js { } function savedMsgHeader(Nmsg,usrctr,fullname) { - var height = 30*Nmsg+250; + var height = 50*Nmsg+250; var scrollbar = "no"; if (height > 600) { height = 600; @@ -671,21 +762,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) { + 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() { @@ -783,7 +874,6 @@ function displaySavedMsg(ctr,msg,shwsel) function highlightend() { hwdWin.document.write("
'. + 'Problem: '.$ENV{'form.probTitle'}.'
Subject
"+ctr+"
New
"); hwdWin.document.write(" "); -// hwdWin.document.write("  "); hwdWin.document.write("  "); hwdWin.document.write("

"); hwdWin.document.write("
"); @@ -794,44 +884,114 @@ 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.=''."\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; +} # --------------------------- show submissions of a student, option to grade sub submission { my ($request,$counter,$total) = @_; (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) = ($ENV{'form.student'},$ENV{'form.userdom'}); ($uname,$udom) = &finduser($uname) if $udom eq ''; $ENV{'form.fullname'} = &get_fullname ($uname,$udom) if $ENV{'form.fullname'} eq ''; -# if ($uname eq '') { &moreinfo($request,'Unable to find student'); return ''; } 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'; # header info if ($counter == 0) { &sub_page_js($request); + &sub_page_kw_js($request); $request->print('

 Submission Record

'."\n". - ' Resource: '.$url.''."\n"); + ' Problem: '.$ENV{'form.probTitle'}.''."\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 @@ -848,13 +1008,16 @@ sub submission { $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'); + $keyhash{$symb.'_subject'} : $ENV{'form.probTitle'}; $ENV{'form.savemsgN'} = $keyhash{$symb.'_savemsgN'} ne '' ? $keyhash{$symb.'_savemsgN'} : '0'; } $request->print('
'."\n". ''."\n". + ''."\n". + ''."\n". + ''."\n". ''."\n". ''."\n". ''."\n". @@ -894,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); @@ -987,7 +1155,7 @@ KEYWORDS } else { my ($string,$timestamp)= &get_last_submission (%record); - my $lastsubonly.=''. + my $lastsubonly=''. ($$timestamp eq '' ? '' : 'Date Submitted: '. $$timestamp).''; if ($$timestamp eq '') { @@ -1000,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).''."\n" if ($ENV{'form.lastSub'} eq 'lastonly' || ($ENV{'form.lastSub'} eq 'hdgrade' && @@ -1022,6 +1195,9 @@ KEYWORDS # return if view submission with no grading option if ($ENV{'form.showgrading'} eq '') { $request->print('
'."\n"); + $request->print(&show_grading_menu_form($symb,$url)) + if (($ENV{'form.command'} eq 'submission') || + ($ENV{'form.command'} eq 'processGroup' && $counter == $total)); return; } @@ -1052,48 +1228,8 @@ 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.=''."\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."
'; - - $result.='
 or /'.$wgt.' '.$wgtmsg.' '; - - $result.=''."  \n"; - $result.=''; - $result.='
'."\n"; - $request->print($result); + $request->print(&gradeBox($request,$symb,$uname,$udom,$counter,$partid,\%record)); } $result=''."\n"; @@ -1111,7 +1247,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.=''; @@ -1146,9 +1282,7 @@ 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)$/) { $timestamp = scalar(localtime($returnhash{$version.':timestamp'})); - } } } foreach ((keys %lasthash)) { @@ -1172,7 +1306,7 @@ 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 @@ -1196,10 +1330,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) { @@ -1327,8 +1465,6 @@ sub processHandGrade { $ENV{'form.student'} = $uname; $ENV{'form.userdom'} = $udom; $ENV{'form.fullname'} = $$fullname{$_}; -# $ENV{'form.'.$_.':submitted_by'} = $submitter; -# print "submitter=$ENV{'form.'.$_.':submitted_by'}= $submitter:
"; &submission($request,$ctr,$total); $ctr++; } @@ -1349,12 +1485,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; @@ -1370,11 +1511,11 @@ sub saveHandGrade { } $newrecord{'resource.'.$_.'.submitted_by'} = $submitter if ($submitter && ($record{'resource.'.$_.'.submitted_by'} ne $submitter)); + $newrecord{'resource.'.$_.'regrader'}="$ENV{'user.name'}:$ENV{'user.domain'}"; } } if (scalar(keys(%newrecord)) > 0) { - $newrecord{'resource.regrader'}="$ENV{'user.name'}:$ENV{'user.domain'}"; &Apache::lonnet::cstore(\%newrecord,$symb, $ENV{'request.course.id'},$domain,$stuname); } @@ -1563,7 +1704,7 @@ sub viewgrades { my ($symb,$url) = ($ENV{'form.symb'},$ENV{'form.url'}); my $result='

Manual Grading

'; - $result.='Resource: '.$ENV{'form.url'}.''."\n"; + $result.='Problem: '.$ENV{'form.probTitle'}.''."\n"; #view individual student submission form - called using Javascript viewOneStudent $result.=&jscriptNform($url,$symb); @@ -1573,7 +1714,11 @@ sub viewgrades { ''."\n". ''."\n". ''."\n". - ''."\n"; + ''."\n". + ''."\n". + ''."\n". + ''."\n"; + $result.='

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

'; @@ -1584,12 +1729,6 @@ sub viewgrades { } $result.= '
'."\n". ''."\n"; $result.= ''."\n"; $ctsparts++; @@ -1694,8 +1833,8 @@ sub viewstudentgrade { ''.$fullname.''. ''."\n"; - foreach my $part (@$parts) { - my ($part,$type) = &split_part_type($part); + foreach my $apart (@$parts) { + my ($part,$type) = &split_part_type($apart); my $score=$record{"resource.$part.$type"}; if ($type eq 'awarded') { my $pts = $score eq '' ? '' : $score*$$weight{$part}; @@ -1739,9 +1878,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: '.$ENV{'form.probTitle'}.'
'."\n"; $title.='Section: '.$ENV{'form.section'}.''."\n"; - $title.= &show_grading_menu_form ($symb,$url); my $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'}); @@ -1626,7 +1765,7 @@ sub viewgrades { $weight{$partid}.' (problem weight)
'.$uname.''.$udom.'
'."\n"; $result.= ''. ''."\n"; @@ -1841,6 +1979,7 @@ sub editgrades { my $awarded = $ENV{'form.GD_'.$user.'_'.$part.'_'.$type}; if ($awarded ne '' && $awarded ne $old_aw) { $newrecord{'resource.'.$part.'.'.$type}= $awarded; + $newrecord{'resource.'.$part.'regrader'}="$ENV{'user.name'}:$ENV{'user.domain'}"; $updateflag=1; } $result .= ''. @@ -1850,12 +1989,12 @@ sub editgrades { $result .= ''."\n"; if ($updateflag) { $count++; - $newrecord{'resource.regrader'}="$ENV{'user.name'}:$ENV{'user.domain'}"; &Apache::lonnet::cstore(\%newrecord,$symb,$ENV{'request.course.id'}, $udom,$user); } } - $result .= '
UsernameFullname'.$old_aw.' 
'."\n"; + $result .= '
'."\n". + &show_grading_menu_form ($symb,$url); my $msg = 'Number of records updated = '.$rec_update. ' for '.$count.' student'.($count <= 1 ? '' : 's').'.
'. 'Total number of students = '.$ENV{'form.total'}.'
'; @@ -1879,6 +2018,48 @@ sub split_part_type { # #-------------------------- Next few routines handles grading by csv upload # +#--- Menu to upload a csv scores --- +sub upcsvScores_form { + my ($request) = shift; + my ($symb,$url)=&get_symb_and_url($request); + if (!$symb) {return '';} + my $result =< + function checkUpload(formname) { + if (formname.upfile.value == "") { + alert("Please use the browse button to select a file from your local directory."); + return false; + } + formname.submit(); + if (navigator.appName !="Netscape") {self.close()}; //if netscape if appears to close before submit!!! + // any suggestion how to get around this?? + } + +CSVFORMJS + $ENV{'form.probTitle'} = &Apache::lonnet::metadata($url,'title'); + $result.='
'."\n"; + $result.=''."\n"; + $result.='
'."\n"; + $result.=' Specify a file containing the class scores for problem - '.$ENV{'form.probTitle'}. + '.
'."\n"; + my $upfile_select=&Apache::loncommon::upfile_select_html(); + $result.=< + + + + +$upfile_select +
  + + + +ENDUPFORM + $result.='
'."\n"; + $result.='
'."\n"; + return $result; +} + #--- Javascript to handle csv upload sub csvupload_javascript_reverse_associate { return(<'; + $result.='Problem: '.$ENV{'form.probTitle'}.''; my ($partlist,$handgrade) = &response_type($url); my ($resptype,$hdgrade)=('','no'); for (sort keys(%$handgrade)) { @@ -1994,6 +2175,9 @@ to this page if the data selected is ins value="$ENV{'form.upfile_associate'}" /> + + +
+LISTJAVASCRIPT + + my ($symb,$url) = &get_symb_and_url($request); + 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". + ''."\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". + ''."\n". + ''."\n"; + + $result.='
 
'."\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; +} + +# +#--- Displays a page/sequence w/wo problems, w/wo submissions +sub displayPage { + my ($request) = shift; + + my ($symb,$url) = &get_symb_and_url($request); + 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". + ''."\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(); + $parts = &temp_parts_fix($parts); # remove line when lonnavmap is fixed + my $title = $curRes->compTitle(); + my $symbx = $curRes->symb(); + $studentTable.=''; + $studentTable.=''; + + } + $curRes = $iterator->next(); + $ctr++; + } + + $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[2].=(exists $record{"$version:resource.$partid.regrader"}) ? + $record{"$version:resource.$partid.regrader"}.' (Part: '.$partid.')' : ''; + } + $displaySub[2].=(exists $record{"$version:resource.regrader"}) ? + $record{"$version:resource.regrader"} : ''; + $studentTable.=''; + } + $studentTable.='
Date/TimeSubmissionStatus 
'.$timestamp.''.$displaySub[0].' '.$displaySub[1]. + ($displaySub[2] eq '' ? '' : 'Manually graded by '.$displaySub[2]).' 
'; + } + } 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 temp_parts_fix { #remove sub once lonnavmap is fixed + my $parts = shift; + my %seen = (); + my @correctParts = (); + foreach (@{$parts}) { + next if ($seen{$_} > 0); + $seen{$_}++; + push @correctParts,$_; + } + return \@correctParts; +} + +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(); + $parts = &temp_parts_fix($parts); # remove line when lonnavmap is fixed + 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; + $newrecord{'resource.'.$partid.'.regrader'}="$ENV{'user.name'}:$ENV{'user.domain'}"; + + $changeflag++; + } + if (scalar(keys(%newrecord)) > 0) { + &Apache::lonnet::cstore(\%newrecord,$symbx,$ENV{'request.course.id'}, + $udom,$uname); + } + $studentTable.=''. + ''. + ''; + + } + $curRes = $iterator->next(); + $ctr++; + } + + $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 ''; +} + +#-------- end of section for handling grading by page/sequence --------- +# +#------------------------------------------------------------------- #-------------------------- Menu interface ------------------------- # @@ -2134,6 +2775,8 @@ sub show_grading_menu_form { my $result.='
'."\n". ''."\n". ''."\n". + ''."\n". + ''."\n". ''."\n". ''."\n". '
'."\n"; @@ -2145,9 +2788,72 @@ sub gradingmenu { my ($request) = @_; my ($symb,$url)=&get_symb_and_url($request); if (!$symb) {return '';} - my $result='

 Select a Grading Method

'; - $result.=''; - $result.=''; + + $request->print(< + function checkChoice(formname) { + var cmd = formname.command; + formname.lastCmd.value = radioSelection(formname.command); + formname.lastSec.value = pullDownSelection(formname.section); + if (cmd[0].checked || cmd[1].checked || cmd[2].checked) { + formname.submit(); + } + + if (cmd[3].checked) { + var url = "/adm/grades?command=csvform&symb="+formname.symb.value+"&url="+formname.url.value; + var options = "width=620,height=340,screenx=70,screeny=75,"; + options += "resizable=no,scrollbars=no,status=no,"; + options += "menubar=no,toolbar=no,location=no,directories=no"; + var newWin = window.open(url, "CSVFile", options); + newWin.focus(); + } + + if (cmd[4].checked) { + if (!checkReceiptNo(formname,'notOK')) { return false;} + formname.submit(); + } + } + + function checkReceiptNo(formname,nospace) { + var receiptNo = formname.receipt.value; + var checkOpt = false; + if (nospace == "OK" && isNaN(receiptNo)) {checkOpt = true;} + if (nospace == "notOK" && (isNaN(receiptNo) || receiptNo == "")) {checkOpt = true;} + if (checkOpt) { + alert("Please enter a receipt number given by a student in the receipt box."); + formname.receipt.value = ""; + formname.receipt.focus(); + return false; + } + formname.command[4].checked = true; + return true; + } + + function radioSelection(radioButton) { + var selection=null; + for (var i=0; i +GRADINGMENUJS + + my $probTitle = &Apache::lonnet::metadata($ENV{'form.url'},'title'); + my $result='

 Manual Grading/View Submission

'. + '
Resource: '.$url.'
'. + ''; my ($partlist,$handgrade) = &response_type($url); my ($resptype,$hdgrade)=('','no'); for (sort keys(%$handgrade)) { @@ -2159,155 +2865,79 @@ sub gradingmenu { ''; } $result.='
Problem: '.$probTitle.'
Handgrade: '.$handgrade.'
'; - $result.=&view_edit_entire_class_form($symb,$url).'
'; - $result.=&upcsvScores_form($symb,$url).'
'; - $result.=&viewGradeaStu_form($symb,$url,$resptype,$hdgrade).'
'; - $result.=&verifyReceipt_form($symb,$url) - if ((&Apache::lonnet::allowed('mgr',$ENV{'request.course.id'})) && ($symb)); - - return $result; -} -#--- Menu for grading a section or the whole class --- -sub view_edit_entire_class_form { - my ($symb,$url)=@_; - my ($classlist,$sections,undef) = &getclasslist('all','0'); - my $result.='
'."\n"; - $result.=''."\n"; - $result.='
'."\n"; - $result.=' Grade Entire Section or Class
'."\n"; - $result.='
'."\n". - ''."\n". - ''."\n". - ''."\n"; - $result.=' Select section: '."
\n"; - $result.=' 
'."\n"; - $result.='
'."\n"; - $result.='
'."\n"; - return $result; -} - -#--- Menu to upload a csv scores --- -sub upcsvScores_form { - my ($symb,$url) = @_; - if (!$symb) {return '';} - my $result = ''."\n"; + my ($classlist,$sections) = &getclasslist('all','0'); + my $lastCmd = ($ENV{'form.lastCmd'} eq '' ? 'pickStudentPage' : $ENV{'form.lastCmd'}); + my $lastSec = ($ENV{'form.lastSec'} eq '' ? 'all' : $ENV{'form.lastSec'}); - $result.='
'."\n"; - $result.=''."\n"; - $result.='
'."\n"; - $result.=' Specify a file containing the class scores for above resource
'."\n"; - my $upfile_select=&Apache::loncommon::upfile_select_html(); - $result.=< - - - -$upfile_select -
  - -ENDUPFORM - $result.='
'."\n"; - $result.='
'."\n"; - return $result; -} + $result.='
'."\n". + ''."\n". + ''."\n". + ''."\n". + ''."\n". + ''."\n". + ''."\n". + ''."\n". + ''."\n"; + + $result.='
'."\n". + ''."\n". + '
'."\n". + ' Select a Grading/Viewing Option
'."\n"; + + $result.=''. + ''."\n". + + ''."\n". + + ''."\n". + ''."\n". -#--- Handgrading problems --- -sub viewGradeaStu_form { - my ($symb,$url,$response,$handgrade) = @_; - my ($classlist,$sections) = &getclasslist('all','0'); - my $result.='
'. + ' '. + 'Handgrade/View Submission for a student by page/sequence
'. + ' '. + 'Grade by section or class
'. + ($hdgrade eq 'yes' ? 'View/Grade essay response of' : 'View'). + ' an individual student --> For students who has: '. + ' submitted'. + ' everybody
'."\n"; - $result.=''."\n"; - $result.=''."\n"; + + if ((&Apache::lonnet::allowed('mgr',$ENV{'request.course.id'})) && ($symb)) { + $result.=''. + ''."\n"; + } - $result.=' Select section:'; - - $result.='
 '."\n"; - $result.='
'."\n"; - $result.=' '; - if ($handgrade eq 'yes') { - $result.="View/Grade "; - } else { - $result.="View "; - } - $result.='an Individual Student\'s Submission
'."\n"; - $result.=''."\n". - ''."\n". - ''."\n". - ''."\n". - ''."\n". - ''."\n". - ''."\n"; + '
'. + ' '. + 'Upload scores from file
'. + ' '. + 'Verify a submission receipt issued by this server--> Receipt no: '.unpack("%32C*",$Apache::lonnet::perlvar{'lonHostID'}). + '-'. + '

'."\n". + ' Select section: '."\n"; - $result.='  Display students who has: '. - ' submitted'. - ' everybody
'; + $result.= '
'."\n"; - $result.='
'."\n"; - return $result; -} - -#--- Form to input a receipt number --- -sub verifyReceipt_form { - my ($symb,$url) = @_; - my $result = ''."\n"; - - my $hostver=unpack("%32C*",$Apache::lonnet::perlvar{'lonHostID'}); - - $result.='
'."\n"; - $result.=''."\n"; - $result.='
'."\n"; - $result.=' Verify a Submission Receipt Issued by this Server
'."\n"; - $result.=''."\n"; - $result.=' '.$hostver.'-
'."\n"; - $result.=' '."\n"; - $result.=''."\n"; - if ($ENV{'form.url'}) { - $result.=''; - } - if ($ENV{'form.symb'}) { - $result.=''; - } - $result.=''; - $result.='
'."\n"; - $result.='
'."\n"; + $result.='

'. + ''."\n". + '
'."\n". + '
'."\n". + ''."\n"; return $result; } @@ -2361,8 +2991,13 @@ 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)); + } 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') { @@ -2375,6 +3010,8 @@ sub handler { $request->print(&editgrades($request)); } elsif ($command eq 'verify') { $request->print(&verifyreceipt($request)); + } elsif ($command eq 'csvform') { + $request->print(&upcsvScores_form($request)); } elsif ($command eq 'csvupload') { $request->print(&csvupload($request)); } elsif ($command eq 'viewclasslist') {