--- loncom/homework/structuretags.pm 2018/03/28 10:29:54 1.512.2.13.4.3
+++ loncom/homework/structuretags.pm 2023/06/04 13:25:21 1.576
@@ -1,7 +1,7 @@
# The LearningOnline Network with CAPA
# definition of tags that give a structure to a document
#
-# $Id: structuretags.pm,v 1.512.2.13.4.3 2018/03/28 10:29:54 raeburn Exp $
+# $Id: structuretags.pm,v 1.576 2023/06/04 13:25:21 raeburn Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -62,12 +62,14 @@ 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;
BEGIN {
- &Apache::lonxml::register('Apache::structuretags',('block','languageblock','translated','instructorcomment','while','randomlist','problem','library','web','tex','part','preduedate','postanswerdate','solved','notsolved','problemtype','startpartmarker','startouttext','endpartmarker','endouttext','simpleeditbutton','definetag'));
+ &Apache::lonxml::register('Apache::structuretags',('block','languageblock','translated','instructorcomment','while','randomlist','problem','library','web','print','tex','part','preduedate','postanswerdate','solved','notsolved','problemtype','startpartmarker','startouttext','endpartmarker','endouttext','simpleeditbutton','definetag'));
}
@@ -192,6 +194,28 @@ sub end_web {
return '';
}
+sub start_print {
+ my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
+ if ($target ne 'edit' && $target ne 'modified') {
+ if ($target ne 'tex') {
+ my $skip = &Apache::lonxml::get_all_text("/print",$parser,$style);
+ &Apache::lonxml::debug("skipping ahead :$skip: $$parser[-1]");
+ }
+ } elsif ($target eq "edit") {
+ my $bodytext = &Apache::lonxml::get_all_text_unbalanced("/print",$parser);
+ my $result = &Apache::edit::tag_start($target,$token);
+ $result .= &Apache::edit::editfield($token->[1],$bodytext,'',80,1);
+ return $result;
+ } elsif ($target eq "modified") {
+ return $token->[4].&Apache::edit::modifiedfield("/print",$parser);
+ }
+ return '';
+}
+
+sub end_print {
+ return '';
+}
+
sub start_tex {
my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
my $result='';
@@ -226,9 +250,11 @@ sub end_tex {
sub homework_js {
my ($postsubmit,$timeout);
if (($env{'request.course.id'}) && ($env{'request.state'} ne 'construct')) {
- my $crstype;
- if (&Apache::loncommon::course_type() eq 'Community') {
+ my $crstype = &Apache::loncommon::course_type();
+ if ($crstype eq 'Community') {
$crstype = 'community';
+ } elsif ($crstype eq 'Placement') {
+ $crstype = 'placement';
} else {
if ($env{'course.'.$env{'request.course.id'}.'.internal.coursecode'}) {
$crstype = 'official';
@@ -270,7 +296,7 @@ sub homework_js {
$jstimeout = 1000 * $timeout;
}
return &Apache::loncommon::resize_textarea_js().
- &Apache::loncommon::colorfuleditor_js().
+ &Apache::loncommon::colorfuleditor_js().
&setmode_javascript().
<<"JS";
';
}
}
@@ -527,23 +553,25 @@ sub page_start {
} elsif (!defined($found{'body'})
&& $env{'request.state'} eq 'construct') {
if ($target eq 'web' || $target eq 'edit') {
- # Breadcrumbs for Authoring Space
- &Apache::lonhtmlcommon::clear_breadcrumbs();
- &Apache::lonhtmlcommon::add_breadcrumb({
- 'text' => 'Authoring Space',
- 'href' => &Apache::loncommon::authorspace($env{'request.uri'}),
- });
- # breadcrumbs (and tools) will be created
- # in start_page->bodytag->innerregister
+ unless ($env{'form.inhibitmenu'} eq 'yes') {
+ # Breadcrumbs for Authoring Space
+ &Apache::lonhtmlcommon::clear_breadcrumbs();
+ &Apache::lonhtmlcommon::add_breadcrumb({
+ 'text' => 'Authoring Space',
+ 'href' => &Apache::loncommon::authorspace($env{'request.uri'}),
+ });
+ # breadcrumbs (and tools) will be created
+ # in start_page->bodytag->innerregister
# FIXME Where are we?
-# &Apache::lonhtmlcommon::add_breadcrumb({
-# 'text' => 'Problem Editing', # 'Problem Testing'
-# 'href' => '',
-# });
- $pageheader =&Apache::loncommon::head_subbox(
- &Apache::loncommon::CSTR_pageheader());
- }
+# &Apache::lonhtmlcommon::add_breadcrumb({
+# 'text' => 'Problem Editing', # 'Problem Testing'
+# 'href' => '',
+# });
+ $pageheader = &Apache::loncommon::head_subbox(
+ &Apache::loncommon::CSTR_pageheader());
+ }
+ }
} elsif (!defined($found{'body'})) {
my %add_entries;
my $background=&Apache::lonxml::get_param('background',$parstack,
@@ -598,7 +626,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";
@@ -641,17 +671,42 @@ sub get_resource_name {
}
sub setup_rndseed {
- my ($safeeval,$target,$probpartlist)=@_;
+ my ($safeeval,$target,$probpartlist,$prevparttype)=@_;
my ($symb)=&Apache::lonnet::whichuser();
- my ($questiontype,$set_safespace,$rndseed);
+ my ($questiontype,$set_safespace,$rndseed,$numtries,$reqtries);
if ($target eq 'analyze') {
$questiontype = $env{'form.grade_questiontype'};
}
unless (defined($questiontype)) {
$questiontype = $Apache::lonhomework::type;
}
- if (($env{'request.state'} eq "construct")
- || ($symb eq '')
+ if ($Apache::lonhomework::type eq 'randomizetry') {
+ my $partfortries = $Apache::inputtags::part;
+#
+# Where question type is "randomizetry" for a problem containing
+# a single part (and unless type is explicitly set to not be
+# "randomizetry" for that part), the number of tries used to
+# determine randomization will be for that part, and randomization
+# from calls to &random() in a perl script block before the part tag,
+# will change based on the number of tries, and value of the
+# "randomizeontries" parameter in effect for the single part.
+#
+ if (ref($probpartlist) eq 'ARRAY') {
+ if ((@{$probpartlist} == 1) && ($probpartlist->[0] ne $partfortries)) {
+ if (&Apache::lonnet::EXT('resource.'.$probpartlist->[0].'.type') eq 'randomizetry') {
+ $partfortries = $probpartlist->[0];
+ } else {
+ $partfortries = '';
+ }
+ }
+ }
+ if ($partfortries ne '') {
+ $numtries = $Apache::lonhomework::history{"resource.$partfortries.tries"};
+ $reqtries = &Apache::lonnet::EXT("resource.$partfortries.randomizeontries");
+ }
+ }
+ if (($env{'request.state'} eq "construct")
+ || ($symb eq '')
|| ($Apache::lonhomework::type eq 'practice')
|| ($Apache::lonhomework::history{'resource.CODE'})
|| (($env{'form.code_for_randomlist'}) && ($target eq 'analyze'))) {
@@ -667,15 +722,19 @@ sub setup_rndseed {
$env{'form.rndseed'}=$rndseed;
}
}
- if (($env{'request.state'} eq "construct") &&
+ if ((($env{'request.state'} eq "construct") || ($symb eq '')) &&
($Apache::lonhomework::type eq 'randomizetry')) {
- my $tries = $Apache::lonhomework::history{"resource.$Apache::inputtags::part.tries"};
- if ($tries) {
- $rndseed += $tries;
+ if ($numtries) {
+ if (($reqtries =~ /^\d+$/) && ($reqtries > 1)) {
+ my $inc = int($numtries/$reqtries);
+ $rndseed += $inc;
+ } else {
+ $rndseed += $numtries;
+ }
}
$env{'form.'.$Apache::inputtags::part.'.rndseed'}=$rndseed;
}
- if ( ($env{'form.resetdata'} eq &mt('New Problem Variation')
+ if ( ($env{'form.resetdata'} eq 'new_problem_variation'
&& $env{'form.submitted'} eq 'yes') ||
$env{'form.newrandomization'} eq &mt('New Randomization')) {
srand(time);
@@ -709,13 +768,7 @@ sub setup_rndseed {
}
unless (($target eq 'analyze') && (defined($rndseed))) {
$rndseed=&Apache::lonnet::rndseed();
- my $partfortries = $Apache::inputtags::part;
- if (ref($probpartlist) eq 'ARRAY') {
- if ((@{$probpartlist} == 1) && ($probpartlist->[0] ne $Apache::inputtags::part)) {
- $partfortries = $probpartlist->[0];
- }
- }
- my $curr_try = $Apache::lonhomework::history{"resource.$partfortries.tries"};
+ my $curr_try = $numtries;
if ($Apache::inputtags::status[-1] eq 'CAN_ANSWER') {
$curr_try ++;
}
@@ -723,7 +776,6 @@ sub setup_rndseed {
$rndseed = $1;
}
if ($curr_try) {
- my $reqtries = &Apache::lonnet::EXT("resource.$partfortries.randomizeontries");
if (($reqtries =~ /^\d+$/) && ($reqtries > 1)) {
my $inc = int(($curr_try-1)/$reqtries);
$rndseed += $inc;
@@ -736,11 +788,20 @@ sub setup_rndseed {
if ($target eq 'grade') {
$Apache::lonhomework::rawrndseed = $rndseed;
}
+ } elsif ($prevparttype eq 'randomizetry') {
+ if ($env{'form.0.rndseed'} ne '') {
+ $set_safespace = 1;
+ $rndseed = $env{'form.0.rndseed'};
+ }
}
if ($set_safespace) {
if ($safeeval) {
&Apache::lonxml::debug("Setting rndseed to $rndseed");
&Apache::run::run('$external::randomseed="'.$rndseed.'";',$safeeval);
+ if (($Apache::lonhomework::type eq 'randomizetry') || ($prevparttype eq 'randomizetry')) {
+ &Apache::lonxml::debug("Setting randomizetrypart to $Apache::inputtags::part");
+ &Apache::run::run('$external::randomizetrypart="'.$Apache::inputtags::part.'";',$safeeval);
+ }
}
}
unless (($env{'request.state'} eq "construct") || ($symb eq '')) {
@@ -799,9 +860,9 @@ sub problem_edit_header {
' . &Apache::lonxml::message_location();
$return .= '
@@ -829,7 +890,6 @@ sub problem_edit_header {
return $return;
}
-
sub problem_edit_footer {
my $resource = $env{'request.ambiguous'};
return '
@@ -905,7 +965,7 @@ sub problem_web_to_edit_header {
".&mt("Problem Type:")."