--- loncom/interface/lonfeedback.pm 2004/08/01 16:05:14 1.111
+++ loncom/interface/lonfeedback.pm 2004/08/04 18:04:57 1.113
@@ -1,7 +1,7 @@
# The LearningOnline Network
# Feedback
#
-# $Id: lonfeedback.pm,v 1.111 2004/08/01 16:05:14 raeburn Exp $
+# $Id: lonfeedback.pm,v 1.113 2004/08/04 18:04:57 raeburn Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -36,6 +36,7 @@ use Apache::loncommon();
use Apache::lontexconvert();
use Apache::lonlocal; # must not have ()
use Apache::lonhtmlcommon();
+use HTML::LCParser();
use Apache::lonspeller();
sub discussion_open {
@@ -268,8 +269,10 @@ sub list_discussion {
}
my ($message,$subject);
if ($idx > 0) {
- if ($contrib{$idx.':message'} =~ /.*::::\Q$numoldver\E::::(.+?)$/si) {
- $message = $1;
+ if ($contrib{$idx.':message'} =~ /^/) {
+ my %versions = ();
+ &get_post_versions(\%versions,$contrib{$idx.':message'},$numoldver);
+ $message = &HTML::Entities::decode($versions{$numoldver});
} else {
$message = $contrib{$idx.':message'};
}
@@ -280,8 +283,10 @@ sub list_discussion {
$message=~s/\n/\
/g;
$message=&Apache::lontexconvert::msgtexconverted($message);
if ($idx > 0) {
- if ($contrib{$idx.':subject'} =~ /.*::::\Q$numoldver\E::::(.+?)$/si) {
- $subject = $1;
+ if ($contrib{$idx.':subject'} =~ /^ 0) {
- if ($contrib{$idx.':message'} =~ /::::\Q$numoldver\E::::(.+?)$/si) {
- $message = $1;
+ if ($contrib{$idx.':message'} =~ /^/g;
$quote=''.&Apache::lontexconvert::msgtexconverted($message).'
';
if ($idx > 0) {
- if ($contrib{$idx.':subject'} =~ /::::\Q$numoldver\E::::(.+?)$/si) {
- $subject = $1;
+ if ($contrib{$idx.':subject'} =~ /^&"');
} else {
$attachmenturls = $contrib{$idx.':attachmenturl'};
- if ($contrib{$idx.':message'} =~ /.*::::(\d+)::::(.*?)$/si) {
- $numoldver = $1;
- $comment = $2;
+ if ($contrib{$idx.':message'} =~ /^/) {
+ my %versions = ();
+ &get_post_versions(\%versions,$contrib{$idx.':message'},$numoldver);
+ $comment = $versions{$numoldver};
} else {
- $comment = $contrib{$idx.':message'};
+ $comment = &HTML::Entities::encode($contrib{$idx.':message'},'<>&"');
}
- $comment = &HTML::Entities::encode($comment,'<>&"');
- if ($contrib{$idx.':subject'} =~ /.*::::\d+::::(.+?)$/si) {
- $subject = $1;
+ if ($contrib{$idx.':subject'} =~ //) {
+ my %versions = ();
+ &get_post_versions(\%versions,$contrib{$idx.':subject'},$numoldver);
+ $subject = $versions{$numoldver};
} else {
- $subject = $contrib{$idx.':subject'};
+ $subject = &HTML::Entities::encode($contrib{$idx.':subject'},'<>&"');
}
- $subject = &HTML::Entities::encode($subject,'<>&"');
if (defined($contrib{$idx.':replyto'})) {
$parentmsg = $contrib{$idx.':replyto'};
}
@@ -1145,7 +1163,7 @@ END
}
if ($ENV{'form.editdisc'}) {
if ($attachmenturls) {
- &extract_attachments($attachmenturls,$idx,$numoldver,\$attachmsg,\@attachments,\%currattach,\@currdelold);
+ &extract_attachments($attachmenturls,$idx,$numoldver,\$attachmsg,\%attachments,\%currattach,\@currdelold);
$attachnum = scalar(keys %currattach);
foreach (keys %currattach) {
$r->print(''."\n");
@@ -1652,7 +1670,44 @@ END
END
}
-sub fail_redirect {
+sub get_post_versions {
+ my ($versions,$incoming,$numver) = @_;
+ my $p = HTML::LCParser->new(\$incoming);
+ my $done = 0;
+ while ( (my $token = $p->get_tag("version")) && (!$done)) {
+ my $num = $token->[1]{num};
+ my $text = $p->get_text("/version");
+ if (defined($numver)) {
+ if ($num == $numver) {
+ $$versions{$numver}=$text;
+ $done = 1;
+ }
+ } else {
+ $$versions{$num}=$text;
+ }
+ }
+ return;
+}
+
+sub get_post_attachments {
+ my ($attachments,$attachmenturls) = @_;
+ my $num;
+ my $p = HTML::LCParser->new(\$attachmenturls);
+ while (my $token = $p->get_tag("attachment","filename","post")) {
+ if ($token->[0] eq "attachment") {
+ $num = $token->[1]{id};
+ %{$$attachments{$num}} =();
+ } elsif ($token->[0] eq "filename") {
+ $$attachments{$num}{'filename'} = $p->get_text("/filename");
+ } elsif ($token->[0] eq "post") {
+ my $id = $token->[1]{id};
+ $$attachments{$num}{$id} = $p->get_text("/post");
+ }
+ }
+ return;
+}
+
+sub fail_redirect {;
my ($r,$feedurl) = @_;
if ($feedurl=~/^\/adm\//) { $feedurl.='?register=1' };
$r->print (</) {
+ $contrib{'subject'} = ''.&HTML::Entities::encode($contrib{'subject'},'<>&"').'';
+ $contrib{'subject'} = $oldcontrib{$oldidx.':subject'}.$contrib{'subject'};
} else {
- $contrib{'subject'} = '::::0::::'.$oldcontrib{$oldidx.':subject'}.'::::1::::'.$contrib{'subject'};
+ $contrib{'subject'} = ''.&HTML::Entities::encode($oldcontrib{$oldidx.':subject'},'<>&"').''.&HTML::Entities::encode($contrib{'subject'},'<>&"').'';
}
}
if (defined($oldcontrib{$oldidx.':message'})) {
- if ($oldcontrib{$oldidx.':message'} =~ /::::\d+::::/) {
- $contrib{'message'} = $oldcontrib{$oldidx.':message'}.'::::'.$numnewver.'::::'.$contrib{'message'};
+ if ($oldcontrib{$oldidx.':message'} =~ /^/) {
+ $contrib{'message'} = ''.&HTML::Entities::encode($contrib{'message'},'<>&"').'';
+ $contrib{'message'} = $oldcontrib{$oldidx.':message'}.$contrib{'message'};
} else {
- $contrib{'message'} = '::::0::::'.$oldcontrib{$oldidx.':message'}.'::::1::::'.$contrib{'message'};
+ $contrib{'message'} = ''.&HTML::Entities::encode($oldcontrib{$oldidx.':message'},'<>&"').''.&HTML::Entities::encode($contrib{'message'},'<>&"').'';
}
}
$contrib{'history'} .= $oldcontrib{$oldidx.':timestamp'};
@@ -2102,10 +2159,10 @@ sub modify_attachments {
my $bodytag=&Apache::loncommon::bodytag('Discussion Post Attachments',
'','');
my $msg = '';
- my @attachments = ();
+ my %attachments = ();
my %currattach = ();
if ($idx) {
- &extract_attachments($attachmenturls,$idx,$numoldver,\$msg,\@attachments,\%currattach,$currdelold);
+ &extract_attachments($attachmenturls,$idx,$numoldver,\$msg,\%attachments,\%currattach,$currdelold);
}
$r->print(<
@@ -2130,10 +2187,10 @@ END
my @currold = keys %currattach;
if (@currold > 0) {
$r->print("The following attachments were part of the most recent saved version of this posting.
Check the checkboxes for any you wish to remove
\n");
- foreach (@currold) {
- my $id = $_;
- $attachments[$id] =~ m#/([^/]+)$#;
- $r->print(' '.$1.'
'."\n");
+ foreach my $id (@currold) {
+ my $attachurl = &HTML::Entities::decode($attachments{$id}{'filename'});
+ $attachurl =~ m#/([^/]+)$#;
+ $r->print(' '.$1.'
'."\n");
}
$r->print("
");
}
@@ -2266,52 +2323,44 @@ ENDATTACH
sub extract_attachments {
my ($attachmenturls,$idx,$numoldver,$message,$attachments,$currattach,$currdelold) = @_;
- if ($attachmenturls =~ m/::::\d+:[\.yn\d]+::::/) {
- @{$attachments} = split/::::\d+:[\.yn\d]+::::/,$attachmenturls;
- shift @{$attachments};
- my $searchstr = '::::';
- for (my $i=0; $i<@{$attachments}; $i++) {
- if ($attachmenturls =~ m#^\Q$searchstr\E(\d+)(:[\.yn\d]+)::::#) {
- my $info = $1.$2;
- my $attachid = $1-1;
- $searchstr .= $info.'::::'.$$attachments[$i].'::::';
- if ($info =~ /\.$numoldver([yn])\./) {
- if (defined($currdelold)) {
- if (@{$currdelold} > 0) {
- unless (grep/^$attachid$/,@{$currdelold}) {
- my $id = $i;
- $$currattach{$id} = $1;
- }
- } else {
- my $id = $i;
- $$currattach{$id} = $1;
+ if ($attachmenturls =~ m/^/) {
+ &get_post_attachments($attachments,$attachmenturls);
+ foreach my $id (sort keys %{$attachments}) {
+ if (exists($$attachments{$id}{$numoldver})) {
+ if (defined($currdelold)) {
+ if (@{$currdelold} > 0) {
+ unless (grep/^$id$/,@{$currdelold}) {
+ $$currattach{$id} = $$attachments{$id}{$numoldver};
}
} else {
- my $id = $i;
- $$currattach{$id} = $1;
+ $$currattach{$id} = $$attachments{$id}{$numoldver};
}
+ } else {
+ $$currattach{$id} = $$attachments{$id}{$numoldver};
}
}
}
my @attached = (sort { $a <=> $b } keys %{$currattach});
if (@attached == 1) {
my $id = $attached[0];
- $$attachments[$attached[0]]=~m|/([^/]+)$|;
- $$message.='
'.
+ my $attachurl = &HTML::Entities::decode($$attachments{$id}{'filename'});
+ $attachurl=~m|/([^/]+)$|;
+ $$message.='
'.
$1.'
';
&Apache::lonnet::allowuploaded('/adm/feedback',
- $$attachments[$id]);
+ $attachurl);
} elsif (@attached > 1) {
$$message.='';
foreach (@attached) {
my $id = $_;
+ my $attachurl = &HTML::Entities::decode($$attachments{$id}{'filename'});
my ($fname)
- =($$attachments[$id]=~m|/([^/]+)$|);
- $$message .= '- '.
$fname.'
';
&Apache::lonnet::allowuploaded('/adm/feedback',
- $$attachments[$id]);
+ $attachurl);
}
$$message .= '
';
}
@@ -2322,7 +2371,7 @@ sub extract_attachments {
': '.
$fname.'
';
- $$attachments[0] = $attachmenturls;
+ $$attachments{0} = $attachmenturls;
$$currattach{'0'} = 'n';
&Apache::lonnet::allowuploaded('/adm/feedback',
$attachmenturls);
@@ -2333,7 +2382,7 @@ sub construct_attachmenturl {
my ($currnewattach,$keepold,$symb,$idx)=@_;
my $oldattachmenturl;
my $newattachmenturl;
- my $startnum = 1;
+ my $startnum = 0;
my $currver = 0;
if (($ENV{'form.editdisc'}) && ($idx)) {
my %contrib=&Apache::lonnet::restore($symb,$ENV{'request.course.id'},
@@ -2351,37 +2400,35 @@ sub construct_attachmenturl {
$currver = 1;
}
if ($oldattachmenturl) {
- if ($oldattachmenturl =~ m/::::\d+:[\.yn\d]+::::/) {
- my @attachments = split/::::\d+:[\.yn\d]+::::/,$oldattachmenturl;
- shift @attachments;
- $startnum += @attachments;
- my $searchstr = '::::';
- $newattachmenturl = '::::';
- for (my $i=0; $i<@attachments; $i++) {
- if ($oldattachmenturl =~ m#^\Q$searchstr\E(\d+)(:[\.yn\d]+)::::#) {
- my $attachid = $1 - 1;
- $searchstr .= $1.$2.'::::'.$attachments[$i].'::::';
- $newattachmenturl .= $1.$2;
- if (grep/^$attachid$/,@{$keepold}) {
- $newattachmenturl .= '.'.$currver.'n.';
- }
- $newattachmenturl .= '::::'.$attachments[$i].'::::';
+ if ($oldattachmenturl =~ m/^/) {
+ my %attachments = ();
+ my $prevver = $currver-1;
+ &get_post_attachments(\%attachments,$oldattachmenturl);
+ my $numattach = keys %attachments;
+ $startnum += $numattach;
+ foreach my $num (sort {$a <=> $b} keys %attachments) {
+ $newattachmenturl .= ''.$attachments{$num}{'filename'}.'';
+ foreach (sort {$a <=> $b} keys %{$attachments{$num}}) {
+ $newattachmenturl .= ''.$attachments{$num}{$_}.'';
}
+ if (grep/^$num$/,@{$keepold}) {
+ $newattachmenturl .= ''.$attachments{$num}{$prevver}.'';
+ }
+ $newattachmenturl .= '';
}
- $newattachmenturl =~ s/::::$//;
} else {
- $newattachmenturl = '::::1:.0n.';
+ $newattachmenturl = ''.&HTML::Entities::encode($oldattachmenturl).'n';
unless (grep/^0$/,@{$keepold}) {
- $newattachmenturl .= '.1n.';
+ $newattachmenturl .= 'n';
}
- $newattachmenturl .= '::::'.$oldattachmenturl;
+ $newattachmenturl .= '';
$startnum ++;
}
}
}
for (my $i=0; $i<@{$currnewattach}; $i++) {
my $attachnum = $startnum + $i;
- $newattachmenturl .= '::::'.$attachnum.':.'.$currver.'n.::::'.$$currnewattach[$i];
+ $newattachmenturl .= ''.&HTML::Entities::encode($$currnewattach[$i]).'n';
}
return $newattachmenturl;
}
@@ -2459,12 +2506,16 @@ END
if ($contrib{$idx.':history'}) {
my $attachmenturls = $contrib{$idx.':attachmenturl'};
my @postversions = ();
+ my %messages = ();
+ my %subjects = ();
if ($contrib{$idx.':history'} =~ m/:/) {
@postversions = split/:/,$contrib{$idx.':history'};
} else {
@postversions = ("$contrib{$idx.':history'}");
}
if (@postversions > 0) {
+ &get_post_versions(\%messages,$contrib{$idx.':message'});
+ &get_post_versions(\%subjects,$contrib{$idx.':subject'});
push @postversions,$contrib{$idx.':timestamp'};
my $screenname=&Apache::loncommon::screenname(
$contrib{$idx.':sendername'},
@@ -2485,21 +2536,16 @@ END
for (my $i=0; $i<@postversions; $i++) {
my ($timesent,$message,$subject,$attachmsg);
$timesent = &Apache::lonlocal::locallocaltime($postversions[$i]);
- if ($i == @postversions-1) {
- ($message)=($contrib{$idx.':message'} =~ /.*::::\Q$i\E::::(.+?)$/si);
- ($subject)=($contrib{$idx.':subject'} =~ /.*::::\Q$i\E::::(.+?)$/si);
- } else {
- ($message)=($contrib{$idx.':message'} =~ /::::\Q$i\E::::(.+?)::::/si);
- ($subject)=($contrib{$idx.':subject'} =~ /::::\Q$i\E::::(.+?)::::/si);
- }
+ $message=&HTML::Entities::decode($messages{$i});
+ $subject=&HTML::Entities::decode($subjects{$i});
$message=~s/\n/\
/g;
$message=&Apache::lontexconvert::msgtexconverted($message);
$subject=~s/\n/\
/g;
$subject=&Apache::lontexconvert::msgtexconverted($subject);
if ($attachmenturls) {
- my @attachments = ();
+ my %attachments = ();
my %currattach = ();
- &extract_attachments($attachmenturls,$idx,$i,\$attachmsg,\@attachments,\%currattach);
+ &extract_attachments($attachmenturls,$idx,$i,\$attachmsg,\%attachments,\%currattach);
}
if ($attachmsg) {
$attachmsg = '
Attachments:'.$attachmsg.'
';