--- loncom/homework/edit.pm 2005/12/15 23:20:55 1.98
+++ loncom/homework/edit.pm 2007/01/29 23:51:19 1.104
@@ -1,7 +1,7 @@
# The LearningOnline Network with CAPA
# edit mode helpers
#
-# $Id: edit.pm,v 1.98 2005/12/15 23:20:55 albertel Exp $
+# $Id: edit.pm,v 1.104 2007/01/29 23:51:19 albertel Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -32,6 +32,9 @@ use strict;
use Apache::lonnet;
use HTML::Entities();
use Apache::lonlocal;
+use lib '/home/httpd/lib/perl/';
+use LONCAPA;
+
# Global Vars
# default list of colors to use in editing
@@ -87,17 +90,10 @@ sub tag_end {
sub start_table {
my ($token)=@_;
- my $tag = $token->[1];
- my $tagnum;
- foreach my $namespace (reverse @Apache::lonxml::namespace) {
- my $testtag=$namespace.'::'.$tag;
- $tagnum=$Apache::lonxml::insertlist{"$testtag.num"};
- &Apache::lonxml::debug(" $testtag ");
- if (defined($tagnum)) { last; }
- }
- if (!defined ($tagnum)) {$tagnum=$Apache::lonxml::insertlist{"$tag.num"};}
- my $color = $Apache::lonxml::insertlist{"$tagnum.color"};
- &Apache::lonxml::debug(" $tagnum -- $color");
+ my $tag = &Apache::lonxml::get_tag($token);
+
+ my $color = $Apache::lonxml::insertlist{"$tag.color"};
+ &Apache::lonxml::debug(" $tag -- $color");
if (!defined($color)) {
$color = $Apache::edit::colorlist[$Apache::edit::colordepth];
}
@@ -174,20 +170,21 @@ sub handle_delete {
sub get_insert_list {
my ($tagname) = @_;
my $result='';
- my @tagnums= ();
+ my @tags= ();
#&Apache::lonxml::debug("keys ".join("\n",sort(keys(%Apache::lonxml::insertlist))));
if ($Apache::lonxml::insertlist{"$tagname.which"}) {
- push (@tagnums, @{ $Apache::lonxml::insertlist{"$tagname.which"} });
+ push (@tags, @{ $Apache::lonxml::insertlist{"$tagname.which"} });
}
foreach my $namespace (@Apache::lonxml::namespace) {
if ($Apache::lonxml::insertlist{"$namespace".'::'."$tagname.which"}) {
- push (@tagnums, @{ $Apache::lonxml::insertlist{"$namespace".'::'."$tagname.which"} });
+ push (@tags, @{ $Apache::lonxml::insertlist{"$namespace".'::'."$tagname.which"} });
}
}
- if (@tagnums) {
+ if (@tags) {
my %options;
- foreach my $tagnum (@tagnums) {
- my $descrip=$Apache::lonxml::insertlist{"$tagnum.description"};
+ foreach my $tag (@tags) {
+ my $descrip=$Apache::lonxml::insertlist{"$tag.description"};
+ my $tagnum =$Apache::lonxml::insertlist{"$tag.num"};
$options{$descrip} ="\n";
}
@@ -225,37 +222,26 @@ sub innerinsertlist {
sub handle_insert {
if ($env{"form.insert_$Apache::lonxml::curdepth"} eq '') { return ''; }
- my $result;
my $tagnum = $env{"form.insert_$Apache::lonxml::curdepth"};
- my $func=$Apache::lonxml::insertlist{"$tagnum.function"};
- if ($func eq 'default') {
- my $newtag=$Apache::lonxml::insertlist{"$tagnum.tag"};
- my $namespace;
- if ($newtag =~ /::/) { ($namespace,$newtag) = split(/::/,$newtag); }
- $result.="\n<$newtag>\n$newtag>";
- } else {
- if (defined(&$func)) {
- {
- no strict 'refs';
- $result.=&$func();
- }
- } else {
- my $newtag=$Apache::lonxml::insertlist{"$tagnum.tag"};
- &Apache::lonxml::error("Unable to insert tag ".$Apache::lonxml::curdepth." ($tagnum) $newtag, func was not defined.");
- }
- }
- return $result;
+ return &do_insert($tagnum);
}
sub handle_insertafter {
my $tagname=shift;
- if ($env{"form.insert_after_$tagname\_$Apache::lonxml::curdepth"} eq '')
- { return ''; }
- my $result;
+ if ($env{"form.insert_after_$tagname\_$Apache::lonxml::curdepth"} eq '') {
+ return '';
+ }
my $tagnum =$env{"form.insert_after_$tagname\_$Apache::lonxml::curdepth"};
- my $func=$Apache::lonxml::insertlist{"$tagnum.function"};
+ return &do_insert($tagnum);
+}
+
+sub do_insert {
+ my ($tagnum) = @_;
+ my $result;
+
+ my $newtag = $Apache::lonxml::insertlist{"$tagnum.tag"};
+ my $func = $Apache::lonxml::insertlist{"$newtag.function"};
if ($func eq 'default') {
- my $newtag=$Apache::lonxml::insertlist{"$tagnum.tag"};
my $namespace;
if ($newtag =~ /::/) { ($namespace,$newtag) = split(/::/,$newtag); }
$result.="\n<$newtag>\n$newtag>";
@@ -266,8 +252,7 @@ sub handle_insertafter {
$result.=&$func();
}
} else {
- my $newtag=$Apache::lonxml::insertlist{"$tagnum.tag"};
- &Apache::lonxml::error("Unable to insert (after) tag $newtag, $func was not defined. ($tagname $tagnum)");
+ &Apache::lonxml::error("Unable to insert tag $newtag, $func was not defined. ($tagnum)");
}
}
return $result;
@@ -504,11 +489,14 @@ sub js_change_detection {