--- loncom/homework/grades.pm 2011/10/09 15:31:12 1.655 +++ loncom/homework/grades.pm 2012/10/02 18:03:07 1.675 @@ -1,7 +1,7 @@ # The LearningOnline Network with CAPA # The LON-CAPA Grading handler # -# $Id: grades.pm,v 1.655 2011/10/09 15:31:12 raeburn Exp $ +# $Id: grades.pm,v 1.675 2012/10/02 18:03:07 bisitz Exp $ # # Copyright Michigan State University Board of Trustees # @@ -45,6 +45,7 @@ use Apache::lonlocal; use Apache::lonenc; use Apache::lonstathelpers; use Apache::lonquickgrades; +use Apache::bridgetask(); use String::Similarity; use LONCAPA; @@ -53,6 +54,7 @@ use POSIX qw(floor); my %perm=(); +my %old_essays=(); # These variables are used to recover from ssi errors @@ -201,6 +203,7 @@ sub get_display_part { sub reset_caches { &reset_analyze_cache(); &reset_perm(); + &reset_old_essays(); } { @@ -340,7 +343,7 @@ sub cleanRecord { return '
'. ''.$toprow.''. ''. - $grayFont.$bottomrow.''.'
'.&mt('Answer').'
'.$grayFont.&mt('Option ID').'
'; + $bottomrow.''; } elsif ($response eq 'match') { my %answer=&Apache::lonnet::str2hash($answer); my %grading=&Apache::lonnet::str2hash($record->{$version."resource.$partid.$respid.submissiongrading"}); @@ -362,7 +365,7 @@ sub cleanRecord { ''.$grayFont.&mt('Item ID').''. $middlerow.''. ''.$grayFont.&mt('Option ID').''. - $bottomrow.''.''; + $bottomrow.''; } elsif ($response eq 'radiobutton') { my %answer=&Apache::lonnet::str2hash($answer); my ($toprow,$bottomrow); @@ -383,7 +386,7 @@ sub cleanRecord { return '
'. ''.$toprow.''. ''. - $bottomrow.''.'
'.&mt('Answer').'
'.$grayFont.&mt('Option ID').'
'; + $bottomrow.''; } elsif ($response eq 'essay') { if (! exists ($env{'form.'.$symb})) { my (%keyhash) = &Apache::lonnet::dump('nohist_handgrade', @@ -680,7 +683,11 @@ sub compute_points { # sub most_similar { - my ($uname,$udom,$uessay,$old_essays)=@_; + my ($uname,$udom,$symb,$uessay)=@_; + + unless ($symb) { return ''; } + + unless (ref($old_essays{$symb}) eq 'HASH') { return ''; } # ignore spaces and punctuation @@ -697,11 +704,11 @@ sub most_similar { my $scrsid=''; my $sessay=''; # go through all essays ... - foreach my $tkey (keys(%$old_essays)) { + foreach my $tkey (keys(%{$old_essays{$symb}})) { my ($tname,$tdom,$tcrsid)=map {&unescape($_)} (split(/\./,$tkey)); # ... except the same student next if (($tname eq $uname) && ($tdom eq $udom)); - my $tessay=$old_essays->{$tkey}; + my $tessay=$old_essays{$symb}{$tkey}; $tessay=~s/\W+/ /gs; # String similarity gives up if not even limit my $tsimilar=&String::Similarity::similarity($uessay,$tessay,$limit); @@ -711,7 +718,7 @@ sub most_similar { $sname=$tname; $sdom=$tdom; $scrsid=$tcrsid; - $sessay=$old_essays->{$tkey}; + $sessay=$old_essays{$symb}{$tkey}; } } if ($limit>0.6) { @@ -1414,6 +1421,7 @@ INNERJS adds => 'Add selection to keyword list? Edit if desired.', comp => 'Compose Message for: ', incl => 'Include', + type => 'Type', subj => 'Subject', mesa => 'Message', new => 'New', @@ -1422,6 +1430,7 @@ INNERJS kehi => 'Keyword Highlight Options', txtc => 'Text Color', font => 'Font Size', + fnst => 'Font Style', ); $request->print(&Apache::lonhtmlcommon::scripttag(< 600) { height = 600; - scrollbar = "yes"; } var xpos = (screen.width-600)/2; xpos = (xpos < 0) ? '0' : xpos; var ypos = (screen.height-height)/2-30; ypos = (ypos < 0) ? '0' : ypos; - pWin = window.open('', 'MessageCenter', 'resizable=yes,toolbar=no,location=no,scrollbars='+scrollbar+',screenx='+xpos+',screeny='+ypos+',width=700,height='+height); + pWin = window.open('', 'MessageCenter', 'resizable=yes,toolbar=no,location=no,scrollbars=yes,screenx='+xpos+',screeny='+ypos+',width=700,height='+height); pWin.focus(); pDoc = pWin.document; pDoc.$docopen; @@ -1543,7 +1550,7 @@ INNERJS pDoc.write('
'); pDoc.write(''); - pDoc.write("
Type<\\/b><\\/td>$lt{'incl'}<\\/b><\\/td>$lt{'mesa'}<\\/td><\\/tr>"); + pDoc.write("$lt{'type'}<\\/b><\\/td>$lt{'incl'}<\\/b><\\/td>$lt{'mesa'}<\\/td><\\/tr>"); } function displaySubject(msg,shwsel) { pDoc = pWin.document; @@ -1628,7 +1635,7 @@ INNERJS hDoc.write(''. &Apache::loncommon::end_data_table_header_row()."\n". &Apache::loncommon::start_data_table_row(). - ''. - ''. + ''. + ''. &Apache::loncommon::end_data_table_row(). &Apache::loncommon::start_data_table_row(). - ''. - ''."\n". + ''. + ''."\n". &Apache::loncommon::end_data_table_row(). &Apache::loncommon::end_data_table().'

'); } else { @@ -7874,7 +8151,8 @@ sub graders_resources_pass { my $ressymb = $resource->symb(); my ($analysis,$parts) = &scantron_partids_tograde($resource,$env{'request.course.id'}, - $env{'user.name'},$env{'user.domain'},1,$bubbles_per_row); + $env{'user.name'},$env{'user.domain'}, + 1,$bubbles_per_row); $grader_partids_by_symb->{$ressymb} = $parts; if (ref($analysis) eq 'HASH') { if (ref($analysis->{'parts_withrandomlist'}) eq 'ARRAY') { @@ -7905,6 +8183,9 @@ sub grade_student_bubbles { if ($bubbles_per_row ne '') { $form{'bubbles_per_row'} = $bubbles_per_row; } + if ($env{'form.scantron_lastbubblepoints'} ne '') { + $form{'scantron_lastbubblepoints'} = $env{'form.scantron_lastbubblepoints'}; + } if (ref($parts) eq 'HASH') { if (ref($parts->{$ressymb}) eq 'ARRAY') { foreach my $part (@{$parts->{$ressymb}}) { @@ -8192,7 +8473,8 @@ sub checkscantron_results { my $map=$navmap->getResourceByUrl($sequence); my @resources=$navmap->retrieveResources($map,\&scantron_filter,1,0); my (%grader_partids_by_symb,%grader_randomlists_by_symb); - &graders_resources_pass(\@resources,\%grader_partids_by_symb, \%grader_randomlists_by_symb); + &graders_resources_pass(\@resources,\%grader_partids_by_symb, + \%grader_randomlists_by_symb,$bubbles_per_row); my ($uname,$udom); my (%scandata,%lastname,%bylast); @@ -8203,9 +8485,7 @@ sub checkscantron_results { my %completedstudents; my $count=&Apache::grades::get_todo_count($scanlines,$scan_data); - my %prog_state=&Apache::lonhtmlcommon::Create_PrgWin($r,'Bubblesheet/Submissions Comparison Status', - 'Progress of Bubblesheet Data/Submission Records Comparison',$count, - 'inline',undef,'checkscantron'); + my %prog_state=&Apache::lonhtmlcommon::Create_PrgWin($r,$count); my ($username,$domain,$started); my $nav_error; &scantron_get_maxbubble(\$nav_error,\%scantron_config); # Need the bubble lines array to parse. @@ -8214,8 +8494,7 @@ sub checkscantron_results { return ''; } - &Apache::lonhtmlcommon::Update_PrgWin($r,\%prog_state, - 'Processing first student'); + &Apache::lonhtmlcommon::Update_PrgWin($r,\%prog_state,'Processing first student'); my $start=&Time::HiRes::time(); my $i=-1; @@ -8225,8 +8504,7 @@ sub checkscantron_results { my $line=&Apache::grades::scantron_get_line($scanlines,$scan_data,$i); if ($line=~/^[\s\cz]*$/) { next; } if ($started) { - &Apache::lonhtmlcommon::Increment_PrgWin($r,\%prog_state, - 'last student'); + &Apache::lonhtmlcommon::Increment_PrgWin($r,\%prog_state,'last student'); } $started=1; my $scan_record= @@ -8258,7 +8536,9 @@ sub checkscantron_results { if ((exists($grader_randomlists_by_symb{$ressymb})) || (ref($grader_partids_by_symb{$ressymb}) ne 'ARRAY')) { (my $analysis,$parts) = - &scantron_partids_tograde($resource,$env{'request.course.id'},$username,$domain,undef,$bubbles_per_row); + &scantron_partids_tograde($resource,$env{'request.course.id'}, + $username,$domain,undef, + $bubbles_per_row); } else { $parts = $grader_partids_by_symb{$ressymb}; } @@ -8478,7 +8758,7 @@ sub letter_to_digits { sub href_symb_cmd { my ($symb,$cmd)=@_; - return '/adm/grades?symb='.&HTML::Entities::encode(&Apache::lonenc::check_encrypt($symb),'<>&"').'&command='.$cmd; + return '/adm/grades?symb='.&HTML::Entities::encode(&Apache::lonenc::check_encrypt($symb),'<>&"').'&command='.$cmd; } sub grading_menu { @@ -8741,6 +9021,21 @@ sub init_perm { } } +sub init_old_essays { + my ($symb,$apath,$adom,$aname) = @_; + if ($symb ne '') { + my %essays = &Apache::lonnet::dump('nohist_essay_'.$apath,$adom,$aname); + if (keys(%essays) > 0) { + $old_essays{$symb} = \%essays; + } + } + return; +} + +sub reset_old_essays { + undef(%old_essays); +} + sub gather_clicker_ids { my %clicker_ids; @@ -8838,7 +9133,8 @@ sub process_clicker { my $pincorrect=&mt("Percentage points for incorrect solution"); my $selectform=&Apache::loncommon::select_form($env{'form.upfiletype'},'upfiletype', {'iclicker' => 'i>clicker', - 'interwrite' => 'interwrite PRS'}); + 'interwrite' => 'interwrite PRS', + 'turning' => 'Turning Technologies'}); $symb = &Apache::lonenc::check_encrypt($symb); $result.= &Apache::lonhtmlcommon::scripttag(<'. ''. &mt('Awarding [_1] percent for correct and [_2] percent for incorrect responses', @@ -9148,6 +9447,32 @@ sub interwrite_eval { return ($errormsg,$number); } +sub turning_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>$number) { $number=$#entries; } + my $id=$entries[0]; + my @idresponses; + $id=~s/^[\#0]+//; + unless ($id) { next; } + for (my $idx=1;$idx<=$#entries;$idx++) { + $entries[$idx]=~s/\,/\;/g; + $entries[$idx]=~s/[^a-zA-Z0-9\.\*\-\+\;]+//g; + push(@idresponses,$entries[$idx]); + } + $$responses{$id}=join(',',@idresponses); + } + for (my $i=1; $i<=$number; $i++) { + $$questiontitles[$i]=&mt('Question [_1]',$i); + } + return ($errormsg,$number); +} + + sub assign_clicker_grades { my ($r,$symb)=@_; if (!$symb) {return '';} @@ -9285,13 +9610,17 @@ sub navmap_errormsg { } sub startpage { - my ($r,$symb,$crumbs,$onlyfolderflag,$nodisplayflag) = @_; - unshift(@$crumbs,{href=>&href_symb_cmd($symb,'gradingmenu'),text=>"Grading"}); - $r->print(&Apache::loncommon::start_page('Grading',undef, - {'bread_crumbs' => $crumbs})); - &Apache::lonquickgrades::startGradeScreen($r,($env{'form.symb'}?'probgrading':'grading')); + my ($r,$symb,$crumbs,$onlyfolderflag,$nodisplayflag,$stuvcurrent,$stuvdisp,$nomenu,$js) = @_; + if ($nomenu) { + $r->print(&Apache::loncommon::start_page("Student's Version",$js,{'only_body' => '1'})); + } else { + unshift(@$crumbs,{href=>&href_symb_cmd($symb,'gradingmenu'),text=>"Grading"}); + $r->print(&Apache::loncommon::start_page('Grading',$js, + {'bread_crumbs' => $crumbs})); + &Apache::lonquickgrades::startGradeScreen($r,($env{'form.symb'}?'probgrading':'grading')); + } unless ($nodisplayflag) { - $r->print(&Apache::lonhtmlcommon::resource_info_box($symb,$onlyfolderflag)); + $r->print(&Apache::lonhtmlcommon::resource_info_box($symb,$onlyfolderflag,$stuvcurrent,$stuvdisp)); } } @@ -9313,23 +9642,25 @@ sub handler { } &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'}); +# see what command we need to execute + + my @commands=&Apache::loncommon::get_env_multiple('form.command'); + my $command=$commands[0]; + &init_perm(); if (!$env{'request.course.id'}) { - # Not in a course. - $env{'user.error.msg'}="/adm/grades::vgr:0:0:Cannot display grades page outside course context"; - return HTTP_NOT_ACCEPTABLE; + unless ((&Apache::lonnet::allowed('usc',$env{'request.role.domain'})) && + ($command =~ /^scantronupload/)) { + # Not in a course. + $env{'user.error.msg'}="/adm/grades::vgr:0:0:Cannot display grades page outside course context"; + return HTTP_NOT_ACCEPTABLE; + } } elsif (!%perm) { $request->internal_redirect('/adm/quickgrades'); } &Apache::loncommon::content_type($request,'text/html'); $request->send_http_header; - -# see what command we need to execute - - my @commands=&Apache::loncommon::get_env_multiple('form.command'); - my $command=$commands[0]; - if ($#commands > 0) { &Apache::lonnet::logthis("grades got multiple commands ".join(':',@commands)); } @@ -9352,8 +9683,29 @@ sub handler { &select_problem($request); } else { if ($command eq 'submission' && $perm{'vgr'}) { - &startpage($request,$symb,[{href=>"", text=>"Student Submissions"}]); + my ($stuvcurrent,$stuvdisp,$versionform,$js); + if (($env{'form.student'} ne '') && ($env{'form.userdom'} ne '')) { + ($stuvcurrent,$stuvdisp,$versionform,$js) = + &choose_task_version_form($symb,$env{'form.student'}, + $env{'form.userdom'}); + } + &startpage($request,$symb,[{href=>"", text=>"Student Submissions"}],undef,undef,$stuvcurrent,$stuvdisp,undef,$js); + if ($versionform) { + $request->print($versionform); + } + $request->print('
'); ($env{'form.student'} eq '' ? &listStudents($request,$symb) : &submission($request,0,0,$symb)); + } elsif ($command eq 'versionsub' && $perm{'vgr'}) { + my ($stuvcurrent,$stuvdisp,$versionform,$js) = + &choose_task_version_form($symb,$env{'form.student'}, + $env{'form.userdom'}, + $env{'form.inhibitmenu'}); + &startpage($request,$symb,[{href=>"", text=>"Previous Student Version"}],undef,undef,$stuvcurrent,$stuvdisp,$env{'form.inhibitmenu'},$js); + if ($versionform) { + $request->print($versionform); + } + $request->print('
'); + $request->print(&show_previous_task_version($request,$symb)); } elsif ($command eq 'pickStudentPage' && $perm{'vgr'}) { &startpage($request,$symb,[{href=>&href_symb_cmd($symb,'all_for_one'),text=>'Grade page/folder for one student'}, {href=>'',text=>'Select student'}],1,1); @@ -9491,8 +9843,11 @@ sub handler { if ($ssi_error) { &ssi_print_error($request); } - &Apache::lonquickgrades::endGradeScreen($request); - $request->print(&Apache::loncommon::end_page()); + if ($env{'form.inhibitmenu'}) { + $request->print(&Apache::loncommon::end_page()); + } else { + &Apache::lonquickgrades::endGradeScreen($request); + } &reset_caches(); return OK; } @@ -9563,6 +9918,75 @@ ssi_with_retries() =over +=head1 Routines to display previous version of a Task for a specific student + +Tasks are graded pass/fail. Students who have yet to pass a particular Task +can receive another opportunity. Access to tasks is slot-based. If a slot +requires a proctor to check-in the student, a new version of the Task will +be created when the student is checked in to the new opportunity. + +If a particular student has tried two or more versions of a particular task, +the submission screen provides a user with vgr privileges (e.g., a Course +Coordinator) the ability to display a previous version worked on by the +student. By default, the current version is displayed. If a previous version +has been selected for display, submission data are only shown that pertain +to that particular version, and the interface to submit grades is not shown. + +=over 4 + +=item show_previous_task_version() + +Displays a specified version of a student's Task, as the student sees it. + +Inputs: 2 + request - request object + symb - unique symb for current instance of resource + +Output: None. + +Side Effects: calls &show_problem() to print version of Task, with + version contained in form item: $env{'form.previousversion'} + +=item choose_task_version_form() + +Displays a web form used to select which version of a student's view of a +Task should be displayed. Either launches a pop-up window, or replaces +content in existing pop-up, or replaces page in main window. + +Inputs: 4 + symb - unique symb for current instance of resource + uname - username of student + udom - domain of student + nomenu - 1 if display is in a pop-up window, and hence no menu + breadcrumbs etc., are displayed + +Output: 4 + current - student's current version + displayed - student's version being displayed + result - scalar containing HTML for web form used to switch to + a different version (or a link to close window, if pop-up). + js - javascript for processing selection in versions web form + +Side Effects: None. + +=item previous_display_javascript() + +Inputs: 2 + nomenu - 1 if display is in a pop-up window, and hence no menu + breadcrumbs etc., are displayed. + current - student's current version number. + +Output: 1 + js - javascript for processing selection in versions web form. + +Side Effects: None. + +=back + +=head1 Routines to process bubblesheet data. + +=over 4 + =item scantron_get_correction() : Builds the interface screen to interact with the operator to fix a @@ -9623,7 +10047,7 @@ ssi_with_retries() =item scantron_process_students() : - Routine that does the actual grading of the bubble sheet information. + Routine that does the actual grading of the bubblesheet information. The parsed scanline hash is added to %env @@ -9643,7 +10067,7 @@ ssi_with_retries() =item scantron_upload_scantron_data() : - Creates the screen for adding a new bubble sheet data file to a course. + Creates the screen for adding a new bubblesheet data file to a course. =item scantron_upload_scantron_data_save() : @@ -9657,7 +10081,7 @@ ssi_with_retries() =item scantron_download_scantron_data() : Shows a list of the three internal files (original, corrected, - skipped) for a specific bubble sheet data file that exists in the + skipped) for a specific bubblesheet data file that exists in the course. =item scantron_validate_ID() : @@ -9668,7 +10092,9 @@ ssi_with_retries() =item navmap_errormsg() : Returns HTML mark-up inside a
with a link to re-initialize the course. - Should be called whenever the request to instantiate a navmap object fails. + Should be called whenever the request to instantiate a navmap object fails. + +=back =back
'); hDoc.write(''); - hDoc.write("'. + ''. + &Apache::loncommon::end_data_table_row(); + unless ($nomenu) { + $result .= &Apache::loncommon::start_data_table_row(). + ''. + ''. + &Apache::loncommon::end_data_table_row(); + } + $result .= + &Apache::loncommon::start_data_table_row(). + ''. + ''. + &Apache::loncommon::end_data_table_row(). + &Apache::loncommon::end_data_table(). + ''; + $js = &previous_display_javascript($nomenu,$current); + } elsif ($displayed && $nomenu) { + $result .= ''.&mt('Close window').''; + } else { + $result .= &mt('No previous versions to show for this student'); + } + $result .= ''; + } + return ($current,$displayed,$result,$js); +} + +sub previous_display_javascript { + my ($nomenu,$current) = @_; + my $js = <<"JSONE"; + +ENDJS + +} + #--- Called from submission routine sub processHandGrade { my ($request,$symb) = @_; @@ -2902,8 +3098,10 @@ sub handback_files { &file_name_version_ext($answer_file); my ($portfolio_path) = ($directory =~ /^.+$stuname\/portfolio(.*)/); my $getpropath = 1; - my @dir_list = &Apache::lonnet::dirlist($portfolio_root.$portfolio_path,$domain,$stuname,$getpropath); - my $version = &get_next_version($answer_name, $answer_ext, \@dir_list); + my ($dir_list,$listerror) = + &Apache::lonnet::dirlist($portfolio_root.$portfolio_path, + $domain,$stuname,$getpropath); + my $version = &get_next_version($answer_name,$answer_ext,$dir_list); # fix file name my ($save_file_name) = (($directory.$answer_name.".$version.".$answer_ext) =~ /^.+\/${stuname}\/(.*)/); my $result=&Apache::lonnet::finishuserfileupload($stuname,$domain, @@ -3064,8 +3262,10 @@ sub version_portfiles { my ($answer_name,$answer_ver,$answer_ext) = &file_name_version_ext($answer_file); my $getpropath = 1; - my @dir_list = &Apache::lonnet::dirlist($portfolio_root.$directory,$domain,$stu_name,$getpropath); - my $version = &get_next_version($answer_name, $answer_ext, \@dir_list); + my ($dir_list,$listerror) = + &Apache::lonnet::dirlist($portfolio_root.$directory,$domain, + $stu_name,$getpropath); + my $version = &get_next_version($answer_name,$answer_ext,$dir_list); my $new_answer = &version_selected_portfile($domain, $stu_name, $directory, $answer_file, $version); if ($new_answer ne 'problem getting file') { push(@versioned_portfiles, $directory.$new_answer); @@ -3084,21 +3284,24 @@ sub version_portfiles { sub get_next_version { my ($answer_name, $answer_ext, $dir_list) = @_; my $version; - foreach my $row (@$dir_list) { - my ($file) = split(/\&/,$row,2); - my ($file_name,$file_version,$file_ext) = - &file_name_version_ext($file); - if (($file_name eq $answer_name) && - ($file_ext eq $answer_ext)) { - # gets here if filename and extension match, regardless of version + if (ref($dir_list) eq 'ARRAY') { + foreach my $row (@{$dir_list}) { + my ($file) = split(/\&/,$row,2); + my ($file_name,$file_version,$file_ext) = + &file_name_version_ext($file); + if (($file_name eq $answer_name) && + ($file_ext eq $answer_ext)) { + # gets here if filename and extension match, + # regardless of version if ($file_version ne '') { - # a versioned file is found so save it for later - if ($file_version > $version) { - $version = $file_version; - } + # a versioned file is found so save it for later + if ($file_version > $version) { + $version = $file_version; + } + } } } - } + } $version ++; return($version); } @@ -4087,6 +4290,7 @@ sub csvuploadassign { my ($classlist) = &getclasslist('all',0); my @notallowed; my @skipped; + my @warnings; my $countdone=0; foreach my $grade (@gradedata) { my %entries=&Apache::loncommon::record_sep($grade); @@ -4136,7 +4340,7 @@ sub csvuploadassign { my $award=($pcr == 0) ? 'incorrect_by_override' : 'correct_by_override'; if ($pcr>1) { - push(@skipped,&mt("[_1]: point value larger than weight","$username:$domain")); + push(@warnings,&mt("[_1]: point value larger than weight","$username:$domain")); } $grades{"resource.$part.awarded"}=$pcr; $grades{"resource.$part.solved"}=$award; @@ -4182,6 +4386,10 @@ sub csvuploadassign { } } $request->print('
'.&Apache::lonhtmlcommon::confirm_success(&mt("Saved scores for [quant,_1,student]",$countdone),$countdone==0)); + if (@warnings) { + $request->print('
'.&Apache::lonhtmlcommon::confirm_success(&mt('Warnings generated for the following saved scores:'),1).'
'); + $request->print(join(', ',@warnings)); + } if (@skipped) { $request->print('
'.&Apache::lonhtmlcommon::confirm_success(&mt('No scores stored for the following username(s):'),1).'
'); $request->print(join(', ',@skipped)); @@ -4525,6 +4733,7 @@ sub displaySubByDates { &Apache::loncommon::start_data_table_header_row(). ''. ($isCODE?'':''). + ($isTask?'':''). ''. ''. &Apache::loncommon::end_data_table_header_row(); @@ -4545,7 +4754,9 @@ sub displaySubByDates { if (exists($$record{$version.':resource.0.version'})) { $interaction = $$record{$version.':resource.0.version'}; } - + if ($isTask && $env{'form.previousversion'}) { + next unless ($interaction == $env{'form.previousversion'}); + } my $where = ($isTask ? "$version:resource.$interaction" : "$version:resource"); $studentTable.=&Apache::loncommon::start_data_table_row(). @@ -4553,6 +4764,9 @@ sub displaySubByDates { if ($isCODE) { $studentTable.=''; } + if ($isTask) { + $studentTable.=''; + } my @versionKeys = split(/\:/,$$record{$version.':keys'}); my @displaySub = (); foreach my $partid (@{$parts}) { @@ -4572,7 +4786,7 @@ sub displaySubByDates { my ($responseId)= ($isTask ? ($matchKey=~ /^resource\.(.*?)\.\Q$partid\E\.award$/) : ($matchKey=~ /^resource\.\Q$partid\E\.(.*?)\.submission$/)); - $displaySub[0].='' .' ' .'('.&mt('Response ID: [_1]',$responseId).')' @@ -4829,12 +5043,12 @@ sub updateGradeByPage { from the file that we are parsing that represents one entire sheet 'bubble line' refers to the data - representing the line of bubbles that are on the physical bubble sheet + representing the line of bubbles that are on the physical bubblesheet -The overall process is that a scanned in bubble sheet data is uploaded +The overall process is that a scanned in bubblesheet data is uploaded into a course. When a user wants to grade, they select a -sequence/folder of resources, a file of bubble sheet info, and pick +sequence/folder of resources, a file of bubblesheet info, and pick one of the predefined configurations for what each scanline looks like. @@ -4850,14 +5064,14 @@ username:domain. During the validation phase the instructor can choose to skip scanlines. -After the validation phase, there are now 3 bubble sheet files +After the validation phase, there are now 3 bubblesheet files scantron_original_filename (unmodified original file) scantron_corrected_filename (file where the corrected information has replaced the original information) scantron_skipped_filename (contains the exact text of scanlines that where skipped) Also there is a separate hash nohist_scantrondata that contains extra -correction information that isn't representable in the bubble sheet +correction information that isn't representable in the bubblesheet file (see &scantron_getfile() for more information) After all scanlines are either valid, marked as valid or skipped, then @@ -4991,14 +5205,16 @@ sub scantron_filenames { my $cdom=$env{'course.'.$env{'request.course.id'}.'.domain'}; my $cname=$env{'course.'.$env{'request.course.id'}.'.num'}; my $getpropath = 1; - my @files=&Apache::lonnet::dirlist('userfiles',$cdom,$cname, - $getpropath); + my ($dirlist,$listerror) = &Apache::lonnet::dirlist('userfiles',$cdom, + $cname,$getpropath); my @possiblenames; - foreach my $filename (sort(@files)) { - ($filename)=split(/&/,$filename); - if ($filename!~/^scantron_orig_/) { next ; } - $filename=~s/^scantron_orig_//; - push(@possiblenames,$filename); + if (ref($dirlist) eq 'ARRAY') { + foreach my $filename (sort(@{$dirlist})) { + ($filename)=split(/&/,$filename); + if ($filename!~/^scantron_orig_/) { next ; } + $filename=~s/^scantron_orig_//; + push(@possiblenames,$filename); + } } return @possiblenames; } @@ -5152,7 +5368,7 @@ sub scantron_CODEunique { =item scantron_selectphase - Generates the initial screen to start the bubble sheet process. + Generates the initial screen to start the bubblesheet process. Allows for - starting a grading run. - downloading existing scan data (original, corrected or skipped info) @@ -5395,6 +5611,7 @@ sub scantron_selectphase { LastNameLength - number of columns that the last name spans BubblesPerRow - number of bubbles available in each row used to bubble an answer. (If not specified, 10 assumed). + =cut sub get_scantron_config { @@ -6174,7 +6391,7 @@ sub remember_current_skipped { =item check_for_error Checks if there was an error when attempting to remove a specific - scantron_.. bubble sheet data file. Prints out an error if + scantron_.. bubblesheet data file. Prints out an error if something went wrong. =cut @@ -6209,6 +6426,12 @@ sub scantron_warning_screen { ''; } + my $lastbubblepoints; + if ($env{'form.scantron_lastbubblepoints'} ne '') { + $lastbubblepoints = + ''; + } return ('

@@ -6217,7 +6440,7 @@ sub scantron_warning_screen {

$lt{'txtc'}<\\/b><\\/td>$lt{'font'}<\\/b><\\/td>Font Style<\\/td><\\/tr>"); + hDoc.write("$lt{'txtc'}<\\/b><\\/td>$lt{'font'}<\\/b><\\/td>$lt{'fnst'}<\\/td><\\/tr>"); } function highlightbody(clrval,clrtxt,clrsel,szval,sztxt,szsel,syval,sytxt,sysel) { @@ -1826,14 +1833,27 @@ sub show_problem { $companswer=~s|||g; $companswer=~s|name="submit"|name="would_have_been_submit"|g; } + my $renderheading = &mt('View of the problem'); + my $answerheading = &mt('Correct answer'); + if (($uname ne $env{'user.name'}) || ($udom ne $env{'user.domain'})) { + my $stu_fullname = $env{'form.fullname'}; + if ($stu_fullname eq '') { + $stu_fullname = &Apache::loncommon::plainname($uname,$udom,'lastname'); + } + my $forwhom = &nameUserString(undef,$stu_fullname,$uname,$udom); + if ($forwhom ne '') { + $renderheading = &mt('View of the problem for[_1]',$forwhom); + $answerheading = &mt('Correct answer for[_1]',$forwhom); + } + } $rendered= '
' - .'

'.&mt('View of the problem').'

' + .'

'.$renderheading.'

' .$rendered .'
'; $companswer= '
' - .'

'.&mt('Correct answer').'

' + .'

'.$answerheading.'

' .$companswer .'
'; my $result; @@ -1935,7 +1955,6 @@ sub submission { '" src="'.$request->dir_config('lonIconsURL'). '/check.gif" height="16" border="0" />'; - my %old_essays; # header info if ($counter == 0) { &sub_page_js($request); @@ -2024,7 +2043,7 @@ sub submission { keyw => 'Keyword Options', list => 'List', past => 'Paste Selection to List', - high => 'Hightlight Attribute', + high => 'Highlight Attribute', ); # # Print out the keyword options line @@ -2043,7 +2062,7 @@ KEYWORDS my ($adom,$aname,$apath)=($essayurl=~/^($LONCAPA::domain_re)\/($LONCAPA::username_re)\/(.*)$/); $apath=&escape($apath); $apath=~s/\W/\_/gs; - %old_essays=&Apache::lonnet::dump('nohist_essay_'.$apath,$adom,$aname); + &init_old_essays($symb,$apath,$adom,$aname); } } @@ -2182,7 +2201,7 @@ KEYWORDS } if($env{'form.checkPlag'}){ my ($oname,$odom,$ocrsid,$oessay,$osim)= - &most_similar($uname,$udom,$subval,\%old_essays); + &most_similar($uname,$udom,$symb,$subval); if ($osim) { $osim=int($osim*100.0); my %old_course_desc = @@ -2505,6 +2524,183 @@ sub keywords_highlight { return $string; } +# For Tasks provide a mechanism to display previous version for one specific student + +sub show_previous_task_version { + my ($request,$symb) = @_; + if ($symb eq '') { + $request->print("Unable to handle ambiguous references."); + + return ''; + } + my ($uname,$udom) = ($env{'form.student'},$env{'form.userdom'}); + my $usec = &Apache::lonnet::getsection($udom,$uname,$env{'request.course.id'}); + if (!&canview($usec)) { + $request->print('Unable to view previous version for requested student.('. + $uname.':'.$udom.' in section '.$usec.' in course id '. + $env{'request.course.id'}.')'); + return; + } + my $mode = 'both'; + my $isTask = ($symb =~/\.task$/); + if ($isTask) { + if ($env{'form.previousversion'} =~ /^\d+$/) { + if ($env{'form.fullname'} eq '') { + $env{'form.fullname'} = + &Apache::loncommon::plainname($uname,$udom,'lastname'); + } + my $probtitle=&Apache::lonnet::gettitle($symb); + $request->print("\n\n". + '
'. + '

'.&nameUserString(undef,$env{'form.fullname'},$uname,$udom). + '

'."\n"); + &Apache::lonxml::clear_problem_counter(); + $request->print(&show_problem($request,$symb,$uname,$udom,1,1,$mode, + {'previousversion' => $env{'form.previousversion'} })); + $request->print("\n
"); + } + } + return; +} + +sub choose_task_version_form { + my ($symb,$uname,$udom,$nomenu) = @_; + my $isTask = ($symb =~/\.task$/); + my ($current,$version,$result,$js,$displayed,$rowtitle); + if ($isTask) { + my %record = &Apache::lonnet::restore($symb,$env{'request.course.id'}, + $udom,$uname); + if (($record{'resource.0.version'} eq '') || + ($record{'resource.0.version'} < 2)) { + return ($record{'resource.0.version'}, + $record{'resource.0.version'},$result,$js); + } else { + $current = $record{'resource.0.version'}; + } + if ($env{'form.previousversion'}) { + $displayed = $env{'form.previousversion'}; + $rowtitle = &mt('Choose another version:') + } else { + $displayed = $current; + $rowtitle = &mt('Show earlier version:'); + } + $result = '
'; + my $list; + my $numversions = 0; + for (my $i=1; $i<=$record{'resource.0.version'}; $i++) { + if ($i == $current) { + if (!$env{'form.previousversion'} || $nomenu) { + next; + } else { + $list .= ''."\n"; + $numversions ++; + } + } elsif (defined($record{'resource.'.$i.'.0.status'})) { + unless ($i == $env{'form.previousversion'}) { + $numversions ++; + } + $list .= ''."\n"; + } + } + if ($numversions) { + $symb = &HTML::Entities::encode($symb,'<>"&'); + $result .= + '
'. + &Apache::loncommon::start_data_table(). + &Apache::loncommon::start_data_table_row(). + '
'.$rowtitle.''.&mt('Open in new window').''. + ''. + ''. + ' '. + ''. + ''.&mt('Date/Time').''.&mt('CODE').''.&mt('Version').''.&mt('Submission').''.&mt('Status').''.$record->{$version.':resource.CODE'}.''.$interaction.'
'.&mt('List of CODES to validate against:').''. $env{'form.scantron_CODElist'}.'
'.&mt('Hand-graded items: points from last bubble in row').''. + $env{'form.scantron_lastbubblepoints'}.'
-'.$CODElist.' +'.$CODElist.$lastbubblepoints.'
'.&mt('Sequence to be Graded:').''.$title.'
'.&mt('Data File that will be used:').''.$env{'form.scantron_selectfile'}.'

'.&mt('If this information is correct, please click on \'[_1]\'.',&mt($button_text)).'
'.&mt('If something is incorrect, please return to [_1]Grade/Manage/Review Bubblesheets[_2] to start over.','','').'

@@ -6255,8 +6478,9 @@ sub scantron_do_warning { } } else { my $warning=&scantron_warning_screen('Grading: Validate Records',$symb); + my $bubbledbyhand=&hand_bubble_option(); $r->print(' -'.$warning.' +'.$warning.$bubbledbyhand.' '); @@ -6308,7 +6532,7 @@ SCANTRONFORM =item scantron_validate_file - Dispatch routine for doing validation of a bubble sheet data file. + Dispatch routine for doing validation of a bubblesheet data file. Also processes any necessary information resets that need to occur before validation begins (ignore previous corrections, @@ -6352,6 +6576,9 @@ sub scantron_validate_file { return ''; } my $result=&scantron_form_start($max_bubble).$default_form_data; + if ($env{'form.scantron_lastbubblepoints'} ne '') { + $result .= ''; + } $r->print($result); my @validate_phases=( 'sequence', @@ -6419,7 +6646,7 @@ sub scantron_validate_file { =item scantron_remove_file - Removes the requested bubble sheet data file, makes sure that + Removes the requested bubblesheet data file, makes sure that scantron_original_ is never removed @@ -6444,7 +6671,7 @@ sub scantron_remove_file { =item scantron_remove_scan_data - Removes all scan_data correction for the requested bubble sheet + Removes all scan_data correction for the requested bubblesheet data file. (In the case that both the are doing skipped records we need to remember the old skipped lines for the time being so that element persists for a while.) @@ -6481,7 +6708,7 @@ sub scantron_remove_scan_data { =item scantron_getfile - Fetches the requested bubble sheet data file (all 3 versions), and + Fetches the requested bubblesheet data file (all 3 versions), and the scan_data hash Arguments: @@ -6581,7 +6808,7 @@ sub lonnet_putfile { =item scantron_putfile - Stores the current version of the bubble sheet data files, and the + Stores the current version of the bubblesheet data files, and the scan_data hash. (Does not modify the original version only the corrected and skipped versions. @@ -6675,7 +6902,7 @@ sub get_todo_count { =item scantron_put_line - Updates the 'corrected' or 'skipped' versions of the bubble sheet + Updates the 'corrected' or 'skipped' versions of the bubblesheet data file. Arguments: @@ -6777,7 +7004,13 @@ sub scantron_validate_sequence { my @resources= $navmap->retrieveResources($map,\&scantron_filter_not_exam,1,0); if (@resources) { - $r->print("

".&mt('Some resources in the sequence currently are not set to exam mode. Grading these resources currently may not work correctly.')."

"); + $r->print( + '

' + .&mt('Some resources in the sequence currently are not set to' + .' exam mode. Grading these resources currently may not' + .' work correctly.') + .'

' + ); return (1,$currentphase); } } @@ -6864,19 +7097,28 @@ sub scantron_get_correction { #the previous one or the current one if ( $$scan_record{'scantron.PaperID'} =~ /\S/) { - $r->print("

".&mt("An error was detected ($error)". - " for PaperID [_1]", - $$scan_record{'scantron.PaperID'})."

\n"); - } else { - $r->print("

".&mt("An error was detected ($error)". - " in scanline [_1]

[_2]
", - $i,$line)."

\n"); - } - my $message="

".&mt("The ID on the form is [_1]
". - "The name on the paper is [_2],[_3]", - $$scan_record{'scantron.ID'}, - $$scan_record{'scantron.LastName'}, - $$scan_record{'scantron.FirstName'})."

"; + $r->print( + '

' + .&mt('An error was detected ([_1]) for PaperID [_2]', + "$error", + ''.$$scan_record{'scantron.PaperID'}.'') + ."

\n"); + } else { + $r->print( + '

' + .&mt('An error was detected ([_1]) in scanline [_2] [_3]', + "$error", $i, "

$line
") + ."

\n"); + } + my $message = + '

' + .&mt('The ID on the form is [_1]', + "$$scan_record{'scantron.ID'}") + .'
' + .&mt('The name on the paper is [_1], [_2]', + $$scan_record{'scantron.LastName'}, + $$scan_record{'scantron.FirstName'}) + .'

'; $r->print(''."\n"); $r->print(''."\n"); @@ -6886,10 +7128,10 @@ sub scantron_get_correction { if ($error =~ /ID$/) { if ($error eq 'incorrectID') { - $r->print("

".&mt("The encoded ID is not in the classlist"). + $r->print('

'.&mt("The encoded ID is not in the classlist"). "

\n"); } elsif ($error eq 'duplicateID') { - $r->print("

".&mt("The encoded ID has also been used by a previous paper [_1]",$arg)."

\n"); + $r->print('

'.&mt("The encoded ID has also been used by a previous paper [_1]",$arg)."

\n"); } $r->print($message); $r->print("

".&mt("How should I handle this?")."
\n"); @@ -6905,14 +7147,15 @@ sub scantron_get_correction { $r->print(''); } elsif ($error =~ /CODE$/) { if ($error eq 'incorrectCODE') { - $r->print("

".&mt("The encoded CODE is not in the list of possible CODEs.")."

\n"); + $r->print('

'.&mt("The encoded CODE is not in the list of possible CODEs.")."

\n"); } elsif ($error eq 'duplicateCODE') { - $r->print("

".&mt("The encoded CODE has also been used by a previous paper [_1], and CODEs are supposed to be unique.",join(', ',@{$arg}))."

\n"); + $r->print('

'.&mt("The encoded CODE has also been used by a previous paper [_1], and CODEs are supposed to be unique.",join(', ',@{$arg}))."

\n"); } - $r->print("

".&mt("The CODE on the form is '[_1]'", - $$scan_record{'scantron.CODE'})."
\n"); + $r->print("

".&mt('The CODE on the form is [_1]', + "'$$scan_record{'scantron.CODE'}'") + ."

\n"); $r->print($message); - $r->print("

".&mt("How should I handle this?")."
\n"); + $r->print("

".&mt("How should I handle this?")."

\n"); $r->print("\n
"); my $i=0; if ($error eq 'incorrectCODE' @@ -6939,7 +7182,7 @@ sub scantron_get_correction { $r->print(" "); $r->print("\n
"); @@ -6977,7 +7220,7 @@ ENDSCRIPT "")); $r->print("\n

"); } elsif ($error eq 'doublebubble') { - $r->print("

".&mt("There have been multiple bubbles scanned for some question(s)")."

\n"); + $r->print('

'.&mt("There have been multiple bubbles scanned for some question(s)")."

\n"); # The form field scantron_questions is acutally a list of line numbers. # represented by this form so: @@ -6995,7 +7238,7 @@ ENDSCRIPT } $r->print(&verify_bubbles_checked(@lines_to_correct)); } elsif ($error eq 'missingbubble') { - $r->print("

".&mt("There have been no bubbles scanned for some question(s)")."

\n"); + $r->print('

'.&mt("There have been [_1]no[_2] bubbles scanned for some question(s)",'','')."

\n"); $r->print($message); $r->print("

".&mt("Please indicate which bubble should be used for grading.")."

"); $r->print(&mt("Some questions have no scanned bubbles.")."\n"); @@ -7481,7 +7724,8 @@ sub scantron_get_maxbubble { my $response_number = 0; my $bubble_line = 0; foreach my $resource (@resources) { - my ($analysis,$parts) = &scantron_partids_tograde($resource,$cid,$uname,$udom,undef,$bubbles_per_row); + my ($analysis,$parts) = &scantron_partids_tograde($resource,$cid,$uname, + $udom,undef,$bubbles_per_row); if ((ref($analysis) eq 'HASH') && (ref($parts) eq 'ARRAY')) { foreach my $part_id (@{$parts}) { my $lines; @@ -7614,6 +7858,41 @@ sub scantron_validate_missingbubbles { return (0,$currentphase+1); } +sub hand_bubble_option { + my (undef, undef, $sequence) = + &Apache::lonnet::decode_symb($env{'form.selectpage'}); + return if ($sequence eq ''); + my $navmap = Apache::lonnavmaps::navmap->new(); + unless (ref($navmap)) { + return; + } + my $needs_hand_bubbles; + my $map=$navmap->getResourceByUrl($sequence); + my @resources=$navmap->retrieveResources($map,\&scantron_filter,1,0); + foreach my $res (@resources) { + if (ref($res)) { + if ($res->is_problem()) { + my $partlist = $res->parts(); + foreach my $part (@{ $partlist }) { + my @types = $res->responseType($part); + if (grep(/^(chem|essay|image|formula|math|string|functionplot)$/,@types)) { + $needs_hand_bubbles = 1; + last; + } + } + } + } + } + if ($needs_hand_bubbles) { + my %scantron_config=&get_scantron_config($env{'form.scantron_format'}); + my $bubbles_per_row = &bubblesheet_bubbles_per_row(\%scantron_config); + return &mt('The sequence to be graded contains response types which are handgraded.').'

'. + &mt('If you have already graded these by bubbling sheets to indicate points awarded, [_1]what point value is assigned to a filled last bubble in each row?','
'). + ' '.&mt('or').' '. + '

'; + } + return; +} sub scantron_process_students { my ($r,$symb) = @_; @@ -7651,7 +7930,8 @@ sub scantron_process_students { } my ($analysis,$parts) = &scantron_partids_tograde($resource,$env{'request.course.id'}, - $env{'user.name'},$env{'user.domain'},1,$bubbles_per_row); + $env{'user.name'},$env{'user.domain'}, + 1,$bubbles_per_row); $grader_partids_by_symb{$ressymb} = $parts; if (ref($analysis) eq 'HASH') { if (ref($analysis->{'parts_withrandomlist'}) eq 'ARRAY') { @@ -7678,11 +7958,8 @@ SCANTRONFORM my $lock=&Apache::lonnet::set_lock(&mt('Grading bubblesheet exam')); my $count=&get_todo_count($scanlines,$scan_data); - my %prog_state=&Apache::lonhtmlcommon::Create_PrgWin($r,'Bubblesheet Status', - 'Bubblesheet Progress',$count, - 'inline',undef,'scantronupload'); - &Apache::lonhtmlcommon::Update_PrgWin($r,\%prog_state, - 'Processing first student'); + my %prog_state=&Apache::lonhtmlcommon::Create_PrgWin($r,$count); + &Apache::lonhtmlcommon::Update_PrgWin($r,\%prog_state,'Processing first student'); $r->print('
'); my $start=&Time::HiRes::time(); my $i=-1; @@ -7714,8 +7991,7 @@ SCANTRONFORM my $line=&scantron_get_line($scanlines,$scan_data,$i); if ($line=~/^[\s\cz]*$/) { next; } if ($started) { - &Apache::lonhtmlcommon::Increment_PrgWin($r,\%prog_state, - 'last student'); + &Apache::lonhtmlcommon::Increment_PrgWin($r,\%prog_state,'last student'); } $started=1; my $scan_record=&scantron_parse_scanline($line,$i,\%scantron_config, @@ -7745,7 +8021,8 @@ SCANTRONFORM if ((exists($grader_randomlists_by_symb{$ressymb})) || (ref($grader_partids_by_symb{$ressymb}) ne 'ARRAY')) { my ($analysis,$parts) = - &scantron_partids_tograde($resource,$env{'request.course.id'},$uname,$udom,undef,$bubbles_per_row); + &scantron_partids_tograde($resource,$env{'request.course.id'}, + $uname,$udom,undef,$bubbles_per_row); $partids_by_symb{$ressymb} = $parts; } else { $partids_by_symb{$ressymb} = $grader_partids_by_symb{$ressymb}; @@ -7822,12 +8099,12 @@ SCANTRONFORM $studentrecord .= $recording; } if ($studentrecord ne $studentdata) { - $r->print('

'); + $r->print('

'); if ($scancode eq '') { - $r->print(&mt('Mismatch grading bubble sheet for user: [_1] with ID: [_2].', + $r->print(&mt('Mismatch grading bubblesheet for user: [_1] with ID: [_2].', $uname.':'.$udom,$scan_record->{'scantron.ID'})); } else { - $r->print(&mt('Mismatch grading bubble sheet for user: [_1] with ID: [_2] and CODE: [_3].', + $r->print(&mt('Mismatch grading bubblesheet for user: [_1] with ID: [_2] and CODE: [_3].', $uname.':'.$udom,$scan_record->{'scantron.ID'},$scancode)); } $r->print('
'.&Apache::loncommon::start_data_table()."\n". @@ -7835,12 +8112,12 @@ SCANTRONFORM '

'.&mt('Source').''.&mt('Bubbled responses').''.&mt('Bubble Sheet').''.$studentdata.''.&mt('Bubblesheet').''.$studentdata.'Stored submissions'.$studentrecord.''.&mt('Stored submissions').''.$studentrecord.'