--- loncom/homework/grades.pm 2002/08/05 20:49:54 1.45 +++ loncom/homework/grades.pm 2002/09/21 00:08:17 1.52 @@ -1,7 +1,7 @@ # The LearningOnline Network with CAPA # The LON-CAPA Grading handler # -# $Id: grades.pm,v 1.45 2002/08/05 20:49:54 ng Exp $ +# $Id: grades.pm,v 1.52 2002/09/21 00:08:17 albertel Exp $ # # Copyright Michigan State University Board of Trustees # @@ -45,17 +45,6 @@ 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) = @_; @@ -114,17 +103,6 @@ sub response_type { return \@partlist,\%handgrade; } -#--- Prints a message on screen if a user did something wrong -#--- Operator error --- -sub userError { - my ($request, $reason, $step) = @_; - $request->print('

LON-CAPA User Error


'."\n"); - $request->print('Reason: '.$reason.'

'."\n"); - $request->print('Step: '.($step ne '' ? $step : 'Use your browser back button to correct') - .'

'."\n"); - return ''; -} - #--- Dumps the class list with usernames,list of sections, #--- section, ids and fullnames for each user. sub getclasslist { @@ -133,6 +111,10 @@ sub getclasslist { my %classlist=&Apache::lonnet::dump('classlist', $ENV{'course.'.$ENV{'request.course.id'}.'.domain'}, $ENV{'course.'.$ENV{'request.course.id'}.'.num'}); + my ($tmp) = keys(%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) { @@ -310,7 +292,7 @@ sub verifyreceipt { $contents. ''."\n"; } - return $string.&show_grading_menu_form ($symb,$url); + return $string.&show_grading_menu_form($symb,$url); } #--- This is called by a number of programs. @@ -319,23 +301,57 @@ sub verifyreceipt { # on the problem page. sub listStudents { 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 $submitonly= $ENV{'form.submitonly'} eq '' ? 'all' : $ENV{'form.submitonly'}; + + my $result; + my ($partlist,$handgrade) = &response_type($url); + for (sort keys(%$handgrade)) { + my ($responsetype,$handgrade)=split(/:/,$$handgrade{$_}); + $ENV{'form.handgrade'} = 'yes' if ($handgrade eq 'yes'); + $result.='Part '.(split(/_/))[0].''. + 'Type: '.$responsetype.''. + 'Handgrade: '.$handgrade.''; + } + $result.=''; + + my $viewgrade; + if ($ENV{'form.handgrade'} eq 'yes') { + $viewgrade = 'View/Grade'; + } else { + $viewgrade = 'View'; + } + + $result='

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

'. + ''.$result; + $request->print(< function checkSelect(checkBox) { var ctr=0; + var sense=""; 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/Grade Submissions for a Student or a Group of Students

'; - $result.='
'. + 'Resource: '.$url.'
'; - $result.=''; - my ($partlist,$handgrade) = &response_type($ENV{'form.url'}); - for (sort keys(%$handgrade)) { - my ($responsetype,$handgrade)=split(/:/,$$handgrade{$_}); - $ENV{'form.handgrade'} = 'yes' if ($handgrade eq 'yes'); - $result.=''. - ''. - ''; - } - $result.='
'. - 'Resource: '.$ENV{'form.url'}.'
Part '.(split(/_/))[0].'Type: '.$responsetype.'Handgrade: '.$handgrade.'
'; $request->print($result); my $checkhdgrade = $ENV{'form.handgrade'} eq 'yes' ? 'checked' : ''; @@ -370,9 +367,11 @@ LISTJAVASCRIPT my $gradeTable='
'."\n". ' View Problem: no '."\n". ' yes
'."\n". - ' Submissions: '."\n". - ' handgrade only'."\n". - ' last sub only'."\n". + ' Submissions: '."\n"; + if ($ENV{'form.handgrade'} eq 'yes') { + $gradeTable.=' handgrade only'."\n"; + } + $gradeTable.=' last sub only'."\n". ' last sub & parts info'."\n". ' all details'."\n". ''."\n". @@ -380,15 +379,15 @@ LISTJAVASCRIPT ''."\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". + ''."\n". + ''."\n". + 'To '.lc($viewgrade).' a submission, click on the check box next to the student\'s name. Then '."\n". + 'click on the '.$viewgrade.' button. To view the submissions for a group of students, click'."\n". ' on the check boxes for the group of students.
'."\n". ''."\n". ''."\n"; + 'value="'.$viewgrade.'" />'."\n"; my ($classlist,$seclist,$ids,$stusec,$fullname) = &getclasslist($getsec,'0'); @@ -404,8 +403,7 @@ LISTJAVASCRIPT 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'}, - $ENV{'form.symb'},$udom,$uname,$partlist); + my (%status) =&student_gradeStatus($url,$symb,$udom,$uname,$partlist); my $statusflg = ''; foreach (keys(%status)) { $statusflg = 1 if ($status{$_} ne 'nothing'); @@ -438,12 +436,14 @@ LISTJAVASCRIPT $gradeTable.=''. ''."\n"; + 'value="'.$viewgrade.'" />
'."\n"; if ($ctr == 0) { $gradeTable='
 '. 'No submission found for this resource.
'; - $gradeTable.=&show_grading_menu_form ($ENV{'form.symb'},$ENV{'form.url'}); + } elsif ($ctr == 1) { + $gradeTable =~ s/type=checkbox/type=checkbox checked/; } + $gradeTable.=&show_grading_menu_form($symb,$url); $request->print($gradeTable); return ''; } @@ -552,7 +552,7 @@ sub sub_page_js { var points = eval("document.SCORE.GD_BOX"+i+"_"+partid+".value"); if (points == "") { var name = eval("document.SCORE.name"+i+".value"); - alert("You did not assign any point for "+name+", part "+partid+"."); + alert("Please assign a score for "+name+", part "+partid+"."); return false; } } @@ -594,7 +594,7 @@ sub sub_page_js { else return; var cleantxt = txt.replace(new RegExp('([\\f\\n\\r\\t\\v ])+', 'g')," "); if (cleantxt=="") { - alert("Select a word or group of words from document and then click this link."); + alert("Please select a word or group of words from document and then click this link."); return; } var nret = prompt("Add selection to keyword list? Edit if desired.",cleantxt); @@ -929,7 +929,6 @@ KEYWORDS my $result='
'."\n". '
'."\n"; -# $result.='
Fullname: '.$ENV{'form.fullname'}. $result.='Fullname: '.$ENV{'form.fullname'}. '   Username: '.$uname.''. '   Domain: '.$udom.'
'."\n"; @@ -1002,7 +1001,7 @@ KEYWORDS $request->print($submitby); } else { my ($string,$timestamp)= - &get_last_submission ($symb,$uname,$udom,$ENV{'request.course.id'}); + &get_last_submission (%record); my $lastsubonly.=''. ($$timestamp eq '' ? '' : 'Date Submitted: '. $$timestamp).''; @@ -1146,6 +1145,7 @@ KEYWORDS $endform.='(Next and Previous do not save the scores.)'."\n" if ($ENV{'form.handgrade'} eq 'yes'); $endform.='
'; + $endform.=&show_grading_menu_form($symb,$url); $request->print($endform); } return ''; @@ -1153,31 +1153,30 @@ KEYWORDS #--- Retrieve the last submission for all the parts sub get_last_submission { - my ($symb,$username,$domain,$course)=@_; - if ($symb) { - my (@string,$timestamp); - my (%returnhash)=&Apache::lonnet::restore($symb,$course,$domain,$username); - if ($returnhash{'version'}) { - my %lasthash=(); - my ($version); - for ($version=1;$version<=$returnhash{'version'};$version++) { - foreach (sort(split(/\:/,$returnhash{$version.':keys'}))) { - $lasthash{$_}=$returnhash{$version.':'.$_}; - } - } - foreach ((keys %lasthash)) { - if ($_ =~ /\.submission$/) { - my ($partid,$foo) = split(/submission$/,$_); - my $draft = $lasthash{$partid.'awarddetail'} eq 'DRAFT' ? - 'Draft Copy ' : ''; - push @string, (join(':',$_,$draft.$lasthash{$_})); - } - if ($_ =~ /timestamp/) {$timestamp = scalar(localtime($lasthash{$_}))}; + my (%returnhash)=@_; + my (@string,$timestamp); + if ($returnhash{'version'}) { + my %lasthash=(); + my ($version); + 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)) { + if ($_ =~ /\.submission$/) { + my ($partid,$foo) = split(/submission$/,$_); + my $draft = $lasthash{$partid.'awarddetail'} eq 'DRAFT' ? + 'Draft Copy ' : ''; + push @string, (join(':',$_,$draft.$lasthash{$_})); } } - @string = $string[0] eq '' ? 'Nothing submitted - no attempts.' : @string; - return \@string,\$timestamp; } + @string = $string[0] eq '' ? 'Nothing submitted - no attempts.' : @string; + return \@string,\$timestamp; } #--- High light keywords, with style choosen by user. @@ -1585,12 +1584,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"; $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'}); @@ -1632,7 +1641,8 @@ sub viewgrades { '
'; + $result.='
'.'
'.'
'."\n". + ''; $result.='    '; $result.=''; + } $result.= '
'."\n". ''. ''."\n"; @@ -2029,8 +2047,6 @@ sub csvuploadassign { } $request->print('

Assigning Grades

'); my $courseid=$ENV{'request.course.id'}; -# my $cdom=$ENV{"course.$courseid.domain"}; -# my $cnum=$ENV{"course.$courseid.num"}; my ($classlist) = &getclasslist('all','1'); my @skipped; my $countdone=0; @@ -2119,18 +2135,20 @@ sub view_edit_entire_class_form { my ($classlist,$sections) = &getclasslist('all','0'); my $result.='
FullnameUsernameDomain
'."\n"; $result.=''."\n"; + $result.=' Grade Entire Section or Class'."\n"; $result.='
'."\n"; - $result.=' View/Grade Entire Section/Class
'."\n"; $result.='
'."\n". ''."\n". ''."\n". ''."\n"; $result.=' Select section: '."
\n"; - $result.=' 
'."\n"; + $result.=' '."\n"; $result.='
'."\n"; $result.='
'."\n"; return $result; @@ -2140,7 +2158,17 @@ sub view_edit_entire_class_form { sub upcsvScores_form { my ($symb,$url) = @_; if (!$symb) {return '';} - my $result.='
'."\n"; + my $result = ''."\n"; + + $result.='
'."\n"; $result.=''."\n"; $result.='
'."\n"; $result.=' Specify a file containing the class scores for above resource
'."\n"; @@ -2151,7 +2179,7 @@ sub upcsvScores_form { $upfile_select -
  +
  ENDUPFORM $result.='
'."\n"; @@ -2165,7 +2193,13 @@ sub viewGradeaStu_form { my ($classlist,$sections) = &getclasslist('all','0'); my $result.='
'."\n"; $result.=''."\n"; + $result.=' '; + if ($handgrade eq 'yes') { + $result.="View/Grade "; + } else { + $result.="View "; + } + $result.='an Individual Student\'s Submission'."\n"; $result.='
'."\n"; - $result.=' View/Grade an Individual Student\'s Submission
'."\n"; $result.='
'."\n". ''."\n". @@ -2176,18 +2210,26 @@ sub viewGradeaStu_form { ''."\n"; $result.=' Select section: '."\n"; $result.='  Display students who has: '. ' submitted'. ' everybody
'; - $result.=' (Section "no" implies the students were not assigned a section.)
' - if (grep /no/,@$sections); - - $result.='
 '."\n". - '
'."\n"; + if (ref($sections)) { + $result.=' (Section "no" implies the students were not assigned a section.)
' + if (grep /no/,@$sections); + } + + + $result.='
 '."\n"; $result.='
'."\n"; $result.='
'."\n"; return $result; @@ -2196,17 +2238,27 @@ sub viewGradeaStu_form { #--- Form to input a receipt number --- sub verifyReceipt_form { my ($symb,$url) = @_; - my $cdom=$ENV{"course.$ENV{'request.course.id'}.domain"}; - my $cnum=$ENV{"course.$ENV{'request.course.id'}.num"}; + my $result = ''."\n"; + my $hostver=unpack("%32C*",$Apache::lonnet::perlvar{'lonHostID'}); - my $result.='
'."\n"; + $result.='
'."\n"; $result.=''."\n"; $result.='
'."\n"; $result.=' Verify a Submission Receipt Issued by this Server
'."\n"; - $result.='
'."\n"; + $result.=''."\n"; $result.=' '.$hostver.'-
'."\n"; - $result.=' '."\n"; + $result.=' '."\n"; $result.=''."\n"; if ($ENV{'form.url'}) { $result.=''; @@ -2268,7 +2320,6 @@ sub handler { } } } else { - #&Apache::lonhomework::showhashsubset(\%ENV,'^form'); $Apache::grades::viewgrades=&Apache::lonnet::allowed('vgr',$ENV{'request.course.id'}); if ($command eq 'submission') { &listStudents($request) if ($ENV{'form.student'} eq ''); @@ -2318,7 +2369,7 @@ sub send_header { #remotewindow=open('','homeworkremote'); #remotewindow.close(); #"); - $request->print(''); + $request->print(&Apache::loncommon::bodytag('Grading')); } sub send_footer {