Diff for /loncom/interface/lonfeedback.pm between versions 1.112 and 1.115

version 1.112, 2004/08/03 21:29:32 version 1.115, 2004/08/10 18:25:53
Line 298  sub list_discussion { Line 298  sub list_discussion {
                     $subject=&Apache::lontexconvert::msgtexconverted($subject);                      $subject=&Apache::lontexconvert::msgtexconverted($subject);
                 }                  }
  if ($attachmenturls) {   if ($attachmenturls) {
                     my @attachments = ();                      my %attachments = ();
                     my %currattach = ();                      my %currattach = ();
                     &extract_attachments($attachmenturls,$idx,$numoldver,\$message,\@attachments,\%currattach);                      &extract_attachments($attachmenturls,$idx,$numoldver,\$message,\%attachments,\%currattach);
  }   }
  if ($message) {   if ($message) {
     if ($hidden) {      if ($hidden) {
Line 682  sub list_discussion { Line 682  sub list_discussion {
     }      }
     $discussion .= '</tr></table></td></tr>';      $discussion .= '</tr></table></td></tr>';
  } else {   } else {
     $discussion.='\vskip 0 mm\noindent\makebox[2 cm][b]{\hrulefill}'.      $discussion.='<tex>\vskip 0 mm\noindent\makebox[2 cm][b]{\hrulefill}'.
                          '\textbf{DISCUSSIONS}\makebox[2 cm][b]{\hrulefill}'.                           '\textbf{DISCUSSIONS}\makebox[2 cm][b]{\hrulefill}'.
                          '\vskip 0 mm\noindent\textbf{'.$lt{'cuse'}.'}:\vskip 0 mm'.                           '\vskip 0 mm\noindent\textbf{'.$lt{'cuse'}.'}:\vskip 0 mm'.
                          '\noindent\textbf{'.$lt{'disa'}.'}: \textit{'.$currdisp.'}\vskip 0 mm'.                           '\noindent\textbf{'.$lt{'disa'}.'}: \textit{'.$currdisp.'}\vskip 0 mm'.
                          '\noindent\textbf{'.$lt{'npce'}.'}: \textit{'.$currmark.'}';                           '\noindent\textbf{'.$lt{'npce'}.'}: \textit{'.$currmark.'}</tex>';
  }   }
         my $numhidden = keys %notshown;          my $numhidden = keys %notshown;
         if ($numhidden > 0) {          if ($numhidden > 0) {
Line 739  sub list_discussion { Line 739  sub list_discussion {
             unless ( ($notshown{$alldiscussion{$_}} eq '1') || ($shown{$alldiscussion{$_}} == 0) ) {              unless ( ($notshown{$alldiscussion{$_}} eq '1') || ($shown{$alldiscussion{$_}} == 0) ) {
                 if ($outputtarget ne 'tex') {                  if ($outputtarget ne 'tex') {
     $discussion.="\n<tr>";      $discussion.="\n<tr>";
  } else {  
     $discussion.='\vskip 0 mm\noindent\makebox[2 cm][b]{\hrulefill}';  
  }   }
         my $thisdepth=$depth[$alldiscussion{$_}];          my $thisdepth=$depth[$alldiscussion{$_}];
                 if ($outputtarget ne 'tex') {                  if ($outputtarget ne 'tex') {
Line 764  sub list_discussion { Line 762  sub list_discussion {
     $discussionitems[$alldiscussion{$_}]=~s/<\/td><td([^>]*)>/$threadinsert<\/td><td TeXwidth="65 mm" align="left">/;      $discussionitems[$alldiscussion{$_}]=~s/<\/td><td([^>]*)>/$threadinsert<\/td><td TeXwidth="65 mm" align="left">/;
     $discussionitems[$alldiscussion{$_}]=~s/<a([^>]+)>(Edit|Hide|Delete|Reply|Submissions)<\/a>//g;      $discussionitems[$alldiscussion{$_}]=~s/<a([^>]+)>(Edit|Hide|Delete|Reply|Submissions)<\/a>//g;
                     $discussionitems[$alldiscussion{$_}]=~s/(<b>|<\/b>|<\/a>|<a([^>]+)>)//g;                      $discussionitems[$alldiscussion{$_}]=~s/(<b>|<\/b>|<\/a>|<a([^>]+)>)//g;
       
                     #FIXME xmlparse can't be safely called from inside xmlparse      $discussionitems[$alldiscussion{$_}]='<tex>\vskip 0 mm\noindent\makebox[2 cm][b]{\hrulefill}</tex>'.$discussionitems[$alldiscussion{$_}];
                     #   due to the global variables that are use, the safe      $discussion.=$discussionitems[$alldiscussion{$_}];
                     #   space etc. I expect this has unforseen issues that  
                     #   need resolving.  
       
                     $discussion.=&Apache::lonxml::xmlparse('','tex',$discussionitems[$alldiscussion{$_}]);  
  }   }
     }      }
         }          }
Line 829  END Line 823  END
            </table>             </table>
            <br /><br /></form>             <br /><br /></form>
 END  END
  }          } 
     }      }
     if ($discussiononly) {      if ($discussiononly) {
         my $now = time;          my $now = time;
Line 901  ENDDISCUSS Line 895  ENDDISCUSS
     }      }
  }   }
     }      }
    return $discussion;      return $discussion;
 }  }
   
 sub mail_screen {  sub mail_screen {
Line 925  sub mail_screen { Line 919  sub mail_screen {
   my @currnewattach = ();    my @currnewattach = ();
   my @currdelold = ();    my @currdelold = ();
   my @keepold = ();    my @keepold = ();
   my @attachments = ();    my %attachments = ();
   my %currattach = ();    my %currattach = ();
   my $attachnum = 0;    my $attachnum = 0;
   my $anonchk = (<<END);    my $anonchk = (<<END);
Line 1163  END Line 1157  END
         }          }
         if ($ENV{'form.editdisc'}) {          if ($ENV{'form.editdisc'}) {
             if ($attachmenturls) {              if ($attachmenturls) {
                 &extract_attachments($attachmenturls,$idx,$numoldver,\$attachmsg,\@attachments,\%currattach,\@currdelold);                  &extract_attachments($attachmenturls,$idx,$numoldver,\$attachmsg,\%attachments,\%currattach,\@currdelold);
                 $attachnum = scalar(keys %currattach);                  $attachnum = scalar(keys %currattach);
                 foreach (keys %currattach) {                  foreach (keys %currattach) {
                     $r->print('<input type="hidden" name="keepold" value="'.$_.'" />'."\n");                      $r->print('<input type="hidden" name="keepold" value="'.$_.'" />'."\n");
Line 1689  sub get_post_versions { Line 1683  sub get_post_versions {
     return;      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) = @_;    my ($r,$feedurl) = @_;
   if ($feedurl=~/^\/adm\//) { $feedurl.='?register=1' };    if ($feedurl=~/^\/adm\//) { $feedurl.='?register=1' };
   $r->print (<<ENDFAILREDIR);    $r->print (<<ENDFAILREDIR);
Line 2141  sub modify_attachments { Line 2153  sub modify_attachments {
     my $bodytag=&Apache::loncommon::bodytag('Discussion Post Attachments',      my $bodytag=&Apache::loncommon::bodytag('Discussion Post Attachments',
                                           '','');                                            '','');
     my $msg = '';      my $msg = '';
     my @attachments = ();      my %attachments = ();
     my %currattach = ();      my %currattach = ();
     if ($idx) {      if ($idx) {
         &extract_attachments($attachmenturls,$idx,$numoldver,\$msg,\@attachments,\%currattach,$currdelold);          &extract_attachments($attachmenturls,$idx,$numoldver,\$msg,\%attachments,\%currattach,$currdelold);
     }      }
     $r->print(<<END);      $r->print(<<END);
 <html>  <html>
Line 2169  END Line 2181  END
             my @currold = keys %currattach;              my @currold = keys %currattach;
             if (@currold > 0) {              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");                    $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) {                  foreach my $id (@currold) {
                     my $id = $_;                      my $attachurl = &HTML::Entities::decode($attachments{$id}{'filename'}); 
                     $attachments[$id] =~ m#/([^/]+)$#;                      $attachurl =~ m#/([^/]+)$#;
                     $r->print('<input type="checkbox" name="deloldattach" value="'.$_.'" />&nbsp;'.$1.'<br />'."\n");                      $r->print('<input type="checkbox" name="deloldattach" value="'.$id.'" />&nbsp;'.$1.'<br />'."\n");
                 }                  }
                 $r->print("<br />");                  $r->print("<br />");
             }              }
Line 2305  ENDATTACH Line 2317  ENDATTACH
   
 sub extract_attachments {  sub extract_attachments {
     my ($attachmenturls,$idx,$numoldver,$message,$attachments,$currattach,$currdelold) = @_;      my ($attachmenturls,$idx,$numoldver,$message,$attachments,$currattach,$currdelold) = @_;
     if ($attachmenturls =~ m/::::\d+:[\.yn\d]+::::/) {      if ($attachmenturls =~ m/^<attachment id="0">/) {
         @{$attachments} = split/::::\d+:[\.yn\d]+::::/,$attachmenturls;          &get_post_attachments($attachments,$attachmenturls);
         shift @{$attachments};          foreach my $id (sort keys %{$attachments}) {
         my $searchstr = '::::';              if (exists($$attachments{$id}{$numoldver})) {
         for (my $i=0; $i<@{$attachments}; $i++) {                  if (defined($currdelold)) {
             if ($attachmenturls =~ m#^\Q$searchstr\E(\d+)(:[\.yn\d]+)::::#) {                      if (@{$currdelold} > 0) {
                 my $info = $1.$2;                          unless (grep/^$id$/,@{$currdelold}) {
                 my $attachid = $1-1;                              $$currattach{$id} = $$attachments{$id}{$numoldver}; 
                 $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;  
                         }                          }
                     } else {                      } else {
                         my $id = $i;                          $$currattach{$id} = $$attachments{$id}{$numoldver};
                         $$currattach{$id} = $1;  
                     }                      }
                   } else {
                       $$currattach{$id} = $$attachments{$id}{$numoldver};
                 }                  }
             }              }
         }          }
         my @attached = (sort { $a <=> $b } keys %{$currattach});          my @attached = (sort { $a <=> $b } keys %{$currattach});
         if (@attached == 1) {          if (@attached == 1) {
             my $id = $attached[0];              my $id = $attached[0];
             $$attachments[$attached[0]]=~m|/([^/]+)$|;              my $attachurl = &HTML::Entities::decode($$attachments{$id}{'filename'});
             $$message.='<br /><a href="'.$$attachments[$id].'"><tt>'.              $attachurl=~m|/([^/]+)$|;
               $$message.='<br /><a href="'.$attachurl.'"><tt>'.
             $1.'</tt></a><br />';              $1.'</tt></a><br />';
             &Apache::lonnet::allowuploaded('/adm/feedback',              &Apache::lonnet::allowuploaded('/adm/feedback',
                                    $$attachments[$id]);                                     $attachurl);
         } elsif (@attached > 1) {          } elsif (@attached > 1) {
             $$message.='<ol>';              $$message.='<ol>';
             foreach (@attached) {              foreach (@attached) {
                 my $id = $_;                  my $id = $_;
                   my $attachurl = &HTML::Entities::decode($$attachments{$id}{'filename'});
                 my ($fname)                  my ($fname)
                   =($$attachments[$id]=~m|/([^/]+)$|);                    =($attachurl=~m|/([^/]+)$|);
                 $$message .= '<li><a href="'.$$attachments[$id].                  $$message .= '<li><a href="'.$attachurl.
                   '"><tt>'.                    '"><tt>'.
                   $fname.'</tt></a></li>';                    $fname.'</tt></a></li>';
                 &Apache::lonnet::allowuploaded('/adm/feedback',                  &Apache::lonnet::allowuploaded('/adm/feedback',
                                  $$attachments[$id]);                                   $attachurl);
             }              }
             $$message .= '</ol><br />';              $$message .= '</ol><br />';
         }          }
Line 2361  sub extract_attachments { Line 2365  sub extract_attachments {
            ': <a href="'.$attachmenturls.             ': <a href="'.$attachmenturls.
            '"><tt>'.             '"><tt>'.
            $fname.'</tt></a></p>';             $fname.'</tt></a></p>';
            $$attachments[0] = $attachmenturls;             $$attachments{0} = $attachmenturls;
            $$currattach{'0'} = 'n';             $$currattach{'0'} = 'n';
            &Apache::lonnet::allowuploaded('/adm/feedback',             &Apache::lonnet::allowuploaded('/adm/feedback',
                              $attachmenturls);                               $attachmenturls);
Line 2372  sub construct_attachmenturl { Line 2376  sub construct_attachmenturl {
     my ($currnewattach,$keepold,$symb,$idx)=@_;      my ($currnewattach,$keepold,$symb,$idx)=@_;
     my $oldattachmenturl;      my $oldattachmenturl;
     my $newattachmenturl;      my $newattachmenturl;
     my $startnum = 1;      my $startnum = 0;
     my $currver = 0;      my $currver = 0;
     if (($ENV{'form.editdisc'}) && ($idx)) {      if (($ENV{'form.editdisc'}) && ($idx)) {
         my %contrib=&Apache::lonnet::restore($symb,$ENV{'request.course.id'},          my %contrib=&Apache::lonnet::restore($symb,$ENV{'request.course.id'},
Line 2390  sub construct_attachmenturl { Line 2394  sub construct_attachmenturl {
             $currver = 1;              $currver = 1;
         }          }
         if ($oldattachmenturl) {          if ($oldattachmenturl) {
             if ($oldattachmenturl =~ m/::::\d+:[\.yn\d]+::::/) {              if ($oldattachmenturl =~ m/^<attachment id="0">/) {
                 my @attachments = split/::::\d+:[\.yn\d]+::::/,$oldattachmenturl;                  my %attachments = ();
                 shift @attachments;                  my $prevver = $currver-1;
                 $startnum += @attachments;                  &get_post_attachments(\%attachments,$oldattachmenturl);
                 my $searchstr = '::::';                  my $numattach = keys %attachments;
                 $newattachmenturl = '::::';                  $startnum += $numattach;
                 for (my $i=0; $i<@attachments; $i++) {                  foreach my $num (sort {$a <=> $b} keys %attachments) {
                     if ($oldattachmenturl =~ m#^\Q$searchstr\E(\d+)(:[\.yn\d]+)::::#) {                      $newattachmenturl .= '<attachment id="'.$num.'"><filename>'.$attachments{$num}{'filename'}.'</filename>';
                         my $attachid = $1 - 1;                      foreach (sort {$a <=> $b} keys %{$attachments{$num}}) { 
                         $searchstr .= $1.$2.'::::'.$attachments[$i].'::::';                          $newattachmenturl .= '<post id="'.$_.'">'.$attachments{$num}{$_}.'</post>';
                         $newattachmenturl .= $1.$2;                      }
                         if (grep/^$attachid$/,@{$keepold}) {                      if (grep/^$num$/,@{$keepold}) {
                             $newattachmenturl .= '.'.$currver.'n.';                          $newattachmenturl .= '<post id="'.$currver.'">'.$attachments{$num}{$prevver}.'</post>';
                         }  
                         $newattachmenturl .= '::::'.$attachments[$i].'::::';  
                     }                      }
                       $newattachmenturl .= '</attachment>';
                 }                  }
                 $newattachmenturl =~ s/::::$//;  
             } else {              } else {
                 $newattachmenturl = '::::1:.0n.';                  $newattachmenturl = '<attachment id="0"><filename>'.&HTML::Entities::encode($oldattachmenturl).'<post id="0">n</post>';
                 unless (grep/^0$/,@{$keepold}) {                  unless (grep/^0$/,@{$keepold}) {
                     $newattachmenturl .= '.1n.';                      $newattachmenturl .= '<post id="1">n</post>';
                 }                  }
                 $newattachmenturl .= '::::'.$oldattachmenturl;                  $newattachmenturl .= '</attachment>';
                 $startnum ++;                  $startnum ++;
             }              }
         }          }
     }      }
     for (my $i=0; $i<@{$currnewattach}; $i++) {      for (my $i=0; $i<@{$currnewattach}; $i++) {
         my $attachnum = $startnum + $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;       return $newattachmenturl; 
 }  }
Line 2535  END Line 2537  END
                       $subject=~s/\n/\<br \/\>/g;                        $subject=~s/\n/\<br \/\>/g;
                       $subject=&Apache::lontexconvert::msgtexconverted($subject);                        $subject=&Apache::lontexconvert::msgtexconverted($subject);
                       if ($attachmenturls) {                        if ($attachmenturls) {
                           my @attachments = ();                            my %attachments = ();
                           my %currattach = ();                            my %currattach = ();
                           &extract_attachments($attachmenturls,$idx,$i,\$attachmsg,\@attachments,\%currattach);                            &extract_attachments($attachmenturls,$idx,$i,\$attachmsg,\%attachments,\%currattach);
                       }                        }
                       if ($attachmsg) {                        if ($attachmsg) {
                           $attachmsg = '<br />Attachments:'.$attachmsg.'<br />';                            $attachmsg = '<br />Attachments:'.$attachmsg.'<br />';

Removed from v.1.112  
changed lines
  Added in v.1.115


FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>