--- loncom/homework/grades.pm 2010/03/11 16:29:42 1.597 +++ loncom/homework/grades.pm 2010/04/01 00:58:43 1.604 @@ -1,7 +1,7 @@ # The LearningOnline Network with CAPA # The LON-CAPA Grading handler # -# $Id: grades.pm,v 1.597 2010/03/11 16:29:42 wenzelju Exp $ +# $Id: grades.pm,v 1.604 2010/04/01 00:58:43 raeburn Exp $ # # Copyright Michigan State University Board of Trustees # @@ -96,6 +96,9 @@ sub ssi_print_error { # # --- Retrieve the parts from the metadata file.--- +# Returns an array of everything that the resources stores away +# + sub getpartlist { my ($symb,$errorref) = @_; @@ -121,13 +124,17 @@ sub getpartlist { } # --- Get the symbolic name of a problem and the url +# Generate an error message if symb could not be found unless silent flag is set +# Takes $env{'form.symb'} by default; if not present, takes $env{'form.url'} and tries to get symb from that +# + sub get_symb { my ($request,$silent) = @_; (my $url=$env{'form.url'}) =~ s-^http://($ENV{'SERVER_NAME'}|$ENV{'HTTP_HOST'})--; my $symb=($env{'form.symb'} ne '' ? $env{'form.symb'} : (&Apache::lonnet::symbread($url))); if ($symb eq '') { if (!$silent) { - $request->print("Unable to handle ambiguous references:$url:."); + $request->print(&mt("Unable to handle ambiguous references: [_1].",$url)); return (); } } @@ -207,55 +214,6 @@ sub get_display_part { return $display; } -#--- Show resource title -#--- and parts and response type -sub showResourceInfo { - my ($symb,$probTitle,$checkboxes,$res_error) = @_; - my $result = '

'.&mt('Current Resource').': '.$probTitle.'

'."\n"; - my ($partlist,$handgrade,$responseType) = &response_type($symb,$res_error); - if (ref($res_error)) { - if ($$res_error) { - return; - } - } - $result.=&Apache::loncommon::start_data_table() - .&Apache::loncommon::start_data_table_header_row(); - if ($checkboxes) { - $result.=' '; - } - $result.=''.&mt('Problem Part').'' - .''.&mt('Res. ID').'' - .''.&mt('Type').'' - .&Apache::loncommon::end_data_table_header_row(); - my %resptype = (); - my $hdgrade='no'; - my %partsseen; - foreach my $partID (sort(keys(%$responseType))) { - foreach my $resID (sort(keys(%{ $responseType->{$partID} }))) { - my $handgrade=$$handgrade{$partID.'_'.$resID}; - my $responsetype = $responseType->{$partID}->{$resID}; - $hdgrade = $handgrade if ($handgrade eq 'yes'); - $result.=&Apache::loncommon::start_data_table_row(); - if ($checkboxes) { - if (exists($partsseen{$partID})) { - $result.=" "; - } else { - $result.=""; - } - $partsseen{$partID}=1; - } - my $display_part=&get_display_part($partID,$symb); - $result.=''.$display_part.'' - .''.''.$resID.'' - .''.&mt($responsetype).'' -# .''.&mt('Handgrade: [_1]',$handgrade).'' - .&Apache::loncommon::end_data_table_row(); - } - } - $result.=&Apache::loncommon::end_data_table(); - return $result,$responseType,$hdgrade,$partlist,$handgrade; -} - sub reset_caches { &reset_analyze_cache(); &reset_perm(); @@ -732,7 +690,7 @@ sub most_similar { # ignore empty submissions (occuring when only files are sent) - unless ($uessay=~/\w+/) { return ''; } + unless ($uessay=~/\w+/s) { return ''; } # these will be returned. Do not care if not at least 50 percent similar my $limit=0.6; @@ -769,6 +727,19 @@ sub most_similar { #------------------------------------ Receipt Verification Routines # + +sub initialverifyreceipt { + my $request = shift; + &commonJSfunctions($request); + my ($symb) = &get_symb($request); + return '
'. + &Apache::lonnet::recprefix($env{'request.course.id'}). + '-'. + ''."\n". + ''. + "
\n"; +} + #--- Check whether a receipt number is valid.--- sub verifyreceipt { my $request = shift; @@ -878,7 +849,9 @@ sub listStudents { .&mt("$viewgrade Submissions for a Student or a Group of Students") .''; - my ($table,undef,$hdgrade,$partlist,$handgrade) = &showResourceInfo($symb,$env{'form.probTitle'},($env{'form.showgrading'} eq 'yes')); + my ($partlist,$handgrade,$responseType) = &response_type($symb +#,$res_error + ); my %lt = &Apache::lonlocal::texthash ( 'multiple' => 'Please select a student or group of students before clicking on the Next button.', @@ -921,7 +894,7 @@ LISTJAVASCRIPT my $checkhdgrade = ($env{'form.handgrade'} eq 'yes' && scalar(@$partlist) > 1 ) ? 'checked="checked"' : ''; my $checklastsub = $checkhdgrade eq '' ? 'checked="checked"' : ''; my $gradeTable='
'. - "\n".$table; + "\n"; $gradeTable .= &Apache::lonhtmlcommon::start_pick_box(); $gradeTable .= &Apache::lonhtmlcommon::row_title(&mt('View Problem Text')) @@ -1785,7 +1758,6 @@ sub gradeBox { $line.=''."\n"; - #&mt('Part:[_1]Points:[_2]or[_3]',$display_part,$radio,$line); $result .= ''.$display_part.''.$radio.''.&mt('or').''.$line.''; $result.=&Apache::loncommon::end_data_table_row(); @@ -2268,7 +2240,9 @@ KEYWORDS } $request->print($lastsubonly); } elsif ($env{'form.lastSub'} eq 'datesub') { - my (undef,$responseType,undef,$parts) = &showResourceInfo($symb); +# my (undef,$responseType,undef,$parts) = &showResourceInfo($symb); + my ($parts,$handgrade,$responseType) = &response_type($symb); + $request->print(&displaySubByDates($symb,\%record,$parts,$responseType,$checkIcon,$uname,$udom)); } elsif ($env{'form.lastSub'} =~ /^(last|all)$/) { $request->print(&Apache::loncommon::get_previous_attempt($symb,$uname,$udom, @@ -2664,7 +2638,7 @@ sub processHandGrade { # Go directly to grade student - from submission or link from chart page if ($button eq 'Grade Student') { - (undef,undef,$env{'form.handgrade'},undef,undef) = &showResourceInfo($symb); +# (undef,undef,$env{'form.handgrade'},undef,undef) = &showResourceInfo($symb); my $processUser = $env{'form.unamedom'.$env{'form.studentNo'}}; ($env{'form.student'},$env{'form.userdom'}) = split(/:/,$processUser); $env{'form.fullname'} = $$fullname{$processUser}; @@ -3894,7 +3868,8 @@ sub csvuploadmap_header { $javascript=&csvupload_javascript_forward_associate(); } - my ($result) = &showResourceInfo($symb,$env{'form.probTitle'}); +# my ($result) = &showResourceInfo($symb,$env{'form.probTitle'}); + my $result=''; my $checked=(($env{'form.noFirstLine'})?' checked="checked"':''); my $ignore=&mt('Ignore First Line'); $symb = &Apache::lonenc::check_encrypt($symb); @@ -3985,8 +3960,8 @@ sub upcsvScores_form { if (!$symb) {return '';} my $result=&checkforfile_js(); $env{'form.probTitle'} = &Apache::lonnet::gettitle($symb); - my ($table) = &showResourceInfo($symb,$env{'form.probTitle'}); - $result.=$table; +# my ($table) = &showResourceInfo($symb,$env{'form.probTitle'}); +# $result.=$table; $result.='
'."\n"; $result.='
'."\n"; $result.=' '.&mt('Specify a file containing the class scores for current resource.'). @@ -8502,36 +8477,29 @@ sub show_grading_menu_form { return $result; } -# -- Retrieve choices for grading form -sub savedState { - my %savedState = (); - if ($env{'form.saveState'}) { - foreach (split(/:/,$env{'form.saveState'})) { - my ($key,$value) = split(/=/,$_,2); - $savedState{$key} = $value; - } - } - return \%savedState; -} - sub grading_menu { my ($request) = @_; my ($symb)=&get_symb($request); if (!$symb) {return '';} my $probTitle = &Apache::lonnet::gettitle($symb); - my ($table,undef,$hdgrade) = &showResourceInfo($symb,$probTitle); - $request->print($table); my %fields = ('symb'=>&Apache::lonenc::check_encrypt($symb), - 'handgrade'=>$hdgrade, 'probTitle'=>$probTitle, - 'command'=>'submit_options', - 'saveState'=>"", + 'command'=>'individual', 'gradingMenu'=>1, 'showgrading'=>"yes"); - my $url1 = &Apache::lonhtmlcommon::build_url('grades/',\%fields); - + my $url1a = &Apache::lonhtmlcommon::build_url('grades/',\%fields); + + $fields{'command'}='ungraded'; + my $url1b=&Apache::lonhtmlcommon::build_url('grades/',\%fields); + + $fields{'command'}='table'; + my $url1c=&Apache::lonhtmlcommon::build_url('grades/',\%fields); + + $fields{'command'}='all_for_one'; + my $url1d=&Apache::lonhtmlcommon::build_url('grades/',\%fields); + $fields{'command'} = 'csvform'; my $url2 = &Apache::lonhtmlcommon::build_url('grades/',\%fields); @@ -8540,15 +8508,40 @@ sub grading_menu { $fields{'command'} = 'scantron_selectphase'; my $url4 = &Apache::lonhtmlcommon::build_url('grades/',\%fields); + + $fields{'command'} = 'initialverifyreceipt'; + my $url5 = &Apache::lonhtmlcommon::build_url('grades/',\%fields); - my @menu = ({ categorytitle=>'Course Grading', + my @menu = ({ categorytitle=>'Hand Grading', items =>[ - { linktext => 'Manual Grading/View Submissions', - url => $url1, + { linktext => 'Select individual students to grade', + url => $url1a, permission => 'F', icon => 'edit-find-replace.png', - linktitle => 'Start the process of hand grading submissions.' + linktitle => 'Grade current resource for a selection of students.' + }, + { linktext => 'Grade ungraded submissions.', + url => $url1b, + permission => 'F', + icon => 'edit-find-replace.png', + linktitle => 'Grade all submissions that have not been graded yet.' + }, + + { linktext => 'Grading table', + url => $url1c, + permission => 'F', + icon => 'edit-find-replace.png', + linktitle => 'Grade current resource for all students.' }, + { linktext => 'Grade complete page/sequence/folder for one student', + url => $url1d, + permission => 'F', + icon => 'edit-find-replace.png', + linktitle => 'Grade all resources in current page/sequence/folder for one student.' + }]}, + { categorytitle=>'Automated Grading', + items =>[ + { linktext => 'Upload Scores', url => $url2, permission => 'F', @@ -8566,73 +8559,91 @@ sub grading_menu { permission => 'F', icon => 'stat.png', linktitle => 'Grade scantron exams, upload/download scantron data files, and review previously graded scantron exams.' - } + }, + { linktext => 'Verify Receipt No.', + url => $url5, + permission => 'F', + icon => 'edit-find-replace.png', + linktitle => 'Verify a system-generated receipt number for correct problem solution.' + } + ] }); - #$fields{'command'} = 'verify'; - #$url = &Apache::lonhtmlcommon::build_url('grades/',\%fields); - # # Create the menu my $Str; - # $Str .= '

'.&mt('Please select a grading task').'

'; $Str .= ''; $Str .= ''. ''."\n". - ''."\n". ''."\n". - ''."\n". ''."\n". ''."\n"; - $Str .= Apache::lonhtmlcommon::generate_menu(@menu); - #$menudata->{'jscript'} - $Str .='
'. - &Apache::lonnet::recprefix($env{'request.course.id'}). - '-'; + $Str .= &Apache::lonhtmlcommon::generate_menu(@menu); + return $Str; +} - $Str .="\n"; - my $receiptalert = &mt("Please enter a receipt number given by a student in the receipt box."); - $request->print(&Apache::lonhtmlcommon::scripttag(<'."\n". + ''."\n". + ''."\n"; + + $result.=' +

+ '.&mt('Grade complete page/sequence/folder for one student').' +

'. + &selectfield(0). + ' +
+ +
+ + '; + $result .= &show_grading_menu_form($symb); + return $result; } +sub submit_options_table { + my ($request) = @_; + my ($symb)=&get_symb($request); + if (!$symb) {return '';} + &commonJSfunctions($request); + my $result; + + $result.='
'."\n". + ''."\n". + ''."\n". + ''."\n"; + + $result.=' +

+ '.&mt('Grading table').' +

'. + &selectfield(0). + ' +
+ +
+ +
'; + $result .= &show_grading_menu_form($symb); + return $result; +} + + #--- Displays the submissions first page ------- sub submit_options { @@ -8641,87 +8652,39 @@ sub submit_options { if (!$symb) {return '';} my $probTitle = &Apache::lonnet::gettitle($symb); - my $receiptalert = &mt("Please enter a receipt number given by a student in the receipt box."); - $request->print(&Apache::lonhtmlcommon::scripttag(<'.$section.''."\n"; - } - } $result.='
'."\n". ''."\n". - ''."\n". ''."\n". - ''."\n". - ''."\n". ''."\n". ''."\n"; $result.='

- '.&mt('Grade Current Resource').' -

-
- '.$table.' -
+ '.&mt('Select individual students to grade').' +'.&selectfield(1).' + + + + -
+ + '; + $result .= &show_grading_menu_form($symb); + return $result; +} + +sub selectfield { + my ($full)=@_; + my $result='
'.&mt('Sections').' -   '; - $result.=' + '.&Apache::lonstatistics::SectionSelect('section','multiple',5).'
@@ -8735,63 +8698,25 @@ GRADINGMENUJS '.&mt('Access Status').' - '.&Apache::lonhtmlcommon::StatusOptions($saveStatus,undef,5,undef,'mult').' -
- + '.&Apache::lonhtmlcommon::StatusOptions(undef,undef,5,undef,'mult').' + '; + if ($full) { + $result.='
'.&mt('Submission Status').' - - -
- -
- -
-
-
- -
-
- -
-
- -
-
- - -

- '.&mt('Grade Complete Folder for One Student').' -

-
-
- -
-
- -
-
- '; - $result .= &show_grading_menu_form($symb); + '. + &Apache::loncommon::select_form('all','submitonly', + (&Apache::lonlocal::texthash( + 'yes' => 'with submissions', + 'queued' => 'in grading queue', + 'graded' => 'with ungraded submissions', + 'incorrect' => 'with incorrect submissions', + 'all' => 'with any status'), + 'select_form_order' => ['yes','queued','graded','incorrect','all'])). + ''; + } + $result.='

'; return $result; } @@ -8884,13 +8809,11 @@ sub process_clicker { if (!$symb) {return '';} my $result=&checkforfile_js(); $env{'form.probTitle'} = &Apache::lonnet::gettitle($symb); - my ($table) = &showResourceInfo($symb,$env{'form.probTitle'}); - $result.=$table; $result.='
'."\n"; $result.=''."\n"; - $result.='
'."\n"; $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', @@ -8994,8 +8917,8 @@ sub process_clicker_file { my %Saveable_Parameters=&clicker_grading_parameters(); &Apache::loncommon::store_course_settings('grades_clicker', \%Saveable_Parameters); - - my ($result) = &showResourceInfo($symb,$env{'form.probTitle'}); + my $result=''; +# 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); @@ -9234,7 +9157,8 @@ sub assign_clicker_grades { # 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 $result=''; +# my ($result) = &showResourceInfo($symb,$env{'form.probTitle'}); my $heading=&mt('Assigning grades based on clicker file'); $result.=(<print(&Apache::loncommon::start_page('Grading',undef, {'bread_crumbs' => $brcrum})); if ($symb eq '' && $command eq '') { - if ($env{'user.adv'}) { - if (($env{'form.codeone'}) && ($env{'form.codetwo'}) && - ($env{'form.codethree'})) { - my $token=$env{'form.codeone'}.'*'.$env{'form.codetwo'}.'*'. - $env{'form.codethree'}; - my ($tsymb,$tuname,$tudom,$tcrsid)= - &Apache::lonnet::checkin($token); - if ($tsymb) { - my ($map,$id,$url)=&Apache::lonnet::decode_symb($tsymb); - if (&Apache::lonnet::allowed('mgr',$tcrsid)) { - $request->print(&ssi_with_retries('/res/'.$url, $ssi_retries, - ('grade_username' => $tuname, - 'grade_domain' => $tudom, - 'grade_courseid' => $tcrsid, - 'grade_symb' => $tsymb))); - } else { - $request->print('

Not authorized: '.$token.'

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

Not a valid DocID: '.$token.'

'); - } - } else { - $request->print(&Apache::lonxml::tokeninputfield()); - } - } +# +# Not called from a resource +# + } else { &init_perm(); if ($command eq 'submission' && $perm{'vgr'}) { @@ -9404,14 +9307,22 @@ sub handler { &processGroup($request); } elsif ($command eq 'gradingmenu' && $perm{'vgr'}) { $request->print(&grading_menu($request)); - } elsif ($command eq 'submit_options' && $perm{'vgr'}) { + } elsif ($command eq 'individual' && $perm{'vgr'}) { $request->print(&submit_options($request)); + } elsif ($command eq 'ungraded' && $perm{'vgr'}) { + $request->print(&submit_options($request)); + } elsif ($command eq 'table' && $perm{'vgr'}) { + $request->print(&submit_options_table($request)); + } elsif ($command eq 'all_for_one' && $perm{'vgr'}) { + $request->print(&submit_options_sequence($request)); } elsif ($command eq 'viewgrades' && $perm{'vgr'}) { $request->print(&viewgrades($request)); } elsif ($command eq 'handgrade' && $perm{'mgr'}) { $request->print(&processHandGrade($request)); } elsif ($command eq 'editgrades' && $perm{'mgr'}) { $request->print(&editgrades($request)); + } elsif ($command eq 'initialverifyreceipt' && $perm{'vgr'}) { + $request->print(&initialverifyreceipt($request)); } elsif ($command eq 'verify' && $perm{'vgr'}) { $request->print(&verifyreceipt($request)); } elsif ($command eq 'processclicker' && $perm{'mgr'}) {