[LON-CAPA-cvs] cvs: loncom /homework structuretags.pm
albertel
lon-capa-cvs@mail.lon-capa.org
Wed, 13 Aug 2003 18:19:59 -0000
albertel Wed Aug 13 14:19:59 2003 EDT
Modified files:
/loncom/homework structuretags.pm
Log:
- redo init / rest code
- have <library> call init code
- have get_resource_name act more cachingly
- have get_resource_name if it can't find any info default to resquest.url
Index: loncom/homework/structuretags.pm
diff -u loncom/homework/structuretags.pm:1.203 loncom/homework/structuretags.pm:1.204
--- loncom/homework/structuretags.pm:1.203 Wed Aug 13 13:54:12 2003
+++ loncom/homework/structuretags.pm Wed Aug 13 14:19:59 2003
@@ -1,7 +1,7 @@
# The LearningOnline Network with CAPA
# definition of tags that give a structure to a document
#
-# $Id: structuretags.pm,v 1.203 2003/08/13 17:54:12 sakharuk Exp $
+# $Id: structuretags.pm,v 1.204 2003/08/13 18:19:59 albertel Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -130,11 +130,18 @@
#use Time::HiRes();
sub get_resource_name {
my ($parstack,$safeeval)=@_;
+ if (defined($Apache::lonhomework::name)) {
+ return $Apache::lonhomework::name;
+ }
my $name=&Apache::lonnet::gettitle();
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-;
+ }
$Apache::lonhomework::name=$name;
return $name;
}
@@ -268,6 +275,41 @@
ENDCHECKOUT
}
+sub init_problem_globals {
+ my ($type)=@_;
+ #initialize globals
+ if ($type eq 'problem') {
+ $Apache::inputtags::part='0';
+ @Apache::inputtags::partlist=('0');
+ $Apache::lonhomework::problemstatus=
+ &Apache::lonnet::EXT('resource.0.problemstatus');
+ } else {
+ $Apache::inputtags::part='';
+ @Apache::inputtags::partlist=();
+ $Apache::lonhomework::problemstatus='';
+ }
+ @Apache::inputtags::responselist = ();
+ @Apache::inputtags::importlist = ();
+ @Apache::inputtags::previous=();
+ @Apache::inputtags::previous_version=();
+ $Apache::structuretags::printanswer='No';
+ @Apache::structuretags::whileconds=();
+ @Apache::structuretags::whilebody=();
+ @Apache::structuretags::whileline=();
+ $Apache::lonhomework::scantronmode=0;
+ undef($Apache::lonhomework::name);
+
+}
+
+sub reset_problem_globals {
+ my ($type)=@_;
+ undef(%Apache::lonhomework::history);
+ undef(%Apache::lonhomework::results);
+ undef($Apache::inputtags::part);
+ undef($Apache::lonhomework::parsing_a_problem);
+ undef($Apache::lonhomework::name);
+}
+
sub start_problem {
my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
@@ -279,20 +321,7 @@
}
$Apache::lonhomework::parsing_a_problem=1;
-#initialize globals
- $Apache::inputtags::part='0';
- @Apache::inputtags::partlist=('0');
- @Apache::inputtags::responselist = ();
- @Apache::inputtags::importlist = ();
- @Apache::inputtags::previous=();
- @Apache::inputtags::previous_version=();
- $Apache::structuretags::printanswer='No';
- @Apache::structuretags::whileconds=();
- @Apache::structuretags::whilebody=();
- @Apache::structuretags::whileline=();
- $Apache::lonhomework::scantronmode=0;
- $Apache::lonhomework::problemstatus=
- &Apache::lonnet::EXT('resource.0.problemstatus');
+ &init_problem_globals('problem');
if (defined($ENV{'scantron.maxquest'})) {
$Apache::lonhomework::scantronmode=1;
@@ -443,11 +472,6 @@
my $due_file_content = $due_file_content[$#due_file_content];
chomp $due_file_content;
my $name_of_resourse= &get_resource_name($parstack,$safeeval);
- if (not $name_of_resourse=~/\S+/) {
- $name_of_resourse=$ENV{'request.uri'};
- $name_of_resourse=~/\/([^\/]+)$/;
- $name_of_resourse=$1;
- }
if ($due_file_content ne $duedate) {
$temp_file = Apache::File->new('>'.$filename);
print $temp_file "$duedate\n";
@@ -556,10 +580,8 @@
if ($ENV{'request.state'} eq 'construct' && $target eq 'web') {
&Apache::inputtags::check_for_duplicate_ids();
}
- undef(%Apache::lonhomework::history);
- undef(%Apache::lonhomework::results);
- undef($Apache::inputtags::part);
- undef($Apache::lonhomework::parsing_a_problem);
+
+ &reset_problem_globals('problem');
return $result;
}
@@ -568,7 +590,7 @@
sub start_library {
my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
my ($result,$head_tag_start,$body_tag_start,$form_tag_start);
-
+ if ($$tagstack[0] eq 'library') { &init_problem_globals('library') };
if ($target eq 'edit') {
($result,$head_tag_start,$body_tag_start,$form_tag_start)=
&page_start($target,$token,$tagstack,$parstack,$parser,$safeeval);
@@ -602,6 +624,7 @@
$ENV{'request.state'} eq "construct") {
$result.='</form></body>'.&Apache::lonxml::xmlend();
}
+ if ($$tagstack[0] eq 'library') { &reset_problem_globals('library') };
return $result;
}