--- loncom/homework/grades.pm 2007/06/15 22:00:42 1.406 +++ loncom/homework/grades.pm 2007/07/04 18:37:30 1.419 @@ -1,7 +1,7 @@ # The LearningOnline Network with CAPA # The LON-CAPA Grading handler # -# $Id: grades.pm,v 1.406 2007/06/15 22:00:42 www Exp $ +# $Id: grades.pm,v 1.419 2007/07/04 18:37:30 www Exp $ # # Copyright Michigan State University Board of Trustees # @@ -41,7 +41,6 @@ use Apache::Constants qw(:common); use Apache::lonlocal; use Apache::lonenc; use String::Similarity; -use lib '/home/httpd/lib/perl'; use LONCAPA; use POSIX qw(floor); @@ -94,6 +93,7 @@ sub get_symb { return (); } } + &Apache::lonenc::check_decrypt(\$symb); return ($symb); } @@ -493,7 +493,7 @@ sub jscriptNform { ' }'."\n". ''."\n"; $jscript.= '
'."\n". - ''."\n". + ''."\n". ''."\n". ''."\n". ''."\n". @@ -618,7 +618,7 @@ sub verifyreceipt { if ($receipt eq &Apache::lonnet::ireceipt($uname,$udom,$courseid,$symb,$part)) { $contents.=' '."\n". ''.$$fullname{$_}.' '."\n". + '\');" target="_self">'.$$fullname{$_}.' '."\n". ' '.$uname.' '. ' '.$udom.' '; if ($receiptparts) { @@ -743,7 +743,7 @@ LISTJAVASCRIPT '
'."\n". ''."\n". ''."\n". - ''."\n". + ''."\n". ''."\n"; if (exists($env{'form.gradingMenu'}) && exists($env{'form.Status'})) { @@ -1752,7 +1752,7 @@ sub submission { ''."\n". ''."\n". ''."\n". - ''."\n". + ''."\n". ''."\n". ''."\n". ''."\n". @@ -1793,10 +1793,10 @@ sub submission { # $request->print(<Keyword Options:  -List    +List    Paste Selection to List    -Highlight Attribute

+Highlight Attribute

KEYWORDS # # Load the other essays for similarity check @@ -1922,7 +1922,7 @@ KEYWORDS ' Collaborative submission by: '. ''. + '\');" target="_self">'. $$fullname{$env{"form.$uname:$udom:$partid:submitted_by"}}.'
'; $request->print($submitby); next; @@ -2000,7 +2000,7 @@ KEYWORDS if ($env{'form.showgrading'} eq '' || (!&canmodify($usec))) { my $toGrade.='  '."\n" if (&canmodify($usec)); + .$counter.'\');" target="_self" />  '."\n" if (&canmodify($usec)); $toGrade.=''."\n"; if (($env{'form.command'} eq 'submission') || ($env{'form.command'} eq 'processGroup' && $counter == $total)) { @@ -2024,7 +2024,7 @@ KEYWORDS $result=''."\n". ''."\n"; $result.=' '. + ',\''.$msgfor.'\');" target="_self">'. &mt('Compose message to student').(scalar(@col_fullnames) >= 1 ? 's' : '').')'. ''."\n"; $endform.='  '."\n"; + $total.','.scalar(@partlist).');" target="_self" />  '."\n"; my $ntstu ='  '; + 'onClick="javascript:checksubmit(this.form,\'Next\');" target="_self" />  '; $endform.='(Next and Previous (student) do not save the scores.)'."\n" ; $endform.=""; @@ -2169,18 +2169,10 @@ sub processHandGrade { } my $includemsg = $env{'form.includemsg'.$ctr}; my ($subject,$message,$msgstatus) = ('','',''); - my $restitle = &Apache::lonnet::gettitle($symb); - my $encrypturl=&Apache::lonnet::EXT('resource.0.encrypturl', - $symb,$udom,$uname); - my ($feedurl,$baseurl,$showsymb,$messagetail); - $feedurl = &Apache::lonnet::clutter($url); - if ($encrypturl =~ /^yes$/i) { - $baseurl = &Apache::lonenc::encrypted($feedurl,1); - $showsymb = &Apache::lonenc::encrypted($symb,1); - } else { - $baseurl = $feedurl; - $showsymb = $symb; - } + my $restitle = &Apache::lonnet::gettitle($symb); + my ($feedurl,$showsymb) = + &get_feedurl_and_symb($symb,$uname,$udom); + my $messagetail; if ($includemsg =~ /savemsg|newmsg\Q$ctr\E/) { $subject = $env{'form.msgsub'} if ($includemsg =~ /msgsub/); unless ($subject=~/\w/) { $subject=&mt('Grading Feedback'); } @@ -2193,12 +2185,12 @@ sub processHandGrade { if ($env{'form.withgrades'.$ctr}) { $message.="\n\nPoint".($pts > 1 ? 's':'').' awarded = '.$pts.' out of '.$wgt; $messagetail = " for $env{'form.probTitle'}"; + $feedurl."?symb=$showsymb\">$env{'form.probTitle'}"; } $msgstatus = &Apache::lonmsg::user_normal_msg($uname,$udom,$subject, $message.$messagetail, - undef,$baseurl,undef, + undef,$feedurl,undef, undef,undef,$showsymb, $restitle); $request->print('
'.&mt('Sending message to [_1]:[_2]',$uname,$udom).': '. @@ -2215,26 +2207,16 @@ sub processHandGrade { if ($errorflag eq 'not_allowed') { $request->print("".&mt('Not allowed to modify grades for [_1]',"$collaborator:$udom").""); next; - } else { - if ($message ne '') { - $encrypturl= - &Apache::lonnet::EXT('resource.0.encrypturl', - $symb,$udom,$collaborator); - if ($encrypturl =~ /^yes$/i) { - $baseurl = &Apache::lonenc::encrypted($feedurl,1); - $showsymb = &Apache::lonenc::encrypted($symb,1); - } else { - $baseurl = $feedurl; - $showsymb = $symb; - } - if ($env{'form.withgrades'.$ctr}) { - $messagetail = " for $env{'form.probTitle'}"; - - } - $msgstatus = - &Apache::lonmsg::user_normal_msg($collaborator,$udom,$subject,$message.$messagetail,undef,$baseurl,undef,undef,undef,$showsymb,$restitle); } + $msgstatus = + &Apache::lonmsg::user_normal_msg($collaborator,$udom,$subject,$message.$messagetail,undef,$baseurl,undef,undef,undef,$showsymb,$restitle); } } } @@ -2588,28 +2570,31 @@ sub handback_files { $message .= "".&Apache::lonnet::gettitle($symb)."
"; $message .= ' The returned file(s) are named: '. $file_msg; $message .= " and can be found in your portfolio space."; - my $url = (&Apache::lonnet::decode_symb($symb))[2]; - my $feedurl = &Apache::lonnet::clutter($url); - my $encrypturl=&Apache::lonnet::EXT('resource.0.encrypturl', - $symb,$domain,$stuname); - my ($baseurl,$showsymb); - if ($encrypturl =~ /^yes$/i) { - $baseurl = &Apache::lonenc::encrypted($feedurl,1); - $showsymb = &Apache::lonenc::encrypted($symb,1); - } else { - $baseurl = $feedurl; - $showsymb = $symb; - } + my ($feedurl,$showsymb) = + &get_feedurl_and_symb($symb,$domain,$stuname); my $restitle = &Apache::lonnet::gettitle($symb); my $msgstatus = &Apache::lonmsg::user_normal_msg($stuname,$domain,$subject. ' (File Returned) ['.$restitle.']',$message,undef, - $baseurl,undef,undef,undef,$showsymb,$restitle); + $feedurl,undef,undef,undef,$showsymb,$restitle); } } return; } +sub get_feedurl_and_symb { + my ($symb,$uname,$udom) = @_; + my (undef,undef,$url) = &Apache::lonnet::decode_symb($symb); + $url = &Apache::lonnet::clutter($url); + my $encrypturl=&Apache::lonnet::EXT('resource.0.encrypturl', + $symb,$udom,$uname); + if ($encrypturl =~ /^yes$/i) { + &Apache::lonenc::encrypted(\$url,1); + &Apache::lonenc::encrypted(\$symb,1); + } + return ($url,$symb); +} + sub get_submitted_files { my ($udom,$uname,$partid,$respid,$record) = @_; my @files; @@ -2970,7 +2955,7 @@ sub viewgrades { #beginning of class grading form $result.= ''."\n". - ''."\n". + ''."\n". ''."\n". ''."\n". ''."\n". @@ -3037,7 +3022,7 @@ sub viewgrades { $result.=''.''.''."\n". ''; $result.=''; + 'onClick="javascript:resetEntry('.$ctsparts.');" target="_self" />'; #table listing all the students in a section/class #header of table @@ -3088,7 +3073,7 @@ sub viewgrades { $result.=''; $result.=''."\n"; $result.=''."\n"; + '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'}. @@ -3108,7 +3093,7 @@ sub viewstudentgrade { ''. "\n".$ctr.'  '. ''.$fullname.' '. + '\');" target="_self">'.$fullname.' '. '('.$uname.($env{'user.domain'} eq $udom ? '' : ':'.$udom).')'."\n"; $student=~s/:/_/; # colon doen't work in javascript for names foreach my $apart (@$parts) { @@ -3472,6 +3457,7 @@ sub csvuploadmap_header { my ($result) = &showResourceInfo($symb,$env{'form.probTitle'}); my $checked=(($env{'form.noFirstLine'})?' checked="checked"':''); my $ignore=&mt('Ignore First Line'); + $symb = &Apache::lonenc::check_encrypt($symb); $request->print(<

Uploading Class Grades

@@ -3566,6 +3552,7 @@ sub upcsvScores_form { my $upload=&mt("Upload Scores"); my $upfile_select=&Apache::loncommon::upfile_select_html(); my $ignore=&mt('Ignore First Line'); + $symb = &Apache::lonenc::check_encrypt($symb); $result.=< @@ -3874,7 +3861,7 @@ LISTJAVASCRIPT $result.=''."\n". ''."\n". ''."\n". - ''."\n". + ''."\n". ''."
\n"; $result.=' '.&mt('Use CODE:').' '. @@ -3998,7 +3985,7 @@ sub displayPage { ''."\n". ''."\n". ''."\n". - ''."\n". + ''."\n". ''."\n". ''."\n"; @@ -4370,7 +4357,7 @@ sub updateGradeByPage { sub defaultFormData { my ($symb)=@_; return ' - '."\n". + '."\n". ''."\n". ''."\n"; } @@ -5939,7 +5926,7 @@ DOWNLOAD sub show_grading_menu_form { my ($symb)=@_; my $result.='
'."\n". - ''."\n". + ''."\n". ''."\n". ''."\n". ''."\n". @@ -6014,7 +6001,7 @@ GRADINGMENUJS my $saveStatus = ($$savedState{'saveStatus'} eq '' ? 'Active' : $$savedState{'saveStatus'}); $result.=''."\n". - ''."\n". + ''."\n". ''."\n". ''."\n". ''."\n". @@ -6130,53 +6117,61 @@ sub init_perm { } sub gather_clicker_ids { - my %clickerids=(); + my %clicker_ids; my $classlist = &Apache::loncoursedata::get_classlist(); # Set up a couple variables. - my $usernameidx = &Apache::loncoursedata::CL_SNAME(); - my $domainidx = &Apache::loncoursedata::CL_SDOM(); + my $username_idx = &Apache::loncoursedata::CL_SNAME(); + my $domain_idx = &Apache::loncoursedata::CL_SDOM(); - foreach my $student (keys %$classlist) { + foreach my $student (keys(%$classlist)) { - my $username = $classlist->{$student}->[$usernameidx]; - my $domain = $classlist->{$student}->[$domainidx]; + my $username = $classlist->{$student}->[$username_idx]; + my $domain = $classlist->{$student}->[$domain_idx]; my $clickers = - (&Apache::lonnet::userenvironment($domain,$username,'clickers'))[1]; + (&Apache::lonnet::userenvironment($domain,$username,'clickers'))[1]; foreach my $id (split(/\,/,$clickers)) { - $id=~s/^0+//; - if (exists($clickerids{$id})) { - $clickerids{$id}.=','.$username.':'.$domain; + $id=~s/^[\#0]+//; + if (exists($clicker_ids{$id})) { + $clicker_ids{$id}.=','.$username.':'.$domain; } else { - $clickerids{$id}=$username.':'.$domain; + $clicker_ids{$id}=$username.':'.$domain; } } } - return %clickerids; + return %clicker_ids; } sub gather_adv_clicker_ids { - my %clickerids=(); + my %clicker_ids; my $cnum=$env{'course.'.$env{'request.course.id'}.'.num'}; my $cdom=$env{'course.'.$env{'request.course.id'}.'.domain'}; my %coursepersonnel=&Apache::lonnet::get_course_adv_roles($cdom.'/'.$cnum); - foreach my $element (sort keys %coursepersonnel) { + foreach my $element (sort(keys(%coursepersonnel))) { foreach my $person (split(/\,/,$coursepersonnel{$element})) { my ($puname,$pudom)=split(/\:/,$person); my $clickers = - (&Apache::lonnet::userenvironment($pudom,$puname,'clickers'))[1]; + (&Apache::lonnet::userenvironment($pudom,$puname,'clickers'))[1]; foreach my $id (split(/\,/,$clickers)) { - $id=~s/^0+//; - if (exists($clickerids{$id})) { - $clickerids{$id}.=','.$puname.':'.$pudom; - } else { - $clickerids{$id}=$puname.':'.$pudom; - } + $id=~s/^[\#0]+//; + if (exists($clicker_ids{$id})) { + $clicker_ids{$id}.=','.$puname.':'.$pudom; + } else { + $clicker_ids{$id}=$puname.':'.$pudom; + } } } } - return %clickerids; + return %clicker_ids; +} + +sub clicker_grading_parameters { + return ('gradingmechanism' => 'scalar', + 'upfiletype' => 'scalar', + 'specificid' => 'scalar', + 'pcorrect' => 'scalar', + 'pincorrect' => 'scalar'); } sub process_clicker { @@ -6192,16 +6187,33 @@ sub process_clicker { $result.=' '.&mt('Specify a file containing the clicker information for this resource'). '.'."\n"; $result.=''."\n"; +# Attempt to restore parameters from last session, set defaults if not present + my %Saveable_Parameters=&clicker_grading_parameters(); + &Apache::loncommon::restore_course_settings('grades_clicker', + \%Saveable_Parameters); + if (!$env{'form.pcorrect'}) { $env{'form.pcorrect'}=100; } + if (!$env{'form.pincorrect'}) { $env{'form.pincorrect'}=100; } + if (!$env{'form.gradingmechanism'}) { $env{'form.gradingmechanism'}='attendance'; } + if (!$env{'form.upfiletype'}) { $env{'form.upfiletype'}='iclicker'; } + + my %checked; + foreach my $gradingmechanism ('attendance','personnel','specific') { + if ($env{'form.gradingmechanism'} eq $gradingmechanism) { + $checked{$gradingmechanism}="checked='checked'"; + } + } + my $upload=&mt("Upload File"); my $type=&mt("Type"); my $attendance=&mt("Award points just for participation"); my $personnel=&mt("Correctness determined from response by course personnel"); - my $specific=&mt("Correctness determined from response with clicker ID"); + my $specific=&mt("Correctness determined from response with clicker ID(s)"); my $pcorrect=&mt("Percentage points for correct solution"); my $pincorrect=&mt("Percentage points for incorrect solution"); - my $selectform=&Apache::loncommon::select_form('iclicker','upfiletype', - ('iclicker' => 'i>clicker')); - + my $selectform=&Apache::loncommon::select_form($env{'form.upfiletype'},'upfiletype', + ('iclicker' => 'i>clicker', + 'interwrite' => 'interwrite PRS')); + $symb = &Apache::lonenc::check_encrypt($symb); $result.=< function sanitycheck() { @@ -6249,13 +6261,13 @@ function sanitycheck() {
-
-
-
- - -
-
+
+
+
+ + +
+

ENDUPFORM @@ -6269,59 +6281,137 @@ sub process_clicker_file { my ($r)=@_; my ($symb)=&get_symb($r); if (!$symb) {return '';} + + my %Saveable_Parameters=&clicker_grading_parameters(); + &Apache::loncommon::store_course_settings('grades_clicker', + \%Saveable_Parameters); + my ($result) = &showResourceInfo($symb,$env{'form.probTitle'}); if (($env{'form.gradingmechanism'} eq 'specific') && ($env{'form.specificid'}!~/\w/)) { - $result.=''.&mt('You need to specify a clicker ID for the correct answer').''; - return $result.&show_grading_menu_form($symb); + $result.=''.&mt('You need to specify a clicker ID for the correct answer').''; + return $result.&show_grading_menu_form($symb); } - my %clickerids=&gather_clicker_ids(); - my %correctids=(); + my %clicker_ids=&gather_clicker_ids(); + my %correct_ids; if ($env{'form.gradingmechanism'} eq 'personnel') { - %correctids=&gather_adv_clicker_ids(); + %correct_ids=&gather_adv_clicker_ids(); } if ($env{'form.gradingmechanism'} eq 'specific') { - my $correctid=$env{'form.specificid'}; - $correctid=~tr/a-z/A-Z/; - $correctid=~s/\s//gs; - $correctid=~s/^0+//; - $correctids{$correctid}='specified'; + foreach my $correct_id (split(/[\s\,]/,$env{'form.specificid'})) {; + $correct_id=~tr/a-z/A-Z/; + $correct_id=~s/\s//gs; + $correct_id=~s/^[\#0]+//; + if ($correct_id) { + $correct_ids{$correct_id}='specified'; + } + } } if ($env{'form.gradingmechanism'} eq 'attendance') { - $result.=&mt('Score based on attendance only'); + $result.=&mt('Score based on attendance only'); } else { - my $number=0; - $result.='

'.&mt('Correctness determined by the following IDs').'

'; - foreach my $id (sort(keys(%correctids))) { - $result.=''.$id.' - '; - if ($correctids{$id} eq 'specified') { - $result.=&mt('specified'); - } else { - my ($uname,$udom)=split(/\:/,$correctids{$id}); - $result.=&Apache::loncommon::plainname($uname,$udom); - } - $result.='
'; - $number++; - } - if ($number==0) { - $result.=''.&mt('No IDs found to determine correct answer').''; - return $result.&show_grading_menu_form($symb); - } + my $number=0; + $result.='

'.&mt('Correctness determined by the following IDs').''; + foreach my $id (sort(keys(%correct_ids))) { + $result.='
'.$id.' - '; + if ($correct_ids{$id} eq 'specified') { + $result.=&mt('specified'); + } else { + my ($uname,$udom)=split(/\:/,$correct_ids{$id}); + $result.=&Apache::loncommon::plainname($uname,$udom); + } + $number++; + } + $result.="

\n"; + if ($number==0) { + $result.=''.&mt('No IDs found to determine correct answer').''; + return $result.&show_grading_menu_form($symb); + } } if (length($env{'form.upfile'}) < 2) { - $result.="Error: The file you attempted to upload, ".&HTML::Entities::encode($env{'form.upfile.filename'},'<>&"').", contained no information. Please check that you entered the correct filename."; + $result.=&mt('[_1] Error: [_2] The file you attempted to upload, [_3] contained no information. Please check that you entered the correct filename.', + '', + '', + ''.&HTML::Entities::encode($env{'form.upfile.filename'},'<>&"').''); return $result.&show_grading_menu_form($symb); } - my %responses=(); - my @questiontitles=(); + +# Were able to get all the info needed, now analyze the file + + $result.=&Apache::loncommon::studentbrowser_javascript(); + $symb = &Apache::lonenc::check_encrypt($symb); + my $heading=&mt('Scanning clicker file'); + $result.=(<
+
+$heading
+
+ + + + + + + +ENDHEADER + my %responses; + my @questiontitles; my $errormsg=''; my $number=0; if ($env{'form.upfiletype'} eq 'iclicker') { - ($errormsg,$number)=&iclicker_eval(\@questiontitles,\%responses); + ($errormsg,$number)=&iclicker_eval(\@questiontitles,\%responses); + } + if ($env{'form.upfiletype'} eq 'interwrite') { + ($errormsg,$number)=&interwrite_eval(\@questiontitles,\%responses); + } + $result.='
'.&mt('Found [_1] question(s)',$number).'
'. + ''. + &mt('Awarding [_1] percent for correct and [_2] percent for incorrect responses', + $env{'form.pcorrect'},$env{'form.pincorrect'}). + '
'; +# Remember Question Titles +# FIXME: Possibly need delimiter other than ":" + for (my $i=0;$i<$number;$i++) { + $result.='').'" />'; + } + my $correct_count=0; + my $student_count=0; + my $unknown_count=0; +# Match answers with usernames +# FIXME: Possibly need delimiter other than ":" + foreach my $id (keys(%responses)) { + if ($correct_ids{$id}) { + $result.="\n".''; + $correct_count++; + } elsif ($clicker_ids{$id}) { + $result.="\n".''; + $student_count++; + } else { + $result.="\n
".&mt('Unregistered Clicker')." ".$id."
"; + $result.="\n".''. + "\n".&mt("Username").":  ". + "\n".&mt("Domain").": ". + &Apache::loncommon::select_dom_form($env{'course.'.$env{'request.course.id'}.'.domain'},'udom'.$id).' '. + &Apache::loncommon::selectstudent_link('clickeranalysis','uname'.$id,'udom'.$id); + $unknown_count++; + } } - $result.='
'.&mt('Found [_1] questions',$number).'
'; - foreach my $id (keys %responses) { - $result.='
'.$id.' - '.$responses{$id}; + $result.='
'. + &mt('Found [_1] registered and [_2] unregistered clickers.',$student_count,$unknown_count); + if ($env{'form.gradingmechanism'} ne 'attendance') { + if ($correct_count==0) { + $errormsg.="Found no correct answers answers for grading!"; + } elsif ($correct_count>1) { + $result.='
'.&mt("Found [_1] entries for grading!",$correct_count).''; + } + } + if ($errormsg) { + $result.='
'.&mt($errormsg).''; + } else { + $result.='
'; } + $result.='
'."\n". + '


'."\n"; return $result.&show_grading_menu_form($symb); } @@ -6330,32 +6420,146 @@ sub iclicker_eval { my $number=0; my $errormsg=''; foreach my $line (split(/[\n\r]/,$env{'form.upfile'})) { - chomp($line); - foreach my $quoted ($line=~/\,\s*\"([^\"]*)\"\s*\,/g) { - my $replace=$quoted; - $replace=~s/\,//g; - &Apache::lonnet::logthis($quoted.' - '.$replace.'
'); - $line=~s/\,\s*\"\Q$quoted\E\"\s*\,/,$replace,/gs; + my %components=&Apache::loncommon::record_sep($line); + my @entries=map {$components{$_}} (sort(keys(%components))); + if ($entries[0] eq 'Question') { + for (my $i=3;$i<$#entries;$i+=6) { + $$questiontitles[$number]=$entries[$i]; + $number++; + } + } + if ($entries[0]=~/^\#/) { + my $id=$entries[0]; + my @idresponses; + $id=~s/^[\#0]+//; + for (my $i=0;$i<$number;$i++) { + my $idx=3+$i*6; + push(@idresponses,$entries[$idx]); + } + $$responses{$id}=join(',',@idresponses); + } + } + return ($errormsg,$number); +} + +sub interwrite_eval { + my ($questiontitles,$responses)=@_; + my $number=0; + my $errormsg=''; + foreach my $line (split(/[\n\r]/,$env{'form.upfile'})) { + my %components=&Apache::loncommon::record_sep($line); + my @entries=map {$components{$_}} (sort(keys(%components))); + if ($entries[0] eq 'Question') { + for (my $i=3;$i<$#entries;$i+=6) { + $$questiontitles[$number]=$entries[$i]; + $number++; + } + } + if ($entries[0]=~/^\#/) { + my $id=$entries[0]; + my @idresponses; + $id=~s/^[\#0]+//; + for (my $i=0;$i<$number;$i++) { + my $idx=3+$i*6; + push(@idresponses,$entries[$idx]); + } + $$responses{$id}=join(',',@idresponses); + } + } + return ($errormsg,$number); +} + +sub assign_clicker_grades { + my ($r)=@_; + my ($symb)=&get_symb($r); + if (!$symb) {return '';} +# See which part we are saving to + my ($partlist,$handgrade,$responseType) = &response_type($symb); +# FIXME: This should probably look for the first handgradeable part + my $part=$$partlist[0]; +# Start screen output + my ($result) = &showResourceInfo($symb,$env{'form.probTitle'}); + + my $heading=&mt('Assigning grades based on clicker file'); + $result.=(<
+
+$heading
+ENDHEADER +# Get correct result +# FIXME: Possibly need delimiter other than ":" + my @correct=(); + my $gradingmechanism=$env{'form.gradingmechanism'}; + my $number=$env{'form.number'}; + if ($gradingmechanism ne 'attendance') { + foreach my $key (keys(%env)) { + if ($key=~/^form\.correct\:/) { + my @input=split(/\,/,$env{$key}); + for (my $i=0;$i<=$#input;$i++) { + if (($correct[$i]) && ($input[$i]) && + ($correct[$i] ne $input[$i])) { + $result.='
'. + &mt('More than one correct result given for question "[_1]": [_2] versus [_3].', + $env{'form.question:'.$i},$correct[$i],$input[$i]).''; + } elsif ($input[$i]) { + $correct[$i]=$input[$i]; + } + } + } } - my @entries=split(/\,/,$line); - if ($entries[0] eq 'Question') { - for (my $i=3;$i<$#entries;$i+=6) { - $$questiontitles[$number]=$entries[$i]; - $number++; + for (my $i=0;$i<$number;$i++) { + if (!$correct[$i]) { + $result.='
'. + &mt('No correct result given for question "[_1]"!', + $env{'form.question:'.$i}).''; } } - if ($entries[0]=~/^\#/) { - my $id=$entries[0]; - my @idresponses=(); - $id=~s/^[\#0]+//; + $result.='
'.&mt("Correct answer: [_1]",join(', ',map { ($_?$_:'-') } @correct)); + } +# Start grading + my $pcorrect=$env{'form.pcorrect'}; + my $pincorrect=$env{'form.pincorrect'}; + my $storecount=0; + foreach my $key (keys(%env)) { + if ($key=~/^form\.student\:(.*)$/) { + my $user=$1; + my @answer=split(/\,/,$env{$key}); + my $sum=0; for (my $i=0;$i<$number;$i++) { - my $idx=3+$i*6; - push(@idresponses,$entries[$idx]); + if ($answer[$i]) { + if ($gradingmechanism eq 'attendance') { + $sum+=$pcorrect; + } else { + if ($answer[$i] eq $correct[$i]) { + $sum+=$pcorrect; + } else { + $sum+=$pincorrect; + } + } + } + } + my $ave=$sum/(100*$number); +# Store + my ($username,$domain)=split(/\:/,$user); + my %grades=(); + $grades{"resource.$part.solved"}='correct_by_override'; + $grades{"resource.$part.awarded"}=$ave; + $grades{"resource.regrader"}="$env{'user.name'}:$env{'user.domain'}"; + my $returncode=&Apache::lonnet::cstore(\%grades,$symb, + $env{'request.course.id'}, + $domain,$username); + if ($returncode ne 'ok') { + $result.="
Failed to save student $username:$domain. Message when trying to save was ($returncode)"; + } else { + $storecount++; } - $$responses{$id}=join(',',@idresponses); } } - return ($errormsg,$number); +# We are done + $result.='
'.&mt('Successfully stored grades for [_1] student(s).',$storecount). + '
'."\n". + '


'."\n"; + return $result.&show_grading_menu_form($symb); } sub handler { @@ -6429,6 +6633,8 @@ sub handler { $request->print(&process_clicker($request)); } elsif ($command eq 'processclickerfile' && $perm{'mgr'}) { $request->print(&process_clicker_file($request)); + } elsif ($command eq 'assignclickergrades' && $perm{'mgr'}) { + $request->print(&assign_clicker_grades($request)); } elsif ($command eq 'csvform' && $perm{'mgr'}) { $request->print(&upcsvScores_form($request)); } elsif ($command eq 'csvupload' && $perm{'mgr'}) {