version 1.374, 2018/09/20 14:16:51
|
version 1.393, 2025/01/05 22:42:44
|
Line 50 use Apache::chemresponse();
|
Line 50 use Apache::chemresponse();
|
use Apache::functionplotresponse(); |
use Apache::functionplotresponse(); |
use Apache::drawimage(); |
use Apache::drawimage(); |
use Apache::loncapamath(); |
use Apache::loncapamath(); |
|
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::lonparmset(); |
Line 161 sub get_target {
|
Line 163 sub get_target {
|
return ('web','answer'); |
return ('web','answer'); |
} elsif (($env{'form.problemmode'} eq 'saveedit') || |
} elsif (($env{'form.problemmode'} eq 'saveedit') || |
($env{'form.problemmode'} eq 'undo')) { |
($env{'form.problemmode'} eq 'undo')) { |
return ('modified','no_output_web','edit'); |
my %editors = &Apache::loncommon::permitted_editors(); |
|
if ($editors{'edit'}) { |
|
return ('modified','no_output_web','edit'); |
|
} else { |
|
return ('web'); |
|
} |
} elsif ($env{'form.problemmode'} eq 'edit') { |
} elsif ($env{'form.problemmode'} eq 'edit') { |
return ('no_output_web','edit'); |
my %editors = &Apache::loncommon::permitted_editors(); |
|
if ($editors{'edit'}) { |
|
return ('no_output_web','edit'); |
|
} else { |
|
return ('web'); |
|
} |
} else { |
} else { |
return ('web'); |
return ('web'); |
} |
} |
Line 369 sub check_slot_access {
|
Line 381 sub check_slot_access {
|
my $probstatus = &Apache::structuretags::get_problem_status($part); |
my $probstatus = &Apache::structuretags::get_problem_status($part); |
my $earlyout; |
my $earlyout; |
unless (($probstatus eq 'no') || |
unless (($probstatus eq 'no') || |
($probstatus eq 'no_feedback_ever')) { |
($probstatus eq 'no_feedback_ever')) { |
if ($Apache::lonhomework::history{"resource.$part.solved"} =~/^correct_/) { |
if ($Apache::lonhomework::history{"resource.$part.solved"} =~/^correct_/) { |
$numcorrect ++; |
$numcorrect ++; |
} else { |
} else { |
Line 378 sub check_slot_access {
|
Line 390 sub check_slot_access {
|
} |
} |
if ($currtries == $maxtries) { |
if ($currtries == $maxtries) { |
$earlyout = 1; |
$earlyout = 1; |
} else { |
} else { |
$numgraded ++; |
$numgraded ++; |
} |
} |
last if ($earlyout); |
last if ($earlyout); |
Line 795 sub setuppermissions {
|
Line 807 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 812 sub setuppermissions {
|
Line 827 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 830 sub setuppermissions {
|
Line 848 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 929 STATE
|
Line 949 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 $text = 'Authoring Space'; |
'text' => 'Authoring Space'}, |
my $href = &Apache::loncommon::authorspace($request->uri); |
|
if ($env{'request.course.id'}) { |
|
my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'}; |
|
my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'}; |
|
if ($href eq "/priv/$cdom/$cnum/") { |
|
$text = 'Course Authoring Space'; |
|
} |
|
} |
|
my $brcrum = [{'href' => $href, |
|
'text' => $text}, |
{'href' => '', |
{'href' => '', |
'text' => 'Problem Testing'}, |
'text' => 'Problem Testing'}, |
{'href' => '', |
{'href' => '', |
Line 945 sub analyze_header {
|
Line 974 sub analyze_header {
|
{'bread_crumbs' => $brcrum,}) |
{'bread_crumbs' => $brcrum,}) |
.&Apache::loncommon::head_subbox( |
.&Apache::loncommon::head_subbox( |
&Apache::loncommon::CSTR_pageheader()); |
&Apache::loncommon::CSTR_pageheader()); |
|
my %lt = &Apache::lonlocal::texthash( |
|
edit => 'Edit', |
|
editxml => 'EditXML', |
|
); |
$result .= |
$result .= |
'<form name="lonhomework" method="post" action="'. |
'<form name="lonhomework" method="post" action="'. |
&HTML::Entities::encode($env{'request.uri'},'<>&"').'">'. |
&HTML::Entities::encode($env{'request.uri'},'<>&"').'">'. |
'<input type="hidden" name="problemmode" value="'. |
'<input type="hidden" name="problemmode" value="'. |
$env{'form.problemmode'}.'" />'. |
$env{'form.problemmode'}.'" />'. |
&Apache::structuretags::remember_problem_state().' |
&Apache::structuretags::remember_problem_state().' |
<div class="LC_edit_problem_analyze_header"> |
<div class="LC_edit_problem_analyze_header">'; |
<input type="button" name="submitmode" value="'.&mt("EditXML").'" '. |
my %editors = &Apache::loncommon::permitted_editors(); |
'onclick="javascript:setmode(this.form,'."'editxml'".')" /> |
foreach my $item ('editxml','edit') { |
<input type="button" name="submitmode" value="'.&mt('Edit').'" '. |
next unless ($editors{$item}); |
'onclick="javascript:setmode(this.form,'."'edit'".')" /> |
$result .= '<input type="button" name="submitmode" value="'.$lt{$item}.'" '. |
<hr /> |
'onclick="javascript:setmode(this.form,'."'$item'".')" />'. |
|
"\n"; |
|
} |
|
$result .= |
|
'<hr /> |
<input type="button" name="submitmode" value="'.&mt("View").'" '. |
<input type="button" name="submitmode" value="'.&mt("View").'" '. |
'onclick="javascript:setmode(this.form,'."'view'".')" /> |
'onclick="javascript:setmode(this.form,'."'view'".')" /> |
<hr /> |
<hr /> |
Line 1161 sub editxmlmode {
|
Line 1198 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 |
my $brcrum = [{'href' => &Apache::loncommon::authorspace($request->uri), |
my $text = 'Authoring Space'; |
'text' => 'Authoring Space'}, |
my $href = &Apache::loncommon::authorspace($request->uri); |
|
if ($env{'request.course.id'}) { |
|
my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'}; |
|
my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'}; |
|
if ($href eq "/priv/$cdom/$cnum/") { |
|
$text = 'Course Authoring Space'; |
|
} |
|
} |
|
my $brcrum = [{'href' => $href, |
|
'text' => $text}, |
{'href' => '', |
{'href' => '', |
'text' => 'Problem Editing'}]; |
'text' => 'Problem Editing'}]; |
|
|
Line 1199 sub editxmlmode {
|
Line 1245 sub editxmlmode {
|
|
|
$result .= '<ol class="LC_primary_menu" style="display:inline-block;font-size:90%;vertical-align:middle;">'; |
$result .= '<ol class="LC_primary_menu" style="display:inline-block;font-size:90%;vertical-align:middle;">'; |
|
|
unless ($env{'environment.nocodemirror'}) { |
my $nocodemirror = &Apache::loncommon::nocodemirror(); |
|
unless ($nocodemirror) { |
# dropdown menus |
# dropdown menus |
$result .= Apache::lonmenu::create_submenu("#", "", |
$result .= Apache::lonmenu::create_submenu("#", "", |
&mt("Problem Templates"), template_dropdown_datastructure()); |
&mt("Problem Templates"), template_dropdown_datastructure()); |
|
|
$result .= Apache::lonmenu::create_submenu("#", "", |
$result .= Apache::lonmenu::create_submenu("#", "", |
&mt("Response Types"), responseblock_dropdown_datastructure()); |
&mt("Response Types"), responseblock_dropdown_datastructure()); |
|
|
$result .= Apache::lonmenu::create_submenu("#", "", |
$result .= Apache::lonmenu::create_submenu("#", "", |
&mt("Conditional Blocks"), conditional_scripting_datastructure()); |
&mt("Conditional Blocks"), conditional_scripting_datastructure()); |
|
|
$result .= Apache::lonmenu::create_submenu("#", "", |
$result .= Apache::lonmenu::create_submenu("#", "", |
&mt("Miscellaneous"), misc_datastructure()); |
&mt("Miscellaneous"), misc_datastructure()); |
} |
} |
|
|
$result .= Apache::lonmenu::create_submenu("#", "", |
$result .= Apache::lonmenu::create_submenu("#", "", |
&mt("Help") . ' <img src="/adm/help/help.png" alt="' . &mt("Help") . |
&mt("Help") . ' <img src="/adm/help/help.png" alt="' . &mt("Help") . |
'" style="vertical-align:text-bottom; height: auto; margin:0; "/>', |
'" style="vertical-align:text-bottom; height: auto; margin:0; "/>', |
helpmenu_datastructure(),""); |
helpmenu_datastructure(),""); |
|
|
$result.="</ol></div>"; |
$result.="</ol></div>"; |
|
|
$result .= '</div></div>' . |
$result .= '</div></div>' . |
&Apache::lonxml::message_location() . |
&Apache::lonxml::message_location() . |
&Apache::loncommon::xmleditor_js() . |
&Apache::loncommon::xmleditor_js() . |
'<textarea ' . &Apache::edit::element_change_detection() . |
'<textarea ' . &Apache::edit::element_change_detection() . |
Line 1231 sub editxmlmode {
|
Line 1278 sub editxmlmode {
|
'</textarea> <div id="LC_aftertextarea"> </div> </form>'; |
'</textarea> <div id="LC_aftertextarea"> </div> </form>'; |
|
|
my $resource = $env{'request.ambiguous'}; |
my $resource = $env{'request.ambiguous'}; |
unless($env{'environment.nocodemirror'}){ |
unless ($nocodemirror) { |
$result .= '<link rel="stylesheet" href="/adm/codemirror/codemirror-combined-xml.css"> |
$result .= '<link rel="stylesheet" href="/adm/codemirror/codemirror-combined-xml.css"> |
<script src="/adm/codemirror/codemirror-compressed-xml.js"></script> |
<script src="/adm/codemirror/codemirror-compressed-xml.js"></script> |
<script> |
<script> |
Line 1257 sub editxmlmode {
|
Line 1304 sub editxmlmode {
|
autoCloseBrackets: true, |
autoCloseBrackets: true, |
height: "auto", |
height: "auto", |
styleActiveLine: true, |
styleActiveLine: true, |
|
|
extraKeys: { |
extraKeys: { |
"Tab": "indentMore", |
"Tab": "indentMore", |
"Shift-Tab": "indentLess", |
"Shift-Tab": "indentLess", |
Line 1278 sub editxmlmode {
|
Line 1325 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,$donebuttonmsg) = @_; |
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 1319 sub renderpage {
|
Line 1366 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 1344 sub renderpage {
|
Line 1395 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 1371 sub finished_parsing {
|
Line 1430 sub finished_parsing {
|
# value 3: name of help topic ??? |
# value 3: name of help topic ??? |
sub get_template_list{ |
sub get_template_list{ |
my ($extension) = @_; |
my ($extension) = @_; |
|
|
my @files = glob($Apache::lonnet::perlvar{'lonIncludes'}. |
my @files = glob($Apache::lonnet::perlvar{'lonIncludes'}. |
'/templates/*.'.$extension); |
'/templates/*.'.$extension); |
@files = map {[$_,&mt(&Apache::lonnet::metadata($_, 'title')), |
@files = map {[$_,&mt(&Apache::lonnet::metadata($_, 'title')), |
Line 1502 sub newproblem {
|
Line 1561 sub newproblem {
|
my $url=&HTML::Entities::encode($request->uri,'<>&"'); |
my $url=&HTML::Entities::encode($request->uri,'<>&"'); |
my $dest = &Apache::lonnet::filelocation("",$request->uri); |
my $dest = &Apache::lonnet::filelocation("",$request->uri); |
my $instructions; |
my $instructions; |
my $brcrum = [{'href' => &Apache::loncommon::authorspace($request->uri), |
my $text = 'Authoring Space'; |
'text' => 'Authoring Space'}, |
my $href = &Apache::loncommon::authorspace($request->uri); |
|
if ($env{'request.course.id'}) { |
|
my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'}; |
|
my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'}; |
|
if ($href eq "/priv/$cdom/$cnum/") { |
|
$text = 'Course Authoring Space'; |
|
} |
|
} |
|
my $brcrum = [{'href' => $href, |
|
'text' => $text}, |
{'href' => '', |
{'href' => '', |
'text' => "Create New $extension"}]; |
'text' => "Create New $extension"}]; |
my $start_page = |
my $start_page = |
Line 1551 sub update_construct_style {
|
Line 1619 sub update_construct_style {
|
} |
} |
|
|
# |
# |
# Sets interval for current user so time left will be zero, either for the entire folder |
# Sets interval for current user so time left will be zero, either for the entire folder |
# containing the current resource, or just the resource, depending on value of first item |
# containing the current resource, or just the resource, depending on value of first item |
# in interval array retrieved from EXT("resource.0.interval"); |
# in interval array retrieved from EXT("resource.0.interval"); |
# |
# |
Line 1575 sub zero_timer {
|
Line 1643 sub zero_timer {
|
$key =~ s/\s+$//; |
$key =~ s/\s+$//; |
if ($env{'form.LC_interval_done_proctorpass'} ne $secret) { |
if ($env{'form.LC_interval_done_proctorpass'} ne $secret) { |
return ('fail', |
return ('fail', |
&mt('Incorrect key entered by proctor')); |
&mt('Incorrect key entered by proctor')); |
} |
} |
} |
} |
if ($first_access+$timelimit > $now) { |
if ($first_access+$timelimit > $now) { |
Line 1598 sub zero_timer {
|
Line 1666 sub zero_timer {
|
return ('ok'); |
return ('ok'); |
} else { |
} else { |
return ('fail',&mt('Error ending timed event: [_1]',$result)); |
return ('fail',&mt('Error ending timed event: [_1]',$result)); |
} |
} |
} else { |
} else { |
return ('fail',&mt('Timed event already ended')); |
return ('fail',&mt('Timed event already ended')); |
} |
} |
Line 1624 sub handler {
|
Line 1692 sub handler {
|
$env{'request.uri'}=$request->uri; |
$env{'request.uri'}=$request->uri; |
&setuppermissions(); |
&setuppermissions(); |
|
|
|
# -------------------------------------- Flag and buffer for registered cleanup |
|
$registered_cleanup=0; |
|
undef(@Apache::lonhomework::ltipassback); |
|
|
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 1658 sub handler {
|
Line 1730 sub handler {
|
($env{'form.problemmode'} eq 'saveeditxml') || |
($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')) { |
&editxmlmode($request,$file); |
my %editors = &Apache::loncommon::permitted_editors(); |
|
if (($editors{'xml'}) || ($env{'form.problemmode'} eq 'saveviewxml') || ($env{'form.problemmode'} eq 'undoxml')) { |
|
&editxmlmode($request,$file); |
|
} else { |
|
&update_construct_style(); |
|
&renderpage($request,$file); |
|
} |
} elsif ($env{'form.problemmode'} eq 'calcanswers') { |
} elsif ($env{'form.problemmode'} eq 'calcanswers') { |
&analyze($request,$file); |
&analyze($request,$file); |
} else { |
} else { |
Line 1674 sub handler {
|
Line 1752 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 doneButton form created in lonmenu.pm |
# part of the doneButton form created in lonmenu.pm |
my ($donebuttonresult,$donemsg); |
my ($donebuttonresult,$donemsg,$viewasuser); |
if ($symb && $env{'form.LC_interval_done'} eq 'true') { |
if ($symb && $env{'form.LC_interval_done'} eq 'true') { |
($donebuttonresult,$donemsg) = &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'}); |
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"); |
undef(@Apache::lonhomework::ltipassback); |
&renderpage($request,$file,undef,undef,$donemsg,$viewasuser,$symb); |
&renderpage($request,$file,undef,undef,$donemsg); |
|
if (@Apache::lonhomework::ltipassback) { |
if (@Apache::lonhomework::ltipassback) { |
unless ($registered_cleanup) { |
unless ($registered_cleanup) { |
my $handlers = $request->get_handlers('PerlCleanupHandler'); |
my $handlers = $request->get_handlers('PerlCleanupHandler'); |
$request->set_handlers('PerlCleanupHandler' => |
$request->set_handlers('PerlCleanupHandler' => |
[\&do_ltipassback,@{$handlers}]); |
[\&do_ltipassback,@{$handlers}]); |
|
$registered_cleanup=1; |
} |
} |
} |
} |
} |
} |
Line 1880 sub convert_for_js {
|
Line 1982 sub convert_for_js {
|
|
|
sub do_ltipassback { |
sub do_ltipassback { |
if (@Apache::lonhomework::ltipassback) { |
if (@Apache::lonhomework::ltipassback) { |
|
my $lonhost = $Apache::lonnet::perlvar{'lonHostID'}; |
|
my $ip = &Apache::lonnet::get_host_ip($lonhost); |
foreach my $item (@Apache::lonhomework::ltipassback) { |
foreach my $item (@Apache::lonhomework::ltipassback) { |
if (ref($item) eq 'HASH') { |
&Apache::lonhomework::run_passback($item,$lonhost,$ip); |
if ((ref($item->{'lti'}) eq 'HASH') && ($item->{'cid'} =~ /^($match_domain)_($match_courseid)$/)) { |
} |
my ($cdom,$cnum) = ($1,$2); |
undef(@Apache::lonhomework::ltipassback); |
my $ckey = $item->{'lti'}->{'key'}; |
} |
my $secret = $item->{'lti'}->{'secret'}; |
return OK; |
my $msgformat = $item->{'lti'}->{'passbackformat'}; |
} |
my $sigmethod = 'HMAC-SHA1'; |
|
my $id = $item->{'pbid'}; |
sub run_passback { |
my $url = $item->{'pburl'}; |
my ($item,$lonhost,$ip) = @_; |
my $scope = $item->{'scope'}; |
if (ref($item) eq 'HASH') { |
my $map = $item->{'ltimap'}; |
if ((ref($item->{'lti'}) eq 'HASH') && ($item->{'cid'} =~ /^($match_domain)_($match_courseid)$/)) { |
my $symb = $item->{'ltisymb'}; |
my ($cdom,$cnum) = ($1,$2); |
my $uname = $item->{'uname'}; |
my $msgformat = $item->{'lti'}->{'passbackformat'}; |
my $udom = $item->{'udom'}; |
my $sigmethod = 'HMAC-SHA1'; |
my $scoretype = $item->{'format'}; |
my $ltinum = $item->{'ltinum'}; |
my ($total,$possible); |
my $id = $item->{'pbid'}; |
if ($scope eq 'resource') { |
my $url = $item->{'pburl'}; |
|
my $type = $item->{'pbtype'}; |
|
my $pbscope = $item->{'pbscope'}; |
|
my $map = $item->{'pbmap'}; |
|
my $symb = $item->{'pbsymb'}; |
|
my $uname = $item->{'uname'}; |
|
my $udom = $item->{'udom'}; |
|
my $uhome = $item->{'uhome'}; |
|
my $usec = $item->{'usec'}; |
|
my $keynum = $item->{'lti'}->{'cipher'}; |
|
my $crsdef = $item->{'crsdef'}; |
|
my $scoretype = $item->{'format'}; |
|
my $scope = $item->{'scope'}; |
|
my $clientip = $item->{'clientip'}; |
|
my ($total,$possible,%total_by_symb,%possible_by_symb); |
|
if ((exists($item->{'total_s'})) && (ref($item->{'total_s'}) eq 'HASH')) { |
|
%total_by_symb = %{$item->{'total_s'}}; |
|
if ($pbscope eq 'resource') { |
|
if (exists($total_by_symb{$symb})) { |
|
$total = $total_by_symb{$symb}; |
|
} else { |
$total = $item->{'total'}; |
$total = $item->{'total'}; |
|
} |
|
} |
|
} elsif ($pbscope eq 'resource') { |
|
$total = $item->{'total'}; |
|
} |
|
if ((exists($item->{'possible_s'})) && (ref($item->{'possible_s'}) eq 'HASH')) { |
|
%possible_by_symb = %{$item->{'possible_s'}}; |
|
if ($pbscope eq 'resource') { |
|
if (exists($possible_by_symb{$symb})) { |
|
$possible = $possible_by_symb{$symb}; |
|
} else { |
$possible = $item->{'possible'}; |
$possible = $item->{'possible'}; |
} elsif ($scope eq 'map') { |
|
($total,$possible) = &get_lti_score($uname,$udom,$map); |
|
} elsif ($scope eq 'course') { |
|
($total,$possible) = &get_lti_score($uname,$udom); |
|
} |
} |
if (($ckey ne '') && ($secret ne '') && ($id ne '') && ($url ne '') && ($possible)) { |
} |
&LONCAPA::ltiutils::send_grade($id,$url,$ckey,$secret,$scoretype,$sigmethod, |
} elsif ($pbscope eq 'resource') { |
$msgformat,$total,$possible); |
$possible = $item->{'possible'}; |
|
} |
|
if (($pbscope eq 'map') || ($pbscope eq 'nonrec')) { |
|
if ((keys(%total_by_symb)) && (keys(%possible_by_symb))) { |
|
($total,$possible) = |
|
&get_lti_score($uname,$udom,$usec,$map,$pbscope,\%total_by_symb,\%possible_by_symb); |
|
} else { |
|
($total,$possible) = &get_lti_score($uname,$udom,$usec,$map,$pbscope); |
|
} |
|
} elsif ($pbscope eq 'course') { |
|
($total,$possible) = &get_lti_score($uname,$udom,$usec); |
|
} |
|
$item->{'total'} = $total; |
|
$item->{'possible'} = $possible; |
|
if (($id ne '') && ($url ne '') && ($possible)) { |
|
my ($sent,$score,$code,$result) = |
|
&LONCAPA::ltiutils::send_grade($cdom,$cnum,$crsdef,$type,$ltinum,$keynum,$id, |
|
$url,$scoretype,$sigmethod,$msgformat,$total,$possible); |
|
$item->{'score'} = $score; |
|
my ($linkprotector,$linkuri,$no_passback,$appname); |
|
if ($item->{'linkprot'}) { |
|
($linkprotector,$linkuri) = split(/:/,$item->{'linkprot'}); |
|
} |
|
if ($sent) { |
|
if ($code == 200) { |
|
if ($item->{'linkprot'}) { |
|
my $skey = join("\0",($linkuri,$linkprotector,$scope)); |
|
my $namespace = $cdom.'_'.$cnum.'_lp_passback'; |
|
my $store = { |
|
'score' => $score, |
|
'ip' => $ip, |
|
'host' => $Apache::lonnet::perlvar{'lonHostID'}, |
|
'protector' => $linkprotector, |
|
'deeplink' => $linkuri, |
|
'scope' => $scope, |
|
'url' => $url, |
|
'id' => $id, |
|
'clientip' => $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},$skey,$namespace,$udom,$uname,$ip); |
|
} |
|
} else { |
|
if ($item->{'linkprot'}) { |
|
$no_passback = "Passback response was $code ($result)."; |
|
} |
|
} |
|
} else { |
|
if ($item->{'linkprot'}) { |
|
$no_passback = 'No passback of scores.'; |
|
} |
|
} |
|
if ($no_passback) { |
|
if ($item->{'linkprot'}) { |
|
my ($ltinum,$ltitype) = ($linkprotector =~ /^(\d+)(c|d)$/); |
|
if ($ltitype eq 'c') { |
|
my %lti = &Apache::lonnet::get_course_lti($cnum,$cdom,'provider'); |
|
if (ref($lti{$ltinum}) eq 'HASH') { |
|
$appname = $lti{$ltinum}{'name'}; |
|
} |
|
} elsif ($ltitype eq 'd') { |
|
my %lti = &Apache::lonnet::get_domain_lti($cdom,'linkprot'); |
|
if (ref($lti{$ltinum}) eq 'HASH') { |
|
$appname = $lti{$ltinum}{'name'}; |
|
} |
|
} |
|
$no_passback .= " LTI launcher $linkprotector ($appname) for $linkuri (${cdom}_${cnum})"; |
|
&Apache::lonnet::logthis($no_passback." for $uname:$udom"); |
|
&Apache::lonnet::log($udom,$uname,$uhome,"$no_passback score=$score total=$total poss=$possible"); |
|
if ($item->{'linkprot'}) { |
|
my $pendingkey = &Time::HiRes::time().':'.$uname.':'.$udom.':'. |
|
"$linkuri\0$linkprotector\0$scope"; |
|
&Apache::lonnet::put('linkprot_passback_pending',{$pendingkey => $item},$cdom,$cnum); |
|
} |
} |
} |
} |
} |
} |
} |
} |
} |
undef(@Apache::lonhomework::ltipassback); |
|
} |
} |
|
return; |
} |
} |
|
|
sub get_lti_score { |
sub get_lti_score { |
my ($uname,$udom,$mapurl) = @_; |
my ($uname,$udom,$usec,$mapurl,$pbscope,$totals,$possibles) = @_; |
my $navmap = Apache::lonnavmaps::navmap->new($uname,$udom); |
my $navmap = Apache::lonnavmaps::navmap->new($uname,$udom,$usec); |
if (ref($navmap)) { |
if (ref($navmap)) { |
my $iterator; |
my $iterator; |
if ($mapurl ne '') { |
if ($mapurl ne '') { |
my $map = $navmap->getResourceByUrl($mapurl); |
my $map = $navmap->getResourceByUrl($mapurl); |
my $firstres = $map->map_start(); |
my $firstres = $map->map_start(); |
my $finishres = $map->map_finish(); |
my $finishres = $map->map_finish(); |
$iterator = $navmap->getIterator($firstres,$finishres,undef,1); |
my $recursive = 1; |
|
if ($pbscope eq 'nonrec') { |
|
$recursive = 0; |
|
} |
|
$iterator = $navmap->getIterator($firstres,$finishres,undef,$recursive); |
} else { |
} else { |
$iterator = $navmap->getIterator(undef,undef,undef,1); |
$iterator = $navmap->getIterator(undef,undef,undef,1); |
} |
} |
Line 1933 sub get_lti_score {
|
Line 2147 sub get_lti_score {
|
my $depth = 1; |
my $depth = 1; |
my $total = 0; |
my $total = 0; |
my $possible = 0; |
my $possible = 0; |
|
my (%totals_by_symb,%possibles_by_symb); |
|
if (ref($totals) eq 'HASH') { |
|
%totals_by_symb = %{$totals}; |
|
} |
|
if (ref($possibles) eq 'HASH') { |
|
%possibles_by_symb = %{$possibles}; |
|
} |
$iterator->next(); # ignore first BEGIN_MAP |
$iterator->next(); # ignore first BEGIN_MAP |
my $curRes = $iterator->next(); |
my $curRes = $iterator->next(); |
while ( $depth > 0 ) { |
while ( $depth > 0 ) { |
if ($curRes == $iterator->BEGIN_MAP()) {$depth++;} |
if ($curRes == $iterator->BEGIN_MAP()) {$depth++;} |
if ($curRes == $iterator->END_MAP()) { $depth--; } |
if ($curRes == $iterator->END_MAP()) { $depth--; } |
if (ref($curRes) && $curRes->is_gradable() && !$curRes->randomout) { |
if (ref($curRes) && $curRes->is_gradable() && !$curRes->randomout) { |
my $parts = $curRes->parts(); |
my $currsymb = $curRes->symb(); |
foreach my $part (@{$parts}) { |
if (($currsymb) && (exists($totals_by_symb{$currsymb})) && |
next if ($curRes->solved($part) eq 'excused'); |
(exists($possibles_by_symb{$currsymb}))) { |
$total += $curRes->weight($part) * $curRes->awarded($part); |
$total += $totals_by_symb{$currsymb}; |
$possible += $curRes->weight($part); |
$possible += $possibles_by_symb{$currsymb}; |
|
} else { |
|
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(); |
$curRes = $iterator->next(); |