--- loncom/homework/structuretags.pm 2006/01/18 20:16:43 1.331
+++ loncom/homework/structuretags.pm 2011/12/12 12:07:45 1.497.2.3
@@ -1,7 +1,7 @@
# The LearningOnline Network with CAPA
# definition of tags that give a structure to a document
#
-# $Id: structuretags.pm,v 1.331 2006/01/18 20:16:43 albertel Exp $
+# $Id: structuretags.pm,v 1.497.2.3 2011/12/12 12:07:45 foxr Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -27,6 +27,29 @@
#
###
+=pod
+
+=head1 NAME
+
+Apache::structuretags
+
+=head1 SYNOPSIS
+
+
+This is part of the LearningOnline Network with CAPA project
+described at http://www.lon-capa.org.
+
+
+=head1 NOTABLE SUBROUTINES
+
+=over
+
+=item
+
+=back
+
+=cut
+
package Apache::structuretags;
@@ -36,16 +59,31 @@ use Apache::File();
use Apache::lonmenu;
use Apache::lonlocal;
use Apache::lonxml;
+use Apache::londefdef;
+use Apache::lonenc();
use Time::HiRes qw( gettimeofday tv_interval );
+use lib '/home/httpd/lib/perl/';
+use LONCAPA;
+
BEGIN {
- &Apache::lonxml::register('Apache::structuretags',('block','languageblock','instructorcomment','while','randomlist','problem','library','web','tex','part','preduedate','postanswerdate','solved','notsolved','problemtype','startouttext','endouttext','simpleeditbutton','definetag'));
+ &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'));
}
sub start_web {
my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
- my $bodytext=&Apache::lonxml::get_all_text("/web",$parser,$style);
- if ($target eq 'web') {
- return $bodytext;
+ if ($target ne 'edit' && $target ne 'modified') {
+ my $bodytext=&Apache::lonxml::get_all_text("/web",$parser,$style);
+ if ($target eq 'web' || $target eq 'webgrade') {
+ return $bodytext;
+ }
+ } elsif ($target eq "edit" ) {
+ my $bodytext =
+ &Apache::lonxml::get_all_text_unbalanced("/web",$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("/web",$parser);
}
return '';
}
@@ -57,9 +95,26 @@ sub end_web {
sub start_tex {
my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
my $result='';
- my $bodytext=&Apache::lonxml::get_all_text("/tex",$parser,$style);
- if ($target eq 'tex') {
- return $bodytext.' ';
+ if ($target ne 'edit' && $target ne 'modified') {
+ my $bodytext=&Apache::lonxml::get_all_text("/tex",$parser,$style);
+ if ($target eq 'tex') {
+
+ # If inside a table, occurrences of \\ must be removed;
+ # else the table blows up.
+
+ if (&Apache::londefdef::is_inside_of($tagstack, "table")) {
+ $bodytext =~ s/\\\\//g;
+ }
+ return $bodytext.'{}';
+ }
+ } elsif ($target eq "edit" ) {
+ my $bodytext =
+ &Apache::lonxml::get_all_text_unbalanced("/tex",$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("/tex",$parser);
}
return $result;;
}
@@ -68,35 +123,58 @@ sub end_tex {
return '';
}
-sub body_tag_start {
- my ($target,$background,$bgcolor)=@_;
- my $body_tag_start='
+// '.&Apache::lonmenu::menubuttons(undef,$target,1);
-
- &Apache::lontexconvert::jsMath_reset();
- if ($env{'environment.texengine'} eq 'jsMath') {
- $body_tag_start.=&Apache::lontexconvert::jsMath_header();
+ for (var i=0;i
+
+JS
+}
+
+sub setmode_javascript {
+ return <<"ENDSCRIPT";
+
+ENDSCRIPT
}
sub page_start {
- my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
+ my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$name,
+ $extra_head)=@_;
my %found;
foreach my $taginside (@$tagstack) {
foreach my $taglookedfor ('html','body','form') {
@@ -104,90 +182,229 @@ sub page_start {
}
}
- my $result;
- my $head_tag_start;
- if (!defined($found{'html'})) {
- $result=&Apache::londefdef::start_html($target,$token,$tagstack,
- $parstack,$parser,$safeeval);
- $head_tag_start=''.&Apache::lonmenu::registerurl(undef,$target).
- &Apache::lonhtmlcommon::htmlareaheaders().
- &Apache::lonhtmlcommon::spellheader().
- &Apache::lonxml::fontsettings();
- if ($target eq 'edit') {
- $head_tag_start.=&Apache::edit::js_change_detection();
+ if ($target eq 'tex') {
+ return
+ &Apache::londefdef::start_html($target,$token,$tagstack,
+ $parstack,$parser,$safeeval);
+ }
+
+ $extra_head .= &homework_js().
+ &Apache::lonhtmlcommon::dragmath_js("EditMathPopup");
+ if (&Apache::lonhtmlcommon::htmlareabrowser()) {
+ my %textarea_args = (
+ dragmath => 'math',
+ );
+ $extra_head .= &Apache::lonhtmlcommon::htmlareaselectactive(\%textarea_args);
+ }
+ my $is_task = ($env{'request.uri'} =~ /\.task$/);
+ my $needs_upload;
+ my ($symb)= &Apache::lonnet::whichuser();
+ my ($map,$resid,$resurl)=&Apache::lonnet::decode_symb($symb);
+ if ($is_task) {
+ $extra_head .= &Apache::lonhtmlcommon::file_submissionchk_js();
+ } else {
+ if (&Apache::lonnet::EXT("resource.$Apache::inputtags::part.uploadedfiletypes") ne '') {
+ unless ($env{'request.state'} eq 'construct') {
+ my $navmap = Apache::lonnavmaps::navmap->new();
+ if (ref($navmap)) {
+ my $mapres = $navmap->getResourceByUrl($map);
+ my $is_page;
+ if (ref($mapres)) {
+ $is_page = $mapres->is_page();
+ }
+ unless ($is_page) {
+ $needs_upload = 1;
+ }
+ }
+ }
+ } else {
+ unless ($env{'request.state'} eq 'construct') {
+ my $navmap = Apache::lonnavmaps::navmap->new();
+ if (ref($navmap)) {
+ my $mapres = $navmap->getResourceByUrl($map);
+ my $is_page;
+ if (ref($mapres)) {
+ $is_page = $mapres->is_page();
+ }
+ unless ($is_page) {
+ my $res = $navmap->getBySymb($symb);
+ if (ref($res)) {
+ my $partlist = $res->parts();
+ if (ref($partlist) eq 'ARRAY') {
+ foreach my $part (@{$partlist}) {
+ my @types = $res->responseType($part);
+ my @ids = $res->responseIds($part);
+ for (my $i=0; $i < scalar(@ids); $i++) {
+ if ($types[$i] eq 'essay') {
+ my $partid = $part.'_'.$ids[$i];
+ if (&Apache::lonnet::EXT("resource.$partid.uploadedfiletypes") ne '') {
+ $needs_upload = 1;
+ last;
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+ if ($needs_upload) {
+ $extra_head .= &Apache::lonhtmlcommon::file_submissionchk_js();
+ }
+ }
+
+ my %body_args;
+ if (defined($found{'html'})) {
+ $body_args{'skip_phases'}{'head'}=1;
+ } else {
+
+ $extra_head .= &Apache::lonhtmlcommon::spellheader();
+
+ $extra_head .= &Apache::londefdef::generate_css_links();
+
+ if ($env{'request.state'} eq 'construct') {
+ $extra_head.=&Apache::edit::js_change_detection().
+ "\n";
}
}
- my $body_tag_start;
- if (!defined($found{'body'}) && $env{'request.state'} eq 'construct') {
- if ($env{'environment.remote'} eq 'off') {
- if ($target eq 'web' || $target eq 'edit') {
- $body_tag_start=&Apache::loncommon::bodytag();
- $body_tag_start.=&Apache::lonxml::message_location();
- }
- } else {
- if ($target eq 'web' || $target eq 'edit') {
- $body_tag_start=&Apache::loncommon::bodytag(undef,undef,undef,1);
- $body_tag_start.=&Apache::lonxml::message_location();
- }
+
+ my $pageheader = '';
+ if (defined($found{'body'})) {
+ $body_args{'skip_phases'}{'body'}=1;
+ } elsif (!defined($found{'body'})
+ && $env{'request.state'} eq 'construct') {
+ if ($target eq 'web' || $target eq 'edit') {
+ # Breadcrumbs for Construction Space
+ &Apache::lonhtmlcommon::clear_breadcrumbs();
+ &Apache::lonhtmlcommon::add_breadcrumb({
+ 'text' => 'Construction 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());
}
} elsif (!defined($found{'body'})) {
+ my %add_entries;
my $background=&Apache::lonxml::get_param('background',$parstack,
$safeeval);
+ if ($background ne '' ) {
+ $add_entries{'background'} = $background;
+ }
+
my $bgcolor=&Apache::lonxml::get_param('bgcolor',$parstack,
$safeeval);
- $body_tag_start=&body_tag_start($target,$background,$bgcolor);
- if ( ($target eq 'web' || $target eq 'webgrade')
- && $env{'request.state'} ne 'construct') {
- my ($symb,undef,undef,undef,$publicuser)=
- &Apache::lonxml::whichuser();
- if ($symb eq '' && !$publicuser) {
- my $help = &Apache::loncommon::help_open_topic("Ambiguous_Reference");
- $help=&mt("Browsing resource, all submissions are temporary.")." ";
- $body_tag_start.=$help;
- }
- }
- $body_tag_start.=&Apache::lonxml::message_location();
+ if ($bgcolor eq '' ) { $bgcolor = '#FFFFFF'; }
+
+ $body_args{'bgcolor'} = $bgcolor;
+ # $body_args{'no_title'} = 1;
+ $body_args{'force_register'} = 1;
+ $body_args{'add_entries'} = \%add_entries;
+ if ( $env{'request.state'} eq 'construct') {
+ $body_args{'only_body'} = 1;
+ }
+ }
+ $body_args{'no_auto_mt_title'} = 1;
+ my $page_start = &Apache::loncommon::start_page($name,$extra_head,
+ \%body_args);
+ $page_start .= $pageheader;
+ if (!defined($found{'body'})
+ && $env{'request.state'} ne 'construct'
+ && ($target eq 'web' || $target eq 'webgrade')) {
+
+ my ($symb,undef,undef,undef,$publicuser)= &Apache::lonnet::whichuser();
+ if ($symb eq '' && !$publicuser) {
+ $page_start .= '
'
+ .&mt('Browsing resource, all submissions are temporary.')
+ .'
';
+ }
+ }
+
+ if (!defined($found{'body'}) && $env{'request.state'} ne 'construct') {
+ $page_start .= &Apache::lonxml::message_location();
}
my $form_tag_start;
if (!defined($found{'form'})) {
- $form_tag_start='\n".&Apache::loncommon::end_page();
}
sub option {
@@ -260,31 +564,40 @@ sub option {
sub problem_web_to_edit_header {
my ($rndseed)=@_;
- my $result.='';
+ my $result .= '
'.&mt('You are not currently signed up to work at this time and/or place.').'
';
} elsif ($status ne 'NOT_YET_VIEWED') {
$msg.='
'.&mt('Not open to be viewed').'
';
}
if ($status eq 'CLOSED' || $status eq 'INVALID_ACCESS') {
- $msg.='The problem '.$accessmsg;
+ $msg.=&mt('The problem ').$accessmsg;
} elsif ($status eq 'UNCHECKEDOUT') {
- $msg.=&checkout_msg;
+ $msg.=&checkout_msg();
} elsif ($status eq 'NOT_YET_VIEWED') {
$msg.=&firstaccess_msg($accessmsg,$symb);
} elsif ($status eq 'NOT_IN_A_SLOT') {
- $msg.=&Apache::bridgetask::add_request_another_attempt_button("Sign up for time to work.");
+ $msg.=&Apache::bridgetask::add_request_another_attempt_button("Sign up for time to work");
}
$result.=$msg.' ';
} elsif ($target eq 'tex') {
- $result.='\begin{document}\noindent \vskip 1 mm \begin{minipage}{\textwidth}\vskip 0 mm';
+ my $startminipage = ($env{'form.problem_split'}=~/yes/i)? ''
+ : '\begin{minipage}{\textwidth}';
+ $result.='\noindent \vskip 1 mm '.
+ $startminipage.'\vskip 0 mm';
if ($status eq 'UNAVAILABLE') {
$result.=&mt('Unable to determine if this resource is open due to network problems. Please try again later.').'\vskip 0 mm ';
} else {
@@ -669,21 +1166,30 @@ sub start_problem {
my $bodytext=&Apache::lonxml::get_all_text("/problem",$parser,
$style);
if ($target eq 'web') {
- $result .= $head_tag_start.'';
- $result .= $body_tag_start;
- $result .= &Apache::bridgetask::proctor_validation_screen();
+ $result .=
+ &Apache::bridgetask::proctor_validation_screen($slot);
} elsif ($target eq 'grade') {
&Apache::bridgetask::proctor_check_auth($slot_name,$slot,
'problem');
}
} elsif ($target eq 'web') {
- my $name= &get_resource_name($parstack,$safeeval);
- $result.="$head_tag_start$name
- $body_tag_start \n $form_tag_start".
+ if ($status eq 'CAN_ANSWER'
+ && $slot_name ne ''
+ && $Apache::lonhomework::history{'resource.0.checkedin'} eq '') {
+ # unproctored slot access, self checkin
+ &Apache::bridgetask::check_in('problem',undef,undef,
+ $slot_name);
+ }
+ $result.="\n $form_tag_start \t".
'';
# create a page header and exit
if ($env{'request.state'} eq "construct") {
$result.= &problem_web_to_edit_header($env{'form.rndseed'});
+ if ($Apache::lonhomework::type eq 'practice') {
+ $result.= ''.
+ &practice_problem_header().'';
+ }
}
# if we are viewing someone else preserve that info
if (defined $env{'form.grade_symb'}) {
@@ -691,21 +1197,28 @@ sub start_problem {
$result .= ''."\n";
}
+ foreach my $field ('trial','questiontype') {
+ if ($env{"form.grade_$field"} ne '') {
+ $result .= ''."\n";
+ }
+ }
}
+ if ($env{'form.grade_imsexport'}) {
+ $result = '';
+ }
} elsif ($target eq 'tex') {
$result .= 'INSERTTEXFRONTMATTERHERE';
}
} elsif ($target eq 'edit') {
- $result.=$head_tag_start."".$body_tag_start.$form_tag_start.
- &problem_edit_header();
+ $result .= $form_tag_start.&problem_edit_header();
$Apache::lonxml::warnings_error_header=
&mt("Editor Errors - these errors might not effect the running of the problem, but they will likely cause problems with further use of the Edit mode. Please use the EditXML mode to fix these errors.")." ";
my $temp=&Apache::edit::insertlist($target,$token);
$result.=$temp;
} elsif ($target eq 'modified') {
$result=$token->[4];
- $result.=&Apache::edit::handle_insert();
} else {
# page_start returned a starting result, delete it if we don't need it
$result = '';
@@ -723,7 +1236,6 @@ sub end_problem {
}
if ($target eq 'tex') {
-
# Figure out the front matter and replace the
# INSERTTEXFRONTMATTERHERE in result with it. note that we do
# this in end_problem because whether or not we display due
@@ -752,7 +1264,7 @@ sub end_problem {
$allow_print_points=0;
}
my $name_of_resourse= &Apache::lonxml::latex_special_symbols(&get_resource_name($parstack,$safeeval),'header');
- my $begin_doc='\begin{document} \typeout{STAMPOFPASSEDRESOURCESTART Resource
"'.$name_of_resourse.'"
located in '.$env{'request.uri'}.' STAMPOFPASSEDRESOURCEEND} \noindent ';
+ my $begin_doc=' \typeout{STAMPOFPASSEDRESOURCESTART Resource
"'.$name_of_resourse.'"
located in '.$env{'request.uri'}.' STAMPOFPASSEDRESOURCEEND} \noindent ';
my $toc_line='\vskip 1 mm\noindent '.$startminipage.
'\addcontentsline{toc}{subsection}{'.$name_of_resourse.'}';
@@ -762,6 +1274,8 @@ sub end_problem {
my $duetime = &Apache::lonnet::EXT("resource.$id.duedate");
my $duedate = POSIX::strftime("%c",localtime($duetime));
+ my $duedate_text = &mt('Due date: [_1]'
+ ,&Apache::lonlocal::locallocaltime($duetime));
my $temp_file;
my $filename = "/home/httpd/prtspool/$env{'user.name'}_$env{'user.domain'}_printout.due";
@@ -793,20 +1307,24 @@ sub end_problem {
if (not $env{'request.symb'} =~ m/\.page_/) {
if(not $duedate=~m/1969/ and $Apache::lonhomework::type ne 'exam') {
$frontmatter .= $begin_doc.
- '\textit{Due date: '.$duedate.'} '.$toc_line;
+ '\textit{'.$duedate_text.'} '.$toc_line;
} else {
$frontmatter.= $begin_doc.$toc_line;
- if ($Apache::lonhomework::type eq 'exam' and $allow_print_points==1) { $frontmatter .= '\fbox{\textit{'.$weight.' pt}}';}
+ if ($Apache::lonhomework::type eq 'exam' and $allow_print_points==1) {
+ $frontmatter .= '\fbox{\textit{'.&mt('[quant,_1,pt,pt]',$weight ).'}}';
+ }
}
} else {
- $frontmatter .= '\vskip 1mm\textit{Due date: '.$duedate.'} \\\\\\\\';
+ $frontmatter .= '\vskip 1mm\textit{'.$duedate_text.'} \\\\\\\\'.$startminipage;
}
} else {
if (not $env{'request.symb'} =~ m/\.page_/) {
$frontmatter .= $begin_doc.$toc_line;
- if (($Apache::lonhomework::type eq 'exam') and ($allow_print_points==1)) { $frontmatter .= '\fbox{\textit{'.$weight.' pt}}';}
+ if (($Apache::lonhomework::type eq 'exam') and ($allow_print_points==1)) {
+ $frontmatter .= '\fbox{\textit{'.&mt('[quant,_1,pt,pt]',$weight ).'}}';
+ }
} else {
- $frontmatter .= '\vskip 1mm \\\\\\\\';
+ $frontmatter .= '\vskip 1mm \\\\\\\\'.$startminipage;
}
}
$result =~ s/INSERTTEXFRONTMATTERHERE/$frontmatter/;
@@ -827,7 +1345,8 @@ sub end_problem {
}
} elsif ( ($target eq 'web' || $target eq 'tex') &&
$Apache::inputtags::part eq '0' &&
- $status ne 'UNCHECKEDOUT' && $status ne 'NOT_YET_VIEWED') {
+ $status ne 'UNCHECKEDOUT' && $status ne 'NOT_YET_VIEWED'
+ && !$env{'form.grade_imsexport'}) {
# if part is zero, no s existed, so we need show the current
# grading status
my $gradestatus = &Apache::inputtags::gradestatus($Apache::inputtags::part,$target);
@@ -837,13 +1356,13 @@ sub end_problem {
(($target eq 'web') && ($env{'request.state'} ne 'construct')) ||
($target eq 'answer') || ($target eq 'tex')
) {
- if ($target ne 'tex' &&
- $env{'form.answer_output_mode'} ne 'tex') {
+ if (($target ne 'tex') &&
+ ($env{'form.answer_output_mode'} ne 'tex') &&
+ (!$env{'form.grade_imsexport'})) {
$result.="";
- $result.=&Apache::lonhtmlcommon::htmlareaselectactive(@Apache::lonxml::htmlareafields);
}
if ($target eq 'web') {
- $result.=&Apache::lonxml::xmlend().'