--- loncom/homework/structuretags.pm 2006/04/15 01:06:59 1.346
+++ loncom/homework/structuretags.pm 2007/05/28 22:51:29 1.378
@@ -1,7 +1,7 @@
# The LearningOnline Network with CAPA
# definition of tags that give a structure to a document
#
-# $Id: structuretags.pm,v 1.346 2006/04/15 01:06:59 albertel Exp $
+# $Id: structuretags.pm,v 1.378 2007/05/28 22:51:29 albertel Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -38,6 +38,9 @@ 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'));
}
@@ -79,13 +82,20 @@ sub page_start {
}
}
-
if ($target eq 'tex') {
return
&Apache::londefdef::start_html($target,$token,$tagstack,
$parstack,$parser,$safeeval);
}
+ $extra_head.= '
+
+';
+
my %body_args;
if (defined($found{'html'})) {
$body_args{'skip_phases'}{'head'}=1;
@@ -132,7 +142,7 @@ sub page_start {
$body_args{'force_register'} = 1;
$body_args{'add_entries'} = \%add_entries;
}
-
+ $body_args{'no_auto_mt_title'} = 1;
my $page_start = &Apache::loncommon::start_page($name,$extra_head,
\%body_args);
@@ -140,7 +150,7 @@ sub page_start {
&& $env{'request.state'} ne 'construct'
&& ($target eq 'web' || $target eq 'webgrade')) {
- my ($symb,undef,undef,undef,$publicuser)= &Apache::lonxml::whichuser();
+ 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.")." ";
@@ -160,9 +170,16 @@ sub page_start {
if ($target eq 'edit') {
$form_tag_start.=&Apache::edit::form_change_detection();
}
- $form_tag_start.='>';
- }
+ $form_tag_start.='>'."\n";
+ my $symb=&Apache::lonnet::symbread();
+ if ($symb =~ /\S/) {
+ $symb=
+ &HTML::Entities::encode(&Apache::lonenc::check_encrypt($symb));
+ $form_tag_start.=
+ "\t".' '."\n";
+ }
+ }
return ($page_start,$form_tag_start);
}
@@ -172,7 +189,7 @@ sub get_resource_name {
if (defined($Apache::lonhomework::name)) {
return $Apache::lonhomework::name;
}
- my ($symb)=&Apache::lonxml::whichuser();
+ my ($symb)=&Apache::lonnet::whichuser();
my $name=&Apache::lonnet::gettitle($symb);
if ($name eq '') {
$name=&Apache::lonnet::EXT('resource.title');
@@ -189,7 +206,7 @@ sub get_resource_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'
@@ -204,7 +221,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));
@@ -242,7 +260,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')
.'
'.
'';
}
@@ -250,7 +268,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();
}
@@ -267,9 +285,7 @@ sub option {
sub problem_web_to_edit_header {
my ($rndseed)=@_;
my $result.=' ';
- if (!$Apache::lonhomework::parsing_a_task) {
- $result .= ' ';
- }
+ $result .= ' ';
$result .= '
@@ -284,9 +300,9 @@ sub problem_web_to_edit_header {
: &mt(' Show All Foils');
if (defined($env{'form.showallfoils'})) { $result.='checked="on"'; }
- $result.= ' />'.$show_all_foils_text.
+ $result.= ' />'.$show_all_foils_text.''.
&Apache::loncommon::help_open_topic('Problem_Editor_Testing_Area','Testing Problems').
- ' ';
+ ' ';
if (!$Apache::lonhomework::parsing_a_task) {
$result.="
@@ -328,21 +344,45 @@ Feedback Mode:
'.'.&Apache::loncommon::help_open_topic("Analyze_Problem",
'',undef,undef,300).
' ';
+ } elsif ($Apache::lonhomework::parsing_a_task) {
+ $result.="
+
+Problem Status:
+
+
+ ".&option('CLOSED' ,'problemstate').&mt("Closed")."
+ ".&option('CAN_ANSWER' ,'problemstate').&mt("Answerable")."
+ ".&option('WEB_GRADE' ,'problemstate').&mt("Criteria Grading")."
+ ".&option('SHOW_ANSWER' ,'problemstate').&mt("Show Feedback")."
+
+
+
+ ";
}
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");
@@ -355,6 +395,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=(); }
@@ -367,11 +408,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') {
@@ -442,13 +485,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'}
-
@@ -460,9 +504,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".
-
@@ -503,7 +548,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 {
@@ -515,6 +561,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::problemstatus);
+ undef($Apache::lonhomework::ignore_response_errors);
}
sub set_problem_state {
@@ -564,11 +615,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') &&
@@ -589,6 +636,12 @@ sub start_problem {
}
$Apache::lonhomework::default_type = $Apache::lonhomework::type;
+ &initialize_storage();
+ 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.'\';';
@@ -597,9 +650,14 @@ sub start_problem {
my $accessmsg;
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); }
@@ -621,7 +679,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") {
@@ -726,7 +792,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 = '';
@@ -744,7 +809,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
@@ -861,7 +925,7 @@ 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::loncommon::end_page({'discussion' => 1});
@@ -872,7 +936,6 @@ 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_/) {
@@ -905,7 +968,6 @@ sub end_problem {
$result .= &problem_edit_footer();
} elsif ($target eq 'modified') {
$result .= $token->[2];
- $result.=&Apache::edit::handle_insertafter($token->[1]);
}
if ($env{'request.state'} eq 'construct' && $target eq 'web') {
@@ -921,7 +983,7 @@ sub end_problem {
sub start_library {
my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
my ($result,$form_tag_start);
- if ($$tagstack[0] eq 'library') {
+ if ($#$tagstack eq 0 && $$tagstack[0] eq 'library') {
&init_problem_globals('library');
$Apache::lonhomework::type='problem';
}
@@ -934,9 +996,8 @@ sub start_library {
$result.=$temp;
} elsif ($target eq 'modified') {
$result=$token->[4];
- $result.=&Apache::edit::handle_insert();
} elsif (($target eq 'web' || $target eq 'webgrade')
- && $$tagstack[0] eq 'library'
+ && ($#$tagstack eq 0 && $$tagstack[0] eq 'library')
&& $env{'request.state'} eq "construct" ) {
my $name=&get_resource_name($parstack,$safeeval);
($result,$form_tag_start)=
@@ -955,11 +1016,14 @@ sub end_library {
my $result='';
if ($target eq 'edit') {
$result=&problem_edit_footer();
- } elsif ($target eq 'web' && $$tagstack[0] ne 'problem' &&
- $env{'request.state'} eq "construct") {
- $result.=''.&Apache::lonxml::xmlend();
+ } elsif ($target eq 'web'
+ && ($#$tagstack eq 0 && $$tagstack[0] eq 'library')
+ && $env{'request.state'} eq "construct") {
+ $result.=''.&Apache::loncommon::end_page({'discussion' => 1});
+ }
+ if ( $#$tagstack eq 0 && $$tagstack[0] eq 'library') {
+ &reset_problem_globals('library');
}
- if ($$tagstack[0] eq 'library') { &reset_problem_globals('library') };
return $result;
}
@@ -1162,7 +1226,7 @@ sub end_while {
while ($return) {
if (time-$starttime >
$Apache::lonnet::perlvar{'lonScriptTimeout'}) {
- #$return = 0; $error=1; next;
+ $return = 0; $error=1; next;
}
$result.=&Apache::scripttag::xmlparse($bodytext);
$return = &Apache::run::run($code,$safeeval);
@@ -1360,7 +1424,7 @@ sub start_part {
}
if (($Apache::lonhomework::type eq 'exam') && ($allow_print_points)) { $result .= '\fbox{\textit{'.$weight.' pt}}';}
} elsif ($target eq 'web') {
- $result.=' ';
+ $result.=' ';
}
}
}
@@ -1378,7 +1442,6 @@ sub start_part {
#limiting ids to only letters numbers, and space
$token->[2]->{'id'}=~s/[^A-Za-z0-9 ]//gs;
$result = &Apache::edit::rebuild_tag($token);
- $result.=&Apache::edit::handle_insert();
}
}
return $result;
@@ -1416,7 +1479,6 @@ sub end_part {
$result.=&Apache::edit::end_table();
} elsif ($target eq 'modified') {
$result .= $token->[2];
- $result.=&Apache::edit::handle_insertafter($token->[1]);
}
pop @Apache::inputtags::status;
$Apache::inputtags::part='';
@@ -1443,15 +1505,21 @@ sub end_preduedate {
return '';
}
+# In all the modes where text is
+# displayable, all we do is eat up the text between the start/stop
+# tags if the conditions are not right to display it.
sub start_postanswerdate {
my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
- if ($target eq 'web' || $target eq 'grade' || $target eq 'webgrade') {
+ my $pav = &Apache::lonnet::allowed('pav', $env{'request.course.id'}) ||
+ &Apache::lonnet::allowed('pav',
+ $env{'request.course.id'}.'/'.$env{'request.course.sec'});
+ if ($target eq 'web' || $target eq 'grade' || $target eq 'webgrade' ||
+ $target eq 'tex' ) {
if ($Apache::lonhomework::scantronmode ||
- $Apache::inputtags::status['-1'] ne 'SHOW_ANSWER') {
+ $Apache::inputtags::status['-1'] ne 'SHOW_ANSWER' ||
+ (($target eq 'tex') && !$pav)) {
&Apache::lonxml::get_all_text("/postanswerdate",$parser,$style);
}
- } elsif ($target eq 'tex') {
- &Apache::lonxml::get_all_text("/postanswerdate",$parser,$style);
}
return '';
}
@@ -1558,9 +1626,10 @@ sub end_startouttext {
."
".
&Apache::edit::insertlist($target,$token).
+ ' ' .
+ &Apache::loncommon::helpLatexCheatsheet().
&Apache::edit::end_row().
- &Apache::edit::start_spanning_row()."\n"
- . &Apache::loncommon::helpLatexCheatsheet () .
+ &Apache::edit::start_spanning_row()."\n".
&Apache::edit::editfield($token->[1],$text,"",80,8,1);
}
if ($target eq 'modified') {
@@ -1578,7 +1647,8 @@ sub start_endouttext {
if ($target eq "edit" ) { $result=" ".&Apache::edit::end_table()."\n"; }
if ($target eq "modified") {
$result=' '.
- &Apache::edit::handle_insertafter('startouttext'); }
+ &Apache::edit::handle_insertafter('startouttext');
+ }
return $result;
}
@@ -1611,9 +1681,9 @@ sub start_simpleeditbutton {
(&Apache::lonnet::allowed('mdc',$env{'request.course.id'}))) {
my $url=$env{'request.noversionuri'};
$url=~s/\?.*$//;
- my ($symb) = &Apache::lonxml::whichuser();
+ my ($symb) = &Apache::lonnet::whichuser();
$result=''.
- ''.&mt('Edit').' - '.&mt('Note: it can take up to 10 minutes for changes to take effect for all users.').
+ ''.&mt('Edit').' - '.&mt('Note: it can take up to 10 minutes for changes to take effect for all users.').
&Apache::loncommon::help_open_topic('Caching').'
';
}
return $result;