--- loncom/homework/structuretags.pm 2007/08/08 19:13:19 1.387
+++ loncom/homework/structuretags.pm 2007/11/13 23:01:05 1.411
@@ -1,7 +1,7 @@
# The LearningOnline Network with CAPA
# definition of tags that give a structure to a document
#
-# $Id: structuretags.pm,v 1.387 2007/08/08 19:13:19 albertel Exp $
+# $Id: structuretags.pm,v 1.411 2007/11/13 23:01:05 albertel Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -42,7 +42,7 @@ 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','startouttext','endouttext','simpleeditbutton','definetag'));
}
sub start_web {
@@ -92,6 +92,31 @@ sub end_tex {
return '';
}
+sub homework_js {
+ return &Apache::loncommon::resize_textarea_js().
+ <<'JS';
+
+JS
+}
+
sub page_start {
my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$name,
$extra_head)=@_;
@@ -108,13 +133,7 @@ sub page_start {
$parstack,$parser,$safeeval);
}
- $extra_head.= '
-
-';
+ $extra_head .= &homework_js();
my %body_args;
if (defined($found{'html'})) {
@@ -139,7 +158,9 @@ function setSubmittedPart (part) {
} elsif (!defined($found{'body'})
&& $env{'request.state'} eq 'construct') {
if ($target eq 'web' || $target eq 'edit') {
- # no extra args to bodytag
+ if ($env{'environment.remote'} ne 'off') {
+ $body_args{'only_body'} = 1;
+ }
}
} elsif (!defined($found{'body'})) {
my %add_entries;
@@ -157,6 +178,10 @@ function setSubmittedPart (part) {
$body_args{'no_title'} = 1;
$body_args{'force_register'} = 1;
$body_args{'add_entries'} = \%add_entries;
+ if ($env{'environment.remote'} eq 'off'
+ && $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,
@@ -174,7 +199,7 @@ function setSubmittedPart (part) {
}
}
- if (!defined($found{'body'})) {
+ if (!defined($found{'body'}) && $env{'request.state'} ne 'construct') {
$page_start .= &Apache::lonxml::message_location();
}
@@ -202,20 +227,27 @@ function setSubmittedPart (part) {
#use Time::HiRes();
sub get_resource_name {
my ($parstack,$safeeval)=@_;
+ my $name;
if (defined($Apache::lonhomework::name)) {
- return $Apache::lonhomework::name;
- }
- my ($symb)=&Apache::lonnet::whichuser();
- my $name=&Apache::lonnet::gettitle($symb);
- if ($name eq '') {
- $name=&Apache::lonnet::EXT('resource.title');
- if ($name eq 'con_lost') { $name = ''; }
- }
- if ($name!~/\S+/) {
- $name=$env{'request.uri'};
- $name=~s-.*/([^/]+)$-$1-;
+ $name = $Apache::lonhomework::name;
+ } else {
+ my ($symb)=&Apache::lonnet::whichuser();
+ $name=&Apache::lonnet::gettitle($symb);
+ if ($name eq '') {
+ $name=&Apache::lonnet::EXT('resource.title');
+ if ($name eq 'con_lost') { $name = ''; }
+ }
+ if ($name!~/\S+/) {
+ $name=$env{'request.uri'};
+ $name=~s-.*/([^/]+)$-$1-;
+ }
+ # The name has had html tags escaped:
+
+ $name=~s/<//gs;
+
+ $Apache::lonhomework::name=$name;
}
- $Apache::lonhomework::name=$name;
return $name;
}
@@ -270,20 +302,30 @@ sub remember_problem_state {
sub problem_edit_header {
return ''.
&Apache::structuretags::remember_problem_state().'
+
+'.
'';
}
sub problem_edit_footer {
- return ' |
- '.
+ return '
+ '.
&Apache::lonhtmlcommon::htmlareaselectactive(&Apache::lonhtmlcommon::get_htmlareafields()).
"\n\n".&Apache::loncommon::end_page();
}
@@ -300,35 +342,38 @@ sub option {
sub problem_web_to_edit_header {
my ($rndseed)=@_;
- my $result.='';
- $result .= '';
- $result .= '
-
-
-
-
- '.
- &Apache::loncommon::help_open_topic('Problem_Editor_Testing_Area','Testing Problems').
- '
';
- $result.=&mt('Apply style file: ').'
-&').'" />
- '.&mt('Select').'
-
-
';
+ my $show_all= '';
+
+
+ $result .= '';
return $result;
}
@@ -544,19 +628,19 @@ sub init_problem_globals {
if ($type eq 'problem') {
$Apache::inputtags::part='0';
@Apache::inputtags::partlist=('0');
- $Apache::lonhomework::problemstatus=&get_problem_status('0');
+ &Apache::lonhomework::set_show_problem_status(&get_problem_status('0'));
$Apache::lonhomework::ignore_response_errors=0;
} elsif ($type eq 'library') {
$Apache::inputtags::part='';
@Apache::inputtags::partlist=();
- $Apache::lonhomework::problemstatus='';
+ &Apache::lonhomework::reset_show_problem_status();
$Apache::lonhomework::ignore_response_errors=1;
} elsif ($type eq 'Task') {
$Apache::inputtags::part='0';
@Apache::inputtags::partlist=('0');
- $Apache::lonhomework::problemstatus='';
+ &Apache::lonhomework::reset_show_problem_status();
$Apache::lonhomework::ignore_response_errors=1;
}
@Apache::inputtags::responselist = ();
@@ -585,8 +669,8 @@ sub reset_problem_globals {
undef($Apache::lonhomework::default_type);
undef($Apache::lonhomework::type);
undef($Apache::lonhomework::scantronmode);
- undef($Apache::lonhomework::problemstatus);
undef($Apache::lonhomework::ignore_response_errors);
+ &Apache::lonhomework::reset_show_problem_status();
}
sub set_problem_state {
@@ -637,10 +721,9 @@ sub start_problem {
}
if ($target ne 'analyze') {
- if ($env{'request.state'} eq 'construct') { &set_problem_state('0'); }
$Apache::lonhomework::type=&Apache::lonnet::EXT('resource.0.type');
if (($env{'request.state'} eq 'construct') &&
- defined($env{'form.problemtype'})) {
+ $env{'form.problemtype'} =~ /\S/) {
$Apache::lonhomework::type=$env{'form.problemtype'};
}
&Apache::lonxml::debug("Found this to be of type :$Apache::lonhomework::type:");
@@ -658,6 +741,11 @@ sub start_problem {
$Apache::lonhomework::default_type = $Apache::lonhomework::type;
&initialize_storage();
+ if ($target ne 'analyze'
+ && $env{'request.state'} eq 'construct') {
+ &set_problem_state('0');
+ }
+
if ($target eq 'web') {
&Apache::lonxml::debug(" grading history ");
&Apache::lonhomework::showhash(%Apache::lonhomework::history);
@@ -750,7 +838,7 @@ sub start_problem {
$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();
} elsif ($status eq 'NOT_YET_VIEWED') {
@@ -1055,16 +1143,19 @@ sub start_definetag {
my $name = $token->[2]->{'name'};
my $skip=&Apache::lonxml::get_all_text("/definetag",$parser,$style);
- if ($name=~/^\//) {
- $result=
- '
END '.$name.' |
';
- } else {
- $result=
- '
BEGIN '.$name.' |
';
+ if ($target eq 'web') {
+ if ($name=~/^\//) {
+ $result=
+ '
'.
+ &mt('END [_1]'.''.$name.'').' |
';
+ } else {
+ $result=
+ '
'.
+ &mt('BEGIN [_1]'.''.$name.'').' |
';
+ }
+ $skip = &HTML::Entities::encode($skip, '<>&"');
+ $result.=''.$skip.' |
';
}
- $skip=~s/\\<\;/gs;
- $skip=~s/\>/\>\;/gs;
- $result.=''.$skip.' |
';
return $result;
}
@@ -1125,19 +1216,38 @@ sub start_languageblock {
$target eq 'tex' || $target eq 'analyze' || $target eq 'webgrade') {
my $include = $token->[2]->{'include'};
my $exclude = $token->[2]->{'exclude'};
- my %languages=&Apache::loncommon::display_languages();
- $result='1';
- if ($include) {
- $result='';
- foreach (split(/\,/,$include)) {
- if ($languages{$_}) { $result='1'; }
- }
- }
- if ($exclude) {
- foreach (split(/\,/,$exclude)) {
- if ($languages{$_}) { $result='0'; }
- }
- }
+ my @preferred_languages=&Apache::loncommon::preferred_languages();
+# This should not even happen, since we should at least have the server language
+ if (!$preferred_languages[0]) { $preferred_languages[0]='en'; }
+# Now loop over all languages in order of preference
+ foreach my $preferred_language (@preferred_languages) {
+# If the languageblock has no arguments, show the contents
+ $result=1;
+ my $found=0;
+# Do we have an include argument?
+ if ($include) {
+# If include is specified, by default, don't render the block
+ $result=0;
+ foreach my $included_language (split(/\,/,$include)) {
+# ... but if my preferred language is included, render it
+ if ($included_language eq $preferred_language) {
+ $result=1;
+ $found=1;
+ }
+ }
+ }
+# Do we have an exclude argument?
+ if ($exclude) {
+ $result=1;
+ foreach my $excluded_language (split(/\,/,$exclude)) {
+ if ($excluded_language eq $preferred_language) {
+ $result=0;
+ $found=1;
+ }
+ }
+ }
+ if ($found) { last; }
+ }
if ( ! $result ) {
my $skip=&Apache::lonxml::get_all_text("/languageblock",$parser,
$style);
@@ -1169,6 +1279,56 @@ sub end_languageblock {
return $result;
}
+{
+ my %available_texts;
+ sub start_translated {
+ my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
+ &Apache::lonxml::register('Apache::structuretags',('lang'));
+ undef(%available_texts);
+ }
+
+ sub end_translated {
+ my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
+ my $result;
+ #show the translation on viewable targets
+ if ($target eq 'web' || $target eq 'tex' || $target eq 'webgrade'||
+ # or non-viewable targets, if it's embedded in something that
+ # wants the output
+ (($target eq 'answer' || $target eq 'analyze'|| $target eq 'grade')
+ && &Apache::lonxml::in_redirection() ) ) {
+ my @possibilities = keys(%available_texts);
+ my $which =
+ &Apache::loncommon::languages(\@possibilities) || 'default';
+ $result = $available_texts{$which};
+ }
+ undef(%available_texts);
+ &Apache::lonxml::deregister('Apache::structuretags',('lang'));
+ return $result;
+ }
+
+
+ sub start_lang {
+ my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
+ if ($target eq 'web' || $target eq 'grade' || $target eq 'answer' ||
+ $target eq 'tex' || $target eq 'analyze' || $target eq 'webgrade') {
+ &Apache::lonxml::startredirection();
+ }
+ return '';
+ }
+
+ sub end_lang {
+ my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
+ if ($target eq 'web' || $target eq 'grade' || $target eq 'answer' ||
+ $target eq 'tex' || $target eq 'analyze' || $target eq 'webgrade') {
+ my $result = &Apache::lonxml::endredirection();
+ my $which = &Apache::lonxml::get_param('which',$parstack,
+ $safeeval);
+ $available_texts{$which} = $result;
+ }
+ return '';
+ }
+}
+
sub start_instructorcomment {
my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
@@ -1380,7 +1540,9 @@ sub start_part {
@Apache::inputtags::response=();
@Apache::inputtags::previous=();
@Apache::inputtags::previous_version=();
- $Apache::lonhomework::problemstatus=&get_problem_status($id);
+ &Apache::lonhomework::set_show_problem_status(&get_problem_status($id));
+ &Apache::response::reset_params();
+
my $hidden=&Apache::loncommon::check_if_partid_hidden($Apache::inputtags::part);
my $newtype=&Apache::lonnet::EXT("resource.$id.type");
if ($newtype) { $Apache::lonhomework::type=$newtype; }
@@ -1427,7 +1589,7 @@ sub start_part {
if ($target eq 'tex') {
if (not $env{'form.problem_split'}=~/yes/) {
if ($$tagstack[-2] eq 'td') {
- $result.='\vskip 0 mm \noindent \begin{minipage}{\textwidth}\noindent';
+ $result.='\noindent \begin{minipage}{\textwidth}\noindent';
} else {
$result.='\noindent \end{minipage}\vskip 0 mm \noindent \begin{minipage}{\textwidth}\noindent';
}
@@ -1637,6 +1799,13 @@ sub start_startouttext {
my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
my @result=(''.'');
if ($target eq 'edit' || $target eq 'modified' ) { @result=('','no'); }
+
+ my $nesting =
+ &Apache::lonxml::set_state('outtext',
+ &Apache::lonxml::get_state('outtext')+1);
+ if ($nesting > 1 && $env{'request.state'} eq 'construct') {
+ &Apache::lonxml::error("Nesting of <startouttext /> not allowed, on line ".$token->[5]);
+ }
return (@result);
}
@@ -1676,6 +1845,14 @@ sub start_endouttext {
$result=''.
&Apache::edit::handle_insertafter('startouttext');
}
+
+ my $nesting =
+ &Apache::lonxml::set_state('outtext',
+ &Apache::lonxml::get_state('outtext')-1);
+ if ($nesting < 0 && $env{'request.state'} eq 'construct') {
+ &Apache::lonxml::error(" Extraneous <endouttext /> not allowed on line ".$token->[5]);
+ &Apache::lonxml::set_state('outtext', 0);
+ }
return $result;
}