--- loncom/homework/structuretags.pm 2019/11/07 02:58:37 1.570 +++ loncom/homework/structuretags.pm 2023/09/10 18:12:53 1.578 @@ -1,7 +1,7 @@ # The LearningOnline Network with CAPA # definition of tags that give a structure to a document # -# $Id: structuretags.pm,v 1.570 2019/11/07 02:58:37 raeburn Exp $ +# $Id: structuretags.pm,v 1.578 2023/09/10 18:12:53 raeburn Exp $ # # Copyright Michigan State University Board of Trustees # @@ -62,7 +62,9 @@ use Apache::lonxml; use Apache::londefdef; use Apache::lonenc(); use Apache::loncommon(); +use Apache::lonnavmaps; use Time::HiRes qw( gettimeofday tv_interval ); +use HTML::Entities(); use lib '/home/httpd/lib/perl/'; use LONCAPA; @@ -341,7 +343,7 @@ var keypresshandled = 0; var postsubmit = '$postsubmit'; \$(document).ready(function(){ - if (postsubmit != 'off') { + if (postsubmit != 'off') { \$(document).keypress(function(event){ var keycode = (event.keyCode ? event.keyCode : event.which); if ((keycode == '13') && (keypresshandled == 0)) { @@ -552,11 +554,20 @@ sub page_start { && $env{'request.state'} eq 'construct') { if ($target eq 'web' || $target eq 'edit') { unless ($env{'form.inhibitmenu'} eq 'yes') { + my $text = 'Authoring Space'; + my $href = &Apache::loncommon::authorspace($env{'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 = &mt('Course Authoring Space'); + } + } # Breadcrumbs for Authoring Space &Apache::lonhtmlcommon::clear_breadcrumbs(); &Apache::lonhtmlcommon::add_breadcrumb({ - 'text' => 'Authoring Space', - 'href' => &Apache::loncommon::authorspace($env{'request.uri'}), + 'text' => $text, + 'href' => $href, }); # breadcrumbs (and tools) will be created # in start_page->bodytag->innerregister @@ -624,7 +635,9 @@ sub page_start { my ($symb,$courseid,$udom,$uname)=&Apache::lonnet::whichuser(); my ($path,$multiresp) = &Apache::loncommon::get_turnedin_filepath($symb,$uname,$udom); - if (($is_task) || ($needs_upload)) { + if ($env{'request.user_in_effect'}) { + $form_tag_start .= ' onsubmit="preventDefault();"'; + } elsif (($is_task) || ($needs_upload)) { $form_tag_start .= ' onsubmit="return file_submission_check(this,'."'$path','$multiresp'".');"'; } $form_tag_start.='>'."\n"; @@ -718,7 +731,7 @@ sub setup_rndseed { $env{'form.rndseed'}=$rndseed; } } - if ((($env{'request.state'} eq "construct") || ($symb eq '')) && + if ((($env{'request.state'} eq "construct") || ($symb eq '')) && ($Apache::lonhomework::type eq 'randomizetry')) { if ($numtries) { if (($reqtries =~ /^\d+$/) && ($reqtries > 1)) { @@ -1088,7 +1101,7 @@ sub initialize_storage { } %Apache::lonhomework::history= &Apache::lonnet::tmprestore($namespace,'',$domain,$name); - my ($temp)=keys(%Apache::lonhomework::history) ; + my ($temp)=keys(%Apache::lonhomework::history); &Apache::lonxml::debug("Return message of $temp"); } else { %Apache::lonhomework::history= @@ -1111,13 +1124,13 @@ sub initialize_storage { &check_correctness_changes() is called in two circumstances in which the results hash is to be stored permanently, for grading triggered by a student's submission, where feedback on - correctness is to be provided to the student. + correctness is to be provided to the student. 1. Immediately prior to storing the results hash - To handle the case where a student's submission (and award) were + To handle the case where a student's submission (and award) were stored after history was retrieved in &initialize_storage(), e.g., - if a student submitted answers in quick succession (e.g., from + if a student submitted answers in quick succession (e.g., from multiple tabs). &Apache::inputtags::hidealldata() is called for any parts with out-of-order storage (i.e., correct then incorrect, where awarded >= 1 when correct). @@ -1127,12 +1140,12 @@ sub initialize_storage { To handle the case where lond on the student's homeserver returns delay:N -- where N is the number of transactions between the last retrieved in &initialize_storage() and the last stored immediately - before permanent storage of the current transaction via - lond::store_handler(). &Apache::grades::makehidden() is called + before permanent storage of the current transaction via + lond::store_handler(). &Apache::grades::makehidden() is called for any parts with out-of-order storage (i.e., correct then incorrect, where awarded >= 1 when correct). - Will call &store_aggregates() to increment totals for attempts, + Will call &store_aggregates() to increment totals for attempts, students, and corrects, if running user has student role. =cut @@ -1146,7 +1159,8 @@ sub finalize_storage { delete(@Apache::lonhomework::results{@remove}); my ($symb,$courseid,$domain,$name) = &Apache::lonnet::whichuser($given_symb); - my ($passback,$ltiscope,$ltimap,$ltisymb,$ltiref,$total,$possible,$dopassback); + my ($passback,$pbscope,$pbmap,$pbsymb,$pbtype,$crsdef,$ltinum, + $ltiref,$total,$possible,$dopassback); if ($env{'request.state'} eq 'construct' || $symb eq '' || $Apache::lonhomework::type eq 'practice') { @@ -1160,11 +1174,16 @@ sub finalize_storage { if (($env{'user.name'} eq $name) && ($env{'user.domain'} eq $domain) && (!$Apache::lonhomework::scantronmode) && (!defined($env{'form.grade_symb'})) && (!defined($env{'form.grade_courseid'}))) { - if ($env{'request.lti.login'}) { + if (($env{'request.lti.login'}) || ($env{'request.deeplink.login'})) { my ($map)=&Apache::lonnet::decode_symb($symb); $map = &Apache::lonnet::clutter($map); - ($passback,$ltiscope,$ltimap,$ltisymb,$ltiref) = - &needs_lti_passback($courseid,$symb,$map); + if ($env{'request.lti.login'}) { + ($passback,$pbscope,$pbmap,$pbsymb,$ltinum,$ltiref) = + &needs_lti_passback($courseid,$symb,$map); + } elsif ($env{'request.deeplink.login'}) { + ($passback,$pbscope,$pbmap,$pbsymb,$crsdef,$ltinum,$ltiref) = + &needs_linkprot_passback($courseid,$symb,$map); + } } if ($Apache::lonhomework::history{'version'}) { $laststore = $Apache::lonhomework::history{'version'}.'='. @@ -1261,7 +1280,7 @@ sub finalize_storage { } } } - if (($dopassback) && ($ltiscope eq 'resource') && ($ltisymb eq $symb)) { + if (($dopassback) && ($pbscope eq 'resource') && ($pbsymb eq $symb)) { $total = 0; $possible = 0; my $navmap = Apache::lonnavmaps::navmap->new(); @@ -1302,24 +1321,39 @@ sub finalize_storage { &store_aggregates($symb,$courseid); if ($dopassback) { my $scoreformat = 'decimal'; - if (ref($ltiref) eq 'HASH') { - if ($ltiref->{'scoreformat'} =~ /^(decimal|ratio|percentage)$/) { - $scoreformat = $1; + if (($env{'request.lti.login'}) || ($env{'request.deeplink.login'})) { + if (ref($ltiref) eq 'HASH') { + if ($ltiref->{'scoreformat'} =~ /^(decimal|ratio|percentage)$/) { + $scoreformat = $1; + } } } + my ($pbid,$pburl,$pbtype); + if ($env{'request.lti.login'}) { + $pbid = $env{'request.lti.passbackid'}; + $pburl = $env{'request.lti.passbackurl'}; + $pbtype = 'lti'; + } elsif ($env{'request.deeplink.login'}) { + $pbid = $env{'request.linkprotpbid'}; + $pburl = $env{'request.linkprotpburl'}; + $pbtype = 'linkprot'; + } my $ltigrade = { + 'ltinum' => $ltinum, 'lti' => $ltiref, + 'crsdef' => $crsdef, 'cid' => $courseid, 'uname' => $env{'user.name'}, 'udom' => $env{'user.domain'}, - 'pbid' => $env{'request.lti.passbackid'}, - 'pburl' => $env{'request.lti.passbackurl'}, - 'scope' => $ltiscope, - 'ltimap' => $ltimap, - 'ltisymb' => $ltisymb, + 'pbid' => $pbid, + 'pburl' => $pburl, + 'pbtype' => $pbtype, + 'scope' => $pbscope, + 'pbmap' => $pbmap, + 'pbsymb' => $pbsymb, 'format' => $scoreformat, }; - if ($ltiscope eq 'resource') { + if ($pbscope eq 'resource') { $ltigrade->{'total'} = $total; $ltigrade->{'possible'} = $possible; } @@ -1340,6 +1374,7 @@ sub needs_lti_passback { my %lti = &Apache::lonnet::get_domain_lti($cdom,'provider'); if (ref($lti{$env{'request.lti.login'}}) eq 'HASH') { if ($lti{$env{'request.lti.login'}}{'passback'}) { + my $itemnum = $env{'request.lti.login'}; my ($ltiscope,$ltiuri,$ltisymb) = &LONCAPA::ltiutils::lti_provider_scope($env{'request.lti.uri'}, $cdom,$cnum,1); @@ -1358,7 +1393,7 @@ sub needs_lti_passback { $passback = 1; } } - return ($passback,$ltiscope,$ltimap,$ltisymb,$lti{$env{'request.lti.login'}}); + return ($passback,$ltiscope,$ltimap,$ltisymb,$itemnum,$lti{$itemnum}); } } } @@ -1366,18 +1401,71 @@ sub needs_lti_passback { return; } +sub needs_linkprot_passback { + my ($courseid,$symb,$map) = @_; + if (($env{'request.linkprotpbid'}) && ($env{'request.linkprotpburl'})) { + if ($courseid =~ /^($LONCAPA::match_domain)_($LONCAPA::match_courseid)$/) { + my ($cdom,$cnum) = ($1,$2); + my ($deeplink_symb,$deeplink_map,$deeplink,$passback); + $deeplink_symb = &Apache::loncommon::deeplink_login_symb($cnum,$cdom); + if ($deeplink_symb) { + if ($deeplink_symb =~ /\.(page|sequence)$/) { + $deeplink_map = &Apache::lonnet::deversion((&Apache::lonnet::decode_symb($deeplink_symb))[2]); + my $navmap = Apache::lonnavmaps::navmap->new(); + if (ref($navmap)) { + $deeplink = $navmap->get_mapparam(undef,$deeplink_map,'0.deeplink'); + } + } else { + $deeplink = &Apache::lonnet::EXT('resource.0.deeplink',$deeplink_symb); + $deeplink_map = &Apache::lonnet::deversion((&Apache::lonnet::decode_symb($deeplink_symb))[0]); + } + if (($deeplink ne '') && ($env{'request.linkprot'} ne '')) { + my ($itemid,$tinyurl) = split(/:/,$env{'request.linkprot'}); + if ($itemid =~ /^(\d+)(c|d)$/) { + my ($itemnum,$itemtype) = ($1,$2); + my ($crsdef,$lti_in_use); + if ($itemtype eq 'c') { + $crsdef = 1; + my %crslti = &Apache::lonnet::get_course_lti($cnum,$cdom,'provider'); + $lti_in_use = $crslti{$itemnum}; + } else { + my %domlti = &Apache::lonnet::get_domain_lti($cdom,'linkprot'); + $lti_in_use = $domlti{$itemnum}; + } + my ($state,$others,$listed,$scope,$protect,$display,$target,$exit) = split(/,/,$deeplink); + my $passback; + if ($scope eq 'resource') { + if ($deeplink_symb eq $symb) { + $passback = 1; + } + } elsif ($scope eq 'map') { + if (&Apache::lonnet::clutter($deeplink_map) eq $map) { + $passback = 1; + } + } elsif ($scope eq 'recurse') { +#FIXME check if $deeplink_map contains $map + $passback = 1; + } + return ($passback,$scope,$deeplink_map,$deeplink_symb,$crsdef,$itemnum,$lti_in_use); + } + } + } + } + } +} + =pod =item check_correctness_changes() For all parts for which current results contain a solved status - of "incorrect_attempted", check if there was a transaction in which - solved was set to "correct_by_student" in the time since the last - transaction (retrieved when &initialize_storage() was called i.e., + of "incorrect_attempted", check if there was a transaction in which + solved was set to "correct_by_student" in the time since the last + transaction (retrieved when &initialize_storage() was called i.e., when &start_problem() was called), unless: (a) questiontype parameter is set to survey or anonymous survey (+/- credit) (b) problemstatus is set to no or no_feedback_ever - If such a transaction exists, and did not occur after "reset status" + If such a transaction exists, and did not occur after "reset status" by a user with grading privileges, then the current transaction is an example of an out-of-order transaction (i.e., incorrect occurring after correct). Accordingly, the current transaction should be hidden. @@ -1646,9 +1734,11 @@ sub firstaccess_msg { my $uri = &Apache::lonenc::check_encrypt($env{'request.uri'}); my $buttontext = &mt('Show Resource'); my $timertext = &mt('Start Timer?'); + my $shownsymb = &HTML::Entities::encode(&Apache::lonenc::check_encrypt($symb),'\'"<>&'); $result .= (< + ENDCHECKOUT @@ -1842,6 +1932,11 @@ sub start_problem { } } + if (($target eq 'web') && ($env{'request.user_in_effect'})) { + &Apache::lonxml::get_all_text("/problem",$parser,$style); + return $result; + } + if ($target eq 'web' || $target eq 'grade' || $target eq 'answer' || $target eq 'tex') { @@ -2126,6 +2221,12 @@ sub end_problem { } } $result =~ s/INSERTTEXFRONTMATTERHERE/$frontmatter/; + } elsif ($target eq 'web') { + if ($env{'request.user_in_effect'}) { + &reset_problem_globals('problem'); + $result .= &Apache::lonhtmlcommon::set_compute_end_time(); + return $result; + } } my $status=$Apache::inputtags::status['-1']; @@ -2272,7 +2373,8 @@ ENDJS # computation: # if ($target eq 'web') { - $result .= &Apache::lonhtmlcommon::set_compute_end_time(); + $result .= &Apache::lonhtmlcommon::dash_to_minus_js(). + &Apache::lonhtmlcommon::set_compute_end_time(); # # Closing tags delayed so any tags # not in head can appear inside body, for valid xhtml. @@ -3104,7 +3206,11 @@ sub end_part { $gradestatus=''; } $result.=$gradestatus; - if ($$tagstack[-2] eq 'td' and $target eq 'tex') {$result.='\end{minipage}';} + if ($$tagstack[-2] eq 'td' and $target eq 'tex') { + if (not $env{'form.problem_split'}=~/yes/) { + $result.='\end{minipage}'; + } + } } elsif ($target eq 'edit') { $result.=&Apache::edit::end_table(); } elsif ($target eq 'modified') {