version 1.344.2.8.4.1, 2017/06/21 19:55:00
|
version 1.344.2.10.4.5, 2024/01/13 12:31:32
|
Line 49 use Apache::matchresponse();
|
Line 49 use Apache::matchresponse();
|
use Apache::chemresponse(); |
use Apache::chemresponse(); |
use Apache::functionplotresponse(); |
use Apache::functionplotresponse(); |
use Apache::drawimage(); |
use Apache::drawimage(); |
|
use Apache::loncourseuser(); |
|
use Apache::grades(); |
use Apache::Constants qw(:common); |
use Apache::Constants qw(:common); |
use Apache::loncommon(); |
use Apache::loncommon(); |
|
use Apache::lonparmset(); |
|
use Apache::lonnavmaps(); |
use Apache::lonlocal; |
use Apache::lonlocal; |
|
use LONCAPA qw(:DEFAULT :match); |
|
use LONCAPA::ltiutils(); |
use Time::HiRes qw( gettimeofday tv_interval ); |
use Time::HiRes qw( gettimeofday tv_interval ); |
use HTML::Entities(); |
use HTML::Entities(); |
use File::Copy(); |
use File::Copy(); |
|
|
# FIXME - improve commenting |
# FIXME - improve commenting |
|
|
|
my $registered_cleanup; |
|
|
BEGIN { |
BEGIN { |
&Apache::lonxml::register_insert(); |
&Apache::lonxml::register_insert(); |
Line 188 sub proctor_checked_in {
|
Line 195 sub proctor_checked_in {
|
if ($type eq 'Task') { |
if ($type eq 'Task') { |
my $version=$Apache::lonhomework::history{'resource.0.version'}; |
my $version=$Apache::lonhomework::history{'resource.0.version'}; |
$key ="resource.$version.0.checkedin"; |
$key ="resource.$version.0.checkedin"; |
} elsif ($type eq 'problem') { |
} elsif (($type eq 'problem') || ($type eq 'tool')) { |
$key ='resource.0.checkedin'; |
$key ='resource.0.checkedin'; |
} |
} |
# backward compatability, used to be username@domain, |
# backward compatability, used to be username@domain, |
Line 203 sub proctor_checked_in {
|
Line 210 sub proctor_checked_in {
|
return 1; |
return 1; |
} |
} |
} |
} |
|
|
return 0; |
return 0; |
} |
} |
|
|
Line 212 sub check_slot_access {
|
Line 218 sub check_slot_access {
|
|
|
# does it pass normal muster |
# does it pass normal muster |
my ($status,$datemsg)=&check_access($id,$symb); |
my ($status,$datemsg)=&check_access($id,$symb); |
|
|
my $useslots = &Apache::lonnet::EXT("resource.0.useslots",$symb); |
my $useslots = &Apache::lonnet::EXT("resource.0.useslots",$symb); |
if ($useslots ne 'resource' && $useslots ne 'map' |
if ($useslots ne 'resource' && $useslots ne 'map' |
&& $useslots ne 'map_map') { |
&& $useslots ne 'map_map') { |
Line 235 sub check_slot_access {
|
Line 241 sub check_slot_access {
|
$Apache::lonhomework::history{"resource.$version.0.status"} eq 'pass') { |
$Apache::lonhomework::history{"resource.$version.0.status"} eq 'pass') { |
return ('SHOW_ANSWER'); |
return ('SHOW_ANSWER'); |
} |
} |
|
} elsif (($type eq 'problem') && |
|
($Apache::lonhomework::browse eq 'F') && |
|
($ENV{'REMOTE_ADDR'} eq '127.0.0.1') && |
|
($env{'form.grade_courseid'} eq $env{'request.course.id'}) && |
|
(&Apache::lonnet::allowed('mgr',$env{'request.course.id'}))) { |
|
return ($status,$datemsg); |
} |
} |
|
|
my $availablestudent = &Apache::lonnet::EXT("resource.0.availablestudent",$symb); |
my $availablestudent = &Apache::lonnet::EXT("resource.0.availablestudent",$symb); |
Line 286 sub check_slot_access {
|
Line 298 sub check_slot_access {
|
|| $Apache::lonhomework::history{"resource.0.solved"} =~ /^correct_/ ); |
|| $Apache::lonhomework::history{"resource.0.solved"} =~ /^correct_/ ); |
$checkedin = |
$checkedin = |
$Apache::lonhomework::history{"resource.$version.0.checkedin"}; |
$Apache::lonhomework::history{"resource.$version.0.checkedin"}; |
} elsif ($type eq 'problem') { |
} elsif (($type eq 'problem') || ($type eq 'tool')) { |
$checkin = 'resource.0.checkedin'; |
$checkin = 'resource.0.checkedin'; |
$checkedin = $Apache::lonhomework::history{$checkin}; |
$checkedin = $Apache::lonhomework::history{$checkin}; |
} |
} |
Line 295 sub check_slot_access {
|
Line 307 sub check_slot_access {
|
my %slot=&Apache::lonnet::get_slot($checkinslot); |
my %slot=&Apache::lonnet::get_slot($checkinslot); |
$consumed_uniq = $slot{'uniqueperiod'}; |
$consumed_uniq = $slot{'uniqueperiod'}; |
} |
} |
if ($type eq 'problem') { |
if (($type eq 'problem') || ($type eq 'tool')) { |
if ((ref($partlist) eq 'ARRAY') && (@{$partlist} > 0)) { |
if ((ref($partlist) eq 'ARRAY') && (@{$partlist} > 0)) { |
my ($numcorrect,$numgraded) = (0,0); |
my ($numcorrect,$numgraded) = (0,0); |
foreach my $part (@{$partlist}) { |
foreach my $part (@{$partlist}) { |
Line 311 sub check_slot_access {
|
Line 323 sub check_slot_access {
|
$earlyout = 1; |
$earlyout = 1; |
} |
} |
} |
} |
if (($currtries == $maxtries) || ($is_correct)) { |
if ($currtries == $maxtries) { |
$earlyout = 1; |
$earlyout = 1; |
} else { |
} else { |
$numgraded ++; |
$numgraded ++; |
Line 354 sub check_slot_access {
|
Line 366 sub check_slot_access {
|
# However, the problem is not closed, and potentially, another slot might be |
# However, the problem is not closed, and potentially, another slot might be |
# used to gain access to it to work on it, until the due date is reached, and the |
# used to gain access to it to work on it, until the due date is reached, and the |
# problem then becomes CLOSED. Therefore return the slotstatus - |
# problem then becomes CLOSED. Therefore return the slotstatus - |
# (which will be one of: NOT_IN_A_SLOT, RESERVABLE, RESERVABLE_LATER, or NOTRESERVABLE. |
# (which will be one of: NOT_IN_A_SLOT, RESERVABLE, RESERVABLE_LATER, or NOTRESERVABLE). |
if (!defined($slot_name) && $type eq 'problem') { |
|
|
if (!defined($slot_name) && (($type eq 'problem') || ($type eq 'tool'))) { |
if ($slotstatus eq 'NOT_IN_A_SLOT') { |
if ($slotstatus eq 'NOT_IN_A_SLOT') { |
if (!$num_usable_slots) { |
if (!$num_usable_slots) { |
if ($env{'request.course.id'}) { |
if ($env{'request.course.id'}) { |
Line 439 sub check_slot_access {
|
Line 452 sub check_slot_access {
|
} |
} |
|
|
if ( $is_correct) { |
if ( $is_correct) { |
if ($type eq 'problem') { |
if (($type eq 'problem') || ($type eq 'tool')) { |
return ($status); |
return ($status); |
} |
} |
return ('SHOW_ANSWER'); |
return ('SHOW_ANSWER'); |
Line 710 sub setuppermissions {
|
Line 723 sub setuppermissions {
|
$env{'request.course.sec'} !~ /^\s*$/) { |
$env{'request.course.sec'} !~ /^\s*$/) { |
$viewgrades = &Apache::lonnet::allowed('vgr',$env{'request.course.id'}. |
$viewgrades = &Apache::lonnet::allowed('vgr',$env{'request.course.id'}. |
'/'.$env{'request.course.sec'}); |
'/'.$env{'request.course.sec'}); |
|
if ($viewgrades) { |
|
$Apache::lonhomework::viewgradessec = $env{'request.course.sec'}; |
|
} |
} |
} |
$Apache::lonhomework::viewgrades = $viewgrades; |
$Apache::lonhomework::viewgrades = $viewgrades; |
|
|
Line 727 sub setuppermissions {
|
Line 743 sub setuppermissions {
|
$modifygrades = |
$modifygrades = |
&Apache::lonnet::allowed('mgr',$env{'request.course.id'}. |
&Apache::lonnet::allowed('mgr',$env{'request.course.id'}. |
'/'.$env{'request.course.sec'}); |
'/'.$env{'request.course.sec'}); |
|
if ($modifygrades) { |
|
$Apache::lonhomework::modifygradessec = $env{'request.course.sec'}; |
|
} |
} |
} |
$Apache::lonhomework::modifygrades = $modifygrades; |
$Apache::lonhomework::modifygrades = $modifygrades; |
|
|
Line 745 sub setuppermissions {
|
Line 764 sub setuppermissions {
|
sub unset_permissions { |
sub unset_permissions { |
undef($Apache::lonhomework::queuegrade); |
undef($Apache::lonhomework::queuegrade); |
undef($Apache::lonhomework::modifygrades); |
undef($Apache::lonhomework::modifygrades); |
|
undef($Apache::lonhomework::modifygradessec); |
undef($Apache::lonhomework::viewgrades); |
undef($Apache::lonhomework::viewgrades); |
|
undef($Apache::lonhomework::viewgradessec); |
undef($Apache::lonhomework::browse); |
undef($Apache::lonhomework::browse); |
} |
} |
|
|
Line 844 STATE
|
Line 865 STATE
|
|
|
sub analyze_header { |
sub analyze_header { |
my ($request) = @_; |
my ($request) = @_; |
my $js = &Apache::structuretags::setmode_javascript(); |
my $js = &Apache::lonxml::setmode_javascript(); |
|
|
# Breadcrumbs |
# Breadcrumbs |
my $brcrum = [{'href' => &Apache::loncommon::authorspace($request->uri), |
my $brcrum = [{'href' => &Apache::loncommon::authorspace($request->uri), |
Line 1056 sub editxmlmode {
|
Line 1077 sub editxmlmode {
|
|
|
$problem=''; |
$problem=''; |
} |
} |
|
|
if (($env{'form.problemmode'} eq 'saveeditxml') || |
if (($env{'form.problemmode'} eq 'saveeditxml') || |
($env{'form.problemmode'} eq 'saveviewxml') || |
($env{'form.problemmode'} eq 'saveviewxml') || |
($env{'form.problemmode'} eq 'undoxml')) { |
($env{'form.problemmode'} eq 'undoxml')) { |
my $error=&handle_save_or_undo($request,\$problem, |
my $error=&handle_save_or_undo($request,\$problem, |
\$env{'form.editxmltext'}); |
\$env{'form.editxmltext'}); |
Line 1077 sub editxmlmode {
|
Line 1097 sub editxmlmode {
|
my $js = |
my $js = |
&Apache::edit::js_change_detection(). |
&Apache::edit::js_change_detection(). |
&Apache::loncommon::resize_textarea_js(). |
&Apache::loncommon::resize_textarea_js(). |
&Apache::structuretags::setmode_javascript(). |
&Apache::lonxml::setmode_javascript(). |
&Apache::lonhtmlcommon::dragmath_js("EditMathPopup"); |
&Apache::lonhtmlcommon::dragmath_js("EditMathPopup"); |
|
|
# Breadcrumbs |
# Breadcrumbs |
Line 1194 sub editxmlmode {
|
Line 1214 sub editxmlmode {
|
# Render the page in whatever target desired. |
# Render the page in whatever target desired. |
# |
# |
sub renderpage { |
sub renderpage { |
my ($request,$file,$targets,$return_string) = @_; |
my ($request,$file,$targets,$return_string,$donebuttonmsg,$viewasuser,$symb) = @_; |
|
|
my @targets = @{$targets || [&get_target()]}; |
my @targets = @{$targets || [&get_target()]}; |
&Apache::lonhomework::showhashsubset(\%env,'form.'); |
&Apache::lonhomework::showhashsubset(\%env,'form.'); |
Line 1233 sub renderpage {
|
Line 1253 sub renderpage {
|
if ($target eq 'answer') { &showhash(%Apache::lonhomework::history); } |
if ($target eq 'answer') { &showhash(%Apache::lonhomework::history); } |
if ($target eq 'web') {&Apache::lonhomework::showhashsubset(\%env,'^form');} |
if ($target eq 'web') {&Apache::lonhomework::showhashsubset(\%env,'^form');} |
|
|
|
if (($target eq 'web') && ($viewasuser ne '') && ($symb ne '')) { |
|
$env{'request.user_in_effect'} = $viewasuser; |
|
} |
|
|
&Apache::lonxml::debug("Should be parsing now"); |
&Apache::lonxml::debug("Should be parsing now"); |
$result .= &Apache::lonxml::xmlparse($request, $target, $problem, |
$result .= &Apache::lonxml::xmlparse($request, $target, $problem, |
&setup_vars($target),%mystyle); |
&setup_vars($target),%mystyle); |
Line 1245 sub renderpage {
|
Line 1269 sub renderpage {
|
if ($target eq 'analyze') { |
if ($target eq 'analyze') { |
$result=&Apache::lonnet::hashref2str(\%Apache::lonhomework::analyze); |
$result=&Apache::lonnet::hashref2str(\%Apache::lonhomework::analyze); |
undef(%Apache::lonhomework::analyze); |
undef(%Apache::lonhomework::analyze); |
|
} elsif ($target eq 'web') { |
|
if ($donebuttonmsg) { |
|
$result =~ s{</body>}{}; |
|
$result.= &Apache::loncommon::confirmwrapper(&Apache::lonhtmlcommon::confirm_success($donebuttonmsg,1))."\n</body>"; |
|
} |
} |
} |
#my $td=&tv_interval($t0); |
#my $td=&tv_interval($t0); |
#if ( $Apache::lonxml::debug) { |
#if ( $Apache::lonxml::debug) { |
Line 1253 sub renderpage {
|
Line 1282 sub renderpage {
|
#} |
#} |
# $request->print($result); |
# $request->print($result); |
$overall_result.=$result; |
$overall_result.=$result; |
|
if (($target eq 'web') && ($viewasuser ne '') && ($symb ne '')) { |
|
my ($vuname,$vudom) = split(/:/,$viewasuser); |
|
$overall_result .= &Apache::grades::view_as_user($symb,$vuname,$vudom). |
|
'</body></html>'; |
|
} |
# $request->rflush(); |
# $request->rflush(); |
} |
} |
|
if (($target eq 'web') && ($viewasuser ne '') && ($symb ne '')) { |
|
undef($env{'request.user_in_effect'}); |
|
} |
#$request->print(":Result ends"); |
#$request->print(":Result ends"); |
#my $td=&tv_interval($t0); |
#my $td=&tv_interval($t0); |
} |
} |
if (!$return_string) { |
if (!$return_string) { |
&Apache::lonxml::add_messages(\$overall_result); |
&Apache::lonxml::add_messages(\$overall_result); |
$request->print($overall_result); |
$request->print($overall_result); |
$request->rflush(); |
$request->rflush(); |
} else { |
} else { |
return $overall_result; |
return $overall_result; |
} |
} |
Line 1272 sub finished_parsing {
|
Line 1309 sub finished_parsing {
|
undef($Apache::lonhomework::parsing_a_task); |
undef($Apache::lonhomework::parsing_a_task); |
} |
} |
|
|
|
|
# function extracted from get_template_html |
# function extracted from get_template_html |
# returns "key" -> list |
# returns "key" -> list |
# key: path of template |
# key: path of template |
Line 1468 sub update_construct_style {
|
Line 1504 sub update_construct_style {
|
sub zero_timer { |
sub zero_timer { |
my ($symb) = @_; |
my ($symb) = @_; |
my ($hastimeleft,$first_access,$now); |
my ($hastimeleft,$first_access,$now); |
my @interval=&Apache::lonnet::EXT("resource.0.interval"); |
my @interval=&Apache::lonnet::EXT("resource.0.interval",$symb); |
if (@interval > 1) { |
if (@interval > 1) { |
if ($interval[1] eq 'course') { |
if ($interval[1] eq 'course') { |
return; |
return ('fail',&mt('Ending of timed events not supported for intervals set course-wide')); |
} else { |
} else { |
my $now = time; |
my $now = time; |
my $first_access=&Apache::lonnet::get_first_access($interval[1],$symb); |
my $first_access=&Apache::lonnet::get_first_access($interval[1],$symb); |
if ($first_access > 0) { |
if ($first_access > 0) { |
if ($first_access+$interval[0] > $now) { |
my ($timelimit,$donesuffix) = split(/_/,$interval[0],2); |
my $done_time = $now - $first_access; |
if ($donesuffix =~ /^done(?:|\:[^\:]+\:)(.*)$/) { |
my $snum = 1; |
my ($dummy,$proctor,$secret) = split(/_/,$1); |
if ($interval[1] eq 'map') { |
if (($proctor) && ($secret ne '')) { |
$snum = 2; |
my $key = $env{'form.LC_interval_done_proctorpass'}; |
|
$key =~ s/^\s+//; |
|
$key =~ s/\s+$//; |
|
if ($env{'form.LC_interval_done_proctorpass'} ne $secret) { |
|
return ('fail', |
|
&mt('Incorrect key entered by proctor')); |
|
} |
} |
} |
my $result = |
if ($first_access+$timelimit > $now) { |
&Apache::lonparmset::storeparm_by_symb_inner($symb,'0_interval', |
my $done_time = $now - $first_access; |
$snum,$done_time, |
my $snum = 1; |
'date_interval', |
if ($interval[1] eq 'map') { |
$env{'user.name'}, |
$snum = 2; |
$env{'user.domain'}); |
} |
return $result; |
my $result = |
|
&Apache::lonparmset::storeparm_by_symb_inner($symb,'0_interval', |
|
$snum,$done_time, |
|
'date_interval', |
|
$env{'user.name'}, |
|
$env{'user.domain'}); |
|
if ($result eq '') { |
|
# Record action in "User Notes" |
|
&Apache::lonmsg::store_instructor_comment( |
|
'Pressed Done button for symb:<br />'.$symb, |
|
$env{'user.name'}, $env{'user.domain'}); |
|
return ('ok'); |
|
} else { |
|
return ('fail',&mt('Error ending timed event: [_1]',$result)); |
|
} |
|
} else { |
|
return ('fail',&mt('Timed event already ended')); |
|
} |
|
} else { |
|
return ('fail',&mt('Timed event can not be ended before the time limit')); |
} |
} |
|
} else { |
|
return ('fail',&mt('Timer not yet started for this timed event')); |
} |
} |
} |
} |
|
} else { |
|
return ('fail',&mt('No timer in use')); |
} |
} |
return; |
return(); |
} |
} |
|
|
sub handler { |
sub handler { |
Line 1507 sub handler {
|
Line 1572 sub handler {
|
my $file=&Apache::lonnet::filelocation("",$request->uri); |
my $file=&Apache::lonnet::filelocation("",$request->uri); |
|
|
#check if we know where we are |
#check if we know where we are |
if ($env{'request.course.fn'} && !&Apache::lonnet::symbread('','',1,1)) { |
if ($env{'request.course.fn'} && !&Apache::lonnet::symbread('','',1,1)) { |
# if we are browsing we might not be able to know where we are |
# if we are browsing we might not be able to know where we are |
if ($Apache::lonhomework::browse ne 'F' && |
if ($Apache::lonhomework::browse ne 'F' && |
$env{'request.state'} ne "construct") { |
$env{'request.state'} ne "construct") { |
#should know where we are, so ask |
#should know where we are, so ask |
&unset_permissions(); |
&unset_permissions(); |
Line 1521 sub handler {
|
Line 1586 sub handler {
|
&unset_permissions(); |
&unset_permissions(); |
return OK; |
return OK; |
} |
} |
|
|
&Apache::lonxml::debug("Permissions:$Apache::lonhomework::browse:$Apache::lonhomework::viewgrades:$Apache::lonhomework::modifygrades:$Apache::lonhomework::queuegrade"); |
&Apache::lonxml::debug("Permissions:$Apache::lonhomework::browse:$Apache::lonhomework::viewgrades:$Apache::lonhomework::modifygrades:$Apache::lonhomework::queuegrade"); |
&Apache::lonxml::debug("Problem Mode ".$env{'form.problemmode'}); |
&Apache::lonxml::debug("Problem Mode ".$env{'form.problemmode'}); |
my ($symb) = &Apache::lonnet::whichuser(); |
my ($symb) = &Apache::lonnet::whichuser(); |
Line 1552 sub handler {
|
Line 1618 sub handler {
|
} |
} |
} else { |
} else { |
# Set the event timer to zero if the "done button" was clicked. The button is |
# Set the event timer to zero if the "done button" was clicked. The button is |
# part of the LCdoneButton form created in lonmenu.pm |
# part of the doneButton form created in lonmenu.pm |
|
my ($donebuttonresult,$donemsg,$viewasuser); |
if ($symb && $env{'form.LC_interval_done'} eq 'true') { |
if ($symb && $env{'form.LC_interval_done'} eq 'true') { |
&zero_timer($symb); |
($donebuttonresult,$donemsg) = &zero_timer($symb); |
undef($env{'form.LC_interval_done'}); |
undef($env{'form.LC_interval_done'}); |
|
undef($env{'form.LC_interval_done_proctorpass'}); |
|
} |
|
if (($env{'form.LC_viewas'} ne '') && $symb && $env{'request.course.id'} && |
|
($Apache::lonhomework::viewgrades || $Apache::lonhomework::modifygrades)) { |
|
if ($env{'form.LC_viewas'} =~ /^($match_username):($match_domain)$/) { |
|
my ($possuname,$possudom) = ($1,$2); |
|
my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'}; |
|
my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'}; |
|
my ($canview,$posssec); |
|
if ($env{'request.course.sec'} ne '') { |
|
if ($Apache::lonhomework::modifygradessec eq $env{'request.course.sec'}) { |
|
$canview = 'section'; |
|
$posssec = $env{'request.course.sec'}; |
|
} elsif ($Apache::lonhomework::viewgradessec eq $env{'request.course.sec'}) { |
|
$canview = 'section'; |
|
$posssec = $env{'request.course.sec'}; |
|
} |
|
} |
|
my $crstype = &Apache::loncommon::course_type(); |
|
if (&Apache::loncourseuser::is_course_user($possudom,$possuname,$cdom,$cnum, |
|
$canview,$crstype,$posssec)) { |
|
$viewasuser = $possuname.':'.$possudom; |
|
} |
|
} |
|
undef($env{'form.LC_viewas'}); |
} |
} |
# just render the page normally outside of construction space |
# just render the page normally outside of construction space |
&Apache::lonxml::debug("not construct"); |
&Apache::lonxml::debug("not construct"); |
&renderpage($request,$file); |
undef(@Apache::lonhomework::ltipassback); |
|
&renderpage($request,$file,undef,undef,$donemsg,$viewasuser,$symb); |
|
if (@Apache::lonhomework::ltipassback) { |
|
unless ($registered_cleanup) { |
|
my $handlers = $request->get_handlers('PerlCleanupHandler'); |
|
$request->set_handlers('PerlCleanupHandler' => |
|
[\&do_ltipassback,@{$handlers}]); |
|
} |
|
} |
} |
} |
#my $td=&tv_interval($t0); |
#my $td=&tv_interval($t0); |
#&Apache::lonxml::debug("Spent $td seconds processing"); |
#&Apache::lonxml::debug("Spent $td seconds processing"); |
Line 1706 sub helpmenu_datastructure {
|
Line 1806 sub helpmenu_datastructure {
|
|
|
# filename, title, width, height |
# filename, title, width, height |
my $helpers = [ |
my $helpers = [ |
['Problem_LON-CAPA_Function.hlp', &mt('Script Functions'), 800, 600], |
['Problem_LON-CAPA_Functions.hlp', &mt('Script Functions'), 800, 600], |
['Greek_Symbols.hlp', &mt('Greek Symbols'), 500, 600], |
['Greek_Symbols.hlp', &mt('Greek Symbols'), 500, 600], |
['Other_Symbols.hlp', &mt('Other Symbols'), 500, 600], |
['Other_Symbols.hlp', &mt('Other Symbols'), 500, 600], |
['Authoring_Output_Tags.hlp', &mt('Output Tags'), 800, 600], |
['Authoring_Output_Tags.hlp', &mt('Output Tags'), 800, 600], |
Line 1744 sub convert_for_js {
|
Line 1844 sub convert_for_js {
|
return $return; |
return $return; |
} |
} |
|
|
|
sub do_ltipassback { |
|
if (@Apache::lonhomework::ltipassback) { |
|
foreach my $item (@Apache::lonhomework::ltipassback) { |
|
if (ref($item) eq 'HASH') { |
|
if ((ref($item->{'lti'}) eq 'HASH') && ($item->{'cid'} =~ /^($match_domain)_($match_courseid)$/)) { |
|
my ($cdom,$cnum) = ($1,$2); |
|
my $msgformat = $item->{'lti'}->{'passbackformat'}; |
|
my $sigmethod = 'HMAC-SHA1'; |
|
my $ltinum = $item->{'ltinum'}; |
|
my $id = $item->{'pbid'}; |
|
my $url = $item->{'pburl'}; |
|
my $type = $item->{'pbtype'}; |
|
my $scope = $item->{'scope'}; |
|
my $map = $item->{'ltimap'}; |
|
my $symb = $item->{'ltisymb'}; |
|
my $uname = $item->{'uname'}; |
|
my $udom = $item->{'udom'}; |
|
my $keynum = $item->{'lti'}->{'cipher'}; |
|
my $crsdef = $item->{'crsdef'}; |
|
my $scoretype = $item->{'format'}; |
|
my ($total,$possible); |
|
if ($scope eq 'resource') { |
|
$total = $item->{'total'}; |
|
$possible = $item->{'possible'}; |
|
} elsif (($scope eq 'map') || ($scope eq 'nonrec')) { |
|
($total,$possible) = &get_lti_score($uname,$udom,$map,$scope); |
|
} elsif ($scope eq 'course') { |
|
($total,$possible) = &get_lti_score($uname,$udom); |
|
} |
|
if (($id ne '') && ($url ne '') && ($possible)) { |
|
&LONCAPA::ltiutils::send_grade($cdom,$cnum,$crsdef,$type,$ltinum,$keynum,$id,$url,$scoretype,$sigmethod,$msgformat,$total,$possible); |
|
} |
|
} |
|
} |
|
} |
|
undef(@Apache::lonhomework::ltipassback); |
|
} |
|
} |
|
|
|
sub get_lti_score { |
|
my ($uname,$udom,$mapurl,$scope) = @_; |
|
my $navmap = Apache::lonnavmaps::navmap->new($uname,$udom); |
|
if (ref($navmap)) { |
|
my $iterator; |
|
if ($mapurl ne '') { |
|
my $map = $navmap->getResourceByUrl($mapurl); |
|
my $firstres = $map->map_start(); |
|
my $finishres = $map->map_finish(); |
|
my $recursive = 1; |
|
if ($scope eq 'nonrec') { |
|
$recursive = 0; |
|
} |
|
$iterator = $navmap->getIterator($firstres,$finishres,undef,$recursive); |
|
} else { |
|
$iterator = $navmap->getIterator(undef,undef,undef,1); |
|
} |
|
if (ref($iterator)) { |
|
my $depth = 1; |
|
my $total = 0; |
|
my $possible = 0; |
|
$iterator->next(); # ignore first BEGIN_MAP |
|
my $curRes = $iterator->next(); |
|
while ( $depth > 0 ) { |
|
if ($curRes == $iterator->BEGIN_MAP()) {$depth++;} |
|
if ($curRes == $iterator->END_MAP()) { $depth--; } |
|
if (ref($curRes) && $curRes->is_gradable() && !$curRes->randomout) { |
|
my $parts = $curRes->parts(); |
|
foreach my $part (@{$parts}) { |
|
next if ($curRes->solved($part) eq 'excused'); |
|
$total += $curRes->weight($part) * $curRes->awarded($part); |
|
$possible += $curRes->weight($part); |
|
} |
|
} |
|
$curRes = $iterator->next(); |
|
} |
|
if ($total > $possible) { |
|
$total = $possible; |
|
} |
|
return ($total,$possible); |
|
} |
|
} |
|
return; |
|
} |
|
|
1; |
1; |
__END__ |
__END__ |