--- loncom/interface/lonfeedback.pm 2004/08/03 21:29:32 1.112 +++ 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.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 @@ sub list_discussion { $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 @@ sub mail_screen { my @currnewattach = (); my @currdelold = (); my @keepold = (); - my @attachments = (); + my %attachments = (); my %currattach = (); my $attachnum = 0; my $anonchk = (<print(''."\n"); @@ -1689,7 +1689,25 @@ sub get_post_versions { 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 (<print(< @@ -2169,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("
"); } @@ -2305,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 .= '
  1. '. $fname.'
  2. '; &Apache::lonnet::allowuploaded('/adm/feedback', - $$attachments[$id]); + $attachurl); } $$message .= '

'; } @@ -2361,7 +2371,7 @@ sub extract_attachments { ': '. $fname.'

'; - $$attachments[0] = $attachmenturls; + $$attachments{0} = $attachmenturls; $$currattach{'0'} = 'n'; &Apache::lonnet::allowuploaded('/adm/feedback', $attachmenturls); @@ -2372,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'}, @@ -2390,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; } @@ -2535,9 +2543,9 @@ END $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.'
';