[LON-CAPA-cvs] cvs: loncom /interface lonfeedback.pm
raeburn
lon-capa-cvs@mail.lon-capa.org
Wed, 04 Aug 2004 18:04:57 -0000
This is a MIME encoded message
--raeburn1091642697
Content-Type: text/plain
raeburn Wed Aug 4 14:04:57 2004 EDT
Modified files:
/loncom/interface lonfeedback.pm
Log:
XML now used to store information about multiple attachments. Still to do: option to set display of attachments inline in post.
--raeburn1091642697
Content-Type: text/plain
Content-Disposition: attachment; filename="raeburn-20040804140457.txt"
Index: loncom/interface/lonfeedback.pm
diff -u loncom/interface/lonfeedback.pm:1.112 loncom/interface/lonfeedback.pm:1.113
--- loncom/interface/lonfeedback.pm:1.112 Tue Aug 3 17:29:32 2004
+++ loncom/interface/lonfeedback.pm Wed Aug 4 14:04:57 2004
@@ -1,7 +1,7 @@
# The LearningOnline Network
# Feedback
#
-# $Id: lonfeedback.pm,v 1.112 2004/08/03 21:29:32 raeburn Exp $
+# $Id: lonfeedback.pm,v 1.113 2004/08/04 18:04:57 raeburn Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -298,9 +298,9 @@
$subject=&Apache::lontexconvert::msgtexconverted($subject);
}
if ($attachmenturls) {
- my @attachments = ();
+ my %attachments = ();
my %currattach = ();
- &extract_attachments($attachmenturls,$idx,$numoldver,\$message,\@attachments,\%currattach);
+ &extract_attachments($attachmenturls,$idx,$numoldver,\$message,\%attachments,\%currattach);
}
if ($message) {
if ($hidden) {
@@ -925,7 +925,7 @@
my @currnewattach = ();
my @currdelold = ();
my @keepold = ();
- my @attachments = ();
+ my %attachments = ();
my %currattach = ();
my $attachnum = 0;
my $anonchk = (<<END);
@@ -1163,7 +1163,7 @@
}
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('<input type="hidden" name="keepold" value="'.$_.'" />'."\n");
@@ -1689,7 +1689,25 @@
return;
}
-sub fail_redirect {
+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 (<<ENDFAILREDIR);
@@ -2141,10 +2159,10 @@
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(<<END);
<html>
@@ -2169,10 +2187,10 @@
my @currold = keys %currattach;
if (@currold > 0) {
$r->print("The following attachments were part of the most recent saved version of this posting.<br />Check the checkboxes for any you wish to remove<br />\n");
- foreach (@currold) {
- my $id = $_;
- $attachments[$id] =~ m#/([^/]+)$#;
- $r->print('<input type="checkbox" name="deloldattach" value="'.$_.'" /> '.$1.'<br />'."\n");
+ foreach my $id (@currold) {
+ my $attachurl = &HTML::Entities::decode($attachments{$id}{'filename'});
+ $attachurl =~ m#/([^/]+)$#;
+ $r->print('<input type="checkbox" name="deloldattach" value="'.$id.'" /> '.$1.'<br />'."\n");
}
$r->print("<br />");
}
@@ -2305,52 +2323,44 @@
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/^<attachment id="0">/) {
+ &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.='<br /><a href="'.$$attachments[$id].'"><tt>'.
+ my $attachurl = &HTML::Entities::decode($$attachments{$id}{'filename'});
+ $attachurl=~m|/([^/]+)$|;
+ $$message.='<br /><a href="'.$attachurl.'"><tt>'.
$1.'</tt></a><br />';
&Apache::lonnet::allowuploaded('/adm/feedback',
- $$attachments[$id]);
+ $attachurl);
} elsif (@attached > 1) {
$$message.='<ol>';
foreach (@attached) {
my $id = $_;
+ my $attachurl = &HTML::Entities::decode($$attachments{$id}{'filename'});
my ($fname)
- =($$attachments[$id]=~m|/([^/]+)$|);
- $$message .= '<li><a href="'.$$attachments[$id].
+ =($attachurl=~m|/([^/]+)$|);
+ $$message .= '<li><a href="'.$attachurl.
'"><tt>'.
$fname.'</tt></a></li>';
&Apache::lonnet::allowuploaded('/adm/feedback',
- $$attachments[$id]);
+ $attachurl);
}
$$message .= '</ol><br />';
}
@@ -2361,7 +2371,7 @@
': <a href="'.$attachmenturls.
'"><tt>'.
$fname.'</tt></a></p>';
- $$attachments[0] = $attachmenturls;
+ $$attachments{0} = $attachmenturls;
$$currattach{'0'} = 'n';
&Apache::lonnet::allowuploaded('/adm/feedback',
$attachmenturls);
@@ -2372,7 +2382,7 @@
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'},
@@ -2390,37 +2400,35 @@
$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/^<attachment id="0">/) {
+ 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 .= '<attachment id="'.$num.'"><filename>'.$attachments{$num}{'filename'}.'</filename>';
+ foreach (sort {$a <=> $b} keys %{$attachments{$num}}) {
+ $newattachmenturl .= '<post id="'.$_.'">'.$attachments{$num}{$_}.'</post>';
+ }
+ if (grep/^$num$/,@{$keepold}) {
+ $newattachmenturl .= '<post id="'.$currver.'">'.$attachments{$num}{$prevver}.'</post>';
}
+ $newattachmenturl .= '</attachment>';
}
- $newattachmenturl =~ s/::::$//;
} else {
- $newattachmenturl = '::::1:.0n.';
+ $newattachmenturl = '<attachment id="0"><filename>'.&HTML::Entities::encode($oldattachmenturl).'<post id="0">n</post>';
unless (grep/^0$/,@{$keepold}) {
- $newattachmenturl .= '.1n.';
+ $newattachmenturl .= '<post id="1">n</post>';
}
- $newattachmenturl .= '::::'.$oldattachmenturl;
+ $newattachmenturl .= '</attachment>';
$startnum ++;
}
}
}
for (my $i=0; $i<@{$currnewattach}; $i++) {
my $attachnum = $startnum + $i;
- $newattachmenturl .= '::::'.$attachnum.':.'.$currver.'n.::::'.$$currnewattach[$i];
+ $newattachmenturl .= '<attachment id="'.$attachnum.'"><filename>'.&HTML::Entities::encode($$currnewattach[$i]).'</filename><post id="'.$currver.'">n</post></attachment>';
}
return $newattachmenturl;
}
@@ -2535,9 +2543,9 @@
$subject=~s/\n/\<br \/\>/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 = '<br />Attachments:'.$attachmsg.'<br />';
--raeburn1091642697--