--- loncom/homework/structuretags.pm 2006/04/14 20:16:23 1.343
+++ loncom/homework/structuretags.pm 2007/10/17 00:22:51 1.405
@@ -1,7 +1,7 @@
# The LearningOnline Network with CAPA
# definition of tags that give a structure to a document
#
-# $Id: structuretags.pm,v 1.343 2006/04/14 20:16:23 albertel Exp $
+# $Id: structuretags.pm,v 1.405 2007/10/17 00:22:51 albertel Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -38,15 +38,28 @@ use Apache::lonlocal;
use Apache::lonxml;
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','startouttext','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' || $target eq 'webgrade') {
- 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 '';
}
@@ -58,9 +71,19 @@ 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') {
+ 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;;
}
@@ -69,8 +92,34 @@ 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)=@_;
+ my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$name,
+ $extra_head)=@_;
my %found;
foreach my $taginside (@$tagstack) {
foreach my $taglookedfor ('html','body','form') {
@@ -78,42 +127,40 @@ sub page_start {
}
}
-
if ($target eq 'tex') {
return
&Apache::londefdef::start_html($target,$token,$tagstack,
$parstack,$parser,$safeeval);
}
- my $page_start;
- if (!defined($found{'html'})) {
+ $extra_head .= &homework_js();
+
+ my %body_args;
+ if (defined($found{'html'})) {
+ $body_args{'skip_phases'}{'head'}=1;
+ } else {
- my $extra_head = &Apache::lonhtmlcommon::spellheader();
+ $extra_head .= &Apache::lonhtmlcommon::spellheader();
- my $css_href = &Apache::lonnet::EXT('resource.0.cssfile');
- if ($css_href =~ /\S/) {
- &Apache::lonxml::extlink($css_href);
- $extra_head .=
- '';
- }
- if ($target eq 'edit') {
+ $extra_head .= &Apache::londefdef::generate_css_links();
+
+ if ($env{'request.state'} eq 'construct') {
$extra_head.=&Apache::edit::js_change_detection().
"\n";
-
}
- $page_start .=
- &Apache::loncommon::head($name,$extra_head,
- {'force_register' =>
- ($target ne 'edit') });
}
- if (!defined($found{'body'}) && $env{'request.state'} eq 'construct') {
+ 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') {
- $page_start.=&Apache::loncommon::bodytag();
- $page_start.=&Apache::lonxml::message_location();
+ if ($env{'environment.remote'} ne 'off') {
+ $body_args{'only_body'} = 1;
+ }
}
} elsif (!defined($found{'body'})) {
my %add_entries;
@@ -122,27 +169,40 @@ sub page_start {
if ($background ne '' ) {
$add_entries{'background'} = $background;
}
+
my $bgcolor=&Apache::lonxml::get_param('bgcolor',$parstack,
$safeeval);
-
- if ($bgcolor eq '' ) { $bgcolor = '#FFFFFF'; }
- $page_start .=
- &Apache::loncommon::bodytag(undef,undef,\%add_entries,undef,undef,
- 1,undef,undef,$bgcolor,$target,1);
-
- 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.")."
";
- $page_start .= $help;
- }
+ 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{'environment.remote'} eq 'off'
+ && $env{'request.state'} eq 'construct') {
+ $body_args{'only_body'} = 1;
}
- $page_start .= &Apache::lonxml::message_location();
}
+ $body_args{'no_auto_mt_title'} = 1;
+ my $page_start = &Apache::loncommon::start_page($name,$extra_head,
+ \%body_args);
+
+ 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) {
+ my $help = &Apache::loncommon::help_open_topic("Ambiguous_Reference");
+ $help=&mt("Browsing resource, all submissions are temporary.")."
";
+ $page_start .= $help;
+ }
+ }
+
+ if (!defined($found{'body'})) {
+ $page_start .= &Apache::lonxml::message_location();
+ }
+
my $form_tag_start;
if (!defined($found{'form'})) {
$form_tag_start='
'."\n";
+ }
}
return ($page_start,$form_tag_start);
}
@@ -159,27 +227,34 @@ sub page_start {
#use Time::HiRes();
sub get_resource_name {
my ($parstack,$safeeval)=@_;
+ my $name;
if (defined($Apache::lonhomework::name)) {
- return $Apache::lonhomework::name;
- }
- my ($symb)=&Apache::lonxml::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;
}
sub setup_rndseed {
my ($safeeval)=@_;
my $rndseed;
- my ($symb)=&Apache::lonxml::whichuser();
+ my ($symb)=&Apache::lonnet::whichuser();
if ($env{'request.state'} eq "construct"
|| $symb eq ''
|| $Apache::lonhomework::type eq 'practice'
@@ -194,7 +269,8 @@ sub setup_rndseed {
}
$env{'form.rndseed'}=$rndseed;
}
- if ($env{'form.resetdata'} eq &mt('New Problem Variation') ||
+ if ( ($env{'form.resetdata'} eq &mt('New Problem Variation')
+ && $env{'form.submitted'} eq 'yes') ||
$env{'form.newrandomization'} eq &mt('New Randomization')) {
srand(time);
$rndseed=int(rand(2100000000));
@@ -232,7 +308,7 @@ sub problem_edit_header {
'.
- &Apache::loncommon::help_open_menu('','Problem Editing Help','Problem_Editor_XML_Index','',5,'Authoring',undef,undef,undef,'Problem Editing Help')
+ &Apache::loncommon::help_open_menu('Problem Editing Help','Problem_Editor_XML_Index',5,'Authoring',undef,undef,undef,'Problem Editing Help')
.' |
'.
'';
}
@@ -240,7 +316,7 @@ sub problem_edit_header {
sub problem_edit_footer {
return ' |
'.
- &Apache::lonhtmlcommon::htmlareaselectactive(@Apache::lonxml::htmlareafields).
+ &Apache::lonhtmlcommon::htmlareaselectactive(&Apache::lonhtmlcommon::get_htmlareafields()).
"\n\n".&Apache::loncommon::end_page();
}
@@ -257,9 +333,7 @@ sub option {
sub problem_web_to_edit_header {
my ($rndseed)=@_;
my $result.='';
- if (!$Apache::lonhomework::parsing_a_task) {
- $result .= '';
- }
+ $result .= '';
$result .= '
@@ -267,20 +341,26 @@ sub problem_web_to_edit_header {
-
';
+ '
';
+ $result.=&mt('Apply style file: ').'
+&').'" />
+ '.&mt('Select').'
+
+
';
+
if (!$Apache::lonhomework::parsing_a_task) {
$result.="
-Problem Status:
+".&mt("Problem Status:")."
-Problem Type:
+".&mt("Problem Type:")."
-Feedback Mode:
+".&mt("Feedback Mode:")."
@@ -318,21 +399,45 @@ Feedback Mode:
'.'.&Apache::loncommon::help_open_topic("Analyze_Problem",
'',undef,undef,300).
'
';
+ } elsif ($Apache::lonhomework::parsing_a_task) {
+ $result.="
+
+".&mt("Problem Status:")."
+
+
+
+
";
}
return $result;
}
sub initialize_storage {
- %Apache::lonhomework::results=();
- %Apache::lonhomework::history=();
- my ($symb,$courseid,$domain,$name) = &Apache::lonxml::whichuser();
+ my ($given_symb) = @_;
+ undef(%Apache::lonhomework::results);
+ undef(%Apache::lonhomework::history);
+ my ($symb,$courseid,$domain,$name) =
+ &Apache::lonnet::whichuser($given_symb);
+
+ # anonymous users (CODEd exams) have no data
+ if ($name eq 'anonymous'
+ && !defined($domain)) {
+ return;
+ }
+
if ($env{'request.state'} eq 'construct'
|| $symb eq ''
|| $Apache::lonhomework::type eq 'practice') {
my $namespace = $symb || $env{'request.uri'};
if ($env{'form.resetdata'} eq &mt('Reset Submissions') ||
- $env{'form.resetdata'} eq &mt('New Problem Variation') ||
+ ($env{'form.resetdata'} eq &mt('New Problem Variation')
+ && $env{'form.submitted'} eq 'yes') ||
$env{'form.newrandomization'} eq &mt('New Randomization')) {
&Apache::lonnet::tmpreset($namespace,'',$domain,$name);
&Apache::lonxml::debug("Attempt reset");
@@ -345,6 +450,7 @@ sub initialize_storage {
%Apache::lonhomework::history=
&Apache::lonnet::restore($symb,$courseid,$domain,$name);
}
+
#ignore error conditions
my ($temp)=keys %Apache::lonhomework::history ;
if ($temp =~ m/^error:.*/) { %Apache::lonhomework::history=(); }
@@ -357,11 +463,13 @@ sub initialize_storage {
# Will increment totals for attempts, students, and corrects
# if running user has student role.
sub finalize_storage {
+ my ($given_symb) = @_;
my $result;
if (%Apache::lonhomework::results) {
my @remove = grep(/^INTERNAL_/,keys(%Apache::lonhomework::results));
delete(@Apache::lonhomework::results{@remove});
- my ($symb,$courseid,$domain,$name) = &Apache::lonxml::whichuser();
+ my ($symb,$courseid,$domain,$name) =
+ &Apache::lonnet::whichuser($given_symb);
if ($env{'request.state'} eq 'construct'
|| $symb eq ''
|| $Apache::lonhomework::type eq 'practice') {
@@ -383,7 +491,6 @@ sub finalize_storage {
}
return $result;
}
-use Data::Dumper;
# -------------------------------------------------------------store_aggregates
# Sends hash of values to be incremented in nohist_resourcetracker.db
@@ -432,13 +539,14 @@ sub checkout_msg {
'warning'=>'Checking out resources is subject to course policies, and may exclude future credit even if done erroneously.',
'checkout'=>'Check out Exam for Viewing',
'checkout?'=>'Check out Exam?');
+ my $uri = &Apache::lonenc::check_encrypt($env{'request.uri'});
return (<$lt{'resource'}
$lt{'id_expln'}
$lt{'warning'}
-
@@ -450,9 +558,10 @@ sub firstaccess_msg {
my ($map)=&Apache::lonnet::decode_symb($symb);
my $foldertitle=&Apache::lonnet::gettitle($map);
&Apache::lonxml::debug("map is $map title is $foldertitle");
+ my $uri = &Apache::lonenc::check_encrypt($env{'request.uri'});
return (<The resources in "$foldertitle" are open for a limited time. Once you click the 'Show Resource' button below you have $time to complete all resources "$foldertitle".
-
@@ -468,19 +577,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 = ();
@@ -493,7 +602,8 @@ sub init_problem_globals {
@Apache::structuretags::whileline=();
$Apache::lonhomework::scantronmode=0;
undef($Apache::lonhomework::name);
-
+ undef($Apache::lonhomework::default_type);
+ undef($Apache::lonhomework::type);
}
sub reset_problem_globals {
@@ -505,6 +615,11 @@ sub reset_problem_globals {
#detect if we try to do 2 problems in one file
# undef($Apache::lonhomework::parsing_a_problem);
undef($Apache::lonhomework::name);
+ undef($Apache::lonhomework::default_type);
+ undef($Apache::lonhomework::type);
+ undef($Apache::lonhomework::scantronmode);
+ undef($Apache::lonhomework::ignore_response_errors);
+ &Apache::lonhomework::reset_show_problem_status();
}
sub set_problem_state {
@@ -554,12 +669,7 @@ sub start_problem {
$Apache::lonhomework::scantronmode=1;
}
- &initialize_storage();
if ($target ne 'analyze') {
- if ($target eq 'web') {
- &Apache::lonhomework::showhash(%Apache::lonhomework::history);
- }
- 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'})) {
@@ -579,6 +689,17 @@ 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);
+ }
+
#added vars to the scripting enviroment
my $expression='$external::part=\''.$Apache::inputtags::part.'\';';
$expression.='$external::type=\''.$Apache::lonhomework::type.'\';';
@@ -586,11 +707,15 @@ sub start_problem {
my $status;
my $accessmsg;
- #should get back a or the neccesary stuff to start XML/MathML
my $name= &get_resource_name($parstack,$safeeval);
- my ($result,$form_tag_start)=
- &page_start($target,$token,$tagstack,$parstack,$parser,$safeeval,
- $name);
+ my ($result,$form_tag_start);
+ if ($target eq 'web' || $target eq 'webgrade' || $target eq 'tex'
+ || $target eq 'edit') {
+ ($result,$form_tag_start) =
+ &page_start($target,$token,$tagstack,$parstack,$parser,$safeeval,
+ $name);
+ }
+
if ($target eq 'tex' and $env{'request.symb'} =~ m/\.page_/) {$result='';}
if ($target eq 'analyze') { my $rndseed=&setup_rndseed($safeeval); }
@@ -612,7 +737,7 @@ sub start_problem {
}
#handle rand seed in construction space
my $rndseed=&setup_rndseed($safeeval);
- my ($symb)=&Apache::lonxml::whichuser();
+ my ($symb)=&Apache::lonnet::whichuser();
if ($env{'request.state'} ne "construct" &&
($symb eq '' || $Apache::lonhomework::type eq 'practice')) {
$form_tag_start.='';
# create a page header and exit
if ($env{'request.state'} eq "construct") {
@@ -717,7 +850,6 @@ sub start_problem {
$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 = '';
@@ -735,7 +867,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
@@ -811,14 +942,14 @@ sub end_problem {
if ($Apache::lonhomework::type eq 'exam' and $allow_print_points==1) { $frontmatter .= '\fbox{\textit{'.$weight.' pt}}';}
}
} else {
- $frontmatter .= '\vskip 1mm\textit{Due date: '.$duedate.'} \\\\\\\\';
+ $frontmatter .= '\vskip 1mm\textit{Due date: '.$duedate.'} \\\\\\\\'.$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}}';}
} else {
- $frontmatter .= '\vskip 1mm \\\\\\\\';
+ $frontmatter .= '\vskip 1mm \\\\\\\\'.$startminipage;
}
}
$result =~ s/INSERTTEXFRONTMATTERHERE/$frontmatter/;
@@ -852,10 +983,10 @@ sub end_problem {
if ($target ne 'tex' &&
$env{'form.answer_output_mode'} ne 'tex') {
$result.="";
- $result.=&Apache::lonhtmlcommon::htmlareaselectactive(@Apache::lonxml::htmlareafields);
+ $result.= &Apache::lonhtmlcommon::htmlareaselectactive(&Apache::lonhtmlcommon::get_htmlareafields());
}
if ($target eq 'web') {
- $result.=&Apache::lonxml::xmlend().'';
+ $result.= &Apache::loncommon::end_page({'discussion' => 1});
} elsif ($target eq 'tex') {
my $endminipage = '';
if (not $env{'form.problem_split'}=~/yes/) {
@@ -863,13 +994,12 @@ sub end_problem {
}
if ($env{'form.print_discussions'} eq 'yes') {
$result.=&Apache::lonxml::xmlend($target,$parser);
- $result=~s/<\/html>//;
} else {
$result .= '\keephidden{ENDOFPROBLEM}\vskip 0.5mm\noindent\makebox[\textwidth/$number_of_columns][b]{\hrulefill}';
if (not $env{'request.symb'} =~ m/\.page_/) {
$result .= $endminipage.'\end{document} ';
} else {
- $result .= '';
+ $result .= $endminipage;
}
}
}
@@ -880,7 +1010,7 @@ sub end_problem {
}
if ($target eq 'answer' && ($env{'request.state'} eq 'construct')
&& $env{'form.answer_output_mode'} ne 'tex') {
- $result.=&Apache::lonxml::xmlend().'