--- loncom/homework/grades.pm 2002/08/02 21:10:03 1.44 +++ loncom/homework/grades.pm 2002/08/05 20:49:54 1.45 @@ -1,7 +1,7 @@ # The LearningOnline Network with CAPA # The LON-CAPA Grading handler # -# $Id: grades.pm,v 1.44 2002/08/02 21:10:03 ng Exp $ +# $Id: grades.pm,v 1.45 2002/08/05 20:49:54 ng Exp $ # # Copyright Michigan State University Board of Trustees # @@ -45,6 +45,17 @@ use Apache::Constants qw(:common); # ----- These first few routines are general use routines.----- # + +sub print_hash { + my ($request, $hash) = @_; + $request->print(''); + for (sort keys (%$hash)) { + $request->print(''); + } + $request->print('
KeyValue
'.$_.''.$$hash{$_}.' 
'); + return ''; +} + # --- Retrieve the parts that matches stores_\d+ from the metadata file.--- sub getpartlist { my ($url) = @_; @@ -224,11 +235,33 @@ sub student_gradeStatus { return %partstatus; } +# hidden form and javascript that calls the form +# Use by verifyscript and viewgrades +# Shows a student's view of problem and submission +sub jscriptNform { + my ($url,$symb) = @_; + my $jscript=''."\n"; + $jscript.= '
'."\n". + ''."\n". + ''."\n". + ''."\n". + ''."\n". + ''."\n". + '
'."\n"; + return $jscript; +} #------------------ End of general use routines -------------------- #------------------------------------------------------------------- #------------------------------------ Receipt Verification Routines +# #--- Check whether a receipt number is valid.--- sub verifyreceipt { my $request = shift; @@ -243,23 +276,8 @@ sub verifyreceipt { $symb = &Apache::lonnet::symbread($url); } - my $jscript=''."\n"; - $jscript.= '
'."\n". - ''."\n". - ''."\n". - ''."\n". - ''."\n". - ''."\n". - '
'."\n"; - - my $title.='

Verifying Submission Receipt '. - $receipt.'

'."\n". + my $title.='

Verifying Submission Receipt '. + $receipt.'

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

'."\n"; my ($string,$contents,$matches) = ('','',0); @@ -281,7 +299,7 @@ sub verifyreceipt { if ($matches == 0) { $string = $title.'No match found for the above receipt.'; } else { - $string = $jscript.$title. + $string = &jscriptNform($url,$symb).$title. 'The above receipt matches the following student'. ($matches <= 1 ? '.' : 's.')."\n". '
'."\n". @@ -301,13 +319,37 @@ sub verifyreceipt { # on the problem page. sub listStudents { my ($request) = shift; + $request->print(< + function checkSelect(checkBox) { + var ctr=0; + if (checkBox.length > 1) { + for (var i=0; i +LISTJAVASCRIPT + 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 $submitonly= $ENV{'form.submitonly'} eq '' ? 'all' : $ENV{'form.submitonly'}; - my $result='

 '. - 'View Submissions for a Student or a Group of Students

'; + my $result='

 '. + 'View/Grade Submissions for a Student or a Group of Students

'; $result.=''; $result.=''; @@ -322,41 +364,44 @@ sub listStudents { $result.='
'. 'Resource: '.$ENV{'form.url'}.'
'; $request->print($result); - $request->print(<View Problem: no - yes
Submissions: - handgrade only - last sub only - last sub & parts info - all details - - - -
-
- -ENDTABLEST - if ($ENV{'form.url'}) { - $request->print(''."\n"); - } - if ($ENV{'form.symb'}) { - $request->print(''."\n"); - } - $request->print(''."\n"); + my $checkhdgrade = $ENV{'form.handgrade'} eq 'yes' ? 'checked' : ''; + my $checklastsub = $ENV{'form.handgrade'} eq 'yes' ? '' : 'checked'; + my $gradeTable='
'."\n". + ' View Problem: no '."\n". + ' yes
'."\n". + ' Submissions: '."\n". + ' handgrade only'."\n". + ' last sub only'."\n". + ' last sub & parts info'."\n". + ' all details'."\n". + ''."\n". + ''."\n". + ''."\n". + '
'."\n". + '
'."\n". + ''."\n". + ''."\n". + 'To view/grade a submission, click on the check box next to the student\'s name. Then '."\n". + 'click on the View/Grade button. To view the submissions for a group of students, click'."\n". + ' on the check boxes for the group of students.
'."\n". + ''."\n". + ''."\n"; + my ($classlist,$seclist,$ids,$stusec,$fullname) = &getclasslist($getsec,'0'); - $result='
'. + $gradeTable.='
'. ''. ''. ''; foreach (sort(@$partlist)) { - $result.=''; + $gradeTable.=''; } - $request->print($result.''."\n"); + $gradeTable.=''."\n"; + my $ctr = 0; foreach my $student (sort {$$fullname{$a} cmp $$fullname{$b} } keys %$fullname) { my ($uname,$udom) = split(/:/,$student); my (%status) = &student_gradeStatus($ENV{'form.url'}, @@ -367,15 +412,16 @@ ENDTABLEST my ($foo,$partid,$foo1) = split(/\./,$_); if ($status{'resource.'.$partid.'.submitted_by'} ne '') { $statusflg = ''; - $request->print(''); + $gradeTable.=''; } } next if ($statusflg eq '' && $submitonly eq 'yes'); + $ctr++; if ( $Apache::grades::viewgrades eq 'F' ) { - $result=''. + $gradeTable.=''. ''."\n". ''."\n". @@ -384,13 +430,21 @@ ENDTABLEST foreach (sort keys(%status)) { next if (/^resource.*?submitted_by$/); - $result.=''."\n"; + $gradeTable.=''."\n"; } - $request->print($result.''."\n"); + $gradeTable.=''."\n"; } } - $request->print('
 Select  Fullname  Username  Domain  Part '.(split(/_/))[0].' Status  Part '.(split(/_/))[0].' Status 
 '.$$fullname{$student}.'  '.$status{$_}.'  '.$status{$_}.' 
'); - $request->print(''); + $gradeTable.='
'. + ''."\n"; + if ($ctr == 0) { + $gradeTable='
 '. + 'No submission found for this resource.
'; + $gradeTable.=&show_grading_menu_form ($ENV{'form.symb'},$ENV{'form.url'}); + } + $request->print($gradeTable); return ''; } @@ -402,10 +456,7 @@ sub processGroup { my @stuchecked = (ref($ENV{'form.stuinfo'}) ? @{$ENV{'form.stuinfo'}} : ($ENV{'form.stuinfo'})); my $total = scalar(@stuchecked)-1; - if ($stuchecked[0] eq '') { - &userError($request,'No student was selected for viewing/grading.'); - return; - } + foreach (@stuchecked) { my ($uname,$udom,$fullname) = split(/:/); $ENV{'form.student'} = $uname; @@ -489,6 +540,30 @@ sub sub_page_js { return; } +//=================== Check that a point is assigned for all the parts ============== + function checksubmit(val,total,parttot) { + document.SCORE.gradeOpt.value = val; + if (val == "Save & Next") { + for (i=0;i<=total;i++) { + for (j=0;jprint('

 Submission Record

'. - ' Resource: '.$url.''); + $request->print('

 Submission Record

'."\n". + ' Resource: '.$url.''."\n"); # option to display problem, only once else it cause problems # with the form later since the problem has a form. @@ -778,7 +853,7 @@ sub submission { $ENV{'request.course.id'}); my $result.='
'; $result.='
'; - $result.=' View of the problem for '.$ENV{'form.fullname'}. + $result.=' View of the problem - '.$ENV{'form.fullname'}. '
'.$rendered.'
'; $result.='Correct answer:
'.$companswer; $result.='
'; @@ -851,16 +926,18 @@ KEYWORDS # Display student info $request->print(($counter == 0 ? '' : '
')); - my $result='
'. - '
'; + my $result='
'."\n". + '
'."\n"; # $result.=''; + $lastsubonly.=''."\n"; } else { for my $part (sort keys(%$handgrade)) { foreach (@$string) { @@ -939,7 +1017,7 @@ KEYWORDS $lastsubonly.='' + &keywords_highlight($subval).''."\n" if ($ENV{'form.lastSub'} eq 'lastonly' || ($ENV{'form.lastSub'} eq 'hdgrade' && $$handgrade{$part} =~ /:yes$/)); @@ -947,7 +1025,7 @@ KEYWORDS } } } - $lastsubonly.=''."\n"; $request->print($lastsubonly); } } else { @@ -959,17 +1037,25 @@ KEYWORDS # return if view submission with no grading option if ($ENV{'form.showgrading'} eq '') { - $request->print('
Fullname: '.$ENV{'form.fullname'}. $result.='Fullname: '.$ENV{'form.fullname'}. '   Username: '.$uname.''. - '   Domain: '.$udom.'
'; + '   Domain: '.$udom.'
'."\n"; + $result.=''."\n"; # If this is handgraded, then check for collaborators - my $col_flag = 0; + my @col_fullnames; if ($ENV{'form.handgrade'} eq 'yes') { my @col_list; ($classlist,$seclist,$ids,$stusec,$fullname) = &getclasslist('all','0'); @@ -883,8 +960,9 @@ KEYWORDS push @badcollaborators,$collaborator; next; } - $col_flag++; push @col_list, $collaborator; + my ($lastname,$givenn) = split(/,/,$$fullname{$collaborator.':'.$udom}); + push @col_fullnames, $givenn.' '.$lastname; $result.=$$fullname{$collaborator.':'.$udom}.'     '; } $result.='
'."\n"; @@ -929,7 +1007,7 @@ KEYWORDS ($$timestamp eq '' ? '' : 'Date Submitted: '. $$timestamp).''; if ($$timestamp eq '') { - $lastsubonly.='
'.$$string[0].'
'.$$string[0].'
Part '. $partid.' ( ID '.$respid. ' )   Answer: '. - &keywords_highlight($subval).'
'."\n"; + $lastsubonly.='
'); + $request->print('
'."\n"); return; } # Grading options $result=''."\n". ''."\n". - ''."\n"; - $result.=' '. - 'Compose Message to student'.($col_flag > 1 ? 's' : '').''. + ''."\n"; + my ($lastname,$givenn) = split(/,/,$ENV{'form.fullname'}); + my $msgfor = $givenn.' '.$lastname; + if (scalar(@col_fullnames) > 0) { + my $lastone = pop @col_fullnames; + $msgfor .= ', '.(join ', ',@col_fullnames).' and '.$lastone.'.'; + } + $result.='
'."\n". + ' '. + 'Compose Message to student'.(scalar(@col_fullnames) >= 1 ? 's' : '').''. '
 (Message will be sent when you click on Save & Next below.)'."\n" if ($ENV{'form.handgrade'} eq 'yes'); $request->print($result); @@ -1022,26 +1108,44 @@ KEYWORDS ''. ''."  \n"; $result.=''; - $result.='
'; + $result.='
'."\n"; $request->print($result); } - $request->print(''."\n"); - $request->print(''."\n"); + $result=''."\n"; + my $ctr = 0; + while ($ctr < scalar(@partlist)) { + $result.=''."\n"; + $ctr++; + } + $request->print($result.''."\n"); # print end of form if ($counter == $total) { - my $endform.='
'; - my $ntstu =''."\n"; - my $nsel = ($ENV{'form.NTSTU'} ne '' ? $ENV{'form.NTSTU'} : '1'); - $ntstu =~ s/
'; + my $endform='
'. + ''."\n"; + if ($ENV{'form.handgrade'} eq 'yes') { + $endform.='  '."\n"; + my $ntstu =''."\n"; + my $nsel = ($ENV{'form.NTSTU'} ne '' ? $ENV{'form.NTSTU'} : '1'); + $ntstu =~ s/
'; $request->print($endform); } return ''; @@ -1102,8 +1206,7 @@ sub processHandGrade { my $ctr = 0; while ($ctr < $ngrade) { my ($uname,$udom) = split(/:/,$ENV{'form.unamedom'.$ctr}); - my ($errorflg) = &saveHandGrade($request,$url,$symb,$uname,$udom,$ctr); - return '' if ($errorflg eq 'error'); + my ($errorflag) = &saveHandGrade($request,$url,$symb,$uname,$udom,$ctr); my $includemsg = $ENV{'form.includemsg'.$ctr}; my ($subject,$message,$msgstatus) = ('','',''); @@ -1263,11 +1366,6 @@ sub saveHandGrade { my $pts = ($ENV{'form.GD_BOX'.$newflg.'_'.$_} ne '' ? $ENV{'form.GD_BOX'.$newflg.'_'.$_} : $ENV{'form.RADVAL'.$newflg.'_'.$_}); - if ($pts eq '') { - &userError($request,'No point was assigned for part '.$_. - ' and for username '.$stuname.'.'); - return 'error'; - } my $wgt = $ENV{'form.WGT'.$newflg.'_'.$_} eq '' ? 1 : $ENV{'form.WGT'.$newflg.'_'.$_}; my $partial= $pts/$wgt; @@ -1304,13 +1402,7 @@ sub viewgrades_js { $request->print(< - function viewOneStudent(user,domain) { - document.onestudent.student.value = user; - document.onestudent.userdom.value = domain; - document.onestudent.submit(); - } - - function writePoint(partid,weight,point) { + function writePoint(partid,weight,point) { var radioButton = eval("document.classgrade.RADVAL_"+partid); var textbox = eval("document.classgrade.TEXTVAL_"+partid); if (point == "textval") { @@ -1480,18 +1572,12 @@ sub viewgrades { &viewgrades_js($request); my ($symb,$url) = ($ENV{'form.symb'},$ENV{'form.url'}); - my $result='

Manual Grading

'; + my $result='

Manual Grading

'; $result.='Resource: '.$ENV{'form.url'}.''."\n"; #view individual student submission form - called using Javascript viewOneStudent - $result.= '
'."\n". - ''."\n". - ''."\n". - ''."\n". - ''."\n". - ''."\n". - '
'."\n"; + $result.=&jscriptNform($url,$symb); #beginning of class grading form $result.= '
'."\n". @@ -1499,7 +1585,6 @@ 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 '. @@ -1512,9 +1597,12 @@ sub viewgrades { my %weight = (); my $ctsparts = 0; $result.=''; + my %seen = (); for (sort keys(%$handgrade)) { - my ($responsetype,$handgrade)=split(/:/,$$handgrade{$_}); my ($partid,$respid) = split (/_/); + next if $seen{$partid}; + $seen{$partid}++; + my ($responsetype,$handgrade)=split(/:/,$$handgrade{$_}); my $wgt = &Apache::lonnet::EXT('resource.'.$partid.'.weight',$symb); $weight{$partid} = $wgt eq '' ? '1' : $wgt; @@ -1547,9 +1635,8 @@ sub viewgrades { $result.='
'; $result.='    '; -# $result.=''."\n"; - $result.= ''."\n"; + $result.=''."\n"; #table listing all the students in a section/class #header of table @@ -1586,7 +1673,8 @@ sub viewgrades { } $result.=''; $result.=''."\n"; - $result.=''; + $result.=''."\n"; $result.=&show_grading_menu_form($symb,$url); return $result; } @@ -1638,7 +1726,7 @@ sub editgrades { my $symb=$ENV{'form.symb'}; my $url =$ENV{'form.url'}; - my $title='

Current Grade Status

'; + my $title='

Current Grade Status

'; $title.='Resource: '.$ENV{'form.url'}.'
'."\n"; $title.='Section: '.$ENV{'form.section'}.''."\n"; $title.= &show_grading_menu_form ($symb,$url); @@ -1810,16 +1898,30 @@ ENDPICK sub csvuploadmap_header { my ($request,$symb,$url,$datatoken,$distotal)= @_; - my $result; my $javascript; if ($ENV{'form.upfile_associate'} eq 'reverse') { $javascript=&csvupload_javascript_reverse_associate(); } else { $javascript=&csvupload_javascript_forward_associate(); } + + my $result=''; + $result.=''; + my ($partlist,$handgrade) = &response_type($url); + my ($resptype,$hdgrade)=('','no'); + for (sort keys(%$handgrade)) { + my ($responsetype,$handgrade)=split(/:/,$$handgrade{$_}); + $resptype = $responsetype; + $hdgrade = $handgrade if ($handgrade eq 'yes'); + $result.=''. + ''. + ''; + } + $result.='
Resource: '.$url.'
Part '.(split(/_/))[0].'Type: '.$responsetype.'Handgrade: '.$handgrade.'
'; $request->print(< -

Uploading Class Grades for resource $url

+

Uploading Class Grades

+$result

Identify fields

Total number of records found in file: $distotal
@@ -1887,6 +1989,7 @@ sub csvuploadmap { my ($i,$keyfields); if (@records) { my @fields=&csvupload_fields($url); + if ($ENV{'form.upfile_associate'} eq 'reverse') { &Apache::loncommon::csv_print_samples($request,\@records); $i=&Apache::loncommon::csv_print_select_table($request,\@records, @@ -1987,7 +2090,7 @@ sub gradingmenu { my ($request) = @_; my ($symb,$url)=&get_symb_and_url($request); if (!$symb) {return '';} - my $result='

 Select a Grading Method

'; + my $result='

 Select a Grading Method

'; $result.=''; $result.=''; my ($partlist,$handgrade) = &response_type($url); @@ -2155,10 +2258,10 @@ sub handler { 'grade_courseid' => $tcrsid, 'grade_symb' => $tsymb))); } else { - $request->print('

Not authorized: '.$token.'

'); + $request->print('

Not authorized: '.$token.'

'); } } else { - $request->print('

Not a valid DocID: '.$token.'

'); + $request->print('

Not a valid DocID: '.$token.'

'); } } else { $request->print(&Apache::lonxml::tokeninputfield());
Resource: '.$url.'