--- loncom/homework/grades.pm 2025/01/18 21:29:42 1.596.2.12.2.60.2.9 +++ loncom/homework/grades.pm 2024/07/01 22:51:46 1.596.2.12.2.61 @@ -1,7 +1,7 @@ # The LearningOnline Network with CAPA # The LON-CAPA Grading handler # -# $Id: grades.pm,v 1.596.2.12.2.60.2.9 2025/01/18 21:29:42 raeburn Exp $ +# $Id: grades.pm,v 1.596.2.12.2.61 2024/07/01 22:51:46 raeburn Exp $ # # Copyright Michigan State University Board of Trustees # @@ -46,12 +46,10 @@ use Apache::lonenc; use Apache::lonstathelpers; use Apache::bridgetask(); use Apache::lontexconvert(); -use Apache::loncourserespicker; -use String::Similarity; use HTML::Parser(); use File::MMagic; +use String::Similarity; use LONCAPA; -use LONCAPA::ltiutils(); use POSIX qw(floor); @@ -66,7 +64,7 @@ my $ssi_retries = 5; my $ssi_error; my $ssi_error_resource; my $ssi_error_message; -my $registered_cleanup; + sub ssi_with_retries { my ($resource, $retries, %form) = @_; @@ -120,11 +118,7 @@ sub getpartlist { my $res = $navmap->getBySymb($symb); my $partlist = $res->parts(); my $url = $res->src(); - my $toolsymb; - if ($url =~ /ext\.tool$/) { - $toolsymb = $symb; - } - my @metakeys = split(/,/,&Apache::lonnet::metadata($url,'keys',$toolsymb)); + my @metakeys = split(/,/,&Apache::lonnet::metadata($url,'keys')); my @stores; foreach my $part (@{ $partlist }) { @@ -305,7 +299,7 @@ sub showResourceInfo { } else { return '
'; } - } + } return $result; } @@ -592,7 +586,7 @@ sub cleanRecord { return $result; } } elsif ( $response =~ m/(?:numerical|formula|custom)/) { - # Respect multiple input fields, see Bug #5409 + # Respect multiple input fields, see Bug #5409 $answer = &Apache::loncommon::format_previous_attempt_value('submission', $answer); @@ -638,7 +632,7 @@ COMMONJSFUNCTIONS #--- Dumps the class list with usernames,list of sections, #--- section, ids and fullnames for each user. sub getclasslist { - my ($getsec,$filterbyaccstatus,$getgroup,$symb,$submitonly,$filterbysubmstatus,$filterbypbid,$possibles) = @_; + my ($getsec,$filterbyaccstatus,$getgroup,$symb,$submitonly,$filterbysubmstatus) = @_; my @getsec; my @getgroup; my $stu_status = join(':',&Apache::loncommon::get_env_multiple('form.Status')); @@ -666,16 +660,12 @@ sub getclasslist { # my %sections; my %fullnames; - my %passback; my ($cdom,$cnum,$partlist); if (($filterbysubmstatus) && ($submitonly ne 'all') && ($symb ne '')) { $cdom = $env{"course.$env{'request.course.id'}.domain"}; $cnum = $env{"course.$env{'request.course.id'}.num"}; my $res_error; ($partlist) = &response_type($symb,\$res_error); - } elsif ($filterbypbid) { - $cdom = $env{"course.$env{'request.course.id'}.domain"}; - $cnum = $env{"course.$env{'request.course.id'}.num"}; } foreach my $student (keys(%$classlist)) { my $end = @@ -762,27 +752,6 @@ sub getclasslist { } } } - if ($filterbypbid) { - if (ref($possibles) eq 'HASH') { - unless (exists($possibles->{$student})) { - delete($classlist->{$student}); - next; - } - } - my $udom = - $classlist->{$student}->[&Apache::loncoursedata::CL_SDOM()]; - my $uname = - $classlist->{$student}->[&Apache::loncoursedata::CL_SNAME()]; - if (($udom ne '') && ($uname ne '')) { - my %pbinfo = &Apache::lonnet::get('nohist_'.$cdom.'_'.$cnum.'_linkprot_pb',[$filterbypbid],$udom,$uname); - if (ref($pbinfo{$filterbypbid}) eq 'ARRAY') { - $passback{$student} = $pbinfo{$filterbypbid}; - } else { - delete($classlist->{$student}); - next; - } - } - } $section = ($section ne '' ? $section : 'none'); if (&canview($section)) { if (!@getsec || grep(/^\Q$section\E$/,@getsec)) { @@ -798,7 +767,7 @@ sub getclasslist { } } my @sections = sort(keys(%sections)); - return ($classlist,\@sections,\%fullnames,\%passback); + return ($classlist,\@sections,\%fullnames); } sub canmodify { @@ -1061,877 +1030,6 @@ sub verifyreceipt { return $string; } -#------------------------------------------------------------------- - -#------------------------------------------- Grade Passback Routines -# - -sub initialpassback { - my ($request,$symb) = @_; - my $cdom = $env{"course.$env{'request.course.id'}.domain"}; - my $cnum = $env{"course.$env{'request.course.id'}.num"}; - my $crstype = &Apache::loncommon::course_type(); - my %passback = &Apache::lonnet::dump('nohist_linkprot_passback',$cdom,$cnum); - my $readonly; - unless ($perm{'mgr'}) { - $readonly = 1; - } - my $formname = 'initialpassback'; - my $navmap = Apache::lonnavmaps::navmap->new(); - my $output; - if (!defined($navmap)) { - if ($crstype eq 'Community') { - $output = &mt('Unable to retrieve information about community contents'); - } else { - $output = &mt('Unable to retrieve information about course contents'); - } - return '

'.$output.'

'; - } - return &Apache::loncourserespicker::create_picker($navmap,'passback',$formname,$crstype,undef, - undef,undef,undef,undef,undef,undef, - \%passback,$readonly); -} - -sub passback_filters { - my ($request,$symb) = @_; - my $cdom = $env{"course.$env{'request.course.id'}.domain"}; - my $cnum = $env{"course.$env{'request.course.id'}.num"}; - my $crstype = &Apache::loncommon::course_type(); - my ($launcher,$appname,$setter,$linkuri,$linkprotector,$scope,$chosen); - if ($env{'form.passback'} ne '') { - $chosen = &unescape($env{'form.passback'}); - ($linkuri,$linkprotector,$scope) = split("\0",$chosen); - ($launcher,$appname,$setter) = &get_passback_launcher($cdom,$cnum,$chosen); - } - my $result; - if ($launcher ne '') { - $result = &launcher_info_box($launcher,$appname,$setter,$linkuri,$scope). - '


'.&mt('Set criteria to use to list students for possible passback of scores, then push Next [_1]', - '→'). - '

'; - } - $result .= '
'."\n". - ''."\n". - ''."\n"; - my ($submittext,$newcommand); - if ($launcher ne '') { - $submittext = &mt('Next').' →'; - $newcommand = 'passbacknames'; - $result .= &selectfield(0)."\n"; - } else { - $submittext = '← '.&mt('Previous'); - $newcommand = 'initialpassback'; - if ($env{'form.passback'}) { - $result .= ''.&mt('Invalid launcher').''."\n"; - } else { - $result .= ''.&mt('No launcher selected').''."\n"; - } - } - $result .= ''."\n". - '
'."\n". - ''."\n". - '
'."\n". - '
'."\n"; - return $result; -} - -sub names_for_passback { - my ($request,$symb) = @_; - my $cdom = $env{"course.$env{'request.course.id'}.domain"}; - my $cnum = $env{"course.$env{'request.course.id'}.num"}; - my $crstype = &Apache::loncommon::course_type(); - my ($launcher,$appname,$setter,$linkuri,$linkprotector,$scope,$chosen); - if ($env{'form.passback'} ne '') { - $chosen = &unescape($env{'form.passback'}); - ($linkuri,$linkprotector,$scope) = split("\0",$chosen); - ($launcher,$appname,$setter) = &get_passback_launcher($cdom,$cnum,$chosen); - } - my ($result,$ctr,$newcommand,$submittext); - if ($launcher ne '') { - $result = &launcher_info_box($launcher,$appname,$setter,$linkuri,$scope); - } - $ctr = 0; - my @statuses = &Apache::loncommon::get_env_multiple('form.Status'); - my $stu_status = join(':',@statuses); - $result .= '
'."\n". - ''."\n"; - if ($launcher ne '') { - $result .= ''."\n". - ''."\n"; - my ($sections,$groups,$group_display,$disabled) = §ions_and_groups(); - my $section_display = join(' ',@{$sections}); - my $status_display; - if ((grep(/^Any$/,@statuses)) || - (@statuses == 3)) { - $status_display = &mt('Any'); - } else { - $status_display = join(' '.&mt('or').' ',map { &mt($_); } @statuses); - } - $result .= '

'.&mt('Student(s) with stored passback credentials for [_1], and also satisfy:', - ''.$linkuri.''). - '

'; - my ($classlist,undef,$fullname) = &getclasslist($sections,'1',$groups,'','','',$chosen); - if (keys(%$fullname)) { - $newcommand = 'passbackscores'; - $result .= &build_section_inputs(). - &checkselect_js('passbackusers'). - '


'. - &mt("To send scores, check box(es) next to the student's name(s), then push 'Send Scores'."). - '

'. - &check_script('passbackusers', 'stuinfo')."\n". - '
'."\n". - &check_buttons()."\n". - &Apache::loncommon::start_data_table(). - &Apache::loncommon::start_data_table_header_row(); - my $loop = 0; - while ($loop < 2) { - $result .= ''.&mt('No.').''.&mt('Select').''. - ''.&nameUserString('header').' '.&mt('Section/Group').''; - $loop++; - } - $result .= &Apache::loncommon::end_data_table_header_row()."\n"; - foreach my $student (sort - { - if (lc($$fullname{$a}) ne lc($$fullname{$b})) { - return (lc($$fullname{$a}) cmp lc($$fullname{$b})); - } - return $a cmp $b; - } - (keys(%$fullname))) { - $ctr++; - my $section = $classlist->{$student}->[&Apache::loncoursedata::CL_SECTION()]; - my $group = $classlist->{$student}->[&Apache::loncoursedata::CL_GROUP()]; - my $udom = $classlist->{$student}->[&Apache::loncoursedata::CL_SDOM()]; - my $uname = $classlist->{$student}->[&Apache::loncoursedata::CL_SNAME()]; - if ( $perm{'vgr'} eq 'F' ) { - if ($ctr%2 ==1) { - $result.= &Apache::loncommon::start_data_table_row(); - } - $result .= ''.$ctr.' '. - ''."\n".''. - &nameUserString(undef,$$fullname{$student},$uname,$udom). - ' '.$section.($group ne '' ?'/'.$group:'').''."\n"; - - if ($ctr%2 ==0) { - $result .= &Apache::loncommon::end_data_table_row()."\n"; - } - } - } - if ($ctr%2 ==1) { - $result .= &Apache::loncommon::end_data_table_row(); - } - $result .= &Apache::loncommon::end_data_table()."\n"; - if ($ctr) { - $result .= ''."\n"; - } - } else { - $submittext = '← '.&mt('Previous'); - $newcommand = 'passback'; - $result .= ''.&mt('No students match the selection criteria').'

'; - } - } else { - $newcommand = 'initialpassback'; - $submittext = &mt('Start over'); - if ($env{'form.passback'}) { - $result .= ''.&mt('Invalid launcher').''."\n"; - } else { - $result .= ''.&mt('No launcher selected').''."\n"; - } - } - $result .= ''."\n"; - if (!$ctr) { - $result .= '
'."\n". - ''."\n". - '
'."\n"; - } - $result .= ''."\n"; - return $result; -} - -sub do_passback { - my ($request,$symb) = @_; - my $cdom = $env{"course.$env{'request.course.id'}.domain"}; - my $cnum = $env{"course.$env{'request.course.id'}.num"}; - my $crstype = &Apache::loncommon::course_type(); - my ($launchsymb,$appname,$setter,$linkuri,$linkprotector,$scope,$chosen); - if ($env{'form.passback'} ne '') { - $chosen = &unescape($env{'form.passback'}); - ($linkuri,$linkprotector,$scope) = split("\0",$chosen); - ($launchsymb,$appname,$setter) = &get_passback_launcher($cdom,$cnum,$chosen); - } - if ($launchsymb ne '') { - $request->print(&launcher_info_box($launchsymb,$appname,$setter,$linkuri,$scope)); - } - my $error; - if ($perm{'mgr'}) { - if ($launchsymb ne '') { - my @poss_students = &Apache::loncommon::get_env_multiple('form.stuinfo'); - if (@poss_students) { - my %possibles; - foreach my $item (@poss_students) { - my ($stuname,$studom) = split(/:/,$item,3); - $possibles{$stuname.':'.$studom} = 1; - } - my ($sections,$groups,$group_display,$disabled) = §ions_and_groups(); - my ($classlist,undef,$fullname,$pbinfo) = - &getclasslist($sections,'1',$groups,'','','',$chosen,\%possibles); - if ((ref($classlist) eq 'HASH') && (ref($pbinfo) eq 'HASH')) { - my %passback = %{$pbinfo}; - my (%tosend,%remotenotok,%scorenotok,%zeroposs,%nopbinfo); - foreach my $possible (keys(%possibles)) { - if ((exists($classlist->{$possible})) && - (exists($passback{$possible})) && (ref($passback{$possible}) eq 'ARRAY')) { - $tosend{$possible} = 1; - } - } - if (keys(%tosend)) { - my ($lti_in_use,$crsdef); - my ($ltinum,$ltitype) = ($linkprotector =~ /^(\d+)(c|d)$/); - if ($ltitype eq 'c') { - my %crslti = &Apache::lonnet::get_course_lti($cnum,$cdom,'provider'); - $lti_in_use = $crslti{$ltinum}; - $crsdef = 1; - } else { - my %domlti = &Apache::lonnet::get_domain_lti($cdom,'linkprot'); - $lti_in_use = $domlti{$ltinum}; - } - if (ref($lti_in_use) eq 'HASH') { - my $msgformat = $lti_in_use->{'passbackformat'}; - my $keynum = $lti_in_use->{'cipher'}; - my $scoretype = 'decimal'; - if ($lti_in_use->{'scoreformat'} =~ /^(decimal|ratio|percentage)$/) { - $scoretype = $1; - } - my $pbmap; - if ($launchsymb =~ /\.(page|sequence)$/) { - $pbmap = &Apache::lonnet::deversion((&Apache::lonnet::decode_symb($launchsymb))[2]); - } else { - $pbmap = &Apache::lonnet::deversion((&Apache::lonnet::decode_symb($launchsymb))[0]); - } - $pbmap = &Apache::lonnet::clutter($pbmap); - my $pbscope; - if ($scope eq 'res') { - $pbscope = 'resource'; - } elsif ($scope eq 'map') { - $pbscope = 'nonrec'; - } elsif ($scope eq 'rec') { - $pbscope = 'map'; - } - my %pb = &common_passback_info(); - my $numstudents = scalar(keys(%tosend)); - my %prog_state = &Apache::lonhtmlcommon::Create_PrgWin($request,$numstudents); - my $outcome = &Apache::loncommon::start_data_table(). - &Apache::loncommon::start_data_table_header_row(); - my $loop = 0; - while ($loop < 2) { - $outcome .= ''.&mt('No.').''. - ''.&nameUserString('header').' '.&mt('Section/Group').''. - ''.&mt('Score').''; - $loop++; - } - $outcome .= &Apache::loncommon::end_data_table_header_row()."\n"; - my $ctr=0; - foreach my $student (sort - { - if (lc($$fullname{$a}) ne lc($$fullname{$b})) { - return (lc($$fullname{$a}) cmp lc($$fullname{$b})); - } - return $a cmp $b; - } (keys(%$fullname))) { - next unless ($tosend{$student}); - my ($uname,$udom) = split(/:/,$student); - &Apache::lonhtmlcommon::Increment_PrgWin($request,\%prog_state,'last student'); - my ($uname,$udom) = split(/:/,$student); - my $uhome = &Apache::lonnet::homeserver($uname,$udom), - my $id = $passback{$student}[0], - my $url = $passback{$student}[1], - my ($total,$possible,$usec); - if (ref($classlist->{$student}) eq 'ARRAY') { - $usec = $classlist->{$student}->[&Apache::loncoursedata::CL_SECTION]; - } - if ($pbscope eq 'resource') { - $total = 0; - $possible = 0; - my $navmap = Apache::lonnavmaps::navmap->new($uname,$udom); - if (ref($navmap)) { - my $res = $navmap->getBySymb($launchsymb); - if (ref($res)) { - my $partlist = $res->parts(); - if (ref($partlist) eq 'ARRAY') { - my %record = &Apache::lonnet::restore($launchsymb,$env{'request.course.id'},$udom,$uname); - foreach my $part (@{$partlist}) { - next if ($record{"resource.$part.solved"} =~/^excused/); - my $weight = &Apache::lonnet::EXT("resource.$part.weight",$launchsymb,$udom,$uname,$usec); - $possible += $weight; - if (($record{'version'}) && (exists($record{"resource.$part.awarded"}))) { - my $awarded = $record{"resource.$part.awarded"}; - if ($awarded) { - $total += $weight * $awarded; - } - } - } - } - } - } - } elsif (($pbscope eq 'map') || ($pbscope eq 'nonrec')) { - ($total,$possible) = - &Apache::lonhomework::get_lti_score($uname,$udom,$usec,$pbmap,$pbscope); - } - if (($id ne '') && ($url ne '') && ($possible)) { - my ($sent,$score,$code,$result) = - &LONCAPA::ltiutils::send_grade($cdom,$cnum,$crsdef,$pb{'type'},$ltinum,$keynum,$id, - $url,$scoretype,$pb{'sigmethod'},$msgformat,$total,$possible); - my $no_passback; - if ($sent) { - if ($code == 200) { - delete($tosend{$student}); - my $namespace = $cdom.'_'.$cnum.'_lp_passback'; - my $store = { - 'score' => $score, - 'ip' => $pb{'ip'}, - 'host' => $pb{'lonhost'}, - 'protector' => $linkprotector, - 'deeplink' => $linkuri, - 'scope' => $scope, - 'url' => $url, - 'id' => $id, - 'clientip' => $pb{'clientip'}, - 'whodoneit' => $env{'user.name'}.':'.$env{'user.domain'}, - }; - my $value=''; - foreach my $key (keys(%{$store})) { - $value.=&escape($key).'='.&Apache::lonnet::freeze_escape($store->{$key}).'&'; - } - $value=~s/\&$//; - &Apache::lonnet::courselog(&escape($linkuri).':'.$uname.':'.$udom.':EXPORT:'.$value); - &Apache::lonnet::store_userdata({'score' => $score},$chosen,$namespace,$udom,$uname,$pb{'ip'}); - $ctr++; - if ($ctr%2 ==1) { - $outcome .= &Apache::loncommon::start_data_table_row(); - } - my $group = $classlist->{$student}->[&Apache::loncoursedata::CL_GROUP()]; - $outcome .= ''.$ctr.' '. - ''.&nameUserString(undef,$$fullname{$student},$uname,$udom). - ' '.$usec.($group ne '' ?'/'.$group:'').''. - ''.$score.''."\n"; - if ($ctr%2 ==0) { - $outcome .= &Apache::loncommon::end_data_table_row()."\n"; - } - } else { - $remotenotok{$student} = 1; - $no_passback = "Passback response for ".$linkprotector." was $code ($result)"; - &Apache::lonnet::logthis($no_passback." for $uname:$udom in ${cdom}_${cnum}"); - } - } else { - $scorenotok{$student} = 1; - $no_passback = "Passback of grades not sent for ".$linkprotector; - &Apache::lonnet::logthis($no_passback." for $uname:$udom in ${cdom}_${cnum}"); - } - if ($no_passback) { - &Apache::lonnet::log($udom,$uname,$uhome,$no_passback." score: $score; total: $total; possible: $possible"); - my $key = &Time::HiRes::time().':'.$uname.':'.$udom.':'. - "$linkuri\0$linkprotector\0$scope"; - my $ltigrade = { - $key => { - 'ltinum' => $ltinum, - 'lti' => $lti_in_use, - 'crsdef' => $crsdef, - 'cid' => $cdom.'_'.$cnum, - 'uname' => $uname, - 'udom' => $udom, - 'uhome' => $uhome, - 'pbid' => $id, - 'pburl' => $url, - 'pbtype' => $pb{'type'}, - 'pbscope' => $pbscope, - 'pbmap' => $pbmap, - 'pbsymb' => $launchsymb, - 'format' => $scoretype, - 'scope' => $scope, - 'clientip' => $pb{'clientip'}, - 'linkprot' => $linkprotector.':'.$linkuri, - 'total' => $total, - 'possible' => $possible, - 'score' => $score, - }, - }; - &Apache::lonnet::put('linkprot_passback_pending',$ltigrade,$cdom,$cnum); - } - } else { - if (($id ne '') && ($url ne '')) { - $zeroposs{$student} = 1; - } else { - $nopbinfo{$student} = 1; - } - } - } - &Apache::lonhtmlcommon::Close_PrgWin($request,\%prog_state); - if ($ctr%2 ==1) { - $outcome .= &Apache::loncommon::end_data_table_row(); - } - $outcome .= &Apache::loncommon::end_data_table(); - if ($ctr) { - $request->print('


'.&mt('Scores sent to launcher CMS').'

'. - '

'.$outcome.'

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

'.&mt('No scores sent to launcher CMS').'

'); - } - if (keys(%tosend)) { - $request->print('

'.&mt('No scores sent for following')); - my ($zeros,$nopbcreds,$noconfirm,$noscore); - foreach my $student (sort - { - if (lc($$fullname{$a}) ne lc($$fullname{$b})) { - return (lc($$fullname{$a}) cmp lc($$fullname{$b})); - } - return $a cmp $b; - } (keys(%$fullname))) { - next unless ($tosend{$student}); - my ($uname,$udom) = split(/:/,$student); - my $line = '

  • '.&nameUserString(undef,$$fullname{$student},$uname,$udom).'
  • '."\n"; - if ($zeroposs{$student}) { - $zeros .= $line; - } elsif ($nopbinfo{$student}) { - $nopbcreds .= $line; - } elsif ($remotenotok{$student}) { - $noconfirm .= $line; - } elsif ($scorenotok{$student}) { - $noscore .= $line; - } - } - if ($zeros) { - $request->print('
    '.&mt('Total points possible was 0').':'. - '
    '); - } - if ($nopbcreds) { - $request->print('
    '.&mt('Missing unique identifier and/or passback location').':'. - '
    '); - } - if ($noconfirm) { - $request->print('
    '.&mt('Score receipt not confirmed by receiving CMS').':'. - '
    '); - } - if ($noscore) { - $request->print('
    '.&mt('Score computation or transmission failed').':'. - '
    '); - } - $request->print('

    '); - } - } else { - $error = &mt('Settings for deep-link launch target unavailable, so no scores were sent'); - } - } else { - $error = &mt('No available students for whom scores can be sent.'); - } - } else { - $error = &mt('Classlist could not be retrieved so no scores were sent.'); - } - } else { - $error = &mt('No students selected to receive scores so none were sent.'); - } - } else { - if ($env{'form.passback'}) { - $error = &mt('Deep-link launch target was invalid so no scores were sent.'); - } else { - $error = &mt('Deep-link launch target was missing so no scores were sent.'); - } - } - } else { - $error = &mt('You do not have permission to manage grades, so no scores were sent'); - } - if ($error) { - $request->print('

    '.$error.'

    '); - } - return; -} - -sub get_passback_launcher { - my ($cdom,$cnum,$chosen) = @_; - my ($linkuri,$linkprotector,$scope) = split("\0",$chosen); - my ($ltinum,$ltitype) = ($linkprotector =~ /^(\d+)(c|d)$/); - my ($appname,$setter); - if ($ltitype eq 'c') { - my %lti = &Apache::lonnet::get_course_lti($cnum,$cdom,'provider'); - if (ref($lti{$ltinum}) eq 'HASH') { - $appname = $lti{$ltinum}{'name'}; - if ($appname) { - $setter = ' (defined in course)'; - } - } - } elsif ($ltitype eq 'd') { - my %lti = &Apache::lonnet::get_domain_lti($cdom,'linkprot'); - if (ref($lti{$ltinum}) eq 'HASH') { - $appname = $lti{$ltinum}{'name'}; - if ($appname) { - $setter = ' (defined in domain)'; - } - } - } - my $launchsymb = &Apache::loncommon::symb_from_tinyurl($linkuri,$cnum,$cdom); - if ($launchsymb eq '') { - my %passback = &Apache::lonnet::dump('nohist_linkprot_passback',$cdom,$cnum); - foreach my $poss_symb (keys(%passback)) { - if (ref($passback{$poss_symb}) eq 'HASH') { - if (exists($passback{$poss_symb}{$chosen})) { - $launchsymb = $poss_symb; - last; - } - } - } - if ($launchsymb ne '') { - return ($launchsymb,$appname,$setter); - } - } else { - my %passback = &Apache::lonnet::get('nohist_linkprot_passback',[$launchsymb],$cdom,$cnum); - if (ref($passback{$launchsymb}) eq 'HASH') { - if (exists($passback{$launchsymb}{$chosen})) { - return ($launchsymb,$appname,$setter); - } - } - } - return (); -} - -sub sections_and_groups { - my (@sections,@groups,$group_display); - @groups = &Apache::loncommon::get_env_multiple('form.group'); - if (grep(/^all$/,@groups)) { - @groups = ('all'); - $group_display = 'all'; - } elsif (grep(/^none$/,@groups)) { - @groups = ('none'); - $group_display = 'none'; - } elsif (@groups > 0) { - $group_display = join(', ',@groups); - } - if ($env{'request.course.sec'} ne '') { - @sections = ($env{'request.course.sec'}); - } else { - @sections = &Apache::loncommon::get_env_multiple('form.section'); - } - my $disabled = ' disabled="disabled"'; - if ($perm{'mgr'}) { - if (grep(/^all$/,@sections)) { - undef($disabled); - } else { - foreach my $sec (@sections) { - if (&canmodify($sec)) { - undef($disabled); - last; - } - } - } - } - if (grep(/^all$/,@sections)) { - @sections = ('all'); - } - return(\@sections,\@groups,$group_display,$disabled); -} - -sub launcher_info_box { - my ($launcher,$appname,$setter,$linkuri,$scope) = @_; - my $shownscope; - if ($scope eq 'res') { - $shownscope = &mt('Resource'); - } elsif ($scope eq 'map') { - $shownscope = &mt('Folder'); - } elsif ($scope eq 'rec') { - $shownscope = &mt('Folder + sub-folders'); - } - return '

    '. - &Apache::lonhtmlcommon::start_pick_box(). - &Apache::lonhtmlcommon::row_title(&mt('Launch Item Title')). - &Apache::lonnet::gettitle($launcher). - &Apache::lonhtmlcommon::row_closure(). - &Apache::lonhtmlcommon::row_title(&mt('Deep-link')). - $linkuri. - &Apache::lonhtmlcommon::row_closure(). - &Apache::lonhtmlcommon::row_title(&mt('Launcher')). - $appname.' '.$setter. - &Apache::lonhtmlcommon::row_closure(). - &Apache::lonhtmlcommon::row_title(&mt('Score Type')). - $shownscope. - &Apache::lonhtmlcommon::row_closure(1). - &Apache::lonhtmlcommon::end_pick_box().'

    '."\n"; -} - -sub passbacks_for_symb { - my ($cdom,$cnum,$symb) = @_; - my %passback = &Apache::lonnet::dump('nohist_linkprot_passback',$cdom,$cnum); - my %needpb; - if (keys(%passback)) { - my $checkpb = 1; - if (exists($passback{$symb})) { - if (keys(%passback) == 1) { - undef($checkpb); - } - if (ref($passback{$symb}) eq 'HASH') { - foreach my $launcher (keys(%{$passback{$symb}})) { - $needpb{$launcher} = $symb; - } - } - } - if ($checkpb) { - my ($map,$id,$url) = &Apache::lonnet::decode_symb($symb); - my $navmap = Apache::lonnavmaps::navmap->new(); - if (ref($navmap)) { - my $mapres = $navmap->getResourceByUrl($map); - if (ref($mapres)) { - my $mapsymb = $mapres->symb(); - if (exists($passback{$mapsymb})) { - if (keys(%passback) == 1) { - undef($checkpb); - } - if (ref($passback{$mapsymb}) eq 'HASH') { - foreach my $launcher (keys(%{$passback{$mapsymb}})) { - $needpb{$launcher} = $mapsymb; - } - } - } - my %posspb; - if ($checkpb) { - my @recurseup = $navmap->recurseup_maps($map,1); - if (@recurseup) { - map { $posspb{$_} = 1; } @recurseup; - } - } - foreach my $key (keys(%passback)) { - if (exists($posspb{$key})) { - if (ref($passback{$key}) eq 'HASH') { - foreach my $launcher (keys(%{$passback{$key}})) { - my ($linkuri,$linkprotector,$scope) = split("\0",$launcher); - next unless ($scope eq 'rec'); - $needpb{$launcher} = $key; - } - } - } - } - } - } - } - } - return %needpb; -} - -sub process_passbacks { - my ($context,$symbs,$cdom,$cnum,$udom,$uname,$usec,$weights,$awardeds,$excuseds,$needpb, - $skip_passback,$pbsave,$pbids) = @_; - if ((ref($needpb) eq 'HASH') && (ref($skip_passback) eq 'HASH') && (ref($pbsave) eq 'HASH')) { - my (%weight,%awarded,%excused); - if ((ref($symbs) eq 'ARRAY') && (ref($weights) eq 'HASH') && (ref($awardeds) eq 'HASH') && - (ref($excuseds) eq 'HASH')) { - %weight = %{$weights}; - %awarded = %{$awardeds}; - %excused = %{$excuseds}; - } - my $uhome = &Apache::lonnet::homeserver($uname,$udom); - my @launchers = keys(%{$needpb}); - my %pbinfo; - if (ref($pbids) eq 'HASH') { - %pbinfo = %{$pbids}; - } else { - %pbinfo = &Apache::lonnet::get('nohist_'.$cdom.'_'.$cnum.'_linkprot_pb',\@launchers,$udom,$uname); - } - my %pbc = &common_passback_info(); - foreach my $launcher (@launchers) { - if (ref($pbinfo{$launcher}) eq 'ARRAY') { - my $pbid = $pbinfo{$launcher}[0]; - my $pburl = $pbinfo{$launcher}[1]; - my (%total_by_symb,%possible_by_symb); - if (($pbid ne '') && ($pburl ne '')) { - next if ($skip_passback->{$launcher}); - my %pb = %pbc; - if ((exists($pbsave->{$launcher})) && - (ref($pbsave->{$launcher}) eq 'HASH')) { - foreach my $item ('lti_in_use','crsdef','ltinum','keynum','scoretype','msgformat', - 'symb','map','pbscope','linkuri','linkprotector','scope') { - $pb{$item} = $pbsave->{$launcher}{$item}; - } - } else { - my $ltitype; - ($pb{'linkuri'},$pb{'linkprotector'},$pb{'scope'}) = split("\0",$launcher); - ($pb{'ltinum'},$ltitype) = ($pb{'linkprotector'} =~ /^(\d+)(c|d)$/); - if ($ltitype eq 'c') { - my %crslti = &Apache::lonnet::get_course_lti($cnum,$cdom,'provider'); - $pb{'lti_in_use'} = $crslti{$pb{'ltinum'}}; - $pb{'crsdef'} = 1; - } else { - my %domlti = &Apache::lonnet::get_domain_lti($cdom,'linkprot'); - $pb{'lti_in_use'} = $domlti{$pb{'ltinum'}}; - } - if (ref($pb{'lti_in_use'}) eq 'HASH') { - $pb{'msgformat'} = $pb{'lti_in_use'}->{'passbackformat'}; - $pb{'keynum'} = $pb{'lti_in_use'}->{'cipher'}; - $pb{'scoretype'} = 'decimal'; - if ($pb{'lti_in_use'}->{'scoreformat'} =~ /^(decimal|ratio|percentage)$/) { - $pb{'scoretype'} = $1; - } - $pb{'symb'} = $needpb->{$launcher}; - if ($pb{'symb'} =~ /\.(page|sequence)$/) { - $pb{'map'} = &Apache::lonnet::deversion((&Apache::lonnet::decode_symb($pb{'symb'}))[2]); - } else { - $pb{'map'} = &Apache::lonnet::deversion((&Apache::lonnet::decode_symb($pb{'symb'}))[0]); - } - $pb{'map'} = &Apache::lonnet::clutter($pb{'map'}); - if ($pb{'scope'} eq 'res') { - $pb{'pbscope'} = 'resource'; - } elsif ($pb{'scope'} eq 'map') { - $pb{'pbscope'} = 'nonrec'; - } elsif ($pb{'scope'} eq 'rec') { - $pb{'pbscope'} = 'map'; - } - foreach my $item ('lti_in_use','crsdef','ltinum','keynum','scoretype','msgformat', - 'symb','map','pbscope','linkuri','linkprotector','scope') { - $pbsave->{$launcher}{$item} = $pb{$item}; - } - } else { - $skip_passback->{$launcher} = 1; - } - } - if (ref($symbs) eq 'ARRAY') { - foreach my $symb (@{$symbs}) { - if ((ref($weight{$symb}) eq 'HASH') && (ref($awarded{$symb}) eq 'HASH') && - (ref($excused{$symb}) eq 'HASH')) { - foreach my $part (keys(%{$weight{$symb}})) { - if ($excused{$symb}{$part}) { - next; - } - my $partweight = $weight{$symb}{$part} eq '' ? 1 : - $weight{$symb}{$part}; - if ($awarded{$symb}{$part}) { - $total_by_symb{$symb} += $partweight * $awarded{$symb}{$part}; - } - $possible_by_symb{$symb} += $partweight; - } - } - } - } - if ($context eq 'updatebypage') { - my $ltigrade = { - 'ltinum' => $pb{'ltinum'}, - 'lti' => $pb{'lti_in_use'}, - 'crsdef' => $pb{'crsdef'}, - 'cid' => $cdom.'_'.$cnum, - 'uname' => $uname, - 'udom' => $udom, - 'uhome' => $uhome, - 'usec' => $usec, - 'pbid' => $pbid, - 'pburl' => $pburl, - 'pbtype' => $pb{'type'}, - 'pbscope' => $pb{'pbscope'}, - 'pbmap' => $pb{'map'}, - 'pbsymb' => $pb{'symb'}, - 'format' => $pb{'scoretype'}, - 'scope' => $pb{'scope'}, - 'clientip' => $pb{'clientip'}, - 'linkprot' => $pb{'linkprotector'}.':'.$pb{'linkuri'}, - 'total_s' => \%total_by_symb, - 'possible_s' => \%possible_by_symb, - }; - push(@Apache::grades::ltipassback,$ltigrade); - next; - } - my ($total,$possible); - if ($pb{'pbscope'} eq 'resource') { - $total = $total_by_symb{$pb{'symb'}}; - $possible = $possible_by_symb{$pb{'symb'}}; - } elsif (($pb{'pbscope'} eq 'map') || ($pb{'pbscope'} eq 'nonrec')) { - ($total,$possible) = - &Apache::lonhomework::get_lti_score($uname,$udom,$usec,$pb{'map'},$pb{'pbscope'}, - \%total_by_symb,\%possible_by_symb); - } - if (!$possible) { - $total = 0; - $possible = 1; - } - my ($sent,$score,$code,$result) = - &LONCAPA::ltiutils::send_grade($cdom,$cnum,$pb{'crsdef'},$pb{'type'},$pb{'ltinum'}, - $pb{'keynum'},$pbid,$pburl,$pb{'scoretype'},$pb{'sigmethod'}, - $pb{'msgformat'},$total,$possible); - my $no_passback; - if ($sent) { - if ($code == 200) { - my $namespace = $cdom.'_'.$cnum.'_lp_passback'; - my $store = { - 'score' => $score, - 'ip' => $pb{'ip'}, - 'host' => $pb{'lonhost'}, - 'protector' => $pb{'linkprotector'}, - 'deeplink' => $pb{'linkuri'}, - 'scope' => $pb{'scope'}, - 'url' => $pburl, - 'id' => $pbid, - 'clientip' => $pb{'clientip'}, - 'whodoneit' => $env{'user.name'}.':'.$env{'user.domain'}, - }; - my $value=''; - foreach my $key (keys(%{$store})) { - $value.=&escape($key).'='.&Apache::lonnet::freeze_escape($store->{$key}).'&'; - } - $value=~s/\&$//; - &Apache::lonnet::courselog(&escape($pb{'linkuri'}).':'.$uname.':'.$udom.':EXPORT:'.$value); - &Apache::lonnet::store_userdata({'score' => $score},$launcher,$namespace,$udom,$uname,$pb{'ip'}); - } else { - $no_passback = 1; - } - } else { - $no_passback = 1; - } - if ($no_passback) { - &Apache::lonnet::log($udom,$uname,$uhome,$no_passback." score: $score; total: $total; possible: $possible"); - my $ltigrade = { - 'ltinum' => $pb{'ltinum'}, - 'lti' => $pb{'lti_in_use'}, - 'crsdef' => $pb{'crsdef'}, - 'cid' => $cdom.'_'.$cnum, - 'uname' => $uname, - 'udom' => $udom, - 'uhome' => $uhome, - 'pbid' => $pbid, - 'pburl' => $pburl, - 'pbtype' => $pb{'type'}, - 'pbscope' => $pb{'pbscope'}, - 'pbmap' => $pb{'map'}, - 'pbsymb' => $pb{'symb'}, - 'format' => $pb{'scoretype'}, - 'scope' => $pb{'scope'}, - 'clientip' => $pb{'clientip'}, - 'linkprot' => $pb{'linkprotector'}.':'.$pb{'linkuri'}, - 'total' => $total, - 'possible' => $possible, - 'score' => $score, - }; - &Apache::lonnet::put('linkprot_passback_pending',$ltigrade,$cdom,$cnum); - } - } - } - } - } - return; -} - -sub common_passback_info { - my %pbc = ( - sigmethod => 'HMAC-SHA1', - type => 'linkprot', - clientip => &Apache::lonnet::get_requestor_ip(), - lonhost => $Apache::lonnet::perlvar{'lonHostID'}, - ip => &Apache::lonnet::get_host_ip($Apache::lonnet::perlvar{'lonHostID'}), - ); - return %pbc; -} - #--- This is called by a number of programs. #--- Called from the Grading Menu - View/Grade an individual student #--- Also called directly when one clicks on the subm button @@ -1939,7 +1037,6 @@ sub common_passback_info { sub listStudents { my ($request,$symb,$submitonly,$divforres) = @_; - my $is_tool = ($symb =~ /ext\.tool$/); my $cdom = $env{"course.$env{'request.course.id'}.domain"}; my $cnum = $env{"course.$env{'request.course.id'}.num"}; my $getsec = $env{'form.section'} eq '' ? 'all' : $env{'form.section'}; @@ -1963,8 +1060,34 @@ sub listStudents { } } - $request->print(&checkselect_js()); + my %js_lt = &Apache::lonlocal::texthash ( + 'multiple' => 'Please select a student or group of students before clicking on the Next button.', + 'single' => 'Please select the student before clicking on the Next button.', + ); + &js_escape(\%js_lt); $request->print(&Apache::lonhtmlcommon::scripttag(< 1) { + for (var i=0; i '.&mt('no').' '."\n" - .''."\n" - .'
    '."\n" - .&Apache::lonhtmlcommon::row_closure(); - $gradeTable .= &Apache::lonhtmlcommon::row_title(&mt('View Answer')) - .''."\n" - .''."\n" - .'
    '."\n" - .&Apache::lonhtmlcommon::row_closure(); - } + $gradeTable .= &Apache::lonhtmlcommon::row_title(&mt('View Problem Text')) + .''."\n" + .''."\n" + .'
    '."\n" + .&Apache::lonhtmlcommon::row_closure(); + $gradeTable .= &Apache::lonhtmlcommon::row_title(&mt('View Answer')) + .''."\n" + .''."\n" + .'
    '."\n" + .&Apache::lonhtmlcommon::row_closure(); my $stu_status = join(':',&Apache::loncommon::get_env_multiple('form.Status')); my $saveStatus = $stu_status eq '' ? 'Active' : $stu_status; $env{'form.Status'} = $saveStatus; - my %optiontext; - if ($is_tool) { - %optiontext = &Apache::lonlocal::texthash ( - lastonly => 'last transaction', - last => 'last transaction with details', - datesub => 'all transactions', - all => 'all transactions with details', - ); - } else { - %optiontext = &Apache::lonlocal::texthash ( + my %optiontext = &Apache::lonlocal::texthash ( lastonly => 'last submission', last => 'last submission with details', datesub => 'all submissions', all => 'all submissions with details', ); - } my $submission_options = ''. '