--- loncom/interface/lonfeedback.pm	2005/05/20 17:04:30	1.163
+++ loncom/interface/lonfeedback.pm	2005/10/04 18:27:32	1.169
@@ -1,7 +1,7 @@
 # The LearningOnline Network
 # Feedback
 #
-# $Id: lonfeedback.pm,v 1.163 2005/05/20 17:04:30 albertel Exp $
+# $Id: lonfeedback.pm,v 1.169 2005/10/04 18:27:32 albertel Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -97,7 +97,7 @@ sub list_discussion {
     $ressymb=&wrap_symb($ressymb);
     my $encsymb=&Apache::lonenc::check_encrypt($ressymb);
     my $viewgrades=(&Apache::lonnet::allowed('vgr',$crs)
-		  && ($ressymb=~/\.(problem|exam|quiz|assess|survey|form)$/));
+		  && ($ressymb=~/\.(problem|exam|quiz|assess|survey|form|task)$/));
     
     my %usernamesort = ();
     my %namesort =();
@@ -113,7 +113,7 @@ sub list_discussion {
     my $toggkey = $ressymb.'_readtoggle';
     my $readkey = $ressymb.'_read';
     $ressymb=$encsymb;
-    my %dischash = &Apache::lonnet::get('nohist_'.$env{'request.course.id'}.'_discuss',[$lastkey,$showkey,$markkey,$visitkey,$ondispkey,$userpickkey,$toggkey,$readkey],$env{'user.domain'},$env{'user.name'});
+    my %dischash = &Apache::lonnet::get('nohist_'.$cid.'_discuss',[$lastkey,$showkey,$markkey,$visitkey,$ondispkey,$userpickkey,$toggkey,$readkey],$env{'user.domain'},$env{'user.name'});
     my %discinfo = ();
     my $showonlyunread = 0;
     my $showunmark = 0; 
@@ -154,7 +154,9 @@ sub list_discussion {
     my %roleshash = ();
     my %roleinfo = ();
     if ($env{'form.rolefilter'}) {
-        %roleshash = &Apache::lonnet::dump('nohist_userroles',$env{'course.'.$env{'request.course.id'}.'.domain'},$env{'course.'.$env{'request.course.id'}.'.num'});
+        %roleshash = &Apache::lonnet::dump('nohist_userroles',
+					   $env{'course.'.$cid.'.domain'},
+					   $env{'course.'.$cid.'.num'});
         foreach (keys %roleshash) {
             my ($role,$uname,$udom,$sec) = split/:/,$_;
             if ($role =~ /^cr/) {
@@ -171,9 +173,8 @@ sub list_discussion {
             }
         }
         my ($classlist) = &Apache::loncoursedata::get_classlist(
-                              $env{'request.course.id'},
-                              $env{'course.'.$env{'request.course.id'}.'.domain'},
-                              $env{'course.'.$env{'request.course.id'}.'.num'});
+                              $env{'course.'.$cid.'.domain'},
+                              $env{'course.'.$cid.'.num'});
         my $sec_index = &Apache::loncoursedata::CL_SECTION();
         my $status_index = &Apache::loncoursedata::CL_STATUS();
         while (my ($student,$data) = each %$classlist) {
@@ -245,7 +246,7 @@ sub list_discussion {
     my $now = time;
     $discinfo{$visitkey} = $visit;
 
-    &Apache::lonnet::put('nohist_'.$env{'request.course.id'}.'_discuss',\%discinfo,$env{'user.domain'},$env{'user.name'});
+    &Apache::lonnet::put('nohist_'.$cid.'_discuss',\%discinfo,$env{'user.domain'},$env{'user.name'});
     &build_posting_display(\%usernamesort,\%subjectsort,\%namesort,\%notshown,\%newitem,\%dischash,\%shown,\%alldiscussion,\%imsitems,\%imsfiles,\%roleinfo,\@discussionitems,\@replies,\@depth,\@posters,\$maxdepth,\$visible,\$newpostsflag,\$current,$status,$viewgrades,$seeid,$prevread,$sortposts,$encsymb,$target,$readkey,$showunmark,$showonlyunread,$totposters,\@rolefilter,\@sectionpick,$statusfilter,$toggkey,$outputtarget);
 
     my $discussion='';
@@ -858,7 +859,7 @@ sub build_posting_display {
 					 $contrib{$idx.':sendername'}.' at '.
 					 $contrib{$idx.':senderdomain'}.')';
 			    if ($contrib{$idx.':anonymous'}) {
-			        $sender.=' ['.&mt('anonymous').'] '.
+			        $sender.=' <font color="red"><b>['.&mt('anonymous').']</b></font> '.
 				    $screenname;
 			    }
 
@@ -1205,7 +1206,7 @@ sub get_post_contents {
         my ($timesent,$attachmsg);
         my %currattach = ();
         $timesent = &Apache::lonlocal::locallocaltime($postversions[$i]);
-        $$messages{$i}=~s/\n/\<br \/\>/g;
+	&newline_to_br(\$messages->{$i});
         $$messages{$i}=&Apache::lontexconvert::msgtexconverted($$messages{$i});
         $$subjects{$i}=~s/\n/\<br \/\>/g;
         $$subjects{$i}=&Apache::lontexconvert::msgtexconverted($$subjects{$i});
@@ -1375,7 +1376,7 @@ END
                   &get_post_versions(\%msgversions,$contrib{$idx.':message'},0,$numoldver);
                   $message = $msgversions{$numoldver};
               }
-	      $message=~s/\n/\<br \/\>/g;
+	      &newline_to_br(\$message);
 	      $quote='<blockquote>'.&Apache::lontexconvert::msgtexconverted($message).'</blockquote>';
               if ($idx > 0) {
                   my %subversions = ();
@@ -2259,7 +2260,7 @@ sub screen_header {
     my $msgoptions='';
     my $discussoptions='';
     unless (($env{'form.replydisc'}) || ($env{'form.editdisc'})) {
-	if (($feedurl=~/^\/res\//) && ($feedurl!~/^\/res\/adm/)) {
+	if (($feedurl=~/^\/res\//) && ($feedurl!~/^\/res\/adm/) && ($env{'user.adv'})) {
 	    $msgoptions= 
 		'<p><label><input type="checkbox" name="author" /> '.
 		&mt('Feedback to resource author').'</label></p>';
@@ -2603,7 +2604,7 @@ sub show_preview {
     &Apache::loncommon::content_type($r,'text/html');
     $r->send_http_header;
     my $message=&clear_out_html($env{'form.comment'});
-    $message=~s/\n/\<br \/\>/g;
+    &newline_to_br(\$message);
     $message=&Apache::lonspeller::markeduptext($message);
     $message=&Apache::lontexconvert::msgtexconverted($message);
     my $subject=&clear_out_html($env{'form.subject'});
@@ -2616,6 +2617,28 @@ sub show_preview {
 	      $message.'</td></tr></table></body></html>');
 }
 
+
+sub newline_to_br {
+    my ($message)=@_;
+    my $newmessage;
+    my $parser=HTML::LCParser->new($message);
+    while (my $token=$parser->get_token()) {
+	if ($token->[0] eq 'T') {
+	    my $text=$token->[1];
+	    $text=~s/\n/\<br \/\>/g;
+	    $newmessage.=$text;
+	} elsif ($token->[0] eq 'D' || $token->[0] eq 'C') {
+	    $newmessage.=$token->[1];
+	} elsif ($token->[0] eq 'PI' || $token->[0] eq 'E') {
+	    $newmessage.=$token->[2];
+	} elsif ($token->[0] eq 'S') {
+	    $newmessage.=$token->[4];
+	}
+	    
+    }
+    $$message=$newmessage;
+}
+
 sub generate_preview_button {
     my $pre=&mt("Show Preview and Check Spelling");
     return(<<ENDPREVIEW);
@@ -2762,8 +2785,8 @@ this.form.submit();" />
 <input type="hidden" name="timestamp" value="$now" />
 <input type="hidden" name="subject" />
 <input type="hidden" name="comment" />
-<input type="hidden" name="anondiscuss" value = "0";
-<input type="hidden" name="discuss" value = "0";
+<input type="hidden" name="anondiscuss" value = "0" />
+<input type="hidden" name="discuss" value = "0" />
 <input type="hidden" name="numoldver" value="$numoldver" />
 ENDATTACH
     if (defined($deloldattach)) {
@@ -3235,7 +3258,7 @@ ENDREDIR
       my $mode='board';
       my $status='OPEN';
       my $previous=$env{'form.previous'};
-      if ($feedurl =~ /\.(problem|exam|quiz|assess|survey|form|library)$/) {
+      if ($feedurl =~ /\.(problem|exam|quiz|assess|survey|form|library|task)$/) {
           $mode='problem';
           $status=$Apache::inputtags::status[-1];
       }
@@ -3274,7 +3297,7 @@ ENDREDIR
       }
       &Apache::lonenc::check_decrypt(\$symb);
       my $goahead=1;
-      if ($feedurl=~/\.(problem|exam|quiz|assess|survey|form)$/) {
+      if ($feedurl=~/\.(problem|exam|quiz|assess|survey|form|task)$/) {
 	  unless ($symb) { $goahead=0; }
       }
       # backward compatibility (bulletin boards used to be 'wrapped')