--- loncom/homework/grades.pm 2003/06/20 21:28:18 1.104 +++ loncom/homework/grades.pm 2003/07/14 14:29:07 1.113 @@ -1,7 +1,7 @@ # The LearningOnline Network with CAPA # The LON-CAPA Grading handler # -# $Id: grades.pm,v 1.104 2003/06/20 21:28:18 albertel Exp $ +# $Id: grades.pm,v 1.113 2003/07/14 14:29:07 ng Exp $ # # Copyright Michigan State University Board of Trustees # @@ -41,6 +41,7 @@ use Apache::style; use Apache::lonxml; use Apache::lonnet; use Apache::loncommon; +use Apache::lonhtmlcommon; use Apache::lonnavmaps; use Apache::lonhomework; use Apache::loncoursedata; @@ -129,8 +130,8 @@ sub getclasslist { my (undef,undef,$end,$start,$id,$section,$fullname,$status)= @{$classlist->{$_}}; # filter students according to status selected - if ($filterlist && $ENV{'form.status'} ne 'Any') { - if ($ENV{'form.status'} ne $status) { + if ($filterlist && $ENV{'form.Status'} ne 'Any') { + if ($ENV{'form.Status'} ne $status) { delete ($classlist->{$_}); next; } @@ -367,28 +368,47 @@ sub listStudents { $request->print(< - function checkSelect(checkBox) { - var ctr=0; - var sense=""; - if (checkBox.length > 1) { - for (var i=0; i 1) { + for (var i=0; i 1) { + for (var i=0; i LISTJAVASCRIPT @@ -405,6 +425,10 @@ LISTJAVASCRIPT if ($ENV{'form.handgrade'} eq 'yes') { $gradeTable.=' handgrade only'."\n"; } + + my $saveStatus = $ENV{'form.Status'} eq '' ? 'Active' : $ENV{'form.Status'}; + $ENV{'form.Status'} = $saveStatus; + $gradeTable.=' last sub only'."\n". ' last sub & parts info'."\n". ' all details'."\n". @@ -417,58 +441,82 @@ LISTJAVASCRIPT ''."\n". ''."\n". ''."\n". - 'To '.lc($viewgrade).' a submission, click on the check box next to the student\'s name. Then '."\n". + ''."\n"; + + $gradeTable.='Student Status: '. + &Apache::lonhtmlcommon::StatusOptions($saveStatus,undef,1,'javascript:reLoadList(this.form);').'
'; + + $gradeTable.='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"; + $gradeTable.=''."\n"; - - my (undef,undef,$fullname) = &getclasslist($getsec,$ENV{'form.showgrading'} eq 'yes' ? '1' : '0'); - + + my (undef, undef, $fullname) = &getclasslist($getsec,'1'); $gradeTable.='
'. - ''. - ''. - ''; - foreach (sort(@$partlist)) { - $gradeTable.=''; + '
 Select  Fullname  Username  Domain  Part '.(split(/_/))[0].' Status 
'; + my $loop = 0; + while ($loop < 2) { + $gradeTable.=''; + if ($ENV{'form.showgrading'} eq 'yes' && $submitonly ne 'all') { + foreach (sort(@$partlist)) { + $gradeTable.=''; + } + } + $loop++; } $gradeTable.=''."\n"; my $ctr = 0; 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 = ''; - foreach (keys(%status)) { - $statusflg = 1 if ($status{$_} ne 'nothing'); - my ($foo,$partid,$foo1) = split(/\./,$_); - if ($status{'resource.'.$partid.'.submitted_by'} ne '') { - $statusflg = ''; - $gradeTable.=''; + my %status = (); + if ($ENV{'form.showgrading'} eq 'yes' && $submitonly ne 'all') { + (%status) =&student_gradeStatus($url,$symb,$udom,$uname,$partlist); + my $statusflg = ''; + foreach (keys(%status)) { + $statusflg = 1 if ($status{$_} ne 'nothing'); + my ($foo,$partid,$foo1) = split(/\./,$_); + if ($status{'resource.'.$partid.'.submitted_by'} ne '') { + $statusflg = ''; + $gradeTable.=''; + } } + next if ($statusflg eq '' && $submitonly eq 'yes'); } - next if ($statusflg eq '' && $submitonly eq 'yes'); $ctr++; if ( $perm{'vgr'} eq 'F' ) { - $gradeTable.=''. - ''."\n". - ''."\n". - ''."\n". - ''."\n"; - - foreach (sort keys(%status)) { - next if (/^resource.*?submitted_by$/); - $gradeTable.=''."\n"; + $gradeTable.='' if ($ctr%2 ==1); + $gradeTable.=''."\n". + ''."\n"; + + if ($ENV{'form.showgrading'} eq 'yes' && $submitonly ne 'all') { + foreach (sort keys(%status)) { + next if (/^resource.*?submitted_by$/); + $gradeTable.=''."\n"; + } } - $gradeTable.=''."\n"; + $gradeTable.=''."\n" if ($ctr%2 ==0); } } + if ($ctr%2 ==1) { + $gradeTable.=''; + if ($ENV{'form.showgrading'} eq 'yes' && $submitonly ne 'all') { + foreach (@$partlist) { + $gradeTable.=''; + } + } + $gradeTable.=''; + } + $gradeTable.='
 Select  Fullname '. + '(Username)  Part '.(split(/_/))[0].' Status 
 '.$$fullname{$student}.'  '.$uname.'  '.$udom.'  '.$status{$_}.' 
 '.$$fullname{$student}.' '."\n". + '('.$uname.') '.$status{$_}.' 
   
'. '
'; + 'No submissions found for this resource for any students. ('.$num_students. + ' checked for submissions
'; } } elsif ($ctr == 1) { $gradeTable =~ s/type=checkbox/type=checkbox checked/; @@ -1264,7 +1313,7 @@ KEYWORDS } else { for my $part (sort keys(%$handgrade)) { foreach (@$string) { - my ($partid,$respid) = /^resource\.(\d+)\.(\d+)\.submission/; + my ($partid,$respid) = /^resource\.(\w+)\.(\w+)\.submission/; if ($part eq ($partid.'_'.$respid)) { my ($ressub,$subval) = split(/:/,$_,2); # Similarity check @@ -1322,7 +1371,7 @@ KEYWORDS my $lastone = pop @col_fullnames; $msgfor .= ', '.(join ', ',@col_fullnames).' and '.$lastone.'.'; } - $msgfor =~ s/\'/\\'/g; #' stupid emacs + $msgfor =~ s/\'/\\'/g; #' stupid emacs - no! javascript $result.=''."\n". ' '. @@ -1673,8 +1722,8 @@ sub viewgrades_js { var textbox = eval("document.classgrade.TEXTVAL_"+partid); if (point == "textval") { var point = eval("document.classgrade.TEXTVAL_"+partid+".value"); - if (isNaN(point) || point < 0) { - alert("A number equal or greater than 0 is expected. Entered value = "+point); + if (isNaN(point) || parseFloat(point) < 0) { + alert("A number equal or greater than 0 is expected. Entered value = "+parseFloat(point)); var resetbox = false; for (var i=0; i weight) { - var resp = confirm("You entered a value ("+point+ + if (parseFloat(point) > parseFloat(weight)) { + var resp = confirm("You entered a value ("+parseFloat(point)+ ") greater than the weight for the part. Accept?"); if (resp == false) { textbox.value = ""; @@ -1697,7 +1746,7 @@ sub viewgrades_js { } for (var i=0; i weight) { - var resp = confirm("You entered a value ("+point+ + if (parseFloat(point) > parseFloat(weight)) { + var resp = confirm("You entered a value ("+parseFloat(point)+ ") greater than the weight of the part. Accept?"); if (resp == false) { textbox.value = ""; @@ -1908,9 +1957,9 @@ sub viewgrades { $result.=''.''.''."\n". ''; $result.='    '; - $result.=''."\n"; + 'onClick="javascript:resetEntry('.$ctsparts.');" TARGET=_self>'; +# $result.='    '."\n"; #table listing all the students in a section/class #header of table @@ -1924,7 +1973,7 @@ sub viewgrades { } $result.= '
'."\n". ''. - ''."\n"; + ''."\n"; my (@parts) = sort(&getpartlist($url)); foreach my $part (@parts) { my $display=&Apache::lonnet::metadata($url,$part.'.display'); @@ -1958,7 +2007,7 @@ sub viewgrades { 'onClick="javascript:submit();" TARGET=_self />'."\n"; if (scalar(%$fullname) eq 0) { my $colspan=3+scalar(@parts); - $result='There are no students in section "'.$ENV{'form.section'}.'" with enrollment status "'.$ENV{'form.status'}.'" to modify or grade.'; + $result='There are no students in section "'.$ENV{'form.section'}.'" with enrollment status "'.$ENV{'form.Status'}.'" to modify or grade.'; } $result.=&show_grading_menu_form($symb,$url); return $result; @@ -1972,8 +2021,8 @@ sub viewstudentgrade { my %record=&Apache::lonnet::restore($symb,$courseid,$udom,$uname); my $result=''."\n"; + '\')"; TARGET=_self>'.$fullname.' '. + '('.$uname.($ENV{'user.domain'} eq $udom ? '' : ':'.$udom).')'."\n"; foreach my $apart (@$parts) { my ($part,$type) = &split_part_type($apart); my $score=$record{"resource.$part.$type"}; @@ -2080,10 +2129,15 @@ sub editgrades { my ($uname,$udom)=split(/_/,$user); my %newrecord; my $updateflag = 0; - $line .= ''; + my $usec=$classlist->{"$uname:$udom"}[5]; + if (!&canmodify($usec)) { + my $numcols=scalar(@partid)*(scalar(@parts)-1)*2; + $noupdate.=$line.""; + next; + } foreach (@partid) { my $old_aw = $ENV{'form.GD_'.$user.'_'.$_.'_awarded_s'}; my $old_part_pcr = $old_aw/($weight{$_} ne '0' ? $weight{$_}:1); @@ -2141,7 +2195,8 @@ sub editgrades { } } if ($noupdate) { - $result .= ''.$noupdate; + my $numcols=(scalar(@partid)*(scalar(@parts)-1)*2)+3; + $result .= ''.$noupdate; } $result .= '
FullnameUsernameDomainFullname (Username)
'. ''.$fullname.''. - ''.$uname.''.$udom.'
'.$uname.' '. $udom.' '. $$fullname{$usercolon}.' Not allowed to modify student
No Changes Occured For the Students Below
No Changes Occured For the Students Below
'."\n". &show_grading_menu_form ($symb,$url); @@ -2344,7 +2399,7 @@ CSVFORMJS $result.=''."\n"; my $upfile_select=&Apache::loncommon::upfile_select_html(); $result.=< +
@@ -2423,6 +2478,7 @@ sub csvuploadassign { $request->print('

Assigning Grades

'); my $courseid=$ENV{'request.course.id'}; my ($classlist) = &getclasslist('all',0); + my @notallowed; my @skipped; my $countdone=0; foreach my $grade (@gradedata) { @@ -2433,6 +2489,11 @@ sub csvuploadassign { push(@skipped,"$username:$domain"); next; } + my $usec=$classlist->{"$username:$domain"}[5]; + if (!&canmodify($usec)) { + push(@notallowed,"$username:$domain"); + next; + } my %grades; foreach my $dest (keys(%fields)) { if ($dest eq 'username' || $dest eq 'domain') { next; } @@ -2451,9 +2512,14 @@ sub csvuploadassign { } $request->print("
Stored $countdone students\n"); if (@skipped) { - $request->print('
Skipped Students
'); - foreach my $student (@skipped) { $request->print("
$student"); } + $request->print('Skipped Students

'); + foreach my $student (@skipped) { $request->print("$student
\n"); } + } + if (@notallowed) { + $request->print('

Students Not Allowed to Modify

'); + foreach my $student (@notallowed) { $request->print("$student
\n"); } } + $request->print("
\n"); $request->print(&show_grading_menu_form($symb,$url)); return ''; } @@ -2550,7 +2616,7 @@ LISTJAVASCRIPT ' all details'."\n"; $result.=''."\n". - ''."\n". + ''."\n". ''."\n". ''."\n". ''."\n". @@ -2597,21 +2663,21 @@ 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 + #my $res = $navmap->firstResource(); # temp resource to access constants $navmap->init(); # End navmap using boilerplate - my $iterator = $navmap->getIterator(undef, undef, undef, 1); + my $iterator = Apache::lonnavmaps::iterator->new($navmap, undef, undef, undef, 1, 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++;} + my $seenBeginMap = 0; + while ($depth > 0 && !$seenBeginMap) { + if ($curRes == $iterator->BEGIN_MAP()) {$depth++; $seenBeginMap = 1; } if ($curRes == $iterator->END_MAP()) { $depth--; } if (ref($curRes) && $curRes->is_map()) { @@ -3273,7 +3339,7 @@ sub gradingmenu { function checkChoice(formname) { var cmd = formname.command; formname.saveState.value = "saveCmd="+radioSelection(cmd)+":saveSec="+pullDownSelection(formname.section)+ - ":saveSub="+radioSelection(formname.submitonly)+":saveStatus="+pullDownSelection(formname.status); + ":saveSub="+radioSelection(formname.submitonly)+":saveStatus="+pullDownSelection(formname.Status); if (cmd[0].checked || cmd[1].checked || cmd[2].checked || cmd[3].checked || cmd[4].checked) formname.submit(); if (cmd[5].checked) { if (!checkReceiptNo(formname,'notOK')) { return false;} @@ -3411,12 +3477,7 @@ GRADINGMENUJS } $result.= '